@gusto/baerly-storage 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +29 -0
  3. package/README.md +176 -70
  4. package/dist/API.md +213 -139
  5. package/dist/CHANGELOG.md +434 -0
  6. package/dist/RECIPES.md +125 -0
  7. package/dist/THIRD-PARTY-LICENSES.txt +238 -0
  8. package/dist/{app-config-C0Bbw_Z6.d.ts → app-config-DyiFK3_k.d.ts} +55 -11
  9. package/dist/app-config.d.ts +1 -1
  10. package/dist/auth.d.ts +1 -1
  11. package/dist/auth.js +301 -301
  12. package/dist/auth.js.map +1 -1
  13. package/dist/aws4fetch.esm-p7eEzLCs.js +1702 -0
  14. package/dist/aws4fetch.esm-p7eEzLCs.js.map +1 -0
  15. package/dist/baerly.js +35 -15
  16. package/dist/baerly.js.map +1 -1
  17. package/dist/baerly.spec.json +342 -0
  18. package/dist/bytes-BXdamO3L.js.map +1 -1
  19. package/dist/{client-DYZfoZb9.d.ts → client-Fe8CwB73.d.ts} +10 -10
  20. package/dist/client-react.d.ts +3 -3
  21. package/dist/client-react.js +4 -4
  22. package/dist/client-react.js.map +1 -1
  23. package/dist/client.d.ts +4 -4
  24. package/dist/client.js +3 -3
  25. package/dist/client.js.map +1 -1
  26. package/dist/{cloudflare-CINJPKCW.js → cloudflare-DzKBrUlg.js} +178 -2
  27. package/dist/cloudflare-DzKBrUlg.js.map +1 -0
  28. package/dist/cloudflare.d.ts +49 -6
  29. package/dist/cloudflare.js +59 -26
  30. package/dist/cloudflare.js.map +1 -1
  31. package/dist/config-1tv0-Yzm.js +2693 -0
  32. package/dist/config-1tv0-Yzm.js.map +1 -0
  33. package/dist/constants-CfeMWQWk.js +222 -0
  34. package/dist/constants-CfeMWQWk.js.map +1 -0
  35. package/dist/context-DRZ3tZ5l.js.map +1 -1
  36. package/dist/{cost-CQt1YRkA.js → cost-DSMIVqzL.js} +43 -42
  37. package/dist/cost-DSMIVqzL.js.map +1 -0
  38. package/dist/current-json-C6nhPOm1.js +190 -0
  39. package/dist/current-json-C6nhPOm1.js.map +1 -0
  40. package/dist/{db-BM3y2JQw.d.ts → db-DsPkOVEH.d.ts} +26 -108
  41. package/dist/{deploy-CrAbfgCq.js → deploy-DonTr-CV.js} +12 -5
  42. package/dist/deploy-DonTr-CV.js.map +1 -0
  43. package/dist/dev-vite.d.ts +11 -7
  44. package/dist/dev-vite.js +7 -6
  45. package/dist/dev-vite.js.map +1 -1
  46. package/dist/dev.d.ts +1 -1
  47. package/dist/dev.js +1 -1
  48. package/dist/{doctor-Db-hzPmE.js → doctor-DSIyCDg_.js} +14 -136
  49. package/dist/doctor-DSIyCDg_.js.map +1 -0
  50. package/dist/{dump-BYA55NLP.js → dump-Bh5k26VQ.js} +10 -31
  51. package/dist/dump-Bh5k26VQ.js.map +1 -0
  52. package/dist/{errors-DOdL95kK.js → errors-Dfa3p78c.js} +25 -5
  53. package/dist/errors-Dfa3p78c.js.map +1 -0
  54. package/dist/{export-Bhbz90-z.js → export-DtF5tDIM.js} +11 -32
  55. package/dist/{export-Bhbz90-z.js.map → export-DtF5tDIM.js.map} +1 -1
  56. package/dist/{fsck-CPPZWt9p.js → fsck-D_djMO5D.js} +28 -39
  57. package/dist/fsck-D_djMO5D.js.map +1 -0
  58. package/dist/{http-Cw8p6y5b.js → http-DxM9MflO.js} +151 -79
  59. package/dist/http-DxM9MflO.js.map +1 -0
  60. package/dist/http.d.ts +42 -26
  61. package/dist/http.js +3 -2
  62. package/dist/{index-DwDTWPSU.d.ts → index-0rZcMBwy.d.ts} +10 -7
  63. package/dist/{index-C3JAH1Yo.d.ts → index-B6oexfOB.d.ts} +9 -9
  64. package/dist/{index-cUY-36AN.d.ts → index-BNRh23K9.d.ts} +21 -5
  65. package/dist/{index-DSvwEUeF.d.ts → index-BYk9oCNf.d.ts} +240 -202
  66. package/dist/index.d.ts +6 -6
  67. package/dist/index.js +5 -5
  68. package/dist/{indexes-DAu2AkTW.d.ts → indexes-Dn9hbGQG.d.ts} +2 -2
  69. package/dist/{inspect-Bdbzvi-_.js → inspect-6WZ-pC7-.js} +21 -36
  70. package/dist/inspect-6WZ-pC7-.js.map +1 -0
  71. package/dist/key-Di6yyxFu.js +35 -0
  72. package/dist/key-Di6yyxFu.js.map +1 -0
  73. package/dist/{snapshot-SS8USDUF.js → log-tail-D98U1JBo.js} +179 -84
  74. package/dist/log-tail-D98U1JBo.js.map +1 -0
  75. package/dist/{maintenance-ClzBC1Vv.js → maintenance-B4Dki6Ig.js} +438 -176
  76. package/dist/maintenance-B4Dki6Ig.js.map +1 -0
  77. package/dist/{maintenance-BRrThz8V.d.ts → maintenance-B_e0T99L.d.ts} +114 -26
  78. package/dist/{maintenance-BvOv6BMM.js → maintenance-C7coQp4c.js} +217 -94
  79. package/dist/maintenance-C7coQp4c.js.map +1 -0
  80. package/dist/maintenance.d.ts +3 -2
  81. package/dist/maintenance.js +3 -2
  82. package/dist/node.d.ts +176 -68
  83. package/dist/node.js +3 -2
  84. package/dist/{normalize-XWY25_sG.js → normalize-rjnZLwS4.js} +2 -2
  85. package/dist/normalize-rjnZLwS4.js.map +1 -0
  86. package/dist/{observability-CpOiEN0k.js → observability-wzs3-BL_.js} +279 -109
  87. package/dist/observability-wzs3-BL_.js.map +1 -0
  88. package/dist/observability.d.ts +3 -3
  89. package/dist/observability.js +1 -1
  90. package/dist/{plan-DOTl21vq.js → plan-a7PJHBCy.js} +7 -4
  91. package/dist/plan-a7PJHBCy.js.map +1 -0
  92. package/dist/{query-BmiQy328.js → query-rAtXNQQB.js} +1063 -1202
  93. package/dist/query-rAtXNQQB.js.map +1 -0
  94. package/dist/{rebuild-index-DC_nR6wP.js → rebuild-index-BVzQSZlm.js} +10 -32
  95. package/dist/rebuild-index-BVzQSZlm.js.map +1 -0
  96. package/dist/{request-BEF_OvMh.js → request-u0M51mhJ.js} +3 -3
  97. package/dist/{request-BEF_OvMh.js.map → request-u0M51mhJ.js.map} +1 -1
  98. package/dist/restore-R-4rbciV.js +778 -0
  99. package/dist/restore-R-4rbciV.js.map +1 -0
  100. package/dist/runtime-spec-qL3_lTTU.js +391 -0
  101. package/dist/runtime-spec-qL3_lTTU.js.map +1 -0
  102. package/dist/s3-http-B-z8th6O.d.ts +60 -0
  103. package/dist/s3.d.ts +47 -0
  104. package/dist/s3.js +45 -0
  105. package/dist/s3.js.map +1 -0
  106. package/dist/{shared-secret-BJdSwpgw.js → shared-secret-DgEicd3x.js} +13 -5
  107. package/dist/shared-secret-DgEicd3x.js.map +1 -0
  108. package/dist/src-BG20LZs7.js +2271 -0
  109. package/dist/src-BG20LZs7.js.map +1 -0
  110. package/dist/{src-zhEAmmF7.js → src-CYHFDrKz.js} +82 -99
  111. package/dist/src-CYHFDrKz.js.map +1 -0
  112. package/dist/{src-QQ7jDeL2.js → src-DYZ4H1aF.js} +44 -23
  113. package/dist/src-DYZ4H1aF.js.map +1 -0
  114. package/dist/subcommand-DoDA-K7d.js +197 -0
  115. package/dist/subcommand-DoDA-K7d.js.map +1 -0
  116. package/dist/time-DUqvFMHq.js +119 -0
  117. package/dist/time-DUqvFMHq.js.map +1 -0
  118. package/dist/{usage-CLjirdD-.js → usage-DBV1eQHC.js} +7 -22
  119. package/dist/usage-DBV1eQHC.js.map +1 -0
  120. package/dist/{validate-DCq_0DIn.js → validate-DtljsCh1.js} +51 -51
  121. package/dist/{validate-DCq_0DIn.js.map → validate-DtljsCh1.js.map} +1 -1
  122. package/dist/wire-izfGZDvr.js.map +1 -1
  123. package/package.json +77 -42
  124. package/dist/cloudflare-CINJPKCW.js.map +0 -1
  125. package/dist/config-DVfDGyw1.js +0 -278
  126. package/dist/config-DVfDGyw1.js.map +0 -1
  127. package/dist/cost-CQt1YRkA.js.map +0 -1
  128. package/dist/current-json-C-EyJqs0.js +0 -354
  129. package/dist/current-json-C-EyJqs0.js.map +0 -1
  130. package/dist/deploy-CrAbfgCq.js.map +0 -1
  131. package/dist/doctor-Db-hzPmE.js.map +0 -1
  132. package/dist/dump-BYA55NLP.js.map +0 -1
  133. package/dist/errors-DOdL95kK.js.map +0 -1
  134. package/dist/fsck-CPPZWt9p.js.map +0 -1
  135. package/dist/http-Cw8p6y5b.js.map +0 -1
  136. package/dist/inspect-Bdbzvi-_.js.map +0 -1
  137. package/dist/maintenance-BvOv6BMM.js.map +0 -1
  138. package/dist/maintenance-ClzBC1Vv.js.map +0 -1
  139. package/dist/normalize-XWY25_sG.js.map +0 -1
  140. package/dist/observability-CpOiEN0k.js.map +0 -1
  141. package/dist/plan-DOTl21vq.js.map +0 -1
  142. package/dist/query-BmiQy328.js.map +0 -1
  143. package/dist/rebuild-index-DC_nR6wP.js.map +0 -1
  144. package/dist/restore-C6IcmLeA.js +0 -771
  145. package/dist/restore-C6IcmLeA.js.map +0 -1
  146. package/dist/shared-secret-BJdSwpgw.js.map +0 -1
  147. package/dist/snapshot-SS8USDUF.js.map +0 -1
  148. package/dist/src-DU1sCMlr.js +0 -6236
  149. package/dist/src-DU1sCMlr.js.map +0 -1
  150. package/dist/src-QQ7jDeL2.js.map +0 -1
  151. package/dist/src-zhEAmmF7.js.map +0 -1
  152. package/dist/subcommand-DZcHcsYp.js +0 -5122
  153. package/dist/subcommand-DZcHcsYp.js.map +0 -1
  154. package/dist/usage-CLjirdD-.js.map +0 -1
  155. /package/dist/{chunk-EAsCxrDo.js → rolldown-runtime-EAsCxrDo.js} +0 -0
