actly 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (130) hide show
  1. package/LICENSE +0 -0
  2. package/README.md +262 -232
  3. package/dist/core/act.cjs +505 -39
  4. package/dist/core/act.d.ts +81 -10
  5. package/dist/core/act.d.ts.map +1 -1
  6. package/dist/core/act.js +504 -40
  7. package/dist/core/act.js.map +1 -1
  8. package/dist/core/executor.cjs +21 -9
  9. package/dist/core/executor.d.ts +31 -6
  10. package/dist/core/executor.d.ts.map +1 -1
  11. package/dist/core/executor.js +21 -9
  12. package/dist/core/executor.js.map +1 -1
  13. package/dist/core/health.cjs +34 -0
  14. package/dist/core/health.d.ts +18 -0
  15. package/dist/core/health.d.ts.map +1 -0
  16. package/dist/core/health.js +28 -0
  17. package/dist/core/health.js.map +1 -0
  18. package/dist/core/shutdown.cjs +60 -0
  19. package/dist/core/shutdown.d.ts +8 -0
  20. package/dist/core/shutdown.d.ts.map +1 -0
  21. package/dist/core/shutdown.js +56 -0
  22. package/dist/core/shutdown.js.map +1 -0
  23. package/dist/core/tenant.cjs +71 -0
  24. package/dist/core/tenant.d.ts +29 -0
  25. package/dist/core/tenant.d.ts.map +1 -0
  26. package/dist/core/tenant.js +68 -0
  27. package/dist/core/tenant.js.map +1 -0
  28. package/dist/errors.cjs +182 -0
  29. package/dist/errors.d.ts +151 -0
  30. package/dist/errors.d.ts.map +1 -0
  31. package/dist/errors.js +171 -0
  32. package/dist/errors.js.map +1 -0
  33. package/dist/index.cjs +56 -6
  34. package/dist/index.d.ts +22 -3
  35. package/dist/index.d.ts.map +1 -1
  36. package/dist/index.js +24 -4
  37. package/dist/index.js.map +1 -1
  38. package/dist/observability.cjs +45 -0
  39. package/dist/observability.d.ts +145 -0
  40. package/dist/observability.d.ts.map +1 -0
  41. package/dist/observability.js +43 -0
  42. package/dist/observability.js.map +1 -0
  43. package/dist/policies/bulkhead.cjs +97 -0
  44. package/dist/policies/bulkhead.d.ts +3 -0
  45. package/dist/policies/bulkhead.d.ts.map +1 -0
  46. package/dist/policies/bulkhead.js +95 -0
  47. package/dist/policies/bulkhead.js.map +1 -0
  48. package/dist/policies/cache.cjs +223 -22
  49. package/dist/policies/cache.d.ts +42 -7
  50. package/dist/policies/cache.d.ts.map +1 -1
  51. package/dist/policies/cache.js +223 -22
  52. package/dist/policies/cache.js.map +1 -1
  53. package/dist/policies/circuitBreaker.cjs +85 -0
  54. package/dist/policies/circuitBreaker.d.ts +3 -0
  55. package/dist/policies/circuitBreaker.d.ts.map +1 -0
  56. package/dist/policies/circuitBreaker.js +83 -0
  57. package/dist/policies/circuitBreaker.js.map +1 -0
  58. package/dist/policies/dedupe.cjs +98 -21
  59. package/dist/policies/dedupe.d.ts +20 -13
  60. package/dist/policies/dedupe.d.ts.map +1 -1
  61. package/dist/policies/dedupe.js +98 -21
  62. package/dist/policies/dedupe.js.map +1 -1
  63. package/dist/policies/rateLimit.cjs +35 -0
  64. package/dist/policies/rateLimit.d.ts +3 -0
  65. package/dist/policies/rateLimit.d.ts.map +1 -0
  66. package/dist/policies/rateLimit.js +33 -0
  67. package/dist/policies/rateLimit.js.map +1 -0
  68. package/dist/policies/retry.cjs +103 -26
  69. package/dist/policies/retry.d.ts +25 -2
  70. package/dist/policies/retry.d.ts.map +1 -1
  71. package/dist/policies/retry.js +103 -26
  72. package/dist/policies/retry.js.map +1 -1
  73. package/dist/policies/timeout.cjs +78 -36
  74. package/dist/policies/timeout.d.ts +7 -18
  75. package/dist/policies/timeout.d.ts.map +1 -1
  76. package/dist/policies/timeout.js +84 -31
  77. package/dist/policies/timeout.js.map +1 -1
  78. package/dist/state/store.cjs +9 -2
  79. package/dist/state/store.d.ts +9 -0
  80. package/dist/state/store.d.ts.map +1 -1
  81. package/dist/state/store.js +9 -2
  82. package/dist/state/store.js.map +1 -1
  83. package/dist/stores/base.cjs +4 -4
  84. package/dist/stores/base.d.ts +32 -56
  85. package/dist/stores/base.d.ts.map +1 -1
  86. package/dist/stores/base.js +4 -4
  87. package/dist/stores/base.js.map +1 -1
  88. package/dist/stores/memory.cjs +161 -39
  89. package/dist/stores/memory.d.ts +64 -24
  90. package/dist/stores/memory.d.ts.map +1 -1
  91. package/dist/stores/memory.js +160 -39
  92. package/dist/stores/memory.js.map +1 -1
  93. package/dist/types/index.d.ts +315 -37
  94. package/dist/types/index.d.ts.map +1 -1
  95. package/dist/utils/abort.cjs +212 -0
  96. package/dist/utils/abort.d.ts +79 -0
  97. package/dist/utils/abort.d.ts.map +1 -0
  98. package/dist/utils/abort.js +206 -0
  99. package/dist/utils/abort.js.map +1 -0
  100. package/dist/utils/abortPool.cjs +26 -0
  101. package/dist/utils/abortPool.d.ts +4 -0
  102. package/dist/utils/abortPool.d.ts.map +1 -0
  103. package/dist/utils/abortPool.js +22 -0
  104. package/dist/utils/abortPool.js.map +1 -0
  105. package/dist/utils/backoff.cjs +54 -0
  106. package/dist/utils/backoff.d.ts +14 -0
  107. package/dist/utils/backoff.d.ts.map +1 -0
  108. package/dist/utils/backoff.js +52 -0
  109. package/dist/utils/backoff.js.map +1 -0
  110. package/dist/utils/key.cjs +77 -0
  111. package/dist/utils/key.d.ts +29 -0
  112. package/dist/utils/key.d.ts.map +1 -0
  113. package/dist/utils/key.js +75 -0
  114. package/dist/utils/key.js.map +1 -0
  115. package/dist/utils/limits.cjs +40 -0
  116. package/dist/utils/limits.d.ts +39 -0
  117. package/dist/utils/limits.d.ts.map +1 -0
  118. package/dist/utils/limits.js +38 -0
  119. package/dist/utils/limits.js.map +1 -0
  120. package/dist/utils/sanitize.cjs +29 -0
  121. package/dist/utils/sanitize.d.ts +3 -0
  122. package/dist/utils/sanitize.d.ts.map +1 -0
  123. package/dist/utils/sanitize.js +26 -0
  124. package/dist/utils/sanitize.js.map +1 -0
  125. package/dist/utils/validate.cjs +153 -0
  126. package/dist/utils/validate.d.ts +26 -0
  127. package/dist/utils/validate.d.ts.map +1 -0
  128. package/dist/utils/validate.js +141 -0
  129. package/dist/utils/validate.js.map +1 -0
  130. package/package.json +20 -37
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Key sanitisation — the first line of defence against:
3
+ *
4
+ * - **Prototype pollution**: `__proto__`, `constructor`, `prototype` as keys
5
+ * bypass namespace isolation in plain-object store adapters.
6
+ * - **Control-char injection**: `\x00`–`\x1f`, `\x7f` break some store
7
+ * backends (Redis Lua, HTTP header logs, JSON-LD contexts).
8
+ * - **CRLF injection**: `\r\n` in keys can break naive log/HTTP serializers.
9
+ * - **Memory exhaustion**: unbounded key length lets a caller store a 10MB
10
+ * string as a key, bloating the store and blocking iteration.
11
+ * - **Namespace collision**: user keys starting with `dedupe:`, `cache:`,
12
+ * or `__inflight:` would clobber internal slots.
13
+ *
14
+ * # Why a dedicated module?
15
+ *
16
+ * Key validation is security-sensitive. Centralising it here means every
17
+ * call site (`act()`, `invalidate()`, `withStore().invalidate()`) applies
18
+ * the same rules. Local inlining risks drift.
19
+ */
20
+ import { LIMITS } from './limits.js';
21
+ const RESERVED_PREFIXES = ['dedupe:', 'cache:', '__inflight:', '__tenant:', 'tenant:'];
22
+ /**
23
+ * Strings that, if used as Map keys, are safe — but if used as plain-object
24
+ * keys (e.g. a naive store adapter) enable prototype pollution. Reject them
25
+ * regardless of store type: the contract is "your key is safe everywhere".
26
+ */
27
+ const FORBIDDEN_LITERALS = new Set(['__proto__', 'constructor', 'prototype']);
28
+ /**
29
+ * Reject any character in the C0 control range, DEL (0x7f), or CRLF.
30
+ * Allow TAB (0x09) and LF (0x0a) since some callers embed newlines in
31
+ * structured keys legitimately — but CR is always forbidden.
32
+ */
33
+ const UNSAFE_CHAR = /[\x00-\x08\x0b\x0c\x0d\x0e-\x1f\x7f]/;
34
+ /**
35
+ * Validate a user-supplied key. Throws synchronously on invalid input.
36
+ *
37
+ * Programmer errors throw — they must not be swallowed into an `ActFailure`
38
+ * because the caller's code is broken.
39
+ *
40
+ * @returns the same `key` (for chaining); never transforms it.
41
+ */
42
+ export function sanitizeKey(key) {
43
+ if (typeof key !== 'string') {
44
+ throw new TypeError(`Actly: key must be a string, got ${typeName(key)}`);
45
+ }
46
+ if (key.length === 0) {
47
+ throw new RangeError("Actly: key must be non-empty. An empty key collapses every caller " +
48
+ "onto the same dedupe/cache slot — almost certainly a bug.");
49
+ }
50
+ if (key.length > LIMITS.MAX_KEY_LENGTH) {
51
+ throw new RangeError(`Actly: key length ${key.length} exceeds limit ${LIMITS.MAX_KEY_LENGTH}. ` +
52
+ `Long keys bloat stores and slow iteration. Hash externally if you need longer keys.`);
53
+ }
54
+ if (FORBIDDEN_LITERALS.has(key)) {
55
+ throw new RangeError(`Actly: key ${JSON.stringify(key)} is forbidden (prototype-pollution vector). ` +
56
+ `Pick a different key.`);
57
+ }
58
+ if (UNSAFE_CHAR.test(key)) {
59
+ throw new RangeError(`Actly: key contains control characters or CRLF, which break store backends ` +
60
+ `and log serializers. Got ${JSON.stringify(key)}.`);
61
+ }
62
+ for (const prefix of RESERVED_PREFIXES) {
63
+ if (key.startsWith(prefix)) {
64
+ throw new RangeError(`Actly: key must not start with reserved prefix "${prefix}" ` +
65
+ `(got ${JSON.stringify(key)}). These namespaces are used internally.`);
66
+ }
67
+ }
68
+ return key;
69
+ }
70
+ function typeName(v) {
71
+ if (v === null)
72
+ return 'null';
73
+ return typeof v;
74
+ }
75
+ //# sourceMappingURL=key.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"key.js","sourceRoot":"","sources":["../../src/utils/key.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEpC,MAAM,iBAAiB,GAAG,CAAC,SAAS,EAAE,QAAQ,EAAE,aAAa,EAAE,WAAW,EAAE,SAAS,CAAU,CAAA;AAE/F;;;;GAIG;AACH,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAC,CAAC,WAAW,EAAE,aAAa,EAAE,WAAW,CAAC,CAAC,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;AAED,SAAS,QAAQ,CAAC,CAAU;IAC1B,IAAI,CAAC,KAAK,IAAI;QAAE,OAAO,MAAM,CAAA;IAC7B,OAAO,OAAO,CAAC,CAAA;AACjB,CAAC"}
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ /**
3
+ * Centralised numeric limits for all actly inputs.
4
+ *
5
+ * # Why central?
6
+ *
7
+ * Every numeric input that flows into actly (retry.attempts, timeout.ms,
8
+ * cache.ttl, etc.) must be bounded to prevent:
9
+ * - memory exhaustion (e.g. `cache: { ttl: 1e15 }` → 31 700-year TTL)
10
+ * - CPU exhaustion (e.g. `retry: { attempts: 1e9 }`)
11
+ * - timer overflow (e.g. `setTimeout(fn, 1e16)` wraps to 1ms on some engines)
12
+ *
13
+ * The values are deliberately generous: they prevent pathological abuse,
14
+ * not legitimate use. If you need to exceed one of these limits, you almost
15
+ * certainly have a bug.
16
+ *
17
+ * These limits are constants — they are not runtime-configurable. If you
18
+ * need different limits, fork the source or wrap `act()` with your own
19
+ * validation layer.
20
+ */
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.LIMITS = void 0;
23
+ exports.LIMITS = Object.freeze({
24
+ /** Maximum key length in characters. Prevents multi-MB keys bloating stores. */
25
+ MAX_KEY_LENGTH: 1024,
26
+ /** Hard ceiling on `retry.attempts`. 100 attempts ≈ 100 fn invocations. */
27
+ MAX_RETRY_ATTEMPTS: 100,
28
+ /** Maximum per-attempt / total timeout in ms. ~27 hours. */
29
+ MAX_TIMEOUT_MS: 100_000_000,
30
+ /** Maximum cache TTL in ms. ~24 hours. */
31
+ MAX_CACHE_TTL: 86_400_000,
32
+ /** Maximum delay between retries in ms. ~5 minutes. */
33
+ MAX_RETRY_DELAY_MS: 300_000,
34
+ /** Maximum dedupe inflightTtl in ms. ~24 hours. */
35
+ MAX_INFLIGHT_TTL: 86_400_000,
36
+ /** Default bound for InMemoryStore when used as the module-level default. */
37
+ DEFAULT_STORE_MAX_SIZE: 10_000,
38
+ /** Background sweep interval for the default store. */
39
+ DEFAULT_STORE_CLEANUP_INTERVAL_MS: 60_000,
40
+ });
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Centralised numeric limits for all actly inputs.
3
+ *
4
+ * # Why central?
5
+ *
6
+ * Every numeric input that flows into actly (retry.attempts, timeout.ms,
7
+ * cache.ttl, etc.) must be bounded to prevent:
8
+ * - memory exhaustion (e.g. `cache: { ttl: 1e15 }` → 31 700-year TTL)
9
+ * - CPU exhaustion (e.g. `retry: { attempts: 1e9 }`)
10
+ * - timer overflow (e.g. `setTimeout(fn, 1e16)` wraps to 1ms on some engines)
11
+ *
12
+ * The values are deliberately generous: they prevent pathological abuse,
13
+ * not legitimate use. If you need to exceed one of these limits, you almost
14
+ * certainly have a bug.
15
+ *
16
+ * These limits are constants — they are not runtime-configurable. If you
17
+ * need different limits, fork the source or wrap `act()` with your own
18
+ * validation layer.
19
+ */
20
+ export declare const LIMITS: Readonly<{
21
+ /** Maximum key length in characters. Prevents multi-MB keys bloating stores. */
22
+ MAX_KEY_LENGTH: 1024;
23
+ /** Hard ceiling on `retry.attempts`. 100 attempts ≈ 100 fn invocations. */
24
+ MAX_RETRY_ATTEMPTS: 100;
25
+ /** Maximum per-attempt / total timeout in ms. ~27 hours. */
26
+ MAX_TIMEOUT_MS: 100000000;
27
+ /** Maximum cache TTL in ms. ~24 hours. */
28
+ MAX_CACHE_TTL: 86400000;
29
+ /** Maximum delay between retries in ms. ~5 minutes. */
30
+ MAX_RETRY_DELAY_MS: 300000;
31
+ /** Maximum dedupe inflightTtl in ms. ~24 hours. */
32
+ MAX_INFLIGHT_TTL: 86400000;
33
+ /** Default bound for InMemoryStore when used as the module-level default. */
34
+ DEFAULT_STORE_MAX_SIZE: 10000;
35
+ /** Background sweep interval for the default store. */
36
+ DEFAULT_STORE_CLEANUP_INTERVAL_MS: 60000;
37
+ }>;
38
+ export type Limits = typeof LIMITS;
39
+ //# sourceMappingURL=limits.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"limits.d.ts","sourceRoot":"","sources":["../../src/utils/limits.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,eAAO,MAAM,MAAM;IACjB,gFAAgF;;IAGhF,2EAA2E;;IAG3E,4DAA4D;;IAG5D,0CAA0C;;IAG1C,uDAAuD;;IAGvD,mDAAmD;;IAGnD,6EAA6E;;IAG7E,uDAAuD;;EAEvD,CAAA;AAEF,MAAM,MAAM,MAAM,GAAG,OAAO,MAAM,CAAA"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Centralised numeric limits for all actly inputs.
3
+ *
4
+ * # Why central?
5
+ *
6
+ * Every numeric input that flows into actly (retry.attempts, timeout.ms,
7
+ * cache.ttl, etc.) must be bounded to prevent:
8
+ * - memory exhaustion (e.g. `cache: { ttl: 1e15 }` → 31 700-year TTL)
9
+ * - CPU exhaustion (e.g. `retry: { attempts: 1e9 }`)
10
+ * - timer overflow (e.g. `setTimeout(fn, 1e16)` wraps to 1ms on some engines)
11
+ *
12
+ * The values are deliberately generous: they prevent pathological abuse,
13
+ * not legitimate use. If you need to exceed one of these limits, you almost
14
+ * certainly have a bug.
15
+ *
16
+ * These limits are constants — they are not runtime-configurable. If you
17
+ * need different limits, fork the source or wrap `act()` with your own
18
+ * validation layer.
19
+ */
20
+ export const LIMITS = Object.freeze({
21
+ /** Maximum key length in characters. Prevents multi-MB keys bloating stores. */
22
+ MAX_KEY_LENGTH: 1024,
23
+ /** Hard ceiling on `retry.attempts`. 100 attempts ≈ 100 fn invocations. */
24
+ MAX_RETRY_ATTEMPTS: 100,
25
+ /** Maximum per-attempt / total timeout in ms. ~27 hours. */
26
+ MAX_TIMEOUT_MS: 100_000_000,
27
+ /** Maximum cache TTL in ms. ~24 hours. */
28
+ MAX_CACHE_TTL: 86_400_000,
29
+ /** Maximum delay between retries in ms. ~5 minutes. */
30
+ MAX_RETRY_DELAY_MS: 300_000,
31
+ /** Maximum dedupe inflightTtl in ms. ~24 hours. */
32
+ MAX_INFLIGHT_TTL: 86_400_000,
33
+ /** Default bound for InMemoryStore when used as the module-level default. */
34
+ DEFAULT_STORE_MAX_SIZE: 10_000,
35
+ /** Background sweep interval for the default store. */
36
+ DEFAULT_STORE_CLEANUP_INTERVAL_MS: 60_000,
37
+ });
38
+ //# sourceMappingURL=limits.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"limits.js","sourceRoot":"","sources":["../../src/utils/limits.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,MAAM,CAAC,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;IAClC,gFAAgF;IAChF,cAAc,EAAE,IAAI;IAEpB,2EAA2E;IAC3E,kBAAkB,EAAE,GAAG;IAEvB,4DAA4D;IAC5D,cAAc,EAAE,WAAW;IAE3B,0CAA0C;IAC1C,aAAa,EAAE,UAAU;IAEzB,uDAAuD;IACvD,kBAAkB,EAAE,OAAO;IAE3B,mDAAmD;IACnD,gBAAgB,EAAE,UAAU;IAE5B,6EAA6E;IAC7E,sBAAsB,EAAE,MAAM;IAE9B,uDAAuD;IACvD,iCAAiC,EAAE,MAAM;CAC1C,CAAC,CAAA"}
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sanitizeErrorMessage = sanitizeErrorMessage;
4
+ exports.sanitizeError = sanitizeError;
5
+ const FORBIDDEN_CHARS = /[\x00-\x1f\x7f]/g;
6
+ const HTML_ENTITIES = { '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#x27;' };
7
+ function sanitizeErrorMessage(msg) {
8
+ let str;
9
+ if (msg instanceof Error) {
10
+ str = msg.message;
11
+ }
12
+ else if (typeof msg === 'string') {
13
+ str = msg;
14
+ }
15
+ else {
16
+ str = String(msg ?? '');
17
+ }
18
+ str = str.replace(/[&<>"']/g, (c) => HTML_ENTITIES[c]);
19
+ str = str.replace(FORBIDDEN_CHARS, '');
20
+ return str;
21
+ }
22
+ function sanitizeError(err) {
23
+ if (err instanceof Error) {
24
+ const sanitized = new Error(sanitizeErrorMessage(err.message));
25
+ sanitized.name = err.name;
26
+ return sanitized;
27
+ }
28
+ return sanitizeErrorMessage(err);
29
+ }
@@ -0,0 +1,3 @@
1
+ export declare function sanitizeErrorMessage(msg: unknown): string;
2
+ export declare function sanitizeError(err: unknown): unknown;
3
+ //# sourceMappingURL=sanitize.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sanitize.d.ts","sourceRoot":"","sources":["../../src/utils/sanitize.ts"],"names":[],"mappings":"AAGA,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,CAYzD;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAOnD"}
@@ -0,0 +1,26 @@
1
+ const FORBIDDEN_CHARS = /[\x00-\x1f\x7f]/g;
2
+ const HTML_ENTITIES = { '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#x27;' };
3
+ export function sanitizeErrorMessage(msg) {
4
+ let str;
5
+ if (msg instanceof Error) {
6
+ str = msg.message;
7
+ }
8
+ else if (typeof msg === 'string') {
9
+ str = msg;
10
+ }
11
+ else {
12
+ str = String(msg ?? '');
13
+ }
14
+ str = str.replace(/[&<>"']/g, (c) => HTML_ENTITIES[c]);
15
+ str = str.replace(FORBIDDEN_CHARS, '');
16
+ return str;
17
+ }
18
+ export function sanitizeError(err) {
19
+ if (err instanceof Error) {
20
+ const sanitized = new Error(sanitizeErrorMessage(err.message));
21
+ sanitized.name = err.name;
22
+ return sanitized;
23
+ }
24
+ return sanitizeErrorMessage(err);
25
+ }
26
+ //# sourceMappingURL=sanitize.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sanitize.js","sourceRoot":"","sources":["../../src/utils/sanitize.ts"],"names":[],"mappings":"AAAA,MAAM,eAAe,GAAG,kBAAkB,CAAA;AAC1C,MAAM,aAAa,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAA;AAE9F,MAAM,UAAU,oBAAoB,CAAC,GAAY;IAC/C,IAAI,GAAW,CAAA;IACf,IAAI,GAAG,YAAY,KAAK,EAAE,CAAC;QACzB,GAAG,GAAG,GAAG,CAAC,OAAO,CAAA;IACnB,CAAC;SAAM,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;QACnC,GAAG,GAAG,GAAG,CAAA;IACX,CAAC;SAAM,CAAC;QACN,GAAG,GAAG,MAAM,CAAC,GAAG,IAAI,EAAE,CAAC,CAAA;IACzB,CAAC;IACD,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,aAAa,CAAC,CAA+B,CAAC,CAAC,CAAA;IACpF,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,eAAe,EAAE,EAAE,CAAC,CAAA;IACtC,OAAO,GAAG,CAAA;AACZ,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,GAAY;IACxC,IAAI,GAAG,YAAY,KAAK,EAAE,CAAC;QACzB,MAAM,SAAS,GAAG,IAAI,KAAK,CAAC,oBAAoB,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAA;QAC9D,SAAS,CAAC,IAAI,GAAG,GAAG,CAAC,IAAI,CAAA;QACzB,OAAO,SAAS,CAAA;IAClB,CAAC;IACD,OAAO,oBAAoB,CAAC,GAAG,CAAC,CAAA;AAClC,CAAC"}
@@ -0,0 +1,153 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.assertKey = assertKey;
4
+ exports.assertRetryOptions = assertRetryOptions;
5
+ exports.assertTimeoutOptions = assertTimeoutOptions;
6
+ exports.assertCacheOptions = assertCacheOptions;
7
+ exports.assertDedupeOptions = assertDedupeOptions;
8
+ exports.assertOptions = assertOptions;
9
+ exports.assertAuditOptions = assertAuditOptions;
10
+ exports.assertCircuitBreakerOptions = assertCircuitBreakerOptions;
11
+ exports.assertBulkheadOptions = assertBulkheadOptions;
12
+ exports.assertRateLimitOptions = assertRateLimitOptions;
13
+ exports.assertHedgeOptions = assertHedgeOptions;
14
+ const limits_js_1 = require("./limits.js");
15
+ const key_js_1 = require("./key.js");
16
+ /**
17
+ * Validate user-facing option shapes. Throws `RangeError` / `TypeError` on
18
+ * invalid input — these are programmer errors, not runtime failures, so
19
+ * throwing (rather than returning an `ActFailure`) is the right call.
20
+ *
21
+ * Called once at the top of `act()` so policies can assume well-formed input.
22
+ *
23
+ * # Caps
24
+ *
25
+ * Every numeric input is bounded by {@link LIMITS}. This prevents memory
26
+ * exhaustion (huge TTLs), CPU exhaustion (huge retry counts), and timer
27
+ * overflow (huge delays). See `limits.ts` for rationale.
28
+ */
29
+ function assertKey(key) {
30
+ // Delegated to the dedicated sanitiser — keeps key rules in one place
31
+ // for security centralisation. See `key.ts` for the full rule set.
32
+ (0, key_js_1.sanitizeKey)(key);
33
+ }
34
+ function assertRetryOptions(opts) {
35
+ if (!Number.isInteger(opts.attempts) || opts.attempts < 1) {
36
+ throw new RangeError(`Actly: retry.attempts must be a positive integer, got ${opts.attempts}`);
37
+ }
38
+ if (opts.attempts > limits_js_1.LIMITS.MAX_RETRY_ATTEMPTS) {
39
+ throw new RangeError(`Actly: retry.attempts ${opts.attempts} exceeds limit ${limits_js_1.LIMITS.MAX_RETRY_ATTEMPTS}. ` +
40
+ `If you genuinely need more, use an outer supervisor.`);
41
+ }
42
+ if (opts.delayMs !== undefined) {
43
+ assertNonNegativeFinite('retry.delayMs', opts.delayMs, limits_js_1.LIMITS.MAX_RETRY_DELAY_MS);
44
+ }
45
+ if (opts.maxDelay !== undefined) {
46
+ assertNonNegativeFinite('retry.maxDelay', opts.maxDelay, limits_js_1.LIMITS.MAX_RETRY_DELAY_MS);
47
+ }
48
+ if (opts.backoff !== undefined && !BACKOFF_MODES.has(opts.backoff)) {
49
+ throw new RangeError(`Actly: retry.backoff must be one of ${[...BACKOFF_MODES].map((m) => JSON.stringify(m)).join(' | ')}, ` +
50
+ `got ${JSON.stringify(opts.backoff)}`);
51
+ }
52
+ if (opts.jitter !== undefined && !JITTER_MODES.has(opts.jitter)) {
53
+ throw new RangeError(`Actly: retry.jitter must be one of ${[...JITTER_MODES].map((m) => JSON.stringify(m)).join(' | ')}, ` +
54
+ `got ${JSON.stringify(opts.jitter)}`);
55
+ }
56
+ if (opts.shouldRetry !== undefined && typeof opts.shouldRetry !== 'function') {
57
+ throw new TypeError(`Actly: retry.shouldRetry must be a function, got ${typeof opts.shouldRetry}`);
58
+ }
59
+ }
60
+ function assertTimeoutOptions(opts, field) {
61
+ if (typeof opts.ms !== 'number' || !Number.isFinite(opts.ms) || opts.ms <= 0) {
62
+ throw new RangeError(`Actly: ${field}.ms must be a positive finite number, got ${opts.ms}`);
63
+ }
64
+ if (opts.ms > limits_js_1.LIMITS.MAX_TIMEOUT_MS) {
65
+ throw new RangeError(`Actly: ${field}.ms ${opts.ms} exceeds limit ${limits_js_1.LIMITS.MAX_TIMEOUT_MS}.`);
66
+ }
67
+ }
68
+ function assertCacheOptions(opts) {
69
+ if (typeof opts.ttl !== 'number' || !Number.isFinite(opts.ttl) || opts.ttl <= 0) {
70
+ throw new RangeError(`Actly: cache.ttl must be a positive finite number, got ${opts.ttl}`);
71
+ }
72
+ if (opts.ttl > limits_js_1.LIMITS.MAX_CACHE_TTL) {
73
+ throw new RangeError(`Actly: cache.ttl ${opts.ttl} exceeds limit ${limits_js_1.LIMITS.MAX_CACHE_TTL} (~24h).`);
74
+ }
75
+ }
76
+ function assertDedupeOptions(opts) {
77
+ if (opts.inflightTtl !== undefined) {
78
+ assertNonNegativeFinite('dedupe.inflightTtl', opts.inflightTtl, limits_js_1.LIMITS.MAX_INFLIGHT_TTL);
79
+ }
80
+ }
81
+ function assertOptions(options) {
82
+ if (options.retry)
83
+ assertRetryOptions(options.retry);
84
+ if (options.timeout)
85
+ assertTimeoutOptions(options.timeout, 'timeout');
86
+ if (options.totalTimeout)
87
+ assertTimeoutOptions(options.totalTimeout, 'totalTimeout');
88
+ if (options.cache)
89
+ assertCacheOptions(options.cache);
90
+ if (options.dedupe && typeof options.dedupe !== 'boolean') {
91
+ assertDedupeOptions(options.dedupe);
92
+ }
93
+ if (options.signal !== undefined && !(options.signal instanceof AbortSignal)) {
94
+ throw new TypeError(`Actly: signal must be an AbortSignal, got ${options.signal === null ? 'null' : typeof options.signal}`);
95
+ }
96
+ if (options.circuitBreaker)
97
+ assertCircuitBreakerOptions(options.circuitBreaker);
98
+ if (options.bulkhead)
99
+ assertBulkheadOptions(options.bulkhead);
100
+ if (options.rateLimit)
101
+ assertRateLimitOptions(options.rateLimit);
102
+ if (options.hedge)
103
+ assertHedgeOptions(options.hedge);
104
+ if (options.audit)
105
+ assertAuditOptions(options.audit);
106
+ }
107
+ function assertAuditOptions(opts) {
108
+ if (typeof opts.log !== 'function') {
109
+ throw new TypeError(`Actly: audit.log must be a function, got ${opts.log === null ? 'null' : typeof opts.log}`);
110
+ }
111
+ }
112
+ function assertCircuitBreakerOptions(opts) {
113
+ if (!Number.isInteger(opts.threshold) || opts.threshold < 1) {
114
+ throw new RangeError(`Actly: circuitBreaker.threshold must be a positive integer, got ${opts.threshold}`);
115
+ }
116
+ if (typeof opts.cooldownMs !== 'number' || !Number.isFinite(opts.cooldownMs) || opts.cooldownMs <= 0) {
117
+ throw new RangeError(`Actly: circuitBreaker.cooldownMs must be a positive finite number, got ${opts.cooldownMs}`);
118
+ }
119
+ if (opts.resetTimeoutMs !== undefined) {
120
+ assertNonNegativeFinite('circuitBreaker.resetTimeoutMs', opts.resetTimeoutMs, Number.POSITIVE_INFINITY);
121
+ }
122
+ }
123
+ function assertBulkheadOptions(opts) {
124
+ if (!Number.isInteger(opts.maxConcurrent) || opts.maxConcurrent < 1) {
125
+ throw new RangeError(`Actly: bulkhead.maxConcurrent must be a positive integer, got ${opts.maxConcurrent}`);
126
+ }
127
+ if (opts.queueTimeoutMs !== undefined) {
128
+ assertNonNegativeFinite('bulkhead.queueTimeoutMs', opts.queueTimeoutMs, Number.POSITIVE_INFINITY);
129
+ }
130
+ }
131
+ function assertRateLimitOptions(opts) {
132
+ if (!Number.isInteger(opts.maxCalls) || opts.maxCalls < 1) {
133
+ throw new RangeError(`Actly: rateLimit.maxCalls must be a positive integer, got ${opts.maxCalls}`);
134
+ }
135
+ if (typeof opts.windowMs !== 'number' || !Number.isFinite(opts.windowMs) || opts.windowMs <= 0) {
136
+ throw new RangeError(`Actly: rateLimit.windowMs must be a positive finite number, got ${opts.windowMs}`);
137
+ }
138
+ }
139
+ function assertHedgeOptions(opts) {
140
+ if (typeof opts.delayMs !== 'number' || !Number.isFinite(opts.delayMs) || opts.delayMs <= 0) {
141
+ throw new RangeError(`Actly: hedge.delayMs must be a positive finite number, got ${opts.delayMs}`);
142
+ }
143
+ }
144
+ function assertNonNegativeFinite(field, value, max) {
145
+ if (typeof value !== 'number' || !Number.isFinite(value) || value < 0) {
146
+ throw new RangeError(`Actly: ${field} must be a non-negative finite number, got ${value}`);
147
+ }
148
+ if (value > max) {
149
+ throw new RangeError(`Actly: ${field} ${value} exceeds limit ${max}.`);
150
+ }
151
+ }
152
+ const BACKOFF_MODES = new Set(['none', 'linear', 'exponential']);
153
+ const JITTER_MODES = new Set(['none', 'full', 'equal', 'decorrelated']);
@@ -0,0 +1,26 @@
1
+ import type { ActOptions, CacheOptions, DedupeOptions, RetryOptions, TimeoutOptions } from '../types/index.js';
2
+ /**
3
+ * Validate user-facing option shapes. Throws `RangeError` / `TypeError` on
4
+ * invalid input — these are programmer errors, not runtime failures, so
5
+ * throwing (rather than returning an `ActFailure`) is the right call.
6
+ *
7
+ * Called once at the top of `act()` so policies can assume well-formed input.
8
+ *
9
+ * # Caps
10
+ *
11
+ * Every numeric input is bounded by {@link LIMITS}. This prevents memory
12
+ * exhaustion (huge TTLs), CPU exhaustion (huge retry counts), and timer
13
+ * overflow (huge delays). See `limits.ts` for rationale.
14
+ */
15
+ export declare function assertKey(key: string): void;
16
+ export declare function assertRetryOptions(opts: RetryOptions): void;
17
+ export declare function assertTimeoutOptions(opts: TimeoutOptions, field: string): void;
18
+ export declare function assertCacheOptions(opts: CacheOptions): void;
19
+ export declare function assertDedupeOptions(opts: DedupeOptions): void;
20
+ export declare function assertOptions(options: ActOptions): void;
21
+ export declare function assertAuditOptions(opts: import('../types/index.js').AuditOptions): void;
22
+ export declare function assertCircuitBreakerOptions(opts: import('../types/index.js').CircuitBreakerOptions): void;
23
+ export declare function assertBulkheadOptions(opts: import('../types/index.js').BulkheadOptions): void;
24
+ export declare function assertRateLimitOptions(opts: import('../types/index.js').RateLimitOptions): void;
25
+ export declare function assertHedgeOptions(opts: import('../types/index.js').HedgeOptions): void;
26
+ //# sourceMappingURL=validate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../src/utils/validate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EACV,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,cAAc,EACf,MAAM,mBAAmB,CAAA;AAI1B;;;;;;;;;;;;GAYG;AAEH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAI3C;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI,CAmC3D;AAED,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAW9E;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI,CAW3D;AAED,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,aAAa,GAAG,IAAI,CAI7D;AAED,wBAAgB,aAAa,CAAC,OAAO,EAAE,UAAU,GAAG,IAAI,CAkBvD;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,OAAO,mBAAmB,EAAE,YAAY,GAAG,IAAI,CAMvF;AAED,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,OAAO,mBAAmB,EAAE,qBAAqB,GAAG,IAAI,CAczG;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,OAAO,mBAAmB,EAAE,eAAe,GAAG,IAAI,CAS7F;AAED,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,OAAO,mBAAmB,EAAE,gBAAgB,GAAG,IAAI,CAW/F;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,OAAO,mBAAmB,EAAE,YAAY,GAAG,IAAI,CAMvF"}
@@ -0,0 +1,141 @@
1
+ import { LIMITS } from './limits.js';
2
+ import { sanitizeKey } from './key.js';
3
+ /**
4
+ * Validate user-facing option shapes. Throws `RangeError` / `TypeError` on
5
+ * invalid input — these are programmer errors, not runtime failures, so
6
+ * throwing (rather than returning an `ActFailure`) is the right call.
7
+ *
8
+ * Called once at the top of `act()` so policies can assume well-formed input.
9
+ *
10
+ * # Caps
11
+ *
12
+ * Every numeric input is bounded by {@link LIMITS}. This prevents memory
13
+ * exhaustion (huge TTLs), CPU exhaustion (huge retry counts), and timer
14
+ * overflow (huge delays). See `limits.ts` for rationale.
15
+ */
16
+ export function assertKey(key) {
17
+ // Delegated to the dedicated sanitiser — keeps key rules in one place
18
+ // for security centralisation. See `key.ts` for the full rule set.
19
+ sanitizeKey(key);
20
+ }
21
+ export function assertRetryOptions(opts) {
22
+ if (!Number.isInteger(opts.attempts) || opts.attempts < 1) {
23
+ throw new RangeError(`Actly: retry.attempts must be a positive integer, got ${opts.attempts}`);
24
+ }
25
+ if (opts.attempts > LIMITS.MAX_RETRY_ATTEMPTS) {
26
+ throw new RangeError(`Actly: retry.attempts ${opts.attempts} exceeds limit ${LIMITS.MAX_RETRY_ATTEMPTS}. ` +
27
+ `If you genuinely need more, use an outer supervisor.`);
28
+ }
29
+ if (opts.delayMs !== undefined) {
30
+ assertNonNegativeFinite('retry.delayMs', opts.delayMs, LIMITS.MAX_RETRY_DELAY_MS);
31
+ }
32
+ if (opts.maxDelay !== undefined) {
33
+ assertNonNegativeFinite('retry.maxDelay', opts.maxDelay, LIMITS.MAX_RETRY_DELAY_MS);
34
+ }
35
+ if (opts.backoff !== undefined && !BACKOFF_MODES.has(opts.backoff)) {
36
+ throw new RangeError(`Actly: retry.backoff must be one of ${[...BACKOFF_MODES].map((m) => JSON.stringify(m)).join(' | ')}, ` +
37
+ `got ${JSON.stringify(opts.backoff)}`);
38
+ }
39
+ if (opts.jitter !== undefined && !JITTER_MODES.has(opts.jitter)) {
40
+ throw new RangeError(`Actly: retry.jitter must be one of ${[...JITTER_MODES].map((m) => JSON.stringify(m)).join(' | ')}, ` +
41
+ `got ${JSON.stringify(opts.jitter)}`);
42
+ }
43
+ if (opts.shouldRetry !== undefined && typeof opts.shouldRetry !== 'function') {
44
+ throw new TypeError(`Actly: retry.shouldRetry must be a function, got ${typeof opts.shouldRetry}`);
45
+ }
46
+ }
47
+ export function assertTimeoutOptions(opts, field) {
48
+ if (typeof opts.ms !== 'number' || !Number.isFinite(opts.ms) || opts.ms <= 0) {
49
+ throw new RangeError(`Actly: ${field}.ms must be a positive finite number, got ${opts.ms}`);
50
+ }
51
+ if (opts.ms > LIMITS.MAX_TIMEOUT_MS) {
52
+ throw new RangeError(`Actly: ${field}.ms ${opts.ms} exceeds limit ${LIMITS.MAX_TIMEOUT_MS}.`);
53
+ }
54
+ }
55
+ export function assertCacheOptions(opts) {
56
+ if (typeof opts.ttl !== 'number' || !Number.isFinite(opts.ttl) || opts.ttl <= 0) {
57
+ throw new RangeError(`Actly: cache.ttl must be a positive finite number, got ${opts.ttl}`);
58
+ }
59
+ if (opts.ttl > LIMITS.MAX_CACHE_TTL) {
60
+ throw new RangeError(`Actly: cache.ttl ${opts.ttl} exceeds limit ${LIMITS.MAX_CACHE_TTL} (~24h).`);
61
+ }
62
+ }
63
+ export function assertDedupeOptions(opts) {
64
+ if (opts.inflightTtl !== undefined) {
65
+ assertNonNegativeFinite('dedupe.inflightTtl', opts.inflightTtl, LIMITS.MAX_INFLIGHT_TTL);
66
+ }
67
+ }
68
+ export function assertOptions(options) {
69
+ if (options.retry)
70
+ assertRetryOptions(options.retry);
71
+ if (options.timeout)
72
+ assertTimeoutOptions(options.timeout, 'timeout');
73
+ if (options.totalTimeout)
74
+ assertTimeoutOptions(options.totalTimeout, 'totalTimeout');
75
+ if (options.cache)
76
+ assertCacheOptions(options.cache);
77
+ if (options.dedupe && typeof options.dedupe !== 'boolean') {
78
+ assertDedupeOptions(options.dedupe);
79
+ }
80
+ if (options.signal !== undefined && !(options.signal instanceof AbortSignal)) {
81
+ throw new TypeError(`Actly: signal must be an AbortSignal, got ${options.signal === null ? 'null' : typeof options.signal}`);
82
+ }
83
+ if (options.circuitBreaker)
84
+ assertCircuitBreakerOptions(options.circuitBreaker);
85
+ if (options.bulkhead)
86
+ assertBulkheadOptions(options.bulkhead);
87
+ if (options.rateLimit)
88
+ assertRateLimitOptions(options.rateLimit);
89
+ if (options.hedge)
90
+ assertHedgeOptions(options.hedge);
91
+ if (options.audit)
92
+ assertAuditOptions(options.audit);
93
+ }
94
+ export function assertAuditOptions(opts) {
95
+ if (typeof opts.log !== 'function') {
96
+ throw new TypeError(`Actly: audit.log must be a function, got ${opts.log === null ? 'null' : typeof opts.log}`);
97
+ }
98
+ }
99
+ export function assertCircuitBreakerOptions(opts) {
100
+ if (!Number.isInteger(opts.threshold) || opts.threshold < 1) {
101
+ throw new RangeError(`Actly: circuitBreaker.threshold must be a positive integer, got ${opts.threshold}`);
102
+ }
103
+ if (typeof opts.cooldownMs !== 'number' || !Number.isFinite(opts.cooldownMs) || opts.cooldownMs <= 0) {
104
+ throw new RangeError(`Actly: circuitBreaker.cooldownMs must be a positive finite number, got ${opts.cooldownMs}`);
105
+ }
106
+ if (opts.resetTimeoutMs !== undefined) {
107
+ assertNonNegativeFinite('circuitBreaker.resetTimeoutMs', opts.resetTimeoutMs, Number.POSITIVE_INFINITY);
108
+ }
109
+ }
110
+ export function assertBulkheadOptions(opts) {
111
+ if (!Number.isInteger(opts.maxConcurrent) || opts.maxConcurrent < 1) {
112
+ throw new RangeError(`Actly: bulkhead.maxConcurrent must be a positive integer, got ${opts.maxConcurrent}`);
113
+ }
114
+ if (opts.queueTimeoutMs !== undefined) {
115
+ assertNonNegativeFinite('bulkhead.queueTimeoutMs', opts.queueTimeoutMs, Number.POSITIVE_INFINITY);
116
+ }
117
+ }
118
+ export function assertRateLimitOptions(opts) {
119
+ if (!Number.isInteger(opts.maxCalls) || opts.maxCalls < 1) {
120
+ throw new RangeError(`Actly: rateLimit.maxCalls must be a positive integer, got ${opts.maxCalls}`);
121
+ }
122
+ if (typeof opts.windowMs !== 'number' || !Number.isFinite(opts.windowMs) || opts.windowMs <= 0) {
123
+ throw new RangeError(`Actly: rateLimit.windowMs must be a positive finite number, got ${opts.windowMs}`);
124
+ }
125
+ }
126
+ export function assertHedgeOptions(opts) {
127
+ if (typeof opts.delayMs !== 'number' || !Number.isFinite(opts.delayMs) || opts.delayMs <= 0) {
128
+ throw new RangeError(`Actly: hedge.delayMs must be a positive finite number, got ${opts.delayMs}`);
129
+ }
130
+ }
131
+ function assertNonNegativeFinite(field, value, max) {
132
+ if (typeof value !== 'number' || !Number.isFinite(value) || value < 0) {
133
+ throw new RangeError(`Actly: ${field} must be a non-negative finite number, got ${value}`);
134
+ }
135
+ if (value > max) {
136
+ throw new RangeError(`Actly: ${field} ${value} exceeds limit ${max}.`);
137
+ }
138
+ }
139
+ const BACKOFF_MODES = new Set(['none', 'linear', 'exponential']);
140
+ const JITTER_MODES = new Set(['none', 'full', 'equal', 'decorrelated']);
141
+ //# sourceMappingURL=validate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate.js","sourceRoot":"","sources":["../../src/utils/validate.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,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