@routier/core 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (174) hide show
  1. package/LICENSE +21 -0
  2. package/{readme.md → README.md} +2 -2
  3. package/dist/assertions/index.cjs +191 -0
  4. package/dist/assertions/index.cjs.map +1 -0
  5. package/dist/assertions/index.d.ts +30 -0
  6. package/dist/assertions/index.js +94 -30
  7. package/dist/assertions/index.js.map +1 -1
  8. package/dist/capabilities/index.cjs +820 -0
  9. package/dist/capabilities/index.cjs.map +1 -0
  10. package/dist/capabilities/index.js +580 -545
  11. package/dist/capabilities/index.js.map +1 -1
  12. package/dist/codegen/handlers/CloneHandlerBuilder.d.ts +10 -1
  13. package/dist/codegen/handlers/SetHandlerBuilder.d.ts +4 -0
  14. package/dist/codegen/handlers/clone/CloneArrayHandler.d.ts +3 -0
  15. package/dist/codegen/handlers/clone/CloneDateHandler.d.ts +13 -0
  16. package/dist/codegen/handlers/clone/CloneValueHandler.d.ts +16 -0
  17. package/dist/codegen/handlers/compare/CompareComputedHandler.d.ts +10 -0
  18. package/dist/codegen/handlers/compare/CompareFunctionHandler.d.ts +10 -0
  19. package/dist/codegen/handlers/deserialize/DeserializeArrayHandler.d.ts +14 -0
  20. package/dist/codegen/handlers/enableChangeTracking/EnableChangeTrackingArrayHandler.d.ts +11 -0
  21. package/dist/codegen/handlers/enrichment/EnrichmentArrayHandler.d.ts +11 -0
  22. package/dist/codegen/handlers/freeze/FreezeArrayHandler.d.ts +6 -0
  23. package/dist/codegen/handlers/hash/HashArrayHandler.d.ts +10 -0
  24. package/dist/codegen/handlers/hash/HashFileHandler.d.ts +24 -0
  25. package/dist/codegen/handlers/hash/HashObjectHandler.d.ts +10 -0
  26. package/dist/codegen/handlers/hash/HashTransformHandler.d.ts +23 -0
  27. package/dist/codegen/handlers/index.d.ts +1 -0
  28. package/dist/codegen/handlers/merge/MergeArrayHandler.d.ts +20 -0
  29. package/dist/codegen/handlers/merge/MergeObjectHandler.d.ts +10 -0
  30. package/dist/codegen/handlers/serialize/SerializeArrayHandler.d.ts +19 -0
  31. package/dist/codegen/handlers/serialize/SerializeComputedHandler.d.ts +6 -0
  32. package/dist/codegen/handlers/set/SetComplexHandler.d.ts +6 -0
  33. package/dist/codegen/handlers/strip/StripComputedHandler.d.ts +10 -0
  34. package/dist/codegen/handlers/strip/StripFunctionHandler.d.ts +9 -0
  35. package/dist/codegen/handlers/types.d.ts +55 -1
  36. package/dist/codegen/index.cjs +618 -0
  37. package/dist/codegen/index.cjs.map +1 -0
  38. package/dist/codegen/index.js +100 -127
  39. package/dist/codegen/index.js.map +1 -1
  40. package/dist/collections/Changes.d.ts +2 -2
  41. package/dist/collections/MemoryDataCollection.d.ts +15 -1
  42. package/dist/collections/TagCollection.d.ts +7 -8
  43. package/dist/collections/index.cjs +702 -0
  44. package/dist/collections/index.cjs.map +1 -0
  45. package/dist/collections/index.js +282 -276
  46. package/dist/collections/index.js.map +1 -1
  47. package/dist/errors/OptimisticConcurrencyError.d.ts +18 -0
  48. package/dist/errors/PluginDestroyedError.d.ts +10 -0
  49. package/dist/errors/index.cjs +132 -0
  50. package/dist/errors/index.cjs.map +1 -0
  51. package/dist/errors/index.d.ts +2 -0
  52. package/dist/errors/index.js +61 -19
  53. package/dist/errors/index.js.map +1 -1
  54. package/dist/expressions/constants.d.ts +2 -0
  55. package/dist/expressions/evaluate.d.ts +53 -0
  56. package/dist/expressions/index.cjs +2087 -0
  57. package/dist/expressions/index.cjs.map +1 -0
  58. package/dist/expressions/index.d.ts +2 -0
  59. package/dist/expressions/index.js +1784 -772
  60. package/dist/expressions/index.js.map +1 -1
  61. package/dist/expressions/parser.d.ts +19 -0
  62. package/dist/expressions/types.d.ts +87 -2
  63. package/dist/expressions/utils.d.ts +1 -2
  64. package/dist/index.cjs +13925 -0
  65. package/dist/index.cjs.map +1 -0
  66. package/dist/index.js +12094 -7049
  67. package/dist/index.js.map +1 -1
  68. package/dist/performance/index.cjs +217 -0
  69. package/dist/performance/index.cjs.map +1 -0
  70. package/dist/performance/index.js +126 -50
  71. package/dist/performance/index.js.map +1 -1
  72. package/dist/pipeline/index.cjs +576 -0
  73. package/dist/pipeline/index.cjs.map +1 -0
  74. package/dist/pipeline/index.js +229 -156
  75. package/dist/pipeline/index.js.map +1 -1
  76. package/dist/plugins/BatchingDbPlugin.d.ts +139 -0
  77. package/dist/plugins/CacheDbPlugin.d.ts +70 -0
  78. package/dist/plugins/ConcurrencyDbPlugin.d.ts +78 -0
  79. package/dist/plugins/EphemeralDataPlugin.d.ts +57 -1
  80. package/dist/plugins/RetryDbPlugin.d.ts +77 -0
  81. package/dist/plugins/index.cjs +6104 -0
  82. package/dist/plugins/index.cjs.map +1 -0
  83. package/dist/plugins/index.d.ts +5 -1
  84. package/dist/plugins/index.js +5572 -1491
  85. package/dist/plugins/index.js.map +1 -1
  86. package/dist/plugins/query/QueryOptionsCollection.d.ts +22 -0
  87. package/dist/plugins/query/index.d.ts +2 -0
  88. package/dist/plugins/query/join.d.ts +210 -0
  89. package/dist/plugins/query/similarity.d.ts +38 -0
  90. package/dist/plugins/query/types.d.ts +64 -1
  91. package/dist/plugins/translators/DataTranslator.d.ts +28 -0
  92. package/dist/plugins/translators/JsonTranslator.d.ts +27 -0
  93. package/dist/plugins/translators/SqlTranslator.d.ts +45 -0
  94. package/dist/plugins/translators/TranslatedArrayValue.d.ts +3 -1
  95. package/dist/plugins/translators/TranslatedGroupValue.d.ts +3 -1
  96. package/dist/plugins/translators/TranslatedSingleValue.d.ts +3 -1
  97. package/dist/plugins/translators/TupleTranslator.d.ts +45 -0
  98. package/dist/plugins/translators/index.d.ts +1 -0
  99. package/dist/plugins/translators/types.d.ts +8 -1
  100. package/dist/plugins/types.d.ts +87 -11
  101. package/dist/plugins/wire/handler.d.ts +122 -0
  102. package/dist/plugins/wire/index.d.ts +4 -0
  103. package/dist/plugins/wire/persist.d.ts +43 -0
  104. package/dist/plugins/wire/query.d.ts +49 -0
  105. package/dist/plugins/wire/types.d.ts +123 -0
  106. package/dist/results/Result.d.ts +2 -2
  107. package/dist/results/index.cjs +174 -0
  108. package/dist/results/index.cjs.map +1 -0
  109. package/dist/results/index.js +29 -44
  110. package/dist/results/index.js.map +1 -1
  111. package/dist/schema/PropertyInfo.d.ts +35 -2
  112. package/dist/schema/SchemaDefinition.d.ts +51 -1
  113. package/dist/schema/builder.d.ts +35 -1
  114. package/dist/schema/communication/broadcast.d.ts +17 -1
  115. package/dist/schema/index.cjs +6911 -0
  116. package/dist/schema/index.cjs.map +1 -0
  117. package/dist/schema/index.d.ts +4 -0
  118. package/dist/schema/index.js +5781 -3973
  119. package/dist/schema/index.js.map +1 -1
  120. package/dist/schema/property/base/SchemaBase.d.ts +50 -2
  121. package/dist/schema/property/modifiers/SchemaDeserialize.d.ts +5 -1
  122. package/dist/schema/property/modifiers/SchemaForeignKey.d.ts +15 -0
  123. package/dist/schema/property/modifiers/SchemaKey.d.ts +2 -0
  124. package/dist/schema/property/modifiers/SchemaNullable.d.ts +15 -1
  125. package/dist/schema/property/modifiers/SchemaOptional.d.ts +22 -1
  126. package/dist/schema/property/modifiers/SchemaSearchable.d.ts +34 -0
  127. package/dist/schema/property/modifiers/SchemaTag.d.ts +27 -0
  128. package/dist/schema/property/modifiers/SchemaTracked.d.ts +5 -1
  129. package/dist/schema/property/modifiers/index.d.ts +3 -0
  130. package/dist/schema/property/types/SchemaArray.d.ts +2 -0
  131. package/dist/schema/property/types/SchemaBoolean.d.ts +2 -0
  132. package/dist/schema/property/types/SchemaDate.d.ts +2 -0
  133. package/dist/schema/property/types/SchemaFile.d.ts +60 -0
  134. package/dist/schema/property/types/SchemaNumber.d.ts +5 -1
  135. package/dist/schema/property/types/SchemaObject.d.ts +2 -0
  136. package/dist/schema/property/types/SchemaString.d.ts +25 -1
  137. package/dist/schema/property/types/SchemaVector.d.ts +61 -0
  138. package/dist/schema/property/types/index.d.ts +2 -0
  139. package/dist/schema/table/SchemaTransform.d.ts +40 -0
  140. package/dist/schema/table/index.d.ts +1 -0
  141. package/dist/schema/types.d.ts +200 -32
  142. package/dist/schema/utils/propertyKind.d.ts +4 -0
  143. package/dist/schema/utils/standardJsonSchema.d.ts +90 -0
  144. package/dist/types/index.cjs +23 -0
  145. package/dist/types/index.cjs.map +1 -0
  146. package/dist/types/index.js +0 -14
  147. package/dist/types/index.js.map +1 -1
  148. package/dist/utilities/functions.d.ts +1 -1
  149. package/dist/utilities/index.cjs +982 -0
  150. package/dist/utilities/index.cjs.map +1 -0
  151. package/dist/utilities/index.js +590 -321
  152. package/dist/utilities/index.js.map +1 -1
  153. package/dist/utilities/logger.d.ts +48 -0
  154. package/package.json +152 -98
  155. package/dist/collections/Changes.test.d.ts +0 -1
  156. package/dist/collections/MemoryDataCollection.test.d.ts +0 -1
  157. package/dist/collections/TagCollection.test.d.ts +0 -1
  158. package/dist/expressions/parser.test.d.ts +0 -1
  159. package/dist/expressions/utils.test.d.ts +0 -1
  160. package/dist/pipeline/SyncronousQueue.test.d.ts +0 -1
  161. package/dist/pipeline/WorkPipeline.test.d.ts +0 -1
  162. package/dist/plugins/EphemeralDataPlugin.test.d.ts +0 -1
  163. package/dist/plugins/query/QueryOptionsCollection.test.d.ts +0 -1
  164. package/dist/plugins/replication/OptimisticReplicationDbPlugin.d.ts +0 -23
  165. package/dist/plugins/replication/ReplicationDbPlugin.d.ts +0 -22
  166. package/dist/plugins/replication/index.d.ts +0 -3
  167. package/dist/plugins/replication/types.d.ts +0 -5
  168. package/dist/plugins/translators/JsonTranslator.test.d.ts +0 -1
  169. package/dist/schema/PropertyInfo.test.d.ts +0 -1
  170. package/dist/schema/schemaGeneration.test.d.ts +0 -1
  171. package/dist/schema/testSchemas.test.d.ts +0 -314
  172. package/dist/utilities/arrays.test.d.ts +0 -1
  173. package/dist/utilities/dates.test.d.ts +0 -1
  174. package/dist/utilities/strings.test.d.ts +0 -1
