@routier/core 0.0.5 → 0.0.7
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/capabilities/Capability.d.ts +11 -0
- package/dist/capabilities/PerformanceCapability.d.ts +13 -0
- package/dist/capabilities/TracingCapability.d.ts +11 -0
- package/dist/capabilities/index.d.ts +4 -0
- package/dist/capabilities/index.js +763 -0
- package/dist/capabilities/index.js.map +1 -0
- package/dist/capabilities/performance/PerformanceTracker.d.ts +11 -0
- package/dist/capabilities/tracing/CallTraceManager.d.ts +12 -0
- package/dist/capabilities/types.d.ts +17 -0
- package/dist/codegen/blocks.d.ts +8 -0
- package/dist/codegen/handlers/CompareIdsHandlerBuilder.d.ts +4 -0
- package/dist/codegen/handlers/compare/CompareArrayHandler.d.ts +6 -0
- package/dist/codegen/handlers/compare/CompareDateHandler.d.ts +6 -0
- package/dist/codegen/handlers/compareIds/CompareIdsKeyHandler.d.ts +6 -0
- package/dist/codegen/handlers/index.d.ts +1 -0
- package/dist/codegen/handlers/serialize/SerializeDateHandler.d.ts +2 -1
- package/dist/codegen/handlers/serialize/SerializeFunctionHandler.d.ts +6 -0
- package/dist/codegen/index.js +660 -0
- package/dist/codegen/index.js.map +1 -0
- package/dist/collections/index.js.map +1 -1
- package/dist/expressions/index.js +108 -19
- package/dist/expressions/index.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1406 -602
- package/dist/index.js.map +1 -1
- package/dist/pipeline/WorkPipeline.test.d.ts +1 -0
- package/dist/pipeline/index.js.map +1 -1
- package/dist/plugins/EphemeralDataPlugin.d.ts +2 -2
- package/dist/plugins/EphemeralDataPlugin.test.d.ts +1 -0
- package/dist/plugins/index.d.ts +0 -1
- package/dist/plugins/index.js +244 -483
- package/dist/plugins/index.js.map +1 -1
- package/dist/plugins/query/types.d.ts +5 -0
- package/dist/plugins/replication/OptimisticReplicationDbPlugin.d.ts +2 -1
- package/dist/plugins/replication/ReplicationDbPlugin.d.ts +2 -1
- package/dist/plugins/translators/DataTranslator.d.ts +3 -1
- package/dist/plugins/translators/JsonTranslator.d.ts +1 -0
- package/dist/plugins/translators/SqlTranslator.d.ts +1 -0
- package/dist/plugins/translators/TranslatedArrayValue.d.ts +6 -0
- package/dist/plugins/translators/TranslatedGroupValue.d.ts +6 -0
- package/dist/plugins/translators/TranslatedSingleValue.d.ts +6 -0
- package/dist/plugins/translators/index.d.ts +4 -0
- package/dist/plugins/translators/types.d.ts +10 -0
- package/dist/plugins/types.d.ts +2 -1
- package/dist/schema/PropertyInfo.d.ts +6 -1
- package/dist/schema/SchemaDefinition.d.ts +1 -1
- package/dist/schema/communication/broadcast.d.ts +3 -3
- package/dist/schema/index.js +508 -76
- package/dist/schema/index.js.map +1 -1
- package/dist/schema/property/modifiers/SchemaTracked.d.ts +3 -1
- package/dist/schema/table/SchemaComputed.d.ts +1 -1
- package/dist/schema/testSchemas.test.d.ts +60 -36
- package/dist/schema/types.d.ts +16 -1
- package/dist/utilities/index.js +145 -2
- package/dist/utilities/index.js.map +1 -1
- package/dist/utilities/strings.d.ts +34 -0
- package/dist/utilities/strings.test.d.ts +1 -0
- package/package.json +5 -1
- package/readme.md +1 -1
- package/dist/plugins/capabilities/DbPluginCapability.d.ts +0 -23
- package/dist/plugins/capabilities/index.d.ts +0 -2
- package/dist/plugins/capabilities/logging/DbPluginLoggingCapability.d.ts +0 -28
- package/dist/plugins/capabilities/logging/index.d.ts +0 -1
package/dist/schema/index.js
CHANGED
|
@@ -63,6 +63,24 @@ class Block {
|
|
|
63
63
|
indexOf(name) {
|
|
64
64
|
return this._lines.findIndex(w => typeof w !== "string" && w.name === name);
|
|
65
65
|
}
|
|
66
|
+
getLines() {
|
|
67
|
+
return this._lines;
|
|
68
|
+
}
|
|
69
|
+
getParent() {
|
|
70
|
+
return this._parent;
|
|
71
|
+
}
|
|
72
|
+
getIndent() {
|
|
73
|
+
return this._indent;
|
|
74
|
+
}
|
|
75
|
+
setLines(lines) {
|
|
76
|
+
this._lines = lines;
|
|
77
|
+
}
|
|
78
|
+
setParent(block) {
|
|
79
|
+
this._parent = block;
|
|
80
|
+
}
|
|
81
|
+
setIndent(indent) {
|
|
82
|
+
this._indent = indent;
|
|
83
|
+
}
|
|
66
84
|
getOrDefault(name) {
|
|
67
85
|
if (name.includes('.') === false) {
|
|
68
86
|
return this._lines.find(w => typeof w !== "string" && w.name === name);
|
|
@@ -92,6 +110,27 @@ class Block {
|
|
|
92
110
|
has(name) {
|
|
93
111
|
return this._lines.some(w => typeof w !== "string" && w.name === name);
|
|
94
112
|
}
|
|
113
|
+
remove(name) {
|
|
114
|
+
this._lines = this._lines.filter(x => typeof x === "object" && typeof x.name === "string" && x.name !== name);
|
|
115
|
+
}
|
|
116
|
+
replace(name, line) {
|
|
117
|
+
const foundIndex = this._lines.findIndex(x => typeof x !== "string" && x.name === name);
|
|
118
|
+
if (foundIndex === -1) {
|
|
119
|
+
throw new Error(`Cannot find line by name. Name: ${name}`);
|
|
120
|
+
}
|
|
121
|
+
const found = this._lines[foundIndex];
|
|
122
|
+
if (typeof found === "string") {
|
|
123
|
+
// Replace the line
|
|
124
|
+
this._lines.splice(foundIndex, 1, line);
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
line.setLines(found.getLines());
|
|
128
|
+
line.setIndent(found.getIndent());
|
|
129
|
+
line.setParent(found.getParent());
|
|
130
|
+
// Replace the line
|
|
131
|
+
this._lines.splice(foundIndex, 1, line);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
95
134
|
push(line) {
|
|
96
135
|
this._lines.push(line);
|
|
97
136
|
}
|
|
@@ -522,15 +561,40 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
522
561
|
__webpack_require__.d(__webpack_exports__, {
|
|
523
562
|
CompareHandlerBuilder: () => (CompareHandlerBuilder)
|
|
524
563
|
});
|
|
564
|
+
/* ESM import */var _compare_CompareArrayHandler__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./compare/CompareArrayHandler */ "./src/codegen/handlers/compare/CompareArrayHandler.ts");
|
|
565
|
+
/* ESM import */var _compare_CompareDateHandler__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./compare/CompareDateHandler */ "./src/codegen/handlers/compare/CompareDateHandler.ts");
|
|
525
566
|
/* ESM import */var _compare_CompareObjectHandler__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./compare/CompareObjectHandler */ "./src/codegen/handlers/compare/CompareObjectHandler.ts");
|
|
526
|
-
/* ESM import */var
|
|
567
|
+
/* ESM import */var _compare_CompareValueHandler__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./compare/CompareValueHandler */ "./src/codegen/handlers/compare/CompareValueHandler.ts");
|
|
568
|
+
|
|
569
|
+
|
|
527
570
|
|
|
528
571
|
|
|
529
|
-
/// Purpose:
|
|
530
572
|
class CompareHandlerBuilder {
|
|
531
573
|
build() {
|
|
532
574
|
const handler = new _compare_CompareObjectHandler__WEBPACK_IMPORTED_MODULE_0__.CompareObjectHandler();
|
|
533
|
-
handler.setNext(new
|
|
575
|
+
handler.setNext(new _compare_CompareArrayHandler__WEBPACK_IMPORTED_MODULE_1__.CompareArrayHandler())
|
|
576
|
+
.setNext(new _compare_CompareDateHandler__WEBPACK_IMPORTED_MODULE_2__.CompareDateHandler())
|
|
577
|
+
.setNext(new _compare_CompareValueHandler__WEBPACK_IMPORTED_MODULE_3__.CompareValueHandler());
|
|
578
|
+
return handler;
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
|
|
583
|
+
}),
|
|
584
|
+
"./src/codegen/handlers/CompareIdsHandlerBuilder.ts":
|
|
585
|
+
/*!**********************************************************!*\
|
|
586
|
+
!*** ./src/codegen/handlers/CompareIdsHandlerBuilder.ts ***!
|
|
587
|
+
\**********************************************************/
|
|
588
|
+
(function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
|
|
589
|
+
__webpack_require__.r(__webpack_exports__);
|
|
590
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
591
|
+
CompareIdsHandlerBuilder: () => (CompareIdsHandlerBuilder)
|
|
592
|
+
});
|
|
593
|
+
/* ESM import */var _compareIds_CompareIdsKeyHandler__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./compareIds/CompareIdsKeyHandler */ "./src/codegen/handlers/compareIds/CompareIdsKeyHandler.ts");
|
|
594
|
+
|
|
595
|
+
class CompareIdsHandlerBuilder {
|
|
596
|
+
build() {
|
|
597
|
+
const handler = new _compareIds_CompareIdsKeyHandler__WEBPACK_IMPORTED_MODULE_0__.CompareIdsKeyHandler();
|
|
534
598
|
return handler;
|
|
535
599
|
}
|
|
536
600
|
}
|
|
@@ -828,10 +892,12 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
828
892
|
__webpack_require__.d(__webpack_exports__, {
|
|
829
893
|
SerializeHandlerBuilder: () => (SerializeHandlerBuilder)
|
|
830
894
|
});
|
|
831
|
-
/* ESM import */var
|
|
832
|
-
/* ESM import */var
|
|
833
|
-
/* ESM import */var
|
|
895
|
+
/* ESM import */var _serialize_SerializeDateHandler__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./serialize/SerializeDateHandler */ "./src/codegen/handlers/serialize/SerializeDateHandler.ts");
|
|
896
|
+
/* ESM import */var _serialize_SerializeObjectHandler__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./serialize/SerializeObjectHandler */ "./src/codegen/handlers/serialize/SerializeObjectHandler.ts");
|
|
897
|
+
/* ESM import */var _serialize_SerializeValueHandler__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./serialize/SerializeValueHandler */ "./src/codegen/handlers/serialize/SerializeValueHandler.ts");
|
|
834
898
|
/* ESM import */var _serialize_SerializeSerializerHandler__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./serialize/SerializeSerializerHandler */ "./src/codegen/handlers/serialize/SerializeSerializerHandler.ts");
|
|
899
|
+
/* ESM import */var _serialize_SerializeFunctionHandler__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./serialize/SerializeFunctionHandler */ "./src/codegen/handlers/serialize/SerializeFunctionHandler.ts");
|
|
900
|
+
|
|
835
901
|
|
|
836
902
|
|
|
837
903
|
|
|
@@ -841,9 +907,10 @@ class SerializeHandlerBuilder {
|
|
|
841
907
|
build() {
|
|
842
908
|
const handler = new _serialize_SerializeSerializerHandler__WEBPACK_IMPORTED_MODULE_0__.SerializeSerializerHandler();
|
|
843
909
|
handler
|
|
844
|
-
.setNext(new
|
|
845
|
-
.setNext(new
|
|
846
|
-
.setNext(new
|
|
910
|
+
.setNext(new _serialize_SerializeFunctionHandler__WEBPACK_IMPORTED_MODULE_1__.SerializeFunctionHandler())
|
|
911
|
+
.setNext(new _serialize_SerializeDateHandler__WEBPACK_IMPORTED_MODULE_2__.SerializeDateHandler())
|
|
912
|
+
.setNext(new _serialize_SerializeValueHandler__WEBPACK_IMPORTED_MODULE_3__.SerializeValueHandler())
|
|
913
|
+
.setNext(new _serialize_SerializeObjectHandler__WEBPACK_IMPORTED_MODULE_4__.SerializeObjectHandler());
|
|
847
914
|
return handler;
|
|
848
915
|
}
|
|
849
916
|
}
|
|
@@ -900,10 +967,11 @@ class CloneArrayHandler extends _types__WEBPACK_IMPORTED_MODULE_0__.PropertyInfo
|
|
|
900
967
|
// Child properties will take care of this
|
|
901
968
|
return builder;
|
|
902
969
|
}
|
|
903
|
-
const
|
|
904
|
-
const resultAssignmentPath = property.getAssignmentPath({ parent: "result" });
|
|
970
|
+
const entitySelectorPath = property.getSelectrorPath({ parent: "entity" });
|
|
905
971
|
if (property.parent == null) {
|
|
906
|
-
|
|
972
|
+
const resultAssignmentPath = property.getAssignmentPath({ parent: "result" });
|
|
973
|
+
const slot = builder.get("if");
|
|
974
|
+
slot.if(`${entitySelectorPath} != null`).appendBody(`${resultAssignmentPath} = [...${entitySelectorPath}]`);
|
|
907
975
|
return builder;
|
|
908
976
|
}
|
|
909
977
|
// slotPath.push(...property.getParentPathArray());
|
|
@@ -980,6 +1048,74 @@ class CloneValueHandler extends _types__WEBPACK_IMPORTED_MODULE_0__.PropertyInfo
|
|
|
980
1048
|
}
|
|
981
1049
|
|
|
982
1050
|
|
|
1051
|
+
}),
|
|
1052
|
+
"./src/codegen/handlers/compare/CompareArrayHandler.ts":
|
|
1053
|
+
/*!*************************************************************!*\
|
|
1054
|
+
!*** ./src/codegen/handlers/compare/CompareArrayHandler.ts ***!
|
|
1055
|
+
\*************************************************************/
|
|
1056
|
+
(function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
|
|
1057
|
+
__webpack_require__.r(__webpack_exports__);
|
|
1058
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
1059
|
+
CompareArrayHandler: () => (CompareArrayHandler)
|
|
1060
|
+
});
|
|
1061
|
+
/* ESM import */var _types__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../types */ "./src/codegen/handlers/types.ts");
|
|
1062
|
+
/* ESM import */var _schema__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../../schema */ "./src/schema/types.ts");
|
|
1063
|
+
|
|
1064
|
+
|
|
1065
|
+
class CompareArrayHandler extends _types__WEBPACK_IMPORTED_MODULE_0__.PropertyInfoHandler {
|
|
1066
|
+
handle(property, builder) {
|
|
1067
|
+
if (property.type === _schema__WEBPACK_IMPORTED_MODULE_1__.SchemaTypes.Array) {
|
|
1068
|
+
let compare = builder.getOrDefault("result.variable.compare");
|
|
1069
|
+
const leftCompare = property.getSelectrorPath({ parent: "a" });
|
|
1070
|
+
const rightCompare = property.getSelectrorPath({ parent: "b" });
|
|
1071
|
+
if (compare == null) {
|
|
1072
|
+
compare = builder.get("result")
|
|
1073
|
+
.assign("const result", { name: "variable" })
|
|
1074
|
+
.and(`JSON.stringify(${leftCompare}) === JSON.stringify(${rightCompare})`, { name: "compareArray" });
|
|
1075
|
+
return builder;
|
|
1076
|
+
}
|
|
1077
|
+
compare.and(`JSON.stringify(${leftCompare}) === JSON.stringify(${rightCompare})`);
|
|
1078
|
+
return builder;
|
|
1079
|
+
}
|
|
1080
|
+
return super.handle(property, builder);
|
|
1081
|
+
}
|
|
1082
|
+
}
|
|
1083
|
+
|
|
1084
|
+
|
|
1085
|
+
}),
|
|
1086
|
+
"./src/codegen/handlers/compare/CompareDateHandler.ts":
|
|
1087
|
+
/*!************************************************************!*\
|
|
1088
|
+
!*** ./src/codegen/handlers/compare/CompareDateHandler.ts ***!
|
|
1089
|
+
\************************************************************/
|
|
1090
|
+
(function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
|
|
1091
|
+
__webpack_require__.r(__webpack_exports__);
|
|
1092
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
1093
|
+
CompareDateHandler: () => (CompareDateHandler)
|
|
1094
|
+
});
|
|
1095
|
+
/* ESM import */var _types__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../types */ "./src/codegen/handlers/types.ts");
|
|
1096
|
+
/* ESM import */var _schema__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../../schema */ "./src/schema/types.ts");
|
|
1097
|
+
|
|
1098
|
+
|
|
1099
|
+
class CompareDateHandler extends _types__WEBPACK_IMPORTED_MODULE_0__.PropertyInfoHandler {
|
|
1100
|
+
handle(property, builder) {
|
|
1101
|
+
if (property.type === _schema__WEBPACK_IMPORTED_MODULE_1__.SchemaTypes.Date) {
|
|
1102
|
+
let compare = builder.getOrDefault("result.variable.compare");
|
|
1103
|
+
const leftCompare = property.getSelectrorPath({ parent: "a" });
|
|
1104
|
+
const rightCompare = property.getSelectrorPath({ parent: "b" });
|
|
1105
|
+
if (compare == null) {
|
|
1106
|
+
compare = builder.get("result")
|
|
1107
|
+
.assign("const result", { name: "variable" })
|
|
1108
|
+
.and(`${leftCompare}?.toISOString() === ${rightCompare}?.toISOString()`, { name: "compareDate" });
|
|
1109
|
+
return builder;
|
|
1110
|
+
}
|
|
1111
|
+
compare.and(`${leftCompare}?.toISOString() === ${rightCompare}?.toISOString()`);
|
|
1112
|
+
return builder;
|
|
1113
|
+
}
|
|
1114
|
+
return super.handle(property, builder);
|
|
1115
|
+
}
|
|
1116
|
+
}
|
|
1117
|
+
|
|
1118
|
+
|
|
983
1119
|
}),
|
|
984
1120
|
"./src/codegen/handlers/compare/CompareObjectHandler.ts":
|
|
985
1121
|
/*!**************************************************************!*\
|
|
@@ -1038,6 +1174,32 @@ class CompareValueHandler extends _types__WEBPACK_IMPORTED_MODULE_0__.PropertyIn
|
|
|
1038
1174
|
}
|
|
1039
1175
|
|
|
1040
1176
|
|
|
1177
|
+
}),
|
|
1178
|
+
"./src/codegen/handlers/compareIds/CompareIdsKeyHandler.ts":
|
|
1179
|
+
/*!*****************************************************************!*\
|
|
1180
|
+
!*** ./src/codegen/handlers/compareIds/CompareIdsKeyHandler.ts ***!
|
|
1181
|
+
\*****************************************************************/
|
|
1182
|
+
(function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
|
|
1183
|
+
__webpack_require__.r(__webpack_exports__);
|
|
1184
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
1185
|
+
CompareIdsKeyHandler: () => (CompareIdsKeyHandler)
|
|
1186
|
+
});
|
|
1187
|
+
/* ESM import */var _types__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../types */ "./src/codegen/handlers/types.ts");
|
|
1188
|
+
|
|
1189
|
+
class CompareIdsKeyHandler extends _types__WEBPACK_IMPORTED_MODULE_0__.PropertyInfoHandler {
|
|
1190
|
+
handle(property, builder) {
|
|
1191
|
+
if (property.isKey) {
|
|
1192
|
+
const slot = builder.get("ifs");
|
|
1193
|
+
const leftCompare = property.getSelectrorPath({ parent: "a" });
|
|
1194
|
+
const rightCompare = property.getSelectrorPath({ parent: "b" });
|
|
1195
|
+
slot.if(`${leftCompare} != ${rightCompare}`).appendBody("return false;");
|
|
1196
|
+
return builder;
|
|
1197
|
+
}
|
|
1198
|
+
return super.handle(property, builder);
|
|
1199
|
+
}
|
|
1200
|
+
}
|
|
1201
|
+
|
|
1202
|
+
|
|
1041
1203
|
}),
|
|
1042
1204
|
"./src/codegen/handlers/deserialize/DeserializeComputedValueHandler.ts":
|
|
1043
1205
|
/*!*****************************************************************************!*\
|
|
@@ -1087,8 +1249,8 @@ class DeserializeDateHandler extends _types__WEBPACK_IMPORTED_MODULE_0__.Propert
|
|
|
1087
1249
|
if (property.type === _schema__WEBPACK_IMPORTED_MODULE_1__.SchemaTypes.Date) {
|
|
1088
1250
|
const slotPath = new _SlotPath__WEBPACK_IMPORTED_MODULE_2__.SlotPath("result.variable.object");
|
|
1089
1251
|
let objectBuilder = builder.get(slotPath.get());
|
|
1090
|
-
const entitySelectorPath = property.getSelectrorPath({ parent: "
|
|
1091
|
-
const entityAssignmentPath = property.getAssignmentPath({ parent: "
|
|
1252
|
+
const entitySelectorPath = property.getSelectrorPath({ parent: "unserialized" });
|
|
1253
|
+
const entityAssignmentPath = property.getAssignmentPath({ parent: "entity", useFromPropertyName: property.isRenamed });
|
|
1092
1254
|
const assignment = `${property.name}: typeof ${entitySelectorPath} === "string" ? new Date(${entitySelectorPath}) : ${entitySelectorPath}`;
|
|
1093
1255
|
// if it is nullable or optional, assign in an if block, otherwise we
|
|
1094
1256
|
// could unintentionally assign null/undefined to a property that does not exist
|
|
@@ -1132,10 +1294,10 @@ class DeserializeDeserializerHandler extends _types__WEBPACK_IMPORTED_MODULE_0__
|
|
|
1132
1294
|
if (property.valueDeserializer != null) {
|
|
1133
1295
|
let objectBuilder = builder.getOrDefault("result.variable.object");
|
|
1134
1296
|
const assignmentBuilder = builder.getOrDefault("functions");
|
|
1135
|
-
const entitySelectorPath = property.getSelectrorPath({ parent: "
|
|
1297
|
+
const entitySelectorPath = property.getSelectrorPath({ parent: "unserialized" });
|
|
1136
1298
|
if (objectBuilder == null) {
|
|
1137
1299
|
objectBuilder = builder.get("result")
|
|
1138
|
-
.assign("const
|
|
1300
|
+
.assign("const entity", { name: "variable" })
|
|
1139
1301
|
.object({ name: "object" });
|
|
1140
1302
|
}
|
|
1141
1303
|
const defaultFunctionWithParameters = this.toNamedFunction(property.valueDeserializer.toString(), assignmentBuilder);
|
|
@@ -1201,12 +1363,12 @@ class DeserializeObjectHandler extends _types__WEBPACK_IMPORTED_MODULE_0__.Prope
|
|
|
1201
1363
|
const slotPath = new _SlotPath__WEBPACK_IMPORTED_MODULE_2__.SlotPath("result.variable.object");
|
|
1202
1364
|
let objectBuilder = builder.get(slotPath.get());
|
|
1203
1365
|
if (property.parent == null) {
|
|
1204
|
-
objectBuilder.nested(property.
|
|
1366
|
+
objectBuilder.nested(property.getResolvedName(), property.name);
|
|
1205
1367
|
return builder;
|
|
1206
1368
|
}
|
|
1207
1369
|
slotPath.push(...property.getParentPathArray());
|
|
1208
1370
|
const nestedObjectBuilder = builder.get(slotPath.get());
|
|
1209
|
-
nestedObjectBuilder.nested(property.
|
|
1371
|
+
nestedObjectBuilder.nested(property.getResolvedName(), property.name);
|
|
1210
1372
|
return builder;
|
|
1211
1373
|
}
|
|
1212
1374
|
return super.handle(property, builder);
|
|
@@ -1234,10 +1396,10 @@ class DeserializeValueHandler extends _types__WEBPACK_IMPORTED_MODULE_0__.Proper
|
|
|
1234
1396
|
handle(property, builder) {
|
|
1235
1397
|
if (property.type != _schema__WEBPACK_IMPORTED_MODULE_1__.SchemaTypes.Object && property.type != _schema__WEBPACK_IMPORTED_MODULE_1__.SchemaTypes.Date) {
|
|
1236
1398
|
let objectBuilder = builder.getOrDefault("result.variable.object");
|
|
1237
|
-
const entitySelectorPath = property.getAssignmentPath({ parent: "
|
|
1399
|
+
const entitySelectorPath = property.getAssignmentPath({ parent: "unserialized", useFromPropertyName: property.isRenamed });
|
|
1238
1400
|
if (objectBuilder == null) {
|
|
1239
1401
|
objectBuilder = builder.get("result")
|
|
1240
|
-
.assign("const
|
|
1402
|
+
.assign("const entity", { name: "variable" })
|
|
1241
1403
|
.object({ name: "object" });
|
|
1242
1404
|
}
|
|
1243
1405
|
if (property.parent == null) {
|
|
@@ -2250,14 +2412,17 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
2250
2412
|
|
|
2251
2413
|
|
|
2252
2414
|
/**
|
|
2253
|
-
* Handles converting a Date value from JavaScript to a string value
|
|
2415
|
+
* Handles converting a Date value from JavaScript to a string value. Should handle remapping here because it is the lowest level in the code here.
|
|
2416
|
+
* Remapping higher up could break lower level code
|
|
2254
2417
|
*/
|
|
2255
2418
|
class SerializeDateHandler extends _types__WEBPACK_IMPORTED_MODULE_0__.PropertyInfoHandler {
|
|
2256
2419
|
handle(property, builder) {
|
|
2257
2420
|
if (property.type === _schema__WEBPACK_IMPORTED_MODULE_1__.SchemaTypes.Date) {
|
|
2258
2421
|
let objectBuilder = builder.get("if");
|
|
2259
|
-
const entitySelectorPath = property.getSelectrorPath({ parent: "entity" });
|
|
2260
|
-
const entityAssignmentPath = property.getAssignmentPath({
|
|
2422
|
+
const entitySelectorPath = property.getSelectrorPath({ parent: "entity", useFromPropertyName: property.isRenamed });
|
|
2423
|
+
const entityAssignmentPath = property.getAssignmentPath({
|
|
2424
|
+
parent: "result"
|
|
2425
|
+
});
|
|
2261
2426
|
const assignment = `${property.name}: ${entitySelectorPath} instanceof Date ? ${entitySelectorPath}.toISOString() : ${entitySelectorPath}`;
|
|
2262
2427
|
// if it is nullable or optional, assign in an if block, otherwise we
|
|
2263
2428
|
// could unintentionally assign null/undefined to a property that does not exist
|
|
@@ -2284,6 +2449,31 @@ class SerializeDateHandler extends _types__WEBPACK_IMPORTED_MODULE_0__.PropertyI
|
|
|
2284
2449
|
}
|
|
2285
2450
|
|
|
2286
2451
|
|
|
2452
|
+
}),
|
|
2453
|
+
"./src/codegen/handlers/serialize/SerializeFunctionHandler.ts":
|
|
2454
|
+
/*!********************************************************************!*\
|
|
2455
|
+
!*** ./src/codegen/handlers/serialize/SerializeFunctionHandler.ts ***!
|
|
2456
|
+
\********************************************************************/
|
|
2457
|
+
(function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
|
|
2458
|
+
__webpack_require__.r(__webpack_exports__);
|
|
2459
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
2460
|
+
SerializeFunctionHandler: () => (SerializeFunctionHandler)
|
|
2461
|
+
});
|
|
2462
|
+
/* ESM import */var _types__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../types */ "./src/codegen/handlers/types.ts");
|
|
2463
|
+
/* ESM import */var _schema__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../../schema */ "./src/schema/types.ts");
|
|
2464
|
+
|
|
2465
|
+
|
|
2466
|
+
class SerializeFunctionHandler extends _types__WEBPACK_IMPORTED_MODULE_0__.PropertyInfoHandler {
|
|
2467
|
+
handle(property, builder) {
|
|
2468
|
+
if (property.functionBody != null && property.type === _schema__WEBPACK_IMPORTED_MODULE_1__.SchemaTypes.Function) {
|
|
2469
|
+
// Functions should not be serialized
|
|
2470
|
+
return builder;
|
|
2471
|
+
}
|
|
2472
|
+
return super.handle(property, builder);
|
|
2473
|
+
}
|
|
2474
|
+
}
|
|
2475
|
+
|
|
2476
|
+
|
|
2287
2477
|
}),
|
|
2288
2478
|
"./src/codegen/handlers/serialize/SerializeObjectHandler.ts":
|
|
2289
2479
|
/*!******************************************************************!*\
|
|
@@ -2304,7 +2494,9 @@ class SerializeObjectHandler extends _types__WEBPACK_IMPORTED_MODULE_0__.Propert
|
|
|
2304
2494
|
handle(property, builder) {
|
|
2305
2495
|
if (property.type === _schema__WEBPACK_IMPORTED_MODULE_1__.SchemaTypes.Object) {
|
|
2306
2496
|
const slotPath = new _SlotPath__WEBPACK_IMPORTED_MODULE_2__.SlotPath("assignments");
|
|
2307
|
-
const childPath = property.getAssignmentPath({
|
|
2497
|
+
const childPath = property.getAssignmentPath({
|
|
2498
|
+
parent: "result"
|
|
2499
|
+
});
|
|
2308
2500
|
if (property.isNullable || property.isOptional) {
|
|
2309
2501
|
// Do nothing if it's nullable or optional as property assignments will check
|
|
2310
2502
|
// and create if it does not exist. This way we can handle null/optional
|
|
@@ -2336,7 +2528,7 @@ class SerializeSerializerHandler extends _types__WEBPACK_IMPORTED_MODULE_0__.Pro
|
|
|
2336
2528
|
if (property.valueSerializer != null) {
|
|
2337
2529
|
const objectBuilder = builder.getOrDefault("if");
|
|
2338
2530
|
const assignmentBuilder = builder.getOrDefault("functions");
|
|
2339
|
-
const entitySelectorPath = property.getAssignmentPath({ parent: "entity" });
|
|
2531
|
+
const entitySelectorPath = property.getAssignmentPath({ parent: "entity", useFromPropertyName: property.isRenamed });
|
|
2340
2532
|
const resultSelectorPath = property.getAssignmentPath({ parent: "result" });
|
|
2341
2533
|
const defaultFunctionWithParameters = this.toNamedFunction(property.valueSerializer.toString(), assignmentBuilder);
|
|
2342
2534
|
defaultFunctionWithParameters.builder.parameters(...defaultFunctionWithParameters.parameters.map((_, i) => ({ name: defaultFunctionWithParameters.parameters[i], callName: entitySelectorPath })));
|
|
@@ -2376,7 +2568,7 @@ class SerializeValueHandler extends _types__WEBPACK_IMPORTED_MODULE_0__.Property
|
|
|
2376
2568
|
handle(property, builder) {
|
|
2377
2569
|
if (property.type != _schema__WEBPACK_IMPORTED_MODULE_1__.SchemaTypes.Object && property.type != _schema__WEBPACK_IMPORTED_MODULE_1__.SchemaTypes.Date) {
|
|
2378
2570
|
const slot = builder.getOrDefault("if");
|
|
2379
|
-
const entitySelectorPath = property.getAssignmentPath({ parent: "entity" });
|
|
2571
|
+
const entitySelectorPath = property.getAssignmentPath({ parent: "entity", useFromPropertyName: property.isRenamed });
|
|
2380
2572
|
const resultSelectorPath = property.getAssignmentPath({ parent: "result" });
|
|
2381
2573
|
if (property.parent == null) {
|
|
2382
2574
|
// Only assign if the incoming entity has the property, this allows partial serialization
|
|
@@ -2575,14 +2767,13 @@ class PropertyInfoHandler {
|
|
|
2575
2767
|
return result;
|
|
2576
2768
|
}
|
|
2577
2769
|
setEnrichedProperty(property, root) {
|
|
2578
|
-
const
|
|
2579
|
-
const entitySelectorPath = property.getAssignmentPath({ parent: "entity", useFromPropertyName });
|
|
2770
|
+
const entitySelectorPath = property.getAssignmentPath({ parent: "entity" });
|
|
2580
2771
|
if (property.parent != null) {
|
|
2581
2772
|
const slotPath = new _SlotPath__WEBPACK_IMPORTED_MODULE_1__.SlotPath("factory", "function", "enriched", "object", "enriched");
|
|
2582
2773
|
const path = property.parent.getAssignmentPath({ parent: "enriched" });
|
|
2583
2774
|
slotPath.push(`[${path}]`);
|
|
2584
2775
|
const objectBuilder = root.get(slotPath.get());
|
|
2585
|
-
const childEntityPathSelector = property.getSelectrorPath({ parent: "entity"
|
|
2776
|
+
const childEntityPathSelector = property.getSelectrorPath({ parent: "entity" });
|
|
2586
2777
|
objectBuilder.property(`${property.name}: ${childEntityPathSelector}`);
|
|
2587
2778
|
return;
|
|
2588
2779
|
}
|
|
@@ -2770,10 +2961,16 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
2770
2961
|
__webpack_require__.d(__webpack_exports__, {
|
|
2771
2962
|
PropertyInfo: () => (PropertyInfo)
|
|
2772
2963
|
});
|
|
2773
|
-
/* ESM import */var
|
|
2774
|
-
/* ESM import */var
|
|
2964
|
+
/* ESM import */var _property_types_SchemaArray__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./property/types/SchemaArray */ "./src/schema/property/types/SchemaArray.ts");
|
|
2965
|
+
/* ESM import */var _types__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./types */ "./src/schema/types.ts");
|
|
2775
2966
|
|
|
2776
2967
|
|
|
2968
|
+
const SUPPORTED_DESERIALIZATION_TYPES = new Set([
|
|
2969
|
+
_types__WEBPACK_IMPORTED_MODULE_0__.SchemaTypes.Boolean,
|
|
2970
|
+
_types__WEBPACK_IMPORTED_MODULE_0__.SchemaTypes.Date,
|
|
2971
|
+
_types__WEBPACK_IMPORTED_MODULE_0__.SchemaTypes.Number,
|
|
2972
|
+
_types__WEBPACK_IMPORTED_MODULE_0__.SchemaTypes.String,
|
|
2973
|
+
]);
|
|
2777
2974
|
/**
|
|
2778
2975
|
* Represents metadata and utilities for a property in a schema, including its type, name, parent, children, and serialization details.
|
|
2779
2976
|
*/
|
|
@@ -2839,7 +3036,7 @@ class PropertyInfo {
|
|
|
2839
3036
|
this.name = name;
|
|
2840
3037
|
this.type = schema.type;
|
|
2841
3038
|
this.literals = schema.literals;
|
|
2842
|
-
if (schema instanceof
|
|
3039
|
+
if (schema instanceof _property_types_SchemaArray__WEBPACK_IMPORTED_MODULE_1__.SchemaArray) {
|
|
2843
3040
|
this.innerSchema = schema.innerSchema;
|
|
2844
3041
|
}
|
|
2845
3042
|
this.isNullable = schema.isNullable;
|
|
@@ -2883,6 +3080,12 @@ class PropertyInfo {
|
|
|
2883
3080
|
this._levelCache = level;
|
|
2884
3081
|
return level;
|
|
2885
3082
|
}
|
|
3083
|
+
get isRenamed() {
|
|
3084
|
+
return !!this.from;
|
|
3085
|
+
}
|
|
3086
|
+
get supportsDeserialization() {
|
|
3087
|
+
return this.valueDeserializer != null || SUPPORTED_DESERIALIZATION_TYPES.has(this.type);
|
|
3088
|
+
}
|
|
2886
3089
|
_getPropertyChain() {
|
|
2887
3090
|
if (this._propertyChainCache) {
|
|
2888
3091
|
return this._propertyChainCache;
|
|
@@ -2912,6 +3115,9 @@ class PropertyInfo {
|
|
|
2912
3115
|
}
|
|
2913
3116
|
return path;
|
|
2914
3117
|
}
|
|
3118
|
+
getResolvedName() {
|
|
3119
|
+
return this.from ?? this.name;
|
|
3120
|
+
}
|
|
2915
3121
|
/**
|
|
2916
3122
|
* Returns an array of property names representing the path from the root to this property.
|
|
2917
3123
|
*
|
|
@@ -2996,12 +3202,17 @@ class PropertyInfo {
|
|
|
2996
3202
|
return null;
|
|
2997
3203
|
}
|
|
2998
3204
|
const pathArray = this.getPathArray();
|
|
3205
|
+
const length = pathArray.length;
|
|
3206
|
+
// Fast path for single level properties
|
|
3207
|
+
if (length === 1) {
|
|
3208
|
+
return instance[pathArray[0]];
|
|
3209
|
+
}
|
|
2999
3210
|
let current = instance;
|
|
3000
|
-
for (
|
|
3211
|
+
for (let i = 0; i < length; i++) {
|
|
3001
3212
|
if (current == null) {
|
|
3002
3213
|
return null;
|
|
3003
3214
|
}
|
|
3004
|
-
current = current[
|
|
3215
|
+
current = current[pathArray[i]];
|
|
3005
3216
|
}
|
|
3006
3217
|
return current;
|
|
3007
3218
|
}
|
|
@@ -3048,8 +3259,8 @@ class PropertyInfo {
|
|
|
3048
3259
|
getSelectrorPath(options) {
|
|
3049
3260
|
const parts = this._resolvePathArray({
|
|
3050
3261
|
root: options.parent,
|
|
3051
|
-
assignmentType: options
|
|
3052
|
-
useFromPropertyName: options
|
|
3262
|
+
assignmentType: options?.assignmentType,
|
|
3263
|
+
useFromPropertyName: options?.useFromPropertyName
|
|
3053
3264
|
});
|
|
3054
3265
|
return parts.join("");
|
|
3055
3266
|
}
|
|
@@ -3074,16 +3285,16 @@ class PropertyInfo {
|
|
|
3074
3285
|
if (this.valueDeserializer != null) {
|
|
3075
3286
|
return this.valueDeserializer(value);
|
|
3076
3287
|
}
|
|
3077
|
-
if (this.type ===
|
|
3288
|
+
if (this.type === _types__WEBPACK_IMPORTED_MODULE_0__.SchemaTypes.Date) {
|
|
3078
3289
|
return new Date(value);
|
|
3079
3290
|
}
|
|
3080
|
-
if (this.type ===
|
|
3291
|
+
if (this.type === _types__WEBPACK_IMPORTED_MODULE_0__.SchemaTypes.String) {
|
|
3081
3292
|
return String(value);
|
|
3082
3293
|
}
|
|
3083
|
-
if (this.type ===
|
|
3294
|
+
if (this.type === _types__WEBPACK_IMPORTED_MODULE_0__.SchemaTypes.Number) {
|
|
3084
3295
|
return Number(value);
|
|
3085
3296
|
}
|
|
3086
|
-
if (this.type ===
|
|
3297
|
+
if (this.type === _types__WEBPACK_IMPORTED_MODULE_0__.SchemaTypes.Boolean) {
|
|
3087
3298
|
return Boolean(value);
|
|
3088
3299
|
}
|
|
3089
3300
|
throw new Error(`Unsupported deserialization for type. Type: ${this.type}`);
|
|
@@ -3105,7 +3316,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
3105
3316
|
/* ESM import */var _table_SchemaComputed__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./table/SchemaComputed */ "./src/schema/table/SchemaComputed.ts");
|
|
3106
3317
|
/* ESM import */var _property_base_SchemaBase__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./property/base/SchemaBase */ "./src/schema/property/base/SchemaBase.ts");
|
|
3107
3318
|
/* ESM import */var _PropertyInfo__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./PropertyInfo */ "./src/schema/PropertyInfo.ts");
|
|
3108
|
-
/* ESM import */var
|
|
3319
|
+
/* ESM import */var _codegen__WEBPACK_IMPORTED_MODULE_19__ = __webpack_require__(/*! ../codegen */ "./src/codegen/blocks.ts");
|
|
3109
3320
|
/* ESM import */var _codegen_handlers_EnrichmentHandlerBuilder__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../codegen/handlers/EnrichmentHandlerBuilder */ "./src/codegen/handlers/EnrichmentHandlerBuilder.ts");
|
|
3110
3321
|
/* ESM import */var _codegen_handlers_MergeHandlerBuilder__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../codegen/handlers/MergeHandlerBuilder */ "./src/codegen/handlers/MergeHandlerBuilder.ts");
|
|
3111
3322
|
/* ESM import */var _codegen_handlers_PrepareHandlerBuilder__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../codegen/handlers/PrepareHandlerBuilder */ "./src/codegen/handlers/PrepareHandlerBuilder.ts");
|
|
@@ -3118,11 +3329,13 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
3118
3329
|
/* ESM import */var _codegen_handlers_HashHandlerBuilder__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ../codegen/handlers/HashHandlerBuilder */ "./src/codegen/handlers/HashHandlerBuilder.ts");
|
|
3119
3330
|
/* ESM import */var _codegen_handlers_EnableChangeTrackingHandlerBuilder__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(/*! ../codegen/handlers/EnableChangeTrackingHandlerBuilder */ "./src/codegen/handlers/EnableChangeTrackingHandlerBuilder.ts");
|
|
3120
3331
|
/* ESM import */var _codegen_handlers_FreezeHandlerBuilder__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(/*! ../codegen/handlers/FreezeHandlerBuilder */ "./src/codegen/handlers/FreezeHandlerBuilder.ts");
|
|
3121
|
-
/* ESM import */var
|
|
3332
|
+
/* ESM import */var _errors_SchemaError__WEBPACK_IMPORTED_MODULE_22__ = __webpack_require__(/*! ../errors/SchemaError */ "./src/errors/SchemaError.ts");
|
|
3122
3333
|
/* ESM import */var _codegen_handlers_SerializeHandlerBuilder__WEBPACK_IMPORTED_MODULE_17__ = __webpack_require__(/*! ../codegen/handlers/SerializeHandlerBuilder */ "./src/codegen/handlers/SerializeHandlerBuilder.ts");
|
|
3123
|
-
/* ESM import */var
|
|
3334
|
+
/* ESM import */var _utilities__WEBPACK_IMPORTED_MODULE_20__ = __webpack_require__(/*! ../utilities */ "./src/utilities/strings.ts");
|
|
3124
3335
|
/* ESM import */var _types__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./types */ "./src/schema/types.ts");
|
|
3125
|
-
/* ESM import */var
|
|
3336
|
+
/* ESM import */var _communication_broadcast__WEBPACK_IMPORTED_MODULE_21__ = __webpack_require__(/*! ./communication/broadcast */ "./src/schema/communication/broadcast.ts");
|
|
3337
|
+
/* ESM import */var _codegen_handlers_CompareIdsHandlerBuilder__WEBPACK_IMPORTED_MODULE_18__ = __webpack_require__(/*! ../codegen/handlers/CompareIdsHandlerBuilder */ "./src/codegen/handlers/CompareIdsHandlerBuilder.ts");
|
|
3338
|
+
|
|
3126
3339
|
|
|
3127
3340
|
|
|
3128
3341
|
|
|
@@ -3307,6 +3520,7 @@ class SchemaDefinition extends _property_base_SchemaBase__WEBPACK_IMPORTED_MODUL
|
|
|
3307
3520
|
const enableChangeTrackingHandlerBuilder = new _codegen_handlers_EnableChangeTrackingHandlerBuilder__WEBPACK_IMPORTED_MODULE_15__.EnableChangeTrackingHandlerBuilder();
|
|
3308
3521
|
const freezeHandlerBuilder = new _codegen_handlers_FreezeHandlerBuilder__WEBPACK_IMPORTED_MODULE_16__.FreezeHandlerBuilder();
|
|
3309
3522
|
const serializeHandlerBuilder = new _codegen_handlers_SerializeHandlerBuilder__WEBPACK_IMPORTED_MODULE_17__.SerializeHandlerBuilder();
|
|
3523
|
+
const compareIdsHandlerBuilder = new _codegen_handlers_CompareIdsHandlerBuilder__WEBPACK_IMPORTED_MODULE_18__.CompareIdsHandlerBuilder();
|
|
3310
3524
|
const enricher = enrichmentHandlerBuilder.build();
|
|
3311
3525
|
const merge = mergeHandlerFactory.build();
|
|
3312
3526
|
const prepare = prepareHandlerBuilder.build();
|
|
@@ -3320,26 +3534,36 @@ class SchemaDefinition extends _property_base_SchemaBase__WEBPACK_IMPORTED_MODUL
|
|
|
3320
3534
|
const enableChangeTrackingHandler = enableChangeTrackingHandlerBuilder.build();
|
|
3321
3535
|
const freezeHandler = freezeHandlerBuilder.build();
|
|
3322
3536
|
const serializeHandler = serializeHandlerBuilder.build();
|
|
3323
|
-
const
|
|
3537
|
+
const compareIdsHandler = compareIdsHandlerBuilder.build();
|
|
3538
|
+
const changeTrackingCodeBuilder = new _codegen__WEBPACK_IMPORTED_MODULE_19__.CodeBuilder();
|
|
3324
3539
|
changeTrackingCodeBuilder.raw(`function ${this.createChangeTracker.toString()}`);
|
|
3325
3540
|
changeTrackingCodeBuilder.slot("declarations").variable("enableChangeTracking").value('createChangeTracker()');
|
|
3326
3541
|
changeTrackingCodeBuilder.slot("assignment");
|
|
3327
3542
|
changeTrackingCodeBuilder.slot("return").raw('\treturn enableChangeTracking(entity);');
|
|
3328
|
-
const freezeCodeBuilder = new
|
|
3543
|
+
const freezeCodeBuilder = new _codegen__WEBPACK_IMPORTED_MODULE_19__.CodeBuilder();
|
|
3329
3544
|
freezeCodeBuilder.slot("assignment");
|
|
3330
3545
|
freezeCodeBuilder.slot("return").raw('\treturn Object.freeze(entity);');
|
|
3331
|
-
const enricherCodeBuilder = new
|
|
3546
|
+
const enricherCodeBuilder = new _codegen__WEBPACK_IMPORTED_MODULE_19__.CodeBuilder();
|
|
3332
3547
|
const enricherFunctionRoot = enricherCodeBuilder.factory("factory", { name: "factory" }).parameters({ name: "collectionName", value: this.collectionName });
|
|
3333
3548
|
const enricherFunctionBody = enricherFunctionRoot.function(undefined, { name: "function" }).parameters("entity", "changeTrackingType").return();
|
|
3334
|
-
enricherFunctionBody.raw(
|
|
3335
|
-
enricherFunctionBody.
|
|
3549
|
+
enricherFunctionBody.slot("changeTracker").raw(`\tfunction ${this.createChangeTracker.toString()}`);
|
|
3550
|
+
enricherFunctionBody.slot("enableChangeTracking")
|
|
3551
|
+
.variable("enableChangeTracking")
|
|
3552
|
+
.value('changeTrackingType === "proxy" ? createChangeTracker() : e => e');
|
|
3553
|
+
enricherFunctionBody.slot("append");
|
|
3336
3554
|
enricherFunctionBody.slot("enriched");
|
|
3337
3555
|
enricherFunctionBody.slot("declarations");
|
|
3338
3556
|
enricherFunctionBody.slot("assignment");
|
|
3339
3557
|
enricherFunctionBody.slot("ifs");
|
|
3340
3558
|
enricherFunctionBody.slot("tracking").if('changeTrackingType === "immutable"', { name: "freeze" });
|
|
3341
|
-
enricherFunctionBody.raw('\treturn enableChangeTracking(enriched);');
|
|
3342
|
-
const
|
|
3559
|
+
enricherFunctionBody.slot("return").raw('\treturn enableChangeTracking(enriched);');
|
|
3560
|
+
const preprocessCodeBuilder = new _codegen__WEBPACK_IMPORTED_MODULE_19__.CodeBuilder();
|
|
3561
|
+
preprocessCodeBuilder.slot("main");
|
|
3562
|
+
preprocessCodeBuilder.slot("return").raw(` return result;`);
|
|
3563
|
+
const postprocessCodeBuilder = new _codegen__WEBPACK_IMPORTED_MODULE_19__.CodeBuilder();
|
|
3564
|
+
postprocessCodeBuilder.slot("main");
|
|
3565
|
+
postprocessCodeBuilder.slot("return").raw(` return result;`);
|
|
3566
|
+
const mergeCodeBuilder = new _codegen__WEBPACK_IMPORTED_MODULE_19__.CodeBuilder();
|
|
3343
3567
|
const mergeFunctionRoot = mergeCodeBuilder.factory("factory", { name: "factory" }).parameters({ name: "collectionName", value: this.collectionName });
|
|
3344
3568
|
const mergeFunctionBody = mergeFunctionRoot.function(undefined, { name: "function" }).parameters("destination", "source").return();
|
|
3345
3569
|
const pauseFunctionBody = mergeFunctionBody.function("pause")
|
|
@@ -3358,40 +3582,43 @@ class SchemaDefinition extends _property_base_SchemaBase__WEBPACK_IMPORTED_MODUL
|
|
|
3358
3582
|
unpause();
|
|
3359
3583
|
|
|
3360
3584
|
return destination;`);
|
|
3361
|
-
const prepareCodeBuilder = new
|
|
3585
|
+
const prepareCodeBuilder = new _codegen__WEBPACK_IMPORTED_MODULE_19__.CodeBuilder();
|
|
3362
3586
|
prepareCodeBuilder.slot("result");
|
|
3363
3587
|
prepareCodeBuilder.slot("assignments");
|
|
3364
3588
|
prepareCodeBuilder.slot("return").raw(` return result;`);
|
|
3365
|
-
const stripCodeBuilder = new
|
|
3589
|
+
const stripCodeBuilder = new _codegen__WEBPACK_IMPORTED_MODULE_19__.CodeBuilder();
|
|
3366
3590
|
stripCodeBuilder.slot("result");
|
|
3367
3591
|
stripCodeBuilder.slot("return").raw(` return result;`);
|
|
3368
|
-
const cloneCodeBuilder = new
|
|
3592
|
+
const cloneCodeBuilder = new _codegen__WEBPACK_IMPORTED_MODULE_19__.CodeBuilder();
|
|
3369
3593
|
cloneCodeBuilder.slot("result").raw("const result = {};");
|
|
3370
3594
|
;
|
|
3371
3595
|
cloneCodeBuilder.slot("assignments");
|
|
3372
3596
|
cloneCodeBuilder.slot("if");
|
|
3373
3597
|
cloneCodeBuilder.slot("return").raw(` return result;`);
|
|
3374
|
-
const compareCodeBuilder = new
|
|
3598
|
+
const compareCodeBuilder = new _codegen__WEBPACK_IMPORTED_MODULE_19__.CodeBuilder();
|
|
3375
3599
|
compareCodeBuilder.slot("result");
|
|
3376
3600
|
compareCodeBuilder.slot("return").raw(` return result;`);
|
|
3377
|
-
const
|
|
3601
|
+
const compareIdsCodeBuilder = new _codegen__WEBPACK_IMPORTED_MODULE_19__.CodeBuilder();
|
|
3602
|
+
compareIdsCodeBuilder.slot("ifs");
|
|
3603
|
+
compareIdsCodeBuilder.slot("return").raw(` return true;`);
|
|
3604
|
+
const deserializeCodeBuilder = new _codegen__WEBPACK_IMPORTED_MODULE_19__.CodeBuilder();
|
|
3378
3605
|
deserializeCodeBuilder.slot("functions");
|
|
3379
3606
|
deserializeCodeBuilder.slot("result");
|
|
3380
3607
|
deserializeCodeBuilder.slot("if");
|
|
3381
|
-
deserializeCodeBuilder.slot("return").raw(` return
|
|
3382
|
-
const serializeCodeBuilder = new
|
|
3608
|
+
deserializeCodeBuilder.slot("return").raw(` return entity;`);
|
|
3609
|
+
const serializeCodeBuilder = new _codegen__WEBPACK_IMPORTED_MODULE_19__.CodeBuilder();
|
|
3383
3610
|
serializeCodeBuilder.slot("result").raw("const result = {};");
|
|
3384
3611
|
serializeCodeBuilder.slot("assignments");
|
|
3385
3612
|
serializeCodeBuilder.slot("functions");
|
|
3386
3613
|
serializeCodeBuilder.slot("if");
|
|
3387
3614
|
serializeCodeBuilder.slot("return").raw(` return result;`);
|
|
3388
|
-
const idSelectorCodeBuilder = new
|
|
3615
|
+
const idSelectorCodeBuilder = new _codegen__WEBPACK_IMPORTED_MODULE_19__.CodeBuilder();
|
|
3389
3616
|
idSelectorCodeBuilder.slot("result");
|
|
3390
3617
|
idSelectorCodeBuilder.slot("return").raw(` return result;`);
|
|
3391
|
-
const hashTypeCodeBuilder = new
|
|
3618
|
+
const hashTypeCodeBuilder = new _codegen__WEBPACK_IMPORTED_MODULE_19__.CodeBuilder();
|
|
3392
3619
|
hashTypeCodeBuilder.slot("ifs");
|
|
3393
3620
|
hashTypeCodeBuilder.slot("return").raw(` return "Ids";`);
|
|
3394
|
-
const hashCodeBuilder = new
|
|
3621
|
+
const hashCodeBuilder = new _codegen__WEBPACK_IMPORTED_MODULE_19__.CodeBuilder();
|
|
3395
3622
|
hashCodeBuilder.slot("functions").raw(`
|
|
3396
3623
|
function stringifyDate(d) {
|
|
3397
3624
|
|
|
@@ -3446,6 +3673,7 @@ class SchemaDefinition extends _property_base_SchemaBase__WEBPACK_IMPORTED_MODUL
|
|
|
3446
3673
|
hashHandler.handle(property, hashCodeBuilder);
|
|
3447
3674
|
enableChangeTrackingHandler.handle(property, changeTrackingCodeBuilder);
|
|
3448
3675
|
freezeHandler.handle(property, freezeCodeBuilder);
|
|
3676
|
+
compareIdsHandler.handle(property, compareIdsCodeBuilder);
|
|
3449
3677
|
});
|
|
3450
3678
|
if (idProperties.length === 0) {
|
|
3451
3679
|
throw new Error(`Schema must have a key. Use .key() to mark a property as a key. Collection Name: ${this.collectionName}`);
|
|
@@ -3454,20 +3682,36 @@ class SchemaDefinition extends _property_base_SchemaBase__WEBPACK_IMPORTED_MODUL
|
|
|
3454
3682
|
const mergeParams = mergeFunctionRoot.getParameters();
|
|
3455
3683
|
const enrichGenerator = Function(`return ${enricherCodeBuilder.toString()}`);
|
|
3456
3684
|
const mergeGenerator = Function(`return ${mergeCodeBuilder.toString()}`);
|
|
3685
|
+
// After enricher is used, we modify it to be deserialize and enrich
|
|
3686
|
+
enricherFunctionBody.get("append").insert(deserializeCodeBuilder.get("functions"));
|
|
3687
|
+
enricherFunctionBody.get("append").insert(deserializeCodeBuilder.get("result"));
|
|
3688
|
+
enricherFunctionBody.get("append").insert(deserializeCodeBuilder.get("if"));
|
|
3689
|
+
enricherFunctionRoot.replace("function", new _codegen__WEBPACK_IMPORTED_MODULE_19__.FunctionBuilder(undefined).parameters("unserialized", "changeTrackingType").return());
|
|
3690
|
+
const postProcessGenerator = Function(`return ${enricherCodeBuilder.toString()}`);
|
|
3691
|
+
const postProcessParams = enricherFunctionRoot.getParameters();
|
|
3692
|
+
// Combine prepare and serialize
|
|
3693
|
+
preprocessCodeBuilder.get("main").insert(prepareCodeBuilder.get("result"));
|
|
3694
|
+
preprocessCodeBuilder.get("main").insert(prepareCodeBuilder.get("assignments"));
|
|
3695
|
+
preprocessCodeBuilder.get("main").insert(serializeCodeBuilder.get("assignments"));
|
|
3696
|
+
preprocessCodeBuilder.get("main").insert(serializeCodeBuilder.get("functions"));
|
|
3697
|
+
preprocessCodeBuilder.get("main").insert(serializeCodeBuilder.get("if"));
|
|
3457
3698
|
const getIdsFunction = Function("entity", idSelectorCodeBuilder.toString());
|
|
3458
3699
|
const getHashTypeFunction = Function("entity", hashTypeCodeBuilder.toString());
|
|
3459
3700
|
const prepareFunction = Function("entity", prepareCodeBuilder.toString());
|
|
3460
3701
|
const cloneFunction = Function("entity", cloneCodeBuilder.toString());
|
|
3461
|
-
const deserializeFunction = Function("
|
|
3702
|
+
const deserializeFunction = Function("unserialized", deserializeCodeBuilder.toString());
|
|
3462
3703
|
const serializeFunction = Function("entity", serializeCodeBuilder.toString());
|
|
3463
3704
|
const compareFunction = Function("a", "b", compareCodeBuilder.toString());
|
|
3464
|
-
;
|
|
3465
3705
|
const stripFunction = Function("entity", stripCodeBuilder.toString());
|
|
3466
3706
|
const hashFunction = Function("entity", "type", hashCodeBuilder.toString());
|
|
3467
3707
|
const enableChangeTrackingFunction = Function("entity", changeTrackingCodeBuilder.toString());
|
|
3468
3708
|
const freezeFunction = Function("entity", freezeCodeBuilder.toString());
|
|
3709
|
+
const compareIdsFunction = Function("a", "b", compareIdsCodeBuilder.toString());
|
|
3710
|
+
const preprocessFunction = Function("entity", preprocessCodeBuilder.toString());
|
|
3469
3711
|
const enricherFactoryFunction = enrichGenerator();
|
|
3712
|
+
const postProcessFactoryFunction = postProcessGenerator();
|
|
3470
3713
|
const mergeFactoryFunction = mergeGenerator();
|
|
3714
|
+
const postProcessFunction = postProcessFactoryFunction(...postProcessParams.map(w => w.value));
|
|
3471
3715
|
const enricherFunction = enricherFactoryFunction(...enrichParams.map(w => w.value));
|
|
3472
3716
|
const mergeFunction = mergeFactoryFunction(...mergeParams.map(w => w.value));
|
|
3473
3717
|
const idPropertyNames = idProperties.map(w => w.name);
|
|
@@ -3478,7 +3722,7 @@ class SchemaDefinition extends _property_base_SchemaBase__WEBPACK_IMPORTED_MODUL
|
|
|
3478
3722
|
return getIdsFunction(entity)[0];
|
|
3479
3723
|
};
|
|
3480
3724
|
const getProperty = (id) => propertyMap.get(id);
|
|
3481
|
-
const id = (0,
|
|
3725
|
+
const id = (0,_utilities__WEBPACK_IMPORTED_MODULE_20__.hash)([...allPropertyNamesAndPaths, this.collectionName].join(","));
|
|
3482
3726
|
// memoize this by the validProperties
|
|
3483
3727
|
// TODO: See if we can generate a function to do this and eliminate loops
|
|
3484
3728
|
const deserializePartial = (item, properties) => {
|
|
@@ -3493,8 +3737,9 @@ class SchemaDefinition extends _property_base_SchemaBase__WEBPACK_IMPORTED_MODUL
|
|
|
3493
3737
|
}
|
|
3494
3738
|
return item;
|
|
3495
3739
|
};
|
|
3496
|
-
|
|
3497
|
-
|
|
3740
|
+
const result = {
|
|
3741
|
+
preprocess: preprocessFunction,
|
|
3742
|
+
postprocess: postProcessFunction,
|
|
3498
3743
|
getId,
|
|
3499
3744
|
getProperty,
|
|
3500
3745
|
properties,
|
|
@@ -3509,6 +3754,7 @@ class SchemaDefinition extends _property_base_SchemaBase__WEBPACK_IMPORTED_MODUL
|
|
|
3509
3754
|
deserialize: deserializeFunction,
|
|
3510
3755
|
serialize: serializeFunction,
|
|
3511
3756
|
compare: compareFunction,
|
|
3757
|
+
compareIds: compareIdsFunction,
|
|
3512
3758
|
strip: stripFunction,
|
|
3513
3759
|
hash: hashFunction,
|
|
3514
3760
|
id,
|
|
@@ -3570,9 +3816,13 @@ class SchemaDefinition extends _property_base_SchemaBase__WEBPACK_IMPORTED_MODUL
|
|
|
3570
3816
|
return indexes;
|
|
3571
3817
|
}
|
|
3572
3818
|
};
|
|
3819
|
+
return {
|
|
3820
|
+
createSubscription: (signal) => new _communication_broadcast__WEBPACK_IMPORTED_MODULE_21__.SchemaSubscription(result, signal),
|
|
3821
|
+
...result
|
|
3822
|
+
};
|
|
3573
3823
|
}
|
|
3574
3824
|
catch (e) {
|
|
3575
|
-
throw new
|
|
3825
|
+
throw new _errors_SchemaError__WEBPACK_IMPORTED_MODULE_22__.SchemaError(e, `Error compiling schema for collection: ${this.collectionName}`);
|
|
3576
3826
|
}
|
|
3577
3827
|
}
|
|
3578
3828
|
}
|
|
@@ -3688,43 +3938,81 @@ class SubscriptionListener {
|
|
|
3688
3938
|
}
|
|
3689
3939
|
class SchemaSubscription {
|
|
3690
3940
|
id;
|
|
3691
|
-
|
|
3941
|
+
schema;
|
|
3692
3942
|
createdAt;
|
|
3693
|
-
constructor(
|
|
3943
|
+
constructor(schema, signal) {
|
|
3694
3944
|
this.createdAt = (0,_performance__WEBPACK_IMPORTED_MODULE_0__.now)();
|
|
3695
3945
|
this.id = (0,_utilities__WEBPACK_IMPORTED_MODULE_1__.uuid)(8);
|
|
3696
|
-
this.
|
|
3946
|
+
this.schema = schema;
|
|
3697
3947
|
signal?.addEventListener("abort", () => {
|
|
3698
3948
|
this.dispose();
|
|
3699
3949
|
}, { once: true });
|
|
3700
3950
|
}
|
|
3701
3951
|
send(changes) {
|
|
3702
|
-
const regisry = getChannelRegistry(this.
|
|
3952
|
+
const regisry = getChannelRegistry(this.schema.id);
|
|
3953
|
+
// cannot send raw data, needs to be preprocessed
|
|
3954
|
+
const preprocessedChanges = {
|
|
3955
|
+
adds: new Array(changes.adds.length),
|
|
3956
|
+
removals: new Array(changes.removals.length),
|
|
3957
|
+
unknown: new Array(changes.unknown.length),
|
|
3958
|
+
updates: new Array(changes.updates.length),
|
|
3959
|
+
};
|
|
3960
|
+
for (let i = 0, length = changes.adds.length; i < length; i++) {
|
|
3961
|
+
preprocessedChanges.adds[i] = this.schema.preprocess(changes.adds[i]);
|
|
3962
|
+
}
|
|
3963
|
+
for (let i = 0, length = changes.removals.length; i < length; i++) {
|
|
3964
|
+
preprocessedChanges.removals[i] = this.schema.preprocess(changes.removals[i]);
|
|
3965
|
+
}
|
|
3966
|
+
for (let i = 0, length = changes.unknown.length; i < length; i++) {
|
|
3967
|
+
preprocessedChanges.unknown[i] = this.schema.preprocess(changes.unknown[i]);
|
|
3968
|
+
}
|
|
3969
|
+
for (let i = 0, length = changes.updates.length; i < length; i++) {
|
|
3970
|
+
preprocessedChanges.updates[i] = this.schema.preprocess(changes.updates[i]);
|
|
3971
|
+
}
|
|
3703
3972
|
// Send message to all listeners.
|
|
3704
3973
|
// Since we create a new listener when we do onMessage,
|
|
3705
3974
|
// we don't need to worry about sending to ourselves, it
|
|
3706
3975
|
// can't happen
|
|
3707
3976
|
regisry.sender.send({
|
|
3708
|
-
data:
|
|
3977
|
+
data: preprocessedChanges,
|
|
3709
3978
|
timestamp: (0,_performance__WEBPACK_IMPORTED_MODULE_0__.now)()
|
|
3710
3979
|
});
|
|
3711
3980
|
}
|
|
3712
3981
|
onMessage(callback) {
|
|
3713
|
-
const regisry = getChannelRegistry(this.
|
|
3982
|
+
const regisry = getChannelRegistry(this.schema.id);
|
|
3714
3983
|
// Link the callback to an instance
|
|
3715
3984
|
regisry.receiver.addListener(this.id, ({ data, timestamp }) => {
|
|
3716
3985
|
if (timestamp < this.createdAt) {
|
|
3717
3986
|
// Sent before the receiver was even created
|
|
3718
3987
|
return;
|
|
3719
3988
|
}
|
|
3720
|
-
|
|
3989
|
+
// Changes were preprocessed before they were sent, need to postprocess them
|
|
3990
|
+
const postProcessedChanges = {
|
|
3991
|
+
adds: new Array(data.adds.length),
|
|
3992
|
+
removals: new Array(data.removals.length),
|
|
3993
|
+
unknown: new Array(data.unknown.length),
|
|
3994
|
+
updates: new Array(data.updates.length),
|
|
3995
|
+
};
|
|
3996
|
+
for (let i = 0, length = data.adds.length; i < length; i++) {
|
|
3997
|
+
postProcessedChanges.adds[i] = this.schema.preprocess(data.adds[i]);
|
|
3998
|
+
}
|
|
3999
|
+
for (let i = 0, length = data.removals.length; i < length; i++) {
|
|
4000
|
+
postProcessedChanges.removals[i] = this.schema.preprocess(data.removals[i]);
|
|
4001
|
+
}
|
|
4002
|
+
for (let i = 0, length = data.unknown.length; i < length; i++) {
|
|
4003
|
+
postProcessedChanges.unknown[i] = this.schema.preprocess(data.unknown[i]);
|
|
4004
|
+
}
|
|
4005
|
+
for (let i = 0, length = data.updates.length; i < length; i++) {
|
|
4006
|
+
postProcessedChanges.updates[i] = this.schema.preprocess(data.updates[i]);
|
|
4007
|
+
}
|
|
4008
|
+
callback(postProcessedChanges);
|
|
3721
4009
|
});
|
|
3722
4010
|
}
|
|
3723
4011
|
dispose() {
|
|
3724
4012
|
this[Symbol.dispose]();
|
|
3725
4013
|
}
|
|
3726
4014
|
[Symbol.dispose]() {
|
|
3727
|
-
const regisry = getChannelRegistry(this.
|
|
4015
|
+
const regisry = getChannelRegistry(this.schema.id);
|
|
3728
4016
|
// Remove listeners for this instance only
|
|
3729
4017
|
regisry.receiver.removeListeners(this.id);
|
|
3730
4018
|
}
|
|
@@ -4222,6 +4510,8 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
4222
4510
|
SchemaTracked: () => (SchemaTracked)
|
|
4223
4511
|
});
|
|
4224
4512
|
/* ESM import */var _base_SchemaBase__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../base/SchemaBase */ "./src/schema/property/base/SchemaBase.ts");
|
|
4513
|
+
/* ESM import */var _SchemaKey__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./SchemaKey */ "./src/schema/property/modifiers/SchemaKey.ts");
|
|
4514
|
+
|
|
4225
4515
|
|
|
4226
4516
|
class SchemaTracked extends _base_SchemaBase__WEBPACK_IMPORTED_MODULE_0__.SchemaBase {
|
|
4227
4517
|
instance;
|
|
@@ -4231,6 +4521,9 @@ class SchemaTracked extends _base_SchemaBase__WEBPACK_IMPORTED_MODULE_0__.Schema
|
|
|
4231
4521
|
this.instance = current.instance;
|
|
4232
4522
|
this.isUnmapped = false;
|
|
4233
4523
|
}
|
|
4524
|
+
key() {
|
|
4525
|
+
return new _SchemaKey__WEBPACK_IMPORTED_MODULE_1__.SchemaKey(this);
|
|
4526
|
+
}
|
|
4234
4527
|
}
|
|
4235
4528
|
|
|
4236
4529
|
|
|
@@ -4844,7 +5137,9 @@ var HashType;
|
|
|
4844
5137
|
(function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
|
|
4845
5138
|
__webpack_require__.r(__webpack_exports__);
|
|
4846
5139
|
__webpack_require__.d(__webpack_exports__, {
|
|
4847
|
-
|
|
5140
|
+
fastHash: () => (fastHash),
|
|
5141
|
+
hash: () => (hash),
|
|
5142
|
+
stringifyObject: () => (stringifyObject)
|
|
4848
5143
|
});
|
|
4849
5144
|
const hash = (value, seed = 0) => {
|
|
4850
5145
|
// From Stack Overflow
|
|
@@ -4861,6 +5156,143 @@ const hash = (value, seed = 0) => {
|
|
|
4861
5156
|
h2 ^= Math.imul(h1 ^ (h1 >>> 13), 3266489909);
|
|
4862
5157
|
return 4294967296 * (2097151 & h2) + (h1 >>> 0);
|
|
4863
5158
|
};
|
|
5159
|
+
/**
|
|
5160
|
+
* Fast string hash optimized for comparisons.
|
|
5161
|
+
* Uses djb2 algorithm - very fast and good distribution for short to medium strings.
|
|
5162
|
+
* Same input always produces same output (deterministic).
|
|
5163
|
+
*
|
|
5164
|
+
* @param value - The string to hash
|
|
5165
|
+
* @param seed - Optional seed value (default: 5381)
|
|
5166
|
+
* @returns A positive 32-bit integer hash value
|
|
5167
|
+
*
|
|
5168
|
+
* @example
|
|
5169
|
+
* ```ts
|
|
5170
|
+
* fastHash("test") === fastHash("test") // true
|
|
5171
|
+
* fastHash("test") !== fastHash("test2") // true
|
|
5172
|
+
* ```
|
|
5173
|
+
*/
|
|
5174
|
+
const fastHash = (value, seed = 5381) => {
|
|
5175
|
+
let hash = seed;
|
|
5176
|
+
for (let i = 0; i < value.length; i++) {
|
|
5177
|
+
hash = ((hash << 5) + hash) + value.charCodeAt(i);
|
|
5178
|
+
}
|
|
5179
|
+
return hash >>> 0; // Convert to unsigned 32-bit integer
|
|
5180
|
+
};
|
|
5181
|
+
/**
|
|
5182
|
+
* Converts any value to a readable string representation.
|
|
5183
|
+
* Handles primitives, objects, arrays, classes, dates, errors, and functions.
|
|
5184
|
+
* Supports depth limiting to prevent infinite recursion on circular references.
|
|
5185
|
+
*
|
|
5186
|
+
* @param obj - The value to stringify
|
|
5187
|
+
* @param maxDepth - Maximum depth for nested objects (default: 3)
|
|
5188
|
+
* @param currentDepth - Current recursion depth (default: 0)
|
|
5189
|
+
* @returns String representation of the value
|
|
5190
|
+
*
|
|
5191
|
+
* @example
|
|
5192
|
+
* ```ts
|
|
5193
|
+
* stringifyObject({ name: "test", count: 5 }) // '{ name: "test", count: 5 }'
|
|
5194
|
+
* stringifyObject([1, 2, 3]) // '[1, 2, 3]'
|
|
5195
|
+
* stringifyObject(new Date()) // 'Date(2024-01-01T00:00:00.000Z)'
|
|
5196
|
+
* ```
|
|
5197
|
+
*/
|
|
5198
|
+
function stringifyObject(obj, maxDepth = 3, currentDepth = 0) {
|
|
5199
|
+
if (obj === null)
|
|
5200
|
+
return 'null';
|
|
5201
|
+
if (obj === undefined)
|
|
5202
|
+
return 'undefined';
|
|
5203
|
+
const type = typeof obj;
|
|
5204
|
+
switch (type) {
|
|
5205
|
+
case 'string':
|
|
5206
|
+
return `"${obj}"`;
|
|
5207
|
+
case 'number':
|
|
5208
|
+
case 'boolean':
|
|
5209
|
+
return String(obj);
|
|
5210
|
+
case 'function':
|
|
5211
|
+
return `[Function: ${getFunctionName(obj)}]`;
|
|
5212
|
+
case 'object':
|
|
5213
|
+
if (currentDepth >= maxDepth) {
|
|
5214
|
+
return '[Max Depth Reached]';
|
|
5215
|
+
}
|
|
5216
|
+
return stringifyObjectValue(obj, maxDepth, currentDepth);
|
|
5217
|
+
default:
|
|
5218
|
+
return `[${type}]`;
|
|
5219
|
+
}
|
|
5220
|
+
}
|
|
5221
|
+
function getFunctionName(fn) {
|
|
5222
|
+
const name = fn.name;
|
|
5223
|
+
return name || 'anonymous';
|
|
5224
|
+
}
|
|
5225
|
+
function getObjectProperties(obj) {
|
|
5226
|
+
const properties = {};
|
|
5227
|
+
for (const key in obj) {
|
|
5228
|
+
if (obj.hasOwnProperty(key)) {
|
|
5229
|
+
properties[key] = obj[key];
|
|
5230
|
+
}
|
|
5231
|
+
}
|
|
5232
|
+
return properties;
|
|
5233
|
+
}
|
|
5234
|
+
function stringifyObjectValue(obj, maxDepth, currentDepth) {
|
|
5235
|
+
if (obj === null)
|
|
5236
|
+
return 'null';
|
|
5237
|
+
if (obj instanceof Date) {
|
|
5238
|
+
return `Date(${obj.toISOString()})`;
|
|
5239
|
+
}
|
|
5240
|
+
if (obj instanceof Error) {
|
|
5241
|
+
return `Error(${obj.message})`;
|
|
5242
|
+
}
|
|
5243
|
+
if (obj instanceof RegExp) {
|
|
5244
|
+
return obj.toString();
|
|
5245
|
+
}
|
|
5246
|
+
if (Array.isArray(obj)) {
|
|
5247
|
+
return stringifyArray(obj, maxDepth, currentDepth);
|
|
5248
|
+
}
|
|
5249
|
+
if (obj.constructor && obj.constructor.name !== 'Object') {
|
|
5250
|
+
return stringifyClassInstance(obj, maxDepth, currentDepth);
|
|
5251
|
+
}
|
|
5252
|
+
return stringifyPlainObject(obj, maxDepth, currentDepth);
|
|
5253
|
+
}
|
|
5254
|
+
function stringifyArray(arr, maxDepth, currentDepth) {
|
|
5255
|
+
if (arr.length === 0)
|
|
5256
|
+
return '[]';
|
|
5257
|
+
const items = arr.slice(0, 5).map(item => stringifyObject(item, maxDepth, currentDepth + 1));
|
|
5258
|
+
const suffix = arr.length > 5 ? `... (+${arr.length - 5} more)` : '';
|
|
5259
|
+
return `[${items.join(', ')}${suffix}]`;
|
|
5260
|
+
}
|
|
5261
|
+
function stringifyClassInstance(obj, maxDepth, currentDepth) {
|
|
5262
|
+
const className = obj.constructor.name;
|
|
5263
|
+
const properties = getObjectProperties(obj);
|
|
5264
|
+
if (Object.keys(properties).length === 0) {
|
|
5265
|
+
return `${className} {}`;
|
|
5266
|
+
}
|
|
5267
|
+
const props = Object.entries(properties)
|
|
5268
|
+
.slice(0, 5)
|
|
5269
|
+
.map(([key, value]) => {
|
|
5270
|
+
const isPrimitive = value === null || value === undefined ||
|
|
5271
|
+
(typeof value !== 'object' && typeof value !== 'function');
|
|
5272
|
+
const depth = isPrimitive ? currentDepth : currentDepth + 1;
|
|
5273
|
+
return `${key}: ${stringifyObject(value, maxDepth, depth)}`;
|
|
5274
|
+
});
|
|
5275
|
+
const suffix = Object.keys(properties).length > 5 ?
|
|
5276
|
+
`... (+${Object.keys(properties).length - 5} more)` : '';
|
|
5277
|
+
return `${className} { ${props.join(', ')}${suffix} }`;
|
|
5278
|
+
}
|
|
5279
|
+
function stringifyPlainObject(obj, maxDepth, currentDepth) {
|
|
5280
|
+
const properties = getObjectProperties(obj);
|
|
5281
|
+
if (Object.keys(properties).length === 0) {
|
|
5282
|
+
return '{}';
|
|
5283
|
+
}
|
|
5284
|
+
const props = Object.entries(properties)
|
|
5285
|
+
.slice(0, 5)
|
|
5286
|
+
.map(([key, value]) => {
|
|
5287
|
+
const isPrimitive = value === null || value === undefined ||
|
|
5288
|
+
(typeof value !== 'object' && typeof value !== 'function');
|
|
5289
|
+
const depth = isPrimitive ? currentDepth : currentDepth + 1;
|
|
5290
|
+
return `${key}: ${stringifyObject(value, maxDepth, depth)}`;
|
|
5291
|
+
});
|
|
5292
|
+
const suffix = Object.keys(properties).length > 5 ?
|
|
5293
|
+
`... (+${Object.keys(properties).length - 5} more)` : '';
|
|
5294
|
+
return `{ ${props.join(', ')}${suffix} }`;
|
|
5295
|
+
}
|
|
4864
5296
|
|
|
4865
5297
|
|
|
4866
5298
|
}),
|