rads-db 3.2.13 → 3.2.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +2 -0
- package/dist/index.d.ts +10 -1
- package/dist/index.mjs +1 -1
- package/drivers/sql.cjs +3 -2
- package/drivers/sql.mjs +3 -2
- package/features/eventSourcing.cjs +3 -12
- package/features/eventSourcing.mjs +2 -11
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1426,6 +1426,8 @@ function createRadsDbClient(dataSourceKey, args) {
|
|
|
1426
1426
|
return generateMethods(s, validators, radsDbArgs);
|
|
1427
1427
|
}
|
|
1428
1428
|
|
|
1429
|
+
exports.afterPut = afterPut;
|
|
1430
|
+
exports.beforePut = beforePut;
|
|
1429
1431
|
exports.cleanEntity = cleanEntity;
|
|
1430
1432
|
exports.computed = computed;
|
|
1431
1433
|
exports.createRadsDb = createRadsDb;
|
package/dist/index.d.ts
CHANGED
|
@@ -16,6 +16,15 @@ declare function getDriverInstance(schema: Schema, key: string, driverConstructo
|
|
|
16
16
|
|
|
17
17
|
declare function handlePrecomputed(context: ComputedContext, docs: any[], ctx: RadsRequestContext): Promise<void>;
|
|
18
18
|
|
|
19
|
+
declare function beforePut(items: {
|
|
20
|
+
oldDoc: any;
|
|
21
|
+
doc: any;
|
|
22
|
+
}[], ctx: RadsRequestContext, computedContext: ComputedContext): Promise<void>;
|
|
23
|
+
declare function afterPut(items: {
|
|
24
|
+
oldDoc: any;
|
|
25
|
+
doc: any;
|
|
26
|
+
}[], ctx: RadsRequestContext, computedContext: ComputedContext): Promise<void>;
|
|
27
|
+
|
|
19
28
|
/** Performs immutable deep merge */
|
|
20
29
|
declare function merge<T extends Record<string, any>>(target: T, source: any): T;
|
|
21
30
|
|
|
@@ -35,4 +44,4 @@ declare function createRadsDb<T extends keyof RadsDb>(dataSourceKey: T, args?: C
|
|
|
35
44
|
*/
|
|
36
45
|
declare function createRadsDbClient<T extends keyof RadsDb>(dataSourceKey: T, args?: CreateRadsDbClientArgs): RadsDb[T];
|
|
37
46
|
|
|
38
|
-
export { ComputedContext, ComputedDecoratorArgs, CreateRadsDbArgs, CreateRadsDbClientArgs, Driver, DriverConstructor, EntityDecoratorArgs, FieldDecoratorArgs, RadsRequestContext, Schema, UiDecoratorArgs, UiFieldDecoratorArgs, ValidateEntityDecoratorArgs, ValidateFieldDecoratorArgs, cleanEntity, computed, createRadsDb, createRadsDbClient, diff, entity, field, getDriverInstance, handlePrecomputed, keepHistory, merge, precomputed, ui, validate };
|
|
47
|
+
export { ComputedContext, ComputedDecoratorArgs, CreateRadsDbArgs, CreateRadsDbClientArgs, Driver, DriverConstructor, EntityDecoratorArgs, FieldDecoratorArgs, RadsRequestContext, Schema, UiDecoratorArgs, UiFieldDecoratorArgs, ValidateEntityDecoratorArgs, ValidateFieldDecoratorArgs, afterPut, beforePut, cleanEntity, computed, createRadsDb, createRadsDbClient, diff, entity, field, getDriverInstance, handlePrecomputed, keepHistory, merge, precomputed, ui, validate };
|
package/dist/index.mjs
CHANGED
|
@@ -1419,4 +1419,4 @@ function createRadsDbClient(dataSourceKey, args) {
|
|
|
1419
1419
|
return generateMethods(s, validators, radsDbArgs);
|
|
1420
1420
|
}
|
|
1421
1421
|
|
|
1422
|
-
export { cleanEntity, computed, createRadsDb, createRadsDbClient, diff, entity, field, getDriverInstance, handlePrecomputed, keepHistory, merge, precomputed, ui, validate };
|
|
1422
|
+
export { afterPut, beforePut, cleanEntity, computed, createRadsDb, createRadsDbClient, diff, entity, field, getDriverInstance, handlePrecomputed, keepHistory, merge, precomputed, ui, validate };
|
package/drivers/sql.cjs
CHANGED
|
@@ -377,6 +377,7 @@ ${insertQuery.slice(0, 300)}...`);
|
|
|
377
377
|
await client.query(`delete from ${entity}`);
|
|
378
378
|
return [];
|
|
379
379
|
},
|
|
380
|
+
ensureClientConnected,
|
|
380
381
|
/** Generates migration script for this one entity */
|
|
381
382
|
async generateMigrationScript() {
|
|
382
383
|
await ensureIntrospectionIsAvailable();
|
|
@@ -720,12 +721,12 @@ END;
|
|
|
720
721
|
await clientPromise;
|
|
721
722
|
}
|
|
722
723
|
async function ensureClientConnectedInner() {
|
|
723
|
-
client = await _mssql.default.
|
|
724
|
+
client = await new _mssql.default.ConnectionPool({
|
|
724
725
|
authentication: options.authentication,
|
|
725
726
|
server: options.server,
|
|
726
727
|
database: options.database,
|
|
727
728
|
...options.options
|
|
728
|
-
});
|
|
729
|
+
}).connect();
|
|
729
730
|
}
|
|
730
731
|
};
|
|
731
732
|
module.exports = _default;
|
package/drivers/sql.mjs
CHANGED
|
@@ -248,6 +248,7 @@ ${insertQuery.slice(0, 300)}...`);
|
|
|
248
248
|
await client.query(`delete from ${entity}`);
|
|
249
249
|
return [];
|
|
250
250
|
},
|
|
251
|
+
ensureClientConnected,
|
|
251
252
|
/** Generates migration script for this one entity */
|
|
252
253
|
async generateMigrationScript() {
|
|
253
254
|
await ensureIntrospectionIsAvailable();
|
|
@@ -596,12 +597,12 @@ END;
|
|
|
596
597
|
await clientPromise;
|
|
597
598
|
}
|
|
598
599
|
async function ensureClientConnectedInner() {
|
|
599
|
-
client = await sql.
|
|
600
|
+
client = await new sql.ConnectionPool({
|
|
600
601
|
authentication: options.authentication,
|
|
601
602
|
server: options.server,
|
|
602
603
|
database: options.database,
|
|
603
604
|
...options.options
|
|
604
|
-
});
|
|
605
|
+
}).connect();
|
|
605
606
|
}
|
|
606
607
|
};
|
|
607
608
|
function stringifyValueForInsert(value) {
|
|
@@ -113,14 +113,15 @@ function getEffectFor(entityName, aggregateRelationField, eventEntityName, schem
|
|
|
113
113
|
updatedEvents: v.updatedEvents,
|
|
114
114
|
oldDoc: v.oldAggDoc
|
|
115
115
|
}));
|
|
116
|
+
console.log(ctx);
|
|
116
117
|
const aggregateEffectContext = {
|
|
117
118
|
...context,
|
|
118
119
|
typeName: entityName,
|
|
119
120
|
handle: schema[entityName].handle
|
|
120
121
|
};
|
|
121
|
-
await beforePut(hookItems, ctx, aggregateEffectContext);
|
|
122
|
+
await (0, _radsDb.beforePut)(hookItems, ctx, aggregateEffectContext);
|
|
122
123
|
await context.drivers[entityName].putMany(aggs, ctx);
|
|
123
|
-
await afterPut(hookItems, ctx, aggregateEffectContext);
|
|
124
|
+
await (0, _radsDb.afterPut)(hookItems, ctx, aggregateEffectContext);
|
|
124
125
|
}
|
|
125
126
|
};
|
|
126
127
|
}
|
|
@@ -189,14 +190,4 @@ function validateSchemaField(fieldName, eventEntityName, expectedFields, schema)
|
|
|
189
190
|
const expectedRequired = expectedField.isRequired ? `required` : "optional";
|
|
190
191
|
throw new Error(`"${eventEntityName}.${fieldName}" must be ${expectedRequired}`);
|
|
191
192
|
}
|
|
192
|
-
}
|
|
193
|
-
async function beforePut(items, ctx, computedContext) {
|
|
194
|
-
for (const f of computedContext.options.features) {
|
|
195
|
-
await f.beforePut?.(items, ctx, computedContext);
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
async function afterPut(items, ctx, computedContext) {
|
|
199
|
-
for (const f of computedContext.options.features) {
|
|
200
|
-
await f.afterPut?.(items, ctx, computedContext);
|
|
201
|
-
}
|
|
202
193
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import _ from "lodash";
|
|
2
|
-
import { cleanEntity, diff, handlePrecomputed, merge } from "rads-db";
|
|
2
|
+
import { afterPut, beforePut, cleanEntity, diff, handlePrecomputed, merge } from "rads-db";
|
|
3
3
|
export default (options) => {
|
|
4
4
|
return {
|
|
5
5
|
name: "eventSourcing",
|
|
@@ -97,6 +97,7 @@ function getEffectFor(entityName, aggregateRelationField, eventEntityName, schem
|
|
|
97
97
|
updatedEvents: v.updatedEvents,
|
|
98
98
|
oldDoc: v.oldAggDoc
|
|
99
99
|
}));
|
|
100
|
+
console.log(ctx);
|
|
100
101
|
const aggregateEffectContext = { ...context, typeName: entityName, handle: schema[entityName].handle };
|
|
101
102
|
await beforePut(hookItems, ctx, aggregateEffectContext);
|
|
102
103
|
await context.drivers[entityName].putMany(aggs, ctx);
|
|
@@ -157,13 +158,3 @@ function validateSchemaField(fieldName, eventEntityName, expectedFields, schema)
|
|
|
157
158
|
throw new Error(`"${eventEntityName}.${fieldName}" must be ${expectedRequired}`);
|
|
158
159
|
}
|
|
159
160
|
}
|
|
160
|
-
async function beforePut(items, ctx, computedContext) {
|
|
161
|
-
for (const f of computedContext.options.features) {
|
|
162
|
-
await f.beforePut?.(items, ctx, computedContext);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
async function afterPut(items, ctx, computedContext) {
|
|
166
|
-
for (const f of computedContext.options.features) {
|
|
167
|
-
await f.afterPut?.(items, ctx, computedContext);
|
|
168
|
-
}
|
|
169
|
-
}
|