@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
|
@@ -1,152 +1,225 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* This is
|
|
4
|
-
*
|
|
5
|
-
* @
|
|
6
|
-
* @
|
|
7
|
-
* @
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
2
|
+
* Create a new Slothlet instance and load an API from a directory.
|
|
3
|
+
* This is the sole public entry point for slothlet. Each call produces an independent
|
|
4
|
+
* API instance with its own component graph, context store, and lifecycle.
|
|
5
|
+
* @alias module:@cldmv/slothlet
|
|
6
|
+
* @async
|
|
7
|
+
* @param {SlothletOptions} config - Configuration options
|
|
8
|
+
* @returns {Promise<SlothletAPI>} Fully loaded, proxy-based API object
|
|
9
|
+
* @public
|
|
10
|
+
* @example
|
|
11
|
+
* // Minimal usage
|
|
12
|
+
* const api = await slothlet({ dir: "./api" });
|
|
13
|
+
* const result = await api.math.add(2, 3);
|
|
14
|
+
* await api.slothlet.shutdown();
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* // Lazy mode with background materialization
|
|
18
|
+
* const api = await slothlet({
|
|
19
|
+
* dir: "./api",
|
|
20
|
+
* mode: "lazy",
|
|
21
|
+
* backgroundMaterialize: true
|
|
22
|
+
* });
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* // With hooks
|
|
26
|
+
* const api = await slothlet({ dir: "./api", hook: true });
|
|
27
|
+
* api.slothlet.hook.on("before", "**", (endpoint, args) => { /* ... *\/ });
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* // Hot-reload a module at runtime
|
|
31
|
+
* await api.slothlet.api.reload("./api/math.mjs");
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* // Strict collision control
|
|
35
|
+
* const api = await slothlet({
|
|
36
|
+
* dir: "./api",
|
|
37
|
+
* api: { collision: { initial: "merge", api: "error" } }
|
|
38
|
+
* });
|
|
15
39
|
*/
|
|
16
|
-
export
|
|
40
|
+
export function slothlet(config: SlothletOptions): Promise<SlothletAPI>;
|
|
41
|
+
export default slothlet;
|
|
17
42
|
/**
|
|
18
|
-
*
|
|
19
|
-
* @type {object}
|
|
20
|
-
* @private
|
|
21
|
-
* @internal
|
|
43
|
+
* Configuration options passed to `slothlet()`.
|
|
22
44
|
*/
|
|
23
|
-
export const reference: object;
|
|
24
|
-
export default slothlet;
|
|
25
45
|
export type SlothletOptions = {
|
|
26
46
|
/**
|
|
27
|
-
* - Directory to
|
|
28
|
-
* - Can be absolute or relative path.
|
|
29
|
-
* - If relative, resolved from the calling file's location.
|
|
30
|
-
* - Defaults to "api" directory relative to caller.
|
|
47
|
+
* - Directory to scan for API modules. Relative paths are resolved from the calling file.
|
|
31
48
|
*/
|
|
32
|
-
dir
|
|
49
|
+
dir: string;
|
|
33
50
|
/**
|
|
34
|
-
* - Loading strategy
|
|
35
|
-
* - `
|
|
36
|
-
* - `
|
|
51
|
+
* - Loading strategy.
|
|
52
|
+
* - `"eager"` — all modules are loaded immediately at startup (default).
|
|
53
|
+
* - `"lazy"` — modules are loaded on first access via a Proxy.
|
|
54
|
+
* Also accepted: `"immediate"` / `"preload"` (eager aliases); `"deferred"` / `"proxy"` (lazy aliases).
|
|
37
55
|
*/
|
|
38
|
-
|
|
56
|
+
mode?: "eager" | "lazy";
|
|
39
57
|
/**
|
|
40
|
-
* -
|
|
41
|
-
* - `"
|
|
42
|
-
* - `"
|
|
43
|
-
*
|
|
44
|
-
* - Takes precedence over lazy option when both are provided
|
|
58
|
+
* - Context propagation runtime.
|
|
59
|
+
* - `"async"` — AsyncLocalStorage (Node.js built-in, recommended for production).
|
|
60
|
+
* - `"live"` — Experimental live bindings.
|
|
61
|
+
* Also accepted: `"asynclocalstorage"` / `"als"` / `"node"` as aliases for `"async"`.
|
|
45
62
|
*/
|
|
46
|
-
|
|
63
|
+
runtime?: "async" | "live";
|
|
47
64
|
/**
|
|
48
|
-
* -
|
|
49
|
-
* - `"singleton"`: Single shared instance within current process (default, fastest)
|
|
50
|
-
* - `"vm"`: Isolated VM context for security/isolation
|
|
51
|
-
* - `"worker"`: Web Worker or Worker Thread execution
|
|
52
|
-
* - `"fork"`: Child process execution for complete isolation
|
|
65
|
+
* - Directory traversal depth. `Infinity` scans all subdirectories (default). `0` scans only the root.
|
|
53
66
|
*/
|
|
54
|
-
|
|
67
|
+
apiDepth?: number;
|
|
55
68
|
/**
|
|
56
|
-
* -
|
|
57
|
-
* - `"async"` or `"asynclocalstorage"`: Use AsyncLocalStorage for context isolation (default, recommended)
|
|
58
|
-
* - `"live"` or `"livebindings"`: Use live binding system for dynamic context updates
|
|
59
|
-
* - Controls how `self`, `context`, and `reference` bindings are managed across function calls
|
|
69
|
+
* - Object merged into the per-request context accessible inside API functions via `import { context } from "@cldmv/slothlet/runtime"`.
|
|
60
70
|
*/
|
|
61
|
-
|
|
71
|
+
context?: object | null;
|
|
62
72
|
/**
|
|
63
|
-
* -
|
|
64
|
-
* - `Infinity`: Traverse all subdirectories recursively (default)
|
|
65
|
-
* - `0`: Only load files in root directory, no subdirectories
|
|
66
|
-
* - `1`, `2`, etc.: Limit traversal to specified depth levels
|
|
73
|
+
* - Object whose properties are merged directly onto the root API and also available as `api.slothlet.reference`.
|
|
67
74
|
*/
|
|
68
|
-
|
|
75
|
+
reference?: object | null;
|
|
69
76
|
/**
|
|
70
|
-
* -
|
|
71
|
-
* - `true`: Enable verbose logging for module loading, API construction, and binding operations
|
|
72
|
-
* - `false`: Silent operation (default)
|
|
73
|
-
* - Can be set via command line flag `--slothletdebug`, environment variable `SLOTHLET_DEBUG=true`, or options parameter
|
|
74
|
-
* - Command line and environment settings become the default for all instances unless overridden
|
|
77
|
+
* - Controls how per-request scope data is merged. `"shallow"` merges top-level keys; `"deep"` recurses into nested objects.
|
|
75
78
|
*/
|
|
76
|
-
|
|
79
|
+
scope?: {
|
|
80
|
+
merge: "shallow" | "deep";
|
|
81
|
+
};
|
|
77
82
|
/**
|
|
78
|
-
* - API
|
|
79
|
-
* - `"auto"`: Auto-detect based on root module exports (function vs object) - recommended (default)
|
|
80
|
-
* - `"function"`: Force API to be callable as function with properties attached
|
|
81
|
-
* - `"object"`: Force API to be plain object with method properties
|
|
83
|
+
* - API build and mutation settings.
|
|
82
84
|
*/
|
|
83
|
-
|
|
85
|
+
api?: {
|
|
86
|
+
collision?: string | {
|
|
87
|
+
initial: string;
|
|
88
|
+
api: string;
|
|
89
|
+
};
|
|
90
|
+
mutations?: object;
|
|
91
|
+
};
|
|
84
92
|
/**
|
|
85
|
-
* -
|
|
86
|
-
* - `
|
|
87
|
-
* - `
|
|
88
|
-
* -
|
|
93
|
+
* - Hook system configuration.
|
|
94
|
+
* - `false` — disabled (default).
|
|
95
|
+
* - `true` — enabled, all endpoints.
|
|
96
|
+
* - `string` — enabled with a default glob pattern.
|
|
97
|
+
* - `object` — full control: `{ enabled: boolean, pattern?: string, suppressErrors?: boolean }`.
|
|
89
98
|
*/
|
|
90
|
-
|
|
99
|
+
hook?: boolean | string | object;
|
|
91
100
|
/**
|
|
92
|
-
* - Enable
|
|
93
|
-
* - `
|
|
94
|
-
* - `false`: Disable ownership tracking (default, no performance overhead)
|
|
95
|
-
* - When enabled, supports hot-reloading scenarios where modules can selectively overwrite only their own APIs
|
|
96
|
-
* - Requires moduleId parameter in addApi options when using forceOverwrite capability
|
|
101
|
+
* - Enable verbose internal logging. `true` enables all categories.
|
|
102
|
+
* Pass an object with sub-keys `builder`, `api`, `index`, `modes`, `wrapper`, `ownership`, `context` to target specific subsystems.
|
|
97
103
|
*/
|
|
98
|
-
|
|
104
|
+
debug?: boolean | object;
|
|
99
105
|
/**
|
|
100
|
-
* -
|
|
101
|
-
* - Available to all loaded modules via `import { context } from "@cldmv/slothlet/runtime"`. Useful for request data,
|
|
102
|
-
* - user sessions, environment configs, etc.
|
|
106
|
+
* - Suppress all console output from slothlet (warnings, deprecations). Does not affect `debug`.
|
|
103
107
|
*/
|
|
104
|
-
|
|
108
|
+
silent?: boolean;
|
|
105
109
|
/**
|
|
106
|
-
* -
|
|
107
|
-
* - Properties not conflicting with loaded modules are added directly to the API.
|
|
108
|
-
* - Useful for utility functions, constants, or external service connections.
|
|
110
|
+
* - Enable the `api.slothlet.diag.*` introspection namespace. Intended for testing; do not enable in production.
|
|
109
111
|
*/
|
|
110
|
-
|
|
112
|
+
diagnostics?: boolean;
|
|
111
113
|
/**
|
|
112
|
-
* -
|
|
113
|
-
* - Controls how file names are converted to valid JavaScript identifiers.
|
|
114
|
-
* - Default behavior: camelCase conversion with lowerFirst=true.
|
|
114
|
+
* - Enable internal tracking. Pass `true` or `{ materialization: true }` to track lazy-mode materialization progress.
|
|
115
115
|
*/
|
|
116
|
-
|
|
117
|
-
lowerFirst?: boolean;
|
|
118
|
-
preserveAllUpper?: boolean;
|
|
119
|
-
preserveAllLower?: boolean;
|
|
120
|
-
rules?: {
|
|
121
|
-
leave?: string[];
|
|
122
|
-
leaveInsensitive?: string[];
|
|
123
|
-
upper?: string[];
|
|
124
|
-
lower?: string[];
|
|
125
|
-
};
|
|
126
|
-
};
|
|
127
|
-
};
|
|
128
|
-
export type SlothletAPI = {
|
|
116
|
+
tracking?: boolean | object;
|
|
129
117
|
/**
|
|
130
|
-
* -
|
|
118
|
+
* - When `mode: "lazy"`, immediately begins materializing all paths in the background after init.
|
|
131
119
|
*/
|
|
132
|
-
|
|
120
|
+
backgroundMaterialize?: boolean;
|
|
133
121
|
/**
|
|
134
|
-
* -
|
|
122
|
+
* - Internationalization settings (dev-facing, process-global).
|
|
123
|
+
* `{ language: string }` — selects the locale for framework messages (e.g. `"en-us"`, `"fr-fr"`, `"ja-jp"`).
|
|
135
124
|
*/
|
|
136
|
-
|
|
125
|
+
i18n?: object;
|
|
137
126
|
/**
|
|
138
|
-
* -
|
|
127
|
+
* - TypeScript support.
|
|
128
|
+
* - `false` — disabled (default).
|
|
129
|
+
* - `true` or `"fast"` — esbuild transpilation, no type checking.
|
|
130
|
+
* - `"strict"` — tsc compilation with type checking and `.d.ts` generation.
|
|
131
|
+
* See [TYPESCRIPT.md](docs/TYPESCRIPT.md) for the full configuration reference.
|
|
139
132
|
*/
|
|
140
|
-
|
|
133
|
+
typescript?: boolean | "fast" | "strict" | object;
|
|
141
134
|
};
|
|
142
135
|
/**
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
* @async
|
|
146
|
-
* @alias module:@cldmv/slothlet
|
|
147
|
-
* @param {SlothletOptions} [options={}] - Configuration options for creating the API
|
|
148
|
-
* @returns {Promise<SlothletAPI>} The bound API object or function with management methods
|
|
149
|
-
* @public
|
|
136
|
+
* Bound API object returned by `slothlet()`.
|
|
137
|
+
* The root contains all loaded module exports plus the reserved `slothlet` namespace.
|
|
150
138
|
*/
|
|
151
|
-
export
|
|
139
|
+
export type SlothletAPI = {
|
|
140
|
+
/**
|
|
141
|
+
* - Like `shutdown()` but additionally invokes registered destroy hooks before teardown. %%sig: (): void%% %%example: // ESM usage via slothlet API|import slothlet from "@cldmv/slothlet";|const api = await slothlet({ dir: './api' });|await api.destroy();%% %%example: // ESM usage via slothlet API (inside async function)|async function example() {| const { default: slothlet } = await import("@cldmv/slothlet");| const api = await slothlet({ dir: './api' });| await api.destroy();|}%% %%example: // CJS usage via slothlet API (top-level)|let slothlet;|(async () => {| ({ slothlet } = await import("@cldmv/slothlet"));| const api = await slothlet({ dir: './api' });| await api.destroy();|})();%% %%example: // CJS usage via slothlet API (inside async function)|const slothlet = require("@cldmv/slothlet");|const api = await slothlet({ dir: './api' });|await api.destroy();%%
|
|
142
|
+
*/
|
|
143
|
+
destroy: () => void;
|
|
144
|
+
/**
|
|
145
|
+
* - Convenience alias for `slothlet.shutdown()`. Shuts down the instance and invokes any user-provided shutdown hook first. %%sig: (): void%% %%example: // ESM usage via slothlet API|import slothlet from "@cldmv/slothlet";|const api = await slothlet({ dir: './api' });|await api.shutdown();%% %%example: // ESM usage via slothlet API (inside async function)|async function example() {| const { default: slothlet } = await import("@cldmv/slothlet");| const api = await slothlet({ dir: './api' });| await api.shutdown();|}%% %%example: // CJS usage via slothlet API (top-level)|let slothlet;|(async () => {| ({ slothlet } = await import("@cldmv/slothlet"));| const api = await slothlet({ dir: './api' });| await api.shutdown();|})();%% %%example: // CJS usage via slothlet API (inside async function)|const slothlet = require("@cldmv/slothlet");|const api = await slothlet({ dir: './api' });|await api.shutdown();%%
|
|
146
|
+
*/
|
|
147
|
+
shutdown: () => void;
|
|
148
|
+
/**
|
|
149
|
+
* - Built-in control namespace. All framework internals live here to avoid collisions with loaded modules.
|
|
150
|
+
*/
|
|
151
|
+
slothlet: {
|
|
152
|
+
api: {
|
|
153
|
+
add: Function;
|
|
154
|
+
reload: Function;
|
|
155
|
+
remove: Function;
|
|
156
|
+
};
|
|
157
|
+
context: {
|
|
158
|
+
get: Function;
|
|
159
|
+
inspect: () => any;
|
|
160
|
+
run: Function;
|
|
161
|
+
scope: Function;
|
|
162
|
+
set: Function;
|
|
163
|
+
};
|
|
164
|
+
diag?: {
|
|
165
|
+
caches?: {
|
|
166
|
+
get?: () => any;
|
|
167
|
+
getAllModuleIDs?: () => string[];
|
|
168
|
+
has?: Function;
|
|
169
|
+
};
|
|
170
|
+
context?: object;
|
|
171
|
+
describe?: Function;
|
|
172
|
+
getAPI?: () => any;
|
|
173
|
+
getOwnership?: () => any;
|
|
174
|
+
hook?: object;
|
|
175
|
+
inspect?: () => any;
|
|
176
|
+
owner?: {
|
|
177
|
+
get?: Function;
|
|
178
|
+
};
|
|
179
|
+
reference?: object;
|
|
180
|
+
SlothletWarning?: () => SlothletWarning;
|
|
181
|
+
};
|
|
182
|
+
hook: {
|
|
183
|
+
clear: Function;
|
|
184
|
+
disable: Function;
|
|
185
|
+
enable: Function;
|
|
186
|
+
list: Function;
|
|
187
|
+
off: Function;
|
|
188
|
+
on: Function;
|
|
189
|
+
remove: Function;
|
|
190
|
+
};
|
|
191
|
+
lifecycle: {
|
|
192
|
+
off: Function;
|
|
193
|
+
on: Function;
|
|
194
|
+
};
|
|
195
|
+
materialize: {
|
|
196
|
+
get: () => any;
|
|
197
|
+
materialized: boolean;
|
|
198
|
+
wait: () => Promise<void>;
|
|
199
|
+
};
|
|
200
|
+
metadata: {
|
|
201
|
+
caller: () => any | null;
|
|
202
|
+
get: Function;
|
|
203
|
+
remove: Function;
|
|
204
|
+
removeFor: Function;
|
|
205
|
+
self: () => any | null;
|
|
206
|
+
set: Function;
|
|
207
|
+
setFor: Function;
|
|
208
|
+
setGlobal: Function;
|
|
209
|
+
};
|
|
210
|
+
owner: {
|
|
211
|
+
get: Function;
|
|
212
|
+
};
|
|
213
|
+
ownership: {
|
|
214
|
+
get: Function;
|
|
215
|
+
unregister: Function;
|
|
216
|
+
};
|
|
217
|
+
reference?: object;
|
|
218
|
+
reload: Function;
|
|
219
|
+
run: Function;
|
|
220
|
+
scope: Function;
|
|
221
|
+
shutdown: () => Promise<void>;
|
|
222
|
+
};
|
|
223
|
+
};
|
|
224
|
+
import { SlothletWarning } from "@cldmv/slothlet/errors";
|
|
152
225
|
//# sourceMappingURL=slothlet.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slothlet.d.mts","sourceRoot":"","sources":["../../dist/slothlet.mjs"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"slothlet.d.mts","sourceRoot":"","sources":["../../dist/slothlet.mjs"],"names":[],"mappings":"AAk2BA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,iCAjCW,eAAe,GACb,OAAO,CAAC,WAAW,CAAC,CAsChC;;;;;;;;;SAWa,MAAM;;;;;;;WACN,OAAO,GAAC,MAAM;;;;;;;cAId,OAAO,GAAC,MAAM;;;;eAId,MAAM;;;;cACN,MAAM,GAAC,IAAI;;;;gBACX,MAAM,GAAC,IAAI;;;;YACX;QAAC,KAAK,EAAE,SAAS,GAAC,MAAM,CAAA;KAAC;;;;UAEpC;QAAuD,SAAS,GAArD,MAAM,GAAC;YAAC,OAAO,EAAE,MAAM,CAAC;YAAC,GAAG,EAAE,MAAM,CAAA;SAAC;QAGxB,SAAS,GAAtB,MAAM;KAEjB;;;;;;;;WAAW,OAAO,GAAC,MAAM,GAAC,MAAM;;;;;YAKrB,OAAO,GAAC,MAAM;;;;aAEd,OAAO;;;;kBACP,OAAO;;;;eACP,OAAO,GAAC,MAAM;;;;4BACd,OAAO;;;;;WACP,MAAM;;;;;;;;iBAEN,OAAO,GAAC,MAAM,GAAC,QAAQ,GAAC,MAAM;;;;;;;;;;aAW9B,MAAY,IAAI;;;;cAChB,MAAY,IAAI;;;;cAE3B;QAA4B,GAAG,EAC/B;YAAkC,GAAG;YACH,MAAM;YACN,MAAM;SACxC;QAA4B,OAAO,EACnC;YAAsC,GAAG;YACO,OAAO,EAA5C,SAAkB;YACS,GAAG;YACH,KAAK;YACL,GAAG;SACzC;QAA6B,IAAI,GACjC;YAAkC,MAAM,GACxC;gBAAqD,GAAG,GAA7C,SAAkB;gBAC0B,eAAe,GAA3D,MAAY,MAAM,EAAE;gBACY,GAAG;aAC9C;YAAkC,OAAO,GAA9B,MAAM;YACmB,QAAQ;YACE,MAAM,GAAzC,SAAkB;YACiB,YAAY,GAA/C,SAAkB;YACK,IAAI,GAA3B,MAAM;YAC6B,OAAO,GAA1C,SAAkB;YACK,KAAK,GACvC;gBAA0C,GAAG;aAC7C;YAAkC,SAAS,GAAhC,MAAM;YACsC,eAAe,GAA3D,MAAY,eAAe;SACtC;QAA4B,IAAI,EAChC;YAAmC,KAAK;YACL,OAAO;YACP,MAAM;YACN,IAAI;YACJ,GAAG;YACH,EAAE;YACF,MAAM;SACzC;QAA4B,SAAS,EACrC;YAAwC,GAAG;YACH,EAAE;SAC1C;QAA4B,WAAW,EACvC;YAAoD,GAAG,EAA5C,SAAkB;YACY,YAAY,EAA1C,OAAO;YAC0C,IAAI,EAArD,MAAY,OAAO,CAAE,IAAI,CAAC;SACrC;QAA4B,QAAQ,EACpC;YAAsD,MAAM,EAAjD,MAAY,MAAO,IAAI;YACK,GAAG;YACH,MAAM;YACN,SAAS;YACM,IAAI,EAA/C,MAAY,MAAO,IAAI;YACK,GAAG;YACH,MAAM;YACN,SAAS;SAChD;QAA4B,KAAK,EACjC;YAAoC,GAAG;SACvC;QAA4B,SAAS,EACrC;YAAwC,GAAG;YACH,UAAU;SAClD;QAA6B,SAAS,GAA3B,MAAM;QACa,MAAM;QACN,GAAG;QACH,KAAK;QACa,QAAQ,EAA7C,MAAY,OAAO,CAAE,IAAI,CAAC;KACvC;;gCA56B6D,wBAAwB"}
|
package/types/index.d.mts
CHANGED
|
@@ -11,9 +11,7 @@ export type * from "./dist/slothlet.d.mts";
|
|
|
11
11
|
export * from "./dist/slothlet.mts";
|
|
12
12
|
|
|
13
13
|
// Auto-generated named export declarations (these override the re-export above)
|
|
14
|
-
export const
|
|
15
|
-
export const reference: any;
|
|
16
|
-
export const self: any;
|
|
14
|
+
export const async: any;
|
|
17
15
|
|
|
18
16
|
// Main slothlet export
|
|
19
17
|
declare const slothlet: any;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
# src/lib Experimental Code
|
|
2
|
-
|
|
3
|
-
This folder contains experimental modules for the slothlet API loader. The code here is either not working, partially working, or not fully tested. Use at your own risk.
|
|
4
|
-
|
|
5
|
-
## Purpose
|
|
6
|
-
|
|
7
|
-
The files in this folder are prototypes and work-in-progress implementations for advanced features in slothlet, such as:
|
|
8
|
-
|
|
9
|
-
- **slothlet_child.mjs**: Experiments with child process or worker-based API loading and isolation.
|
|
10
|
-
- **slothlet_engine.mjs**: Attempts to provide a modular engine for API loading, context binding, and shutdown management.
|
|
11
|
-
- **slothlet_esm.mjs**: Explores ES module dynamic loading and compatibility.
|
|
12
|
-
- **slothlet_helpers.mjs**: Utility functions for API flattening, key conversion, and module handling.
|
|
13
|
-
- **slothlet_worker.mjs**: Prototypes for worker thread-based API execution and communication.
|
|
14
|
-
|
|
15
|
-
## Status
|
|
16
|
-
|
|
17
|
-
These modules are not guaranteed to work and may be incomplete, buggy, or subject to breaking changes. They are intended for experimentation and future development, not for production use.
|
|
18
|
-
|
|
19
|
-
## Contribution
|
|
20
|
-
|
|
21
|
-
If you wish to contribute, please review the code and leave comments or suggestions. Any improvements or bug fixes are welcome, but stability is not guaranteed.
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2026 CLDMV/Shinrai
|
|
3
|
-
|
|
4
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
you may not use this file except in compliance with the License.
|
|
6
|
-
You may obtain a copy of the License at
|
|
7
|
-
|
|
8
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
|
|
10
|
-
Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
See the License for the specific language governing permissions and
|
|
14
|
-
limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
import { installGlobalsInCurrentRealm, extendSelfWithReference, installPortalForSelf } from "./slothlet_helpers.mjs";
|
|
20
|
-
|
|
21
|
-
let initialized = false;
|
|
22
|
-
|
|
23
|
-
process.on("message", async (msg) => {
|
|
24
|
-
try {
|
|
25
|
-
if (msg.t === "init") {
|
|
26
|
-
if (initialized) return;
|
|
27
|
-
initialized = true;
|
|
28
|
-
|
|
29
|
-
const { entry, loadConfig, contextMap, reference } = msg;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
installGlobalsInCurrentRealm(contextMap);
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const { slothlet } = await import(entry);
|
|
36
|
-
if (!slothlet) throw new Error("Entry did not export `slothlet`");
|
|
37
|
-
|
|
38
|
-
const api = await slothlet.load(loadConfig, { context: contextMap, reference });
|
|
39
|
-
globalThis.self = api;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
extendSelfWithReference(globalThis.self, reference);
|
|
43
|
-
installPortalForSelf();
|
|
44
|
-
|
|
45
|
-
process.send({ id: msg.id, ok: 1, result: true });
|
|
46
|
-
} else if (msg.t === "call") {
|
|
47
|
-
const result = await globalThis._portal.call(msg.path, msg.args || []);
|
|
48
|
-
process.send({ id: msg.id, ok: 1, result });
|
|
49
|
-
} else if (msg.t === "batch") {
|
|
50
|
-
const result = await globalThis._portal.batch(msg.ops || []);
|
|
51
|
-
process.send({ id: msg.id, ok: 1, result });
|
|
52
|
-
} else if (msg.t === "dispose") {
|
|
53
|
-
process.send({ id: msg.id, ok: 1, result: true });
|
|
54
|
-
process.exit(0);
|
|
55
|
-
}
|
|
56
|
-
} catch (e) {
|
|
57
|
-
process.send({ id: msg.id, ok: 0, error: String(e?.stack || e) });
|
|
58
|
-
}
|
|
59
|
-
});
|