@@ -1,17 +1,100 @@
1
1
  var __webpack_modules__ = ({
2
- "./src/expressions/utils.ts"(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
3
- __webpack_require__.r(__webpack_exports__);
2
+ 126(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
4
3
  __webpack_require__.d(__webpack_exports__, {
5
- forEach: () => (forEach),
6
- getProperties: () => (getProperties),
7
- isPropertyExpression: () => (isPropertyExpression)
4
+ e3: () => (isPropertyExpression)
5
+ });
6
+
7
+
8
+ function assertDate(data) {
9
+ if (isDate(data) === false) {
10
+ throw new TypeError('Value is not a Date');
11
+ }
12
+ }
13
+ function assertIsNotNull(data, message) {
14
+ if (data == null) {
15
+ if (message == null) {
16
+ throw new TypeError('Assertion failed, data is null');
17
+ }
18
+ if (typeof message === "string") {
19
+ throw new TypeError(message);
20
+ }
21
+ throw new TypeError(message());
22
+ }
23
+ }
24
+ function assertIsArray(data, message) {
25
+ if (!Array.isArray(data)) {
26
+ throw new TypeError(message ?? 'Assertion failed, data is not of type Array');
27
+ }
28
+ }
29
+ function assertString(data, message) {
30
+ if (typeof data !== "string") {
31
+ throw new TypeError(message ?? 'Assertion failed, data is not of type String');
32
+ }
33
+ }
34
+ function assertInstanceOf(value, Instance) {
35
+ if (value instanceof Instance) {
36
+ return;
37
+ }
38
+ if (value != null && typeof value === "object" && "constructor" in value) {
39
+ throw new TypeError(`value is not instance of type. Type: ${value.constructor.name}`);
40
+ }
41
+ throw new TypeError(`value is not instance of type`);
42
+ }
43
+ function assertIsNumber(value) {
44
+ if (typeof value !== "number") {
45
+ throw new TypeError("value is not of type `number`");
46
+ }
47
+ }
48
+ function isObjectWithType(value) {
49
+ return typeof value === "object" && value !== null && "type" in value;
50
+ }
51
+ /**
52
+ * Type guard: narrows `value` to `Expression` when it is an object with a valid `type` property.
53
+ */ function isExpression(value) {
54
+ return isObjectWithType(value) && EXPRESSION_TYPES.includes(value.type);
55
+ }
56
+ /**
57
+ * Type guard: narrows `value` to `OperatorExpression` when it is an object with `type === "operator"`.
58
+ */ function isOperatorExpression(value) {
59
+ return isObjectWithType(value) && value.type === "operator";
60
+ }
61
+ /**
62
+ * Type guard: narrows `value` to `ComparatorExpression` when it is an object with `type === "comparator"`.
63
+ */ function isComparatorExpression(value) {
64
+ return isObjectWithType(value) && value.type === "comparator";
65
+ }
66
+ /**
67
+ * Type guard: narrows `value` to `PropertyExpression` when it is an object with `type === "property"`.
68
+ */ function isPropertyExpression(value) {
69
+ return isObjectWithType(value) && value.type === "property";
70
+ }
71
+ /**
72
+ * Type guard: narrows `value` to `ValueExpression` when it is an object with `type === "value"`.
73
+ */ function isValueExpression(value) {
74
+ return isObjectWithType(value) && value.type === "value";
75
+ }
76
+ /**
77
+ * Type guard: narrows `value` to `EmptyExpression` when it is an object with `type === "empty"`.
78
+ */ function isEmptyExpression(value) {
79
+ return isObjectWithType(value) && value.type === "empty";
80
+ }
81
+ /**
82
+ * Type guard: narrows `value` to `NotParsableExpression` when it is an object with `type === "not-parsable"`.
83
+ */ function isNotParsableExpression(value) {
84
+ return isObjectWithType(value) && value.type === "not-parsable";
85
+ }
86
+
87
+
88
+ },
89
+ 63(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
90
+ __webpack_require__.d(__webpack_exports__, {
91
+ j: () => (forEach)
8
92
  });
9
93
  /**
10
94
  * Extracts all properties referenced in an expression
11
95
  * @param expression The expression to analyze
12
96
  * @returns Array of PropertyInfo objects referenced in the expression
13
- */
14
- function getProperties(expression) {
97
+ */ function getProperties(expression) {
15
98
  const properties = [];
16
99
  function traverse(expr) {
17
100
  // If this is a property expression, add it to our collection
@@ -29,9 +112,6 @@ function getProperties(expression) {
29
112
  traverse(expression);
30
113
  return properties;
31
114
  }
32
- function isPropertyExpression(expression) {
33
- return expression.type === "property";
34
- }
35
115
  function forEach(expression, callback) {
36
116
  function traverse(expr) {
37
117
  // Call the callback for this expression
@@ -57,12 +137,13 @@ function forEach(expression, callback) {
57
137
 
58
138
 
59
139
  },
60
- "./src/plugins/query/QueryOptionsCollection.ts"(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
61
- __webpack_require__.r(__webpack_exports__);
140
+ 198(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
62
141
  __webpack_require__.d(__webpack_exports__, {
63
- QueryOptionsCollection: () => (QueryOptionsCollection)
142
+ H: () => (QueryOptionsCollection)
64
143
  });
65
- /* import */ var _expressions_utils__rspack_import_0 = __webpack_require__("./src/expressions/utils.ts");
144
+ /* import */ var _assertions__rspack_import_1 = __webpack_require__(126);
145
+ /* import */ var _expressions_utils__rspack_import_0 = __webpack_require__(63);
146
+
66
147
 
67
148
  class QueryOptionsCollection {
68
149
  options = new Map();
@@ -86,30 +167,74 @@ class QueryOptionsCollection {
86
167
  const mapValue = value;
87
168
  // Evaluate the map value to see if we are renaming properties,
88
169
  // if we are we need to perform everything after in memory
89
- if (mapValue.fields.some(x => x.isRename === true) || mapValue.fields.some(x => x.property?.isUnmapped === true)) {
170
+ if (mapValue.fields.some((x)=>x.isRename === true) || mapValue.fields.some((x)=>x.property?.isUnmapped === true)) {
90
171
  // Cut over to memory execution since we are renaming a property with .map
91
172
  // We do not want to figure out how the new name flows through the entire query
92
173
  this.nextExecutionTarget = "memory";
93
174
  }
94
175
  }
95
176
  if (name === "filter") {
96
- // Need to check for unmapped properties
177
+ // Need to check for unmapped and renamed properties
97
178
  const filterValue = value;
179
+ // A tautology (`x => true`) filters nothing — skip it entirely so
180
+ // plugins never see it
181
+ if (filterValue.expression.type === "empty") {
182
+ return;
183
+ }
98
184
  if (filterValue.expression.type === "not-parsable") {
99
185
  this.nextExecutionTarget = "memory";
100
- }
101
- else {
102
- (0,_expressions_utils__rspack_import_0.forEach)(filterValue.expression, (expression) => {
103
- if ((0,_expressions_utils__rspack_import_0.isPropertyExpression)(expression) && expression.property.isUnmapped) {
186
+ } else {
187
+ (0,_expressions_utils__rspack_import_0/* .forEach */.j)(filterValue.expression, (expression)=>{
188
+ if ((0,_assertions__rspack_import_1/* .isPropertyExpression */.e3)(expression) && expression.property.isUnmapped) {
104
189
  // Cut over to memory execution, unmapped properties are not in the database and
105
190
  // cannot be queried
106
191
  this.nextExecutionTarget = "memory";
107
192
  return false;
108
193
  }
194
+ if ((0,_assertions__rspack_import_1/* .isPropertyExpression */.e3)(expression) && expression.property.hasRenamedSegments) {
195
+ // Cut over to memory execution: the plugin stores data under the
196
+ // `from` (storage) names, but filter selectors reference the
197
+ // in-memory names. Memory execution runs after deserialization,
198
+ // where the in-memory names exist
199
+ this.nextExecutionTarget = "memory";
200
+ return false;
201
+ }
109
202
  return true;
110
203
  });
111
204
  }
112
205
  }
206
+ if (name === "sort") {
207
+ const sortValue = value;
208
+ // Same rule as filters: sort selectors reference in-memory names, which
209
+ // only exist after deserialization when the property is renamed or unmapped
210
+ if (sortValue.property != null && (sortValue.property.isUnmapped || sortValue.property.hasRenamedSegments)) {
211
+ this.nextExecutionTarget = "memory";
212
+ }
213
+ }
214
+ if (name === "nearest") {
215
+ const nearestValue = value;
216
+ // Same rule as sort, and for the same reason: the plugin stores the vector under
217
+ // the `from` name, and an unmapped property is not stored at all. Both are only
218
+ // readable after deserialization, which is where memory execution runs.
219
+ //
220
+ // This is also what lets every translator's in-memory fallback read the column by
221
+ // its resolved name — anything whose storage name differs never reaches them.
222
+ if (nearestValue.property != null && (nearestValue.property.isUnmapped || nearestValue.property.hasRenamedSegments)) {
223
+ this.nextExecutionTarget = "memory";
224
+ }
225
+ }
226
+ if (name === "join") {
227
+ const joinValue = value;
228
+ // A join whose two sides live on different plugins cannot be sent to EITHER of
229
+ // them — neither can read the other's rows — so the option itself belongs to the
230
+ // memory half, where the datastore interprets it.
231
+ //
232
+ // Set BEFORE the item is created, unlike `nearest`'s ratchet below, because this
233
+ // moves the join option itself rather than everything after it.
234
+ if (joinValue.crossPlugin === true) {
235
+ this.nextExecutionTarget = "memory";
236
+ }
237
+ }
113
238
  const item = {
114
239
  index: this.nextIndex,
115
240
  option: {
@@ -120,14 +245,96 @@ class QueryOptionsCollection {
120
245
  };
121
246
  this.nextIndex++;
122
247
  const found = this.options.get(name);
123
- this.options.set(name, [...found ?? [], item]);
248
+ this.options.set(name, [
249
+ ...found ?? [],
250
+ item
251
+ ]);
252
+ if (name === "nearest") {
253
+ // Everything AFTER a similarity search runs in memory, whatever the backend.
254
+ //
255
+ // Whether the search was pushed down is a fact about the plugin, which this
256
+ // collection cannot see — so a later option is only safe if it runs after the
257
+ // scoring definitely happened, and in memory is the only place that is true of.
258
+ //
259
+ // The failure this prevents is silent. `.nearest(x => x.embedding, v, 10).take(3)`
260
+ // sends `LIMIT 3` to a backend that ignored the ordering, so three arbitrary rows
261
+ // come back and get scored — three real rows, in a plausible order, and not the
262
+ // three nearest. Nothing errors.
263
+ //
264
+ // A plugin that DID push the search down loses nothing but the chance to also
265
+ // push down what follows it, which is a limit over ten rows.
266
+ this.nextExecutionTarget = "memory";
267
+ }
268
+ if (name === "join") {
269
+ // Everything AFTER a join runs in memory, for the same reason as `nearest`: this
270
+ // collection cannot see HOW the plugin executed the join, and the rows it produced
271
+ // are TUPLES rather than entities of the root schema.
272
+ //
273
+ // A `take` sent to a backend that hash-joined in its translator would limit the
274
+ // OUTER rows read, not the pairs produced — a plausible-looking result with the
275
+ // wrong number of rows in it. Conjuncts that can safely run earlier are split off
276
+ // by the query builder BEFORE dispatch, which is the only exception.
277
+ this.nextExecutionTarget = "memory";
278
+ }
279
+ }
280
+ /**
281
+ * Splits the collection around the FIRST occurrence of `name`, preserving order.
282
+ *
283
+ * For a join: the options recorded before it operate on entity rows, the option itself
284
+ * produces tuples, and the ones after it operate on tuples. Three different shapes, so the
285
+ * caller has to run them in three steps rather than one pass.
286
+ */ splitAt(name) {
287
+ this.resolveEnumeration();
288
+ const sortedItems = this.enumeratedItems.toSorted((a, b)=>a.index - b.index);
289
+ const before = new QueryOptionsCollection();
290
+ const after = new QueryOptionsCollection();
291
+ let at = null;
292
+ for(let i = 0, length = sortedItems.length; i < length; i++){
293
+ const { option } = sortedItems[i];
294
+ if (at == null && option.name === name) {
295
+ at = option;
296
+ continue;
297
+ }
298
+ const destination = at == null ? before : after;
299
+ destination.add(option.name, option.value);
300
+ }
301
+ return {
302
+ before,
303
+ at,
304
+ after
305
+ };
306
+ }
307
+ /**
308
+ * Captures the collection's current state and returns a function that restores it.
309
+ *
310
+ * Terminal queryable operations (count, first, aggregates, …) record their option on
311
+ * the shared collection before executing. Without restoring, a re-executed terminal —
312
+ * the whole point of a subscribed queryable — stacks its option a second time and
313
+ * runs it over the first execution's scalar result.
314
+ */ snapshot() {
315
+ const options = new Map([
316
+ ...this.options.entries()
317
+ ].map(([key, items])=>[
318
+ key,
319
+ [
320
+ ...items
321
+ ]
322
+ ]));
323
+ const nextExecutionTarget = this.nextExecutionTarget;
324
+ const nextIndex = this.nextIndex;
325
+ return ()=>{
326
+ this.options = new Map(options);
327
+ this.nextExecutionTarget = nextExecutionTarget;
328
+ this.nextIndex = nextIndex;
329
+ this.enumeratedItems = [];
330
+ };
124
331
  }
125
332
  split() {
126
333
  this.resolveEnumeration();
127
- const sortedItems = this.enumeratedItems.toSorted((a, b) => a.index - b.index);
334
+ const sortedItems = this.enumeratedItems.toSorted((a, b)=>a.index - b.index);
128
335
  const memoryQueryOptionsCollection = new QueryOptionsCollection();
129
336
  const databaseQueryOptionsCollection = new QueryOptionsCollection();
130
- for (let i = 0, length = sortedItems.length; i < length; i++) {
337
+ for(let i = 0, length = sortedItems.length; i < length; i++){
131
338
  const sortedItem = sortedItems[i];
132
339
  if (sortedItem.option.target === "database") {
133
340
  databaseQueryOptionsCollection.add(sortedItem.option.name, sortedItem.option.value);
@@ -140,6 +347,17 @@ class QueryOptionsCollection {
140
347
  database: databaseQueryOptionsCollection
141
348
  };
142
349
  }
350
+ hasTransformations() {
351
+ const transformationOptions = [
352
+ "map",
353
+ "group",
354
+ "min",
355
+ "max",
356
+ "count",
357
+ "sum"
358
+ ];
359
+ return transformationOptions.some((name)=>this.options.has(name));
360
+ }
143
361
  has(name) {
144
362
  return this.options.has(name);
145
363
  }
@@ -148,7 +366,7 @@ class QueryOptionsCollection {
148
366
  }
149
367
  getLast(name) {
150
368
  this.resolveEnumeration();
151
- for (let i = this.enumeratedItems.length - 1; i >= 0; i--) {
369
+ for(let i = this.enumeratedItems.length - 1; i >= 0; i--){
152
370
  const item = this.enumeratedItems[i];
153
371
  if (item.option.name === name) {
154
372
  return item.option;
@@ -161,10 +379,12 @@ class QueryOptionsCollection {
161
379
  if (found == null) {
162
380
  return [];
163
381
  }
164
- return found.map(w => w.option.value);
382
+ return found.map((w)=>w.option.value);
165
383
  }
166
384
  getEnumeration() {
167
- return [...this.options.values()].flat().toSorted((a, b) => a.index - b.index);
385
+ return [
386
+ ...this.options.values()
387
+ ].flat().toSorted((a, b)=>a.index - b.index);
168
388
  }
169
389
  resolveEnumeration() {
170
390
  if (this.enumeratedItems.length != this.nextIndex) {
@@ -173,7 +393,7 @@ class QueryOptionsCollection {
173
393
  }
174
394
  forEach(iterator) {
175
395
  this.resolveEnumeration();
176
- for (let i = 0, length = this.enumeratedItems.length; i < length; i++) {
396
+ for(let i = 0, length = this.enumeratedItems.length; i < length; i++){
177
397
  iterator(this.enumeratedItems[i].option);
178
398
  }
179
399
  }
@@ -181,29 +401,11 @@ class QueryOptionsCollection {
181
401
 
182
402
 
183
403
  },
184
- "./src/utilities/arrays.ts"(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
185
- __webpack_require__.r(__webpack_exports__);
186
- __webpack_require__.d(__webpack_exports__, {
187
- toMap: () => (toMap)
188
- });
189
- const toMap = (data, keySelector) => {
190
- const result = new Map();
191
- for (let i = 0; i < data.length; i++) {
192
- const item = data[i];
193
- const key = keySelector(item);
194
- result.set(key, item);
195
- }
196
- return result;
197
- };
198
-
199
-
200
- },
201
- "./src/utilities/dates.ts"(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
202
- __webpack_require__.r(__webpack_exports__);
404
+ 76(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
203
405
  __webpack_require__.d(__webpack_exports__, {
204
- isDate: () => (isDate)
406
+ $: () => (isDate)
205
407
  });
206
- const isDate = (data) => {
408
+ const isDate = (data)=>{
207
409
  if (data == null) {
208
410
  return false;
209
411
  }
@@ -215,200 +417,178 @@ const isDate = (data) => {
215
417
 
216
418
 
217
419
  },
218
- "./src/utilities/dbPluginEventUtils.ts"(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
219
- __webpack_require__.r(__webpack_exports__);
420
+ 581(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
220
421
  __webpack_require__.d(__webpack_exports__, {
221
- toEventArray: () => (toEventArray)
422
+ Cg: () => (resetLogLevel),
423
+ He: () => (setLogLevel),
424
+ Mi: () => (isLogLevelEnabled),
425
+ XM: () => (getLogLevel),
426
+ p_: () => (LOG_LEVELS),
427
+ vF: () => (logger)
222
428
  });
223
- const toEventArray = (event) => {
224
- const result = [];
225
- for (const [schemaId, changes] of event.operation) {
226
- if (changes.hasItems === false) {
227
- continue;
228
- }
229
- if (changes.adds.length > 0) {
230
- result.push(...changes.adds.map(add => {
231
- return [schemaId, { data: { ...add }, type: "add" }];
232
- }));
233
- }
234
- if (changes.updates.length > 0) {
235
- result.push(...changes.updates.map(update => {
236
- return [schemaId, { data: { ...update }, type: "update" }];
237
- }));
429
+ /**
430
+ * Levelled logging, resolved once.
431
+ *
432
+ * Three things about the previous implementation drove this shape:
433
+ *
434
+ * - **There was no way to turn logging off.** `globalThis.__ROUTIER_DEBUG__` was only ever
435
+ * compared against `true`, so setting it to `false` did nothing — while
436
+ * `docs/how-to/debug-logging.md` documented exactly that as the way to force logging off.
437
+ * A documented switch that silently does nothing is worse than no switch.
438
+ * - **`NODE_ENV === 'test'` enabled it.** Every Jest run therefore logged, because Jest always
439
+ * sets `NODE_ENV=test`. Measured on the S7 stress scenario, which drives ~2,000 saves through
440
+ * a plugin that logs three lines per query: 12.4s with logging, ~6s without. Test runners also
441
+ * capture console output by snapshotting a stack trace per call, so the cost is far above what
442
+ * writing to a terminal would suggest and the output buries whatever the failure was.
443
+ * - **It was all-or-nothing, and re-resolved per call.** An error could not be kept while debug
444
+ * was dropped, and every one of the ~97 call sites re-read `globalThis` and `process.env`.
445
+ *
446
+ * Levels are compared numerically against a value cached at module load. Measured against a
447
+ * no-op console at 200k calls: an enabled call costs ~70ns, a call rejected by the gate ~3ns.
448
+ * Building the arguments the call site passes in accounts for ~0.2ns of that 3ns, which is why
449
+ * this keeps the ordinary `logger.debug(msg, payload)` signature instead of taking a thunk —
450
+ * a lazy API would recover 0.3% of an enabled call's cost and would have to change every call
451
+ * site to do it.
452
+ */ /** Ordered from most severe to most verbose. `silent` discards everything. */ const LOG_LEVELS = [
453
+ 'silent',
454
+ 'error',
455
+ 'warn',
456
+ 'info',
457
+ 'debug'
458
+ ];
459
+ /** Numeric rank, so a gate is one integer comparison. */ const RANK = {
460
+ silent: 0,
461
+ error: 1,
462
+ warn: 2,
463
+ info: 3,
464
+ debug: 4
465
+ };
466
+ const isLogLevel = (value)=>typeof value === 'string' && LOG_LEVELS.includes(value);
467
+ /**
468
+ * Resolves the configured level, in precedence order.
469
+ *
470
+ * Ordered most specific first: an explicit level beats a boolean flag, a boolean flag beats an
471
+ * environment variable, and an environment variable beats an inference from `NODE_ENV`. Anything
472
+ * unrecognised is ignored rather than treated as an error — a typo'd level should not take down
473
+ * an application, and `silent` is the safe direction to fall back to.
474
+ */ const resolveLevel = ()=>{
475
+ if (typeof globalThis !== 'undefined') {
476
+ const g = globalThis;
477
+ if (isLogLevel(g.__ROUTIER_LOG_LEVEL__)) {
478
+ return g.__ROUTIER_LOG_LEVEL__;
238
479
  }
239
- if (changes.removes.length > 0) {
240
- result.push(...changes.removes.map(remove => {
241
- return [schemaId, { data: { ...remove }, type: "remove" }];
242
- }));
480
+ // Both directions honoured. `=== false` used to fall through to the NODE_ENV checks
481
+ // below and re-enable the logging it was asked to suppress.
482
+ if (g.__ROUTIER_DEBUG__ === true) return 'debug';
483
+ if (g.__ROUTIER_DEBUG__ === false) return 'silent';
484
+ }
485
+ // There is deliberately no `import.meta.env` branch, although the documentation used to
486
+ // promise one. It could never work: this package is bundled with rspack, which replaces
487
+ // `import.meta` with `undefined`, so the check would read the *library's* build-time
488
+ // environment rather than the application's — and referencing `import.meta` at all is a parse
489
+ // error under a CommonJS build target, which is how the test suite loads this file. Vite and
490
+ // similar apps set `__ROUTIER_LOG_LEVEL__` or `__ROUTIER_DEBUG__` from their own
491
+ // `import.meta.env`, which is what the docs now describe.
492
+ if (typeof process !== 'undefined' && process.env != null) {
493
+ if (isLogLevel(process.env.ROUTIER_LOG_LEVEL)) {
494
+ return process.env.ROUTIER_LOG_LEVEL;
243
495
  }
244
- }
245
- return result;
496
+ const debug = process.env.DEBUG;
497
+ if (debug === 'routier' || debug === '*') return 'debug';
498
+ const env = "production"?.toLowerCase();
499
+ // `test` is deliberately absent. It used to be here, which meant no test suite anywhere
500
+ // could run Routier quietly. Opt in with DEBUG=routier or ROUTIER_LOG_LEVEL when a test
501
+ // needs the output.
502
+ if (env === 'dev' || env === 'development') return 'debug';
503
+ }
504
+ return 'silent';
246
505
  };
247
-
248
-
249
- },
250
- "./src/utilities/functions.ts"(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
251
- __webpack_require__.r(__webpack_exports__);
252
- __webpack_require__.d(__webpack_exports__, {
253
- noop: () => (noop)
254
- });
255
- const noop = (...args) => { };
256
-
257
-
258
- },
259
- "./src/utilities/logger.ts"(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
260
- __webpack_require__.r(__webpack_exports__);
261
- __webpack_require__.d(__webpack_exports__, {
262
- logger: () => (logger)
263
- });
264
- const isDevelopment = () => {
265
- if (typeof process === 'undefined' || process.env == null) {
266
- return false;
267
- }
268
- const env = "development"?.toLowerCase();
269
- return env === 'dev' || env === 'development' || env === 'test';
270
- };
271
- const shouldLog = isDevelopment();
272
- const tryLog = (type, ...args) => {
273
- if (shouldLog) {
274
- console[type](...args);
275
- }
506
+ let level = resolveLevel();
507
+ let rank = RANK[level];
508
+ /**
509
+ * Overrides the level for the rest of the process.
510
+ *
511
+ * The configuration above is read once, at import, which is what makes the gate cheap — but it
512
+ * also means an application that decides its verbosity after startup, or a test that wants to
513
+ * assert on output, has no way in. This is that way in.
514
+ */ const setLogLevel = (next)=>{
515
+ if (isLogLevel(next) === false) {
516
+ throw new Error(`Unknown log level "${next}". Expected one of: ${LOG_LEVELS.join(', ')}`);
517
+ }
518
+ level = next;
519
+ rank = RANK[next];
276
520
  };
277
- const logger = {
278
- log: (...args) => {
279
- tryLog("log", ...args);
280
- },
281
- info: (...args) => {
282
- tryLog("info", ...args);
283
- },
284
- warn: (...args) => {
285
- tryLog("warn", ...args);
286
- },
287
- error: (...args) => {
288
- tryLog("error", ...args);
289
- },
290
- debug: (...args) => {
291
- tryLog("debug", ...args);
292
- },
293
- table: (...args) => {
294
- tryLog("table", ...args);
295
- },
521
+ const getLogLevel = ()=>level;
522
+ /** Re-reads the environment. For tests that change it after this module was imported. */ const resetLogLevel = ()=>{
523
+ level = resolveLevel();
524
+ rank = RANK[level];
296
525
  };
297
-
298
-
299
- },
300
- "./src/utilities/objects.ts"(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
301
- __webpack_require__.r(__webpack_exports__);
302
- __webpack_require__.d(__webpack_exports__, {
303
- cast: () => (cast),
304
- clone: () => (clone)
305
- });
306
- const cast = (item) => {
307
- return item;
308
- };
309
- function clone(data) {
310
- return JSON.parse(JSON.stringify(data));
311
- }
312
-
313
-
314
- },
315
- "./src/utilities/queryOptionsCollection.ts"(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
316
- __webpack_require__.r(__webpack_exports__);
317
- __webpack_require__.d(__webpack_exports__, {
318
- combineQueryOptionsCollections: () => (combineQueryOptionsCollections)
319
- });
320
- /* import */ var _plugins_query__rspack_import_0 = __webpack_require__("./src/plugins/query/QueryOptionsCollection.ts");
321
-
322
- const combineQueryOptionsCollections = (...collections) => {
323
- const result = new _plugins_query__rspack_import_0.QueryOptionsCollection();
324
- for (let i = 0, length = collections.length; i < length; i++) {
325
- const collection = collections[i];
326
- // Add scoped items first
327
- collection.forEach(item => {
328
- result.add(item.name, item.value);
329
- });
330
- }
331
- return result;
526
+ /**
527
+ * Whether a message at this level would be emitted.
528
+ *
529
+ * For the rare call site whose *arguments* are expensive to build — a serialization, a deep
530
+ * clone, a join over a large collection. An ordinary payload object is not worth guarding; see
531
+ * the measurement in the header.
532
+ */ const isLogLevelEnabled = (at)=>rank >= RANK[at];
533
+ const emit = (at, method, args)=>{
534
+ if (rank < RANK[at]) {
535
+ return;
536
+ }
537
+ // Resolved at call time rather than captured once: test harnesses and browser devtools both
538
+ // replace console methods after modules have loaded, and a captured reference would keep
539
+ // writing past the replacement.
540
+ console[method](...args);
332
541
  };
333
-
334
-
335
- },
336
- "./src/utilities/replication.ts"(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
337
- __webpack_require__.r(__webpack_exports__);
338
- __webpack_require__.d(__webpack_exports__, {
339
- resolveBulkPersistChanges: () => (resolveBulkPersistChanges)
340
- });
341
- const resolveBulkPersistChanges = (event, result, bulkPersistChanges) => {
342
- // make sure we swap the adds here, that way we can make sure other persist events
343
- // don't take their additions and try to change subsequent calls
344
- for (const [schemaId, changes] of event.operation) {
345
- const schemmaBulkPersistResult = result.get(schemaId);
346
- const schemaBulkPersistChanges = bulkPersistChanges.resolve(schemaId);
347
- // Set the original removes
348
- schemaBulkPersistChanges.removes = changes.removes;
349
- // Set the original updates
350
- schemaBulkPersistChanges.updates = changes.updates;
351
- // Take the adds from the result and set them to be persisted
352
- // in the replicated plugins because the id's are set in the
353
- // memory data store
354
- schemaBulkPersistChanges.adds = schemmaBulkPersistResult.adds;
355
- }
542
+ const logger = {
543
+ /** General-purpose output. Carried at `info`, since `log` names a console method, not a level. */ log: (...args)=>emit('info', 'log', args),
544
+ info: (...args)=>emit('info', 'info', args),
545
+ warn: (...args)=>emit('warn', 'warn', args),
546
+ error: (...args)=>emit('error', 'error', args),
547
+ debug: (...args)=>emit('debug', 'debug', args),
548
+ /** Diagnostic tabular output; verbose by nature, so it sits at `debug`. */ table: (...args)=>emit('debug', 'table', args)
356
549
  };
357
550
 
358
551
 
359
552
  },
360
- "./src/utilities/runtime.ts"(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
361
- __webpack_require__.r(__webpack_exports__);
362
- __webpack_require__.d(__webpack_exports__, {
363
- isNodeRuntime: () => (isNodeRuntime)
364
- });
365
- const isNodeRuntime = () => typeof process !== 'undefined' &&
366
- process.versions != null &&
367
- process.versions.node != null;
368
-
369
-
370
- },
371
- "./src/utilities/strings.ts"(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
372
- __webpack_require__.r(__webpack_exports__);
553
+ 615(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
373
554
  __webpack_require__.d(__webpack_exports__, {
374
- fastHash: () => (fastHash),
375
- hash: () => (hash),
376
- stringifyObject: () => (stringifyObject)
555
+ Nr: () => (fastHash),
556
+ Zm: () => (stringifyObject),
557
+ tW: () => (hash)
377
558
  });
378
- const hash = (value, seed = 0) => {
559
+ const hash = (value, seed = 0)=>{
379
560
  // From Stack Overflow
380
561
  // https://stackoverflow.com/a/52171480/3329760
381
562
  let h1 = 0xdeadbeef ^ seed, h2 = 0x41c6ce57 ^ seed;
382
- for (let i = 0, ch; i < value.length; i++) {
563
+ for(let i = 0, ch; i < value.length; i++){
383
564
  ch = value.charCodeAt(i);
384
565
  h1 = Math.imul(h1 ^ ch, 2654435761);
385
566
  h2 = Math.imul(h2 ^ ch, 1597334677);
386
567
  }
387
- h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507);
388
- h1 ^= Math.imul(h2 ^ (h2 >>> 13), 3266489909);
389
- h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507);
390
- h2 ^= Math.imul(h1 ^ (h1 >>> 13), 3266489909);
568
+ h1 = Math.imul(h1 ^ h1 >>> 16, 2246822507);
569
+ h1 ^= Math.imul(h2 ^ h2 >>> 13, 3266489909);
570
+ h2 = Math.imul(h2 ^ h2 >>> 16, 2246822507);
571
+ h2 ^= Math.imul(h1 ^ h1 >>> 13, 3266489909);
391
572
  return 4294967296 * (2097151 & h2) + (h1 >>> 0);
392
573
  };
393
574
  /**
394
575
  * Fast string hash optimized for comparisons.
395
576
  * Uses djb2 algorithm - very fast and good distribution for short to medium strings.
396
577
  * Same input always produces same output (deterministic).
397
- *
578
+ *
398
579
  * @param value - The string to hash
399
580
  * @param seed - Optional seed value (default: 5381)
400
581
  * @returns A positive 32-bit integer hash value
401
- *
582
+ *
402
583
  * @example
403
584
  * ```ts
404
585
  * fastHash("test") === fastHash("test") // true
405
586
  * fastHash("test") !== fastHash("test2") // true
406
587
  * ```
407
- */
408
- const fastHash = (value, seed = 5381) => {
588
+ */ const fastHash = (value, seed = 5381)=>{
409
589
  let hash = seed;
410
- for (let i = 0; i < value.length; i++) {
411
- hash = ((hash << 5) + hash) + value.charCodeAt(i);
590
+ for(let i = 0; i < value.length; i++){
591
+ hash = (hash << 5) + hash + value.charCodeAt(i);
412
592
  }
413
593
  return hash >>> 0; // Convert to unsigned 32-bit integer
414
594
  };
@@ -416,26 +596,23 @@ const fastHash = (value, seed = 5381) => {
416
596
  * Converts any value to a readable string representation.
417
597
  * Handles primitives, objects, arrays, classes, dates, errors, and functions.
418
598
  * Supports depth limiting to prevent infinite recursion on circular references.
419
- *
599
+ *
420
600
  * @param obj - The value to stringify
421
601
  * @param maxDepth - Maximum depth for nested objects (default: 3)
422
602
  * @param currentDepth - Current recursion depth (default: 0)
423
603
  * @returns String representation of the value
424
- *
604
+ *
425
605
  * @example
426
606
  * ```ts
427
607
  * stringifyObject({ name: "test", count: 5 }) // '{ name: "test", count: 5 }'
428
608
  * stringifyObject([1, 2, 3]) // '[1, 2, 3]'
429
609
  * stringifyObject(new Date()) // 'Date(2024-01-01T00:00:00.000Z)'
430
610
  * ```
431
- */
432
- function stringifyObject(obj, maxDepth = 3, currentDepth = 0) {
433
- if (obj === null)
434
- return 'null';
435
- if (obj === undefined)
436
- return 'undefined';
611
+ */ function stringifyObject(obj, maxDepth = 3, currentDepth = 0) {
612
+ if (obj === null) return 'null';
613
+ if (obj === undefined) return 'undefined';
437
614
  const type = typeof obj;
438
- switch (type) {
615
+ switch(type){
439
616
  case 'string':
440
617
  return `"${obj}"`;
441
618
  case 'number':
@@ -458,7 +635,7 @@ function getFunctionName(fn) {
458
635
  }
459
636
  function getObjectProperties(obj) {
460
637
  const properties = {};
461
- for (const key in obj) {
638
+ for(const key in obj){
462
639
  if (obj.hasOwnProperty(key)) {
463
640
  properties[key] = obj[key];
464
641
  }
@@ -466,8 +643,7 @@ function getObjectProperties(obj) {
466
643
  return properties;
467
644
  }
468
645
  function stringifyObjectValue(obj, maxDepth, currentDepth) {
469
- if (obj === null)
470
- return 'null';
646
+ if (obj === null) return 'null';
471
647
  if (obj instanceof Date) {
472
648
  return `Date(${obj.toISOString()})`;
473
649
  }
@@ -486,9 +662,8 @@ function stringifyObjectValue(obj, maxDepth, currentDepth) {
486
662
  return stringifyPlainObject(obj, maxDepth, currentDepth);
487
663
  }
488
664
  function stringifyArray(arr, maxDepth, currentDepth) {
489
- if (arr.length === 0)
490
- return '[]';
491
- const items = arr.slice(0, 5).map(item => stringifyObject(item, maxDepth, currentDepth + 1));
665
+ if (arr.length === 0) return '[]';
666
+ const items = arr.slice(0, 5).map((item)=>stringifyObject(item, maxDepth, currentDepth + 1));
492
667
  const suffix = arr.length > 5 ? `... (+${arr.length - 5} more)` : '';
493
668
  return `[${items.join(', ')}${suffix}]`;
494
669
  }
@@ -498,16 +673,12 @@ function stringifyClassInstance(obj, maxDepth, currentDepth) {
498
673
  if (Object.keys(properties).length === 0) {
499
674
  return `${className} {}`;
500
675
  }
501
- const props = Object.entries(properties)
502
- .slice(0, 5)
503
- .map(([key, value]) => {
504
- const isPrimitive = value === null || value === undefined ||
505
- (typeof value !== 'object' && typeof value !== 'function');
676
+ const props = Object.entries(properties).slice(0, 5).map(([key, value])=>{
677
+ const isPrimitive = value === null || value === undefined || typeof value !== 'object' && typeof value !== 'function';
506
678
  const depth = isPrimitive ? currentDepth : currentDepth + 1;
507
679
  return `${key}: ${stringifyObject(value, maxDepth, depth)}`;
508
680
  });
509
- const suffix = Object.keys(properties).length > 5 ?
510
- `... (+${Object.keys(properties).length - 5} more)` : '';
681
+ const suffix = Object.keys(properties).length > 5 ? `... (+${Object.keys(properties).length - 5} more)` : '';
511
682
  return `${className} { ${props.join(', ')}${suffix} }`;
512
683
  }
513
684
  function stringifyPlainObject(obj, maxDepth, currentDepth) {
@@ -515,43 +686,27 @@ function stringifyPlainObject(obj, maxDepth, currentDepth) {
515
686
  if (Object.keys(properties).length === 0) {
516
687
  return '{}';
517
688
  }
518
- const props = Object.entries(properties)
519
- .slice(0, 5)
520
- .map(([key, value]) => {
521
- const isPrimitive = value === null || value === undefined ||
522
- (typeof value !== 'object' && typeof value !== 'function');
689
+ const props = Object.entries(properties).slice(0, 5).map(([key, value])=>{
690
+ const isPrimitive = value === null || value === undefined || typeof value !== 'object' && typeof value !== 'function';
523
691
  const depth = isPrimitive ? currentDepth : currentDepth + 1;
524
692
  return `${key}: ${stringifyObject(value, maxDepth, depth)}`;
525
693
  });
526
- const suffix = Object.keys(properties).length > 5 ?
527
- `... (+${Object.keys(properties).length - 5} more)` : '';
694
+ const suffix = Object.keys(properties).length > 5 ? `... (+${Object.keys(properties).length - 5} more)` : '';
528
695
  return `{ ${props.join(', ')}${suffix} }`;
529
696
  }
530
697
 
531
698
 
532
699
  },
533
- "./src/utilities/unsafeCast.ts"(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
534
- __webpack_require__.r(__webpack_exports__);
700
+ 618(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
535
701
  __webpack_require__.d(__webpack_exports__, {
536
- unsafeCast: () => (unsafeCast)
702
+ g: () => (uuidv4),
703
+ u: () => (uuid)
537
704
  });
538
- const unsafeCast = (value) => {
539
- return value;
540
- };
541
-
542
-
543
- },
544
- "./src/utilities/uuid.ts"(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
545
- __webpack_require__.r(__webpack_exports__);
546
- __webpack_require__.d(__webpack_exports__, {
547
- uuid: () => (uuid),
548
- uuidv4: () => (uuidv4)
549
- });
550
- const uuid = (length = 16) => {
705
+ const uuid = (length = 16)=>{
551
706
  const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
552
707
  const charLength = chars.length;
553
708
  let result = '';
554
- for (let i = 0; i < length; i++) {
709
+ for(let i = 0; i < length; i++){
555
710
  result += chars[Math.random() * charLength | 0];
556
711
  }
557
712
  return result;
@@ -559,14 +714,21 @@ const uuid = (length = 16) => {
559
714
  const HEX_CHARS = '0123456789abcdef';
560
715
  const UUID_TEMPLATE = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx';
561
716
  const hasCrypto = typeof crypto !== 'undefined' && typeof crypto.getRandomValues === 'function';
562
- const uuidv4 = () => {
717
+ const hasRandomUUID = typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function';
718
+ const uuidv4 = ()=>{
719
+ if (hasRandomUUID) {
720
+ return crypto.randomUUID();
721
+ }
722
+ return uuidv4Fallback();
723
+ };
724
+ const uuidv4Fallback = ()=>{
563
725
  let randomBytes = null;
564
726
  if (hasCrypto) {
565
727
  randomBytes = crypto.getRandomValues(new Uint8Array(16));
566
728
  }
567
729
  let byteIndex = 0;
568
730
  let uuid = '';
569
- for (let i = 0; i < UUID_TEMPLATE.length; i++) {
731
+ for(let i = 0; i < UUID_TEMPLATE.length; i++){
570
732
  const c = UUID_TEMPLATE[i];
571
733
  if (c === '-') {
572
734
  uuid += '-';
@@ -575,22 +737,16 @@ const uuidv4 = () => {
575
737
  let r;
576
738
  if (hasCrypto && randomBytes) {
577
739
  // Each byte gives two hex digits (nibbles)
578
- r =
579
- (i % 2 === 0
580
- ? randomBytes[byteIndex] >> 4
581
- : randomBytes[byteIndex++] & 0x0f);
582
- }
583
- else {
740
+ r = i % 2 === 0 ? randomBytes[byteIndex] >> 4 : randomBytes[byteIndex++] & 0x0f;
741
+ } else {
584
742
  r = Math.floor(Math.random() * 16);
585
743
  }
586
744
  if (c === 'x') {
587
745
  uuid += HEX_CHARS[r];
588
- }
589
- else if (c === 'y') {
746
+ } else if (c === 'y') {
590
747
  // Variant bits: 8, 9, A, or B
591
- uuid += HEX_CHARS[(r & 0x3) | 0x8];
592
- }
593
- else if (c === '4') {
748
+ uuid += HEX_CHARS[r & 0x3 | 0x8];
749
+ } else if (c === '4') {
594
750
  uuid += '4';
595
751
  }
596
752
  }
@@ -638,50 +794,158 @@ __webpack_require__.d = (exports, definition) => {
638
794
  (() => {
639
795
  __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
640
796
  })();
641
- // webpack/runtime/make_namespace_object
642
- (() => {
643
- // define __esModule on exports
644
- __webpack_require__.r = (exports) => {
645
- if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
646
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
647
- }
648
- Object.defineProperty(exports, '__esModule', { value: true });
649
- };
650
- })();
651
797
  var __webpack_exports__ = {};
652
798
  // This entry needs to be wrapped in an IIFE because it needs to be isolated against other modules in the chunk.
653
799
  (() => {
654
- __webpack_require__.r(__webpack_exports__);
800
+
801
+ // EXPORTS
655
802
  __webpack_require__.d(__webpack_exports__, {
656
- cast: () => (/* reexport safe */ _objects__rspack_import_3.cast),
657
- clone: () => (/* reexport safe */ _objects__rspack_import_3.clone),
658
- combineQueryOptionsCollections: () => (/* reexport safe */ _queryOptionsCollection__rspack_import_7.combineQueryOptionsCollections),
659
- fastHash: () => (/* reexport safe */ _strings__rspack_import_1.fastHash),
660
- hash: () => (/* reexport safe */ _strings__rspack_import_1.hash),
661
- isDate: () => (/* reexport safe */ _dates__rspack_import_2.isDate),
662
- isNodeRuntime: () => (/* reexport safe */ _runtime__rspack_import_4.isNodeRuntime),
663
- logger: () => (/* reexport safe */ _logger__rspack_import_11.logger),
664
- noop: () => (/* reexport safe */ _functions__rspack_import_9.noop),
665
- resolveBulkPersistChanges: () => (/* reexport safe */ _replication__rspack_import_6.resolveBulkPersistChanges),
666
- stringifyObject: () => (/* reexport safe */ _strings__rspack_import_1.stringifyObject),
667
- toEventArray: () => (/* reexport safe */ _dbPluginEventUtils__rspack_import_8.toEventArray),
668
- toMap: () => (/* reexport safe */ _arrays__rspack_import_0.toMap),
669
- unsafeCast: () => (/* reexport safe */ _unsafeCast__rspack_import_10.unsafeCast),
670
- uuid: () => (/* reexport safe */ _uuid__rspack_import_5.uuid),
671
- uuidv4: () => (/* reexport safe */ _uuid__rspack_import_5.uuidv4)
803
+ N8: () => (/* reexport */ combineQueryOptionsCollections),
804
+ tW: () => (/* reexport */ strings/* .hash */.tW),
805
+ vF: () => (/* reexport */ logger/* .logger */.vF),
806
+ lQ: () => (/* reexport */ noop),
807
+ He: () => (/* reexport */ logger/* .setLogLevel */.He),
808
+ Nr: () => (/* reexport */ strings/* .fastHash */.Nr),
809
+ uR: () => (/* reexport */ uuid/* .uuid */.u),
810
+ p_: () => (/* reexport */ logger/* .LOG_LEVELS */.p_),
811
+ XM: () => (/* reexport */ logger/* .getLogLevel */.XM),
812
+ Cg: () => (/* reexport */ logger/* .resetLogLevel */.Cg),
813
+ Zm: () => (/* reexport */ strings/* .stringifyObject */.Zm),
814
+ av: () => (/* reexport */ toMap),
815
+ wg: () => (/* reexport */ cast),
816
+ $P: () => (/* reexport */ dates/* .isDate */.$),
817
+ Vg: () => (/* reexport */ toEventArray),
818
+ sz: () => (/* reexport */ unsafeCast),
819
+ Mi: () => (/* reexport */ logger/* .isLogLevelEnabled */.Mi),
820
+ ap: () => (/* reexport */ resolveBulkPersistChanges),
821
+ tX: () => (/* reexport */ isNodeRuntime),
822
+ gZ: () => (/* reexport */ uuid/* .uuidv4 */.g),
823
+ o8: () => (/* reexport */ clone)
672
824
  });
673
- /* import */ var _arrays__rspack_import_0 = __webpack_require__("./src/utilities/arrays.ts");
674
- /* import */ var _strings__rspack_import_1 = __webpack_require__("./src/utilities/strings.ts");
675
- /* import */ var _dates__rspack_import_2 = __webpack_require__("./src/utilities/dates.ts");
676
- /* import */ var _objects__rspack_import_3 = __webpack_require__("./src/utilities/objects.ts");
677
- /* import */ var _runtime__rspack_import_4 = __webpack_require__("./src/utilities/runtime.ts");
678
- /* import */ var _uuid__rspack_import_5 = __webpack_require__("./src/utilities/uuid.ts");
679
- /* import */ var _replication__rspack_import_6 = __webpack_require__("./src/utilities/replication.ts");
680
- /* import */ var _queryOptionsCollection__rspack_import_7 = __webpack_require__("./src/utilities/queryOptionsCollection.ts");
681
- /* import */ var _dbPluginEventUtils__rspack_import_8 = __webpack_require__("./src/utilities/dbPluginEventUtils.ts");
682
- /* import */ var _functions__rspack_import_9 = __webpack_require__("./src/utilities/functions.ts");
683
- /* import */ var _unsafeCast__rspack_import_10 = __webpack_require__("./src/utilities/unsafeCast.ts");
684
- /* import */ var _logger__rspack_import_11 = __webpack_require__("./src/utilities/logger.ts");
825
+
826
+ ;// CONCATENATED MODULE: ./src/utilities/arrays.ts
827
+ const toMap = (data, keySelector)=>{
828
+ const result = new Map();
829
+ for(let i = 0; i < data.length; i++){
830
+ const item = data[i];
831
+ const key = keySelector(item);
832
+ result.set(key, item);
833
+ }
834
+ return result;
835
+ };
836
+
837
+ // EXTERNAL MODULE: ./src/utilities/strings.ts
838
+ var strings = __webpack_require__(615);
839
+ // EXTERNAL MODULE: ./src/utilities/dates.ts
840
+ var dates = __webpack_require__(76);
841
+ ;// CONCATENATED MODULE: ./src/utilities/objects.ts
842
+ const cast = (item)=>{
843
+ return item;
844
+ };
845
+ function clone(data) {
846
+ return JSON.parse(JSON.stringify(data));
847
+ }
848
+
849
+ ;// CONCATENATED MODULE: ./src/utilities/runtime.ts
850
+ const isNodeRuntime = ()=>typeof process !== 'undefined' && process.versions != null && process.versions.node != null;
851
+
852
+ // EXTERNAL MODULE: ./src/utilities/uuid.ts
853
+ var uuid = __webpack_require__(618);
854
+ ;// CONCATENATED MODULE: ./src/utilities/replication.ts
855
+ const resolveBulkPersistChanges = (event, result, bulkPersistChanges)=>{
856
+ // make sure we swap the adds here, that way we can make sure other persist events
857
+ // don't take their additions and try to change subsequent calls
858
+ for (const [schemaId, changes] of event.operation){
859
+ const schemmaBulkPersistResult = result.get(schemaId);
860
+ const schemaBulkPersistChanges = bulkPersistChanges.resolve(schemaId);
861
+ // Set the original removes
862
+ schemaBulkPersistChanges.removes = changes.removes;
863
+ // Set the original updates
864
+ schemaBulkPersistChanges.updates = changes.updates;
865
+ // Take the adds from the result and set them to be persisted
866
+ // in the replicated plugins because the id's are set in the
867
+ // memory data store
868
+ schemaBulkPersistChanges.adds = schemmaBulkPersistResult.adds;
869
+ }
870
+ };
871
+
872
+ // EXTERNAL MODULE: ./src/plugins/query/QueryOptionsCollection.ts
873
+ var QueryOptionsCollection = __webpack_require__(198);
874
+ ;// CONCATENATED MODULE: ./src/utilities/queryOptionsCollection.ts
875
+
876
+ const combineQueryOptionsCollections = (...collections)=>{
877
+ const result = new QueryOptionsCollection/* .QueryOptionsCollection */.H();
878
+ for(let i = 0, length = collections.length; i < length; i++){
879
+ const collection = collections[i];
880
+ // Add scoped items first
881
+ collection.forEach((item)=>{
882
+ result.add(item.name, item.value);
883
+ });
884
+ }
885
+ return result;
886
+ };
887
+
888
+ ;// CONCATENATED MODULE: ./src/utilities/dbPluginEventUtils.ts
889
+ const toEventArray = (event)=>{
890
+ const result = [];
891
+ for (const [schemaId, changes] of event.operation){
892
+ if (changes.hasItems === false) {
893
+ continue;
894
+ }
895
+ if (changes.adds.length > 0) {
896
+ result.push(...changes.adds.map((add)=>{
897
+ return [
898
+ schemaId,
899
+ {
900
+ data: {
901
+ ...add
902
+ },
903
+ type: "add"
904
+ }
905
+ ];
906
+ }));
907
+ }
908
+ if (changes.updates.length > 0) {
909
+ result.push(...changes.updates.map((update)=>{
910
+ return [
911
+ schemaId,
912
+ {
913
+ data: {
914
+ ...update
915
+ },
916
+ type: "update"
917
+ }
918
+ ];
919
+ }));
920
+ }
921
+ if (changes.removes.length > 0) {
922
+ result.push(...changes.removes.map((remove)=>{
923
+ return [
924
+ schemaId,
925
+ {
926
+ data: {
927
+ ...remove
928
+ },
929
+ type: "remove"
930
+ }
931
+ ];
932
+ }));
933
+ }
934
+ }
935
+ return result;
936
+ };
937
+
938
+ ;// CONCATENATED MODULE: ./src/utilities/functions.ts
939
+ const noop = (..._args)=>{};
940
+
941
+ ;// CONCATENATED MODULE: ./src/utilities/unsafeCast.ts
942
+ const unsafeCast = (value)=>{
943
+ return value;
944
+ };
945
+
946
+ // EXTERNAL MODULE: ./src/utilities/logger.ts
947
+ var logger = __webpack_require__(581);
948
+ ;// CONCATENATED MODULE: ./src/utilities/index.ts
685
949
 
686
950
 
687
951
 
@@ -698,22 +962,27 @@ __webpack_require__.d(__webpack_exports__, {
698
962
 
699
963
  })();
700
964
 
701
- var __webpack_exports__cast = __webpack_exports__.cast;
702
- var __webpack_exports__clone = __webpack_exports__.clone;
703
- var __webpack_exports__combineQueryOptionsCollections = __webpack_exports__.combineQueryOptionsCollections;
704
- var __webpack_exports__fastHash = __webpack_exports__.fastHash;
705
- var __webpack_exports__hash = __webpack_exports__.hash;
706
- var __webpack_exports__isDate = __webpack_exports__.isDate;
707
- var __webpack_exports__isNodeRuntime = __webpack_exports__.isNodeRuntime;
708
- var __webpack_exports__logger = __webpack_exports__.logger;
709
- var __webpack_exports__noop = __webpack_exports__.noop;
710
- var __webpack_exports__resolveBulkPersistChanges = __webpack_exports__.resolveBulkPersistChanges;
711
- var __webpack_exports__stringifyObject = __webpack_exports__.stringifyObject;
712
- var __webpack_exports__toEventArray = __webpack_exports__.toEventArray;
713
- var __webpack_exports__toMap = __webpack_exports__.toMap;
714
- var __webpack_exports__unsafeCast = __webpack_exports__.unsafeCast;
715
- var __webpack_exports__uuid = __webpack_exports__.uuid;
716
- var __webpack_exports__uuidv4 = __webpack_exports__.uuidv4;
717
- export { __webpack_exports__cast as cast, __webpack_exports__clone as clone, __webpack_exports__combineQueryOptionsCollections as combineQueryOptionsCollections, __webpack_exports__fastHash as fastHash, __webpack_exports__hash as hash, __webpack_exports__isDate as isDate, __webpack_exports__isNodeRuntime as isNodeRuntime, __webpack_exports__logger as logger, __webpack_exports__noop as noop, __webpack_exports__resolveBulkPersistChanges as resolveBulkPersistChanges, __webpack_exports__stringifyObject as stringifyObject, __webpack_exports__toEventArray as toEventArray, __webpack_exports__toMap as toMap, __webpack_exports__unsafeCast as unsafeCast, __webpack_exports__uuid as uuid, __webpack_exports__uuidv4 as uuidv4 };
965
+ var __webpack_exports__LOG_LEVELS = __webpack_exports__.p_;
966
+ var __webpack_exports__cast = __webpack_exports__.wg;
967
+ var __webpack_exports__clone = __webpack_exports__.o8;
968
+ var __webpack_exports__combineQueryOptionsCollections = __webpack_exports__.N8;
969
+ var __webpack_exports__fastHash = __webpack_exports__.Nr;
970
+ var __webpack_exports__getLogLevel = __webpack_exports__.XM;
971
+ var __webpack_exports__hash = __webpack_exports__.tW;
972
+ var __webpack_exports__isDate = __webpack_exports__.$P;
973
+ var __webpack_exports__isLogLevelEnabled = __webpack_exports__.Mi;
974
+ var __webpack_exports__isNodeRuntime = __webpack_exports__.tX;
975
+ var __webpack_exports__logger = __webpack_exports__.vF;
976
+ var __webpack_exports__noop = __webpack_exports__.lQ;
977
+ var __webpack_exports__resetLogLevel = __webpack_exports__.Cg;
978
+ var __webpack_exports__resolveBulkPersistChanges = __webpack_exports__.ap;
979
+ var __webpack_exports__setLogLevel = __webpack_exports__.He;
980
+ var __webpack_exports__stringifyObject = __webpack_exports__.Zm;
981
+ var __webpack_exports__toEventArray = __webpack_exports__.Vg;
982
+ var __webpack_exports__toMap = __webpack_exports__.av;
983
+ var __webpack_exports__unsafeCast = __webpack_exports__.sz;
984
+ var __webpack_exports__uuid = __webpack_exports__.uR;
985
+ var __webpack_exports__uuidv4 = __webpack_exports__.gZ;
986
+ export { __webpack_exports__LOG_LEVELS as LOG_LEVELS, __webpack_exports__cast as cast, __webpack_exports__clone as clone, __webpack_exports__combineQueryOptionsCollections as combineQueryOptionsCollections, __webpack_exports__fastHash as fastHash, __webpack_exports__getLogLevel as getLogLevel, __webpack_exports__hash as hash, __webpack_exports__isDate as isDate, __webpack_exports__isLogLevelEnabled as isLogLevelEnabled, __webpack_exports__isNodeRuntime as isNodeRuntime, __webpack_exports__logger as logger, __webpack_exports__noop as noop, __webpack_exports__resetLogLevel as resetLogLevel, __webpack_exports__resolveBulkPersistChanges as resolveBulkPersistChanges, __webpack_exports__setLogLevel as setLogLevel, __webpack_exports__stringifyObject as stringifyObject, __webpack_exports__toEventArray as toEventArray, __webpack_exports__toMap as toMap, __webpack_exports__unsafeCast as unsafeCast, __webpack_exports__uuid as uuid, __webpack_exports__uuidv4 as uuidv4 };
718
987
 
719
988
  //# sourceMappingURL=index.js.map