@atscript/moost-wf 0.1.70 → 0.1.72
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/index.d.mts +11 -40
- package/dist/index.mjs +15 -63
- package/package.json +13 -13
package/dist/index.d.mts
CHANGED
|
@@ -35,38 +35,6 @@ declare function extractPassContext(type: TAtscriptAnnotatedType, wfContext: Rec
|
|
|
35
35
|
*/
|
|
36
36
|
declare function getFormActions(type: TAtscriptAnnotatedType): TFormActions;
|
|
37
37
|
//#endregion
|
|
38
|
-
//#region src/wf-io/use-wf-action-slot.d.ts
|
|
39
|
-
/**
|
|
40
|
-
* Low-level accessor for the workflow action slot in the current wf event context.
|
|
41
|
-
*
|
|
42
|
-
* Used by:
|
|
43
|
-
* - Transport adapters (HTTP / CLI / WS controllers) to **write** the action
|
|
44
|
-
* from the incoming request (`useWfActionSlot().setAction(body.action)`).
|
|
45
|
-
* - Composable helpers that need to **read + clear** the slot atomically
|
|
46
|
-
* (e.g. one-shot action consumption patterns).
|
|
47
|
-
*
|
|
48
|
-
* In step handlers, prefer `useAtscriptWf(Type).resolveAction()` — it reads
|
|
49
|
-
* the same slot but validates the value against the schema's
|
|
50
|
-
* `@ui.form.action` / `@wf.action.withData` declarations and throws
|
|
51
|
-
* `StepRetriableError` on unknown actions.
|
|
52
|
-
*
|
|
53
|
-
* **In a transport adapter** (to set the action from the request body):
|
|
54
|
-
* ```ts
|
|
55
|
-
* const { setAction } = useWfActionSlot()
|
|
56
|
-
* setAction(body.action)
|
|
57
|
-
* ```
|
|
58
|
-
*
|
|
59
|
-
* **In step handlers** (raw read — prefer `@WfAction()` / `useAtscriptWf().resolveAction()`):
|
|
60
|
-
* ```ts
|
|
61
|
-
* const { getAction } = useWfActionSlot()
|
|
62
|
-
* const action = getAction()
|
|
63
|
-
* ```
|
|
64
|
-
*/
|
|
65
|
-
declare function useWfActionSlot(): {
|
|
66
|
-
getAction: () => string | undefined;
|
|
67
|
-
setAction: (action: string | undefined) => void;
|
|
68
|
-
};
|
|
69
|
-
//#endregion
|
|
70
38
|
//#region src/wf-io/use-atscript-wf.d.ts
|
|
71
39
|
/**
|
|
72
40
|
* Schema-driven workflow I/O primitives for atscript types. Returned helpers
|
|
@@ -127,26 +95,29 @@ declare function WfInput(opts?: {
|
|
|
127
95
|
//#endregion
|
|
128
96
|
//#region src/wf-io/wf-action.decorator.d.ts
|
|
129
97
|
/**
|
|
130
|
-
* Parameter decorator
|
|
98
|
+
* Parameter decorator — sugar for `useAtscriptWf(Type).resolveAction()`.
|
|
99
|
+
*
|
|
100
|
+
* Resolves to the current workflow action name from the input envelope, or
|
|
101
|
+
* `undefined` when no action was submitted.
|
|
131
102
|
*
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
*
|
|
103
|
+
* The form type is **required**: the decorator validates the action against
|
|
104
|
+
* the form's declared `@ui.form.action` / `@wf.action.withData` whitelist and
|
|
105
|
+
* throws `StepRetriableError` for any unknown action — the step body never
|
|
106
|
+
* sees actions that aren't part of the form's contract.
|
|
136
107
|
*
|
|
137
108
|
* @example
|
|
138
109
|
* ```ts
|
|
139
110
|
* @Step('mfa-verify')
|
|
140
111
|
* async mfaVerify(
|
|
141
112
|
* @WfInput() input: PincodeForm,
|
|
142
|
-
* @WfAction() action: string | undefined,
|
|
113
|
+
* @WfAction(PincodeForm) action: string | undefined,
|
|
143
114
|
* ) {
|
|
144
115
|
* if (action === 'resend') return this.sendOtp()
|
|
145
116
|
* await this.verifyCode(input.code)
|
|
146
117
|
* }
|
|
147
118
|
* ```
|
|
148
119
|
*/
|
|
149
|
-
declare function WfAction(): ParameterDecorator;
|
|
120
|
+
declare function WfAction<T extends TAtscriptTypeDef>(type: TAtscriptAnnotatedType<T>): ParameterDecorator;
|
|
150
121
|
//#endregion
|
|
151
122
|
//#region src/outlet.d.ts
|
|
152
123
|
/**
|
|
@@ -253,4 +224,4 @@ declare function finishWf<T = unknown>(opts?: FinishWfOpts<T>): void;
|
|
|
253
224
|
*/
|
|
254
225
|
declare function abortWf(reason: string, opts?: FinishWfOpts): void;
|
|
255
226
|
//#endregion
|
|
256
|
-
export { type FinishWfOpts, WfAction, type WfActionRequest, type WfButton, type WfFinished, WfInput, type WfMessage, type WfNext, abortWf, createAsHttpOutlet, extractPassContext, finishWf, getFormActions, handleAsOutletRequest, isWfFinished, serializeFormSchema, useAtscriptWf
|
|
227
|
+
export { type FinishWfOpts, WfAction, type WfActionRequest, type WfButton, type WfFinished, WfInput, type WfMessage, type WfNext, abortWf, createAsHttpOutlet, extractPassContext, finishWf, getFormActions, handleAsOutletRequest, isWfFinished, serializeFormSchema, useAtscriptWf };
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { isAnnotatedType, serializeAnnotatedType } from "@atscript/typescript/utils";
|
|
2
|
-
import { current, key } from "@wooksjs/event-core";
|
|
3
2
|
import { createHttpOutlet, handleWfOutletRequest, useWfState } from "@moostjs/event-wf";
|
|
4
3
|
import { StepRetriableError, useWfFinished } from "@wooksjs/event-wf";
|
|
5
4
|
import { Optional, Resolve } from "moost";
|
|
@@ -84,51 +83,6 @@ function serializeFormSchema(type) {
|
|
|
84
83
|
return schema;
|
|
85
84
|
}
|
|
86
85
|
//#endregion
|
|
87
|
-
//#region src/wf-io/wf-keys.ts
|
|
88
|
-
/**
|
|
89
|
-
* Internal event context key for the workflow action name.
|
|
90
|
-
*
|
|
91
|
-
* Not exported from the package barrel — HTTP triggers should call
|
|
92
|
-
* `useWfActionSlot().setAction(body.action)` before `wf.resume()`, and step
|
|
93
|
-
* handlers should read via `@WfAction()` or `useAtscriptWf()`.
|
|
94
|
-
*/
|
|
95
|
-
const actionKey = key("wf.action");
|
|
96
|
-
//#endregion
|
|
97
|
-
//#region src/wf-io/use-wf-action-slot.ts
|
|
98
|
-
/**
|
|
99
|
-
* Low-level accessor for the workflow action slot in the current wf event context.
|
|
100
|
-
*
|
|
101
|
-
* Used by:
|
|
102
|
-
* - Transport adapters (HTTP / CLI / WS controllers) to **write** the action
|
|
103
|
-
* from the incoming request (`useWfActionSlot().setAction(body.action)`).
|
|
104
|
-
* - Composable helpers that need to **read + clear** the slot atomically
|
|
105
|
-
* (e.g. one-shot action consumption patterns).
|
|
106
|
-
*
|
|
107
|
-
* In step handlers, prefer `useAtscriptWf(Type).resolveAction()` — it reads
|
|
108
|
-
* the same slot but validates the value against the schema's
|
|
109
|
-
* `@ui.form.action` / `@wf.action.withData` declarations and throws
|
|
110
|
-
* `StepRetriableError` on unknown actions.
|
|
111
|
-
*
|
|
112
|
-
* **In a transport adapter** (to set the action from the request body):
|
|
113
|
-
* ```ts
|
|
114
|
-
* const { setAction } = useWfActionSlot()
|
|
115
|
-
* setAction(body.action)
|
|
116
|
-
* ```
|
|
117
|
-
*
|
|
118
|
-
* **In step handlers** (raw read — prefer `@WfAction()` / `useAtscriptWf().resolveAction()`):
|
|
119
|
-
* ```ts
|
|
120
|
-
* const { getAction } = useWfActionSlot()
|
|
121
|
-
* const action = getAction()
|
|
122
|
-
* ```
|
|
123
|
-
*/
|
|
124
|
-
function useWfActionSlot() {
|
|
125
|
-
const ctx = current();
|
|
126
|
-
return {
|
|
127
|
-
getAction: () => ctx.has(actionKey) ? ctx.get(actionKey) : void 0,
|
|
128
|
-
setAction: (action) => ctx.set(actionKey, action)
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
//#endregion
|
|
132
86
|
//#region src/wf-io/validator-cache.ts
|
|
133
87
|
const cache = /* @__PURE__ */ new WeakMap();
|
|
134
88
|
/**
|
|
@@ -163,7 +117,6 @@ function isValidatorError(err) {
|
|
|
163
117
|
}
|
|
164
118
|
function useAtscriptWf(type) {
|
|
165
119
|
const wfState = useWfState();
|
|
166
|
-
const wfAction = useWfActionSlot();
|
|
167
120
|
function requireInput({ errors, formMessage } = {}) {
|
|
168
121
|
const passContext = extractPassContext(type, wfState.ctx() ?? {});
|
|
169
122
|
const mergedErrors = errors ? { ...errors } : formMessage ? {} : void 0;
|
|
@@ -188,7 +141,7 @@ function useAtscriptWf(type) {
|
|
|
188
141
|
}
|
|
189
142
|
}
|
|
190
143
|
function resolveInput(opts) {
|
|
191
|
-
const input = wfState.input();
|
|
144
|
+
const input = wfState.input()?.formData;
|
|
192
145
|
if (input === void 0) throw requireInput();
|
|
193
146
|
validateOrThrow(input, opts?.partial === "deep" ? {
|
|
194
147
|
partial: "deep",
|
|
@@ -197,7 +150,7 @@ function useAtscriptWf(type) {
|
|
|
197
150
|
return input;
|
|
198
151
|
}
|
|
199
152
|
function resolveAction() {
|
|
200
|
-
const action =
|
|
153
|
+
const action = wfState.input()?.action;
|
|
201
154
|
if (action === void 0) return void 0;
|
|
202
155
|
const { actions, actionsWithData } = getFormActions(type);
|
|
203
156
|
if (!actions.includes(action) && !actionsWithData.includes(action)) throw requireInput({ formMessage: `Action "${action}" is not supported` });
|
|
@@ -241,7 +194,7 @@ function WfInput(opts) {
|
|
|
241
194
|
const pass = opts?.pass === true;
|
|
242
195
|
const action = wf.resolveAction();
|
|
243
196
|
if (action) {
|
|
244
|
-
const wfInput = useWfState().input();
|
|
197
|
+
const wfInput = useWfState().input()?.formData;
|
|
245
198
|
const { actions, actionsWithData } = getFormActions(type);
|
|
246
199
|
const isNoData = actions.includes(action);
|
|
247
200
|
const isWithData = actionsWithData.includes(action);
|
|
@@ -263,33 +216,32 @@ function WfInput(opts) {
|
|
|
263
216
|
//#endregion
|
|
264
217
|
//#region src/wf-io/wf-action.decorator.ts
|
|
265
218
|
/**
|
|
266
|
-
* Parameter decorator
|
|
219
|
+
* Parameter decorator — sugar for `useAtscriptWf(Type).resolveAction()`.
|
|
220
|
+
*
|
|
221
|
+
* Resolves to the current workflow action name from the input envelope, or
|
|
222
|
+
* `undefined` when no action was submitted.
|
|
267
223
|
*
|
|
268
|
-
*
|
|
269
|
-
*
|
|
270
|
-
*
|
|
271
|
-
*
|
|
224
|
+
* The form type is **required**: the decorator validates the action against
|
|
225
|
+
* the form's declared `@ui.form.action` / `@wf.action.withData` whitelist and
|
|
226
|
+
* throws `StepRetriableError` for any unknown action — the step body never
|
|
227
|
+
* sees actions that aren't part of the form's contract.
|
|
272
228
|
*
|
|
273
229
|
* @example
|
|
274
230
|
* ```ts
|
|
275
231
|
* @Step('mfa-verify')
|
|
276
232
|
* async mfaVerify(
|
|
277
233
|
* @WfInput() input: PincodeForm,
|
|
278
|
-
* @WfAction() action: string | undefined,
|
|
234
|
+
* @WfAction(PincodeForm) action: string | undefined,
|
|
279
235
|
* ) {
|
|
280
236
|
* if (action === 'resend') return this.sendOtp()
|
|
281
237
|
* await this.verifyCode(input.code)
|
|
282
238
|
* }
|
|
283
239
|
* ```
|
|
284
240
|
*/
|
|
285
|
-
function WfAction() {
|
|
241
|
+
function WfAction(type) {
|
|
286
242
|
return (target, key, index) => {
|
|
287
243
|
if (typeof index !== "number") return;
|
|
288
|
-
Resolve((
|
|
289
|
-
const type = metas?.targetMeta?.type;
|
|
290
|
-
if (type && isAnnotatedType(type)) return useAtscriptWf(type).resolveAction();
|
|
291
|
-
return useWfActionSlot().getAction();
|
|
292
|
-
}, "WfAction")(target, key, index);
|
|
244
|
+
Resolve(() => useAtscriptWf(type).resolveAction(), "WfAction")(target, key, index);
|
|
293
245
|
};
|
|
294
246
|
}
|
|
295
247
|
//#endregion
|
|
@@ -420,4 +372,4 @@ function abortWf(reason, opts) {
|
|
|
420
372
|
});
|
|
421
373
|
}
|
|
422
374
|
//#endregion
|
|
423
|
-
export { WfAction, WfInput, abortWf, createAsHttpOutlet, extractPassContext, finishWf, getFormActions, handleAsOutletRequest, isWfFinished, serializeFormSchema, useAtscriptWf
|
|
375
|
+
export { WfAction, WfInput, abortWf, createAsHttpOutlet, extractPassContext, finishWf, getFormActions, handleAsOutletRequest, isWfFinished, serializeFormSchema, useAtscriptWf };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atscript/moost-wf",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.72",
|
|
4
4
|
"description": "Workflow form integration for moost — decorators, interceptors, and serialization driven by atscript type metadata",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"atscript",
|
|
@@ -51,26 +51,26 @@
|
|
|
51
51
|
"access": "public"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@atscript/core": "^0.1.
|
|
55
|
-
"@atscript/db": "^0.1.
|
|
56
|
-
"@atscript/db-sqlite": "^0.1.
|
|
57
|
-
"@atscript/typescript": "^0.1.
|
|
58
|
-
"@moostjs/event-wf": "^0.6.
|
|
54
|
+
"@atscript/core": "^0.1.59",
|
|
55
|
+
"@atscript/db": "^0.1.83",
|
|
56
|
+
"@atscript/db-sqlite": "^0.1.83",
|
|
57
|
+
"@atscript/typescript": "^0.1.59",
|
|
58
|
+
"@moostjs/event-wf": "^0.6.15",
|
|
59
59
|
"@prostojs/wf": "^0.1.1",
|
|
60
60
|
"@wooksjs/event-core": "^0.7.13",
|
|
61
61
|
"@wooksjs/event-wf": "^0.7.13",
|
|
62
|
-
"moost": "^0.6.
|
|
63
|
-
"unplugin-atscript": "^0.1.
|
|
62
|
+
"moost": "^0.6.15",
|
|
63
|
+
"unplugin-atscript": "^0.1.59",
|
|
64
64
|
"vitest": "npm:@voidzero-dev/vite-plus-test@0.1.14",
|
|
65
|
-
"@atscript/ui": "^0.1.
|
|
65
|
+
"@atscript/ui": "^0.1.72"
|
|
66
66
|
},
|
|
67
67
|
"peerDependencies": {
|
|
68
|
-
"@atscript/core": "^0.1.
|
|
69
|
-
"@atscript/typescript": "^0.1.
|
|
70
|
-
"@moostjs/event-wf": "^0.6.
|
|
68
|
+
"@atscript/core": "^0.1.59",
|
|
69
|
+
"@atscript/typescript": "^0.1.59",
|
|
70
|
+
"@moostjs/event-wf": "^0.6.15",
|
|
71
71
|
"@wooksjs/event-core": "^0.7.13",
|
|
72
72
|
"@wooksjs/event-wf": "^0.7.13",
|
|
73
|
-
"moost": "^0.6.
|
|
73
|
+
"moost": "^0.6.15"
|
|
74
74
|
},
|
|
75
75
|
"scripts": {
|
|
76
76
|
"build": "vp pack",
|