@routier/core 0.7.0 → 0.8.0
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/codegen/blocks.d.ts +17 -1
- package/dist/codegen/handlers/types.d.ts +13 -5
- package/dist/codegen/index.cjs +28 -0
- package/dist/codegen/index.cjs.map +1 -1
- package/dist/codegen/index.js +28 -0
- package/dist/codegen/index.js.map +1 -1
- package/dist/collections/MemoryDataCollection.d.ts +2 -4
- package/dist/collections/index.cjs +127 -15
- package/dist/collections/index.cjs.map +1 -1
- package/dist/collections/index.js +127 -15
- package/dist/collections/index.js.map +1 -1
- package/dist/expressions/index.cjs +226 -4
- package/dist/expressions/index.cjs.map +1 -1
- package/dist/expressions/index.js +228 -5
- package/dist/expressions/index.js.map +1 -1
- package/dist/expressions/parser.d.ts +42 -1
- package/dist/index.cjs +753 -345
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +756 -345
- package/dist/index.js.map +1 -1
- package/dist/plugins/EphemeralDataPlugin.d.ts +8 -0
- package/dist/plugins/index.cjs +566 -49
- package/dist/plugins/index.cjs.map +1 -1
- package/dist/plugins/index.js +566 -48
- package/dist/plugins/index.js.map +1 -1
- package/dist/plugins/query/QueryOptionsCollection.d.ts +15 -5
- package/dist/plugins/query/index.d.ts +1 -0
- package/dist/plugins/query/renames.d.ts +27 -0
- package/dist/plugins/query/types.d.ts +15 -1
- package/dist/plugins/translators/SqlTranslator.d.ts +15 -0
- package/dist/schema/SchemaDefinition.d.ts +8 -0
- package/dist/schema/changeTracker.d.ts +10 -0
- package/dist/schema/index.cjs +291 -274
- package/dist/schema/index.cjs.map +1 -1
- package/dist/schema/index.d.ts +1 -0
- package/dist/schema/index.js +294 -276
- package/dist/schema/index.js.map +1 -1
- package/dist/schema/types.d.ts +8 -7
- package/dist/schema/utils/storageDates.d.ts +25 -0
- package/dist/transfer/index.cjs.map +1 -1
- package/dist/transfer/index.js.map +1 -1
- package/dist/utilities/index.cjs +74 -29
- package/dist/utilities/index.cjs.map +1 -1
- package/dist/utilities/index.js +74 -29
- package/dist/utilities/index.js.map +1 -1
- package/package.json +2 -2
- package/dist/codegen/utils.d.ts +0 -22
package/dist/schema/index.js
CHANGED
|
@@ -344,6 +344,14 @@ class FunctionFactoryBuilder extends ContainerBlock {
|
|
|
344
344
|
this._params.push(...params);
|
|
345
345
|
return this;
|
|
346
346
|
}
|
|
347
|
+
/**
|
|
348
|
+
* Adds a factory parameter carrying `value` and returns its name, for generated code to
|
|
349
|
+
* refer to. See `CodeBuilder.bind` for why values travel this way.
|
|
350
|
+
*/ bind(value) {
|
|
351
|
+
const parameter = this.createParameter(value);
|
|
352
|
+
this._params.push(parameter);
|
|
353
|
+
return parameter.name;
|
|
354
|
+
}
|
|
347
355
|
return() {
|
|
348
356
|
this._return = true;
|
|
349
357
|
return this;
|
|
@@ -459,6 +467,26 @@ class IfBuilder extends ContainerBlock {
|
|
|
459
467
|
}
|
|
460
468
|
}
|
|
461
469
|
class CodeBuilder extends ContainerBlock {
|
|
470
|
+
_bindings = [];
|
|
471
|
+
/**
|
|
472
|
+
* Makes `value` available to the generated function under the returned name.
|
|
473
|
+
*
|
|
474
|
+
* Generated code must never reach a runtime value by its source name or by pasting its
|
|
475
|
+
* source text: a minifier renames the declaration and cannot see inside the generated
|
|
476
|
+
* string, and pasted source loses the scope it closed over (#40, #46). A binding is passed
|
|
477
|
+
* in as a real value when the function is compiled, so it survives any bundler.
|
|
478
|
+
*/ bind(value, name = `binding${this._bindings.length}`) {
|
|
479
|
+
this._bindings.push({
|
|
480
|
+
name,
|
|
481
|
+
value
|
|
482
|
+
});
|
|
483
|
+
return name;
|
|
484
|
+
}
|
|
485
|
+
getBindings() {
|
|
486
|
+
return [
|
|
487
|
+
...this._bindings
|
|
488
|
+
];
|
|
489
|
+
}
|
|
462
490
|
toString() {
|
|
463
491
|
return this._lines.map((line)=>typeof line === 'string' ? this.indent(line) : line.toString()).join('\n\n');
|
|
464
492
|
}
|
|
@@ -541,6 +569,129 @@ var HashType = /*#__PURE__*/ function(HashType) {
|
|
|
541
569
|
}({});
|
|
542
570
|
|
|
543
571
|
|
|
572
|
+
},
|
|
573
|
+
575(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
574
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
575
|
+
L: () => (hasPrimitiveElements),
|
|
576
|
+
l: () => (isArrayValued)
|
|
577
|
+
});
|
|
578
|
+
/* import */ var _types__rspack_import_0 = __webpack_require__(537);
|
|
579
|
+
|
|
580
|
+
/**
|
|
581
|
+
* Types whose runtime value is a JS array.
|
|
582
|
+
*
|
|
583
|
+
* `Array` and `Vector` are the same thing to every layer that copies, compares, hashes or
|
|
584
|
+
* freezes a value — a vector is a list of numbers and nothing more. They differ only where a
|
|
585
|
+
* backend chooses storage, which is the one place that should ask for `SchemaTypes.Vector` by
|
|
586
|
+
* name.
|
|
587
|
+
*
|
|
588
|
+
* This exists so adding a third array-shaped type is one edit rather than a hunt through
|
|
589
|
+
* twelve handlers. Missing one of those is silent in the worst way: a vector that clones by
|
|
590
|
+
* reference is shared with the change tracker's copy, so overwriting an embedding produces no
|
|
591
|
+
* diff and the save reports nothing to do.
|
|
592
|
+
*/ const ARRAY_VALUED_TYPES = new Set([
|
|
593
|
+
_types__rspack_import_0/* .SchemaTypes.Array */.L.Array,
|
|
594
|
+
_types__rspack_import_0/* .SchemaTypes.Vector */.L.Vector
|
|
595
|
+
]);
|
|
596
|
+
/** True when the property's value is a JS array and needs value rather than reference semantics. */ const isArrayValued = (type)=>ARRAY_VALUED_TYPES.has(type);
|
|
597
|
+
/**
|
|
598
|
+
* True when the property's elements are primitives, so a spread is a sufficient copy.
|
|
599
|
+
*
|
|
600
|
+
* A vector is always numbers, so it never needs the per-element deep copy an array of objects
|
|
601
|
+
* or dates does.
|
|
602
|
+
*/ const PRIMITIVE_ELEMENT_TYPES = new Set([
|
|
603
|
+
_types__rspack_import_0/* .SchemaTypes.String */.L.String,
|
|
604
|
+
_types__rspack_import_0/* .SchemaTypes.Number */.L.Number,
|
|
605
|
+
_types__rspack_import_0/* .SchemaTypes.Boolean */.L.Boolean
|
|
606
|
+
]);
|
|
607
|
+
const hasPrimitiveElements = (type, elementType)=>type === _types__rspack_import_0/* .SchemaTypes.Vector */.L.Vector || PRIMITIVE_ELEMENT_TYPES.has(elementType);
|
|
608
|
+
|
|
609
|
+
|
|
610
|
+
},
|
|
611
|
+
894(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
612
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
613
|
+
T: () => (getStorageDateReviver)
|
|
614
|
+
});
|
|
615
|
+
/* import */ var _types__rspack_import_0 = __webpack_require__(537);
|
|
616
|
+
/* import */ var _propertyKind__rspack_import_1 = __webpack_require__(575);
|
|
617
|
+
|
|
618
|
+
|
|
619
|
+
const collectDatePaths = (properties, paths)=>{
|
|
620
|
+
for (const property of properties){
|
|
621
|
+
// The stored value belongs to whoever wrote it: a custom serializer, deserializer or
|
|
622
|
+
// transform reads it back, and would be handed a Date it did not expect. Unmapped
|
|
623
|
+
// properties are never stored.
|
|
624
|
+
if (property.valueSerializer != null || property.valueDeserializer != null || property.transform != null || property.isUnmapped) {
|
|
625
|
+
continue;
|
|
626
|
+
}
|
|
627
|
+
if (property.type === _types__rspack_import_0/* .SchemaTypes.Object */.L.Object) {
|
|
628
|
+
collectDatePaths(property.children, paths);
|
|
629
|
+
continue;
|
|
630
|
+
}
|
|
631
|
+
const isArray = (0,_propertyKind__rspack_import_1/* .isArrayValued */.l)(property.type) && property.innerSchema?.type === _types__rspack_import_0/* .SchemaTypes.Date */.L.Date;
|
|
632
|
+
if (property.type !== _types__rspack_import_0/* .SchemaTypes.Date */.L.Date && isArray === false) {
|
|
633
|
+
continue;
|
|
634
|
+
}
|
|
635
|
+
paths.push({
|
|
636
|
+
segments: [
|
|
637
|
+
...property.getParentPathArray({
|
|
638
|
+
useFromPropertyName: true
|
|
639
|
+
}),
|
|
640
|
+
property.getResolvedName()
|
|
641
|
+
],
|
|
642
|
+
isArray
|
|
643
|
+
});
|
|
644
|
+
}
|
|
645
|
+
};
|
|
646
|
+
const reviveAt = (record, path)=>{
|
|
647
|
+
const { segments } = path;
|
|
648
|
+
let parent = record;
|
|
649
|
+
for(let i = 0, length = segments.length - 1; i < length; i++){
|
|
650
|
+
parent = parent[segments[i]];
|
|
651
|
+
// An absent or null parent holds no date
|
|
652
|
+
if (parent == null || typeof parent !== "object") {
|
|
653
|
+
return;
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
const key = segments[segments.length - 1];
|
|
657
|
+
const value = parent[key];
|
|
658
|
+
if (path.isArray === false) {
|
|
659
|
+
if (typeof value === "string") {
|
|
660
|
+
parent[key] = new Date(value);
|
|
661
|
+
}
|
|
662
|
+
return;
|
|
663
|
+
}
|
|
664
|
+
if (Array.isArray(value)) {
|
|
665
|
+
for(let i = 0, length = value.length; i < length; i++){
|
|
666
|
+
if (typeof value[i] === "string") {
|
|
667
|
+
value[i] = new Date(value[i]);
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
};
|
|
672
|
+
/** Per schema: `null` for a schema with no dates, so a caller can skip the pass. */ const revivers = new WeakMap();
|
|
673
|
+
/**
|
|
674
|
+
* The reviver for `schema`'s records, or `null` when it declares no dates.
|
|
675
|
+
*
|
|
676
|
+
* Built once per compiled schema. A read revives every row it returns, so the paths are resolved
|
|
677
|
+
* here rather than per row.
|
|
678
|
+
*/ const getStorageDateReviver = (schema)=>{
|
|
679
|
+
const cached = revivers.get(schema);
|
|
680
|
+
if (cached !== undefined) {
|
|
681
|
+
return cached;
|
|
682
|
+
}
|
|
683
|
+
const paths = [];
|
|
684
|
+
collectDatePaths(schema.properties, paths);
|
|
685
|
+
const reviver = paths.length === 0 ? null : (record)=>{
|
|
686
|
+
for(let i = 0, length = paths.length; i < length; i++){
|
|
687
|
+
reviveAt(record, paths[i]);
|
|
688
|
+
}
|
|
689
|
+
};
|
|
690
|
+
revivers.set(schema, reviver);
|
|
691
|
+
return reviver;
|
|
692
|
+
};
|
|
693
|
+
|
|
694
|
+
|
|
544
695
|
},
|
|
545
696
|
581(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
546
697
|
__webpack_require__.d(__webpack_exports__, {
|
|
@@ -920,7 +1071,7 @@ var __webpack_exports__ = {};
|
|
|
920
1071
|
|
|
921
1072
|
// EXPORTS
|
|
922
1073
|
__webpack_require__.d(__webpack_exports__, {
|
|
923
|
-
ly: () => (/* reexport */ isArrayValued),
|
|
1074
|
+
ly: () => (/* reexport */ propertyKind/* .isArrayValued */.l),
|
|
924
1075
|
Qc: () => (/* reexport */ SchemaDate),
|
|
925
1076
|
dF: () => (/* reexport */ SchemaDefinition),
|
|
926
1077
|
VG: () => (/* reexport */ compiledSchemaToJsonSchema),
|
|
@@ -931,7 +1082,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
931
1082
|
qQ: () => (/* reexport */ SchemaIdentity),
|
|
932
1083
|
_t: () => (/* reexport */ SchemaDistinct),
|
|
933
1084
|
PG: () => (/* reexport */ SchemaNumber),
|
|
934
|
-
LL: () => (/* reexport */ hasPrimitiveElements),
|
|
1085
|
+
LL: () => (/* reexport */ propertyKind/* .hasPrimitiveElements */.L),
|
|
935
1086
|
IB: () => (/* reexport */ SchemaTracked),
|
|
936
1087
|
L$: () => (/* reexport */ rehydrateSchemaFromJsonSchema),
|
|
937
1088
|
CW: () => (/* reexport */ SchemaSerialize),
|
|
@@ -947,10 +1098,11 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
947
1098
|
w_: () => (/* reexport */ SchemaBoolean),
|
|
948
1099
|
Od: () => (/* reexport */ extractTypeInfo),
|
|
949
1100
|
r5: () => (/* reexport */ SchemaComputed),
|
|
950
|
-
|
|
1101
|
+
TH: () => (/* reexport */ storageDates/* .getStorageDateReviver */.T),
|
|
951
1102
|
XM: () => (/* reexport */ SchemaString),
|
|
952
1103
|
Cg: () => (/* reexport */ SchemaFile),
|
|
953
1104
|
FR: () => (/* reexport */ SchemaBase),
|
|
1105
|
+
UX: () => (/* reexport */ propertyInfoToJsonSchema),
|
|
954
1106
|
s: () => (/* reexport */ s),
|
|
955
1107
|
yV: () => (/* reexport */ SchemaTag),
|
|
956
1108
|
ge: () => (/* reexport */ SchemaSearchable),
|
|
@@ -2165,78 +2317,9 @@ class SlotPath {
|
|
|
2165
2317
|
|
|
2166
2318
|
// EXTERNAL MODULE: ./src/errors/SchemaError.ts
|
|
2167
2319
|
var SchemaError = __webpack_require__(131);
|
|
2168
|
-
;// CONCATENATED MODULE: ./src/codegen/utils.ts
|
|
2169
|
-
/**
|
|
2170
|
-
* Counts non-overlapping occurrences of a term in text.
|
|
2171
|
-
*
|
|
2172
|
-
* Behavior:
|
|
2173
|
-
* - Case-sensitive matching
|
|
2174
|
-
* - If the search term is composed entirely of word characters (A–Z, a–z, 0–9, _),
|
|
2175
|
-
* enforce whole-word boundaries so "red" does not match inside "redder".
|
|
2176
|
-
* - If the search term contains any non-word character (e.g. "=>", "()", "::"),
|
|
2177
|
-
* match anywhere without boundary checks (useful for symbols).
|
|
2178
|
-
* - Non-overlapping matches (after a hit, advances by term length)
|
|
2179
|
-
* - Optimized single-character fast path; otherwise uses indexOf loop
|
|
2180
|
-
*
|
|
2181
|
-
* Examples:
|
|
2182
|
-
* - countWordOccurance("red redder red", "red") => 2
|
|
2183
|
-
* - countWordOccurance("()=>{}", "=>") => 1
|
|
2184
|
-
* - countWordOccurance("aaaa", "aa") => 2 (non-overlapping)
|
|
2185
|
-
*
|
|
2186
|
-
* @param text The source text to scan
|
|
2187
|
-
* @param word The term to match (must be non-empty)
|
|
2188
|
-
* @returns The number of occurrences found
|
|
2189
|
-
*/ const countWordOccurance = (text, word)=>{
|
|
2190
|
-
const wl = word.length;
|
|
2191
|
-
const tl = text.length;
|
|
2192
|
-
if (wl === 0 || wl > tl) return 0;
|
|
2193
|
-
// Fast path for single-character words
|
|
2194
|
-
if (wl === 1) {
|
|
2195
|
-
let c = 0;
|
|
2196
|
-
const code = word.charCodeAt(0);
|
|
2197
|
-
for(let i = 0; i < tl; i++)if (text.charCodeAt(i) === code) c++;
|
|
2198
|
-
return c;
|
|
2199
|
-
}
|
|
2200
|
-
let count = 0;
|
|
2201
|
-
let i = 0;
|
|
2202
|
-
function isWordCharCode(c) {
|
|
2203
|
-
return c >= 48 && c <= 57 // 0-9
|
|
2204
|
-
|| c >= 65 && c <= 90 // A-Z
|
|
2205
|
-
|| c >= 97 && c <= 122 // a-z
|
|
2206
|
-
|| c === 95; // _
|
|
2207
|
-
}
|
|
2208
|
-
// Decide whether to enforce word boundaries based on the search term
|
|
2209
|
-
let enforceWordBoundaries = true;
|
|
2210
|
-
for(let k = 0; k < wl; k++){
|
|
2211
|
-
const cc = word.charCodeAt(k);
|
|
2212
|
-
if (!isWordCharCode(cc)) {
|
|
2213
|
-
enforceWordBoundaries = false;
|
|
2214
|
-
break;
|
|
2215
|
-
}
|
|
2216
|
-
}
|
|
2217
|
-
while(true){
|
|
2218
|
-
i = text.indexOf(word, i);
|
|
2219
|
-
if (i === -1) break;
|
|
2220
|
-
if (enforceWordBoundaries) {
|
|
2221
|
-
const left = i - 1;
|
|
2222
|
-
const right = i + wl;
|
|
2223
|
-
const leftOk = left < 0 || !isWordCharCode(text.charCodeAt(left));
|
|
2224
|
-
const rightOk = right >= tl || !isWordCharCode(text.charCodeAt(right));
|
|
2225
|
-
if (leftOk && rightOk) count++;
|
|
2226
|
-
} else {
|
|
2227
|
-
// No boundary enforcement for symbol-containing terms
|
|
2228
|
-
count++;
|
|
2229
|
-
}
|
|
2230
|
-
i += wl; // non-overlapping word matches
|
|
2231
|
-
}
|
|
2232
|
-
return count;
|
|
2233
|
-
};
|
|
2234
|
-
|
|
2235
2320
|
;// CONCATENATED MODULE: ./src/codegen/handlers/types.ts
|
|
2236
2321
|
|
|
2237
2322
|
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
2323
|
/**
|
|
2241
2324
|
* Terminal link for chains that apply only to a subset of properties (keys,
|
|
2242
2325
|
* identities). Returning the builder marks every other property as
|
|
@@ -2412,34 +2495,16 @@ class PropertyInfoHandler {
|
|
|
2412
2495
|
}
|
|
2413
2496
|
enriched.property(`${property.name}: ${entitySelectorPath}`);
|
|
2414
2497
|
}
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
const index = stringifiedFunction.indexOf("=>");
|
|
2426
|
-
body = stringifiedFunction.slice(index + 2, stringifiedFunction.length);
|
|
2427
|
-
}
|
|
2428
|
-
if (body.startsWith("{") === true && body.endsWith("}")) {
|
|
2429
|
-
// Remove brackets, wrapping function will have them
|
|
2430
|
-
builder.appendBody(body.slice(1, body.length - 1));
|
|
2431
|
-
return {
|
|
2432
|
-
builder,
|
|
2433
|
-
parameters
|
|
2434
|
-
};
|
|
2435
|
-
}
|
|
2436
|
-
builder.appendBody(`return ${body};`);
|
|
2437
|
-
return {
|
|
2438
|
-
builder,
|
|
2439
|
-
parameters
|
|
2440
|
-
};
|
|
2441
|
-
}
|
|
2442
|
-
throw new Error("Only arrow functions are allowed in the schema definition: function () {} ---> () => {}");
|
|
2498
|
+
/**
|
|
2499
|
+
* Binds a function the schema author supplied (a default, a computed, a serializer) into
|
|
2500
|
+
* the generated code and returns the expression that calls it with `args`.
|
|
2501
|
+
*
|
|
2502
|
+
* The function is passed in by value rather than pasted in as source text. Pasted source
|
|
2503
|
+
* loses the scope it was written in, so a default that called an imported helper threw, and
|
|
2504
|
+
* it had to be parsed back apart, which only worked for arrows: a bundler that lowers arrows
|
|
2505
|
+
* to `function` expressions, or renames what they refer to, broke every schema (#46).
|
|
2506
|
+
*/ emitBoundCall(target, fn, args) {
|
|
2507
|
+
return `${target.bind(fn)}(${args.join(", ")})`;
|
|
2443
2508
|
}
|
|
2444
2509
|
}
|
|
2445
2510
|
|
|
@@ -2599,28 +2664,21 @@ class EnrichmentPrimitiveHandler extends PropertyInfoHandler {
|
|
|
2599
2664
|
class EnrichmentFunctionHandler extends PropertyInfoHandler {
|
|
2600
2665
|
handle(property, builder) {
|
|
2601
2666
|
if (property.functionBody != null && property.type === types/* .SchemaTypes.Function */.L.Function) {
|
|
2602
|
-
const
|
|
2667
|
+
const factory = builder.get("factory");
|
|
2668
|
+
const args = [
|
|
2603
2669
|
"enriched",
|
|
2604
2670
|
"collectionName"
|
|
2605
2671
|
];
|
|
2606
2672
|
if (property.injected != null) {
|
|
2607
|
-
|
|
2608
|
-
const parameter = factory.createParameter(property.injected);
|
|
2609
|
-
factory.parameters(parameter);
|
|
2610
|
-
parameterNames.push(parameter.name);
|
|
2673
|
+
args.push(factory.bind(property.injected));
|
|
2611
2674
|
}
|
|
2612
|
-
const declarationsSlot = builder.get("factory.function.declarations");
|
|
2613
|
-
// Unwrap the functions to removing currying
|
|
2614
|
-
const defaultFunctionWithParameters = this.toNamedFunction(property.functionBody.toString(), declarationsSlot);
|
|
2615
|
-
defaultFunctionWithParameters.builder.parameters(...parameterNames.map((w, i)=>({
|
|
2616
|
-
name: defaultFunctionWithParameters.parameters[i],
|
|
2617
|
-
callName: w
|
|
2618
|
-
})));
|
|
2619
2675
|
const slot = builder.get("factory.function.assignment");
|
|
2620
2676
|
const enrichedAssignmentPath = property.getAssignmentPath({
|
|
2621
2677
|
parent: "enriched"
|
|
2622
2678
|
});
|
|
2623
|
-
|
|
2679
|
+
// The definition is curried: calling it with the entity returns the function the
|
|
2680
|
+
// property holds
|
|
2681
|
+
slot.assign(enrichedAssignmentPath).value(this.emitBoundCall(factory, property.functionBody, args));
|
|
2624
2682
|
return builder;
|
|
2625
2683
|
}
|
|
2626
2684
|
return super.handle(property, builder);
|
|
@@ -2675,34 +2733,17 @@ class EnrichmentDefaultFunctionHandler extends PropertyInfoHandler {
|
|
|
2675
2733
|
handle(property, builder) {
|
|
2676
2734
|
if (property.defaultValue != null && typeof property.defaultValue === "function") {
|
|
2677
2735
|
this.setEnrichedProperty(property, builder);
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
}
|
|
2685
|
-
const parameter = factory.createParameter(property.injected);
|
|
2686
|
-
factory.parameters(parameter);
|
|
2687
|
-
const defaultFunctionWithParameters = this.toNamedFunction(property.defaultValue.toString(), declarationsSlot);
|
|
2688
|
-
// This is ok, defaults can only inject one parameter anyways
|
|
2689
|
-
defaultFunctionWithParameters.builder.parameters(...defaultFunctionWithParameters.parameters.map((w)=>({
|
|
2690
|
-
name: w,
|
|
2691
|
-
callName: parameter.name
|
|
2692
|
-
})));
|
|
2693
|
-
const ifsSlot = builder.get("factory.function.ifs");
|
|
2694
|
-
const enrichedAssignmentPath = property.getAssignmentPath({
|
|
2695
|
-
parent: "enriched"
|
|
2696
|
-
});
|
|
2697
|
-
ifsSlot.if(`${enrichedAssignmentPath} == null`).appendBody(`${enrichedAssignmentPath} = ${defaultFunctionWithParameters.builder.toCallable()}`);
|
|
2698
|
-
return builder;
|
|
2699
|
-
}
|
|
2700
|
-
const defaultFunction = this.toNamedFunction(property.defaultValue.toString(), declarationsSlot);
|
|
2736
|
+
const factory = builder.get("factory");
|
|
2737
|
+
// Defaults take at most one argument: the injected value, when there is one
|
|
2738
|
+
const args = property.injected != null ? [
|
|
2739
|
+
factory.bind(property.injected)
|
|
2740
|
+
] : [];
|
|
2741
|
+
const call = this.emitBoundCall(factory, property.defaultValue, args);
|
|
2701
2742
|
const ifsSlot = builder.get("factory.function.ifs");
|
|
2702
2743
|
const enrichedAssignmentPath = property.getAssignmentPath({
|
|
2703
2744
|
parent: "enriched"
|
|
2704
2745
|
});
|
|
2705
|
-
ifsSlot.if(`${enrichedAssignmentPath} == null`).appendBody(`${enrichedAssignmentPath} = ${
|
|
2746
|
+
ifsSlot.if(`${enrichedAssignmentPath} == null`).appendBody(`${enrichedAssignmentPath} = ${call}`);
|
|
2706
2747
|
return builder;
|
|
2707
2748
|
}
|
|
2708
2749
|
return super.handle(property, builder);
|
|
@@ -2715,22 +2756,15 @@ class EnrichmentDefaultFunctionHandler extends PropertyInfoHandler {
|
|
|
2715
2756
|
class EnrichmentComputedValueHandler extends PropertyInfoHandler {
|
|
2716
2757
|
handle(property, builder) {
|
|
2717
2758
|
if (property.functionBody != null && property.type === types/* .SchemaTypes.Computed */.L.Computed) {
|
|
2718
|
-
const
|
|
2759
|
+
const factory = builder.get("factory");
|
|
2760
|
+
const args = [
|
|
2719
2761
|
"enriched",
|
|
2720
2762
|
"collectionName"
|
|
2721
2763
|
];
|
|
2722
2764
|
if (property.injected != null) {
|
|
2723
|
-
|
|
2724
|
-
const parameter = factory.createParameter(property.injected);
|
|
2725
|
-
factory.parameters(parameter);
|
|
2726
|
-
parameterNames.push(parameter.name);
|
|
2765
|
+
args.push(factory.bind(property.injected));
|
|
2727
2766
|
}
|
|
2728
|
-
const
|
|
2729
|
-
const defaultFunctionWithParameters = this.toNamedFunction(property.functionBody.toString(), declarationsSlot);
|
|
2730
|
-
defaultFunctionWithParameters.builder.parameters(...parameterNames.map((w, i)=>({
|
|
2731
|
-
name: defaultFunctionWithParameters.parameters[i],
|
|
2732
|
-
callName: w
|
|
2733
|
-
})));
|
|
2767
|
+
const call = this.emitBoundCall(factory, property.functionBody, args);
|
|
2734
2768
|
// Compute-once semantics for computed keys/identities: an existing value is
|
|
2735
2769
|
// carried into the enriched literal and never recomputed — a key must stay
|
|
2736
2770
|
// stable once assigned (content-hash ids would otherwise churn as the
|
|
@@ -2743,44 +2777,15 @@ class EnrichmentComputedValueHandler extends PropertyInfoHandler {
|
|
|
2743
2777
|
const enrichedAssignmentPath = property.getAssignmentPath({
|
|
2744
2778
|
parent: "enriched"
|
|
2745
2779
|
});
|
|
2746
|
-
ifsSlot.if(`${enrichedAssignmentPath} == null`).appendBody(`${enrichedAssignmentPath} = ${
|
|
2780
|
+
ifsSlot.if(`${enrichedAssignmentPath} == null`).appendBody(`${enrichedAssignmentPath} = ${call}`);
|
|
2747
2781
|
return builder;
|
|
2748
2782
|
}
|
|
2749
2783
|
return super.handle(property, builder);
|
|
2750
2784
|
}
|
|
2751
2785
|
}
|
|
2752
2786
|
|
|
2753
|
-
|
|
2754
|
-
|
|
2755
|
-
/**
|
|
2756
|
-
* Types whose runtime value is a JS array.
|
|
2757
|
-
*
|
|
2758
|
-
* `Array` and `Vector` are the same thing to every layer that copies, compares, hashes or
|
|
2759
|
-
* freezes a value — a vector is a list of numbers and nothing more. They differ only where a
|
|
2760
|
-
* backend chooses storage, which is the one place that should ask for `SchemaTypes.Vector` by
|
|
2761
|
-
* name.
|
|
2762
|
-
*
|
|
2763
|
-
* This exists so adding a third array-shaped type is one edit rather than a hunt through
|
|
2764
|
-
* twelve handlers. Missing one of those is silent in the worst way: a vector that clones by
|
|
2765
|
-
* reference is shared with the change tracker's copy, so overwriting an embedding produces no
|
|
2766
|
-
* diff and the save reports nothing to do.
|
|
2767
|
-
*/ const ARRAY_VALUED_TYPES = new Set([
|
|
2768
|
-
types/* .SchemaTypes.Array */.L.Array,
|
|
2769
|
-
types/* .SchemaTypes.Vector */.L.Vector
|
|
2770
|
-
]);
|
|
2771
|
-
/** True when the property's value is a JS array and needs value rather than reference semantics. */ const isArrayValued = (type)=>ARRAY_VALUED_TYPES.has(type);
|
|
2772
|
-
/**
|
|
2773
|
-
* True when the property's elements are primitives, so a spread is a sufficient copy.
|
|
2774
|
-
*
|
|
2775
|
-
* A vector is always numbers, so it never needs the per-element deep copy an array of objects
|
|
2776
|
-
* or dates does.
|
|
2777
|
-
*/ const PRIMITIVE_ELEMENT_TYPES = new Set([
|
|
2778
|
-
types/* .SchemaTypes.String */.L.String,
|
|
2779
|
-
types/* .SchemaTypes.Number */.L.Number,
|
|
2780
|
-
types/* .SchemaTypes.Boolean */.L.Boolean
|
|
2781
|
-
]);
|
|
2782
|
-
const hasPrimitiveElements = (type, elementType)=>type === types/* .SchemaTypes.Vector */.L.Vector || PRIMITIVE_ELEMENT_TYPES.has(elementType);
|
|
2783
|
-
|
|
2787
|
+
// EXTERNAL MODULE: ./src/schema/utils/propertyKind.ts
|
|
2788
|
+
var propertyKind = __webpack_require__(575);
|
|
2784
2789
|
;// CONCATENATED MODULE: ./src/codegen/handlers/enrichment/EnrichmentArrayHandler.ts
|
|
2785
2790
|
|
|
2786
2791
|
|
|
@@ -2790,7 +2795,7 @@ const hasPrimitiveElements = (type, elementType)=>type === types/* .SchemaTypes.
|
|
|
2790
2795
|
* mark the root entity dirty instead of being silently lost on save.
|
|
2791
2796
|
*/ class EnrichmentArrayHandler extends PropertyInfoHandler {
|
|
2792
2797
|
handle(property, builder) {
|
|
2793
|
-
if (isArrayValued(property.type)) {
|
|
2798
|
+
if ((0,propertyKind/* .isArrayValued */.l)(property.type)) {
|
|
2794
2799
|
// Place the property in the enriched literal like any other leaf
|
|
2795
2800
|
this.setEnrichedProperty(property, builder);
|
|
2796
2801
|
const enrichedPath = property.getAssignmentPath({
|
|
@@ -2832,13 +2837,10 @@ class MergeDefaultFunctionHandler extends PropertyInfoHandler {
|
|
|
2832
2837
|
// we are changing merge to be more like enrich so we can handle injections
|
|
2833
2838
|
// we may need to change more. Need to move towards factories
|
|
2834
2839
|
if (property.defaultValue != null && typeof property.defaultValue === "function") {
|
|
2835
|
-
const
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
factory.parameters(parameter);
|
|
2840
|
-
defaultFunctionParameters.push(parameter.name);
|
|
2841
|
-
}
|
|
2840
|
+
const factory = builder.get("factory");
|
|
2841
|
+
const args = property.injected != null ? [
|
|
2842
|
+
factory.bind(property.injected)
|
|
2843
|
+
] : [];
|
|
2842
2844
|
// A defaulted property still merges from the source; the default only fills
|
|
2843
2845
|
// the gap when neither side has a value
|
|
2844
2846
|
this.emitMergeCopy(property, builder, {
|
|
@@ -2854,15 +2856,9 @@ class MergeDefaultFunctionHandler extends PropertyInfoHandler {
|
|
|
2854
2856
|
const assignmentPath = property.getAssignmentPath({
|
|
2855
2857
|
parent: "destination"
|
|
2856
2858
|
});
|
|
2857
|
-
const declarationsSlot = builder.get("factory.function.header");
|
|
2858
|
-
const defaultFunctionWithParameters = this.toNamedFunction(property.defaultValue.toString(), declarationsSlot);
|
|
2859
|
-
defaultFunctionWithParameters.builder.parameters(...defaultFunctionParameters.map((w, i)=>({
|
|
2860
|
-
name: defaultFunctionWithParameters.parameters[i],
|
|
2861
|
-
callName: w
|
|
2862
|
-
})));
|
|
2863
2859
|
const defaultIf = ifsSlot.if(`${selectorPath} == null`);
|
|
2864
2860
|
this.emitDestinationAncestorGuards(property, defaultIf);
|
|
2865
|
-
defaultIf.appendBody(`${assignmentPath} = ${
|
|
2861
|
+
defaultIf.appendBody(`${assignmentPath} = ${this.emitBoundCall(factory, property.defaultValue, args)}`);
|
|
2866
2862
|
return builder;
|
|
2867
2863
|
}
|
|
2868
2864
|
return super.handle(property, builder);
|
|
@@ -2903,28 +2899,20 @@ class MergePrimitiveHandler extends PropertyInfoHandler {
|
|
|
2903
2899
|
class MergeComputedValueHandler extends PropertyInfoHandler {
|
|
2904
2900
|
handle(property, builder) {
|
|
2905
2901
|
if (property.functionBody != null && property.type === types/* .SchemaTypes.Computed */.L.Computed) {
|
|
2906
|
-
const
|
|
2902
|
+
const factory = builder.get("factory");
|
|
2903
|
+
const args = [
|
|
2907
2904
|
"source",
|
|
2908
2905
|
"collectionName"
|
|
2909
2906
|
];
|
|
2910
2907
|
if (property.injected != null) {
|
|
2911
|
-
|
|
2912
|
-
const parameter = factory.createParameter(property.injected);
|
|
2913
|
-
factory.parameters(parameter);
|
|
2914
|
-
parameterNames.push(parameter.name);
|
|
2908
|
+
args.push(factory.bind(property.injected));
|
|
2915
2909
|
}
|
|
2916
|
-
const declarationsSlot = builder.get("factory.function.header");
|
|
2917
|
-
const defaultFunctionWithParameters = this.toNamedFunction(property.functionBody.toString(), declarationsSlot);
|
|
2918
|
-
defaultFunctionWithParameters.builder.parameters(...parameterNames.map((w, i)=>({
|
|
2919
|
-
name: defaultFunctionWithParameters.parameters[i],
|
|
2920
|
-
callName: w
|
|
2921
|
-
})));
|
|
2922
2910
|
const slot = builder.get("factory.function.assignments");
|
|
2923
2911
|
const enrichedAssignmentPath = property.getAssignmentPath({
|
|
2924
2912
|
parent: "destination"
|
|
2925
2913
|
});
|
|
2926
2914
|
// We want to recompute the value always in case there are changes
|
|
2927
|
-
slot.assign(enrichedAssignmentPath).value(
|
|
2915
|
+
slot.assign(enrichedAssignmentPath).value(this.emitBoundCall(factory, property.functionBody, args));
|
|
2928
2916
|
return builder;
|
|
2929
2917
|
}
|
|
2930
2918
|
return super.handle(property, builder);
|
|
@@ -2997,7 +2985,7 @@ class MergeFunctionHandler extends PropertyInfoHandler {
|
|
|
2997
2985
|
* reference is adopted as-is — same as the primitive copy this replaces.
|
|
2998
2986
|
*/ class MergeArrayHandler extends PropertyInfoHandler {
|
|
2999
2987
|
handle(property, builder) {
|
|
3000
|
-
if (isArrayValued(property.type)) {
|
|
2988
|
+
if ((0,propertyKind/* .isArrayValued */.l)(property.type)) {
|
|
3001
2989
|
const selectorPath = property.getSelectrorPath({
|
|
3002
2990
|
parent: "source",
|
|
3003
2991
|
assignmentType: "FORCE_NULLABLE_OR_OPTIONAL"
|
|
@@ -3334,7 +3322,7 @@ class CloneArrayHandler extends PropertyInfoHandler {
|
|
|
3334
3322
|
super(), this.useFromPropertyName = useFromPropertyName;
|
|
3335
3323
|
}
|
|
3336
3324
|
handle(property, builder) {
|
|
3337
|
-
if (isArrayValued(property.type)) {
|
|
3325
|
+
if ((0,propertyKind/* .isArrayValued */.l)(property.type)) {
|
|
3338
3326
|
// Arrays are leaf properties — they have no child PropertyInfos, so the
|
|
3339
3327
|
// copy must happen here for every array, including nullable/optional ones.
|
|
3340
3328
|
// The `!== undefined` guard below covers absent values; an explicit null is copied as
|
|
@@ -3360,7 +3348,7 @@ class CloneArrayHandler extends PropertyInfoHandler {
|
|
|
3360
3348
|
// across merges), and a Proxy cannot pass a structured-clone boundary.
|
|
3361
3349
|
const elementType = property.innerSchema?.type;
|
|
3362
3350
|
let copyExpression;
|
|
3363
|
-
if (hasPrimitiveElements(property.type, elementType)) {
|
|
3351
|
+
if ((0,propertyKind/* .hasPrimitiveElements */.L)(property.type, elementType)) {
|
|
3364
3352
|
copyExpression = `[...${entitySelectorPath}]`;
|
|
3365
3353
|
} else if (elementType === types/* .SchemaTypes.Date */.L.Date) {
|
|
3366
3354
|
copyExpression = `${entitySelectorPath}.map(function (v) { return v == null ? v : new Date(v); })`;
|
|
@@ -3479,7 +3467,7 @@ class CloneObjectHandler extends PropertyInfoHandler {
|
|
|
3479
3467
|
// Anything that copies by assignment. An array-valued property must not land here:
|
|
3480
3468
|
// assigning the reference shares it with the source, which is the whole point of
|
|
3481
3469
|
// CloneArrayHandler.
|
|
3482
|
-
if (property.type != types/* .SchemaTypes.Object */.L.Object && isArrayValued(property.type) === false) {
|
|
3470
|
+
if (property.type != types/* .SchemaTypes.Object */.L.Object && (0,propertyKind/* .isArrayValued */.l)(property.type) === false) {
|
|
3483
3471
|
const slot = builder.get("if");
|
|
3484
3472
|
const useFromPropertyName = this.useFromPropertyName;
|
|
3485
3473
|
const entitySelectorPath = property.getSelectrorPath({
|
|
@@ -3542,7 +3530,7 @@ class CloneHandlerBuilder {
|
|
|
3542
3530
|
|
|
3543
3531
|
class CompareArrayHandler extends PropertyInfoHandler {
|
|
3544
3532
|
handle(property, builder) {
|
|
3545
|
-
if (isArrayValued(property.type)) {
|
|
3533
|
+
if ((0,propertyKind/* .isArrayValued */.l)(property.type)) {
|
|
3546
3534
|
let compare = builder.getOrDefault("result.variable.compare");
|
|
3547
3535
|
const leftCompare = property.getSelectrorPath({
|
|
3548
3536
|
parent: "a"
|
|
@@ -3837,7 +3825,6 @@ class DeserializeDeserializerHandler extends PropertyInfoHandler {
|
|
|
3837
3825
|
handle(property, builder) {
|
|
3838
3826
|
if (property.valueDeserializer != null) {
|
|
3839
3827
|
let objectBuilder = builder.getOrDefault("result.variable.object");
|
|
3840
|
-
const assignmentBuilder = builder.getOrDefault("functions");
|
|
3841
3828
|
// Read the incoming record by `from` (storage) name
|
|
3842
3829
|
const entitySelectorPath = property.getSelectrorPath({
|
|
3843
3830
|
parent: "unserialized",
|
|
@@ -3850,18 +3837,16 @@ class DeserializeDeserializerHandler extends PropertyInfoHandler {
|
|
|
3850
3837
|
name: "object"
|
|
3851
3838
|
});
|
|
3852
3839
|
}
|
|
3853
|
-
const
|
|
3854
|
-
|
|
3855
|
-
|
|
3856
|
-
callName: entitySelectorPath
|
|
3857
|
-
})));
|
|
3840
|
+
const call = this.emitBoundCall(builder, property.valueDeserializer, [
|
|
3841
|
+
entitySelectorPath
|
|
3842
|
+
]);
|
|
3858
3843
|
if (property.parent == null) {
|
|
3859
|
-
objectBuilder.property(`${property.name}: ${
|
|
3844
|
+
objectBuilder.property(`${property.name}: ${call}`);
|
|
3860
3845
|
return builder;
|
|
3861
3846
|
}
|
|
3862
3847
|
const slotPath = new SlotPath(...property.getParentPathArray());
|
|
3863
3848
|
objectBuilder = objectBuilder.get(slotPath.get());
|
|
3864
|
-
objectBuilder.property(`${property.name}: ${
|
|
3849
|
+
objectBuilder.property(`${property.name}: ${call}`);
|
|
3865
3850
|
return builder;
|
|
3866
3851
|
}
|
|
3867
3852
|
return super.handle(property, builder);
|
|
@@ -3887,7 +3872,7 @@ class DeserializeDeserializerHandler extends PropertyInfoHandler {
|
|
|
3887
3872
|
return `[...${selector}]`;
|
|
3888
3873
|
}
|
|
3889
3874
|
handle(property, builder) {
|
|
3890
|
-
if (isArrayValued(property.type)) {
|
|
3875
|
+
if ((0,propertyKind/* .isArrayValued */.l)(property.type)) {
|
|
3891
3876
|
const slotPath = new SlotPath("result.variable.object");
|
|
3892
3877
|
// Create the result object when this is the first property iterated —
|
|
3893
3878
|
// handler output cannot depend on schema property order
|
|
@@ -4128,7 +4113,7 @@ class HashComputedValueHandler extends PropertyInfoHandler {
|
|
|
4128
4113
|
* objects would collapse every value to "[object Object]" and collide.
|
|
4129
4114
|
*/ class HashArrayHandler extends PropertyInfoHandler {
|
|
4130
4115
|
handle(property, builder) {
|
|
4131
|
-
if (isArrayValued(property.type)) {
|
|
4116
|
+
if ((0,propertyKind/* .isArrayValued */.l)(property.type)) {
|
|
4132
4117
|
let stringBuilder = builder.getOrDefault("hash-object-return.variable.string");
|
|
4133
4118
|
const entitySelectorPath = property.getSelectrorPath({
|
|
4134
4119
|
parent: "entity"
|
|
@@ -4293,7 +4278,7 @@ class EnableChangeTrackingObjectHandler extends PropertyInfoHandler {
|
|
|
4293
4278
|
* mark the root entity dirty instead of being silently lost on save.
|
|
4294
4279
|
*/ class EnableChangeTrackingArrayHandler extends PropertyInfoHandler {
|
|
4295
4280
|
handle(property, builder) {
|
|
4296
|
-
if (isArrayValued(property.type)) {
|
|
4281
|
+
if ((0,propertyKind/* .isArrayValued */.l)(property.type)) {
|
|
4297
4282
|
const assignmentSlot = builder.get("assignment");
|
|
4298
4283
|
const childSelectorPath = property.getSelectrorPath({
|
|
4299
4284
|
parent: "entity"
|
|
@@ -4370,7 +4355,7 @@ class FreezeObjectHandler extends PropertyInfoHandler {
|
|
|
4370
4355
|
|
|
4371
4356
|
class FreezeArrayHandler extends PropertyInfoHandler {
|
|
4372
4357
|
handle(property, builder) {
|
|
4373
|
-
if (isArrayValued(property.type)) {
|
|
4358
|
+
if ((0,propertyKind/* .isArrayValued */.l)(property.type)) {
|
|
4374
4359
|
const assignmentSlot = builder.get("assignment");
|
|
4375
4360
|
const childSelectorPath = property.getSelectrorPath({
|
|
4376
4361
|
parent: "entity"
|
|
@@ -4506,7 +4491,6 @@ class SerializeSerializerHandler extends PropertyInfoHandler {
|
|
|
4506
4491
|
handle(property, builder) {
|
|
4507
4492
|
if (property.valueSerializer != null) {
|
|
4508
4493
|
const slot = builder.getOrDefault("if");
|
|
4509
|
-
const assignmentBuilder = builder.getOrDefault("functions");
|
|
4510
4494
|
// Serialize maps in-memory shape -> storage shape: read the entity by
|
|
4511
4495
|
// property name, write the result by `from` (storage) name
|
|
4512
4496
|
const entitySelectorPath = property.getSelectrorPath({
|
|
@@ -4516,17 +4500,15 @@ class SerializeSerializerHandler extends PropertyInfoHandler {
|
|
|
4516
4500
|
parent: "result",
|
|
4517
4501
|
useFromPropertyName: true
|
|
4518
4502
|
});
|
|
4519
|
-
const
|
|
4520
|
-
|
|
4521
|
-
|
|
4522
|
-
callName: entitySelectorPath
|
|
4523
|
-
})));
|
|
4503
|
+
const call = this.emitBoundCall(builder, property.valueSerializer, [
|
|
4504
|
+
entitySelectorPath
|
|
4505
|
+
]);
|
|
4524
4506
|
if (property.parent == null) {
|
|
4525
|
-
slot.if(`Object.hasOwn(entity, "${property.name}")`).appendBody(`${resultSelectorPath} = ${
|
|
4507
|
+
slot.if(`Object.hasOwn(entity, "${property.name}")`).appendBody(`${resultSelectorPath} = ${call}`);
|
|
4526
4508
|
return builder;
|
|
4527
4509
|
}
|
|
4528
4510
|
// Nested serializer: same pattern as SerializeValueHandler — if block for parent existence, then assign via serializer
|
|
4529
|
-
this.emitSerializeNestedAssignment(property, slot,
|
|
4511
|
+
this.emitSerializeNestedAssignment(property, slot, call);
|
|
4530
4512
|
return builder;
|
|
4531
4513
|
}
|
|
4532
4514
|
return super.handle(property, builder);
|
|
@@ -4585,7 +4567,7 @@ class SerializeComputedHandler extends PropertyInfoHandler {
|
|
|
4585
4567
|
return `[...${selector}]`;
|
|
4586
4568
|
}
|
|
4587
4569
|
handle(property, builder) {
|
|
4588
|
-
if (isArrayValued(property.type)) {
|
|
4570
|
+
if ((0,propertyKind/* .isArrayValued */.l)(property.type)) {
|
|
4589
4571
|
const slot = builder.get("if");
|
|
4590
4572
|
// Serialize maps in-memory shape -> storage shape: read the entity by
|
|
4591
4573
|
// property name, write the result by `from` (storage) name
|
|
@@ -5489,8 +5471,8 @@ const arrayConverter = (property, context)=>{
|
|
|
5489
5471
|
// Create the function using new Function()
|
|
5490
5472
|
// If no parameters, call with just the body; otherwise spread the params
|
|
5491
5473
|
const fn = params.length > 0 ? new Function(...params, functionBody) : new Function(functionBody);
|
|
5492
|
-
// Wrap it so toString() returns the original arrow function string
|
|
5493
|
-
//
|
|
5474
|
+
// Wrap it so toString() returns the original arrow function string, so
|
|
5475
|
+
// serializing the rehydrated schema writes the same functionSource again
|
|
5494
5476
|
recreatedFn = Object.assign(fn, {
|
|
5495
5477
|
toString: ()=>functionSource
|
|
5496
5478
|
});
|
|
@@ -5499,7 +5481,7 @@ const arrayConverter = (property, context)=>{
|
|
|
5499
5481
|
recreatedFn = ()=>{
|
|
5500
5482
|
throw new Error(`Cannot recreate computed property ${computedProp.name}: ${e instanceof Error ? e.message : 'unknown error'}`);
|
|
5501
5483
|
};
|
|
5502
|
-
//
|
|
5484
|
+
// Keep functionSource re-parseable if this schema is serialized again
|
|
5503
5485
|
Object.assign(recreatedFn, {
|
|
5504
5486
|
toString: ()=>`() => { throw new Error("Cannot recreate computed property ${computedProp.name}"); }`
|
|
5505
5487
|
});
|
|
@@ -5636,39 +5618,16 @@ class SetHandlerBuilder {
|
|
|
5636
5618
|
}
|
|
5637
5619
|
}
|
|
5638
5620
|
|
|
5639
|
-
;// CONCATENATED MODULE: ./src/schema/
|
|
5640
|
-
|
|
5641
|
-
|
|
5642
|
-
|
|
5643
|
-
|
|
5644
|
-
|
|
5645
|
-
|
|
5646
|
-
|
|
5647
|
-
|
|
5648
|
-
|
|
5649
|
-
|
|
5650
|
-
|
|
5651
|
-
|
|
5652
|
-
|
|
5653
|
-
|
|
5654
|
-
|
|
5655
|
-
|
|
5656
|
-
|
|
5657
|
-
|
|
5658
|
-
|
|
5659
|
-
|
|
5660
|
-
|
|
5661
|
-
|
|
5662
|
-
|
|
5663
|
-
|
|
5664
|
-
|
|
5665
|
-
|
|
5666
|
-
function assertPropertyHandled(generatorName, property, result) {
|
|
5667
|
-
if (result == null) {
|
|
5668
|
-
throw new Error(`Schema compilation failed: no '${generatorName}' code generator handles property '${property.getAssignmentPath()}' (type: ${property.type}). Add a handler for this property shape or mark it not applicable in the ${generatorName} chain.`);
|
|
5669
|
-
}
|
|
5670
|
-
}
|
|
5671
|
-
function createChangeTracker() {
|
|
5621
|
+
;// CONCATENATED MODULE: ./src/schema/changeTracker.ts
|
|
5622
|
+
/**
|
|
5623
|
+
* Builds the proxy factory that change-tracks an entity.
|
|
5624
|
+
*
|
|
5625
|
+
* Generated schema code receives the result as a bound value — a parameter of the generated
|
|
5626
|
+
* factory — and never refers to this module by name. Name references do not survive a minifier,
|
|
5627
|
+
* which renames the declaration but cannot see inside generated source text (#40, #46). The
|
|
5628
|
+
* returned function holds no per-entity state, so one per compiled schema is shared by every
|
|
5629
|
+
* entity it tracks.
|
|
5630
|
+
*/ function createChangeTracker() {
|
|
5672
5631
|
const DIRTY_ENTITY_MARKER = "isDirty";
|
|
5673
5632
|
const CHANGES_ENTITY_KEY = "changes";
|
|
5674
5633
|
const ORIGINAL_ENTITY_KEY = "original";
|
|
@@ -5767,6 +5726,40 @@ function createChangeTracker() {
|
|
|
5767
5726
|
return new Proxy(entity, proxyHandler);
|
|
5768
5727
|
};
|
|
5769
5728
|
}
|
|
5729
|
+
|
|
5730
|
+
;// CONCATENATED MODULE: ./src/schema/SchemaDefinition.ts
|
|
5731
|
+
|
|
5732
|
+
|
|
5733
|
+
|
|
5734
|
+
|
|
5735
|
+
|
|
5736
|
+
|
|
5737
|
+
|
|
5738
|
+
|
|
5739
|
+
|
|
5740
|
+
|
|
5741
|
+
|
|
5742
|
+
|
|
5743
|
+
|
|
5744
|
+
|
|
5745
|
+
|
|
5746
|
+
|
|
5747
|
+
|
|
5748
|
+
|
|
5749
|
+
|
|
5750
|
+
|
|
5751
|
+
|
|
5752
|
+
|
|
5753
|
+
|
|
5754
|
+
|
|
5755
|
+
|
|
5756
|
+
|
|
5757
|
+
|
|
5758
|
+
function assertPropertyHandled(generatorName, property, result) {
|
|
5759
|
+
if (result == null) {
|
|
5760
|
+
throw new Error(`Schema compilation failed: no '${generatorName}' code generator handles property '${property.getAssignmentPath()}' (type: ${property.type}). Add a handler for this property shape or mark it not applicable in the ${generatorName} chain.`);
|
|
5761
|
+
}
|
|
5762
|
+
}
|
|
5770
5763
|
class SchemaDefinition extends SchemaBase {
|
|
5771
5764
|
instance;
|
|
5772
5765
|
type = types/* .SchemaTypes.Definition */.L.Definition;
|
|
@@ -5817,10 +5810,22 @@ class SchemaDefinition extends SchemaBase {
|
|
|
5817
5810
|
throw e;
|
|
5818
5811
|
}
|
|
5819
5812
|
}
|
|
5820
|
-
|
|
5813
|
+
/**
|
|
5814
|
+
* Compiles `builder` into a function taking `fnArgs`.
|
|
5815
|
+
*
|
|
5816
|
+
* A builder with bindings is compiled one level out: an outer function whose parameters are
|
|
5817
|
+
* the bindings, called once here with their values, returns the function that is kept. The
|
|
5818
|
+
* bound values become closure variables of that function, so the per-call cost is a context
|
|
5819
|
+
* read rather than anything resolved by name.
|
|
5820
|
+
*/ createFunction(builder, ...fnArgs) {
|
|
5821
5821
|
const body = builder.toString();
|
|
5822
|
+
const bindings = builder.getBindings();
|
|
5822
5823
|
try {
|
|
5823
|
-
|
|
5824
|
+
if (bindings.length === 0) {
|
|
5825
|
+
return Function(...fnArgs, body);
|
|
5826
|
+
}
|
|
5827
|
+
const outer = Function(...bindings.map((w)=>w.name), `return function(${fnArgs.join(", ")}) {\n${body}\n}`);
|
|
5828
|
+
return outer(...bindings.map((w)=>w.value));
|
|
5824
5829
|
} catch (e) {
|
|
5825
5830
|
logger/* .logger.error */.vF.error(`Error compiling schema function. Function Body: ${body}`);
|
|
5826
5831
|
throw e;
|
|
@@ -5953,9 +5958,11 @@ class SchemaDefinition extends SchemaBase {
|
|
|
5953
5958
|
const serializeHandler = serializeHandlerBuilder.build();
|
|
5954
5959
|
const compareIdsHandler = compareIdsHandlerBuilder.build();
|
|
5955
5960
|
const setHandlerHanlder = setHandlerBuilder.build();
|
|
5961
|
+
// Handed to the generated functions as a value, never embedded as source and called
|
|
5962
|
+
// by name — a minifier renames the declaration and breaks every schema (#40).
|
|
5963
|
+
const changeTracker = createChangeTracker();
|
|
5956
5964
|
const changeTrackingCodeBuilder = new blocks/* .CodeBuilder */.Nl();
|
|
5957
|
-
changeTrackingCodeBuilder.
|
|
5958
|
-
changeTrackingCodeBuilder.slot("declarations").variable("enableChangeTracking").value('createChangeTracker()');
|
|
5965
|
+
changeTrackingCodeBuilder.bind(changeTracker, "enableChangeTracking");
|
|
5959
5966
|
// Nested proxies are installed by assigning through already-proxied parents;
|
|
5960
5967
|
// pause tracking during setup so those writes don't register as changes
|
|
5961
5968
|
changeTrackingCodeBuilder.slot("pause").raw('\tconst hadTracking = entity.__tracking__ != null;\n\tif (!hadTracking) { Object.defineProperty(entity, "__tracking__", { value: { changes: {}, isDirty: false, original: {}, isPaused: false }, configurable: true, writable: true, enumerable: false }); }\n\tconst wasPaused = entity.__tracking__.isPaused;\n\tentity.__tracking__.isPaused = true;');
|
|
@@ -5984,9 +5991,10 @@ class SchemaDefinition extends SchemaBase {
|
|
|
5984
5991
|
}).parameters({
|
|
5985
5992
|
name: "collectionName",
|
|
5986
5993
|
value: this.collectionName
|
|
5994
|
+
}, {
|
|
5995
|
+
name: "changeTracker",
|
|
5996
|
+
value: changeTracker
|
|
5987
5997
|
});
|
|
5988
|
-
enricherFunctionRoot.slot("changeTracker").raw(`${createChangeTracker.toString()}`);
|
|
5989
|
-
enricherFunctionRoot.slot("changeTrackerFunction").raw(`\tconst changeTracker = createChangeTracker();`);
|
|
5990
5998
|
const enricherFunctionBody = enricherFunctionRoot.function(undefined, {
|
|
5991
5999
|
name: "function"
|
|
5992
6000
|
}).parameters("entity", "changeTrackingType").return();
|
|
@@ -6221,6 +6229,8 @@ class SchemaDefinition extends SchemaBase {
|
|
|
6221
6229
|
enricherFunctionBody.get("append").insert(deserializeCodeBuilder.get("result"));
|
|
6222
6230
|
enricherFunctionBody.get("append").insert(deserializeCodeBuilder.get("if"));
|
|
6223
6231
|
enricherFunctionRoot.replace("function", new blocks/* .FunctionBuilder */.kF(undefined).parameters("unserialized", "changeTrackingType").return());
|
|
6232
|
+
// The deserialize slots moved in above call the deserializers bound on their own builder
|
|
6233
|
+
enricherFunctionRoot.parameters(...deserializeCodeBuilder.getBindings());
|
|
6224
6234
|
const postProcessGenerator = this.createReturnFunction(enricherCodeBuilder);
|
|
6225
6235
|
const postProcessParams = enricherFunctionRoot.getParameters();
|
|
6226
6236
|
// Combine prepare and serialize
|
|
@@ -6229,6 +6239,10 @@ class SchemaDefinition extends SchemaBase {
|
|
|
6229
6239
|
preprocessCodeBuilder.get("main").insert(serializeCodeBuilder.get("assignments"));
|
|
6230
6240
|
preprocessCodeBuilder.get("main").insert(serializeCodeBuilder.get("functions"));
|
|
6231
6241
|
preprocessCodeBuilder.get("main").insert(serializeCodeBuilder.get("if"));
|
|
6242
|
+
// Likewise the serialize slots call the serializers bound on the serialize builder
|
|
6243
|
+
for (const binding of serializeCodeBuilder.getBindings()){
|
|
6244
|
+
preprocessCodeBuilder.bind(binding.value, binding.name);
|
|
6245
|
+
}
|
|
6232
6246
|
const getIdsFunction = this.createFunction(idSelectorCodeBuilder, "entity");
|
|
6233
6247
|
const getHashTypeFunction = this.createFunction(hashTypeCodeBuilder, "entity");
|
|
6234
6248
|
const prepareFunction = this.createFunction(prepareCodeBuilder, "entity");
|
|
@@ -6870,6 +6884,8 @@ const s = {
|
|
|
6870
6884
|
|
|
6871
6885
|
|
|
6872
6886
|
|
|
6887
|
+
// EXTERNAL MODULE: ./src/schema/utils/storageDates.ts
|
|
6888
|
+
var storageDates = __webpack_require__(894);
|
|
6873
6889
|
;// CONCATENATED MODULE: ./src/schema/index.ts
|
|
6874
6890
|
|
|
6875
6891
|
|
|
@@ -6882,6 +6898,7 @@ const s = {
|
|
|
6882
6898
|
|
|
6883
6899
|
|
|
6884
6900
|
|
|
6901
|
+
|
|
6885
6902
|
})();
|
|
6886
6903
|
|
|
6887
6904
|
var __webpack_exports__HashType = __webpack_exports__.$H;
|
|
@@ -6918,12 +6935,13 @@ var __webpack_exports__SchemaVector = __webpack_exports__.TF;
|
|
|
6918
6935
|
var __webpack_exports__compiledSchemaToJsonSchema = __webpack_exports__.VG;
|
|
6919
6936
|
var __webpack_exports__createStandardJsonSchemaProps = __webpack_exports__.hM;
|
|
6920
6937
|
var __webpack_exports__extractTypeInfo = __webpack_exports__.Od;
|
|
6938
|
+
var __webpack_exports__getStorageDateReviver = __webpack_exports__.TH;
|
|
6921
6939
|
var __webpack_exports__hasPrimitiveElements = __webpack_exports__.LL;
|
|
6922
6940
|
var __webpack_exports__isArrayValued = __webpack_exports__.ly;
|
|
6923
6941
|
var __webpack_exports__propertyInfoToJsonSchema = __webpack_exports__.UX;
|
|
6924
6942
|
var __webpack_exports__rehydrateSchemaFromJsonSchema = __webpack_exports__.L$;
|
|
6925
6943
|
var __webpack_exports__rehydrateSchemaFromJsonString = __webpack_exports__.Dk;
|
|
6926
6944
|
var __webpack_exports__s = __webpack_exports__.s;
|
|
6927
|
-
export { __webpack_exports__HashType as HashType, __webpack_exports__PropertyInfo as PropertyInfo, __webpack_exports__SchemaArray as SchemaArray, __webpack_exports__SchemaBase as SchemaBase, __webpack_exports__SchemaBoolean as SchemaBoolean, __webpack_exports__SchemaComputed as SchemaComputed, __webpack_exports__SchemaDate as SchemaDate, __webpack_exports__SchemaDefault as SchemaDefault, __webpack_exports__SchemaDefinition as SchemaDefinition, __webpack_exports__SchemaDeserialize as SchemaDeserialize, __webpack_exports__SchemaDistinct as SchemaDistinct, __webpack_exports__SchemaFile as SchemaFile, __webpack_exports__SchemaForeignKey as SchemaForeignKey, __webpack_exports__SchemaFrom as SchemaFrom, __webpack_exports__SchemaFunction as SchemaFunction, __webpack_exports__SchemaIdentity as SchemaIdentity, __webpack_exports__SchemaIndex as SchemaIndex, __webpack_exports__SchemaKey as SchemaKey, __webpack_exports__SchemaNullable as SchemaNullable, __webpack_exports__SchemaNumber as SchemaNumber, __webpack_exports__SchemaObject as SchemaObject, __webpack_exports__SchemaOptional as SchemaOptional, __webpack_exports__SchemaReadonly as SchemaReadonly, __webpack_exports__SchemaSearchable as SchemaSearchable, __webpack_exports__SchemaSerialize as SchemaSerialize, __webpack_exports__SchemaString as SchemaString, __webpack_exports__SchemaTag as SchemaTag, __webpack_exports__SchemaTracked as SchemaTracked, __webpack_exports__SchemaTransform as SchemaTransform, __webpack_exports__SchemaTypes as SchemaTypes, __webpack_exports__SchemaVector as SchemaVector, __webpack_exports__compiledSchemaToJsonSchema as compiledSchemaToJsonSchema, __webpack_exports__createStandardJsonSchemaProps as createStandardJsonSchemaProps, __webpack_exports__extractTypeInfo as extractTypeInfo, __webpack_exports__hasPrimitiveElements as hasPrimitiveElements, __webpack_exports__isArrayValued as isArrayValued, __webpack_exports__propertyInfoToJsonSchema as propertyInfoToJsonSchema, __webpack_exports__rehydrateSchemaFromJsonSchema as rehydrateSchemaFromJsonSchema, __webpack_exports__rehydrateSchemaFromJsonString as rehydrateSchemaFromJsonString, __webpack_exports__s as s };
|
|
6945
|
+
export { __webpack_exports__HashType as HashType, __webpack_exports__PropertyInfo as PropertyInfo, __webpack_exports__SchemaArray as SchemaArray, __webpack_exports__SchemaBase as SchemaBase, __webpack_exports__SchemaBoolean as SchemaBoolean, __webpack_exports__SchemaComputed as SchemaComputed, __webpack_exports__SchemaDate as SchemaDate, __webpack_exports__SchemaDefault as SchemaDefault, __webpack_exports__SchemaDefinition as SchemaDefinition, __webpack_exports__SchemaDeserialize as SchemaDeserialize, __webpack_exports__SchemaDistinct as SchemaDistinct, __webpack_exports__SchemaFile as SchemaFile, __webpack_exports__SchemaForeignKey as SchemaForeignKey, __webpack_exports__SchemaFrom as SchemaFrom, __webpack_exports__SchemaFunction as SchemaFunction, __webpack_exports__SchemaIdentity as SchemaIdentity, __webpack_exports__SchemaIndex as SchemaIndex, __webpack_exports__SchemaKey as SchemaKey, __webpack_exports__SchemaNullable as SchemaNullable, __webpack_exports__SchemaNumber as SchemaNumber, __webpack_exports__SchemaObject as SchemaObject, __webpack_exports__SchemaOptional as SchemaOptional, __webpack_exports__SchemaReadonly as SchemaReadonly, __webpack_exports__SchemaSearchable as SchemaSearchable, __webpack_exports__SchemaSerialize as SchemaSerialize, __webpack_exports__SchemaString as SchemaString, __webpack_exports__SchemaTag as SchemaTag, __webpack_exports__SchemaTracked as SchemaTracked, __webpack_exports__SchemaTransform as SchemaTransform, __webpack_exports__SchemaTypes as SchemaTypes, __webpack_exports__SchemaVector as SchemaVector, __webpack_exports__compiledSchemaToJsonSchema as compiledSchemaToJsonSchema, __webpack_exports__createStandardJsonSchemaProps as createStandardJsonSchemaProps, __webpack_exports__extractTypeInfo as extractTypeInfo, __webpack_exports__getStorageDateReviver as getStorageDateReviver, __webpack_exports__hasPrimitiveElements as hasPrimitiveElements, __webpack_exports__isArrayValued as isArrayValued, __webpack_exports__propertyInfoToJsonSchema as propertyInfoToJsonSchema, __webpack_exports__rehydrateSchemaFromJsonSchema as rehydrateSchemaFromJsonSchema, __webpack_exports__rehydrateSchemaFromJsonString as rehydrateSchemaFromJsonString, __webpack_exports__s as s };
|
|
6928
6946
|
|
|
6929
6947
|
//# sourceMappingURL=index.js.map
|