@routier/core 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (174) hide show
  1. package/LICENSE +21 -0
  2. package/{readme.md → README.md} +2 -2
  3. package/dist/assertions/index.cjs +191 -0
  4. package/dist/assertions/index.cjs.map +1 -0
  5. package/dist/assertions/index.d.ts +30 -0
  6. package/dist/assertions/index.js +94 -30
  7. package/dist/assertions/index.js.map +1 -1
  8. package/dist/capabilities/index.cjs +820 -0
  9. package/dist/capabilities/index.cjs.map +1 -0
  10. package/dist/capabilities/index.js +580 -545
  11. package/dist/capabilities/index.js.map +1 -1
  12. package/dist/codegen/handlers/CloneHandlerBuilder.d.ts +10 -1
  13. package/dist/codegen/handlers/SetHandlerBuilder.d.ts +4 -0
  14. package/dist/codegen/handlers/clone/CloneArrayHandler.d.ts +3 -0
  15. package/dist/codegen/handlers/clone/CloneDateHandler.d.ts +13 -0
  16. package/dist/codegen/handlers/clone/CloneValueHandler.d.ts +16 -0
  17. package/dist/codegen/handlers/compare/CompareComputedHandler.d.ts +10 -0
  18. package/dist/codegen/handlers/compare/CompareFunctionHandler.d.ts +10 -0
  19. package/dist/codegen/handlers/deserialize/DeserializeArrayHandler.d.ts +14 -0
  20. package/dist/codegen/handlers/enableChangeTracking/EnableChangeTrackingArrayHandler.d.ts +11 -0
  21. package/dist/codegen/handlers/enrichment/EnrichmentArrayHandler.d.ts +11 -0
  22. package/dist/codegen/handlers/freeze/FreezeArrayHandler.d.ts +6 -0
  23. package/dist/codegen/handlers/hash/HashArrayHandler.d.ts +10 -0
  24. package/dist/codegen/handlers/hash/HashFileHandler.d.ts +24 -0
  25. package/dist/codegen/handlers/hash/HashObjectHandler.d.ts +10 -0
  26. package/dist/codegen/handlers/hash/HashTransformHandler.d.ts +23 -0
  27. package/dist/codegen/handlers/index.d.ts +1 -0
  28. package/dist/codegen/handlers/merge/MergeArrayHandler.d.ts +20 -0
  29. package/dist/codegen/handlers/merge/MergeObjectHandler.d.ts +10 -0
  30. package/dist/codegen/handlers/serialize/SerializeArrayHandler.d.ts +19 -0
  31. package/dist/codegen/handlers/serialize/SerializeComputedHandler.d.ts +6 -0
  32. package/dist/codegen/handlers/set/SetComplexHandler.d.ts +6 -0
  33. package/dist/codegen/handlers/strip/StripComputedHandler.d.ts +10 -0
  34. package/dist/codegen/handlers/strip/StripFunctionHandler.d.ts +9 -0
  35. package/dist/codegen/handlers/types.d.ts +55 -1
  36. package/dist/codegen/index.cjs +618 -0
  37. package/dist/codegen/index.cjs.map +1 -0
  38. package/dist/codegen/index.js +100 -127
  39. package/dist/codegen/index.js.map +1 -1
  40. package/dist/collections/Changes.d.ts +2 -2
  41. package/dist/collections/MemoryDataCollection.d.ts +15 -1
  42. package/dist/collections/TagCollection.d.ts +7 -8
  43. package/dist/collections/index.cjs +702 -0
  44. package/dist/collections/index.cjs.map +1 -0
  45. package/dist/collections/index.js +282 -276
  46. package/dist/collections/index.js.map +1 -1
  47. package/dist/errors/OptimisticConcurrencyError.d.ts +18 -0
  48. package/dist/errors/PluginDestroyedError.d.ts +10 -0
  49. package/dist/errors/index.cjs +132 -0
  50. package/dist/errors/index.cjs.map +1 -0
  51. package/dist/errors/index.d.ts +2 -0
  52. package/dist/errors/index.js +61 -19
  53. package/dist/errors/index.js.map +1 -1
  54. package/dist/expressions/constants.d.ts +2 -0
  55. package/dist/expressions/evaluate.d.ts +53 -0
  56. package/dist/expressions/index.cjs +2087 -0
  57. package/dist/expressions/index.cjs.map +1 -0
  58. package/dist/expressions/index.d.ts +2 -0
  59. package/dist/expressions/index.js +1784 -772
  60. package/dist/expressions/index.js.map +1 -1
  61. package/dist/expressions/parser.d.ts +19 -0
  62. package/dist/expressions/types.d.ts +87 -2
  63. package/dist/expressions/utils.d.ts +1 -2
  64. package/dist/index.cjs +13925 -0
  65. package/dist/index.cjs.map +1 -0
  66. package/dist/index.js +12094 -7049
  67. package/dist/index.js.map +1 -1
  68. package/dist/performance/index.cjs +217 -0
  69. package/dist/performance/index.cjs.map +1 -0
  70. package/dist/performance/index.js +126 -50
  71. package/dist/performance/index.js.map +1 -1
  72. package/dist/pipeline/index.cjs +576 -0
  73. package/dist/pipeline/index.cjs.map +1 -0
  74. package/dist/pipeline/index.js +229 -156
  75. package/dist/pipeline/index.js.map +1 -1
  76. package/dist/plugins/BatchingDbPlugin.d.ts +139 -0
  77. package/dist/plugins/CacheDbPlugin.d.ts +70 -0
  78. package/dist/plugins/ConcurrencyDbPlugin.d.ts +78 -0
  79. package/dist/plugins/EphemeralDataPlugin.d.ts +57 -1
  80. package/dist/plugins/RetryDbPlugin.d.ts +77 -0
  81. package/dist/plugins/index.cjs +6104 -0
  82. package/dist/plugins/index.cjs.map +1 -0
  83. package/dist/plugins/index.d.ts +5 -1
  84. package/dist/plugins/index.js +5572 -1491
  85. package/dist/plugins/index.js.map +1 -1
  86. package/dist/plugins/query/QueryOptionsCollection.d.ts +22 -0
  87. package/dist/plugins/query/index.d.ts +2 -0
  88. package/dist/plugins/query/join.d.ts +210 -0
  89. package/dist/plugins/query/similarity.d.ts +38 -0
  90. package/dist/plugins/query/types.d.ts +64 -1
  91. package/dist/plugins/translators/DataTranslator.d.ts +28 -0
  92. package/dist/plugins/translators/JsonTranslator.d.ts +27 -0
  93. package/dist/plugins/translators/SqlTranslator.d.ts +45 -0
  94. package/dist/plugins/translators/TranslatedArrayValue.d.ts +3 -1
  95. package/dist/plugins/translators/TranslatedGroupValue.d.ts +3 -1
  96. package/dist/plugins/translators/TranslatedSingleValue.d.ts +3 -1
  97. package/dist/plugins/translators/TupleTranslator.d.ts +45 -0
  98. package/dist/plugins/translators/index.d.ts +1 -0
  99. package/dist/plugins/translators/types.d.ts +8 -1
  100. package/dist/plugins/types.d.ts +87 -11
  101. package/dist/plugins/wire/handler.d.ts +122 -0
  102. package/dist/plugins/wire/index.d.ts +4 -0
  103. package/dist/plugins/wire/persist.d.ts +43 -0
  104. package/dist/plugins/wire/query.d.ts +49 -0
  105. package/dist/plugins/wire/types.d.ts +123 -0
  106. package/dist/results/Result.d.ts +2 -2
  107. package/dist/results/index.cjs +174 -0
  108. package/dist/results/index.cjs.map +1 -0
  109. package/dist/results/index.js +29 -44
  110. package/dist/results/index.js.map +1 -1
  111. package/dist/schema/PropertyInfo.d.ts +35 -2
  112. package/dist/schema/SchemaDefinition.d.ts +51 -1
  113. package/dist/schema/builder.d.ts +35 -1
  114. package/dist/schema/communication/broadcast.d.ts +17 -1
  115. package/dist/schema/index.cjs +6911 -0
  116. package/dist/schema/index.cjs.map +1 -0
  117. package/dist/schema/index.d.ts +4 -0
  118. package/dist/schema/index.js +5781 -3973
  119. package/dist/schema/index.js.map +1 -1
  120. package/dist/schema/property/base/SchemaBase.d.ts +50 -2
  121. package/dist/schema/property/modifiers/SchemaDeserialize.d.ts +5 -1
  122. package/dist/schema/property/modifiers/SchemaForeignKey.d.ts +15 -0
  123. package/dist/schema/property/modifiers/SchemaKey.d.ts +2 -0
  124. package/dist/schema/property/modifiers/SchemaNullable.d.ts +15 -1
  125. package/dist/schema/property/modifiers/SchemaOptional.d.ts +22 -1
  126. package/dist/schema/property/modifiers/SchemaSearchable.d.ts +34 -0
  127. package/dist/schema/property/modifiers/SchemaTag.d.ts +27 -0
  128. package/dist/schema/property/modifiers/SchemaTracked.d.ts +5 -1
  129. package/dist/schema/property/modifiers/index.d.ts +3 -0
  130. package/dist/schema/property/types/SchemaArray.d.ts +2 -0
  131. package/dist/schema/property/types/SchemaBoolean.d.ts +2 -0
  132. package/dist/schema/property/types/SchemaDate.d.ts +2 -0
  133. package/dist/schema/property/types/SchemaFile.d.ts +60 -0
  134. package/dist/schema/property/types/SchemaNumber.d.ts +5 -1
  135. package/dist/schema/property/types/SchemaObject.d.ts +2 -0
  136. package/dist/schema/property/types/SchemaString.d.ts +25 -1
  137. package/dist/schema/property/types/SchemaVector.d.ts +61 -0
  138. package/dist/schema/property/types/index.d.ts +2 -0
  139. package/dist/schema/table/SchemaTransform.d.ts +40 -0
  140. package/dist/schema/table/index.d.ts +1 -0
  141. package/dist/schema/types.d.ts +200 -32
  142. package/dist/schema/utils/propertyKind.d.ts +4 -0
  143. package/dist/schema/utils/standardJsonSchema.d.ts +90 -0
  144. package/dist/types/index.cjs +23 -0
  145. package/dist/types/index.cjs.map +1 -0
  146. package/dist/types/index.js +0 -14
  147. package/dist/types/index.js.map +1 -1
  148. package/dist/utilities/functions.d.ts +1 -1
  149. package/dist/utilities/index.cjs +982 -0
  150. package/dist/utilities/index.cjs.map +1 -0
  151. package/dist/utilities/index.js +590 -321
  152. package/dist/utilities/index.js.map +1 -1
  153. package/dist/utilities/logger.d.ts +48 -0
  154. package/package.json +152 -98
  155. package/dist/collections/Changes.test.d.ts +0 -1
  156. package/dist/collections/MemoryDataCollection.test.d.ts +0 -1
  157. package/dist/collections/TagCollection.test.d.ts +0 -1
  158. package/dist/expressions/parser.test.d.ts +0 -1
  159. package/dist/expressions/utils.test.d.ts +0 -1
  160. package/dist/pipeline/SyncronousQueue.test.d.ts +0 -1
  161. package/dist/pipeline/WorkPipeline.test.d.ts +0 -1
  162. package/dist/plugins/EphemeralDataPlugin.test.d.ts +0 -1
  163. package/dist/plugins/query/QueryOptionsCollection.test.d.ts +0 -1
  164. package/dist/plugins/replication/OptimisticReplicationDbPlugin.d.ts +0 -23
  165. package/dist/plugins/replication/ReplicationDbPlugin.d.ts +0 -22
  166. package/dist/plugins/replication/index.d.ts +0 -3
  167. package/dist/plugins/replication/types.d.ts +0 -5
  168. package/dist/plugins/translators/JsonTranslator.test.d.ts +0 -1
  169. package/dist/schema/PropertyInfo.test.d.ts +0 -1
  170. package/dist/schema/schemaGeneration.test.d.ts +0 -1
  171. package/dist/schema/testSchemas.test.d.ts +0 -314
  172. package/dist/utilities/arrays.test.d.ts +0 -1
  173. package/dist/utilities/dates.test.d.ts +0 -1
  174. package/dist/utilities/strings.test.d.ts +0 -1
