@datakable/core 1.0.0 → 1.1.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 (290) hide show
  1. package/README.md +4 -2
  2. package/dist/catalog/codes.cjs +12 -8
  3. package/dist/catalog/codes.cjs.map +1 -1
  4. package/dist/catalog/codes.js +12 -8
  5. package/dist/catalog/codes.js.map +1 -1
  6. package/dist/catalog/slots.cjs +10 -6
  7. package/dist/catalog/slots.cjs.map +1 -1
  8. package/dist/catalog/slots.js +10 -6
  9. package/dist/catalog/slots.js.map +1 -1
  10. package/dist/{codes-BKdS9EiO.d.cts → codes-B9bCK73-.d.cts} +46 -8
  11. package/dist/{codes-BKdS9EiO.d.ts → codes-B9bCK73-.d.ts} +46 -8
  12. package/dist/column/column-def.cjs.map +1 -1
  13. package/dist/column/get-value.cjs +6 -1
  14. package/dist/column/get-value.cjs.map +1 -1
  15. package/dist/column/get-value.js +6 -1
  16. package/dist/column/get-value.js.map +1 -1
  17. package/dist/column-filters.d.cts +2 -2
  18. package/dist/column-filters.d.ts +2 -2
  19. package/dist/diagnostics/build.cjs +10 -4
  20. package/dist/diagnostics/build.cjs.map +1 -1
  21. package/dist/diagnostics/build.js +8 -3
  22. package/dist/diagnostics/build.js.map +1 -1
  23. package/dist/diagnostics/catalog.cjs +11 -5
  24. package/dist/diagnostics/catalog.cjs.map +1 -1
  25. package/dist/diagnostics/catalog.js +10 -5
  26. package/dist/diagnostics/catalog.js.map +1 -1
  27. package/dist/diagnostics/codes.cjs +12 -8
  28. package/dist/diagnostics/codes.cjs.map +1 -1
  29. package/dist/diagnostics/codes.js +12 -8
  30. package/dist/diagnostics/codes.js.map +1 -1
  31. package/dist/diagnostics/console.cjs +13 -6
  32. package/dist/diagnostics/console.cjs.map +1 -1
  33. package/dist/diagnostics/console.js +13 -6
  34. package/dist/diagnostics/console.js.map +1 -1
  35. package/dist/diagnostics/env.cjs +1 -0
  36. package/dist/diagnostics/env.cjs.map +1 -1
  37. package/dist/diagnostics/env.js +1 -0
  38. package/dist/diagnostics/env.js.map +1 -1
  39. package/dist/diagnostics/explain-text.cjs +2 -1
  40. package/dist/diagnostics/explain-text.cjs.map +1 -1
  41. package/dist/diagnostics/explain-text.js +2 -1
  42. package/dist/diagnostics/explain-text.js.map +1 -1
  43. package/dist/diagnostics/explain.cjs +3 -2
  44. package/dist/diagnostics/explain.cjs.map +1 -1
  45. package/dist/diagnostics/explain.js +3 -2
  46. package/dist/diagnostics/explain.js.map +1 -1
  47. package/dist/diagnostics/hub.cjs +6 -5
  48. package/dist/diagnostics/hub.cjs.map +1 -1
  49. package/dist/diagnostics/hub.js +7 -6
  50. package/dist/diagnostics/hub.js.map +1 -1
  51. package/dist/diagnostics/process-guard.cjs +26 -0
  52. package/dist/diagnostics/process-guard.cjs.map +1 -0
  53. package/dist/diagnostics/process-guard.js +9 -0
  54. package/dist/diagnostics/process-guard.js.map +1 -0
  55. package/dist/diagnostics/prose.cjs +120 -0
  56. package/dist/diagnostics/prose.cjs.map +1 -0
  57. package/dist/diagnostics/prose.js +93 -0
  58. package/dist/diagnostics/prose.js.map +1 -0
  59. package/dist/diagnostics/redact.cjs +7 -4
  60. package/dist/diagnostics/redact.cjs.map +1 -1
  61. package/dist/diagnostics/redact.js +6 -4
  62. package/dist/diagnostics/redact.js.map +1 -1
  63. package/dist/diagnostics/trace-store.cjs +6 -0
  64. package/dist/diagnostics/trace-store.cjs.map +1 -1
  65. package/dist/diagnostics/trace-store.js +4 -0
  66. package/dist/diagnostics/trace-store.js.map +1 -1
  67. package/dist/diagnostics/tracer.cjs +74 -13
  68. package/dist/diagnostics/tracer.cjs.map +1 -1
  69. package/dist/diagnostics/tracer.js +75 -14
  70. package/dist/diagnostics/tracer.js.map +1 -1
  71. package/dist/diagnostics/types.cjs.map +1 -1
  72. package/dist/{explain-aagaYHcy.d.cts → explain-Q8Cg0cZy.d.cts} +13 -4
  73. package/dist/{explain-DcUZfFh5.d.ts → explain-i0OATi_W.d.ts} +13 -4
  74. package/dist/feature/codes.cjs +1 -0
  75. package/dist/feature/codes.cjs.map +1 -1
  76. package/dist/feature/codes.js +1 -0
  77. package/dist/feature/codes.js.map +1 -1
  78. package/dist/feature/define.cjs +3 -1
  79. package/dist/feature/define.cjs.map +1 -1
  80. package/dist/feature/define.js +3 -1
  81. package/dist/feature/define.js.map +1 -1
  82. package/dist/feature/install.cjs +4 -3
  83. package/dist/feature/install.cjs.map +1 -1
  84. package/dist/feature/install.js +4 -3
  85. package/dist/feature/install.js.map +1 -1
  86. package/dist/feature/runtime.cjs.map +1 -1
  87. package/dist/feature/runtime.js.map +1 -1
  88. package/dist/features/column-filters/codes.cjs +1 -0
  89. package/dist/features/column-filters/codes.cjs.map +1 -1
  90. package/dist/features/column-filters/codes.js +1 -0
  91. package/dist/features/column-filters/codes.js.map +1 -1
  92. package/dist/features/column-filters/column-filters.cjs +4 -2
  93. package/dist/features/column-filters/column-filters.cjs.map +1 -1
  94. package/dist/features/column-filters/column-filters.js +4 -2
  95. package/dist/features/column-filters/column-filters.js.map +1 -1
  96. package/dist/features/column-filters/match.cjs +5 -5
  97. package/dist/features/column-filters/match.cjs.map +1 -1
  98. package/dist/features/column-filters/match.js +5 -5
  99. package/dist/features/column-filters/match.js.map +1 -1
  100. package/dist/features/pagination/codes.cjs +6 -3
  101. package/dist/features/pagination/codes.cjs.map +1 -1
  102. package/dist/features/pagination/codes.js +6 -3
  103. package/dist/features/pagination/codes.js.map +1 -1
  104. package/dist/features/pagination/pagination.cjs +19 -14
  105. package/dist/features/pagination/pagination.cjs.map +1 -1
  106. package/dist/features/pagination/pagination.js +19 -14
  107. package/dist/features/pagination/pagination.js.map +1 -1
  108. package/dist/features/search/codes.cjs +1 -0
  109. package/dist/features/search/codes.cjs.map +1 -1
  110. package/dist/features/search/codes.js +1 -0
  111. package/dist/features/search/codes.js.map +1 -1
  112. package/dist/features/search/search-index.cjs +105 -48
  113. package/dist/features/search/search-index.cjs.map +1 -1
  114. package/dist/features/search/search-index.js +106 -49
  115. package/dist/features/search/search-index.js.map +1 -1
  116. package/dist/features/search/search.cjs +82 -24
  117. package/dist/features/search/search.cjs.map +1 -1
  118. package/dist/features/search/search.js +82 -24
  119. package/dist/features/search/search.js.map +1 -1
  120. package/dist/features/search/skipped-codes.cjs +45 -0
  121. package/dist/features/search/skipped-codes.cjs.map +1 -0
  122. package/dist/features/search/skipped-codes.js +20 -0
  123. package/dist/features/search/skipped-codes.js.map +1 -0
  124. package/dist/features/sorting/codes.cjs +1 -0
  125. package/dist/features/sorting/codes.cjs.map +1 -1
  126. package/dist/features/sorting/codes.js +1 -0
  127. package/dist/features/sorting/codes.js.map +1 -1
  128. package/dist/features/sorting/sorting.cjs +19 -23
  129. package/dist/features/sorting/sorting.cjs.map +1 -1
  130. package/dist/features/sorting/sorting.js +19 -23
  131. package/dist/features/sorting/sorting.js.map +1 -1
  132. package/dist/features/sorting/strategy.cjs +4 -4
  133. package/dist/features/sorting/strategy.cjs.map +1 -1
  134. package/dist/features/sorting/strategy.js +4 -4
  135. package/dist/features/sorting/strategy.js.map +1 -1
  136. package/dist/features/validity/codes.cjs +1 -0
  137. package/dist/features/validity/codes.cjs.map +1 -1
  138. package/dist/features/validity/codes.js +1 -0
  139. package/dist/features/validity/codes.js.map +1 -1
  140. package/dist/features/validity/validity.cjs +3 -3
  141. package/dist/features/validity/validity.cjs.map +1 -1
  142. package/dist/features/validity/validity.js +3 -3
  143. package/dist/features/validity/validity.js.map +1 -1
  144. package/dist/index.d.cts +16 -11
  145. package/dist/index.d.ts +16 -11
  146. package/dist/ingest/data-check-codes.cjs +4 -2
  147. package/dist/ingest/data-check-codes.cjs.map +1 -1
  148. package/dist/ingest/data-check-codes.js +4 -2
  149. package/dist/ingest/data-check-codes.js.map +1 -1
  150. package/dist/ingest/data-checks.cjs +1 -1
  151. package/dist/ingest/data-checks.cjs.map +1 -1
  152. package/dist/ingest/data-checks.js +1 -1
  153. package/dist/ingest/data-checks.js.map +1 -1
  154. package/dist/ingest/row-key-codes.cjs +1 -0
  155. package/dist/ingest/row-key-codes.cjs.map +1 -1
  156. package/dist/ingest/row-key-codes.js +1 -0
  157. package/dist/ingest/row-key-codes.js.map +1 -1
  158. package/dist/ingest/row-key.cjs +23 -20
  159. package/dist/ingest/row-key.cjs.map +1 -1
  160. package/dist/ingest/row-key.js +23 -20
  161. package/dist/ingest/row-key.js.map +1 -1
  162. package/dist/ingest/schema-codes.cjs +1 -0
  163. package/dist/ingest/schema-codes.cjs.map +1 -1
  164. package/dist/ingest/schema-codes.js +1 -0
  165. package/dist/ingest/schema-codes.js.map +1 -1
  166. package/dist/ingest/unique-fields.cjs +2 -2
  167. package/dist/ingest/unique-fields.cjs.map +1 -1
  168. package/dist/ingest/unique-fields.js +2 -2
  169. package/dist/ingest/unique-fields.js.map +1 -1
  170. package/dist/intercept/boundary.cjs +4 -2
  171. package/dist/intercept/boundary.cjs.map +1 -1
  172. package/dist/intercept/boundary.js +4 -2
  173. package/dist/intercept/boundary.js.map +1 -1
  174. package/dist/intercept/cell-batch.cjs +7 -4
  175. package/dist/intercept/cell-batch.cjs.map +1 -1
  176. package/dist/intercept/cell-batch.js +7 -4
  177. package/dist/intercept/cell-batch.js.map +1 -1
  178. package/dist/intercept/codes.cjs +1 -0
  179. package/dist/intercept/codes.cjs.map +1 -1
  180. package/dist/intercept/codes.js +1 -0
  181. package/dist/intercept/codes.js.map +1 -1
  182. package/dist/intercept/fallbacks.cjs +12 -20
  183. package/dist/intercept/fallbacks.cjs.map +1 -1
  184. package/dist/intercept/fallbacks.js +12 -20
  185. package/dist/intercept/fallbacks.js.map +1 -1
  186. package/dist/intercept/runtime.cjs +7 -9
  187. package/dist/intercept/runtime.cjs.map +1 -1
  188. package/dist/intercept/runtime.js +7 -9
  189. package/dist/intercept/runtime.js.map +1 -1
  190. package/dist/messages/index.cjs +4 -1
  191. package/dist/messages/index.cjs.map +1 -1
  192. package/dist/messages/index.js +4 -1
  193. package/dist/messages/index.js.map +1 -1
  194. package/dist/pagination.d.cts +2 -2
  195. package/dist/pagination.d.ts +2 -2
  196. package/dist/pipeline/codes.cjs +1 -0
  197. package/dist/pipeline/codes.cjs.map +1 -1
  198. package/dist/pipeline/codes.js +1 -0
  199. package/dist/pipeline/codes.js.map +1 -1
  200. package/dist/pipeline/column-cache.cjs +94 -76
  201. package/dist/pipeline/column-cache.cjs.map +1 -1
  202. package/dist/pipeline/column-cache.js +92 -75
  203. package/dist/pipeline/column-cache.js.map +1 -1
  204. package/dist/pipeline/dev-checks.cjs +1 -0
  205. package/dist/pipeline/dev-checks.cjs.map +1 -1
  206. package/dist/pipeline/dev-checks.js +1 -0
  207. package/dist/pipeline/dev-checks.js.map +1 -1
  208. package/dist/pipeline/env-codes.cjs +3 -2
  209. package/dist/pipeline/env-codes.cjs.map +1 -1
  210. package/dist/pipeline/env-codes.js +3 -2
  211. package/dist/pipeline/env-codes.js.map +1 -1
  212. package/dist/pipeline/perf-codes.cjs +1 -0
  213. package/dist/pipeline/perf-codes.cjs.map +1 -1
  214. package/dist/pipeline/perf-codes.js +1 -0
  215. package/dist/pipeline/perf-codes.js.map +1 -1
  216. package/dist/pipeline/row.cjs +8 -7
  217. package/dist/pipeline/row.cjs.map +1 -1
  218. package/dist/pipeline/row.js +8 -7
  219. package/dist/pipeline/row.js.map +1 -1
  220. package/dist/pipeline/runner.cjs +17 -9
  221. package/dist/pipeline/runner.cjs.map +1 -1
  222. package/dist/pipeline/runner.js +17 -9
  223. package/dist/pipeline/runner.js.map +1 -1
  224. package/dist/pipeline/slice.cjs +3 -1
  225. package/dist/pipeline/slice.cjs.map +1 -1
  226. package/dist/pipeline/slice.js +3 -1
  227. package/dist/pipeline/slice.js.map +1 -1
  228. package/dist/schema.d.cts +2 -2
  229. package/dist/schema.d.ts +2 -2
  230. package/dist/{search-async-entry-C3mXxLP8.d.cts → search-async-entry-CuLYPfY_.d.cts} +2 -2
  231. package/dist/{search-async-entry-BmQYT120.d.ts → search-async-entry-Cx7xpuVZ.d.ts} +2 -2
  232. package/dist/search-async.d.cts +3 -3
  233. package/dist/search-async.d.ts +3 -3
  234. package/dist/search.d.cts +8 -6
  235. package/dist/search.d.ts +8 -6
  236. package/dist/server.d.cts +3 -3
  237. package/dist/server.d.ts +3 -3
  238. package/dist/sorting.d.cts +6 -3
  239. package/dist/sorting.d.ts +6 -3
  240. package/dist/source/codes.cjs +1 -0
  241. package/dist/source/codes.cjs.map +1 -1
  242. package/dist/source/codes.js +1 -0
  243. package/dist/source/codes.js.map +1 -1
  244. package/dist/source/fetch-codes.cjs +1 -0
  245. package/dist/source/fetch-codes.cjs.map +1 -1
  246. package/dist/source/fetch-codes.js +1 -0
  247. package/dist/source/fetch-codes.js.map +1 -1
  248. package/dist/table/codes.cjs +1 -0
  249. package/dist/table/codes.cjs.map +1 -1
  250. package/dist/table/codes.js +1 -0
  251. package/dist/table/codes.js.map +1 -1
  252. package/dist/table/create-table.cjs +39 -9
  253. package/dist/table/create-table.cjs.map +1 -1
  254. package/dist/table/create-table.js +39 -9
  255. package/dist/table/create-table.js.map +1 -1
  256. package/dist/table/data-mutation.cjs +1 -0
  257. package/dist/table/data-mutation.cjs.map +1 -1
  258. package/dist/table/data-mutation.js +1 -0
  259. package/dist/table/data-mutation.js.map +1 -1
  260. package/dist/table/internals.cjs.map +1 -1
  261. package/dist/table/internals.js.map +1 -1
  262. package/dist/table/ssr-codes.cjs +1 -0
  263. package/dist/table/ssr-codes.cjs.map +1 -1
  264. package/dist/table/ssr-codes.js +1 -0
  265. package/dist/table/ssr-codes.js.map +1 -1
  266. package/dist/table/ssr.cjs +4 -1
  267. package/dist/table/ssr.cjs.map +1 -1
  268. package/dist/table/ssr.js +4 -1
  269. package/dist/table/ssr.js.map +1 -1
  270. package/dist/table/state-feedback.cjs +19 -0
  271. package/dist/table/state-feedback.cjs.map +1 -1
  272. package/dist/table/state-feedback.js +19 -0
  273. package/dist/table/state-feedback.js.map +1 -1
  274. package/dist/table/types.cjs.map +1 -1
  275. package/dist/table/types.js.map +1 -1
  276. package/dist/validity.d.cts +2 -2
  277. package/dist/validity.d.ts +2 -2
  278. package/dist/version.cjs +1 -1
  279. package/dist/version.cjs.map +1 -1
  280. package/dist/version.js +1 -1
  281. package/dist/version.js.map +1 -1
  282. package/dist/versioning/codes.cjs +18 -0
  283. package/dist/versioning/codes.cjs.map +1 -1
  284. package/dist/versioning/codes.js +18 -0
  285. package/dist/versioning/codes.js.map +1 -1
  286. package/dist/versioning/registry.cjs +4 -2
  287. package/dist/versioning/registry.cjs.map +1 -1
  288. package/dist/versioning/registry.js +4 -2
  289. package/dist/versioning/registry.js.map +1 -1
  290. package/package.json +39 -3
