@cldmv/slothlet 2.11.0 → 3.0.1
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/AGENT-USAGE.md +355 -325
- package/README.md +554 -238
- package/dist/lib/builders/api-assignment.mjs +605 -0
- package/dist/lib/builders/api_builder.mjs +1073 -0
- package/dist/lib/builders/builder.mjs +94 -0
- package/dist/lib/builders/modes-processor.mjs +1816 -0
- package/dist/lib/errors.mjs +227 -0
- package/dist/lib/factories/component-base.mjs +96 -0
- package/dist/lib/factories/context.mjs +38 -0
- package/dist/lib/handlers/api-cache-manager.mjs +216 -0
- package/dist/lib/handlers/api-manager.mjs +2364 -0
- package/dist/lib/handlers/context-async.mjs +184 -0
- package/dist/lib/handlers/context-live.mjs +184 -0
- package/dist/lib/handlers/hook-manager.mjs +789 -0
- package/dist/lib/handlers/lifecycle-token.mjs +44 -0
- package/dist/lib/handlers/lifecycle.mjs +131 -0
- package/dist/lib/handlers/materialize-manager.mjs +64 -0
- package/dist/lib/handlers/metadata.mjs +500 -0
- package/dist/lib/handlers/ownership.mjs +338 -0
- package/dist/lib/handlers/unified-wrapper.mjs +3031 -0
- package/dist/lib/helpers/class-instance-wrapper.mjs +125 -0
- package/dist/lib/helpers/config.mjs +343 -0
- package/dist/lib/helpers/eventemitter-context.mjs +365 -0
- package/dist/lib/helpers/hint-detector.mjs +63 -0
- package/dist/lib/helpers/modes-utils.mjs +53 -0
- package/dist/lib/helpers/resolve-from-caller.mjs +123 -117
- package/dist/lib/helpers/sanitize.mjs +247 -168
- package/dist/lib/helpers/utilities.mjs +46 -81
- package/dist/lib/i18n/languages/de-de.json +377 -0
- package/dist/lib/i18n/languages/en-gb.json +377 -0
- package/dist/lib/i18n/languages/en-us.json +377 -0
- package/dist/lib/i18n/languages/es-mx.json +377 -0
- package/dist/lib/i18n/languages/fr-fr.json +377 -0
- package/dist/lib/i18n/languages/hi-in.json +377 -0
- package/dist/lib/i18n/languages/ja-jp.json +377 -0
- package/dist/lib/i18n/languages/ko-kr.json +377 -0
- package/dist/lib/i18n/languages/pt-br.json +377 -0
- package/dist/lib/i18n/languages/ru-ru.json +377 -0
- package/dist/lib/i18n/languages/zh-cn.json +377 -0
- package/dist/lib/i18n/translations.mjs +140 -0
- package/dist/lib/modes/eager.mjs +75 -0
- package/dist/lib/modes/lazy.mjs +97 -0
- package/dist/lib/processors/flatten.mjs +453 -0
- package/dist/lib/processors/loader.mjs +355 -0
- package/dist/lib/processors/type-generator.mjs +291 -0
- package/dist/lib/processors/typescript.mjs +188 -0
- package/dist/lib/runtime/runtime-asynclocalstorage.mjs +80 -522
- package/dist/lib/runtime/runtime-livebindings.mjs +45 -390
- package/dist/lib/runtime/runtime.mjs +39 -159
- package/dist/slothlet.mjs +525 -744
- package/docs/API-RULES.md +338 -486
- package/index.cjs +4 -4
- package/index.mjs +82 -45
- package/package.json +143 -30
- package/types/dist/lib/builders/api-assignment.d.mts +97 -0
- package/types/dist/lib/builders/api-assignment.d.mts.map +1 -0
- package/types/dist/lib/builders/api_builder.d.mts +96 -0
- package/types/dist/lib/builders/api_builder.d.mts.map +1 -0
- package/types/dist/lib/builders/builder.d.mts +60 -0
- package/types/dist/lib/builders/builder.d.mts.map +1 -0
- package/types/dist/lib/builders/modes-processor.d.mts +32 -0
- package/types/dist/lib/builders/modes-processor.d.mts.map +1 -0
- package/types/dist/lib/errors.d.mts +118 -0
- package/types/dist/lib/errors.d.mts.map +1 -0
- package/types/dist/lib/factories/component-base.d.mts +182 -0
- package/types/dist/lib/factories/component-base.d.mts.map +1 -0
- package/types/dist/lib/factories/context.d.mts +26 -0
- package/types/dist/lib/factories/context.d.mts.map +1 -0
- package/types/dist/lib/handlers/api-cache-manager.d.mts +208 -0
- package/types/dist/lib/handlers/api-cache-manager.d.mts.map +1 -0
- package/types/dist/lib/handlers/api-manager.d.mts +392 -0
- package/types/dist/lib/handlers/api-manager.d.mts.map +1 -0
- package/types/dist/lib/handlers/context-async.d.mts +66 -0
- package/types/dist/lib/handlers/context-async.d.mts.map +1 -0
- package/types/dist/lib/handlers/context-live.d.mts +65 -0
- package/types/dist/lib/handlers/context-live.d.mts.map +1 -0
- package/types/dist/lib/handlers/hook-manager.d.mts +199 -0
- package/types/dist/lib/handlers/hook-manager.d.mts.map +1 -0
- package/types/dist/lib/handlers/lifecycle-token.d.mts +49 -0
- package/types/dist/lib/handlers/lifecycle-token.d.mts.map +1 -0
- package/types/dist/lib/handlers/lifecycle.d.mts +90 -0
- package/types/dist/lib/handlers/lifecycle.d.mts.map +1 -0
- package/types/dist/lib/handlers/materialize-manager.d.mts +75 -0
- package/types/dist/lib/handlers/materialize-manager.d.mts.map +1 -0
- package/types/dist/lib/handlers/metadata.d.mts +215 -0
- package/types/dist/lib/handlers/metadata.d.mts.map +1 -0
- package/types/dist/lib/handlers/ownership.d.mts +170 -0
- package/types/dist/lib/handlers/ownership.d.mts.map +1 -0
- package/types/dist/lib/handlers/unified-wrapper.d.mts +250 -0
- package/types/dist/lib/handlers/unified-wrapper.d.mts.map +1 -0
- package/types/dist/lib/helpers/class-instance-wrapper.d.mts +54 -0
- package/types/dist/lib/helpers/class-instance-wrapper.d.mts.map +1 -0
- package/types/dist/lib/helpers/config.d.mts +96 -0
- package/types/dist/lib/helpers/config.d.mts.map +1 -0
- package/types/dist/lib/helpers/eventemitter-context.d.mts +31 -0
- package/types/dist/lib/helpers/eventemitter-context.d.mts.map +1 -0
- package/types/dist/lib/helpers/hint-detector.d.mts +20 -0
- package/types/dist/lib/helpers/hint-detector.d.mts.map +1 -0
- package/types/dist/lib/helpers/modes-utils.d.mts +35 -0
- package/types/dist/lib/helpers/modes-utils.d.mts.map +1 -0
- package/types/dist/lib/helpers/resolve-from-caller.d.mts +29 -145
- package/types/dist/lib/helpers/resolve-from-caller.d.mts.map +1 -1
- package/types/dist/lib/helpers/sanitize.d.mts +95 -94
- package/types/dist/lib/helpers/sanitize.d.mts.map +1 -1
- package/types/dist/lib/helpers/utilities.d.mts +53 -116
- package/types/dist/lib/helpers/utilities.d.mts.map +1 -1
- package/types/dist/lib/i18n/translations.d.mts +39 -0
- package/types/dist/lib/i18n/translations.d.mts.map +1 -0
- package/types/dist/lib/modes/eager.d.mts +36 -0
- package/types/dist/lib/modes/eager.d.mts.map +1 -0
- package/types/dist/lib/modes/lazy.d.mts +49 -0
- package/types/dist/lib/modes/lazy.d.mts.map +1 -0
- package/types/dist/lib/processors/flatten.d.mts +114 -0
- package/types/dist/lib/processors/flatten.d.mts.map +1 -0
- package/types/dist/lib/processors/loader.d.mts +47 -0
- package/types/dist/lib/processors/loader.d.mts.map +1 -0
- package/types/dist/lib/processors/type-generator.d.mts +19 -0
- package/types/dist/lib/processors/type-generator.d.mts.map +1 -0
- package/types/dist/lib/processors/typescript.d.mts +55 -0
- package/types/dist/lib/processors/typescript.d.mts.map +1 -0
- package/types/dist/lib/runtime/runtime-asynclocalstorage.d.mts +47 -42
- package/types/dist/lib/runtime/runtime-asynclocalstorage.d.mts.map +1 -1
- package/types/dist/lib/runtime/runtime-livebindings.d.mts +34 -65
- package/types/dist/lib/runtime/runtime-livebindings.d.mts.map +1 -1
- package/types/dist/lib/runtime/runtime.d.mts +39 -9
- package/types/dist/lib/runtime/runtime.d.mts.map +1 -1
- package/types/dist/slothlet.d.mts +184 -111
- package/types/dist/slothlet.d.mts.map +1 -1
- package/types/index.d.mts +1 -3
- package/dist/lib/engine/README.md +0 -21
- package/dist/lib/engine/slothlet_child.mjs +0 -59
- package/dist/lib/engine/slothlet_engine.mjs +0 -372
- package/dist/lib/engine/slothlet_esm.mjs +0 -230
- package/dist/lib/engine/slothlet_helpers.mjs +0 -455
- package/dist/lib/engine/slothlet_worker.mjs +0 -149
- package/dist/lib/helpers/als-eventemitter.mjs +0 -256
- package/dist/lib/helpers/api_builder/add_api.mjs +0 -553
- package/dist/lib/helpers/api_builder/analysis.mjs +0 -532
- package/dist/lib/helpers/api_builder/construction.mjs +0 -495
- package/dist/lib/helpers/api_builder/decisions.mjs +0 -748
- package/dist/lib/helpers/api_builder/metadata.mjs +0 -248
- package/dist/lib/helpers/api_builder.mjs +0 -41
- package/dist/lib/helpers/auto-wrap.mjs +0 -62
- package/dist/lib/helpers/hooks.mjs +0 -389
- package/dist/lib/helpers/instance-manager.mjs +0 -111
- package/dist/lib/helpers/metadata-api.mjs +0 -201
- package/dist/lib/helpers/multidefault.mjs +0 -216
- package/dist/lib/modes/slothlet_eager.mjs +0 -154
- package/dist/lib/modes/slothlet_lazy.mjs +0 -594
- package/docs/API-RULES-CONDITIONS.md +0 -712
- package/types/dist/lib/engine/slothlet_child.d.mts +0 -2
- package/types/dist/lib/engine/slothlet_child.d.mts.map +0 -1
- package/types/dist/lib/engine/slothlet_engine.d.mts +0 -31
- package/types/dist/lib/engine/slothlet_engine.d.mts.map +0 -1
- package/types/dist/lib/engine/slothlet_esm.d.mts +0 -19
- package/types/dist/lib/engine/slothlet_esm.d.mts.map +0 -1
- package/types/dist/lib/engine/slothlet_helpers.d.mts +0 -25
- package/types/dist/lib/engine/slothlet_helpers.d.mts.map +0 -1
- package/types/dist/lib/engine/slothlet_worker.d.mts +0 -2
- package/types/dist/lib/engine/slothlet_worker.d.mts.map +0 -1
- package/types/dist/lib/helpers/als-eventemitter.d.mts +0 -56
- package/types/dist/lib/helpers/als-eventemitter.d.mts.map +0 -1
- package/types/dist/lib/helpers/api_builder/add_api.d.mts +0 -102
- package/types/dist/lib/helpers/api_builder/add_api.d.mts.map +0 -1
- package/types/dist/lib/helpers/api_builder/analysis.d.mts +0 -189
- package/types/dist/lib/helpers/api_builder/analysis.d.mts.map +0 -1
- package/types/dist/lib/helpers/api_builder/construction.d.mts +0 -107
- package/types/dist/lib/helpers/api_builder/construction.d.mts.map +0 -1
- package/types/dist/lib/helpers/api_builder/decisions.d.mts +0 -213
- package/types/dist/lib/helpers/api_builder/decisions.d.mts.map +0 -1
- package/types/dist/lib/helpers/api_builder/metadata.d.mts +0 -99
- package/types/dist/lib/helpers/api_builder/metadata.d.mts.map +0 -1
- package/types/dist/lib/helpers/api_builder.d.mts +0 -6
- package/types/dist/lib/helpers/api_builder.d.mts.map +0 -1
- package/types/dist/lib/helpers/auto-wrap.d.mts +0 -49
- package/types/dist/lib/helpers/auto-wrap.d.mts.map +0 -1
- package/types/dist/lib/helpers/hooks.d.mts +0 -342
- package/types/dist/lib/helpers/hooks.d.mts.map +0 -1
- package/types/dist/lib/helpers/instance-manager.d.mts +0 -41
- package/types/dist/lib/helpers/instance-manager.d.mts.map +0 -1
- package/types/dist/lib/helpers/metadata-api.d.mts +0 -132
- package/types/dist/lib/helpers/metadata-api.d.mts.map +0 -1
- package/types/dist/lib/helpers/multidefault.d.mts +0 -90
- package/types/dist/lib/helpers/multidefault.d.mts.map +0 -1
- package/types/dist/lib/modes/slothlet_eager.d.mts +0 -65
- package/types/dist/lib/modes/slothlet_eager.d.mts.map +0 -1
- package/types/dist/lib/modes/slothlet_lazy.d.mts +0 -31
- package/types/dist/lib/modes/slothlet_lazy.d.mts.map +0 -1
- package/types/index.d.mts.map +0 -1
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Manages runtime API component lifecycle (add/remove/reload).
|
|
3
|
+
* @class ApiManager
|
|
4
|
+
* @extends ComponentBase
|
|
5
|
+
* @package
|
|
6
|
+
*
|
|
7
|
+
* @description
|
|
8
|
+
* Class-based handler for managing API components at runtime. Tracks add history,
|
|
9
|
+
* removed module IDs, and initial configuration per instance. Extends ComponentBase
|
|
10
|
+
* for common Slothlet property access (config, debug, api, error classes, etc.).
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* const manager = new ApiManager(slothlet);
|
|
14
|
+
* await manager.addApiComponent({ apiPath: "plugins", folderPath: "./plugins" });
|
|
15
|
+
*/
|
|
16
|
+
export class ApiManager extends ComponentBase {
|
|
17
|
+
static slothletProperty: string;
|
|
18
|
+
state: {
|
|
19
|
+
addHistory: any[];
|
|
20
|
+
initialConfig: any;
|
|
21
|
+
operationHistory: any[];
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Normalize and validate an API path.
|
|
25
|
+
* @param {string|string[]} apiPath - Dot-delimited API path, array of path segments, or empty/null for root.
|
|
26
|
+
* @returns {{ apiPath: string, parts: string[] }} Normalized path data.
|
|
27
|
+
* @throws {SlothletError} When apiPath is invalid.
|
|
28
|
+
* @private
|
|
29
|
+
*
|
|
30
|
+
* @description
|
|
31
|
+
* Ensures the API path is valid. Accepts:
|
|
32
|
+
* - String: "some.path" → parts: ["some", "path"]
|
|
33
|
+
* - Array: ["some", "path"] → parts: ["some", "path"]
|
|
34
|
+
* - Empty string, null, or undefined → root level (parts: [])
|
|
35
|
+
* Non-empty paths must contain no empty segments.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* const { apiPath, parts } = this.normalizeApiPath("plugins.tools");
|
|
39
|
+
* const { apiPath, parts } = this.normalizeApiPath(["plugins", "tools"]);
|
|
40
|
+
* const { apiPath, parts } = this.normalizeApiPath(""); // Root level: parts = []
|
|
41
|
+
*/
|
|
42
|
+
private normalizeApiPath;
|
|
43
|
+
/**
|
|
44
|
+
* Resolve and validate a path (file or directory) from caller context.
|
|
45
|
+
* @param {string} inputPath - File or folder path provided by caller.
|
|
46
|
+
* @returns {Promise<{resolvedPath: string, isDirectory: boolean, isFile: boolean}>} Path info.
|
|
47
|
+
* @throws {SlothletError} When the path does not exist.
|
|
48
|
+
* @private
|
|
49
|
+
*
|
|
50
|
+
* @description
|
|
51
|
+
* Resolves relative paths from the caller and verifies the path exists.
|
|
52
|
+
* Supports both files (.mjs, .cjs, .js) and directories.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* const { resolvedPath, isDirectory, isFile } = await this.resolvePath("./plugins");
|
|
56
|
+
* const { resolvedPath, isDirectory, isFile } = await this.resolvePath("./module.mjs");
|
|
57
|
+
*/
|
|
58
|
+
private resolvePath;
|
|
59
|
+
/**
|
|
60
|
+
* Resolve and validate a folder path from caller context.
|
|
61
|
+
* @param {string} folderPath - Folder path provided by caller.
|
|
62
|
+
* @returns {Promise<string>} Absolute folder path.
|
|
63
|
+
* @throws {SlothletError} When the folder does not exist or is not a directory.
|
|
64
|
+
* @private
|
|
65
|
+
*
|
|
66
|
+
* @description
|
|
67
|
+
* Resolves relative paths from the caller and verifies the folder exists.
|
|
68
|
+
*
|
|
69
|
+
* @deprecated Use resolvePath() instead for file/directory support.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* const resolved = await this.resolveFolderPath("./plugins");
|
|
73
|
+
*/
|
|
74
|
+
private resolveFolderPath;
|
|
75
|
+
/**
|
|
76
|
+
* Build a default moduleID when none is provided.
|
|
77
|
+
* @param {string} apiPath - API path for this module.
|
|
78
|
+
* @param {string} resolvedFolderPath - Absolute folder path.
|
|
79
|
+
* @returns {string} Stable module identifier.
|
|
80
|
+
* @private
|
|
81
|
+
*
|
|
82
|
+
* @description
|
|
83
|
+
* Generates a stable moduleID using the apiPath and resolved folder path.
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* const moduleID = this.buildDefaultModuleId("plugins", "/abs/path/plugins");
|
|
87
|
+
*/
|
|
88
|
+
private buildDefaultModuleId;
|
|
89
|
+
/**
|
|
90
|
+
* Read the current value at an API path.
|
|
91
|
+
* @param {function|object} root - API root object.
|
|
92
|
+
* @param {string[]} parts - Path segments.
|
|
93
|
+
* @returns {unknown} Current value or undefined.
|
|
94
|
+
* @private
|
|
95
|
+
*
|
|
96
|
+
* @description
|
|
97
|
+
* Traverses the API graph by path segments and returns the value if found.
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* const value = this.getValueAtPath(api, ["plugins", "tools"]);
|
|
101
|
+
*/
|
|
102
|
+
private getValueAtPath;
|
|
103
|
+
/**
|
|
104
|
+
* Ensure parent path exists and return the parent object.
|
|
105
|
+
* @param {function|object} root - API root object.
|
|
106
|
+
* @param {string[]} parts - Path segments.
|
|
107
|
+
* @returns {function|object} Parent container for the final segment.
|
|
108
|
+
* @throws {SlothletError} When a non-object path segment blocks creation.
|
|
109
|
+
* @private
|
|
110
|
+
*
|
|
111
|
+
* @description
|
|
112
|
+
* Walks through the path segments, creating missing objects as needed.
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* const parent = this.ensureParentPath(api, ["plugins", "tools"]);
|
|
116
|
+
*/
|
|
117
|
+
private ensureParentPath;
|
|
118
|
+
/**
|
|
119
|
+
* Determine whether a value is a UnifiedWrapper proxy.
|
|
120
|
+
* @param {unknown} value - Value to inspect.
|
|
121
|
+
* @returns {boolean} True when value looks like a wrapper proxy.
|
|
122
|
+
* @private
|
|
123
|
+
*
|
|
124
|
+
* @description
|
|
125
|
+
* Checks for wrapper markers that are exposed on UnifiedWrapper proxies.
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* if (this.isWrapperProxy(api.plugins)) {
|
|
129
|
+
* // Update wrapper implementation
|
|
130
|
+
* }
|
|
131
|
+
*/
|
|
132
|
+
private isWrapperProxy;
|
|
133
|
+
/**
|
|
134
|
+
* Synchronize an existing wrapper proxy with a new wrapper.
|
|
135
|
+
* @param {function|object} existingProxy - Existing wrapper proxy.
|
|
136
|
+
* @param {function|object} nextProxy - New wrapper proxy.
|
|
137
|
+
* @param {object} config - Configuration object for debug logging.
|
|
138
|
+
* @returns {Promise<boolean>} True when a wrapper update occurred.
|
|
139
|
+
* @private
|
|
140
|
+
*
|
|
141
|
+
* @description
|
|
142
|
+
* Copies materialization behavior and implementation from the new proxy into the existing
|
|
143
|
+
* proxy to preserve references during reload operations.
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* await this.syncWrapper(existingProxy, nextProxy, this.____config);
|
|
147
|
+
*/
|
|
148
|
+
private syncWrapper;
|
|
149
|
+
/**
|
|
150
|
+
* Recursively mutate an existing API value to match a new value.
|
|
151
|
+
* @param {function|object} existingValue - Existing value to mutate.
|
|
152
|
+
* @param {unknown} nextValue - New value to apply.
|
|
153
|
+
* @param {object} options - Mutation options.
|
|
154
|
+
* @param {boolean} options.removeMissing - Remove properties not present in nextValue.
|
|
155
|
+
* @param {object} config - Configuration object for debug logging.
|
|
156
|
+
* @returns {Promise<void>}
|
|
157
|
+
* @private
|
|
158
|
+
*
|
|
159
|
+
* @description
|
|
160
|
+
* Uses unified mergeApiObjects logic from api_assignment.mjs to ensure consistent
|
|
161
|
+
* merge behavior between initial build and hot reload.
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* await this.mutateApiValue(existing, next, { removeMissing: true }, this.____config);
|
|
165
|
+
*/
|
|
166
|
+
private mutateApiValue;
|
|
167
|
+
/**
|
|
168
|
+
* Set a value at a path within an API root.
|
|
169
|
+
* @param {function|object} root - API root object.
|
|
170
|
+
* @param {string[]} parts - Path segments.
|
|
171
|
+
* @param {unknown} value - New value to assign.
|
|
172
|
+
* @param {object} options - Assignment options.
|
|
173
|
+
* @param {boolean} options.mutateExisting - Mutate existing values in place.
|
|
174
|
+
* @param {boolean} options.allowOverwrite - Allow overwriting existing values.
|
|
175
|
+
* @param {string} [options.collisionMode] - Collision handling mode (skip/warn/replace/merge/error).
|
|
176
|
+
* @returns {Promise<boolean>} True if value was set, false if skipped due to collision.
|
|
177
|
+
* @throws {SlothletError} When overwrite is not allowed or collision mode is "error".
|
|
178
|
+
* @private
|
|
179
|
+
*
|
|
180
|
+
* @description
|
|
181
|
+
* Writes a new value at the requested path with configurable collision handling.
|
|
182
|
+
* Supports five collision modes:
|
|
183
|
+
* - skip: Silently ignore collision, keep existing
|
|
184
|
+
* - warn: Warn about collision, keep existing
|
|
185
|
+
* - replace: Replace existing value completely
|
|
186
|
+
* - merge: Merge properties (preserve original + add new)
|
|
187
|
+
* - error: Throw error on collision
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* await this.setValueAtPath(api, ["plugins"], newApi, {
|
|
191
|
+
* mutateExisting: true,
|
|
192
|
+
* allowOverwrite: true,
|
|
193
|
+
* collisionMode: "merge"
|
|
194
|
+
* });
|
|
195
|
+
*/
|
|
196
|
+
private setValueAtPath;
|
|
197
|
+
/**
|
|
198
|
+
* Delete a value at a path and prune empty parents.
|
|
199
|
+
* @param {function|object} root - API root object.
|
|
200
|
+
* @param {string[]} parts - Path segments.
|
|
201
|
+
* @returns {Promise<boolean>} True when a value was deleted.
|
|
202
|
+
* @private
|
|
203
|
+
*
|
|
204
|
+
* @description
|
|
205
|
+
* Removes the property at the provided path and cleans up any empty parent objects.
|
|
206
|
+
*
|
|
207
|
+
* @example
|
|
208
|
+
* const deleted = await await this.deletePath(api, ["plugins", "tools"]);
|
|
209
|
+
*/
|
|
210
|
+
private deletePath;
|
|
211
|
+
/**
|
|
212
|
+
* Restore a path from api.slothlet.api.add history or core load.
|
|
213
|
+
* @param {string} apiPath - API path to restore.
|
|
214
|
+
* @param {?string} moduleID - ModuleId to restore.
|
|
215
|
+
* @returns {Promise<void>}
|
|
216
|
+
* @private
|
|
217
|
+
*
|
|
218
|
+
* @description
|
|
219
|
+
* Attempts to reapply a previous api.slothlet.api.add entry or rebuild the core API for the path.
|
|
220
|
+
*
|
|
221
|
+
* @example
|
|
222
|
+
* await this.restoreApiPath("plugins", "plugins-core");
|
|
223
|
+
*/
|
|
224
|
+
private restoreApiPath;
|
|
225
|
+
/**
|
|
226
|
+
* Add new API modules at runtime.
|
|
227
|
+
* @param {object} params - Add parameters.
|
|
228
|
+
* @param {string} params.apiPath - API path to attach.
|
|
229
|
+
* @param {string|string[]} params.folderPath - File path, folder path, or array of paths to load.
|
|
230
|
+
* @param {Record<string, unknown>} [params.options={}] - Add options (including optional metadata).
|
|
231
|
+
* @returns {Promise<string|string[]>} Module ID or array of module IDs.
|
|
232
|
+
* @throws {SlothletError} When the instance is not loaded or inputs are invalid.
|
|
233
|
+
* @package
|
|
234
|
+
*
|
|
235
|
+
* @description
|
|
236
|
+
* Loads modules from a folder, file, or array of files/folders using the instance configuration
|
|
237
|
+
* and merges the resulting API under the specified apiPath.
|
|
238
|
+
*
|
|
239
|
+
* Supports three input types:
|
|
240
|
+
* 1. Single directory path (original behavior)
|
|
241
|
+
* 2. Single file path (.mjs, .cjs, .js)
|
|
242
|
+
* 3. Array of file and/or directory paths
|
|
243
|
+
*
|
|
244
|
+
* When an array is provided, each path is processed sequentially,
|
|
245
|
+
* honoring collision settings, metadata, and ownership for each.
|
|
246
|
+
*
|
|
247
|
+
* @example
|
|
248
|
+
* // Directory
|
|
249
|
+
* await manager.addApiComponent({
|
|
250
|
+
* apiPath: "plugins",
|
|
251
|
+
* folderPath: "./plugins",
|
|
252
|
+
* options: { moduleID: "plugins-core", metadata: { version: "1.0.0" } }
|
|
253
|
+
* });
|
|
254
|
+
*
|
|
255
|
+
* @example
|
|
256
|
+
* // Single file
|
|
257
|
+
* await manager.addApiComponent({
|
|
258
|
+
* apiPath: "utils",
|
|
259
|
+
* folderPath: "./helpers/string-utils.mjs",
|
|
260
|
+
* options: { metadata: { author: "team" } }
|
|
261
|
+
* });
|
|
262
|
+
*
|
|
263
|
+
* @example
|
|
264
|
+
* // Array of files and folders
|
|
265
|
+
* await manager.addApiComponent({
|
|
266
|
+
* apiPath: "extensions",
|
|
267
|
+
* folderPath: ["./ext/plugin1.mjs", "./ext/plugin2.mjs", "./ext/utils"],
|
|
268
|
+
* options: { collisionMode: "merge" }
|
|
269
|
+
* });
|
|
270
|
+
*/
|
|
271
|
+
addApiComponent(params: {
|
|
272
|
+
apiPath: string;
|
|
273
|
+
folderPath: string | string[];
|
|
274
|
+
options?: Record<string, unknown>;
|
|
275
|
+
}): Promise<string | string[]>;
|
|
276
|
+
/**
|
|
277
|
+
* Remove API modules at runtime.
|
|
278
|
+
* @param {string} pathOrModuleId - API path (with dots) or module ID (with underscore) to remove.
|
|
279
|
+
* @returns {Promise<void>}
|
|
280
|
+
* @throws {SlothletError} When inputs are invalid.
|
|
281
|
+
* @package
|
|
282
|
+
*
|
|
283
|
+
* @description
|
|
284
|
+
* Removes an API subtree by apiPath or removes all paths owned by a moduleID.
|
|
285
|
+
* Automatically detects whether the parameter is a moduleID (contains underscore) or apiPath.
|
|
286
|
+
*
|
|
287
|
+
* @example
|
|
288
|
+
* await manager.removeApiComponent("plugins.tools"); // Remove by API path
|
|
289
|
+
*
|
|
290
|
+
* @example
|
|
291
|
+
* await manager.removeApiComponent("plugins_abc123"); // Remove by module ID
|
|
292
|
+
*/
|
|
293
|
+
removeApiComponent(pathOrModuleId: string, options?: {}): Promise<void>;
|
|
294
|
+
/**
|
|
295
|
+
* Reload API modules using cache system.
|
|
296
|
+
* @param {object} params - Reload parameters.
|
|
297
|
+
* @param {?string} params.apiPath - API path to reload.
|
|
298
|
+
* @param {?string} params.moduleID - ModuleId to reload.
|
|
299
|
+
* @returns {Promise<void>}
|
|
300
|
+
* @package
|
|
301
|
+
*
|
|
302
|
+
* @description
|
|
303
|
+
* Reloads modules from disk using cached parameters. For moduleID reload, rebuilds
|
|
304
|
+
* entire cache and restores all paths. For apiPath reload, rebuilds all contributing
|
|
305
|
+
* moduleID caches and merges implementations.
|
|
306
|
+
*
|
|
307
|
+
* @example
|
|
308
|
+
* await manager.reloadApiComponent({ moduleID: "plugins_abc123" });
|
|
309
|
+
* await manager.reloadApiComponent({ apiPath: "plugins" });
|
|
310
|
+
*/
|
|
311
|
+
reloadApiComponent(params: {
|
|
312
|
+
apiPath: string | null;
|
|
313
|
+
moduleID: string | null;
|
|
314
|
+
}): Promise<void>;
|
|
315
|
+
/**
|
|
316
|
+
* Reload by moduleID - rebuild cache and restore all paths
|
|
317
|
+
* @param {string} moduleID - Module identifier
|
|
318
|
+
* @param {Object} [options] - Reload options
|
|
319
|
+
* @param {boolean} [options.forceReplace=true] - Force replace mode on existing wrappers.
|
|
320
|
+
* When true, temporarily overrides collision mode to "replace" so the fresh impl
|
|
321
|
+
* fully replaces the old one. When false, the wrapper's original collision mode is
|
|
322
|
+
* preserved, allowing merge behavior for multi-cache rebuilds.
|
|
323
|
+
* @returns {Promise<void>}
|
|
324
|
+
* @private
|
|
325
|
+
*/
|
|
326
|
+
private _reloadByModuleID;
|
|
327
|
+
/**
|
|
328
|
+
* Reload by API path - find affected caches, rebuild them, update impls.
|
|
329
|
+
*
|
|
330
|
+
* Accepts "." for base module. For other paths, the resolution order is:
|
|
331
|
+
* 1. Exact cache endpoint match
|
|
332
|
+
* 2. Child caches (endpoints under the path)
|
|
333
|
+
* 3. Ownership history (modules that registered the exact path)
|
|
334
|
+
* 4. Parent cache (most specific cache whose scope covers the path)
|
|
335
|
+
*
|
|
336
|
+
* @param {string} apiPath - API path or "." for base module
|
|
337
|
+
* @param {Object} [options] - Optional reload options
|
|
338
|
+
* @param {Object} [options.metadata] - Metadata to merge for the reloaded path after rebuild
|
|
339
|
+
* @returns {Promise<void>}
|
|
340
|
+
* @private
|
|
341
|
+
*/
|
|
342
|
+
private _reloadByApiPath;
|
|
343
|
+
/**
|
|
344
|
+
* Find all cache entries that need to be rebuilt for a given API path.
|
|
345
|
+
*
|
|
346
|
+
* Resolution order:
|
|
347
|
+
* 1. "." or "" or null → base module cache(s) (endpoint ".")
|
|
348
|
+
* 2. Exact endpoint match → that specific cache
|
|
349
|
+
* 3. Child caches → caches whose endpoint is under the given path
|
|
350
|
+
* 4. Ownership history → modules that registered the exact path
|
|
351
|
+
* 5. Parent cache → most specific cache whose scope covers the path
|
|
352
|
+
*
|
|
353
|
+
* @param {string} apiPath - The API path to find caches for
|
|
354
|
+
* @returns {string[]} Array of moduleIDs to reload
|
|
355
|
+
* @private
|
|
356
|
+
*/
|
|
357
|
+
private _findAffectedCaches;
|
|
358
|
+
/**
|
|
359
|
+
* Collect user-set custom properties from a proxy/wrapper that are NOT in the fresh API.
|
|
360
|
+
* Custom properties are those set by the user at runtime (e.g., api.custom.testFlag = true)
|
|
361
|
+
* that should survive a selective reload.
|
|
362
|
+
* @param {Object} existingProxy - The existing proxy/wrapper to collect from
|
|
363
|
+
* @param {Object} freshApi - The fresh API from rebuild (keys to exclude)
|
|
364
|
+
* @returns {Object} Map of custom property names to their values
|
|
365
|
+
* @private
|
|
366
|
+
*/
|
|
367
|
+
private _collectCustomProperties;
|
|
368
|
+
/**
|
|
369
|
+
* Restore previously collected custom properties onto a proxy/wrapper after reload.
|
|
370
|
+
* @param {Object} proxy - The proxy to restore properties onto
|
|
371
|
+
* @param {Object} customProps - Map of property names to values from _collectCustomProperties
|
|
372
|
+
* @private
|
|
373
|
+
*/
|
|
374
|
+
private _restoreCustomProperties;
|
|
375
|
+
/**
|
|
376
|
+
* Restore API from fresh rebuild by updating existing wrapper.
|
|
377
|
+
* For non-root endpoints, updates the wrapper's implementation without replacing structure.
|
|
378
|
+
* For root endpoints, merges keys directly as addApiComponent does.
|
|
379
|
+
* @param {object} freshApi - Fresh API from rebuild
|
|
380
|
+
* @param {string} endpoint - Original endpoint path
|
|
381
|
+
* @param {string} moduleID - Module identifier
|
|
382
|
+
* @param {string} collisionMode - Collision handling mode
|
|
383
|
+
* @param {boolean} [forceReplace=true] - When true, temporarily overrides wrapper collision
|
|
384
|
+
* mode to "replace" so fresh impl fully replaces old. When false, preserves original
|
|
385
|
+
* collision mode for proper merge behavior in multi-cache rebuilds.
|
|
386
|
+
* @returns {Promise<void>}
|
|
387
|
+
* @private
|
|
388
|
+
*/
|
|
389
|
+
private _restoreApiTree;
|
|
390
|
+
}
|
|
391
|
+
import { ComponentBase } from "@cldmv/slothlet/factories/component-base";
|
|
392
|
+
//# sourceMappingURL=api-manager.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-manager.d.mts","sourceRoot":"","sources":["../../../../dist/lib/handlers/api-manager.mjs"],"names":[],"mappings":"AAmDA;;;;;;;;;;;;;;GAcG;AACH;IACC,gCAAuC;IAgBtC;;;;MAMC;IAGF;;;;;;;;;;;;;;;;;;OAkBG;IACH,yBAuFC;IAED;;;;;;;;;;;;;;OAcG;IACH,oBA+BC;IAED;;;;;;;;;;;;;;OAcG;IACH,0BA4BC;IAED;;;;;;;;;;;;OAYG;IACH,6BAIC;IAED;;;;;;;;;;;;OAYG;IACH,uBASC;IAED;;;;;;;;;;;;;OAaG;IACH,yBAkCC;IAED;;;;;;;;;;;;;OAaG;IACH,uBAEC;IAED;;;;;;;;;;;;;;OAcG;IACH,oBAmNC;IAED;;;;;;;;;;;;;;;;OAgBG;IACH,uBAkGC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;IACH,uBA8GC;IAED;;;;;;;;;;;;OAYG;IACH,mBAmGC;IACD;;;;;;;;;;;;OAYG;IACH,uBAwEC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6CG;IACH,wBA3CG;QAAuB,OAAO,EAAtB,MAAM;QACkB,UAAU,EAAlC,MAAM,GAAC,MAAM,EAAE;QACkB,OAAO,GAAxC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;KAC/B,GAAU,OAAO,CAAC,MAAM,GAAC,MAAM,EAAE,CAAC,CA4epC;IAED;;;;;;;;;;;;;;;;OAgBG;IACH,mCAfW,MAAM,iBACJ,OAAO,CAAC,IAAI,CAAC,CA6XzB;IAED;;;;;;;;;;;;;;;;OAgBG;IACH,2BAdG;QAAwB,OAAO,EAAtB,MAAM,OAAA;QACS,QAAQ,EAAvB,MAAM,OAAA;KACf,GAAU,OAAO,CAAC,IAAI,CAAC,CAuCzB;IAED;;;;;;;;;;OAUG;IACH,0BAiEC;IAED;;;;;;;;;;;;;;OAcG;IACH,yBAsFC;IAED;;;;;;;;;;;;;OAaG;IACH,4BA0FC;IAED;;;;;;;;OAQG;IACH,iCAuDC;IAED;;;;;OAKG;IACH,iCAeC;IAED;;;;;;;;;;;;;OAaG;IACH,wBA+TC;CACD;8BA5nF6B,0CAA0C"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AsyncLocalStorage-based context manager for async runtime
|
|
3
|
+
* Uses ALS for full context isolation across async operations
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export class AsyncContextManager {
|
|
7
|
+
als: AsyncLocalStorage<any>;
|
|
8
|
+
instances: Map<any, any>;
|
|
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?: any): any;
|
|
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
|
+
* @returns {*} Result of function execution
|
|
31
|
+
* @public
|
|
32
|
+
*/
|
|
33
|
+
public runInContext(instanceID: string, fn: Function, thisArg: any, args: any[], currentWrapper?: any): any;
|
|
34
|
+
/**
|
|
35
|
+
* Get current active context
|
|
36
|
+
* @returns {Object} Current context store
|
|
37
|
+
* @throws {SlothletError} If no active context
|
|
38
|
+
* @public
|
|
39
|
+
*/
|
|
40
|
+
public getContext(): any;
|
|
41
|
+
/**
|
|
42
|
+
* Try to get context (returns undefined instead of throwing)
|
|
43
|
+
* @returns {Object|undefined} Current context store or undefined
|
|
44
|
+
* @public
|
|
45
|
+
*/
|
|
46
|
+
public tryGetContext(): any | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* Cleanup instance context
|
|
49
|
+
* @param {string} instanceID - Instance to cleanup
|
|
50
|
+
* @public
|
|
51
|
+
*/
|
|
52
|
+
public cleanup(instanceID: string): void;
|
|
53
|
+
/**
|
|
54
|
+
* Get diagnostic information
|
|
55
|
+
* @returns {Object} Diagnostic data
|
|
56
|
+
* @public
|
|
57
|
+
*/
|
|
58
|
+
public getDiagnostics(): any;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Singleton async context manager
|
|
62
|
+
* @public
|
|
63
|
+
*/
|
|
64
|
+
export const asyncContextManager: AsyncContextManager;
|
|
65
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
66
|
+
//# sourceMappingURL=context-async.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-async.d.mts","sourceRoot":"","sources":["../../../../dist/lib/handlers/context-async.mjs"],"names":[],"mappings":"AAuBA;;;;GAIG;AACH;IAEE,4BAAkC;IAClC,yBAA0B;IAG3B;;;;OAIG;IACH,kDAKC;IAED;;;;;;OAMG;IACH,8BALW,MAAM,qBAoBhB;IAED;;;;;;;;;OASG;IACH,gCARW,MAAM,yBAEN,GAAC,sCAGC,GAAC,CA4Eb;IAED;;;;;OAKG;IACH,yBAMC;IAED;;;;OAIG;IACH,wBAHa,MAAO,SAAS,CAK5B;IAED;;;;OAIG;IACH,2BAHW,MAAM,QAoBhB;IAED;;;;OAIG;IACH,6BAWC;CACD;AAED;;;GAGG;AACH,sDAA6D;kCA/M3B,kBAAkB"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Live bindings context manager (direct global state)
|
|
3
|
+
* Uses direct instance tracking without AsyncLocalStorage overhead
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export class LiveContextManager {
|
|
7
|
+
instances: Map<any, any>;
|
|
8
|
+
currentInstanceID: any;
|
|
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?: any): any;
|
|
23
|
+
/**
|
|
24
|
+
* Run function with instance context active (live mode)
|
|
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
|
+
* @returns {*} Result of function execution
|
|
31
|
+
* @public
|
|
32
|
+
*/
|
|
33
|
+
public runInContext(instanceID: string, fn: Function, thisArg: any, args: any[], currentWrapper?: any): any;
|
|
34
|
+
/**
|
|
35
|
+
* Get current active context
|
|
36
|
+
* @returns {Object} Current context store
|
|
37
|
+
* @throws {SlothletError} If no active context
|
|
38
|
+
* @public
|
|
39
|
+
*/
|
|
40
|
+
public getContext(): any;
|
|
41
|
+
/**
|
|
42
|
+
* Try to get context (returns undefined instead of throwing)
|
|
43
|
+
* @returns {Object|undefined} Current context store or undefined
|
|
44
|
+
* @public
|
|
45
|
+
*/
|
|
46
|
+
public tryGetContext(): any | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* Cleanup instance context
|
|
49
|
+
* @param {string} instanceID - Instance to cleanup
|
|
50
|
+
* @public
|
|
51
|
+
*/
|
|
52
|
+
public cleanup(instanceID: string): void;
|
|
53
|
+
/**
|
|
54
|
+
* Get diagnostic information
|
|
55
|
+
* @returns {Object} Diagnostic data
|
|
56
|
+
* @public
|
|
57
|
+
*/
|
|
58
|
+
public getDiagnostics(): any;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Singleton live context manager
|
|
62
|
+
* @public
|
|
63
|
+
*/
|
|
64
|
+
export const liveContextManager: LiveContextManager;
|
|
65
|
+
//# sourceMappingURL=context-live.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-live.d.mts","sourceRoot":"","sources":["../../../../dist/lib/handlers/context-live.mjs"],"names":[],"mappings":"AAqBA;;;;GAIG;AACH;IAEE,yBAA0B;IAC1B,uBAA6B;IAG9B;;;;OAIG;IACH,kDAIC;IAED;;;;;;OAMG;IACH,8BALW,MAAM,qBA0BhB;IAED;;;;;;;;;OASG;IACH,gCARW,MAAM,yBAEN,GAAC,sCAGC,GAAC,CAoDb;IAED;;;;;OAKG;IACH,yBAmBC;IAED;;;;OAIG;IACH,wBAHa,MAAO,SAAS,CAQ5B;IAED;;;;OAIG;IACH,2BAHW,MAAM,QAyBhB;IAED;;;;OAIG;IACH,6BAWC;CACD;AAED;;;GAGG;AACH,oDAA2D"}
|