@@ -0,0 +1,217 @@
1
+ (() => {
2
+ "use strict";
3
+ var __webpack_modules__ = ({
4
+ 581(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
5
+ __webpack_require__.d(__webpack_exports__, {
6
+ vF: () => (logger)
7
+ });
8
+ /**
9
+ * Levelled logging, resolved once.
10
+ *
11
+ * Three things about the previous implementation drove this shape:
12
+ *
13
+ * - **There was no way to turn logging off.** `globalThis.__ROUTIER_DEBUG__` was only ever
14
+ * compared against `true`, so setting it to `false` did nothing — while
15
+ * `docs/how-to/debug-logging.md` documented exactly that as the way to force logging off.
16
+ * A documented switch that silently does nothing is worse than no switch.
17
+ * - **`NODE_ENV === 'test'` enabled it.** Every Jest run therefore logged, because Jest always
18
+ * sets `NODE_ENV=test`. Measured on the S7 stress scenario, which drives ~2,000 saves through
19
+ * a plugin that logs three lines per query: 12.4s with logging, ~6s without. Test runners also
20
+ * capture console output by snapshotting a stack trace per call, so the cost is far above what
21
+ * writing to a terminal would suggest — and the output buries whatever the failure was.
22
+ * - **It was all-or-nothing, and re-resolved per call.** An error could not be kept while debug
23
+ * was dropped, and every one of the ~97 call sites re-read `globalThis` and `process.env`.
24
+ *
25
+ * Levels are compared numerically against a value cached at module load. Measured against a
26
+ * no-op console at 200k calls: an enabled call costs ~70ns, a call rejected by the gate ~3ns.
27
+ * Building the arguments the call site passes in accounts for ~0.2ns of that 3ns, which is why
28
+ * this keeps the ordinary `logger.debug(msg, payload)` signature instead of taking a thunk —
29
+ * a lazy API would recover 0.3% of an enabled call's cost and would have to change every call
30
+ * site to do it.
31
+ */ /** Ordered from most severe to most verbose. `silent` discards everything. */ const LOG_LEVELS = [
32
+ 'silent',
33
+ 'error',
34
+ 'warn',
35
+ 'info',
36
+ 'debug'
37
+ ];
38
+ /** Numeric rank, so a gate is one integer comparison. */ const RANK = {
39
+ silent: 0,
40
+ error: 1,
41
+ warn: 2,
42
+ info: 3,
43
+ debug: 4
44
+ };
45
+ const isLogLevel = (value)=>typeof value === 'string' && LOG_LEVELS.includes(value);
46
+ /**
47
+ * Resolves the configured level, in precedence order.
48
+ *
49
+ * Ordered most specific first: an explicit level beats a boolean flag, a boolean flag beats an
50
+ * environment variable, and an environment variable beats an inference from `NODE_ENV`. Anything
51
+ * unrecognised is ignored rather than treated as an error — a typo'd level should not take down
52
+ * an application, and `silent` is the safe direction to fall back to.
53
+ */ const resolveLevel = ()=>{
54
+ if (typeof globalThis !== 'undefined') {
55
+ const g = globalThis;
56
+ if (isLogLevel(g.__ROUTIER_LOG_LEVEL__)) {
57
+ return g.__ROUTIER_LOG_LEVEL__;
58
+ }
59
+ // Both directions honoured. `=== false` used to fall through to the NODE_ENV checks
60
+ // below and re-enable the logging it was asked to suppress.
61
+ if (g.__ROUTIER_DEBUG__ === true) return 'debug';
62
+ if (g.__ROUTIER_DEBUG__ === false) return 'silent';
63
+ }
64
+ // There is deliberately no `import.meta.env` branch, although the documentation used to
65
+ // promise one. It could never work: this package is bundled with rspack, which replaces
66
+ // `import.meta` with `undefined`, so the check would read the *library's* build-time
67
+ // environment rather than the application's — and referencing `import.meta` at all is a parse
68
+ // error under a CommonJS build target, which is how the test suite loads this file. Vite and
69
+ // similar apps set `__ROUTIER_LOG_LEVEL__` or `__ROUTIER_DEBUG__` from their own
70
+ // `import.meta.env`, which is what the docs now describe.
71
+ if (typeof process !== 'undefined' && process.env != null) {
72
+ if (isLogLevel(process.env.ROUTIER_LOG_LEVEL)) {
73
+ return process.env.ROUTIER_LOG_LEVEL;
74
+ }
75
+ const debug = process.env.DEBUG;
76
+ if (debug === 'routier' || debug === '*') return 'debug';
77
+ const env = "production"?.toLowerCase();
78
+ // `test` is deliberately absent. It used to be here, which meant no test suite anywhere
79
+ // could run Routier quietly. Opt in with DEBUG=routier or ROUTIER_LOG_LEVEL when a test
80
+ // needs the output.
81
+ if (env === 'dev' || env === 'development') return 'debug';
82
+ }
83
+ return 'silent';
84
+ };
85
+ let level = resolveLevel();
86
+ let rank = RANK[level];
87
+ /**
88
+ * Overrides the level for the rest of the process.
89
+ *
90
+ * The configuration above is read once, at import, which is what makes the gate cheap — but it
91
+ * also means an application that decides its verbosity after startup, or a test that wants to
92
+ * assert on output, has no way in. This is that way in.
93
+ */ const setLogLevel = (next)=>{
94
+ if (isLogLevel(next) === false) {
95
+ throw new Error(`Unknown log level "${next}". Expected one of: ${LOG_LEVELS.join(', ')}`);
96
+ }
97
+ level = next;
98
+ rank = RANK[next];
99
+ };
100
+ const getLogLevel = ()=>level;
101
+ /** Re-reads the environment. For tests that change it after this module was imported. */ const resetLogLevel = ()=>{
102
+ level = resolveLevel();
103
+ rank = RANK[level];
104
+ };
105
+ /**
106
+ * Whether a message at this level would be emitted.
107
+ *
108
+ * For the rare call site whose *arguments* are expensive to build — a serialization, a deep
109
+ * clone, a join over a large collection. An ordinary payload object is not worth guarding; see
110
+ * the measurement in the header.
111
+ */ const isLogLevelEnabled = (at)=>rank >= RANK[at];
112
+ const emit = (at, method, args)=>{
113
+ if (rank < RANK[at]) {
114
+ return;
115
+ }
116
+ // Resolved at call time rather than captured once: test harnesses and browser devtools both
117
+ // replace console methods after modules have loaded, and a captured reference would keep
118
+ // writing past the replacement.
119
+ console[method](...args);
120
+ };
121
+ const logger = {
122
+ /** General-purpose output. Carried at `info`, since `log` names a console method, not a level. */ log: (...args)=>emit('info', 'log', args),
123
+ info: (...args)=>emit('info', 'info', args),
124
+ warn: (...args)=>emit('warn', 'warn', args),
125
+ error: (...args)=>emit('error', 'error', args),
126
+ debug: (...args)=>emit('debug', 'debug', args),
127
+ /** Diagnostic tabular output; verbose by nature, so it sits at `debug`. */ table: (...args)=>emit('debug', 'table', args)
128
+ };
129
+
130
+
131
+ },
132
+
133
+ });
134
+ // The module cache
135
+ var __webpack_module_cache__ = {};
136
+
137
+ // The require function
138
+ function __webpack_require__(moduleId) {
139
+
140
+ // Check if module is in cache
141
+ var cachedModule = __webpack_module_cache__[moduleId];
142
+ if (cachedModule !== undefined) {
143
+ return cachedModule.exports;
144
+ }
145
+ // Create a new module (and put it into the cache)
146
+ var module = (__webpack_module_cache__[moduleId] = {
147
+ exports: {}
148
+ });
149
+ // Execute the module function
150
+ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
151
+
152
+ // Return the exports of the module
153
+ return module.exports;
154
+
155
+ }
156
+
157
+ // webpack/runtime/define_property_getters
158
+ (() => {
159
+ __webpack_require__.d = (exports, definition) => {
160
+ for(var key in definition) {
161
+ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
162
+ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
163
+ }
164
+ }
165
+ };
166
+ })();
167
+ // webpack/runtime/has_own_property
168
+ (() => {
169
+ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
170
+ })();
171
+ // webpack/runtime/make_namespace_object
172
+ (() => {
173
+ // define __esModule on exports
174
+ __webpack_require__.r = (exports) => {
175
+ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
176
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
177
+ }
178
+ Object.defineProperty(exports, '__esModule', { value: true });
179
+ };
180
+ })();
181
+ var __webpack_exports__ = {};
182
+ // This entry needs to be wrapped in an IIFE because it needs to be isolated against other modules in the chunk.
183
+ (() => {
184
+ __webpack_require__.r(__webpack_exports__);
185
+ __webpack_require__.d(__webpack_exports__, {
186
+ measure: () => (measure),
187
+ now: () => (now)
188
+ });
189
+ /* import */ var _utilities__rspack_import_0 = __webpack_require__(581);
190
+
191
+ const measurements = {};
192
+ const now = ()=>{
193
+ if (typeof performance !== 'undefined' && performance.now) {
194
+ // Browser or modern Node.js
195
+ return performance.now();
196
+ }
197
+ // Fallback for older environments
198
+ return Date.now();
199
+ };
200
+ const measure = {
201
+ start: (name)=>{
202
+ measurements[name] = now();
203
+ },
204
+ end: (name)=>{
205
+ const start = measurements[name];
206
+ delete measurements[name];
207
+ const delta = now() - start;
208
+ _utilities__rspack_import_0/* .logger.log */.vF.log(`[ROUTIER] - Performance: ${name} took ${delta}`);
209
+ }
210
+ };
211
+
212
+ })();
213
+
214
+ module.exports = __webpack_exports__;
215
+ })()
216
+ ;
217
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"performance/index.cjs","sources":["webpack://@routier/core/./src/utilities/logger.ts","webpack://@routier/core/webpack/runtime/define_property_getters","webpack://@routier/core/webpack/runtime/has_own_property","webpack://@routier/core/webpack/runtime/make_namespace_object","webpack://@routier/core/./src/performance/index.ts"],"sourcesContent":["/**\n * Levelled logging, resolved once.\n *\n * Three things about the previous implementation drove this shape:\n *\n * - **There was no way to turn logging off.** `globalThis.__ROUTIER_DEBUG__` was only ever\n * compared against `true`, so setting it to `false` did nothing — while\n * `docs/how-to/debug-logging.md` documented exactly that as the way to force logging off.\n * A documented switch that silently does nothing is worse than no switch.\n * - **`NODE_ENV === 'test'` enabled it.** Every Jest run therefore logged, because Jest always\n * sets `NODE_ENV=test`. Measured on the S7 stress scenario, which drives ~2,000 saves through\n * a plugin that logs three lines per query: 12.4s with logging, ~6s without. Test runners also\n * capture console output by snapshotting a stack trace per call, so the cost is far above what\n * writing to a terminal would suggest — and the output buries whatever the failure was.\n * - **It was all-or-nothing, and re-resolved per call.** An error could not be kept while debug\n * was dropped, and every one of the ~97 call sites re-read `globalThis` and `process.env`.\n *\n * Levels are compared numerically against a value cached at module load. Measured against a\n * no-op console at 200k calls: an enabled call costs ~70ns, a call rejected by the gate ~3ns.\n * Building the arguments the call site passes in accounts for ~0.2ns of that 3ns, which is why\n * this keeps the ordinary `logger.debug(msg, payload)` signature instead of taking a thunk —\n * a lazy API would recover 0.3% of an enabled call's cost and would have to change every call\n * site to do it.\n */\n\n/** Ordered from most severe to most verbose. `silent` discards everything. */\nexport const LOG_LEVELS = ['silent', 'error', 'warn', 'info', 'debug'] as const;\n\nexport type LogLevel = (typeof LOG_LEVELS)[number];\n\n/** Numeric rank, so a gate is one integer comparison. */\nconst RANK: Record<LogLevel, number> = {\n silent: 0,\n error: 1,\n warn: 2,\n info: 3,\n debug: 4,\n};\n\nconst isLogLevel = (value: unknown): value is LogLevel =>\n typeof value === 'string' && (LOG_LEVELS as readonly string[]).includes(value);\n\n/**\n * Resolves the configured level, in precedence order.\n *\n * Ordered most specific first: an explicit level beats a boolean flag, a boolean flag beats an\n * environment variable, and an environment variable beats an inference from `NODE_ENV`. Anything\n * unrecognised is ignored rather than treated as an error — a typo'd level should not take down\n * an application, and `silent` is the safe direction to fall back to.\n */\nconst resolveLevel = (): LogLevel => {\n if (typeof globalThis !== 'undefined') {\n const g = globalThis as { __ROUTIER_LOG_LEVEL__?: unknown; __ROUTIER_DEBUG__?: unknown };\n\n if (isLogLevel(g.__ROUTIER_LOG_LEVEL__)) {\n return g.__ROUTIER_LOG_LEVEL__;\n }\n\n // Both directions honoured. `=== false` used to fall through to the NODE_ENV checks\n // below and re-enable the logging it was asked to suppress.\n if (g.__ROUTIER_DEBUG__ === true) return 'debug';\n if (g.__ROUTIER_DEBUG__ === false) return 'silent';\n }\n\n // There is deliberately no `import.meta.env` branch, although the documentation used to\n // promise one. It could never work: this package is bundled with rspack, which replaces\n // `import.meta` with `undefined`, so the check would read the *library's* build-time\n // environment rather than the application's — and referencing `import.meta` at all is a parse\n // error under a CommonJS build target, which is how the test suite loads this file. Vite and\n // similar apps set `__ROUTIER_LOG_LEVEL__` or `__ROUTIER_DEBUG__` from their own\n // `import.meta.env`, which is what the docs now describe.\n if (typeof process !== 'undefined' && process.env != null) {\n if (isLogLevel(process.env.ROUTIER_LOG_LEVEL)) {\n return process.env.ROUTIER_LOG_LEVEL as LogLevel;\n }\n\n const debug = process.env.DEBUG;\n if (debug === 'routier' || debug === '*') return 'debug';\n\n const env = process.env.NODE_ENV?.toLowerCase();\n\n // `test` is deliberately absent. It used to be here, which meant no test suite anywhere\n // could run Routier quietly. Opt in with DEBUG=routier or ROUTIER_LOG_LEVEL when a test\n // needs the output.\n if (env === 'dev' || env === 'development') return 'debug';\n }\n\n return 'silent';\n};\n\nlet level: LogLevel = resolveLevel();\nlet rank = RANK[level];\n\n/**\n * Overrides the level for the rest of the process.\n *\n * The configuration above is read once, at import, which is what makes the gate cheap — but it\n * also means an application that decides its verbosity after startup, or a test that wants to\n * assert on output, has no way in. This is that way in.\n */\nexport const setLogLevel = (next: LogLevel): void => {\n if (isLogLevel(next) === false) {\n throw new Error(`Unknown log level \"${next}\". Expected one of: ${LOG_LEVELS.join(', ')}`);\n }\n\n level = next;\n rank = RANK[next];\n};\n\nexport const getLogLevel = (): LogLevel => level;\n\n/** Re-reads the environment. For tests that change it after this module was imported. */\nexport const resetLogLevel = (): void => {\n level = resolveLevel();\n rank = RANK[level];\n};\n\n/**\n * Whether a message at this level would be emitted.\n *\n * For the rare call site whose *arguments* are expensive to build — a serialization, a deep\n * clone, a join over a large collection. An ordinary payload object is not worth guarding; see\n * the measurement in the header.\n */\nexport const isLogLevelEnabled = (at: LogLevel): boolean => rank >= RANK[at];\n\ntype ConsoleMethod = 'log' | 'info' | 'warn' | 'error' | 'debug' | 'table';\n\nconst emit = (at: LogLevel, method: ConsoleMethod, args: unknown[]) => {\n if (rank < RANK[at]) {\n return;\n }\n\n // Resolved at call time rather than captured once: test harnesses and browser devtools both\n // replace console methods after modules have loaded, and a captured reference would keep\n // writing past the replacement.\n (console[method] as (...a: unknown[]) => void)(...args);\n};\n\nexport const logger = {\n /** General-purpose output. Carried at `info`, since `log` names a console method, not a level. */\n log: (...args: unknown[]): void => emit('info', 'log', args),\n info: (...args: unknown[]): void => emit('info', 'info', args),\n warn: (...args: unknown[]): void => emit('warn', 'warn', args),\n error: (...args: unknown[]): void => emit('error', 'error', args),\n debug: (...args: unknown[]): void => emit('debug', 'debug', args),\n /** Diagnostic tabular output; verbose by nature, so it sits at `debug`. */\n table: (...args: unknown[]): void => emit('debug', 'table', args),\n};\n","__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n }\n }\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","import { logger } from \"../utilities\";\n\nconst measurements: Record<string, number> = {}\n\nexport const now = (): number => {\n if (typeof performance !== 'undefined' && performance.now) {\n // Browser or modern Node.js\n return performance.now();\n }\n\n // Fallback for older environments\n return Date.now();\n}\n\nexport const measure = {\n start: (name: string): void => {\n measurements[name] = now();\n },\n end: (name: string): void => {\n const start = measurements[name];\n\n delete measurements[name];\n\n const delta = now() - start;\n\n logger.log(`[ROUTIER] - Performance: ${name} took ${delta}`);\n }\n}"],"names":["LOG_LEVELS","RANK","isLogLevel","value","resolveLevel","globalThis","g","process","debug","env","level","rank","setLogLevel","next","Error","getLogLevel","resetLogLevel","isLogLevelEnabled","at","emit","method","args","console","logger","measurements","now","performance","Date","measure","name","start","delta"],"mappings":";;;;;;;AAAA;;;;;;;;;;;;;;;;;;;;;;;CAuBC,GAED,4EAA4E,GACrE,MAAMA,aAAa;IAAC;IAAU;IAAS;IAAQ;IAAQ;CAAQ,CAAU;AAIhF,uDAAuD,GACvD,MAAMC,OAAiC;IACnC,QAAQ;IACR,OAAO;IACP,MAAM;IACN,MAAM;IACN,OAAO;AACX;AAEA,MAAMC,aAAa,CAACC,QAChB,OAAOA,UAAU,YAAaH,WAAiC,QAAQ,CAACG;AAE5E;;;;;;;CAOC,GACD,MAAMC,eAAe;IACjB,IAAI,OAAOC,eAAe,aAAa;QACnC,MAAMC,IAAID;QAEV,IAAIH,WAAWI,EAAE,qBAAqB,GAAG;YACrC,OAAOA,EAAE,qBAAqB;QAClC;QAEA,oFAAoF;QACpF,4DAA4D;QAC5D,IAAIA,EAAE,iBAAiB,KAAK,MAAM,OAAO;QACzC,IAAIA,EAAE,i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,MAAME,SAAS;IAClB,gGAAgG,GAChG,KAAK,CAAC,GAAGF,OAA0BF,KAAK,QAAQ,OAAOE;IACvD,MAAM,CAAC,GAAGA,OAA0BF,KAAK,QAAQ,QAAQE;IACzD,MAAM,CAAC,GAAGA,OAA0BF,KAAK,QAAQ,QAAQE;IACzD,OAAO,CAAC,GAAGA,OAA0BF,KAAK,SAAS,SAASE;IAC5D,OAAO,CAAC,GAAGA,OAA0BF,KAAK,SAAS,SAASE;IAC5D,yEAAyE,GACzE,OAAO,CAAC,GAAGA,OAA0BF,KAAK,SAAS,SAASE;AAChE,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACpJF;AACA;AACA;AACA,kDAAkD,wCAAwC;AAC1F;AACA;AACA,E;;;;ACNA,wF;;;;ACAA;AACA;AACA;AACA,uDAAuD,iBAAiB;AACxE;AACA,gDAAgD,aAAa;AAC7D,E;;;;;;;;;;;ACNsC;AAEtC,MAAMG,eAAuC,CAAC;AAEvC,MAAMC,MAAM;IACf,IAAI,OAAOC,gBAAgB,eAAeA,YAAY,GAAG,EAAE;QACvD,4BAA4B;QAC5B,OAAOA,YAAY,GAAG;IAC1B;IAEA,kCAAkC;IAClC,OAAOC,KAAK,GAAG;AACnB,EAAC;AAEM,MAAMC,UAAU;IACnB,OAAO,CAACC;QACJL,YAAY,CAACK,KAAK,GAAGJ;IACzB;IACA,KAAK,CAACI;QACF,MAAMC,QAAQN,YAAY,CAACK,KAAK;QAEhC,OAAOL,YAAY,CAACK,KAAK;QAEzB,MAAME,QAAQN,QAAQK;QAEtBP,mDAAU,CAAC,CAAC,yBAAyB,EAAEM,KAAK,MAAM,EAAEE,OAAO;IAC/D;AACJ,EAAC"}
@@ -1,41 +1,128 @@
1
1
  var __webpack_modules__ = ({
2
- "./src/utilities/logger.ts"(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
3
- __webpack_require__.r(__webpack_exports__);
2
+ 581(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
4
3
  __webpack_require__.d(__webpack_exports__, {
5
- logger: () => (logger)
4
+ vF: () => (logger)
6
5
  });
7
- const isDevelopment = () => {
8
- if (typeof process === 'undefined' || process.env == null) {
9
- return false;
6
+ /**
7
+ * Levelled logging, resolved once.
8
+ *
9
+ * Three things about the previous implementation drove this shape:
10
+ *
11
+ * - **There was no way to turn logging off.** `globalThis.__ROUTIER_DEBUG__` was only ever
12
+ * compared against `true`, so setting it to `false` did nothing — while
13
+ * `docs/how-to/debug-logging.md` documented exactly that as the way to force logging off.
14
+ * A documented switch that silently does nothing is worse than no switch.
15
+ * - **`NODE_ENV === 'test'` enabled it.** Every Jest run therefore logged, because Jest always
16
+ * sets `NODE_ENV=test`. Measured on the S7 stress scenario, which drives ~2,000 saves through
17
+ * a plugin that logs three lines per query: 12.4s with logging, ~6s without. Test runners also
18
+ * capture console output by snapshotting a stack trace per call, so the cost is far above what
19
+ * writing to a terminal would suggest — and the output buries whatever the failure was.
20
+ * - **It was all-or-nothing, and re-resolved per call.** An error could not be kept while debug
21
+ * was dropped, and every one of the ~97 call sites re-read `globalThis` and `process.env`.
22
+ *
23
+ * Levels are compared numerically against a value cached at module load. Measured against a
24
+ * no-op console at 200k calls: an enabled call costs ~70ns, a call rejected by the gate ~3ns.
25
+ * Building the arguments the call site passes in accounts for ~0.2ns of that 3ns, which is why
26
+ * this keeps the ordinary `logger.debug(msg, payload)` signature instead of taking a thunk —
27
+ * a lazy API would recover 0.3% of an enabled call's cost and would have to change every call
28
+ * site to do it.
29
+ */ /** Ordered from most severe to most verbose. `silent` discards everything. */ const LOG_LEVELS = [
30
+ 'silent',
31
+ 'error',
32
+ 'warn',
33
+ 'info',
34
+ 'debug'
35
+ ];
36
+ /** Numeric rank, so a gate is one integer comparison. */ const RANK = {
37
+ silent: 0,
38
+ error: 1,
39
+ warn: 2,
40
+ info: 3,
41
+ debug: 4
42
+ };
43
+ const isLogLevel = (value)=>typeof value === 'string' && LOG_LEVELS.includes(value);
44
+ /**
45
+ * Resolves the configured level, in precedence order.
46
+ *
47
+ * Ordered most specific first: an explicit level beats a boolean flag, a boolean flag beats an
48
+ * environment variable, and an environment variable beats an inference from `NODE_ENV`. Anything
49
+ * unrecognised is ignored rather than treated as an error — a typo'd level should not take down
50
+ * an application, and `silent` is the safe direction to fall back to.
51
+ */ const resolveLevel = ()=>{
52
+ if (typeof globalThis !== 'undefined') {
53
+ const g = globalThis;
54
+ if (isLogLevel(g.__ROUTIER_LOG_LEVEL__)) {
55
+ return g.__ROUTIER_LOG_LEVEL__;
56
+ }
57
+ // Both directions honoured. `=== false` used to fall through to the NODE_ENV checks
58
+ // below and re-enable the logging it was asked to suppress.
59
+ if (g.__ROUTIER_DEBUG__ === true) return 'debug';
60
+ if (g.__ROUTIER_DEBUG__ === false) return 'silent';
61
+ }
62
+ // There is deliberately no `import.meta.env` branch, although the documentation used to
63
+ // promise one. It could never work: this package is bundled with rspack, which replaces
64
+ // `import.meta` with `undefined`, so the check would read the *library's* build-time
65
+ // environment rather than the application's — and referencing `import.meta` at all is a parse
66
+ // error under a CommonJS build target, which is how the test suite loads this file. Vite and
67
+ // similar apps set `__ROUTIER_LOG_LEVEL__` or `__ROUTIER_DEBUG__` from their own
68
+ // `import.meta.env`, which is what the docs now describe.
69
+ if (typeof process !== 'undefined' && process.env != null) {
70
+ if (isLogLevel(process.env.ROUTIER_LOG_LEVEL)) {
71
+ return process.env.ROUTIER_LOG_LEVEL;
72
+ }
73
+ const debug = process.env.DEBUG;
74
+ if (debug === 'routier' || debug === '*') return 'debug';
75
+ const env = "production"?.toLowerCase();
76
+ // `test` is deliberately absent. It used to be here, which meant no test suite anywhere
77
+ // could run Routier quietly. Opt in with DEBUG=routier or ROUTIER_LOG_LEVEL when a test
78
+ // needs the output.
79
+ if (env === 'dev' || env === 'development') return 'debug';
10
80
  }
11
- const env = "development"?.toLowerCase();
12
- return env === 'dev' || env === 'development' || env === 'test';
81
+ return 'silent';
13
82
  };
14
- const shouldLog = isDevelopment();
15
- const tryLog = (type, ...args) => {
16
- if (shouldLog) {
17
- console[type](...args);
83
+ let level = resolveLevel();
84
+ let rank = RANK[level];
85
+ /**
86
+ * Overrides the level for the rest of the process.
87
+ *
88
+ * The configuration above is read once, at import, which is what makes the gate cheap — but it
89
+ * also means an application that decides its verbosity after startup, or a test that wants to
90
+ * assert on output, has no way in. This is that way in.
91
+ */ const setLogLevel = (next)=>{
92
+ if (isLogLevel(next) === false) {
93
+ throw new Error(`Unknown log level "${next}". Expected one of: ${LOG_LEVELS.join(', ')}`);
18
94
  }
95
+ level = next;
96
+ rank = RANK[next];
97
+ };
98
+ const getLogLevel = ()=>level;
99
+ /** Re-reads the environment. For tests that change it after this module was imported. */ const resetLogLevel = ()=>{
100
+ level = resolveLevel();
101
+ rank = RANK[level];
102
+ };
103
+ /**
104
+ * Whether a message at this level would be emitted.
105
+ *
106
+ * For the rare call site whose *arguments* are expensive to build — a serialization, a deep
107
+ * clone, a join over a large collection. An ordinary payload object is not worth guarding; see
108
+ * the measurement in the header.
109
+ */ const isLogLevelEnabled = (at)=>rank >= RANK[at];
110
+ const emit = (at, method, args)=>{
111
+ if (rank < RANK[at]) {
112
+ return;
113
+ }
114
+ // Resolved at call time rather than captured once: test harnesses and browser devtools both
115
+ // replace console methods after modules have loaded, and a captured reference would keep
116
+ // writing past the replacement.
117
+ console[method](...args);
19
118
  };
20
119
  const logger = {
21
- log: (...args) => {
22
- tryLog("log", ...args);
23
- },
24
- info: (...args) => {
25
- tryLog("info", ...args);
26
- },
27
- warn: (...args) => {
28
- tryLog("warn", ...args);
29
- },
30
- error: (...args) => {
31
- tryLog("error", ...args);
32
- },
33
- debug: (...args) => {
34
- tryLog("debug", ...args);
35
- },
36
- table: (...args) => {
37
- tryLog("table", ...args);
38
- },
120
+ /** General-purpose output. Carried at `info`, since `log` names a console method, not a level. */ log: (...args)=>emit('info', 'log', args),
121
+ info: (...args)=>emit('info', 'info', args),
122
+ warn: (...args)=>emit('warn', 'warn', args),
123
+ error: (...args)=>emit('error', 'error', args),
124
+ debug: (...args)=>emit('debug', 'debug', args),
125
+ /** Diagnostic tabular output; verbose by nature, so it sits at `debug`. */ table: (...args)=>emit('debug', 'table', args)
39
126
  };
40
127
 
41
128
 
@@ -79,28 +166,17 @@ __webpack_require__.d = (exports, definition) => {
79
166
  (() => {
80
167
  __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
81
168
  })();
82
- // webpack/runtime/make_namespace_object
83
- (() => {
84
- // define __esModule on exports
85
- __webpack_require__.r = (exports) => {
86
- if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
87
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
88
- }
89
- Object.defineProperty(exports, '__esModule', { value: true });
90
- };
91
- })();
92
169
  var __webpack_exports__ = {};
93
170
  // This entry needs to be wrapped in an IIFE because it needs to be isolated against other modules in the chunk.
94
171
  (() => {
95
- __webpack_require__.r(__webpack_exports__);
96
172
  __webpack_require__.d(__webpack_exports__, {
97
- measure: () => (measure),
98
- now: () => (now)
173
+ t: () => (now),
174
+ x: () => (measure)
99
175
  });
100
- /* import */ var _utilities__rspack_import_0 = __webpack_require__("./src/utilities/logger.ts");
176
+ /* import */ var _utilities__rspack_import_0 = __webpack_require__(581);
101
177
 
102
178
  const measurements = {};
103
- const now = () => {
179
+ const now = ()=>{
104
180
  if (typeof performance !== 'undefined' && performance.now) {
105
181
  // Browser or modern Node.js
106
182
  return performance.now();
@@ -109,21 +185,21 @@ const now = () => {
109
185
  return Date.now();
110
186
  };
111
187
  const measure = {
112
- start: (name) => {
188
+ start: (name)=>{
113
189
  measurements[name] = now();
114
190
  },
115
- end: (name) => {
191
+ end: (name)=>{
116
192
  const start = measurements[name];
117
193
  delete measurements[name];
118
194
  const delta = now() - start;
119
- _utilities__rspack_import_0.logger.log(`[ROUTIER] - Performance: ${name} took ${delta}`);
195
+ _utilities__rspack_import_0/* .logger.log */.vF.log(`[ROUTIER] - Performance: ${name} took ${delta}`);
120
196
  }
121
197
  };
122
198
 
123
199
  })();
124
200
 
125
- var __webpack_exports__measure = __webpack_exports__.measure;
126
- var __webpack_exports__now = __webpack_exports__.now;
201
+ var __webpack_exports__measure = __webpack_exports__.x;
202
+ var __webpack_exports__now = __webpack_exports__.t;
127
203
  export { __webpack_exports__measure as measure, __webpack_exports__now as now };
128
204
 
129
205
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"performance/index.js","sources":["webpack://@routier/core/./src/utilities/logger.ts","webpack://@routier/core/webpack/runtime/define_property_getters","webpack://@routier/core/webpack/runtime/has_own_property","webpack://@routier/core/webpack/runtime/make_namespace_object","webpack://@routier/core/./src/performance/index.ts"],"sourcesContent":["const isDevelopment = (): boolean => {\n if (typeof process === 'undefined' || process.env == null) {\n return false;\n }\n const env = process.env.NODE_ENV?.toLowerCase();\n return env === 'dev' || env === 'development' || env === 'test';\n};\n\ntype LogMethods = \"log\" | \"info\" | \"warn\" | \"error\" | \"debug\" | \"table\";\nconst shouldLog = isDevelopment();\nconst tryLog = (type: LogMethods, ...args: unknown[]) => {\n if (shouldLog) {\n (console[type] as (...args: unknown[]) => void)(...args);\n }\n};\n\nexport const logger = {\n log: (...args: unknown[]): void => {\n tryLog(\"log\", ...args);\n },\n info: (...args: unknown[]): void => {\n tryLog(\"info\", ...args);\n },\n warn: (...args: unknown[]): void => {\n tryLog(\"warn\", ...args);\n },\n error: (...args: unknown[]): void => {\n tryLog(\"error\", ...args);\n },\n debug: (...args: unknown[]): void => {\n tryLog(\"debug\", ...args);\n },\n table: (...args: unknown[]): void => {\n tryLog(\"table\", ...args);\n },\n};\n\n","__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n }\n }\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","import { logger } from \"../utilities\";\n\nconst measurements: Record<string, number> = {}\n\nexport const now = (): number => {\n if (typeof performance !== 'undefined' && performance.now) {\n // Browser or modern Node.js\n return performance.now();\n }\n\n // Fallback for older environments\n return Date.now();\n}\n\nexport const measure = {\n start: (name: string): void => {\n measurements[name] = now();\n },\n end: (name: string): void => {\n const start = measurements[name];\n\n delete measurements[name];\n\n const delta = now() - start;\n\n logger.log(`[ROUTIER] - Performance: ${name} took ${delta}`);\n }\n}"],"names":[],"mappings":";;;;;;AAAA,MAAM,aAAa,GAAG,GAAY,EAAE;IAChC,IAAI,OAAO,OAAO,KAAK,WAAW,IAAI,OAAO,CAAC,GAAG,IAAI,IAAI,EAAE,CAAC;QACxD,OAAO,KAAK,CAAC;IACjB,CAAC;IACD,MAAM,GAAG,GAAG,aAAoB,EAAE,WAAW,EAAE,CAAC;IAChD,OAAO,GAAG,KAAK,KAAK,IAAI,GAAG,KAAK,aAAa,IAAI,GAAG,KAAK,MAAM,CAAC;AACpE,CAAC,CAAC;AAGF,MAAM,SAAS,GAAG,aAAa,EAAE,CAAC;AAClC,MAAM,MAAM,GAAG,CAAC,IAAgB,EAAE,GAAG,IAAe,EAAE,EAAE;IACpD,IAAI,SAAS,EAAE,CAAC;QACX,OAAO,CAAC,IAAI,CAAkC,CAAC,GAAG,IAAI,CAAC,CAAC;IAC7D,CAAC;AACL,CAAC,CAAC;AAEK,MAAM,MAAM,GAAG;IAClB,GAAG,EAAE,CAAC,GAAG,IAAe,EAAQ,EAAE;QAC9B,MAAM,CAAC,KAAK,EAAE,GAAG,IAAI,CAAC,CAAC;IAC3B,CAAC;IACD,IAAI,EAAE,CAAC,GAAG,IAAe,EAAQ,EAAE;QAC/B,MAAM,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC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AI,CAAC,CAAC;QAE1B,MAAM,KAAK,GAAG,GAAG,EAAE,GAAG,KAAK,CAAC;QAE5B,sCAAU,CAAC,4BAA4B,IAAI,SAAS,KAAK,EAAE,CAAC,CAAC;IACjE,CAAC;CACJ"}
1
+ {"version":3,"file":"performance/index.js","sources":["webpack://@routier/core/./src/utilities/logger.ts","webpack://@routier/core/webpack/runtime/define_property_getters","webpack://@routier/core/webpack/runtime/has_own_property","webpack://@routier/core/./src/performance/index.ts"],"sourcesContent":["/**\n * Levelled logging, resolved once.\n *\n * Three things about the previous implementation drove this shape:\n *\n * - **There was no way to turn logging off.** `globalThis.__ROUTIER_DEBUG__` was only ever\n * compared against `true`, so setting it to `false` did nothing — while\n * `docs/how-to/debug-logging.md` documented exactly that as the way to force logging off.\n * A documented switch that silently does nothing is worse than no switch.\n * - **`NODE_ENV === 'test'` enabled it.** Every Jest run therefore logged, because Jest always\n * sets `NODE_ENV=test`. Measured on the S7 stress scenario, which drives ~2,000 saves through\n * a plugin that logs three lines per query: 12.4s with logging, ~6s without. Test runners also\n * capture console output by snapshotting a stack trace per call, so the cost is far above what\n * writing to a terminal would suggest — and the output buries whatever the failure was.\n * - **It was all-or-nothing, and re-resolved per call.** An error could not be kept while debug\n * was dropped, and every one of the ~97 call sites re-read `globalThis` and `process.env`.\n *\n * Levels are compared numerically against a value cached at module load. Measured against a\n * no-op console at 200k calls: an enabled call costs ~70ns, a call rejected by the gate ~3ns.\n * Building the arguments the call site passes in accounts for ~0.2ns of that 3ns, which is why\n * this keeps the ordinary `logger.debug(msg, payload)` signature instead of taking a thunk —\n * a lazy API would recover 0.3% of an enabled call's cost and would have to change every call\n * site to do it.\n */\n\n/** Ordered from most severe to most verbose. `silent` discards everything. */\nexport const LOG_LEVELS = ['silent', 'error', 'warn', 'info', 'debug'] as const;\n\nexport type LogLevel = (typeof LOG_LEVELS)[number];\n\n/** Numeric rank, so a gate is one integer comparison. */\nconst RANK: Record<LogLevel, number> = {\n silent: 0,\n error: 1,\n warn: 2,\n info: 3,\n debug: 4,\n};\n\nconst isLogLevel = (value: unknown): value is LogLevel =>\n typeof value === 'string' && (LOG_LEVELS as readonly string[]).includes(value);\n\n/**\n * Resolves the configured level, in precedence order.\n *\n * Ordered most specific first: an explicit level beats a boolean flag, a boolean flag beats an\n * environment variable, and an environment variable beats an inference from `NODE_ENV`. Anything\n * unrecognised is ignored rather than treated as an error — a typo'd level should not take down\n * an application, and `silent` is the safe direction to fall back to.\n */\nconst resolveLevel = (): LogLevel => {\n if (typeof globalThis !== 'undefined') {\n const g = globalThis as { __ROUTIER_LOG_LEVEL__?: unknown; __ROUTIER_DEBUG__?: unknown };\n\n if (isLogLevel(g.__ROUTIER_LOG_LEVEL__)) {\n return g.__ROUTIER_LOG_LEVEL__;\n }\n\n // Both directions honoured. `=== false` used to fall through to the NODE_ENV checks\n // below and re-enable the logging it was asked to suppress.\n if (g.__ROUTIER_DEBUG__ === true) return 'debug';\n if (g.__ROUTIER_DEBUG__ === false) return 'silent';\n }\n\n // There is deliberately no `import.meta.env` branch, although the documentation used to\n // promise one. It could never work: this package is bundled with rspack, which replaces\n // `import.meta` with `undefined`, so the check would read the *library's* build-time\n // environment rather than the application's — and referencing `import.meta` at all is a parse\n // error under a CommonJS build target, which is how the test suite loads this file. Vite and\n // similar apps set `__ROUTIER_LOG_LEVEL__` or `__ROUTIER_DEBUG__` from their own\n // `import.meta.env`, which is what the docs now describe.\n if (typeof process !== 'undefined' && process.env != null) {\n if (isLogLevel(process.env.ROUTIER_LOG_LEVEL)) {\n return process.env.ROUTIER_LOG_LEVEL as LogLevel;\n }\n\n const debug = process.env.DEBUG;\n if (debug === 'routier' || debug === '*') return 'debug';\n\n const env = process.env.NODE_ENV?.toLowerCase();\n\n // `test` is deliberately absent. It used to be here, which meant no test suite anywhere\n // could run Routier quietly. Opt in with DEBUG=routier or ROUTIER_LOG_LEVEL when a test\n // needs the output.\n if (env === 'dev' || env === 'development') return 'debug';\n }\n\n return 'silent';\n};\n\nlet level: LogLevel = resolveLevel();\nlet rank = RANK[level];\n\n/**\n * Overrides the level for the rest of the process.\n *\n * The configuration above is read once, at import, which is what makes the gate cheap — but it\n * also means an application that decides its verbosity after startup, or a test that wants to\n * assert on output, has no way in. This is that way in.\n */\nexport const setLogLevel = (next: LogLevel): void => {\n if (isLogLevel(next) === false) {\n throw new Error(`Unknown log level \"${next}\". Expected one of: ${LOG_LEVELS.join(', ')}`);\n }\n\n level = next;\n rank = RANK[next];\n};\n\nexport const getLogLevel = (): LogLevel => level;\n\n/** Re-reads the environment. For tests that change it after this module was imported. */\nexport const resetLogLevel = (): void => {\n level = resolveLevel();\n rank = RANK[level];\n};\n\n/**\n * Whether a message at this level would be emitted.\n *\n * For the rare call site whose *arguments* are expensive to build — a serialization, a deep\n * clone, a join over a large collection. An ordinary payload object is not worth guarding; see\n * the measurement in the header.\n */\nexport const isLogLevelEnabled = (at: LogLevel): boolean => rank >= RANK[at];\n\ntype ConsoleMethod = 'log' | 'info' | 'warn' | 'error' | 'debug' | 'table';\n\nconst emit = (at: LogLevel, method: ConsoleMethod, args: unknown[]) => {\n if (rank < RANK[at]) {\n return;\n }\n\n // Resolved at call time rather than captured once: test harnesses and browser devtools both\n // replace console methods after modules have loaded, and a captured reference would keep\n // writing past the replacement.\n (console[method] as (...a: unknown[]) => void)(...args);\n};\n\nexport const logger = {\n /** General-purpose output. Carried at `info`, since `log` names a console method, not a level. */\n log: (...args: unknown[]): void => emit('info', 'log', args),\n info: (...args: unknown[]): void => emit('info', 'info', args),\n warn: (...args: unknown[]): void => emit('warn', 'warn', args),\n error: (...args: unknown[]): void => emit('error', 'error', args),\n debug: (...args: unknown[]): void => emit('debug', 'debug', args),\n /** Diagnostic tabular output; verbose by nature, so it sits at `debug`. */\n table: (...args: unknown[]): void => emit('debug', 'table', args),\n};\n","__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n }\n }\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","import { logger } from \"../utilities\";\n\nconst measurements: Record<string, number> = {}\n\nexport const now = (): number => {\n if (typeof performance !== 'undefined' && performance.now) {\n // Browser or modern Node.js\n return performance.now();\n }\n\n // Fallback for older environments\n return Date.now();\n}\n\nexport const measure = {\n start: (name: string): void => {\n measurements[name] = now();\n },\n end: (name: string): void => {\n const start = measurements[name];\n\n delete measurements[name];\n\n const delta = now() - start;\n\n logger.log(`[ROUTIER] - Performance: ${name} took ${delta}`);\n }\n}"],"names":["LOG_LEVELS","RANK","isLogLevel","value","resolveLevel","globalThis","g","process","debug","env","level","rank","setLogLevel","next","Error","getLogLevel","resetLogLevel","isLogLevelEnabled","at","emit","method","args","console","logger","measurements","now","performance","Date","measure","name","start","delta"],"mappings":";;;;;AAAA;;;;;;;;;;;;;;;;;;;;;;;CAuBC,GAED,4EAA4E,GACrE,MAAMA,aAAa;IAAC;IAAU;IAAS;IAAQ;IAAQ;CAAQ,CAAU;AAIhF,uDAAuD,GACvD,MAAMC,OAAiC;IACnC,QAAQ;IACR,OAAO;IACP,MAAM;IACN,MAAM;IACN,OAAO;AACX;AAEA,MAAMC,aAAa,CAACC,QAChB,OAAOA,UAAU,YAAaH,WAAiC,QAAQ,CAACG;AAE5E;;;;;;;CAOC,GACD,MAAMC,eAAe;IACjB,IAAI,OAAOC,eAAe,aAAa;QACnC,MAAMC,IAAID;QAEV,IAAIH,WAAWI,EAAE,qBAAqB,GAAG;YACrC,OAAOA,EAAE,qBAAqB;QAClC;QAEA,oFAAoF;QACpF,4DAA4D;QAC5D,IAAIA,EAAE,iBAAiB,KAAK,MAAM,OAAO;QACzC,IAAIA,EAAE,iBAAiB,KAAK,OAAO,OAAO;IAC9C;IAEA,wFAAwF;IACxF,wFAAwF;IACxF,qFAAqF;IACrF,8FAA8F;IAC9F,6FAA6F;IAC7F,iFAAiF;IACjF,0DAA0D;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