@fjell/core 4.4.47 → 4.4.49
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/README.md +92 -0
- package/dist/Coordinate.d.ts +7 -0
- package/dist/errors/ActionError.d.ts +51 -0
- package/dist/errors/BusinessLogicError.d.ts +4 -0
- package/dist/errors/DuplicateError.d.ts +4 -0
- package/dist/errors/NotFoundError.d.ts +4 -0
- package/dist/errors/PermissionError.d.ts +4 -0
- package/dist/errors/ValidationError.d.ts +4 -0
- package/dist/errors/index.d.ts +6 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +1314 -49
- package/dist/item/IUtils.d.ts +6 -3
- package/dist/operations/OperationContext.d.ts +10 -0
- package/dist/operations/Operations.d.ts +259 -0
- package/dist/operations/contained.d.ts +65 -0
- package/dist/operations/errorEnhancer.d.ts +79 -0
- package/dist/operations/index.d.ts +2 -0
- package/dist/operations/methods.d.ts +134 -0
- package/dist/operations/primary.d.ts +57 -0
- package/dist/operations/specialized.d.ts +41 -0
- package/dist/operations/wrappers/createActionWrapper.d.ts +28 -0
- package/dist/operations/wrappers/createAllActionWrapper.d.ts +28 -0
- package/dist/operations/wrappers/createAllFacetWrapper.d.ts +27 -0
- package/dist/operations/wrappers/createAllWrapper.d.ts +28 -0
- package/dist/operations/wrappers/createCreateWrapper.d.ts +28 -0
- package/dist/operations/wrappers/createFacetWrapper.d.ts +27 -0
- package/dist/operations/wrappers/createFindOneWrapper.d.ts +28 -0
- package/dist/operations/wrappers/createFindWrapper.d.ts +28 -0
- package/dist/operations/wrappers/createGetWrapper.d.ts +28 -0
- package/dist/operations/wrappers/createOneWrapper.d.ts +38 -0
- package/dist/operations/wrappers/createRemoveWrapper.d.ts +28 -0
- package/dist/operations/wrappers/createUpdateWrapper.d.ts +28 -0
- package/dist/operations/wrappers/createUpsertWrapper.d.ts +28 -0
- package/dist/operations/wrappers/index.d.ts +34 -0
- package/dist/operations/wrappers/types.d.ts +48 -0
- package/dist/validation/ItemValidator.d.ts +43 -0
- package/dist/validation/KeyValidator.d.ts +56 -0
- package/dist/validation/LocationValidator.d.ts +39 -0
- package/dist/validation/QueryValidator.d.ts +57 -0
- package/dist/validation/index.d.ts +15 -0
- package/dist/validation/index.js +501 -0
- package/dist/validation/types.d.ts +38 -0
- package/package.json +7 -2
- package/src/Coordinate.ts +35 -0
- package/src/errors/ActionError.ts +69 -0
- package/src/errors/BusinessLogicError.ts +24 -0
- package/src/errors/DuplicateError.ts +57 -0
- package/src/errors/NotFoundError.ts +24 -0
- package/src/errors/PermissionError.ts +31 -0
- package/src/errors/ValidationError.ts +27 -0
- package/src/errors/index.ts +7 -0
- package/src/index.ts +53 -0
- package/src/item/IUtils.ts +9 -80
- package/src/key/KUtils.ts +2 -2
- package/src/operations/OperationContext.ts +12 -0
- package/src/operations/Operations.ts +357 -0
- package/src/operations/contained.ts +134 -0
- package/src/operations/errorEnhancer.ts +204 -0
- package/src/operations/index.ts +2 -0
- package/src/operations/methods.ts +363 -0
- package/src/operations/primary.ts +101 -0
- package/src/operations/specialized.ts +71 -0
- package/src/operations/wrappers/createActionWrapper.ts +108 -0
- package/src/operations/wrappers/createAllActionWrapper.ts +109 -0
- package/src/operations/wrappers/createAllFacetWrapper.ts +98 -0
- package/src/operations/wrappers/createAllWrapper.ts +103 -0
- package/src/operations/wrappers/createCreateWrapper.ts +117 -0
- package/src/operations/wrappers/createFacetWrapper.ts +97 -0
- package/src/operations/wrappers/createFindOneWrapper.ts +105 -0
- package/src/operations/wrappers/createFindWrapper.ts +105 -0
- package/src/operations/wrappers/createGetWrapper.ts +96 -0
- package/src/operations/wrappers/createOneWrapper.ts +128 -0
- package/src/operations/wrappers/createRemoveWrapper.ts +91 -0
- package/src/operations/wrappers/createUpdateWrapper.ts +106 -0
- package/src/operations/wrappers/createUpsertWrapper.ts +108 -0
- package/src/operations/wrappers/index.ts +39 -0
- package/src/operations/wrappers/types.ts +63 -0
- package/src/validation/ItemValidator.ts +131 -0
- package/src/validation/KeyValidator.ts +365 -0
- package/src/validation/LocationValidator.ts +136 -0
- package/src/validation/QueryValidator.ts +250 -0
- package/src/validation/index.ts +32 -0
- package/src/validation/types.ts +45 -0
package/dist/index.js
CHANGED
|
@@ -64,11 +64,23 @@ var Dictionary = class _Dictionary {
|
|
|
64
64
|
}
|
|
65
65
|
};
|
|
66
66
|
|
|
67
|
+
// src/Coordinate.ts
|
|
68
|
+
var logger2 = logger_default.get("Coordinate");
|
|
69
|
+
var createCoordinate = (kta, scopes = []) => {
|
|
70
|
+
const ktArray = Array.isArray(kta) ? kta : [kta];
|
|
71
|
+
const toString = () => {
|
|
72
|
+
logger2.debug("toString", { kta, scopes });
|
|
73
|
+
return `${ktArray.join(", ")} - ${scopes.join(", ")}`;
|
|
74
|
+
};
|
|
75
|
+
logger2.debug("createCoordinate", { kta: ktArray, scopes, toString });
|
|
76
|
+
return { kta: ktArray, scopes, toString };
|
|
77
|
+
};
|
|
78
|
+
|
|
67
79
|
// src/item/IFactory.ts
|
|
68
80
|
import deepmerge from "deepmerge";
|
|
69
81
|
|
|
70
82
|
// src/key/KUtils.ts
|
|
71
|
-
var
|
|
83
|
+
var logger3 = logger_default.get("KUtils");
|
|
72
84
|
var normalizeKeyValue = (value) => {
|
|
73
85
|
return String(value);
|
|
74
86
|
};
|
|
@@ -96,15 +108,15 @@ var createNormalizedHashFunction = () => {
|
|
|
96
108
|
};
|
|
97
109
|
};
|
|
98
110
|
var isPriKeyEqualNormalized = (a, b) => {
|
|
99
|
-
|
|
111
|
+
logger3.trace("isPriKeyEqualNormalized", { a, b });
|
|
100
112
|
return a && b && normalizeKeyValue(a.pk) === normalizeKeyValue(b.pk) && a.kt === b.kt;
|
|
101
113
|
};
|
|
102
114
|
var isLocKeyEqualNormalized = (a, b) => {
|
|
103
|
-
|
|
115
|
+
logger3.trace("isLocKeyEqualNormalized", { a, b });
|
|
104
116
|
return a && b && normalizeKeyValue(a.lk) === normalizeKeyValue(b.lk) && a.kt === b.kt;
|
|
105
117
|
};
|
|
106
118
|
var isComKeyEqualNormalized = (a, b) => {
|
|
107
|
-
|
|
119
|
+
logger3.trace("isComKeyEqualNormalized", { a, b });
|
|
108
120
|
if (a && b && isPriKeyEqualNormalized({ kt: a.kt, pk: a.pk }, { kt: b.kt, pk: b.pk })) {
|
|
109
121
|
if (a.loc.length === b.loc.length) {
|
|
110
122
|
for (let i = 0; i < a.loc.length; i++) {
|
|
@@ -121,7 +133,7 @@ var isComKeyEqualNormalized = (a, b) => {
|
|
|
121
133
|
}
|
|
122
134
|
};
|
|
123
135
|
var isItemKeyEqualNormalized = (a, b) => {
|
|
124
|
-
|
|
136
|
+
logger3.trace("isItemKeyEqualNormalized", { a, b });
|
|
125
137
|
if (isComKey(a) && isComKey(b)) {
|
|
126
138
|
return isComKeyEqualNormalized(a, b);
|
|
127
139
|
} else if (isPriKey(a) && isPriKey(b)) {
|
|
@@ -135,7 +147,7 @@ var isItemKeyEqualNormalized = (a, b) => {
|
|
|
135
147
|
}
|
|
136
148
|
};
|
|
137
149
|
var isItemKeyEqual = (a, b) => {
|
|
138
|
-
|
|
150
|
+
logger3.trace("isKeyEqual", { a, b });
|
|
139
151
|
if (isComKey(a) && isComKey(b)) {
|
|
140
152
|
return isComKeyEqual(a, b);
|
|
141
153
|
} else if (isPriKey(a) && isPriKey(b)) {
|
|
@@ -149,15 +161,15 @@ var isItemKeyEqual = (a, b) => {
|
|
|
149
161
|
}
|
|
150
162
|
};
|
|
151
163
|
var isPriKeyEqual = (a, b) => {
|
|
152
|
-
|
|
164
|
+
logger3.trace("isPriKeyEqual", { a, b });
|
|
153
165
|
return a && b && a.pk === b.pk && a.kt === b.kt;
|
|
154
166
|
};
|
|
155
167
|
var isLocKeyEqual = (a, b) => {
|
|
156
|
-
|
|
168
|
+
logger3.trace("isLocKeyEqual", { a, b });
|
|
157
169
|
return a && b && a.lk === b.lk && a.kt === b.kt;
|
|
158
170
|
};
|
|
159
171
|
var isComKeyEqual = (a, b) => {
|
|
160
|
-
|
|
172
|
+
logger3.trace("isComKeyEqual", { a, b });
|
|
161
173
|
if (a && b && isPriKeyEqual({ kt: a.kt, pk: a.pk }, { kt: b.kt, pk: b.pk })) {
|
|
162
174
|
if (a.loc.length === b.loc.length) {
|
|
163
175
|
for (let i = 0; i < a.loc.length; i++) {
|
|
@@ -174,23 +186,23 @@ var isComKeyEqual = (a, b) => {
|
|
|
174
186
|
}
|
|
175
187
|
};
|
|
176
188
|
var isItemKey = (key) => {
|
|
177
|
-
|
|
189
|
+
logger3.trace("isItemKey", { key });
|
|
178
190
|
return key !== void 0 && (isComKey(key) || isPriKey(key));
|
|
179
191
|
};
|
|
180
192
|
var isComKey = (key) => {
|
|
181
|
-
|
|
182
|
-
return key !== void 0 && (key.pk !== void 0 && key.kt !== void 0) && (key.loc !== void 0 && key.loc
|
|
193
|
+
logger3.trace("isComKey", { key });
|
|
194
|
+
return key !== void 0 && (key.pk !== void 0 && key.kt !== void 0) && (key.loc !== void 0 && Array.isArray(key.loc));
|
|
183
195
|
};
|
|
184
196
|
var isPriKey = (key) => {
|
|
185
|
-
|
|
186
|
-
return key !== void 0 && (key.pk !== void 0 && key.kt !== void 0) &&
|
|
197
|
+
logger3.trace("isPriKey", { key });
|
|
198
|
+
return key !== void 0 && (key.pk !== void 0 && key.kt !== void 0) && key.loc === void 0;
|
|
187
199
|
};
|
|
188
200
|
var isLocKey = (key) => {
|
|
189
|
-
|
|
201
|
+
logger3.trace("isLocKey", { key });
|
|
190
202
|
return key !== void 0 && (key.lk !== void 0 && key.kt !== void 0);
|
|
191
203
|
};
|
|
192
204
|
var generateKeyArray = (key) => {
|
|
193
|
-
|
|
205
|
+
logger3.trace("generateKeyArray", { key });
|
|
194
206
|
const keys = [];
|
|
195
207
|
if (isComKey(key) || isPriKey(key)) {
|
|
196
208
|
if (isComKey(key)) {
|
|
@@ -211,7 +223,7 @@ var generateKeyArray = (key) => {
|
|
|
211
223
|
return keys;
|
|
212
224
|
};
|
|
213
225
|
var constructPriKey = (pk, kt) => {
|
|
214
|
-
|
|
226
|
+
logger3.trace("constructPriKey", { pk, kt });
|
|
215
227
|
let pri;
|
|
216
228
|
if (typeof pk === "string" || typeof pk === "number") {
|
|
217
229
|
pri = { kt, pk };
|
|
@@ -222,7 +234,7 @@ var constructPriKey = (pk, kt) => {
|
|
|
222
234
|
};
|
|
223
235
|
var cPK = constructPriKey;
|
|
224
236
|
var toKeyTypeArray = (ik) => {
|
|
225
|
-
|
|
237
|
+
logger3.trace("toKeyTypeArray", { ik });
|
|
226
238
|
if (isComKey(ik)) {
|
|
227
239
|
const ck = ik;
|
|
228
240
|
return [ck.kt, ...ck.loc.map((l) => l.kt)];
|
|
@@ -231,7 +243,7 @@ var toKeyTypeArray = (ik) => {
|
|
|
231
243
|
}
|
|
232
244
|
};
|
|
233
245
|
var extractKeyTypeArray = (key) => {
|
|
234
|
-
|
|
246
|
+
logger3.trace("extractKeyTypeArray", { key });
|
|
235
247
|
if (isComKey(key)) {
|
|
236
248
|
const ck = key;
|
|
237
249
|
return [ck.kt, ...ck.loc.map((l) => l.kt)];
|
|
@@ -240,12 +252,12 @@ var extractKeyTypeArray = (key) => {
|
|
|
240
252
|
} else if (Array.isArray(key)) {
|
|
241
253
|
return key.map((locKey) => locKey.kt);
|
|
242
254
|
} else {
|
|
243
|
-
|
|
255
|
+
logger3.warning("extractKeyTypeArray: Unknown key type", { key });
|
|
244
256
|
return [];
|
|
245
257
|
}
|
|
246
258
|
};
|
|
247
259
|
var abbrevIK = (ik) => {
|
|
248
|
-
|
|
260
|
+
logger3.trace("abbrevIK", { ik });
|
|
249
261
|
if (ik) {
|
|
250
262
|
if (isComKey(ik)) {
|
|
251
263
|
const ck = ik;
|
|
@@ -258,7 +270,7 @@ var abbrevIK = (ik) => {
|
|
|
258
270
|
}
|
|
259
271
|
};
|
|
260
272
|
var abbrevLKA = (keyArray) => {
|
|
261
|
-
|
|
273
|
+
logger3.trace("abbrevLKA", { keyArray });
|
|
262
274
|
if (keyArray === void 0 || keyArray === null) {
|
|
263
275
|
return "null LKA";
|
|
264
276
|
} else {
|
|
@@ -272,7 +284,7 @@ var abbrevLKA = (keyArray) => {
|
|
|
272
284
|
}
|
|
273
285
|
};
|
|
274
286
|
var primaryType = (ik) => {
|
|
275
|
-
|
|
287
|
+
logger3.trace("primaryType", { ik });
|
|
276
288
|
if (isComKey(ik)) {
|
|
277
289
|
return ik.kt;
|
|
278
290
|
} else {
|
|
@@ -280,7 +292,7 @@ var primaryType = (ik) => {
|
|
|
280
292
|
}
|
|
281
293
|
};
|
|
282
294
|
var itemKeyToLocKeyArray = (ik) => {
|
|
283
|
-
|
|
295
|
+
logger3.trace("itemKeyToLocKeyArray", { ik: abbrevIK(ik) });
|
|
284
296
|
let lka = [];
|
|
285
297
|
if (isComKey(ik)) {
|
|
286
298
|
const ck = ik;
|
|
@@ -289,12 +301,12 @@ var itemKeyToLocKeyArray = (ik) => {
|
|
|
289
301
|
const pk = ik;
|
|
290
302
|
lka = [{ kt: pk.kt, lk: pk.pk }];
|
|
291
303
|
}
|
|
292
|
-
|
|
304
|
+
logger3.trace("itemKeyToLocKeyArray Results", { ik: abbrevIK(ik), lka: abbrevLKA(lka) });
|
|
293
305
|
return lka;
|
|
294
306
|
};
|
|
295
307
|
var ikToLKA = itemKeyToLocKeyArray;
|
|
296
308
|
var locKeyArrayToItemKey = (lka) => {
|
|
297
|
-
|
|
309
|
+
logger3.trace("locKeyArrayToItemKey", { lka: abbrevLKA(lka) });
|
|
298
310
|
if (lka && lka.length === 1) {
|
|
299
311
|
const priKey = cPK(lka[0].lk, lka[0].kt);
|
|
300
312
|
return priKey;
|
|
@@ -538,7 +550,7 @@ var IQFactory = class _IQFactory {
|
|
|
538
550
|
|
|
539
551
|
// src/item/IQUtils.ts
|
|
540
552
|
import * as luxon from "luxon";
|
|
541
|
-
var
|
|
553
|
+
var logger4 = logger_default.get("IQUtils");
|
|
542
554
|
var queryToParams = (query) => {
|
|
543
555
|
const params = {};
|
|
544
556
|
if (query.compoundCondition) {
|
|
@@ -594,8 +606,8 @@ var paramsToQuery = (params) => {
|
|
|
594
606
|
return query;
|
|
595
607
|
};
|
|
596
608
|
var isRefQueryMatch = (refKey, queryRef, references) => {
|
|
597
|
-
|
|
598
|
-
|
|
609
|
+
logger4.trace("doesRefMatch", { queryRef, references });
|
|
610
|
+
logger4.debug("Comparing Ref", { refKey, itemRef: references[refKey], queryRef });
|
|
599
611
|
if (!references[refKey]) {
|
|
600
612
|
return false;
|
|
601
613
|
}
|
|
@@ -614,12 +626,12 @@ var isCompoundConditionQueryMatch = (queryCondition, item) => {
|
|
|
614
626
|
};
|
|
615
627
|
var isConditionQueryMatch = (queryCondition, item) => {
|
|
616
628
|
const propKey = queryCondition.column;
|
|
617
|
-
|
|
629
|
+
logger4.trace("doesConditionMatch", { propKey, queryCondition, item });
|
|
618
630
|
if (item[propKey] === void 0) {
|
|
619
|
-
|
|
631
|
+
logger4.debug("Item does not contain prop under key", { propKey, item });
|
|
620
632
|
return false;
|
|
621
633
|
}
|
|
622
|
-
|
|
634
|
+
logger4.debug("Comparing Condition", { propKey, itemProp: item[propKey], queryCondition });
|
|
623
635
|
if (queryCondition.value === null) {
|
|
624
636
|
if (queryCondition.operator === "==") {
|
|
625
637
|
return item[propKey] === null;
|
|
@@ -668,7 +680,7 @@ var isConditionQueryMatch = (queryCondition, item) => {
|
|
|
668
680
|
};
|
|
669
681
|
var isAggQueryMatch = (aggKey, aggQuery, agg) => {
|
|
670
682
|
const aggItem = agg.item;
|
|
671
|
-
|
|
683
|
+
logger4.debug("Comparing Agg", { aggKey, aggItem, aggQuery });
|
|
672
684
|
if (!aggItem) {
|
|
673
685
|
return false;
|
|
674
686
|
}
|
|
@@ -676,35 +688,35 @@ var isAggQueryMatch = (aggKey, aggQuery, agg) => {
|
|
|
676
688
|
};
|
|
677
689
|
var isEventQueryMatch = (eventKey, eventQuery, item) => {
|
|
678
690
|
if (!item.events[eventKey]) {
|
|
679
|
-
|
|
691
|
+
logger4.debug("Item does not contain event under key", { eventKey, events: item.events });
|
|
680
692
|
return false;
|
|
681
693
|
} else {
|
|
682
694
|
const itemEvent = item.events[eventKey];
|
|
683
695
|
if (itemEvent.at !== null) {
|
|
684
696
|
if (eventQuery.start && !(eventQuery.start.getTime() <= itemEvent.at.getTime())) {
|
|
685
|
-
|
|
697
|
+
logger4.debug("Item date before event start query", { eventQuery, itemEvent });
|
|
686
698
|
return false;
|
|
687
699
|
}
|
|
688
700
|
if (eventQuery.end && !(eventQuery.end.getTime() > itemEvent.at.getTime())) {
|
|
689
|
-
|
|
701
|
+
logger4.debug("Item date after event end query", { eventQuery, itemEvent });
|
|
690
702
|
return false;
|
|
691
703
|
}
|
|
692
704
|
} else {
|
|
693
|
-
|
|
705
|
+
logger4.debug("Item event does contains a null at", { itemEvent });
|
|
694
706
|
return false;
|
|
695
707
|
}
|
|
696
708
|
return true;
|
|
697
709
|
}
|
|
698
710
|
};
|
|
699
711
|
var isQueryMatch = (item, query) => {
|
|
700
|
-
|
|
712
|
+
logger4.trace("isMatch", { item, query });
|
|
701
713
|
if (query.refs && item.refs) {
|
|
702
714
|
for (const key in query.refs) {
|
|
703
715
|
const queryRef = query.refs[key];
|
|
704
716
|
if (!isRefQueryMatch(key, queryRef.key, item.refs)) return false;
|
|
705
717
|
}
|
|
706
718
|
} else if (query.refs && !item.refs) {
|
|
707
|
-
|
|
719
|
+
logger4.debug("Query contains refs but item does not have refs", { query, item });
|
|
708
720
|
return false;
|
|
709
721
|
}
|
|
710
722
|
if (query.compoundCondition && item) {
|
|
@@ -734,7 +746,7 @@ var isQueryMatch = (item, query) => {
|
|
|
734
746
|
}
|
|
735
747
|
}
|
|
736
748
|
} else if (query.aggs && !item.aggs) {
|
|
737
|
-
|
|
749
|
+
logger4.debug("Query contains aggs but item does not have aggs", { query, item });
|
|
738
750
|
return false;
|
|
739
751
|
}
|
|
740
752
|
return true;
|
|
@@ -796,33 +808,33 @@ var abbrevCondition = (condition) => {
|
|
|
796
808
|
}
|
|
797
809
|
};
|
|
798
810
|
|
|
799
|
-
// src/
|
|
800
|
-
var
|
|
811
|
+
// src/validation/ItemValidator.ts
|
|
812
|
+
var logger5 = logger_default.get("validation", "ItemValidator");
|
|
801
813
|
var validatePKForItem = (item, pkType) => {
|
|
802
814
|
if (!item) {
|
|
803
|
-
|
|
815
|
+
logger5.error("Validating PK, Item is undefined", { item });
|
|
804
816
|
throw new Error("Validating PK, Item is undefined");
|
|
805
817
|
}
|
|
806
818
|
if (!item.key) {
|
|
807
|
-
|
|
819
|
+
logger5.error("Validating PK, Item does not have a key", { item });
|
|
808
820
|
throw new Error("Validating PK, Item does not have a key");
|
|
809
821
|
}
|
|
810
822
|
const keyTypeArray = toKeyTypeArray(item.key);
|
|
811
823
|
if (keyTypeArray[0] !== pkType) {
|
|
812
|
-
|
|
824
|
+
logger5.error("Key Type Array Mismatch", { keyTypeArray, pkType });
|
|
813
825
|
throw new Error(`Item does not have the correct primary key type. Expected ${pkType}, got ${keyTypeArray[0]}`);
|
|
814
826
|
}
|
|
815
827
|
return item;
|
|
816
828
|
};
|
|
817
829
|
var validatePK = (input, pkType) => {
|
|
818
|
-
|
|
830
|
+
logger5.trace("Checking Return Type", { input });
|
|
819
831
|
if (Array.isArray(input)) {
|
|
820
832
|
return input.map((item) => validatePKForItem(item, pkType));
|
|
821
833
|
}
|
|
822
834
|
return validatePKForItem(input, pkType);
|
|
823
835
|
};
|
|
824
836
|
var validateKeys = (item, keyTypes) => {
|
|
825
|
-
|
|
837
|
+
logger5.trace("Checking Return Type", { item });
|
|
826
838
|
if (!item) {
|
|
827
839
|
throw new Error("validating keys, item is undefined");
|
|
828
840
|
}
|
|
@@ -835,22 +847,1244 @@ var validateKeys = (item, keyTypes) => {
|
|
|
835
847
|
}
|
|
836
848
|
const match = JSON.stringify(keyTypeArray) === JSON.stringify(keyTypes);
|
|
837
849
|
if (!match) {
|
|
838
|
-
|
|
850
|
+
logger5.error("Key Type Array Mismatch", { keyTypeArray, thisKeyTypes: keyTypes });
|
|
839
851
|
throw new Error(`Item does not have the correct key types. Expected [${keyTypes.join(", ")}], but got [${keyTypeArray.join(", ")}]`);
|
|
840
852
|
}
|
|
841
853
|
return item;
|
|
842
854
|
};
|
|
855
|
+
|
|
856
|
+
// src/item/IUtils.ts
|
|
843
857
|
var isPriItem = (item) => {
|
|
844
858
|
return !!(item && item.key && isPriKey(item.key));
|
|
845
859
|
};
|
|
846
860
|
var isComItem = (item) => {
|
|
847
861
|
return !!(item && item.key && isComKey(item.key));
|
|
848
862
|
};
|
|
863
|
+
|
|
864
|
+
// src/validation/LocationValidator.ts
|
|
865
|
+
var logger6 = logger_default.get("validation", "LocationValidator");
|
|
866
|
+
var validateLocations = (locations, coordinate, operation) => {
|
|
867
|
+
if (!locations || locations.length === 0) {
|
|
868
|
+
return;
|
|
869
|
+
}
|
|
870
|
+
const keyTypeArray = coordinate.kta;
|
|
871
|
+
const expectedLocationTypes = keyTypeArray.slice(1);
|
|
872
|
+
const actualLocationTypes = locations.map((loc) => loc.kt);
|
|
873
|
+
logger6.debug(`Validating locations for ${operation}`, {
|
|
874
|
+
expected: expectedLocationTypes,
|
|
875
|
+
actual: actualLocationTypes,
|
|
876
|
+
coordinate: keyTypeArray
|
|
877
|
+
});
|
|
878
|
+
if (actualLocationTypes.length > expectedLocationTypes.length) {
|
|
879
|
+
logger6.error("Location key array has too many elements", {
|
|
880
|
+
expected: expectedLocationTypes.length,
|
|
881
|
+
actual: actualLocationTypes.length,
|
|
882
|
+
expectedTypes: expectedLocationTypes,
|
|
883
|
+
actualTypes: actualLocationTypes,
|
|
884
|
+
coordinate,
|
|
885
|
+
operation
|
|
886
|
+
});
|
|
887
|
+
throw new Error(
|
|
888
|
+
`Invalid location key array for ${operation}: Expected at most ${expectedLocationTypes.length} location keys (hierarchy: [${expectedLocationTypes.join(", ")}]), but received ${actualLocationTypes.length} (types: [${actualLocationTypes.join(", ")}])`
|
|
889
|
+
);
|
|
890
|
+
}
|
|
891
|
+
for (let i = 0; i < actualLocationTypes.length; i++) {
|
|
892
|
+
if (expectedLocationTypes[i] !== actualLocationTypes[i]) {
|
|
893
|
+
logger6.error("Location key array order mismatch", {
|
|
894
|
+
position: i,
|
|
895
|
+
expected: expectedLocationTypes[i],
|
|
896
|
+
actual: actualLocationTypes[i],
|
|
897
|
+
expectedHierarchy: expectedLocationTypes,
|
|
898
|
+
actualOrder: actualLocationTypes,
|
|
899
|
+
coordinate,
|
|
900
|
+
operation
|
|
901
|
+
});
|
|
902
|
+
throw new Error(
|
|
903
|
+
`Invalid location key array order for ${operation}: At position ${i}, expected key type "${expectedLocationTypes[i]}" but received "${actualLocationTypes[i]}". Location keys must be ordered according to the hierarchy: [${expectedLocationTypes.join(", ")}]. Received order: [${actualLocationTypes.join(", ")}]`
|
|
904
|
+
);
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
logger6.debug(`Location key array validation passed for ${operation}`, { locations });
|
|
908
|
+
};
|
|
909
|
+
var isValidLocations = (locations, coordinate, operation) => {
|
|
910
|
+
try {
|
|
911
|
+
validateLocations(locations, coordinate, operation);
|
|
912
|
+
return { valid: true };
|
|
913
|
+
} catch (error) {
|
|
914
|
+
return {
|
|
915
|
+
valid: false,
|
|
916
|
+
error: error instanceof Error ? error.message : String(error)
|
|
917
|
+
};
|
|
918
|
+
}
|
|
919
|
+
};
|
|
920
|
+
|
|
921
|
+
// src/validation/KeyValidator.ts
|
|
922
|
+
var logger7 = logger_default.get("validation", "KeyValidator");
|
|
923
|
+
var validateLocationKeyOrder = (key, coordinate, operation) => {
|
|
924
|
+
const keyTypeArray = coordinate.kta;
|
|
925
|
+
const expectedLocationTypes = keyTypeArray.slice(1);
|
|
926
|
+
const actualLocationTypes = key.loc.map((loc) => loc.kt);
|
|
927
|
+
if (expectedLocationTypes.length !== actualLocationTypes.length) {
|
|
928
|
+
logger7.error("Location key array length mismatch", {
|
|
929
|
+
expected: expectedLocationTypes.length,
|
|
930
|
+
actual: actualLocationTypes.length,
|
|
931
|
+
key,
|
|
932
|
+
coordinate,
|
|
933
|
+
operation
|
|
934
|
+
});
|
|
935
|
+
const expectedOrder = expectedLocationTypes.map(
|
|
936
|
+
(kt, i) => ` [${i}] { kt: '${kt}', lk: <value> }`
|
|
937
|
+
).join("\n");
|
|
938
|
+
const actualOrder = key.loc.map(
|
|
939
|
+
(loc, i) => ` [${i}] { kt: '${loc.kt}', lk: ${JSON.stringify(loc.lk)} }`
|
|
940
|
+
).join("\n");
|
|
941
|
+
throw new Error(
|
|
942
|
+
`Location key array length mismatch for ${operation} operation.
|
|
943
|
+
|
|
944
|
+
Expected ${expectedLocationTypes.length} location keys but received ${actualLocationTypes.length}.
|
|
945
|
+
|
|
946
|
+
Expected location key order for '${keyTypeArray[0]}':
|
|
947
|
+
${expectedOrder}
|
|
948
|
+
|
|
949
|
+
Received location key order:
|
|
950
|
+
${actualOrder}`
|
|
951
|
+
);
|
|
952
|
+
}
|
|
953
|
+
for (let i = 0; i < expectedLocationTypes.length; i++) {
|
|
954
|
+
if (expectedLocationTypes[i] !== actualLocationTypes[i]) {
|
|
955
|
+
logger7.error("Location key array order mismatch", {
|
|
956
|
+
position: i,
|
|
957
|
+
expected: expectedLocationTypes[i],
|
|
958
|
+
actual: actualLocationTypes[i],
|
|
959
|
+
key,
|
|
960
|
+
coordinate,
|
|
961
|
+
operation
|
|
962
|
+
});
|
|
963
|
+
const expectedOrder = expectedLocationTypes.map(
|
|
964
|
+
(kt, i2) => ` [${i2}] { kt: '${kt}', lk: <value> }`
|
|
965
|
+
).join("\n");
|
|
966
|
+
const actualOrder = key.loc.map(
|
|
967
|
+
(loc, i2) => ` [${i2}] { kt: '${loc.kt}', lk: ${JSON.stringify(loc.lk)} }`
|
|
968
|
+
).join("\n");
|
|
969
|
+
throw new Error(
|
|
970
|
+
`Location key array order mismatch for ${operation} operation.
|
|
971
|
+
|
|
972
|
+
At position ${i}, expected key type "${expectedLocationTypes[i]}" but received "${actualLocationTypes[i]}".
|
|
973
|
+
|
|
974
|
+
Expected location key order for '${keyTypeArray[0]}':
|
|
975
|
+
${expectedOrder}
|
|
976
|
+
|
|
977
|
+
Received location key order:
|
|
978
|
+
${actualOrder}
|
|
979
|
+
|
|
980
|
+
Tip: Location keys must be ordered according to the hierarchy: [${expectedLocationTypes.join(", ")}]`
|
|
981
|
+
);
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
};
|
|
985
|
+
var validateKey = (key, coordinate, operation) => {
|
|
986
|
+
logger7.debug(`Validating key for ${operation}`, { key, coordinate: coordinate.kta });
|
|
987
|
+
if (!key || key === null) {
|
|
988
|
+
throw new Error(
|
|
989
|
+
`Invalid key structure for ${operation} operation.
|
|
990
|
+
|
|
991
|
+
The provided key is null or undefined.
|
|
992
|
+
|
|
993
|
+
Valid key formats:
|
|
994
|
+
PriKey: { kt: string, pk: string|number }
|
|
995
|
+
ComKey: { kt: string, pk: string|number, loc: Array<{ kt: string, lk: string|number }> }`
|
|
996
|
+
);
|
|
997
|
+
}
|
|
998
|
+
const isCompositeLibrary = coordinate.kta.length > 1;
|
|
999
|
+
const keyIsComposite = isComKey(key);
|
|
1000
|
+
const keyIsPrimary = isPriKey(key);
|
|
1001
|
+
if (isCompositeLibrary && !keyIsComposite) {
|
|
1002
|
+
logger7.error(`Composite library received primary key in ${operation}`, { key, coordinate });
|
|
1003
|
+
const keyTypeArray = coordinate.kta;
|
|
1004
|
+
throw new Error(
|
|
1005
|
+
`Invalid key type for ${operation} operation.
|
|
1006
|
+
|
|
1007
|
+
This is a composite item library. You must provide a ComKey with location keys.
|
|
1008
|
+
|
|
1009
|
+
Expected: ComKey with format:
|
|
1010
|
+
{
|
|
1011
|
+
kt: '${keyTypeArray[0]}',
|
|
1012
|
+
pk: string|number,
|
|
1013
|
+
loc: [
|
|
1014
|
+
` + keyTypeArray.slice(1).map((kt) => ` { kt: '${kt}', lk: string|number }`).join(",\n") + `
|
|
1015
|
+
]
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
Received: PriKey with format:
|
|
1019
|
+
${JSON.stringify(key, null, 2)}
|
|
1020
|
+
|
|
1021
|
+
Example correct usage:
|
|
1022
|
+
library.operations.${operation}({
|
|
1023
|
+
kt: '${keyTypeArray[0]}',
|
|
1024
|
+
pk: 'item-id',
|
|
1025
|
+
loc: [${keyTypeArray.slice(1).map((kt) => `{ kt: '${kt}', lk: 'parent-id' }`).join(", ")}]
|
|
1026
|
+
})`
|
|
1027
|
+
);
|
|
1028
|
+
}
|
|
1029
|
+
if (!isCompositeLibrary && keyIsComposite) {
|
|
1030
|
+
logger7.error(`Primary library received composite key in ${operation}`, { key, coordinate });
|
|
1031
|
+
const keyTypeArray = coordinate.kta;
|
|
1032
|
+
throw new Error(
|
|
1033
|
+
`Invalid key type for ${operation} operation.
|
|
1034
|
+
|
|
1035
|
+
This is a primary item library. You should provide a PriKey without location keys.
|
|
1036
|
+
|
|
1037
|
+
Expected: PriKey with format:
|
|
1038
|
+
{ kt: '${keyTypeArray[0]}', pk: string|number }
|
|
1039
|
+
|
|
1040
|
+
Received: ComKey with format:
|
|
1041
|
+
${JSON.stringify(key, null, 2)}
|
|
1042
|
+
|
|
1043
|
+
Example correct usage:
|
|
1044
|
+
library.operations.${operation}({ kt: '${keyTypeArray[0]}', pk: 'item-id' })`
|
|
1045
|
+
);
|
|
1046
|
+
}
|
|
1047
|
+
if (!keyIsPrimary && !keyIsComposite) {
|
|
1048
|
+
logger7.error(`Invalid key structure in ${operation}`, { key, coordinate });
|
|
1049
|
+
throw new Error(
|
|
1050
|
+
`Invalid key structure for ${operation} operation.
|
|
1051
|
+
|
|
1052
|
+
The provided key does not match PriKey or ComKey format.
|
|
1053
|
+
|
|
1054
|
+
Received:
|
|
1055
|
+
${JSON.stringify(key, null, 2)}
|
|
1056
|
+
|
|
1057
|
+
Valid key formats:
|
|
1058
|
+
PriKey: { kt: string, pk: string|number }
|
|
1059
|
+
ComKey: { kt: string, pk: string|number, loc: Array<{ kt: string, lk: string|number }> }`
|
|
1060
|
+
);
|
|
1061
|
+
}
|
|
1062
|
+
const expectedKeyType = coordinate.kta[0];
|
|
1063
|
+
if (key.kt !== expectedKeyType) {
|
|
1064
|
+
logger7.error(`Key type mismatch in ${operation}`, {
|
|
1065
|
+
expected: expectedKeyType,
|
|
1066
|
+
received: key.kt,
|
|
1067
|
+
key,
|
|
1068
|
+
coordinate
|
|
1069
|
+
});
|
|
1070
|
+
throw new Error(
|
|
1071
|
+
`Invalid key type for ${operation} operation.
|
|
1072
|
+
|
|
1073
|
+
Expected key type: '${expectedKeyType}'
|
|
1074
|
+
Received key type: '${key.kt}'
|
|
1075
|
+
|
|
1076
|
+
Example correct usage:
|
|
1077
|
+
library.operations.${operation}({ kt: '${expectedKeyType}', pk: 'item-id', ... })`
|
|
1078
|
+
);
|
|
1079
|
+
}
|
|
1080
|
+
if (keyIsComposite) {
|
|
1081
|
+
const comKey = key;
|
|
1082
|
+
if (comKey.loc.length === 0) {
|
|
1083
|
+
logger7.debug(`Empty loc array detected in ${operation} - will search across all locations`, { key });
|
|
1084
|
+
} else {
|
|
1085
|
+
validateLocationKeyOrder(comKey, coordinate, operation);
|
|
1086
|
+
}
|
|
1087
|
+
}
|
|
1088
|
+
logger7.debug(`Key validation passed for ${operation}`, { key });
|
|
1089
|
+
};
|
|
1090
|
+
var validatePriKey = (key, expectedType, operation) => {
|
|
1091
|
+
if (!key || key === null) {
|
|
1092
|
+
throw new Error(`[${operation}] PriKey is undefined or null`);
|
|
1093
|
+
}
|
|
1094
|
+
if (!key.kt) {
|
|
1095
|
+
throw new Error(`[${operation}] PriKey is missing 'kt' field`);
|
|
1096
|
+
}
|
|
1097
|
+
if (key.kt !== expectedType) {
|
|
1098
|
+
throw new Error(
|
|
1099
|
+
`[${operation}] PriKey has incorrect type.
|
|
1100
|
+
Expected: '${expectedType}'
|
|
1101
|
+
Received: '${key.kt}'`
|
|
1102
|
+
);
|
|
1103
|
+
}
|
|
1104
|
+
if (typeof key.pk === "undefined" || key.pk === null) {
|
|
1105
|
+
throw new Error(`[${operation}] PriKey is missing 'pk' field`);
|
|
1106
|
+
}
|
|
1107
|
+
};
|
|
1108
|
+
var validateComKey = (key, coordinate, operation) => {
|
|
1109
|
+
if (!key || key === null) {
|
|
1110
|
+
throw new Error(`[${operation}] ComKey is undefined or null`);
|
|
1111
|
+
}
|
|
1112
|
+
if (!key.kt) {
|
|
1113
|
+
throw new Error(`[${operation}] ComKey is missing 'kt' field`);
|
|
1114
|
+
}
|
|
1115
|
+
if (key.kt !== coordinate.kta[0]) {
|
|
1116
|
+
throw new Error(
|
|
1117
|
+
`[${operation}] ComKey has incorrect type.
|
|
1118
|
+
Expected: '${coordinate.kta[0]}'
|
|
1119
|
+
Received: '${key.kt}'`
|
|
1120
|
+
);
|
|
1121
|
+
}
|
|
1122
|
+
if (typeof key.pk === "undefined" || key.pk === null) {
|
|
1123
|
+
throw new Error(`[${operation}] ComKey is missing 'pk' field`);
|
|
1124
|
+
}
|
|
1125
|
+
if (!Array.isArray(key.loc)) {
|
|
1126
|
+
throw new Error(`[${operation}] ComKey is missing or invalid 'loc' field (must be an array)`);
|
|
1127
|
+
}
|
|
1128
|
+
if (key.loc.length > 0) {
|
|
1129
|
+
validateLocationKeyOrder(key, coordinate, operation);
|
|
1130
|
+
}
|
|
1131
|
+
};
|
|
1132
|
+
|
|
1133
|
+
// src/validation/QueryValidator.ts
|
|
1134
|
+
var logger8 = logger_default.get("validation", "QueryValidator");
|
|
1135
|
+
var validateQuery = (query, operation) => {
|
|
1136
|
+
if (typeof query === "undefined" || query === null) {
|
|
1137
|
+
return;
|
|
1138
|
+
}
|
|
1139
|
+
if (typeof query !== "object") {
|
|
1140
|
+
logger8.error(`Invalid query type for ${operation}`, { query, type: typeof query });
|
|
1141
|
+
throw new Error(
|
|
1142
|
+
`[${operation}] Invalid query parameter.
|
|
1143
|
+
|
|
1144
|
+
Expected: object or undefined
|
|
1145
|
+
Received: ${typeof query}
|
|
1146
|
+
|
|
1147
|
+
Example valid queries:
|
|
1148
|
+
{}
|
|
1149
|
+
{ filter: { status: 'active' } }
|
|
1150
|
+
{ limit: 10, sort: { field: 'name', order: 'asc' } }`
|
|
1151
|
+
);
|
|
1152
|
+
}
|
|
1153
|
+
if (Array.isArray(query)) {
|
|
1154
|
+
logger8.error(`Query cannot be an array for ${operation}`, { query });
|
|
1155
|
+
throw new Error(
|
|
1156
|
+
`[${operation}] Invalid query parameter.
|
|
1157
|
+
|
|
1158
|
+
Query cannot be an array.
|
|
1159
|
+
Received: ${JSON.stringify(query)}`
|
|
1160
|
+
);
|
|
1161
|
+
}
|
|
1162
|
+
logger8.debug(`Query validation passed for ${operation}`, { query });
|
|
1163
|
+
};
|
|
1164
|
+
var validateOperationParams = (params, operation) => {
|
|
1165
|
+
if (typeof params === "undefined") {
|
|
1166
|
+
return;
|
|
1167
|
+
}
|
|
1168
|
+
if (params === null) {
|
|
1169
|
+
logger8.error(`Params cannot be null for ${operation}`, { params });
|
|
1170
|
+
throw new Error(
|
|
1171
|
+
`[${operation}] Invalid operation parameters.
|
|
1172
|
+
|
|
1173
|
+
Parameters cannot be null.
|
|
1174
|
+
Expected: object or undefined
|
|
1175
|
+
Received: null
|
|
1176
|
+
|
|
1177
|
+
Example valid parameters:
|
|
1178
|
+
{}
|
|
1179
|
+
{ email: 'user@example.com' }
|
|
1180
|
+
{ status: 'active', limit: 10 }`
|
|
1181
|
+
);
|
|
1182
|
+
}
|
|
1183
|
+
if (typeof params !== "object") {
|
|
1184
|
+
logger8.error(`Invalid params type for ${operation}`, { params, type: typeof params });
|
|
1185
|
+
throw new Error(
|
|
1186
|
+
`[${operation}] Invalid operation parameters.
|
|
1187
|
+
|
|
1188
|
+
Expected: object or undefined
|
|
1189
|
+
Received: ${typeof params}
|
|
1190
|
+
|
|
1191
|
+
Example valid parameters:
|
|
1192
|
+
{}
|
|
1193
|
+
{ email: 'user@example.com' }
|
|
1194
|
+
{ status: 'active', limit: 10 }`
|
|
1195
|
+
);
|
|
1196
|
+
}
|
|
1197
|
+
if (Array.isArray(params)) {
|
|
1198
|
+
logger8.error(`Params cannot be an array for ${operation}`, { params });
|
|
1199
|
+
throw new Error(
|
|
1200
|
+
`[${operation}] Invalid operation parameters.
|
|
1201
|
+
|
|
1202
|
+
Parameters cannot be an array.
|
|
1203
|
+
Received: ${JSON.stringify(params)}`
|
|
1204
|
+
);
|
|
1205
|
+
}
|
|
1206
|
+
for (const [key, value] of Object.entries(params)) {
|
|
1207
|
+
const valueType = typeof value;
|
|
1208
|
+
const isValidType = valueType === "string" || valueType === "number" || valueType === "boolean" || value instanceof Date || Array.isArray(value) && value.every(
|
|
1209
|
+
(v) => typeof v === "string" || typeof v === "number" || typeof v === "boolean" || v instanceof Date
|
|
1210
|
+
);
|
|
1211
|
+
if (!isValidType) {
|
|
1212
|
+
logger8.error(`Invalid param value type for ${operation}`, { key, value, valueType });
|
|
1213
|
+
throw new Error(
|
|
1214
|
+
`[${operation}] Invalid value type for parameter "${key}".
|
|
1215
|
+
|
|
1216
|
+
Allowed types: string, number, boolean, Date, or arrays of these types
|
|
1217
|
+
Received: ${valueType}
|
|
1218
|
+
Value: ${JSON.stringify(value)}`
|
|
1219
|
+
);
|
|
1220
|
+
}
|
|
1221
|
+
}
|
|
1222
|
+
logger8.debug(`Operation params validation passed for ${operation}`, { params });
|
|
1223
|
+
};
|
|
1224
|
+
var validateFinderName = (finder, operation) => {
|
|
1225
|
+
if (!finder || typeof finder !== "string") {
|
|
1226
|
+
logger8.error(`Invalid finder name for ${operation}`, { finder, type: typeof finder });
|
|
1227
|
+
throw new Error(
|
|
1228
|
+
`[${operation}] Finder name must be a non-empty string.
|
|
1229
|
+
|
|
1230
|
+
Received: ${JSON.stringify(finder)}`
|
|
1231
|
+
);
|
|
1232
|
+
}
|
|
1233
|
+
if (finder.trim().length === 0) {
|
|
1234
|
+
logger8.error(`Empty finder name for ${operation}`, { finder });
|
|
1235
|
+
throw new Error(
|
|
1236
|
+
`[${operation}] Finder name cannot be empty or whitespace only.
|
|
1237
|
+
|
|
1238
|
+
Received: "${finder}"`
|
|
1239
|
+
);
|
|
1240
|
+
}
|
|
1241
|
+
logger8.debug(`Finder name validation passed for ${operation}`, { finder });
|
|
1242
|
+
};
|
|
1243
|
+
var validateActionName = (action, operation) => {
|
|
1244
|
+
if (!action || typeof action !== "string") {
|
|
1245
|
+
logger8.error(`Invalid action name for ${operation}`, { action, type: typeof action });
|
|
1246
|
+
throw new Error(
|
|
1247
|
+
`[${operation}] Action name must be a non-empty string.
|
|
1248
|
+
|
|
1249
|
+
Received: ${JSON.stringify(action)}`
|
|
1250
|
+
);
|
|
1251
|
+
}
|
|
1252
|
+
if (action.trim().length === 0) {
|
|
1253
|
+
logger8.error(`Empty action name for ${operation}`, { action });
|
|
1254
|
+
throw new Error(
|
|
1255
|
+
`[${operation}] Action name cannot be empty or whitespace only.
|
|
1256
|
+
|
|
1257
|
+
Received: "${action}"`
|
|
1258
|
+
);
|
|
1259
|
+
}
|
|
1260
|
+
logger8.debug(`Action name validation passed for ${operation}`, { action });
|
|
1261
|
+
};
|
|
1262
|
+
var validateFacetName = (facet, operation) => {
|
|
1263
|
+
if (!facet || typeof facet !== "string") {
|
|
1264
|
+
logger8.error(`Invalid facet name for ${operation}`, { facet, type: typeof facet });
|
|
1265
|
+
throw new Error(
|
|
1266
|
+
`[${operation}] Facet name must be a non-empty string.
|
|
1267
|
+
|
|
1268
|
+
Received: ${JSON.stringify(facet)}`
|
|
1269
|
+
);
|
|
1270
|
+
}
|
|
1271
|
+
if (facet.trim().length === 0) {
|
|
1272
|
+
logger8.error(`Empty facet name for ${operation}`, { facet });
|
|
1273
|
+
throw new Error(
|
|
1274
|
+
`[${operation}] Facet name cannot be empty or whitespace only.
|
|
1275
|
+
|
|
1276
|
+
Received: "${facet}"`
|
|
1277
|
+
);
|
|
1278
|
+
}
|
|
1279
|
+
logger8.debug(`Facet name validation passed for ${operation}`, { facet });
|
|
1280
|
+
};
|
|
1281
|
+
|
|
1282
|
+
// src/errors/ActionError.ts
|
|
1283
|
+
var ActionError = class extends Error {
|
|
1284
|
+
constructor(errorInfo, cause) {
|
|
1285
|
+
super(errorInfo.message);
|
|
1286
|
+
this.errorInfo = errorInfo;
|
|
1287
|
+
this.name = "ActionError";
|
|
1288
|
+
this.cause = cause;
|
|
1289
|
+
if (!this.errorInfo.technical) {
|
|
1290
|
+
this.errorInfo.technical = { timestamp: (/* @__PURE__ */ new Date()).toISOString() };
|
|
1291
|
+
}
|
|
1292
|
+
if (!this.errorInfo.technical.timestamp) {
|
|
1293
|
+
this.errorInfo.technical.timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
1294
|
+
}
|
|
1295
|
+
}
|
|
1296
|
+
toJSON() {
|
|
1297
|
+
return this.errorInfo;
|
|
1298
|
+
}
|
|
1299
|
+
};
|
|
1300
|
+
|
|
1301
|
+
// src/errors/ValidationError.ts
|
|
1302
|
+
var ValidationError = class extends ActionError {
|
|
1303
|
+
constructor(message, validOptions, suggestedAction, conflictingValue) {
|
|
1304
|
+
super({
|
|
1305
|
+
code: "VALIDATION_ERROR",
|
|
1306
|
+
message,
|
|
1307
|
+
operation: { type: "create", name: "", params: {} },
|
|
1308
|
+
// Will be filled by wrapper
|
|
1309
|
+
context: { itemType: "" },
|
|
1310
|
+
// Will be filled by wrapper
|
|
1311
|
+
details: {
|
|
1312
|
+
validOptions,
|
|
1313
|
+
suggestedAction,
|
|
1314
|
+
retryable: true,
|
|
1315
|
+
conflictingValue
|
|
1316
|
+
},
|
|
1317
|
+
technical: {
|
|
1318
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
1319
|
+
}
|
|
1320
|
+
});
|
|
1321
|
+
}
|
|
1322
|
+
};
|
|
1323
|
+
|
|
1324
|
+
// src/errors/NotFoundError.ts
|
|
1325
|
+
var NotFoundError = class extends ActionError {
|
|
1326
|
+
constructor(message, itemType, key) {
|
|
1327
|
+
super({
|
|
1328
|
+
code: "NOT_FOUND",
|
|
1329
|
+
message,
|
|
1330
|
+
operation: { type: "get", name: "", params: {} },
|
|
1331
|
+
context: {
|
|
1332
|
+
itemType,
|
|
1333
|
+
key: typeof key === "object" ? key : { primary: key }
|
|
1334
|
+
},
|
|
1335
|
+
details: { retryable: false },
|
|
1336
|
+
technical: {
|
|
1337
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
1338
|
+
}
|
|
1339
|
+
});
|
|
1340
|
+
}
|
|
1341
|
+
};
|
|
1342
|
+
|
|
1343
|
+
// src/errors/BusinessLogicError.ts
|
|
1344
|
+
var BusinessLogicError = class extends ActionError {
|
|
1345
|
+
constructor(message, suggestedAction, retryable = false) {
|
|
1346
|
+
super({
|
|
1347
|
+
code: "BUSINESS_LOGIC_ERROR",
|
|
1348
|
+
message,
|
|
1349
|
+
operation: { type: "action", name: "", params: {} },
|
|
1350
|
+
context: { itemType: "" },
|
|
1351
|
+
details: {
|
|
1352
|
+
suggestedAction,
|
|
1353
|
+
retryable
|
|
1354
|
+
},
|
|
1355
|
+
technical: {
|
|
1356
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
1357
|
+
}
|
|
1358
|
+
});
|
|
1359
|
+
}
|
|
1360
|
+
};
|
|
1361
|
+
|
|
1362
|
+
// src/errors/PermissionError.ts
|
|
1363
|
+
var PermissionError = class extends ActionError {
|
|
1364
|
+
constructor(message, requiredPermission, currentPermissions) {
|
|
1365
|
+
super({
|
|
1366
|
+
code: "PERMISSION_DENIED",
|
|
1367
|
+
message,
|
|
1368
|
+
operation: { type: "action", name: "", params: {} },
|
|
1369
|
+
context: {
|
|
1370
|
+
itemType: "",
|
|
1371
|
+
...requiredPermission && { requiredPermission }
|
|
1372
|
+
},
|
|
1373
|
+
details: {
|
|
1374
|
+
...requiredPermission && {
|
|
1375
|
+
suggestedAction: `Required permission: ${requiredPermission}`,
|
|
1376
|
+
expectedValue: requiredPermission
|
|
1377
|
+
},
|
|
1378
|
+
...currentPermissions && { conflictingValue: currentPermissions },
|
|
1379
|
+
retryable: false
|
|
1380
|
+
},
|
|
1381
|
+
technical: {
|
|
1382
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
1383
|
+
}
|
|
1384
|
+
});
|
|
1385
|
+
}
|
|
1386
|
+
};
|
|
1387
|
+
|
|
1388
|
+
// src/errors/DuplicateError.ts
|
|
1389
|
+
var DuplicateError = class extends ActionError {
|
|
1390
|
+
constructor(message, existingItemIdOrKey, duplicateField) {
|
|
1391
|
+
let existingItemId = null;
|
|
1392
|
+
let keyInfo = null;
|
|
1393
|
+
if (typeof existingItemIdOrKey === "object" && existingItemIdOrKey !== null) {
|
|
1394
|
+
existingItemId = existingItemIdOrKey.pk || existingItemIdOrKey.id || existingItemIdOrKey.primary || null;
|
|
1395
|
+
if (existingItemId !== null) {
|
|
1396
|
+
keyInfo = {
|
|
1397
|
+
primary: existingItemId,
|
|
1398
|
+
...existingItemIdOrKey
|
|
1399
|
+
};
|
|
1400
|
+
} else {
|
|
1401
|
+
keyInfo = existingItemIdOrKey;
|
|
1402
|
+
}
|
|
1403
|
+
} else if (typeof existingItemIdOrKey !== "undefined") {
|
|
1404
|
+
existingItemId = existingItemIdOrKey;
|
|
1405
|
+
keyInfo = { primary: existingItemId };
|
|
1406
|
+
}
|
|
1407
|
+
super({
|
|
1408
|
+
code: "DUPLICATE_ERROR",
|
|
1409
|
+
message,
|
|
1410
|
+
operation: { type: "create", name: "", params: {} },
|
|
1411
|
+
context: {
|
|
1412
|
+
itemType: "",
|
|
1413
|
+
...keyInfo && { key: keyInfo },
|
|
1414
|
+
...existingItemId && {
|
|
1415
|
+
affectedItems: [{
|
|
1416
|
+
id: existingItemId,
|
|
1417
|
+
type: "",
|
|
1418
|
+
displayName: `Existing item with ${duplicateField || "key"}`
|
|
1419
|
+
}]
|
|
1420
|
+
}
|
|
1421
|
+
},
|
|
1422
|
+
details: {
|
|
1423
|
+
retryable: false,
|
|
1424
|
+
conflictingValue: duplicateField
|
|
1425
|
+
},
|
|
1426
|
+
technical: {
|
|
1427
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
1428
|
+
}
|
|
1429
|
+
});
|
|
1430
|
+
}
|
|
1431
|
+
};
|
|
1432
|
+
|
|
1433
|
+
// src/operations/errorEnhancer.ts
|
|
1434
|
+
async function executeWithContext(operation, context) {
|
|
1435
|
+
try {
|
|
1436
|
+
return await operation();
|
|
1437
|
+
} catch (error) {
|
|
1438
|
+
throw enhanceError(error, context);
|
|
1439
|
+
}
|
|
1440
|
+
}
|
|
1441
|
+
function executeWithContextSync(operation, context) {
|
|
1442
|
+
try {
|
|
1443
|
+
return operation();
|
|
1444
|
+
} catch (error) {
|
|
1445
|
+
throw enhanceError(error, context);
|
|
1446
|
+
}
|
|
1447
|
+
}
|
|
1448
|
+
function enhanceError(error, context) {
|
|
1449
|
+
if (!(error instanceof ActionError)) {
|
|
1450
|
+
return error;
|
|
1451
|
+
}
|
|
1452
|
+
error.errorInfo.operation = {
|
|
1453
|
+
type: context.operationType,
|
|
1454
|
+
name: context.operationName,
|
|
1455
|
+
params: context.params
|
|
1456
|
+
};
|
|
1457
|
+
if (!error.errorInfo.context.itemType) {
|
|
1458
|
+
error.errorInfo.context.itemType = context.itemType;
|
|
1459
|
+
}
|
|
1460
|
+
if (context.key) {
|
|
1461
|
+
const existingKey = error.errorInfo.context.key;
|
|
1462
|
+
const hasNoPrimaryKey = !existingKey || typeof existingKey.primary === "undefined";
|
|
1463
|
+
const hasNoCompositeKey = !existingKey || !existingKey.composite;
|
|
1464
|
+
const shouldOverride = hasNoPrimaryKey && hasNoCompositeKey;
|
|
1465
|
+
if (shouldOverride) {
|
|
1466
|
+
error.errorInfo.context.key = extractKeyInfo(context.key);
|
|
1467
|
+
}
|
|
1468
|
+
}
|
|
1469
|
+
if (context.locations && context.locations.length > 0 && !error.errorInfo.context.parentLocation) {
|
|
1470
|
+
error.errorInfo.context.parentLocation = {
|
|
1471
|
+
id: context.locations[0].lk,
|
|
1472
|
+
type: context.locations[0].kt
|
|
1473
|
+
};
|
|
1474
|
+
}
|
|
1475
|
+
return error;
|
|
1476
|
+
}
|
|
1477
|
+
function extractKeyInfo(key) {
|
|
1478
|
+
if ("loc" in key) {
|
|
1479
|
+
const ktaArray = Array.isArray(key.kt) ? key.kt : [key.kt];
|
|
1480
|
+
const locations = Array.isArray(key.loc) ? key.loc : [];
|
|
1481
|
+
return {
|
|
1482
|
+
composite: {
|
|
1483
|
+
sk: key.pk,
|
|
1484
|
+
kta: ktaArray,
|
|
1485
|
+
locations: locations.map((loc) => ({
|
|
1486
|
+
lk: loc.lk,
|
|
1487
|
+
kt: loc.kt
|
|
1488
|
+
}))
|
|
1489
|
+
}
|
|
1490
|
+
};
|
|
1491
|
+
} else if ("pk" in key) {
|
|
1492
|
+
return { primary: key.pk };
|
|
1493
|
+
}
|
|
1494
|
+
return { primary: JSON.stringify(key) };
|
|
1495
|
+
}
|
|
1496
|
+
function isActionError(error) {
|
|
1497
|
+
return error instanceof ActionError;
|
|
1498
|
+
}
|
|
1499
|
+
function getErrorInfo(error) {
|
|
1500
|
+
if (isActionError(error)) {
|
|
1501
|
+
return error.toJSON();
|
|
1502
|
+
}
|
|
1503
|
+
if (error instanceof Error) {
|
|
1504
|
+
return {
|
|
1505
|
+
code: "UNKNOWN_ERROR",
|
|
1506
|
+
message: error.message,
|
|
1507
|
+
technical: {
|
|
1508
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1509
|
+
stackTrace: error.stack
|
|
1510
|
+
}
|
|
1511
|
+
};
|
|
1512
|
+
}
|
|
1513
|
+
return {
|
|
1514
|
+
code: "UNKNOWN_ERROR",
|
|
1515
|
+
message: String(error),
|
|
1516
|
+
technical: {
|
|
1517
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
1518
|
+
}
|
|
1519
|
+
};
|
|
1520
|
+
}
|
|
1521
|
+
|
|
1522
|
+
// src/operations/Operations.ts
|
|
1523
|
+
function isPriKey2(key) {
|
|
1524
|
+
return !("loc" in key) || !key.loc;
|
|
1525
|
+
}
|
|
1526
|
+
function isComKey2(key) {
|
|
1527
|
+
return "loc" in key && key.loc && Array.isArray(key.loc) && key.loc.length > 0;
|
|
1528
|
+
}
|
|
1529
|
+
|
|
1530
|
+
// src/operations/wrappers/createOneWrapper.ts
|
|
1531
|
+
var logger9 = logger_default.get("operations", "wrappers", "one");
|
|
1532
|
+
function createOneWrapper(coordinate, implementation, options = {}) {
|
|
1533
|
+
const operationName = options.operationName || "one";
|
|
1534
|
+
return async (query, locations) => {
|
|
1535
|
+
if (options.debug) {
|
|
1536
|
+
logger9.debug(`[${operationName}] Called with:`, { query, locations });
|
|
1537
|
+
}
|
|
1538
|
+
if (!options.skipValidation) {
|
|
1539
|
+
try {
|
|
1540
|
+
validateQuery(query, operationName);
|
|
1541
|
+
validateLocations(locations, coordinate, operationName);
|
|
1542
|
+
} catch (error) {
|
|
1543
|
+
throw error;
|
|
1544
|
+
}
|
|
1545
|
+
}
|
|
1546
|
+
const normalizedQuery = query ?? {};
|
|
1547
|
+
const normalizedLocations = locations ?? [];
|
|
1548
|
+
try {
|
|
1549
|
+
const result = await implementation(normalizedQuery, normalizedLocations);
|
|
1550
|
+
if (options.debug) {
|
|
1551
|
+
logger9.debug(`[${operationName}] Result:`, result ? "found" : "not found");
|
|
1552
|
+
}
|
|
1553
|
+
if (result && !options.skipValidation) {
|
|
1554
|
+
return validatePK(result, coordinate.kta[0]);
|
|
1555
|
+
}
|
|
1556
|
+
return result;
|
|
1557
|
+
} catch (error) {
|
|
1558
|
+
if (options.onError) {
|
|
1559
|
+
const context = {
|
|
1560
|
+
operationName,
|
|
1561
|
+
params: [query, locations],
|
|
1562
|
+
coordinate
|
|
1563
|
+
};
|
|
1564
|
+
throw options.onError(error, context);
|
|
1565
|
+
}
|
|
1566
|
+
const enhanced = new Error(
|
|
1567
|
+
`[${operationName}] Operation failed: ${error.message}`,
|
|
1568
|
+
{ cause: error }
|
|
1569
|
+
);
|
|
1570
|
+
if (error.stack) {
|
|
1571
|
+
enhanced.stack = error.stack;
|
|
1572
|
+
}
|
|
1573
|
+
throw enhanced;
|
|
1574
|
+
}
|
|
1575
|
+
};
|
|
1576
|
+
}
|
|
1577
|
+
|
|
1578
|
+
// src/operations/wrappers/createAllWrapper.ts
|
|
1579
|
+
var logger10 = logger_default.get("operations", "wrappers", "all");
|
|
1580
|
+
function createAllWrapper(coordinate, implementation, options = {}) {
|
|
1581
|
+
const operationName = options.operationName || "all";
|
|
1582
|
+
return async (query, locations) => {
|
|
1583
|
+
if (options.debug) {
|
|
1584
|
+
logger10.debug(`[${operationName}] Called with:`, { query, locations });
|
|
1585
|
+
}
|
|
1586
|
+
if (!options.skipValidation) {
|
|
1587
|
+
validateQuery(query, operationName);
|
|
1588
|
+
validateLocations(locations, coordinate, operationName);
|
|
1589
|
+
}
|
|
1590
|
+
const normalizedQuery = query ?? {};
|
|
1591
|
+
const normalizedLocations = locations ?? [];
|
|
1592
|
+
try {
|
|
1593
|
+
const result = await implementation(normalizedQuery, normalizedLocations);
|
|
1594
|
+
if (options.debug) {
|
|
1595
|
+
logger10.debug(`[${operationName}] Result: ${result.length} items`);
|
|
1596
|
+
}
|
|
1597
|
+
if (!options.skipValidation) {
|
|
1598
|
+
return validatePK(result, coordinate.kta[0]);
|
|
1599
|
+
}
|
|
1600
|
+
return result;
|
|
1601
|
+
} catch (error) {
|
|
1602
|
+
if (options.onError) {
|
|
1603
|
+
const context = {
|
|
1604
|
+
operationName,
|
|
1605
|
+
params: [query, locations],
|
|
1606
|
+
coordinate
|
|
1607
|
+
};
|
|
1608
|
+
throw options.onError(error, context);
|
|
1609
|
+
}
|
|
1610
|
+
throw new Error(
|
|
1611
|
+
`[${operationName}] Operation failed: ${error.message}`,
|
|
1612
|
+
{ cause: error }
|
|
1613
|
+
);
|
|
1614
|
+
}
|
|
1615
|
+
};
|
|
1616
|
+
}
|
|
1617
|
+
|
|
1618
|
+
// src/operations/wrappers/createGetWrapper.ts
|
|
1619
|
+
var logger11 = logger_default.get("operations", "wrappers", "get");
|
|
1620
|
+
function createGetWrapper(coordinate, implementation, options = {}) {
|
|
1621
|
+
const operationName = options.operationName || "get";
|
|
1622
|
+
return async (key) => {
|
|
1623
|
+
if (options.debug) {
|
|
1624
|
+
logger11.debug(`[${operationName}] Called with key:`, key);
|
|
1625
|
+
}
|
|
1626
|
+
if (!options.skipValidation) {
|
|
1627
|
+
validateKey(key, coordinate, operationName);
|
|
1628
|
+
}
|
|
1629
|
+
try {
|
|
1630
|
+
const result = await implementation(key);
|
|
1631
|
+
if (options.debug) {
|
|
1632
|
+
logger11.debug(`[${operationName}] Result:`, result ? "found" : "not found");
|
|
1633
|
+
}
|
|
1634
|
+
if (result && !options.skipValidation) {
|
|
1635
|
+
return validatePK(result, coordinate.kta[0]);
|
|
1636
|
+
}
|
|
1637
|
+
return result;
|
|
1638
|
+
} catch (error) {
|
|
1639
|
+
if (options.onError) {
|
|
1640
|
+
const context = {
|
|
1641
|
+
operationName,
|
|
1642
|
+
params: [key],
|
|
1643
|
+
coordinate
|
|
1644
|
+
};
|
|
1645
|
+
throw options.onError(error, context);
|
|
1646
|
+
}
|
|
1647
|
+
throw new Error(
|
|
1648
|
+
`[${operationName}] Operation failed: ${error.message}`,
|
|
1649
|
+
{ cause: error }
|
|
1650
|
+
);
|
|
1651
|
+
}
|
|
1652
|
+
};
|
|
1653
|
+
}
|
|
1654
|
+
|
|
1655
|
+
// src/operations/wrappers/createCreateWrapper.ts
|
|
1656
|
+
var logger12 = logger_default.get("operations", "wrappers", "create");
|
|
1657
|
+
function createCreateWrapper(coordinate, implementation, wrapperOptions = {}) {
|
|
1658
|
+
const operationName = wrapperOptions.operationName || "create";
|
|
1659
|
+
return async (item, createOptions) => {
|
|
1660
|
+
if (wrapperOptions.debug) {
|
|
1661
|
+
logger12.debug(`[${operationName}] Called with:`, { item, options: createOptions });
|
|
1662
|
+
}
|
|
1663
|
+
if (!wrapperOptions.skipValidation) {
|
|
1664
|
+
if (!item || typeof item !== "object" || Array.isArray(item)) {
|
|
1665
|
+
throw new Error(
|
|
1666
|
+
`[${operationName}] Invalid item parameter.
|
|
1667
|
+
|
|
1668
|
+
Expected: object
|
|
1669
|
+
Received: ${Array.isArray(item) ? "array" : typeof item}`
|
|
1670
|
+
);
|
|
1671
|
+
}
|
|
1672
|
+
if (createOptions) {
|
|
1673
|
+
if ("key" in createOptions) {
|
|
1674
|
+
validateKey(createOptions.key, coordinate, operationName);
|
|
1675
|
+
}
|
|
1676
|
+
if ("locations" in createOptions) {
|
|
1677
|
+
validateLocations(createOptions.locations, coordinate, operationName);
|
|
1678
|
+
}
|
|
1679
|
+
}
|
|
1680
|
+
}
|
|
1681
|
+
try {
|
|
1682
|
+
const result = await implementation(item, createOptions);
|
|
1683
|
+
if (wrapperOptions.debug) {
|
|
1684
|
+
logger12.debug(`[${operationName}] Created item:`, result.key);
|
|
1685
|
+
}
|
|
1686
|
+
if (!wrapperOptions.skipValidation) {
|
|
1687
|
+
return validatePK(result, coordinate.kta[0]);
|
|
1688
|
+
}
|
|
1689
|
+
return result;
|
|
1690
|
+
} catch (error) {
|
|
1691
|
+
if (wrapperOptions.onError) {
|
|
1692
|
+
const context = {
|
|
1693
|
+
operationName,
|
|
1694
|
+
params: [item, createOptions],
|
|
1695
|
+
coordinate
|
|
1696
|
+
};
|
|
1697
|
+
throw wrapperOptions.onError(error, context);
|
|
1698
|
+
}
|
|
1699
|
+
throw new Error(
|
|
1700
|
+
`[${operationName}] Operation failed: ${error.message}`,
|
|
1701
|
+
{ cause: error }
|
|
1702
|
+
);
|
|
1703
|
+
}
|
|
1704
|
+
};
|
|
1705
|
+
}
|
|
1706
|
+
|
|
1707
|
+
// src/operations/wrappers/createUpdateWrapper.ts
|
|
1708
|
+
var logger13 = logger_default.get("operations", "wrappers", "update");
|
|
1709
|
+
function createUpdateWrapper(coordinate, implementation, options = {}) {
|
|
1710
|
+
const operationName = options.operationName || "update";
|
|
1711
|
+
return async (key, item) => {
|
|
1712
|
+
if (options.debug) {
|
|
1713
|
+
logger13.debug(`[${operationName}] Called with:`, { key, item });
|
|
1714
|
+
}
|
|
1715
|
+
if (!options.skipValidation) {
|
|
1716
|
+
validateKey(key, coordinate, operationName);
|
|
1717
|
+
if (!item || typeof item !== "object" || Array.isArray(item)) {
|
|
1718
|
+
throw new Error(
|
|
1719
|
+
`[${operationName}] Invalid item parameter.
|
|
1720
|
+
|
|
1721
|
+
Expected: object
|
|
1722
|
+
Received: ${Array.isArray(item) ? "array" : typeof item}`
|
|
1723
|
+
);
|
|
1724
|
+
}
|
|
1725
|
+
}
|
|
1726
|
+
try {
|
|
1727
|
+
const result = await implementation(key, item);
|
|
1728
|
+
if (options.debug) {
|
|
1729
|
+
logger13.debug(`[${operationName}] Updated item:`, result.key);
|
|
1730
|
+
}
|
|
1731
|
+
if (!options.skipValidation) {
|
|
1732
|
+
return validatePK(result, coordinate.kta[0]);
|
|
1733
|
+
}
|
|
1734
|
+
return result;
|
|
1735
|
+
} catch (error) {
|
|
1736
|
+
if (options.onError) {
|
|
1737
|
+
const context = {
|
|
1738
|
+
operationName,
|
|
1739
|
+
params: [key, item],
|
|
1740
|
+
coordinate
|
|
1741
|
+
};
|
|
1742
|
+
throw options.onError(error, context);
|
|
1743
|
+
}
|
|
1744
|
+
throw new Error(
|
|
1745
|
+
`[${operationName}] Operation failed: ${error.message}`,
|
|
1746
|
+
{ cause: error }
|
|
1747
|
+
);
|
|
1748
|
+
}
|
|
1749
|
+
};
|
|
1750
|
+
}
|
|
1751
|
+
|
|
1752
|
+
// src/operations/wrappers/createUpsertWrapper.ts
|
|
1753
|
+
var logger14 = logger_default.get("operations", "wrappers", "upsert");
|
|
1754
|
+
function createUpsertWrapper(coordinate, implementation, options = {}) {
|
|
1755
|
+
const operationName = options.operationName || "upsert";
|
|
1756
|
+
return async (key, item, locations) => {
|
|
1757
|
+
if (options.debug) {
|
|
1758
|
+
logger14.debug(`[${operationName}] Called with:`, { key, item, locations });
|
|
1759
|
+
}
|
|
1760
|
+
if (!options.skipValidation) {
|
|
1761
|
+
validateKey(key, coordinate, operationName);
|
|
1762
|
+
validateLocations(locations, coordinate, operationName);
|
|
1763
|
+
if (!item || typeof item !== "object" || Array.isArray(item)) {
|
|
1764
|
+
throw new Error(
|
|
1765
|
+
`[${operationName}] Invalid item parameter.
|
|
1766
|
+
|
|
1767
|
+
Expected: object
|
|
1768
|
+
Received: ${Array.isArray(item) ? "array" : typeof item}`
|
|
1769
|
+
);
|
|
1770
|
+
}
|
|
1771
|
+
}
|
|
1772
|
+
try {
|
|
1773
|
+
const result = await implementation(key, item);
|
|
1774
|
+
if (options.debug) {
|
|
1775
|
+
logger14.debug(`[${operationName}] Upserted item:`, result.key);
|
|
1776
|
+
}
|
|
1777
|
+
if (!options.skipValidation) {
|
|
1778
|
+
return validatePK(result, coordinate.kta[0]);
|
|
1779
|
+
}
|
|
1780
|
+
return result;
|
|
1781
|
+
} catch (error) {
|
|
1782
|
+
if (options.onError) {
|
|
1783
|
+
const context = {
|
|
1784
|
+
operationName,
|
|
1785
|
+
params: [key, item, locations],
|
|
1786
|
+
coordinate
|
|
1787
|
+
};
|
|
1788
|
+
throw options.onError(error, context);
|
|
1789
|
+
}
|
|
1790
|
+
throw new Error(
|
|
1791
|
+
`[${operationName}] Operation failed: ${error.message}`,
|
|
1792
|
+
{ cause: error }
|
|
1793
|
+
);
|
|
1794
|
+
}
|
|
1795
|
+
};
|
|
1796
|
+
}
|
|
1797
|
+
|
|
1798
|
+
// src/operations/wrappers/createRemoveWrapper.ts
|
|
1799
|
+
var logger15 = logger_default.get("operations", "wrappers", "remove");
|
|
1800
|
+
function createRemoveWrapper(coordinate, implementation, options = {}) {
|
|
1801
|
+
const operationName = options.operationName || "remove";
|
|
1802
|
+
return async (key) => {
|
|
1803
|
+
if (options.debug) {
|
|
1804
|
+
logger15.debug(`[${operationName}] Called with key:`, key);
|
|
1805
|
+
}
|
|
1806
|
+
if (!options.skipValidation) {
|
|
1807
|
+
validateKey(key, coordinate, operationName);
|
|
1808
|
+
}
|
|
1809
|
+
try {
|
|
1810
|
+
const result = await implementation(key);
|
|
1811
|
+
if (options.debug) {
|
|
1812
|
+
logger15.debug(`[${operationName}] Removed item:`, key);
|
|
1813
|
+
}
|
|
1814
|
+
return result;
|
|
1815
|
+
} catch (error) {
|
|
1816
|
+
if (options.onError) {
|
|
1817
|
+
const context = {
|
|
1818
|
+
operationName,
|
|
1819
|
+
params: [key],
|
|
1820
|
+
coordinate
|
|
1821
|
+
};
|
|
1822
|
+
throw options.onError(error, context);
|
|
1823
|
+
}
|
|
1824
|
+
throw new Error(
|
|
1825
|
+
`[${operationName}] Operation failed: ${error.message}`,
|
|
1826
|
+
{ cause: error }
|
|
1827
|
+
);
|
|
1828
|
+
}
|
|
1829
|
+
};
|
|
1830
|
+
}
|
|
1831
|
+
|
|
1832
|
+
// src/operations/wrappers/createFindWrapper.ts
|
|
1833
|
+
var logger16 = logger_default.get("operations", "wrappers", "find");
|
|
1834
|
+
function createFindWrapper(coordinate, implementation, options = {}) {
|
|
1835
|
+
const operationName = options.operationName || "find";
|
|
1836
|
+
return async (finder, params, locations) => {
|
|
1837
|
+
if (options.debug) {
|
|
1838
|
+
logger16.debug(`[${operationName}] Called:`, { finder, params, locations });
|
|
1839
|
+
}
|
|
1840
|
+
if (!options.skipValidation) {
|
|
1841
|
+
validateFinderName(finder, operationName);
|
|
1842
|
+
validateOperationParams(params, operationName);
|
|
1843
|
+
validateLocations(locations, coordinate, operationName);
|
|
1844
|
+
}
|
|
1845
|
+
const normalizedParams = params ?? {};
|
|
1846
|
+
const normalizedLocations = locations ?? [];
|
|
1847
|
+
try {
|
|
1848
|
+
const result = await implementation(finder, normalizedParams, normalizedLocations);
|
|
1849
|
+
if (options.debug) {
|
|
1850
|
+
logger16.debug(`[${operationName}] Found ${result.length} items for finder "${finder}"`);
|
|
1851
|
+
}
|
|
1852
|
+
if (!options.skipValidation) {
|
|
1853
|
+
return validatePK(result, coordinate.kta[0]);
|
|
1854
|
+
}
|
|
1855
|
+
return result;
|
|
1856
|
+
} catch (error) {
|
|
1857
|
+
if (options.onError) {
|
|
1858
|
+
const context = {
|
|
1859
|
+
operationName,
|
|
1860
|
+
params: [finder, params, locations],
|
|
1861
|
+
coordinate
|
|
1862
|
+
};
|
|
1863
|
+
throw options.onError(error, context);
|
|
1864
|
+
}
|
|
1865
|
+
throw new Error(
|
|
1866
|
+
`[${operationName}] Operation failed for finder "${finder}": ${error.message}`,
|
|
1867
|
+
{ cause: error }
|
|
1868
|
+
);
|
|
1869
|
+
}
|
|
1870
|
+
};
|
|
1871
|
+
}
|
|
1872
|
+
|
|
1873
|
+
// src/operations/wrappers/createFindOneWrapper.ts
|
|
1874
|
+
var logger17 = logger_default.get("operations", "wrappers", "findOne");
|
|
1875
|
+
function createFindOneWrapper(coordinate, implementation, options = {}) {
|
|
1876
|
+
const operationName = options.operationName || "findOne";
|
|
1877
|
+
return async (finder, params, locations) => {
|
|
1878
|
+
if (options.debug) {
|
|
1879
|
+
logger17.debug(`[${operationName}] Called:`, { finder, params, locations });
|
|
1880
|
+
}
|
|
1881
|
+
if (!options.skipValidation) {
|
|
1882
|
+
validateFinderName(finder, operationName);
|
|
1883
|
+
validateOperationParams(params, operationName);
|
|
1884
|
+
validateLocations(locations, coordinate, operationName);
|
|
1885
|
+
}
|
|
1886
|
+
const normalizedParams = params ?? {};
|
|
1887
|
+
const normalizedLocations = locations ?? [];
|
|
1888
|
+
try {
|
|
1889
|
+
const result = await implementation(finder, normalizedParams, normalizedLocations);
|
|
1890
|
+
if (options.debug) {
|
|
1891
|
+
logger17.debug(`[${operationName}] Result for finder "${finder}":`, result ? "found" : "not found");
|
|
1892
|
+
}
|
|
1893
|
+
if (result && !options.skipValidation) {
|
|
1894
|
+
return validatePK(result, coordinate.kta[0]);
|
|
1895
|
+
}
|
|
1896
|
+
return result;
|
|
1897
|
+
} catch (error) {
|
|
1898
|
+
if (options.onError) {
|
|
1899
|
+
const context = {
|
|
1900
|
+
operationName,
|
|
1901
|
+
params: [finder, params, locations],
|
|
1902
|
+
coordinate
|
|
1903
|
+
};
|
|
1904
|
+
throw options.onError(error, context);
|
|
1905
|
+
}
|
|
1906
|
+
throw new Error(
|
|
1907
|
+
`[${operationName}] Operation failed for finder "${finder}": ${error.message}`,
|
|
1908
|
+
{ cause: error }
|
|
1909
|
+
);
|
|
1910
|
+
}
|
|
1911
|
+
};
|
|
1912
|
+
}
|
|
1913
|
+
|
|
1914
|
+
// src/operations/wrappers/createActionWrapper.ts
|
|
1915
|
+
var logger18 = logger_default.get("operations", "wrappers", "action");
|
|
1916
|
+
function createActionWrapper(coordinate, implementation, options = {}) {
|
|
1917
|
+
const operationName = options.operationName || "action";
|
|
1918
|
+
return async (key, action, params) => {
|
|
1919
|
+
if (options.debug) {
|
|
1920
|
+
logger18.debug(`[${operationName}] Called:`, { key, action, params });
|
|
1921
|
+
}
|
|
1922
|
+
if (!options.skipValidation) {
|
|
1923
|
+
validateKey(key, coordinate, operationName);
|
|
1924
|
+
validateActionName(action, operationName);
|
|
1925
|
+
validateOperationParams(params, operationName);
|
|
1926
|
+
}
|
|
1927
|
+
const normalizedParams = params ?? {};
|
|
1928
|
+
try {
|
|
1929
|
+
const result = await implementation(key, action, normalizedParams);
|
|
1930
|
+
if (options.debug) {
|
|
1931
|
+
logger18.debug(`[${operationName}] Action "${action}" completed:`, {
|
|
1932
|
+
itemKey: result[0].key,
|
|
1933
|
+
affectedKeys: result[1].length
|
|
1934
|
+
});
|
|
1935
|
+
}
|
|
1936
|
+
if (!options.skipValidation) {
|
|
1937
|
+
const validatedItem = validatePK(result[0], coordinate.kta[0]);
|
|
1938
|
+
return [validatedItem, result[1]];
|
|
1939
|
+
}
|
|
1940
|
+
return result;
|
|
1941
|
+
} catch (error) {
|
|
1942
|
+
if (options.onError) {
|
|
1943
|
+
const context = {
|
|
1944
|
+
operationName,
|
|
1945
|
+
params: [key, action, params],
|
|
1946
|
+
coordinate
|
|
1947
|
+
};
|
|
1948
|
+
throw options.onError(error, context);
|
|
1949
|
+
}
|
|
1950
|
+
throw new Error(
|
|
1951
|
+
`[${operationName}] Action "${action}" failed: ${error.message}`,
|
|
1952
|
+
{ cause: error }
|
|
1953
|
+
);
|
|
1954
|
+
}
|
|
1955
|
+
};
|
|
1956
|
+
}
|
|
1957
|
+
|
|
1958
|
+
// src/operations/wrappers/createAllActionWrapper.ts
|
|
1959
|
+
var logger19 = logger_default.get("operations", "wrappers", "allAction");
|
|
1960
|
+
function createAllActionWrapper(coordinate, implementation, options = {}) {
|
|
1961
|
+
const operationName = options.operationName || "allAction";
|
|
1962
|
+
return async (action, params, locations) => {
|
|
1963
|
+
if (options.debug) {
|
|
1964
|
+
logger19.debug(`[${operationName}] Called:`, { action, params, locations });
|
|
1965
|
+
}
|
|
1966
|
+
if (!options.skipValidation) {
|
|
1967
|
+
validateActionName(action, operationName);
|
|
1968
|
+
validateOperationParams(params, operationName);
|
|
1969
|
+
validateLocations(locations, coordinate, operationName);
|
|
1970
|
+
}
|
|
1971
|
+
const normalizedParams = params ?? {};
|
|
1972
|
+
const normalizedLocations = locations ?? [];
|
|
1973
|
+
try {
|
|
1974
|
+
const result = await implementation(action, normalizedParams, normalizedLocations);
|
|
1975
|
+
if (options.debug) {
|
|
1976
|
+
logger19.debug(`[${operationName}] Action "${action}" completed:`, {
|
|
1977
|
+
itemsAffected: result[0].length,
|
|
1978
|
+
affectedKeys: result[1].length
|
|
1979
|
+
});
|
|
1980
|
+
}
|
|
1981
|
+
if (!options.skipValidation) {
|
|
1982
|
+
const validatedItems = validatePK(result[0], coordinate.kta[0]);
|
|
1983
|
+
return [validatedItems, result[1]];
|
|
1984
|
+
}
|
|
1985
|
+
return result;
|
|
1986
|
+
} catch (error) {
|
|
1987
|
+
if (options.onError) {
|
|
1988
|
+
const context = {
|
|
1989
|
+
operationName,
|
|
1990
|
+
params: [action, params, locations],
|
|
1991
|
+
coordinate
|
|
1992
|
+
};
|
|
1993
|
+
throw options.onError(error, context);
|
|
1994
|
+
}
|
|
1995
|
+
throw new Error(
|
|
1996
|
+
`[${operationName}] Action "${action}" failed: ${error.message}`,
|
|
1997
|
+
{ cause: error }
|
|
1998
|
+
);
|
|
1999
|
+
}
|
|
2000
|
+
};
|
|
2001
|
+
}
|
|
2002
|
+
|
|
2003
|
+
// src/operations/wrappers/createFacetWrapper.ts
|
|
2004
|
+
var logger20 = logger_default.get("operations", "wrappers", "facet");
|
|
2005
|
+
function createFacetWrapper(coordinate, implementation, options = {}) {
|
|
2006
|
+
const operationName = options.operationName || "facet";
|
|
2007
|
+
return async (key, facet, params) => {
|
|
2008
|
+
if (options.debug) {
|
|
2009
|
+
logger20.debug(`[${operationName}] Called:`, { key, facet, params });
|
|
2010
|
+
}
|
|
2011
|
+
if (!options.skipValidation) {
|
|
2012
|
+
validateKey(key, coordinate, operationName);
|
|
2013
|
+
validateFacetName(facet, operationName);
|
|
2014
|
+
validateOperationParams(params, operationName);
|
|
2015
|
+
}
|
|
2016
|
+
const normalizedParams = params ?? {};
|
|
2017
|
+
try {
|
|
2018
|
+
const result = await implementation(key, facet, normalizedParams);
|
|
2019
|
+
if (options.debug) {
|
|
2020
|
+
logger20.debug(`[${operationName}] Facet "${facet}" completed`);
|
|
2021
|
+
}
|
|
2022
|
+
return result;
|
|
2023
|
+
} catch (error) {
|
|
2024
|
+
if (options.onError) {
|
|
2025
|
+
const context = {
|
|
2026
|
+
operationName,
|
|
2027
|
+
params: [key, facet, params],
|
|
2028
|
+
coordinate
|
|
2029
|
+
};
|
|
2030
|
+
throw options.onError(error, context);
|
|
2031
|
+
}
|
|
2032
|
+
throw new Error(
|
|
2033
|
+
`[${operationName}] Facet "${facet}" failed: ${error.message}`,
|
|
2034
|
+
{ cause: error }
|
|
2035
|
+
);
|
|
2036
|
+
}
|
|
2037
|
+
};
|
|
2038
|
+
}
|
|
2039
|
+
|
|
2040
|
+
// src/operations/wrappers/createAllFacetWrapper.ts
|
|
2041
|
+
var logger21 = logger_default.get("operations", "wrappers", "allFacet");
|
|
2042
|
+
function createAllFacetWrapper(coordinate, implementation, options = {}) {
|
|
2043
|
+
const operationName = options.operationName || "allFacet";
|
|
2044
|
+
return async (facet, params, locations) => {
|
|
2045
|
+
if (options.debug) {
|
|
2046
|
+
logger21.debug(`[${operationName}] Called:`, { facet, params, locations });
|
|
2047
|
+
}
|
|
2048
|
+
if (!options.skipValidation) {
|
|
2049
|
+
validateFacetName(facet, operationName);
|
|
2050
|
+
validateOperationParams(params, operationName);
|
|
2051
|
+
validateLocations(locations, coordinate, operationName);
|
|
2052
|
+
}
|
|
2053
|
+
const normalizedParams = params ?? {};
|
|
2054
|
+
const normalizedLocations = locations ?? [];
|
|
2055
|
+
try {
|
|
2056
|
+
const result = await implementation(facet, normalizedParams, normalizedLocations);
|
|
2057
|
+
if (options.debug) {
|
|
2058
|
+
logger21.debug(`[${operationName}] Facet "${facet}" completed`);
|
|
2059
|
+
}
|
|
2060
|
+
return result;
|
|
2061
|
+
} catch (error) {
|
|
2062
|
+
if (options.onError) {
|
|
2063
|
+
const context = {
|
|
2064
|
+
operationName,
|
|
2065
|
+
params: [facet, params, locations],
|
|
2066
|
+
coordinate
|
|
2067
|
+
};
|
|
2068
|
+
throw options.onError(error, context);
|
|
2069
|
+
}
|
|
2070
|
+
throw new Error(
|
|
2071
|
+
`[${operationName}] Facet "${facet}" failed: ${error.message}`,
|
|
2072
|
+
{ cause: error }
|
|
2073
|
+
);
|
|
2074
|
+
}
|
|
2075
|
+
};
|
|
2076
|
+
}
|
|
849
2077
|
export {
|
|
850
2078
|
AItemService,
|
|
2079
|
+
ActionError,
|
|
2080
|
+
BusinessLogicError,
|
|
851
2081
|
Dictionary,
|
|
2082
|
+
DuplicateError,
|
|
852
2083
|
IFactory,
|
|
853
2084
|
IQFactory,
|
|
2085
|
+
NotFoundError,
|
|
2086
|
+
PermissionError,
|
|
2087
|
+
ValidationError,
|
|
854
2088
|
abbrevAgg,
|
|
855
2089
|
abbrevCompoundCondition,
|
|
856
2090
|
abbrevCondition,
|
|
@@ -860,10 +2094,29 @@ export {
|
|
|
860
2094
|
abbrevRef,
|
|
861
2095
|
cPK,
|
|
862
2096
|
constructPriKey,
|
|
2097
|
+
createActionWrapper,
|
|
2098
|
+
createAllActionWrapper,
|
|
2099
|
+
createAllFacetWrapper,
|
|
2100
|
+
createAllWrapper,
|
|
2101
|
+
createCoordinate,
|
|
2102
|
+
createCreateWrapper,
|
|
2103
|
+
createFacetWrapper,
|
|
2104
|
+
createFindOneWrapper,
|
|
2105
|
+
createFindWrapper,
|
|
2106
|
+
createGetWrapper,
|
|
863
2107
|
createNormalizedHashFunction,
|
|
2108
|
+
createOneWrapper,
|
|
2109
|
+
createRemoveWrapper,
|
|
2110
|
+
createUpdateWrapper,
|
|
2111
|
+
createUpsertWrapper,
|
|
2112
|
+
enhanceError,
|
|
2113
|
+
executeWithContext,
|
|
2114
|
+
executeWithContextSync,
|
|
864
2115
|
extractKeyTypeArray,
|
|
865
2116
|
generateKeyArray,
|
|
2117
|
+
getErrorInfo,
|
|
866
2118
|
ikToLKA,
|
|
2119
|
+
isActionError,
|
|
867
2120
|
isComItem,
|
|
868
2121
|
isComKey,
|
|
869
2122
|
isComKeyEqual,
|
|
@@ -875,6 +2128,8 @@ export {
|
|
|
875
2128
|
isLocKey,
|
|
876
2129
|
isLocKeyEqual,
|
|
877
2130
|
isLocKeyEqualNormalized,
|
|
2131
|
+
isComKey2 as isOperationComKey,
|
|
2132
|
+
isPriKey2 as isOperationPriKey,
|
|
878
2133
|
isPriItem,
|
|
879
2134
|
isPriKey,
|
|
880
2135
|
isPriKeyEqual,
|
|
@@ -884,6 +2139,7 @@ export {
|
|
|
884
2139
|
isValidItemKey,
|
|
885
2140
|
isValidLocKey,
|
|
886
2141
|
isValidLocKeyArray,
|
|
2142
|
+
isValidLocations,
|
|
887
2143
|
isValidPriKey,
|
|
888
2144
|
itemKeyToLocKeyArray,
|
|
889
2145
|
lkaToIK,
|
|
@@ -892,6 +2148,15 @@ export {
|
|
|
892
2148
|
primaryType,
|
|
893
2149
|
queryToParams,
|
|
894
2150
|
toKeyTypeArray,
|
|
2151
|
+
validateActionName,
|
|
2152
|
+
validateComKey,
|
|
2153
|
+
validateFacetName,
|
|
2154
|
+
validateFinderName,
|
|
2155
|
+
validateKey,
|
|
895
2156
|
validateKeys,
|
|
896
|
-
|
|
2157
|
+
validateLocations,
|
|
2158
|
+
validateOperationParams,
|
|
2159
|
+
validatePK,
|
|
2160
|
+
validatePriKey,
|
|
2161
|
+
validateQuery
|
|
897
2162
|
};
|