@contentful/optimization-core 0.1.0-alpha8 → 0.1.0-alpha9

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 (147) hide show
  1. package/README.md +221 -31
  2. package/dist/260.mjs +14 -0
  3. package/dist/260.mjs.map +1 -0
  4. package/dist/499.mjs +4 -0
  5. package/dist/632.mjs +5 -0
  6. package/dist/632.mjs.map +1 -0
  7. package/dist/808.mjs +2 -0
  8. package/dist/942.mjs +2 -0
  9. package/dist/api-client.cjs +60 -0
  10. package/dist/api-client.cjs.map +1 -0
  11. package/dist/api-client.d.cts +4 -0
  12. package/dist/api-client.d.mts +4 -0
  13. package/dist/api-client.d.ts +4 -0
  14. package/dist/api-client.mjs +2 -0
  15. package/dist/api-schemas.cjs +60 -0
  16. package/dist/api-schemas.cjs.map +1 -0
  17. package/dist/api-schemas.d.cts +4 -0
  18. package/dist/api-schemas.d.mts +4 -0
  19. package/dist/api-schemas.d.ts +4 -0
  20. package/dist/api-schemas.mjs +2 -0
  21. package/dist/constants.cjs +78 -0
  22. package/dist/constants.cjs.map +1 -0
  23. package/dist/{global-constants.d.ts → constants.d.cts} +88 -67
  24. package/dist/{global-constants.js → constants.d.mts} +88 -69
  25. package/dist/constants.d.ts +88 -0
  26. package/dist/constants.mjs +1 -0
  27. package/dist/index.cjs +1833 -1706
  28. package/dist/index.cjs.map +1 -1
  29. package/dist/index.d.cts +774 -341
  30. package/dist/index.d.mts +774 -341
  31. package/dist/index.d.ts +2432 -15
  32. package/dist/index.mjs +617 -341
  33. package/dist/index.mjs.map +1 -1
  34. package/dist/logger.cjs +67 -0
  35. package/dist/logger.cjs.map +1 -0
  36. package/dist/logger.d.cts +8 -0
  37. package/dist/logger.d.mts +8 -0
  38. package/dist/logger.d.ts +8 -0
  39. package/dist/logger.mjs +2 -0
  40. package/dist/symbols.cjs +42 -0
  41. package/dist/symbols.cjs.map +1 -0
  42. package/dist/symbols.d.cts +10 -0
  43. package/dist/symbols.d.mts +10 -0
  44. package/dist/symbols.d.ts +10 -0
  45. package/dist/symbols.mjs +1 -0
  46. package/package.json +56 -8
  47. package/dist/Consent.d.ts +0 -44
  48. package/dist/Consent.d.ts.map +0 -1
  49. package/dist/Consent.js +0 -2
  50. package/dist/Consent.js.map +0 -1
  51. package/dist/CoreBase.d.ts +0 -161
  52. package/dist/CoreBase.d.ts.map +0 -1
  53. package/dist/CoreBase.js +0 -151
  54. package/dist/CoreBase.js.map +0 -1
  55. package/dist/CoreStateful.d.ts +0 -144
  56. package/dist/CoreStateful.d.ts.map +0 -1
  57. package/dist/CoreStateful.js +0 -141
  58. package/dist/CoreStateful.js.map +0 -1
  59. package/dist/CoreStateless.d.ts +0 -53
  60. package/dist/CoreStateless.d.ts.map +0 -1
  61. package/dist/CoreStateless.js +0 -43
  62. package/dist/CoreStateless.js.map +0 -1
  63. package/dist/ProductBase.d.ts +0 -83
  64. package/dist/ProductBase.d.ts.map +0 -1
  65. package/dist/ProductBase.js +0 -50
  66. package/dist/ProductBase.js.map +0 -1
  67. package/dist/analytics/AnalyticsBase.d.ts +0 -35
  68. package/dist/analytics/AnalyticsBase.d.ts.map +0 -1
  69. package/dist/analytics/AnalyticsBase.js +0 -13
  70. package/dist/analytics/AnalyticsBase.js.map +0 -1
  71. package/dist/analytics/AnalyticsStateful.d.ts +0 -138
  72. package/dist/analytics/AnalyticsStateful.d.ts.map +0 -1
  73. package/dist/analytics/AnalyticsStateful.js +0 -179
  74. package/dist/analytics/AnalyticsStateful.js.map +0 -1
  75. package/dist/analytics/AnalyticsStateless.d.ts +0 -48
  76. package/dist/analytics/AnalyticsStateless.d.ts.map +0 -1
  77. package/dist/analytics/AnalyticsStateless.js +0 -61
  78. package/dist/analytics/AnalyticsStateless.js.map +0 -1
  79. package/dist/analytics/index.d.ts +0 -5
  80. package/dist/analytics/index.d.ts.map +0 -1
  81. package/dist/analytics/index.js +0 -5
  82. package/dist/analytics/index.js.map +0 -1
  83. package/dist/global-constants.d.ts.map +0 -1
  84. package/dist/global-constants.js.map +0 -1
  85. package/dist/index.d.ts.map +0 -1
  86. package/dist/index.js +0 -15
  87. package/dist/index.js.map +0 -1
  88. package/dist/lib/decorators/guardedBy.d.ts +0 -113
  89. package/dist/lib/decorators/guardedBy.d.ts.map +0 -1
  90. package/dist/lib/decorators/guardedBy.js +0 -143
  91. package/dist/lib/decorators/guardedBy.js.map +0 -1
  92. package/dist/lib/decorators/index.d.ts +0 -2
  93. package/dist/lib/decorators/index.d.ts.map +0 -1
  94. package/dist/lib/decorators/index.js +0 -2
  95. package/dist/lib/decorators/index.js.map +0 -1
  96. package/dist/lib/interceptor/InterceptorManager.d.ts +0 -127
  97. package/dist/lib/interceptor/InterceptorManager.d.ts.map +0 -1
  98. package/dist/lib/interceptor/InterceptorManager.js +0 -125
  99. package/dist/lib/interceptor/InterceptorManager.js.map +0 -1
  100. package/dist/lib/interceptor/index.d.ts +0 -2
  101. package/dist/lib/interceptor/index.d.ts.map +0 -1
  102. package/dist/lib/interceptor/index.js +0 -2
  103. package/dist/lib/interceptor/index.js.map +0 -1
  104. package/dist/lib/value-presence/ValuePresence.d.ts +0 -123
  105. package/dist/lib/value-presence/ValuePresence.d.ts.map +0 -1
  106. package/dist/lib/value-presence/ValuePresence.js +0 -141
  107. package/dist/lib/value-presence/ValuePresence.js.map +0 -1
  108. package/dist/lib/value-presence/index.d.ts +0 -2
  109. package/dist/lib/value-presence/index.d.ts.map +0 -1
  110. package/dist/lib/value-presence/index.js +0 -2
  111. package/dist/lib/value-presence/index.js.map +0 -1
  112. package/dist/personalization/PersonalizationBase.d.ts +0 -184
  113. package/dist/personalization/PersonalizationBase.d.ts.map +0 -1
  114. package/dist/personalization/PersonalizationBase.js +0 -76
  115. package/dist/personalization/PersonalizationBase.js.map +0 -1
  116. package/dist/personalization/PersonalizationStateful.d.ts +0 -226
  117. package/dist/personalization/PersonalizationStateful.d.ts.map +0 -1
  118. package/dist/personalization/PersonalizationStateful.js +0 -297
  119. package/dist/personalization/PersonalizationStateful.js.map +0 -1
  120. package/dist/personalization/PersonalizationStateless.d.ts +0 -74
  121. package/dist/personalization/PersonalizationStateless.d.ts.map +0 -1
  122. package/dist/personalization/PersonalizationStateless.js +0 -98
  123. package/dist/personalization/PersonalizationStateless.js.map +0 -1
  124. package/dist/personalization/index.d.ts +0 -6
  125. package/dist/personalization/index.d.ts.map +0 -1
  126. package/dist/personalization/index.js +0 -6
  127. package/dist/personalization/index.js.map +0 -1
  128. package/dist/personalization/resolvers/FlagsResolver.d.ts +0 -35
  129. package/dist/personalization/resolvers/FlagsResolver.d.ts.map +0 -1
  130. package/dist/personalization/resolvers/FlagsResolver.js +0 -47
  131. package/dist/personalization/resolvers/FlagsResolver.js.map +0 -1
  132. package/dist/personalization/resolvers/MergeTagValueResolver.d.ts +0 -74
  133. package/dist/personalization/resolvers/MergeTagValueResolver.d.ts.map +0 -1
  134. package/dist/personalization/resolvers/MergeTagValueResolver.js +0 -109
  135. package/dist/personalization/resolvers/MergeTagValueResolver.js.map +0 -1
  136. package/dist/personalization/resolvers/PersonalizedEntryResolver.d.ts +0 -142
  137. package/dist/personalization/resolvers/PersonalizedEntryResolver.d.ts.map +0 -1
  138. package/dist/personalization/resolvers/PersonalizedEntryResolver.js +0 -196
  139. package/dist/personalization/resolvers/PersonalizedEntryResolver.js.map +0 -1
  140. package/dist/personalization/resolvers/index.d.ts +0 -7
  141. package/dist/personalization/resolvers/index.d.ts.map +0 -1
  142. package/dist/personalization/resolvers/index.js +0 -7
  143. package/dist/personalization/resolvers/index.js.map +0 -1
  144. package/dist/signals.d.ts +0 -42
  145. package/dist/signals.d.ts.map +0 -1
  146. package/dist/signals.js +0 -36
  147. package/dist/signals.js.map +0 -1