@@ -1,48 +1,73 @@
1
- import { n as __exportAll } from "./chunk-EAsCxrDo.js";
2
- import { t as BaerlyError } from "./errors-DOdL95kK.js";
1
+ import { n as __exportAll } from "./rolldown-runtime-EAsCxrDo.js";
2
+ import { n as isRetriableCode, t as BaerlyError } from "./errors-Dfa3p78c.js";
3
3
  import { i as noopMetricsRecorder, n as getCurrentContext, r as runWithContext, t as createObservabilityContext } from "./context-DRZ3tZ5l.js";
4
+ //#region packages/protocol/src/code-resolution.ts
5
+ /** Canonical per-code corrective action; `errorEnvelope` falls back to this and it crosses the wire as `resolution`. Actionable codes only — context-sensitive codes use throw-site overrides. */
6
+ const CODE_RESOLUTIONS = {
7
+ PayloadTooLarge: "Reduce the request body below the server's body-size cap (1 MiB default).",
8
+ Unauthorized: "Send a valid Authorization header for the server's configured auth method.",
9
+ AccessDenied: "These credentials are denied for this tenant prefix or bucket policy.",
10
+ NotFound: "No row matches this id; create it first or treat this as a miss."
11
+ };
12
+ /** Resolution for a malformed `?where=` / `?order=` query value. */
13
+ const WHERE_ORDER_JSON_RESOLUTION = "Pass a URL-encoded JSON object as the ?where= / ?order= value.";
14
+ /** Resolution for an empty / malformed / unwrapped write body. */
15
+ const WRITE_BODY_SHAPE_RESOLUTION = "Send a JSON body shaped { \"doc\": { ... } } for POST/PUT, or { \"patch\": { ... } } for PATCH.";
16
+ //#endregion
4
17
  //#region packages/server/src/contract.ts
