@ontrails/core 1.0.0-beta.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/.turbo/turbo-build.log +1 -0
- package/.turbo/turbo-lint.log +3 -0
- package/.turbo/turbo-typecheck.log +1 -0
- package/CHANGELOG.md +15 -0
- package/README.md +179 -0
- package/dist/adapters.d.ts +39 -0
- package/dist/adapters.d.ts.map +1 -0
- package/dist/adapters.js +2 -0
- package/dist/adapters.js.map +1 -0
- package/dist/blob-ref.d.ts +20 -0
- package/dist/blob-ref.d.ts.map +1 -0
- package/dist/blob-ref.js +22 -0
- package/dist/blob-ref.js.map +1 -0
- package/dist/branded.d.ts +36 -0
- package/dist/branded.d.ts.map +1 -0
- package/dist/branded.js +89 -0
- package/dist/branded.js.map +1 -0
- package/dist/collections.d.ts +31 -0
- package/dist/collections.d.ts.map +1 -0
- package/dist/collections.js +60 -0
- package/dist/collections.js.map +1 -0
- package/dist/context.d.ts +10 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +15 -0
- package/dist/context.js.map +1 -0
- package/dist/derive.d.ts +33 -0
- package/dist/derive.d.ts.map +1 -0
- package/dist/derive.js +122 -0
- package/dist/derive.js.map +1 -0
- package/dist/errors.d.ts +83 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +142 -0
- package/dist/errors.js.map +1 -0
- package/dist/event.d.ts +45 -0
- package/dist/event.d.ts.map +1 -0
- package/dist/event.js +17 -0
- package/dist/event.js.map +1 -0
- package/dist/fetch.d.ts +15 -0
- package/dist/fetch.d.ts.map +1 -0
- package/dist/fetch.js +102 -0
- package/dist/fetch.js.map +1 -0
- package/dist/guards.d.ts +17 -0
- package/dist/guards.d.ts.map +1 -0
- package/dist/guards.js +25 -0
- package/dist/guards.js.map +1 -0
- package/dist/health.d.ts +18 -0
- package/dist/health.d.ts.map +1 -0
- package/dist/health.js +5 -0
- package/dist/health.js.map +1 -0
- package/dist/hike.d.ts +36 -0
- package/dist/hike.d.ts.map +1 -0
- package/dist/hike.js +20 -0
- package/dist/hike.js.map +1 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +38 -0
- package/dist/index.js.map +1 -0
- package/dist/job.d.ts +24 -0
- package/dist/job.d.ts.map +1 -0
- package/dist/job.js +17 -0
- package/dist/job.js.map +1 -0
- package/dist/layer.d.ts +17 -0
- package/dist/layer.d.ts.map +1 -0
- package/dist/layer.js +21 -0
- package/dist/layer.js.map +1 -0
- package/dist/path-security.d.ts +28 -0
- package/dist/path-security.d.ts.map +1 -0
- package/dist/path-security.js +63 -0
- package/dist/path-security.js.map +1 -0
- package/dist/patterns/bulk.d.ts +15 -0
- package/dist/patterns/bulk.d.ts.map +1 -0
- package/dist/patterns/bulk.js +14 -0
- package/dist/patterns/bulk.js.map +1 -0
- package/dist/patterns/change.d.ts +10 -0
- package/dist/patterns/change.d.ts.map +1 -0
- package/dist/patterns/change.js +10 -0
- package/dist/patterns/change.js.map +1 -0
- package/dist/patterns/date-range.d.ts +10 -0
- package/dist/patterns/date-range.d.ts.map +1 -0
- package/dist/patterns/date-range.js +10 -0
- package/dist/patterns/date-range.js.map +1 -0
- package/dist/patterns/index.d.ts +9 -0
- package/dist/patterns/index.d.ts.map +1 -0
- package/dist/patterns/index.js +9 -0
- package/dist/patterns/index.js.map +1 -0
- package/dist/patterns/pagination.d.ts +18 -0
- package/dist/patterns/pagination.d.ts.map +1 -0
- package/dist/patterns/pagination.js +18 -0
- package/dist/patterns/pagination.js.map +1 -0
- package/dist/patterns/progress.d.ts +11 -0
- package/dist/patterns/progress.d.ts.map +1 -0
- package/dist/patterns/progress.js +11 -0
- package/dist/patterns/progress.js.map +1 -0
- package/dist/patterns/sorting.d.ts +13 -0
- package/dist/patterns/sorting.d.ts.map +1 -0
- package/dist/patterns/sorting.js +10 -0
- package/dist/patterns/sorting.js.map +1 -0
- package/dist/patterns/status.d.ts +15 -0
- package/dist/patterns/status.d.ts.map +1 -0
- package/dist/patterns/status.js +9 -0
- package/dist/patterns/status.js.map +1 -0
- package/dist/patterns/timestamps.d.ts +10 -0
- package/dist/patterns/timestamps.d.ts.map +1 -0
- package/dist/patterns/timestamps.js +10 -0
- package/dist/patterns/timestamps.js.map +1 -0
- package/dist/redaction/index.d.ts +4 -0
- package/dist/redaction/index.d.ts.map +1 -0
- package/dist/redaction/index.js +3 -0
- package/dist/redaction/index.js.map +1 -0
- package/dist/redaction/patterns.d.ts +9 -0
- package/dist/redaction/patterns.d.ts.map +1 -0
- package/dist/redaction/patterns.js +39 -0
- package/dist/redaction/patterns.js.map +1 -0
- package/dist/redaction/redactor.d.ts +27 -0
- package/dist/redaction/redactor.d.ts.map +1 -0
- package/dist/redaction/redactor.js +89 -0
- package/dist/redaction/redactor.js.map +1 -0
- package/dist/resilience.d.ts +34 -0
- package/dist/resilience.d.ts.map +1 -0
- package/dist/resilience.js +164 -0
- package/dist/resilience.js.map +1 -0
- package/dist/result.d.ts +57 -0
- package/dist/result.d.ts.map +1 -0
- package/dist/result.js +145 -0
- package/dist/result.js.map +1 -0
- package/dist/serialization.d.ts +27 -0
- package/dist/serialization.d.ts.map +1 -0
- package/dist/serialization.js +115 -0
- package/dist/serialization.js.map +1 -0
- package/dist/topo.d.ts +18 -0
- package/dist/topo.d.ts.map +1 -0
- package/dist/topo.js +74 -0
- package/dist/topo.js.map +1 -0
- package/dist/trail.d.ts +83 -0
- package/dist/trail.d.ts.map +1 -0
- package/dist/trail.js +16 -0
- package/dist/trail.js.map +1 -0
- package/dist/types.d.ts +46 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/validate-topo.d.ts +24 -0
- package/dist/validate-topo.d.ts.map +1 -0
- package/dist/validate-topo.js +108 -0
- package/dist/validate-topo.js.map +1 -0
- package/dist/validation.d.ts +27 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +134 -0
- package/dist/validation.js.map +1 -0
- package/dist/workspace.d.ts +25 -0
- package/dist/workspace.d.ts.map +1 -0
- package/dist/workspace.js +57 -0
- package/dist/workspace.js.map +1 -0
- package/package.json +21 -0
- package/src/__tests__/blob-ref.test.ts +103 -0
- package/src/__tests__/branded.test.ts +148 -0
- package/src/__tests__/collections.test.ts +126 -0
- package/src/__tests__/context.test.ts +66 -0
- package/src/__tests__/derive.test.ts +159 -0
- package/src/__tests__/errors.test.ts +309 -0
- package/src/__tests__/event.test.ts +82 -0
- package/src/__tests__/fetch.test.ts +217 -0
- package/src/__tests__/guards.test.ts +102 -0
- package/src/__tests__/hike.test.ts +117 -0
- package/src/__tests__/job.test.ts +98 -0
- package/src/__tests__/layer.test.ts +224 -0
- package/src/__tests__/path-security.test.ts +114 -0
- package/src/__tests__/patterns.test.ts +273 -0
- package/src/__tests__/redaction.test.ts +244 -0
- package/src/__tests__/resilience.test.ts +246 -0
- package/src/__tests__/result.test.ts +155 -0
- package/src/__tests__/serialization.test.ts +236 -0
- package/src/__tests__/topo.test.ts +184 -0
- package/src/__tests__/trail.test.ts +179 -0
- package/src/__tests__/validate-topo.test.ts +201 -0
- package/src/__tests__/validation.test.ts +283 -0
- package/src/__tests__/workspace.test.ts +183 -0
- package/src/adapters.ts +68 -0
- package/src/blob-ref.ts +39 -0
- package/src/branded.ts +135 -0
- package/src/collections.ts +99 -0
- package/src/context.ts +18 -0
- package/src/derive.ts +223 -0
- package/src/errors.ts +196 -0
- package/src/event.ts +77 -0
- package/src/fetch.ts +138 -0
- package/src/guards.ts +37 -0
- package/src/health.ts +23 -0
- package/src/hike.ts +77 -0
- package/src/index.ts +158 -0
- package/src/job.ts +20 -0
- package/src/layer.ts +44 -0
- package/src/path-security.ts +90 -0
- package/src/patterns/bulk.ts +16 -0
- package/src/patterns/change.ts +12 -0
- package/src/patterns/date-range.ts +12 -0
- package/src/patterns/index.ts +8 -0
- package/src/patterns/pagination.ts +22 -0
- package/src/patterns/progress.ts +13 -0
- package/src/patterns/sorting.ts +14 -0
- package/src/patterns/status.ts +11 -0
- package/src/patterns/timestamps.ts +12 -0
- package/src/redaction/index.ts +3 -0
- package/src/redaction/patterns.ts +47 -0
- package/src/redaction/redactor.ts +178 -0
- package/src/resilience.ts +234 -0
- package/src/result.ts +180 -0
- package/src/serialization.ts +183 -0
- package/src/topo.ts +123 -0
- package/src/trail.ts +130 -0
- package/src/types.ts +58 -0
- package/src/validate-topo.ts +151 -0
- package/src/validation.ts +182 -0
- package/src/workspace.ts +77 -0
- package/tsconfig.json +9 -0
- package/tsconfig.tsbuildinfo +1 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Status schema helpers for @ontrails/core/patterns
|
|
3
|
+
*/
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
/** Standard workflow status field. */
|
|
6
|
+
export declare const statusFields: () => z.ZodObject<{
|
|
7
|
+
status: z.ZodEnum<{
|
|
8
|
+
cancelled: "cancelled";
|
|
9
|
+
pending: "pending";
|
|
10
|
+
running: "running";
|
|
11
|
+
completed: "completed";
|
|
12
|
+
failed: "failed";
|
|
13
|
+
}>;
|
|
14
|
+
}, z.core.$strip>;
|
|
15
|
+
//# sourceMappingURL=status.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"status.d.ts","sourceRoot":"","sources":["../../src/patterns/status.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,sCAAsC;AACtC,eAAO,MAAM,YAAY;;;;;;;;iBAGrB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Status schema helpers for @ontrails/core/patterns
|
|
3
|
+
*/
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
/** Standard workflow status field. */
|
|
6
|
+
export const statusFields = () => z.object({
|
|
7
|
+
status: z.enum(['pending', 'running', 'completed', 'failed', 'cancelled']),
|
|
8
|
+
});
|
|
9
|
+
//# sourceMappingURL=status.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"status.js","sourceRoot":"","sources":["../../src/patterns/status.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,sCAAsC;AACtC,MAAM,CAAC,MAAM,YAAY,GAAG,GAAG,EAAE,CAC/B,CAAC,CAAC,MAAM,CAAC;IACP,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,QAAQ,EAAE,WAAW,CAAC,CAAC;CAC3E,CAAC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Timestamp schema helpers for @ontrails/core/patterns
|
|
3
|
+
*/
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
/** Standard createdAt / updatedAt fields. */
|
|
6
|
+
export declare const timestampFields: () => z.ZodObject<{
|
|
7
|
+
createdAt: z.ZodString;
|
|
8
|
+
updatedAt: z.ZodString;
|
|
9
|
+
}, z.core.$strip>;
|
|
10
|
+
//# sourceMappingURL=timestamps.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timestamps.d.ts","sourceRoot":"","sources":["../../src/patterns/timestamps.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,6CAA6C;AAC7C,eAAO,MAAM,eAAe;;;iBAIxB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Timestamp schema helpers for @ontrails/core/patterns
|
|
3
|
+
*/
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
/** Standard createdAt / updatedAt fields. */
|
|
6
|
+
export const timestampFields = () => z.object({
|
|
7
|
+
createdAt: z.string(),
|
|
8
|
+
updatedAt: z.string(),
|
|
9
|
+
});
|
|
10
|
+
//# sourceMappingURL=timestamps.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timestamps.js","sourceRoot":"","sources":["../../src/patterns/timestamps.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,6CAA6C;AAC7C,MAAM,CAAC,MAAM,eAAe,GAAG,GAAG,EAAE,CAClC,CAAC,CAAC,MAAM,CAAC;IACP,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;IACrB,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;CACtB,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/redaction/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AACzE,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,YAAY,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/redaction/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AACzE,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default redaction patterns and sensitive key lists.
|
|
3
|
+
*
|
|
4
|
+
* These are used by {@link createRedactor} to strip secrets from strings
|
|
5
|
+
* and object values before they reach logs, traces, or error payloads.
|
|
6
|
+
*/
|
|
7
|
+
export declare const DEFAULT_PATTERNS: RegExp[];
|
|
8
|
+
export declare const DEFAULT_SENSITIVE_KEYS: string[];
|
|
9
|
+
//# sourceMappingURL=patterns.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"patterns.d.ts","sourceRoot":"","sources":["../../src/redaction/patterns.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,eAAO,MAAM,gBAAgB,EAAE,MAAM,EAkBpC,CAAC;AAMF,eAAO,MAAM,sBAAsB,EAAE,MAAM,EAW1C,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default redaction patterns and sensitive key lists.
|
|
3
|
+
*
|
|
4
|
+
* These are used by {@link createRedactor} to strip secrets from strings
|
|
5
|
+
* and object values before they reach logs, traces, or error payloads.
|
|
6
|
+
*/
|
|
7
|
+
// ---------------------------------------------------------------------------
|
|
8
|
+
// Regex patterns that match sensitive values inside arbitrary strings
|
|
9
|
+
// ---------------------------------------------------------------------------
|
|
10
|
+
export const DEFAULT_PATTERNS = [
|
|
11
|
+
// Credit card numbers: 4 groups of 4 digits separated by spaces or dashes
|
|
12
|
+
/\b\d{4}[- ]\d{4}[- ]\d{4}[- ]\d{4}\b/g,
|
|
13
|
+
// SSN: XXX-XX-XXXX
|
|
14
|
+
/\b\d{3}-\d{2}-\d{4}\b/g,
|
|
15
|
+
// Bearer tokens
|
|
16
|
+
/Bearer\s+[A-Za-z0-9\-._~+/]+=*/g,
|
|
17
|
+
// Basic auth
|
|
18
|
+
/Basic\s+[A-Za-z0-9+/]+=*/g,
|
|
19
|
+
// API keys: sk-*, pk_*, sk_* prefixed tokens
|
|
20
|
+
/\b(?:sk-|pk_|sk_)[A-Za-z0-9_-]{8,}\b/g,
|
|
21
|
+
// JWT tokens: eyJ... (three base64url segments separated by dots)
|
|
22
|
+
/\beyJ[A-Za-z0-9_-]+\.eyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\b/g,
|
|
23
|
+
];
|
|
24
|
+
// ---------------------------------------------------------------------------
|
|
25
|
+
// Object keys whose values should always be redacted
|
|
26
|
+
// ---------------------------------------------------------------------------
|
|
27
|
+
export const DEFAULT_SENSITIVE_KEYS = [
|
|
28
|
+
'password',
|
|
29
|
+
'secret',
|
|
30
|
+
'token',
|
|
31
|
+
'apiKey',
|
|
32
|
+
'api_key',
|
|
33
|
+
'authorization',
|
|
34
|
+
'cookie',
|
|
35
|
+
'ssn',
|
|
36
|
+
'creditCard',
|
|
37
|
+
'credit_card',
|
|
38
|
+
];
|
|
39
|
+
//# sourceMappingURL=patterns.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"patterns.js","sourceRoot":"","sources":["../../src/redaction/patterns.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,8EAA8E;AAC9E,sEAAsE;AACtE,8EAA8E;AAE9E,MAAM,CAAC,MAAM,gBAAgB,GAAa;IACxC,0EAA0E;IAC1E,uCAAuC;IAEvC,mBAAmB;IACnB,wBAAwB;IAExB,gBAAgB;IAChB,iCAAiC;IAEjC,aAAa;IACb,2BAA2B;IAE3B,6CAA6C;IAC7C,uCAAuC;IAEvC,kEAAkE;IAClE,2DAA2D;CAC5D,CAAC;AAEF,8EAA8E;AAC9E,qDAAqD;AACrD,8EAA8E;AAE9E,MAAM,CAAC,MAAM,sBAAsB,GAAa;IAC9C,UAAU;IACV,QAAQ;IACR,OAAO;IACP,QAAQ;IACR,SAAS;IACT,eAAe;IACf,QAAQ;IACR,KAAK;IACL,YAAY;IACZ,aAAa;CACd,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Redactor — strips sensitive data from strings and objects.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* const r = createRedactor();
|
|
7
|
+
* r.redact("token: Bearer abc123"); // "token: [REDACTED]"
|
|
8
|
+
* r.redactObject({ password: "s3cret" }); // { password: "[REDACTED]" }
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
11
|
+
export interface RedactorConfig {
|
|
12
|
+
readonly patterns?: RegExp[];
|
|
13
|
+
readonly sensitiveKeys?: string[];
|
|
14
|
+
readonly replacement?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface Redactor {
|
|
17
|
+
/** Replace all pattern matches in a string with the replacement. */
|
|
18
|
+
redact(value: string): string;
|
|
19
|
+
/**
|
|
20
|
+
* Deep-clone `obj` and redact:
|
|
21
|
+
* 1. Values whose key matches a sensitive key (case-insensitive).
|
|
22
|
+
* 2. All remaining string values that match a pattern.
|
|
23
|
+
*/
|
|
24
|
+
redactObject<T extends Record<string, unknown>>(obj: T): T;
|
|
25
|
+
}
|
|
26
|
+
export declare const createRedactor: (config?: RedactorConfig) => Redactor;
|
|
27
|
+
//# sourceMappingURL=redactor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redactor.d.ts","sourceRoot":"","sources":["../../src/redaction/redactor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAQH,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IAC7B,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IAClC,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED,MAAM,WAAW,QAAQ;IACvB,oEAAoE;IACpE,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;IAE9B;;;;OAIG;IACH,YAAY,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC;CAC5D;AA8HD,eAAO,MAAM,cAAc,GAAI,SAAS,cAAc,KAAG,QAkBxD,CAAC"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Redactor — strips sensitive data from strings and objects.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* const r = createRedactor();
|
|
7
|
+
* r.redact("token: Bearer abc123"); // "token: [REDACTED]"
|
|
8
|
+
* r.redactObject({ password: "s3cret" }); // { password: "[REDACTED]" }
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
11
|
+
import { DEFAULT_PATTERNS, DEFAULT_SENSITIVE_KEYS } from './patterns.js';
|
|
12
|
+
// ---------------------------------------------------------------------------
|
|
13
|
+
// Helpers
|
|
14
|
+
// ---------------------------------------------------------------------------
|
|
15
|
+
const resetPatterns = (patterns) => {
|
|
16
|
+
for (const p of patterns) {
|
|
17
|
+
p.lastIndex = 0;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
const applyPatterns = (value, patterns, replacement) => {
|
|
21
|
+
let result = value;
|
|
22
|
+
for (const pattern of patterns) {
|
|
23
|
+
// Reset in case the regex is stateful (global flag)
|
|
24
|
+
pattern.lastIndex = 0;
|
|
25
|
+
result = result.replace(pattern, replacement);
|
|
26
|
+
}
|
|
27
|
+
return result;
|
|
28
|
+
};
|
|
29
|
+
const isSensitiveKey = (key, sensitiveKeysLower) => key !== undefined && sensitiveKeysLower.has(key.toLowerCase());
|
|
30
|
+
const mapObjectValues = (value, visit) => {
|
|
31
|
+
const result = {};
|
|
32
|
+
for (const [key, item] of Object.entries(value)) {
|
|
33
|
+
result[key] = visit(item, key);
|
|
34
|
+
}
|
|
35
|
+
return result;
|
|
36
|
+
};
|
|
37
|
+
/** Track and guard against circular references in object graphs. */
|
|
38
|
+
const trackOrCircular = (value, seen) => {
|
|
39
|
+
if (seen.has(value)) {
|
|
40
|
+
return '[Circular]';
|
|
41
|
+
}
|
|
42
|
+
seen.add(value);
|
|
43
|
+
return null;
|
|
44
|
+
};
|
|
45
|
+
/* oxlint-disable no-use-before-define -- mutual recursion between redactCompound and deepRedact */
|
|
46
|
+
/** Redact a compound value (array or object), delegating scalars back to deepRedact. */
|
|
47
|
+
const redactCompound = (value, sensitiveKeysLower, patterns, replacement, seen) => {
|
|
48
|
+
const circular = trackOrCircular(value, seen);
|
|
49
|
+
if (circular) {
|
|
50
|
+
return circular;
|
|
51
|
+
}
|
|
52
|
+
if (Array.isArray(value)) {
|
|
53
|
+
return value.map((item) => deepRedact(item, sensitiveKeysLower, patterns, replacement, undefined, seen));
|
|
54
|
+
}
|
|
55
|
+
return mapObjectValues(value, (item, key) => deepRedact(item, sensitiveKeysLower, patterns, replacement, key, seen));
|
|
56
|
+
};
|
|
57
|
+
const deepRedact = (value, sensitiveKeysLower, patterns, replacement, currentKey, seen = new WeakSet()) => {
|
|
58
|
+
if (isSensitiveKey(currentKey, sensitiveKeysLower)) {
|
|
59
|
+
return replacement;
|
|
60
|
+
}
|
|
61
|
+
if (typeof value === 'string') {
|
|
62
|
+
return applyPatterns(value, patterns, replacement);
|
|
63
|
+
}
|
|
64
|
+
if (value !== null && typeof value === 'object') {
|
|
65
|
+
return redactCompound(value, sensitiveKeysLower, patterns, replacement, seen);
|
|
66
|
+
}
|
|
67
|
+
return value;
|
|
68
|
+
};
|
|
69
|
+
/* oxlint-enable no-use-before-define */
|
|
70
|
+
// ---------------------------------------------------------------------------
|
|
71
|
+
// Factory
|
|
72
|
+
// ---------------------------------------------------------------------------
|
|
73
|
+
export const createRedactor = (config) => {
|
|
74
|
+
const patterns = config?.patterns ?? DEFAULT_PATTERNS;
|
|
75
|
+
const sensitiveKeys = config?.sensitiveKeys ?? DEFAULT_SENSITIVE_KEYS;
|
|
76
|
+
const replacement = config?.replacement ?? '[REDACTED]';
|
|
77
|
+
const sensitiveKeysLower = new Set(sensitiveKeys.map((k) => k.toLowerCase()));
|
|
78
|
+
return {
|
|
79
|
+
redact(value) {
|
|
80
|
+
resetPatterns(patterns);
|
|
81
|
+
return applyPatterns(value, patterns, replacement);
|
|
82
|
+
},
|
|
83
|
+
redactObject(obj) {
|
|
84
|
+
resetPatterns(patterns);
|
|
85
|
+
return deepRedact(obj, sensitiveKeysLower, patterns, replacement);
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
//# sourceMappingURL=redactor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"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,EAAE,WAAW,CAAC,CAAC;IACrD,CAAC;IACD,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAChD,OAAO,cAAc,CACnB,KAAK,EACL,kBAAkB,EAClB,QAAQ,EACR,WAAW,EACX,IAAI,CACL,CAAC;IACJ,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF,wCAAwC;AAExC,8EAA8E;AAC9E,UAAU;AACV,8EAA8E;AAE9E,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,MAAuB,EAAY,EAAE;IAClE,MAAM,QAAQ,GAAG,MAAM,EAAE,QAAQ,IAAI,gBAAgB,CAAC;IACtD,MAAM,aAAa,GAAG,MAAM,EAAE,aAAa,IAAI,sBAAsB,CAAC;IACtE,MAAM,WAAW,GAAG,MAAM,EAAE,WAAW,IAAI,YAAY,CAAC;IAExD,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;IAE9E,OAAO;QACL,MAAM,CAAC,KAAa;YAClB,aAAa,CAAC,QAAQ,CAAC,CAAC;YACxB,OAAO,aAAa,CAAC,KAAK,EAAE,QAAQ,EAAE,WAAW,CAAC,CAAC;QACrD,CAAC;QAED,YAAY,CAAoC,GAAM;YACpD,aAAa,CAAC,QAAQ,CAAC,CAAC;YACxB,OAAO,UAAU,CAAC,GAAG,EAAE,kBAAkB,EAAE,QAAQ,EAAE,WAAW,CAAM,CAAC;QACzE,CAAC;KACF,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resilience utilities for @ontrails/core
|
|
3
|
+
*
|
|
4
|
+
* Retry with exponential backoff and timeout wrappers,
|
|
5
|
+
* all returning Result types.
|
|
6
|
+
*/
|
|
7
|
+
import { Result } from './result.js';
|
|
8
|
+
export interface RetryOptions {
|
|
9
|
+
/** Maximum number of attempts (default: 3) */
|
|
10
|
+
readonly maxAttempts?: number | undefined;
|
|
11
|
+
/** Base delay in ms before first retry (default: 1000) */
|
|
12
|
+
readonly baseDelay?: number | undefined;
|
|
13
|
+
/** Maximum delay in ms (default: 30000) */
|
|
14
|
+
readonly maxDelay?: number | undefined;
|
|
15
|
+
/** Exponential backoff factor (default: 2) */
|
|
16
|
+
readonly backoffFactor?: number | undefined;
|
|
17
|
+
/** Custom predicate — defaults to isRetryable from error taxonomy */
|
|
18
|
+
readonly shouldRetry?: ((error: Error) => boolean) | undefined;
|
|
19
|
+
/** AbortSignal for cancellation */
|
|
20
|
+
readonly signal?: AbortSignal | undefined;
|
|
21
|
+
}
|
|
22
|
+
/** Default retry predicate using the error taxonomy. */
|
|
23
|
+
export declare const shouldRetry: (error: Error) => boolean;
|
|
24
|
+
/** Compute exponential backoff delay with full jitter. */
|
|
25
|
+
export declare const getBackoffDelay: (attempt: number, options?: Pick<RetryOptions, "baseDelay" | "maxDelay" | "backoffFactor">) => number;
|
|
26
|
+
export declare const retry: <T>(fn: () => Promise<Result<T, Error>>, options?: RetryOptions) => Promise<Result<T, Error>>;
|
|
27
|
+
/**
|
|
28
|
+
* Run an async Result-returning function with a timeout.
|
|
29
|
+
*
|
|
30
|
+
* If the timeout fires first, returns a TimeoutError result.
|
|
31
|
+
* Also respects an external AbortSignal.
|
|
32
|
+
*/
|
|
33
|
+
export declare const withTimeout: <T>(fn: () => Promise<Result<T, Error>>, ms: number, signal?: AbortSignal) => Promise<Result<T, Error>>;
|
|
34
|
+
//# sourceMappingURL=resilience.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resilience.d.ts","sourceRoot":"","sources":["../src/resilience.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAMrC,MAAM,WAAW,YAAY;IAC3B,8CAA8C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|
3
|
+
*
|
|
4
|
+
* Retry with exponential backoff and timeout wrappers,
|
|
5
|
+
* all returning Result types.
|
|
6
|
+
*/
|
|
7
|
+
import { CancelledError, TimeoutError, isRetryable } from './errors.js';
|
|
8
|
+
import { Result } from './result.js';
|
|
9
|
+
// ---------------------------------------------------------------------------
|
|
10
|
+
// Helpers (defined before usage)
|
|
11
|
+
// ---------------------------------------------------------------------------
|
|
12
|
+
const sleep = (ms, signal) =>
|
|
13
|
+
// oxlint-disable-next-line avoid-new -- Promise constructor needed for setTimeout-based sleep
|
|
14
|
+
new Promise((resolve) => {
|
|
15
|
+
if (signal?.aborted) {
|
|
16
|
+
resolve();
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
let settled = false;
|
|
20
|
+
const done = () => {
|
|
21
|
+
if (!settled) {
|
|
22
|
+
settled = true;
|
|
23
|
+
resolve();
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
const timer = setTimeout(done, ms);
|
|
27
|
+
const onAbort = () => {
|
|
28
|
+
clearTimeout(timer);
|
|
29
|
+
done();
|
|
30
|
+
};
|
|
31
|
+
signal?.addEventListener('abort', onAbort, { once: true });
|
|
32
|
+
});
|
|
33
|
+
// ---------------------------------------------------------------------------
|
|
34
|
+
// shouldRetry (default)
|
|
35
|
+
// ---------------------------------------------------------------------------
|
|
36
|
+
/** Default retry predicate using the error taxonomy. */
|
|
37
|
+
export const shouldRetry = (error) => isRetryable(error);
|
|
38
|
+
// ---------------------------------------------------------------------------
|
|
39
|
+
// getBackoffDelay
|
|
40
|
+
// ---------------------------------------------------------------------------
|
|
41
|
+
/** Compute exponential backoff delay with full jitter. */
|
|
42
|
+
export const getBackoffDelay = (attempt, options) => {
|
|
43
|
+
const base = options?.baseDelay ?? 1000;
|
|
44
|
+
const max = options?.maxDelay ?? 30_000;
|
|
45
|
+
const factor = options?.backoffFactor ?? 2;
|
|
46
|
+
const exponential = base * factor ** attempt;
|
|
47
|
+
const capped = Math.min(exponential, max);
|
|
48
|
+
// Full jitter: random value in [0, capped]
|
|
49
|
+
return Math.floor(Math.random() * capped);
|
|
50
|
+
};
|
|
51
|
+
// ---------------------------------------------------------------------------
|
|
52
|
+
// retry
|
|
53
|
+
// ---------------------------------------------------------------------------
|
|
54
|
+
/**
|
|
55
|
+
* Retry an async function that returns a Result.
|
|
56
|
+
*
|
|
57
|
+
* On each failure, checks whether the error is retryable and whether the
|
|
58
|
+
* attempt budget remains. Applies exponential backoff with jitter between
|
|
59
|
+
* retries.
|
|
60
|
+
*/
|
|
61
|
+
/** Attempt a single retry iteration. Returns the result to stop, or undefined to continue. */
|
|
62
|
+
const tryAttempt = async (fn, attempt, maxAttempts, retryPredicate, options) => {
|
|
63
|
+
const result = await fn();
|
|
64
|
+
if (result.isOk()) {
|
|
65
|
+
return { done: true, result };
|
|
66
|
+
}
|
|
67
|
+
const isLast = attempt === maxAttempts - 1;
|
|
68
|
+
if (isLast || !retryPredicate(result.error)) {
|
|
69
|
+
return { done: true, result };
|
|
70
|
+
}
|
|
71
|
+
const delay = getBackoffDelay(attempt, options);
|
|
72
|
+
if (delay > 0) {
|
|
73
|
+
await sleep(delay, options?.signal);
|
|
74
|
+
}
|
|
75
|
+
return { done: false, result };
|
|
76
|
+
};
|
|
77
|
+
/** Resolve retry options to concrete values. */
|
|
78
|
+
const resolveRetryOptions = (options) => ({
|
|
79
|
+
maxAttempts: options?.maxAttempts ?? 3,
|
|
80
|
+
retryPredicate: options?.shouldRetry ?? shouldRetry,
|
|
81
|
+
signal: options?.signal,
|
|
82
|
+
});
|
|
83
|
+
export const retry = async (fn, options) => {
|
|
84
|
+
const { maxAttempts, retryPredicate, signal } = resolveRetryOptions(options);
|
|
85
|
+
let lastResult;
|
|
86
|
+
for (let attempt = 0; attempt < maxAttempts; attempt += 1) {
|
|
87
|
+
if (signal?.aborted) {
|
|
88
|
+
return Result.err(new CancelledError('Retry cancelled'));
|
|
89
|
+
}
|
|
90
|
+
const outcome = await tryAttempt(fn, attempt, maxAttempts, retryPredicate, options);
|
|
91
|
+
lastResult = outcome.result;
|
|
92
|
+
if (outcome.done) {
|
|
93
|
+
return outcome.result;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return lastResult ?? Result.err(new CancelledError('Retry exhausted'));
|
|
97
|
+
};
|
|
98
|
+
// ---------------------------------------------------------------------------
|
|
99
|
+
// withTimeout
|
|
100
|
+
// ---------------------------------------------------------------------------
|
|
101
|
+
/**
|
|
102
|
+
* Run an async Result-returning function with a timeout.
|
|
103
|
+
*
|
|
104
|
+
* If the timeout fires first, returns a TimeoutError result.
|
|
105
|
+
* Also respects an external AbortSignal.
|
|
106
|
+
*/
|
|
107
|
+
export const withTimeout = (fn, ms, signal) => {
|
|
108
|
+
if (signal?.aborted) {
|
|
109
|
+
return Promise.resolve(Result.err(new CancelledError('Already cancelled')));
|
|
110
|
+
}
|
|
111
|
+
// oxlint-disable-next-line avoid-new, promise/no-multiple-resolved -- Promise constructor needed for timeout race; settled guard ensures single resolution
|
|
112
|
+
return new Promise((resolve) => {
|
|
113
|
+
let settled = false;
|
|
114
|
+
// oxlint-disable-next-line prefer-const -- assigned after declaration
|
|
115
|
+
let timer;
|
|
116
|
+
const onAbort = () => {
|
|
117
|
+
if (settled) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
settled = true;
|
|
121
|
+
clearTimeout(timer);
|
|
122
|
+
signal?.removeEventListener('abort', onAbort);
|
|
123
|
+
// oxlint-disable-next-line promise/no-multiple-resolved -- settled guard ensures single resolution
|
|
124
|
+
resolve(Result.err(new CancelledError('Operation cancelled')));
|
|
125
|
+
};
|
|
126
|
+
signal?.addEventListener('abort', onAbort, { once: true });
|
|
127
|
+
timer = setTimeout(() => {
|
|
128
|
+
if (settled) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
settled = true;
|
|
132
|
+
signal?.removeEventListener('abort', onAbort);
|
|
133
|
+
// oxlint-disable-next-line promise/no-multiple-resolved -- settled guard ensures single resolution
|
|
134
|
+
resolve(Result.err(new TimeoutError(`Operation timed out after ${ms}ms`, {
|
|
135
|
+
context: { timeoutMs: ms },
|
|
136
|
+
})));
|
|
137
|
+
}, ms);
|
|
138
|
+
// oxlint-disable-next-line prefer-await-to-then, no-void -- .then() needed inside Promise constructor; void discards unhandled rejection
|
|
139
|
+
void fn().then(
|
|
140
|
+
// oxlint-disable-next-line prefer-await-to-callbacks -- callback required inside .then()
|
|
141
|
+
(result) => {
|
|
142
|
+
if (settled) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
settled = true;
|
|
146
|
+
clearTimeout(timer);
|
|
147
|
+
signal?.removeEventListener('abort', onAbort);
|
|
148
|
+
// oxlint-disable-next-line promise/no-multiple-resolved -- settled guard ensures single resolution
|
|
149
|
+
resolve(result);
|
|
150
|
+
},
|
|
151
|
+
// oxlint-disable-next-line prefer-await-to-callbacks -- rejection handler required inside .then()
|
|
152
|
+
(error) => {
|
|
153
|
+
if (settled) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
settled = true;
|
|
157
|
+
clearTimeout(timer);
|
|
158
|
+
signal?.removeEventListener('abort', onAbort);
|
|
159
|
+
// oxlint-disable-next-line promise/no-multiple-resolved -- settled guard ensures single resolution
|
|
160
|
+
resolve(Result.err(error instanceof Error ? error : new Error(String(error))));
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
};
|
|
164
|
+
//# sourceMappingURL=resilience.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resilience.js","sourceRoot":"","sources":["../src/resilience.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACxE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAqBrC,8EAA8E;AAC9E,iCAAiC;AACjC,8EAA8E;AAE9E,MAAM,KAAK,GAAG,CAAC,EAAU,EAAE,MA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AAO,EAAE,CAAC;gBACZ,OAAO;YACT,CAAC;YACD,OAAO,GAAG,IAAI,CAAC;YACf,YAAY,CAAC,KAAK,CAAC,CAAC;YACpB,MAAM,EAAE,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YAC9C,mGAAmG;YACnG,OAAO,CACL,MAAM,CAAC,GAAG,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CACtE,CAAC;QACJ,CAAC,CACF,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC"}
|
package/dist/result.d.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A type-safe Result monad for representing success/failure without exceptions.
|
|
3
|
+
*/
|
|
4
|
+
import { InternalError, ValidationError } from './errors.js';
|
|
5
|
+
declare class Ok<T, E> {
|
|
6
|
+
readonly value: T;
|
|
7
|
+
constructor(value: T);
|
|
8
|
+
isOk(): this is Ok<T, E>;
|
|
9
|
+
isErr(): this is Err<T, E>;
|
|
10
|
+
map<U>(fn: (value: T) => U): Result<U, E>;
|
|
11
|
+
flatMap<U, F = E>(fn: (value: T) => Result<U, F>): Result<U, E | F>;
|
|
12
|
+
mapErr<F>(_fn: (error: E) => F): Result<T, F>;
|
|
13
|
+
match<U>(handlers: {
|
|
14
|
+
ok: (value: T) => U;
|
|
15
|
+
err: (error: E) => U;
|
|
16
|
+
}): U;
|
|
17
|
+
unwrap(): T;
|
|
18
|
+
unwrapOr(_fallback: T): T;
|
|
19
|
+
}
|
|
20
|
+
declare class Err<T, E> {
|
|
21
|
+
readonly error: E;
|
|
22
|
+
constructor(error: E);
|
|
23
|
+
isOk(): this is Ok<T, E>;
|
|
24
|
+
isErr(): this is Err<T, E>;
|
|
25
|
+
map<U>(_fn: (value: T) => U): Result<U, E>;
|
|
26
|
+
flatMap<U, F = E>(_fn: (value: T) => Result<U, F>): Result<U, E | F>;
|
|
27
|
+
mapErr<F>(fn: (error: E) => F): Result<T, F>;
|
|
28
|
+
match<U>(handlers: {
|
|
29
|
+
ok: (value: T) => U;
|
|
30
|
+
err: (error: E) => U;
|
|
31
|
+
}): U;
|
|
32
|
+
unwrap(): never;
|
|
33
|
+
unwrapOr(fallback: T): T;
|
|
34
|
+
}
|
|
35
|
+
export type Result<T, E = Error> = Ok<T, E> | Err<T, E>;
|
|
36
|
+
export declare const Result: {
|
|
37
|
+
readonly combine: <T, E>(results: readonly Result<T, E>[]) => Result<T[], E>;
|
|
38
|
+
readonly err: <E>(error: E) => Result<never, E>;
|
|
39
|
+
/**
|
|
40
|
+
* Wrap a fetch call in a Result, mapping failures to TrailsError subclasses.
|
|
41
|
+
*
|
|
42
|
+
* Network errors become NetworkError. Abort signals become CancelledError.
|
|
43
|
+
* HTTP error status codes map to the appropriate error category.
|
|
44
|
+
*/
|
|
45
|
+
readonly fromFetch: (input: string | URL | Request, init?: RequestInit) => Promise<Result<Response, Error>>;
|
|
46
|
+
/**
|
|
47
|
+
* Parse a JSON string, returning a Result instead of throwing.
|
|
48
|
+
*/
|
|
49
|
+
readonly fromJson: (json: string) => Result<unknown, ValidationError>;
|
|
50
|
+
readonly ok: <T = void>(value?: T) => Result<T, never>;
|
|
51
|
+
/**
|
|
52
|
+
* Stringify a value to JSON, returning a Result. Handles circular references.
|
|
53
|
+
*/
|
|
54
|
+
readonly toJson: (value: unknown) => Result<string, InternalError>;
|
|
55
|
+
};
|
|
56
|
+
export {};
|
|
57
|
+
//# sourceMappingURL=result.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"result.d.ts","sourceRoot":"","sources":["../src/result.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE7D,cAAM,EAAE,CAAC,CAAC,EAAE,CAAC;IACX,QAAQ,CAAC,K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