@blokjs/shared 0.2.1 → 0.4.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/__tests__/unit/BlokError.test.ts +294 -0
- package/__tests__/unit/NodeBase.test.ts +4 -1
- package/__tests__/unit/utils/Mapper.test.ts +299 -31
- package/__tests__/unit/utils/MapperResolutionError.test.ts +64 -0
- package/dist/BlokError.d.ts +196 -0
- package/dist/BlokError.js +328 -0
- package/dist/BlokError.js.map +1 -0
- package/dist/NodeBase.d.ts +96 -2
- package/dist/NodeBase.js +120 -2
- package/dist/NodeBase.js.map +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/types/Context.d.ts +91 -0
- package/dist/types/StateContext.d.ts +21 -0
- package/dist/types/StateContext.js +2 -0
- package/dist/types/StateContext.js.map +1 -0
- package/dist/types/VarsContext.d.ts +15 -2
- package/dist/utils/Mapper.d.ts +111 -2
- package/dist/utils/Mapper.js +256 -23
- package/dist/utils/Mapper.js.map +1 -1
- package/dist/utils/MapperResolutionError.d.ts +84 -0
- package/dist/utils/MapperResolutionError.js +61 -0
- package/dist/utils/MapperResolutionError.js.map +1 -0
- package/dist/utils/index.d.ts +2 -1
- package/dist/utils/index.js +1 -0
- package/dist/utils/index.js.map +1 -1
- package/package.json +2 -5
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structured error thrown by `Mapper` when a workflow input expression
|
|
3
|
+
* cannot be resolved against the live `Context`.
|
|
4
|
+
*
|
|
5
|
+
* The Mapper resolves two template syntaxes inside step `inputs`:
|
|
6
|
+
* - **`${path.to.value}`** — interpolated string (lodash-path lookup
|
|
7
|
+
* with a JS-eval fallback)
|
|
8
|
+
* - **`"js/..."`** — full-string JS evaluation against `ctx`
|
|
9
|
+
*
|
|
10
|
+
* When evaluation throws (typo, undefined access, syntax error,
|
|
11
|
+
* unknown identifier), the Mapper packages the failure in a
|
|
12
|
+
* `MapperResolutionError` carrying full diagnostic context — the
|
|
13
|
+
* literal expression, which syntax it was, the workflow + step name,
|
|
14
|
+
* and the original underlying error as `cause`.
|
|
15
|
+
*
|
|
16
|
+
* **What happens next depends on `BLOK_MAPPER_MODE`** (read from env):
|
|
17
|
+
*
|
|
18
|
+
* - `"warn"` (default) — the error is caught inside the Mapper, logged
|
|
19
|
+
* via `ctx.logger.logLevel("warn", ...)` (which routes to both the
|
|
20
|
+
* console AND Studio's log viewer via `TracingLogger`), and the
|
|
21
|
+
* original expression string passes through to the node. Backward-
|
|
22
|
+
* compatible with v1 behavior + actionable diagnostics.
|
|
23
|
+
*
|
|
24
|
+
* - `"strict"` — the error escapes the Mapper, is re-thrown by
|
|
25
|
+
* `NodeBase.blueprintMapper`, and the step fails fast with a
|
|
26
|
+
* structured error. **Recommended for production deployments** —
|
|
27
|
+
* silent input resolution failures are a source of subtle bugs
|
|
28
|
+
* (the node receives a literal `"js/ctx.bad.path"` string instead
|
|
29
|
+
* of the resolved value, then produces wrong output downstream).
|
|
30
|
+
*
|
|
31
|
+
* - `"silent"` — pre-v0.3.x behavior: completely suppress the error
|
|
32
|
+
* (no log, no throw). Provided as an opt-out for tests / workflows
|
|
33
|
+
* that intentionally use undefined-tolerant resolution for optional
|
|
34
|
+
* fields. Discouraged.
|
|
35
|
+
*
|
|
36
|
+
* This class is a `core/shared` concern (not `core/runner`) because
|
|
37
|
+
* the Mapper itself lives in shared. Consumers in any package may
|
|
38
|
+
* `instanceof` check it to handle resolution failures specifically
|
|
39
|
+
* (e.g., a custom trigger may want to translate it into a 400-class
|
|
40
|
+
* HTTP response).
|
|
41
|
+
*/
|
|
42
|
+
export declare class MapperResolutionError extends Error {
|
|
43
|
+
/** Always the literal string `"MapperResolutionError"`. */
|
|
44
|
+
readonly name = "MapperResolutionError";
|
|
45
|
+
/** Structured diagnostic context attached at construction time. */
|
|
46
|
+
readonly context: {
|
|
47
|
+
/**
|
|
48
|
+
* The literal expression that failed, WITHOUT the surrounding
|
|
49
|
+
* syntax markers. For `js/ctx.bad.path` the value is
|
|
50
|
+
* `"ctx.bad.path"`; for `${ctx.user.name}` it is `"ctx.user.name"`.
|
|
51
|
+
*/
|
|
52
|
+
readonly expression: string;
|
|
53
|
+
/**
|
|
54
|
+
* Which template syntax was being parsed.
|
|
55
|
+
* - `"js"` — full-string `"js/..."` expression
|
|
56
|
+
* - `"template"` — interpolated `${...}` placeholder
|
|
57
|
+
*/
|
|
58
|
+
readonly syntax: "js" | "template";
|
|
59
|
+
/**
|
|
60
|
+
* The workflow's `name:` field, when known. Read from
|
|
61
|
+
* `ctx.workflow_name`. Absent on hand-rolled test contexts.
|
|
62
|
+
*/
|
|
63
|
+
readonly workflowName?: string;
|
|
64
|
+
/**
|
|
65
|
+
* The step's `id` (or v1 `name`), when known. Read from
|
|
66
|
+
* `ctx._stepInfo.name` which is set by `RunnerSteps` before
|
|
67
|
+
* each step runs. Absent during early-boot or test contexts.
|
|
68
|
+
*/
|
|
69
|
+
readonly stepName?: string;
|
|
70
|
+
/**
|
|
71
|
+
* The original error thrown by the JS evaluator (typically a
|
|
72
|
+
* `TypeError` or `ReferenceError`). Preserved for full stack
|
|
73
|
+
* trace + downstream `instanceof` checks.
|
|
74
|
+
*/
|
|
75
|
+
readonly cause?: unknown;
|
|
76
|
+
};
|
|
77
|
+
constructor(message: string, context: {
|
|
78
|
+
readonly expression: string;
|
|
79
|
+
readonly syntax: "js" | "template";
|
|
80
|
+
readonly workflowName?: string;
|
|
81
|
+
readonly stepName?: string;
|
|
82
|
+
readonly cause?: unknown;
|
|
83
|
+
});
|
|
84
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structured error thrown by `Mapper` when a workflow input expression
|
|
3
|
+
* cannot be resolved against the live `Context`.
|
|
4
|
+
*
|
|
5
|
+
* The Mapper resolves two template syntaxes inside step `inputs`:
|
|
6
|
+
* - **`${path.to.value}`** — interpolated string (lodash-path lookup
|
|
7
|
+
* with a JS-eval fallback)
|
|
8
|
+
* - **`"js/..."`** — full-string JS evaluation against `ctx`
|
|
9
|
+
*
|
|
10
|
+
* When evaluation throws (typo, undefined access, syntax error,
|
|
11
|
+
* unknown identifier), the Mapper packages the failure in a
|
|
12
|
+
* `MapperResolutionError` carrying full diagnostic context — the
|
|
13
|
+
* literal expression, which syntax it was, the workflow + step name,
|
|
14
|
+
* and the original underlying error as `cause`.
|
|
15
|
+
*
|
|
16
|
+
* **What happens next depends on `BLOK_MAPPER_MODE`** (read from env):
|
|
17
|
+
*
|
|
18
|
+
* - `"warn"` (default) — the error is caught inside the Mapper, logged
|
|
19
|
+
* via `ctx.logger.logLevel("warn", ...)` (which routes to both the
|
|
20
|
+
* console AND Studio's log viewer via `TracingLogger`), and the
|
|
21
|
+
* original expression string passes through to the node. Backward-
|
|
22
|
+
* compatible with v1 behavior + actionable diagnostics.
|
|
23
|
+
*
|
|
24
|
+
* - `"strict"` — the error escapes the Mapper, is re-thrown by
|
|
25
|
+
* `NodeBase.blueprintMapper`, and the step fails fast with a
|
|
26
|
+
* structured error. **Recommended for production deployments** —
|
|
27
|
+
* silent input resolution failures are a source of subtle bugs
|
|
28
|
+
* (the node receives a literal `"js/ctx.bad.path"` string instead
|
|
29
|
+
* of the resolved value, then produces wrong output downstream).
|
|
30
|
+
*
|
|
31
|
+
* - `"silent"` — pre-v0.3.x behavior: completely suppress the error
|
|
32
|
+
* (no log, no throw). Provided as an opt-out for tests / workflows
|
|
33
|
+
* that intentionally use undefined-tolerant resolution for optional
|
|
34
|
+
* fields. Discouraged.
|
|
35
|
+
*
|
|
36
|
+
* This class is a `core/shared` concern (not `core/runner`) because
|
|
37
|
+
* the Mapper itself lives in shared. Consumers in any package may
|
|
38
|
+
* `instanceof` check it to handle resolution failures specifically
|
|
39
|
+
* (e.g., a custom trigger may want to translate it into a 400-class
|
|
40
|
+
* HTTP response).
|
|
41
|
+
*/
|
|
42
|
+
export class MapperResolutionError extends Error {
|
|
43
|
+
/** Always the literal string `"MapperResolutionError"`. */
|
|
44
|
+
name = "MapperResolutionError";
|
|
45
|
+
/** Structured diagnostic context attached at construction time. */
|
|
46
|
+
context;
|
|
47
|
+
constructor(message, context) {
|
|
48
|
+
super(message);
|
|
49
|
+
this.context = context;
|
|
50
|
+
// Preserve the prototype chain across Babel/TS down-compilation —
|
|
51
|
+
// without this, `instanceof MapperResolutionError` fails on
|
|
52
|
+
// constructors transpiled to ES5 targets.
|
|
53
|
+
Object.setPrototypeOf(this, MapperResolutionError.prototype);
|
|
54
|
+
// Standard `Error.cause` mirror (Node 16.9+, ES2022). Lets
|
|
55
|
+
// `console.error(e)` pretty-print the underlying cause too.
|
|
56
|
+
if (context.cause !== undefined) {
|
|
57
|
+
this.cause = context.cause;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=MapperResolutionError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MapperResolutionError.js","sourceRoot":"","sources":["../../src/utils/MapperResolutionError.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,MAAM,OAAO,qBAAsB,SAAQ,KAAK;IAC/C,2DAA2D;IAClC,IAAI,GAAG,uBAAuB,CAAC;IAExD,mEAAmE;IACnD,OAAO,CA8BrB;IAEF,YACC,OAAe,EACf,OAMC;QAED,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,kEAAkE;QAClE,4DAA4D;QAC5D,0CAA0C;QAC1C,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,qBAAqB,CAAC,SAAS,CAAC,CAAC;QAC7D,2DAA2D;QAC3D,4DAA4D;QAC5D,IAAI,OAAO,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;YAChC,IAAoC,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAC7D,CAAC;IACF,CAAC;CACD"}
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { default as CpuUsage } from "./CpuUsage";
|
|
2
|
-
export { default as Mapper } from "./Mapper";
|
|
2
|
+
export { default as Mapper, type MapperMode } from "./Mapper";
|
|
3
|
+
export { MapperResolutionError } from "./MapperResolutionError";
|
|
3
4
|
export { default as MemoryUsage } from "./MemoryUsage";
|
|
4
5
|
export { default as Metrics } from "./MetricsBase";
|
|
5
6
|
export { default as Time } from "./Time";
|
package/dist/utils/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { default as CpuUsage } from "./CpuUsage";
|
|
2
2
|
export { default as Mapper } from "./Mapper";
|
|
3
|
+
export { MapperResolutionError } from "./MapperResolutionError";
|
|
3
4
|
export { default as MemoryUsage } from "./MemoryUsage";
|
|
4
5
|
export { default as Metrics } from "./MetricsBase";
|
|
5
6
|
export { default as Time } from "./Time";
|
package/dist/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,EAAE,OAAO,IAAI,MAAM,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,EAAE,OAAO,IAAI,MAAM,EAAmB,MAAM,UAAU,CAAC;AAC9D,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,MAAM,QAAQ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blokjs/shared",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Shared class, interfaces and types",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -11,10 +11,7 @@
|
|
|
11
11
|
"test": "vitest run",
|
|
12
12
|
"test:dev": "vitest"
|
|
13
13
|
},
|
|
14
|
-
"keywords": [
|
|
15
|
-
"api",
|
|
16
|
-
"blueprint"
|
|
17
|
-
],
|
|
14
|
+
"keywords": ["api", "blueprint"],
|
|
18
15
|
"author": "Deskree Inc",
|
|
19
16
|
"license": "MIT",
|
|
20
17
|
"devDependencies": {
|