rads-db 3.0.32 → 3.0.34
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.
|
@@ -68,8 +68,9 @@ function verifyEventSourcingSetup(schema, effects) {
|
|
|
68
68
|
id: aggId
|
|
69
69
|
}, ev.change));
|
|
70
70
|
ev.beforeChange = aggDoc;
|
|
71
|
+
const originalChange = ev.change;
|
|
71
72
|
ev.change = (0, _radsDb.diff)(newAggDoc, aggDoc);
|
|
72
|
-
keepHistory(schema[entityName].keepHistoryFields,
|
|
73
|
+
keepHistory(schema[entityName].keepHistoryFields, originalChange, ev);
|
|
73
74
|
aggDoc = newAggDoc;
|
|
74
75
|
if (!context.options.keepNulls) (0, _radsDb.cleanUndefinedAndNull)(aggDoc);
|
|
75
76
|
}
|
|
@@ -97,11 +98,11 @@ function verifyEventSourcingSetup(schema, effects) {
|
|
|
97
98
|
});
|
|
98
99
|
}
|
|
99
100
|
}
|
|
100
|
-
function keepHistory(keepHistoryFields,
|
|
101
|
-
if (keepHistoryFields &&
|
|
101
|
+
function keepHistory(keepHistoryFields, originalChange, changeEvent) {
|
|
102
|
+
if (keepHistoryFields && originalChange) {
|
|
102
103
|
keepHistoryFields.forEach(prop => {
|
|
103
|
-
if (!
|
|
104
|
-
|
|
104
|
+
if (!changeEvent.change[prop] && originalChange[prop]) {
|
|
105
|
+
changeEvent.change[prop] = originalChange[prop];
|
|
105
106
|
}
|
|
106
107
|
});
|
|
107
108
|
}
|
|
@@ -62,8 +62,9 @@ function verifyEventSourcingSetup(schema, effects) {
|
|
|
62
62
|
for (const ev of events) {
|
|
63
63
|
const newAggDoc = context.validators[entityName](merge(aggDoc || { id: aggId }, ev.change));
|
|
64
64
|
ev.beforeChange = aggDoc;
|
|
65
|
+
const originalChange = ev.change;
|
|
65
66
|
ev.change = diff(newAggDoc, aggDoc);
|
|
66
|
-
keepHistory(schema[entityName].keepHistoryFields,
|
|
67
|
+
keepHistory(schema[entityName].keepHistoryFields, originalChange, ev);
|
|
67
68
|
aggDoc = newAggDoc;
|
|
68
69
|
if (!context.options.keepNulls)
|
|
69
70
|
cleanUndefinedAndNull(aggDoc);
|
|
@@ -85,11 +86,11 @@ function verifyEventSourcingSetup(schema, effects) {
|
|
|
85
86
|
});
|
|
86
87
|
}
|
|
87
88
|
}
|
|
88
|
-
function keepHistory(keepHistoryFields,
|
|
89
|
-
if (keepHistoryFields &&
|
|
89
|
+
function keepHistory(keepHistoryFields, originalChange, changeEvent) {
|
|
90
|
+
if (keepHistoryFields && originalChange) {
|
|
90
91
|
keepHistoryFields.forEach((prop) => {
|
|
91
|
-
if (!
|
|
92
|
-
|
|
92
|
+
if (!changeEvent.change[prop] && originalChange[prop]) {
|
|
93
|
+
changeEvent.change[prop] = originalChange[prop];
|
|
93
94
|
}
|
|
94
95
|
});
|
|
95
96
|
}
|
package/integrations/node.cjs
CHANGED
|
@@ -158,7 +158,32 @@ export interface RadsDb {
|
|
|
158
158
|
`.trim();
|
|
159
159
|
}
|
|
160
160
|
function getEntityTypesStrFromSchema(schema) {
|
|
161
|
-
|
|
161
|
+
const definitions = [];
|
|
162
|
+
for (const key in schema) {
|
|
163
|
+
const type = schema[key];
|
|
164
|
+
if (!type.fields) {
|
|
165
|
+
definitions.push(`export type ${type.name} = ${_lodash.default.keys(type.enumValues).map(x => `'${x}'`).join(" | ")}`);
|
|
166
|
+
} else {
|
|
167
|
+
const fields = Object.values(type.fields);
|
|
168
|
+
const fieldsStr = fields.map(f => {
|
|
169
|
+
if (type.isExtending && schema[type.isExtending]?.fields?.[f.name]) return "";
|
|
170
|
+
let fieldTypeStr = f.type;
|
|
171
|
+
if (f.isChange) fieldTypeStr = `Change<${fieldTypeStr}>`;
|
|
172
|
+
if (f.isRelation) fieldTypeStr = `Relation<${fieldTypeStr}>`;
|
|
173
|
+
if (f.isArray) fieldTypeStr = `${fieldTypeStr}[]`;
|
|
174
|
+
const fieldStr = ` ${f.name}${f.isRequired ? "!" : "?"}: ${fieldTypeStr}`;
|
|
175
|
+
const commentStr2 = f.comment ? ` /** ${f.comment} */` : "";
|
|
176
|
+
return [fieldStr, commentStr2].filter(x => x).join("\n");
|
|
177
|
+
}).filter(x => x).join("\n");
|
|
178
|
+
const commentStr = type.comment ? `/** ${type.comment} */
|
|
179
|
+
` : "";
|
|
180
|
+
definitions.push(`
|
|
181
|
+
${commentStr}export class ${type.name}${type.isExtending ? ` extends ${type.isExtending}` : ""} {
|
|
182
|
+
${fieldsStr}
|
|
183
|
+
}`.trim());
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return definitions.join("\n\n");
|
|
162
187
|
}
|
|
163
188
|
function getWhereFields(schema, type) {
|
|
164
189
|
const result = [];
|
package/integrations/node.mjs
CHANGED
|
@@ -160,7 +160,40 @@ export interface RadsDb {
|
|
|
160
160
|
`.trim();
|
|
161
161
|
}
|
|
162
162
|
export function getEntityTypesStrFromSchema(schema) {
|
|
163
|
-
|
|
163
|
+
const definitions = [];
|
|
164
|
+
for (const key in schema) {
|
|
165
|
+
const type = schema[key];
|
|
166
|
+
if (!type.fields) {
|
|
167
|
+
definitions.push(
|
|
168
|
+
`export type ${type.name} = ${_.keys(type.enumValues).map((x) => `'${x}'`).join(" | ")}`
|
|
169
|
+
);
|
|
170
|
+
} else {
|
|
171
|
+
const fields = Object.values(type.fields);
|
|
172
|
+
const fieldsStr = fields.map((f) => {
|
|
173
|
+
if (type.isExtending && schema[type.isExtending]?.fields?.[f.name])
|
|
174
|
+
return "";
|
|
175
|
+
let fieldTypeStr = f.type;
|
|
176
|
+
if (f.isChange)
|
|
177
|
+
fieldTypeStr = `Change<${fieldTypeStr}>`;
|
|
178
|
+
if (f.isRelation)
|
|
179
|
+
fieldTypeStr = `Relation<${fieldTypeStr}>`;
|
|
180
|
+
if (f.isArray)
|
|
181
|
+
fieldTypeStr = `${fieldTypeStr}[]`;
|
|
182
|
+
const fieldStr = ` ${f.name}${f.isRequired ? "!" : "?"}: ${fieldTypeStr}`;
|
|
183
|
+
const commentStr2 = f.comment ? ` /** ${f.comment} */` : "";
|
|
184
|
+
return [fieldStr, commentStr2].filter((x) => x).join("\n");
|
|
185
|
+
}).filter((x) => x).join("\n");
|
|
186
|
+
const commentStr = type.comment ? `/** ${type.comment} */
|
|
187
|
+
` : "";
|
|
188
|
+
definitions.push(
|
|
189
|
+
`
|
|
190
|
+
${commentStr}export class ${type.name}${type.isExtending ? ` extends ${type.isExtending}` : ""} {
|
|
191
|
+
${fieldsStr}
|
|
192
|
+
}`.trim()
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return definitions.join("\n\n");
|
|
164
197
|
}
|
|
165
198
|
function getWhereFields(schema, type) {
|
|
166
199
|
const result = [];
|