5
18
  /**
6
19
  * Single drift surface for the {@link HttpErrorEnvelope} shape. The
7
20
  * router and both adapters call this — adding or renaming a field on
8
- * the wire is a one-edit change here.
21
+ * the wire is a one-edit change here. `retriable` is additive (always
22
+ * present, defaulted from `code`); older clients ignore it.
9
23
  */
10
- const errorEnvelope = (code, message, issues) => ({ error: {
11
- code,
12
- message,
13
- ...issues !== void 0 && issues.length > 0 ? { issues } : {}
14
- } });
24
+ const errorEnvelope = (code, message, issues, resolution, retriable) => {
25
+ const resolved = resolution ?? CODE_RESOLUTIONS[code];
26
+ return { error: {
27
+ code,
28
+ message,
29
+ retriable: retriable ?? isRetriableCode(code),
30
+ ...issues !== void 0 && issues.length > 0 ? { issues } : {},
31
+ ...resolved !== void 0 ? { resolution: resolved } : {}
32
+ } };
33
+ };
15
34
  //#endregion
16
- //#region node_modules/.pnpm/@logtape+logtape@2.1.1/node_modules/@logtape/logtape/dist/filter.js
35
+ //#region node_modules/.pnpm/@logtape+logtape@2.2.2/node_modules/@logtape/logtape/dist/context.js
17
36
  /**
18
- * Converts a {@link FilterLike} value to an actual {@link Filter}.
19
- *
20
- * @param filter The filter-like value to convert.
21
- * @returns The actual filter.
37
+ * Internal symbol for storing category prefix in context.
22
38
  */
