@routier/core 0.1.0-rc.2 → 0.2.1

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.
Files changed (91) hide show
  1. package/dist/assertions/index.d.ts +30 -0
  2. package/dist/assertions/index.js +92 -19
  3. package/dist/assertions/index.js.map +1 -1
  4. package/dist/capabilities/index.js +75 -105
  5. package/dist/capabilities/index.js.map +1 -1
  6. package/dist/codegen/blocks.test.d.ts +1 -0
  7. package/dist/codegen/handlers/SetHandlerBuilder.d.ts +4 -0
  8. package/dist/codegen/handlers/index.d.ts +1 -0
  9. package/dist/codegen/handlers/serialize/SerializeComputedHandler.d.ts +6 -0
  10. package/dist/codegen/handlers/set/SetComplexHandler.d.ts +6 -0
  11. package/dist/codegen/index.js +22 -36
  12. package/dist/codegen/index.js.map +1 -1
  13. package/dist/codegen/utils.test.d.ts +1 -0
  14. package/dist/collections/Changes.d.ts +2 -2
  15. package/dist/collections/IdSet.test.d.ts +1 -0
  16. package/dist/collections/TagCollection.contract.test.d.ts +1 -0
  17. package/dist/collections/TagCollection.d.ts +7 -7
  18. package/dist/collections/index.js +50 -93
  19. package/dist/collections/index.js.map +1 -1
  20. package/dist/errors/index.js +4 -15
  21. package/dist/errors/index.js.map +1 -1
  22. package/dist/expressions/constants.d.ts +2 -0
  23. package/dist/expressions/index.d.ts +2 -0
  24. package/dist/expressions/index.js +450 -114
  25. package/dist/expressions/index.js.map +1 -1
  26. package/dist/expressions/sql.d.ts +28 -0
  27. package/dist/expressions/sql.test.d.ts +1 -0
  28. package/dist/expressions/utils.d.ts +1 -2
  29. package/dist/index.js +3058 -2618
  30. package/dist/index.js.map +1 -1
  31. package/dist/performance/index.js +22 -22
  32. package/dist/performance/index.js.map +1 -1
  33. package/dist/pipeline/index.js +48 -60
  34. package/dist/pipeline/index.js.map +1 -1
  35. package/dist/plugins/index.d.ts +0 -1
  36. package/dist/plugins/index.js +268 -937
  37. package/dist/plugins/index.js.map +1 -1
  38. package/dist/plugins/query/Query.test.d.ts +1 -0
  39. package/dist/plugins/query/QueryOptionsCollection.d.ts +1 -0
  40. package/dist/plugins/translators/SqlTranslator.test.d.ts +1 -0
  41. package/dist/plugins/translators/TranslatedArrayValue.d.ts +3 -1
  42. package/dist/plugins/translators/TranslatedGroupValue.d.ts +3 -1
  43. package/dist/plugins/translators/TranslatedSingleValue.d.ts +3 -1
  44. package/dist/plugins/translators/TranslatedValues.test.d.ts +1 -0
  45. package/dist/plugins/translators/types.d.ts +8 -1
  46. package/dist/plugins/types.d.ts +6 -10
  47. package/dist/results/Result.d.ts +2 -2
  48. package/dist/results/Result.test.d.ts +1 -0
  49. package/dist/results/index.js +11 -26
  50. package/dist/results/index.js.map +1 -1
  51. package/dist/results/utils.test.d.ts +1 -0
  52. package/dist/schema/PropertyInfo.d.ts +5 -1
  53. package/dist/schema/SchemaDefinition.d.ts +35 -6
  54. package/dist/schema/communication/broadcast.test.d.ts +1 -0
  55. package/dist/schema/index.d.ts +2 -0
  56. package/dist/schema/index.js +2115 -1513
  57. package/dist/schema/index.js.map +1 -1
  58. package/dist/schema/property/base/SchemaBase.d.ts +3 -1
  59. package/dist/schema/property/modifiers/SchemaDeserialize.d.ts +5 -1
  60. package/dist/schema/property/modifiers/SchemaForeignKey.d.ts +15 -0
  61. package/dist/schema/property/modifiers/SchemaKey.d.ts +2 -0
  62. package/dist/schema/property/modifiers/SchemaNullable.d.ts +5 -1
  63. package/dist/schema/property/modifiers/SchemaOptional.d.ts +3 -1
  64. package/dist/schema/property/modifiers/SchemaTag.d.ts +27 -0
  65. package/dist/schema/property/modifiers/SchemaTracked.d.ts +5 -1
  66. package/dist/schema/property/modifiers/index.d.ts +2 -0
  67. package/dist/schema/property/types/SchemaArray.d.ts +2 -0
  68. package/dist/schema/property/types/SchemaBoolean.d.ts +2 -0
  69. package/dist/schema/property/types/SchemaDate.d.ts +2 -0
  70. package/dist/schema/property/types/SchemaNumber.d.ts +5 -1
  71. package/dist/schema/property/types/SchemaObject.d.ts +2 -0
  72. package/dist/schema/property/types/SchemaString.d.ts +5 -1
  73. package/dist/schema/types.d.ts +41 -29
  74. package/dist/schema/utils/standardJsonSchema.d.ts +90 -0
  75. package/dist/schema/utils/standardJsonSchema.test.d.ts +1 -0
  76. package/dist/types/index.js +0 -6
  77. package/dist/types/index.js.map +1 -1
  78. package/dist/utilities/functions.d.ts +1 -1
  79. package/dist/utilities/index.js +213 -138
  80. package/dist/utilities/index.js.map +1 -1
  81. package/dist/utilities/runtime.test.d.ts +1 -0
  82. package/dist/utilities/types.d.ts +17 -2
  83. package/dist/utilities/uuid.test.d.ts +1 -0
  84. package/package.json +2 -2
  85. package/readme.md +1 -1
  86. package/dist/plugins/replication/OptimisticReplicationDbPlugin.d.ts +0 -22
  87. package/dist/plugins/replication/ReplicationDbPlugin.d.ts +0 -22
  88. package/dist/plugins/replication/index.d.ts +0 -3
  89. package/dist/plugins/replication/types.d.ts +0 -4
  90. package/dist/schema/testSchemas.test.d.ts +0 -314
  91. /package/dist/{pipeline/WorkPipeline.test.d.ts → codegen/SlotPath.test.d.ts} +0 -0
