@sdux-vault/core 0.0.9
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/LICENSE +249 -0
- package/README.md +190 -0
- package/fesm2022/sdux-vault-core.mjs +1841 -0
- package/fesm2022/sdux-vault-core.mjs.map +1 -0
- package/package.json +52 -0
- package/types/sdux-vault-core.d.ts +219 -0
|
@@ -0,0 +1,1841 @@
|
|
|
1
|
+
import { registerVersion, BehaviorTypes, vaultDebug, VAULT_CLEAR_STATE, vaultWarn, VaultBehavior, defineBehaviorKey, AbstractErrorCallbackBehavior, createVaultError, safeStringify, vaultError, VAULT_NOOP, ResolveTypes, isUndefined, isDeferredFactory, isFunction, isHttpResourceRef, isolateValue, isNullish, isStateInputShape, isNull, StateEmitTypes, isDefined, isVaultNoop, isVaultClearState } from '@sdux-vault/shared';
|
|
2
|
+
import { __decorate } from 'tslib';
|
|
3
|
+
import { isPipelineTerminal, createFeatureCellToken, registerFeatureCell, FeatureCellClass, VaultCore } from '@sdux-vault/engine';
|
|
4
|
+
import { Observable, EMPTY, takeUntil, take, isObservable, firstValueFrom } from 'rxjs';
|
|
5
|
+
|
|
6
|
+
// --- AI Model File Path (DO NOT DELETE) ---
|
|
7
|
+
// FilePath: libs > core > src > lib > behaviors > observable > interface > from-observable-behavior.interface.ts
|
|
8
|
+
// Updated: 2026-03-30 18:53
|
|
9
|
+
// Generated by pathcomment [tab] (see .vscode/typescript.code-snippets) or
|
|
10
|
+
// cmd+alt+j (see .vscode/keybindings.json)
|
|
11
|
+
// --- END AI MODEL FILE PATH ---
|
|
12
|
+
const __fromObservable = true;
|
|
13
|
+
|
|
14
|
+
var observableExt = /*#__PURE__*/Object.freeze({
|
|
15
|
+
__proto__: null,
|
|
16
|
+
__fromObservable: __fromObservable
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
// --- AI Model File Path (DO NOT DELETE) ---
|
|
20
|
+
// FilePath: libs > core > src > lib > behaviors > promise > interface > from-promise-behavior.interface.ts
|
|
21
|
+
// Updated: 2026-03-30 18:54
|
|
22
|
+
// Generated by pathcomment [tab] (see .vscode/typescript.code-snippets) or
|
|
23
|
+
// cmd+alt+j (see .vscode/keybindings.json)
|
|
24
|
+
// --- END AI MODEL FILE PATH ---
|
|
25
|
+
const __fromPromise_extension = true;
|
|
26
|
+
|
|
27
|
+
var promiseExt = /*#__PURE__*/Object.freeze({
|
|
28
|
+
__proto__: null,
|
|
29
|
+
__fromPromise_extension: __fromPromise_extension
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
// --- AI Model File Path (DO NOT DELETE) ---
|
|
33
|
+
// FilePath: libs > core > src > lib > behaviors > resolve > from-stream > interface > from-stream-behavior.interface.ts
|
|
34
|
+
// Updated: 2026-03-30 18:27
|
|
35
|
+
// Generated by pathcomment [tab] (see .vscode/typescript.code-snippets) or
|
|
36
|
+
// cmd+alt+j (see .vscode/keybindings.json)
|
|
37
|
+
// --- END AI MODEL FILE PATH ---
|
|
38
|
+
const __fromStream_extension = true;
|
|
39
|
+
|
|
40
|
+
var streamExt = /*#__PURE__*/Object.freeze({
|
|
41
|
+
__proto__: null,
|
|
42
|
+
__fromStream_extension: __fromStream_extension
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// --- AI Model File Path (DO NOT DELETE) ---
|
|
46
|
+
// FilePath: libs > core > src > extensions > index.ts
|
|
47
|
+
// Updated: 2026-03-30 18:48
|
|
48
|
+
// Generated by pathcomment [tab] (see .vscode/typescript.code-snippets) or
|
|
49
|
+
// cmd+alt+j (see .vscode/keybindings.json)
|
|
50
|
+
// --- END AI MODEL FILE PATH ---
|
|
51
|
+
// This file exists ONLY for side effects
|
|
52
|
+
// Register ALL behavior extensions
|
|
53
|
+
void observableExt;
|
|
54
|
+
void promiseExt;
|
|
55
|
+
void streamExt;
|
|
56
|
+
const __core_extensions_loaded = true;
|
|
57
|
+
|
|
58
|
+
// --- AI Model File Path (DO NOT DELETE) ---
|
|
59
|
+
// FilePath: libs > core > src > lib > version > version.register.ts
|
|
60
|
+
// Updated: 2026-03-03 08:07
|
|
61
|
+
// Generated by pathcomment [tab] (see .vscode/typescript.code-snippets) or
|
|
62
|
+
// cmd+alt+j (see .vscode/keybindings.json)
|
|
63
|
+
// --- END AI MODEL FILE PATH ---
|
|
64
|
+
const SDUX_PACKAGE = '@sdux-vault/core';
|
|
65
|
+
const SDUX_VERSION = '0.0.9';
|
|
66
|
+
registerVersion(SDUX_PACKAGE, SDUX_VERSION);
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Shallow object merge behavior for the Vault merge stage.
|
|
70
|
+
*
|
|
71
|
+
* This behavior performs a one-level object merge where the incoming
|
|
72
|
+
* object spreads over the existing state. Non-object values, arrays,
|
|
73
|
+
* and `null` values bypass merging and are returned directly.
|
|
74
|
+
*
|
|
75
|
+
* The behavior also supports optional merge configuration, such as
|
|
76
|
+
* `clearUndefined`, which determines whether an `undefined` incoming
|
|
77
|
+
* value should clear the current state.
|
|
78
|
+
*
|
|
79
|
+
* This merge strategy is marked as a core, critical behavior and must
|
|
80
|
+
* always be present when selected as the FeatureCell’s merge behavior.
|
|
81
|
+
*
|
|
82
|
+
* @typeParam T - The state value type processed during merge.
|
|
83
|
+
*/
|
|
84
|
+
let withObjectShallowMergeBehavior = class withObjectShallowMergeBehavior {
|
|
85
|
+
behaviorCtx;
|
|
86
|
+
/** Static metadata used for orchestrator behavior classification. */
|
|
87
|
+
static type;
|
|
88
|
+
/** Unique identifier for behavior diagnostics and devtools. */
|
|
89
|
+
static key;
|
|
90
|
+
/** Indicates this merge behavior is pipeline-critical. */
|
|
91
|
+
static critical = true;
|
|
92
|
+
/** Pipeline behavior type identifier. */
|
|
93
|
+
type = BehaviorTypes.Merge;
|
|
94
|
+
/** Unique merge behavior instance identifier. */
|
|
95
|
+
key;
|
|
96
|
+
/** Instance-level criticality flag. */
|
|
97
|
+
critical = true;
|
|
98
|
+
/**
|
|
99
|
+
* Creates a new shallow object merge behavior instance.
|
|
100
|
+
*
|
|
101
|
+
* @param key - Unique behavior identifier supplied by the factory.
|
|
102
|
+
* @param behaviorCtx - BehaviorCtx for future extensibility hooks.
|
|
103
|
+
*/
|
|
104
|
+
constructor(key, behaviorCtx) {
|
|
105
|
+
this.behaviorCtx = behaviorCtx;
|
|
106
|
+
this.key = key;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Computes the shallow merge result between the current state and
|
|
110
|
+
* the incoming value. Non-object inputs bypass merging and are
|
|
111
|
+
* forwarded directly. When `clearUndefined=true`, an undefined
|
|
112
|
+
* incoming value clears the state.
|
|
113
|
+
*
|
|
114
|
+
* @param currentValue - The current FeatureCell state value.
|
|
115
|
+
* @param nextValue - The incoming value to merge into the current state.
|
|
116
|
+
* @param options - Optional merge configuration including `clearUndefined`.
|
|
117
|
+
* @returns The merged or forwarded next state value.
|
|
118
|
+
*/
|
|
119
|
+
computeMerge(currentValue, nextValue, options) {
|
|
120
|
+
const curr = currentValue;
|
|
121
|
+
const next = nextValue;
|
|
122
|
+
const clear = options?.clearUndefined ?? false;
|
|
123
|
+
vaultDebug(`${this.key} shallow merge (clearUndefined=${clear})`);
|
|
124
|
+
if (next === undefined && !clear) {
|
|
125
|
+
vaultDebug(`${this.key} next undefined, preserve current`);
|
|
126
|
+
return curr;
|
|
127
|
+
}
|
|
128
|
+
if (next === undefined && clear) {
|
|
129
|
+
vaultDebug(`${this.key} next undefined & clear=true → return undefined`);
|
|
130
|
+
return VAULT_CLEAR_STATE;
|
|
131
|
+
}
|
|
132
|
+
if (curr == null ||
|
|
133
|
+
next == null ||
|
|
134
|
+
typeof curr !== 'object' ||
|
|
135
|
+
typeof next !== 'object' ||
|
|
136
|
+
Array.isArray(curr) ||
|
|
137
|
+
Array.isArray(next)) {
|
|
138
|
+
vaultDebug(`${this.key} non-object merge return next`);
|
|
139
|
+
return next;
|
|
140
|
+
}
|
|
141
|
+
vaultDebug(`${this.key} shallow merge curr & next`);
|
|
142
|
+
return { ...curr, ...next };
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Invoked when the behavior instance is destroyed.
|
|
146
|
+
* This merge behavior maintains no internal resources.
|
|
147
|
+
*/
|
|
148
|
+
destroy() {
|
|
149
|
+
vaultWarn(`${this.key} - destroy "noop"`);
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Resets the shallow merge behavior.
|
|
153
|
+
*
|
|
154
|
+
* Object shallow merge is a fully stateless, pure merge strategy.
|
|
155
|
+
* It holds no timers, caches, or internal merge state, meaning
|
|
156
|
+
* there is nothing to reset. This lifecycle hook exists solely
|
|
157
|
+
* to support the FeatureCell reset pipeline and to provide a
|
|
158
|
+
* diagnostic signal for DevTools and monitoring systems.
|
|
159
|
+
*
|
|
160
|
+
* After reset, the behavior continues to function identically.
|
|
161
|
+
*/
|
|
162
|
+
reset() {
|
|
163
|
+
vaultWarn(`${this.key} - reset "noop"`);
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
withObjectShallowMergeBehavior = __decorate([
|
|
167
|
+
VaultBehavior({
|
|
168
|
+
type: BehaviorTypes.Merge,
|
|
169
|
+
key: defineBehaviorKey('Core', 'ObjectMerge'),
|
|
170
|
+
critical: true
|
|
171
|
+
})
|
|
172
|
+
], withObjectShallowMergeBehavior);
|
|
173
|
+
|
|
174
|
+
var withCoreErrorCallbackBehavior_1;
|
|
175
|
+
/**
|
|
176
|
+
* Core error callback behavior for invoking legacy error handlers.
|
|
177
|
+
*
|
|
178
|
+
* This behavior executes an optional consumer-supplied error callback when a
|
|
179
|
+
* pipeline error occurs, forwarding the normalized error and an immutable
|
|
180
|
+
* snapshot of the FeatureCell state without altering error flow.
|
|
181
|
+
*/
|
|
182
|
+
let withCoreErrorCallbackBehavior = class withCoreErrorCallbackBehavior extends AbstractErrorCallbackBehavior {
|
|
183
|
+
static { withCoreErrorCallbackBehavior_1 = this; }
|
|
184
|
+
/**
|
|
185
|
+
* Static behavior type identifier used for orchestrator classification.
|
|
186
|
+
*/
|
|
187
|
+
static type;
|
|
188
|
+
/**
|
|
189
|
+
* Static behavior key used for diagnostics and tooling.
|
|
190
|
+
*/
|
|
191
|
+
static key;
|
|
192
|
+
/**
|
|
193
|
+
* Indicates that this behavior is critical within the pipeline.
|
|
194
|
+
*/
|
|
195
|
+
static critical;
|
|
196
|
+
/**
|
|
197
|
+
* Indicates that this error callback behavior is always executed.
|
|
198
|
+
*/
|
|
199
|
+
critical = withCoreErrorCallbackBehavior_1.critical;
|
|
200
|
+
/**
|
|
201
|
+
* Creates a new core error callback behavior instance.
|
|
202
|
+
*
|
|
203
|
+
* @param key Unique behavior identifier.
|
|
204
|
+
* @param behaviorCtx Behavior class context for dependency access.
|
|
205
|
+
*/
|
|
206
|
+
constructor(key, behaviorCtx) {
|
|
207
|
+
super(key, behaviorCtx);
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Invokes a legacy error callback with the normalized error and state snapshot.
|
|
211
|
+
*
|
|
212
|
+
* @param current The normalized error value.
|
|
213
|
+
* @param state Immutable snapshot of the FeatureCell state.
|
|
214
|
+
* @param oldschoolCallback Optional legacy callback function.
|
|
215
|
+
* @returns Resolves after callback execution completes.
|
|
216
|
+
*/
|
|
217
|
+
async callbackError(current, state, oldschoolCallback) {
|
|
218
|
+
if (typeof oldschoolCallback !== 'function') {
|
|
219
|
+
vaultWarn(`${this.key} handleError skipped - "${oldschoolCallback}" is not a function.`);
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
try {
|
|
223
|
+
await oldschoolCallback(current, state);
|
|
224
|
+
}
|
|
225
|
+
catch (err) {
|
|
226
|
+
vaultWarn(`${this.key} oldschoolCallback threw: ${err}`);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
withCoreErrorCallbackBehavior = withCoreErrorCallbackBehavior_1 = __decorate([
|
|
233
|
+
VaultBehavior({
|
|
234
|
+
type: BehaviorTypes.CoreErrorCallback,
|
|
235
|
+
key: defineBehaviorKey('Core', 'ErrorCallback'),
|
|
236
|
+
critical: true
|
|
237
|
+
})
|
|
238
|
+
], withCoreErrorCallbackBehavior);
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Core error behavior used internally by the Vault orchestrator.
|
|
242
|
+
*
|
|
243
|
+
* This behavior represents the **first step** in the error-handling pipeline.
|
|
244
|
+
* It is intentionally minimal and exists solely to normalize any thrown value—
|
|
245
|
+
* regardless of type—into a canonical ResourceStateError using
|
|
246
|
+
* resourceError.
|
|
247
|
+
*
|
|
248
|
+
* ## Responsibilities
|
|
249
|
+
* - Convert `unknown` errors into a well-structured `ResourceStateError`
|
|
250
|
+
* - Provide a deterministic starting point for all addon error behaviors
|
|
251
|
+
* - Guarantee error normalization before transformations occur
|
|
252
|
+
*
|
|
253
|
+
* All richer behaviors (mapping, retries, notifications, old-school callbacks)
|
|
254
|
+
* are implemented as **addon error behaviors** layered after this one.
|
|
255
|
+
*/
|
|
256
|
+
let withCoreErrorBehavior = class withCoreErrorBehavior {
|
|
257
|
+
behaviorCtx;
|
|
258
|
+
/** Behavior type metadata assigned by the decorator. */
|
|
259
|
+
static type;
|
|
260
|
+
/**
|
|
261
|
+
* Unique behavior key assigned by the decorator. */
|
|
262
|
+
static key;
|
|
263
|
+
/** Indicates this behavior participates critically in the pipeline. */
|
|
264
|
+
static critical;
|
|
265
|
+
/** Indicates that this error behavior is critical and always executed. */
|
|
266
|
+
critical = true;
|
|
267
|
+
/** Unique identifier for this behavior instance. */
|
|
268
|
+
key;
|
|
269
|
+
/** Behavior type for orchestrator registration. */
|
|
270
|
+
type = BehaviorTypes.CoreError;
|
|
271
|
+
/**
|
|
272
|
+
* Creates a new Core Error Behavior instance.
|
|
273
|
+
*
|
|
274
|
+
* @param key - Runtime identifier assigned by the behavior factory.
|
|
275
|
+
* @param behaviorCtx - Behavior context providing injector access and
|
|
276
|
+
* future extensibility hooks.
|
|
277
|
+
*
|
|
278
|
+
* This constructor performs no allocation of runtime resources. It simply
|
|
279
|
+
* stores metadata required by the orchestrator and devtools.
|
|
280
|
+
*/
|
|
281
|
+
constructor(key, behaviorCtx) {
|
|
282
|
+
this.behaviorCtx = behaviorCtx;
|
|
283
|
+
this.key = key;
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Normalizes an unknown error into a {@link VaultErrorShape}.
|
|
287
|
+
*
|
|
288
|
+
* This is the *only* operation performed by the core error behavior.
|
|
289
|
+
* Additional behaviors further down the pipeline may inspect or transform
|
|
290
|
+
* the returned structure.
|
|
291
|
+
*
|
|
292
|
+
* @param error - The raw error thrown during pipeline execution.
|
|
293
|
+
* @param feaetureCellKey - The FeatureCell key where the error originated.
|
|
294
|
+
* @returns A canonical `ResourceStateError` created from the raw value.
|
|
295
|
+
*/
|
|
296
|
+
handleError(error, featureCellKey) {
|
|
297
|
+
return createVaultError(error, featureCellKey);
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Lifecycle hook invoked when the behavior instance is destroyed.
|
|
301
|
+
*
|
|
302
|
+
* Core behaviors maintain no internal resources and therefore perform no
|
|
303
|
+
* cleanup. This method logs a devtools-friendly "noop" warning to help
|
|
304
|
+
* with behavior lifecycle introspection.
|
|
305
|
+
*/
|
|
306
|
+
destroy() {
|
|
307
|
+
vaultWarn(`${this.key} - destroy "noop"`);
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* Resets the behavior instance.
|
|
311
|
+
*
|
|
312
|
+
* This behavior maintains no internal mutable state. The reset hook exists
|
|
313
|
+
* strictly for lifecycle symmetry across all behavior types and to support
|
|
314
|
+
* devtools state introspection.
|
|
315
|
+
*/
|
|
316
|
+
reset() {
|
|
317
|
+
vaultWarn(`${this.key} - reset "noop"`);
|
|
318
|
+
}
|
|
319
|
+
};
|
|
320
|
+
withCoreErrorBehavior = __decorate([
|
|
321
|
+
VaultBehavior({
|
|
322
|
+
type: BehaviorTypes.CoreError,
|
|
323
|
+
key: defineBehaviorKey('Core', 'Error'),
|
|
324
|
+
critical: true
|
|
325
|
+
})
|
|
326
|
+
], withCoreErrorBehavior);
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* Core filter behavior for Vault.
|
|
330
|
+
*
|
|
331
|
+
* This behavior participates in the filter stage of the pipeline.
|
|
332
|
+
* A filter function receives the current state and may return:
|
|
333
|
+
* - the same state
|
|
334
|
+
* - a transformed state of the same structural type
|
|
335
|
+
* - `undefined` to indicate that the state update should be aborted
|
|
336
|
+
*
|
|
337
|
+
* This behavior enforces type alignment between the incoming value
|
|
338
|
+
* and the filtered result, ensuring that filters cannot mutate or
|
|
339
|
+
* reshape the state into an incompatible type. When a mismatch is
|
|
340
|
+
* detected, a controlled Vault error is thrown.
|
|
341
|
+
*
|
|
342
|
+
* Filters MUST be pure and must not mutate the incoming value.
|
|
343
|
+
*
|
|
344
|
+
* @typeParam T - The state type handled by this filter behavior.
|
|
345
|
+
*/
|
|
346
|
+
let withCoreFilterBehavior = class withCoreFilterBehavior {
|
|
347
|
+
behaviorCtx;
|
|
348
|
+
/** Static behavior type used for pipeline classification. */
|
|
349
|
+
static type;
|
|
350
|
+
/** Unique behavior key used for introspection and diagnostics. */
|
|
351
|
+
static key;
|
|
352
|
+
/** Indicates that filter behavior is required in the pipeline. */
|
|
353
|
+
static critical;
|
|
354
|
+
/** Instance-level criticality flag. */
|
|
355
|
+
type = BehaviorTypes.Filter;
|
|
356
|
+
/** Indicates that this behavior must always run as part of filtering. */
|
|
357
|
+
critical = true;
|
|
358
|
+
/** Unique identifier for this filter behavior instance. */
|
|
359
|
+
key;
|
|
360
|
+
/**
|
|
361
|
+
* Creates a new filter behavior instance.
|
|
362
|
+
*
|
|
363
|
+
* @param key - Unique behavior identifier supplied by the factory.
|
|
364
|
+
* @param behaviorCtx - BehaviorCtx for future extensibility hooks.
|
|
365
|
+
*/
|
|
366
|
+
constructor(key, behaviorCtx) {
|
|
367
|
+
this.behaviorCtx = behaviorCtx;
|
|
368
|
+
this.key = key;
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Applies the provided filter function to the current state.
|
|
372
|
+
*
|
|
373
|
+
* If the filter returns `undefined`, the state update is aborted.
|
|
374
|
+
* Filter output must preserve the shape of:
|
|
375
|
+
* - arrays
|
|
376
|
+
* - plain objects
|
|
377
|
+
* - primitives
|
|
378
|
+
*
|
|
379
|
+
* Structural mismatches result in a thrown Vault error.
|
|
380
|
+
* Filters must not mutate the incoming value and should remain pure.
|
|
381
|
+
*
|
|
382
|
+
* @param current - The current value before filtering.
|
|
383
|
+
* @param filter - A pure filter function that may transform or reject the value.
|
|
384
|
+
* @returns The filtered value, or `undefined` to abort the update.
|
|
385
|
+
*/
|
|
386
|
+
applyFilter(current, filter) {
|
|
387
|
+
vaultDebug(`${this.key} applyFilter called with "${safeStringify(current)}".`);
|
|
388
|
+
if (current === undefined) {
|
|
389
|
+
vaultDebug(`${this.key} applyFilter skipped - not a valid plain state. The current type is ${typeof current}. Undefined returned.`);
|
|
390
|
+
return undefined;
|
|
391
|
+
}
|
|
392
|
+
if (typeof filter !== 'function') {
|
|
393
|
+
vaultDebug(`${this.key} applyFilter skipped. The filter type is ${typeof filter}. "${safeStringify(current)}" returned.`);
|
|
394
|
+
return current;
|
|
395
|
+
}
|
|
396
|
+
let next;
|
|
397
|
+
try {
|
|
398
|
+
next = filter(current);
|
|
399
|
+
// eslint-disable-next-line
|
|
400
|
+
}
|
|
401
|
+
catch (err) {
|
|
402
|
+
vaultError(`${this.key} filter execution failed`, err.message);
|
|
403
|
+
throw err;
|
|
404
|
+
}
|
|
405
|
+
if (next === undefined) {
|
|
406
|
+
vaultDebug(`${this.key} Filter returned undefined. state rejected.`);
|
|
407
|
+
return VAULT_NOOP;
|
|
408
|
+
}
|
|
409
|
+
if (this.#handleArrayLogic(current, next))
|
|
410
|
+
return next;
|
|
411
|
+
if (this.#handleObjectLogic(current, next))
|
|
412
|
+
return next;
|
|
413
|
+
this.#handlePrimitiveLogic(current, next);
|
|
414
|
+
vaultDebug(`${this.key} applyFilter returned with "${safeStringify(next)}".`);
|
|
415
|
+
return next;
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* Performs type validation when filtering array state values.
|
|
419
|
+
*
|
|
420
|
+
* Ensures the filtered output remains an array when the input was an array.
|
|
421
|
+
*
|
|
422
|
+
* @param current - The pre-filter state value.
|
|
423
|
+
* @param next - The filtered state value.
|
|
424
|
+
* @returns `true` if array handling was applied.
|
|
425
|
+
*/
|
|
426
|
+
#handleArrayLogic(current, next) {
|
|
427
|
+
if (Array.isArray(current)) {
|
|
428
|
+
if (!Array.isArray(next)) {
|
|
429
|
+
this.#typeAlignmentDebug(current, next);
|
|
430
|
+
throw new Error(`[vault] Filter returned non-array for array input.`);
|
|
431
|
+
}
|
|
432
|
+
return true;
|
|
433
|
+
}
|
|
434
|
+
return false;
|
|
435
|
+
}
|
|
436
|
+
/**
|
|
437
|
+
* Performs type validation when filtering object-based state values.
|
|
438
|
+
*
|
|
439
|
+
* Ensures the filter returns a valid non-null object of compatible structure.
|
|
440
|
+
*
|
|
441
|
+
* @param current - The pre-filter state value.
|
|
442
|
+
* @param next - The filtered state value.
|
|
443
|
+
* @returns `true` if object handling was applied.
|
|
444
|
+
*/
|
|
445
|
+
#handleObjectLogic(current, next) {
|
|
446
|
+
if (current !== null && typeof current === 'object') {
|
|
447
|
+
if (typeof next !== 'object' || next === null || Array.isArray(next)) {
|
|
448
|
+
this.#typeAlignmentDebug(current, next);
|
|
449
|
+
throw new Error(`[vault] Filter returned invalid object for object input.`);
|
|
450
|
+
}
|
|
451
|
+
return true;
|
|
452
|
+
}
|
|
453
|
+
return false;
|
|
454
|
+
}
|
|
455
|
+
/**
|
|
456
|
+
* Performs type validation for primitive state values.
|
|
457
|
+
*
|
|
458
|
+
* Ensures the filter output matches the primitive type of the input.
|
|
459
|
+
*
|
|
460
|
+
* @param current - The pre-filter primitive value.
|
|
461
|
+
* @param next - The filtered primitive value.
|
|
462
|
+
*/
|
|
463
|
+
#handlePrimitiveLogic(current, next) {
|
|
464
|
+
if (typeof next !== typeof current) {
|
|
465
|
+
this.#typeAlignmentDebug(current, next);
|
|
466
|
+
throw new Error(`[vault] Filter returned a value of incorrect type. Expected "${typeof current}", got "${typeof next}".`);
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
/**
|
|
470
|
+
* Emits detailed debug output when filter output does not align with the input type.
|
|
471
|
+
*
|
|
472
|
+
* @param current - The original state value.
|
|
473
|
+
* @param next - The returned filter value.
|
|
474
|
+
*/
|
|
475
|
+
#typeAlignmentDebug(current, next) {
|
|
476
|
+
vaultDebug(`${this.key} The types not aligned. Current type: "${typeof current}". Next type: ${typeof next}. "${safeStringify(next)}" returned.`);
|
|
477
|
+
}
|
|
478
|
+
/**
|
|
479
|
+
* Invoked during behavior teardown.
|
|
480
|
+
* This behavior maintains no internal resources and requires no cleanup.
|
|
481
|
+
*/
|
|
482
|
+
destroy() {
|
|
483
|
+
vaultWarn(`${this.key} - destroy "noop"`);
|
|
484
|
+
}
|
|
485
|
+
/**
|
|
486
|
+
* Resets the filter behavior.
|
|
487
|
+
*
|
|
488
|
+
* Since core filters do not maintain internal state, this reset operation
|
|
489
|
+
* performs no functional work. It exists to support the FeatureCell reset
|
|
490
|
+
* lifecycle and provides a diagnostic hook for DevTools and monitoring.
|
|
491
|
+
*
|
|
492
|
+
* After reset, the behavior continues operating identically to before.
|
|
493
|
+
*/
|
|
494
|
+
reset() {
|
|
495
|
+
vaultWarn(`${this.key} - reset "noop"`);
|
|
496
|
+
}
|
|
497
|
+
};
|
|
498
|
+
withCoreFilterBehavior = __decorate([
|
|
499
|
+
VaultBehavior({
|
|
500
|
+
type: BehaviorTypes.Filter,
|
|
501
|
+
key: defineBehaviorKey('Core', 'Filter'),
|
|
502
|
+
critical: true
|
|
503
|
+
})
|
|
504
|
+
], withCoreFilterBehavior);
|
|
505
|
+
|
|
506
|
+
var withArrayMergeBehavior_1;
|
|
507
|
+
/**
|
|
508
|
+
* Array merge behavior for Vault.
|
|
509
|
+
*
|
|
510
|
+
* This merge strategy replaces arrays rather than merging them, ensuring
|
|
511
|
+
* predictable and immutable updates for list-like state. All non-array values
|
|
512
|
+
* are returned directly without transformation.
|
|
513
|
+
*
|
|
514
|
+
* This behavior is marked as critical, ensuring it participates in every
|
|
515
|
+
* merge pipeline unless explicitly replaced by a custom merge behavior.
|
|
516
|
+
*
|
|
517
|
+
* @typeParam T - The pipeline state value type handled by this behavior.
|
|
518
|
+
*/
|
|
519
|
+
let withArrayMergeBehavior = class withArrayMergeBehavior {
|
|
520
|
+
static { withArrayMergeBehavior_1 = this; }
|
|
521
|
+
behaviorCtx;
|
|
522
|
+
/** Static behavior type used by the orchestrator. */
|
|
523
|
+
static type;
|
|
524
|
+
/** Static unique key assigned to this behavior. */
|
|
525
|
+
static key;
|
|
526
|
+
/** Indicates this behavior is required for merge processing. */
|
|
527
|
+
static critical = true;
|
|
528
|
+
/** Instance-level merge behavior type identifier. */
|
|
529
|
+
type = withArrayMergeBehavior_1.type;
|
|
530
|
+
/** Unique identifier for this behavior instance. */
|
|
531
|
+
key;
|
|
532
|
+
/** Flags this behavior instance as critical within the pipeline. */
|
|
533
|
+
critical = withArrayMergeBehavior_1.critical;
|
|
534
|
+
/**
|
|
535
|
+
* Creates a new array merge behavior instance.
|
|
536
|
+
*
|
|
537
|
+
* @param key - Unique behavior identifier supplied by the factory.
|
|
538
|
+
* @param behaviorCtx - BehaviorCtx for future extensibility hooks.
|
|
539
|
+
*/
|
|
540
|
+
constructor(key, behaviorCtx) {
|
|
541
|
+
this.behaviorCtx = behaviorCtx;
|
|
542
|
+
this.key = key;
|
|
543
|
+
}
|
|
544
|
+
/**
|
|
545
|
+
* Computes the merged state value using array-replacement semantics.
|
|
546
|
+
*
|
|
547
|
+
* - If `nextValue` is undefined and `clearUndefined` is false,
|
|
548
|
+
* the current value is preserved.
|
|
549
|
+
* - If `nextValue` is undefined and `clearUndefined` is true,
|
|
550
|
+
* the merge resolves to `undefined`.
|
|
551
|
+
* - If both values are arrays, a shallow clone of `nextValue`
|
|
552
|
+
* is returned to maintain immutability.
|
|
553
|
+
* - All other values pass through as-is.
|
|
554
|
+
*
|
|
555
|
+
* @param currentValue - The existing state value.
|
|
556
|
+
* @param nextValue - The incoming state value to merge.
|
|
557
|
+
* @param options - Optional merge configuration.
|
|
558
|
+
* @returns The merged pipeline value.
|
|
559
|
+
*/
|
|
560
|
+
computeMerge(currentValue, nextValue, options) {
|
|
561
|
+
const curr = currentValue;
|
|
562
|
+
const next = nextValue;
|
|
563
|
+
const clear = options?.clearUndefined ?? false;
|
|
564
|
+
vaultDebug(`${this.key} merge called (clear: ${clear})`);
|
|
565
|
+
if (next === undefined && !clear) {
|
|
566
|
+
vaultDebug(`${this.key} computeMerge skipped. The next value "${next}" and clear is "${clear}`);
|
|
567
|
+
return curr;
|
|
568
|
+
}
|
|
569
|
+
if (next === undefined && clear) {
|
|
570
|
+
vaultDebug(`${this.key} computeMerge skipped. The next value "${next}" and clear is "${clear}`);
|
|
571
|
+
return VAULT_CLEAR_STATE;
|
|
572
|
+
}
|
|
573
|
+
if (Array.isArray(curr) && Array.isArray(next)) {
|
|
574
|
+
vaultDebug(`${this.key} merging array. Return clone of next`);
|
|
575
|
+
return [...next];
|
|
576
|
+
}
|
|
577
|
+
vaultDebug(`${this.key} non-array branch. Return next`);
|
|
578
|
+
return next;
|
|
579
|
+
}
|
|
580
|
+
/**
|
|
581
|
+
* Performs teardown when the behavior instance is destroyed.
|
|
582
|
+
* This merge behavior maintains no resources and requires no cleanup.
|
|
583
|
+
*/
|
|
584
|
+
destroy() {
|
|
585
|
+
vaultWarn(`${this.key} - destroy "noop"`);
|
|
586
|
+
}
|
|
587
|
+
/**
|
|
588
|
+
* Resets the merge behavior.
|
|
589
|
+
*
|
|
590
|
+
* Array merge is a fully stateless behavior and maintains no internal
|
|
591
|
+
* resources, configuration mutations, or cached values. As a result,
|
|
592
|
+
* this reset operation performs no functional work and simply emits a
|
|
593
|
+
* diagnostic event for DevTools and monitoring.
|
|
594
|
+
*
|
|
595
|
+
* After reset, this behavior continues to operate identically to before.
|
|
596
|
+
*/
|
|
597
|
+
reset() {
|
|
598
|
+
vaultWarn(`${this.key} - reset "noop"`);
|
|
599
|
+
}
|
|
600
|
+
};
|
|
601
|
+
withArrayMergeBehavior = withArrayMergeBehavior_1 = __decorate([
|
|
602
|
+
VaultBehavior({
|
|
603
|
+
type: BehaviorTypes.Merge,
|
|
604
|
+
key: defineBehaviorKey('Core', 'ArrayMerge'),
|
|
605
|
+
critical: true
|
|
606
|
+
})
|
|
607
|
+
], withArrayMergeBehavior);
|
|
608
|
+
|
|
609
|
+
/**
|
|
610
|
+
* Extends a FeatureCell with a `fromObservable` helper for observable-based state sources.
|
|
611
|
+
*
|
|
612
|
+
* This function installs a placeholder implementation that accepts an observable
|
|
613
|
+
* and exposes it as a stream of `VaultStateRef<T>` values, with the runtime behavior
|
|
614
|
+
* replaced by the corresponding pipeline behavior when installed.
|
|
615
|
+
*
|
|
616
|
+
* @param cell The FeatureCell instance to extend.
|
|
617
|
+
*/
|
|
618
|
+
function extendFromObservable(cell) {
|
|
619
|
+
/**
|
|
620
|
+
* Wraps an observable source for integration with the FeatureCell pipeline.
|
|
621
|
+
*
|
|
622
|
+
* @param source$ Observable emitting raw state values.
|
|
623
|
+
* @returns Observable emitting vault state references.
|
|
624
|
+
*/
|
|
625
|
+
cell.fromObservable = function (source$) {
|
|
626
|
+
return source$;
|
|
627
|
+
};
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
var withCoreFromObservableBehavior_1;
|
|
631
|
+
/**
|
|
632
|
+
* Extension behavior that enables FeatureCells to resolve state from observable sources.
|
|
633
|
+
*
|
|
634
|
+
* This behavior augments the FeatureCell API with a `fromObservable` method that
|
|
635
|
+
* converts a single observable emission into a normalized state envelope and
|
|
636
|
+
* binds subscription lifetime to the cell lifecycle.
|
|
637
|
+
*
|
|
638
|
+
* @deprecated
|
|
639
|
+
* This API exists as a migration bridge for observable-based workflows.
|
|
640
|
+
* Prefer using `replaceState` or `mergeState` to resolve
|
|
641
|
+
* observables directly within the pipeline.
|
|
642
|
+
*
|
|
643
|
+
* --RelatedStart--
|
|
644
|
+
* FromObservableBehaviorExtension
|
|
645
|
+
* withCoreObservableBehavior
|
|
646
|
+
* replaceState
|
|
647
|
+
* mergeState
|
|
648
|
+
* --RelatedEnd--
|
|
649
|
+
*/
|
|
650
|
+
let withCoreFromObservableBehavior = class withCoreFromObservableBehavior {
|
|
651
|
+
static { withCoreFromObservableBehavior_1 = this; }
|
|
652
|
+
behaviorCtx;
|
|
653
|
+
/** Extension function used to attach observable APIs to the FeatureCell. */
|
|
654
|
+
static extension = extendFromObservable;
|
|
655
|
+
/** Static behavior type used for pipeline classification. */
|
|
656
|
+
static type;
|
|
657
|
+
/** Static behavior key used for diagnostics and introspection. */
|
|
658
|
+
static key;
|
|
659
|
+
/** Resolve type associated with observable-based resolution. */
|
|
660
|
+
static resolveType;
|
|
661
|
+
/** Indicates whether this behavior is required by the pipeline. */
|
|
662
|
+
static critical;
|
|
663
|
+
/** Instance-level behavior type identifier. */
|
|
664
|
+
type = withCoreFromObservableBehavior_1.type;
|
|
665
|
+
/** Unique identifier for this behavior instance. */
|
|
666
|
+
key;
|
|
667
|
+
/** Indicates that this behavior is optional within the pipeline. */
|
|
668
|
+
critical = withCoreFromObservableBehavior_1.critical;
|
|
669
|
+
/** Resolve type for this behavior instance. */
|
|
670
|
+
resolveType = withCoreFromObservableBehavior_1.resolveType;
|
|
671
|
+
/**
|
|
672
|
+
* Creates a new observable extension behavior instance.
|
|
673
|
+
*
|
|
674
|
+
* @param key Unique identifier assigned by the behavior factory.
|
|
675
|
+
* @param behaviorCtx Behavior class context used for configuration access.
|
|
676
|
+
*/
|
|
677
|
+
constructor(key, behaviorCtx) {
|
|
678
|
+
this.behaviorCtx = behaviorCtx;
|
|
679
|
+
this.key = key;
|
|
680
|
+
}
|
|
681
|
+
/**
|
|
682
|
+
* Extends the FeatureCell API with observable-based resolution support.
|
|
683
|
+
*
|
|
684
|
+
* @param ctx FeatureCell extension context providing lifecycle signals.
|
|
685
|
+
* @returns An extension object exposing the `fromObservable` API.
|
|
686
|
+
*/
|
|
687
|
+
extendCellAPI(ctx) {
|
|
688
|
+
return {
|
|
689
|
+
fromObservable: (source$) => new Observable((observer) => {
|
|
690
|
+
vaultDebug(`${this.key} fromObservable called.`);
|
|
691
|
+
const destroy$ = ctx.destroyed$ ?? EMPTY;
|
|
692
|
+
const reset$ = ctx.reset$ ?? EMPTY;
|
|
693
|
+
const subscription = source$.pipe(takeUntil(reset$), takeUntil(destroy$), take(1)).subscribe({
|
|
694
|
+
next: (value) => {
|
|
695
|
+
vaultDebug(`${this.key} fromObservable emitted value "${safeStringify(value)}".`);
|
|
696
|
+
observer.next({
|
|
697
|
+
loading: false,
|
|
698
|
+
value,
|
|
699
|
+
error: null
|
|
700
|
+
});
|
|
701
|
+
},
|
|
702
|
+
error: (err) => {
|
|
703
|
+
const error = createVaultError(err, ctx.featureCellKey);
|
|
704
|
+
observer.error(error);
|
|
705
|
+
vaultDebug(`${this.key} fromObservable emitted error "${error.message}".`);
|
|
706
|
+
},
|
|
707
|
+
complete: () => {
|
|
708
|
+
observer.complete();
|
|
709
|
+
vaultDebug(`${this.key} fromObservable completed.`);
|
|
710
|
+
}
|
|
711
|
+
});
|
|
712
|
+
return () => {
|
|
713
|
+
subscription.unsubscribe();
|
|
714
|
+
vaultDebug(`${this.key} fromObservable subscription unsubscribed.`);
|
|
715
|
+
};
|
|
716
|
+
})
|
|
717
|
+
};
|
|
718
|
+
}
|
|
719
|
+
/**
|
|
720
|
+
* Invoked when the behavior instance is destroyed.
|
|
721
|
+
*/
|
|
722
|
+
destroy() {
|
|
723
|
+
vaultWarn(`${this.key} - destroy "noop"`);
|
|
724
|
+
}
|
|
725
|
+
/**
|
|
726
|
+
* Resets the observable extension behavior.
|
|
727
|
+
*/
|
|
728
|
+
reset() {
|
|
729
|
+
vaultWarn(`${this.key} - reset "noop"`);
|
|
730
|
+
}
|
|
731
|
+
};
|
|
732
|
+
withCoreFromObservableBehavior = withCoreFromObservableBehavior_1 = __decorate([
|
|
733
|
+
VaultBehavior({
|
|
734
|
+
type: BehaviorTypes.FromObservable,
|
|
735
|
+
key: defineBehaviorKey('Core', 'FromObservable'),
|
|
736
|
+
critical: false,
|
|
737
|
+
resolveType: ResolveTypes.Observable
|
|
738
|
+
})
|
|
739
|
+
], withCoreFromObservableBehavior);
|
|
740
|
+
|
|
741
|
+
/**
|
|
742
|
+
* Extends a FeatureCell with promise-based resolution placeholders.
|
|
743
|
+
*
|
|
744
|
+
* This function attaches `fromDeferred` and `fromPromise` methods to the
|
|
745
|
+
* FeatureCell shape as build-time stubs. These methods are replaced at
|
|
746
|
+
* runtime by the corresponding resolve behavior when installed.
|
|
747
|
+
*
|
|
748
|
+
* --RelatedStart--
|
|
749
|
+
* FeatureCellShape
|
|
750
|
+
* DeferredFactory
|
|
751
|
+
* --RelatedEnd--
|
|
752
|
+
*
|
|
753
|
+
* @param cell The FeatureCell instance being extended.
|
|
754
|
+
*/
|
|
755
|
+
function extendFromPromise(cell) {
|
|
756
|
+
/**
|
|
757
|
+
* Resolves state from a deferred factory using promise semantics.
|
|
758
|
+
*
|
|
759
|
+
* @param _incoming Deferred factory that produces the state value.
|
|
760
|
+
* @returns A promise resolving to a normalized state envelope.
|
|
761
|
+
*/
|
|
762
|
+
cell.fromDeferred = function (_incoming) {
|
|
763
|
+
// runtime behavior will replace this implementation
|
|
764
|
+
throw new Error('[vault] fromDeferred() behavior not installed');
|
|
765
|
+
};
|
|
766
|
+
/**
|
|
767
|
+
* Resolves state from a deferred factory using promise semantics.
|
|
768
|
+
*
|
|
769
|
+
* @param _incoming Deferred factory that produces the state value.
|
|
770
|
+
* @returns A promise resolving to a normalized state envelope.
|
|
771
|
+
*/
|
|
772
|
+
cell.fromPromise = function (_incoming) {
|
|
773
|
+
// runtime behavior will replace this implementation
|
|
774
|
+
throw new Error('[vault] fromPromise() behavior not installed');
|
|
775
|
+
};
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
var withCoreFromPromiseBehavior_1;
|
|
779
|
+
/**
|
|
780
|
+
* Extension behavior that enables promise-based state resolution for FeatureCells.
|
|
781
|
+
*
|
|
782
|
+
* This behavior augments a FeatureCell with APIs that accept deferred factories
|
|
783
|
+
* and resolve their produced values into normalized state inputs. It supports
|
|
784
|
+
* both promise and deferred invocation semantics while preserving pipeline
|
|
785
|
+
* loading and error metadata.
|
|
786
|
+
*
|
|
787
|
+
* @deprecated
|
|
788
|
+
* This API exists as a migration bridge for deferred- and promise-based workflows.
|
|
789
|
+
* Prefer using `replaceState` or `mergeState` to resolve promises
|
|
790
|
+
* directly within the pipeline.
|
|
791
|
+
*
|
|
792
|
+
* --RelatedStart--
|
|
793
|
+
* FromPromiseBehaviorExtension
|
|
794
|
+
* DeferredFactory
|
|
795
|
+
* withCorePromiseBehavior
|
|
796
|
+
* replaceState
|
|
797
|
+
* mergeState
|
|
798
|
+
* --RelatedEnd--
|
|
799
|
+
*/
|
|
800
|
+
let withCoreFromPromiseBehavior = class withCoreFromPromiseBehavior {
|
|
801
|
+
static { withCoreFromPromiseBehavior_1 = this; }
|
|
802
|
+
behaviorCtx;
|
|
803
|
+
/** Static behavior function used to extend the FeatureCell API. */
|
|
804
|
+
static extension = extendFromPromise;
|
|
805
|
+
/** Static behavior type used for orchestrator classification. */
|
|
806
|
+
static type;
|
|
807
|
+
/** Static behavior key used for diagnostics and tooling. */
|
|
808
|
+
static key;
|
|
809
|
+
/** Indicates whether this behavior is required by the pipeline. */
|
|
810
|
+
static critical;
|
|
811
|
+
/** Resolve type identifier for promise-based resolution. */
|
|
812
|
+
static resolveType;
|
|
813
|
+
/** Instance-level behavior type identifier. */
|
|
814
|
+
type = withCoreFromPromiseBehavior_1.type;
|
|
815
|
+
/** Unique identifier for this behavior instance. */
|
|
816
|
+
key;
|
|
817
|
+
/** Indicates that this behavior is optional within the pipeline. */
|
|
818
|
+
critical = withCoreFromPromiseBehavior_1.critical;
|
|
819
|
+
/** Resolve type identifier for this behavior instance. */
|
|
820
|
+
resolveType = withCoreFromPromiseBehavior_1.resolveType;
|
|
821
|
+
/**
|
|
822
|
+
* Creates a new instance of the promise resolution behavior.
|
|
823
|
+
*
|
|
824
|
+
* @param key Unique behavior identifier supplied by the factory.
|
|
825
|
+
* @param behaviorCtx Behavior context providing configuration and lifecycle hooks.
|
|
826
|
+
*/
|
|
827
|
+
constructor(key, behaviorCtx) {
|
|
828
|
+
this.behaviorCtx = behaviorCtx;
|
|
829
|
+
this.key = key;
|
|
830
|
+
}
|
|
831
|
+
/**
|
|
832
|
+
* Extends the FeatureCell API with promise-based resolution functions.
|
|
833
|
+
*
|
|
834
|
+
* @param ctx FeatureCell extension context used for lifecycle coordination.
|
|
835
|
+
* @returns An extension object exposing promise-based resolution methods.
|
|
836
|
+
*/
|
|
837
|
+
extendCellAPI(ctx) {
|
|
838
|
+
const handleDeferred = (incoming) => new Promise((resolve, reject) => {
|
|
839
|
+
vaultDebug(`${this.key} fromPromise called.`);
|
|
840
|
+
if (isUndefined(incoming)) {
|
|
841
|
+
resolve({
|
|
842
|
+
loading: false,
|
|
843
|
+
value: undefined,
|
|
844
|
+
error: null
|
|
845
|
+
});
|
|
846
|
+
return;
|
|
847
|
+
}
|
|
848
|
+
if (!isDeferredFactory(incoming)) {
|
|
849
|
+
const potentialIncoming = incoming;
|
|
850
|
+
resolve({
|
|
851
|
+
loading: potentialIncoming?.loading ?? false,
|
|
852
|
+
value: undefined,
|
|
853
|
+
error: potentialIncoming?.error ?? null
|
|
854
|
+
});
|
|
855
|
+
return;
|
|
856
|
+
}
|
|
857
|
+
let result;
|
|
858
|
+
try {
|
|
859
|
+
result = incoming.value?.();
|
|
860
|
+
}
|
|
861
|
+
catch (err) {
|
|
862
|
+
const error = createVaultError(err, ctx.featureCellKey);
|
|
863
|
+
reject(error);
|
|
864
|
+
return;
|
|
865
|
+
}
|
|
866
|
+
Promise.resolve(result)
|
|
867
|
+
.then((value) => {
|
|
868
|
+
vaultDebug(`${this.key} fromPromise resolved value: ${safeStringify(value)}`);
|
|
869
|
+
resolve({
|
|
870
|
+
loading: incoming.loading ?? false,
|
|
871
|
+
value,
|
|
872
|
+
error: incoming.error ?? null
|
|
873
|
+
});
|
|
874
|
+
})
|
|
875
|
+
.catch((err) => {
|
|
876
|
+
const error = createVaultError(err, ctx.featureCellKey);
|
|
877
|
+
reject(error);
|
|
878
|
+
});
|
|
879
|
+
});
|
|
880
|
+
return {
|
|
881
|
+
fromPromise: (incoming) => handleDeferred(incoming),
|
|
882
|
+
fromDeferred: (incoming) => handleDeferred(incoming)
|
|
883
|
+
};
|
|
884
|
+
}
|
|
885
|
+
/**
|
|
886
|
+
* Invoked during behavior teardown.
|
|
887
|
+
*/
|
|
888
|
+
destroy() {
|
|
889
|
+
vaultWarn(`${this.key} - destroy "noop"`);
|
|
890
|
+
}
|
|
891
|
+
/**
|
|
892
|
+
* Resets the behavior state.
|
|
893
|
+
*/
|
|
894
|
+
reset() {
|
|
895
|
+
vaultWarn(`${this.key} - reset "noop"`);
|
|
896
|
+
}
|
|
897
|
+
};
|
|
898
|
+
withCoreFromPromiseBehavior = withCoreFromPromiseBehavior_1 = __decorate([
|
|
899
|
+
VaultBehavior({
|
|
900
|
+
type: BehaviorTypes.FromPromise,
|
|
901
|
+
key: defineBehaviorKey('Core', 'FromPromise'),
|
|
902
|
+
critical: false,
|
|
903
|
+
resolveType: ResolveTypes.Promise
|
|
904
|
+
})
|
|
905
|
+
], withCoreFromPromiseBehavior);
|
|
906
|
+
|
|
907
|
+
/**
|
|
908
|
+
* Core reducer behavior that applies pure reducer functions to state values.
|
|
909
|
+
*
|
|
910
|
+
* This behavior participates in the reduce stage of the pipeline and is
|
|
911
|
+
* responsible for invoking reducer functions supplied by consumers to
|
|
912
|
+
* transform the current state into a new value. It performs no validation
|
|
913
|
+
* beyond ensuring the reducer is callable.
|
|
914
|
+
*/
|
|
915
|
+
let withCoreReducerBehavior = class withCoreReducerBehavior {
|
|
916
|
+
behaviorCtx;
|
|
917
|
+
/** Static metadata used for orchestrator behavior classification. */
|
|
918
|
+
static type;
|
|
919
|
+
/** Unique behavior identifier for diagnostics and devtools. */
|
|
920
|
+
static key;
|
|
921
|
+
/** Indicates that reducer behavior is essential to the pipeline. */
|
|
922
|
+
static critical;
|
|
923
|
+
/** Instance-level criticality flag. */
|
|
924
|
+
critical = true;
|
|
925
|
+
/** Pipeline behavior type identifier. */
|
|
926
|
+
type = BehaviorTypes.Reduce;
|
|
927
|
+
/** Unique identifier for this reducer behavior instance. */
|
|
928
|
+
key;
|
|
929
|
+
/**
|
|
930
|
+
* Creates a new reducer behavior instance.
|
|
931
|
+
*
|
|
932
|
+
* @param key Unique behavior identifier supplied by the factory.
|
|
933
|
+
* @param behaviorCtx Behavior class context for dependency injection and configuration.
|
|
934
|
+
*/
|
|
935
|
+
constructor(key, behaviorCtx) {
|
|
936
|
+
this.behaviorCtx = behaviorCtx;
|
|
937
|
+
this.key = key;
|
|
938
|
+
}
|
|
939
|
+
/**
|
|
940
|
+
* Applies a reducer function to the current state value.
|
|
941
|
+
*
|
|
942
|
+
* @param current The current state value before reduction.
|
|
943
|
+
* @param reducer A reducer function that produces the next state value.
|
|
944
|
+
* @returns The reduced state value.
|
|
945
|
+
*/
|
|
946
|
+
applyReducer(current, reducer) {
|
|
947
|
+
vaultDebug(`${this.key} applyReducer called with "${safeStringify(current)}".`);
|
|
948
|
+
if (typeof reducer !== 'function') {
|
|
949
|
+
vaultDebug(`${this.key} applyReducer skipped - reducer is not a function.`);
|
|
950
|
+
return current;
|
|
951
|
+
}
|
|
952
|
+
return reducer(current);
|
|
953
|
+
}
|
|
954
|
+
/**
|
|
955
|
+
* Invoked when the behavior instance is destroyed.
|
|
956
|
+
*/
|
|
957
|
+
destroy() {
|
|
958
|
+
vaultWarn(`${this.key} - destroy "noop"`);
|
|
959
|
+
}
|
|
960
|
+
/**
|
|
961
|
+
* Resets the reducer behavior to its initial state.
|
|
962
|
+
*/
|
|
963
|
+
reset() {
|
|
964
|
+
vaultWarn(`${this.key} - reset "noop"`);
|
|
965
|
+
}
|
|
966
|
+
};
|
|
967
|
+
withCoreReducerBehavior = __decorate([
|
|
968
|
+
VaultBehavior({
|
|
969
|
+
type: BehaviorTypes.Reduce,
|
|
970
|
+
key: defineBehaviorKey('Core', 'Reducer'),
|
|
971
|
+
critical: true
|
|
972
|
+
})
|
|
973
|
+
], withCoreReducerBehavior);
|
|
974
|
+
|
|
975
|
+
var withCoreObservableBehavior_1;
|
|
976
|
+
/**
|
|
977
|
+
* Core resolve behavior that extracts a single value from an RxJS Observable.
|
|
978
|
+
*
|
|
979
|
+
* This behavior participates in the resolve stage and handles incoming
|
|
980
|
+
* Observable values by subscribing once and resolving with the first emitted
|
|
981
|
+
* value. Resolution is automatically terminated when the FeatureCell is reset
|
|
982
|
+
* or destroyed.
|
|
983
|
+
*/
|
|
984
|
+
let withCoreObservableBehavior = class withCoreObservableBehavior {
|
|
985
|
+
static { withCoreObservableBehavior_1 = this; }
|
|
986
|
+
behaviorCtx;
|
|
987
|
+
/** Static behavior type used for orchestrator classification. */
|
|
988
|
+
static type;
|
|
989
|
+
/** Unique behavior key used for diagnostics and devtools. */
|
|
990
|
+
static key;
|
|
991
|
+
/** Indicates whether this behavior is required by the pipeline. */
|
|
992
|
+
static critical;
|
|
993
|
+
/** Resolve type classification for observable-based resolution. */
|
|
994
|
+
static resolveType;
|
|
995
|
+
/** The pipeline behavior type identifier. */
|
|
996
|
+
type = BehaviorTypes.Resolve;
|
|
997
|
+
/** Unique identifier for this behavior instance. */
|
|
998
|
+
key;
|
|
999
|
+
/** Indicates that this behavior is optional within the pipeline. */
|
|
1000
|
+
critical = false;
|
|
1001
|
+
/** Resolve type identifier for observable-based resolution. */
|
|
1002
|
+
resolveType = withCoreObservableBehavior_1.resolveType;
|
|
1003
|
+
/**
|
|
1004
|
+
* Creates a new observable resolve behavior instance.
|
|
1005
|
+
*
|
|
1006
|
+
* @param key Unique behavior identifier supplied by the factory.
|
|
1007
|
+
* @param behaviorCtx Behavior class context for dependency injection and configuration.
|
|
1008
|
+
*/
|
|
1009
|
+
constructor(key, behaviorCtx) {
|
|
1010
|
+
this.behaviorCtx = behaviorCtx;
|
|
1011
|
+
this.key = key;
|
|
1012
|
+
}
|
|
1013
|
+
/**
|
|
1014
|
+
* Resolves a state value from an Observable input.
|
|
1015
|
+
*
|
|
1016
|
+
* @param ctx The resolve behavior context containing the incoming value.
|
|
1017
|
+
* @returns The resolved state value or undefined if resolution is skipped.
|
|
1018
|
+
*/
|
|
1019
|
+
async computeResolve(ctx) {
|
|
1020
|
+
const incoming = ctx.incoming;
|
|
1021
|
+
vaultDebug(`${this.key} computeResolve called with incoming: ${safeStringify(incoming)}`);
|
|
1022
|
+
if (!isObservable(incoming)) {
|
|
1023
|
+
vaultDebug(`${this.key} computeResolve skipped — incoming is not an Observable.`);
|
|
1024
|
+
return;
|
|
1025
|
+
}
|
|
1026
|
+
vaultDebug(`${this.key} computeResolve detected Observable input.`);
|
|
1027
|
+
const source$ = incoming;
|
|
1028
|
+
const reset$ = ctx.reset$ ?? EMPTY;
|
|
1029
|
+
const destroyed$ = ctx.destroyed$ ?? EMPTY;
|
|
1030
|
+
try {
|
|
1031
|
+
const value = await firstValueFrom(source$.pipe(takeUntil(reset$), takeUntil(destroyed$), take(1)));
|
|
1032
|
+
vaultDebug(`${this.key} computeResolve resolved value: ${safeStringify(value)}`);
|
|
1033
|
+
return value;
|
|
1034
|
+
}
|
|
1035
|
+
catch (err) {
|
|
1036
|
+
const vaultError = createVaultError(err, ctx.featureCellKey);
|
|
1037
|
+
vaultDebug(`${this.key} computeResolve caught error: ${vaultError.message}`);
|
|
1038
|
+
throw vaultError;
|
|
1039
|
+
}
|
|
1040
|
+
}
|
|
1041
|
+
/**
|
|
1042
|
+
* Invoked when the behavior instance is destroyed.
|
|
1043
|
+
*/
|
|
1044
|
+
destroy() {
|
|
1045
|
+
vaultWarn(`${this.key} - destroy "noop"`);
|
|
1046
|
+
}
|
|
1047
|
+
/**
|
|
1048
|
+
* Resets the resolve behavior to its initial state.
|
|
1049
|
+
*/
|
|
1050
|
+
reset() {
|
|
1051
|
+
vaultWarn(`${this.key} - reset "noop"`);
|
|
1052
|
+
}
|
|
1053
|
+
};
|
|
1054
|
+
withCoreObservableBehavior = withCoreObservableBehavior_1 = __decorate([
|
|
1055
|
+
VaultBehavior({
|
|
1056
|
+
type: BehaviorTypes.Resolve,
|
|
1057
|
+
key: defineBehaviorKey('Core', 'Observable'),
|
|
1058
|
+
critical: false,
|
|
1059
|
+
resolveType: ResolveTypes.Observable
|
|
1060
|
+
})
|
|
1061
|
+
], withCoreObservableBehavior);
|
|
1062
|
+
|
|
1063
|
+
var withCorePromiseBehavior_1;
|
|
1064
|
+
/**
|
|
1065
|
+
* Core resolve behavior that extracts a value from a deferred promise factory.
|
|
1066
|
+
*
|
|
1067
|
+
* This behavior participates in the resolve stage and handles incoming
|
|
1068
|
+
* deferred factories by invoking the factory exactly once and resolving
|
|
1069
|
+
* with the resulting value. Errors are normalized and propagated through
|
|
1070
|
+
* the pipeline error handling contract.
|
|
1071
|
+
*/
|
|
1072
|
+
let withCorePromiseBehavior = class withCorePromiseBehavior {
|
|
1073
|
+
static { withCorePromiseBehavior_1 = this; }
|
|
1074
|
+
behaviorCtx;
|
|
1075
|
+
/** Static behavior type used for orchestrator classification. */
|
|
1076
|
+
static type;
|
|
1077
|
+
/** Unique behavior key used for diagnostics and devtools. */
|
|
1078
|
+
static key;
|
|
1079
|
+
/** Indicates whether this behavior is required by the pipeline. */
|
|
1080
|
+
static critical;
|
|
1081
|
+
/** Resolve type classification for promise-based resolution. */
|
|
1082
|
+
static resolveType;
|
|
1083
|
+
/** The pipeline behavior type identifier. */
|
|
1084
|
+
type = withCorePromiseBehavior_1.type;
|
|
1085
|
+
/** Unique identifier for this behavior instance. */
|
|
1086
|
+
key;
|
|
1087
|
+
/** Indicates that this behavior is optional within the pipeline. */
|
|
1088
|
+
critical = withCorePromiseBehavior_1.critical;
|
|
1089
|
+
/** Resolve type identifier for promise-based resolution. */
|
|
1090
|
+
resolveType = withCorePromiseBehavior_1.resolveType;
|
|
1091
|
+
/**
|
|
1092
|
+
* Creates a new promise resolve behavior instance.
|
|
1093
|
+
*
|
|
1094
|
+
* @param key Unique behavior identifier supplied by the factory.
|
|
1095
|
+
* @param behaviorCtx Behavior class context for dependency injection and configuration.
|
|
1096
|
+
*/
|
|
1097
|
+
constructor(key, behaviorCtx) {
|
|
1098
|
+
this.behaviorCtx = behaviorCtx;
|
|
1099
|
+
this.key = key;
|
|
1100
|
+
}
|
|
1101
|
+
/**
|
|
1102
|
+
* Resolves a state value from a deferred promise factory.
|
|
1103
|
+
*
|
|
1104
|
+
* @param ctx The resolve behavior context containing the incoming value.
|
|
1105
|
+
* @returns The resolved state value or undefined if resolution is skipped.
|
|
1106
|
+
*/
|
|
1107
|
+
async computeResolve(ctx) {
|
|
1108
|
+
const incoming = ctx.incoming;
|
|
1109
|
+
vaultDebug(`${this.key} computeResolve promise called with incoming: ${safeStringify(incoming)}`);
|
|
1110
|
+
if (!(isDeferredFactory(incoming) || isFunction(incoming)) || isUndefined(incoming)) {
|
|
1111
|
+
vaultDebug(`${this.key} computeResolve skipped — incoming is not a deferred factory.`);
|
|
1112
|
+
return;
|
|
1113
|
+
}
|
|
1114
|
+
vaultDebug(`${this.key} computeResolve detected Promise input.`);
|
|
1115
|
+
try {
|
|
1116
|
+
let value;
|
|
1117
|
+
if (isFunction(incoming)) {
|
|
1118
|
+
value = (await incoming?.());
|
|
1119
|
+
}
|
|
1120
|
+
else {
|
|
1121
|
+
value = (await incoming.value?.());
|
|
1122
|
+
}
|
|
1123
|
+
vaultDebug(`${this.key} computeResolve resolved value: ${safeStringify(value)}`);
|
|
1124
|
+
return value;
|
|
1125
|
+
}
|
|
1126
|
+
catch (err) {
|
|
1127
|
+
const vaultError = createVaultError(err, ctx.featureCellKey);
|
|
1128
|
+
vaultDebug(`${this.key} computeResolve caught error: ${vaultError.message}`);
|
|
1129
|
+
throw vaultError;
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
/**
|
|
1133
|
+
* Invoked when the behavior instance is destroyed.
|
|
1134
|
+
*/
|
|
1135
|
+
destroy() {
|
|
1136
|
+
vaultWarn(`${this.key} - destroy "noop"`);
|
|
1137
|
+
}
|
|
1138
|
+
/**
|
|
1139
|
+
* Resets the resolve behavior to its initial state.
|
|
1140
|
+
*/
|
|
1141
|
+
reset() {
|
|
1142
|
+
vaultWarn(`${this.key} - reset "noop"`);
|
|
1143
|
+
}
|
|
1144
|
+
};
|
|
1145
|
+
withCorePromiseBehavior = withCorePromiseBehavior_1 = __decorate([
|
|
1146
|
+
VaultBehavior({
|
|
1147
|
+
type: BehaviorTypes.Resolve,
|
|
1148
|
+
key: defineBehaviorKey('Core', 'Promise'),
|
|
1149
|
+
critical: false,
|
|
1150
|
+
resolveType: ResolveTypes.Promise
|
|
1151
|
+
})
|
|
1152
|
+
], withCorePromiseBehavior);
|
|
1153
|
+
|
|
1154
|
+
var withCoreValueBehavior_1;
|
|
1155
|
+
/**
|
|
1156
|
+
* Core resolve behavior that extracts a plain value from an incoming state envelope.
|
|
1157
|
+
*
|
|
1158
|
+
* This behavior participates in the resolve stage and handles direct value-based
|
|
1159
|
+
* state inputs by safely normalizing the contained value. Objects and arrays are
|
|
1160
|
+
* shallow-cloned to preserve immutability guarantees, while null and undefined
|
|
1161
|
+
* values are handled explicitly according to pipeline semantics.
|
|
1162
|
+
*/
|
|
1163
|
+
let withCoreValueBehavior = class withCoreValueBehavior {
|
|
1164
|
+
static { withCoreValueBehavior_1 = this; }
|
|
1165
|
+
behaviorCtx;
|
|
1166
|
+
/** Static behavior type for orchestrator classification. */
|
|
1167
|
+
static type;
|
|
1168
|
+
/** Static unique behavior identifier. */
|
|
1169
|
+
static key;
|
|
1170
|
+
/** Static flag marking this behavior as pipeline-critical. */
|
|
1171
|
+
static critical;
|
|
1172
|
+
/** Resolve type classification for value-based resolution. */
|
|
1173
|
+
static resolveType;
|
|
1174
|
+
/** Instance-level pipeline type identifier. */
|
|
1175
|
+
type = withCoreValueBehavior_1.type;
|
|
1176
|
+
/** Indicates this resolve behavior is required for pipeline operation. */
|
|
1177
|
+
critical = withCoreValueBehavior_1.critical;
|
|
1178
|
+
/** Unique behavior key for the instance. */
|
|
1179
|
+
key;
|
|
1180
|
+
/** Resolve mode indicating plain value resolution. */
|
|
1181
|
+
resolveType = withCoreValueBehavior_1.resolveType;
|
|
1182
|
+
/**
|
|
1183
|
+
* Creates a new value resolve behavior instance.
|
|
1184
|
+
*
|
|
1185
|
+
* @param key Unique behavior identifier assigned by the factory.
|
|
1186
|
+
* @param behaviorCtx Behavior class context for dependency injection and configuration.
|
|
1187
|
+
*/
|
|
1188
|
+
constructor(key, behaviorCtx) {
|
|
1189
|
+
this.behaviorCtx = behaviorCtx;
|
|
1190
|
+
this.key = key;
|
|
1191
|
+
}
|
|
1192
|
+
/**
|
|
1193
|
+
* Resolves a state value from a plain state envelope.
|
|
1194
|
+
*
|
|
1195
|
+
* @param ctx Resolve context containing the incoming state packet.
|
|
1196
|
+
* @returns The normalized resolved value, a clear signal, or undefined.
|
|
1197
|
+
*/
|
|
1198
|
+
async computeResolve(ctx) {
|
|
1199
|
+
vaultDebug(`${this.key} computeResolve called with "${safeStringify(ctx.incoming)}".`);
|
|
1200
|
+
const incoming = ctx.incoming;
|
|
1201
|
+
if (!incoming || isHttpResourceRef(incoming)) {
|
|
1202
|
+
vaultDebug(`${this.key} computeResolve skipped - not a valid plain state.`);
|
|
1203
|
+
return;
|
|
1204
|
+
}
|
|
1205
|
+
const { value } = incoming;
|
|
1206
|
+
if (value === undefined) {
|
|
1207
|
+
vaultDebug(`${this.key} value is undefined and resolution skipped.`);
|
|
1208
|
+
return;
|
|
1209
|
+
}
|
|
1210
|
+
if (value === null) {
|
|
1211
|
+
vaultDebug(`${this.key} value is null and clear state returned.`);
|
|
1212
|
+
return VAULT_CLEAR_STATE;
|
|
1213
|
+
}
|
|
1214
|
+
if (Array.isArray(value)) {
|
|
1215
|
+
vaultDebug(`${this.key} array value detected and cloned.`);
|
|
1216
|
+
return [...value];
|
|
1217
|
+
}
|
|
1218
|
+
if (typeof value === 'object') {
|
|
1219
|
+
vaultDebug(`${this.key} object value detected and cloned.`);
|
|
1220
|
+
return { ...value };
|
|
1221
|
+
}
|
|
1222
|
+
vaultDebug(`${this.key} primitive value detected and returned.`);
|
|
1223
|
+
return value;
|
|
1224
|
+
}
|
|
1225
|
+
/**
|
|
1226
|
+
* Invoked when the behavior instance is destroyed.
|
|
1227
|
+
*/
|
|
1228
|
+
destroy() {
|
|
1229
|
+
vaultWarn(`${this.key} - destroy "noop"`);
|
|
1230
|
+
}
|
|
1231
|
+
/**
|
|
1232
|
+
* Resets the resolve behavior to its initial state.
|
|
1233
|
+
*/
|
|
1234
|
+
reset() {
|
|
1235
|
+
vaultWarn(`${this.key} - reset "noop"`);
|
|
1236
|
+
}
|
|
1237
|
+
};
|
|
1238
|
+
withCoreValueBehavior = withCoreValueBehavior_1 = __decorate([
|
|
1239
|
+
VaultBehavior({
|
|
1240
|
+
type: BehaviorTypes.Resolve,
|
|
1241
|
+
key: defineBehaviorKey('Core', 'Value'),
|
|
1242
|
+
critical: true,
|
|
1243
|
+
resolveType: ResolveTypes.Value
|
|
1244
|
+
})
|
|
1245
|
+
], withCoreValueBehavior);
|
|
1246
|
+
|
|
1247
|
+
/**
|
|
1248
|
+
* Extends a FeatureCell instance with a placeholder `fromStream` API.
|
|
1249
|
+
*
|
|
1250
|
+
* This function installs a stub implementation that is replaced at runtime
|
|
1251
|
+
* by the corresponding behavior. It defines the method shape so that
|
|
1252
|
+
* consumers may invoke `fromStream` once the behavior is installed.
|
|
1253
|
+
*
|
|
1254
|
+
* @param cell The FeatureCell instance being extended.
|
|
1255
|
+
*/
|
|
1256
|
+
function extendFromStream(cell) {
|
|
1257
|
+
/**
|
|
1258
|
+
* Bridges a streaming observable source into the FeatureCell pipeline.
|
|
1259
|
+
*
|
|
1260
|
+
* @param _source$ Observable stream emitting values to be resolved.
|
|
1261
|
+
* @param _options Optional stream configuration options.
|
|
1262
|
+
*/
|
|
1263
|
+
cell.fromStream = function (_source$, _options) { };
|
|
1264
|
+
}
|
|
1265
|
+
|
|
1266
|
+
// --- AI Model File Path (DO NOT DELETE) ---
|
|
1267
|
+
// FilePath: libs > core > src > lib > behaviors > resolve > from-stream > with-core-from-stream.behavior.ts
|
|
1268
|
+
// Updated: 2026-03-02 08:26
|
|
1269
|
+
// Generated by pathcomment [tab] (see .vscode/typescript.code-snippets) or
|
|
1270
|
+
// cmd+alt+j (see .vscode/keybindings.json)
|
|
1271
|
+
// --- END AI MODEL FILE PATH ---
|
|
1272
|
+
// --- AI Model File Path (DO NOT DELETE) ---
|
|
1273
|
+
var withCoreFromStreamBehavior_1;
|
|
1274
|
+
let withCoreFromStreamBehavior = class withCoreFromStreamBehavior {
|
|
1275
|
+
static { withCoreFromStreamBehavior_1 = this; }
|
|
1276
|
+
behaviorCtx;
|
|
1277
|
+
/** Static behavior to extend the cell api dynamically */
|
|
1278
|
+
static extension = extendFromStream;
|
|
1279
|
+
/** Static behavior type used for orchestrator classification. */
|
|
1280
|
+
static type;
|
|
1281
|
+
/** Unique behavior key used for diagnostics and devtools. */
|
|
1282
|
+
static key;
|
|
1283
|
+
/** Indicates whether this behavior is required by the pipeline. */
|
|
1284
|
+
static critical;
|
|
1285
|
+
static resolveType;
|
|
1286
|
+
/** The extension behavior type identifier. */
|
|
1287
|
+
type = withCoreFromStreamBehavior_1.type;
|
|
1288
|
+
/** Unique identifier for this behavior instance. */
|
|
1289
|
+
key;
|
|
1290
|
+
/** Indicates that this behavior is optional within the pipeline. */
|
|
1291
|
+
critical = withCoreFromStreamBehavior_1.critical;
|
|
1292
|
+
resolveType = withCoreFromStreamBehavior_1.resolveType;
|
|
1293
|
+
constructor(key, behaviorCtx) {
|
|
1294
|
+
this.behaviorCtx = behaviorCtx;
|
|
1295
|
+
this.key = key;
|
|
1296
|
+
}
|
|
1297
|
+
extendCellAPI(ctx) {
|
|
1298
|
+
return {
|
|
1299
|
+
fromStream: (source$, options) => {
|
|
1300
|
+
const { autoResetError = true } = options ?? {};
|
|
1301
|
+
vaultDebug(`${this.key} fromStream called.`);
|
|
1302
|
+
vaultDebug(`${this.key} fromStream options resolved (autoResetError=${autoResetError}).`);
|
|
1303
|
+
ctx.vaultMonitor.ingressSubscribed(ctx.featureCellKey, this.key, ctx, 'fromStream');
|
|
1304
|
+
vaultDebug(`${this.key} fromStream subscription started.`);
|
|
1305
|
+
source$.pipe(takeUntil(ctx.destroyed$)).subscribe({
|
|
1306
|
+
next: (incomingItem) => {
|
|
1307
|
+
vaultDebug(`${this.key} subscription.next called.`);
|
|
1308
|
+
vaultDebug(`${this.key} incoming value received: "${safeStringify(incomingItem)}".`);
|
|
1309
|
+
if (autoResetError) {
|
|
1310
|
+
vaultDebug(`${this.key} autoResetError enabled → clearing error.`);
|
|
1311
|
+
}
|
|
1312
|
+
const nextState = autoResetError
|
|
1313
|
+
? { value: incomingItem, error: null }
|
|
1314
|
+
: { value: incomingItem };
|
|
1315
|
+
ctx.mergeState(nextState);
|
|
1316
|
+
vaultDebug(`${this.key} mergeState invoked from stream.next.`);
|
|
1317
|
+
},
|
|
1318
|
+
error: (err) => {
|
|
1319
|
+
vaultDebug(`${this.key} subscription.error called.`);
|
|
1320
|
+
const vaultError = createVaultError(err, this.key);
|
|
1321
|
+
vaultDebug(`${this.key} stream error converted to VaultError: "${vaultError.message}".`);
|
|
1322
|
+
ctx.mergeState({ error: vaultError });
|
|
1323
|
+
vaultDebug(`${this.key} mergeState invoked from stream.error.`);
|
|
1324
|
+
},
|
|
1325
|
+
complete: () => {
|
|
1326
|
+
vaultDebug(`${this.key} subscription.complete called.`);
|
|
1327
|
+
ctx.vaultMonitor.ingressCompleted(ctx.featureCellKey, this.key, ctx, 'fromStream');
|
|
1328
|
+
vaultDebug(`${this.key} fromStream completed.`);
|
|
1329
|
+
}
|
|
1330
|
+
});
|
|
1331
|
+
}
|
|
1332
|
+
};
|
|
1333
|
+
}
|
|
1334
|
+
destroy() {
|
|
1335
|
+
vaultWarn(`${this.key} - destroy "noop"`);
|
|
1336
|
+
}
|
|
1337
|
+
reset() {
|
|
1338
|
+
vaultWarn(`${this.key} - reset "noop"`);
|
|
1339
|
+
}
|
|
1340
|
+
};
|
|
1341
|
+
withCoreFromStreamBehavior = withCoreFromStreamBehavior_1 = __decorate([
|
|
1342
|
+
VaultBehavior({
|
|
1343
|
+
type: BehaviorTypes.FromStream,
|
|
1344
|
+
key: defineBehaviorKey('Core', 'FromStream'),
|
|
1345
|
+
critical: false,
|
|
1346
|
+
resolveType: ResolveTypes.Observable
|
|
1347
|
+
})
|
|
1348
|
+
], withCoreFromStreamBehavior);
|
|
1349
|
+
|
|
1350
|
+
/**
|
|
1351
|
+
* Core behavior responsible for invoking `emitState` callbacks.
|
|
1352
|
+
*
|
|
1353
|
+
* This behavior executes a consumer-provided callback with the current
|
|
1354
|
+
* immutable state snapshot, allowing external observers to react to
|
|
1355
|
+
* state emission events without mutating pipeline state.
|
|
1356
|
+
*
|
|
1357
|
+
* It is critical to pipeline execution and always runs during emitState
|
|
1358
|
+
* processing when a callback is provided.
|
|
1359
|
+
*/
|
|
1360
|
+
let withCoreEmitStateBehavior = class withCoreEmitStateBehavior {
|
|
1361
|
+
behaviorCtx;
|
|
1362
|
+
/** Static behavior type used for pipeline classification. */
|
|
1363
|
+
static type;
|
|
1364
|
+
/** Unique behavior key used for introspection and diagnostics. */
|
|
1365
|
+
static key;
|
|
1366
|
+
/** Indicates that emitState behavior is required in the pipeline. */
|
|
1367
|
+
static critical;
|
|
1368
|
+
/** Instance-level pipeline behavior type identifier. */
|
|
1369
|
+
type = BehaviorTypes.CoreEmitState;
|
|
1370
|
+
/** Indicates that this behavior must always run during emitState execution. */
|
|
1371
|
+
critical = true;
|
|
1372
|
+
/** Unique identifier for this emitState behavior instance. */
|
|
1373
|
+
key;
|
|
1374
|
+
/**
|
|
1375
|
+
* Creates a new core emitState behavior instance.
|
|
1376
|
+
*
|
|
1377
|
+
* @param key Unique behavior identifier supplied by the factory.
|
|
1378
|
+
* @param behaviorCtx Behavior class context for dependency injection and extensibility.
|
|
1379
|
+
*/
|
|
1380
|
+
constructor(key, behaviorCtx) {
|
|
1381
|
+
this.behaviorCtx = behaviorCtx;
|
|
1382
|
+
this.key = key;
|
|
1383
|
+
}
|
|
1384
|
+
/**
|
|
1385
|
+
* Executes a provided emitState callback with the current state snapshot.
|
|
1386
|
+
*
|
|
1387
|
+
* If the callback is not a function or throws during execution, the behavior
|
|
1388
|
+
* logs the failure and returns `VAULT_NOOP` without interrupting pipeline flow.
|
|
1389
|
+
*
|
|
1390
|
+
* @param snapshot Immutable snapshot of the current FeatureCell state.
|
|
1391
|
+
* @param callback Consumer-provided emitState callback.
|
|
1392
|
+
* @returns A core emitState result or `VAULT_NOOP` when no action is taken.
|
|
1393
|
+
*/
|
|
1394
|
+
// eslint-disable-next-line
|
|
1395
|
+
emitState(snapshot, callback) {
|
|
1396
|
+
vaultDebug(`${this.key} emitState called with "${safeStringify(snapshot)}".`);
|
|
1397
|
+
if (typeof callback !== 'function') {
|
|
1398
|
+
vaultDebug(`${this.key} emitState skipped. The emitState type is ${typeof callback}. "${safeStringify(snapshot)}" returned.`);
|
|
1399
|
+
return VAULT_NOOP;
|
|
1400
|
+
}
|
|
1401
|
+
try {
|
|
1402
|
+
callback(snapshot);
|
|
1403
|
+
}
|
|
1404
|
+
catch (err) {
|
|
1405
|
+
vaultError(`${this.key} emitState execution failed`, safeStringify(err));
|
|
1406
|
+
return VAULT_NOOP;
|
|
1407
|
+
}
|
|
1408
|
+
return;
|
|
1409
|
+
}
|
|
1410
|
+
/**
|
|
1411
|
+
* Performs cleanup when the behavior instance is destroyed.
|
|
1412
|
+
*/
|
|
1413
|
+
destroy() {
|
|
1414
|
+
vaultWarn(`${this.key} - destroy "noop"`);
|
|
1415
|
+
}
|
|
1416
|
+
/**
|
|
1417
|
+
* Resets the emitState behavior.
|
|
1418
|
+
*
|
|
1419
|
+
* This behavior does not retain internal state and therefore requires
|
|
1420
|
+
* no reset logic beyond lifecycle participation.
|
|
1421
|
+
*/
|
|
1422
|
+
reset() {
|
|
1423
|
+
vaultWarn(`${this.key} - reset "noop"`);
|
|
1424
|
+
}
|
|
1425
|
+
};
|
|
1426
|
+
withCoreEmitStateBehavior = __decorate([
|
|
1427
|
+
VaultBehavior({
|
|
1428
|
+
type: BehaviorTypes.CoreEmitState,
|
|
1429
|
+
key: defineBehaviorKey('Core', 'EmitState'),
|
|
1430
|
+
critical: true
|
|
1431
|
+
})
|
|
1432
|
+
], withCoreEmitStateBehavior);
|
|
1433
|
+
|
|
1434
|
+
/**
|
|
1435
|
+
* Canonical identifier used to mark values or errors originating outside the Vault pipeline.
|
|
1436
|
+
*/
|
|
1437
|
+
const VAULT_EXTERNAL = 'external';
|
|
1438
|
+
|
|
1439
|
+
var withCoreStateBehavior_1;
|
|
1440
|
+
/**
|
|
1441
|
+
* Core behavior responsible for committing resolved pipeline outcomes into state.
|
|
1442
|
+
*
|
|
1443
|
+
* This behavior translates pipeline execution results into immutable state
|
|
1444
|
+
* snapshots and emits authoritative state lifecycle events. It coordinates
|
|
1445
|
+
* loading, value, and error transitions and ensures state emission remains
|
|
1446
|
+
* atomic and ordered.
|
|
1447
|
+
*/
|
|
1448
|
+
let withCoreStateBehavior = class withCoreStateBehavior {
|
|
1449
|
+
static { withCoreStateBehavior_1 = this; }
|
|
1450
|
+
behaviorCtx;
|
|
1451
|
+
/** Static behavior type used for pipeline classification. */
|
|
1452
|
+
static type;
|
|
1453
|
+
/** Unique behavior key used for introspection and diagnostics. */
|
|
1454
|
+
static key;
|
|
1455
|
+
/** Indicates that this behavior is required for pipeline execution. */
|
|
1456
|
+
static critical;
|
|
1457
|
+
/** Instance-level pipeline behavior type identifier. */
|
|
1458
|
+
type = withCoreStateBehavior_1.type;
|
|
1459
|
+
/** Indicates that this behavior must always execute. */
|
|
1460
|
+
critical = withCoreStateBehavior_1.critical;
|
|
1461
|
+
/** Unique identifier for this behavior instance. */
|
|
1462
|
+
key;
|
|
1463
|
+
/**
|
|
1464
|
+
* Creates a new core state behavior instance.
|
|
1465
|
+
*
|
|
1466
|
+
* @param key Unique behavior identifier supplied by the factory.
|
|
1467
|
+
* @param behaviorCtx Behavior class context for dependency injection.
|
|
1468
|
+
*/
|
|
1469
|
+
constructor(key, behaviorCtx) {
|
|
1470
|
+
this.behaviorCtx = behaviorCtx;
|
|
1471
|
+
this.key = key;
|
|
1472
|
+
}
|
|
1473
|
+
/**
|
|
1474
|
+
* Commits partial state changes and emits a single state snapshot event.
|
|
1475
|
+
*
|
|
1476
|
+
* @param ctx Pipeline behavior context containing state references.
|
|
1477
|
+
* @param changes Partial snapshot changes or null.
|
|
1478
|
+
* @param type State emission classification.
|
|
1479
|
+
*/
|
|
1480
|
+
#commitState(ctx, changes, type) {
|
|
1481
|
+
vaultDebug(`${this.key} commitState called with: ${safeStringify(changes)}`);
|
|
1482
|
+
try {
|
|
1483
|
+
if (changes) {
|
|
1484
|
+
const safeChanges = isolateValue(changes);
|
|
1485
|
+
Object.assign(ctx.lastSnapshot, safeChanges);
|
|
1486
|
+
ctx.lastSnapshot.hasValue = ctx.lastSnapshot.value !== undefined && ctx.lastSnapshot.value !== null;
|
|
1487
|
+
}
|
|
1488
|
+
const snapshotEmit = {
|
|
1489
|
+
snapshot: isolateValue(ctx.lastSnapshot),
|
|
1490
|
+
type
|
|
1491
|
+
};
|
|
1492
|
+
if (ctx.options) {
|
|
1493
|
+
snapshotEmit.options = ctx.options;
|
|
1494
|
+
}
|
|
1495
|
+
ctx.state$.next(snapshotEmit);
|
|
1496
|
+
}
|
|
1497
|
+
catch (error) {
|
|
1498
|
+
vaultError(`${this.key} an error occurred updating the state`, error);
|
|
1499
|
+
}
|
|
1500
|
+
}
|
|
1501
|
+
/**
|
|
1502
|
+
* Prepares incoming pipeline input and emits an initial incoming state.
|
|
1503
|
+
*
|
|
1504
|
+
* @param ctx Pipeline behavior context.
|
|
1505
|
+
* @returns The incoming value or `VAULT_NOOP`.
|
|
1506
|
+
*/
|
|
1507
|
+
preparePipelineIncoming(ctx) {
|
|
1508
|
+
const incoming = ctx.incoming;
|
|
1509
|
+
const changes = {};
|
|
1510
|
+
if (isNullish(incoming) || (isStateInputShape(incoming) && isNull(incoming.value))) {
|
|
1511
|
+
changes.isLoading = false;
|
|
1512
|
+
changes.value = undefined;
|
|
1513
|
+
changes.error = null;
|
|
1514
|
+
this.#commitState(ctx, changes, StateEmitTypes.IncomingPipeline);
|
|
1515
|
+
return VAULT_NOOP;
|
|
1516
|
+
}
|
|
1517
|
+
if (isHttpResourceRef(incoming)) {
|
|
1518
|
+
changes.isLoading = true;
|
|
1519
|
+
}
|
|
1520
|
+
else if (isStateInputShape(incoming)) {
|
|
1521
|
+
if (!isNullish(incoming?.loading)) {
|
|
1522
|
+
changes.isLoading = incoming.loading;
|
|
1523
|
+
}
|
|
1524
|
+
if (isDefined(incoming?.error)) {
|
|
1525
|
+
changes.error = isNull(incoming.error) ? null : createVaultError(incoming.error, VAULT_EXTERNAL);
|
|
1526
|
+
}
|
|
1527
|
+
}
|
|
1528
|
+
if (Object.keys(changes).length > 0) {
|
|
1529
|
+
this.#commitState(ctx, changes, StateEmitTypes.IncomingPipeline);
|
|
1530
|
+
}
|
|
1531
|
+
return incoming;
|
|
1532
|
+
}
|
|
1533
|
+
/**
|
|
1534
|
+
* Finalizes state after pipeline resolution completes.
|
|
1535
|
+
*
|
|
1536
|
+
* @param value Final pipeline output.
|
|
1537
|
+
* @param ctx Pipeline behavior context.
|
|
1538
|
+
*/
|
|
1539
|
+
finalizePipelineState(value, ctx) {
|
|
1540
|
+
vaultDebug(`${this.key} - finalizeVaultState`);
|
|
1541
|
+
if (isHttpResourceRef(ctx.incoming)) {
|
|
1542
|
+
this.#commitState(ctx, { isLoading: false }, StateEmitTypes.FinalizePipeline);
|
|
1543
|
+
}
|
|
1544
|
+
if (isVaultNoop(value)) {
|
|
1545
|
+
this.#commitState(ctx, null, StateEmitTypes.FinalizePipeline);
|
|
1546
|
+
return;
|
|
1547
|
+
}
|
|
1548
|
+
if (isNull(value) || isVaultClearState(value)) {
|
|
1549
|
+
this.#commitState(ctx, { value: undefined }, StateEmitTypes.FinalizePipeline);
|
|
1550
|
+
return;
|
|
1551
|
+
}
|
|
1552
|
+
if (!isNullish(value) && !isPipelineTerminal(value)) {
|
|
1553
|
+
this.#commitState(ctx, { value: value }, StateEmitTypes.FinalizePipeline);
|
|
1554
|
+
}
|
|
1555
|
+
}
|
|
1556
|
+
/**
|
|
1557
|
+
* Finalizes state when pipeline execution is stopped.
|
|
1558
|
+
*
|
|
1559
|
+
* @param ctx Pipeline behavior context.
|
|
1560
|
+
*/
|
|
1561
|
+
finalizePipelineVaultStop(ctx) {
|
|
1562
|
+
vaultDebug(`${this.key} - finalizePipelineVaultStop`);
|
|
1563
|
+
this.#commitState(ctx, null, StateEmitTypes.FinalizePipeline);
|
|
1564
|
+
}
|
|
1565
|
+
/**
|
|
1566
|
+
* Finalizes state when a pipeline error occurs.
|
|
1567
|
+
*
|
|
1568
|
+
* @param err Normalized vault error or null.
|
|
1569
|
+
* @param ctx Pipeline behavior context.
|
|
1570
|
+
*/
|
|
1571
|
+
finalizePipelineError(err, ctx) {
|
|
1572
|
+
vaultDebug(`${this.key} - finalizePipelineError`);
|
|
1573
|
+
this.#commitState(ctx, {
|
|
1574
|
+
error: err,
|
|
1575
|
+
value: ctx.lastSnapshot.value,
|
|
1576
|
+
isLoading: false
|
|
1577
|
+
}, StateEmitTypes.PipelineError);
|
|
1578
|
+
}
|
|
1579
|
+
/**
|
|
1580
|
+
* Finalizes state when a controller abort occurs.
|
|
1581
|
+
*
|
|
1582
|
+
* @param ctx Pipeline behavior context.
|
|
1583
|
+
*/
|
|
1584
|
+
finalizeControllerAbort(ctx) {
|
|
1585
|
+
vaultDebug(`${this.key} - finalizeAbort`);
|
|
1586
|
+
this.#commitState(ctx, { isLoading: false }, StateEmitTypes.AbortController);
|
|
1587
|
+
}
|
|
1588
|
+
/**
|
|
1589
|
+
* Finalizes state when a controller deny occurs.
|
|
1590
|
+
*
|
|
1591
|
+
* @param ctx Pipeline behavior context.
|
|
1592
|
+
*/
|
|
1593
|
+
finalizeControllerDeny(ctx) {
|
|
1594
|
+
vaultDebug(`${this.key} - finalizeDeny`);
|
|
1595
|
+
this.#commitState(ctx, { isLoading: false }, StateEmitTypes.DenyController);
|
|
1596
|
+
}
|
|
1597
|
+
/**
|
|
1598
|
+
* Emits a terminal destroy state snapshot.
|
|
1599
|
+
*
|
|
1600
|
+
* @param ctx Pipeline behavior context.
|
|
1601
|
+
*/
|
|
1602
|
+
destroy(ctx) {
|
|
1603
|
+
vaultWarn(`${this.key} - destroy`);
|
|
1604
|
+
this.#commitState(ctx, { isLoading: false, value: undefined, error: null }, StateEmitTypes.PipelineDestroy);
|
|
1605
|
+
}
|
|
1606
|
+
/**
|
|
1607
|
+
* Emits a terminal reset state snapshot.
|
|
1608
|
+
*
|
|
1609
|
+
* @param ctx Pipeline behavior context.
|
|
1610
|
+
*/
|
|
1611
|
+
reset(ctx) {
|
|
1612
|
+
vaultWarn(`${this.key} - reset`);
|
|
1613
|
+
this.#commitState(ctx, { isLoading: false, value: undefined, error: null }, StateEmitTypes.PipelineReset);
|
|
1614
|
+
}
|
|
1615
|
+
};
|
|
1616
|
+
withCoreStateBehavior = withCoreStateBehavior_1 = __decorate([
|
|
1617
|
+
VaultBehavior({
|
|
1618
|
+
type: BehaviorTypes.CoreState,
|
|
1619
|
+
key: defineBehaviorKey('Core', 'State'),
|
|
1620
|
+
critical: true
|
|
1621
|
+
})
|
|
1622
|
+
], withCoreStateBehavior);
|
|
1623
|
+
|
|
1624
|
+
/**
|
|
1625
|
+
* Abstract base class for tap behaviors in the Vault pipeline.
|
|
1626
|
+
*
|
|
1627
|
+
* This class provides shared execution logic for tap behaviors, which are
|
|
1628
|
+
* permitted to observe pipeline values and perform side effects without
|
|
1629
|
+
* modifying pipeline state. It centralizes validation, logging, and lifecycle
|
|
1630
|
+
* handling common to both pre- and post-reducer tap behaviors.
|
|
1631
|
+
*
|
|
1632
|
+
* @typeParam T - The pipeline state value type observed by the tap.
|
|
1633
|
+
*/
|
|
1634
|
+
class TapAbstractBehavior {
|
|
1635
|
+
behaviorCtx;
|
|
1636
|
+
/** Static behavior type used for pipeline classification. */
|
|
1637
|
+
static type;
|
|
1638
|
+
/** Static key used to identify the tap behavior. */
|
|
1639
|
+
static key;
|
|
1640
|
+
/** Indicates that tap behaviors participate critically in the pipeline. */
|
|
1641
|
+
static critical = true;
|
|
1642
|
+
/** Instance-level criticality flag. */
|
|
1643
|
+
critical = true;
|
|
1644
|
+
/** Unique identifier for this tap behavior instance. */
|
|
1645
|
+
key;
|
|
1646
|
+
type;
|
|
1647
|
+
/**
|
|
1648
|
+
* Creates a new tap behavior instance.
|
|
1649
|
+
*
|
|
1650
|
+
* @param key Unique behavior identifier supplied by the factory.
|
|
1651
|
+
* @param behaviorCtx Behavior class context for dependency injection.
|
|
1652
|
+
*/
|
|
1653
|
+
constructor(key, behaviorCtx) {
|
|
1654
|
+
this.behaviorCtx = behaviorCtx;
|
|
1655
|
+
this.key = key;
|
|
1656
|
+
}
|
|
1657
|
+
/**
|
|
1658
|
+
* Executes a tap callback against the current pipeline value.
|
|
1659
|
+
*
|
|
1660
|
+
* The tap callback is invoked for observational or side-effect purposes only.
|
|
1661
|
+
* If the provided callback is not a function, execution is skipped and logged.
|
|
1662
|
+
*
|
|
1663
|
+
* @param current The current pipeline value being observed.
|
|
1664
|
+
* @param tap The tap callback function.
|
|
1665
|
+
*/
|
|
1666
|
+
executeTap(current, tap) {
|
|
1667
|
+
vaultDebug(`${this.key} executeTap called with "${safeStringify(current)}".`);
|
|
1668
|
+
if (typeof tap !== 'function') {
|
|
1669
|
+
vaultDebug(`${this.key} executeTap skipped - tap is not a function. Type is "${typeof tap}".`);
|
|
1670
|
+
}
|
|
1671
|
+
tap(current);
|
|
1672
|
+
}
|
|
1673
|
+
/**
|
|
1674
|
+
* Invoked when the behavior instance is destroyed.
|
|
1675
|
+
*
|
|
1676
|
+
* Tap behaviors do not allocate resources or maintain subscriptions, so
|
|
1677
|
+
* destruction performs no cleanup beyond emitting a diagnostic event.
|
|
1678
|
+
*/
|
|
1679
|
+
destroy() {
|
|
1680
|
+
vaultWarn(`${this.key} - destroy "noop"`);
|
|
1681
|
+
}
|
|
1682
|
+
/**
|
|
1683
|
+
* Resets the tap behavior.
|
|
1684
|
+
*
|
|
1685
|
+
* Tap behaviors are stateless and require no reset logic. This method exists
|
|
1686
|
+
* solely to participate in the FeatureCell lifecycle and provide diagnostic
|
|
1687
|
+
* visibility.
|
|
1688
|
+
*/
|
|
1689
|
+
reset() {
|
|
1690
|
+
vaultWarn(`${this.key} - reset "noop"`);
|
|
1691
|
+
}
|
|
1692
|
+
}
|
|
1693
|
+
|
|
1694
|
+
/**
|
|
1695
|
+
* Core tap behavior executed after reducer completion.
|
|
1696
|
+
*
|
|
1697
|
+
* This behavior allows consumers to observe the finalized pipeline value
|
|
1698
|
+
* after all reducer logic has executed. It delegates tap execution to the
|
|
1699
|
+
* shared tap abstraction and does not modify pipeline state.
|
|
1700
|
+
*
|
|
1701
|
+
* @typeParam T - The pipeline state value type observed by the tap.
|
|
1702
|
+
*/
|
|
1703
|
+
let withCoreAfterTapBehavior = class withCoreAfterTapBehavior extends TapAbstractBehavior {
|
|
1704
|
+
/** Pipeline behavior type indicating execution occurs after reducers. */
|
|
1705
|
+
type = BehaviorTypes.CoreAfterTap;
|
|
1706
|
+
/**
|
|
1707
|
+
* Executes the provided tap callback after reducer completion.
|
|
1708
|
+
*
|
|
1709
|
+
* The tap is invoked for observational or side-effect purposes only and
|
|
1710
|
+
* does not influence pipeline control flow or state resolution.
|
|
1711
|
+
*
|
|
1712
|
+
* @param current - The finalized pipeline value.
|
|
1713
|
+
* @param tap - The tap callback to invoke.
|
|
1714
|
+
*/
|
|
1715
|
+
applyAfterTap(current, tap) {
|
|
1716
|
+
this.executeTap(current, tap);
|
|
1717
|
+
}
|
|
1718
|
+
};
|
|
1719
|
+
withCoreAfterTapBehavior = __decorate([
|
|
1720
|
+
VaultBehavior({
|
|
1721
|
+
type: BehaviorTypes.CoreAfterTap,
|
|
1722
|
+
key: defineBehaviorKey('Core', 'AfterTap'),
|
|
1723
|
+
critical: true
|
|
1724
|
+
})
|
|
1725
|
+
], withCoreAfterTapBehavior);
|
|
1726
|
+
|
|
1727
|
+
/**
|
|
1728
|
+
* Core tap behavior executed before reducer evaluation.
|
|
1729
|
+
*
|
|
1730
|
+
* This behavior allows consumers to observe or react to the pipeline value
|
|
1731
|
+
* prior to reducer execution. It delegates tap execution to the shared tap
|
|
1732
|
+
* abstraction and does not modify pipeline state or control flow.
|
|
1733
|
+
*
|
|
1734
|
+
* @typeParam T - The pipeline state value type observed by the tap.
|
|
1735
|
+
*/
|
|
1736
|
+
let withCoreBeforeTapBehavior = class withCoreBeforeTapBehavior extends TapAbstractBehavior {
|
|
1737
|
+
/** Pipeline behavior type indicating execution occurs prior to reducers. */
|
|
1738
|
+
type = BehaviorTypes.CoreBeforeTap;
|
|
1739
|
+
/**
|
|
1740
|
+
* Executes the provided tap callback before reducer evaluation.
|
|
1741
|
+
*
|
|
1742
|
+
* The tap is invoked for observational or side-effect purposes only and
|
|
1743
|
+
* does not influence reducer logic or state resolution.
|
|
1744
|
+
*
|
|
1745
|
+
* @param current - The current pipeline value prior to reduction.
|
|
1746
|
+
* @param tap - The tap callback to invoke.
|
|
1747
|
+
*/
|
|
1748
|
+
applyBeforeTap(current, tap) {
|
|
1749
|
+
this.executeTap(current, tap);
|
|
1750
|
+
}
|
|
1751
|
+
};
|
|
1752
|
+
withCoreBeforeTapBehavior = __decorate([
|
|
1753
|
+
VaultBehavior({
|
|
1754
|
+
type: BehaviorTypes.CoreBeforeTap,
|
|
1755
|
+
key: defineBehaviorKey('Core', 'BeforeTap'),
|
|
1756
|
+
critical: true
|
|
1757
|
+
})
|
|
1758
|
+
], withCoreBeforeTapBehavior);
|
|
1759
|
+
|
|
1760
|
+
// --- AI Model File Path (DO NOT DELETE) ---
|
|
1761
|
+
// FilePath: libs > core > src > lib > factories > feature-cell > feature-cell.ts
|
|
1762
|
+
// Updated: 2026-03-02 19:53
|
|
1763
|
+
// Generated by pathcomment [tab] (see .vscode/typescript.code-snippets) or
|
|
1764
|
+
// cmd+alt+j (see .vscode/keybindings.json)
|
|
1765
|
+
// --- END AI MODEL FILE PATH ---
|
|
1766
|
+
/**
|
|
1767
|
+
* Creates and registers a Feature Cell using the provided configuration and optional behavior and controller contracts.
|
|
1768
|
+
* This function produces a Feature Cell instance keyed by the descriptor and registers it for later resolution and usage.
|
|
1769
|
+
*
|
|
1770
|
+
* --RelatedStart--
|
|
1771
|
+
* FeatureCellConfig
|
|
1772
|
+
* BehaviorClassContract
|
|
1773
|
+
* ControllerClassContract
|
|
1774
|
+
* FeatureCellShape
|
|
1775
|
+
* --RelatedEnd--
|
|
1776
|
+
*
|
|
1777
|
+
* @param descriptor Configuration descriptor that defines the Feature Cell identity and setup.
|
|
1778
|
+
* @param behaviors Behavior class contracts applied during Feature Cell construction.
|
|
1779
|
+
* @param controllers Controller class contracts applied during Feature Cell construction.
|
|
1780
|
+
* @returns The registered Feature Cell instance.
|
|
1781
|
+
*/
|
|
1782
|
+
function FeatureCell(descriptor, behaviors = [], controllers = []) {
|
|
1783
|
+
createFeatureCellToken(descriptor.key);
|
|
1784
|
+
registerFeatureCell({
|
|
1785
|
+
key: descriptor.key
|
|
1786
|
+
});
|
|
1787
|
+
return new FeatureCellClass(descriptor, loadDefaultBehaviors(), behaviors, controllers).build();
|
|
1788
|
+
}
|
|
1789
|
+
function loadDefaultBehaviors() {
|
|
1790
|
+
return [
|
|
1791
|
+
withCoreAfterTapBehavior,
|
|
1792
|
+
withCoreBeforeTapBehavior,
|
|
1793
|
+
withCoreErrorBehavior,
|
|
1794
|
+
withCoreFilterBehavior,
|
|
1795
|
+
withCoreFromObservableBehavior,
|
|
1796
|
+
withCoreFromPromiseBehavior,
|
|
1797
|
+
withCoreFromStreamBehavior,
|
|
1798
|
+
withCoreObservableBehavior,
|
|
1799
|
+
withCorePromiseBehavior,
|
|
1800
|
+
withCoreReducerBehavior,
|
|
1801
|
+
withCoreValueBehavior,
|
|
1802
|
+
withCoreStateBehavior,
|
|
1803
|
+
withCoreErrorCallbackBehavior,
|
|
1804
|
+
withArrayMergeBehavior,
|
|
1805
|
+
withCoreEmitStateBehavior
|
|
1806
|
+
];
|
|
1807
|
+
}
|
|
1808
|
+
|
|
1809
|
+
// --- AI Model File Path (DO NOT DELETE) ---
|
|
1810
|
+
// FilePath: libs > core > src > lib > factories > vault > vault.ts
|
|
1811
|
+
// Updated: 2026-03-02 19:51
|
|
1812
|
+
// Generated by pathcomment [tab] (see .vscode/typescript.code-snippets) or
|
|
1813
|
+
// cmd+alt+j (see .vscode/keybindings.json)
|
|
1814
|
+
// --- END AI MODEL FILE PATH ---
|
|
1815
|
+
/**
|
|
1816
|
+
* Initializes the Vault runtime using the provided configuration and prepares the global feature cell registry.
|
|
1817
|
+
* This function establishes the required Vault infrastructure and applies the supplied options for core initialization.
|
|
1818
|
+
*
|
|
1819
|
+
* --RelatedStart--
|
|
1820
|
+
* VaultConfig
|
|
1821
|
+
* --RelatedEnd--
|
|
1822
|
+
*
|
|
1823
|
+
* @param options Configuration options used to initialize the Vault runtime.
|
|
1824
|
+
*/
|
|
1825
|
+
function Vault(options = {}) {
|
|
1826
|
+
VaultCore(options);
|
|
1827
|
+
}
|
|
1828
|
+
|
|
1829
|
+
// --- AI Model File Path (DO NOT DELETE) ---
|
|
1830
|
+
// FilePath: libs > core > src > public-api.ts
|
|
1831
|
+
// Updated: 2026-03-03 07:37
|
|
1832
|
+
// Generated by pathcomment [tab] (see .vscode/typescript.code-snippets) or
|
|
1833
|
+
// cmd+alt+j (see .vscode/keybindings.json)
|
|
1834
|
+
// --- END AI MODEL FILE PATH ---
|
|
1835
|
+
|
|
1836
|
+
/**
|
|
1837
|
+
* Generated bundle index. Do not edit.
|
|
1838
|
+
*/
|
|
1839
|
+
|
|
1840
|
+
export { FeatureCell, Vault, __core_extensions_loaded, __fromObservable, __fromPromise_extension, __fromStream_extension, withObjectShallowMergeBehavior };
|
|
1841
|
+
//# sourceMappingURL=sdux-vault-core.mjs.map
|