@h-ai/core 1.0.0-beta.18 → 1.0.0-beta.19

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.
@@ -159,11 +159,11 @@ declare const EnvSchema: z.ZodEnum<{
159
159
  * ```
160
160
  */
161
161
  declare const LogLevelSchema: z.ZodEnum<{
162
- error: "error";
163
162
  trace: "trace";
164
163
  debug: "debug";
165
164
  info: "info";
166
165
  warn: "warn";
166
+ error: "error";
167
167
  fatal: "fatal";
168
168
  }>;
169
169
  /**
@@ -188,11 +188,11 @@ declare const LogFormatSchema: z.ZodEnum<{
188
188
  */
189
189
  declare const LoggingConfigSchema: z.ZodObject<{
190
190
  level: z.ZodDefault<z.ZodEnum<{
191
- error: "error";
192
191
  trace: "trace";
193
192
  debug: "debug";
194
193
  info: "info";
195
194
  warn: "warn";
195
+ error: "error";
196
196
  fatal: "fatal";
197
197
  }>>;
198
198
  format: z.ZodDefault<z.ZodEnum<{
@@ -225,11 +225,11 @@ declare const CoreConfigSchema: z.ZodObject<{
225
225
  }>>;
226
226
  logging: z.ZodOptional<z.ZodObject<{
227
227
  level: z.ZodDefault<z.ZodEnum<{
228
- error: "error";
229
228
  trace: "trace";
230
229
  debug: "debug";
231
230
  info: "info";
232
231
  warn: "warn";
232
+ error: "error";
233
233
  fatal: "fatal";
234
234
  }>>;
235
235
  format: z.ZodDefault<z.ZodEnum<{
@@ -1806,6 +1806,7 @@ declare const typeUtils: {
1806
1806
  declare function formatMessage(error: Pick<HaiError, 'message' | 'traceId'>): string;
1807
1807
  /**
1808
1808
  * HTTP/UI 边界仅公开安全消息和关联标识;内部异常及扩展信息留在脱敏日志。
1809
+ * 只有明确有效的 4xx 状态公开业务消息,缺失或非法状态按 500 处理。
1809
1810
  * @example
1810
1811
  * ```ts
1811
1812
  * import { core } from '@h-ai/core'
@@ -2083,6 +2084,7 @@ declare const HaiCommonError: {
2083
2084
  readonly VALIDATION_ERROR: HaiErrorDef;
2084
2085
  readonly INVALID_REQUEST: HaiErrorDef;
2085
2086
  readonly PARAMETER_MISSING: HaiErrorDef;
2087
+ readonly RATE_LIMIT_EXCEEDED: HaiErrorDef;
2086
2088
  readonly NOT_FOUND: HaiErrorDef;
2087
2089
  readonly ALREADY_EXISTS: HaiErrorDef;
2088
2090
  readonly CONFLICT: HaiErrorDef;
@@ -2882,4 +2884,5 @@ interface ModuleRuntime {
2882
2884
  close: () => Promise<HaiResult<void>>;
2883
2885
  }
2884
2886
 
2885
- export { type PaginationOptionsInput as $, type AccessCondition as A, type BrowserCoreFunctions as B, type ConfigFn as C, LogFormatSchema as D, type Env as E, type LogLevel as F, LogLevelSchema as G, HaiCommonError as H, type I18nFn as I, type LogObserver as J, type LogRecord as K, type Locale as L, type Logger as M, type LoggerFunctions as N, type LoggerOptions as O, type LoggingConfig as P, LoggingConfigSchema as Q, type MatchHandlers as R, type MessageDictionary as S, type MessageOptions as T, type ModuleFn as U, type ModuleRuntime as V, type NodeCoreFunctions as W, type NotInitializedKit as X, type ObjectFn as Y, type PaginatedResult as Z, type PaginationOptions as _, AccessConditionSchema as a, type RequestAccessCheck as a0, type RequestAccessConfigInput as a1, RequestAccessConfigSchema as a2, type RequestAccessPolicy as a3, RequestAccessPolicySchema as a4, type RequestContext as a5, type RequestEncryptionMode as a6, type RuntimeStep as a7, type SanitizeFn as a8, type SanitizeSensitiveFieldsOptions as a9, type SensitiveKeyMatcher as aa, type StringFn as ab, type TimeFn as ac, type TrustedProxies as ad, TrustedProxiesSchema as ae, type TypeUtilFn as af, type ValidationFormError as ag, type WatchCallback as ah, type ZodMessageGetter as ai, type ZodValidationFn as aj, type ZodValidationMessageKey as ak, err as al, ok as am, type AccessDecision as b, type AccessFunctions as c, type ArrayFn as d, type AsyncFn as e, type BrowserConfigFn as f, type CoreConfig as g, CoreConfigSchema as h, type CoreFunctions as i, type CoreLogger as j, type CoreOptions as k, type CreateNotInitializedKitFn as l, EnvSchema as m, type ErrorFn as n, type ErrorInfo as o, type ErrorInfoValue as p, HaiConfigError as q, type HaiError as r, type HaiErrorDef as s, type HaiResult as t, type IdFn as u, type InterpolationParams as v, type LocaleInfo as w, type LocaleMessages as x, type LogContext as y, type LogFormat as z };
2887
+ export { LogFormatSchema as D, LogLevelSchema as G, HaiCommonError as H, LoggingConfigSchema as Q, AccessConditionSchema as a, RequestAccessConfigSchema as a2, RequestAccessPolicySchema as a4, TrustedProxiesSchema as ae, err as al, ok as am, CoreConfigSchema as h, EnvSchema as m, HaiConfigError as q };
2888
+ export type { PaginationOptionsInput as $, AccessCondition as A, BrowserCoreFunctions as B, ConfigFn as C, Env as E, LogLevel as F, I18nFn as I, LogObserver as J, LogRecord as K, Locale as L, Logger as M, LoggerFunctions as N, LoggerOptions as O, LoggingConfig as P, MatchHandlers as R, MessageDictionary as S, MessageOptions as T, ModuleFn as U, ModuleRuntime as V, NodeCoreFunctions as W, NotInitializedKit as X, ObjectFn as Y, PaginatedResult as Z, PaginationOptions as _, RequestAccessCheck as a0, RequestAccessConfigInput as a1, RequestAccessPolicy as a3, RequestContext as a5, RequestEncryptionMode as a6, RuntimeStep as a7, SanitizeFn as a8, SanitizeSensitiveFieldsOptions as a9, SensitiveKeyMatcher as aa, StringFn as ab, TimeFn as ac, TrustedProxies as ad, TypeUtilFn as af, ValidationFormError as ag, WatchCallback as ah, ZodMessageGetter as ai, ZodValidationFn as aj, ZodValidationMessageKey as ak, AccessDecision as b, AccessFunctions as c, ArrayFn as d, AsyncFn as e, BrowserConfigFn as f, CoreConfig as g, CoreFunctions as i, CoreLogger as j, CoreOptions as k, CreateNotInitializedKitFn as l, ErrorFn as n, ErrorInfo as o, ErrorInfoValue as p, HaiError as r, HaiErrorDef as s, HaiResult as t, IdFn as u, InterpolationParams as v, LocaleInfo as w, LocaleMessages as x, LogContext as y, LogFormat as z };
package/dist/node.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { W as NodeCoreFunctions } from './core-types-n2KjBtto.js';
2
- export { A as AccessCondition, a as AccessConditionSchema, b as AccessDecision, c as AccessFunctions, d as ArrayFn, e as AsyncFn, f as BrowserConfigFn, B as BrowserCoreFunctions, C as ConfigFn, g as CoreConfig, h as CoreConfigSchema, i as CoreFunctions, j as CoreLogger, k as CoreOptions, l as CreateNotInitializedKitFn, E as Env, m as EnvSchema, n as ErrorFn, o as ErrorInfo, p as ErrorInfoValue, H as HaiCommonError, q as HaiConfigError, r as HaiError, s as HaiErrorDef, t as HaiResult, I as I18nFn, u as IdFn, v as InterpolationParams, L as Locale, w as LocaleInfo, x as LocaleMessages, y as LogContext, z as LogFormat, D as LogFormatSchema, F as LogLevel, G as LogLevelSchema, J as LogObserver, K as LogRecord, M as Logger, N as LoggerFunctions, O as LoggerOptions, P as LoggingConfig, Q as LoggingConfigSchema, R as MatchHandlers, S as MessageDictionary, T as MessageOptions, U as ModuleFn, V as ModuleRuntime, X as NotInitializedKit, Y as ObjectFn, Z as PaginatedResult, _ as PaginationOptions, $ as PaginationOptionsInput, a0 as RequestAccessCheck, a1 as RequestAccessConfigInput, a2 as RequestAccessConfigSchema, a3 as RequestAccessPolicy, a4 as RequestAccessPolicySchema, a5 as RequestContext, a6 as RequestEncryptionMode, a7 as RuntimeStep, a8 as SanitizeFn, a9 as SanitizeSensitiveFieldsOptions, aa as SensitiveKeyMatcher, ab as StringFn, ac as TimeFn, ad as TrustedProxies, ae as TrustedProxiesSchema, af as TypeUtilFn, ag as ValidationFormError, ah as WatchCallback, ai as ZodMessageGetter, aj as ZodValidationFn, ak as ZodValidationMessageKey, al as err, am as ok } from './core-types-n2KjBtto.js';
1
+ import { W as NodeCoreFunctions } from './core-types-Dp3Vr2uI.js';
2
+ export { A as AccessCondition, a as AccessConditionSchema, b as AccessDecision, c as AccessFunctions, d as ArrayFn, e as AsyncFn, f as BrowserConfigFn, B as BrowserCoreFunctions, C as ConfigFn, g as CoreConfig, h as CoreConfigSchema, i as CoreFunctions, j as CoreLogger, k as CoreOptions, l as CreateNotInitializedKitFn, E as Env, m as EnvSchema, n as ErrorFn, o as ErrorInfo, p as ErrorInfoValue, H as HaiCommonError, q as HaiConfigError, r as HaiError, s as HaiErrorDef, t as HaiResult, I as I18nFn, u as IdFn, v as InterpolationParams, L as Locale, w as LocaleInfo, x as LocaleMessages, y as LogContext, z as LogFormat, D as LogFormatSchema, F as LogLevel, G as LogLevelSchema, J as LogObserver, K as LogRecord, M as Logger, N as LoggerFunctions, O as LoggerOptions, P as LoggingConfig, Q as LoggingConfigSchema, R as MatchHandlers, S as MessageDictionary, T as MessageOptions, U as ModuleFn, V as ModuleRuntime, X as NotInitializedKit, Y as ObjectFn, Z as PaginatedResult, _ as PaginationOptions, $ as PaginationOptionsInput, a0 as RequestAccessCheck, a1 as RequestAccessConfigInput, a2 as RequestAccessConfigSchema, a3 as RequestAccessPolicy, a4 as RequestAccessPolicySchema, a5 as RequestContext, a6 as RequestEncryptionMode, a7 as RuntimeStep, a8 as SanitizeFn, a9 as SanitizeSensitiveFieldsOptions, aa as SensitiveKeyMatcher, ab as StringFn, ac as TimeFn, ad as TrustedProxies, ae as TrustedProxiesSchema, af as TypeUtilFn, ag as ValidationFormError, ah as WatchCallback, ai as ZodMessageGetter, aj as ZodValidationFn, ak as ZodValidationMessageKey, al as err, am as ok } from './core-types-Dp3Vr2uI.js';
3
3
  import 'zod';
4
4
 
5
5
  /**
package/dist/node.js CHANGED
@@ -1,5 +1,5 @@
1
- import { installRequestLocales, installRequestContext, createCore, i18n, err, HaiConfigError, ok, RequestAccessConfigSchema, RequestAccessPolicySchema, AccessConditionSchema, requestContext, sanitize, emitLogRecord, sanitizeLogFields, CoreConfigSchema } from './chunk-MYNB4HIZ.js';
2
- export { AccessConditionSchema, CoreConfigSchema, EnvSchema, HaiCommonError, HaiConfigError, LogFormatSchema, LogLevelSchema, LoggingConfigSchema, RequestAccessConfigSchema, RequestAccessPolicySchema, TrustedProxiesSchema, err, ok } from './chunk-MYNB4HIZ.js';
1
+ import { installRequestLocales, installRequestContext, createCore, i18n, err, HaiConfigError, ok, RequestAccessConfigSchema, RequestAccessPolicySchema, AccessConditionSchema, requestContext, sanitize, emitLogRecord, sanitizeLogFields, CoreConfigSchema } from './chunk-WU6HUTBO.js';
2
+ export { AccessConditionSchema, CoreConfigSchema, EnvSchema, HaiCommonError, HaiConfigError, LogFormatSchema, LogLevelSchema, LoggingConfigSchema, RequestAccessConfigSchema, RequestAccessPolicySchema, TrustedProxiesSchema, err, ok } from './chunk-WU6HUTBO.js';
3
3
  import { AsyncLocalStorage } from 'async_hooks';
4
4
  import { Buffer } from 'buffer';
5
5
  import { timingSafeEqual } from 'crypto';
@@ -36,8 +36,9 @@ function addAddress(list, entry) {
36
36
  return;
37
37
  }
38
38
  const bits = Number(prefix);
39
- if (!/^\d+$/.test(prefix) || bits < 0 || bits > (family === 4 ? 32 : 128))
39
+ if (!/^\d+$/.test(prefix) || bits < 0 || bits > (family === 4 ? 32 : 128)) {
40
40
  throw new Error("Invalid CIDR prefix");
41
+ }
41
42
  list.addSubnet(address, bits, type);
42
43
  }
43
44
  function createClientIpResolver(trustedProxies = "auto") {
@@ -73,8 +74,22 @@ function createClientIpResolver(trustedProxies = "auto") {
73
74
  };
74
75
  }
75
76
  function timeReader(timezone) {
76
- const formatter = new Intl.DateTimeFormat("en-US", { timeZone: timezone, weekday: "short", hour: "2-digit", minute: "2-digit", hourCycle: "h23" });
77
- const weekdays = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
77
+ const formatter = new Intl.DateTimeFormat("en-US", {
78
+ timeZone: timezone,
79
+ weekday: "short",
80
+ hour: "2-digit",
81
+ minute: "2-digit",
82
+ hourCycle: "h23"
83
+ });
84
+ const weekdays = [
85
+ "Mon",
86
+ "Tue",
87
+ "Wed",
88
+ "Thu",
89
+ "Fri",
90
+ "Sat",
91
+ "Sun"
92
+ ];
78
93
  let lastMinute = Number.NaN;
79
94
  let local;
80
95
  return (now) => {
@@ -180,8 +195,12 @@ function normalizeRequestPath(value) {
180
195
  }
181
196
  function createRequestCheck(input = false) {
182
197
  const policy = loadPolicy(input);
183
- if (policy === false)
184
- return Object.assign(() => allowed, { encryption: () => void 0, requiresEncryption: false });
198
+ if (policy === false) {
199
+ return Object.assign(() => allowed, {
200
+ encryption: () => void 0,
201
+ requiresEncryption: false
202
+ });
203
+ }
185
204
  const clocks = /* @__PURE__ */ new Map();
186
205
  const compile = (condition, id) => {
187
206
  let readTime;
@@ -193,12 +212,29 @@ function createRequestCheck(input = false) {
193
212
  };
194
213
  const globalCheck = policy.global ? compile(policy.global) : () => allowed;
195
214
  const exact = /* @__PURE__ */ new Map();
196
- const prefixes = { children: /* @__PURE__ */ new Map(), rules: [] };
197
- const allMethods = ["GET", "HEAD", "POST", "PUT", "PATCH", "DELETE", "OPTIONS", "CONNECT", "TRACE", "*"];
215
+ const prefixes = {
216
+ children: /* @__PURE__ */ new Map(),
217
+ rules: []
218
+ };
219
+ const allMethods = [
220
+ "GET",
221
+ "HEAD",
222
+ "POST",
223
+ "PUT",
224
+ "PATCH",
225
+ "DELETE",
226
+ "OPTIONS",
227
+ "CONNECT",
228
+ "TRACE",
229
+ "*"
230
+ ];
198
231
  let requiresEncryption = false;
199
232
  let hasEncryption = false;
200
233
  for (const rule of policy.rules) {
201
- const compiled = { methods: new Set(rule.methods), check: compile(rule, rule.id) };
234
+ const compiled = {
235
+ methods: new Set(rule.methods),
236
+ check: compile(rule, rule.id)
237
+ };
202
238
  for (const pattern of new Set(rule.paths)) {
203
239
  if (rule.encryption) {
204
240
  hasEncryption = true;
@@ -210,7 +246,10 @@ function createRequestCheck(input = false) {
210
246
  for (const segment2 of path2.split("/").filter(Boolean)) {
211
247
  let child = node.children.get(segment2);
212
248
  if (!child) {
213
- child = { children: /* @__PURE__ */ new Map(), rules: [] };
249
+ child = {
250
+ children: /* @__PURE__ */ new Map(),
251
+ rules: []
252
+ };
214
253
  node.children.set(segment2, child);
215
254
  }
216
255
  node = child;
@@ -236,7 +275,10 @@ function createRequestCheck(input = false) {
236
275
  for (const segment2 of pattern.slice(0, -3).split("/").filter(Boolean)) {
237
276
  let child = node.children.get(segment2);
238
277
  if (!child) {
239
- child = { children: /* @__PURE__ */ new Map(), rules: [] };
278
+ child = {
279
+ children: /* @__PURE__ */ new Map(),
280
+ rules: []
281
+ };
240
282
  node.children.set(segment2, child);
241
283
  }
242
284
  node = child;
@@ -302,14 +344,23 @@ function createRequestCheck(input = false) {
302
344
  }
303
345
  return mode ?? node?.exactEncryption?.get(method) ?? node?.exactEncryption?.get("*");
304
346
  };
305
- return Object.assign(check, { encryption: hasEncryption ? encryption : () => void 0, requiresEncryption });
347
+ return Object.assign(check, {
348
+ encryption: hasEncryption ? encryption : () => void 0,
349
+ requiresEncryption
350
+ });
306
351
  }
307
- var access = { normalizeClientIp, createClientIpResolver, createConditionCheck, createRequestCheck, loadPolicy };
352
+ var access = {
353
+ normalizeClientIp,
354
+ createClientIpResolver,
355
+ createConditionCheck,
356
+ createRequestCheck,
357
+ loadPolicy
358
+ };
308
359
  function object(value) {
309
360
  return value !== null && typeof value === "object" && !Array.isArray(value) ? value : void 0;
310
361
  }
311
362
  function segment(value) {
312
- return value.replace(/[^a-z0-9]+/gi, "_").replace(/^_+|_+$/g, "").toUpperCase();
363
+ return value.replace(/[^a-z0-9]+/gi, "_").replace(/^_|_$/g, "").toUpperCase();
313
364
  }
314
365
  function shapes(node, root, value, depth = 0) {
315
366
  if (depth > 32)
@@ -427,11 +478,17 @@ function resolveEnvironment(options, literal = false) {
427
478
  const discriminators = /* @__PURE__ */ new Map();
428
479
  for (const candidate of alternatives) {
429
480
  for (const [key, field] of Object.entries(object(candidate.properties) ?? {})) {
430
- if (shapes(object(field) ?? {}, root).some((item) => Object.hasOwn(item, "const")))
431
- discriminators.set(key, [...discriminators.get(key) ?? [], field]);
481
+ if (shapes(object(field) ?? {}, root).some((item) => Object.hasOwn(item, "const"))) {
482
+ discriminators.set(key, [
483
+ ...discriminators.get(key) ?? [],
484
+ field
485
+ ]);
486
+ }
432
487
  }
433
488
  }
434
- const selection = { ...object(value) };
489
+ const selection = {
490
+ ...object(value)
491
+ };
435
492
  for (const [key, fields] of discriminators) {
436
493
  const text = environment[`${name}_${segment(key)}`];
437
494
  if (text !== void 0)
@@ -442,7 +499,10 @@ function resolveEnvironment(options, literal = false) {
442
499
  const valueType = typeof value;
443
500
  const primitiveOverride = value === void 0 || candidates.some((candidate) => value !== null && candidate.type === valueType || candidate.const === value || value === null && candidate.type === "null");
444
501
  if (primitiveOverride && !object(value) && !Array.isArray(value)) {
445
- const declared = /* @__PURE__ */ new Set([...Object.keys(object(declaration) ?? {}), ...candidates.flatMap((candidate) => Object.keys(object(candidate.properties) ?? {}))]);
502
+ const declared = /* @__PURE__ */ new Set([
503
+ ...Object.keys(object(declaration) ?? {}),
504
+ ...candidates.flatMap((candidate) => Object.keys(object(candidate.properties) ?? {}))
505
+ ]);
446
506
  const specified = [...declared].filter((key) => Object.keys(environment).some((candidate) => environment[candidate] !== void 0 && (candidate === `${name}_${segment(key)}` || candidate.startsWith(`${name}_${segment(key)}_`))));
447
507
  if (specified.length)
448
508
  value = Object.fromEntries(specified.map((key) => [key, void 0]));
@@ -455,7 +515,7 @@ function resolveEnvironment(options, literal = false) {
455
515
  if (value === void 0 && indexed.length && candidates.some((candidate) => candidate.type === "array")) {
456
516
  const defaults = candidates.find((candidate) => Array.isArray(candidate.default))?.default;
457
517
  if (!Array.isArray(defaults))
458
- throw new Error(indexed[0]);
518
+ throw new TypeError(indexed[0]);
459
519
  value = structuredClone(defaults);
460
520
  }
461
521
  if (Array.isArray(value)) {
@@ -471,37 +531,76 @@ function resolveEnvironment(options, literal = false) {
471
531
  if (input) {
472
532
  const properties = /* @__PURE__ */ new Map();
473
533
  for (const candidate of candidates) {
474
- for (const [key, field] of Object.entries(object(candidate.properties) ?? {}))
475
- properties.set(key, [...properties.get(key) ?? [], field]);
534
+ for (const [key, field] of Object.entries(object(candidate.properties) ?? {})) {
535
+ properties.set(key, [
536
+ ...properties.get(key) ?? [],
537
+ field
538
+ ]);
539
+ }
476
540
  }
477
- const declaredKeys = /* @__PURE__ */ new Set([...Object.keys(object(declaration) ?? {}), ...properties.keys()]);
478
- const keys = /* @__PURE__ */ new Set([...Object.keys(input), ...[...declaredKeys].filter((key) => Object.keys(environment).some((nameInEnv) => environment[nameInEnv] !== void 0 && (nameInEnv === `${name}_${segment(key)}` || nameInEnv.startsWith(`${name}_${segment(key)}_`))))]);
541
+ const declaredKeys = /* @__PURE__ */ new Set([
542
+ ...Object.keys(object(declaration) ?? {}),
543
+ ...properties.keys()
544
+ ]);
545
+ const keys = /* @__PURE__ */ new Set([
546
+ ...Object.keys(input),
547
+ ...[...declaredKeys].filter((key) => Object.keys(environment).some((nameInEnv) => environment[nameInEnv] !== void 0 && (nameInEnv === `${name}_${segment(key)}` || nameInEnv.startsWith(`${name}_${segment(key)}_`))))
548
+ ]);
479
549
  const entries = [...keys].map((key) => {
480
550
  if (["__proto__", "prototype", "constructor"].includes(key))
481
551
  throw new Error(name);
482
- return [key, visit(input[key], `${name}_${segment(key)}`, combined(properties.get(key) ?? candidates.map((candidate) => candidate.additionalProperties)), fromEnvironment, depth + 1, object(declaration)?.[key])];
552
+ return [
553
+ key,
554
+ visit(input[key], `${name}_${segment(key)}`, combined(properties.get(key) ?? candidates.map((candidate) => candidate.additionalProperties)), fromEnvironment, depth + 1, object(declaration)?.[key])
555
+ ];
483
556
  }).filter(([, child]) => child !== void 0);
484
557
  return synthesized && !entries.length ? void 0 : Object.fromEntries(entries);
485
558
  }
486
559
  if (typeof value !== "string" || fromEnvironment)
487
560
  return value;
488
- const full = /^\$\{[^}:]+(?::[^}]*)?\}$/.test(value);
489
- const resolved = value.replace(/\$\{([^}:]+)(?::([^}]*))?\}/g, (_match, key, fallback) => {
561
+ const parts = [];
562
+ let consumed = 0;
563
+ let search = 0;
564
+ let full = false;
565
+ while (search < value.length) {
566
+ const start = value.indexOf("${", search);
567
+ if (start < 0)
568
+ break;
569
+ if (value[start + 2] === ":" || value[start + 2] === "}") {
570
+ search = start + 2;
571
+ continue;
572
+ }
573
+ const end = value.indexOf("}", start + 2);
574
+ if (end < 0)
575
+ break;
576
+ const expression = value.slice(start + 2, end);
577
+ const separator = expression.indexOf(":");
578
+ const key = separator < 0 ? expression : expression.slice(0, separator);
579
+ const fallback = separator < 0 ? void 0 : expression.slice(separator + 1);
490
580
  if (environment[key] === void 0 && fallback === void 0 && options.missing !== "empty") {
491
581
  missingNames.add(key);
492
582
  throw new Error(key);
493
583
  }
494
- return environment[key] ?? fallback ?? "";
495
- });
584
+ parts.push(value.slice(consumed, start), environment[key] ?? fallback ?? "");
585
+ consumed = end + 1;
586
+ search = consumed;
587
+ full = start === 0 && consumed === value.length;
588
+ }
589
+ const resolved = parts.join("") + value.slice(consumed);
496
590
  return full ? scalar(resolved, node, root) : resolved;
497
591
  }
498
592
  try {
499
593
  return ok(visit(options.value, prefix, root, literal, 0));
500
594
  } catch (failure) {
501
595
  const name = failure instanceof Error && /^[A-Z_]\w*$/i.test(failure.message) ? failure.message : prefix;
502
- if (!missingNames.has(name))
503
- return err(HaiConfigError.CONFIG_VALIDATION_ERROR, i18n.coreM("core_configValidationFailed"), { fields: [name] });
504
- return err(HaiConfigError.CONFIG_ENV_VAR_MISSING, i18n.coreM("core_configEnvVarMissing", { params: { varName: name } }));
596
+ if (!missingNames.has(name)) {
597
+ return err(HaiConfigError.CONFIG_VALIDATION_ERROR, i18n.coreM("core_configValidationFailed"), {
598
+ fields: [name]
599
+ });
600
+ }
601
+ return err(HaiConfigError.CONFIG_ENV_VAR_MISSING, i18n.coreM("core_configEnvVarMissing", {
602
+ params: { varName: name }
603
+ }));
505
604
  }
506
605
  }
507
606
  function toEnv(options) {
@@ -531,7 +630,9 @@ function toEnv(options) {
531
630
  var configCache = /* @__PURE__ */ new Map();
532
631
  var watchEntries = /* @__PURE__ */ new Map();
533
632
  function createNotLoadedError(name) {
534
- const result = err(HaiConfigError.CONFIG_NOT_LOADED, i18n.coreM("core_configNotLoaded", { params: { name } }));
633
+ const result = err(HaiConfigError.CONFIG_NOT_LOADED, i18n.coreM("core_configNotLoaded", {
634
+ params: { name }
635
+ }));
535
636
  if (!result.success)
536
637
  return result.error;
537
638
  throw new Error("unreachable");
@@ -558,14 +659,18 @@ function notifyWatchCallbacks(name, result) {
558
659
  }
559
660
  function loadYaml(name, filePath, schema) {
560
661
  if (!existsSync(filePath)) {
561
- return err(HaiConfigError.CONFIG_FILE_NOT_FOUND, i18n.coreM("core_configFileNotExist", { params: { filePath } }));
662
+ return err(HaiConfigError.CONFIG_FILE_NOT_FOUND, i18n.coreM("core_configFileNotExist", {
663
+ params: { filePath }
664
+ }));
562
665
  }
563
666
  try {
564
667
  const content = readFileSync(filePath, "utf-8");
565
668
  const parsed = parse(content);
566
669
  return resolveEnvironment({ name, value: parsed, schema });
567
670
  } catch (error) {
568
- return err(HaiConfigError.CONFIG_PARSE_ERROR, i18n.coreM("core_configParseFailed", { params: { filePath } }), error);
671
+ return err(HaiConfigError.CONFIG_PARSE_ERROR, i18n.coreM("core_configParseFailed", {
672
+ params: { filePath }
673
+ }), error);
569
674
  }
570
675
  }
571
676
  function loadConfig(name, filePath, schema) {
@@ -592,8 +697,14 @@ function loadAndCache(name, filePath, schema) {
592
697
  }
593
698
  function loadConfigStructure(name, filePath, schemaHint) {
594
699
  const result = loadYaml(name, filePath, schemaHint);
595
- if (result.success)
596
- configCache.set(name, { data: result.data, filePath, schemaHint, loadedAt: Date.now() });
700
+ if (result.success) {
701
+ configCache.set(name, {
702
+ data: result.data,
703
+ filePath,
704
+ schemaHint,
705
+ loadedAt: Date.now()
706
+ });
707
+ }
597
708
  return result;
598
709
  }
599
710
  function validateLoadedConfig(name, schema) {
@@ -799,7 +910,12 @@ var config = {
799
910
  const envDir = options.envDir ?? process4.cwd();
800
911
  try {
801
912
  const layers = [];
802
- for (const name of [".env", `.env.${mode}`, ".env.local", `.env.${mode}.local`]) {
913
+ for (const name of [
914
+ ".env",
915
+ `.env.${mode}`,
916
+ ".env.local",
917
+ `.env.${mode}.local`
918
+ ]) {
803
919
  const file = join(envDir, name);
804
920
  if (existsSync(file))
805
921
  layers.push(parseEnvironment(readFileSync(file, "utf8")));
@@ -809,7 +925,9 @@ var config = {
809
925
  const merged = mergeEnv(layers);
810
926
  return ok(merged);
811
927
  } catch {
812
- return err(HaiConfigError.CONFIG_PARSE_ERROR, i18n.coreM("core_configParseFailed", { params: { filePath: envDir } }));
928
+ return err(HaiConfigError.CONFIG_PARSE_ERROR, i18n.coreM("core_configParseFailed", {
929
+ params: { filePath: envDir }
930
+ }));
813
931
  }
814
932
  },
815
933
  /**
@@ -889,7 +1007,9 @@ var config = {
889
1007
  getOrThrow(name) {
890
1008
  const data = this.get(name);
891
1009
  if (data === void 0) {
892
- throw new Error(i18n.coreM("core_configNotLoaded", { params: { name } }));
1010
+ throw new Error(i18n.coreM("core_configNotLoaded", {
1011
+ params: { name }
1012
+ }));
893
1013
  }
894
1014
  return data;
895
1015
  },
@@ -1032,8 +1152,12 @@ function configureLogger(config2) {
1032
1152
  globalFormat = config2.format;
1033
1153
  outputRevision++;
1034
1154
  }
1035
- if (config2.context)
1036
- globalContext = { ...globalContext, ...config2.context };
1155
+ if (config2.context) {
1156
+ globalContext = {
1157
+ ...globalContext,
1158
+ ...config2.context
1159
+ };
1160
+ }
1037
1161
  if (config2.redact) {
1038
1162
  globalRedact = [...config2.redact];
1039
1163
  outputRevision++;
@@ -1056,11 +1180,21 @@ function wrapPino(resolvePino, resolveContext) {
1056
1180
  const output = resolvePino();
1057
1181
  if (!output.isLevelEnabled(level))
1058
1182
  return;
1059
- const context = sanitizeLogContext({ ...resolveContext(), ...ctx, ...requestContext.get() }) ?? {};
1183
+ const context = sanitizeLogContext({
1184
+ ...resolveContext(),
1185
+ ...ctx,
1186
+ ...requestContext.get()
1187
+ }) ?? {};
1060
1188
  message = sanitize.sanitizeText(message);
1061
1189
  output[level](context, message);
1062
- if (!requestContext.get().suppressLogObservers)
1063
- emitLogRecord({ timestamp: Date.now(), level, message, context });
1190
+ if (!requestContext.get().suppressLogObservers) {
1191
+ emitLogRecord({
1192
+ timestamp: Date.now(),
1193
+ level,
1194
+ message,
1195
+ context
1196
+ });
1197
+ }
1064
1198
  };
1065
1199
  return {
1066
1200
  trace(message, ctx) {
@@ -1082,12 +1216,18 @@ function wrapPino(resolvePino, resolveContext) {
1082
1216
  write("fatal", message, ctx);
1083
1217
  },
1084
1218
  child(childContext) {
1085
- return wrapPino(resolvePino, () => ({ ...resolveContext(), ...childContext }));
1219
+ return wrapPino(resolvePino, () => ({
1220
+ ...resolveContext(),
1221
+ ...childContext
1222
+ }));
1086
1223
  }
1087
1224
  };
1088
1225
  }
1089
1226
  function createLogger(options = {}) {
1090
- const localOptions = { ...options, context: { ...options.context } };
1227
+ const localOptions = {
1228
+ ...options,
1229
+ context: { ...options.context }
1230
+ };
1091
1231
  let revision = outputRevision;
1092
1232
  let output = createPinoOutput(localOptions);
1093
1233
  const resolvePino = () => {
@@ -1102,7 +1242,10 @@ function createLogger(options = {}) {
1102
1242
  output.instance.level = level;
1103
1243
  return output.instance;
1104
1244
  };
1105
- return wrapPino(resolvePino, () => ({ ...globalContext, ...localOptions.context }));
1245
+ return wrapPino(resolvePino, () => ({
1246
+ ...globalContext,
1247
+ ...localOptions.context
1248
+ }));
1106
1249
  }
1107
1250
  function createPinoOutput(options) {
1108
1251
  const level = options.level ?? globalLevel;
@@ -1145,7 +1288,10 @@ function createPinoOutput(options) {
1145
1288
  } else {
1146
1289
  pinoInstance = pino(pinoOptions);
1147
1290
  }
1148
- return { instance: pinoInstance, close: () => transport?.end() };
1291
+ return {
1292
+ instance: pinoInstance,
1293
+ close: () => transport?.end()
1294
+ };
1149
1295
  }
1150
1296
  function isPrettyTransportAvailable() {
1151
1297
  try {