@blokjs/helper 0.2.1 → 0.6.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/dist/components/AddElse.d.ts +15 -0
- package/dist/components/AddIf.d.ts +15 -0
- package/dist/components/StepNode.d.ts +6 -0
- package/dist/components/StepNode.js +8 -0
- package/dist/components/StepNode.js.map +1 -1
- package/dist/components/Trigger.d.ts +10 -2
- package/dist/components/Trigger.js +16 -5
- package/dist/components/Trigger.js.map +1 -1
- package/dist/components/branch.d.ts +44 -0
- package/dist/components/branch.js +57 -0
- package/dist/components/branch.js.map +1 -0
- package/dist/components/forEach.d.ts +53 -0
- package/dist/components/forEach.js +64 -0
- package/dist/components/forEach.js.map +1 -0
- package/dist/components/loop.d.ts +52 -0
- package/dist/components/loop.js +54 -0
- package/dist/components/loop.js.map +1 -0
- package/dist/components/switchOn.d.ts +68 -0
- package/dist/components/switchOn.js +76 -0
- package/dist/components/switchOn.js.map +1 -0
- package/dist/components/tryCatch.d.ts +63 -0
- package/dist/components/tryCatch.js +68 -0
- package/dist/components/tryCatch.js.map +1 -0
- package/dist/components/workflowV2.d.ts +83 -0
- package/dist/components/workflowV2.js +84 -0
- package/dist/components/workflowV2.js.map +1 -0
- package/dist/index.d.ts +12 -3
- package/dist/index.js +25 -4
- package/dist/index.js.map +1 -1
- package/dist/proxy/$.d.ts +102 -0
- package/dist/proxy/$.js +130 -0
- package/dist/proxy/$.js.map +1 -0
- package/dist/types/StepOpts.d.ts +723 -3
- package/dist/types/StepOpts.js +702 -3
- package/dist/types/StepOpts.js.map +1 -1
- package/dist/types/TriggerOpts.d.ts +1600 -35
- package/dist/types/TriggerOpts.js +601 -29
- package/dist/types/TriggerOpts.js.map +1 -1
- package/dist/types/WorkflowOpts.d.ts +478 -28
- package/dist/types/WorkflowOpts.js +66 -3
- package/dist/types/WorkflowOpts.js.map +1 -1
- package/dist/utils/parseDuration.d.ts +33 -0
- package/dist/utils/parseDuration.js +78 -0
- package/dist/utils/parseDuration.js.map +1 -0
- package/dist/workflow.schema.json +662 -0
- package/package.json +6 -6
package/dist/proxy/$.js
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The typed `$` proxy — typed sugar over the runtime's `js/...` resolver.
|
|
3
|
+
*
|
|
4
|
+
* Property access on `$` builds a path string at definition time. The
|
|
5
|
+
* `unwrapProxies` deep-walk in the `workflow()` factory replaces each proxy
|
|
6
|
+
* value with its compiled `"js/ctx.<path>"` string before the workflow is
|
|
7
|
+
* handed to the runner. This means:
|
|
8
|
+
*
|
|
9
|
+
* - Authors get IDE autocomplete on `$.req.body.foo`, `$.state.users[0]`, etc.
|
|
10
|
+
* - The runtime sees plain strings (no Proxy traversal at execution time).
|
|
11
|
+
* - The existing `Mapper.jsMapper` resolver works unchanged — it already
|
|
12
|
+
* evaluates `js/...` strings against `ctx`.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* import { workflow, $ } from "@blokjs/helper";
|
|
16
|
+
*
|
|
17
|
+
* workflow({
|
|
18
|
+
* trigger: { http: { method: "GET" } },
|
|
19
|
+
* steps: [
|
|
20
|
+
* { id: "fetch", use: "@blokjs/api-call",
|
|
21
|
+
* inputs: { userId: $.req.params.id } },
|
|
22
|
+
* { id: "respond", use: "@blokjs/respond",
|
|
23
|
+
* inputs: { body: $.state.fetch } }
|
|
24
|
+
* ]
|
|
25
|
+
* });
|
|
26
|
+
* // After `unwrapProxies` runs at definition time:
|
|
27
|
+
* // inputs.userId === "js/ctx.req.params.id"
|
|
28
|
+
* // inputs.body === "js/ctx.state.fetch"
|
|
29
|
+
*/
|
|
30
|
+
/** Internal symbol used to detect proxy values during the deep-walk. */
|
|
31
|
+
export const JS_EXPR_TAG = Symbol("blok.jsExpr");
|
|
32
|
+
const IDENT_RE = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
|
|
33
|
+
const NUMERIC_RE = /^\d+$/;
|
|
34
|
+
function makeProxy(prefix) {
|
|
35
|
+
// Use a function as the target so `typeof` is `function` — that lets us
|
|
36
|
+
// distinguish proxy values from plain objects in `unwrapProxies`. The
|
|
37
|
+
// function is never called; it's just a tag.
|
|
38
|
+
const target = (() => prefix);
|
|
39
|
+
target[JS_EXPR_TAG] = prefix;
|
|
40
|
+
return new Proxy(target, {
|
|
41
|
+
get(_target, key) {
|
|
42
|
+
if (key === JS_EXPR_TAG)
|
|
43
|
+
return prefix;
|
|
44
|
+
if (key === Symbol.toPrimitive)
|
|
45
|
+
return (_hint) => `js/${prefix}`;
|
|
46
|
+
if (key === "toString")
|
|
47
|
+
return () => `js/${prefix}`;
|
|
48
|
+
if (key === "toJSON")
|
|
49
|
+
return () => `js/${prefix}`;
|
|
50
|
+
if (key === "valueOf")
|
|
51
|
+
return () => `js/${prefix}`;
|
|
52
|
+
// Don't pretend to be a thenable — Promise.resolve() probes `.then`.
|
|
53
|
+
if (key === "then")
|
|
54
|
+
return undefined;
|
|
55
|
+
// Ignore inherited symbols (Symbol.iterator, etc.).
|
|
56
|
+
if (typeof key === "symbol")
|
|
57
|
+
return undefined;
|
|
58
|
+
const k = String(key);
|
|
59
|
+
let next;
|
|
60
|
+
if (NUMERIC_RE.test(k)) {
|
|
61
|
+
next = `${prefix}[${k}]`;
|
|
62
|
+
}
|
|
63
|
+
else if (IDENT_RE.test(k)) {
|
|
64
|
+
next = `${prefix}.${k}`;
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
next = `${prefix}[${JSON.stringify(k)}]`;
|
|
68
|
+
}
|
|
69
|
+
return makeProxy(next);
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* The `$` proxy entry point. All paths root at `ctx`.
|
|
75
|
+
*
|
|
76
|
+
* @see DollarProxy for the typed surface.
|
|
77
|
+
*/
|
|
78
|
+
export const $ = makeProxy("ctx");
|
|
79
|
+
/**
|
|
80
|
+
* Recursively replace any `$` proxy values inside `value` with their
|
|
81
|
+
* compiled `"js/ctx.<path>"` strings.
|
|
82
|
+
*
|
|
83
|
+
* Called by `workflow()` and `branch()` factories at definition time to
|
|
84
|
+
* convert in-memory proxy references into the wire-shape strings the
|
|
85
|
+
* runner's `Mapper` expects.
|
|
86
|
+
*
|
|
87
|
+
* Unwraps:
|
|
88
|
+
* - Proxies → `"js/ctx.<path>"` strings
|
|
89
|
+
* - Plain objects → walked recursively, returning a NEW object
|
|
90
|
+
* - Arrays → walked, returning a NEW array
|
|
91
|
+
*
|
|
92
|
+
* Leaves alone:
|
|
93
|
+
* - Primitives (string, number, boolean, null, undefined)
|
|
94
|
+
* - Class instances (anything with a non-Object prototype)
|
|
95
|
+
* - Functions other than the proxy itself
|
|
96
|
+
*
|
|
97
|
+
* Pure — never mutates the input.
|
|
98
|
+
*/
|
|
99
|
+
export function unwrapProxies(value) {
|
|
100
|
+
return unwrap(value);
|
|
101
|
+
}
|
|
102
|
+
function unwrap(value) {
|
|
103
|
+
if (value === null || value === undefined)
|
|
104
|
+
return value;
|
|
105
|
+
// Detect proxy via the tag symbol.
|
|
106
|
+
if (typeof value === "function") {
|
|
107
|
+
const tag = value[JS_EXPR_TAG];
|
|
108
|
+
if (typeof tag === "string") {
|
|
109
|
+
return `js/${tag}`;
|
|
110
|
+
}
|
|
111
|
+
// Other functions — leave as-is.
|
|
112
|
+
return value;
|
|
113
|
+
}
|
|
114
|
+
if (Array.isArray(value)) {
|
|
115
|
+
return value.map(unwrap);
|
|
116
|
+
}
|
|
117
|
+
// Plain object only — class instances pass through untouched.
|
|
118
|
+
if (typeof value === "object") {
|
|
119
|
+
const proto = Object.getPrototypeOf(value);
|
|
120
|
+
if (proto === null || proto === Object.prototype) {
|
|
121
|
+
const out = {};
|
|
122
|
+
for (const k of Object.keys(value)) {
|
|
123
|
+
out[k] = unwrap(value[k]);
|
|
124
|
+
}
|
|
125
|
+
return out;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return value;
|
|
129
|
+
}
|
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