@@ -26,13 +26,14 @@ module.exports = __toCommonJS(hub_exports);
26
26
  var import_context = require("../intercept/context.cjs");
27
27
  var import_build = require("./build.cjs");
28
28
  var import_console = require("./console.cjs");
29
+ var import_process_guard = require("./process-guard.cjs");
29
30
  var import_redact = require("./redact.cjs");
30
31
  var import_ring_buffer = require("./ring-buffer.cjs");
31
32
  var tableSeq = 0;
32
33
  function createDiagnostics(options = {}) {
33
34
  const table = options.name ?? `table#${++tableSeq}`;
34
35
  const dev = options.dev ?? process.env.NODE_ENV !== "production";
35
- const now = options.now ?? Date.now;
36
+ const now = options.now ?? import_build.wallClock;
36
37
  const dedupeLimit = options.dedupeLimit ?? 500;
37
38
  const buffer = new import_ring_buffer.RingBuffer(options.bufferSize ?? 100);
38
39
  const seen = /* @__PURE__ */ new Map();
@@ -55,7 +56,7 @@ function createDiagnostics(options = {}) {
55
56
  dev ? e : (0, import_redact.scrubError)(e)
56
57
  );
57
58
  };
58
- function deliver(input) {
59
+ function deliver(input, quiet) {
59
60
  const d = redact ? redact(input) : input;
60
61
  if (getDataRef) {
61
62
  const ref = getDataRef();
@@ -80,7 +81,7 @@ function createDiagnostics(options = {}) {
80
81
  fail(e);
81
82
  }
82
83
  }
83
- toConsole?.(d);
84
+ if (!quiet) toConsole?.(d);
84
85
  return d;
85
86
  }
86
87
  const redactor = () => {
@@ -119,13 +120,13 @@ function createDiagnostics(options = {}) {
119
120
  depth++;
120
121
  try {
121
122
  runtime.run("diagnostic:emit", ctx, (x) => {
122
- out = deliver(x.input.diagnostic);
123
+ out = deliver(x.input.diagnostic, opts.quiet);
123
124
  });
124
125
  } finally {
125
126
  depth--;
126
127
  }
127
128
  } else {
128
- out = deliver(d);
129
+ out = deliver(d, opts.quiet);
129
130
  }
130
131
  } catch (e) {
131
132
  if (strict && e instanceof import_build.DatakableError) throw e;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/diagnostics/hub.ts"],"sourcesContent":["import { createContext } from '../intercept/context'\nimport type { InterceptorRuntime } from '../intercept/runtime'\nimport { buildDiagnostic, DatakableError, defaultPhase, formatWhere } from './build'\nimport type { DiagnosticCode, DiagnosticDetails } from './catalog'\nimport { createConsoleSink } from './console'\nimport {\n DK_UNSAFE_REDACTION,\n type RedactionOptions,\n type RedactLevel,\n resolveRedaction,\n scrubError,\n} from './redact'\nimport { RingBuffer } from './ring-buffer'\nimport type { Diagnostic, DiagnosticStateSummary, EmitOptions, Phase, Trigger } from './types'\n\n/** Live values the store supplies at emit time (T07+). Missing ones use defaults. */\nexport interface LiveDiagnosticContext {\n trigger?: Trigger\n run?: number\n phase?: Phase\n mode?: Record<string, 'client' | 'server'>\n state?: DiagnosticStateSummary\n}\n\nexport interface DiagnosticsOptions {\n /** `options.name` of the table; default `table#n`. */\n name?: string\n /** The table instance, put on the `diagnostic:emit` ctx. */\n table?: unknown\n /** Dev: the table's creation site. */\n createdAt?: string\n getContext?: () => LiveDiagnosticContext\n /** Dedupe is per data reference: a new reference reports known diagnostics again. */\n getDataRef?: () => unknown\n /** User sink (e.g. Sentry). Throwing is swallowed with one console.error. */\n onDiagnostic?: (d: Diagnostic) => void\n /** Rethrow error-level diagnostics as `DatakableError`. */\n strict?: boolean\n /** Default console sink. Default `true`. */\n console?: boolean\n /** Text builders + dev console format. Default: `process.env.NODE_ENV !== 'production'`. */\n dev?: boolean\n /**\n * Redaction policy (§8.2, `diagnostics.redact`): a level or `{ level, redact(path, value),\n * sensitiveColumns, rowKeySensitive }`. Default `'keys'` in development, `'safe'` in production.\n * Applied while the diagnostic is built, so `diagnostic:emit` interceptors, the `redact` seam and\n * every sink only see redacted data. `'full'` in production warns (`DK_UNSAFE_REDACTION`).\n */\n redaction?: RedactLevel | RedactionOptions\n /**\n * Extra whole-diagnostic rewrite after the `diagnostic:emit` interceptors, before dedupe and\n * sinks. It receives already-redacted data; `fingerprint` is not recomputed.\n */\n redact?: (d: Diagnostic) => Diagnostic\n /** Ring buffer size behind getDiagnostics(). Default 100. */\n bufferSize?: number\n /** Max fingerprints remembered for dedupe. Default 500. */\n dedupeLimit?: number\n /** Console rate limit. Default 20 per 1000 ms. */\n rateLimit?: { max: number; windowMs: number }\n now?: () => number\n}\n\nexport interface Diagnostics {\n /** Resolved table name (`context.table`). */\n readonly table: string\n /**\n * Emits a catalog diagnostic through `diagnostic:emit`. Returns the stored diagnostic (the\n * aggregated one on a dedupe hit), or `undefined` if an interceptor dropped it. Never throws,\n * except `DatakableError` under `strict: true`.\n */\n emit<C extends DiagnosticCode>(\n code: C,\n details: DiagnosticDetails<C>,\n options?: EmitOptions,\n ): Diagnostic | undefined\n /** Oldest first; at most `bufferSize` entries. */\n getDiagnostics(): Diagnostic[]\n /** Runs emits through this runtime's `diagnostic:emit` chain (user interceptors can redact/drop). */\n attach(runtime: InterceptorRuntime): void\n clear(): void\n}\n\nlet tableSeq = 0\n\n/**\n * One per table. Pipeline (§8.2): enrich + redact (build: context, policy redaction, then text,\n * where, fingerprint and docs from the redacted data) → `diagnostic:emit` interceptors → `redact`\n * seam → dedupe (aggregates `occurrences`) → ring buffer → sinks (onDiagnostic, console) → strict.\n */\nexport function createDiagnostics(options: DiagnosticsOptions = {}): Diagnostics {\n const table = options.name ?? `table#${++tableSeq}`\n const dev = options.dev ?? (process.env.NODE_ENV !== \"production\")\n const now = options.now ?? Date.now\n const dedupeLimit = options.dedupeLimit ?? 500\n const buffer = new RingBuffer<Diagnostic>(options.bufferSize ?? 100)\n const seen = new Map<string, Diagnostic>()\n const { onDiagnostic, getContext, getDataRef, redact, strict } = options\n const toConsole =\n options.console === false\n ? undefined\n : createConsoleSink({\n table,\n dev,\n now,\n rateLimit: options.rateLimit ?? { max: 20, windowMs: 1000 },\n })\n\n let runtime: InterceptorRuntime | undefined\n let depth = 0\n let lastRef: unknown\n let failed = false\n\n const fail = (e: unknown) => {\n // The logger never kills the table: one console.error, then silence.\n if (failed) return\n failed = true\n // Production prints the error name only: its message can embed row values (§8.2).\n console.error(\n `[DataKable ${table}] diagnostics pipeline failed; later failures are silent`,\n dev ? e : scrubError(e),\n )\n }\n\n function deliver(input: Diagnostic): Diagnostic {\n const d = redact ? redact(input) : input\n if (getDataRef) {\n const ref = getDataRef()\n if (ref !== lastRef) {\n seen.clear()\n lastRef = ref\n }\n }\n const prev = seen.get(d.fingerprint)\n if (prev) {\n prev.context.occurrences.count++\n prev.context.occurrences.last = d.context.occurrences.last\n return prev\n }\n seen.set(d.fingerprint, d)\n if (seen.size > dedupeLimit) seen.delete(seen.keys().next().value as string)\n buffer.push(d)\n if (onDiagnostic) {\n try {\n onDiagnostic(d)\n } catch (e) {\n fail(e)\n }\n }\n toConsole?.(d)\n return d\n }\n\n // Resolved per emit: sensitive columns and the rowKey can change with setOptions.\n const redactor = () => {\n const r = resolveRedaction(options.redaction, dev)\n r.onError = fail\n return r\n }\n\n const emit: Diagnostics['emit'] = (code, details, opts = {}) => {\n let out: Diagnostic | undefined\n try {\n const live = getContext?.() ?? {}\n const d = buildDiagnostic(code, details, {\n table,\n ...(options.createdAt === undefined ? {} : { createdAt: options.createdAt }),\n trigger: opts.trigger ?? live.trigger ?? 'init',\n run: opts.run ?? live.run ?? 0,\n phase: opts.phase ?? live.phase ?? defaultPhase(),\n ...(live.mode ? { mode: live.mode } : {}),\n ...(live.state ? { state: live.state } : {}),\n now: now(),\n ...(opts.cause === undefined ? {} : { cause: opts.cause }),\n ...(opts.causedBy === undefined ? {} : { causedBy: opts.causedBy }),\n dev,\n redaction: redactor(),\n })\n // Emits made while the chain runs (e.g. DK_INTERCEPTOR_FAILED for an interceptor on\n // diagnostic:emit) skip the chain, so a broken logger cannot recurse.\n if (runtime && depth === 0) {\n const c = d.context\n // ctx.where reaches slots, fingerprints and issue links unredacted: never the row key.\n const at = d.where.kind === 'row' ? { kind: 'row' as const, index: d.where.index } : d.where\n const ctx = createContext('diagnostic:emit', { diagnostic: d }, formatWhere(at), {\n table: options.table,\n run: c.run,\n trigger: c.trigger,\n phase: c.phase,\n emit,\n })\n depth++\n try {\n runtime.run('diagnostic:emit', ctx, (x) => {\n out = deliver(x.input.diagnostic)\n })\n } finally {\n depth--\n }\n } else {\n out = deliver(d)\n }\n } catch (e) {\n // strict: an error-level emit nested in the chain (e.g. DK_INTERCEPTOR_FAILED) still throws.\n if (strict && e instanceof DatakableError) throw e\n fail(e)\n return undefined\n }\n if (strict && out?.level === 'error') throw new DatakableError(out)\n return out\n }\n\n if (!dev && resolveRedaction(options.redaction, dev).level === 'full') {\n emit(DK_UNSAFE_REDACTION.code, { level: 'full' })\n }\n\n return {\n table,\n emit,\n getDiagnostics: () => buffer.toArray(),\n attach(rt) {\n runtime = rt\n },\n clear() {\n buffer.clear()\n seen.clear()\n },\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAA8B;AAE9B,mBAA2E;AAE3E,qBAAkC;AAClC,oBAMO;AACP,yBAA2B;AAuE3B,IAAI,WAAW;AAOR,SAAS,kBAAkB,UAA8B,CAAC,GAAgB;AAC/E,QAAM,QAAQ,QAAQ,QAAQ,SAAS,EAAE,QAAQ;AACjD,QAAM,MAAM,QAAQ,OAAQ,QAAQ,IAAI,aAAa;AACrD,QAAM,MAAM,QAAQ,OAAO,KAAK;AAChC,QAAM,cAAc,QAAQ,eAAe;AAC3C,QAAM,SAAS,IAAI,8BAAu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A,QACF;AAAA,MACF,OAAO;AACL,cAAM,QAAQ,CAAC;AAAA,MACjB;AAAA,IACF,SAAS,GAAG;AAEV,UAAI,UAAU,aAAa,4BAAgB,OAAM;AACjD,WAAK,CAAC;AACN,aAAO;AAAA,IACT;AACA,QAAI,UAAU,KAAK,UAAU,QAAS,OAAM,IAAI,4BAAe,GAAG;AAClE,WAAO;AAAA,EACT;AAEA,MAAI,CAAC,WAAO,gCAAiB,QAAQ,WAAW,GAAG,EAAE,UAAU,QAAQ;AACrE,SAAK,kCAAoB,MAAM,EAAE,OAAO,OAAO,CAAC;AAAA,EAClD;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,gBAAgB,MAAM,OAAO,QAAQ;AAAA,IACrC,OAAO,IAAI;AACT,gBAAU;AAAA,IACZ;AAAA,IACA,QAAQ;AACN,aAAO,MAAM;AACb,WAAK,MAAM;AAAA,IACb;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/diagnostics/hub.ts"],"sourcesContent":["import { createContext } from '../intercept/context'\nimport type { InterceptorRuntime } from '../intercept/runtime'\nimport { buildDiagnostic, DatakableError, defaultPhase, formatWhere, wallClock } from './build'\nimport type { DiagnosticCode, DiagnosticDetails } from './catalog'\nimport { createConsoleSink } from './console'\nimport './process-guard'\nimport {\n DK_UNSAFE_REDACTION,\n type RedactionOptions,\n type RedactLevel,\n resolveRedaction,\n scrubError,\n} from './redact'\nimport { RingBuffer } from './ring-buffer'\nimport type { Diagnostic, DiagnosticStateSummary, EmitOptions, Phase, Trigger } from './types'\n\n/** Live values the store supplies at emit time (T07+). Missing ones use defaults. */\nexport interface LiveDiagnosticContext {\n trigger?: Trigger\n run?: number\n phase?: Phase\n mode?: Record<string, 'client' | 'server'>\n state?: DiagnosticStateSummary\n}\n\nexport interface DiagnosticsOptions {\n /** `options.name` of the table; default `table#n`. */\n name?: string\n /** The table instance, put on the `diagnostic:emit` ctx. */\n table?: unknown\n /** Dev: the table's creation site. */\n createdAt?: string\n getContext?: () => LiveDiagnosticContext\n /** Dedupe is per data reference: a new reference reports known diagnostics again. */\n getDataRef?: () => unknown\n /** User sink (e.g. Sentry). Throwing is swallowed with one console.error. */\n onDiagnostic?: (d: Diagnostic) => void\n /** Rethrow error-level diagnostics as `DatakableError`. */\n strict?: boolean\n /** Default console sink. Default `true`. */\n console?: boolean\n /** Text builders + dev console format. Default: `process.env.NODE_ENV !== 'production'`. */\n dev?: boolean\n /**\n * Redaction policy (§8.2, `diagnostics.redact`): a level or `{ level, redact(path, value),\n * sensitiveColumns, rowKeySensitive }`. Default `'keys'` in development, `'safe'` in production.\n * Applied while the diagnostic is built, so `diagnostic:emit` interceptors, the `redact` seam and\n * every sink only see redacted data. `'full'` in production warns (`DK_UNSAFE_REDACTION`).\n */\n redaction?: RedactLevel | RedactionOptions\n /**\n * Extra whole-diagnostic rewrite after the `diagnostic:emit` interceptors, before dedupe and\n * sinks. It receives already-redacted data; `fingerprint` is not recomputed.\n */\n redact?: (d: Diagnostic) => Diagnostic\n /** Ring buffer size behind getDiagnostics(). Default 100. */\n bufferSize?: number\n /** Max fingerprints remembered for dedupe. Default 500. */\n dedupeLimit?: number\n /** Console rate limit. Default 20 per 1000 ms. */\n rateLimit?: { max: number; windowMs: number }\n /** Clock (epoch ms) for `occurrences` and the rate limit. Default `wallClock` (never `Date`, #7). */\n now?: () => number\n}\n\nexport interface Diagnostics {\n /** Resolved table name (`context.table`). */\n readonly table: string\n /**\n * Emits a catalog diagnostic through `diagnostic:emit`. Returns the stored diagnostic (the\n * aggregated one on a dedupe hit), or `undefined` if an interceptor dropped it. Never throws,\n * except `DatakableError` under `strict: true`.\n */\n emit<C extends DiagnosticCode>(\n code: C,\n details: DiagnosticDetails<C>,\n options?: EmitOptions,\n ): Diagnostic | undefined\n /** Oldest first; at most `bufferSize` entries. */\n getDiagnostics(): Diagnostic[]\n /** Runs emits through this runtime's `diagnostic:emit` chain (user interceptors can redact/drop). */\n attach(runtime: InterceptorRuntime): void\n clear(): void\n}\n\nlet tableSeq = 0\n\n/**\n * One per table. Pipeline (§8.2): enrich + redact (build: context, policy redaction, then text,\n * where, fingerprint and docs from the redacted data) → `diagnostic:emit` interceptors → `redact`\n * seam → dedupe (aggregates `occurrences`) → ring buffer → sinks (onDiagnostic, console) → strict.\n */\nexport function createDiagnostics(options: DiagnosticsOptions = {}): Diagnostics {\n const table = options.name ?? `table#${++tableSeq}`\n const dev = options.dev ?? (process.env.NODE_ENV !== \"production\")\n const now = options.now ?? wallClock\n const dedupeLimit = options.dedupeLimit ?? 500\n const buffer = new RingBuffer<Diagnostic>(options.bufferSize ?? 100)\n const seen = new Map<string, Diagnostic>()\n const { onDiagnostic, getContext, getDataRef, redact, strict } = options\n const toConsole =\n options.console === false\n ? undefined\n : createConsoleSink({\n table,\n dev,\n now,\n rateLimit: options.rateLimit ?? { max: 20, windowMs: 1000 },\n })\n\n let runtime: InterceptorRuntime | undefined\n let depth = 0\n let lastRef: unknown\n let failed = false\n\n const fail = (e: unknown) => {\n // The logger never kills the table: one console.error, then silence.\n if (failed) return\n failed = true\n // Production prints the error name only: its message can embed row values (§8.2).\n console.error(\n `[DataKable ${table}] diagnostics pipeline failed; later failures are silent`,\n dev ? e : scrubError(e),\n )\n }\n\n function deliver(input: Diagnostic, quiet?: boolean): Diagnostic {\n const d = redact ? redact(input) : input\n if (getDataRef) {\n const ref = getDataRef()\n if (ref !== lastRef) {\n seen.clear()\n lastRef = ref\n }\n }\n const prev = seen.get(d.fingerprint)\n if (prev) {\n prev.context.occurrences.count++\n prev.context.occurrences.last = d.context.occurrences.last\n return prev\n }\n seen.set(d.fingerprint, d)\n if (seen.size > dedupeLimit) seen.delete(seen.keys().next().value as string)\n buffer.push(d)\n if (onDiagnostic) {\n try {\n onDiagnostic(d)\n } catch (e) {\n fail(e)\n }\n }\n if (!quiet) toConsole?.(d)\n return d\n }\n\n // Resolved per emit: sensitive columns and the rowKey can change with setOptions.\n const redactor = () => {\n const r = resolveRedaction(options.redaction, dev)\n r.onError = fail\n return r\n }\n\n const emit: Diagnostics['emit'] = (code, details, opts = {}) => {\n let out: Diagnostic | undefined\n try {\n const live = getContext?.() ?? {}\n const d = buildDiagnostic(code, details, {\n table,\n ...(options.createdAt === undefined ? {} : { createdAt: options.createdAt }),\n trigger: opts.trigger ?? live.trigger ?? 'init',\n run: opts.run ?? live.run ?? 0,\n phase: opts.phase ?? live.phase ?? defaultPhase(),\n ...(live.mode ? { mode: live.mode } : {}),\n ...(live.state ? { state: live.state } : {}),\n now: now(),\n ...(opts.cause === undefined ? {} : { cause: opts.cause }),\n ...(opts.causedBy === undefined ? {} : { causedBy: opts.causedBy }),\n dev,\n redaction: redactor(),\n })\n // Emits made while the chain runs (e.g. DK_INTERCEPTOR_FAILED for an interceptor on\n // diagnostic:emit) skip the chain, so a broken logger cannot recurse.\n if (runtime && depth === 0) {\n const c = d.context\n // ctx.where reaches slots, fingerprints and issue links unredacted: never the row key.\n const at = d.where.kind === 'row' ? { kind: 'row' as const, index: d.where.index } : d.where\n const ctx = createContext('diagnostic:emit', { diagnostic: d }, formatWhere(at), {\n table: options.table,\n run: c.run,\n trigger: c.trigger,\n phase: c.phase,\n emit,\n })\n depth++\n try {\n runtime.run('diagnostic:emit', ctx, (x) => {\n out = deliver(x.input.diagnostic, opts.quiet)\n })\n } finally {\n depth--\n }\n } else {\n out = deliver(d, opts.quiet)\n }\n } catch (e) {\n // strict: an error-level emit nested in the chain (e.g. DK_INTERCEPTOR_FAILED) still throws.\n if (strict && e instanceof DatakableError) throw e\n fail(e)\n return undefined\n }\n if (strict && out?.level === 'error') throw new DatakableError(out)\n return out\n }\n\n if (!dev && resolveRedaction(options.redaction, dev).level === 'full') {\n emit(DK_UNSAFE_REDACTION.code, { level: 'full' })\n }\n\n return {\n table,\n emit,\n getDiagnostics: () => buffer.toArray(),\n attach(rt) {\n runtime = rt\n },\n clear() {\n buffer.clear()\n seen.clear()\n },\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;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Q,EAAE,MAAM,OAAgB,OAAO,EAAE,MAAM,MAAM,IAAI,EAAE;AACvF,cAAM,UAAM,8BAAc,mBAAmB,EAAE,YAAY,EAAE,OAAG,0BAAY,EAAE,GAAG;AAAA,UAC/E,OAAO,QAAQ;AAAA,UACf,KAAK,EAAE;AAAA,UACP,SAAS,EAAE;AAAA,UACX,OAAO,EAAE;AAAA,UACT;AAAA,QACF,CAAC;AACD;AACA,YAAI;AACF,kBAAQ,IAAI,mBAAmB,KAAK,CAAC,MAAM;AACzC,kBAAM,QAAQ,EAAE,MAAM,YAAY,KAAK,KAAK;AAAA,UAC9C,CAAC;AAAA,QACH,UAAE;AACA;AAAA,QACF;AAAA,MACF,OAAO;AACL,cAAM,QAAQ,GAAG,KAAK,KAAK;AAAA,MAC7B;AAAA,IACF,SAAS,GAAG;AAEV,UAAI,UAAU,aAAa,4BAAgB,OAAM;AACjD,WAAK,CAAC;AACN,aAAO;AAAA,IACT;AACA,QAAI,UAAU,KAAK,UAAU,QAAS,OAAM,IAAI,4BAAe,GAAG;AAClE,WAAO;AAAA,EACT;AAEA,MAAI,CAAC,WAAO,gCAAiB,QAAQ,WAAW,GAAG,EAAE,UAAU,QAAQ;AACrE,SAAK,kCAAoB,MAAM,EAAE,OAAO,OAAO,CAAC;AAAA,EAClD;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,gBAAgB,MAAM,OAAO,QAAQ;AAAA,IACrC,OAAO,IAAI;AACT,gBAAU;AAAA,IACZ;AAAA,IACA,QAAQ;AACN,aAAO,MAAM;AACb,WAAK,MAAM;AAAA,IACb;AAAA,EACF;AACF;","names":[]}
@@ -1,7 +1,8 @@
1
1
  // src/diagnostics/hub.ts
2
2
  import { createContext } from "../intercept/context.js";
3
- import { buildDiagnostic, DatakableError, defaultPhase, formatWhere } from "./build.js";
3
+ import { buildDiagnostic, DatakableError, defaultPhase, formatWhere, wallClock } from "./build.js";
4
4
  import { createConsoleSink } from "./console.js";
5
+ import "./process-guard.js";
5
6
  import {
6
7
  DK_UNSAFE_REDACTION,
7
8
  resolveRedaction,
@@ -12,7 +13,7 @@ var tableSeq = 0;
12
13
  function createDiagnostics(options = {}) {
13
14
  const table = options.name ?? `table#${++tableSeq}`;
14
15
  const dev = options.dev ?? process.env.NODE_ENV !== "production";
15
- const now = options.now ?? Date.now;
16
+ const now = options.now ?? wallClock;
16
17
  const dedupeLimit = options.dedupeLimit ?? 500;
17
18
  const buffer = new RingBuffer(options.bufferSize ?? 100);
18
19
  const seen = /* @__PURE__ */ new Map();
@@ -35,7 +36,7 @@ function createDiagnostics(options = {}) {
35
36
  dev ? e : scrubError(e)
36
37
  );
37
38
  };
38
- function deliver(input) {
39
+ function deliver(input, quiet) {
39
40
  const d = redact ? redact(input) : input;
40
41
  if (getDataRef) {
41
42
  const ref = getDataRef();
@@ -60,7 +61,7 @@ function createDiagnostics(options = {}) {
60
61
  fail(e);
61
62
  }
62
63
  }
63
- toConsole?.(d);
64
+ if (!quiet) toConsole?.(d);
64
65
  return d;
65
66
  }
66
67
  const redactor = () => {
@@ -99,13 +100,13 @@ function createDiagnostics(options = {}) {
99
100
  depth++;
100
101
  try {
101
102
  runtime.run("diagnostic:emit", ctx, (x) => {
102
- out = deliver(x.input.diagnostic);
103
+ out = deliver(x.input.diagnostic, opts.quiet);
103
104
  });
104
105
  } finally {
105
106
  depth--;
106
107
  }
107
108
  } else {
108
- out = deliver(d);
109
+ out = deliver(d, opts.quiet);
109
110
  }
110
111
  } catch (e) {
111
112
  if (strict && e instanceof DatakableError) throw e;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/diagnostics/hub.ts"],"sourcesContent":["import { createContext } from '../intercept/context'\nimport type { InterceptorRuntime } from '../intercept/runtime'\nimport { buildDiagnostic, DatakableError, defaultPhase, formatWhere } from './build'\nimport type { DiagnosticCode, DiagnosticDetails } from './catalog'\nimport { createConsoleSink } from './console'\nimport {\n DK_UNSAFE_REDACTION,\n type RedactionOptions,\n type RedactLevel,\n resolveRedaction,\n scrubError,\n} from './redact'\nimport { RingBuffer } from './ring-buffer'\nimport type { Diagnostic, DiagnosticStateSummary, EmitOptions, Phase, Trigger } from './types'\n\n/** Live values the store supplies at emit time (T07+). Missing ones use defaults. */\nexport interface LiveDiagnosticContext {\n trigger?: Trigger\n run?: number\n phase?: Phase\n mode?: Record<string, 'client' | 'server'>\n state?: DiagnosticStateSummary\n}\n\nexport interface DiagnosticsOptions {\n /** `options.name` of the table; default `table#n`. */\n name?: string\n /** The table instance, put on the `diagnostic:emit` ctx. */\n table?: unknown\n /** Dev: the table's creation site. */\n createdAt?: string\n getContext?: () => LiveDiagnosticContext\n /** Dedupe is per data reference: a new reference reports known diagnostics again. */\n getDataRef?: () => unknown\n /** User sink (e.g. Sentry). Throwing is swallowed with one console.error. */\n onDiagnostic?: (d: Diagnostic) => void\n /** Rethrow error-level diagnostics as `DatakableError`. */\n strict?: boolean\n /** Default console sink. Default `true`. */\n console?: boolean\n /** Text builders + dev console format. Default: `process.env.NODE_ENV !== 'production'`. */\n dev?: boolean\n /**\n * Redaction policy (§8.2, `diagnostics.redact`): a level or `{ level, redact(path, value),\n * sensitiveColumns, rowKeySensitive }`. Default `'keys'` in development, `'safe'` in production.\n * Applied while the diagnostic is built, so `diagnostic:emit` interceptors, the `redact` seam and\n * every sink only see redacted data. `'full'` in production warns (`DK_UNSAFE_REDACTION`).\n */\n redaction?: RedactLevel | RedactionOptions\n /**\n * Extra whole-diagnostic rewrite after the `diagnostic:emit` interceptors, before dedupe and\n * sinks. It receives already-redacted data; `fingerprint` is not recomputed.\n */\n redact?: (d: Diagnostic) => Diagnostic\n /** Ring buffer size behind getDiagnostics(). Default 100. */\n bufferSize?: number\n /** Max fingerprints remembered for dedupe. Default 500. */\n dedupeLimit?: number\n /** Console rate limit. Default 20 per 1000 ms. */\n rateLimit?: { max: number; windowMs: number }\n now?: () => number\n}\n\nexport interface Diagnostics {\n /** Resolved table name (`context.table`). */\n readonly table: string\n /**\n * Emits a catalog diagnostic through `diagnostic:emit`. Returns the stored diagnostic (the\n * aggregated one on a dedupe hit), or `undefined` if an interceptor dropped it. Never throws,\n * except `DatakableError` under `strict: true`.\n */\n emit<C extends DiagnosticCode>(\n code: C,\n details: DiagnosticDetails<C>,\n options?: EmitOptions,\n ): Diagnostic | undefined\n /** Oldest first; at most `bufferSize` entries. */\n getDiagnostics(): Diagnostic[]\n /** Runs emits through this runtime's `diagnostic:emit` chain (user interceptors can redact/drop). */\n attach(runtime: InterceptorRuntime): void\n clear(): void\n}\n\nlet tableSeq = 0\n\n/**\n * One per table. Pipeline (§8.2): enrich + redact (build: context, policy redaction, then text,\n * where, fingerprint and docs from the redacted data) → `diagnostic:emit` interceptors → `redact`\n * seam → dedupe (aggregates `occurrences`) → ring buffer → sinks (onDiagnostic, console) → strict.\n */\nexport function createDiagnostics(options: DiagnosticsOptions = {}): Diagnostics {\n const table = options.name ?? `table#${++tableSeq}`\n const dev = options.dev ?? (process.env.NODE_ENV !== \"production\")\n const now = options.now ?? Date.now\n const dedupeLimit = options.dedupeLimit ?? 500\n const buffer = new RingBuffer<Diagnostic>(options.bufferSize ?? 100)\n const seen = new Map<string, Diagnostic>()\n const { onDiagnostic, getContext, getDataRef, redact, strict } = options\n const toConsole =\n options.console === false\n ? undefined\n : createConsoleSink({\n table,\n dev,\n now,\n rateLimit: options.rateLimit ?? { max: 20, windowMs: 1000 },\n })\n\n let runtime: InterceptorRuntime | undefined\n let depth = 0\n let lastRef: unknown\n let failed = false\n\n const fail = (e: unknown) => {\n // The logger never kills the table: one console.error, then silence.\n if (failed) return\n failed = true\n // Production prints the error name only: its message can embed row values (§8.2).\n console.error(\n `[DataKable ${table}] diagnostics pipeline failed; later failures are silent`,\n dev ? e : scrubError(e),\n )\n }\n\n function deliver(input: Diagnostic): Diagnostic {\n const d = redact ? redact(input) : input\n if (getDataRef) {\n const ref = getDataRef()\n if (ref !== lastRef) {\n seen.clear()\n lastRef = ref\n }\n }\n const prev = seen.get(d.fingerprint)\n if (prev) {\n prev.context.occurrences.count++\n prev.context.occurrences.last = d.context.occurrences.last\n return prev\n }\n seen.set(d.fingerprint, d)\n if (seen.size > dedupeLimit) seen.delete(seen.keys().next().value as string)\n buffer.push(d)\n if (onDiagnostic) {\n try {\n onDiagnostic(d)\n } catch (e) {\n fail(e)\n }\n }\n toConsole?.(d)\n return d\n }\n\n // Resolved per emit: sensitive columns and the rowKey can change with setOptions.\n const redactor = () => {\n const r = resolveRedaction(options.redaction, dev)\n r.onError = fail\n return r\n }\n\n const emit: Diagnostics['emit'] = (code, details, opts = {}) => {\n let out: Diagnostic | undefined\n try {\n const live = getContext?.() ?? {}\n const d = buildDiagnostic(code, details, {\n table,\n ...(options.createdAt === undefined ? {} : { createdAt: options.createdAt }),\n trigger: opts.trigger ?? live.trigger ?? 'init',\n run: opts.run ?? live.run ?? 0,\n phase: opts.phase ?? live.phase ?? defaultPhase(),\n ...(live.mode ? { mode: live.mode } : {}),\n ...(live.state ? { state: live.state } : {}),\n now: now(),\n ...(opts.cause === undefined ? {} : { cause: opts.cause }),\n ...(opts.causedBy === undefined ? {} : { causedBy: opts.causedBy }),\n dev,\n redaction: redactor(),\n })\n // Emits made while the chain runs (e.g. DK_INTERCEPTOR_FAILED for an interceptor on\n // diagnostic:emit) skip the chain, so a broken logger cannot recurse.\n if (runtime && depth === 0) {\n const c = d.context\n // ctx.where reaches slots, fingerprints and issue links unredacted: never the row key.\n const at = d.where.kind === 'row' ? { kind: 'row' as const, index: d.where.index } : d.where\n const ctx = createContext('diagnostic:emit', { diagnostic: d }, formatWhere(at), {\n table: options.table,\n run: c.run,\n trigger: c.trigger,\n phase: c.phase,\n emit,\n })\n depth++\n try {\n runtime.run('diagnostic:emit', ctx, (x) => {\n out = deliver(x.input.diagnostic)\n })\n } finally {\n depth--\n }\n } else {\n out = deliver(d)\n }\n } catch (e) {\n // strict: an error-level emit nested in the chain (e.g. DK_INTERCEPTOR_FAILED) still throws.\n if (strict && e instanceof DatakableError) throw e\n fail(e)\n return undefined\n }\n if (strict && out?.level === 'error') throw new DatakableError(out)\n return out\n }\n\n if (!dev && resolveRedaction(options.redaction, dev).level === 'full') {\n emit(DK_UNSAFE_REDACTION.code, { level: 'full' })\n }\n\n return {\n table,\n emit,\n getDiagnostics: () => buffer.toArray(),\n attach(rt) {\n runtime = rt\n },\n clear() {\n buffer.clear()\n seen.clear()\n },\n }\n}\n"],"mappings":";AAAA,SAAS,qBAAqB;AAE9B,SAAS,iBAAiB,gBAAgB,cAAc,mBAAmB;AAE3E,SAAS,yBAAyB;AAClC;AAAA,EACE;AAAA,EAGA;AAAA,EACA;AAAA,OACK;AACP,SAAS,kBAAkB;AAuE3B,IAAI,WAAW;AAOR,SAAS,kBAAkB,UAA8B,CAAC,GAAgB;AAC/E,QAAM,QAAQ,QAAQ,QAAQ,SAAS,EAAE,QAAQ;AACjD,QAAM,MAAM,QAAQ,OAAQ,QAAQ,IAAI,aAAa;AACrD,QAAM,MAAM,QAAQ,OAAO,KAAK;AAChC,QAAM,cAAc,QAAQ,eAAe;AAC3C,QAAM,SAAS,IAAI,WAAuB,QAAQ,cAAc,GAAG;AACnE,QAAM,OAAO,oBAAI,IAAwB;AACzC,QAAM,EAAE,cAAc,YAAY,YAAY,QAAQ,OAAO,IAAI;AACjE,QAAM,YACJ,QAAQ,YAAY,QAChB,SACA,kBAAkB;AAAA,IAChB;AAAA,IACA;AAAA,IACA;AAAA,IACA,WAAW,QAAQ,aAAa,EAAE,KAAK,IAAI,UAAU,IAAK;AAAA,EAC5D,CAAC;AAEP,MAAI;AACJ,MAAI,QAAQ;AACZ,MAAI;AACJ,MAAI,SAAS;AAEb,QAAM,OAAO,CAAC,MAAe;AAE3B,QAAI,OAAQ;AACZ,aAAS;AAET,YAAQ;AAAA,MACN,cAAc,KAAK;AAAA,MACnB,MAAM,IAAI,WAAW,CAAC;AAAA,IACxB;AAAA,EACF;AAEA,WAAS,QAAQ,OAA+B;AAC9C,UAAM,IAAI,SAAS,OAAO,KAAK,IA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A,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/diagnostics/hub.ts"],"sourcesContent":["import { createContext } from '../intercept/context'\nimport type { InterceptorRuntime } from '../intercept/runtime'\nimport { buildDiagnostic, DatakableError, defaultPhase, formatWhere, wallClock } from './build'\nimport type { DiagnosticCode, DiagnosticDetails } from './catalog'\nimport { createConsoleSink } from './console'\nimport './process-guard'\nimport {\n DK_UNSAFE_REDACTION,\n type RedactionOptions,\n type RedactLevel,\n resolveRedaction,\n scrubError,\n} from './redact'\nimport { RingBuffer } from './ring-buffer'\nimport type { Diagnostic, DiagnosticStateSummary, EmitOptions, Phase, Trigger } from './types'\n\n/** Live values the store supplies at emit time (T07+). Missing ones use defaults. */\nexport interface LiveDiagnosticContext {\n trigger?: Trigger\n run?: number\n phase?: Phase\n mode?: Record<string, 'client' | 'server'>\n state?: DiagnosticStateSummary\n}\n\nexport interface DiagnosticsOptions {\n /** `options.name` of the table; default `table#n`. */\n name?: string\n /** The table instance, put on the `diagnostic:emit` ctx. */\n table?: unknown\n /** Dev: the table's creation site. */\n createdAt?: string\n getContext?: () => LiveDiagnosticContext\n /** Dedupe is per data reference: a new reference reports known diagnostics again. */\n getDataRef?: () => unknown\n /** User sink (e.g. Sentry). Throwing is swallowed with one console.error. */\n onDiagnostic?: (d: Diagnostic) => void\n /** Rethrow error-level diagnostics as `DatakableError`. */\n strict?: boolean\n /** Default console sink. Default `true`. */\n console?: boolean\n /** Text builders + dev console format. Default: `process.env.NODE_ENV !== 'production'`. */\n dev?: boolean\n /**\n * Redaction policy (§8.2, `diagnostics.redact`): a level or `{ level, redact(path, value),\n * sensitiveColumns, rowKeySensitive }`. Default `'keys'` in development, `'safe'` in production.\n * Applied while the diagnostic is built, so `diagnostic:emit` interceptors, the `redact` seam and\n * every sink only see redacted data. `'full'` in production warns (`DK_UNSAFE_REDACTION`).\n */\n redaction?: RedactLevel | RedactionOptions\n /**\n * Extra whole-diagnostic rewrite after the `diagnostic:emit` interceptors, before dedupe and\n * sinks. It receives already-redacted data; `fingerprint` is not recomputed.\n */\n redact?: (d: Diagnostic) => Diagnostic\n /** Ring buffer size behind getDiagnostics(). Default 100. */\n bufferSize?: number\n /** Max fingerprints remembered for dedupe. Default 500. */\n dedupeLimit?: number\n /** Console rate limit. Default 20 per 1000 ms. */\n rateLimit?: { max: number; windowMs: number }\n /** Clock (epoch ms) for `occurrences` and the rate limit. Default `wallClock` (never `Date`, #7). */\n now?: () => number\n}\n\nexport interface Diagnostics {\n /** Resolved table name (`context.table`). */\n readonly table: string\n /**\n * Emits a catalog diagnostic through `diagnostic:emit`. Returns the stored diagnostic (the\n * aggregated one on a dedupe hit), or `undefined` if an interceptor dropped it. Never throws,\n * except `DatakableError` under `strict: true`.\n */\n emit<C extends DiagnosticCode>(\n code: C,\n details: DiagnosticDetails<C>,\n options?: EmitOptions,\n ): Diagnostic | undefined\n /** Oldest first; at most `bufferSize` entries. */\n getDiagnostics(): Diagnostic[]\n /** Runs emits through this runtime's `diagnostic:emit` chain (user interceptors can redact/drop). */\n attach(runtime: InterceptorRuntime): void\n clear(): void\n}\n\nlet tableSeq = 0\n\n/**\n * One per table. Pipeline (§8.2): enrich + redact (build: context, policy redaction, then text,\n * where, fingerprint and docs from the redacted data) → `diagnostic:emit` interceptors → `redact`\n * seam → dedupe (aggregates `occurrences`) → ring buffer → sinks (onDiagnostic, console) → strict.\n */\nexport function createDiagnostics(options: DiagnosticsOptions = {}): Diagnostics {\n const table = options.name ?? `table#${++tableSeq}`\n const dev = options.dev ?? (process.env.NODE_ENV !== \"production\")\n const now = options.now ?? wallClock\n const dedupeLimit = options.dedupeLimit ?? 500\n const buffer = new RingBuffer<Diagnostic>(options.bufferSize ?? 100)\n const seen = new Map<string, Diagnostic>()\n const { onDiagnostic, getContext, getDataRef, redact, strict } = options\n const toConsole =\n options.console === false\n ? undefined\n : createConsoleSink({\n table,\n dev,\n now,\n rateLimit: options.rateLimit ?? { max: 20, windowMs: 1000 },\n })\n\n let runtime: InterceptorRuntime | undefined\n let depth = 0\n let lastRef: unknown\n let failed = false\n\n const fail = (e: unknown) => {\n // The logger never kills the table: one console.error, then silence.\n if (failed) return\n failed = true\n // Production prints the error name only: its message can embed row values (§8.2).\n console.error(\n `[DataKable ${table}] diagnostics pipeline failed; later failures are silent`,\n dev ? e : scrubError(e),\n )\n }\n\n function deliver(input: Diagnostic, quiet?: boolean): Diagnostic {\n const d = redact ? redact(input) : input\n if (getDataRef) {\n const ref = getDataRef()\n if (ref !== lastRef) {\n seen.clear()\n lastRef = ref\n }\n }\n const prev = seen.get(d.fingerprint)\n if (prev) {\n prev.context.occurrences.count++\n prev.context.occurrences.last = d.context.occurrences.last\n return prev\n }\n seen.set(d.fingerprint, d)\n if (seen.size > dedupeLimit) seen.delete(seen.keys().next().value as string)\n buffer.push(d)\n if (onDiagnostic) {\n try {\n onDiagnostic(d)\n } catch (e) {\n fail(e)\n }\n }\n if (!quiet) toConsole?.(d)\n return d\n }\n\n // Resolved per emit: sensitive columns and the rowKey can change with setOptions.\n const redactor = () => {\n const r = resolveRedaction(options.redaction, dev)\n r.onError = fail\n return r\n }\n\n const emit: Diagnostics['emit'] = (code, details, opts = {}) => {\n let out: Diagnostic | undefined\n try {\n const live = getContext?.() ?? {}\n const d = buildDiagnostic(code, details, {\n table,\n ...(options.createdAt === undefined ? {} : { createdAt: options.createdAt }),\n trigger: opts.trigger ?? live.trigger ?? 'init',\n run: opts.run ?? live.run ?? 0,\n phase: opts.phase ?? live.phase ?? defaultPhase(),\n ...(live.mode ? { mode: live.mode } : {}),\n ...(live.state ? { state: live.state } : {}),\n now: now(),\n ...(opts.cause === undefined ? {} : { cause: opts.cause }),\n ...(opts.causedBy === undefined ? {} : { causedBy: opts.causedBy }),\n dev,\n redaction: redactor(),\n })\n // Emits made while the chain runs (e.g. DK_INTERCEPTOR_FAILED for an interceptor on\n // diagnostic:emit) skip the chain, so a broken logger cannot recurse.\n if (runtime && depth === 0) {\n const c = d.context\n // ctx.where reaches slots, fingerprints and issue links unredacted: never the row key.\n const at = d.where.kind === 'row' ? { kind: 'row' as const, index: d.where.index } : d.where\n const ctx = createContext('diagnostic:emit', { diagnostic: d }, formatWhere(at), {\n table: options.table,\n run: c.run,\n trigger: c.trigger,\n phase: c.phase,\n emit,\n })\n depth++\n try {\n runtime.run('diagnostic:emit', ctx, (x) => {\n out = deliver(x.input.diagnostic, opts.quiet)\n })\n } finally {\n depth--\n }\n } else {\n out = deliver(d, opts.quiet)\n }\n } catch (e) {\n // strict: an error-level emit nested in the chain (e.g. DK_INTERCEPTOR_FAILED) still throws.\n if (strict && e instanceof DatakableError) throw e\n fail(e)\n return undefined\n }\n if (strict && out?.level === 'error') throw new DatakableError(out)\n return out\n }\n\n if (!dev && resolveRedaction(options.redaction, dev).level === 'full') {\n emit(DK_UNSAFE_REDACTION.code, { level: 'full' })\n }\n\n return {\n table,\n emit,\n getDiagnostics: () => buffer.toArray(),\n attach(rt) {\n runtime = rt\n },\n clear() {\n buffer.clear()\n seen.clear()\n },\n }\n}\n"],"mappings":";AAAA,SAAS,qBAAqB;AAE9B,SAAS,iBAAiB,gBAAgB,cAAc,aAAa,iBAAiB;AAEtF,SAAS,yBAAyB;AAClC,OAAO;AACP;AAAA,EACE;AAAA,EAGA;AAAA,EACA;AAAA,OACK;AACP,SAAS,kBAAkB;AAwE3B,IAAI,WAAW;AAOR,SAAS,kBAAkB,UAA8B,CAAC,GAAgB;AAC/E,QAAM,QAAQ,QAAQ,QAAQ,SAAS,EAAE,QAAQ;AACjD,QAAM,MAAM,QAAQ,OAAQ,QAAQ,IAAI,aAAa;AACrD,QAAM,MAAM,QAAQ,OAAO;AAC3B,QAAM,cAAc,QAAQ,eAAe;AAC3C,QAAM,SAAS,IAAI,WAAuB,QAAQ,cAAc,GAAG;AACnE,QAAM,OAAO,oBAAI,IAAwB;AACzC,QAAM,EAAE,cAAc,YAAY,YAAY,QAAQ,OAAO,IAAI;AACjE,QAAM,YACJ,QAAQ,YAAY,QAChB,SACA,k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,eAAgB,OAAM;AACjD,WAAK,CAAC;AACN,aAAO;AAAA,IACT;AACA,QAAI,UAAU,KAAK,UAAU,QAAS,OAAM,IAAI,eAAe,GAAG;AAClE,WAAO;AAAA,EACT;AAEA,MAAI,CAAC,OAAO,iBAAiB,QAAQ,WAAW,GAAG,EAAE,UAAU,QAAQ;AACrE,SAAK,oBAAoB,MAAM,EAAE,OAAO,OAAO,CAAC;AAAA,EAClD;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,gBAAgB,MAAM,OAAO,QAAQ;AAAA,IACrC,OAAO,IAAI;AACT,gBAAU;AAAA,IACZ;AAAA,IACA,QAAQ;AACN,aAAO,MAAM;AACb,WAAK,MAAM;AAAA,IACb;AAAA,EACF;AACF;","names":[]}
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+
16
+ // src/diagnostics/process-guard.ts
17
+ var process_guard_exports = {};
18
+ module.exports = __toCommonJS(process_guard_exports);
19
+ try {
20
+ process.env.NODE_ENV;
21
+ } catch {
22
+ throw new ReferenceError(
23
+ `[DataKable] process is not defined: replace process.env.NODE_ENV at build time (e.g. esbuild --define:process.env.NODE_ENV='"production"'), or set globalThis.process = { env: { NODE_ENV: 'production' } } before DataKable loads. See https://github.com/Ink01101011/datakable/blob/main/docs/how-to-fix/process-is-not-defined.md`
24
+ );
25
+ }
26
+ //# sourceMappingURL=process-guard.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/diagnostics/process-guard.ts"],"sourcesContent":["// No @types/node in core: declare just what is read.\ndeclare const process: { env: { NODE_ENV?: string } }\n\n/*\n * Code run without a bundler (CDN, import map) has no `process`: say so and name the fix, instead\n * of the engine's bare \"process is not defined\" (#36).\n *\n * Every module that reads `DEV` imports this module first (the build rewrites `import { DEV } from\n * './env'` to `import './process-guard'`, see scripts/preserve-modules.mjs), so it is evaluated\n * before any `process.env.NODE_ENV` read. It is listed in `sideEffects`, so a bundler run without\n * the replacement (esbuild without --define) keeps it too. Once `process.env.NODE_ENV` is replaced\n * with a literal the `try` body is empty and a minifier removes the statement: production bundles\n * pay nothing (`pnpm check:size`).\n */\ntry {\n process.env.NODE_ENV\n} catch {\n throw new ReferenceError(\n '[DataKable] process is not defined: replace process.env.NODE_ENV at build time (e.g. ' +\n `esbuild --define:process.env.NODE_ENV='\"production\"'), or set globalThis.process = ` +\n \"{ env: { NODE_ENV: 'production' } } before DataKable loads. See \" +\n 'https://github.com/Ink01101011/datakable/blob/main/docs/how-to-fix/process-is-not-defined.md',\n )\n}\n\n// A module, not a script: keeps the `process` declaration above local to this file.\nexport {}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;AAcA,IAAI;AACF,UAAQ,IAAI;AACd,QAAQ;AACN,QAAM,IAAI;AAAA,IACR;AAAA,EAIF;AACF;","names":[]}
@@ -0,0 +1,9 @@
1
+ // src/diagnostics/process-guard.ts
2
+ try {
3
+ process.env.NODE_ENV;
4
+ } catch {
5
+ throw new ReferenceError(
6
+ `[DataKable] process is not defined: replace process.env.NODE_ENV at build time (e.g. esbuild --define:process.env.NODE_ENV='"production"'), or set globalThis.process = { env: { NODE_ENV: 'production' } } before DataKable loads. See https://github.com/Ink01101011/datakable/blob/main/docs/how-to-fix/process-is-not-defined.md`
7
+ );
8
+ }
9
+ //# sourceMappingURL=process-guard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/diagnostics/process-guard.ts"],"sourcesContent":["// No @types/node in core: declare just what is read.\ndeclare const process: { env: { NODE_ENV?: string } }\n\n/*\n * Code run without a bundler (CDN, import map) has no `process`: say so and name the fix, instead\n * of the engine's bare \"process is not defined\" (#36).\n *\n * Every module that reads `DEV` imports this module first (the build rewrites `import { DEV } from\n * './env'` to `import './process-guard'`, see scripts/preserve-modules.mjs), so it is evaluated\n * before any `process.env.NODE_ENV` read. It is listed in `sideEffects`, so a bundler run without\n * the replacement (esbuild without --define) keeps it too. Once `process.env.NODE_ENV` is replaced\n * with a literal the `try` body is empty and a minifier removes the statement: production bundles\n * pay nothing (`pnpm check:size`).\n */\ntry {\n process.env.NODE_ENV\n} catch {\n throw new ReferenceError(\n '[DataKable] process is not defined: replace process.env.NODE_ENV at build time (e.g. ' +\n `esbuild --define:process.env.NODE_ENV='\"production\"'), or set globalThis.process = ` +\n \"{ env: { NODE_ENV: 'production' } } before DataKable loads. See \" +\n 'https://github.com/Ink01101011/datakable/blob/main/docs/how-to-fix/process-is-not-defined.md',\n )\n}\n\n// A module, not a script: keeps the `process` declaration above local to this file.\nexport {}\n"],"mappings":";AAcA,IAAI;AACF,UAAQ,IAAI;AACd,QAAQ;AACN,QAAM,IAAI;AAAA,IACR;AAAA,EAIF;AACF;","names":[]}
@@ -0,0 +1,120 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/diagnostics/prose.ts
21
+ var prose_exports = {};
22
+ __export(prose_exports, {
23
+ expandDetails: () => expandDetails,
24
+ expandProse: () => expandProse,
25
+ proseMessages: () => proseMessages
26
+ });
27
+ module.exports = __toCommonJS(prose_exports);
28
+ var import_catalog = require("./catalog.cjs");
29
+ var import_process_guard = require("./process-guard.cjs");
30
+ var proseMessages = {
31
+ // Cell slots (`DK_CALLBACK_FAILED` / `DK_CALLBACK_BAD_RETURN` fallback).
32
+ "cells-coerced": "those cells were coerced with the default formatter",
33
+ "cells-warn": "those cells rendered \u26A0",
34
+ // `<DataTable />` (@datakable/react)
35
+ "cells-undefined": "the failed cells read as undefined",
36
+ "cells-empty": "the failed cells render ''",
37
+ "rows-unmatched": "the failed rows are treated as non-matching",
38
+ "rows-last": "the failed rows sort as missing values (last)",
39
+ "cell-undefined": "the cell reads as undefined",
40
+ "row-key-index": "those rows use the fallback key '#<index>'",
41
+ "sorted-native": "the rows were sorted with the native algorithm",
42
+ "sorted-default": "the column was sorted with the default comparator",
43
+ // Operation fallbacks (`intercept/fallbacks.ts`, the boundary's reports).
44
+ "init-continued": "table creation continued without the failed step",
45
+ "options-kept": "the previous options were kept",
46
+ "destroy-continued": "teardown continued; the table is destroyed",
47
+ "update-dropped": "the update was dropped (state unchanged)",
48
+ "data-kept": "the previous data was kept",
49
+ "row-model-kept": "the last good row model was kept",
50
+ "step-passthrough": "the step passed its input through",
51
+ "batch-fallback": "the column's cells use the slot fallback ('' for format, undefined for accessor, non-matching for filterFn, missing (sorted last) for sortBy)",
52
+ "results-kept": "the previous results were kept (status: 'error')",
53
+ "diagnostic-dropped": "the diagnostic was dropped (the logger never kills the table)",
54
+ "returned-undefined": "the operation returned undefined",
55
+ // Features.
56
+ "slice-undefined": "the slice starts as undefined",
57
+ "api-not-installed": "its API was not installed",
58
+ "call-ignored": "the call was ignored",
59
+ "api-missing": "table.{0}() did nothing (the API of that feature was not installed)",
60
+ "apis-missing": "table.{0}() did nothing (the API of those features was not installed)",
61
+ "page-reset": "the pagination state was reset to its initial value",
62
+ "page-index-0": "pageIndex was replaced by 0",
63
+ "page-size": "pageSize was replaced by {0}",
64
+ "validity-ignored": "the call was ignored; the validity filter is unchanged",
65
+ "validity-all": "the table shows every row, as with 'all'",
66
+ "validity-needs-flag": "validity filters rows flagged by schema validation, which needs `schema` and `invalidRows: 'flag'` (without a schema no row is invalid; with 'drop' invalid rows are removed, with 'throw' they throw)",
67
+ "not-searchable": "no column is searchable: give the columns to search a `search` weight",
68
+ collation: `the runtime's collation for "{0}"`,
69
+ "not-algorithm": "{0} is not a sort algorithm (accepted: auto, tim, radix, counting, native, or a function); auto was used",
70
+ "exsorted-failed": "exsorted {0}Sort could not sort these keys; auto was used",
71
+ "exsorted-range": "exsorted {0}Sort could not sort these keys (key range above 1,000,000); auto was used",
72
+ "needs-int-keys": "{0} sorts a single column of safe integer keys (numbers or Dates, no sortFn); auto was used",
73
+ // Sorting reasons (DK_SORT_STRATEGY, `debug: true`).
74
+ "custom-threw": "the custom algorithm threw",
75
+ "custom-bad": "the custom algorithm returned a bad value",
76
+ "not-safe-int": "keys are not all safe integers",
77
+ ranks: "{0}, strings as collation ranks",
78
+ "int-keys": "{0}, safe-integer keys",
79
+ "auto-nearly": "auto: safe integers, nearly sorted ({0} descents)",
80
+ "auto-range": "auto: safe integers, key range {0} \u2264 4n",
81
+ "auto-wide": "auto: safe integers, wide range, n \u2265 10k",
82
+ "auto-wide-small": "auto: safe integers, wide range, n < 10k",
83
+ "auto-ranked-nearly": "auto: collation ranks of a string column, safe integers, nearly sorted ({0} descents)",
84
+ "auto-ranked-range": "auto: collation ranks of a string column, safe integers, key range {0} \u2264 4n",
85
+ "auto-ranked-wide": "auto: collation ranks of a string column, safe integers, wide range, n \u2265 10k",
86
+ "auto-ranked-wide-small": "auto: collation ranks of a string column, safe integers, wide range, n < 10k",
87
+ // Filter values (`DK_FILTER_TYPE_MISMATCH` expected).
88
+ "prims-or-dates": "an array of primitives or Dates",
89
+ "prim-or-date": "a primitive or a Date",
90
+ "range-bound": "number | bigint or a valid Date bound",
91
+ "same-type": "min and max of the same type ({0})",
92
+ // An option given without its wrapper (`DK_INVALID_OPTION` expected).
93
+ wrapped: "{0}({1}) from '@datakable/core/{2}'",
94
+ // DK_INTERNAL problems.
95
+ escaped: "an exception escaped DataKable code",
96
+ "unknown-code": 'unknown diagnostic code "{0}": define it with defineDiagnostic() first',
97
+ "unknown-op": 'Unknown operation "{0}": register it with registerOperation()',
98
+ "boundary-twice": 'A boundary interceptor is already installed ("{0}"); "{1}" was rejected'
99
+ };
100
+ function expandProse(v, dev) {
101
+ const [key, ...args] = v.split("|");
102
+ const text = (process.env.NODE_ENV !== "production" && dev ? proseMessages[key] : void 0) ?? (0, import_catalog.installedText)(key);
103
+ return typeof text === "string" ? text.replace(/\{(\d)\}/g, (_, n) => expandProse(args[+n], dev)) : v;
104
+ }
105
+ var FIELDS = ["fallback", "reason", "problem", "expected"];
106
+ function expandDetails(details, dev) {
107
+ const out = { ...details };
108
+ for (const f of FIELDS) {
109
+ const v = details[f];
110
+ if (typeof v === "string") out[f] = expandProse(v, dev);
111
+ }
112
+ return out;
113
+ }
114
+ // Annotate the CommonJS export names for ESM import in node:
115
+ 0 && (module.exports = {
116
+ expandDetails,
117
+ expandProse,
118
+ proseMessages
119
+ });
120
+ //# sourceMappingURL=prose.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/diagnostics/prose.ts"],"sourcesContent":["import { installedText } from './catalog'\nimport './process-guard'\n\n/**\n * Production detail prose (§8.2, §9.3): the sentences some details carry (`fallback`, `reason`,\n * `problem`) are written as short keys at the emit site, e.g. `fallback: 'cells-undefined'`, or\n * `'page-size|10'` with arguments. A diagnostic built in development, or in production with\n * `@datakable/core/messages` installed, reads the full sentence (the key is expanded when it is\n * built); production without the messages keeps the key, so the bundle carries no prose. A value\n * that is not a known key (a plugin's own `registerFallback` text) is kept as written.\n *\n * `{0}`, `{1}` are the arguments after the key, separated by `|`.\n */\nexport const proseMessages: Readonly<Record<string, string>> = {\n // Cell slots (`DK_CALLBACK_FAILED` / `DK_CALLBACK_BAD_RETURN` fallback).\n 'cells-coerced': 'those cells were coerced with the default formatter',\n 'cells-warn': 'those cells rendered ⚠', // `<DataTable />` (@datakable/react)\n 'cells-undefined': 'the failed cells read as undefined',\n 'cells-empty': \"the failed cells render ''\",\n 'rows-unmatched': 'the failed rows are treated as non-matching',\n 'rows-last': 'the failed rows sort as missing values (last)',\n 'cell-undefined': 'the cell reads as undefined',\n 'row-key-index': \"those rows use the fallback key '#<index>'\",\n 'sorted-native': 'the rows were sorted with the native algorithm',\n 'sorted-default': 'the column was sorted with the default comparator',\n // Operation fallbacks (`intercept/fallbacks.ts`, the boundary's reports).\n 'init-continued': 'table creation continued without the failed step',\n 'options-kept': 'the previous options were kept',\n 'destroy-continued': 'teardown continued; the table is destroyed',\n 'update-dropped': 'the update was dropped (state unchanged)',\n 'data-kept': 'the previous data was kept',\n 'row-model-kept': 'the last good row model was kept',\n 'step-passthrough': 'the step passed its input through',\n 'batch-fallback':\n \"the column's cells use the slot fallback ('' for format, undefined for accessor, \" +\n 'non-matching for filterFn, missing (sorted last) for sortBy)',\n 'results-kept': \"the previous results were kept (status: 'error')\",\n 'diagnostic-dropped': 'the diagnostic was dropped (the logger never kills the table)',\n 'returned-undefined': 'the operation returned undefined',\n // Features.\n 'slice-undefined': 'the slice starts as undefined',\n 'api-not-installed': 'its API was not installed',\n 'call-ignored': 'the call was ignored',\n 'api-missing': 'table.{0}() did nothing (the API of that feature was not installed)',\n 'apis-missing': 'table.{0}() did nothing (the API of those features was not installed)',\n 'page-reset': 'the pagination state was reset to its initial value',\n 'page-index-0': 'pageIndex was replaced by 0',\n 'page-size': 'pageSize was replaced by {0}',\n 'validity-ignored': 'the call was ignored; the validity filter is unchanged',\n 'validity-all': \"the table shows every row, as with 'all'\",\n 'validity-needs-flag':\n 'validity filters rows flagged by schema validation, which needs `schema` and ' +\n \"`invalidRows: 'flag'` (without a schema no row is invalid; with 'drop' invalid rows \" +\n \"are removed, with 'throw' they throw)\",\n 'not-searchable': 'no column is searchable: give the columns to search a `search` weight',\n collation: 'the runtime\\'s collation for \"{0}\"',\n 'not-algorithm':\n '{0} is not a sort algorithm (accepted: auto, tim, radix, counting, native, or a function); ' +\n 'auto was used',\n 'exsorted-failed': 'exsorted {0}Sort could not sort these keys; auto was used',\n 'exsorted-range':\n 'exsorted {0}Sort could not sort these keys (key range above 1,000,000); auto was used',\n 'needs-int-keys':\n '{0} sorts a single column of safe integer keys (numbers or Dates, no sortFn); auto was used',\n // Sorting reasons (DK_SORT_STRATEGY, `debug: true`).\n 'custom-threw': 'the custom algorithm threw',\n 'custom-bad': 'the custom algorithm returned a bad value',\n 'not-safe-int': 'keys are not all safe integers',\n ranks: '{0}, strings as collation ranks',\n 'int-keys': '{0}, safe-integer keys',\n 'auto-nearly': 'auto: safe integers, nearly sorted ({0} descents)',\n 'auto-range': 'auto: safe integers, key range {0} ≤ 4n',\n 'auto-wide': 'auto: safe integers, wide range, n ≥ 10k',\n 'auto-wide-small': 'auto: safe integers, wide range, n < 10k',\n 'auto-ranked-nearly':\n 'auto: collation ranks of a string column, safe integers, nearly sorted ({0} descents)',\n 'auto-ranked-range':\n 'auto: collation ranks of a string column, safe integers, key range {0} ≤ 4n',\n 'auto-ranked-wide':\n 'auto: collation ranks of a string column, safe integers, wide range, n ≥ 10k',\n 'auto-ranked-wide-small':\n 'auto: collation ranks of a string column, safe integers, wide range, n < 10k',\n // Filter values (`DK_FILTER_TYPE_MISMATCH` expected).\n 'prims-or-dates': 'an array of primitives or Dates',\n 'prim-or-date': 'a primitive or a Date',\n 'range-bound': 'number | bigint or a valid Date bound',\n 'same-type': 'min and max of the same type ({0})',\n // An option given without its wrapper (`DK_INVALID_OPTION` expected).\n wrapped: \"{0}({1}) from '@datakable/core/{2}'\",\n // DK_INTERNAL problems.\n escaped: 'an exception escaped DataKable code',\n 'unknown-code': 'unknown diagnostic code \"{0}\": define it with defineDiagnostic() first',\n 'unknown-op': 'Unknown operation \"{0}\": register it with registerOperation()',\n 'boundary-twice': 'A boundary interceptor is already installed (\"{0}\"); \"{1}\" was rejected',\n}\n\n/**\n * The sentence of a prose key (`'page-size|10'` → `'pageSize was replaced by 10'`): from\n * {@link proseMessages} in development (`dev`), else from the installed messages; `v` itself when\n * neither has the key.\n */\nexport function expandProse(v: string, dev: boolean): string {\n const [key, ...args] = v.split('|') as [string, ...string[]]\n const text = ((process.env.NODE_ENV !== \"production\") && dev ? proseMessages[key] : undefined) ?? installedText(key)\n // An argument may be a key itself (`'ranks|custom-threw'`).\n return typeof text === 'string'\n ? text.replace(/\\{(\\d)\\}/g, (_, n: string) => expandProse(args[+n] as string, dev))\n : v\n}\n\n/** The detail fields that may hold a prose key. */\nconst FIELDS = ['fallback', 'reason', 'problem', 'expected'] as const\n\n/** A copy of `details` with its prose keys expanded. */\nexport function expandDetails(\n details: Record<string, unknown>,\n dev: boolean,\n): Record<string, unknown> {\n const out = { ...details }\n for (const f of FIELDS) {\n const v = details[f]\n if (typeof v === 'string') out[f] = expandProse(v, dev)\n }\n return out\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAA8B;AAC9B,2BAAO;AAYA,IAAM,gBAAkD;AAAA;AAAA,EAE7D,iBAAiB;AAAA,EACjB,cAAc;AAAA;AAAA,EACd,mBAAmB;AAAA,EACnB,eAAe;AAAA,EACf,kBAAkB;AAAA,EAClB,aAAa;AAAA,EACb,kBAAkB;AAAA,EAClB,iBAAiB;AAAA,EACjB,iBAAiB;AAAA,EACjB,kBAAkB;AAAA;AAAA,EAElB,kBAAkB;AAAA,EAClB,gBAAgB;AAAA,EAChB,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A,IAAM,SAAS,CAAC,YAAY,UAAU,WAAW,UAAU;AAGpD,SAAS,cACd,SACA,KACyB;AACzB,QAAM,MAAM,EAAE,GAAG,QAAQ;AACzB,aAAW,KAAK,QAAQ;AACtB,UAAM,IAAI,QAAQ,CAAC;AACnB,QAAI,OAAO,MAAM,SAAU,KAAI,CAAC,IAAI,YAAY,GAAG,GAAG;AAAA,EACxD;AACA,SAAO;AACT;","names":[]}
@@ -0,0 +1,93 @@
1
+ // src/diagnostics/prose.ts
2
+ import { installedText } from "./catalog.js";
3
+ import "./process-guard.js";
4
+ var proseMessages = {
5
+ // Cell slots (`DK_CALLBACK_FAILED` / `DK_CALLBACK_BAD_RETURN` fallback).
6
+ "cells-coerced": "those cells were coerced with the default formatter",
7
+ "cells-warn": "those cells rendered \u26A0",
8
+ // `<DataTable />` (@datakable/react)
9
+ "cells-undefined": "the failed cells read as undefined",
10
+ "cells-empty": "the failed cells render ''",
11
+ "rows-unmatched": "the failed rows are treated as non-matching",
12
+ "rows-last": "the failed rows sort as missing values (last)",
13
+ "cell-undefined": "the cell reads as undefined",
14
+ "row-key-index": "those rows use the fallback key '#<index>'",
15
+ "sorted-native": "the rows were sorted with the native algorithm",
16
+ "sorted-default": "the column was sorted with the default comparator",
17
+ // Operation fallbacks (`intercept/fallbacks.ts`, the boundary's reports).
18
+ "init-continued": "table creation continued without the failed step",
19
+ "options-kept": "the previous options were kept",
20
+ "destroy-continued": "teardown continued; the table is destroyed",
21
+ "update-dropped": "the update was dropped (state unchanged)",
22
+ "data-kept": "the previous data was kept",
23
+ "row-model-kept": "the last good row model was kept",
24
+ "step-passthrough": "the step passed its input through",
25
+ "batch-fallback": "the column's cells use the slot fallback ('' for format, undefined for accessor, non-matching for filterFn, missing (sorted last) for sortBy)",
26
+ "results-kept": "the previous results were kept (status: 'error')",
27
+ "diagnostic-dropped": "the diagnostic was dropped (the logger never kills the table)",
28
+ "returned-undefined": "the operation returned undefined",
29
+ // Features.
30
+ "slice-undefined": "the slice starts as undefined",
31
+ "api-not-installed": "its API was not installed",
32
+ "call-ignored": "the call was ignored",
33
+ "api-missing": "table.{0}() did nothing (the API of that feature was not installed)",
34
+ "apis-missing": "table.{0}() did nothing (the API of those features was not installed)",
35
+ "page-reset": "the pagination state was reset to its initial value",
36
+ "page-index-0": "pageIndex was replaced by 0",
37
+ "page-size": "pageSize was replaced by {0}",
38
+ "validity-ignored": "the call was ignored; the validity filter is unchanged",
39
+ "validity-all": "the table shows every row, as with 'all'",
40
+ "validity-needs-flag": "validity filters rows flagged by schema validation, which needs `schema` and `invalidRows: 'flag'` (without a schema no row is invalid; with 'drop' invalid rows are removed, with 'throw' they throw)",
41
+ "not-searchable": "no column is searchable: give the columns to search a `search` weight",
42
+ collation: `the runtime's collation for "{0}"`,
43
+ "not-algorithm": "{0} is not a sort algorithm (accepted: auto, tim, radix, counting, native, or a function); auto was used",
44
+ "exsorted-failed": "exsorted {0}Sort could not sort these keys; auto was used",
45
+ "exsorted-range": "exsorted {0}Sort could not sort these keys (key range above 1,000,000); auto was used",
46
+ "needs-int-keys": "{0} sorts a single column of safe integer keys (numbers or Dates, no sortFn); auto was used",
47
+ // Sorting reasons (DK_SORT_STRATEGY, `debug: true`).
48
+ "custom-threw": "the custom algorithm threw",
49
+ "custom-bad": "the custom algorithm returned a bad value",
50
+ "not-safe-int": "keys are not all safe integers",
51
+ ranks: "{0}, strings as collation ranks",
52
+ "int-keys": "{0}, safe-integer keys",
53
+ "auto-nearly": "auto: safe integers, nearly sorted ({0} descents)",
54
+ "auto-range": "auto: safe integers, key range {0} \u2264 4n",
55
+ "auto-wide": "auto: safe integers, wide range, n \u2265 10k",
56
+ "auto-wide-small": "auto: safe integers, wide range, n < 10k",
57
+ "auto-ranked-nearly": "auto: collation ranks of a string column, safe integers, nearly sorted ({0} descents)",
58
+ "auto-ranked-range": "auto: collation ranks of a string column, safe integers, key range {0} \u2264 4n",
59
+ "auto-ranked-wide": "auto: collation ranks of a string column, safe integers, wide range, n \u2265 10k",
60
+ "auto-ranked-wide-small": "auto: collation ranks of a string column, safe integers, wide range, n < 10k",
61
+ // Filter values (`DK_FILTER_TYPE_MISMATCH` expected).
62
+ "prims-or-dates": "an array of primitives or Dates",
63
+ "prim-or-date": "a primitive or a Date",
64
+ "range-bound": "number | bigint or a valid Date bound",
65
+ "same-type": "min and max of the same type ({0})",
66
+ // An option given without its wrapper (`DK_INVALID_OPTION` expected).
67
+ wrapped: "{0}({1}) from '@datakable/core/{2}'",
68
+ // DK_INTERNAL problems.
69
+ escaped: "an exception escaped DataKable code",
70
+ "unknown-code": 'unknown diagnostic code "{0}": define it with defineDiagnostic() first',
71
+ "unknown-op": 'Unknown operation "{0}": register it with registerOperation()',
72
+ "boundary-twice": 'A boundary interceptor is already installed ("{0}"); "{1}" was rejected'
73
+ };
74
+ function expandProse(v, dev) {
75
+ const [key, ...args] = v.split("|");
76
+ const text = (process.env.NODE_ENV !== "production" && dev ? proseMessages[key] : void 0) ?? installedText(key);
77
+ return typeof text === "string" ? text.replace(/\{(\d)\}/g, (_, n) => expandProse(args[+n], dev)) : v;
78
+ }
79
+ var FIELDS = ["fallback", "reason", "problem", "expected"];
80
+ function expandDetails(details, dev) {
81
+ const out = { ...details };
82
+ for (const f of FIELDS) {
83
+ const v = details[f];
84
+ if (typeof v === "string") out[f] = expandProse(v, dev);
85
+ }
86
+ return out;
87
+ }
88
+ export {
89
+ expandDetails,
90
+ expandProse,
91
+ proseMessages
92
+ };
93
+ //# sourceMappingURL=prose.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/diagnostics/prose.ts"],"sourcesContent":["import { installedText } from './catalog'\nimport './process-guard'\n\n/**\n * Production detail prose (§8.2, §9.3): the sentences some details carry (`fallback`, `reason`,\n * `problem`) are written as short keys at the emit site, e.g. `fallback: 'cells-undefined'`, or\n * `'page-size|10'` with arguments. A diagnostic built in development, or in production with\n * `@datakable/core/messages` installed, reads the full sentence (the key is expanded when it is\n * built); production without the messages keeps the key, so the bundle carries no prose. A value\n * that is not a known key (a plugin's own `registerFallback` text) is kept as written.\n *\n * `{0}`, `{1}` are the arguments after the key, separated by `|`.\n */\nexport const proseMessages: Readonly<Record<string, string>> = {\n // Cell slots (`DK_CALLBACK_FAILED` / `DK_CALLBACK_BAD_RETURN` fallback).\n 'cells-coerced': 'those cells were coerced with the default formatter',\n 'cells-warn': 'those cells rendered ⚠', // `<DataTable />` (@datakable/react)\n 'cells-undefined': 'the failed cells read as undefined',\n 'cells-empty': \"the failed cells render ''\",\n 'rows-unmatched': 'the failed rows are treated as non-matching',\n 'rows-last': 'the failed rows sort as missing values (last)',\n 'cell-undefined': 'the cell reads as undefined',\n 'row-key-index': \"those rows use the fallback key '#<index>'\",\n 'sorted-native': 'the rows were sorted with the native algorithm',\n 'sorted-default': 'the column was sorted with the default comparator',\n // Operation fallbacks (`intercept/fallbacks.ts`, the boundary's reports).\n 'init-continued': 'table creation continued without the failed step',\n 'options-kept': 'the previous options were kept',\n 'destroy-continued': 'teardown continued; the table is destroyed',\n 'update-dropped': 'the update was dropped (state unchanged)',\n 'data-kept': 'the previous data was kept',\n 'row-model-kept': 'the last good row model was kept',\n 'step-passthrough': 'the step passed its input through',\n 'batch-fallback':\n \"the column's cells use the slot fallback ('' for format, undefined for accessor, \" +\n 'non-matching for filterFn, missing (sorted last) for sortBy)',\n 'results-kept': \"the previous results were kept (status: 'error')\",\n 'diagnostic-dropped': 'the diagnostic was dropped (the logger never kills the table)',\n 'returned-undefined': 'the operation returned undefined',\n // Features.\n 'slice-undefined': 'the slice starts as undefined',\n 'api-not-installed': 'its API was not installed',\n 'call-ignored': 'the call was ignored',\n 'api-missing': 'table.{0}() did nothing (the API of that feature was not installed)',\n 'apis-missing': 'table.{0}() did nothing (the API of those features was not installed)',\n 'page-reset': 'the pagination state was reset to its initial value',\n 'page-index-0': 'pageIndex was replaced by 0',\n 'page-size': 'pageSize was replaced by {0}',\n 'validity-ignored': 'the call was ignored; the validity filter is unchanged',\n 'validity-all': \"the table shows every row, as with 'all'\",\n 'validity-needs-flag':\n 'validity filters rows flagged by schema validation, which needs `schema` and ' +\n \"`invalidRows: 'flag'` (without a schema no row is invalid; with 'drop' invalid rows \" +\n \"are removed, with 'throw' they throw)\",\n 'not-searchable': 'no column is searchable: give the columns to search a `search` weight',\n collation: 'the runtime\\'s collation for \"{0}\"',\n 'not-algorithm':\n '{0} is not a sort algorithm (accepted: auto, tim, radix, counting, native, or a function); ' +\n 'auto was used',\n 'exsorted-failed': 'exsorted {0}Sort could not sort these keys; auto was used',\n 'exsorted-range':\n 'exsorted {0}Sort could not sort these keys (key range above 1,000,000); auto was used',\n 'needs-int-keys':\n '{0} sorts a single column of safe integer keys (numbers or Dates, no sortFn); auto was used',\n // Sorting reasons (DK_SORT_STRATEGY, `debug: true`).\n 'custom-threw': 'the custom algorithm threw',\n 'custom-bad': 'the custom algorithm returned a bad value',\n 'not-safe-int': 'keys are not all safe integers',\n ranks: '{0}, strings as collation ranks',\n 'int-keys': '{0}, safe-integer keys',\n 'auto-nearly': 'auto: safe integers, nearly sorted ({0} descents)',\n 'auto-range': 'auto: safe integers, key range {0} ≤ 4n',\n 'auto-wide': 'auto: safe integers, wide range, n ≥ 10k',\n 'auto-wide-small': 'auto: safe integers, wide range, n < 10k',\n 'auto-ranked-nearly':\n 'auto: collation ranks of a string column, safe integers, nearly sorted ({0} descents)',\n 'auto-ranked-range':\n 'auto: collation ranks of a string column, safe integers, key range {0} ≤ 4n',\n 'auto-ranked-wide':\n 'auto: collation ranks of a string column, safe integers, wide range, n ≥ 10k',\n 'auto-ranked-wide-small':\n 'auto: collation ranks of a string column, safe integers, wide range, n < 10k',\n // Filter values (`DK_FILTER_TYPE_MISMATCH` expected).\n 'prims-or-dates': 'an array of primitives or Dates',\n 'prim-or-date': 'a primitive or a Date',\n 'range-bound': 'number | bigint or a valid Date bound',\n 'same-type': 'min and max of the same type ({0})',\n // An option given without its wrapper (`DK_INVALID_OPTION` expected).\n wrapped: \"{0}({1}) from '@datakable/core/{2}'\",\n // DK_INTERNAL problems.\n escaped: 'an exception escaped DataKable code',\n 'unknown-code': 'unknown diagnostic code \"{0}\": define it with defineDiagnostic() first',\n 'unknown-op': 'Unknown operation \"{0}\": register it with registerOperation()',\n 'boundary-twice': 'A boundary interceptor is already installed (\"{0}\"); \"{1}\" was rejected',\n}\n\n/**\n * The sentence of a prose key (`'page-size|10'` → `'pageSize was replaced by 10'`): from\n * {@link proseMessages} in development (`dev`), else from the installed messages; `v` itself when\n * neither has the key.\n */\nexport function expandProse(v: string, dev: boolean): string {\n const [key, ...args] = v.split('|') as [string, ...string[]]\n const text = ((process.env.NODE_ENV !== \"production\") && dev ? proseMessages[key] : undefined) ?? installedText(key)\n // An argument may be a key itself (`'ranks|custom-threw'`).\n return typeof text === 'string'\n ? text.replace(/\\{(\\d)\\}/g, (_, n: string) => expandProse(args[+n] as string, dev))\n : v\n}\n\n/** The detail fields that may hold a prose key. */\nconst FIELDS = ['fallback', 'reason', 'problem', 'expected'] as const\n\n/** A copy of `details` with its prose keys expanded. */\nexport function expandDetails(\n details: Record<string, unknown>,\n dev: boolean,\n): Record<string, unknown> {\n const out = { ...details }\n for (const f of FIELDS) {\n const v = details[f]\n if (typeof v === 'string') out[f] = expandProse(v, dev)\n }\n return out\n}\n"],"mappings":";AAAA,SAAS,qBAAqB;AAC9B,OAAO;AAYA,IAAM,gBAAkD;AAAA;AAAA,EAE7D,iBAAiB;AAAA,EACjB,cAAc;AAAA;AAAA,EACd,mBAAmB;AAAA,EACnB,eAAe;AAAA,EACf,kBAAkB;AAAA,EAClB,aAAa;AAAA,EACb,kBAAkB;AAAA,EAClB,iBAAiB;AAAA,EACjB,iBAAiB;AAAA,EACjB,kBAAkB;AAAA;AAAA,EAElB,kBAAkB;AAAA,EAClB,gBAAgB;AAAA,EAChB,qBAAqB;AAAA,EACrB,kBAAkB;AAAA,EAClB,aAAa;AAAA,EACb,kBAAkB;AAAA,EAClB,oBAAoB;AAAA,EACpB,kBACE;AAAA,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ACzB,aAAW,KAAK,QAAQ;AACtB,UAAM,IAAI,QAAQ,CAAC;AACnB,QAAI,OAAO,MAAM,SAAU,KAAI,CAAC,IAAI,YAAY,GAAG,GAAG;AAAA,EACxD;AACA,SAAO;AACT;","names":[]}
@@ -25,6 +25,7 @@ __export(redact_exports, {
25
25
  SENSITIVE: () => SENSITIVE,
26
26
  describeValue: () => describeValue,
27
27
  hashRowKey: () => hashRowKey,
28
+ pathsOverlap: () => pathsOverlap,
28
29
  redactDetails: () => redactDetails,
29
30
  redactLocation: () => redactLocation,
30
31
  redactionMessages: () => redactionMessages,
@@ -34,6 +35,7 @@ __export(redact_exports, {
34
35
  });
35
36
  module.exports = __toCommonJS(redact_exports);
36
37
  var import_catalog = require("./catalog.cjs");
38
+ var import_process_guard = require("./process-guard.cjs");
37
39
  var SENSITIVE = "[sensitive]";
38
40
  var REDACTED = "[redacted]";
39
41
  var LEVELS = ["safe", "keys", "full"];
@@ -83,7 +85,7 @@ function redactKey(r, path, key) {
83
85
  return r.level === "safe" ? hashRowKey(key) : key;
84
86
  }
85
87
  function redactValue(r, path, value, column) {
86
- if (column !== void 0 && r.sensitive.has(column)) return SENSITIVE;
88
+ if (column !== void 0 && underSensitive(r, column)) return SENSITIVE;
87
89
  const c = custom(r, path, value);
88
90
  if (c !== void 0) return c;
89
91
  return r.level === "full" ? value : describeValue(value);
@@ -92,9 +94,9 @@ function issuePath(path) {
92
94
  if (!path) return "";
93
95
  return path.map((s) => String(typeof s === "object" && s !== null ? s.key : s)).join(".");
94
96
  }
97
+ var pathsOverlap = (a, b) => a === b || a.startsWith(`${b}.`) || b.startsWith(`${a}.`);
95
98
  function underSensitive(r, path) {
96
- if (r.sensitive.size === 0) return false;
97
- for (const col of r.sensitive) if (path === col || path.startsWith(`${col}.`)) return true;
99
+ for (const col of r.sensitive) if (pathsOverlap(path, col)) return true;
98
100
  return false;
99
101
  }
100
102
  function scrubSchemaIssue(issue, r, fieldPath = "issue") {
@@ -106,7 +108,7 @@ function scrubSchemaIssue(issue, r, fieldPath = "issue") {
106
108
  path = "";
107
109
  }
108
110
  const own = `invalid value at ${path || "(root)"}`;
109
- if (underSensitive(r, path)) return { path, message: own };
111
+ if (r.sensitive.size > 0) return { path, message: own };
110
112
  const c = custom(r, fieldPath, i.message);
111
113
  if (c !== void 0) return { path, message: c };
112
114
  return { path, message: r.level === "full" && typeof i.message === "string" ? i.message : own };
@@ -185,6 +187,7 @@ var DK_UNSAFE_REDACTION = (0, import_catalog.defineDiagnostic)(
185
187
  SENSITIVE,
186
188
  describeValue,
187
189
  hashRowKey,
190
+ pathsOverlap,
188
191
  redactDetails,
189
192
  redactLocation,
190
193
  redactionMessages,