hazo_core 1.0.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.
- package/README.md +84 -0
- package/SETUP_CHECKLIST.md +114 -0
- package/config/hazo_core_config.ini +14 -0
- package/dist/config/index.d.ts +35 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +117 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/ini_parser.d.ts +10 -0
- package/dist/config/ini_parser.d.ts.map +1 -0
- package/dist/config/ini_parser.js +45 -0
- package/dist/config/ini_parser.js.map +1 -0
- package/dist/constants.d.ts +4 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +4 -0
- package/dist/constants.js.map +1 -0
- package/dist/context/client.d.ts +27 -0
- package/dist/context/client.d.ts.map +1 -0
- package/dist/context/client.js +66 -0
- package/dist/context/client.js.map +1 -0
- package/dist/context/index.d.ts +9 -0
- package/dist/context/index.d.ts.map +1 -0
- package/dist/context/index.js +8 -0
- package/dist/context/index.js.map +1 -0
- package/dist/context/server.d.ts +23 -0
- package/dist/context/server.d.ts.map +1 -0
- package/dist/context/server.js +52 -0
- package/dist/context/server.js.map +1 -0
- package/dist/context/types.d.ts +14 -0
- package/dist/context/types.d.ts.map +1 -0
- package/dist/context/types.js +2 -0
- package/dist/context/types.js.map +1 -0
- package/dist/debug/index.d.ts +20 -0
- package/dist/debug/index.d.ts.map +1 -0
- package/dist/debug/index.js +78 -0
- package/dist/debug/index.js.map +1 -0
- package/dist/errors/auth.d.ts +14 -0
- package/dist/errors/auth.d.ts.map +1 -0
- package/dist/errors/auth.js +19 -0
- package/dist/errors/auth.js.map +1 -0
- package/dist/errors/base.d.ts +89 -0
- package/dist/errors/base.d.ts.map +1 -0
- package/dist/errors/base.js +152 -0
- package/dist/errors/base.js.map +1 -0
- package/dist/errors/config.d.ts +18 -0
- package/dist/errors/config.d.ts.map +1 -0
- package/dist/errors/config.js +14 -0
- package/dist/errors/config.js.map +1 -0
- package/dist/errors/conflict.d.ts +9 -0
- package/dist/errors/conflict.d.ts.map +1 -0
- package/dist/errors/conflict.js +14 -0
- package/dist/errors/conflict.js.map +1 -0
- package/dist/errors/external.d.ts +9 -0
- package/dist/errors/external.d.ts.map +1 -0
- package/dist/errors/external.js +14 -0
- package/dist/errors/external.js.map +1 -0
- package/dist/errors/from_zod.d.ts +33 -0
- package/dist/errors/from_zod.d.ts.map +1 -0
- package/dist/errors/from_zod.js +63 -0
- package/dist/errors/from_zod.js.map +1 -0
- package/dist/errors/index.d.ts +22 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +12 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/errors/internal.d.ts +14 -0
- package/dist/errors/internal.d.ts.map +1 -0
- package/dist/errors/internal.js +14 -0
- package/dist/errors/internal.js.map +1 -0
- package/dist/errors/not_found.d.ts +9 -0
- package/dist/errors/not_found.d.ts.map +1 -0
- package/dist/errors/not_found.js +15 -0
- package/dist/errors/not_found.js.map +1 -0
- package/dist/errors/rate_limit.d.ts +9 -0
- package/dist/errors/rate_limit.d.ts.map +1 -0
- package/dist/errors/rate_limit.js +14 -0
- package/dist/errors/rate_limit.js.map +1 -0
- package/dist/errors/unavailable.d.ts +9 -0
- package/dist/errors/unavailable.d.ts.map +1 -0
- package/dist/errors/unavailable.js +14 -0
- package/dist/errors/unavailable.js.map +1 -0
- package/dist/errors/validation.d.ts +15 -0
- package/dist/errors/validation.d.ts.map +1 -0
- package/dist/errors/validation.js +17 -0
- package/dist/errors/validation.js.map +1 -0
- package/dist/http/fetch_with_request_id.d.ts +14 -0
- package/dist/http/fetch_with_request_id.d.ts.map +1 -0
- package/dist/http/fetch_with_request_id.js +29 -0
- package/dist/http/fetch_with_request_id.js.map +1 -0
- package/dist/http/get_origin_url.d.ts +23 -0
- package/dist/http/get_origin_url.d.ts.map +1 -0
- package/dist/http/get_origin_url.js +61 -0
- package/dist/http/get_origin_url.js.map +1 -0
- package/dist/http/request_id_middleware.d.ts +38 -0
- package/dist/http/request_id_middleware.d.ts.map +1 -0
- package/dist/http/request_id_middleware.js +57 -0
- package/dist/http/request_id_middleware.js.map +1 -0
- package/dist/index.client.d.ts +16 -0
- package/dist/index.client.d.ts.map +1 -0
- package/dist/index.client.js +19 -0
- package/dist/index.client.js.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/dist/logger/index.d.ts +29 -0
- package/dist/logger/index.d.ts.map +1 -0
- package/dist/logger/index.js +125 -0
- package/dist/logger/index.js.map +1 -0
- package/dist/singleton/index.d.ts +16 -0
- package/dist/singleton/index.d.ts.map +1 -0
- package/dist/singleton/index.js +42 -0
- package/dist/singleton/index.js.map +1 -0
- package/dist/utils/dates.d.ts +45 -0
- package/dist/utils/dates.d.ts.map +1 -0
- package/dist/utils/dates.js +79 -0
- package/dist/utils/dates.js.map +1 -0
- package/dist/utils/env.d.ts +7 -0
- package/dist/utils/env.d.ts.map +1 -0
- package/dist/utils/env.js +9 -0
- package/dist/utils/env.js.map +1 -0
- package/dist/utils/index.d.ts +69 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +174 -0
- package/dist/utils/index.js.map +1 -0
- package/package.json +82 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAG3F,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAGvE,OAAO,EACL,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,aAAa,EACb,KAAK,EACL,WAAW,EACX,eAAe,EACf,cAAc,EACd,eAAe,EACf,cAAc,EACd,YAAY,EACZ,aAAa,EACb,WAAW,EACX,WAAW,EACX,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,kBAAkB,CAAC;AAC1B,YAAY,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAGnD,OAAO,EACL,SAAS,EACT,mBAAmB,EACnB,aAAa,EACb,iBAAiB,EACjB,iBAAiB,EACjB,eAAe,EACf,iBAAiB,EACjB,kBAAkB,EAClB,oBAAoB,EACpB,iBAAiB,EACjB,iBAAiB,EACjB,aAAa,GACd,MAAM,mBAAmB,CAAC;AAC3B,YAAY,EACV,gBAAgB,EAChB,0BAA0B,EAC1B,eAAe,EACf,oBAAoB,EACpB,wBAAwB,EACxB,wBAAwB,EACxB,sBAAsB,EACtB,wBAAwB,EACxB,yBAAyB,EACzB,2BAA2B,EAC3B,wBAAwB,GACzB,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EACL,WAAW,EACX,UAAU,EACV,gBAAgB,GACjB,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAGtD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAG3E,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,YAAY,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAGxD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,YAAY,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAGtD,OAAO,EACL,yBAAyB,EACzB,yBAAyB,GAC1B,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* hazo_core — server entry point (Node.js)
|
|
3
|
+
*
|
|
4
|
+
* Exports all public API surface. See architecture.md §5 for the public API spec.
|
|
5
|
+
* Browser-safe consumers should use 'hazo_core/client' instead.
|
|
6
|
+
*/
|
|
7
|
+
// Constants
|
|
8
|
+
export { REQUEST_ID_HEADER, HAZO_ERROR_SYMBOL, HAZO_SINGLETONS_KEY } from './constants.js';
|
|
9
|
+
// Singleton registry
|
|
10
|
+
export { registerSingleton, getSingleton } from './singleton/index.js';
|
|
11
|
+
// Utilities
|
|
12
|
+
export { getCurrentEnv, generateRequestId, optional_import, safeJsonParse, sleep, formatBytes, formatDateShort, formatDateLong, formatDateSlash, formatCurrency, formatNumber, formatBoolean, getInitials, format_date, format_date_range, DEFAULT_DATE_FORMAT, } from './utils/index.js';
|
|
13
|
+
// Errors
|
|
14
|
+
export { HazoError, HazoValidationError, HazoAuthError, HazoNotFoundError, HazoConflictError, HazoConfigError, HazoExternalError, HazoRateLimitError, HazoUnavailableError, HazoInternalError, fromZodValidation, fromZodConfig, } from './errors/index.js';
|
|
15
|
+
// Context (server — AsyncLocalStorage)
|
|
16
|
+
export { withContext, getContext, getCorrelationId, } from './context/index.js';
|
|
17
|
+
// Config
|
|
18
|
+
export { loadConfig, defineConfig, reloadConfig } from './config/index.js';
|
|
19
|
+
// Logger
|
|
20
|
+
export { createLogger } from './logger/index.js';
|
|
21
|
+
// Debug
|
|
22
|
+
export { createDebug } from './debug/index.js';
|
|
23
|
+
// HTTP
|
|
24
|
+
export { createRequestIdMiddleware, withRequestIdRouteHandler, } from './http/request_id_middleware.js';
|
|
25
|
+
export { fetchWithRequestId } from './http/fetch_with_request_id.js';
|
|
26
|
+
export { get_origin_url, create_redirect_url } from './http/get_origin_url.js';
|
|
27
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,YAAY;AACZ,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAE3F,qBAAqB;AACrB,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEvE,YAAY;AACZ,OAAO,EACL,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,aAAa,EACb,KAAK,EACL,WAAW,EACX,eAAe,EACf,cAAc,EACd,eAAe,EACf,cAAc,EACd,YAAY,EACZ,aAAa,EACb,WAAW,EACX,WAAW,EACX,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,kBAAkB,CAAC;AAG1B,SAAS;AACT,OAAO,EACL,SAAS,EACT,mBAAmB,EACnB,aAAa,EACb,iBAAiB,EACjB,iBAAiB,EACjB,eAAe,EACf,iBAAiB,EACjB,kBAAkB,EAClB,oBAAoB,EACpB,iBAAiB,EACjB,iBAAiB,EACjB,aAAa,GACd,MAAM,mBAAmB,CAAC;AAe3B,uCAAuC;AACvC,OAAO,EACL,WAAW,EACX,UAAU,EACV,gBAAgB,GACjB,MAAM,oBAAoB,CAAC;AAG5B,SAAS;AACT,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAE3E,SAAS;AACT,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGjD,QAAQ;AACR,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAG/C,OAAO;AACP,OAAO,EACL,yBAAyB,EACzB,yBAAyB,GAC1B,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* hazo_core logger factory — wraps hazo_logs and auto-injects:
|
|
3
|
+
* - pkg (the passed name)
|
|
4
|
+
* - correlationId (from getCorrelationId() at call time)
|
|
5
|
+
* - env (from getCurrentEnv() at module load time)
|
|
6
|
+
*
|
|
7
|
+
* Falls back to a minimal stderr JSON writer when hazo_logs is not installed.
|
|
8
|
+
*
|
|
9
|
+
* Per architecture.md §9 and D-002.
|
|
10
|
+
*/
|
|
11
|
+
export interface HazoCoreLogger {
|
|
12
|
+
trace(event: string, fields?: Record<string, unknown>): void;
|
|
13
|
+
debug(event: string, fields?: Record<string, unknown>): void;
|
|
14
|
+
info(event: string, fields?: Record<string, unknown>): void;
|
|
15
|
+
warn(event: string, fields?: Record<string, unknown>): void;
|
|
16
|
+
error(event: string, fields?: Record<string, unknown>): void;
|
|
17
|
+
/** Create a child logger that merges fixed fields into every call. */
|
|
18
|
+
child(fields: Record<string, unknown>): HazoCoreLogger;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Create a logger for a hazo package.
|
|
22
|
+
*
|
|
23
|
+
* When hazo_logs is installed, wraps its createLogger and auto-injects
|
|
24
|
+
* correlationId, env, and pkg into every log entry.
|
|
25
|
+
*
|
|
26
|
+
* When hazo_logs is absent, writes JSON lines to process.stderr.
|
|
27
|
+
*/
|
|
28
|
+
export declare function createLogger(pkg: string): HazoCoreLogger;
|
|
29
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/logger/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AASH,MAAM,WAAW,cAAc;IAC7B,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IAC7D,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IAC7D,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IAC5D,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IAC5D,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IAC7D,sEAAsE;IACtE,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,cAAc,CAAC;CACxD;AAqID;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,cAAc,CAUxD"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* hazo_core logger factory — wraps hazo_logs and auto-injects:
|
|
3
|
+
* - pkg (the passed name)
|
|
4
|
+
* - correlationId (from getCorrelationId() at call time)
|
|
5
|
+
* - env (from getCurrentEnv() at module load time)
|
|
6
|
+
*
|
|
7
|
+
* Falls back to a minimal stderr JSON writer when hazo_logs is not installed.
|
|
8
|
+
*
|
|
9
|
+
* Per architecture.md §9 and D-002.
|
|
10
|
+
*/
|
|
11
|
+
import { createRequire } from 'node:module';
|
|
12
|
+
import { getCurrentEnv } from '../utils/env.js';
|
|
13
|
+
// ---------------------------------------------------------------------------
|
|
14
|
+
// Detect hazo_logs at module init time (synchronous, CJS require via createRequire)
|
|
15
|
+
// ---------------------------------------------------------------------------
|
|
16
|
+
const _require = createRequire(import.meta.url);
|
|
17
|
+
let hazoLogsModule = null;
|
|
18
|
+
try {
|
|
19
|
+
hazoLogsModule = _require('hazo_logs');
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
// hazo_logs not installed — fallback to stderr writer below
|
|
23
|
+
}
|
|
24
|
+
// ---------------------------------------------------------------------------
|
|
25
|
+
// Resolve correlationId lazily (avoid circular import with context/server.ts)
|
|
26
|
+
// ---------------------------------------------------------------------------
|
|
27
|
+
function getCorrelationIdLazy() {
|
|
28
|
+
try {
|
|
29
|
+
// The ALS is registered on globalThis by context/server.ts at import time.
|
|
30
|
+
// We read it from there to avoid a direct circular dependency.
|
|
31
|
+
const store = globalThis['__hazo_core_context_store__'];
|
|
32
|
+
if (store && typeof store === 'object' && 'getStore' in store) {
|
|
33
|
+
const ctx = store.getStore();
|
|
34
|
+
return ctx?.['correlationId'];
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
// Context not available — ignore
|
|
39
|
+
}
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
// ---------------------------------------------------------------------------
|
|
43
|
+
// Fallback logger (hazo_logs absent)
|
|
44
|
+
// ---------------------------------------------------------------------------
|
|
45
|
+
const LEVEL_ORDER = {
|
|
46
|
+
trace: 0,
|
|
47
|
+
debug: 1,
|
|
48
|
+
info: 2,
|
|
49
|
+
warn: 3,
|
|
50
|
+
error: 4,
|
|
51
|
+
};
|
|
52
|
+
function writeStderr(level, pkg, event, fields, fixedFields) {
|
|
53
|
+
const entry = {
|
|
54
|
+
level,
|
|
55
|
+
pkg,
|
|
56
|
+
event,
|
|
57
|
+
...fixedFields,
|
|
58
|
+
...fields,
|
|
59
|
+
correlationId: getCorrelationIdLazy(),
|
|
60
|
+
env: getCurrentEnv(),
|
|
61
|
+
ts: new Date().toISOString(),
|
|
62
|
+
};
|
|
63
|
+
process.stderr.write(JSON.stringify(entry) + '\n');
|
|
64
|
+
}
|
|
65
|
+
function makeFallbackLogger(pkg, fixedFields = {}) {
|
|
66
|
+
const log = (level) => (event, fields = {}) => {
|
|
67
|
+
// Only emit levels >= info by default to avoid noise
|
|
68
|
+
if ((LEVEL_ORDER[level] ?? 0) >= (LEVEL_ORDER['info'] ?? 2)) {
|
|
69
|
+
writeStderr(level, pkg, event, fields, fixedFields);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
return {
|
|
73
|
+
trace: log('trace'),
|
|
74
|
+
debug: log('debug'),
|
|
75
|
+
info: log('info'),
|
|
76
|
+
warn: log('warn'),
|
|
77
|
+
error: log('error'),
|
|
78
|
+
child: (childFields) => makeFallbackLogger(pkg, { ...fixedFields, ...childFields }),
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
// ---------------------------------------------------------------------------
|
|
82
|
+
// hazo_logs wrapper
|
|
83
|
+
// ---------------------------------------------------------------------------
|
|
84
|
+
function makeWrappedLogger(inner, pkg, fixedFields = {}) {
|
|
85
|
+
const inject = (fields = {}) => ({
|
|
86
|
+
pkg,
|
|
87
|
+
...fixedFields,
|
|
88
|
+
...fields,
|
|
89
|
+
correlationId: getCorrelationIdLazy(),
|
|
90
|
+
env: getCurrentEnv(),
|
|
91
|
+
});
|
|
92
|
+
return {
|
|
93
|
+
// hazo_logs Logger interface has no 'trace' level — map to debug
|
|
94
|
+
trace: (event, fields = {}) => inner.debug(event, inject(fields)),
|
|
95
|
+
debug: (event, fields = {}) => inner.debug(event, inject(fields)),
|
|
96
|
+
info: (event, fields = {}) => inner.info(event, inject(fields)),
|
|
97
|
+
warn: (event, fields = {}) => inner.warn(event, inject(fields)),
|
|
98
|
+
error: (event, fields = {}) => inner.error(event, inject(fields)),
|
|
99
|
+
child: (childFields) => makeWrappedLogger(inner, pkg, { ...fixedFields, ...childFields }),
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
// ---------------------------------------------------------------------------
|
|
103
|
+
// Public factory
|
|
104
|
+
// ---------------------------------------------------------------------------
|
|
105
|
+
/**
|
|
106
|
+
* Create a logger for a hazo package.
|
|
107
|
+
*
|
|
108
|
+
* When hazo_logs is installed, wraps its createLogger and auto-injects
|
|
109
|
+
* correlationId, env, and pkg into every log entry.
|
|
110
|
+
*
|
|
111
|
+
* When hazo_logs is absent, writes JSON lines to process.stderr.
|
|
112
|
+
*/
|
|
113
|
+
export function createLogger(pkg) {
|
|
114
|
+
if (hazoLogsModule) {
|
|
115
|
+
try {
|
|
116
|
+
const inner = hazoLogsModule.createLogger(pkg);
|
|
117
|
+
return makeWrappedLogger(inner, pkg);
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
// Fall through to fallback
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return makeFallbackLogger(pkg);
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/logger/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAgBhD,8EAA8E;AAC9E,oFAAoF;AACpF,8EAA8E;AAE9E,MAAM,QAAQ,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAYhD,IAAI,cAAc,GAA0B,IAAI,CAAC;AACjD,IAAI,CAAC;IACH,cAAc,GAAG,QAAQ,CAAC,WAAW,CAAmB,CAAC;AAC3D,CAAC;AAAC,MAAM,CAAC;IACP,4DAA4D;AAC9D,CAAC;AAED,8EAA8E;AAC9E,8EAA8E;AAC9E,8EAA8E;AAE9E,SAAS,oBAAoB;IAC3B,IAAI,CAAC;QACH,2EAA2E;QAC3E,+DAA+D;QAC/D,MAAM,KAAK,GAAI,UAAsC,CAAC,6BAA6B,CAAC,CAAC;QACrF,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,UAAU,IAAI,KAAK,EAAE,CAAC;YAC9D,MAAM,GAAG,GAAI,KAA6D,CAAC,QAAQ,EAAE,CAAC;YACtF,OAAO,GAAG,EAAE,CAAC,eAAe,CAAuB,CAAC;QACtD,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,iCAAiC;IACnC,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,8EAA8E;AAC9E,qCAAqC;AACrC,8EAA8E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WAAW,EAAE,GAAG,WAAW,EAAE,CAAC;KACpE,CAAC;AACJ,CAAC;AAED,8EAA8E;AAC9E,iBAAiB;AACjB,8EAA8E;AAE9E;;;;;;;GAOG;AACH,MAAM,UAAU,YAAY,CAAC,GAAW;IACtC,IAAI,cAAc,EAAE,CAAC;QACnB,IAAI,CAAC;YACH,MAAM,KAAK,GAAG,cAAc,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;YAC/C,OAAO,iBAAiB,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QACvC,CAAC;QAAC,MAAM,CAAC;YACP,2BAA2B;QAC7B,CAAC;IACH,CAAC;IACD,OAAO,kBAAkB,CAAC,GAAG,CAAC,CAAC;AACjC,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Register a singleton value under a given key.
|
|
3
|
+
* Convention: keys are `<pkg>:<purpose>` to avoid collisions (e.g. `hazo_core:context_als`).
|
|
4
|
+
*
|
|
5
|
+
* If the key is already registered, the existing value is returned unchanged and a warning
|
|
6
|
+
* is emitted — this operation is idempotent and never overwrites.
|
|
7
|
+
*
|
|
8
|
+
* @returns The registered value (either the new one or the pre-existing one)
|
|
9
|
+
*/
|
|
10
|
+
export declare function registerSingleton<T>(key: string, value: T): T;
|
|
11
|
+
/**
|
|
12
|
+
* Retrieve a previously registered singleton value by key.
|
|
13
|
+
* Returns undefined if the key has never been registered.
|
|
14
|
+
*/
|
|
15
|
+
export declare function getSingleton<T>(key: string): T | undefined;
|
|
16
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/singleton/index.ts"],"names":[],"mappings":"AAgBA;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAU7D;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS,CAM1D"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { HAZO_SINGLETONS_KEY } from '../constants.js';
|
|
2
|
+
/**
|
|
3
|
+
* Gets or creates the singleton registry on globalThis.
|
|
4
|
+
* The registry lives on globalThis so it survives pathological duplicate hazo_core copies.
|
|
5
|
+
*/
|
|
6
|
+
function getRegistry() {
|
|
7
|
+
const g = globalThis;
|
|
8
|
+
if (!g[HAZO_SINGLETONS_KEY]) {
|
|
9
|
+
g[HAZO_SINGLETONS_KEY] = Object.create(null);
|
|
10
|
+
}
|
|
11
|
+
return g[HAZO_SINGLETONS_KEY];
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Register a singleton value under a given key.
|
|
15
|
+
* Convention: keys are `<pkg>:<purpose>` to avoid collisions (e.g. `hazo_core:context_als`).
|
|
16
|
+
*
|
|
17
|
+
* If the key is already registered, the existing value is returned unchanged and a warning
|
|
18
|
+
* is emitted — this operation is idempotent and never overwrites.
|
|
19
|
+
*
|
|
20
|
+
* @returns The registered value (either the new one or the pre-existing one)
|
|
21
|
+
*/
|
|
22
|
+
export function registerSingleton(key, value) {
|
|
23
|
+
const registry = getRegistry();
|
|
24
|
+
if (Object.prototype.hasOwnProperty.call(registry, key)) {
|
|
25
|
+
console.warn(`[hazo_core] registerSingleton: key "${key}" is already registered — returning existing value.`);
|
|
26
|
+
return registry[key];
|
|
27
|
+
}
|
|
28
|
+
registry[key] = value;
|
|
29
|
+
return value;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Retrieve a previously registered singleton value by key.
|
|
33
|
+
* Returns undefined if the key has never been registered.
|
|
34
|
+
*/
|
|
35
|
+
export function getSingleton(key) {
|
|
36
|
+
const registry = getRegistry();
|
|
37
|
+
if (Object.prototype.hasOwnProperty.call(registry, key)) {
|
|
38
|
+
return registry[key];
|
|
39
|
+
}
|
|
40
|
+
return und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* Pure date formatting utilities.
|
|
3
|
+
*
|
|
4
|
+
* No React, no DOM, no browser-only APIs. Safe for Node.js and browser alike.
|
|
5
|
+
* `Intl.DateTimeFormat` (used by the 'locale' format) is a standard ECMAScript
|
|
6
|
+
* Internationalization API available in Node.js 12+ and all modern browsers.
|
|
7
|
+
*
|
|
8
|
+
* Note on SSR safety: the 'locale' format delegates to toLocaleDateString(), which
|
|
9
|
+
* picks up the server or client locale and may therefore produce different output
|
|
10
|
+
* on server vs browser. Prefer 'iso', 'dmy', or 'mdy' for SSR-safe rendering.
|
|
11
|
+
*
|
|
12
|
+
* Originally in hazo_collab_forms/src/utils/date_format.ts — moved here in hazo_core
|
|
13
|
+
* as a pure shared utility. hazo_collab_forms re-exports from 'hazo_core' for backward
|
|
14
|
+
* compatibility.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Date format options for displaying dates.
|
|
18
|
+
* 'iso' — YYYY-MM-DD (locale-independent, SSR-safe)
|
|
19
|
+
* 'dmy' — DD/MM/YYYY
|
|
20
|
+
* 'mdy' — MM/DD/YYYY
|
|
21
|
+
* 'locale' — Use environment locale (NOT SSR-safe; may cause hydration mismatch)
|
|
22
|
+
*/
|
|
23
|
+
export type DateFormat = 'iso' | 'dmy' | 'mdy' | 'locale';
|
|
24
|
+
/**
|
|
25
|
+
* Default date format.
|
|
26
|
+
*/
|
|
27
|
+
export declare const DEFAULT_DATE_FORMAT: DateFormat;
|
|
28
|
+
/**
|
|
29
|
+
* Format a date according to the specified format.
|
|
30
|
+
*
|
|
31
|
+
* @param date - Date object, ISO string, or undefined/null
|
|
32
|
+
* @param format - Format type (iso, dmy, mdy, locale)
|
|
33
|
+
* @returns Formatted date string, or empty string if date is invalid/absent
|
|
34
|
+
*/
|
|
35
|
+
export declare function format_date(date: Date | string | undefined | null, format?: DateFormat): string;
|
|
36
|
+
/**
|
|
37
|
+
* Format a date range according to the specified format.
|
|
38
|
+
*
|
|
39
|
+
* @param from - Start date
|
|
40
|
+
* @param to - End date
|
|
41
|
+
* @param format - Format type
|
|
42
|
+
* @returns Formatted date range string
|
|
43
|
+
*/
|
|
44
|
+
export declare function format_date_range(from: Date | string | undefined | null, to: Date | string | undefined | null, format?: DateFormat): string;
|
|
45
|
+
//# sourceMappingURL=dates.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dates.d.ts","sourceRoot":"","sources":["../../src/utils/dates.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;;;GAMG;AACH,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,QAAQ,CAAC;AAE1D;;GAEG;AACH,eAAO,MAAM,mBAAmB,EAAE,UAAkB,CAAC;AAErD;;;;;;GAMG;AACH,wBAAgB,WAAW,CACzB,IAAI,EAAE,IAAI,GAAG,MAAM,GAAG,SAAS,GAAG,IAAI,EACtC,MAAM,GAAE,UAAgC,GACvC,MAAM,CAsCR;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,IAAI,GAAG,MAAM,GAAG,SAAS,GAAG,IAAI,EACtC,EAAE,EAAE,IAAI,GAAG,MAAM,GAAG,SAAS,GAAG,IAAI,EACpC,MAAM,GAAE,UAAgC,GACvC,MAAM,CAQR"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure date formatting utilities.
|
|
3
|
+
*
|
|
4
|
+
* No React, no DOM, no browser-only APIs. Safe for Node.js and browser alike.
|
|
5
|
+
* `Intl.DateTimeFormat` (used by the 'locale' format) is a standard ECMAScript
|
|
6
|
+
* Internationalization API available in Node.js 12+ and all modern browsers.
|
|
7
|
+
*
|
|
8
|
+
* Note on SSR safety: the 'locale' format delegates to toLocaleDateString(), which
|
|
9
|
+
* picks up the server or client locale and may therefore produce different output
|
|
10
|
+
* on server vs browser. Prefer 'iso', 'dmy', or 'mdy' for SSR-safe rendering.
|
|
11
|
+
*
|
|
12
|
+
* Originally in hazo_collab_forms/src/utils/date_format.ts — moved here in hazo_core
|
|
13
|
+
* as a pure shared utility. hazo_collab_forms re-exports from 'hazo_core' for backward
|
|
14
|
+
* compatibility.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Default date format.
|
|
18
|
+
*/
|
|
19
|
+
export const DEFAULT_DATE_FORMAT = 'iso';
|
|
20
|
+
/**
|
|
21
|
+
* Format a date according to the specified format.
|
|
22
|
+
*
|
|
23
|
+
* @param date - Date object, ISO string, or undefined/null
|
|
24
|
+
* @param format - Format type (iso, dmy, mdy, locale)
|
|
25
|
+
* @returns Formatted date string, or empty string if date is invalid/absent
|
|
26
|
+
*/
|
|
27
|
+
export function format_date(date, format = DEFAULT_DATE_FORMAT) {
|
|
28
|
+
if (!date)
|
|
29
|
+
return '';
|
|
30
|
+
// Parse date if string
|
|
31
|
+
let date_obj;
|
|
32
|
+
if (typeof date === 'string') {
|
|
33
|
+
// Add explicit time component to avoid timezone-shift issues with date-only strings
|
|
34
|
+
date_obj = new Date(date.includes('T') ? date : date + 'T00:00:00');
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
date_obj = date;
|
|
38
|
+
}
|
|
39
|
+
// Validate date
|
|
40
|
+
if (isNaN(date_obj.getTime())) {
|
|
41
|
+
return typeof date === 'string' ? date : '';
|
|
42
|
+
}
|
|
43
|
+
const year = date_obj.getFullYear();
|
|
44
|
+
const month = String(date_obj.getMonth() + 1).padStart(2, '0');
|
|
45
|
+
const day = String(date_obj.getDate()).padStart(2, '0');
|
|
46
|
+
switch (format) {
|
|
47
|
+
case 'iso':
|
|
48
|
+
return `${year}-${month}-${day}`;
|
|
49
|
+
case 'dmy':
|
|
50
|
+
return `${day}/${month}/${year}`;
|
|
51
|
+
case 'mdy':
|
|
52
|
+
return `${month}/${day}/${year}`;
|
|
53
|
+
case 'locale':
|
|
54
|
+
// Uses environment locale — not SSR-safe (may cause hydration mismatch in Next.js)
|
|
55
|
+
return date_obj.toLocaleDateString();
|
|
56
|
+
default:
|
|
57
|
+
return `${year}-${month}-${day}`;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Format a date range according to the specified format.
|
|
62
|
+
*
|
|
63
|
+
* @param from - Start date
|
|
64
|
+
* @param to - End date
|
|
65
|
+
* @param format - Format type
|
|
66
|
+
* @returns Formatted date range string
|
|
67
|
+
*/
|
|
68
|
+
export function format_date_range(from, to, format = DEFAULT_DATE_FORMAT) {
|
|
69
|
+
const from_str = format_date(from, format);
|
|
70
|
+
const to_str = format_date(to, format);
|
|
71
|
+
if (from_str && to_str)
|
|
72
|
+
return `${from_str} - ${to_str}`;
|
|
73
|
+
if (from_str)
|
|
74
|
+
return `From ${from_str}`;
|
|
75
|
+
if (to_str)
|
|
76
|
+
return `To ${to_str}`;
|
|
77
|
+
return '';
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=dates.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dates.js","sourceRoot":"","sources":["../../src/utils/dates.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAWH;;GAEG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAe,KAAK,CAAC;AAErD;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CACzB,IAAsC,EACtC,SAAqB,mBAAmB;IAExC,IAAI,CAAC,IAAI;QAAE,OAAO,EAAE,CAAC;IAErB,uBAAuB;IACvB,IAAI,QAAc,CAAC;IACnB,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC7B,oFAAoF;QACpF,QAAQ,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,GAAG,WAAW,CAAC,CAAC;IACtE,CAAC;SAAM,CAAC;QACN,QAAQ,GAAG,IAAI,CAAC;IAClB,CAAC;IAED,gBAA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QAAQ;QAAE,OAAO,QAAQ,QAAQ,EAAE,CAAC;IACxC,IAAI,MAAM;QAAE,OAAO,MAAM,MAAM,EAAE,CAAC;IAClC,OAAO,EAAE,CAAC;AACZ,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the current environment name.
|
|
3
|
+
* Resolution: HAZO_ENV ?? NODE_ENV ?? 'development'
|
|
4
|
+
* This is the single source of truth for environment resolution across all hazo_* packages.
|
|
5
|
+
*/
|
|
6
|
+
export declare function getCurrentEnv(): string;
|
|
7
|
+
//# sourceMappingURL=env.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../src/utils/env.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,aAAa,IAAI,MAAM,CAEtC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the current environment name.
|
|
3
|
+
* Resolution: HAZO_ENV ?? NODE_ENV ?? 'development'
|
|
4
|
+
* This is the single source of truth for environment resolution across all hazo_* packages.
|
|
5
|
+
*/
|
|
6
|
+
export function getCurrentEnv() {
|
|
7
|
+
return process.env['HAZO_ENV'] ?? process.env['NODE_ENV'] ?? 'development';
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=env.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.js","sourceRoot":"","sources":["../../src/utils/env.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,UAAU,aAAa;IAC3B,OAAO,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,aAAa,CAAC;AAC7E,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
export { getCurrentEnv } from './env.js';
|
|
2
|
+
/**
|
|
3
|
+
* Generate a new request/correlation ID.
|
|
4
|
+
* Format: 'req_' + UUID v7 (time-ordered, sortable in logs and DB indexes).
|
|
5
|
+
* Per D-001 and D-006.
|
|
6
|
+
*/
|
|
7
|
+
export declare function generateRequestId(): string;
|
|
8
|
+
/**
|
|
9
|
+
* Attempt a dynamic import of `pkg`. Returns null if the package is not
|
|
10
|
+
* installed or fails to load for any reason.
|
|
11
|
+
*
|
|
12
|
+
* Useful for optional peer dependencies that provide enhanced behavior when
|
|
13
|
+
* present but are not required.
|
|
14
|
+
*/
|
|
15
|
+
export declare function optional_import<T>(pkg: string): Promise<T | null>;
|
|
16
|
+
/**
|
|
17
|
+
* JSON.parse that returns null instead of throwing on malformed input.
|
|
18
|
+
*/
|
|
19
|
+
export declare function safeJsonParse<T = unknown>(json: string): T | null;
|
|
20
|
+
/**
|
|
21
|
+
* Promise-based delay. Useful in tests and retry loops.
|
|
22
|
+
*/
|
|
23
|
+
export declare function sleep(ms: number): Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Format a byte count into a human-readable string.
|
|
26
|
+
* @example formatBytes(1536) → "1.5 KB"
|
|
27
|
+
* @example formatBytes(1073741824) → "1 GB"
|
|
28
|
+
*/
|
|
29
|
+
export declare function formatBytes(bytes: number, decimals?: number): string;
|
|
30
|
+
export { format_date, format_date_range, DEFAULT_DATE_FORMAT, } from './dates.js';
|
|
31
|
+
export type { DateFormat } from './dates.js';
|
|
32
|
+
/**
|
|
33
|
+
* Format a date as "28 May 2026"
|
|
34
|
+
*/
|
|
35
|
+
export declare function formatDateShort(date: Date | string): string;
|
|
36
|
+
/**
|
|
37
|
+
* Format a date as "Wednesday, 28 May 2026"
|
|
38
|
+
*/
|
|
39
|
+
export declare function formatDateLong(date: Date | string): string;
|
|
40
|
+
/**
|
|
41
|
+
* Format a date as "28/05/2026"
|
|
42
|
+
*/
|
|
43
|
+
export declare function formatDateSlash(date: Date | string): string;
|
|
44
|
+
/**
|
|
45
|
+
* Format a number as currency.
|
|
46
|
+
* @example formatCurrency(1234.56) → "$1,234.56"
|
|
47
|
+
* @example formatCurrency(1234.56, 'GBP') → "£1,234.56"
|
|
48
|
+
*/
|
|
49
|
+
export declare function formatCurrency(amount: number, currency?: string): string;
|
|
50
|
+
/**
|
|
51
|
+
* Format a number with optional decimal places.
|
|
52
|
+
* @example formatNumber(1234567.89) → "1,234,567.89"
|
|
53
|
+
* @example formatNumber(1234567.89, 0) → "1,234,568"
|
|
54
|
+
*/
|
|
55
|
+
export declare function formatNumber(n: number, decimals?: number): string;
|
|
56
|
+
/**
|
|
57
|
+
* Format a boolean as a human-readable string.
|
|
58
|
+
* @example formatBoolean(true) → "Yes"
|
|
59
|
+
* @example formatBoolean(false) → "No"
|
|
60
|
+
*/
|
|
61
|
+
export declare function formatBoolean(val: boolean): string;
|
|
62
|
+
/**
|
|
63
|
+
* Extract initials from a name.
|
|
64
|
+
* @example getInitials('John Doe') → 'JD'
|
|
65
|
+
* @example getInitials('Alice') → 'A'
|
|
66
|
+
* @example getInitials('Mary Jane Watson') → 'MJW'
|
|
67
|
+
*/
|
|
68
|
+
export declare function getInitials(name: string): string;
|
|
69
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAMzC;;;;GAIG;AACH,wBAAgB,iBAAiB,IAAI,MAAM,CAE1C;AAMD;;;;;;GAMG;AACH,wBAAsB,eAAe,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CAMvE;AAMD;;GAEG;AACH,wBAAgB,aAAa,CAAC,CAAC,GAAG,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC,GAAG,IAAI,CAMjE;AAMD;;GAEG;AACH,wBAAgB,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE/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