@cldmv/slothlet-types 3.15.2 → 3.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/builders/api-assignment.d.mts +125 -4
- package/lib/builders/api_builder.d.mts +104 -7
- package/lib/builders/builder.d.mts +82 -1
- package/lib/builders/modes-processor.d.mts +66 -3
- package/lib/errors.d.mts +114 -19
- package/lib/factories/component-base.d.mts +171 -8
- package/lib/factories/context.d.mts +22 -4
- package/lib/handlers/api-cache-manager.d.mts +209 -20
- package/lib/handlers/api-manager.d.mts +539 -38
- package/lib/handlers/context-async.d.mts +92 -25
- package/lib/handlers/context-live.d.mts +117 -30
- package/lib/handlers/framework-internals.d.mts +33 -2
- package/lib/handlers/hook-manager.d.mts +306 -73
- package/lib/handlers/lifecycle-token.d.mts +48 -3
- package/lib/handlers/lifecycle.d.mts +86 -5
- package/lib/handlers/materialize-manager.d.mts +76 -8
- package/lib/handlers/metadata.d.mts +238 -18
- package/lib/handlers/module-manager.d.mts +169 -21
- package/lib/handlers/ownership.d.mts +376 -45
- package/lib/handlers/permission-manager.d.mts +283 -46
- package/lib/handlers/routine-manager.d.mts +425 -0
- package/lib/handlers/trusted-root.d.mts +45 -4
- package/lib/handlers/unified-wrapper.d.mts +287 -26
- package/lib/handlers/version-manager.d.mts +236 -29
- package/lib/helpers/caller-pinning.d.mts +21 -2
- package/lib/helpers/class-instance-wrapper.d.mts +56 -2
- package/lib/helpers/config.d.mts +311 -161
- package/lib/helpers/defaults.d.mts +40 -0
- package/lib/helpers/eventemitter-context.d.mts +29 -3
- package/lib/helpers/eventtarget-context.d.mts +19 -1
- package/lib/helpers/eventtarget-property-context.d.mts +21 -0
- package/lib/helpers/generate-manifest.d.mts +174 -7
- package/lib/helpers/hint-detector.d.mts +22 -2
- package/lib/helpers/manifest-resolver.d.mts +100 -1
- package/lib/helpers/modes-utils.d.mts +30 -3
- package/lib/helpers/module-discovery.d.mts +80 -7
- package/lib/helpers/module-manifest-validator.d.mts +36 -13
- package/lib/helpers/module-sort.d.mts +64 -1
- package/lib/helpers/observer-context.d.mts +21 -0
- package/lib/helpers/pattern-matcher.d.mts +43 -3
- package/lib/helpers/platform.d.mts +109 -10
- package/lib/helpers/resolve-from-caller.d.mts +27 -3
- package/lib/helpers/sanitize.d.mts +92 -4
- package/lib/helpers/scheduler-context.d.mts +21 -1
- package/lib/helpers/utilities.d.mts +52 -4
- package/lib/i18n/translations.d.mts +50 -5
- package/lib/modes/eager.d.mts +46 -8
- package/lib/modes/lazy.d.mts +57 -10
- package/lib/processors/flatten.d.mts +116 -56
- package/lib/processors/loader.d.mts +77 -10
- package/lib/processors/type-generator.d.mts +16 -2
- package/lib/processors/typescript.d.mts +169 -13
- package/lib/runtime/runtime-asynclocalstorage.d.mts +71 -3
- package/lib/runtime/runtime-livebindings.d.mts +37 -2
- package/lib/runtime/runtime.d.mts +39 -3
- package/lib/typegen/typegen.d.mts +34 -2
- package/package.json +5 -23
- package/slothlet.d.mts +428 -3
|
@@ -1,32 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AsyncLocalStorage-based context manager for async runtime
|
|
3
|
+
* Uses ALS for full context isolation across async operations
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
1
6
|
export class AsyncContextManager {
|
|
2
7
|
als: any;
|
|
3
8
|
instances: Map<any, any>;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Register the EventEmitter context checker
|
|
11
|
+
* Must be called AFTER EventEmitter patching is enabled
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
public registerEventEmitterContextChecker(): void;
|
|
15
|
+
/**
|
|
16
|
+
* Initialize context for a new instance
|
|
17
|
+
* @param {string} instanceID - Unique instance identifier
|
|
18
|
+
* @param {Object} config - Instance configuration
|
|
19
|
+
* @returns {Object} Created context store
|
|
20
|
+
* @public
|
|
21
|
+
*/
|
|
22
|
+
public initialize(instanceID: string, config?: Object): Object;
|
|
23
|
+
/**
|
|
24
|
+
* Run function with instance context active
|
|
25
|
+
* @param {string} instanceID - Instance to run in context of
|
|
26
|
+
* @param {Function} fn - Function to execute
|
|
27
|
+
* @param {*} thisArg - this binding for function
|
|
28
|
+
* @param {Array} args - Arguments to pass to function
|
|
29
|
+
* @param {Object} [currentWrapper] - Current wrapper being executed (for metadata.self())
|
|
30
|
+
* @param {boolean} [rawErrors=false] - When `true`, let a non-SlothletError thrown by
|
|
31
|
+
* `fn` propagate unchanged instead of wrapping it as `CONTEXT_EXECUTION_FAILED`. Used
|
|
32
|
+
* for framework callbacks (`lockCaller`, pinned hooks) where the caller expects the
|
|
33
|
+
* original error type/code/status.
|
|
34
|
+
* @returns {*} Result of function execution
|
|
35
|
+
* @public
|
|
36
|
+
*/
|
|
37
|
+
public runInContext(instanceID: string, fn: Function, thisArg: any, args: any[], currentWrapper?: Object, rawErrors?: boolean): any;
|
|
38
|
+
/**
|
|
39
|
+
* Get current active context
|
|
40
|
+
* @returns {Object} Current context store
|
|
41
|
+
* @throws {SlothletError} If no active context
|
|
42
|
+
* @public
|
|
43
|
+
*/
|
|
44
|
+
public getContext(): Object;
|
|
45
|
+
/**
|
|
46
|
+
* Try to get context (returns undefined instead of throwing)
|
|
47
|
+
*
|
|
48
|
+
* @param {string} [instanceID] - When provided, resolve the store scoped to this instance rather
|
|
49
|
+
* than to the active async flow. The active ALS store is used only when it belongs to this
|
|
50
|
+
* instance (its own store or a child scope of it); otherwise this instance has no active flow
|
|
51
|
+
* and its own base store is returned, so host-level checks (e.g. the `TRUSTED_ROOT` read-gate
|
|
52
|
+
* exemption) evaluate against the right instance. AsyncLocalStorage propagates across `await`,
|
|
53
|
+
* so a leaf that boots a second `slothlet()` would otherwise carry its own store into the
|
|
54
|
+
* nested instance's construction (#290). Omit for the legacy "active flow store" behavior.
|
|
55
|
+
* @returns {Object|undefined} Current context store or undefined
|
|
56
|
+
* @public
|
|
57
|
+
*/
|
|
58
|
+
public tryGetContext(instanceID?: string): Object | undefined;
|
|
59
|
+
/**
|
|
60
|
+
* Resolve the caller identity for the executing async flow.
|
|
61
|
+
*
|
|
62
|
+
* Counterpart to the live manager's accessor of the same name, so enforcement can ask for
|
|
63
|
+
* identity without knowing which runtime it is on. No disambiguation is needed here:
|
|
64
|
+
* `runInContext` publishes a fresh execution store into AsyncLocalStorage, so the store this
|
|
65
|
+
* returns already belongs to the calling flow and cannot be another call's.
|
|
66
|
+
*
|
|
67
|
+
* @param {string} [instanceID] - When provided, resolve identity from THIS instance's own store
|
|
68
|
+
* rather than from the active async flow. AsyncLocalStorage propagates across `await`, so an
|
|
69
|
+
* outer leaf booting this nested instance would otherwise be seen as its caller; scoping to the
|
|
70
|
+
* instance's own store reports no caller for that nested boot (base store has none) while still
|
|
71
|
+
* returning the real caller when this instance's own flow is active (#290). Omit for the legacy
|
|
72
|
+
* "active flow caller" behavior.
|
|
73
|
+
* @returns {{currentWrapper: object, callerWrapper: object}|undefined} Identity, or undefined
|
|
74
|
+
* when there is no active context.
|
|
75
|
+
* @public
|
|
76
|
+
*/
|
|
77
|
+
public getCallerIdentity(instanceID?: string): {
|
|
78
|
+
currentWrapper: object;
|
|
79
|
+
callerWrapper: object;
|
|
18
80
|
} | undefined;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
81
|
+
/**
|
|
82
|
+
* Cleanup instance context
|
|
83
|
+
* @param {string} instanceID - Instance to cleanup
|
|
84
|
+
* @public
|
|
85
|
+
*/
|
|
86
|
+
public cleanup(instanceID: string): void;
|
|
87
|
+
/**
|
|
88
|
+
* Get diagnostic information
|
|
89
|
+
* @returns {Object} Diagnostic data
|
|
90
|
+
* @public
|
|
91
|
+
*/
|
|
92
|
+
public getDiagnostics(): Object;
|
|
30
93
|
#private;
|
|
31
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* Singleton async context manager
|
|
97
|
+
* @public
|
|
98
|
+
*/
|
|
32
99
|
export const asyncContextManager: AsyncContextManager;
|
|
@@ -1,37 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Live bindings context manager (direct global state)
|
|
3
|
+
* Uses direct instance tracking without AsyncLocalStorage overhead.
|
|
4
|
+
*
|
|
5
|
+
* Concurrency boundary: the active instance is tracked in a single global field
|
|
6
|
+
* ({@link LiveContextManager#currentInstanceID}), so this manager isolates *sequential*
|
|
7
|
+
* `run()`/`scope()` calls (each restores the prior instance on exit) but NOT *interleaved*
|
|
8
|
+
* concurrent calls on the same instance — across an `await`, a sibling `run()` overwrites the
|
|
9
|
+
* global and a resumed callback reads the wrong context. True per-async-flow isolation requires
|
|
10
|
+
* AsyncLocalStorage (see {@link module:@cldmv/slothlet/handlers/context-async}); the live manager
|
|
11
|
+
* is the deliberate trade-off for environments without `node:async_hooks` (browser/worker, see
|
|
12
|
+
* #123) and for the lowest-overhead single-flow case. See docs/CONTEXT-PROPAGATION.md.
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
1
15
|
export class LiveContextManager {
|
|
2
16
|
instances: Map<any, any>;
|
|
3
17
|
currentInstanceID: any;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Resolve the caller identity for the call that is executing right now.
|
|
20
|
+
*
|
|
21
|
+
* Enforcement asks for identity through here rather than reading `store.currentWrapper`
|
|
22
|
+
* directly, because that field can only name one call. Two paths:
|
|
23
|
+
*
|
|
24
|
+
* - **At most one call suspended** — the field is necessarily that call's (or a synchronous
|
|
25
|
+
* nested call's, which set it on the way in), so it is returned as-is. This is the ordinary
|
|
26
|
+
* case and costs nothing.
|
|
27
|
+
* - **Two or more suspended** — the field names whichever entered last, so a call resuming
|
|
28
|
+
* from its `await` would read another module's identity and inherit its rights. The true
|
|
29
|
+
* caller is taken from the call stack instead: the gated access happens synchronously inside
|
|
30
|
+
* the caller's own function body, so its frame is on the stack. Interleaving can scramble a
|
|
31
|
+
* shared field; it cannot scramble the stack, since each flow has its own.
|
|
32
|
+
*
|
|
33
|
+
* Only the suspended calls are candidates, so this never needs a global file→module index —
|
|
34
|
+
* and when the stack matches none of them (or matches ambiguously), identity is reported as
|
|
35
|
+
* unresolved so enforcement fails closed rather than guessing.
|
|
36
|
+
*
|
|
37
|
+
* Live runtime only. The async manager scopes identity per flow with AsyncLocalStorage and has
|
|
38
|
+
* no such ambiguity.
|
|
39
|
+
*
|
|
40
|
+
* @param {string} [instanceID] - When provided, resolve identity from THIS instance's own store
|
|
41
|
+
* rather than from whichever instance is globally active. The manager is a singleton shared by
|
|
42
|
+
* every instance, so the global `currentInstanceID` can point at a different `slothlet()` at the
|
|
43
|
+
* moment this instance's access is enforced — either an outer leaf mid-boot of this nested
|
|
44
|
+
* instance (its base store has no caller → treated as uncalled) or a concurrent sibling that
|
|
45
|
+
* transiently overwrote the global while this instance's own call is parked at an `await` (its
|
|
46
|
+
* store still holds the in-flight caller → resolved and enforced). Scoping the store keeps both
|
|
47
|
+
* correct; a bare `currentInstanceID` read conflates them (#290). Omit for the legacy behavior.
|
|
48
|
+
* @returns {{currentWrapper: object|null, callerWrapper: object, unresolved?: boolean}|undefined}
|
|
49
|
+
* Identity for the executing call, or undefined when there is no active context.
|
|
50
|
+
* @public
|
|
51
|
+
*/
|
|
52
|
+
public getCallerIdentity(instanceID?: string): {
|
|
53
|
+
currentWrapper: object | null;
|
|
54
|
+
callerWrapper: object;
|
|
55
|
+
unresolved?: boolean;
|
|
12
56
|
} | undefined;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
57
|
+
/**
|
|
58
|
+
* Register the EventEmitter context checker
|
|
59
|
+
* Must be called AFTER EventEmitter patching is enabled
|
|
60
|
+
* @public
|
|
61
|
+
*/
|
|
62
|
+
public registerEventEmitterContextChecker(): void;
|
|
63
|
+
/**
|
|
64
|
+
* Initialize context for a new instance
|
|
65
|
+
* @param {string} instanceID - Unique instance identifier
|
|
66
|
+
* @param {Object} config - Instance configuration
|
|
67
|
+
* @returns {Object} Created context store
|
|
68
|
+
* @public
|
|
69
|
+
*/
|
|
70
|
+
public initialize(instanceID: string, config?: Object): Object;
|
|
71
|
+
/**
|
|
72
|
+
* Run function with instance context active (live mode)
|
|
73
|
+
* @param {string} instanceID - Instance to run in context of
|
|
74
|
+
* @param {Function} fn - Function to execute
|
|
75
|
+
* @param {*} thisArg - this binding for function
|
|
76
|
+
* @param {Array} args - Arguments to pass to function
|
|
77
|
+
* @param {Object} [currentWrapper] - Current wrapper being executed (for metadata.self())
|
|
78
|
+
* @param {boolean} [rawErrors=false] - When `true`, let a non-SlothletError thrown by
|
|
79
|
+
* `fn` propagate unchanged instead of wrapping it as `CONTEXT_EXECUTION_FAILED`. Used
|
|
80
|
+
* for framework callbacks (`lockCaller`, pinned hooks) where the caller expects the
|
|
81
|
+
* original error type/code/status.
|
|
82
|
+
* @returns {*} Result of function execution
|
|
83
|
+
* @public
|
|
84
|
+
*/
|
|
85
|
+
public runInContext(instanceID: string, fn: Function, thisArg: any, args: any[], currentWrapper?: Object, rawErrors?: boolean): any;
|
|
86
|
+
/**
|
|
87
|
+
* Get current active context
|
|
88
|
+
* @returns {Object} Current context store
|
|
89
|
+
* @throws {SlothletError} If no active context
|
|
90
|
+
* @public
|
|
91
|
+
*/
|
|
92
|
+
public getContext(): Object;
|
|
93
|
+
/**
|
|
94
|
+
* Try to get context (returns undefined instead of throwing)
|
|
95
|
+
*
|
|
96
|
+
* @param {string} [instanceID] - When provided, resolve the store scoped to this instance rather
|
|
97
|
+
* than to the globally-active one. If the active flow belongs to this instance (base or a
|
|
98
|
+
* `run()`/`scope()` child) its store is returned; otherwise the instance has no active flow and
|
|
99
|
+
* its own base store is returned, so host-level checks (e.g. the `TRUSTED_ROOT` read-gate
|
|
100
|
+
* exemption) evaluate against the right instance instead of an unrelated ambient caller (#290).
|
|
101
|
+
* Omit for the legacy "globally-active store" behavior.
|
|
102
|
+
* @returns {Object|undefined} Current context store or undefined
|
|
103
|
+
* @public
|
|
104
|
+
*/
|
|
105
|
+
public tryGetContext(instanceID?: string): Object | undefined;
|
|
106
|
+
/**
|
|
107
|
+
* Cleanup instance context
|
|
108
|
+
* @param {string} instanceID - Instance to cleanup
|
|
109
|
+
* @public
|
|
110
|
+
*/
|
|
111
|
+
public cleanup(instanceID: string): void;
|
|
112
|
+
/**
|
|
113
|
+
* Get diagnostic information
|
|
114
|
+
* @returns {Object} Diagnostic data
|
|
115
|
+
* @public
|
|
116
|
+
*/
|
|
117
|
+
public getDiagnostics(): Object;
|
|
35
118
|
#private;
|
|
36
119
|
}
|
|
120
|
+
/**
|
|
121
|
+
* Singleton live context manager
|
|
122
|
+
* @public
|
|
123
|
+
*/
|
|
37
124
|
export const liveContextManager: LiveContextManager;
|
|
@@ -1,3 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Whether `key` is one of slothlet's reserved dispatcher marker keys.
|
|
3
|
+
*
|
|
4
|
+
* The immutable read view over `FRAMEWORK_MARKER_KEYS` — importers can test membership but
|
|
5
|
+
* cannot add keys and broaden the read-gate exemption.
|
|
6
|
+
*
|
|
7
|
+
* @param {string} key - Property name to test.
|
|
8
|
+
* @returns {boolean} True when `key` is a reserved framework marker key.
|
|
9
|
+
* @internal
|
|
10
|
+
* @example
|
|
11
|
+
* if (isFrameworkInternal(wrapper) && isFrameworkMarkerKey(leafKey)) return { allowed: true };
|
|
12
|
+
*/
|
|
13
|
+
export function isFrameworkMarkerKey(key: string): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Brand an object as slothlet-internal so reads of its `FRAMEWORK_MARKER_KEYS` are exempt from
|
|
16
|
+
* the module-private host gate. No-op for non-objects.
|
|
17
|
+
*
|
|
18
|
+
* @param {*} obj - The object (or function) slothlet created / stamped with a marker key.
|
|
19
|
+
* @returns {*} The same `obj`, for call-site chaining.
|
|
20
|
+
* @internal
|
|
21
|
+
* @example
|
|
22
|
+
* const dispatcher = markFrameworkInternal(new Proxy(target, handlers));
|
|
23
|
+
*/
|
|
3
24
|
export function markFrameworkInternal(obj: any): any;
|
|
25
|
+
/**
|
|
26
|
+
* Whether `obj` is a branded slothlet-internal object (see {@link markFrameworkInternal}).
|
|
27
|
+
*
|
|
28
|
+
* @param {*} obj - Candidate object.
|
|
29
|
+
* @returns {boolean} True when `obj` was branded by the framework.
|
|
30
|
+
* @internal
|
|
31
|
+
* @example
|
|
32
|
+
* if (isFrameworkInternal(sourceApi)) markFrameworkInternal(resolveWrapper(targetApi));
|
|
33
|
+
*/
|
|
34
|
+
export function isFrameworkInternal(obj: any): boolean;
|