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