@@ -1,21 +1,27 @@
1
1
  var __webpack_modules__ = ({
2
- "./src/assertions/index.ts":
3
- /*!*********************************!*\
4
- !*** ./src/assertions/index.ts ***!
5
- \*********************************/
6
- (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
2
+ "./src/assertions/index.ts"(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
7
3
  __webpack_require__.r(__webpack_exports__);
8
4
  __webpack_require__.d(__webpack_exports__, {
9
5
  assertDate: () => (assertDate),
10
6
  assertInstanceOf: () => (assertInstanceOf),
11
7
  assertIsArray: () => (assertIsArray),
12
8
  assertIsNotNull: () => (assertIsNotNull),
13
- assertString: () => (assertString)
9
+ assertIsNumber: () => (assertIsNumber),
10
+ assertString: () => (assertString),
11
+ isComparatorExpression: () => (isComparatorExpression),
12
+ isEmptyExpression: () => (isEmptyExpression),
13
+ isExpression: () => (isExpression),
14
+ isNotParsableExpression: () => (isNotParsableExpression),
15
+ isOperatorExpression: () => (isOperatorExpression),
16
+ isPropertyExpression: () => (isPropertyExpression),
17
+ isValueExpression: () => (isValueExpression)
14
18
  });
15
- /* ESM import */var _utilities__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../utilities */ "./src/utilities/dates.ts");
19
+ /* import */ var _expressions_constants__rspack_import_1 = __webpack_require__("./src/expressions/constants.ts");
20
+ /* import */ var _utilities__rspack_import_0 = __webpack_require__("./src/utilities/dates.ts");
21
+
16
22
 
17
23
  function assertDate(data) {
18
- if ((0,_utilities__WEBPACK_IMPORTED_MODULE_0__.isDate)(data) === false) {
24
+ if ((0,_utilities__rspack_import_0.isDate)(data) === false) {
19
25
  throw new TypeError('Value is not a Date');
20
26
  }
21
27
  }
@@ -45,230 +51,84 @@ function assertInstanceOf(value, Instance) {
45
51
  return;
46
52
  }
47
53
  if (value != null && typeof value === "object" && "constructor" in value) {
48
- throw new TypeError(`Value is not instance of type. Type: ${value.constructor.name}`);
54
+ throw new TypeError(`value is not instance of type. Type: ${value.constructor.name}`);
49
55
  }
50
- throw new TypeError(`Value is not instance of type`);
56
+ throw new TypeError(`value is not instance of type`);
51
57
  }
52
-
53
-
54
- }),
55
- "./src/collections/Changes.ts":
56
- /*!************************************!*\
57
- !*** ./src/collections/Changes.ts ***!
58
- \************************************/
59
- (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
60
- __webpack_require__.r(__webpack_exports__);
61
- __webpack_require__.d(__webpack_exports__, {
62
- BulkPersistChanges: () => (BulkPersistChanges),
63
- BulkPersistResult: () => (BulkPersistResult),
64
- SchemaPersistChanges: () => (SchemaPersistChanges),
65
- SchemaPersistResult: () => (SchemaPersistResult)
66
- });
67
- /* ESM import */var _TagCollection__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./TagCollection */ "./src/collections/TagCollection.ts");
68
-
69
- class BulkPersistResult extends Map {
70
- resolve(schemaId) {
71
- if (this.has(schemaId)) {
72
- return this.get(schemaId);
73
- }
74
- this.set(schemaId, new SchemaPersistResult());
75
- return this.get(schemaId);
76
- }
77
- get(schemaId) {
78
- return super.get(schemaId);
79
- }
80
- get aggregate() {
81
- return {
82
- size: this.aggregateSize,
83
- adds: this.aggregateAddsSize,
84
- updates: this.aggregateUpdatesSize,
85
- removes: this.aggregateRemovesSize
86
- };
87
- }
88
- get aggregateSize() {
89
- let count = 0;
90
- for (const [, result] of this) {
91
- count += result.total;
92
- }
93
- return count;
94
- }
95
- get aggregateAddsSize() {
96
- let count = 0;
97
- for (const [, result] of this) {
98
- count += result.adds.length;
99
- }
100
- return count;
101
- }
102
- get aggregateUpdatesSize() {
103
- let count = 0;
104
- for (const [, result] of this) {
105
- count += result.updates.length;
106
- }
107
- return count;
108
- }
109
- get aggregateRemovesSize() {
110
- let count = 0;
111
- for (const [, result] of this) {
112
- count += result.removes.length;
113
- }
114
- return count;
58
+ function assertIsNumber(value) {
59
+ if (typeof value !== "number") {
60
+ throw new TypeError("value is not of type `number`");
115
61
  }
116
62
  }
117
- class BulkPersistChanges extends Map {
118
- resolve(schemaId) {
119
- if (this.has(schemaId)) {
120
- return this.get(schemaId);
121
- }
122
- this.set(schemaId, new SchemaPersistChanges());
123
- return this.get(schemaId);
124
- }
125
- get(schemaId) {
126
- return super.get(schemaId);
127
- }
128
- get aggregate() {
129
- return {
130
- size: this.aggregateSize,
131
- adds: this.aggregateAddsSize,
132
- updates: this.aggregateUpdatesSize,
133
- removes: this.aggregateRemovesSize
134
- };
135
- }
136
- get aggregateSize() {
137
- let count = 0;
138
- for (const [, result] of this) {
139
- count += result.total;
140
- }
141
- return count;
142
- }
143
- get aggregateAddsSize() {
144
- let count = 0;
145
- for (const [, result] of this) {
146
- count += result.adds.length;
147
- }
148
- return count;
149
- }
150
- get aggregateUpdatesSize() {
151
- let count = 0;
152
- for (const [, result] of this) {
153
- count += result.updates.length;
154
- }
155
- return count;
156
- }
157
- get aggregateRemovesSize() {
158
- let count = 0;
159
- for (const [, result] of this) {
160
- count += result.removes.length;
161
- }
162
- return count;
163
- }
164
- /**
165
- * Ensures the result has the same result sets as the change sets
166
- * @returns
167
- */
168
- toResult() {
169
- const result = new BulkPersistResult();
170
- for (const [schemaId] of this) {
171
- result.set(schemaId, new SchemaPersistResult());
172
- }
173
- return result;
174
- }
63
+ function isObjectWithType(value) {
64
+ return typeof value === "object" && value !== null && "type" in value;
175
65
  }
176
- class SchemaPersistChanges {
177
- adds = [];
178
- updates = [];
179
- removes = [];
180
- tags = new _TagCollection__WEBPACK_IMPORTED_MODULE_0__.TagCollection();
181
- get hasItems() {
182
- return this.total > 0;
183
- }
184
- get total() {
185
- return this.adds.length + this.updates.length + this.removes.length;
186
- }
66
+ /**
67
+ * Type guard: narrows `value` to `Expression` when it is an object with a valid `type` property.
68
+ */
69
+ function isExpression(value) {
70
+ return isObjectWithType(value) && _expressions_constants__rspack_import_1.EXPRESSION_TYPES.includes(value.type);
187
71
  }
188
- class SchemaPersistResult {
189
- adds = [];
190
- updates = [];
191
- removes = [];
192
- get hasItems() {
193
- return this.total > 0;
194
- }
195
- get total() {
196
- return this.adds.length + this.updates.length + this.removes.length;
197
- }
72
+ /**
73
+ * Type guard: narrows `value` to `OperatorExpression` when it is an object with `type === "operator"`.
74
+ */
75
+ function isOperatorExpression(value) {
76
+ return isObjectWithType(value) && value.type === "operator";
77
+ }
78
+ /**
79
+ * Type guard: narrows `value` to `ComparatorExpression` when it is an object with `type === "comparator"`.
80
+ */
81
+ function isComparatorExpression(value) {
82
+ return isObjectWithType(value) && value.type === "comparator";
83
+ }
84
+ /**
85
+ * Type guard: narrows `value` to `PropertyExpression` when it is an object with `type === "property"`.
86
+ */
87
+ function isPropertyExpression(value) {
88
+ return isObjectWithType(value) && value.type === "property";
89
+ }
90
+ /**
91
+ * Type guard: narrows `value` to `ValueExpression` when it is an object with `type === "value"`.
92
+ */
93
+ function isValueExpression(value) {
94
+ return isObjectWithType(value) && value.type === "value";
95
+ }
96
+ /**
97
+ * Type guard: narrows `value` to `EmptyExpression` when it is an object with `type === "empty"`.
98
+ */
99
+ function isEmptyExpression(value) {
100
+ return isObjectWithType(value) && value.type === "empty";
101
+ }
102
+ /**
103
+ * Type guard: narrows `value` to `NotParsableExpression` when it is an object with `type === "not-parsable"`.
104
+ */
105
+ function isNotParsableExpression(value) {
106
+ return isObjectWithType(value) && value.type === "not-parsable";
198
107
  }
199
108
 
200
109
 
201
- }),
202
- "./src/collections/TagCollection.ts":
203
- /*!******************************************!*\
204
- !*** ./src/collections/TagCollection.ts ***!
205
- \******************************************/
206
- (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
110
+ },
111
+ "./src/expressions/constants.ts"(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
207
112
  __webpack_require__.r(__webpack_exports__);
208
113
  __webpack_require__.d(__webpack_exports__, {
209
- TagCollection: () => (TagCollection)
114
+ EXPRESSION_TYPES: () => (EXPRESSION_TYPES)
210
115
  });
211
- class TagCollection {
212
- data = new Map();
213
- _size = 0;
214
- get size() {
215
- return this._size;
216
- }
217
- get(key) {
218
- return this.data.get(key);
219
- }
220
- has(key) {
221
- return this.data.has(key);
222
- }
223
- set(key, tag) {
224
- this._size++;
225
- return this.data.set(key, tag);
226
- }
227
- delete(key) {
228
- const result = this.data.delete(key);
229
- if (result) {
230
- this._size--;
231
- }
232
- return result;
233
- }
234
- setMany(keys, tag) {
235
- this._size += keys.length;
236
- for (let i = 0, length = keys.length; i < length; i++) {
237
- const key = keys[i];
238
- this.set(key, tag);
239
- }
240
- }
241
- combine(tags) {
242
- for (const [key, value] of tags) {
243
- this.data.set(key, value);
244
- }
245
- }
246
- values() {
247
- return this.data.values();
248
- }
249
- keys() {
250
- return this.data.keys();
251
- }
252
- [Symbol.dispose]() {
253
- this.data.clear();
254
- }
255
- [Symbol.iterator]() {
256
- return this.data[Symbol.iterator]();
257
- }
258
- }
259
-
260
-
261
- }),
262
- "./src/expressions/utils.ts":
263
- /*!**********************************!*\
264
- !*** ./src/expressions/utils.ts ***!
265
- \**********************************/
266
- (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
116
+ const EXPRESSION_TYPES = [
117
+ "operator",
118
+ "comparator",
119
+ "property",
120
+ "value",
121
+ "empty",
122
+ "not-parsable",
123
+ ];
124
+
125
+
126
+ },
127
+ "./src/expressions/utils.ts"(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
267
128
  __webpack_require__.r(__webpack_exports__);
268
129
  __webpack_require__.d(__webpack_exports__, {
269
130
  forEach: () => (forEach),
270
- getProperties: () => (getProperties),
271
- isPropertyExpression: () => (isPropertyExpression)
131
+ getProperties: () => (getProperties)
272
132
  });
273
133
  /**
274
134
  * Extracts all properties referenced in an expression
@@ -293,9 +153,6 @@ function getProperties(expression) {
293
153
  traverse(expression);
294
154
  return properties;
295
155
  }
296
- function isPropertyExpression(expression) {
297
- return expression.type === "property";
298
- }
299
156
  function forEach(expression, callback) {
300
157
  function traverse(expr) {
301
158
  // Call the callback for this expression
@@ -320,54 +177,15 @@ function forEach(expression, callback) {
320
177
  }
321
178
 
322
179
 
323
- }),
324
- "./src/performance/index.ts":
325
- /*!**********************************!*\
326
- !*** ./src/performance/index.ts ***!
327
- \**********************************/
328
- (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
329
- __webpack_require__.r(__webpack_exports__);
330
- __webpack_require__.d(__webpack_exports__, {
331
- measure: () => (measure),
332
- now: () => (now)
333
- });
334
- /* ESM import */var _utilities__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../utilities */ "./src/utilities/logger.ts");
335
-
336
- const measurements = {};
337
- const now = () => {
338
- if (typeof performance !== 'undefined' && performance.now) {
339
- // Browser or modern Node.js
340
- return performance.now();
341
- }
342
- // Fallback for older environments
343
- return Date.now();
344
- };
345
- const measure = {
346
- start: (name) => {
347
- measurements[name] = now();
348
- },
349
- end: (name) => {
350
- const start = measurements[name];
351
- delete measurements[name];
352
- const delta = now() - start;
353
- _utilities__WEBPACK_IMPORTED_MODULE_0__.logger.log(`[ROUTIER] - Performance: ${name} took ${delta}`);
354
- }
355
- };
356
-
357
-
358
- }),
359
- "./src/pipeline/TrampolinePipeline.ts":
360
- /*!********************************************!*\
361
- !*** ./src/pipeline/TrampolinePipeline.ts ***!
362
- \********************************************/
363
- (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
180
+ },
181
+ "./src/pipeline/TrampolinePipeline.ts"(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
364
182
  __webpack_require__.r(__webpack_exports__);
365
183
  __webpack_require__.d(__webpack_exports__, {
366
184
  TrampolinePipeline: () => (TrampolinePipeline),
367
185
  WorkPipeline: () => (WorkPipeline)
368
186
  });
369
- /* ESM import */var _utilities__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../utilities */ "./src/utilities/logger.ts");
370
- /* ESM import */var _results__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../results */ "./src/results/Result.ts");
187
+ /* import */ var _utilities__rspack_import_0 = __webpack_require__("./src/utilities/logger.ts");
188
+ /* import */ var _results__rspack_import_1 = __webpack_require__("./src/results/Result.ts");
371
189
 
372
190
 
373
191
  class TrampolinePipeline {
@@ -376,7 +194,7 @@ class TrampolinePipeline {
376
194
  filter(initialData, done) {
377
195
  this._hasErrored = false; // Reset error flag on new execution
378
196
  if (this._list.length === 0) {
379
- queueMicrotask(() => done(initialData));
197
+ done(initialData);
380
198
  return;
381
199
  }
382
200
  let index = 0;
@@ -387,7 +205,7 @@ class TrampolinePipeline {
387
205
  const finalStepSentinel = () => {
388
206
  // Only call done if no error has occurred
389
207
  if (!this._hasErrored) {
390
- queueMicrotask(() => done(currentData));
208
+ done(currentData);
391
209
  }
392
210
  return null; // Stop the trampoline
393
211
  };
@@ -406,7 +224,7 @@ class TrampolinePipeline {
406
224
  processor(currentData, (result, error) => {
407
225
  // --- Error Handling ---
408
226
  if (error) {
409
- _utilities__WEBPACK_IMPORTED_MODULE_0__.logger.error(`Error reported by processor at index ${idx}:`, error);
227
+ _utilities__rspack_import_0.logger.error(`Error reported by processor at index ${idx}:`, error);
410
228
  this._hasErrored = true; // Set flag
411
229
  // Throw the error to be caught by outer try...catch blocks
412
230
  throw error;
@@ -429,7 +247,7 @@ class TrampolinePipeline {
429
247
  }
430
248
  catch (error) {
431
249
  if (!this._hasErrored) { // Check flag to avoid double logging if error was from callback
432
- _utilities__WEBPACK_IMPORTED_MODULE_0__.logger.error(`Error thrown by processor at index ${idx} or its callback:`, error);
250
+ _utilities__rspack_import_0.logger.error(`Error thrown by processor at index ${idx} or its callback:`, error);
433
251
  this._hasErrored = true;
434
252
  }
435
253
  // Rethrow to be caught by the trampoline's catch block
@@ -452,7 +270,7 @@ class TrampolinePipeline {
452
270
  }
453
271
  isRunning = true;
454
272
  let currentStep = step;
455
- while (typeof currentStep === 'function') {
273
+ while (currentStep !== null) {
456
274
  try {
457
275
  // Stop immediately if an error was flagged elsewhere
458
276
  if (this._hasErrored) {
@@ -464,7 +282,7 @@ class TrampolinePipeline {
464
282
  catch (trampolineError) {
465
283
  // Catch errors propagated from step execution (processor or callback errors)
466
284
  if (!this._hasErrored) { // Avoid double logging
467
- _utilities__WEBPACK_IMPORTED_MODULE_0__.logger.error("Error during trampoline step execution:", trampolineError);
285
+ _utilities__rspack_import_0.logger.error("Error during trampoline step execution:", trampolineError);
468
286
  this._hasErrored = true;
469
287
  }
470
288
  currentStep = null; // Stop the loop
@@ -493,7 +311,7 @@ class TrampolinePipeline {
493
311
  pipeEach(items, fn, map) {
494
312
  for (let i = 0, length = items.length; i < length; i++) {
495
313
  this.pipe((previous, done) => {
496
- fn(map(previous, _results__WEBPACK_IMPORTED_MODULE_1__.Result.success(items[i])), done);
314
+ fn(map(previous, _results__rspack_import_1.Result.success(items[i])), done);
497
315
  });
498
316
  }
499
317
  }
@@ -511,7 +329,7 @@ class WorkPipeline {
511
329
  filter(done) {
512
330
  this._hasErrored = false; // Reset error flag on new execution
513
331
  if (this.unitsOfWork.length === 0) {
514
- queueMicrotask(() => done(_results__WEBPACK_IMPORTED_MODULE_1__.Result.success()));
332
+ done(_results__rspack_import_1.Result.success());
515
333
  return;
516
334
  }
517
335
  let index = 0;
@@ -521,7 +339,7 @@ class WorkPipeline {
521
339
  const finalStepSentinel = () => {
522
340
  // Only call done if no error has occurred
523
341
  if (!this._hasErrored) {
524
- queueMicrotask(() => done(_results__WEBPACK_IMPORTED_MODULE_1__.Result.success()));
342
+ done(_results__rspack_import_1.Result.success());
525
343
  }
526
344
  return null; // Stop the trampoline
527
345
  };
@@ -539,8 +357,8 @@ class WorkPipeline {
539
357
  try {
540
358
  processor((result) => {
541
359
  // --- Error Handling ---
542
- if (result.ok === _results__WEBPACK_IMPORTED_MODULE_1__.Result.ERROR) {
543
- _utilities__WEBPACK_IMPORTED_MODULE_0__.logger.error(`Error reported by AsyncPipeline at index ${idx}:`, result.error);
360
+ if (result.ok === _results__rspack_import_1.Result.ERROR) {
361
+ _utilities__rspack_import_0.logger.error(`Error reported by AsyncPipeline at index ${idx}:`, result.error);
544
362
  this._hasErrored = true; // Set flag
545
363
  // Throw the error to be caught by outer try...catch blocks
546
364
  throw result.error;
@@ -562,7 +380,7 @@ class WorkPipeline {
562
380
  }
563
381
  catch (error) {
564
382
  if (!this._hasErrored) { // Check flag to avoid double logging if error was from callback
565
- _utilities__WEBPACK_IMPORTED_MODULE_0__.logger.error(`Error thrown by processor at index ${idx} or its callback:`, error);
383
+ _utilities__rspack_import_0.logger.error(`Error thrown by processor at index ${idx} or its callback:`, error);
566
384
  this._hasErrored = true;
567
385
  }
568
386
  // Rethrow to be caught by the trampoline's catch block
@@ -585,7 +403,7 @@ class WorkPipeline {
585
403
  }
586
404
  isRunning = true;
587
405
  let currentStep = step;
588
- while (typeof currentStep === 'function') {
406
+ while (currentStep !== null) {
589
407
  try {
590
408
  // Stop immediately if an error was flagged elsewhere
591
409
  if (this._hasErrored) {
@@ -597,7 +415,7 @@ class WorkPipeline {
597
415
  catch (trampolineError) {
598
416
  // Catch errors propagated from step execution (processor or callback errors)
599
417
  if (!this._hasErrored) { // Avoid double logging
600
- _utilities__WEBPACK_IMPORTED_MODULE_0__.logger.error("Error during trampoline step execution:", trampolineError);
418
+ _utilities__rspack_import_0.logger.error("Error during trampoline step execution:", trampolineError);
601
419
  this._hasErrored = true;
602
420
  }
603
421
  currentStep = null; // Stop the loop
@@ -615,7 +433,7 @@ class WorkPipeline {
615
433
  trampoline(createStepRevised(0)); // Start with the revised step creator
616
434
  }
617
435
  catch (error) {
618
- done(_results__WEBPACK_IMPORTED_MODULE_1__.Result.error(error));
436
+ done(_results__rspack_import_1.Result.error(error));
619
437
  }
620
438
  }
621
439
  pipe(work) {
@@ -624,20 +442,16 @@ class WorkPipeline {
624
442
  }
625
443
 
626
444
 
627
- }),
628
- "./src/plugins/EphemeralDataPlugin.ts":
629
- /*!********************************************!*\
630
- !*** ./src/plugins/EphemeralDataPlugin.ts ***!
631
- \********************************************/
632
- (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
445
+ },
446
+ "./src/plugins/EphemeralDataPlugin.ts"(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
633
447
  __webpack_require__.r(__webpack_exports__);
634
448
  __webpack_require__.d(__webpack_exports__, {
635
449
  EphemeralDataPlugin: () => (EphemeralDataPlugin)
636
450
  });
637
- /* ESM import */var _assertions__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../assertions */ "./src/assertions/index.ts");
638
- /* ESM import */var _pipeline__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../pipeline */ "./src/pipeline/TrampolinePipeline.ts");
639
- /* ESM import */var ___WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! . */ "./src/plugins/translators/JsonTranslator.ts");
640
- /* ESM import */var _results__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../results */ "./src/results/Result.ts");
451
+ /* import */ var _assertions__rspack_import_1 = __webpack_require__("./src/assertions/index.ts");
452
+ /* import */ var _pipeline__rspack_import_0 = __webpack_require__("./src/pipeline/TrampolinePipeline.ts");
453
+ /* import */ var ___rspack_import_3 = __webpack_require__("./src/plugins/translators/JsonTranslator.ts");
454
+ /* import */ var _results__rspack_import_2 = __webpack_require__("./src/results/Result.ts");
641
455
 
642
456
 
643
457
 
@@ -651,7 +465,7 @@ class EphemeralDataPlugin {
651
465
  try {
652
466
  const bulkPersistResult = event.operation.toResult();
653
467
  const schemas = event.schemas;
654
- const pipeline = new _pipeline__WEBPACK_IMPORTED_MODULE_0__.WorkPipeline();
468
+ const pipeline = new _pipeline__rspack_import_0.WorkPipeline();
655
469
  let hasWork = false;
656
470
  for (const [schemaId, changes] of event.operation) {
657
471
  const { adds, hasItems, removes, updates } = changes;
@@ -661,21 +475,20 @@ class EphemeralDataPlugin {
661
475
  hasWork = true;
662
476
  const result = bulkPersistResult.get(schemaId);
663
477
  const schema = schemas.get(schemaId);
664
- (0,_assertions__WEBPACK_IMPORTED_MODULE_1__.assertIsNotNull)(schema);
478
+ (0,_assertions__rspack_import_1.assertIsNotNull)(schema);
665
479
  pipeline.pipe((d) => {
666
480
  try {
667
481
  const collection = this.resolveCollection(schema);
668
- collection.load(readResult => {
669
- if (readResult.ok === _results__WEBPACK_IMPORTED_MODULE_2__.Result.ERROR) {
670
- d(readResult);
671
- return;
672
- }
673
- const addsLength = adds.length;
674
- const updatesLength = updates.length;
675
- const removesLength = removes.length;
676
- result.adds = new Array(addsLength);
677
- result.updates = new Array(updatesLength);
678
- result.removes = new Array(removesLength);
482
+ const addsLength = adds.length;
483
+ const updatesLength = updates.length;
484
+ const removesLength = removes.length;
485
+ // Only need to load if we have updates or removes (need existing data)
486
+ // For adds-only operations, we can skip load for better performance
487
+ const needsLoad = updatesLength > 0 || removesLength > 0;
488
+ const processChanges = () => {
489
+ result.adds = Array.from({ length: addsLength });
490
+ result.updates = Array.from({ length: updatesLength });
491
+ result.removes = Array.from({ length: removesLength });
679
492
  for (let j = 0; j < addsLength; j++) {
680
493
  const item = adds[j];
681
494
  collection.add(item);
@@ -691,74 +504,83 @@ class EphemeralDataPlugin {
691
504
  result.removes[j] = removes[j];
692
505
  }
693
506
  collection.save(saveResult => {
694
- if (saveResult.ok === _results__WEBPACK_IMPORTED_MODULE_2__.Result.ERROR) {
507
+ if (saveResult.ok === _results__rspack_import_2.Result.ERROR) {
695
508
  d(saveResult);
696
509
  return;
697
510
  }
698
- d(_results__WEBPACK_IMPORTED_MODULE_2__.Result.success());
511
+ d(_results__rspack_import_2.Result.success());
699
512
  });
700
- });
513
+ };
514
+ if (needsLoad) {
515
+ collection.load(readResult => {
516
+ if (readResult.ok === _results__rspack_import_2.Result.ERROR) {
517
+ d(readResult);
518
+ return;
519
+ }
520
+ processChanges();
521
+ });
522
+ }
523
+ else {
524
+ // Skip load for adds-only operations
525
+ processChanges();
526
+ }
701
527
  }
702
528
  catch (e) {
703
- d(_results__WEBPACK_IMPORTED_MODULE_2__.Result.error(e));
529
+ d(_results__rspack_import_2.Result.error(e));
704
530
  }
705
531
  });
706
532
  }
707
533
  // If there is no work, just return the result
708
534
  if (!hasWork) {
709
- done(_results__WEBPACK_IMPORTED_MODULE_2__.PluginEventResult.success(event.id, bulkPersistResult));
535
+ done(_results__rspack_import_2.PluginEventResult.success(event.id, bulkPersistResult));
710
536
  return;
711
537
  }
712
538
  pipeline.filter((result) => {
713
- if (result.ok === _results__WEBPACK_IMPORTED_MODULE_2__.Result.ERROR) {
714
- done(_results__WEBPACK_IMPORTED_MODULE_2__.PluginEventResult.error(event.id, result.error));
539
+ if (result.ok === _results__rspack_import_2.Result.ERROR) {
540
+ done(_results__rspack_import_2.PluginEventResult.error(event.id, result.error));
715
541
  return;
716
542
  }
717
- done(_results__WEBPACK_IMPORTED_MODULE_2__.PluginEventResult.success(event.id, bulkPersistResult));
543
+ done(_results__rspack_import_2.PluginEventResult.success(event.id, bulkPersistResult));
718
544
  });
719
545
  }
720
546
  catch (e) {
721
- done(_results__WEBPACK_IMPORTED_MODULE_2__.PluginEventResult.error(event.id, e));
547
+ done(_results__rspack_import_2.PluginEventResult.error(event.id, e));
722
548
  }
723
549
  }
724
550
  query(event, done) {
725
551
  try {
726
552
  const operation = event.operation;
727
553
  const schema = operation.schema;
728
- const translator = new ___WEBPACK_IMPORTED_MODULE_3__.JsonTranslator(operation);
554
+ const translator = new ___rspack_import_3.JsonTranslator(operation);
729
555
  const collection = this.resolveCollection(schema);
730
556
  collection.load(r => {
731
- if (r.ok === _results__WEBPACK_IMPORTED_MODULE_2__.Result.ERROR) {
732
- done(_results__WEBPACK_IMPORTED_MODULE_2__.PluginEventResult.error(event.id, r.error));
557
+ if (r.ok === _results__rspack_import_2.Result.ERROR) {
558
+ done(_results__rspack_import_2.PluginEventResult.error(event.id, r.error));
733
559
  return;
734
560
  }
735
561
  const records = collection.records;
736
562
  const length = records.length;
737
- const cloned = new Array(length);
563
+ const cloned = Array.from({ length });
738
564
  for (let i = 0; i < length; i++) {
739
565
  cloned[i] = schema.clone(records[i]);
740
566
  }
741
- done(_results__WEBPACK_IMPORTED_MODULE_2__.PluginEventResult.success(event.id, translator.translate(cloned)));
567
+ done(_results__rspack_import_2.PluginEventResult.success(event.id, translator.translate(cloned)));
742
568
  });
743
569
  }
744
570
  catch (e) {
745
- done(_results__WEBPACK_IMPORTED_MODULE_2__.PluginEventResult.error(event.id, e));
571
+ done(_results__rspack_import_2.PluginEventResult.error(event.id, e));
746
572
  }
747
573
  }
748
574
  }
749
575
 
750
576
 
751
- }),
752
- "./src/plugins/query/Query.ts":
753
- /*!************************************!*\
754
- !*** ./src/plugins/query/Query.ts ***!
755
- \************************************/
756
- (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
577
+ },
578
+ "./src/plugins/query/Query.ts"(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
757
579
  __webpack_require__.r(__webpack_exports__);
758
580
  __webpack_require__.d(__webpack_exports__, {
759
581
  Query: () => (Query)
760
582
  });
761
- /* ESM import */var _QueryOptionsCollection__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./QueryOptionsCollection */ "./src/plugins/query/QueryOptionsCollection.ts");
583
+ /* import */ var _QueryOptionsCollection__rspack_import_0 = __webpack_require__("./src/plugins/query/QueryOptionsCollection.ts");
762
584
 
763
585
  class Query {
764
586
  options;
@@ -791,10 +613,10 @@ class Query {
791
613
  return true;
792
614
  }
793
615
  static EMPTY(schema) {
794
- return new Query(_QueryOptionsCollection__WEBPACK_IMPORTED_MODULE_0__.QueryOptionsCollection.EMPTY(), schema);
616
+ return new Query(_QueryOptionsCollection__rspack_import_0.QueryOptionsCollection.EMPTY(), schema);
795
617
  }
796
618
  static isEmpty(query) {
797
- return _QueryOptionsCollection__WEBPACK_IMPORTED_MODULE_0__.QueryOptionsCollection.isEmpty(query.options);
619
+ return _QueryOptionsCollection__rspack_import_0.QueryOptionsCollection.isEmpty(query.options);
798
620
  }
799
621
  static toString(query) {
800
622
  return JSON.stringify({
@@ -809,17 +631,15 @@ class Query {
809
631
  }
810
632
 
811
633
 
812
- }),
813
- "./src/plugins/query/QueryOptionsCollection.ts":
814
- /*!*****************************************************!*\
815
- !*** ./src/plugins/query/QueryOptionsCollection.ts ***!
816
- \*****************************************************/
817
- (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
634
+ },
635
+ "./src/plugins/query/QueryOptionsCollection.ts"(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
818
636
  __webpack_require__.r(__webpack_exports__);
819
637
  __webpack_require__.d(__webpack_exports__, {
820
638
  QueryOptionsCollection: () => (QueryOptionsCollection)
821
639
  });
822
- /* ESM import */var _expressions_utils__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../expressions/utils */ "./src/expressions/utils.ts");
640
+ /* import */ var _assertions__rspack_import_1 = __webpack_require__("./src/assertions/index.ts");
641
+ /* import */ var _expressions_utils__rspack_import_0 = __webpack_require__("./src/expressions/utils.ts");
642
+
823
643
 
824
644
  class QueryOptionsCollection {
825
645
  options = new Map();
@@ -856,8 +676,8 @@ class QueryOptionsCollection {
856
676
  this.nextExecutionTarget = "memory";
857
677
  }
858
678
  else {
859
- (0,_expressions_utils__WEBPACK_IMPORTED_MODULE_0__.forEach)(filterValue.expression, (expression) => {
860
- if ((0,_expressions_utils__WEBPACK_IMPORTED_MODULE_0__.isPropertyExpression)(expression) && expression.property.isUnmapped) {
679
+ (0,_expressions_utils__rspack_import_0.forEach)(filterValue.expression, (expression) => {
680
+ if ((0,_assertions__rspack_import_1.isPropertyExpression)(expression) && expression.property.isUnmapped) {
861
681
  // Cut over to memory execution, unmapped properties are not in the database and
862
682
  // cannot be queried
863
683
  this.nextExecutionTarget = "memory";
@@ -897,6 +717,10 @@ class QueryOptionsCollection {
897
717
  database: databaseQueryOptionsCollection
898
718
  };
899
719
  }
720
+ hasTransformations() {
721
+ const transformationOptions = ["map", "group", "min", "max", "count", "sum"];
722
+ return transformationOptions.some((name) => this.options.has(name));
723
+ }
900
724
  has(name) {
901
725
  return this.options.has(name);
902
726
  }
@@ -937,32 +761,24 @@ class QueryOptionsCollection {
937
761
  }
938
762
 
939
763
 
940
- }),
941
- "./src/plugins/query/index.ts":
942
- /*!************************************!*\
943
- !*** ./src/plugins/query/index.ts ***!
944
- \************************************/
945
- (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
764
+ },
765
+ "./src/plugins/query/index.ts"(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
946
766
  __webpack_require__.r(__webpack_exports__);
947
767
  __webpack_require__.d(__webpack_exports__, {
948
- Query: () => (/* reexport safe */ _Query__WEBPACK_IMPORTED_MODULE_0__.Query),
949
- QueryOptionsCollection: () => (/* reexport safe */ _QueryOptionsCollection__WEBPACK_IMPORTED_MODULE_1__.QueryOptionsCollection),
950
- QueryOrdering: () => (/* reexport safe */ _types__WEBPACK_IMPORTED_MODULE_2__.QueryOrdering)
768
+ Query: () => (/* reexport safe */ _Query__rspack_import_0.Query),
769
+ QueryOptionsCollection: () => (/* reexport safe */ _QueryOptionsCollection__rspack_import_1.QueryOptionsCollection),
770
+ QueryOrdering: () => (/* reexport safe */ _types__rspack_import_2.QueryOrdering)
951
771
  });
952
- /* ESM import */var _Query__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./Query */ "./src/plugins/query/Query.ts");
953
- /* ESM import */var _QueryOptionsCollection__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./QueryOptionsCollection */ "./src/plugins/query/QueryOptionsCollection.ts");
954
- /* ESM import */var _types__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./types */ "./src/plugins/query/types.ts");
772
+ /* import */ var _Query__rspack_import_0 = __webpack_require__("./src/plugins/query/Query.ts");
773
+ /* import */ var _QueryOptionsCollection__rspack_import_1 = __webpack_require__("./src/plugins/query/QueryOptionsCollection.ts");
774
+ /* import */ var _types__rspack_import_2 = __webpack_require__("./src/plugins/query/types.ts");
955
775
 
956
776
 
957
777
 
958
778
 
959
779
 
960
- }),
961
- "./src/plugins/query/types.ts":
962
- /*!************************************!*\
963
- !*** ./src/plugins/query/types.ts ***!
964
- \************************************/
965
- (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
780
+ },
781
+ "./src/plugins/query/types.ts"(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
966
782
  __webpack_require__.r(__webpack_exports__);
967
783
  __webpack_require__.d(__webpack_exports__, {
968
784
  QueryOrdering: () => (QueryOrdering)
@@ -974,385 +790,15 @@ var QueryOrdering;
974
790
  })(QueryOrdering || (QueryOrdering = {}));
975
791
 
976
792
 
977
- }),
978
- "./src/plugins/replication/OptimisticReplicationDbPlugin.ts":
979
- /*!******************************************************************!*\
980
- !*** ./src/plugins/replication/OptimisticReplicationDbPlugin.ts ***!
981
- \******************************************************************/
982
- (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
983
- __webpack_require__.r(__webpack_exports__);
984
- __webpack_require__.d(__webpack_exports__, {
985
- OptimisticReplicationDbPlugin: () => (OptimisticReplicationDbPlugin)
986
- });
987
- /* ESM import */var _results__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../results */ "./src/results/Result.ts");
988
- /* ESM import */var _pipeline__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../../pipeline */ "./src/pipeline/TrampolinePipeline.ts");
989
- /* ESM import */var _query__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../query */ "./src/plugins/query/Query.ts");
990
- /* ESM import */var _utilities__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../utilities */ "./src/utilities/uuid.ts");
991
- /* ESM import */var _utilities__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../../utilities */ "./src/utilities/replication.ts");
992
- /* ESM import */var _collections__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../../collections */ "./src/collections/Changes.ts");
993
- /* ESM import */var _performance__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../../performance */ "./src/performance/index.ts");
994
-
995
-
996
- 7;
997
-
998
-
999
-
1000
-
1001
- const getMemoryPluginCollectionSize = (plugin, schema) => {
1002
- if ("getCollectionSize" in plugin && typeof plugin.getCollectionSize === "function") {
1003
- return plugin.getCollectionSize(schema.collectionName);
1004
- }
1005
- throw new Error("Cannot get size of collection for MemoryPlugin, not an instance of MemoryPlugin");
1006
- };
1007
- const MAX_HYDRATION_WAIT_MS = 60_000; // 60 seconds max wait
1008
- const HYDRATION_POLL_INTERVAL_MS = 10; // Check ever 10 ms
1009
- let hydrationStatus = "hydration-not-started";
1010
- class OptimisticReplicationDbPlugin {
1011
- plugins;
1012
- constructor(plugins) {
1013
- this.plugins = plugins;
1014
- }
1015
- /**
1016
- * Creates a new OptimisticDbPluginReplicator that coordinates operations between a source database and its replicas.
1017
- *
1018
- * @param source The primary database plugin that will receive all operations first
1019
- * @param replicas Additional database plugins that will replicate operations from the source
1020
- * @returns A new DbPluginReplicator instance that manages the source-replica relationship
1021
- */
1022
- static create(plugins) {
1023
- return new OptimisticReplicationDbPlugin(plugins);
1024
- }
1025
- /**
1026
- * Will query the read plugin if there is one, otherwise the source plugin will be queried
1027
- */
1028
- query(event, done) {
1029
- try {
1030
- const readPlugin = this.plugins.read;
1031
- const sourcePlugin = this.plugins.source;
1032
- const collectionSize = getMemoryPluginCollectionSize(this.plugins.read, event.operation.schema);
1033
- if (collectionSize === 0 && hydrationStatus === "hydration-not-started") {
1034
- // Notify the cache that the db was hydrated right away
1035
- hydrationStatus = "hydration-pending";
1036
- // nothing is hydrated, let's try and hydrate before querying
1037
- // Memory plugin might not be hydrated, lets hydrate it for the targeted schema only,
1038
- // Other queries will do the same and hydrate if needed
1039
- // We want to select all data here
1040
- sourcePlugin.query({
1041
- id: (0,_utilities__WEBPACK_IMPORTED_MODULE_0__.uuid)(8),
1042
- schemas: event.schemas,
1043
- source: "collection",
1044
- // Select All Data
1045
- operation: _query__WEBPACK_IMPORTED_MODULE_1__.Query.EMPTY(event.operation.schema)
1046
- }, (sourceResult) => {
1047
- if (sourceResult.ok === _results__WEBPACK_IMPORTED_MODULE_2__.Result.ERROR) {
1048
- // Notify that hydration failed
1049
- hydrationStatus = "hydration-error";
1050
- done(sourceResult);
1051
- return;
1052
- }
1053
- // Source plugin can have no data, still should succeed
1054
- if (Array.isArray(sourceResult.data.value) === false) {
1055
- // Notify that hydration failed
1056
- hydrationStatus = "hydration-error";
1057
- done(_results__WEBPACK_IMPORTED_MODULE_2__.PluginEventResult.error(event.id, "Query result is not an array"));
1058
- return;
1059
- }
1060
- const changesCollection = new _collections__WEBPACK_IMPORTED_MODULE_3__.BulkPersistChanges();
1061
- const schemaChanges = changesCollection.resolve(event.operation.schema.id);
1062
- // Add the existing items into the persist payload as adds
1063
- schemaChanges.adds = sourceResult.data.value;
1064
- readPlugin.bulkPersist({
1065
- id: (0,_utilities__WEBPACK_IMPORTED_MODULE_0__.uuid)(8),
1066
- schemas: event.schemas,
1067
- operation: changesCollection,
1068
- source: "collection",
1069
- }, (readPersistResult) => {
1070
- if (readPersistResult.ok === _results__WEBPACK_IMPORTED_MODULE_2__.Result.ERROR) {
1071
- // Notify that hydration failed
1072
- hydrationStatus = "hydration-error";
1073
- done(readPersistResult);
1074
- return;
1075
- }
1076
- hydrationStatus = "hydration-success";
1077
- // requery the read plugin
1078
- readPlugin.query(event, done);
1079
- });
1080
- });
1081
- return;
1082
- }
1083
- if (hydrationStatus === "hydration-error") {
1084
- done(_results__WEBPACK_IMPORTED_MODULE_2__.PluginEventResult.error(event.id, "Hydration failed, unable to query read plugin"));
1085
- return;
1086
- }
1087
- // If hydration is pending, do not query empty collection, wait for hydration
1088
- if (hydrationStatus === "hydration-pending") {
1089
- const start = (0,_performance__WEBPACK_IMPORTED_MODULE_4__.now)();
1090
- const pollHydrationStatus = () => {
1091
- const delta = (0,_performance__WEBPACK_IMPORTED_MODULE_4__.now)() - start;
1092
- if (delta > MAX_HYDRATION_WAIT_MS) {
1093
- hydrationStatus = "hydration-error";
1094
- done(_results__WEBPACK_IMPORTED_MODULE_2__.PluginEventResult.error(event.id, `Hydration timeout: exceeded maximum wait time of ${MAX_HYDRATION_WAIT_MS}ms`));
1095
- return;
1096
- }
1097
- if (hydrationStatus === "hydration-error") {
1098
- done(_results__WEBPACK_IMPORTED_MODULE_2__.PluginEventResult.error(event.id, "Hydration failed, unable to query read plugin"));
1099
- return;
1100
- }
1101
- if (hydrationStatus === "hydration-success") {
1102
- // Hydration completed successfully, proceed with query
1103
- readPlugin.query(event, (readResult) => {
1104
- if (readResult.ok === _results__WEBPACK_IMPORTED_MODULE_2__.Result.ERROR) {
1105
- done(readResult);
1106
- return;
1107
- }
1108
- done(readResult);
1109
- });
1110
- return;
1111
- }
1112
- // Still pending, check again after interval
1113
- setTimeout(pollHydrationStatus, HYDRATION_POLL_INTERVAL_MS);
1114
- };
1115
- pollHydrationStatus();
1116
- return;
1117
- }
1118
- // Collection is hydrated for the targeted collection and should be in sync
1119
- readPlugin.query(event, (readResult) => {
1120
- if (readResult.ok === _results__WEBPACK_IMPORTED_MODULE_2__.Result.ERROR) {
1121
- done(readResult);
1122
- return;
1123
- }
1124
- done(readResult);
1125
- return;
1126
- });
1127
- }
1128
- catch (e) {
1129
- done(_results__WEBPACK_IMPORTED_MODULE_2__.PluginEventResult.error(event.id, e));
1130
- }
1131
- }
1132
- destroy(event, done) {
1133
- try {
1134
- const workPipeline = new _pipeline__WEBPACK_IMPORTED_MODULE_5__.WorkPipeline();
1135
- const plugins = [this.plugins.source, ...this.plugins.replicas];
1136
- for (let i = 0, length = plugins.length; i < length; i++) {
1137
- workPipeline.pipe((done) => plugins[i].destroy(event, done));
1138
- }
1139
- workPipeline.filter((result) => {
1140
- if (result.ok === _results__WEBPACK_IMPORTED_MODULE_2__.Result.ERROR) {
1141
- done(_results__WEBPACK_IMPORTED_MODULE_2__.PluginEventResult.error(event.id, result.error));
1142
- return;
1143
- }
1144
- done(_results__WEBPACK_IMPORTED_MODULE_2__.PluginEventResult.success(event.id));
1145
- });
1146
- }
1147
- catch (e) {
1148
- done(_results__WEBPACK_IMPORTED_MODULE_2__.PluginEventResult.error(event.id, e));
1149
- }
1150
- }
1151
- bulkPersist(event, done) {
1152
- try {
1153
- const workPipeline = new _pipeline__WEBPACK_IMPORTED_MODULE_5__.WorkPipeline();
1154
- const deferredPlugins = [this.plugins.source, ...this.plugins.replicas];
1155
- // Since we are doing optimistic, we insert into the read plugin first and assume later plugins will succeed
1156
- // This means the read plugin will generate ids for the source plugin
1157
- this.plugins.read.bulkPersist({
1158
- id: (0,_utilities__WEBPACK_IMPORTED_MODULE_0__.uuid)(8),
1159
- operation: event.operation,
1160
- schemas: event.schemas,
1161
- source: "data-store",
1162
- }, (r) => {
1163
- if (r.ok !== _results__WEBPACK_IMPORTED_MODULE_2__.Result.SUCCESS) {
1164
- done(r);
1165
- return;
1166
- }
1167
- // optimistically call done and still continue saving the rest of the data. We read from the memory
1168
- // db anyways
1169
- done(r);
1170
- const optimisticBulkPersistChanges = new _collections__WEBPACK_IMPORTED_MODULE_3__.BulkPersistChanges();
1171
- // make sure we swap the adds here, that way we can make sure other persist events
1172
- // don't take their additions and try to change subsequent calls
1173
- (0,_utilities__WEBPACK_IMPORTED_MODULE_6__.resolveBulkPersistChanges)(event, r.data, optimisticBulkPersistChanges);
1174
- for (let i = 0, length = deferredPlugins.length; i < length; i++) {
1175
- workPipeline.pipe((d) => {
1176
- const plugin = deferredPlugins[i];
1177
- plugin.bulkPersist({
1178
- id: (0,_utilities__WEBPACK_IMPORTED_MODULE_0__.uuid)(8),
1179
- operation: optimisticBulkPersistChanges,
1180
- schemas: event.schemas,
1181
- source: "data-store",
1182
- }, (r) => {
1183
- if (r.ok === _results__WEBPACK_IMPORTED_MODULE_2__.Result.ERROR) {
1184
- d(r);
1185
- return;
1186
- }
1187
- d(_results__WEBPACK_IMPORTED_MODULE_2__.Result.success());
1188
- });
1189
- });
1190
- }
1191
- setTimeout(() => {
1192
- workPipeline.filter((_) => {
1193
- // no-op for now, maybe implement retries?
1194
- });
1195
- }, 5);
1196
- });
1197
- }
1198
- catch (e) {
1199
- done(_results__WEBPACK_IMPORTED_MODULE_2__.PluginEventResult.error(event.id, e));
1200
- }
1201
- }
1202
- }
1203
-
1204
-
1205
- }),
1206
- "./src/plugins/replication/ReplicationDbPlugin.ts":
1207
- /*!********************************************************!*\
1208
- !*** ./src/plugins/replication/ReplicationDbPlugin.ts ***!
1209
- \********************************************************/
1210
- (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
1211
- __webpack_require__.r(__webpack_exports__);
1212
- __webpack_require__.d(__webpack_exports__, {
1213
- ReplicationDbPlugin: () => (ReplicationDbPlugin)
1214
- });
1215
- /* ESM import */var _results__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../results */ "./src/results/Result.ts");
1216
- /* ESM import */var _pipeline__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../pipeline */ "./src/pipeline/TrampolinePipeline.ts");
1217
- /* ESM import */var _collections__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../collections */ "./src/collections/Changes.ts");
1218
- /* ESM import */var _utilities__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../../utilities */ "./src/utilities/replication.ts");
1219
-
1220
-
1221
-
1222
-
1223
- class ReplicationDbPlugin {
1224
- plugins;
1225
- constructor(plugins) {
1226
- this.plugins = plugins;
1227
- }
1228
- /**
1229
- * Creates a new DbPluginReplicator that coordinates operations between a source database and its replicas.
1230
- *
1231
- * @param source The primary database plugin that will receive all operations first
1232
- * @param replicas Additional database plugins that will replicate operations from the source
1233
- * @returns A new DbPluginReplicator instance that manages the source-replica relationship
1234
- */
1235
- static create(plugins) {
1236
- return new ReplicationDbPlugin(plugins);
1237
- }
1238
- /**
1239
- * Will query the read plugin if there is one, otherwise the source plugin will be queried
1240
- */
1241
- query(event, done) {
1242
- try {
1243
- const plugin = this.plugins.read != null ? this.plugins.read : this.plugins.source;
1244
- plugin.query(event, done);
1245
- }
1246
- catch (e) {
1247
- done(_results__WEBPACK_IMPORTED_MODULE_0__.PluginEventResult.error(event.id, e));
1248
- }
1249
- }
1250
- destroy(event, done) {
1251
- try {
1252
- const pipeline = new _pipeline__WEBPACK_IMPORTED_MODULE_1__.WorkPipeline();
1253
- const plugins = [this.plugins.source, ...this.plugins.replicas];
1254
- for (let i = 0, length = plugins.length; i < length; i++) {
1255
- pipeline.pipe((done) => plugins[i].destroy(event, done));
1256
- }
1257
- pipeline.filter((result) => {
1258
- if (result.ok === _results__WEBPACK_IMPORTED_MODULE_0__.Result.ERROR) {
1259
- done(_results__WEBPACK_IMPORTED_MODULE_0__.PluginEventResult.error(event.id, result.error));
1260
- return;
1261
- }
1262
- done(_results__WEBPACK_IMPORTED_MODULE_0__.PluginEventResult.success(event.id));
1263
- });
1264
- }
1265
- catch (e) {
1266
- done(_results__WEBPACK_IMPORTED_MODULE_0__.PluginEventResult.error(event.id, e));
1267
- }
1268
- }
1269
- bulkPersist(event, done) {
1270
- try {
1271
- // insert into the source first to generate any ids, then take the result and persist that into the replicas
1272
- const pipeline = new _pipeline__WEBPACK_IMPORTED_MODULE_1__.WorkPipeline();
1273
- const plugins = [this.plugins.source, ...this.plugins.replicas];
1274
- if (this.plugins.read != null) {
1275
- plugins.push(this.plugins.read);
1276
- }
1277
- const result = new _collections__WEBPACK_IMPORTED_MODULE_2__.BulkPersistResult();
1278
- for (let i = 0, length = plugins.length; i < length; i++) {
1279
- pipeline.pipe((d) => {
1280
- const plugin = plugins[i];
1281
- // source is first
1282
- if (i === 0) {
1283
- plugin.bulkPersist(event, (r) => {
1284
- if (r.ok === _results__WEBPACK_IMPORTED_MODULE_0__.Result.ERROR) {
1285
- d(r);
1286
- return;
1287
- }
1288
- // make sure we swap the adds here, that way we can make sure other persist events
1289
- // don't take their additions and try to change subsequent calls
1290
- (0,_utilities__WEBPACK_IMPORTED_MODULE_3__.resolveBulkPersistChanges)(event, r.data, event.operation);
1291
- d(_results__WEBPACK_IMPORTED_MODULE_0__.Result.success());
1292
- });
1293
- return;
1294
- }
1295
- plugin.bulkPersist(event, (r) => {
1296
- if (r.ok === _results__WEBPACK_IMPORTED_MODULE_0__.Result.ERROR) {
1297
- d(r);
1298
- return;
1299
- }
1300
- d(_results__WEBPACK_IMPORTED_MODULE_0__.Result.success());
1301
- });
1302
- });
1303
- }
1304
- let successCount = 0;
1305
- pipeline.filter((r) => {
1306
- if (r.ok === _results__WEBPACK_IMPORTED_MODULE_0__.Result.ERROR) {
1307
- if (successCount > 0) {
1308
- done(_results__WEBPACK_IMPORTED_MODULE_0__.PluginEventResult.partial(event.id, result, r.error));
1309
- return;
1310
- }
1311
- done(_results__WEBPACK_IMPORTED_MODULE_0__.PluginEventResult.error(event.id, r.error));
1312
- return;
1313
- }
1314
- successCount++;
1315
- done(_results__WEBPACK_IMPORTED_MODULE_0__.PluginEventResult.success(event.id, result));
1316
- });
1317
- }
1318
- catch (e) {
1319
- done(_results__WEBPACK_IMPORTED_MODULE_0__.PluginEventResult.error(event.id, e));
1320
- }
1321
- }
1322
- }
1323
-
1324
-
1325
- }),
1326
- "./src/plugins/replication/index.ts":
1327
- /*!******************************************!*\
1328
- !*** ./src/plugins/replication/index.ts ***!
1329
- \******************************************/
1330
- (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
1331
- __webpack_require__.r(__webpack_exports__);
1332
- __webpack_require__.d(__webpack_exports__, {
1333
- OptimisticReplicationDbPlugin: () => (/* reexport safe */ _OptimisticReplicationDbPlugin__WEBPACK_IMPORTED_MODULE_1__.OptimisticReplicationDbPlugin),
1334
- ReplicationDbPlugin: () => (/* reexport safe */ _ReplicationDbPlugin__WEBPACK_IMPORTED_MODULE_0__.ReplicationDbPlugin)
1335
- });
1336
- /* ESM import */var _ReplicationDbPlugin__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./ReplicationDbPlugin */ "./src/plugins/replication/ReplicationDbPlugin.ts");
1337
- /* ESM import */var _OptimisticReplicationDbPlugin__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./OptimisticReplicationDbPlugin */ "./src/plugins/replication/OptimisticReplicationDbPlugin.ts");
1338
-
1339
-
1340
-
1341
-
1342
-
1343
- }),
1344
- "./src/plugins/translators/DataTranslator.ts":
1345
- /*!***************************************************!*\
1346
- !*** ./src/plugins/translators/DataTranslator.ts ***!
1347
- \***************************************************/
1348
- (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
793
+ },
794
+ "./src/plugins/translators/DataTranslator.ts"(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
1349
795
  __webpack_require__.r(__webpack_exports__);
1350
796
  __webpack_require__.d(__webpack_exports__, {
1351
797
  DataTranslator: () => (DataTranslator)
1352
798
  });
1353
- /* ESM import */var _TranslatedArrayValue__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./TranslatedArrayValue */ "./src/plugins/translators/TranslatedArrayValue.ts");
1354
- /* ESM import */var _TranslatedGroupValue__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./TranslatedGroupValue */ "./src/plugins/translators/TranslatedGroupValue.ts");
1355
- /* ESM import */var _TranslatedSingleValue__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./TranslatedSingleValue */ "./src/plugins/translators/TranslatedSingleValue.ts");
799
+ /* import */ var _TranslatedArrayValue__rspack_import_0 = __webpack_require__("./src/plugins/translators/TranslatedArrayValue.ts");
800
+ /* import */ var _TranslatedGroupValue__rspack_import_1 = __webpack_require__("./src/plugins/translators/TranslatedGroupValue.ts");
801
+ /* import */ var _TranslatedSingleValue__rspack_import_2 = __webpack_require__("./src/plugins/translators/TranslatedSingleValue.ts");
1356
802
 
1357
803
 
1358
804
 
@@ -1375,39 +821,36 @@ class DataTranslator {
1375
821
  this.query = query;
1376
822
  }
1377
823
  translate(data) {
824
+ const isTransformed = this.query.options.hasTransformations();
1378
825
  this.query.options.forEach(item => {
1379
826
  data = this.functionMap[item.name](data, item);
1380
827
  });
1381
828
  if (Array.isArray(data)) {
1382
- return new _TranslatedArrayValue__WEBPACK_IMPORTED_MODULE_0__.TranslatedArrayValue(data);
829
+ return new _TranslatedArrayValue__rspack_import_0.TranslatedArrayValue(data, isTransformed);
1383
830
  }
1384
831
  if (this.query.options.has("group")) {
1385
- return new _TranslatedGroupValue__WEBPACK_IMPORTED_MODULE_1__.TranslatedGroupValue(data);
832
+ return new _TranslatedGroupValue__rspack_import_1.TranslatedGroupValue(data, isTransformed);
1386
833
  }
1387
- return new _TranslatedSingleValue__WEBPACK_IMPORTED_MODULE_2__.TranslatedSingleValue(data);
834
+ return new _TranslatedSingleValue__rspack_import_2.TranslatedSingleValue(data, isTransformed);
1388
835
  }
1389
836
  }
1390
837
 
1391
838
 
1392
- }),
1393
- "./src/plugins/translators/JsonTranslator.ts":
1394
- /*!***************************************************!*\
1395
- !*** ./src/plugins/translators/JsonTranslator.ts ***!
1396
- \***************************************************/
1397
- (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
839
+ },
840
+ "./src/plugins/translators/JsonTranslator.ts"(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
1398
841
  __webpack_require__.r(__webpack_exports__);
1399
842
  __webpack_require__.d(__webpack_exports__, {
1400
843
  JsonTranslator: () => (JsonTranslator)
1401
844
  });
1402
- /* ESM import */var _DataTranslator__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./DataTranslator */ "./src/plugins/translators/DataTranslator.ts");
1403
- /* ESM import */var _assertions__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../assertions */ "./src/assertions/index.ts");
1404
- /* ESM import */var _utilities__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../utilities */ "./src/utilities/dates.ts");
845
+ /* import */ var _DataTranslator__rspack_import_0 = __webpack_require__("./src/plugins/translators/DataTranslator.ts");
846
+ /* import */ var _assertions__rspack_import_1 = __webpack_require__("./src/assertions/index.ts");
847
+ /* import */ var _utilities__rspack_import_2 = __webpack_require__("./src/utilities/dates.ts");
1405
848
 
1406
849
 
1407
850
 
1408
- class JsonTranslator extends _DataTranslator__WEBPACK_IMPORTED_MODULE_0__.DataTranslator {
851
+ class JsonTranslator extends _DataTranslator__rspack_import_0.DataTranslator {
1409
852
  filter(data, option) {
1410
- (0,_assertions__WEBPACK_IMPORTED_MODULE_1__.assertIsArray)(data);
853
+ (0,_assertions__rspack_import_1.assertIsArray)(data);
1411
854
  if (option.value.filter) {
1412
855
  if (option.value.params == null) {
1413
856
  // standard filtering
@@ -1423,7 +866,7 @@ class JsonTranslator extends _DataTranslator__WEBPACK_IMPORTED_MODULE_0__.DataTr
1423
866
  if (Array.isArray(data) == false) {
1424
867
  throw new Error("Can only map an array of data");
1425
868
  }
1426
- const response = new Array(data.length);
869
+ const response = Array.from({ length: data.length });
1427
870
  for (let i = 0, length = data.length; i < length; i++) {
1428
871
  for (let j = 0, l = option.value.fields.length; j < l; j++) {
1429
872
  const field = option.value.fields[j];
@@ -1495,7 +938,7 @@ class JsonTranslator extends _DataTranslator__WEBPACK_IMPORTED_MODULE_0__.DataTr
1495
938
  return data;
1496
939
  }
1497
940
  sum(data, _) {
1498
- (0,_assertions__WEBPACK_IMPORTED_MODULE_1__.assertIsArray)(data, this._formatDataNotArrayError("sum"));
941
+ (0,_assertions__rspack_import_1.assertIsArray)(data, this._formatDataNotArrayError("sum"));
1499
942
  if (data.length === 0) {
1500
943
  throw new Error("Cannot perform operation on empty array, result query contains no data");
1501
944
  }
@@ -1512,7 +955,7 @@ class JsonTranslator extends _DataTranslator__WEBPACK_IMPORTED_MODULE_0__.DataTr
1512
955
  return sum;
1513
956
  }
1514
957
  distinct(data, _) {
1515
- (0,_assertions__WEBPACK_IMPORTED_MODULE_1__.assertIsArray)(data, this._formatDataNotArrayError("distinct"));
958
+ (0,_assertions__rspack_import_1.assertIsArray)(data, this._formatDataNotArrayError("distinct"));
1516
959
  const result = new Set();
1517
960
  // would be nice to have property info here for type detection
1518
961
  let needsDateConversion = false;
@@ -1522,7 +965,7 @@ class JsonTranslator extends _DataTranslator__WEBPACK_IMPORTED_MODULE_0__.DataTr
1522
965
  result.add(value);
1523
966
  continue;
1524
967
  }
1525
- if ((0,_utilities__WEBPACK_IMPORTED_MODULE_2__.isDate)(value)) {
968
+ if ((0,_utilities__rspack_import_2.isDate)(value)) {
1526
969
  needsDateConversion = true;
1527
970
  result.add(value.toISOString());
1528
971
  continue;
@@ -1567,7 +1010,7 @@ class JsonTranslator extends _DataTranslator__WEBPACK_IMPORTED_MODULE_0__.DataTr
1567
1010
  return mapOption.value.fields[0];
1568
1011
  }
1569
1012
  _minMax(data, name, sort) {
1570
- (0,_assertions__WEBPACK_IMPORTED_MODULE_1__.assertIsArray)(data, this._formatDataNotArrayError(name));
1013
+ (0,_assertions__rspack_import_1.assertIsArray)(data, this._formatDataNotArrayError(name));
1571
1014
  data.sort(sort);
1572
1015
  if (data.length === 0) {
1573
1016
  throw new Error("Cannot perform operation on empty array, result query contains no data");
@@ -1580,19 +1023,15 @@ class JsonTranslator extends _DataTranslator__WEBPACK_IMPORTED_MODULE_0__.DataTr
1580
1023
  }
1581
1024
 
1582
1025
 
1583
- }),
1584
- "./src/plugins/translators/SqlTranslator.ts":
1585
- /*!**************************************************!*\
1586
- !*** ./src/plugins/translators/SqlTranslator.ts ***!
1587
- \**************************************************/
1588
- (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
1026
+ },
1027
+ "./src/plugins/translators/SqlTranslator.ts"(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
1589
1028
  __webpack_require__.r(__webpack_exports__);
1590
1029
  __webpack_require__.d(__webpack_exports__, {
1591
1030
  SqlTranslator: () => (SqlTranslator)
1592
1031
  });
1593
- /* ESM import */var _DataTranslator__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./DataTranslator */ "./src/plugins/translators/DataTranslator.ts");
1032
+ /* import */ var _DataTranslator__rspack_import_0 = __webpack_require__("./src/plugins/translators/DataTranslator.ts");
1594
1033
 
1595
- class SqlTranslator extends _DataTranslator__WEBPACK_IMPORTED_MODULE_0__.DataTranslator {
1034
+ class SqlTranslator extends _DataTranslator__rspack_import_0.DataTranslator {
1596
1035
  count(data, _) {
1597
1036
  if (Array.isArray(data) && data.length > 0) {
1598
1037
  // Count should be returned as the property alias on the query
@@ -1682,20 +1121,20 @@ class SqlTranslator extends _DataTranslator__WEBPACK_IMPORTED_MODULE_0__.DataTra
1682
1121
  }
1683
1122
 
1684
1123
 
1685
- }),
1686
- "./src/plugins/translators/TranslatedArrayValue.ts":
1687
- /*!*********************************************************!*\
1688
- !*** ./src/plugins/translators/TranslatedArrayValue.ts ***!
1689
- \*********************************************************/
1690
- (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
1124
+ },
1125
+ "./src/plugins/translators/TranslatedArrayValue.ts"(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
1691
1126
  __webpack_require__.r(__webpack_exports__);
1692
1127
  __webpack_require__.d(__webpack_exports__, {
1693
1128
  TranslatedArrayValue: () => (TranslatedArrayValue)
1694
1129
  });
1695
1130
  class TranslatedArrayValue {
1696
1131
  value;
1697
- constructor(value) {
1132
+ isTransformed;
1133
+ isEmpty;
1134
+ constructor(value, isTransformed) {
1698
1135
  this.value = value;
1136
+ this.isEmpty = value == null || (Array.isArray(value) && value.length === 0);
1137
+ this.isTransformed = isTransformed;
1699
1138
  }
1700
1139
  forEach(callback) {
1701
1140
  const data = this.value;
@@ -1710,20 +1149,20 @@ class TranslatedArrayValue {
1710
1149
  }
1711
1150
 
1712
1151
 
1713
- }),
1714
- "./src/plugins/translators/TranslatedGroupValue.ts":
1715
- /*!*********************************************************!*\
1716
- !*** ./src/plugins/translators/TranslatedGroupValue.ts ***!
1717
- \*********************************************************/
1718
- (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
1152
+ },
1153
+ "./src/plugins/translators/TranslatedGroupValue.ts"(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
1719
1154
  __webpack_require__.r(__webpack_exports__);
1720
1155
  __webpack_require__.d(__webpack_exports__, {
1721
1156
  TranslatedGroupValue: () => (TranslatedGroupValue)
1722
1157
  });
1723
1158
  class TranslatedGroupValue {
1724
1159
  value;
1725
- constructor(value) {
1160
+ isTransformed;
1161
+ isEmpty;
1162
+ constructor(value, isTransformed) {
1726
1163
  this.value = value;
1164
+ this.isEmpty = value == null;
1165
+ this.isTransformed = isTransformed;
1727
1166
  }
1728
1167
  forEach(callback) {
1729
1168
  const group = this.value;
@@ -1743,20 +1182,20 @@ class TranslatedGroupValue {
1743
1182
  }
1744
1183
 
1745
1184
 
1746
- }),
1747
- "./src/plugins/translators/TranslatedSingleValue.ts":
1748
- /*!**********************************************************!*\
1749
- !*** ./src/plugins/translators/TranslatedSingleValue.ts ***!
1750
- \**********************************************************/
1751
- (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
1185
+ },
1186
+ "./src/plugins/translators/TranslatedSingleValue.ts"(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
1752
1187
  __webpack_require__.r(__webpack_exports__);
1753
1188
  __webpack_require__.d(__webpack_exports__, {
1754
1189
  TranslatedSingleValue: () => (TranslatedSingleValue)
1755
1190
  });
1756
1191
  class TranslatedSingleValue {
1757
1192
  value;
1758
- constructor(value) {
1193
+ isTransformed;
1194
+ isEmpty;
1195
+ constructor(value, isTransformed) {
1759
1196
  this.value = value;
1197
+ this.isEmpty = value == null;
1198
+ this.isTransformed = isTransformed;
1760
1199
  }
1761
1200
  forEach(callback) {
1762
1201
  const result = callback(this.value);
@@ -1767,27 +1206,23 @@ class TranslatedSingleValue {
1767
1206
  }
1768
1207
 
1769
1208
 
1770
- }),
1771
- "./src/plugins/translators/index.ts":
1772
- /*!******************************************!*\
1773
- !*** ./src/plugins/translators/index.ts ***!
1774
- \******************************************/
1775
- (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
1209
+ },
1210
+ "./src/plugins/translators/index.ts"(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
1776
1211
  __webpack_require__.r(__webpack_exports__);
1777
1212
  __webpack_require__.d(__webpack_exports__, {
1778
- DataTranslator: () => (/* reexport safe */ _DataTranslator__WEBPACK_IMPORTED_MODULE_0__.DataTranslator),
1779
- JsonTranslator: () => (/* reexport safe */ _JsonTranslator__WEBPACK_IMPORTED_MODULE_1__.JsonTranslator),
1780
- SqlTranslator: () => (/* reexport safe */ _SqlTranslator__WEBPACK_IMPORTED_MODULE_2__.SqlTranslator),
1781
- TranslatedArrayValue: () => (/* reexport safe */ _TranslatedArrayValue__WEBPACK_IMPORTED_MODULE_3__.TranslatedArrayValue),
1782
- TranslatedGroupValue: () => (/* reexport safe */ _TranslatedGroupValue__WEBPACK_IMPORTED_MODULE_4__.TranslatedGroupValue),
1783
- TranslatedSingleValue: () => (/* reexport safe */ _TranslatedSingleValue__WEBPACK_IMPORTED_MODULE_5__.TranslatedSingleValue)
1213
+ DataTranslator: () => (/* reexport safe */ _DataTranslator__rspack_import_0.DataTranslator),
1214
+ JsonTranslator: () => (/* reexport safe */ _JsonTranslator__rspack_import_1.JsonTranslator),
1215
+ SqlTranslator: () => (/* reexport safe */ _SqlTranslator__rspack_import_2.SqlTranslator),
1216
+ TranslatedArrayValue: () => (/* reexport safe */ _TranslatedArrayValue__rspack_import_3.TranslatedArrayValue),
1217
+ TranslatedGroupValue: () => (/* reexport safe */ _TranslatedGroupValue__rspack_import_4.TranslatedGroupValue),
1218
+ TranslatedSingleValue: () => (/* reexport safe */ _TranslatedSingleValue__rspack_import_5.TranslatedSingleValue)
1784
1219
  });
1785
- /* ESM import */var _DataTranslator__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./DataTranslator */ "./src/plugins/translators/DataTranslator.ts");
1786
- /* ESM import */var _JsonTranslator__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./JsonTranslator */ "./src/plugins/translators/JsonTranslator.ts");
1787
- /* ESM import */var _SqlTranslator__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./SqlTranslator */ "./src/plugins/translators/SqlTranslator.ts");
1788
- /* ESM import */var _TranslatedArrayValue__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./TranslatedArrayValue */ "./src/plugins/translators/TranslatedArrayValue.ts");
1789
- /* ESM import */var _TranslatedGroupValue__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./TranslatedGroupValue */ "./src/plugins/translators/TranslatedGroupValue.ts");
1790
- /* ESM import */var _TranslatedSingleValue__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./TranslatedSingleValue */ "./src/plugins/translators/TranslatedSingleValue.ts");
1220
+ /* import */ var _DataTranslator__rspack_import_0 = __webpack_require__("./src/plugins/translators/DataTranslator.ts");
1221
+ /* import */ var _JsonTranslator__rspack_import_1 = __webpack_require__("./src/plugins/translators/JsonTranslator.ts");
1222
+ /* import */ var _SqlTranslator__rspack_import_2 = __webpack_require__("./src/plugins/translators/SqlTranslator.ts");
1223
+ /* import */ var _TranslatedArrayValue__rspack_import_3 = __webpack_require__("./src/plugins/translators/TranslatedArrayValue.ts");
1224
+ /* import */ var _TranslatedGroupValue__rspack_import_4 = __webpack_require__("./src/plugins/translators/TranslatedGroupValue.ts");
1225
+ /* import */ var _TranslatedSingleValue__rspack_import_5 = __webpack_require__("./src/plugins/translators/TranslatedSingleValue.ts");
1791
1226
 
1792
1227
 
1793
1228
 
@@ -1797,12 +1232,8 @@ __webpack_require__.d(__webpack_exports__, {
1797
1232
 
1798
1233
 
1799
1234
 
1800
- }),
1801
- "./src/results/Result.ts":
1802
- /*!*******************************!*\
1803
- !*** ./src/results/Result.ts ***!
1804
- \*******************************/
1805
- (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
1235
+ },
1236
+ "./src/results/Result.ts"(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
1806
1237
  __webpack_require__.r(__webpack_exports__);
1807
1238
  __webpack_require__.d(__webpack_exports__, {
1808
1239
  PluginEventResult: () => (PluginEventResult),
@@ -1884,12 +1315,8 @@ class PluginEventResult extends BaseResult {
1884
1315
  }
1885
1316
 
1886
1317
 
1887
- }),
1888
- "./src/utilities/dates.ts":
1889
- /*!********************************!*\
1890
- !*** ./src/utilities/dates.ts ***!
1891
- \********************************/
1892
- (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
1318
+ },
1319
+ "./src/utilities/dates.ts"(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
1893
1320
  __webpack_require__.r(__webpack_exports__);
1894
1321
  __webpack_require__.d(__webpack_exports__, {
1895
1322
  isDate: () => (isDate)
@@ -1905,26 +1332,33 @@ const isDate = (data) => {
1905
1332
  };
1906
1333
 
1907
1334
 
1908
- }),
1909
- "./src/utilities/logger.ts":
1910
- /*!*********************************!*\
1911
- !*** ./src/utilities/logger.ts ***!
1912
- \*********************************/
1913
- (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
1335
+ },
1336
+ "./src/utilities/logger.ts"(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
1914
1337
  __webpack_require__.r(__webpack_exports__);
1915
1338
  __webpack_require__.d(__webpack_exports__, {
1916
1339
  logger: () => (logger)
1917
1340
  });
1918
- const isDevelopment = () => {
1919
- if (typeof process === 'undefined' || process.env == null) {
1920
- return false;
1921
- }
1922
- const env = "development"?.toLowerCase();
1923
- return env === 'dev' || env === 'development' || env === 'test';
1341
+ /**
1342
+ * Enable logging by setting `globalThis.__ROUTIER_DEBUG__ = true` before any routier code runs.
1343
+ */
1344
+ const shouldLog = () => {
1345
+ if (typeof globalThis !== 'undefined') {
1346
+ const g = globalThis;
1347
+ if (g.__ROUTIER_DEBUG__ === true)
1348
+ return true;
1349
+ }
1350
+ if (typeof process !== 'undefined' && process.env != null) {
1351
+ const debug = process.env.DEBUG;
1352
+ if (debug === 'routier' || debug === '*')
1353
+ return true;
1354
+ const env = "development"?.toLowerCase();
1355
+ if (env === 'dev' || env === 'development' || env === 'test')
1356
+ return true;
1357
+ }
1358
+ return false;
1924
1359
  };
1925
- const shouldLog = isDevelopment();
1926
1360
  const tryLog = (type, ...args) => {
1927
- if (shouldLog) {
1361
+ if (shouldLog()) {
1928
1362
  console[type](...args);
1929
1363
  }
1930
1364
  };
@@ -1950,100 +1384,9 @@ const logger = {
1950
1384
  };
1951
1385
 
1952
1386
 
1953
- }),
1954
- "./src/utilities/replication.ts":
1955
- /*!**************************************!*\
1956
- !*** ./src/utilities/replication.ts ***!
1957
- \**************************************/
1958
- (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
1959
- __webpack_require__.r(__webpack_exports__);
1960
- __webpack_require__.d(__webpack_exports__, {
1961
- resolveBulkPersistChanges: () => (resolveBulkPersistChanges)
1962
- });
1963
- const resolveBulkPersistChanges = (event, result, bulkPersistChanges) => {
1964
- // make sure we swap the adds here, that way we can make sure other persist events
1965
- // don't take their additions and try to change subsequent calls
1966
- for (const [schemaId, changes] of event.operation) {
1967
- const schemmaBulkPersistResult = result.get(schemaId);
1968
- const schemaBulkPersistChanges = bulkPersistChanges.resolve(schemaId);
1969
- // Set the original removes
1970
- schemaBulkPersistChanges.removes = changes.removes;
1971
- // Set the original updates
1972
- schemaBulkPersistChanges.updates = changes.updates;
1973
- // Take the adds from the result and set them to be persisted
1974
- // in the replicated plugins because the id's are set in the
1975
- // memory data store
1976
- schemaBulkPersistChanges.adds = schemmaBulkPersistResult.adds;
1977
- }
1978
- };
1979
-
1980
-
1981
- }),
1982
- "./src/utilities/uuid.ts":
1983
- /*!*******************************!*\
1984
- !*** ./src/utilities/uuid.ts ***!
1985
- \*******************************/
1986
- (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
1987
- __webpack_require__.r(__webpack_exports__);
1988
- __webpack_require__.d(__webpack_exports__, {
1989
- uuid: () => (uuid),
1990
- uuidv4: () => (uuidv4)
1991
- });
1992
- const uuid = (length = 16) => {
1993
- const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
1994
- const charLength = chars.length;
1995
- let result = '';
1996
- for (let i = 0; i < length; i++) {
1997
- result += chars[Math.random() * charLength | 0];
1998
- }
1999
- return result;
2000
- };
2001
- const HEX_CHARS = '0123456789abcdef';
2002
- const UUID_TEMPLATE = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx';
2003
- const hasCrypto = typeof crypto !== 'undefined' && typeof crypto.getRandomValues === 'function';
2004
- const uuidv4 = () => {
2005
- let randomBytes = null;
2006
- if (hasCrypto) {
2007
- randomBytes = crypto.getRandomValues(new Uint8Array(16));
2008
- }
2009
- let byteIndex = 0;
2010
- let uuid = '';
2011
- for (let i = 0; i < UUID_TEMPLATE.length; i++) {
2012
- const c = UUID_TEMPLATE[i];
2013
- if (c === '-') {
2014
- uuid += '-';
2015
- continue;
2016
- }
2017
- let r;
2018
- if (hasCrypto && randomBytes) {
2019
- // Each byte gives two hex digits (nibbles)
2020
- r =
2021
- (i % 2 === 0
2022
- ? randomBytes[byteIndex] >> 4
2023
- : randomBytes[byteIndex++] & 0x0f);
2024
- }
2025
- else {
2026
- r = Math.floor(Math.random() * 16);
2027
- }
2028
- if (c === 'x') {
2029
- uuid += HEX_CHARS[r];
2030
- }
2031
- else if (c === 'y') {
2032
- // Variant bits: 8, 9, A, or B
2033
- uuid += HEX_CHARS[(r & 0x3) | 0x8];
2034
- }
2035
- else if (c === '4') {
2036
- uuid += '4';
2037
- }
2038
- }
2039
- return uuid;
2040
- };
2041
-
2042
-
2043
- }),
1387
+ },
2044
1388
 
2045
1389
  });
2046
- /************************************************************************/
2047
1390
  // The module cache
2048
1391
  var __webpack_module_cache__ = {};
2049
1392
 
@@ -2067,7 +1410,6 @@ return module.exports;
2067
1410
 
2068
1411
  }
2069
1412
 
2070
- /************************************************************************/
2071
1413
  // webpack/runtime/define_property_getters
2072
1414
  (() => {
2073
1415
  __webpack_require__.d = (exports, definition) => {
@@ -2092,34 +1434,25 @@ __webpack_require__.r = (exports) => {
2092
1434
  Object.defineProperty(exports, '__esModule', { value: true });
2093
1435
  };
2094
1436
  })();
2095
- /************************************************************************/
2096
1437
  var __webpack_exports__ = {};
2097
1438
  // This entry needs to be wrapped in an IIFE because it needs to be isolated against other modules in the chunk.
2098
1439
  (() => {
2099
-
2100
- /*!******************************!*\
2101
- !*** ./src/plugins/index.ts ***!
2102
- \******************************/
2103
1440
  __webpack_require__.r(__webpack_exports__);
2104
1441
  __webpack_require__.d(__webpack_exports__, {
2105
- DataTranslator: () => (/* reexport safe */ _translators__WEBPACK_IMPORTED_MODULE_0__.DataTranslator),
2106
- EphemeralDataPlugin: () => (/* reexport safe */ _EphemeralDataPlugin__WEBPACK_IMPORTED_MODULE_3__.EphemeralDataPlugin),
2107
- JsonTranslator: () => (/* reexport safe */ _translators__WEBPACK_IMPORTED_MODULE_0__.JsonTranslator),
2108
- OptimisticReplicationDbPlugin: () => (/* reexport safe */ _replication__WEBPACK_IMPORTED_MODULE_1__.OptimisticReplicationDbPlugin),
2109
- Query: () => (/* reexport safe */ _query__WEBPACK_IMPORTED_MODULE_2__.Query),
2110
- QueryOptionsCollection: () => (/* reexport safe */ _query__WEBPACK_IMPORTED_MODULE_2__.QueryOptionsCollection),
2111
- QueryOrdering: () => (/* reexport safe */ _query__WEBPACK_IMPORTED_MODULE_2__.QueryOrdering),
2112
- ReplicationDbPlugin: () => (/* reexport safe */ _replication__WEBPACK_IMPORTED_MODULE_1__.ReplicationDbPlugin),
2113
- SqlTranslator: () => (/* reexport safe */ _translators__WEBPACK_IMPORTED_MODULE_0__.SqlTranslator),
2114
- TranslatedArrayValue: () => (/* reexport safe */ _translators__WEBPACK_IMPORTED_MODULE_0__.TranslatedArrayValue),
2115
- TranslatedGroupValue: () => (/* reexport safe */ _translators__WEBPACK_IMPORTED_MODULE_0__.TranslatedGroupValue),
2116
- TranslatedSingleValue: () => (/* reexport safe */ _translators__WEBPACK_IMPORTED_MODULE_0__.TranslatedSingleValue)
1442
+ DataTranslator: () => (/* reexport safe */ _translators__rspack_import_0.DataTranslator),
1443
+ EphemeralDataPlugin: () => (/* reexport safe */ _EphemeralDataPlugin__rspack_import_2.EphemeralDataPlugin),
1444
+ JsonTranslator: () => (/* reexport safe */ _translators__rspack_import_0.JsonTranslator),
1445
+ Query: () => (/* reexport safe */ _query__rspack_import_1.Query),
1446
+ QueryOptionsCollection: () => (/* reexport safe */ _query__rspack_import_1.QueryOptionsCollection),
1447
+ QueryOrdering: () => (/* reexport safe */ _query__rspack_import_1.QueryOrdering),
1448
+ SqlTranslator: () => (/* reexport safe */ _translators__rspack_import_0.SqlTranslator),
1449
+ TranslatedArrayValue: () => (/* reexport safe */ _translators__rspack_import_0.TranslatedArrayValue),
1450
+ TranslatedGroupValue: () => (/* reexport safe */ _translators__rspack_import_0.TranslatedGroupValue),
1451
+ TranslatedSingleValue: () => (/* reexport safe */ _translators__rspack_import_0.TranslatedSingleValue)
2117
1452
  });
2118
- /* ESM import */var _translators__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./translators */ "./src/plugins/translators/index.ts");
2119
- /* ESM import */var _replication__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./replication */ "./src/plugins/replication/index.ts");
2120
- /* ESM import */var _query__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./query */ "./src/plugins/query/index.ts");
2121
- /* ESM import */var _EphemeralDataPlugin__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./EphemeralDataPlugin */ "./src/plugins/EphemeralDataPlugin.ts");
2122
-
1453
+ /* import */ var _translators__rspack_import_0 = __webpack_require__("./src/plugins/translators/index.ts");
1454
+ /* import */ var _query__rspack_import_1 = __webpack_require__("./src/plugins/query/index.ts");
1455
+ /* import */ var _EphemeralDataPlugin__rspack_import_2 = __webpack_require__("./src/plugins/EphemeralDataPlugin.ts");
2123
1456
 
2124
1457
 
2125
1458
 
@@ -2130,15 +1463,13 @@ __webpack_require__.d(__webpack_exports__, {
2130
1463
  var __webpack_exports__DataTranslator = __webpack_exports__.DataTranslator;
2131
1464
  var __webpack_exports__EphemeralDataPlugin = __webpack_exports__.EphemeralDataPlugin;
2132
1465
  var __webpack_exports__JsonTranslator = __webpack_exports__.JsonTranslator;
2133
- var __webpack_exports__OptimisticReplicationDbPlugin = __webpack_exports__.OptimisticReplicationDbPlugin;
2134
1466
  var __webpack_exports__Query = __webpack_exports__.Query;
2135
1467
  var __webpack_exports__QueryOptionsCollection = __webpack_exports__.QueryOptionsCollection;
2136
1468
  var __webpack_exports__QueryOrdering = __webpack_exports__.QueryOrdering;
2137
- var __webpack_exports__ReplicationDbPlugin = __webpack_exports__.ReplicationDbPlugin;
2138
1469
  var __webpack_exports__SqlTranslator = __webpack_exports__.SqlTranslator;
2139
1470
  var __webpack_exports__TranslatedArrayValue = __webpack_exports__.TranslatedArrayValue;
2140
1471
  var __webpack_exports__TranslatedGroupValue = __webpack_exports__.TranslatedGroupValue;
2141
1472
  var __webpack_exports__TranslatedSingleValue = __webpack_exports__.TranslatedSingleValue;
2142
- export { __webpack_exports__DataTranslator as DataTranslator, __webpack_exports__EphemeralDataPlugin as EphemeralDataPlugin, __webpack_exports__JsonTranslator as JsonTranslator, __webpack_exports__OptimisticReplicationDbPlugin as OptimisticReplicationDbPlugin, __webpack_exports__Query as Query, __webpack_exports__QueryOptionsCollection as QueryOptionsCollection, __webpack_exports__QueryOrdering as QueryOrdering, __webpack_exports__ReplicationDbPlugin as ReplicationDbPlugin, __webpack_exports__SqlTranslator as SqlTranslator, __webpack_exports__TranslatedArrayValue as TranslatedArrayValue, __webpack_exports__TranslatedGroupValue as TranslatedGroupValue, __webpack_exports__TranslatedSingleValue as TranslatedSingleValue };
1473
+ export { __webpack_exports__DataTranslator as DataTranslator, __webpack_exports__EphemeralDataPlugin as EphemeralDataPlugin, __webpack_exports__JsonTranslator as JsonTranslator, __webpack_exports__Query as Query, __webpack_exports__QueryOptionsCollection as QueryOptionsCollection, __webpack_exports__QueryOrdering as QueryOrdering, __webpack_exports__SqlTranslator as SqlTranslator, __webpack_exports__TranslatedArrayValue as TranslatedArrayValue, __webpack_exports__TranslatedGroupValue as TranslatedGroupValue, __webpack_exports__TranslatedSingleValue as TranslatedSingleValue };
2143
1474
 
2144
1475
  //# sourceMappingURL=index.js.map