@cldmv/slothlet 2.9.0 → 2.10.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 +68 -0
- package/dist/lib/engine/slothlet_child.mjs +1 -1
- package/dist/lib/engine/slothlet_engine.mjs +1 -1
- package/dist/lib/engine/slothlet_esm.mjs +1 -1
- package/dist/lib/engine/slothlet_helpers.mjs +1 -1
- package/dist/lib/engine/slothlet_worker.mjs +1 -1
- package/dist/lib/helpers/als-eventemitter.mjs +1 -1
- package/dist/lib/helpers/api_builder/add_api.mjs +58 -3
- package/dist/lib/helpers/api_builder/analysis.mjs +13 -3
- package/dist/lib/helpers/api_builder/construction.mjs +1 -1
- package/dist/lib/helpers/api_builder/decisions.mjs +1 -1
- package/dist/lib/helpers/api_builder/metadata.mjs +248 -0
- package/dist/lib/helpers/api_builder.mjs +1 -1
- package/dist/lib/helpers/auto-wrap.mjs +1 -1
- package/dist/lib/helpers/hooks.mjs +1 -1
- package/dist/lib/helpers/instance-manager.mjs +1 -1
- package/dist/lib/helpers/metadata-api.mjs +201 -0
- package/dist/lib/helpers/multidefault.mjs +12 -3
- package/dist/lib/helpers/resolve-from-caller.mjs +1 -1
- package/dist/lib/helpers/sanitize.mjs +1 -1
- package/dist/lib/helpers/utilities.mjs +1 -1
- package/dist/lib/modes/slothlet_eager.mjs +1 -1
- package/dist/lib/modes/slothlet_lazy.mjs +10 -1
- package/dist/lib/runtime/runtime-asynclocalstorage.mjs +5 -1
- package/dist/lib/runtime/runtime-livebindings.mjs +5 -1
- package/dist/lib/runtime/runtime.mjs +12 -1
- package/dist/slothlet.mjs +19 -3
- package/package.json +1 -1
- package/types/dist/lib/helpers/api_builder/add_api.d.mts +17 -1
- package/types/dist/lib/helpers/api_builder/add_api.d.mts.map +1 -1
- package/types/dist/lib/helpers/api_builder/analysis.d.mts.map +1 -1
- package/types/dist/lib/helpers/api_builder/metadata.d.mts +99 -0
- package/types/dist/lib/helpers/api_builder/metadata.d.mts.map +1 -0
- package/types/dist/lib/helpers/metadata-api.d.mts +132 -0
- package/types/dist/lib/helpers/metadata-api.d.mts.map +1 -0
- package/types/dist/lib/helpers/multidefault.d.mts.map +1 -1
- package/types/dist/lib/runtime/runtime-asynclocalstorage.d.mts +2 -0
- package/types/dist/lib/runtime/runtime-asynclocalstorage.d.mts.map +1 -1
- package/types/dist/lib/runtime/runtime-livebindings.d.mts +2 -0
- package/types/dist/lib/runtime/runtime-livebindings.d.mts.map +1 -1
- package/types/dist/lib/runtime/runtime.d.mts +1 -0
- package/types/dist/lib/runtime/runtime.d.mts.map +1 -1
- package/types/dist/slothlet.d.mts.map +1 -1
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
export namespace metadataAPI {
|
|
2
|
+
/**
|
|
3
|
+
* Get metadata of the function that called the current function.
|
|
4
|
+
*
|
|
5
|
+
* @function caller
|
|
6
|
+
* @memberof metadataAPI
|
|
7
|
+
* @returns {object|null} Caller's metadata object or null if not found
|
|
8
|
+
* @public
|
|
9
|
+
*
|
|
10
|
+
* @description
|
|
11
|
+
* Uses stack trace analysis to identify the calling function and retrieve
|
|
12
|
+
* its attached metadata. Useful for implementing access control where a
|
|
13
|
+
* function needs to verify the identity/permissions of its caller.
|
|
14
|
+
*
|
|
15
|
+
* Stack trace structure:
|
|
16
|
+
* - Line 0: Error
|
|
17
|
+
* - Line 1: metadataAPI.caller (this function)
|
|
18
|
+
* - Line 2: Current function (the one checking)
|
|
19
|
+
* - Line 3: The caller we want to identify
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* // In a secure function
|
|
23
|
+
* import { metadataAPI } from "@cldmv/slothlet/runtime";
|
|
24
|
+
*
|
|
25
|
+
* export function getSecrets() {
|
|
26
|
+
* const caller = metadataAPI.caller();
|
|
27
|
+
*
|
|
28
|
+
* if (!caller?.trusted) {
|
|
29
|
+
* throw new Error("Access denied: untrusted caller");
|
|
30
|
+
* }
|
|
31
|
+
*
|
|
32
|
+
* if (!caller.permissions?.includes("read_secrets")) {
|
|
33
|
+
* throw new Error("Access denied: insufficient permissions");
|
|
34
|
+
* }
|
|
35
|
+
*
|
|
36
|
+
* return { apiKey: "secret123", token: "xyz" };
|
|
37
|
+
* }
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* // With custom metadata tags
|
|
41
|
+
* const caller = metadataAPI.caller();
|
|
42
|
+
* console.log("Caller source:", caller?.sourceFolder);
|
|
43
|
+
* console.log("Caller version:", caller?.version);
|
|
44
|
+
* console.log("Caller author:", caller?.author);
|
|
45
|
+
*/
|
|
46
|
+
function caller(): object | null;
|
|
47
|
+
/**
|
|
48
|
+
* Get metadata of the current function.
|
|
49
|
+
*
|
|
50
|
+
* @function self
|
|
51
|
+
* @memberof metadataAPI
|
|
52
|
+
* @returns {object|null} Current function's metadata or null if not found
|
|
53
|
+
* @public
|
|
54
|
+
*
|
|
55
|
+
* @description
|
|
56
|
+
* Retrieves metadata attached to the currently executing function. Useful
|
|
57
|
+
* for functions that need to inspect their own metadata (e.g., for logging,
|
|
58
|
+
* conditional behavior based on load source).
|
|
59
|
+
*
|
|
60
|
+
* Stack trace structure:
|
|
61
|
+
* - Line 0: Error
|
|
62
|
+
* - Line 1: metadataAPI.self (this function)
|
|
63
|
+
* - Line 2: Current function (the one we want to identify)
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* // Function checking its own metadata
|
|
67
|
+
* import { metadataAPI } from "@cldmv/slothlet/runtime";
|
|
68
|
+
*
|
|
69
|
+
* export function smartFunction() {
|
|
70
|
+
* const meta = metadataAPI.self();
|
|
71
|
+
*
|
|
72
|
+
* if (meta?.environment === "development") {
|
|
73
|
+
* console.log("Running in development mode");
|
|
74
|
+
* }
|
|
75
|
+
*
|
|
76
|
+
* if (meta?.version) {
|
|
77
|
+
* console.log(`Function version: ${meta.version}`);
|
|
78
|
+
* }
|
|
79
|
+
*
|
|
80
|
+
* return "result";
|
|
81
|
+
* }
|
|
82
|
+
*/
|
|
83
|
+
function self(): object | null;
|
|
84
|
+
/**
|
|
85
|
+
* Get metadata of any function by API path.
|
|
86
|
+
*
|
|
87
|
+
* @function get
|
|
88
|
+
* @memberof metadataAPI
|
|
89
|
+
* @param {string} path - Dot-notation API path (e.g., "math.add", "plugins.helper")
|
|
90
|
+
* @param {object} [apiRoot] - Optional API root object (uses runtime.self if not provided)
|
|
91
|
+
* @returns {object|null} Function's metadata or null if not found
|
|
92
|
+
* @public
|
|
93
|
+
*
|
|
94
|
+
* @description
|
|
95
|
+
* Retrieves metadata for any function in the API tree by its path. Useful
|
|
96
|
+
* for checking metadata of functions you have references to, or for
|
|
97
|
+
* administrative/introspection purposes.
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* // Check metadata of a specific function
|
|
101
|
+
* import { metadataAPI } from "@cldmv/slothlet/runtime";
|
|
102
|
+
*
|
|
103
|
+
* export function checkPermissions() {
|
|
104
|
+
* const pluginMeta = metadataAPI.get("plugins.userPlugin");
|
|
105
|
+
*
|
|
106
|
+
* if (!pluginMeta) {
|
|
107
|
+
* throw new Error("Plugin not found or has no metadata");
|
|
108
|
+
* }
|
|
109
|
+
*
|
|
110
|
+
* if (pluginMeta.trusted) {
|
|
111
|
+
* console.log("Plugin is trusted");
|
|
112
|
+
* } else {
|
|
113
|
+
* console.log("Plugin is untrusted");
|
|
114
|
+
* }
|
|
115
|
+
* }
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* // Iterate and check all plugins
|
|
119
|
+
* const pluginPaths = ["plugins.auth", "plugins.logger", "plugins.cache"];
|
|
120
|
+
* for (const path of pluginPaths) {
|
|
121
|
+
* const meta = metadataAPI.get(path);
|
|
122
|
+
* console.log(`${path}: ${meta?.version || "unknown"}`);
|
|
123
|
+
* }
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* // From outside slothlet context, pass API root explicitly
|
|
127
|
+
* const api = await slothlet({ dir: "./modules" });
|
|
128
|
+
* const meta = await metadataAPI.get("plugins.helper", api);
|
|
129
|
+
*/
|
|
130
|
+
function get(path: string, apiRoot?: object): object | null;
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=metadata-api.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metadata-api.d.mts","sourceRoot":"","sources":["../../../../dist/lib/helpers/metadata-api.mjs"],"names":[],"mappings":";IAmNC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2CG;IACH,mBAvCa,MAAM,GAAC,IAAI,CAgEvB;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAmCG;IACH,iBA/Ba,MAAM,GAAC,IAAI,CAsDvB;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6CG;IACH,mBAzCW,MAAM,YACN,MAAM,GACJ,MAAM,GAAC,IAAI,CAsDvB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"multidefault.d.mts","sourceRoot":"","sources":["../../../../dist/lib/helpers/multidefault.mjs"],"names":[],"mappings":"AAoBA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,yDAlBW,KAAK,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAC,CAAC,WACrB,MAAM,YAEd;IAA0B,KAAK,GAAvB,OAAO;IACe,QAAQ,GAA9B,MAAM,GAAC,IAAI;CACnB,GAAU,OAAO,CAAC;IAChB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,yBAAyB,EAAE,OAAO,CAAC;IACnC,oBAAoB,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAClC,cAAc,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACpC,kBAAkB,EAAE,KAAK,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAC,CAAC,CAAA;CACjE,CAAC,
|
|
1
|
+
{"version":3,"file":"multidefault.d.mts","sourceRoot":"","sources":["../../../../dist/lib/helpers/multidefault.mjs"],"names":[],"mappings":"AAoBA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,yDAlBW,KAAK,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAC,CAAC,WACrB,MAAM,YAEd;IAA0B,KAAK,GAAvB,OAAO;IACe,QAAQ,GAA9B,MAAM,GAAC,IAAI;CACnB,GAAU,OAAO,CAAC;IAChB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,yBAAyB,EAAE,OAAO,CAAC;IACnC,oBAAoB,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAClC,cAAc,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACpC,kBAAkB,EAAE,KAAK,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAC,CAAC,CAAA;CACjE,CAAC,CAuGJ;AAED;;;;;;;;GAQG;AACH,0DALW,MAAM,GACJ,OAAO,CAWnB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,4DAvBG;IAAyB,yBAAyB,EAA1C,OAAO;IACU,gBAAgB,EAAjC,OAAO;IACU,iBAAiB,EAAlC,OAAO;IACgB,UAAU,EAAjC,KAAK,CAAC,MAAM,CAAC;IACG,UAAU,EAA1B,MAAM;IACU,gBAAgB,EAAhC,MAAM;IACY,KAAK,GAAvB,OAAO;CACf,GAAU;IACR,aAAa,EAAE,OAAO,CAAC;IACvB,aAAa,EAAE,OAAO,CAAC;IACvB,mBAAmB,EAAE,OAAO,CAAC;IAC7B,MAAM,EAAE,MAAM,CAAA;CACf,CA4FH"}
|
|
@@ -60,6 +60,8 @@ export const context: object;
|
|
|
60
60
|
* console.log(reference); // Current reference data
|
|
61
61
|
*/
|
|
62
62
|
export const reference: object;
|
|
63
|
+
export { metadataAPI };
|
|
63
64
|
export type AsyncLocalStorageType = AsyncLocalStorage<any>;
|
|
65
|
+
import { metadataAPI } from "@cldmv/slothlet/helpers/metadata-api";
|
|
64
66
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
65
67
|
//# sourceMappingURL=runtime-asynclocalstorage.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime-asynclocalstorage.d.mts","sourceRoot":"","sources":["../../../../dist/lib/runtime/runtime-asynclocalstorage.mjs"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"runtime-asynclocalstorage.d.mts","sourceRoot":"","sources":["../../../../dist/lib/runtime/runtime-asynclocalstorage.mjs"],"names":[],"mappings":"AAwCA;;;;;GAKG;AACH,wBAHU,qBAAqB,CAGkB;AAEjD;;;;;GAKG;AACH,yBAHU,qBAAqB,CAGmB;AAsB3C,gCAdI,MAAM,yBAEN,GAAG,gBAED,GAAG,CAwGf;AAiBM,0BAZM,MAAM,GAAC,IAAI,CAY0B;AAkN3C,iCAjBI,MAAM,YAiJhB;AA2TD;;;;;;;;;;;;;GAaG;AACH,mBATU,WAAS,MAAM,CAS6B;AAEtD;;;;;;;;;;;;;GAaG;AACH,sBATU,MAAM,CAS4C;AAE5D;;;;;;;;;;;;;GAaG;AACH,wBATU,MAAM,CASgD;;;4BAl1BpC,sCAAsC;kCAHhC,kBAAkB"}
|
|
@@ -63,5 +63,7 @@ export namespace contextManager {
|
|
|
63
63
|
export { setContext as set };
|
|
64
64
|
export { runWithCtx };
|
|
65
65
|
}
|
|
66
|
+
export { metadataAPI };
|
|
66
67
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
68
|
+
import { metadataAPI } from "@cldmv/slothlet/helpers/metadata-api";
|
|
67
69
|
//# sourceMappingURL=runtime-livebindings.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime-livebindings.d.mts","sourceRoot":"","sources":["../../../../dist/lib/runtime/runtime-livebindings.mjs"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"runtime-livebindings.d.mts","sourceRoot":"","sources":["../../../../dist/lib/runtime/runtime-livebindings.mjs"],"names":[],"mappings":"AAgTA;;;;;;;;;GASG;AACH,gCANW,MAAM,yBAEN,GAAG,gBAED,GAAG,CAoFf;AAED;;;;;;GAMG;AACH,iCAHW,MAAM,YAiEhB;AAID;;;GAGG;AAEH,kCAEC;AAED,kDASC;AA/bD;;;;;GAKG;AACH,gDAAkD;AA8ClD;;;;;GAKG;AACH,mBAHU,MAAM,CAmDd;AAEF;;;;;GAKG;AACH,sBAHU,MAAM,CA0Dd;AAEF;;;;;GAKG;AACH,wBAHU,MAAM,CA+Cd;AAEF;;;;;GAKG;AACH,yBAHU,MAAM,CAkCd;;;;;;;kCA7QgC,kBAAkB;4BAOxB,sCAAsC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.d.mts","sourceRoot":"","sources":["../../../../dist/lib/runtime/runtime.mjs"],"names":[],"mappings":"AAoMA,4EAGC;AAED,gDAGC;AAED,8BAGC;AArKA,6BAA+B;AAkDhC,yBAiDE;AAEF,2BAiDE;AAiBF,6BAOK;AAEL,4BAAuD"}
|
|
1
|
+
{"version":3,"file":"runtime.d.mts","sourceRoot":"","sources":["../../../../dist/lib/runtime/runtime.mjs"],"names":[],"mappings":"AAoMA,4EAGC;AAED,gDAGC;AAED,8BAGC;AArKA,6BAA+B;AAkDhC,yBAiDE;AAEF,2BAiDE;AAiBF,6BAOK;AAEL,4BAAuD;AAGvD,6BAQE"}
|
|
@@ -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":"AA+LA;;;;;;;GAOG;AACH,mBAJU,MAAM,CAIO;AAEvB;;;;;GAKG;AACH,sBAJU,MAAM,CAIU;AAE1B;;;;;GAKG;AACH,wBAJU,MAAM,CAIY;;;;;;;;;UA2oCd,MAAM;;;;;;WAIN,OAAO;;;;;;;;WAGP,MAAM;;;;;;;;aAKN,MAAM;;;;;;;cAKN,MAAM;;;;;;;eAIN,MAAM;;;;;;;;YAIN,OAAO;;;;;;;eAKP,MAAM;;;;;;;wBAIN,OAAO;;;;;;cAIP,MAAM;;;;;;gBAGN,MAAM;;;;;;eAMjB;QAA8B,UAAU,GAA7B,OAAO;QACY,gBAAgB,GAAnC,OAAO;QACY,gBAAgB,GAAnC,OAAO;QACW,KAAK,GAClC;YAAqC,KAAK,GAA/B,MAAM,EAAE;YACkB,gBAAgB,GAA1C,MAAM,EAAE;YACkB,KAAK,GAA/B,MAAM,EAAE;YACkB,KAAK,GAA/B,MAAM,EAAE;SACrB;KAAA;;;;;;cAIa,MAAM,OAAO,CAAC,IAAI,CAAC;;;;YACnB,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC;;;;cACtD,CAAC,OAAO,CAAC,EAAE,OAAO,KAAK,CAAC,CAAC,MAAM,GAAC,MAAM,CAAC,EAAE,GAAC,MAAM,GAAC,OAAO,CAAC,MAAM,CAAC,CAAC;;AAtsC/E;;;;;;;;GAQG;AACH,mCAJW,eAAe,GACb,OAAO,CAAC,WAAW,CAAC,CAiChC"}
|