@stonecrop/stonecrop 0.10.7 → 0.10.9
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/doctype.js +51 -2
- package/dist/src/doctype.d.ts +28 -4
- package/dist/src/doctype.d.ts.map +1 -1
- package/dist/src/stonecrop.d.ts.map +1 -1
- package/dist/src/types/index.d.ts +3 -3
- package/dist/src/types/index.d.ts.map +1 -1
- package/dist/stonecrop.d.ts +29 -5
- package/dist/stonecrop.js +42 -8
- package/dist/stonecrop.js.map +1 -1
- package/package.json +4 -4
- package/src/doctype.ts +67 -6
- package/src/stonecrop.ts +15 -5
- package/src/types/index.ts +3 -3
package/dist/doctype.js
CHANGED
|
@@ -135,7 +135,7 @@ export default class Doctype {
|
|
|
135
135
|
}
|
|
136
136
|
/**
|
|
137
137
|
* Returns the transitions available from a given workflow state, derived from the
|
|
138
|
-
* doctype's
|
|
138
|
+
* doctype's workflow configuration. Supports both XState format and WorkflowMeta format.
|
|
139
139
|
*
|
|
140
140
|
* @param currentState - The state name to read transitions from
|
|
141
141
|
* @returns Array of transition descriptors with `name` and `targetState`
|
|
@@ -149,7 +149,34 @@ export default class Doctype {
|
|
|
149
149
|
* @public
|
|
150
150
|
*/
|
|
151
151
|
getAvailableTransitions(currentState) {
|
|
152
|
-
const
|
|
152
|
+
const workflow = this.workflow;
|
|
153
|
+
if (!workflow)
|
|
154
|
+
return [];
|
|
155
|
+
// Check if this is WorkflowMeta format (states is an array) or XState format (states is an object)
|
|
156
|
+
if (Array.isArray(workflow.states)) {
|
|
157
|
+
// WorkflowMeta format: validate state exists and filter actions by allowedStates
|
|
158
|
+
const states = workflow.states;
|
|
159
|
+
if (!states.includes(currentState))
|
|
160
|
+
return [];
|
|
161
|
+
const actions = workflow.actions;
|
|
162
|
+
if (!actions)
|
|
163
|
+
return [];
|
|
164
|
+
return Object.entries(actions)
|
|
165
|
+
.filter(([, actionDef]) => {
|
|
166
|
+
const allowedStates = actionDef.allowedStates;
|
|
167
|
+
// If no allowedStates specified, action is available in all valid states
|
|
168
|
+
if (!allowedStates || allowedStates.length === 0)
|
|
169
|
+
return true;
|
|
170
|
+
return allowedStates.includes(currentState);
|
|
171
|
+
})
|
|
172
|
+
.map(([name]) => ({
|
|
173
|
+
name,
|
|
174
|
+
// WorkflowMeta doesn't define target states - transitions are handled server-side
|
|
175
|
+
targetState: currentState,
|
|
176
|
+
}));
|
|
177
|
+
}
|
|
178
|
+
// XState format: use the on property of the state
|
|
179
|
+
const states = workflow.states;
|
|
153
180
|
if (!states)
|
|
154
181
|
return [];
|
|
155
182
|
const stateConfig = states[currentState];
|
|
@@ -160,6 +187,28 @@ export default class Doctype {
|
|
|
160
187
|
targetState: typeof target === 'string' ? target : 'unknown',
|
|
161
188
|
}));
|
|
162
189
|
}
|
|
190
|
+
/**
|
|
191
|
+
* Returns metadata for a specific action, if available.
|
|
192
|
+
* Only works with WorkflowMeta format; returns undefined for XState format.
|
|
193
|
+
*
|
|
194
|
+
* @param actionName - The action name to get metadata for
|
|
195
|
+
* @returns Action metadata or undefined
|
|
196
|
+
*
|
|
197
|
+
* @example
|
|
198
|
+
* ```ts
|
|
199
|
+
* const actionMeta = doctype.getActionMeta('submit')
|
|
200
|
+
* // { label: 'Submit', handler: 'plan:submit', allowedStates: ['draft'] }
|
|
201
|
+
* ```
|
|
202
|
+
*
|
|
203
|
+
* @public
|
|
204
|
+
*/
|
|
205
|
+
getActionMeta(actionName) {
|
|
206
|
+
const workflow = this.workflow;
|
|
207
|
+
if (!workflow || !Array.isArray(workflow.states))
|
|
208
|
+
return undefined;
|
|
209
|
+
const actions = workflow.actions;
|
|
210
|
+
return actions?.[actionName];
|
|
211
|
+
}
|
|
163
212
|
/**
|
|
164
213
|
* Converts the registered doctype string to a slug (kebab-case). The following conversions are made:
|
|
165
214
|
* - It replaces camelCase and PascalCase with kebab-case strings
|
package/dist/src/doctype.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { Component } from 'vue';
|
|
2
1
|
import type { SchemaTypes } from '@stonecrop/aform';
|
|
2
|
+
import type { WorkflowMeta } from '@stonecrop/schema';
|
|
3
|
+
import { Component } from 'vue';
|
|
3
4
|
import type { UnknownMachineConfig } from 'xstate';
|
|
4
5
|
import type { ImmutableDoctype } from './types';
|
|
5
6
|
/**
|
|
@@ -16,8 +17,8 @@ export type DoctypeConfig = {
|
|
|
16
17
|
tableName?: string;
|
|
17
18
|
/** Field definitions */
|
|
18
19
|
fields?: SchemaTypes[];
|
|
19
|
-
/** Workflow configuration */
|
|
20
|
-
workflow?: UnknownMachineConfig;
|
|
20
|
+
/** Workflow configuration (XState format or simple WorkflowMeta) */
|
|
21
|
+
workflow?: UnknownMachineConfig | WorkflowMeta;
|
|
21
22
|
/** Actions and their field triggers */
|
|
22
23
|
actions?: Record<string, string[]>;
|
|
23
24
|
/** Parent doctype for inheritance */
|
|
@@ -143,7 +144,7 @@ export default class Doctype {
|
|
|
143
144
|
getActionsObject(): Record<string, string[]>;
|
|
144
145
|
/**
|
|
145
146
|
* Returns the transitions available from a given workflow state, derived from the
|
|
146
|
-
* doctype's
|
|
147
|
+
* doctype's workflow configuration. Supports both XState format and WorkflowMeta format.
|
|
147
148
|
*
|
|
148
149
|
* @param currentState - The state name to read transitions from
|
|
149
150
|
* @returns Array of transition descriptors with `name` and `targetState`
|
|
@@ -160,6 +161,29 @@ export default class Doctype {
|
|
|
160
161
|
name: string;
|
|
161
162
|
targetState: string;
|
|
162
163
|
}>;
|
|
164
|
+
/**
|
|
165
|
+
* Returns metadata for a specific action, if available.
|
|
166
|
+
* Only works with WorkflowMeta format; returns undefined for XState format.
|
|
167
|
+
*
|
|
168
|
+
* @param actionName - The action name to get metadata for
|
|
169
|
+
* @returns Action metadata or undefined
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* ```ts
|
|
173
|
+
* const actionMeta = doctype.getActionMeta('submit')
|
|
174
|
+
* // { label: 'Submit', handler: 'plan:submit', allowedStates: ['draft'] }
|
|
175
|
+
* ```
|
|
176
|
+
*
|
|
177
|
+
* @public
|
|
178
|
+
*/
|
|
179
|
+
getActionMeta(actionName: string): {
|
|
180
|
+
label: string;
|
|
181
|
+
handler: string;
|
|
182
|
+
requiredFields?: string[];
|
|
183
|
+
allowedStates?: string[];
|
|
184
|
+
confirm?: boolean;
|
|
185
|
+
args?: Record<string, unknown>;
|
|
186
|
+
} | undefined;
|
|
163
187
|
/**
|
|
164
188
|
* Converts the registered doctype string to a slug (kebab-case). The following conversions are made:
|
|
165
189
|
* - It replaces camelCase and PascalCase with kebab-case strings
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"doctype.d.ts","sourceRoot":"","sources":["../../src/doctype.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"doctype.d.ts","sourceRoot":"","sources":["../../src/doctype.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AACnD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAErD,OAAO,EAAE,SAAS,EAAE,MAAM,KAAK,CAAA;AAC/B,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,QAAQ,CAAA;AAElD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAE/C;;;;GAIG;AACH,MAAM,MAAM,aAAa,GAAG;IAC3B,kCAAkC;IAClC,IAAI,EAAE,MAAM,CAAA;IACZ,qCAAqC;IACrC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,0BAA0B;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,wBAAwB;IACxB,MAAM,CAAC,EAAE,WAAW,EAAE,CAAA;IACtB,oEAAoE;IACpE,QAAQ,CAAC,EAAE,oBAAoB,GAAG,YAAY,CAAA;IAC9C,uCAAuC;IACvC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,C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AE,MAAM,CAAA;KAAE,CAAC;IAsC3F;;;;;;;;;;;;;;OAcG;IACH,aAAa,CACZ,UAAU,EAAE,MAAM,GAEhB;QACA,KAAK,EAAE,MAAM,CAAA;QACb,OAAO,EAAE,MAAM,CAAA;QACf,cAAc,CAAC,EAAE,MAAM,EAAE,CAAA;QACzB,aAAa,CAAC,EAAE,MAAM,EAAE,CAAA;QACxB,OAAO,CAAC,EAAE,OAAO,CAAA;QACjB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAC7B,GACD,SAAS;IAQZ;;;;;;;;;;;;;;;OAeG;IACH,IAAI,IAAI,WAKP;CACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stonecrop.d.ts","sourceRoot":"","sources":["../../src/stonecrop.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,
|
|
1
|
+
{"version":3,"file":"stonecrop.d.ts","sourceRoot":"","sources":["../../src/stonecrop.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAgB,MAAM,mBAAmB,CAAA;AAGjE,OAAO,OAAO,MAAM,WAAW,CAAA;AAC/B,OAAO,QAAQ,MAAM,YAAY,CAAA;AACjC,OAAO,EAAa,KAAK,OAAO,EAAE,MAAM,cAAc,CAAA;AAEtD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAC/D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAEpD;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAChC;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,UAAU,CAAA;CACnB;AAED;;;GAGG;AACH,qBAAa,SAAS;IACrB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,kBAAkB,CAAC,CAAyC;IACpE,OAAO,CAAC,mBAAmB,CAAC,CAA6B;IACzD,OAAO,CAAC,OAAO,CAAC,CAAY;IAE5B,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D;;;OAGG;IACH,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,GAAG,IAAI;IAW7C;;;OAGG;IACH,KAAK,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAK7B;;;;;;OAMG;IACH,SAAS,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,EAAE,GAAG,IAAI;IAkC/D;;;;OAIG;IACG,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAkBjD;;;;;OAKG;IACG,SAAS,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAelE;;;;;;;;;OASG;IACG,cAAc,CACnB,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,MAAM,EACd,IAAI,CAAC,EAAE,OAAO,EAAE,GACd,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,IAAI,EAAE,OAAO,CAAC;QAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAAC;IAWrE;;;OAGG;IACH,OAAO,CAAC,mBAAmB;IAM3B;;;;OAIG;IACG,OAAO,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,GAAG,CAAC;IAOlD;;;OAGG;IACH,QAAQ,IAAI,OAAO;IAInB;;;;;;;;;;;;OAYG;IACH,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM;CAyBnE"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DataClient } from '@stonecrop/schema';
|
|
1
|
+
import type { DataClient, WorkflowMeta } from '@stonecrop/schema';
|
|
2
2
|
import type { SchemaTypes } from '@stonecrop/aform';
|
|
3
3
|
import { List, Map } from 'immutable';
|
|
4
4
|
import type { Component } from 'vue';
|
|
@@ -14,7 +14,7 @@ import type { RouteContext } from './registry';
|
|
|
14
14
|
*/
|
|
15
15
|
export type ImmutableDoctype = {
|
|
16
16
|
readonly schema?: List<SchemaTypes>;
|
|
17
|
-
readonly workflow?: UnknownMachineConfig | AnyStateNodeConfig;
|
|
17
|
+
readonly workflow?: UnknownMachineConfig | AnyStateNodeConfig | WorkflowMeta;
|
|
18
18
|
readonly actions?: Map<string, string[]>;
|
|
19
19
|
};
|
|
20
20
|
/**
|
|
@@ -24,7 +24,7 @@ export type ImmutableDoctype = {
|
|
|
24
24
|
export type MutableDoctype = {
|
|
25
25
|
doctype?: string;
|
|
26
26
|
schema?: SchemaTypes[];
|
|
27
|
-
workflow?: UnknownMachineConfig | AnyStateNodeConfig;
|
|
27
|
+
workflow?: UnknownMachineConfig | AnyStateNodeConfig | WorkflowMeta;
|
|
28
28
|
actions?: Record<string, string[]>;
|
|
29
29
|
};
|
|
30
30
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AACjE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AACnD,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,WAAW,CAAA;AACrC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,KAAK,CAAA;AACpC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AACxC,OAAO,KAAK,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,QAAQ,CAAA;AAEtE,OAAO,KAAK,OAAO,MAAM,YAAY,CAAA;AACrC,OAAO,QAAQ,MAAM,aAAa,CAAA;AAClC,OAA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SAAS,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CACxF,CAAA;AAGD,cAAc,kBAAkB,CAAA;AAChC,cAAc,YAAY,CAAA;AAC1B,cAAc,iBAAiB,CAAA"}
|
package/dist/stonecrop.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ import { SchemaTypes } from '@stonecrop/aform';
|
|
|
11
11
|
import { Store } from 'pinia';
|
|
12
12
|
import { StoreDefinition } from 'pinia';
|
|
13
13
|
import type { UnknownMachineConfig } from 'xstate';
|
|
14
|
+
import type { WorkflowMeta } from '@stonecrop/schema';
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
17
|
* Result of executing a field action
|
|
@@ -231,7 +232,7 @@ export declare class Doctype {
|
|
|
231
232
|
getActionsObject(): Record<string, string[]>;
|
|
232
233
|
/**
|
|
233
234
|
* Returns the transitions available from a given workflow state, derived from the
|
|
234
|
-
* doctype's
|
|
235
|
+
* doctype's workflow configuration. Supports both XState format and WorkflowMeta format.
|
|
235
236
|
*
|
|
236
237
|
* @param currentState - The state name to read transitions from
|
|
237
238
|
* @returns Array of transition descriptors with `name` and `targetState`
|
|
@@ -248,6 +249,29 @@ export declare class Doctype {
|
|
|
248
249
|
name: string;
|
|
249
250
|
targetState: string;
|
|
250
251
|
}>;
|
|
252
|
+
/**
|
|
253
|
+
* Returns metadata for a specific action, if available.
|
|
254
|
+
* Only works with WorkflowMeta format; returns undefined for XState format.
|
|
255
|
+
*
|
|
256
|
+
* @param actionName - The action name to get metadata for
|
|
257
|
+
* @returns Action metadata or undefined
|
|
258
|
+
*
|
|
259
|
+
* @example
|
|
260
|
+
* ```ts
|
|
261
|
+
* const actionMeta = doctype.getActionMeta('submit')
|
|
262
|
+
* // { label: 'Submit', handler: 'plan:submit', allowedStates: ['draft'] }
|
|
263
|
+
* ```
|
|
264
|
+
*
|
|
265
|
+
* @public
|
|
266
|
+
*/
|
|
267
|
+
getActionMeta(actionName: string): {
|
|
268
|
+
label: string;
|
|
269
|
+
handler: string;
|
|
270
|
+
requiredFields?: string[];
|
|
271
|
+
allowedStates?: string[];
|
|
272
|
+
confirm?: boolean;
|
|
273
|
+
args?: Record<string, unknown>;
|
|
274
|
+
} | undefined;
|
|
251
275
|
/**
|
|
252
276
|
* Converts the registered doctype string to a slug (kebab-case). The following conversions are made:
|
|
253
277
|
* - It replaces camelCase and PascalCase with kebab-case strings
|
|
@@ -281,8 +305,8 @@ export declare type DoctypeConfig = {
|
|
|
281
305
|
tableName?: string;
|
|
282
306
|
/** Field definitions */
|
|
283
307
|
fields?: SchemaTypes[];
|
|
284
|
-
/** Workflow configuration */
|
|
285
|
-
workflow?: UnknownMachineConfig;
|
|
308
|
+
/** Workflow configuration (XState format or simple WorkflowMeta) */
|
|
309
|
+
workflow?: UnknownMachineConfig | WorkflowMeta;
|
|
286
310
|
/** Actions and their field triggers */
|
|
287
311
|
actions?: Record<string, string[]>;
|
|
288
312
|
/** Parent doctype for inheritance */
|
|
@@ -733,7 +757,7 @@ export declare type HSTStonecropReturn = BaseStonecropReturn & {
|
|
|
733
757
|
*/
|
|
734
758
|
export declare type ImmutableDoctype = {
|
|
735
759
|
readonly schema?: List<SchemaTypes>;
|
|
736
|
-
readonly workflow?: UnknownMachineConfig | AnyStateNodeConfig;
|
|
760
|
+
readonly workflow?: UnknownMachineConfig | AnyStateNodeConfig | WorkflowMeta;
|
|
737
761
|
readonly actions?: Map_2<string, string[]>;
|
|
738
762
|
};
|
|
739
763
|
|
|
@@ -783,7 +807,7 @@ export declare function markOperationIrreversible(operationId: string | undefine
|
|
|
783
807
|
export declare type MutableDoctype = {
|
|
784
808
|
doctype?: string;
|
|
785
809
|
schema?: SchemaTypes[];
|
|
786
|
-
workflow?: UnknownMachineConfig | AnyStateNodeConfig;
|
|
810
|
+
workflow?: UnknownMachineConfig | AnyStateNodeConfig | WorkflowMeta;
|
|
787
811
|
actions?: Record<string, string[]>;
|
|
788
812
|
};
|
|
789
813
|
|
package/dist/stonecrop.js
CHANGED
|
@@ -1515,8 +1515,9 @@ class Tn {
|
|
|
1515
1515
|
getRecordState(t, r) {
|
|
1516
1516
|
const n = typeof t == "string" ? t : t.slug, i = this.registry.getDoctype(n);
|
|
1517
1517
|
if (!i?.workflow) return "";
|
|
1518
|
-
const s = this.getRecordById(n, r)?.get("status"), a =
|
|
1519
|
-
|
|
1518
|
+
const s = this.getRecordById(n, r)?.get("status"), a = i.workflow;
|
|
1519
|
+
let u;
|
|
1520
|
+
return Array.isArray(a.states) ? u = a.states[0] ?? "" : u = typeof a.initial == "string" ? a.initial : Object.keys(a.states ?? {})[0] ?? "", s || u;
|
|
1520
1521
|
}
|
|
1521
1522
|
}
|
|
1522
1523
|
function as(e) {
|
|
@@ -5182,7 +5183,7 @@ class Ei {
|
|
|
5182
5183
|
}
|
|
5183
5184
|
/**
|
|
5184
5185
|
* Returns the transitions available from a given workflow state, derived from the
|
|
5185
|
-
* doctype's
|
|
5186
|
+
* doctype's workflow configuration. Supports both XState format and WorkflowMeta format.
|
|
5186
5187
|
*
|
|
5187
5188
|
* @param currentState - The state name to read transitions from
|
|
5188
5189
|
* @returns Array of transition descriptors with `name` and `targetState`
|
|
@@ -5196,14 +5197,47 @@ class Ei {
|
|
|
5196
5197
|
* @public
|
|
5197
5198
|
*/
|
|
5198
5199
|
getAvailableTransitions(t) {
|
|
5199
|
-
const r = this.workflow
|
|
5200
|
+
const r = this.workflow;
|
|
5200
5201
|
if (!r) return [];
|
|
5201
|
-
|
|
5202
|
-
|
|
5203
|
-
|
|
5204
|
-
|
|
5202
|
+
if (Array.isArray(r.states)) {
|
|
5203
|
+
if (!r.states.includes(t)) return [];
|
|
5204
|
+
const s = r.actions;
|
|
5205
|
+
return s ? Object.entries(s).filter(([, a]) => {
|
|
5206
|
+
const u = a.allowedStates;
|
|
5207
|
+
return !u || u.length === 0 ? !0 : u.includes(t);
|
|
5208
|
+
}).map(([a]) => ({
|
|
5209
|
+
name: a,
|
|
5210
|
+
// WorkflowMeta doesn't define target states - transitions are handled server-side
|
|
5211
|
+
targetState: t
|
|
5212
|
+
})) : [];
|
|
5213
|
+
}
|
|
5214
|
+
const n = r.states;
|
|
5215
|
+
if (!n) return [];
|
|
5216
|
+
const i = n[t];
|
|
5217
|
+
return i?.on ? Object.entries(i.on).map(([o, s]) => ({
|
|
5218
|
+
name: o,
|
|
5219
|
+
targetState: typeof s == "string" ? s : "unknown"
|
|
5205
5220
|
})) : [];
|
|
5206
5221
|
}
|
|
5222
|
+
/**
|
|
5223
|
+
* Returns metadata for a specific action, if available.
|
|
5224
|
+
* Only works with WorkflowMeta format; returns undefined for XState format.
|
|
5225
|
+
*
|
|
5226
|
+
* @param actionName - The action name to get metadata for
|
|
5227
|
+
* @returns Action metadata or undefined
|
|
5228
|
+
*
|
|
5229
|
+
* @example
|
|
5230
|
+
* ```ts
|
|
5231
|
+
* const actionMeta = doctype.getActionMeta('submit')
|
|
5232
|
+
* // { label: 'Submit', handler: 'plan:submit', allowedStates: ['draft'] }
|
|
5233
|
+
* ```
|
|
5234
|
+
*
|
|
5235
|
+
* @public
|
|
5236
|
+
*/
|
|
5237
|
+
getActionMeta(t) {
|
|
5238
|
+
const r = this.workflow;
|
|
5239
|
+
return !r || !Array.isArray(r.states) ? void 0 : r.actions?.[t];
|
|
5240
|
+
}
|
|
5207
5241
|
/**
|
|
5208
5242
|
* Converts the registered doctype string to a slug (kebab-case). The following conversions are made:
|
|
5209
5243
|
* - It replaces camelCase and PascalCase with kebab-case strings
|