rads-db 3.1.4 → 3.1.6
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
|
@@ -352,7 +352,9 @@ const computedPresets = {
|
|
|
352
352
|
throw new Error('To use "createdBy" preset, please, provide "context.getUser" to "createRads" call.');
|
|
353
353
|
return ___default.pick(ctx.getUser(), "id");
|
|
354
354
|
},
|
|
355
|
-
updatedBy: ({ doc, ctx }) => {
|
|
355
|
+
updatedBy: ({ doc, oldDoc, fieldName, ctx }) => {
|
|
356
|
+
if (ctx.isVerifying && oldDoc?.updatedBy)
|
|
357
|
+
return oldDoc.updatedBy;
|
|
356
358
|
if (!ctx.getUser)
|
|
357
359
|
throw new Error('To use "updatedBy" preset, please, provide "context.getUser" to "createRads" call.');
|
|
358
360
|
return ___default.pick(ctx.getUser(), "id");
|
|
@@ -385,8 +387,8 @@ async function handlePrecomputed(context, docs, ctx) {
|
|
|
385
387
|
if (!handler)
|
|
386
388
|
throw new Error(`Computed handler for ${typeName}.${fieldName} was not found`);
|
|
387
389
|
}
|
|
388
|
-
const precomputedResults = docs.map(async ({ doc, oldDoc, events }) => {
|
|
389
|
-
doc[fieldName] = await handler({ fieldName, doc, oldDoc, events, db, ctx });
|
|
390
|
+
const precomputedResults = docs.map(async ({ doc, oldDoc, events, updatedEvents }) => {
|
|
391
|
+
doc[fieldName] = await handler({ fieldName, doc, oldDoc, events, updatedEvents, db, ctx });
|
|
390
392
|
});
|
|
391
393
|
await Promise.all(precomputedResults);
|
|
392
394
|
}
|
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 { N as Change, x as ComputedContextGlobal, k as CreateRadsArgsDrivers, m as CreateRadsDbArgsNormalized, aj as DeepKeys, ae as DeepPartial, ac as DeepPartialWithNulls, ad as DeepPartialWithNullsItem, ak as EntityMethods, w as EnumDefinition, v as FieldDefinition, I as FileSystemNode, u as FileUploadArgs, q as FileUploadDriver, p as FileUploadResult, B as GenerateClientNormalizedOptions, A as GenerateClientOptions, a8 as Get, _ as GetAggArgs, $ as GetAggArgsAgg, a2 as GetAggArgsAny, a5 as GetAggResponse, Z as GetArgs, a1 as GetArgsAny, a4 as GetArgsInclude, O as GetManyArgs, a0 as GetManyArgsAny, a6 as GetManyResponse, a7 as GetResponse, a9 as GetResponseInclude, aa as GetResponseIncludeSelect, ab as GetResponseNoInclude, s as GetRestRoutesArgs, G as GetRestRoutesOptions, t as GetRestRoutesResponse, ag as InverseRelation, M as MinimalDriver, ai as Put, ah as PutArgs, P as PutEffect, g as RadsConfig, h as RadsConfigDataSource, r as RadsDbInstance, L as RadsFeature, y as RadsHookDoc, K as RadsUiSlotDefinition, J as RadsUiSlotName, H as RadsVitePluginOptions, af as Relation, i as RequiredFields, l as RestDriverOptions, z as RestFileUploadDriverOptions, n as SchemaLoadResult, o as SchemaValidators, T as TypeDefinition, j as ValidateStringDecoratorArgs, Q as VerifyManyArgs, a3 as VerifyManyArgsAny, X as VerifyManyResponse, Y 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-1bda441b.js';
|
|
2
|
+
export { N as Change, x as ComputedContextGlobal, k as CreateRadsArgsDrivers, m as CreateRadsDbArgsNormalized, aj as DeepKeys, ae as DeepPartial, ac as DeepPartialWithNulls, ad as DeepPartialWithNullsItem, ak as EntityMethods, w as EnumDefinition, v as FieldDefinition, I as FileSystemNode, u as FileUploadArgs, q as FileUploadDriver, p as FileUploadResult, B as GenerateClientNormalizedOptions, A as GenerateClientOptions, a8 as Get, _ as GetAggArgs, $ as GetAggArgsAgg, a2 as GetAggArgsAny, a5 as GetAggResponse, Z as GetArgs, a1 as GetArgsAny, a4 as GetArgsInclude, O as GetManyArgs, a0 as GetManyArgsAny, a6 as GetManyResponse, a7 as GetResponse, a9 as GetResponseInclude, aa as GetResponseIncludeSelect, ab as GetResponseNoInclude, s as GetRestRoutesArgs, G as GetRestRoutesOptions, t as GetRestRoutesResponse, ag as InverseRelation, M as MinimalDriver, ai as Put, ah as PutArgs, P as PutEffect, g as RadsConfig, h as RadsConfigDataSource, r as RadsDbInstance, L as RadsFeature, y as RadsHookDoc, K as RadsUiSlotDefinition, J as RadsUiSlotName, H as RadsVitePluginOptions, af as Relation, i as RequiredFields, l as RestDriverOptions, z as RestFileUploadDriverOptions, n as SchemaLoadResult, o as SchemaValidators, T as TypeDefinition, j as ValidateStringDecoratorArgs, Q as VerifyManyArgs, a3 as VerifyManyArgsAny, X as VerifyManyResponse, Y as Where, W as WhereJsonContains } from './types-1bda441b.js';
|
|
3
3
|
import { RadsDb } from '_rads-db';
|
|
4
4
|
export { RadsDb } from '_rads-db';
|
|
5
5
|
|
package/dist/index.mjs
CHANGED
|
@@ -345,7 +345,9 @@ const computedPresets = {
|
|
|
345
345
|
throw new Error('To use "createdBy" preset, please, provide "context.getUser" to "createRads" call.');
|
|
346
346
|
return _.pick(ctx.getUser(), "id");
|
|
347
347
|
},
|
|
348
|
-
updatedBy: ({ doc, ctx }) => {
|
|
348
|
+
updatedBy: ({ doc, oldDoc, fieldName, ctx }) => {
|
|
349
|
+
if (ctx.isVerifying && oldDoc?.updatedBy)
|
|
350
|
+
return oldDoc.updatedBy;
|
|
349
351
|
if (!ctx.getUser)
|
|
350
352
|
throw new Error('To use "updatedBy" preset, please, provide "context.getUser" to "createRads" call.');
|
|
351
353
|
return _.pick(ctx.getUser(), "id");
|
|
@@ -378,8 +380,8 @@ async function handlePrecomputed(context, docs, ctx) {
|
|
|
378
380
|
if (!handler)
|
|
379
381
|
throw new Error(`Computed handler for ${typeName}.${fieldName} was not found`);
|
|
380
382
|
}
|
|
381
|
-
const precomputedResults = docs.map(async ({ doc, oldDoc, events }) => {
|
|
382
|
-
doc[fieldName] = await handler({ fieldName, doc, oldDoc, events, db, ctx });
|
|
383
|
+
const precomputedResults = docs.map(async ({ doc, oldDoc, events, updatedEvents }) => {
|
|
384
|
+
doc[fieldName] = await handler({ fieldName, doc, oldDoc, events, updatedEvents, db, ctx });
|
|
383
385
|
});
|
|
384
386
|
await Promise.all(precomputedResults);
|
|
385
387
|
}
|
|
@@ -355,7 +355,8 @@ interface RadsHookDoc {
|
|
|
355
355
|
/** Previous version of document - i.e. one that is currently in the database (before saving) */
|
|
356
356
|
oldDoc: any;
|
|
357
357
|
/** If current entity is event sourcing aggregate, you can access all events in the chronological order */
|
|
358
|
-
events?: any;
|
|
358
|
+
events?: any[];
|
|
359
|
+
updatedEvents?: any[];
|
|
359
360
|
}
|
|
360
361
|
interface PutEffect {
|
|
361
362
|
beforePut?: (computedContext: ComputedContext, docs: RadsHookDoc[], ctx: RadsRequestContext) => MaybePromise<any>;
|
|
@@ -82,6 +82,7 @@ function getEffectFor(entityName, aggregateRelationField, eventEntityName, schem
|
|
|
82
82
|
result.push({
|
|
83
83
|
aggDoc,
|
|
84
84
|
events,
|
|
85
|
+
updatedEvents: events.filter(ev => docsById[ev.id]),
|
|
85
86
|
oldAggDoc: existingAggregatesById[aggDoc.id]
|
|
86
87
|
});
|
|
87
88
|
}
|
|
@@ -93,6 +94,7 @@ function getEffectFor(entityName, aggregateRelationField, eventEntityName, schem
|
|
|
93
94
|
}, result.map(v => ({
|
|
94
95
|
doc: v.aggDoc,
|
|
95
96
|
events: v.events,
|
|
97
|
+
updatedEvents: v.updatedEvents,
|
|
96
98
|
oldDoc: v.oldAggDoc
|
|
97
99
|
})), ctx);
|
|
98
100
|
return result;
|
|
@@ -102,6 +104,7 @@ function getEffectFor(entityName, aggregateRelationField, eventEntityName, schem
|
|
|
102
104
|
const hookItems = beforePutResult.map(v => ({
|
|
103
105
|
doc: v.aggDoc,
|
|
104
106
|
events: v.events,
|
|
107
|
+
updatedEvents: v.updatedEvents,
|
|
105
108
|
oldDoc: v.oldAggDoc
|
|
106
109
|
}));
|
|
107
110
|
const aggregateEffectContext = {
|
|
@@ -74,19 +74,29 @@ function getEffectFor(entityName, aggregateRelationField, eventEntityName, schem
|
|
|
74
74
|
if (!context.options.keepNulls)
|
|
75
75
|
cleanUndefinedAndNull(aggDoc);
|
|
76
76
|
}
|
|
77
|
-
result.push({
|
|
77
|
+
result.push({
|
|
78
|
+
aggDoc,
|
|
79
|
+
events,
|
|
80
|
+
updatedEvents: events.filter((ev) => docsById[ev.id]),
|
|
81
|
+
oldAggDoc: existingAggregatesById[aggDoc.id]
|
|
82
|
+
});
|
|
78
83
|
}
|
|
79
84
|
await handlePrecomputed(
|
|
80
85
|
// @ts-expect-error TODO wrong types
|
|
81
86
|
{ ...context, typeName: entityName },
|
|
82
|
-
result.map((v) => ({ doc: v.aggDoc, events: v.events, oldDoc: v.oldAggDoc })),
|
|
87
|
+
result.map((v) => ({ doc: v.aggDoc, events: v.events, updatedEvents: v.updatedEvents, oldDoc: v.oldAggDoc })),
|
|
83
88
|
ctx
|
|
84
89
|
);
|
|
85
90
|
return result;
|
|
86
91
|
},
|
|
87
92
|
async afterPut(context, docs, beforePutResult, ctx) {
|
|
88
93
|
const aggs = beforePutResult.map((d) => d.aggDoc);
|
|
89
|
-
const hookItems = beforePutResult.map((v) => ({
|
|
94
|
+
const hookItems = beforePutResult.map((v) => ({
|
|
95
|
+
doc: v.aggDoc,
|
|
96
|
+
events: v.events,
|
|
97
|
+
updatedEvents: v.updatedEvents,
|
|
98
|
+
oldDoc: v.oldAggDoc
|
|
99
|
+
}));
|
|
90
100
|
const aggregateEffectContext = { ...context, typeName: entityName, handle: schema[entityName].handle };
|
|
91
101
|
await beforePut(hookItems, ctx, aggregateEffectContext);
|
|
92
102
|
await context.drivers[entityName].putMany(aggs, ctx);
|