@cldmv/slothlet 3.0.1 → 3.1.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/README.md +10 -13
- package/dist/lib/builders/api_builder.mjs +4 -1
- package/dist/lib/helpers/config.mjs +14 -1
- package/dist/lib/i18n/translations.mjs +2 -0
- package/dist/slothlet.mjs +28 -0
- package/package.json +1 -1
- package/types/dist/lib/builders/api_builder.d.mts.map +1 -1
- package/types/dist/lib/helpers/config.d.mts +33 -0
- package/types/dist/lib/helpers/config.d.mts.map +1 -1
- package/types/dist/lib/i18n/translations.d.mts.map +1 -1
- package/types/dist/slothlet.d.mts +10 -0
- package/types/dist/slothlet.d.mts.map +1 -1
package/README.md
CHANGED
|
@@ -55,23 +55,20 @@ Every feature has been hardened with a comprehensive test suite - over **5,300 t
|
|
|
55
55
|
|
|
56
56
|
## ✨ What's New
|
|
57
57
|
|
|
58
|
-
### Latest: v3.
|
|
58
|
+
### Latest: v3.1.0 (March 2026)
|
|
59
59
|
|
|
60
|
-
- **
|
|
61
|
-
- **
|
|
62
|
-
- **
|
|
63
|
-
-
|
|
64
|
-
- **Lifecycle Event System** - `api.slothlet.lifecycle.on/off()` for module lifecycle events
|
|
65
|
-
- **Collision Modes** - fine-grained control over API namespace conflicts
|
|
66
|
-
- **Mutation Controls** - per-operation access restrictions for API mutations
|
|
67
|
-
- [View full v3.0 Changelog](./docs/changelog/v3.0.md)
|
|
60
|
+
- **Environment Snapshot** — `api.slothlet.env` exposes a frozen copy of `process.env` captured at initialization time; every module accesses it via `self.slothlet.env`
|
|
61
|
+
- **`env.include` Allowlist** — restrict the snapshot to specific keys with `env: { include: ["NODE_ENV", "PORT"] }`; empty array falls back to full snapshot
|
|
62
|
+
- **Reload Immunity** — snapshot is captured once on first `load()` and never replaced on subsequent `api.slothlet.reload()` calls (including partial `api.slothlet.api.reload()` calls)
|
|
63
|
+
- [View full v3.1.0 Changelog](./docs/changelog/v3/v3.1.0.md)
|
|
68
64
|
|
|
69
65
|
### Recent Releases
|
|
70
66
|
|
|
71
|
-
- **
|
|
72
|
-
- **
|
|
73
|
-
- **v2.
|
|
74
|
-
- **v2.
|
|
67
|
+
- **v3.0.1** (March 2026) — Resolver fix for user `index.mjs` mis-classified as internal; CI `slothlet-dev` stripping hardening; respawn race fix; resilient `build:dist` script ([Changelog](./docs/changelog/v3/v3.0.1.md))
|
|
68
|
+
- **v3.0.0** (February 2026) — Unified Wrapper architecture, redesigned hook system, full i18n, background materialization, lifecycle events, collision modes, mutation controls ([Changelog](./docs/changelog/v3.0.md))
|
|
69
|
+
- **v2.11.0** — AddApi Special File Pattern (Rule 11), smart flattening enhancements ([Changelog](https://github.com/CLDMV/slothlet/blob/master/docs/changelog/v2.11.md))
|
|
70
|
+
- **v2.10.0** — Function metadata tagging and introspection capabilities ([Changelog](https://github.com/CLDMV/slothlet/blob/master/docs/changelog/v2.10.md))
|
|
71
|
+
- **v2.9** — Per-Request Context Isolation ([Changelog](https://github.com/CLDMV/slothlet/blob/master/docs/changelog/v2.9.md))
|
|
75
72
|
|
|
76
73
|
📚 **For complete version history and detailed release notes, see [docs/changelog/](./docs/changelog/) folder.**
|
|
77
74
|
|
|
@@ -299,7 +299,8 @@ export class Config extends ComponentBase {
|
|
|
299
299
|
tracking: trackingConfig,
|
|
300
300
|
backgroundMaterialize: config.backgroundMaterialize === true,
|
|
301
301
|
silent: config.silent === true,
|
|
302
|
-
typescript: this.normalizeTypeScript(config.typescript)
|
|
302
|
+
typescript: this.normalizeTypeScript(config.typescript),
|
|
303
|
+
env: this.normalizeEnv(config.env)
|
|
303
304
|
};
|
|
304
305
|
}
|
|
305
306
|
|
|
@@ -340,4 +341,16 @@ export class Config extends ComponentBase {
|
|
|
340
341
|
|
|
341
342
|
return null;
|
|
342
343
|
}
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
normalizeEnv(env) {
|
|
347
|
+
if (!env || typeof env !== "object") {
|
|
348
|
+
return null;
|
|
349
|
+
}
|
|
350
|
+
const include = Array.isArray(env.include) ? env.include.filter((k) => typeof k === "string") : null;
|
|
351
|
+
if (include && include.length > 0) {
|
|
352
|
+
return { include };
|
|
353
|
+
}
|
|
354
|
+
return null;
|
|
355
|
+
}
|
|
343
356
|
}
|
package/dist/slothlet.mjs
CHANGED
|
@@ -58,6 +58,9 @@ class Slothlet {
|
|
|
58
58
|
this.context = null;
|
|
59
59
|
|
|
60
60
|
|
|
61
|
+
this.envSnapshot = null;
|
|
62
|
+
|
|
63
|
+
|
|
61
64
|
this._totalLazyCount = 0;
|
|
62
65
|
this._unmaterializedLazyCount = 0;
|
|
63
66
|
this._materializationComplete = false;
|
|
@@ -291,6 +294,22 @@ class Slothlet {
|
|
|
291
294
|
}
|
|
292
295
|
|
|
293
296
|
|
|
297
|
+
_captureEnvSnapshot(envConfig) {
|
|
298
|
+
const rawInclude = envConfig?.include;
|
|
299
|
+
const include = Array.isArray(rawInclude) ? rawInclude.filter((key) => typeof key === "string") : null;
|
|
300
|
+
const useAllowlist = include !== null && include.length > 0;
|
|
301
|
+
const raw = useAllowlist
|
|
302
|
+
? include.reduce((acc, key) => {
|
|
303
|
+
if (Object.prototype.hasOwnProperty.call(process.env, key)) {
|
|
304
|
+
acc[key] = process.env[key];
|
|
305
|
+
}
|
|
306
|
+
return acc;
|
|
307
|
+
}, Object.create(null))
|
|
308
|
+
: { ...process.env };
|
|
309
|
+
return Object.freeze(raw);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
|
|
294
313
|
async load(config = {}, preservedInstanceID = null) {
|
|
295
314
|
|
|
296
315
|
this.config = config;
|
|
@@ -298,6 +317,15 @@ class Slothlet {
|
|
|
298
317
|
|
|
299
318
|
|
|
300
319
|
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
if (!this.envSnapshot) {
|
|
323
|
+
this.envSnapshot = this._captureEnvSnapshot(config.env);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
|
|
301
329
|
this.debugLogger = new SlothletDebug(config);
|
|
302
330
|
|
|
303
331
|
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api_builder.d.mts","sourceRoot":"","sources":["../../../../dist/lib/builders/api_builder.mjs"],"names":[],"mappings":"AAkEA;;;;;;;;;;;;;GAaG;AACH;IACC,gCAAuC;IAcvC;;;;;OAKG;IACH,oCAHa,OAAO,KAAQ,CAiG3B;IAED;;;;;;;;;;;OAWG;IACH,
|
|
1
|
+
{"version":3,"file":"api_builder.d.mts","sourceRoot":"","sources":["../../../../dist/lib/builders/api_builder.mjs"],"names":[],"mappings":"AAkEA;;;;;;;;;;;;;GAaG;AACH;IACC,gCAAuC;IAcvC;;;;;OAKG;IACH,oCAHa,OAAO,KAAQ,CAiG3B;IAED;;;;;;;;;;;OAWG;IACH,gCAijCC;IAED;;;;OAIG;IACH,+BAYC;IAED;;;;OAIG;IACH,0BAgCC;IAED;;;;OAIG;IACH,4BAoMC;IAED;;;;;OAKG;IACH,8BAyCC;IAED;;;;;OAKG;IACH,uBAgCC;CACD;;;;;;;;;;;;;;;;;;;;;;;;;;8BAtkD6B,0CAA0C"}
|
|
@@ -91,6 +91,39 @@ export class Config extends ComponentBase {
|
|
|
91
91
|
* @public
|
|
92
92
|
*/
|
|
93
93
|
public normalizeTypeScript(typescript: boolean | string | any): any | null;
|
|
94
|
+
/**
|
|
95
|
+
* Normalize env snapshot configuration.
|
|
96
|
+
*
|
|
97
|
+
* @description
|
|
98
|
+
* Validates the `env` option from user config. When `include` is a non-empty
|
|
99
|
+
* string array, returns `{ include }` (the allowlist used by `_captureEnvSnapshot`).
|
|
100
|
+
* Any other value — including `undefined`, `null`, `{}`, or an empty `include`
|
|
101
|
+
* array — is normalised to `null`, meaning the full `process.env` snapshot is used.
|
|
102
|
+
*
|
|
103
|
+
* @param {Object|null|undefined} env - Raw env option from user config.
|
|
104
|
+
* @param {string[]} [env.include] - Allowlist of env variable names to capture.
|
|
105
|
+
* @returns {{ include: string[] }|null} Normalized env config, or `null` for full snapshot.
|
|
106
|
+
* @public
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* // No restriction — full snapshot
|
|
110
|
+
* normalizeEnv(undefined); // => null
|
|
111
|
+
* normalizeEnv(null); // => null
|
|
112
|
+
* normalizeEnv({}); // => null
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* // Include allowlist
|
|
116
|
+
* normalizeEnv({ include: ["NODE_ENV", "PORT"] });
|
|
117
|
+
* // => { include: ["NODE_ENV", "PORT"] }
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* // Non-string keys in the include array are filtered out
|
|
121
|
+
* normalizeEnv({ include: ["NODE_ENV", 42, null] });
|
|
122
|
+
* // => { include: ["NODE_ENV"] }
|
|
123
|
+
*/
|
|
124
|
+
public normalizeEnv(env: any | null | undefined): {
|
|
125
|
+
include: string[];
|
|
126
|
+
} | null;
|
|
94
127
|
}
|
|
95
128
|
import { ComponentBase } from "@cldmv/slothlet/factories/component-base";
|
|
96
129
|
//# sourceMappingURL=config.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.mts","sourceRoot":"","sources":["../../../../dist/lib/helpers/config.mjs"],"names":[],"mappings":"AAoBA;;;;;GAKG;AACH;IACC,gCAAmC;IAEnC;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACH,qCAxBW,MAAM,MAAO,OAkDvB;IAED;;;;;OAKG;IACH,iCAJW,MAAM,GACJ,MAAM,CAsBlB;IAED;;;;;OAKG;IACH,2BAJW,MAAM,GACJ,MAAM,CAsBlB;IAED;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,+CAcC;IAED;;;;;OAKG;IACH,6BAJW,OAAO,MAAO,OA6DxB;IAED;;;;;;OAMG;IACH,
|
|
1
|
+
{"version":3,"file":"config.d.mts","sourceRoot":"","sources":["../../../../dist/lib/helpers/config.mjs"],"names":[],"mappings":"AAoBA;;;;;GAKG;AACH;IACC,gCAAmC;IAEnC;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACH,qCAxBW,MAAM,MAAO,OAkDvB;IAED;;;;;OAKG;IACH,iCAJW,MAAM,GACJ,MAAM,CAsBlB;IAED;;;;;OAKG;IACH,2BAJW,MAAM,GACJ,MAAM,CAsBlB;IAED;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,+CAcC;IAED;;;;;OAKG;IACH,6BAJW,OAAO,MAAO,OA6DxB;IAED;;;;;;OAMG;IACH,0CAgIC;IAED;;;;;OAKG;IACH,uCAJW,OAAO,GAAC,MAAM,MAAO,GACnB,MAAO,IAAI,CAsCvB;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6BG;IACH,yBArBW,MAAO,IAAI,GAAC,SAAS,GAEnB;QAAE,OAAO,EAAE,MAAM,EAAE,CAAA;KAAE,GAAC,IAAI,CA4BtC;CACD;8BAzb6B,0CAA0C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"translations.d.mts","sourceRoot":"","sources":["../../../../dist/lib/i18n/translations.mjs"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"translations.d.mts","sourceRoot":"","sources":["../../../../dist/lib/i18n/translations.mjs"],"names":[],"mappings":"AAuFA;;;;;GAKG;AACH,kCAHW,MAAM,QAsBhB;AAED;;;;GAIG;AACH,+BAHa,MAAM,CAKlB;AAED;;;;;;GAMG;AACH,qCALW,MAAM,iBAEJ,MAAM,CAyBlB;AAED;;;;;GAKG;AACH,mCAHG;IAAyB,QAAQ,GAAzB,MAAM;CACd,QAiBF;AApDD;;;;;;GAMG;AACH,6BALW,MAAM,iBAEJ,MAAM,CAyBlB"}
|
|
@@ -123,6 +123,15 @@ export type SlothletOptions = {
|
|
|
123
123
|
* `{ language: string }` — selects the locale for framework messages (e.g. `"en-us"`, `"fr-fr"`, `"ja-jp"`).
|
|
124
124
|
*/
|
|
125
125
|
i18n?: object;
|
|
126
|
+
/**
|
|
127
|
+
* - Environment variable snapshot configuration.
|
|
128
|
+
* Pass `{ include: ["KEY"] }` to capture only the listed variable names in `api.slothlet.env`.
|
|
129
|
+
* Omit (or pass `undefined`) to capture a full frozen snapshot of `process.env`.
|
|
130
|
+
* Non-string entries in `include` are silently ignored; an all-non-string array falls back to the full snapshot.
|
|
131
|
+
*/
|
|
132
|
+
env?: {
|
|
133
|
+
include?: string[];
|
|
134
|
+
};
|
|
126
135
|
/**
|
|
127
136
|
* - TypeScript support.
|
|
128
137
|
* - `false` — disabled (default).
|
|
@@ -149,6 +158,7 @@ export type SlothletAPI = {
|
|
|
149
158
|
* - Built-in control namespace. All framework internals live here to avoid collisions with loaded modules.
|
|
150
159
|
*/
|
|
151
160
|
slothlet: {
|
|
161
|
+
env: Readonly<Record<string, string | undefined>>;
|
|
152
162
|
api: {
|
|
153
163
|
add: Function;
|
|
154
164
|
reload: Function;
|
|
@@ -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":"AAq5BA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;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