@@ -1,143 +0,0 @@
1
- /**
2
- * Type guard for functions.
3
- *
4
- * @internal
5
- */
6
- const isFunction = (v) => typeof v === 'function';
7
- /**
8
- * Converts a property key to a readable string for logs and messages.
9
- *
10
- * @param name - The property key to stringify.
11
- * @returns A human-friendly name.
12
- *
13
- * @internal
14
- */
15
- const nameToString = (name) => typeof name === 'string'
16
- ? name
17
- : typeof name === 'symbol'
18
- ? (name.description ?? String(name))
19
- : String(name);
20
- /**
21
- * True when the `onBlocked` option is a property key (string or symbol).
22
- *
23
- * @typeParam T - The instance type.
24
- * @param v - The `onBlocked` option value.
25
- * @returns Whether `v` is a property key.
26
- *
27
- * @internal
28
- */
29
- const isOnBlockedKey = (v) => typeof v === 'string' || typeof v === 'symbol';
30
- /**
31
- * Detects declared `async` functions.
32
- *
33
- * @param fn - The candidate to test.
34
- * @returns `true` if `fn` is an async function, else `false`.
35
- *
36
- * @internal
37
- */
38
- const isAsyncFunction = (fn) => Object.prototype.toString.call(fn) === '[object AsyncFunction]';
39
- /**
40
- * Decorator factory that **guards** class methods behind a synchronous predicate.
41
- *
42
- * When a decorated method is invoked:
43
- * - If the predicate returns a value that evaluates to **allowed** (see `invert`), the original
44
- * method is executed and its result is returned.
45
- * - If the call is **blocked**, the optional `onBlocked` hook is invoked (if configured) and:
46
- * - `undefined` is returned for sync methods; or
47
- * - `Promise<undefined>` is returned for async methods (to preserve `await` compatibility).
48
- *
49
- * @typeParam T - The instance type that owns both the predicate and the decorated method.
50
- *
51
- * @param predicateName - The name (string or symbol) of a **synchronous** instance method on `this`
52
- * that acts as the predicate. It is called as `this[predicateName](methodName, argsArray)`.
53
- * @param opts - Optional {@link GuardedByOptions | options} to configure inversion and `onBlocked`.
54
- *
55
- * @returns A methods-only class decorator compatible with Stage-3 decorators that wraps the method.
56
- *
57
- * @throws TypeError
58
- * Thrown at initialization time (first instance construction) if `predicateName` does not resolve
59
- * to a **synchronous function** on the instance.
60
- *
61
- * @remarks
62
- * - This is a **methods-only** decorator; applying it to accessors/fields is a no-op.
63
- * - The decorator preserves the original method's sync/async shape.
64
- * - The predicate is invoked with `(decoratedMethodName, argsArray)` to support context-aware checks.
65
- *
66
- * @example
67
- * Here, `canRun` allows the call when it returns truthy:
68
- * ```ts
69
- * class Runner {
70
- * canRun(method: string, _args: readonly unknown[]) { return method !== 'stop'; }
71
- *
72
- * @guardedBy<Runner>('canRun')
73
- * go() { console.log('running'); }
74
- * }
75
- * ```
76
- *
77
- * @example
78
- * Invert the predicate and call a handler on block:
79
- * ```ts
80
- * class Door {
81
- * isLocked() { return true } // truthy means "locked"
82
- * onBlocked(method: string) { console.warn(`${method} blocked`) }
83
- *
84
- * @guardedBy<Door>('isLocked', { invert: true, onBlocked: 'onBlocked' })
85
- * open() { /* ... *\/ }
86
- * }
87
- * ```
88
- *
89
- * @public
90
- */
91
- export function guardedBy(predicateName, opts) {
92
- return function (_value, context) {
93
- const decoratedName = nameToString(context.name);
94
- context.addInitializer(function init() {
95
- // Original method on the instance
96
- const originalUnknown = Reflect.get(this, context.name);
97
- if (!isFunction(originalUnknown)) {
98
- return; // defensive: nothing to wrap
99
- }
100
- const original = originalUnknown;
101
- const originalIsAsync = isAsyncFunction(original);
102
- const resolvePredicate = (self) => {
103
- const { [predicateName]: cand } = self;
104
- if (!isFunction(cand)) {
105
- throw new TypeError(`@guardedBy expects predicate "${String(predicateName)}" to be a synchronous function.`);
106
- }
107
- return cand;
108
- };
109
- const computeAllowed = (self, args) => {
110
- const pred = resolvePredicate(self);
111
- const ok = Boolean(pred.call(self, decoratedName, args));
112
- return opts?.invert === true ? !ok : ok;
113
- };
114
- const runOnBlocked = (self, args) => {
115
- const { onBlocked } = opts ?? {};
116
- if (onBlocked === undefined) {
117
- return;
118
- }
119
- if (isFunction(onBlocked)) {
120
- onBlocked.call(self, decoratedName, args);
121
- return;
122
- }
123
- if (isOnBlockedKey(onBlocked)) {
124
- const { [onBlocked]: handlerCandidate } = self;
125
- if (isFunction(handlerCandidate)) {
126
- handlerCandidate.call(self, decoratedName, args);
127
- }
128
- }
129
- };
130
- const blockedReturn = () => originalIsAsync ? Promise.resolve(undefined) : undefined;
131
- const wrapped = function (...args) {
132
- if (!computeAllowed(this, args)) {
133
- runOnBlocked(this, args);
134
- return blockedReturn();
135
- }
136
- return original.call(this, ...args);
137
- };
138
- // Replace the instance method with our wrapper
139
- Reflect.set(this, context.name, wrapped);
140
- });
141
- };
142
- }
143
- //# sourceMappingURL=guardedBy.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"guardedBy.js","sourceRoot":"","sources":["../../../src/lib/decorators/guardedBy.ts"],"names":[],"mappings":"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"}
@@ -1,2 +0,0 @@
1
- export { guardedBy } from './guardedBy';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/decorators/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA"}
@@ -1,2 +0,0 @@
1
- export { guardedBy } from './guardedBy';
2
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/decorators/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA"}
@@ -1,127 +0,0 @@
1
- /**
2
- * A utility type representing a value that may be synchronously available or
3
- * produced asynchronously.
4
- *
5
- * @typeParam T - The resolved value type.
6
- * @public
7
- */
8
- type MaybePromise<T> = T | Promise<T>;
9
- /**
10
- * A function that receives a value of type `T` and returns a (possibly async)
11
- * value of the same type `T`. The input is marked as `readonly` to discourage
12
- * mutation of the original object.
13
- *
14
- * @typeParam T - The value type intercepted and returned.
15
- * @param value - The current (readonly) value in the interception chain.
16
- * @returns The next value for the chain, either directly or via a promise.
17
- * @remarks Implementations SHOULD avoid mutating `value` and instead return a
18
- * new or safely-updated instance.
19
- * @see {@link InterceptorManager}
20
- * @public
21
- */
22
- export type Interceptor<T> = (value: Readonly<T>) => MaybePromise<T>;
23
- /**
24
- * Manages a list of interceptors and provides a way to run them in sequence.
25
- *
26
- * Interceptors are executed in insertion order. Each interceptor receives the
27
- * result of the previous interceptor (or the initial input for the first one)
28
- * and may return a new value synchronously or asynchronously.
29
- *
30
- * @typeParam T - The value type processed by the interceptors.
31
- * @remarks This class snapshots the current interceptor list at invocation time
32
- * so additions/removals during `run` do not affect the in-flight execution.
33
- * @example
34
- * ```ts
35
- * const mgr = new InterceptorManager<number>();
36
- * const id = mgr.add((n) => n + 1);
37
- * const final = await mgr.run(1); // 2
38
- * mgr.remove(id);
39
- * ```
40
- * @public
41
- */
42
- export declare class InterceptorManager<T> {
43
- /**
44
- * The registry of interceptors keyed by their insertion id.
45
- *
46
- * @privateRemarks Internal storage; use {@link add}, {@link remove}, and
47
- * {@link clear} to manage contents.
48
- * @readonly
49
- * @defaultValue `new Map()`
50
- */
51
- private readonly interceptors;
52
- /**
53
- * The next numeric id to assign to an added interceptor.
54
- *
55
- * @privateRemarks Used only to generate unique, monotonically increasing ids.
56
- * @defaultValue `0`
57
- */
58
- private nextId;
59
- /**
60
- * Add an interceptor and return its identifier.
61
- *
62
- * @param interceptor - The interceptor function to register.
63
- * @returns The numeric id that can later be used with {@link remove}.
64
- * @remarks Interceptors are executed in the order they are added.
65
- * @example
66
- * ```ts
67
- * const id = manager.add(async (value) => transform(value));
68
- * ```
69
- * @public
70
- */
71
- add(interceptor: Interceptor<T>): number;
72
- /**
73
- * Remove an interceptor by its identifier.
74
- *
75
- * @param id - The id previously returned by {@link add}.
76
- * @returns `true` if an interceptor was removed; otherwise `false`.
77
- * @example
78
- * ```ts
79
- * const removed = manager.remove(id);
80
- * ```
81
- * @public
82
- */
83
- remove(id: number): boolean;
84
- /**
85
- * Remove all registered interceptors.
86
- *
87
- * @returns Nothing.
88
- * @remarks After calling this, {@link count} will return `0`.
89
- * @example
90
- * ```ts
91
- * manager.clear();
92
- * ```
93
- * @public
94
- */
95
- clear(): void;
96
- /**
97
- * Get the number of currently registered interceptors.
98
- *
99
- * @returns The count of interceptors.
100
- * @example
101
- * ```ts
102
- * if (manager.count() === 0) { /* ... *\/ }
103
- * ```
104
- * @public
105
- */
106
- count(): number;
107
- /**
108
- * Run all interceptors in sequence on an input value and return the final result.
109
- *
110
- * Supports both sync and async interceptors; the return type is always `Promise<T>`
111
- * for consistency.
112
- *
113
- * @param input - The initial value to pass to the first interceptor.
114
- * @returns A promise resolving to the final value after all interceptors have run.
115
- * @throws May rethrow any error thrown by an interceptor. <!-- Intentionally vague: error type depends on interceptor implementation -->
116
- * @remarks The interceptor list is snapshotted at invocation time; changes to
117
- * the registry during execution do not affect the running sequence.
118
- * @example
119
- * ```ts
120
- * const result = await manager.run(initial);
121
- * ```
122
- * @public
123
- */
124
- run(input: T): Promise<T>;
125
- }
126
- export {};
127
- //# sourceMappingURL=InterceptorManager.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"InterceptorManager.d.ts","sourceRoot":"","sources":["../../../src/lib/interceptor/InterceptorManager.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,KAAK,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAA;AAErC;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,KAAK,YAAY,CAAC,CAAC,CAAC,CAAA;AAEpE;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,kBAAkB,CAAC,CAAC;IAC/B;;;;;;;OAOG;IACH,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAoC;IAEjE;;;;;OAKG;IACH,OAAO,CAAC,MAAM,CAAI;IAElB;;;;;;;;;;;OAWG;IACH,GAAG,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,MAAM;IAOxC;;;;;;;;;;OAUG;IACH,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO;IAI3B;;;;;;;;;;OAUG;IACH,KAAK,IAAI,IAAI;IAIb;;;;;;;;;OASG;IACH,KAAK,IAAI,MAAM;IAIf;;;;;;;;;;;;;;;;OAgBG;IACG,GAAG,CAAC,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;CAchC"}
@@ -1,125 +0,0 @@
1
- /**
2
- * Manages a list of interceptors and provides a way to run them in sequence.
3
- *
4
- * Interceptors are executed in insertion order. Each interceptor receives the
5
- * result of the previous interceptor (or the initial input for the first one)
6
- * and may return a new value synchronously or asynchronously.
7
- *
8
- * @typeParam T - The value type processed by the interceptors.
9
- * @remarks This class snapshots the current interceptor list at invocation time
10
- * so additions/removals during `run` do not affect the in-flight execution.
11
- * @example
12
- * ```ts
13
- * const mgr = new InterceptorManager<number>();
14
- * const id = mgr.add((n) => n + 1);
15
- * const final = await mgr.run(1); // 2
16
- * mgr.remove(id);
17
- * ```
18
- * @public
19
- */
20
- export class InterceptorManager {
21
- /**
22
- * The registry of interceptors keyed by their insertion id.
23
- *
24
- * @privateRemarks Internal storage; use {@link add}, {@link remove}, and
25
- * {@link clear} to manage contents.
26
- * @readonly
27
- * @defaultValue `new Map()`
28
- */
29
- interceptors = new Map();
30
- /**
31
- * The next numeric id to assign to an added interceptor.
32
- *
33
- * @privateRemarks Used only to generate unique, monotonically increasing ids.
34
- * @defaultValue `0`
35
- */
36
- nextId = 0;
37
- /**
38
- * Add an interceptor and return its identifier.
39
- *
40
- * @param interceptor - The interceptor function to register.
41
- * @returns The numeric id that can later be used with {@link remove}.
42
- * @remarks Interceptors are executed in the order they are added.
43
- * @example
44
- * ```ts
45
- * const id = manager.add(async (value) => transform(value));
46
- * ```
47
- * @public
48
- */
49
- add(interceptor) {
50
- const { nextId: id } = this;
51
- this.nextId += 1;
52
- this.interceptors.set(id, interceptor);
53
- return id;
54
- }
55
- /**
56
- * Remove an interceptor by its identifier.
57
- *
58
- * @param id - The id previously returned by {@link add}.
59
- * @returns `true` if an interceptor was removed; otherwise `false`.
60
- * @example
61
- * ```ts
62
- * const removed = manager.remove(id);
63
- * ```
64
- * @public
65
- */
66
- remove(id) {
67
- return this.interceptors.delete(id);
68
- }
69
- /**
70
- * Remove all registered interceptors.
71
- *
72
- * @returns Nothing.
73
- * @remarks After calling this, {@link count} will return `0`.
74
- * @example
75
- * ```ts
76
- * manager.clear();
77
- * ```
78
- * @public
79
- */
80
- clear() {
81
- this.interceptors.clear();
82
- }
83
- /**
84
- * Get the number of currently registered interceptors.
85
- *
86
- * @returns The count of interceptors.
87
- * @example
88
- * ```ts
89
- * if (manager.count() === 0) { /* ... *\/ }
90
- * ```
91
- * @public
92
- */
93
- count() {
94
- return this.interceptors.size;
95
- }
96
- /**
97
- * Run all interceptors in sequence on an input value and return the final result.
98
- *
99
- * Supports both sync and async interceptors; the return type is always `Promise<T>`
100
- * for consistency.
101
- *
102
- * @param input - The initial value to pass to the first interceptor.
103
- * @returns A promise resolving to the final value after all interceptors have run.
104
- * @throws May rethrow any error thrown by an interceptor. <!-- Intentionally vague: error type depends on interceptor implementation -->
105
- * @remarks The interceptor list is snapshotted at invocation time; changes to
106
- * the registry during execution do not affect the running sequence.
107
- * @example
108
- * ```ts
109
- * const result = await manager.run(initial);
110
- * ```
111
- * @public
112
- */
113
- async run(input) {
114
- // Snapshot to avoid issues if interceptors are added/removed during execution.
115
- const fns = Array.from(this.interceptors.values());
116
- let acc = input;
117
- for (const fn of fns) {
118
- // Pass a readonly view to discourage mutation of intermediate values.
119
- // Each interceptor must return a T (or Promise<T>).
120
- acc = await fn(acc);
121
- }
122
- return acc;
123
- }
124
- }
125
- //# sourceMappingURL=InterceptorManager.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"InterceptorManager.js","sourceRoot":"","sources":["../../../src/lib/interceptor/InterceptorManager.ts"],"names":[],"mappings":"AAwBA;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,OAAO,kBAAkB;IAC7B;;;;;;;OAOG;IACc,YAAY,GAAG,IAAI,GAAG,EAA0B,CAAA;IAEjE;;;;;OAKG;IACK,MAAM,GAAG,CAAC,CAAA;IAElB;;;;;;;;;;;OAWG;IACH,GAAG,CAAC,WAA2B;QAC7B,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,GAAG,IAAI,CAAA;QAC3B,IAAI,CAAC,MAAM,IAAI,CAAC,CAAA;QAChB,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,EAAE,EAAE,WAAW,CAAC,CAAA;QACtC,OAAO,EAAE,CAAA;IACX,CAAC;IAED;;;;;;;;;;OAUG;IACH,MAAM,CAAC,EAAU;QACf,OAAO,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;IACrC,CAAC;IAED;;;;;;;;;;OAUG;IACH,KAAK;QACH,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,CAAA;IAC3B,CAAC;IAED;;;;;;;;;OASG;IACH,KAAK;QACH,OAAO,IAAI,CAAC,YAAY,CAAC,IAAI,CAAA;IAC/B,CAAC;IAED;;;;;;;;;;;;;;;;OAgBG;IACH,KAAK,CAAC,GAAG,CAAC,KAAQ;QAChB,+EAA+E;QAC/E,MAAM,GAAG,GAAkC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,CAAC,CAAA;QAEjF,IAAI,GAAG,GAAM,KAAK,CAAA;QAElB,KAAK,MAAM,EAAE,IAAI,GAAG,EAAE,CAAC;YACrB,sEAAsE;YACtE,oDAAoD;YACpD,GAAG,GAAG,MAAM,EAAE,CAAC,GAAkB,CAAC,CAAA;QACpC,CAAC;QAED,OAAO,GAAG,CAAA;IACZ,CAAC;CACF"}
@@ -1,2 +0,0 @@
1
- export * from './InterceptorManager';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/interceptor/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAA"}
@@ -1,2 +0,0 @@
1
- export * from './InterceptorManager';
2
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/interceptor/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAA"}
@@ -1,123 +0,0 @@
1
- /**
2
- * A scope identifier for grouping values.
3
- *
4
- * @remarks
5
- * Use a non-empty string for a named scope. Use `undefined` for the
6
- * "global/default" scope. An empty string (`""`) passed to the constructor
7
- * initializer is normalized to `undefined`.
8
- *
9
- * @public
10
- */
11
- type ValuePresenceScope = string | undefined;
12
- /**
13
- * Tracks whether a given value is present within one or more logical scopes.
14
- *
15
- * @remarks
16
- * - Scope names are case-sensitive.
17
- * - Presence is based on `Set.has` reference equality for objects and
18
- * value equality for primitives.
19
- *
20
- * @example
21
- * ```ts
22
- * const presence = new ValuePresence({ default: ['a', 'b'] })
23
- * presence.isPresent('default', 'a') // true
24
- * presence.addValue('default', 'c')
25
- * presence.removeValue('default', 'b')
26
- * presence.reset('default')
27
- * ```
28
- *
29
- * @see {@link ValuePresenceScope}
30
- * @public
31
- */
32
- declare class ValuePresence {
33
- #private;
34
- /**
35
- * Create a new {@link ValuePresence}.
36
- *
37
- * @param defaultMap - Optional initial data. Keys are scope names; values are arrays of items to seed.
38
- * Empty-string keys are normalized to the default scope (`undefined`).
39
- *
40
- * @remarks
41
- * - If `defaultMap` contains duplicate items for a scope, duplicates are collapsed by the `Set`.
42
- */
43
- constructor(defaultMap?: Record<string, unknown[]>);
44
- /**
45
- * Check whether a value is present within a given scope.
46
- *
47
- * @param scope - The scope to check. Use `undefined` for the default scope.
48
- * @param value - The value to test for presence.
49
- * @returns `true` if the value is present in the specified scope; otherwise `false`.
50
- *
51
- * @remarks
52
- * Presence testing uses `Set.prototype.has` semantics.
53
- *
54
- * @example
55
- * ```ts
56
- * presence.isPresent(undefined, 42) // e.g., true or false
57
- * ```
58
- *
59
- * @public
60
- */
61
- isPresent(scope: ValuePresenceScope, value: unknown): boolean;
62
- /**
63
- * Add a value to a scope, creating the scope if it does not exist.
64
- *
65
- * @param scope - Scope to add the value to. Use `undefined` for the default scope.
66
- * @param value - The value to add.
67
- * @returns void
68
- *
69
- * @remarks
70
- * - No-op if the value is already present (due to `Set` semantics).
71
- *
72
- * @example
73
- * ```ts
74
- * presence.addValue('users', userId)
75
- * ```
76
- *
77
- * @public
78
- */
79
- addValue(scope: ValuePresenceScope, value: unknown): void;
80
- /**
81
- * Remove a value from a scope.
82
- *
83
- * @param scope - Scope to remove from. Use `undefined` for the default scope.
84
- * @param value - The value to remove.
85
- * @returns void
86
- *
87
- * @remarks
88
- * If the scope does not exist or the value is not present, this is a no-op.
89
- *
90
- * @example
91
- * ```ts
92
- * presence.removeValue('users', userId)
93
- * ```
94
- *
95
- * @public
96
- */
97
- removeValue(scope: ValuePresenceScope, value: unknown): void;
98
- /**
99
- * Clear values from a single scope, or from all scopes.
100
- *
101
- * @param scope - If provided, clears only that scope. If omitted, clears all scopes.
102
- * @returns void
103
- *
104
- * @remarks
105
- * - When called with a specific scope that does not exist, this is a no-op.
106
- * - When called with no arguments, all scopes and values are removed.
107
- * - Clearing a non-existent scope will not create the scope.
108
- *
109
- * @example
110
- * ```ts
111
- * // Clear one scope
112
- * presence.reset('users')
113
- *
114
- * // Clear all scopes
115
- * presence.reset()
116
- * ```
117
- *
118
- * @public
119
- */
120
- reset(scope?: ValuePresenceScope): void;
121
- }
122
- export default ValuePresence;
123
- //# sourceMappingURL=ValuePresence.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ValuePresence.d.ts","sourceRoot":"","sources":["../../../src/lib/value-presence/ValuePresence.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,KAAK,kBAAkB,GAAG,MAAM,GAAG,SAAS,CAAA;AAE5C;;;;;;;;;;;;;;;;;;;GAmBG;AACH,cAAM,aAAa;;IAQjB;;;;;;;;OAQG;gBACS,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC;IAWlD;;;;;;;;;;;;;;;;OAgBG;IACH,SAAS,CAAC,KAAK,EAAE,kBAAkB,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO;IAI7D;;;;;;;;;;;;;;;;OAgBG;IACH,QAAQ,CAAC,KAAK,EAAE,kBAAkB,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI;IAUzD;;;;;;;;;;;;;;;;OAgBG;IACH,WAAW,CAAC,KAAK,EAAE,kBAAkB,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI;IAI5D;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,KAAK,CAAC,KAAK,CAAC,EAAE,kBAAkB,GAAG,IAAI;CAOxC;AAED,eAAe,aAAa,CAAA"}