@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,47 +1,16 @@
1
1
  var __webpack_modules__ = ({
2
- "./src/pipeline/SyncronousQueue.ts"(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
3
- __webpack_require__.r(__webpack_exports__);
2
+ 416(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
4
3
  __webpack_require__.d(__webpack_exports__, {
5
- SyncronousQueue: () => (SyncronousQueue)
4
+ U: () => (WorkPipeline),
5
+ k: () => (TrampolinePipeline)
6
6
  });
7
- class SyncronousQueue {
8
- _queue = [];
9
- _current = null;
10
- enqueue(unitOfWork) {
11
- this._queue.push(unitOfWork);
12
- this._next();
13
- }
14
- _next() {
15
- if (this._current != null || this._queue.length === 0) {
16
- return;
17
- }
18
- // Take first item
19
- this._current = this._queue.shift() ?? null;
20
- if (this._current == null) {
21
- return;
22
- }
23
- this._current(() => {
24
- this._current = null;
25
- this._next();
26
- });
27
- }
28
- }
29
-
30
-
31
- },
32
- "./src/pipeline/TrampolinePipeline.ts"(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
33
- __webpack_require__.r(__webpack_exports__);
34
- __webpack_require__.d(__webpack_exports__, {
35
- TrampolinePipeline: () => (TrampolinePipeline),
36
- WorkPipeline: () => (WorkPipeline)
37
- });
38
- /* import */ var _utilities__rspack_import_0 = __webpack_require__("./src/utilities/logger.ts");
39
- /* import */ var _results__rspack_import_1 = __webpack_require__("./src/results/Result.ts");
7
+ /* import */ var _utilities__rspack_import_0 = __webpack_require__(581);
8
+ /* import */ var _results__rspack_import_1 = __webpack_require__(718);
40
9
 
41
10
 
42
11
  class TrampolinePipeline {
43
12
  _list = [];
44
- _hasErrored = false; // Flag to prevent calling done on error
13
+ _hasErrored = false;
45
14
  filter(initialData, done) {
46
15
  this._hasErrored = false; // Reset error flag on new execution
47
16
  if (this._list.length === 0) {
@@ -53,17 +22,16 @@ class TrampolinePipeline {
53
22
  let isRunning = false; // Guard against overlapping trampoline calls
54
23
  try {
55
24
  // --- Revised Completion Logic --- (Moved up for clarity)
56
- const finalStepSentinel = () => {
25
+ const finalStepSentinel = ()=>{
57
26
  // Only call done if no error has occurred
58
27
  if (!this._hasErrored) {
59
28
  done(currentData);
60
29
  }
61
30
  return null; // Stop the trampoline
62
31
  };
63
- const createStepRevised = (idx) => {
64
- return () => {
65
- if (this._hasErrored)
66
- return null; // Stop if an error occurred elsewhere
32
+ const createStepRevised = (idx)=>{
33
+ return ()=>{
34
+ if (this._hasErrored) return null; // Stop if an error occurred elsewhere
67
35
  if (idx >= this._list.length) {
68
36
  return finalStepSentinel(); // Execute the dedicated final step
69
37
  }
@@ -72,10 +40,10 @@ class TrampolinePipeline {
72
40
  let syncCallbackResult = null;
73
41
  let calledSync = false;
74
42
  try {
75
- processor(currentData, (result, error) => {
43
+ processor(currentData, (result, error)=>{
76
44
  // --- Error Handling ---
77
45
  if (error) {
78
- _utilities__rspack_import_0.logger.error(`Error reported by processor at index ${idx}:`, error);
46
+ _utilities__rspack_import_0/* .logger.error */.vF.error(`Error reported by processor at index ${idx}:`, error);
79
47
  this._hasErrored = true; // Set flag
80
48
  // Throw the error to be caught by outer try...catch blocks
81
49
  throw error;
@@ -89,16 +57,14 @@ class TrampolinePipeline {
89
57
  // Callback was synchronous
90
58
  syncCallbackResult = nextStep; // Store next step function
91
59
  calledSync = true;
92
- }
93
- else {
60
+ } else {
94
61
  // Callback was asynchronous, restart trampoline
95
62
  trampoline(nextStep);
96
63
  }
97
64
  });
98
- }
99
- catch (error) {
100
- if (!this._hasErrored) { // Check flag to avoid double logging if error was from callback
101
- _utilities__rspack_import_0.logger.error(`Error thrown by processor at index ${idx} or its callback:`, error);
65
+ } catch (error) {
66
+ if (!this._hasErrored) {
67
+ _utilities__rspack_import_0/* .logger.error */.vF.error(`Error thrown by processor at index ${idx} or its callback:`, error);
102
68
  this._hasErrored = true;
103
69
  }
104
70
  // Rethrow to be caught by the trampoline's catch block
@@ -107,21 +73,20 @@ class TrampolinePipeline {
107
73
  if (calledSync) {
108
74
  // Return the next step function for the sync loop
109
75
  return syncCallbackResult;
110
- }
111
- else {
76
+ } else {
112
77
  // Pause trampoline for async, loop will stop as step returns null
113
78
  return null;
114
79
  }
115
80
  };
116
81
  };
117
82
  // The trampoline loop
118
- const trampoline = (step) => {
83
+ const trampoline = (step)=>{
119
84
  if (isRunning) {
120
85
  return;
121
86
  }
122
87
  isRunning = true;
123
88
  let currentStep = step;
124
- while (currentStep !== null) {
89
+ while(currentStep !== null){
125
90
  try {
126
91
  // Stop immediately if an error was flagged elsewhere
127
92
  if (this._hasErrored) {
@@ -129,29 +94,39 @@ class TrampolinePipeline {
129
94
  break;
130
95
  }
131
96
  currentStep = currentStep(); // Execute step, get next step or null
132
- }
133
- catch (trampolineError) {
97
+ } catch (trampolineError) {
134
98
  // Catch errors propagated from step execution (processor or callback errors)
135
- if (!this._hasErrored) { // Avoid double logging
136
- _utilities__rspack_import_0.logger.error("Error during trampoline step execution:", trampolineError);
99
+ if (!this._hasErrored) {
100
+ _utilities__rspack_import_0/* .logger.error */.vF.error("Error during trampoline step execution:", trampolineError);
137
101
  this._hasErrored = true;
138
102
  }
139
103
  currentStep = null; // Stop the loop
140
- // We don't call `done` here because an error occurred.
141
- // The application should handle the uncaught exception if desired.
142
- break; // Explicitly break loop on error
104
+ // Report the failure to the caller.
105
+ //
106
+ // This used to break without calling `done`, on the reasoning that
107
+ // the application should handle the uncaught exception. It cannot:
108
+ // the error is caught right here, so nothing escapes to be handled,
109
+ // and every caller awaiting the callback waits forever. A hang is
110
+ // strictly worse than an error — it gives the caller nothing to act
111
+ // on and no way to time out.
112
+ //
113
+ // `done` runs exactly once per execution: this path returns
114
+ // immediately, and finalStepSentinel checks `_hasErrored` before
115
+ // reporting success, so the two are mutually exclusive.
116
+ isRunning = false;
117
+ done(currentData, trampolineError);
118
+ return;
143
119
  }
144
120
  }
145
121
  // Loop ends when currentStep is null or loop is broken by error
146
122
  isRunning = false;
147
- // Completion check is now handled by finalStepSentinel ensuring `done` isn't called on error.
123
+ // Completion check is now handled by finalStepSentinel ensuring `done` isn't called on error.
148
124
  };
149
125
  // --- Start the process ---
150
126
  index = 0; // Reset index
151
127
  currentData = initialData; // Reset data
152
128
  trampoline(createStepRevised(0)); // Start with the revised step creator
153
- }
154
- catch (error) {
129
+ } catch (error) {
155
130
  done(currentData, error);
156
131
  }
157
132
  }
@@ -160,44 +135,42 @@ class TrampolinePipeline {
160
135
  return this;
161
136
  }
162
137
  pipeEach(items, fn, map) {
163
- for (let i = 0, length = items.length; i < length; i++) {
164
- this.pipe((previous, done) => {
165
- fn(map(previous, _results__rspack_import_1.Result.success(items[i])), done);
138
+ for(let i = 0, length = items.length; i < length; i++){
139
+ this.pipe((previous, done)=>{
140
+ fn(map(previous, _results__rspack_import_1/* .Result.success */.Q.success(items[i])), done);
166
141
  });
167
142
  }
168
143
  }
169
144
  }
170
145
  /**
171
146
  * Processes functions with callbacks asynchronously.
172
- *
147
+ *
173
148
  * This pipeline handles work items that contain callback functions,
174
149
  * executing them in an asynchronous manner while maintaining proper
175
150
  * flow control and error handling.
176
- */
177
- class WorkPipeline {
151
+ */ class WorkPipeline {
178
152
  unitsOfWork = [];
179
- _hasErrored = false; // Flag to prevent calling done on error
153
+ _hasErrored = false;
180
154
  filter(done) {
181
155
  this._hasErrored = false; // Reset error flag on new execution
182
156
  if (this.unitsOfWork.length === 0) {
183
- done(_results__rspack_import_1.Result.success());
157
+ done(_results__rspack_import_1/* .Result.success */.Q.success());
184
158
  return;
185
159
  }
186
160
  let index = 0;
187
161
  let isRunning = false; // Guard against overlapping trampoline calls
188
162
  try {
189
163
  // --- Revised Completion Logic --- (Moved up for clarity)
190
- const finalStepSentinel = () => {
164
+ const finalStepSentinel = ()=>{
191
165
  // Only call done if no error has occurred
192
166
  if (!this._hasErrored) {
193
- done(_results__rspack_import_1.Result.success());
167
+ done(_results__rspack_import_1/* .Result.success */.Q.success());
194
168
  }
195
169
  return null; // Stop the trampoline
196
170
  };
197
- const createStepRevised = (idx) => {
198
- return () => {
199
- if (this._hasErrored)
200
- return null; // Stop if an error occurred elsewhere
171
+ const createStepRevised = (idx)=>{
172
+ return ()=>{
173
+ if (this._hasErrored) return null; // Stop if an error occurred elsewhere
201
174
  if (idx >= this.unitsOfWork.length) {
202
175
  return finalStepSentinel(); // Execute the dedicated final step
203
176
  }
@@ -206,10 +179,10 @@ class WorkPipeline {
206
179
  let syncCallbackResult = null;
207
180
  let calledSync = false;
208
181
  try {
209
- processor((result) => {
182
+ processor((result)=>{
210
183
  // --- Error Handling ---
211
- if (result.ok === _results__rspack_import_1.Result.ERROR) {
212
- _utilities__rspack_import_0.logger.error(`Error reported by AsyncPipeline at index ${idx}:`, result.error);
184
+ if (result.ok === _results__rspack_import_1/* .Result.ERROR */.Q.ERROR) {
185
+ _utilities__rspack_import_0/* .logger.error */.vF.error(`Error reported by AsyncPipeline at index ${idx}:`, result.error);
213
186
  this._hasErrored = true; // Set flag
214
187
  // Throw the error to be caught by outer try...catch blocks
215
188
  throw result.error;
@@ -222,16 +195,14 @@ class WorkPipeline {
222
195
  // Callback was synchronous
223
196
  syncCallbackResult = nextStep; // Store next step function
224
197
  calledSync = true;
225
- }
226
- else {
198
+ } else {
227
199
  // Callback was asynchronous, restart trampoline
228
200
  trampoline(nextStep);
229
201
  }
230
202
  });
231
- }
232
- catch (error) {
233
- if (!this._hasErrored) { // Check flag to avoid double logging if error was from callback
234
- _utilities__rspack_import_0.logger.error(`Error thrown by processor at index ${idx} or its callback:`, error);
203
+ } catch (error) {
204
+ if (!this._hasErrored) {
205
+ _utilities__rspack_import_0/* .logger.error */.vF.error(`Error thrown by processor at index ${idx} or its callback:`, error);
235
206
  this._hasErrored = true;
236
207
  }
237
208
  // Rethrow to be caught by the trampoline's catch block
@@ -240,21 +211,20 @@ class WorkPipeline {
240
211
  if (calledSync) {
241
212
  // Return the next step function for the sync loop
242
213
  return syncCallbackResult;
243
- }
244
- else {
214
+ } else {
245
215
  // Pause trampoline for async, loop will stop as step returns null
246
216
  return null;
247
217
  }
248
218
  };
249
219
  };
250
220
  // The trampoline loop
251
- const trampoline = (step) => {
221
+ const trampoline = (step)=>{
252
222
  if (isRunning) {
253
223
  return;
254
224
  }
255
225
  isRunning = true;
256
226
  let currentStep = step;
257
- while (currentStep !== null) {
227
+ while(currentStep !== null){
258
228
  try {
259
229
  // Stop immediately if an error was flagged elsewhere
260
230
  if (this._hasErrored) {
@@ -262,29 +232,30 @@ class WorkPipeline {
262
232
  break;
263
233
  }
264
234
  currentStep = currentStep(); // Execute step, get next step or null
265
- }
266
- catch (trampolineError) {
235
+ } catch (trampolineError) {
267
236
  // Catch errors propagated from step execution (processor or callback errors)
268
- if (!this._hasErrored) { // Avoid double logging
269
- _utilities__rspack_import_0.logger.error("Error during trampoline step execution:", trampolineError);
237
+ if (!this._hasErrored) {
238
+ _utilities__rspack_import_0/* .logger.error */.vF.error("Error during trampoline step execution:", trampolineError);
270
239
  this._hasErrored = true;
271
240
  }
272
241
  currentStep = null; // Stop the loop
273
- // We don't call `done` here because an error occurred.
274
- // The application should handle the uncaught exception if desired.
275
- break; // Explicitly break loop on error
242
+ // Report the failure to the caller. See the note on the same path in
243
+ // TrampolinePipeline: swallowing the error here left every caller
244
+ // awaiting `done` hanging instead of receiving a failure.
245
+ isRunning = false;
246
+ done(_results__rspack_import_1/* .Result.error */.Q.error(trampolineError));
247
+ return;
276
248
  }
277
249
  }
278
250
  // Loop ends when currentStep is null or loop is broken by error
279
251
  isRunning = false;
280
- // Completion check is now handled by finalStepSentinel ensuring `done` isn't called on error.
252
+ // Completion check is now handled by finalStepSentinel ensuring `done` isn't called on error.
281
253
  };
282
254
  // --- Start the process ---
283
255
  index = 0; // Reset index
284
256
  trampoline(createStepRevised(0)); // Start with the revised step creator
285
- }
286
- catch (error) {
287
- done(_results__rspack_import_1.Result.error(error));
257
+ } catch (error) {
258
+ done(_results__rspack_import_1/* .Result.error */.Q.error(error));
288
259
  }
289
260
  }
290
261
  pipe(work) {
@@ -294,11 +265,9 @@ class WorkPipeline {
294
265
 
295
266
 
296
267
  },
297
- "./src/results/Result.ts"(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
298
- __webpack_require__.r(__webpack_exports__);
268
+ 718(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
299
269
  __webpack_require__.d(__webpack_exports__, {
300
- PluginEventResult: () => (PluginEventResult),
301
- Result: () => (Result)
270
+ Q: () => (Result)
302
271
  });
303
272
  class BaseResult {
304
273
  static ERROR = "error";
@@ -345,7 +314,7 @@ class Result extends BaseResult {
345
314
  };
346
315
  }
347
316
  }
348
- class PluginEventResult extends BaseResult {
317
+ class PluginEventResult extends (/* unused pure expression or super */ null && (BaseResult)) {
349
318
  static success(id, data) {
350
319
  return {
351
320
  id,
@@ -377,54 +346,130 @@ class PluginEventResult extends BaseResult {
377
346
 
378
347
 
379
348
  },
380
- "./src/utilities/logger.ts"(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
381
- __webpack_require__.r(__webpack_exports__);
349
+ 581(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
382
350
  __webpack_require__.d(__webpack_exports__, {
383
- logger: () => (logger)
351
+ vF: () => (logger)
384
352
  });
385
353
  /**
386
- * Enable logging by setting `globalThis.__ROUTIER_DEBUG__ = true` before any routier code runs.
387
- */
388
- const shouldLog = () => {
354
+ * Levelled logging, resolved once.
355
+ *
356
+ * Three things about the previous implementation drove this shape:
357
+ *
358
+ * - **There was no way to turn logging off.** `globalThis.__ROUTIER_DEBUG__` was only ever
359
+ * compared against `true`, so setting it to `false` did nothing — while
360
+ * `docs/how-to/debug-logging.md` documented exactly that as the way to force logging off.
361
+ * A documented switch that silently does nothing is worse than no switch.
362
+ * - **`NODE_ENV === 'test'` enabled it.** Every Jest run therefore logged, because Jest always
363
+ * sets `NODE_ENV=test`. Measured on the S7 stress scenario, which drives ~2,000 saves through
364
+ * a plugin that logs three lines per query: 12.4s with logging, ~6s without. Test runners also
365
+ * capture console output by snapshotting a stack trace per call, so the cost is far above what
366
+ * writing to a terminal would suggest — and the output buries whatever the failure was.
367
+ * - **It was all-or-nothing, and re-resolved per call.** An error could not be kept while debug
368
+ * was dropped, and every one of the ~97 call sites re-read `globalThis` and `process.env`.
369
+ *
370
+ * Levels are compared numerically against a value cached at module load. Measured against a
371
+ * no-op console at 200k calls: an enabled call costs ~70ns, a call rejected by the gate ~3ns.
372
+ * Building the arguments the call site passes in accounts for ~0.2ns of that 3ns, which is why
373
+ * this keeps the ordinary `logger.debug(msg, payload)` signature instead of taking a thunk —
374
+ * a lazy API would recover 0.3% of an enabled call's cost and would have to change every call
375
+ * site to do it.
376
+ */ /** Ordered from most severe to most verbose. `silent` discards everything. */ const LOG_LEVELS = [
377
+ 'silent',
378
+ 'error',
379
+ 'warn',
380
+ 'info',
381
+ 'debug'
382
+ ];
383
+ /** Numeric rank, so a gate is one integer comparison. */ const RANK = {
384
+ silent: 0,
385
+ error: 1,
386
+ warn: 2,
387
+ info: 3,
388
+ debug: 4
389
+ };
390
+ const isLogLevel = (value)=>typeof value === 'string' && LOG_LEVELS.includes(value);
391
+ /**
392
+ * Resolves the configured level, in precedence order.
393
+ *
394
+ * Ordered most specific first: an explicit level beats a boolean flag, a boolean flag beats an
395
+ * environment variable, and an environment variable beats an inference from `NODE_ENV`. Anything
396
+ * unrecognised is ignored rather than treated as an error — a typo'd level should not take down
397
+ * an application, and `silent` is the safe direction to fall back to.
398
+ */ const resolveLevel = ()=>{
389
399
  if (typeof globalThis !== 'undefined') {
390
400
  const g = globalThis;
391
- if (g.__ROUTIER_DEBUG__ === true)
392
- return true;
401
+ if (isLogLevel(g.__ROUTIER_LOG_LEVEL__)) {
402
+ return g.__ROUTIER_LOG_LEVEL__;
403
+ }
404
+ // Both directions honoured. `=== false` used to fall through to the NODE_ENV checks
405
+ // below and re-enable the logging it was asked to suppress.
406
+ if (g.__ROUTIER_DEBUG__ === true) return 'debug';
407
+ if (g.__ROUTIER_DEBUG__ === false) return 'silent';
393
408
  }
409
+ // There is deliberately no `import.meta.env` branch, although the documentation used to
410
+ // promise one. It could never work: this package is bundled with rspack, which replaces
411
+ // `import.meta` with `undefined`, so the check would read the *library's* build-time
412
+ // environment rather than the application's — and referencing `import.meta` at all is a parse
413
+ // error under a CommonJS build target, which is how the test suite loads this file. Vite and
414
+ // similar apps set `__ROUTIER_LOG_LEVEL__` or `__ROUTIER_DEBUG__` from their own
415
+ // `import.meta.env`, which is what the docs now describe.
394
416
  if (typeof process !== 'undefined' && process.env != null) {
417
+ if (isLogLevel(process.env.ROUTIER_LOG_LEVEL)) {
418
+ return process.env.ROUTIER_LOG_LEVEL;
419
+ }
395
420
  const debug = process.env.DEBUG;
396
- if (debug === 'routier' || debug === '*')
397
- return true;
398
- const env = "development"?.toLowerCase();
399
- if (env === 'dev' || env === 'development' || env === 'test')
400
- return true;
421
+ if (debug === 'routier' || debug === '*') return 'debug';
422
+ const env = "production"?.toLowerCase();
423
+ // `test` is deliberately absent. It used to be here, which meant no test suite anywhere
424
+ // could run Routier quietly. Opt in with DEBUG=routier or ROUTIER_LOG_LEVEL when a test
425
+ // needs the output.
426
+ if (env === 'dev' || env === 'development') return 'debug';
401
427
  }
402
- return false;
428
+ return 'silent';
429
+ };
430
+ let level = resolveLevel();
431
+ let rank = RANK[level];
432
+ /**
433
+ * Overrides the level for the rest of the process.
434
+ *
435
+ * The configuration above is read once, at import, which is what makes the gate cheap — but it
436
+ * also means an application that decides its verbosity after startup, or a test that wants to
437
+ * assert on output, has no way in. This is that way in.
438
+ */ const setLogLevel = (next)=>{
439
+ if (isLogLevel(next) === false) {
440
+ throw new Error(`Unknown log level "${next}". Expected one of: ${LOG_LEVELS.join(', ')}`);
441
+ }
442
+ level = next;
443
+ rank = RANK[next];
444
+ };
445
+ const getLogLevel = ()=>level;
446
+ /** Re-reads the environment. For tests that change it after this module was imported. */ const resetLogLevel = ()=>{
447
+ level = resolveLevel();
448
+ rank = RANK[level];
403
449
  };
404
- const tryLog = (type, ...args) => {
405
- if (shouldLog()) {
406
- console[type](...args);
450
+ /**
451
+ * Whether a message at this level would be emitted.
452
+ *
453
+ * For the rare call site whose *arguments* are expensive to build — a serialization, a deep
454
+ * clone, a join over a large collection. An ordinary payload object is not worth guarding; see
455
+ * the measurement in the header.
456
+ */ const isLogLevelEnabled = (at)=>rank >= RANK[at];
457
+ const emit = (at, method, args)=>{
458
+ if (rank < RANK[at]) {
459
+ return;
407
460
  }
461
+ // Resolved at call time rather than captured once: test harnesses and browser devtools both
462
+ // replace console methods after modules have loaded, and a captured reference would keep
463
+ // writing past the replacement.
464
+ console[method](...args);
408
465
  };
409
466
  const logger = {
410
- log: (...args) => {
411
- tryLog("log", ...args);
412
- },
413
- info: (...args) => {
414
- tryLog("info", ...args);
415
- },
416
- warn: (...args) => {
417
- tryLog("warn", ...args);
418
- },
419
- error: (...args) => {
420
- tryLog("error", ...args);
421
- },
422
- debug: (...args) => {
423
- tryLog("debug", ...args);
424
- },
425
- table: (...args) => {
426
- tryLog("table", ...args);
427
- },
467
+ /** General-purpose output. Carried at `info`, since `log` names a console method, not a level. */ log: (...args)=>emit('info', 'log', args),
468
+ info: (...args)=>emit('info', 'info', args),
469
+ warn: (...args)=>emit('warn', 'warn', args),
470
+ error: (...args)=>emit('error', 'error', args),
471
+ debug: (...args)=>emit('debug', 'debug', args),
472
+ /** Diagnostic tabular output; verbose by nature, so it sits at `debug`. */ table: (...args)=>emit('debug', 'table', args)
428
473
  };
429
474
 
430
475
 
@@ -468,35 +513,52 @@ __webpack_require__.d = (exports, definition) => {
468
513
  (() => {
469
514
  __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
470
515
  })();
471
- // webpack/runtime/make_namespace_object
472
- (() => {
473
- // define __esModule on exports
474
- __webpack_require__.r = (exports) => {
475
- if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
476
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
477
- }
478
- Object.defineProperty(exports, '__esModule', { value: true });
479
- };
480
- })();
481
516
  var __webpack_exports__ = {};
482
517
  // This entry needs to be wrapped in an IIFE because it needs to be isolated against other modules in the chunk.
483
518
  (() => {
484
- __webpack_require__.r(__webpack_exports__);
519
+
520
+ // EXPORTS
485
521
  __webpack_require__.d(__webpack_exports__, {
486
- SyncronousQueue: () => (/* reexport safe */ _SyncronousQueue__rspack_import_0.SyncronousQueue),
487
- TrampolinePipeline: () => (/* reexport safe */ _TrampolinePipeline__rspack_import_1.TrampolinePipeline),
488
- WorkPipeline: () => (/* reexport safe */ _TrampolinePipeline__rspack_import_1.WorkPipeline)
522
+ kX: () => (/* reexport */ TrampolinePipeline/* .TrampolinePipeline */.k),
523
+ hq: () => (/* reexport */ SyncronousQueue),
524
+ UQ: () => (/* reexport */ TrampolinePipeline/* .WorkPipeline */.U)
489
525
  });
490
- /* import */ var _SyncronousQueue__rspack_import_0 = __webpack_require__("./src/pipeline/SyncronousQueue.ts");
491
- /* import */ var _TrampolinePipeline__rspack_import_1 = __webpack_require__("./src/pipeline/TrampolinePipeline.ts");
526
+
527
+ ;// CONCATENATED MODULE: ./src/pipeline/SyncronousQueue.ts
528
+ class SyncronousQueue {
529
+ _queue = [];
530
+ _current = null;
531
+ enqueue(unitOfWork) {
532
+ this._queue.push(unitOfWork);
533
+ this._next();
534
+ }
535
+ _next() {
536
+ if (this._current != null || this._queue.length === 0) {
537
+ return;
538
+ }
539
+ // Take first item
540
+ this._current = this._queue.shift() ?? null;
541
+ if (this._current == null) {
542
+ return;
543
+ }
544
+ this._current(()=>{
545
+ this._current = null;
546
+ this._next();
547
+ });
548
+ }
549
+ }
550
+
551
+ // EXTERNAL MODULE: ./src/pipeline/TrampolinePipeline.ts
552
+ var TrampolinePipeline = __webpack_require__(416);
553
+ ;// CONCATENATED MODULE: ./src/pipeline/index.ts
492
554
 
493
555
 
494
556
 
495
557
  })();
496
558
 
497
- var __webpack_exports__SyncronousQueue = __webpack_exports__.SyncronousQueue;
498
- var __webpack_exports__TrampolinePipeline = __webpack_exports__.TrampolinePipeline;
499
- var __webpack_exports__WorkPipeline = __webpack_exports__.WorkPipeline;
559
+ var __webpack_exports__SyncronousQueue = __webpack_exports__.hq;
560
+ var __webpack_exports__TrampolinePipeline = __webpack_exports__.kX;
561
+ var __webpack_exports__WorkPipeline = __webpack_exports__.UQ;
500
562
  export { __webpack_exports__SyncronousQueue as SyncronousQueue, __webpack_exports__TrampolinePipeline as TrampolinePipeline, __webpack_exports__WorkPipeline as WorkPipeline };
501
563
 
502
564
  //# sourceMappingURL=index.js.map