rads-db 3.0.30 → 3.0.32
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 +5 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.mjs +5 -1
- package/features/eventSourcing.cjs +10 -0
- package/features/eventSourcing.mjs +10 -0
- package/integrations/lib.cjs +2 -0
- package/integrations/lib.mjs +3 -0
- package/integrations/node.cjs +16 -3
- package/integrations/node.d.ts +1 -0
- package/integrations/node.mjs +16 -3
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1137,6 +1137,10 @@ function computed(meta) {
|
|
|
1137
1137
|
return function(a, b) {
|
|
1138
1138
|
};
|
|
1139
1139
|
}
|
|
1140
|
+
function keepHistory() {
|
|
1141
|
+
return function(a, b) {
|
|
1142
|
+
};
|
|
1143
|
+
}
|
|
1140
1144
|
|
|
1141
1145
|
function createRadsDb(args) {
|
|
1142
1146
|
args = { ...args };
|
|
@@ -1166,6 +1170,7 @@ exports.entity = entity;
|
|
|
1166
1170
|
exports.field = field;
|
|
1167
1171
|
exports.getDriverInstance = getDriverInstance;
|
|
1168
1172
|
exports.handlePrecomputed = handlePrecomputed;
|
|
1173
|
+
exports.keepHistory = keepHistory;
|
|
1169
1174
|
exports.merge = merge;
|
|
1170
1175
|
exports.precomputed = precomputed;
|
|
1171
1176
|
exports.ui = ui;
|
package/dist/index.d.ts
CHANGED
|
@@ -209,6 +209,7 @@ interface TypeDefinition {
|
|
|
209
209
|
handle?: string;
|
|
210
210
|
handlePlural?: string;
|
|
211
211
|
isExtending?: string;
|
|
212
|
+
keepHistoryFields: string[];
|
|
212
213
|
}
|
|
213
214
|
interface FileUploadResult {
|
|
214
215
|
url: string;
|
|
@@ -388,6 +389,7 @@ declare function validate<T, C, F>(args: T extends new () => any ? ValidateEntit
|
|
|
388
389
|
declare function field(meta?: FieldDecoratorArgs): (a: any, b?: ClassFieldDecoratorContext) => void;
|
|
389
390
|
declare function precomputed(meta?: ComputedDecoratorArgs): (a: any, b?: ClassFieldDecoratorContext | ClassDecoratorContext) => void;
|
|
390
391
|
declare function computed(meta?: ComputedDecoratorArgs): (a: any, b?: ClassFieldDecoratorContext | ClassDecoratorContext) => void;
|
|
392
|
+
declare function keepHistory(): (a: any, b?: ClassFieldDecoratorContext) => void;
|
|
391
393
|
|
|
392
394
|
declare function getDriverInstance(schema: Schema, key: string, driverConstructor: DriverConstructor, driverInstances: Record<string, Driver>): Driver;
|
|
393
395
|
|
|
@@ -412,4 +414,4 @@ declare function createRadsDb(args?: CreateRadsDbArgs): RadsDb;
|
|
|
412
414
|
*/
|
|
413
415
|
declare function createRadsDbClient(args?: CreateRadsDbClientArgs): RadsDb;
|
|
414
416
|
|
|
415
|
-
export { Change, ComputedContext, ComputedContextGlobal, ComputedDecoratorArgs, CreateRadsArgsDrivers, CreateRadsDbArgs, CreateRadsDbArgsNormalized, CreateRadsDbClientArgs, DeepPartial, Driver, DriverConstructor, EntityDecoratorArgs, EntityMethods, EnumDefinition, FieldDecoratorArgs, FieldDefinition, FileSystemNode, FileUploadArgs, FileUploadDriver, FileUploadResult, GenerateClientNormalizedOptions, GenerateClientOptions, GetAggArgs, GetAggArgsAgg, GetAggArgsAny, GetAggResponse, GetArgs, GetArgsAny, GetArgsInclude, GetManyArgs, GetManyArgsAny, GetManyResponse, GetResponse, GetResponseInclude, GetResponseIncludeSelect, GetResponseNoInclude, GetRestRoutesArgs, GetRestRoutesOptions, GetRestRoutesResponse, MinimalDriver, PutArgs, PutEffect, RadsFeature, RadsRequestContext, RadsUiSlotDefinition, RadsUiSlotName, RadsVitePluginOptions, Relation, RequiredFields, RestDriverOptions, RestFileUploadDriverOptions, Schema, SchemaValidators, TypeDefinition, UiDecoratorArgs, UiFieldDecoratorArgs, ValidateEntityDecoratorArgs, ValidateFieldDecoratorArgs, ValidateStringDecoratorArgs, VerifyManyArgs, VerifyManyArgsAny, VerifyManyResponse, cleanUndefinedAndNull, computed, createRadsDb, createRadsDbClient, diff, entity, field, getDriverInstance, handlePrecomputed, merge, precomputed, ui, validate };
|
|
417
|
+
export { Change, ComputedContext, ComputedContextGlobal, ComputedDecoratorArgs, CreateRadsArgsDrivers, CreateRadsDbArgs, CreateRadsDbArgsNormalized, CreateRadsDbClientArgs, DeepPartial, Driver, DriverConstructor, EntityDecoratorArgs, EntityMethods, EnumDefinition, FieldDecoratorArgs, FieldDefinition, FileSystemNode, FileUploadArgs, FileUploadDriver, FileUploadResult, GenerateClientNormalizedOptions, GenerateClientOptions, GetAggArgs, GetAggArgsAgg, GetAggArgsAny, GetAggResponse, GetArgs, GetArgsAny, GetArgsInclude, GetManyArgs, GetManyArgsAny, GetManyResponse, GetResponse, GetResponseInclude, GetResponseIncludeSelect, GetResponseNoInclude, GetRestRoutesArgs, GetRestRoutesOptions, GetRestRoutesResponse, MinimalDriver, PutArgs, PutEffect, RadsFeature, RadsRequestContext, RadsUiSlotDefinition, RadsUiSlotName, RadsVitePluginOptions, Relation, RequiredFields, RestDriverOptions, RestFileUploadDriverOptions, Schema, SchemaValidators, TypeDefinition, UiDecoratorArgs, UiFieldDecoratorArgs, ValidateEntityDecoratorArgs, ValidateFieldDecoratorArgs, ValidateStringDecoratorArgs, VerifyManyArgs, VerifyManyArgsAny, VerifyManyResponse, cleanUndefinedAndNull, computed, createRadsDb, createRadsDbClient, diff, entity, field, getDriverInstance, handlePrecomputed, keepHistory, merge, precomputed, ui, validate };
|
package/dist/index.mjs
CHANGED
|
@@ -1129,6 +1129,10 @@ function computed(meta) {
|
|
|
1129
1129
|
return function(a, b) {
|
|
1130
1130
|
};
|
|
1131
1131
|
}
|
|
1132
|
+
function keepHistory() {
|
|
1133
|
+
return function(a, b) {
|
|
1134
|
+
};
|
|
1135
|
+
}
|
|
1132
1136
|
|
|
1133
1137
|
function createRadsDb(args) {
|
|
1134
1138
|
args = { ...args };
|
|
@@ -1149,4 +1153,4 @@ function createRadsDbClient(args) {
|
|
|
1149
1153
|
return generateMethods(s, validators, radsDbArgs);
|
|
1150
1154
|
}
|
|
1151
1155
|
|
|
1152
|
-
export { cleanUndefinedAndNull, computed, createRadsDb, createRadsDbClient, diff, entity, field, getDriverInstance, handlePrecomputed, merge, precomputed, ui, validate };
|
|
1156
|
+
export { cleanUndefinedAndNull, computed, createRadsDb, createRadsDbClient, diff, entity, field, getDriverInstance, handlePrecomputed, keepHistory, merge, precomputed, ui, validate };
|
|
@@ -69,6 +69,7 @@ function verifyEventSourcingSetup(schema, effects) {
|
|
|
69
69
|
}, ev.change));
|
|
70
70
|
ev.beforeChange = aggDoc;
|
|
71
71
|
ev.change = (0, _radsDb.diff)(newAggDoc, aggDoc);
|
|
72
|
+
keepHistory(schema[entityName].keepHistoryFields, newAggDoc, ev);
|
|
72
73
|
aggDoc = newAggDoc;
|
|
73
74
|
if (!context.options.keepNulls) (0, _radsDb.cleanUndefinedAndNull)(aggDoc);
|
|
74
75
|
}
|
|
@@ -96,6 +97,15 @@ function verifyEventSourcingSetup(schema, effects) {
|
|
|
96
97
|
});
|
|
97
98
|
}
|
|
98
99
|
}
|
|
100
|
+
function keepHistory(keepHistoryFields, newAggDoc, eventChange) {
|
|
101
|
+
if (keepHistoryFields && newAggDoc) {
|
|
102
|
+
keepHistoryFields.forEach(prop => {
|
|
103
|
+
if (!eventChange.change[prop]) {
|
|
104
|
+
eventChange.change[prop] = newAggDoc[prop];
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}
|
|
99
109
|
function validateEventSourcingSetup(schema, entityName, eventEntityName, aggregateRelationField) {
|
|
100
110
|
const eventEntity = schema[eventEntityName];
|
|
101
111
|
if (!eventEntity) throw new Error(`You must create entity with name "${eventEntityName}" to use eventSourcing feature with "${entityName}"`);
|
|
@@ -63,6 +63,7 @@ function verifyEventSourcingSetup(schema, effects) {
|
|
|
63
63
|
const newAggDoc = context.validators[entityName](merge(aggDoc || { id: aggId }, ev.change));
|
|
64
64
|
ev.beforeChange = aggDoc;
|
|
65
65
|
ev.change = diff(newAggDoc, aggDoc);
|
|
66
|
+
keepHistory(schema[entityName].keepHistoryFields, newAggDoc, ev);
|
|
66
67
|
aggDoc = newAggDoc;
|
|
67
68
|
if (!context.options.keepNulls)
|
|
68
69
|
cleanUndefinedAndNull(aggDoc);
|
|
@@ -84,6 +85,15 @@ function verifyEventSourcingSetup(schema, effects) {
|
|
|
84
85
|
});
|
|
85
86
|
}
|
|
86
87
|
}
|
|
88
|
+
function keepHistory(keepHistoryFields, newAggDoc, eventChange) {
|
|
89
|
+
if (keepHistoryFields && newAggDoc) {
|
|
90
|
+
keepHistoryFields.forEach((prop) => {
|
|
91
|
+
if (!eventChange.change[prop]) {
|
|
92
|
+
eventChange.change[prop] = newAggDoc[prop];
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}
|
|
87
97
|
function validateEventSourcingSetup(schema, entityName, eventEntityName, aggregateRelationField) {
|
|
88
98
|
const eventEntity = schema[eventEntityName];
|
|
89
99
|
if (!eventEntity)
|
package/integrations/lib.cjs
CHANGED
|
@@ -138,9 +138,11 @@ function fillComputedDefinitionsForType(result) {
|
|
|
138
138
|
const precomputedFields = _lodash.default.values(fields).filter(f => !!f.decorators?.precomputed).sort((f1, f2) => getOrder(f1) - getOrder(f2)).map(f => f.name);
|
|
139
139
|
const computedFields = _lodash.default.values(fields).filter(f => !!f.decorators?.computed).sort((f1, f2) => getOrder(f1) - getOrder(f2)).map(f => f.name);
|
|
140
140
|
const nestedTypeFields = _lodash.default.values(fields).filter(f => result[f.type] && result[f.type].fields && !result[f.type].decorators.entity).map(f => f.name);
|
|
141
|
+
const keepHistoryFields = _lodash.default.values(fields).filter(f => !!f.decorators?.keepHistory).map(f => f.name);
|
|
141
142
|
if (precomputedFields.length) type.precomputedFields = precomputedFields;
|
|
142
143
|
if (computedFields.length) type.computedFields = computedFields;
|
|
143
144
|
if (nestedTypeFields.length) type.nestedTypeFields = nestedTypeFields;
|
|
145
|
+
if (keepHistoryFields.length) type.keepHistoryFields = keepHistoryFields;
|
|
144
146
|
}
|
|
145
147
|
}
|
|
146
148
|
function getOrder(f) {
|
package/integrations/lib.mjs
CHANGED
|
@@ -112,12 +112,15 @@ function fillComputedDefinitionsForType(result) {
|
|
|
112
112
|
const precomputedFields = _.values(fields).filter((f) => !!f.decorators?.precomputed).sort((f1, f2) => getOrder(f1) - getOrder(f2)).map((f) => f.name);
|
|
113
113
|
const computedFields = _.values(fields).filter((f) => !!f.decorators?.computed).sort((f1, f2) => getOrder(f1) - getOrder(f2)).map((f) => f.name);
|
|
114
114
|
const nestedTypeFields = _.values(fields).filter((f) => result[f.type] && result[f.type].fields && !result[f.type].decorators.entity).map((f) => f.name);
|
|
115
|
+
const keepHistoryFields = _.values(fields).filter((f) => !!f.decorators?.keepHistory).map((f) => f.name);
|
|
115
116
|
if (precomputedFields.length)
|
|
116
117
|
type.precomputedFields = precomputedFields;
|
|
117
118
|
if (computedFields.length)
|
|
118
119
|
type.computedFields = computedFields;
|
|
119
120
|
if (nestedTypeFields.length)
|
|
120
121
|
type.nestedTypeFields = nestedTypeFields;
|
|
122
|
+
if (keepHistoryFields.length)
|
|
123
|
+
type.keepHistoryFields = keepHistoryFields;
|
|
121
124
|
}
|
|
122
125
|
}
|
|
123
126
|
function getOrder(f) {
|
package/integrations/node.cjs
CHANGED
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.generateClient = generateClient;
|
|
7
|
+
exports.getEntityTypesStrFromSchema = getEntityTypesStrFromSchema;
|
|
7
8
|
exports.getIndexDts = getIndexDts;
|
|
8
9
|
exports.getSchema = getSchema;
|
|
9
10
|
var _promises = _interopRequireDefault(require("node:fs/promises"));
|
|
@@ -31,9 +32,10 @@ exports.schema=${JSON.stringify(schema)}
|
|
|
31
32
|
const indexMjsText = `
|
|
32
33
|
export const schema = ${JSON.stringify(schema)}
|
|
33
34
|
`.trim();
|
|
35
|
+
const indexDtsText = getIndexDts(schema, normalizedOptions);
|
|
34
36
|
await _promises.default.writeFile(_nodePath.default.join(radsDbPath, "./index.js"), indexJsText);
|
|
35
37
|
await _promises.default.writeFile(_nodePath.default.join(radsDbPath, "./index.mjs"), indexMjsText);
|
|
36
|
-
await _promises.default.writeFile(_nodePath.default.join(radsDbPath, "./index.d.ts"),
|
|
38
|
+
await _promises.default.writeFile(_nodePath.default.join(radsDbPath, "./index.d.ts"), indexDtsText);
|
|
37
39
|
await _promises.default.writeFile(_nodePath.default.join(radsDbPath, "./package.json"), JSON.stringify({
|
|
38
40
|
name: "_rads-db",
|
|
39
41
|
main: "./index.js",
|
|
@@ -95,10 +97,13 @@ function getIndexDts(schema, options) {
|
|
|
95
97
|
const rootFields = [];
|
|
96
98
|
const whereTypes = [];
|
|
97
99
|
const entityMeta = [];
|
|
100
|
+
const schemaTypesStr = options.entitiesDir ? "" : getEntityTypesStrFromSchema(schema);
|
|
98
101
|
for (const key in schema) {
|
|
99
102
|
const type = schema[key];
|
|
100
|
-
if (!type.
|
|
101
|
-
|
|
103
|
+
if (!type.decorators.entity) continue;
|
|
104
|
+
if (options.entitiesDir) {
|
|
105
|
+
imports.push(`import type { ${type.name} } from '../../${options.entitiesDir}/${key}'`);
|
|
106
|
+
}
|
|
102
107
|
rootFields.push(`${type.handle}: EntityMethods<${type.name}, '${type.name}', ${type.name}_Where>`);
|
|
103
108
|
const fieldsArray = Object.values(type.fields);
|
|
104
109
|
const relations = _lodash.default.fromPairs(fieldsArray.filter(f => f.isRelation).map(f => [f.name, {
|
|
@@ -111,6 +116,10 @@ function getIndexDts(schema, options) {
|
|
|
111
116
|
aggregates: fieldsArray.filter(f => f.type === "number" && !f.isArray).map(x => `'${x.name}'`).join(" | "),
|
|
112
117
|
primitives: fieldsArray.filter(f => !schema[f.type]?.decorators?.entity).map(x => `'${x.name}'`).join(" | ")
|
|
113
118
|
});
|
|
119
|
+
}
|
|
120
|
+
for (const key in schema) {
|
|
121
|
+
const type = schema[key];
|
|
122
|
+
if (!type.fields) continue;
|
|
114
123
|
const whereFields = getWhereFields(schema, type);
|
|
115
124
|
whereTypes.push(`
|
|
116
125
|
export interface ${type.name}_Where {
|
|
@@ -128,6 +137,7 @@ ${whereFields.join("\n")}
|
|
|
128
137
|
return `
|
|
129
138
|
import type { EntityMethods, FileUploadArgs, RadsRequestContext } from 'rads-db'
|
|
130
139
|
${imports.join("\n")}
|
|
140
|
+
${schemaTypesStr}
|
|
131
141
|
|
|
132
142
|
export interface EntityMeta {
|
|
133
143
|
${entityMetaStr}
|
|
@@ -147,6 +157,9 @@ export interface RadsDb {
|
|
|
147
157
|
}
|
|
148
158
|
`.trim();
|
|
149
159
|
}
|
|
160
|
+
function getEntityTypesStrFromSchema(schema) {
|
|
161
|
+
return "";
|
|
162
|
+
}
|
|
150
163
|
function getWhereFields(schema, type) {
|
|
151
164
|
const result = [];
|
|
152
165
|
for (const f in type.fields) {
|
package/integrations/node.d.ts
CHANGED
|
@@ -2,3 +2,4 @@ import type { GenerateClientNormalizedOptions, GenerateClientOptions, Schema } f
|
|
|
2
2
|
export declare function generateClient(options?: GenerateClientOptions): Promise<void>;
|
|
3
3
|
export declare function getSchema(normalizedOptions: GenerateClientNormalizedOptions): Promise<any>;
|
|
4
4
|
export declare function getIndexDts(schema: Schema, options: GenerateClientNormalizedOptions): string;
|
|
5
|
+
export declare function getEntityTypesStrFromSchema(schema: Schema): string;
|
package/integrations/node.mjs
CHANGED
|
@@ -24,9 +24,10 @@ exports.schema=${JSON.stringify(schema)}
|
|
|
24
24
|
const indexMjsText = `
|
|
25
25
|
export const schema = ${JSON.stringify(schema)}
|
|
26
26
|
`.trim();
|
|
27
|
+
const indexDtsText = getIndexDts(schema, normalizedOptions);
|
|
27
28
|
await fs.writeFile(path.join(radsDbPath, "./index.js"), indexJsText);
|
|
28
29
|
await fs.writeFile(path.join(radsDbPath, "./index.mjs"), indexMjsText);
|
|
29
|
-
await fs.writeFile(path.join(radsDbPath, "./index.d.ts"),
|
|
30
|
+
await fs.writeFile(path.join(radsDbPath, "./index.d.ts"), indexDtsText);
|
|
30
31
|
await fs.writeFile(
|
|
31
32
|
path.join(radsDbPath, "./package.json"),
|
|
32
33
|
JSON.stringify(
|
|
@@ -88,11 +89,14 @@ export function getIndexDts(schema, options) {
|
|
|
88
89
|
const rootFields = [];
|
|
89
90
|
const whereTypes = [];
|
|
90
91
|
const entityMeta = [];
|
|
92
|
+
const schemaTypesStr = options.entitiesDir ? "" : getEntityTypesStrFromSchema(schema);
|
|
91
93
|
for (const key in schema) {
|
|
92
94
|
const type = schema[key];
|
|
93
|
-
if (!type.
|
|
95
|
+
if (!type.decorators.entity)
|
|
94
96
|
continue;
|
|
95
|
-
|
|
97
|
+
if (options.entitiesDir) {
|
|
98
|
+
imports.push(`import type { ${type.name} } from '../../${options.entitiesDir}/${key}'`);
|
|
99
|
+
}
|
|
96
100
|
rootFields.push(`${type.handle}: EntityMethods<${type.name}, '${type.name}', ${type.name}_Where>`);
|
|
97
101
|
const fieldsArray = Object.values(type.fields);
|
|
98
102
|
const relations = _.fromPairs(
|
|
@@ -109,6 +113,11 @@ export function getIndexDts(schema, options) {
|
|
|
109
113
|
aggregates: fieldsArray.filter((f) => f.type === "number" && !f.isArray).map((x) => `'${x.name}'`).join(" | "),
|
|
110
114
|
primitives: fieldsArray.filter((f) => !schema[f.type]?.decorators?.entity).map((x) => `'${x.name}'`).join(" | ")
|
|
111
115
|
});
|
|
116
|
+
}
|
|
117
|
+
for (const key in schema) {
|
|
118
|
+
const type = schema[key];
|
|
119
|
+
if (!type.fields)
|
|
120
|
+
continue;
|
|
112
121
|
const whereFields = getWhereFields(schema, type);
|
|
113
122
|
whereTypes.push(
|
|
114
123
|
`
|
|
@@ -130,6 +139,7 @@ ${whereFields.join("\n")}
|
|
|
130
139
|
return `
|
|
131
140
|
import type { EntityMethods, FileUploadArgs, RadsRequestContext } from 'rads-db'
|
|
132
141
|
${imports.join("\n")}
|
|
142
|
+
${schemaTypesStr}
|
|
133
143
|
|
|
134
144
|
export interface EntityMeta {
|
|
135
145
|
${entityMetaStr}
|
|
@@ -149,6 +159,9 @@ export interface RadsDb {
|
|
|
149
159
|
}
|
|
150
160
|
`.trim();
|
|
151
161
|
}
|
|
162
|
+
export function getEntityTypesStrFromSchema(schema) {
|
|
163
|
+
return "";
|
|
164
|
+
}
|
|
152
165
|
function getWhereFields(schema, type) {
|
|
153
166
|
const result = [];
|
|
154
167
|
for (const f in type.fields) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rads-db",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.32",
|
|
4
4
|
"files": [
|
|
5
5
|
"dist",
|
|
6
6
|
"drivers",
|
|
@@ -105,7 +105,7 @@
|
|
|
105
105
|
"scripts": {
|
|
106
106
|
"test": "vitest --run && vitest typecheck --run",
|
|
107
107
|
"link-rads-db": "symlink-dir ./test/_rads-db ./node_modules/_rads-db",
|
|
108
|
-
"generate-test-schema": "rads-db",
|
|
108
|
+
"generate-test-schema": "rads-db -d './test/entities'",
|
|
109
109
|
"dev": "pnpm install && pnpm link-rads-db && pnpm build && pnpm generate-test-schema && vitest --ui --test-timeout 300000",
|
|
110
110
|
"lint": "cross-env NODE_ENV=production eslint src/**/*.* test/**/*.*",
|
|
111
111
|
"dev-typecheck": "pnpm install && pnpm build && pnpm generate-test-schema && pnpm link-rads-db && vitest typecheck --ui",
|