@stonecrop/stonecrop 0.31.0 → 0.33.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.
Files changed (121) hide show
  1. package/dist/stonecrop.js +3548 -2740
  2. package/dist/stonecrop.js.map +1 -1
  3. package/dist/tsdoc-metadata.json +1 -1
  4. package/package.json +33 -27
  5. package/dist/src/client-action.d.ts +0 -31
  6. package/dist/src/client-action.d.ts.map +0 -1
  7. package/dist/src/client-action.js +0 -169
  8. package/dist/src/client-handler.d.ts +0 -43
  9. package/dist/src/client-handler.d.ts.map +0 -1
  10. package/dist/src/client-handler.js +0 -42
  11. package/dist/src/composables/lazy-link.d.ts +0 -25
  12. package/dist/src/composables/lazy-link.d.ts.map +0 -1
  13. package/dist/src/composables/lazy-link.js +0 -124
  14. package/dist/src/composables/operation-log.d.ts +0 -136
  15. package/dist/src/composables/operation-log.d.ts.map +0 -1
  16. package/dist/src/composables/operation-log.js +0 -224
  17. package/dist/src/composables/stonecrop.d.ts +0 -37
  18. package/dist/src/composables/stonecrop.d.ts.map +0 -1
  19. package/dist/src/composables/stonecrop.js +0 -433
  20. package/dist/src/doctype.d.ts +0 -243
  21. package/dist/src/doctype.d.ts.map +0 -1
  22. package/dist/src/doctype.js +0 -325
  23. package/dist/src/draft.d.ts +0 -35
  24. package/dist/src/draft.d.ts.map +0 -1
  25. package/dist/src/draft.js +0 -36
  26. package/dist/src/exceptions.d.ts +0 -14
  27. package/dist/src/exceptions.d.ts.map +0 -1
  28. package/dist/src/exceptions.js +0 -16
  29. package/dist/src/field-triggers.d.ts +0 -184
  30. package/dist/src/field-triggers.d.ts.map +0 -1
  31. package/dist/src/field-triggers.js +0 -577
  32. package/dist/src/index.d.ts +0 -25
  33. package/dist/src/index.d.ts.map +0 -1
  34. package/dist/src/index.js +0 -39
  35. package/dist/src/plugins/index.d.ts +0 -35
  36. package/dist/src/plugins/index.d.ts.map +0 -1
  37. package/dist/src/plugins/index.js +0 -98
  38. package/dist/src/registry.d.ts +0 -161
  39. package/dist/src/registry.d.ts.map +0 -1
  40. package/dist/src/registry.js +0 -384
  41. package/dist/src/schema-validator.d.ts +0 -78
  42. package/dist/src/schema-validator.d.ts.map +0 -1
  43. package/dist/src/schema-validator.js +0 -398
  44. package/dist/src/stonecrop.d.ts +0 -539
  45. package/dist/src/stonecrop.d.ts.map +0 -1
  46. package/dist/src/stonecrop.js +0 -610
  47. package/dist/src/stores/hst.d.ts +0 -92
  48. package/dist/src/stores/hst.d.ts.map +0 -1
  49. package/dist/src/stores/hst.js +0 -487
  50. package/dist/src/stores/index.d.ts +0 -9
  51. package/dist/src/stores/index.d.ts.map +0 -1
  52. package/dist/src/stores/index.js +0 -13
  53. package/dist/src/stores/operation-log.d.ts +0 -262
  54. package/dist/src/stores/operation-log.d.ts.map +0 -1
  55. package/dist/src/stores/operation-log.js +0 -571
  56. package/dist/src/stores/validation.d.ts +0 -83
  57. package/dist/src/stores/validation.d.ts.map +0 -1
  58. package/dist/src/stores/validation.js +0 -104
  59. package/dist/src/types/client-action.d.ts +0 -121
  60. package/dist/src/types/client-action.d.ts.map +0 -1
  61. package/dist/src/types/client-action.js +0 -0
  62. package/dist/src/types/composable.d.ts +0 -268
  63. package/dist/src/types/composable.d.ts.map +0 -1
  64. package/dist/src/types/composable.js +0 -0
  65. package/dist/src/types/doctype.d.ts +0 -34
  66. package/dist/src/types/doctype.d.ts.map +0 -1
  67. package/dist/src/types/doctype.js +0 -0
  68. package/dist/src/types/field-triggers.d.ts +0 -186
  69. package/dist/src/types/field-triggers.d.ts.map +0 -1
  70. package/dist/src/types/field-triggers.js +0 -4
  71. package/dist/src/types/hst.d.ts +0 -70
  72. package/dist/src/types/hst.d.ts.map +0 -1
  73. package/dist/src/types/hst.js +0 -0
  74. package/dist/src/types/index.d.ts +0 -11
  75. package/dist/src/types/index.d.ts.map +0 -1
  76. package/dist/src/types/index.js +0 -11
  77. package/dist/src/types/operation-log.d.ts +0 -163
  78. package/dist/src/types/operation-log.d.ts.map +0 -1
  79. package/dist/src/types/operation-log.js +0 -0
  80. package/dist/src/types/plugin.d.ts +0 -37
  81. package/dist/src/types/plugin.d.ts.map +0 -1
  82. package/dist/src/types/plugin.js +0 -0
  83. package/dist/src/types/registry.d.ts +0 -11
  84. package/dist/src/types/registry.d.ts.map +0 -1
  85. package/dist/src/types/registry.js +0 -0
  86. package/dist/src/types/schema-validator.d.ts +0 -66
  87. package/dist/src/types/schema-validator.d.ts.map +0 -1
  88. package/dist/src/types/schema-validator.js +0 -13
  89. package/dist/src/types/stonecrop.d.ts +0 -32
  90. package/dist/src/types/stonecrop.d.ts.map +0 -1
  91. package/dist/src/types/stonecrop.js +0 -0
  92. package/dist/stonecrop.tsbuildinfo +0 -1
  93. package/src/client-action.ts +0 -207
  94. package/src/client-handler.ts +0 -55
  95. package/src/composables/lazy-link.ts +0 -145
  96. package/src/composables/operation-log.ts +0 -257
  97. package/src/composables/stonecrop.ts +0 -556
  98. package/src/doctype.ts +0 -360
  99. package/src/draft.ts +0 -38
  100. package/src/exceptions.ts +0 -16
  101. package/src/field-triggers.ts +0 -686
  102. package/src/index.ts +0 -81
  103. package/src/plugins/index.ts +0 -113
  104. package/src/registry.ts +0 -433
  105. package/src/schema-validator.ts +0 -476
  106. package/src/stonecrop.ts +0 -721
  107. package/src/stores/hst.ts +0 -626
  108. package/src/stores/index.ts +0 -21
  109. package/src/stores/operation-log.ts +0 -675
  110. package/src/stores/validation.ts +0 -138
  111. package/src/types/client-action.ts +0 -121
  112. package/src/types/composable.ts +0 -288
  113. package/src/types/doctype.ts +0 -35
  114. package/src/types/field-triggers.ts +0 -201
  115. package/src/types/hst.ts +0 -77
  116. package/src/types/index.ts +0 -11
  117. package/src/types/operation-log.ts +0 -202
  118. package/src/types/plugin.ts +0 -38
  119. package/src/types/registry.ts +0 -10
  120. package/src/types/schema-validator.ts +0 -69
  121. package/src/types/stonecrop.ts +0 -33
