rads-db 3.2.12 → 3.2.14
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/config.d.ts
CHANGED
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
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { E as EntityDecoratorArgs, U as UiDecoratorArgs, a as UiFieldDecoratorArgs, V as ValidateEntityDecoratorArgs, b as ValidateFieldDecoratorArgs, F as FieldDecoratorArgs, C as ComputedDecoratorArgs, S as Schema, D as DriverConstructor, c as Driver, d as ComputedContext, R as RadsRequestContext, e as CreateRadsDbArgs, f as CreateRadsDbClientArgs } from './types-
|
|
2
|
-
export { O as Change, x as ComputedContextGlobal, k as CreateRadsArgsDrivers, m as CreateRadsDbArgsNormalized, ak as DeepKeys, af as DeepPartial, ad as DeepPartialWithNulls, ae as DeepPartialWithNullsItem, al as EntityMethods, w as EnumDefinition, v as FieldDefinition, J as FileSystemNode, u as FileUploadArgs, q as FileUploadDriver, p as FileUploadResult, H as GenerateClientNormalizedOptions, B as GenerateClientOptions, a9 as Get, $ as GetAggArgs, a0 as GetAggArgsAgg, a3 as GetAggArgsAny, a6 as GetAggResponse, _ as GetArgs, a2 as GetArgsAny, a5 as GetArgsInclude, Q as GetManyArgs, a1 as GetManyArgsAny, a7 as GetManyResponse, a8 as GetResponse, aa as GetResponseInclude, ab as GetResponseIncludeSelect, ac as GetResponseNoInclude, s as GetRestRoutesArgs, G as GetRestRoutesOptions, t as GetRestRoutesResponse, ah as InverseRelation, aj as JsonPutOperations, M as MinimalDriver, ai as Put, P as PutEffect, g as RadsConfig, h as RadsConfigDataSource, r as RadsDbInstance, N as RadsFeature, y as RadsHookDoc, L as RadsUiSlotDefinition, K as RadsUiSlotName, I as RadsVitePluginOptions, ag as Relation, i as RequiredFields, l as RestDriverOptions, A as RestFileUploadDriverOptions, n as SchemaLoadResult, o as SchemaValidators, z as SqlDriverOptions, T as TypeDefinition, j as ValidateStringDecoratorArgs, X as VerifyManyArgs, a4 as VerifyManyArgsAny, Y as VerifyManyResponse, Z as Where, W as WhereJsonContains } from './types-
|
|
1
|
+
import { E as EntityDecoratorArgs, U as UiDecoratorArgs, a as UiFieldDecoratorArgs, V as ValidateEntityDecoratorArgs, b as ValidateFieldDecoratorArgs, F as FieldDecoratorArgs, C as ComputedDecoratorArgs, S as Schema, D as DriverConstructor, c as Driver, d as ComputedContext, R as RadsRequestContext, e as CreateRadsDbArgs, f as CreateRadsDbClientArgs } from './types-a4b98ad2.js';
|
|
2
|
+
export { O as Change, x as ComputedContextGlobal, k as CreateRadsArgsDrivers, m as CreateRadsDbArgsNormalized, ak as DeepKeys, af as DeepPartial, ad as DeepPartialWithNulls, ae as DeepPartialWithNullsItem, al as EntityMethods, w as EnumDefinition, v as FieldDefinition, J as FileSystemNode, u as FileUploadArgs, q as FileUploadDriver, p as FileUploadResult, H as GenerateClientNormalizedOptions, B as GenerateClientOptions, a9 as Get, $ as GetAggArgs, a0 as GetAggArgsAgg, a3 as GetAggArgsAny, a6 as GetAggResponse, _ as GetArgs, a2 as GetArgsAny, a5 as GetArgsInclude, Q as GetManyArgs, a1 as GetManyArgsAny, a7 as GetManyResponse, a8 as GetResponse, aa as GetResponseInclude, ab as GetResponseIncludeSelect, ac as GetResponseNoInclude, s as GetRestRoutesArgs, G as GetRestRoutesOptions, t as GetRestRoutesResponse, ah as InverseRelation, aj as JsonPutOperations, M as MinimalDriver, ai as Put, P as PutEffect, g as RadsConfig, h as RadsConfigDataSource, r as RadsDbInstance, N as RadsFeature, y as RadsHookDoc, L as RadsUiSlotDefinition, K as RadsUiSlotName, I as RadsVitePluginOptions, ag as Relation, i as RequiredFields, l as RestDriverOptions, A as RestFileUploadDriverOptions, n as SchemaLoadResult, o as SchemaValidators, z as SqlDriverOptions, T as TypeDefinition, j as ValidateStringDecoratorArgs, X as VerifyManyArgs, a4 as VerifyManyArgsAny, Y as VerifyManyResponse, Z as Where, W as WhereJsonContains } from './types-a4b98ad2.js';
|
|
3
3
|
import { RadsDb } from '_rads-db';
|
|
4
4
|
export { RadsDb } from '_rads-db';
|
|
5
5
|
import 'mssql';
|
|
@@ -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 };
|
|
@@ -105,7 +105,7 @@ type Put<EN extends keyof EntityMeta> = {
|
|
|
105
105
|
id: string;
|
|
106
106
|
} & JsonPutOperations<EN> & DeepPartialWithNulls<EntityMeta[EN]['type']>;
|
|
107
107
|
type JsonPutOperations<EN extends keyof EntityMeta> = {
|
|
108
|
-
[K in EntityMeta[EN]['jsonFields'] as `${K & string}_replace`]?: EntityMeta[EN]['type'][K]
|
|
108
|
+
[K in EntityMeta[EN]['jsonFields'] as `${K & string}_replace`]?: EntityMeta[EN]['type'][K];
|
|
109
109
|
};
|
|
110
110
|
type DeepKeys<T> = T extends object ? {
|
|
111
111
|
[K in (string | number) & keyof T]: `${`.${K}` | (`${K}` extends `${number}` ? `[${K}]` : never)}${'' | DeepKeys<T[K]>}`;
|
|
@@ -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
|
-
}
|