@routier/core 0.0.6 → 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 +6 -16
- package/dist/capabilities/PerformanceCapability.d.ts +4 -6
- package/dist/capabilities/TracingCapability.d.ts +3 -6
- package/dist/capabilities/index.js +399 -343
- package/dist/capabilities/index.js.map +1 -1
- package/dist/capabilities/types.d.ts +10 -19
- 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 +39 -0
- package/dist/codegen/index.js.map +1 -1
- 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.js +1105 -496
- package/dist/index.js.map +1 -1
- package/dist/pipeline/TrampolinePipeline.d.ts +1 -0
- package/dist/pipeline/index.js +71 -47
- package/dist/pipeline/index.js.map +1 -1
- package/dist/plugins/EphemeralDataPlugin.d.ts +2 -2
- package/dist/plugins/index.js +251 -61
- 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 +504 -73
- 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 +1 -1
- package/readme.md +1 -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
|
}
|
|
@@ -981,6 +1048,74 @@ class CloneValueHandler extends _types__WEBPACK_IMPORTED_MODULE_0__.PropertyInfo
|
|
|
981
1048
|
}
|
|
982
1049
|
|
|
983
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
|
+
|
|
984
1119
|
}),
|
|
985
1120
|
"./src/codegen/handlers/compare/CompareObjectHandler.ts":
|
|
986
1121
|
/*!**************************************************************!*\
|
|
@@ -1039,6 +1174,32 @@ class CompareValueHandler extends _types__WEBPACK_IMPORTED_MODULE_0__.PropertyIn
|
|
|
1039
1174
|
}
|
|
1040
1175
|
|
|
1041
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
|
+
|
|
1042
1203
|
}),
|
|
1043
1204
|
"./src/codegen/handlers/deserialize/DeserializeComputedValueHandler.ts":
|
|
1044
1205
|
/*!*****************************************************************************!*\
|
|
@@ -1088,8 +1249,8 @@ class DeserializeDateHandler extends _types__WEBPACK_IMPORTED_MODULE_0__.Propert
|
|
|
1088
1249
|
if (property.type === _schema__WEBPACK_IMPORTED_MODULE_1__.SchemaTypes.Date) {
|
|
1089
1250
|
const slotPath = new _SlotPath__WEBPACK_IMPORTED_MODULE_2__.SlotPath("result.variable.object");
|
|
1090
1251
|
let objectBuilder = builder.get(slotPath.get());
|
|
1091
|
-
const entitySelectorPath = property.getSelectrorPath({ parent: "
|
|
1092
|
-
const entityAssignmentPath = property.getAssignmentPath({ parent: "
|
|
1252
|
+
const entitySelectorPath = property.getSelectrorPath({ parent: "unserialized" });
|
|
1253
|
+
const entityAssignmentPath = property.getAssignmentPath({ parent: "entity", useFromPropertyName: property.isRenamed });
|
|
1093
1254
|
const assignment = `${property.name}: typeof ${entitySelectorPath} === "string" ? new Date(${entitySelectorPath}) : ${entitySelectorPath}`;
|
|
1094
1255
|
// if it is nullable or optional, assign in an if block, otherwise we
|
|
1095
1256
|
// could unintentionally assign null/undefined to a property that does not exist
|
|
@@ -1133,10 +1294,10 @@ class DeserializeDeserializerHandler extends _types__WEBPACK_IMPORTED_MODULE_0__
|
|
|
1133
1294
|
if (property.valueDeserializer != null) {
|
|
1134
1295
|
let objectBuilder = builder.getOrDefault("result.variable.object");
|
|
1135
1296
|
const assignmentBuilder = builder.getOrDefault("functions");
|
|
1136
|
-
const entitySelectorPath = property.getSelectrorPath({ parent: "
|
|
1297
|
+
const entitySelectorPath = property.getSelectrorPath({ parent: "unserialized" });
|
|
1137
1298
|
if (objectBuilder == null) {
|
|
1138
1299
|
objectBuilder = builder.get("result")
|
|
1139
|
-
.assign("const
|
|
1300
|
+
.assign("const entity", { name: "variable" })
|
|
1140
1301
|
.object({ name: "object" });
|
|
1141
1302
|
}
|
|
1142
1303
|
const defaultFunctionWithParameters = this.toNamedFunction(property.valueDeserializer.toString(), assignmentBuilder);
|
|
@@ -1202,12 +1363,12 @@ class DeserializeObjectHandler extends _types__WEBPACK_IMPORTED_MODULE_0__.Prope
|
|
|
1202
1363
|
const slotPath = new _SlotPath__WEBPACK_IMPORTED_MODULE_2__.SlotPath("result.variable.object");
|
|
1203
1364
|
let objectBuilder = builder.get(slotPath.get());
|
|
1204
1365
|
if (property.parent == null) {
|
|
1205
|
-
objectBuilder.nested(property.
|
|
1366
|
+
objectBuilder.nested(property.getResolvedName(), property.name);
|
|
1206
1367
|
return builder;
|
|
1207
1368
|
}
|
|
1208
1369
|
slotPath.push(...property.getParentPathArray());
|
|
1209
1370
|
const nestedObjectBuilder = builder.get(slotPath.get());
|
|
1210
|
-
nestedObjectBuilder.nested(property.
|
|
1371
|
+
nestedObjectBuilder.nested(property.getResolvedName(), property.name);
|
|
1211
1372
|
return builder;
|
|
1212
1373
|
}
|
|
1213
1374
|
return super.handle(property, builder);
|
|
@@ -1235,10 +1396,10 @@ class DeserializeValueHandler extends _types__WEBPACK_IMPORTED_MODULE_0__.Proper
|
|
|
1235
1396
|
handle(property, builder) {
|
|
1236
1397
|
if (property.type != _schema__WEBPACK_IMPORTED_MODULE_1__.SchemaTypes.Object && property.type != _schema__WEBPACK_IMPORTED_MODULE_1__.SchemaTypes.Date) {
|
|
1237
1398
|
let objectBuilder = builder.getOrDefault("result.variable.object");
|
|
1238
|
-
const entitySelectorPath = property.getAssignmentPath({ parent: "
|
|
1399
|
+
const entitySelectorPath = property.getAssignmentPath({ parent: "unserialized", useFromPropertyName: property.isRenamed });
|
|
1239
1400
|
if (objectBuilder == null) {
|
|
1240
1401
|
objectBuilder = builder.get("result")
|
|
1241
|
-
.assign("const
|
|
1402
|
+
.assign("const entity", { name: "variable" })
|
|
1242
1403
|
.object({ name: "object" });
|
|
1243
1404
|
}
|
|
1244
1405
|
if (property.parent == null) {
|
|
@@ -2251,14 +2412,17 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
2251
2412
|
|
|
2252
2413
|
|
|
2253
2414
|
/**
|
|
2254
|
-
* 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
|
|
2255
2417
|
*/
|
|
2256
2418
|
class SerializeDateHandler extends _types__WEBPACK_IMPORTED_MODULE_0__.PropertyInfoHandler {
|
|
2257
2419
|
handle(property, builder) {
|
|
2258
2420
|
if (property.type === _schema__WEBPACK_IMPORTED_MODULE_1__.SchemaTypes.Date) {
|
|
2259
2421
|
let objectBuilder = builder.get("if");
|
|
2260
|
-
const entitySelectorPath = property.getSelectrorPath({ parent: "entity" });
|
|
2261
|
-
const entityAssignmentPath = property.getAssignmentPath({
|
|
2422
|
+
const entitySelectorPath = property.getSelectrorPath({ parent: "entity", useFromPropertyName: property.isRenamed });
|
|
2423
|
+
const entityAssignmentPath = property.getAssignmentPath({
|
|
2424
|
+
parent: "result"
|
|
2425
|
+
});
|
|
2262
2426
|
const assignment = `${property.name}: ${entitySelectorPath} instanceof Date ? ${entitySelectorPath}.toISOString() : ${entitySelectorPath}`;
|
|
2263
2427
|
// if it is nullable or optional, assign in an if block, otherwise we
|
|
2264
2428
|
// could unintentionally assign null/undefined to a property that does not exist
|
|
@@ -2285,6 +2449,31 @@ class SerializeDateHandler extends _types__WEBPACK_IMPORTED_MODULE_0__.PropertyI
|
|
|
2285
2449
|
}
|
|
2286
2450
|
|
|
2287
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
|
+
|
|
2288
2477
|
}),
|
|
2289
2478
|
"./src/codegen/handlers/serialize/SerializeObjectHandler.ts":
|
|
2290
2479
|
/*!******************************************************************!*\
|
|
@@ -2305,7 +2494,9 @@ class SerializeObjectHandler extends _types__WEBPACK_IMPORTED_MODULE_0__.Propert
|
|
|
2305
2494
|
handle(property, builder) {
|
|
2306
2495
|
if (property.type === _schema__WEBPACK_IMPORTED_MODULE_1__.SchemaTypes.Object) {
|
|
2307
2496
|
const slotPath = new _SlotPath__WEBPACK_IMPORTED_MODULE_2__.SlotPath("assignments");
|
|
2308
|
-
const childPath = property.getAssignmentPath({
|
|
2497
|
+
const childPath = property.getAssignmentPath({
|
|
2498
|
+
parent: "result"
|
|
2499
|
+
});
|
|
2309
2500
|
if (property.isNullable || property.isOptional) {
|
|
2310
2501
|
// Do nothing if it's nullable or optional as property assignments will check
|
|
2311
2502
|
// and create if it does not exist. This way we can handle null/optional
|
|
@@ -2337,7 +2528,7 @@ class SerializeSerializerHandler extends _types__WEBPACK_IMPORTED_MODULE_0__.Pro
|
|
|
2337
2528
|
if (property.valueSerializer != null) {
|
|
2338
2529
|
const objectBuilder = builder.getOrDefault("if");
|
|
2339
2530
|
const assignmentBuilder = builder.getOrDefault("functions");
|
|
2340
|
-
const entitySelectorPath = property.getAssignmentPath({ parent: "entity" });
|
|
2531
|
+
const entitySelectorPath = property.getAssignmentPath({ parent: "entity", useFromPropertyName: property.isRenamed });
|
|
2341
2532
|
const resultSelectorPath = property.getAssignmentPath({ parent: "result" });
|
|
2342
2533
|
const defaultFunctionWithParameters = this.toNamedFunction(property.valueSerializer.toString(), assignmentBuilder);
|
|
2343
2534
|
defaultFunctionWithParameters.builder.parameters(...defaultFunctionWithParameters.parameters.map((_, i) => ({ name: defaultFunctionWithParameters.parameters[i], callName: entitySelectorPath })));
|
|
@@ -2377,7 +2568,7 @@ class SerializeValueHandler extends _types__WEBPACK_IMPORTED_MODULE_0__.Property
|
|
|
2377
2568
|
handle(property, builder) {
|
|
2378
2569
|
if (property.type != _schema__WEBPACK_IMPORTED_MODULE_1__.SchemaTypes.Object && property.type != _schema__WEBPACK_IMPORTED_MODULE_1__.SchemaTypes.Date) {
|
|
2379
2570
|
const slot = builder.getOrDefault("if");
|
|
2380
|
-
const entitySelectorPath = property.getAssignmentPath({ parent: "entity" });
|
|
2571
|
+
const entitySelectorPath = property.getAssignmentPath({ parent: "entity", useFromPropertyName: property.isRenamed });
|
|
2381
2572
|
const resultSelectorPath = property.getAssignmentPath({ parent: "result" });
|
|
2382
2573
|
if (property.parent == null) {
|
|
2383
2574
|
// Only assign if the incoming entity has the property, this allows partial serialization
|
|
@@ -2576,14 +2767,13 @@ class PropertyInfoHandler {
|
|
|
2576
2767
|
return result;
|
|
2577
2768
|
}
|
|
2578
2769
|
setEnrichedProperty(property, root) {
|
|
2579
|
-
const
|
|
2580
|
-
const entitySelectorPath = property.getAssignmentPath({ parent: "entity", useFromPropertyName });
|
|
2770
|
+
const entitySelectorPath = property.getAssignmentPath({ parent: "entity" });
|
|
2581
2771
|
if (property.parent != null) {
|
|
2582
2772
|
const slotPath = new _SlotPath__WEBPACK_IMPORTED_MODULE_1__.SlotPath("factory", "function", "enriched", "object", "enriched");
|
|
2583
2773
|
const path = property.parent.getAssignmentPath({ parent: "enriched" });
|
|
2584
2774
|
slotPath.push(`[${path}]`);
|
|
2585
2775
|
const objectBuilder = root.get(slotPath.get());
|
|
2586
|
-
const childEntityPathSelector = property.getSelectrorPath({ parent: "entity"
|
|
2776
|
+
const childEntityPathSelector = property.getSelectrorPath({ parent: "entity" });
|
|
2587
2777
|
objectBuilder.property(`${property.name}: ${childEntityPathSelector}`);
|
|
2588
2778
|
return;
|
|
2589
2779
|
}
|
|
@@ -2771,10 +2961,16 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
2771
2961
|
__webpack_require__.d(__webpack_exports__, {
|
|
2772
2962
|
PropertyInfo: () => (PropertyInfo)
|
|
2773
2963
|
});
|
|
2774
|
-
/* ESM import */var
|
|
2775
|
-
/* 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");
|
|
2776
2966
|
|
|
2777
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
|
+
]);
|
|
2778
2974
|
/**
|
|
2779
2975
|
* Represents metadata and utilities for a property in a schema, including its type, name, parent, children, and serialization details.
|
|
2780
2976
|
*/
|
|
@@ -2840,7 +3036,7 @@ class PropertyInfo {
|
|
|
2840
3036
|
this.name = name;
|
|
2841
3037
|
this.type = schema.type;
|
|
2842
3038
|
this.literals = schema.literals;
|
|
2843
|
-
if (schema instanceof
|
|
3039
|
+
if (schema instanceof _property_types_SchemaArray__WEBPACK_IMPORTED_MODULE_1__.SchemaArray) {
|
|
2844
3040
|
this.innerSchema = schema.innerSchema;
|
|
2845
3041
|
}
|
|
2846
3042
|
this.isNullable = schema.isNullable;
|
|
@@ -2884,6 +3080,12 @@ class PropertyInfo {
|
|
|
2884
3080
|
this._levelCache = level;
|
|
2885
3081
|
return level;
|
|
2886
3082
|
}
|
|
3083
|
+
get isRenamed() {
|
|
3084
|
+
return !!this.from;
|
|
3085
|
+
}
|
|
3086
|
+
get supportsDeserialization() {
|
|
3087
|
+
return this.valueDeserializer != null || SUPPORTED_DESERIALIZATION_TYPES.has(this.type);
|
|
3088
|
+
}
|
|
2887
3089
|
_getPropertyChain() {
|
|
2888
3090
|
if (this._propertyChainCache) {
|
|
2889
3091
|
return this._propertyChainCache;
|
|
@@ -2913,6 +3115,9 @@ class PropertyInfo {
|
|
|
2913
3115
|
}
|
|
2914
3116
|
return path;
|
|
2915
3117
|
}
|
|
3118
|
+
getResolvedName() {
|
|
3119
|
+
return this.from ?? this.name;
|
|
3120
|
+
}
|
|
2916
3121
|
/**
|
|
2917
3122
|
* Returns an array of property names representing the path from the root to this property.
|
|
2918
3123
|
*
|
|
@@ -2997,12 +3202,17 @@ class PropertyInfo {
|
|
|
2997
3202
|
return null;
|
|
2998
3203
|
}
|
|
2999
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
|
+
}
|
|
3000
3210
|
let current = instance;
|
|
3001
|
-
for (
|
|
3211
|
+
for (let i = 0; i < length; i++) {
|
|
3002
3212
|
if (current == null) {
|
|
3003
3213
|
return null;
|
|
3004
3214
|
}
|
|
3005
|
-
current = current[
|
|
3215
|
+
current = current[pathArray[i]];
|
|
3006
3216
|
}
|
|
3007
3217
|
return current;
|
|
3008
3218
|
}
|
|
@@ -3049,8 +3259,8 @@ class PropertyInfo {
|
|
|
3049
3259
|
getSelectrorPath(options) {
|
|
3050
3260
|
const parts = this._resolvePathArray({
|
|
3051
3261
|
root: options.parent,
|
|
3052
|
-
assignmentType: options
|
|
3053
|
-
useFromPropertyName: options
|
|
3262
|
+
assignmentType: options?.assignmentType,
|
|
3263
|
+
useFromPropertyName: options?.useFromPropertyName
|
|
3054
3264
|
});
|
|
3055
3265
|
return parts.join("");
|
|
3056
3266
|
}
|
|
@@ -3075,16 +3285,16 @@ class PropertyInfo {
|
|
|
3075
3285
|
if (this.valueDeserializer != null) {
|
|
3076
3286
|
return this.valueDeserializer(value);
|
|
3077
3287
|
}
|
|
3078
|
-
if (this.type ===
|
|
3288
|
+
if (this.type === _types__WEBPACK_IMPORTED_MODULE_0__.SchemaTypes.Date) {
|
|
3079
3289
|
return new Date(value);
|
|
3080
3290
|
}
|
|
3081
|
-
if (this.type ===
|
|
3291
|
+
if (this.type === _types__WEBPACK_IMPORTED_MODULE_0__.SchemaTypes.String) {
|
|
3082
3292
|
return String(value);
|
|
3083
3293
|
}
|
|
3084
|
-
if (this.type ===
|
|
3294
|
+
if (this.type === _types__WEBPACK_IMPORTED_MODULE_0__.SchemaTypes.Number) {
|
|
3085
3295
|
return Number(value);
|
|
3086
3296
|
}
|
|
3087
|
-
if (this.type ===
|
|
3297
|
+
if (this.type === _types__WEBPACK_IMPORTED_MODULE_0__.SchemaTypes.Boolean) {
|
|
3088
3298
|
return Boolean(value);
|
|
3089
3299
|
}
|
|
3090
3300
|
throw new Error(`Unsupported deserialization for type. Type: ${this.type}`);
|
|
@@ -3106,7 +3316,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
3106
3316
|
/* ESM import */var _table_SchemaComputed__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./table/SchemaComputed */ "./src/schema/table/SchemaComputed.ts");
|
|
3107
3317
|
/* ESM import */var _property_base_SchemaBase__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./property/base/SchemaBase */ "./src/schema/property/base/SchemaBase.ts");
|
|
3108
3318
|
/* ESM import */var _PropertyInfo__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./PropertyInfo */ "./src/schema/PropertyInfo.ts");
|
|
3109
|
-
/* ESM import */var
|
|
3319
|
+
/* ESM import */var _codegen__WEBPACK_IMPORTED_MODULE_19__ = __webpack_require__(/*! ../codegen */ "./src/codegen/blocks.ts");
|
|
3110
3320
|
/* ESM import */var _codegen_handlers_EnrichmentHandlerBuilder__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../codegen/handlers/EnrichmentHandlerBuilder */ "./src/codegen/handlers/EnrichmentHandlerBuilder.ts");
|
|
3111
3321
|
/* ESM import */var _codegen_handlers_MergeHandlerBuilder__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../codegen/handlers/MergeHandlerBuilder */ "./src/codegen/handlers/MergeHandlerBuilder.ts");
|
|
3112
3322
|
/* ESM import */var _codegen_handlers_PrepareHandlerBuilder__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../codegen/handlers/PrepareHandlerBuilder */ "./src/codegen/handlers/PrepareHandlerBuilder.ts");
|
|
@@ -3119,11 +3329,13 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
3119
3329
|
/* ESM import */var _codegen_handlers_HashHandlerBuilder__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ../codegen/handlers/HashHandlerBuilder */ "./src/codegen/handlers/HashHandlerBuilder.ts");
|
|
3120
3330
|
/* ESM import */var _codegen_handlers_EnableChangeTrackingHandlerBuilder__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(/*! ../codegen/handlers/EnableChangeTrackingHandlerBuilder */ "./src/codegen/handlers/EnableChangeTrackingHandlerBuilder.ts");
|
|
3121
3331
|
/* ESM import */var _codegen_handlers_FreezeHandlerBuilder__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(/*! ../codegen/handlers/FreezeHandlerBuilder */ "./src/codegen/handlers/FreezeHandlerBuilder.ts");
|
|
3122
|
-
/* ESM import */var
|
|
3332
|
+
/* ESM import */var _errors_SchemaError__WEBPACK_IMPORTED_MODULE_22__ = __webpack_require__(/*! ../errors/SchemaError */ "./src/errors/SchemaError.ts");
|
|
3123
3333
|
/* ESM import */var _codegen_handlers_SerializeHandlerBuilder__WEBPACK_IMPORTED_MODULE_17__ = __webpack_require__(/*! ../codegen/handlers/SerializeHandlerBuilder */ "./src/codegen/handlers/SerializeHandlerBuilder.ts");
|
|
3124
|
-
/* ESM import */var
|
|
3334
|
+
/* ESM import */var _utilities__WEBPACK_IMPORTED_MODULE_20__ = __webpack_require__(/*! ../utilities */ "./src/utilities/strings.ts");
|
|
3125
3335
|
/* ESM import */var _types__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./types */ "./src/schema/types.ts");
|
|
3126
|
-
/* 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
|
+
|
|
3127
3339
|
|
|
3128
3340
|
|
|
3129
3341
|
|
|
@@ -3308,6 +3520,7 @@ class SchemaDefinition extends _property_base_SchemaBase__WEBPACK_IMPORTED_MODUL
|
|
|
3308
3520
|
const enableChangeTrackingHandlerBuilder = new _codegen_handlers_EnableChangeTrackingHandlerBuilder__WEBPACK_IMPORTED_MODULE_15__.EnableChangeTrackingHandlerBuilder();
|
|
3309
3521
|
const freezeHandlerBuilder = new _codegen_handlers_FreezeHandlerBuilder__WEBPACK_IMPORTED_MODULE_16__.FreezeHandlerBuilder();
|
|
3310
3522
|
const serializeHandlerBuilder = new _codegen_handlers_SerializeHandlerBuilder__WEBPACK_IMPORTED_MODULE_17__.SerializeHandlerBuilder();
|
|
3523
|
+
const compareIdsHandlerBuilder = new _codegen_handlers_CompareIdsHandlerBuilder__WEBPACK_IMPORTED_MODULE_18__.CompareIdsHandlerBuilder();
|
|
3311
3524
|
const enricher = enrichmentHandlerBuilder.build();
|
|
3312
3525
|
const merge = mergeHandlerFactory.build();
|
|
3313
3526
|
const prepare = prepareHandlerBuilder.build();
|
|
@@ -3321,26 +3534,36 @@ class SchemaDefinition extends _property_base_SchemaBase__WEBPACK_IMPORTED_MODUL
|
|
|
3321
3534
|
const enableChangeTrackingHandler = enableChangeTrackingHandlerBuilder.build();
|
|
3322
3535
|
const freezeHandler = freezeHandlerBuilder.build();
|
|
3323
3536
|
const serializeHandler = serializeHandlerBuilder.build();
|
|
3324
|
-
const
|
|
3537
|
+
const compareIdsHandler = compareIdsHandlerBuilder.build();
|
|
3538
|
+
const changeTrackingCodeBuilder = new _codegen__WEBPACK_IMPORTED_MODULE_19__.CodeBuilder();
|
|
3325
3539
|
changeTrackingCodeBuilder.raw(`function ${this.createChangeTracker.toString()}`);
|
|
3326
3540
|
changeTrackingCodeBuilder.slot("declarations").variable("enableChangeTracking").value('createChangeTracker()');
|
|
3327
3541
|
changeTrackingCodeBuilder.slot("assignment");
|
|
3328
3542
|
changeTrackingCodeBuilder.slot("return").raw('\treturn enableChangeTracking(entity);');
|
|
3329
|
-
const freezeCodeBuilder = new
|
|
3543
|
+
const freezeCodeBuilder = new _codegen__WEBPACK_IMPORTED_MODULE_19__.CodeBuilder();
|
|
3330
3544
|
freezeCodeBuilder.slot("assignment");
|
|
3331
3545
|
freezeCodeBuilder.slot("return").raw('\treturn Object.freeze(entity);');
|
|
3332
|
-
const enricherCodeBuilder = new
|
|
3546
|
+
const enricherCodeBuilder = new _codegen__WEBPACK_IMPORTED_MODULE_19__.CodeBuilder();
|
|
3333
3547
|
const enricherFunctionRoot = enricherCodeBuilder.factory("factory", { name: "factory" }).parameters({ name: "collectionName", value: this.collectionName });
|
|
3334
3548
|
const enricherFunctionBody = enricherFunctionRoot.function(undefined, { name: "function" }).parameters("entity", "changeTrackingType").return();
|
|
3335
|
-
enricherFunctionBody.raw(
|
|
3336
|
-
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");
|
|
3337
3554
|
enricherFunctionBody.slot("enriched");
|
|
3338
3555
|
enricherFunctionBody.slot("declarations");
|
|
3339
3556
|
enricherFunctionBody.slot("assignment");
|
|
3340
3557
|
enricherFunctionBody.slot("ifs");
|
|
3341
3558
|
enricherFunctionBody.slot("tracking").if('changeTrackingType === "immutable"', { name: "freeze" });
|
|
3342
|
-
enricherFunctionBody.raw('\treturn enableChangeTracking(enriched);');
|
|
3343
|
-
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();
|
|
3344
3567
|
const mergeFunctionRoot = mergeCodeBuilder.factory("factory", { name: "factory" }).parameters({ name: "collectionName", value: this.collectionName });
|
|
3345
3568
|
const mergeFunctionBody = mergeFunctionRoot.function(undefined, { name: "function" }).parameters("destination", "source").return();
|
|
3346
3569
|
const pauseFunctionBody = mergeFunctionBody.function("pause")
|
|
@@ -3359,40 +3582,43 @@ class SchemaDefinition extends _property_base_SchemaBase__WEBPACK_IMPORTED_MODUL
|
|
|
3359
3582
|
unpause();
|
|
3360
3583
|
|
|
3361
3584
|
return destination;`);
|
|
3362
|
-
const prepareCodeBuilder = new
|
|
3585
|
+
const prepareCodeBuilder = new _codegen__WEBPACK_IMPORTED_MODULE_19__.CodeBuilder();
|
|
3363
3586
|
prepareCodeBuilder.slot("result");
|
|
3364
3587
|
prepareCodeBuilder.slot("assignments");
|
|
3365
3588
|
prepareCodeBuilder.slot("return").raw(` return result;`);
|
|
3366
|
-
const stripCodeBuilder = new
|
|
3589
|
+
const stripCodeBuilder = new _codegen__WEBPACK_IMPORTED_MODULE_19__.CodeBuilder();
|
|
3367
3590
|
stripCodeBuilder.slot("result");
|
|
3368
3591
|
stripCodeBuilder.slot("return").raw(` return result;`);
|
|
3369
|
-
const cloneCodeBuilder = new
|
|
3592
|
+
const cloneCodeBuilder = new _codegen__WEBPACK_IMPORTED_MODULE_19__.CodeBuilder();
|
|
3370
3593
|
cloneCodeBuilder.slot("result").raw("const result = {};");
|
|
3371
3594
|
;
|
|
3372
3595
|
cloneCodeBuilder.slot("assignments");
|
|
3373
3596
|
cloneCodeBuilder.slot("if");
|
|
3374
3597
|
cloneCodeBuilder.slot("return").raw(` return result;`);
|
|
3375
|
-
const compareCodeBuilder = new
|
|
3598
|
+
const compareCodeBuilder = new _codegen__WEBPACK_IMPORTED_MODULE_19__.CodeBuilder();
|
|
3376
3599
|
compareCodeBuilder.slot("result");
|
|
3377
3600
|
compareCodeBuilder.slot("return").raw(` return result;`);
|
|
3378
|
-
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();
|
|
3379
3605
|
deserializeCodeBuilder.slot("functions");
|
|
3380
3606
|
deserializeCodeBuilder.slot("result");
|
|
3381
3607
|
deserializeCodeBuilder.slot("if");
|
|
3382
|
-
deserializeCodeBuilder.slot("return").raw(` return
|
|
3383
|
-
const serializeCodeBuilder = new
|
|
3608
|
+
deserializeCodeBuilder.slot("return").raw(` return entity;`);
|
|
3609
|
+
const serializeCodeBuilder = new _codegen__WEBPACK_IMPORTED_MODULE_19__.CodeBuilder();
|
|
3384
3610
|
serializeCodeBuilder.slot("result").raw("const result = {};");
|
|
3385
3611
|
serializeCodeBuilder.slot("assignments");
|
|
3386
3612
|
serializeCodeBuilder.slot("functions");
|
|
3387
3613
|
serializeCodeBuilder.slot("if");
|
|
3388
3614
|
serializeCodeBuilder.slot("return").raw(` return result;`);
|
|
3389
|
-
const idSelectorCodeBuilder = new
|
|
3615
|
+
const idSelectorCodeBuilder = new _codegen__WEBPACK_IMPORTED_MODULE_19__.CodeBuilder();
|
|
3390
3616
|
idSelectorCodeBuilder.slot("result");
|
|
3391
3617
|
idSelectorCodeBuilder.slot("return").raw(` return result;`);
|
|
3392
|
-
const hashTypeCodeBuilder = new
|
|
3618
|
+
const hashTypeCodeBuilder = new _codegen__WEBPACK_IMPORTED_MODULE_19__.CodeBuilder();
|
|
3393
3619
|
hashTypeCodeBuilder.slot("ifs");
|
|
3394
3620
|
hashTypeCodeBuilder.slot("return").raw(` return "Ids";`);
|
|
3395
|
-
const hashCodeBuilder = new
|
|
3621
|
+
const hashCodeBuilder = new _codegen__WEBPACK_IMPORTED_MODULE_19__.CodeBuilder();
|
|
3396
3622
|
hashCodeBuilder.slot("functions").raw(`
|
|
3397
3623
|
function stringifyDate(d) {
|
|
3398
3624
|
|
|
@@ -3447,6 +3673,7 @@ class SchemaDefinition extends _property_base_SchemaBase__WEBPACK_IMPORTED_MODUL
|
|
|
3447
3673
|
hashHandler.handle(property, hashCodeBuilder);
|
|
3448
3674
|
enableChangeTrackingHandler.handle(property, changeTrackingCodeBuilder);
|
|
3449
3675
|
freezeHandler.handle(property, freezeCodeBuilder);
|
|
3676
|
+
compareIdsHandler.handle(property, compareIdsCodeBuilder);
|
|
3450
3677
|
});
|
|
3451
3678
|
if (idProperties.length === 0) {
|
|
3452
3679
|
throw new Error(`Schema must have a key. Use .key() to mark a property as a key. Collection Name: ${this.collectionName}`);
|
|
@@ -3455,20 +3682,36 @@ class SchemaDefinition extends _property_base_SchemaBase__WEBPACK_IMPORTED_MODUL
|
|
|
3455
3682
|
const mergeParams = mergeFunctionRoot.getParameters();
|
|
3456
3683
|
const enrichGenerator = Function(`return ${enricherCodeBuilder.toString()}`);
|
|
3457
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"));
|
|
3458
3698
|
const getIdsFunction = Function("entity", idSelectorCodeBuilder.toString());
|
|
3459
3699
|
const getHashTypeFunction = Function("entity", hashTypeCodeBuilder.toString());
|
|
3460
3700
|
const prepareFunction = Function("entity", prepareCodeBuilder.toString());
|
|
3461
3701
|
const cloneFunction = Function("entity", cloneCodeBuilder.toString());
|
|
3462
|
-
const deserializeFunction = Function("
|
|
3702
|
+
const deserializeFunction = Function("unserialized", deserializeCodeBuilder.toString());
|
|
3463
3703
|
const serializeFunction = Function("entity", serializeCodeBuilder.toString());
|
|
3464
3704
|
const compareFunction = Function("a", "b", compareCodeBuilder.toString());
|
|
3465
|
-
;
|
|
3466
3705
|
const stripFunction = Function("entity", stripCodeBuilder.toString());
|
|
3467
3706
|
const hashFunction = Function("entity", "type", hashCodeBuilder.toString());
|
|
3468
3707
|
const enableChangeTrackingFunction = Function("entity", changeTrackingCodeBuilder.toString());
|
|
3469
3708
|
const freezeFunction = Function("entity", freezeCodeBuilder.toString());
|
|
3709
|
+
const compareIdsFunction = Function("a", "b", compareIdsCodeBuilder.toString());
|
|
3710
|
+
const preprocessFunction = Function("entity", preprocessCodeBuilder.toString());
|
|
3470
3711
|
const enricherFactoryFunction = enrichGenerator();
|
|
3712
|
+
const postProcessFactoryFunction = postProcessGenerator();
|
|
3471
3713
|
const mergeFactoryFunction = mergeGenerator();
|
|
3714
|
+
const postProcessFunction = postProcessFactoryFunction(...postProcessParams.map(w => w.value));
|
|
3472
3715
|
const enricherFunction = enricherFactoryFunction(...enrichParams.map(w => w.value));
|
|
3473
3716
|
const mergeFunction = mergeFactoryFunction(...mergeParams.map(w => w.value));
|
|
3474
3717
|
const idPropertyNames = idProperties.map(w => w.name);
|
|
@@ -3479,7 +3722,7 @@ class SchemaDefinition extends _property_base_SchemaBase__WEBPACK_IMPORTED_MODUL
|
|
|
3479
3722
|
return getIdsFunction(entity)[0];
|
|
3480
3723
|
};
|
|
3481
3724
|
const getProperty = (id) => propertyMap.get(id);
|
|
3482
|
-
const id = (0,
|
|
3725
|
+
const id = (0,_utilities__WEBPACK_IMPORTED_MODULE_20__.hash)([...allPropertyNamesAndPaths, this.collectionName].join(","));
|
|
3483
3726
|
// memoize this by the validProperties
|
|
3484
3727
|
// TODO: See if we can generate a function to do this and eliminate loops
|
|
3485
3728
|
const deserializePartial = (item, properties) => {
|
|
@@ -3494,8 +3737,9 @@ class SchemaDefinition extends _property_base_SchemaBase__WEBPACK_IMPORTED_MODUL
|
|
|
3494
3737
|
}
|
|
3495
3738
|
return item;
|
|
3496
3739
|
};
|
|
3497
|
-
|
|
3498
|
-
|
|
3740
|
+
const result = {
|
|
3741
|
+
preprocess: preprocessFunction,
|
|
3742
|
+
postprocess: postProcessFunction,
|
|
3499
3743
|
getId,
|
|
3500
3744
|
getProperty,
|
|
3501
3745
|
properties,
|
|
@@ -3510,6 +3754,7 @@ class SchemaDefinition extends _property_base_SchemaBase__WEBPACK_IMPORTED_MODUL
|
|
|
3510
3754
|
deserialize: deserializeFunction,
|
|
3511
3755
|
serialize: serializeFunction,
|
|
3512
3756
|
compare: compareFunction,
|
|
3757
|
+
compareIds: compareIdsFunction,
|
|
3513
3758
|
strip: stripFunction,
|
|
3514
3759
|
hash: hashFunction,
|
|
3515
3760
|
id,
|
|
@@ -3571,9 +3816,13 @@ class SchemaDefinition extends _property_base_SchemaBase__WEBPACK_IMPORTED_MODUL
|
|
|
3571
3816
|
return indexes;
|
|
3572
3817
|
}
|
|
3573
3818
|
};
|
|
3819
|
+
return {
|
|
3820
|
+
createSubscription: (signal) => new _communication_broadcast__WEBPACK_IMPORTED_MODULE_21__.SchemaSubscription(result, signal),
|
|
3821
|
+
...result
|
|
3822
|
+
};
|
|
3574
3823
|
}
|
|
3575
3824
|
catch (e) {
|
|
3576
|
-
throw new
|
|
3825
|
+
throw new _errors_SchemaError__WEBPACK_IMPORTED_MODULE_22__.SchemaError(e, `Error compiling schema for collection: ${this.collectionName}`);
|
|
3577
3826
|
}
|
|
3578
3827
|
}
|
|
3579
3828
|
}
|
|
@@ -3689,43 +3938,81 @@ class SubscriptionListener {
|
|
|
3689
3938
|
}
|
|
3690
3939
|
class SchemaSubscription {
|
|
3691
3940
|
id;
|
|
3692
|
-
|
|
3941
|
+
schema;
|
|
3693
3942
|
createdAt;
|
|
3694
|
-
constructor(
|
|
3943
|
+
constructor(schema, signal) {
|
|
3695
3944
|
this.createdAt = (0,_performance__WEBPACK_IMPORTED_MODULE_0__.now)();
|
|
3696
3945
|
this.id = (0,_utilities__WEBPACK_IMPORTED_MODULE_1__.uuid)(8);
|
|
3697
|
-
this.
|
|
3946
|
+
this.schema = schema;
|
|
3698
3947
|
signal?.addEventListener("abort", () => {
|
|
3699
3948
|
this.dispose();
|
|
3700
3949
|
}, { once: true });
|
|
3701
3950
|
}
|
|
3702
3951
|
send(changes) {
|
|
3703
|
-
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
|
+
}
|
|
3704
3972
|
// Send message to all listeners.
|
|
3705
3973
|
// Since we create a new listener when we do onMessage,
|
|
3706
3974
|
// we don't need to worry about sending to ourselves, it
|
|
3707
3975
|
// can't happen
|
|
3708
3976
|
regisry.sender.send({
|
|
3709
|
-
data:
|
|
3977
|
+
data: preprocessedChanges,
|
|
3710
3978
|
timestamp: (0,_performance__WEBPACK_IMPORTED_MODULE_0__.now)()
|
|
3711
3979
|
});
|
|
3712
3980
|
}
|
|
3713
3981
|
onMessage(callback) {
|
|
3714
|
-
const regisry = getChannelRegistry(this.
|
|
3982
|
+
const regisry = getChannelRegistry(this.schema.id);
|
|
3715
3983
|
// Link the callback to an instance
|
|
3716
3984
|
regisry.receiver.addListener(this.id, ({ data, timestamp }) => {
|
|
3717
3985
|
if (timestamp < this.createdAt) {
|
|
3718
3986
|
// Sent before the receiver was even created
|
|
3719
3987
|
return;
|
|
3720
3988
|
}
|
|
3721
|
-
|
|
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);
|
|
3722
4009
|
});
|
|
3723
4010
|
}
|
|
3724
4011
|
dispose() {
|
|
3725
4012
|
this[Symbol.dispose]();
|
|
3726
4013
|
}
|
|
3727
4014
|
[Symbol.dispose]() {
|
|
3728
|
-
const regisry = getChannelRegistry(this.
|
|
4015
|
+
const regisry = getChannelRegistry(this.schema.id);
|
|
3729
4016
|
// Remove listeners for this instance only
|
|
3730
4017
|
regisry.receiver.removeListeners(this.id);
|
|
3731
4018
|
}
|
|
@@ -4223,6 +4510,8 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
4223
4510
|
SchemaTracked: () => (SchemaTracked)
|
|
4224
4511
|
});
|
|
4225
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
|
+
|
|
4226
4515
|
|
|
4227
4516
|
class SchemaTracked extends _base_SchemaBase__WEBPACK_IMPORTED_MODULE_0__.SchemaBase {
|
|
4228
4517
|
instance;
|
|
@@ -4232,6 +4521,9 @@ class SchemaTracked extends _base_SchemaBase__WEBPACK_IMPORTED_MODULE_0__.Schema
|
|
|
4232
4521
|
this.instance = current.instance;
|
|
4233
4522
|
this.isUnmapped = false;
|
|
4234
4523
|
}
|
|
4524
|
+
key() {
|
|
4525
|
+
return new _SchemaKey__WEBPACK_IMPORTED_MODULE_1__.SchemaKey(this);
|
|
4526
|
+
}
|
|
4235
4527
|
}
|
|
4236
4528
|
|
|
4237
4529
|
|
|
@@ -4845,7 +5137,9 @@ var HashType;
|
|
|
4845
5137
|
(function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
|
|
4846
5138
|
__webpack_require__.r(__webpack_exports__);
|
|
4847
5139
|
__webpack_require__.d(__webpack_exports__, {
|
|
4848
|
-
|
|
5140
|
+
fastHash: () => (fastHash),
|
|
5141
|
+
hash: () => (hash),
|
|
5142
|
+
stringifyObject: () => (stringifyObject)
|
|
4849
5143
|
});
|
|
4850
5144
|
const hash = (value, seed = 0) => {
|
|
4851
5145
|
// From Stack Overflow
|
|
@@ -4862,6 +5156,143 @@ const hash = (value, seed = 0) => {
|
|
|
4862
5156
|
h2 ^= Math.imul(h1 ^ (h1 >>> 13), 3266489909);
|
|
4863
5157
|
return 4294967296 * (2097151 & h2) + (h1 >>> 0);
|
|
4864
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
|
+
}
|
|
4865
5296
|
|
|
4866
5297
|
|
|
4867
5298
|
}),
|