23
- function toFilter(filter) {
24
- if (typeof filter === "function") return filter;
25
- return getLevelFilter(filter);
39
+ const categoryPrefixSymbol = Symbol.for("logtape.categoryPrefix");
40
+ /**
41
+ * Gets the current category prefix from context local storage.
42
+ * @returns The current category prefix, or an empty array if not set.
43
+ * @since 1.3.0
44
+ */
45
+ function getCategoryPrefix() {
46
+ const store = LoggerImpl.getLogger().contextLocalStorage?.getStore();
47
+ if (store == null) return [];
48
+ const prefix = store[categoryPrefixSymbol];
49
+ return Array.isArray(prefix) ? prefix : [];
26
50
  }
27
51
  /**
28
- * Returns a filter that accepts log records with the specified level.
52
+ * Gets the current implicit context only when user-visible context keys exist.
29
53
  *
30
- * @param level The level to filter by. If `null`, the filter will reject all
31
- * records.
32
- * @returns The filter.
54
+ * This is intentionally not exported from the public entry point. Hot logging
55
+ * paths use it to avoid allocating a fresh `{}` when no implicit context is
56
+ * active, while `getImplicitContext()` keeps its public return contract.
57
+ * @returns The current implicit context without internal symbol keys, or
58
+ * `undefined` if there is no user-visible implicit context.
33
59
  */
34
- function getLevelFilter(level) {
35
- if (level == null) return () => false;
36
- if (level === "fatal") return (record) => record.level === "fatal";
37
- else if (level === "error") return (record) => record.level === "fatal" || record.level === "error";
38
- else if (level === "warning") return (record) => record.level === "fatal" || record.level === "error" || record.level === "warning";
39
- else if (level === "info") return (record) => record.level === "fatal" || record.level === "error" || record.level === "warning" || record.level === "info";
40
- else if (level === "debug") return (record) => record.level === "fatal" || record.level === "error" || record.level === "warning" || record.level === "info" || record.level === "debug";
41
- else if (level === "trace") return () => true;
42
- throw new TypeError(`Invalid log level: ${level}.`);
60
+ function getImplicitContextIfAny() {
61
+ const store = LoggerImpl.getLogger().contextLocalStorage?.getStore();
62
+ if (store == null) return void 0;
63
+ const keys = Object.keys(store);
64
+ if (keys.length < 1) return void 0;
65
+ const result = {};
66
+ for (const key of keys) result[key] = store[key];
67
+ return result;
43
68
  }
44
69
  //#endregion
45
- //#region node_modules/.pnpm/@logtape+logtape@2.1.1/node_modules/@logtape/logtape/dist/level.js
70
+ //#region node_modules/.pnpm/@logtape+logtape@2.2.2/node_modules/@logtape/logtape/dist/level.js
46
71
  const logLevels = [
47
72
  "trace",
48
73
  "debug",
@@ -67,12 +92,15 @@ function compareLogLevel(a, b) {
67
92
  return aIndex - bIndex;
68
93
  }
69
94
  //#endregion
70
- //#region node_modules/.pnpm/@logtape+logtape@2.1.1/node_modules/@logtape/logtape/dist/logger.js
95
+ //#region node_modules/.pnpm/@logtape+logtape@2.2.2/node_modules/@logtape/logtape/dist/logger.js
71
96
  /**
72
97
  * Symbol to identify lazy values.
73
98
  */
74
99
  const lazySymbol = Symbol.for("logtape.lazy");
75
100
  const throttlingSummaryRecordSymbol = Symbol.for("LogTape.throttlingSummaryRecord");
101
+ const immediateSinkSymbol = Symbol.for("LogTape.sinkSnapshotPolicy.immediate");
102
+ const internalStringLogRecords = /* @__PURE__ */ new WeakSet();
103
+ const resolvedStringLogRecords = /* @__PURE__ */ new WeakSet();
76
104
  /**
77
105
  * Checks if a value is a lazy value.
78
106
  *
@@ -121,7 +149,18 @@ function logStringMessage(logger, level, message, props) {
121
149
  logger.log(level, message, result);
122
150
  }
123
151
  function snapshotLogRecordProperties(record) {
152
+ if (resolvedStringLogRecords.has(record)) return record;
124
153
  const properties = resolveProperties(record.properties);
154
+ if (internalStringLogRecords.has(record)) return {
155
+ category: record.category,
156
+ level: record.level,
157
+ get message() {
158
+ return record.message;
159
+ },
160
+ rawMessage: record.rawMessage,
161
+ timestamp: record.timestamp,
162
+ properties
163
+ };
125
164
  const descriptors = Object.getOwnPropertyDescriptors(record);
126
165
  descriptors.properties = {
127
166
  value: properties,
@@ -130,6 +169,13 @@ function snapshotLogRecordProperties(record) {
130
169
  };
131
170
  return Object.defineProperties({}, descriptors);
132
171
  }
172
+ function hasEnumerableProperties(properties) {
173
+ if (properties == null || typeof properties !== "object") return false;
174
+ return Object.keys(properties).length > 0 || Object.prototype.propertyIsEnumerable.call(properties, throttlingSummaryRecordSymbol);
175
+ }
176
+ function shouldSnapshotForSink(sink) {
177
+ return sink[immediateSinkSymbol] !== true;
178
+ }
133
179
  /**
134
180
  * Get a logger with the given category.
135
181
  *
@@ -150,7 +196,7 @@ function getLogger$1(category = []) {
150
196
  */
151
197
  const globalRootLoggerSymbol = Symbol.for("logtape.rootLogger");
152
198
  function isMetaLoggerCategory(category) {
153
- return category.length === 2 && category[0] === "logtape" && category[1] === "meta";
199
+ return category.length >= 2 && category[0] === "logtape" && category[1] === "meta";
154
200
  }
155
201
  /**
156
202
  * A logger implementation. Do not use this directly; use {@link getLogger}
@@ -161,10 +207,11 @@ var LoggerImpl = class LoggerImpl {
161
207
  children;
162
208
  category;
163
209
  sinks;
164
- parentSinks = "inherit";
165
210
  filters;
166
- lowestLevel = "trace";
167
211
  contextLocalStorage;
212
+ #parentSinks = "inherit";
213
+ #lowestLevel = "trace";
214
+ #sinkPlanCache = {};
168
215
  static getLogger(category = []) {
169
216
  let rootLogger = globalRootLoggerSymbol in globalThis ? globalThis[globalRootLoggerSymbol] ?? null : null;
170
217
  if (rootLogger == null) {
@@ -192,6 +239,20 @@ var LoggerImpl = class LoggerImpl {
192
239
  this.sinks = [];
193
240
  this.filters = [];
194
241
  }
242
+ get parentSinks() {
243
+ return this.#parentSinks;
244
+ }
245
+ set parentSinks(value) {
246
+ if (this.#parentSinks === value) return;
247
+ this.#parentSinks = value;
248
+ }
249
+ get lowestLevel() {
250
+ return this.#lowestLevel;
251
+ }
252
+ set lowestLevel(value) {
253
+ if (this.#lowestLevel === value) return;
254
+ this.#lowestLevel = value;
255
+ }
195
256
  getChild(subcategory) {
196
257
  const name = typeof subcategory === "string" ? subcategory : subcategory[0];
197
258
  const childRef = this.children[name];
@@ -232,23 +293,88 @@ var LoggerImpl = class LoggerImpl {
232
293
  return true;
233
294
  }
234
295
  *getSinks(level) {
235
- if (this.lowestLevel === null || compareLogLevel(level, this.lowestLevel) < 0) return;
236
- if (this.parent != null && this.parentSinks === "inherit") for (const sink of this.parent.getSinks(level)) yield sink;
237
- for (const sink of this.sinks) yield sink;
296
+ const plan = this.getSinkDispatchPlan(level);
297
+ switch (plan.kind) {
298
+ case "none": return;
299
+ case "one":
300
+ yield plan.sink;
301
+ return;
302
+ case "many":
303
+ yield* plan.sinks;
304
+ return;
305
+ }
306
+ }
307
+ getSinkDispatchPlan(level) {
308
+ const cached = this.#sinkPlanCache[level];
309
+ if (cached != null && this.isSinkDispatchPlanFresh(level, cached)) return cached;
310
+ const parentPlan = this.parent != null && this.parentSinks === "inherit" ? this.parent.getSinkDispatchPlan(level) : void 0;
311
+ const plan = this.createSinkDispatchPlan(level, parentPlan);
312
+ this.#sinkPlanCache[level] = plan;
313
+ return plan;
314
+ }
315
+ isSinkDispatchPlanFresh(level, plan) {
316
+ if (plan.lowestLevel !== this.lowestLevel || plan.parentSinks !== this.parentSinks || plan.localSinks.length !== this.sinks.length) return false;
317
+ for (let i = 0; i < plan.localSinks.length; i++) if (plan.localSinks[i] !== this.sinks[i]) return false;
318
+ const parentPlan = this.parent != null && this.parentSinks === "inherit" ? this.parent.getSinkDispatchPlan(level) : void 0;
319
+ return plan.parentPlan === parentPlan;
320
+ }
321
+ createSinkDispatchPlan(level, parentPlan) {
322
+ const state = {
323
+ localSinks: [...this.sinks],
324
+ parentSinks: this.parentSinks,
325
+ lowestLevel: this.lowestLevel,
326
+ parentPlan
327
+ };
328
+ if (state.lowestLevel === null) return {
329
+ ...state,
330
+ kind: "none"
331
+ };
332
+ if (compareLogLevel(level, state.lowestLevel) < 0) return {
333
+ ...state,
334
+ kind: "none"
335
+ };
336
+ let firstSink;
337
+ let sinks;
338
+ const appendSink = (sink) => {
339
+ if (sinks != null) sinks.push(sink);
340
+ else if (firstSink == null) firstSink = sink;
341
+ else sinks = [firstSink, sink];
342
+ };
343
+ if (parentPlan != null) {
344
+ if (parentPlan.kind === "one") firstSink = parentPlan.sink;
345
+ else if (parentPlan.kind === "many") sinks = [...parentPlan.sinks];
346
+ }
347
+ for (const sink of state.localSinks) appendSink(sink);
348
+ if (sinks != null) return {
349
+ ...state,
350
+ kind: "many",
351
+ sinks
352
+ };
353
+ if (firstSink != null) return {
354
+ ...state,
355
+ kind: "one",
356
+ sink: firstSink
357
+ };
358
+ return {
359
+ ...state,
360
+ kind: "none"
361
+ };
238
362
  }
239
363
  isEnabledFor(level) {
240
364
  const categoryPrefix = isMetaLoggerCategory(this.category) ? [] : getCategoryPrefix();
241
365
  return (categoryPrefix.length > 0 ? LoggerImpl.getNearestExistingLogger([...categoryPrefix, ...this.category]) : this).isEnabledForResolved(level);
242
366
  }
243
367
  isEnabledForResolved(level) {
244
- if (this.lowestLevel === null || compareLogLevel(level, this.lowestLevel) < 0) return false;
245
- for (const _ of this.getSinks(level)) return true;
246
- return false;
368
+ return this.getSinkDispatchPlan(level).kind !== "none";
247
369
  }
248
370
  emit(record, bypassSinks) {
249
371
  const baseCategory = "category" in record ? record.category : this.category;
250
372
  const categoryPrefix = isMetaLoggerCategory(baseCategory) ? [] : getCategoryPrefix();
251
373
  const fullCategory = categoryPrefix.length > 0 ? [...categoryPrefix, ...baseCategory] : baseCategory;
374
+ if (categoryPrefix.length < 1 && Object.prototype.hasOwnProperty.call(record, "category")) {
375
+ this.emitResolved(record, bypassSinks);
376
+ return;
377
+ }
252
378
  const descriptors = Object.getOwnPropertyDescriptors(record);
253
379
  descriptors.category = {
254
380
  value: fullCategory,
@@ -260,14 +386,36 @@ var LoggerImpl = class LoggerImpl {
260
386
  }
261
387
  emitResolved(record, bypassSinks) {
262
388
  if (this.lowestLevel === null || compareLogLevel(record.level, this.lowestLevel) < 0 || !this.filter(record)) return;
263
- const sinks = [...this.getSinks(record.level)];
264
- if (sinks.length < 1) return;
389
+ const plan = this.getSinkDispatchPlan(record.level);
390
+ if (plan.kind === "none") return;
265
391
  let snapshot;
266
392
  let snapshotFailed = false;
267
- for (const sink of sinks) {
393
+ if (plan.kind === "one") {
394
+ const sink = plan.sink;
395
+ if (bypassSinks?.has(sink)) return;
396
+ try {
397
+ if (shouldSnapshotForSink(sink)) try {
398
+ snapshot = snapshotLogRecordProperties(record);
399
+ } catch {
400
+ snapshotFailed = true;
401
+ snapshot = record;
402
+ }
403
+ sink(snapshot ?? record);
404
+ } catch (error) {
405
+ const bypassSinks2 = new Set(bypassSinks);
406
+ bypassSinks2.add(sink);
407
+ metaLogger.log("fatal", "Failed to emit a log record to sink {sink}: {error}", {
408
+ sink,
409
+ error,
410
+ record
411
+ }, bypassSinks2);
412
+ }
413
+ return;
414
+ }
415
+ for (const sink of plan.sinks) {
268
416
  if (bypassSinks?.has(sink)) continue;
269
417
  try {
270
- if (snapshot == null && !snapshotFailed) try {
418
+ if (snapshot == null && !snapshotFailed && shouldSnapshotForSink(sink)) try {
271
419
  snapshot = snapshotLogRecordProperties(record);
272
420
  } catch {
273
421
  snapshotFailed = true;
@@ -286,7 +434,20 @@ var LoggerImpl = class LoggerImpl {
286
434
  }
287
435
  }
288
436
  log(level, rawMessage, properties, bypassSinks) {
289
- const implicitContext = getImplicitContext();
437
+ const implicitContext = getImplicitContextIfAny();
438
+ if (typeof properties !== "function" && implicitContext == null && !rawMessage.includes("{") && !hasEnumerableProperties(properties)) {
439
+ const record$1 = {
440
+ category: this.category,
441
+ level,
442
+ message: [rawMessage],
443
+ rawMessage,
444
+ timestamp: Date.now(),
445
+ properties: {}
446
+ };
447
+ resolvedStringLogRecords.add(record$1);
448
+ this.emit(record$1, bypassSinks);
449
+ return;
450
+ }
290
451
  let cachedProps = void 0;
291
452
  let cachedMessage = void 0;
292
453
  const record = typeof properties === "function" ? {
@@ -300,7 +461,7 @@ var LoggerImpl = class LoggerImpl {
300
461
  rawMessage,
301
462
  get properties() {
302
463
  if (cachedProps == null) cachedProps = resolveProperties({
303
- ...implicitContext,
464
+ ...implicitContext ?? {},
304
465
  ...properties()
305
466
  });
306
467
  return cachedProps;
@@ -316,16 +477,17 @@ var LoggerImpl = class LoggerImpl {
316
477
  rawMessage,
317
478
  get properties() {
318
479
  if (cachedProps == null) cachedProps = resolveProperties({
319
- ...implicitContext,
480
+ ...implicitContext ?? {},
320
481
  ...properties
321
482
  });
322
483
  return cachedProps;
323
484
  }
324
485
  };
486
+ internalStringLogRecords.add(record);
325
487
  this.emit(record, bypassSinks);
326
488
  }
327
489
  logLazily(level, callback, properties = {}) {
328
- const implicitContext = getImplicitContext();
490
+ const implicitContext = getImplicitContextIfAny();
329
491
  let rawMessage = void 0;
330
492
  let msg = void 0;
331
493
  function realizeMessage() {
@@ -349,13 +511,13 @@ var LoggerImpl = class LoggerImpl {
349
511
  },
350
512
  timestamp: Date.now(),
351
513
  properties: {
352
- ...implicitContext,
514
+ ...implicitContext ?? {},
353
515
  ...properties
354
516
  }
355
517
  });
356
518
  }
357
519
  logTemplate(level, messageTemplate, values, properties = {}) {
358
- const implicitContext = getImplicitContext();
520
+ const implicitContext = getImplicitContextIfAny();
359
521
  this.emit({
360
522
  category: this.category,
361
523
  level,
@@ -363,7 +525,7 @@ var LoggerImpl = class LoggerImpl {
363
525
  rawMessage: messageTemplate,
364
526
  timestamp: Date.now(),
365
527
  properties: {
366
- ...implicitContext,
528
+ ...implicitContext ?? {},
367
529
  ...properties
368
530
  }
369
531
  });
@@ -843,44 +1005,43 @@ function renderMessage(template, values) {
843
1005
  return args;
844
1006
  }
845
1007
  //#endregion
846
- //#region node_modules/.pnpm/@logtape+logtape@2.1.1/node_modules/@logtape/logtape/dist/context.js
1008
+ //#region node_modules/.pnpm/@logtape+logtape@2.2.2/node_modules/@logtape/logtape/dist/filter.js
847
1009
  /**
848
- * Internal symbol for storing category prefix in context.
849
- */
850
- const categoryPrefixSymbol = Symbol.for("logtape.categoryPrefix");
851
- /**
852
- * Gets the current category prefix from context local storage.
853
- * @returns The current category prefix, or an empty array if not set.
854
- * @since 1.3.0
1010
+ * Converts a {@link FilterLike} value to an actual {@link Filter}.
1011
+ *
1012
+ * @param filter The filter-like value to convert.
1013
+ * @returns The actual filter.
855
1014
  */
856
- function getCategoryPrefix() {
857
- const store = LoggerImpl.getLogger().contextLocalStorage?.getStore();
858
- if (store == null) return [];
859
- const prefix = store[categoryPrefixSymbol];
860
- return Array.isArray(prefix) ? prefix : [];
1015
+ function toFilter(filter) {
1016
+ if (typeof filter === "function") return filter;
1017
+ return getLevelFilter(filter);
861
1018
  }
862
1019
  /**
863
- * Gets the current implicit context from context local storage, excluding
864
- * internal symbol keys (like category prefix).
865
- * @returns The current implicit context without internal symbol keys.
866
- * @since 1.3.0
1020
+ * Returns a filter that accepts log records with the specified level.
1021
+ *
1022
+ * @param level The level to filter by. If `null`, the filter will reject all
1023
+ * records.
1024
+ * @returns The filter.
867
1025
  */
868
- function getImplicitContext() {
869
- const store = LoggerImpl.getLogger().contextLocalStorage?.getStore();
870
- if (store == null) return {};
871
- const result = {};
872
- for (const key of Object.keys(store)) result[key] = store[key];
873
- return result;
1026
+ function getLevelFilter(level) {
1027
+ if (level == null) return () => false;
1028
+ if (level === "fatal") return (record) => record.level === "fatal";
1029
+ else if (level === "error") return (record) => record.level === "fatal" || record.level === "error";
1030
+ else if (level === "warning") return (record) => record.level === "fatal" || record.level === "error" || record.level === "warning";
1031
+ else if (level === "info") return (record) => record.level === "fatal" || record.level === "error" || record.level === "warning" || record.level === "info";
1032
+ else if (level === "debug") return (record) => record.level === "fatal" || record.level === "error" || record.level === "warning" || record.level === "info" || record.level === "debug";
1033
+ else if (level === "trace") return () => true;
1034
+ throw new TypeError(`Invalid log level: ${level}.`);
874
1035
  }
875
1036
  //#endregion
876
- //#region node_modules/.pnpm/@logtape+logtape@2.1.1/node_modules/@logtape/logtape/dist/util.js
1037
+ //#region node_modules/.pnpm/@logtape+logtape@2.2.2/node_modules/@logtape/logtape/dist/util.js
877
1038
  var util_exports = /* @__PURE__ */ __exportAll({ inspect: () => inspect$1 });
878
1039
  function inspect$1(obj, options) {
879
1040
  const indent = options?.compact === true ? void 0 : 2;
880
1041
  return JSON.stringify(obj, null, indent);
881
1042
  }
882
1043
  //#endregion
883
- //#region node_modules/.pnpm/@logtape+logtape@2.1.1/node_modules/@logtape/logtape/dist/formatter.js
1044
+ //#region node_modules/.pnpm/@logtape+logtape@2.2.2/node_modules/@logtape/logtape/dist/formatter.js
884
1045
  /**
885
1046
  * The severity level abbreviations.
886
1047
  */
@@ -1124,6 +1285,31 @@ function jsonReplacer(_key, value) {
1124
1285
  for (const key of Object.keys(value)) if (!(key in serialized)) serialized[key] = value[key];
1125
1286
  return serialized;
1126
1287
  }
1288
+ function renderDefaultJsonLinesMessage(message) {
1289
+ const messageLength = message.length;
1290
+ if (messageLength === 1) return message[0];
1291
+ if (messageLength === 3) return message[0] + JSON.stringify(message[1]) + message[2];
1292
+ let rendered = message[0];
1293
+ for (let i = 1; i < messageLength; i++) rendered += i & 1 ? JSON.stringify(message[i]) : message[i];
1294
+ return rendered;
1295
+ }
1296
+ function stringifyJsonLinesField(key, value) {
1297
+ if (value != null && (typeof value === "object" || typeof value === "function" || typeof value === "bigint")) {
1298
+ const toJSON = value.toJSON;
1299
+ if (typeof toJSON === "function") value = toJSON.call(value, key);
1300
+ }
1301
+ return JSON.stringify(jsonReplacer(key, value), jsonReplacer);
1302
+ }
1303
+ function formatDefaultJsonLinesRecord(record, lineEnding) {
1304
+ const level = record.level === "warning" ? "WARN" : record.level.toUpperCase();
1305
+ const messageJson = stringifyJsonLinesField("message", renderDefaultJsonLinesMessage(record.message));
1306
+ const propertiesJson = stringifyJsonLinesField("properties", record.properties);
1307
+ let line = `{"@timestamp":${JSON.stringify(new Date(record.timestamp).toISOString())},"level":${JSON.stringify(level)}`;
1308
+ if (messageJson !== void 0) line += `,"message":${messageJson}`;
1309
+ line += `,"logger":${JSON.stringify(record.category.join("."))}`;
1310
+ if (propertiesJson !== void 0) line += `,"properties":${propertiesJson}`;
1311
+ return `${line}}${lineEnding}`;
1312
+ }
1127
1313
  /**
1128
1314
  * Get a text formatter with the specified options. Although it's flexible
1129
1315
  * enough to create a custom formatter, if you want more control, you can
@@ -1260,31 +1446,7 @@ getAnsiColorFormatter();
1260
1446
  */
1261
1447
  function getJsonLinesFormatter(options = {}) {
1262
1448
  const lineEnding = getLineEndingValue(options.lineEnding);
1263
- if (!options.categorySeparator && !options.message && !options.properties) return (record) => {
1264
- if (record.message.length === 3) return JSON.stringify({
1265
- "@timestamp": new Date(record.timestamp).toISOString(),
1266
- level: record.level === "warning" ? "WARN" : record.level.toUpperCase(),
1267
- message: record.message[0] + JSON.stringify(record.message[1]) + record.message[2],
1268
- logger: record.category.join("."),
1269
- properties: record.properties
1270
- }, jsonReplacer) + lineEnding;
1271
- if (record.message.length === 1) return JSON.stringify({
1272
- "@timestamp": new Date(record.timestamp).toISOString(),
1273
- level: record.level === "warning" ? "WARN" : record.level.toUpperCase(),
1274
- message: record.message[0],
1275
- logger: record.category.join("."),
1276
- properties: record.properties
1277
- }, jsonReplacer) + lineEnding;
1278
- let msg = record.message[0];
1279
- for (let i = 1; i < record.message.length; i++) msg += i & 1 ? JSON.stringify(record.message[i]) : record.message[i];
1280
- return JSON.stringify({
1281
- "@timestamp": new Date(record.timestamp).toISOString(),
1282
- level: record.level === "warning" ? "WARN" : record.level.toUpperCase(),
1283
- message: msg,
1284
- logger: record.category.join("."),
1285
- properties: record.properties
1286
- }, jsonReplacer) + lineEnding;
1287
- };
1449
+ if (!options.categorySeparator && !options.message && !options.properties) return (record) => formatDefaultJsonLinesRecord(record, lineEnding);
1288
1450
  const isTemplateMessage = options.message === "template";
1289
1451
  const propertiesOption = options.properties ?? "nest:properties";
1290
1452
  let joinCategory;
@@ -1496,7 +1658,7 @@ function defaultConsoleFormatter(record) {
1496
1658
  ];
1497
1659
  }
1498
1660
  //#endregion
1499
- //#region node_modules/.pnpm/@logtape+logtape@2.1.1/node_modules/@logtape/logtape/dist/sink.js
1661
+ //#region node_modules/.pnpm/@logtape+logtape@2.2.2/node_modules/@logtape/logtape/dist/sink.js
1500
1662
  /**
1501
1663
  * A console sink factory that returns a sink that logs to the console.
1502
1664
  *
@@ -1531,6 +1693,7 @@ function getConsoleSink(options = {}) {
1531
1693
  const flushInterval = nonBlockingConfig.flushInterval ?? 100;
1532
1694
  const buffer = [];
1533
1695
  let flushTimer = null;
1696
+ let scheduledFlushTimer = null;
1534
1697
  let disposed = false;
1535
1698
  let flushScheduled = false;
1536
1699
  const maxBufferSize = bufferSize * 2;
@@ -1544,7 +1707,8 @@ function getConsoleSink(options = {}) {
1544
1707
  function scheduleFlush() {
1545
1708
  if (flushScheduled) return;
1546
1709
  flushScheduled = true;
1547
- setTimeout(() => {
1710
+ scheduledFlushTimer = setTimeout(() => {
1711
+ scheduledFlushTimer = null;
1548
1712
  flushScheduled = false;
1549
1713
  flush();
1550
1714
  }, 0);
@@ -1568,12 +1732,17 @@ function getConsoleSink(options = {}) {
1568
1732
  clearInterval(flushTimer);
1569
1733
  flushTimer = null;
1570
1734
  }
1735
+ if (scheduledFlushTimer !== null) {
1736
+ clearTimeout(scheduledFlushTimer);
1737
+ scheduledFlushTimer = null;
1738
+ flushScheduled = false;
1739
+ }
1571
1740
  flush();
1572
1741
  };
1573
1742
  return nonBlockingSink;
1574
1743
  }
1575
1744
  //#endregion
1576
- //#region node_modules/.pnpm/@logtape+logtape@2.1.1/node_modules/@logtape/logtape/dist/config.js
1745
+ //#region node_modules/.pnpm/@logtape+logtape@2.2.2/node_modules/@logtape/logtape/dist/config.js
1577
1746
  /**
1578
1747
  * The current configuration, if any. Otherwise, `null`.
1579
1748
  */
@@ -1604,7 +1773,8 @@ const asyncSinkDisposables = /* @__PURE__ */ new Set();
1604
1773
  * Check if a config is for the meta logger.
1605
1774
  */
1606
1775
  function isLoggerConfigMeta(cfg) {
1607
- return cfg.category.length === 0 || cfg.category.length === 1 && cfg.category[0] === "logtape" || cfg.category.length === 2 && cfg.category[0] === "logtape" && cfg.category[1] === "meta";
1776
+ const category = Array.isArray(cfg.category) ? cfg.category : [cfg.category];
1777
+ return category.length === 0 || category.length === 1 && category[0] === "logtape" || category.length === 2 && category[0] === "logtape" && category[1] === "meta";
1608
1778
  }
1609
1779
  function registerDisposeHook(allowAsync) {
1610
1780
  const handler = allowAsync ? dispose : disposeSync;
@@ -1840,7 +2010,7 @@ var ConfigError = class extends Error {
1840
2010
  */
1841
2011
  constructor(message) {
1842
2012
  super(message);
1843
- this.name = "ConfigureError";
2013
+ this.name = "ConfigError";
1844
2014
  }
1845
2015
  };
1846
2016
  //#endregion
@@ -2211,7 +2381,7 @@ const serializeError = (err, includeStack = false) => {
2211
2381
  * pay the formatting cost in production where the level is
2212
2382
  * `info` or higher. (LogTape provides `isEnabledFor` since 2.0.0.)
2213
2383
  */
2214
- const CLASS_A_OPS = new Set([
2384
+ const CLASS_A_OPS = /* @__PURE__ */ new Set([
2215
2385
  "put",
2216
2386
  "delete",
2217
2387
  "list"
@@ -2328,6 +2498,6 @@ const observableStorage = (inner) => {
2328
2498
  };
2329
2499
  };
2330
2500
  //#endregion
2331
- export { withHttpObservability as a, configureObservability as c, serializeError as i, getLogger as l, flushCanonicalLine as n, deriveOutcome as o, flushUnauthorizedAndRespond as r, CATEGORY as s, observableStorage as t, errorEnvelope as u };
2501
+ export { withHttpObservability as a, configureObservability as c, WHERE_ORDER_JSON_RESOLUTION as d, WRITE_BODY_SHAPE_RESOLUTION as f, serializeError as i, getLogger as l, flushCanonicalLine as n, deriveOutcome as o, flushUnauthorizedAndRespond as r, CATEGORY as s, observableStorage as t, errorEnvelope as u };
2332
2502
 
2333
- //# sourceMappingURL=observability-CpOiEN0k.js.map
2503
+ //# sourceMappingURL=observability-wzs3-BL_.js.map