@@ -1,325 +0,0 @@
1
- import { getRecordIdentity, getRecordIdField, isActionAllowedInState, normalizeFieldKind } from '@stonecrop/schema';
2
- import { List } from 'immutable';
3
- /**
4
- * Doctype runtime class with Immutable.js collections for HST change tracking.
5
- * @public
6
- */
7
- export default class Doctype {
8
- /**
9
- * The doctype name
10
- * @public
11
- * @readonly
12
- */
13
- doctype;
14
- /**
15
- * Alias for doctype (for DoctypeLike interface compatibility)
16
- * @public
17
- * @readonly
18
- */
19
- get name() {
20
- return this.doctype;
21
- }
22
- /**
23
- * The doctype schema
24
- * @public
25
- * @readonly
26
- */
27
- schema;
28
- /**
29
- * The doctype workflow
30
- * @public
31
- * @readonly
32
- */
33
- workflow;
34
- /**
35
- * The doctype component
36
- * @public
37
- * @readonly
38
- */
39
- component;
40
- /**
41
- * Relationship links to other doctypes
42
- * @public
43
- * @readonly
44
- */
45
- links;
46
- /**
47
- * Field on this doctype used when displaying a reference to one of its records.
48
- * @public
49
- * @readonly
50
- */
51
- displayField;
52
- /**
53
- * Creates a new Doctype instance
54
- * @param doctype - The doctype name
55
- * @param schema - The doctype schema definition
56
- * @param workflow - The doctype workflow configuration (XState machine)
57
- * @param component - Optional Vue component for rendering the doctype
58
- * @param links - Optional relationship links to other doctypes
59
- * @param displayField - Optional field used when displaying references to this doctype
60
- */
61
- constructor(doctype, schema, workflow, component, links, displayField) {
62
- this.doctype = doctype;
63
- this.schema = schema;
64
- this.workflow = workflow;
65
- this.component = component;
66
- this.links = links;
67
- this.displayField = displayField;
68
- }
69
- /**
70
- * Creates a Doctype instance from a plain configuration object.
71
- * Handles conversion of arrays to Immutable.js collections internally.
72
- *
73
- * This is the recommended way to create a Doctype from API responses
74
- * or configuration files, as it encapsulates the Immutable.js construction
75
- * that the framework uses internally.
76
- *
77
- * @param config - Plain object with doctype configuration (typically from API response)
78
- * @returns A new Doctype instance with Immutable.js collections
79
- *
80
- * @example
81
- * ```ts
82
- * // From an API response
83
- * const response = await client.getMeta({ doctype: 'plan' })
84
- * const doctype = Doctype.fromObject(response)
85
- * registry.addDoctype(doctype)
86
- * ```
87
- *
88
- * @example
89
- * ```ts
90
- * // From a configuration object
91
- * const planDoctype = Doctype.fromObject({
92
- * name: 'Plan',
93
- * fields: [
94
- * { fieldname: 'title', label: 'Title', component: 'ATextInput' },
95
- * { fieldname: 'status', label: 'Status', component: 'ATextInput' },
96
- * ],
97
- * workflow: {
98
- * id: 'plan',
99
- * initial: 'draft',
100
- * states: { draft: {}, submitted: {} }
101
- * }
102
- * })
103
- * ```
104
- *
105
- * @public
106
- */
107
- static fromObject(config) {
108
- // Authored JSON may omit the `kind` discriminant; the Zod schema injects it via a
109
- // preprocess, but this path bypasses Zod. Normalize here so the registry's
110
- // `resolveFields` (which gates link/fieldset handling on `field.kind`) sees the same
111
- // shape a parsed doctype would — otherwise links silently fail to expand.
112
- // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- normalizeFieldKind only injects the `kind` discriminant; the field shape is otherwise preserved
113
- const fields = config.fields?.map(normalizeFieldKind);
114
- const schema = fields ? List(fields) : List();
115
- return new Doctype(config.name, schema, config.workflow, undefined, config.links, config.displayField);
116
- }
117
- /**
118
- * Returns the raw authoring schema as a plain array.
119
- * For the resolved schema suitable for AForm, use `registry.resolveSchema(doctype)`.
120
- *
121
- * @returns Array of raw DoctypeField authoring definitions
122
- *
123
- * @example
124
- * ```ts
125
- * const fields = doctype.getSchemaArray()
126
- * // Pass to resolveSchema for AForm-ready output:
127
- * const resolved = registry.resolveSchema(doctype)
128
- * ```
129
- *
130
- * @public
131
- */
132
- getSchemaArray() {
133
- if (!this.schema)
134
- return [];
135
- return this.schema.toArray();
136
- }
137
- /**
138
- * Resolve a record's identity using this doctype's declared `primaryKey`, falling back to `id`.
139
- *
140
- * Lives here rather than at the call site because the doctype owns its schema — and because the
141
- * rule must match the server's, which builds its SQL identity predicate from the same declared
142
- * field via `@stonecrop/schema`'s `getPrimaryKeyField`.
143
- *
144
- * @param record - the record to read the identity from
145
- * @returns the identity as a string, or `undefined` when neither the declared key nor `id` yields one
146
- *
147
- * @public
148
- */
149
- getRecordId(record) {
150
- return getRecordIdentity(this.getSchemaArray(), record);
151
- }
152
- /**
153
- * The field a record of this doctype is identified by: the declared `primaryKey`, or `id`
154
- * when nothing is declared.
155
- *
156
- * The client-side twin of the adapters' `recordLookupField`. Both are the same call to
157
- * `@stonecrop/schema`'s `getRecordIdField`, so the field a caller reads an identity out of is
158
- * the same field the adapter builds its lookup predicate on.
159
- *
160
- * Use this to ask whether a record *states* its own identity. `getRecordId` deliberately
161
- * falls back to `id` when the declared key is missing, which is right for resolving a link
162
- * from a record already in hand and wrong for deciding whether a server response settled on
163
- * a new identity: a response that omits a natural key would resolve through that fallback to
164
- * a surrogate the adapter cannot look up.
165
- *
166
- * @returns The identifying fieldname
167
- *
168
- * @public
169
- */
170
- get recordIdField() {
171
- return getRecordIdField(this.getSchemaArray());
172
- }
173
- /**
174
- * Returns the transitions available from a given workflow state, derived from the
175
- * doctype's workflow configuration. Supports both XState format and WorkflowMeta format.
176
- *
177
- * @param currentState - The state name to read transitions from
178
- * @returns Array of transition descriptors with `name` and `targetState`
179
- *
180
- * @example
181
- * ```ts
182
- * const transitions = doctype.getAvailableTransitions('draft')
183
- * // [{ name: 'SUBMIT', targetState: 'submitted' }]
184
- * ```
185
- *
186
- * @public
187
- */
188
- getAvailableTransitions(currentState) {
189
- const workflow = this.workflow;
190
- if (!workflow)
191
- return [];
192
- // Check if this is WorkflowMeta format (states is an array) or XState format (states is an object)
193
- if (Array.isArray(workflow.states)) {
194
- // WorkflowMeta format: validate state exists and filter actions by allowedStates
195
- const states = workflow.states;
196
- if (!states.includes(currentState))
197
- return [];
198
- // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- Array.isArray(workflow.states) confirms WorkflowMeta format above
199
- const actions = workflow.actions;
200
- if (!actions)
201
- return [];
202
- return (Object.entries(actions)
203
- // Exclude stateless Commands — they change no state and are surfaced separately
204
- // via getAvailableCommands(). Genuine transitions carry a nextState.
205
- .filter(([, actionDef]) => !actionDef.stateless && isActionAllowedInState(actionDef, currentState))
206
- .map(([name, actionDef]) => ({
207
- name,
208
- targetState: actionDef.nextState ?? currentState,
209
- })));
210
- }
211
- // XState format: use the on property of the state
212
- const states = workflow.states;
213
- if (!states)
214
- return [];
215
- const stateConfig = states[currentState];
216
- if (!stateConfig?.on)
217
- return [];
218
- return Object.entries(stateConfig.on).map(([name, target]) => ({
219
- name,
220
- targetState: typeof target === 'string' ? target : 'unknown',
221
- }));
222
- }
223
- /**
224
- * Returns the stateless **Commands** available in a given workflow state — side-effect
225
- * actions (save/print/email…) that do not change workflow state. Unlike transitions,
226
- * Commands may exist on a workflow that declares no `states` (a commands-only doctype),
227
- * and a Command with no `allowedStates` is available in every state.
228
- *
229
- * Only meaningful for WorkflowMeta format; XState workflows have no Commands.
230
- *
231
- * @param currentState - The record's current state, used to honor a Command's `allowedStates`
232
- * @returns Array of command descriptors with `name`
233
- *
234
- * @example
235
- * ```ts
236
- * const commands = doctype.getAvailableCommands('Draft')
237
- * // [{ name: 'Print' }]
238
- * ```
239
- *
240
- * @public
241
- */
242
- getAvailableCommands(currentState) {
243
- const workflow = this.workflow;
244
- if (!workflow)
245
- return [];
246
- // Only WorkflowMeta carries an `actions` map; XState workflows have no Commands.
247
- // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- probing the workflow union for the optional WorkflowMeta actions map
248
- const actions = workflow.actions;
249
- if (!actions)
250
- return [];
251
- return Object.entries(actions)
252
- .filter(([, actionDef]) => actionDef.stateless === true && isActionAllowedInState(actionDef, currentState ?? ''))
253
- .map(([name]) => ({ name }));
254
- }
255
- /**
256
- * Returns the field-validation **triggers** declared on this doctype's workflow (advisory,
257
- * client-side). Keyed by trigger name. Returns undefined when the workflow is absent, is an
258
- * XState machine (no triggers), or simply declares none.
259
- *
260
- * @returns The `workflow.triggers` map, or undefined
261
- *
262
- * @example
263
- * ```ts
264
- * const triggers = doctype.getTriggers()
265
- * // { dateOrder: { on: ['start_date', 'end_date'], clientHandler: '…' } }
266
- * ```
267
- *
268
- * @public
269
- */
270
- getTriggers() {
271
- const workflow = this.workflow;
272
- if (!workflow)
273
- return undefined;
274
- // Only WorkflowMeta carries a `triggers` map; XState workflows have none.
275
- // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- probing the workflow union for the optional WorkflowMeta triggers map
276
- return workflow.triggers;
277
- }
278
- /**
279
- * Returns metadata for a specific action, if available.
280
- * Only works with WorkflowMeta format; returns undefined for XState format.
281
- *
282
- * @param actionName - The action name to get metadata for
283
- * @returns Action metadata or undefined
284
- *
285
- * @example
286
- * ```ts
287
- * const actionMeta = doctype.getActionMeta('submit')
288
- * // { label: 'Submit', allowedStates: ['draft'] }
289
- * ```
290
- *
291
- * @public
292
- */
293
- getActionMeta(actionName) {
294
- const workflow = this.workflow;
295
- if (!workflow)
296
- return undefined;
297
- // Only WorkflowMeta carries an `actions` map (with labels); XState workflows have none.
298
- // Don't require a `states` array — a commands-only doctype has labeled actions but no states.
299
- // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- probing the workflow union for the optional WorkflowMeta actions map
300
- const actions = workflow.actions;
301
- return actions?.[actionName];
302
- }
303
- /**
304
- * Converts the registered doctype string to a slug (kebab-case). The following conversions are made:
305
- * - It replaces camelCase and PascalCase with kebab-case strings
306
- * - It replaces spaces and underscores with hyphens
307
- * - It converts the string to lowercase
308
- *
309
- * @returns The slugified doctype string
310
- *
311
- * @example
312
- * ```ts
313
- * const doctype = new Doctype('TaskItem', schema, workflow, actions)
314
- * console.log(doctype.slug) // 'task-item'
315
- * ```
316
- *
317
- * @public
318
- */
319
- get slug() {
320
- return this.doctype
321
- .replace(/([a-z])([A-Z])/g, '$1-$2')
322
- .replace(/[\s_]+/g, '-')
323
- .toLowerCase();
324
- }
325
- }
@@ -1,35 +0,0 @@
1
- /**
2
- * The route identity of a record the user is composing that does not exist on the server yet.
3
- *
4
- * Rejected: minting `new-<timestamp>` so a draft had a store key too. Nothing ever created that
5
- * HST node, so every write to `doctype.<draftId>.<field>` threw on the missing ancestor, and the
6
- * form's data survived only because Vue cached the empty object the getter returned and the form
7
- * mutated it in place — any invalidation discarded the edits silently. Seeding the node instead
8
- * makes the draft a phantom row, because `getRecords` lists every key under the doctype.
9
- *
10
- * So a draft is held off-HST by whoever renders the form, and reaches the server as an action
11
- * carrying no record id, which the write path already reads as "create".
12
- */
13
- /**
14
- * The record-id segment a draft route carries: `/{doctype}/new`.
15
- *
16
- * Route only — never a store key, and never sent: an action dispatched for a draft omits the id
17
- * rather than sending this.
18
- *
19
- * @public
20
- */
21
- export declare const DRAFT_RECORD_ID = "new";
22
- /**
23
- * Whether a record id refers to a record that has not been saved yet.
24
- *
25
- * Guard anything that assumes the record exists — fetching it, resolving its links, judging
26
- * workflow readiness — with this rather than the literal. The shell and this package once spelled
27
- * the rule differently, which left every guard here dead.
28
- *
29
- * @param recordId - The record id to test
30
- * @returns `true` when the id is the draft segment, `false` for a real identity or no id at all
31
- *
32
- * @public
33
- */
34
- export declare function isDraftRecordId(recordId: string | null | undefined): boolean;
35
- //# sourceMappingURL=draft.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"draft.d.ts","sourceRoot":"","sources":["../../src/draft.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,QAAQ,CAAA;AAEpC;;;;;;;;;;;GAWG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAE5E"}
package/dist/src/draft.js DELETED
@@ -1,36 +0,0 @@
1
- /**
2
- * The route identity of a record the user is composing that does not exist on the server yet.
3
- *
4
- * Rejected: minting `new-<timestamp>` so a draft had a store key too. Nothing ever created that
5
- * HST node, so every write to `doctype.<draftId>.<field>` threw on the missing ancestor, and the
6
- * form's data survived only because Vue cached the empty object the getter returned and the form
7
- * mutated it in place — any invalidation discarded the edits silently. Seeding the node instead
8
- * makes the draft a phantom row, because `getRecords` lists every key under the doctype.
9
- *
10
- * So a draft is held off-HST by whoever renders the form, and reaches the server as an action
11
- * carrying no record id, which the write path already reads as "create".
12
- */
13
- /**
14
- * The record-id segment a draft route carries: `/{doctype}/new`.
15
- *
16
- * Route only — never a store key, and never sent: an action dispatched for a draft omits the id
17
- * rather than sending this.
18
- *
19
- * @public
20
- */
21
- export const DRAFT_RECORD_ID = 'new';
22
- /**
23
- * Whether a record id refers to a record that has not been saved yet.
24
- *
25
- * Guard anything that assumes the record exists — fetching it, resolving its links, judging
26
- * workflow readiness — with this rather than the literal. The shell and this package once spelled
27
- * the rule differently, which left every guard here dead.
28
- *
29
- * @param recordId - The record id to test
30
- * @returns `true` when the id is the draft segment, `false` for a real identity or no id at all
31
- *
32
- * @public
33
- */
34
- export function isDraftRecordId(recordId) {
35
- return recordId === DRAFT_RECORD_ID;
36
- }
@@ -1,14 +0,0 @@
1
- /**
2
- * NotImplementedError
3
- * @param message {string} - The error message
4
- * @class
5
- * @description This error is thrown when a method has not been implemented
6
- * @example
7
- * throw new NotImplementedError('Method not implemented')
8
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error|Error}
9
- * @public
10
- */
11
- export declare class NotImplementedError extends Error {
12
- constructor(message?: string);
13
- }
14
- //# sourceMappingURL=exceptions.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"exceptions.d.ts","sourceRoot":"","sources":["../../src/exceptions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,qBAAa,mBAAoB,SAAQ,KAAK;gBACjC,OAAO,GAAE,MAAW;CAIhC"}
@@ -1,16 +0,0 @@
1
- /**
2
- * NotImplementedError
3
- * @param message {string} - The error message
4
- * @class
5
- * @description This error is thrown when a method has not been implemented
6
- * @example
7
- * throw new NotImplementedError('Method not implemented')
8
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error|Error}
9
- * @public
10
- */
11
- export class NotImplementedError extends Error {
12
- constructor(message = '') {
13
- super(message);
14
- this.name = 'NotImplemented';
15
- }
16
- }
@@ -1,184 +0,0 @@
1
- import type { Map as ImmutableMap } from 'immutable';
2
- import type { FieldActionFunction, FieldChangeContext, FieldTriggerExecutionResult, FieldTriggerOptions, TransitionChangeContext, TransitionActionFunction, TransitionExecutionResult } from './types/field-triggers';
3
- /**
4
- * Field trigger execution engine integrated with Registry
5
- * Singleton pattern following Registry implementation
6
- * @public
7
- */
8
- export declare class FieldTriggerEngine {
9
- /**
10
- * The root FieldTriggerEngine instance
11
- */
12
- static _root: FieldTriggerEngine;
13
- private options;
14
- private doctypeActions;
15
- private doctypeTransitions;
16
- private fieldRollbackConfig;
17
- private globalActions;
18
- private globalTransitionActions;
19
- /**
20
- * Creates a new FieldTriggerEngine instance (singleton pattern)
21
- * @param options - Configuration options for the field trigger engine
22
- */
23
- constructor(options?: FieldTriggerOptions);
24
- /**
25
- * Register a global action function
26
- * @param name - The name of the action
27
- * @param fn - The action function
28
- */
29
- registerAction(name: string, fn: FieldActionFunction): void;
30
- /**
31
- * Look up a registered action function by name.
32
- * Returns `undefined` if the action has not been registered.
33
- * @param name - The action name
34
- */
35
- getAction(name: string): FieldActionFunction | undefined;
36
- /**
37
- * Register a global XState transition action function
38
- * @param name - The name of the transition action
39
- * @param fn - The transition action function
40
- */
41
- registerTransitionAction(name: string, fn: TransitionActionFunction): void;
42
- /**
43
- * Configure rollback behavior for a specific field trigger
44
- * @param doctype - The doctype name
45
- * @param fieldname - The field name
46
- * @param enableRollback - Whether to enable rollback
47
- */
48
- setFieldRollback(doctype: string, fieldname: string, enableRollback: boolean): void;
49
- /**
50
- * Get rollback configuration for a specific field trigger
51
- */
52
- private getFieldRollback;
53
- /**
54
- * Register actions from a doctype - both regular actions and field triggers
55
- * Separates XState transitions (uppercase) from field triggers (lowercase)
56
- * @param doctype - The doctype name
57
- * @param actions - The actions to register (supports Immutable Map, Map, or plain object)
58
- */
59
- registerDoctypeActions(doctype: string, actions: ImmutableMap<string, string[]> | Map<string, string[]> | Record<string, string[]> | undefined): void;
60
- /**
61
- * Categorize an action as either a field trigger or XState transition
62
- * Uses uppercase convention: UPPERCASE = transition, lowercase/mixed = field trigger
63
- */
64
- private categorizeAction;
65
- /**
66
- * Determine if a key represents an XState transition
67
- * Transitions are identified by being all uppercase
68
- */
69
- private isTransitionKey;
70
- /**
71
- * Execute field triggers for a changed field
72
- * @param context - The field change context
73
- * @param options - Execution options (timeout and enableRollback)
74
- */
75
- executeFieldTriggers(context: FieldChangeContext, options?: {
76
- timeout?: number;
77
- enableRollback?: boolean;
78
- }): Promise<FieldTriggerExecutionResult>;
79
- /**
80
- * Execute XState transition actions
81
- * Similar to field triggers but specifically for FSM state transitions
82
- * @param context - The transition change context
83
- * @param options - Execution options (timeout)
84
- */
85
- executeTransitionActions(context: TransitionChangeContext, options?: {
86
- timeout?: number;
87
- }): Promise<TransitionExecutionResult[]>;
88
- /**
89
- * Find transition actions for a specific doctype and transition
90
- */
91
- private findTransitionActions;
92
- /**
93
- * Execute a single transition action by name
94
- */
95
- private executeTransitionAction;
96
- /**
97
- * Find field triggers for a specific doctype and field
98
- * Field triggers are identified by keys that look like field paths (contain dots or match field names)
99
- */
100
- private findFieldTriggers;
101
- /**
102
- * Determine if an action key represents a field trigger
103
- * Field triggers can be:
104
- * - Exact field name match: "emailAddress"
105
- * - Wildcard patterns: "emailAddress.*", "*.is_primary"
106
- * - Nested field paths: "address.street", "contact.email"
107
- */
108
- private isFieldTriggerKey;
109
- /**
110
- * Match a field pattern against a field name
111
- * Supports wildcards (*) for dynamic segments
112
- */
113
- private matchFieldPattern;
114
- /**
115
- * Execute a single action by name
116
- */
117
- private executeAction;
118
- /**
119
- * Execute a function with timeout
120
- */
121
- private executeWithTimeout;
122
- /**
123
- * Capture a snapshot of the record state before executing actions
124
- * This creates a deep copy of the record data for potential rollback
125
- */
126
- private captureSnapshot;
127
- /**
128
- * Restore a previously captured snapshot
129
- * This reverts the record to its state before actions were executed
130
- */
131
- private restoreSnapshot;
132
- }
133
- /**
134
- * Get or create the global field trigger engine singleton
135
- * @param options - Optional configuration for the field trigger engine
136
- * @public
137
- */
138
- export declare function getGlobalTriggerEngine(options?: FieldTriggerOptions): FieldTriggerEngine;
139
- /**
140
- * Register a global action function that can be used in field triggers
141
- * @param name - The name of the action to register
142
- * @param fn - The action function to execute when the trigger fires
143
- * @public
144
- */
145
- export declare function registerGlobalAction(name: string, fn: FieldActionFunction): void;
146
- /**
147
- * Register a global XState transition action function
148
- * @param name - The name of the transition action to register
149
- * @param fn - The transition action function to execute
150
- * @public
151
- */
152
- export declare function registerTransitionAction(name: string, fn: TransitionActionFunction): void;
153
- /**
154
- * Configure rollback behavior for a specific field trigger
155
- * @param doctype - The doctype name
156
- * @param fieldname - The field name
157
- * @param enableRollback - Whether to enable automatic rollback for this field
158
- * @public
159
- */
160
- export declare function setFieldRollback(doctype: string, fieldname: string, enableRollback: boolean): void;
161
- /**
162
- * Manually trigger an XState transition for a specific doctype/record
163
- * This can be called directly when you need to execute transition actions programmatically
164
- * @param doctype - The doctype name
165
- * @param transition - The XState transition name to trigger
166
- * @param options - Optional configuration for the transition
167
- * @public
168
- */
169
- export declare function triggerTransition(doctype: string, transition: string, options?: {
170
- recordId?: string;
171
- currentState?: string;
172
- targetState?: string;
173
- fsmContext?: Record<string, any>;
174
- path?: string;
175
- }): Promise<any>;
176
- /**
177
- * Mark a specific operation as irreversible.
178
- * Used to prevent undo of critical operations like publishing or deletion.
179
- * @param operationId - The ID of the operation to mark as irreversible
180
- * @param reason - Human-readable reason why the operation cannot be undone
181
- * @public
182
- */
183
- export declare function markOperationIrreversible(operationId: string | undefined, reason: string): void;
184
- //# sourceMappingURL=field-triggers.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"field-triggers.d.ts","sourceRoot":"","sources":["../../src/field-triggers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,IAAI,YAAY,EAAE,MAAM,WAAW,CAAA;AAEpD,OAAO,K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