@stonecrop/stonecrop 0.30.0 → 0.32.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,577 +0,0 @@
1
- import { useOperationLogStore } from './stores/operation-log';
2
- /**
3
- * Field trigger execution engine integrated with Registry
4
- * Singleton pattern following Registry implementation
5
- * @public
6
- */
7
- export class FieldTriggerEngine {
8
- /**
9
- * The root FieldTriggerEngine instance
10
- */
11
- static _root;
12
- options;
13
- doctypeActions = new Map(); // doctype -> action/field -> functions
14
- doctypeTransitions = new Map(); // doctype -> transition -> functions
15
- fieldRollbackConfig = new Map(); // doctype -> field -> rollback enabled
16
- globalActions = new Map(); // action name -> function
17
- globalTransitionActions = new Map(); // transition action name -> function
18
- /**
19
- * Creates a new FieldTriggerEngine instance (singleton pattern)
20
- * @param options - Configuration options for the field trigger engine
21
- */
22
- constructor(options = {}) {
23
- if (FieldTriggerEngine._root) {
24
- return FieldTriggerEngine._root;
25
- }
26
- FieldTriggerEngine._root = this;
27
- this.options = {
28
- defaultTimeout: options.defaultTimeout ?? 5000,
29
- debug: options.debug ?? false,
30
- enableRollback: options.enableRollback ?? true,
31
- errorHandler: options.errorHandler,
32
- };
33
- return this;
34
- }
35
- /**
36
- * Register a global action function
37
- * @param name - The name of the action
38
- * @param fn - The action function
39
- */
40
- registerAction(name, fn) {
41
- this.globalActions.set(name, fn);
42
- }
43
- /**
44
- * Look up a registered action function by name.
45
- * Returns `undefined` if the action has not been registered.
46
- * @param name - The action name
47
- */
48
- getAction(name) {
49
- return this.globalActions.get(name);
50
- }
51
- /**
52
- * Register a global XState transition action function
53
- * @param name - The name of the transition action
54
- * @param fn - The transition action function
55
- */
56
- registerTransitionAction(name, fn) {
57
- this.globalTransitionActions.set(name, fn);
58
- }
59
- /**
60
- * Configure rollback behavior for a specific field trigger
61
- * @param doctype - The doctype name
62
- * @param fieldname - The field name
63
- * @param enableRollback - Whether to enable rollback
64
- */
65
- setFieldRollback(doctype, fieldname, enableRollback) {
66
- if (!this.fieldRollbackConfig.has(doctype)) {
67
- this.fieldRollbackConfig.set(doctype, new Map());
68
- }
69
- this.fieldRollbackConfig.get(doctype).set(fieldname, enableRollback);
70
- }
71
- /**
72
- * Get rollback configuration for a specific field trigger
73
- */
74
- getFieldRollback(doctype, fieldname) {
75
- return this.fieldRollbackConfig.get(doctype)?.get(fieldname);
76
- }
77
- /**
78
- * Register actions from a doctype - both regular actions and field triggers
79
- * Separates XState transitions (uppercase) from field triggers (lowercase)
80
- * @param doctype - The doctype name
81
- * @param actions - The actions to register (supports Immutable Map, Map, or plain object)
82
- */
83
- registerDoctypeActions(doctype, actions) {
84
- if (!actions)
85
- return;
86
- const actionMap = new Map();
87
- const transitionMap = new Map();
88
- // Convert from different Map types to regular Map
89
- // Check for Immutable.js Map first (has entrySeq method)
90
- // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- Immutable.js interop: runtime duck-type check follows
91
- const immutableActions = actions;
92
- if (typeof immutableActions.entrySeq === 'function') {
93
- // Immutable Map
94
- immutableActions.entrySeq().forEach(([key, value]) => {
95
- this.categorizeAction(key, value, actionMap, transitionMap);
96
- });
97
- }
98
- else if (actions instanceof Map) {
99
- // Regular Map
100
- for (const [key, value] of actions) {
101
- this.categorizeAction(key, value, actionMap, transitionMap);
102
- }
103
- }
104
- else if (actions && typeof actions === 'object') {
105
- // Plain object
106
- Object.entries(actions).forEach(([key, value]) => {
107
- // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- Object.entries value type is unknown at runtime; guarded by typeof object check above
108
- this.categorizeAction(key, value, actionMap, transitionMap);
109
- });
110
- }
111
- // Always set the maps, even if empty
112
- this.doctypeActions.set(doctype, actionMap);
113
- this.doctypeTransitions.set(doctype, transitionMap);
114
- }
115
- /**
116
- * Categorize an action as either a field trigger or XState transition
117
- * Uses uppercase convention: UPPERCASE = transition, lowercase/mixed = field trigger
118
- */
119
- categorizeAction(key, value, actionMap, transitionMap) {
120
- // Check if the key is all uppercase (XState transition convention)
121
- if (this.isTransitionKey(key)) {
122
- transitionMap.set(key, value);
123
- }
124
- else {
125
- actionMap.set(key, value);
126
- }
127
- }
128
- /**
129
- * Determine if a key represents an XState transition
130
- * Transitions are identified by being all uppercase
131
- */
132
- isTransitionKey(key) {
133
- // Must be all uppercase letters/numbers/underscores
134
- return /^[A-Z0-9_]+$/.test(key) && key.length > 0;
135
- }
136
- /**
137
- * Execute field triggers for a changed field
138
- * @param context - The field change context
139
- * @param options - Execution options (timeout and enableRollback)
140
- */
141
- async executeFieldTriggers(context, options = {}) {
142
- const { doctype, fieldname } = context;
143
- const triggers = this.findFieldTriggers(doctype, fieldname);
144
- if (triggers.length === 0) {
145
- return {
146
- path: context.path,
147
- actionResults: [],
148
- totalExecutionTime: 0,
149
- allSucceeded: true,
150
- stoppedOnError: false,
151
- rolledBack: false,
152
- };
153
- }
154
- const startTime = performance.now();
155
- const actionResults = [];
156
- let stoppedOnError = false;
157
- let rolledBack = false;
158
- let snapshot = undefined;
159
- // Determine if rollback is enabled (priority: execution option > field config > global setting)
160
- const fieldRollbackConfig = this.getFieldRollback(doctype, fieldname);
161
- const rollbackEnabled = options.enableRollback ?? fieldRollbackConfig ?? this.options.enableRollback;
162
- // Capture snapshot before executing actions if rollback is enabled
163
- if (rollbackEnabled && context.store) {
164
- snapshot = this.captureSnapshot(context);
165
- }
166
- // Execute actions sequentially — each action may depend on state set by the previous; stop-on-error semantics require sequential execution
167
- for (const actionName of triggers) {
168
- try {
169
- // oxlint-disable-next-line eslint/no-await-in-loop -- intentionally sequential; actions are order-dependent and stop on first failure
170
- const actionResult = await this.executeAction(actionName, context, options.timeout);
171
- actionResults.push(actionResult);
172
- if (!actionResult.success) {
173
- stoppedOnError = true;
174
- break;
175
- }
176
- }
177
- catch (error) {
178
- const actionError = error instanceof Error ? error : new Error(String(error));
179
- const errorResult = {
180
- success: false,
181
- error: actionError,
182
- executionTime: 0,
183
- action: actionName,
184
- };
185
- actionResults.push(errorResult);
186
- stoppedOnError = true;
187
- break;
188
- }
189
- }
190
- // Perform rollback if enabled, errors occurred, and we have a snapshot
191
- if (rollbackEnabled && stoppedOnError && snapshot && context.store) {
192
- try {
193
- this.restoreSnapshot(context, snapshot);
194
- rolledBack = true;
195
- }
196
- catch (rollbackError) {
197
- console.error('[FieldTriggers] Rollback failed:', rollbackError);
198
- }
199
- }
200
- const totalExecutionTime = performance.now() - startTime;
201
- // Call global error handler if configured and errors occurred
202
- const failedResults = actionResults.filter(r => !r.success && r.error != null);
203
- if (failedResults.length > 0 && this.options.errorHandler) {
204
- for (const failedResult of failedResults) {
205
- try {
206
- if (failedResult.error) {
207
- this.options.errorHandler(failedResult.error, context, failedResult.action);
208
- }
209
- }
210
- catch (handlerError) {
211
- console.error('[FieldTriggers] Error in global error handler:', handlerError);
212
- }
213
- }
214
- }
215
- const result = {
216
- path: context.path,
217
- actionResults,
218
- totalExecutionTime,
219
- allSucceeded: actionResults.every(r => r.success),
220
- stoppedOnError,
221
- rolledBack,
222
- snapshot: this.options.debug && rollbackEnabled ? snapshot : undefined, // Only include snapshot in debug mode if rollback is enabled
223
- };
224
- return result;
225
- }
226
- /**
227
- * Execute XState transition actions
228
- * Similar to field triggers but specifically for FSM state transitions
229
- * @param context - The transition change context
230
- * @param options - Execution options (timeout)
231
- */
232
- async executeTransitionActions(context, options = {}) {
233
- const { doctype, transition } = context;
234
- const transitionActions = this.findTransitionActions(doctype, transition);
235
- if (transitionActions.length === 0) {
236
- return [];
237
- }
238
- const results = [];
239
- // Execute transition actions sequentially — transitions are state-machine steps; order and stop-on-error are required
240
- for (const actionName of transitionActions) {
241
- try {
242
- // oxlint-disable-next-line eslint/no-await-in-loop -- intentionally sequential; transition actions are order-dependent and stop on first failure
243
- const actionResult = await this.executeTransitionAction(actionName, context, options.timeout);
244
- results.push(actionResult);
245
- if (!actionResult.success) {
246
- // Stop on first error for transitions
247
- break;
248
- }
249
- }
250
- catch (error) {
251
- const actionError = error instanceof Error ? error : new Error(String(error));
252
- const errorResult = {
253
- success: false,
254
- error: actionError,
255
- executionTime: 0,
256
- action: actionName,
257
- transition,
258
- };
259
- results.push(errorResult);
260
- break;
261
- }
262
- }
263
- // Call global error handler if configured and errors occurred
264
- const failedResults = results.filter(r => !r.success);
265
- if (failedResults.length > 0 && this.options.errorHandler) {
266
- for (const failedResult of failedResults) {
267
- try {
268
- // Call with FieldChangeContext (base context type)
269
- if (failedResult.error) {
270
- // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- action result carries string name; FieldAction cast required by errorHandler signature
271
- this.options.errorHandler(failedResult.error, context, failedResult.action);
272
- }
273
- }
274
- catch (handlerError) {
275
- console.error('[FieldTriggers] Error in global error handler:', handlerError);
276
- }
277
- }
278
- }
279
- return results;
280
- }
281
- /**
282
- * Find transition actions for a specific doctype and transition
283
- */
284
- findTransitionActions(doctype, transition) {
285
- const doctypeTransitions = this.doctypeTransitions.get(doctype);
286
- if (!doctypeTransitions)
287
- return [];
288
- return doctypeTransitions.get(transition) || [];
289
- }
290
- /**
291
- * Execute a single transition action by name
292
- */
293
- async executeTransitionAction(actionName, context, timeout) {
294
- const startTime = performance.now();
295
- const actionTimeout = timeout ?? this.options.defaultTimeout;
296
- try {
297
- // Look up action in transition-specific registry first, then fall back to global
298
- let actionFn = this.globalTransitionActions.get(actionName);
299
- // If not found in transition registry, try regular action registry
300
- // This allows sharing actions between field triggers and transitions
301
- if (!actionFn) {
302
- const regularActionFn = this.globalActions.get(actionName);
303
- if (regularActionFn) {
304
- // Wrap regular action to accept TransitionChangeContext
305
- actionFn = regularActionFn;
306
- }
307
- }
308
- if (!actionFn) {
309
- throw new Error(`Transition action "${actionName}" not found in registry`);
310
- }
311
- // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- actionFn may be FieldActionFunction set from globalActions fallback; polymorphic function type
312
- await this.executeWithTimeout(actionFn, context, actionTimeout);
313
- const executionTime = performance.now() - startTime;
314
- return {
315
- success: true,
316
- executionTime,
317
- action: actionName,
318
- transition: context.transition,
319
- };
320
- }
321
- catch (error) {
322
- const executionTime = performance.now() - startTime;
323
- const actionError = error instanceof Error ? error : new Error(String(error));
324
- return {
325
- success: false,
326
- error: actionError,
327
- executionTime,
328
- action: actionName,
329
- transition: context.transition,
330
- };
331
- }
332
- }
333
- /**
334
- * Find field triggers for a specific doctype and field
335
- * Field triggers are identified by keys that look like field paths (contain dots or match field names)
336
- */
337
- findFieldTriggers(doctype, fieldname) {
338
- const doctypeActions = this.doctypeActions.get(doctype);
339
- if (!doctypeActions)
340
- return [];
341
- const triggers = [];
342
- for (const [key, actionNames] of doctypeActions) {
343
- // Check if this key is a field trigger pattern
344
- if (this.isFieldTriggerKey(key, fieldname)) {
345
- triggers.push(...actionNames);
346
- }
347
- }
348
- return triggers;
349
- }
350
- /**
351
- * Determine if an action key represents a field trigger
352
- * Field triggers can be:
353
- * - Exact field name match: "emailAddress"
354
- * - Wildcard patterns: "emailAddress.*", "*.is_primary"
355
- * - Nested field paths: "address.street", "contact.email"
356
- */
357
- isFieldTriggerKey(key, fieldname) {
358
- // Exact match
359
- if (key === fieldname)
360
- return true;
361
- // Contains dots - likely a field path pattern
362
- if (key.includes('.')) {
363
- return this.matchFieldPattern(key, fieldname);
364
- }
365
- // Contains wildcards
366
- if (key.includes('*')) {
367
- return this.matchFieldPattern(key, fieldname);
368
- }
369
- return false;
370
- }
371
- /**
372
- * Match a field pattern against a field name
373
- * Supports wildcards (*) for dynamic segments
374
- */
375
- matchFieldPattern(pattern, fieldname) {
376
- const patternParts = pattern.split('.');
377
- const fieldParts = fieldname.split('.');
378
- if (patternParts.length !== fieldParts.length) {
379
- return false;
380
- }
381
- for (let i = 0; i < patternParts.length; i++) {
382
- const patternPart = patternParts[i];
383
- const fieldPart = fieldParts[i];
384
- if (patternPart === '*') {
385
- // Wildcard matches any segment
386
- continue;
387
- }
388
- else if (patternPart !== fieldPart) {
389
- // Exact match required
390
- return false;
391
- }
392
- }
393
- return true;
394
- }
395
- /**
396
- * Execute a single action by name
397
- */
398
- async executeAction(actionName, context, timeout) {
399
- const startTime = performance.now();
400
- const actionTimeout = timeout ?? this.options.defaultTimeout;
401
- try {
402
- // Look up action in global registry
403
- const actionFn = this.globalActions.get(actionName);
404
- if (!actionFn) {
405
- throw new Error(`Action "${actionName}" not found in registry`);
406
- }
407
- await this.executeWithTimeout(actionFn, context, actionTimeout);
408
- const executionTime = performance.now() - startTime;
409
- return {
410
- success: true,
411
- executionTime,
412
- action: actionName,
413
- };
414
- }
415
- catch (error) {
416
- const executionTime = performance.now() - startTime;
417
- const actionError = error instanceof Error ? error : new Error(String(error));
418
- return {
419
- success: false,
420
- error: actionError,
421
- executionTime,
422
- action: actionName,
423
- };
424
- }
425
- }
426
- /**
427
- * Execute a function with timeout
428
- */
429
- async executeWithTimeout(fn, context, timeout) {
430
- return new Promise((resolve, reject) => {
431
- const timeoutId = setTimeout(() => {
432
- reject(new Error(`Action timeout after ${timeout}ms`));
433
- }, timeout);
434
- Promise.resolve(fn(context))
435
- .then(result => {
436
- clearTimeout(timeoutId);
437
- return resolve(result);
438
- })
439
- .catch(error => {
440
- clearTimeout(timeoutId);
441
- reject(error instanceof Error ? error : new Error(String(error)));
442
- });
443
- });
444
- }
445
- /**
446
- * Capture a snapshot of the record state before executing actions
447
- * This creates a deep copy of the record data for potential rollback
448
- */
449
- captureSnapshot(context) {
450
- if (!context.store || !context.doctype || !context.recordId) {
451
- return undefined;
452
- }
453
- try {
454
- // Get the record path (doctype.recordId)
455
- const recordPath = `${context.doctype}.${context.recordId}`;
456
- // Get the current record data
457
- const recordData = context.store.get(recordPath);
458
- if (!recordData || typeof recordData !== 'object') {
459
- return undefined;
460
- }
461
- // Create a deep copy to avoid reference issues
462
- return JSON.parse(JSON.stringify(recordData));
463
- }
464
- catch (error) {
465
- if (this.options.debug) {
466
- console.warn('[FieldTriggers] Failed to capture snapshot:', error);
467
- }
468
- return undefined;
469
- }
470
- }
471
- /**
472
- * Restore a previously captured snapshot
473
- * This reverts the record to its state before actions were executed
474
- */
475
- restoreSnapshot(context, snapshot) {
476
- if (!context.store || !context.doctype || !context.recordId || !snapshot) {
477
- return;
478
- }
479
- try {
480
- // Get the record path (doctype.recordId)
481
- const recordPath = `${context.doctype}.${context.recordId}`;
482
- // Restore the entire record from snapshot
483
- context.store.set(recordPath, snapshot);
484
- if (this.options.debug) {
485
- // oxlint-disable-next-line no-console
486
- console.log(`[FieldTriggers] Rolled back ${recordPath} to previous state`);
487
- }
488
- }
489
- catch (error) {
490
- console.error('[FieldTriggers] Failed to restore snapshot:', error);
491
- throw error;
492
- }
493
- }
494
- }
495
- /**
496
- * Get or create the global field trigger engine singleton
497
- * @param options - Optional configuration for the field trigger engine
498
- * @public
499
- */
500
- export function getGlobalTriggerEngine(options) {
501
- return new FieldTriggerEngine(options);
502
- }
503
- /**
504
- * Register a global action function that can be used in field triggers
505
- * @param name - The name of the action to register
506
- * @param fn - The action function to execute when the trigger fires
507
- * @public
508
- */
509
- export function registerGlobalAction(name, fn) {
510
- const engine = getGlobalTriggerEngine();
511
- engine.registerAction(name, fn);
512
- }
513
- /**
514
- * Register a global XState transition action function
515
- * @param name - The name of the transition action to register
516
- * @param fn - The transition action function to execute
517
- * @public
518
- */
519
- export function registerTransitionAction(name, fn) {
520
- const engine = getGlobalTriggerEngine();
521
- engine.registerTransitionAction(name, fn);
522
- }
523
- /**
524
- * Configure rollback behavior for a specific field trigger
525
- * @param doctype - The doctype name
526
- * @param fieldname - The field name
527
- * @param enableRollback - Whether to enable automatic rollback for this field
528
- * @public
529
- */
530
- export function setFieldRollback(doctype, fieldname, enableRollback) {
531
- const engine = getGlobalTriggerEngine();
532
- engine.setFieldRollback(doctype, fieldname, enableRollback);
533
- }
534
- /**
535
- * Manually trigger an XState transition for a specific doctype/record
536
- * This can be called directly when you need to execute transition actions programmatically
537
- * @param doctype - The doctype name
538
- * @param transition - The XState transition name to trigger
539
- * @param options - Optional configuration for the transition
540
- * @public
541
- */
542
- export async function triggerTransition(doctype, transition, options) {
543
- const engine = getGlobalTriggerEngine();
544
- const context = {
545
- path: options?.path || (options?.recordId ? `${doctype}.${options.recordId}` : doctype),
546
- fieldname: '',
547
- beforeValue: undefined,
548
- afterValue: undefined,
549
- operation: 'set',
550
- doctype,
551
- recordId: options?.recordId,
552
- timestamp: new Date(),
553
- transition,
554
- currentState: options?.currentState,
555
- targetState: options?.targetState,
556
- fsmContext: options?.fsmContext,
557
- };
558
- return await engine.executeTransitionActions(context);
559
- }
560
- /**
561
- * Mark a specific operation as irreversible.
562
- * Used to prevent undo of critical operations like publishing or deletion.
563
- * @param operationId - The ID of the operation to mark as irreversible
564
- * @param reason - Human-readable reason why the operation cannot be undone
565
- * @public
566
- */
567
- export function markOperationIrreversible(operationId, reason) {
568
- if (!operationId)
569
- return;
570
- try {
571
- const store = useOperationLogStore();
572
- store.markIrreversible(operationId, reason);
573
- }
574
- catch {
575
- // Operation log is optional
576
- }
577
- }
@@ -1,25 +0,0 @@
1
- export type * from '@stonecrop/aform/types';
2
- export type * from '@stonecrop/atable/types';
3
- import { useClientAction } from './client-action';
4
- import { executeClientHandler } from './client-handler';
5
- import { useLazyLink } from './composables/lazy-link';
6
- import { useStonecrop } from './composables/stonecrop';
7
- import { useOperationLog, useUndoRedoShortcuts, withBatch } from './composables/operation-log';
8
- import Doctype from './doctype';
9
- import { DRAFT_RECORD_ID, isDraftRecordId } from './draft';
10
- import { FieldTriggerEngine, getGlobalTriggerEngine, markOperationIrreversible, registerGlobalAction, registerTransitionAction, setFieldRollback, triggerTransition } from './field-triggers';
11
- import plugin from './plugins';
12
- import Registry from './registry';
13
- import { Stonecrop } from './stonecrop';
14
- import { HST, createHST, type HSTNode } from './stores/hst';
15
- import { useOperationLogStore } from './stores/operation-log';
16
- import { useValidationStore } from './stores/validation';
17
- import { SchemaValidator, createValidator, validateSchema } from './schema-validator';
18
- import { ValidationSeverity } from './types/schema-validator';
19
- export type * from './types';
20
- export type { ClientHandlerApi } from './client-handler';
21
- export type { ValidationError } from './stores/validation';
22
- export { ValidationSeverity };
23
- export { Doctype, Registry, Stonecrop, DRAFT_RECORD_ID, isDraftRecordId, useLazyLink, useStonecrop, executeClientHandler, useClientAction, HST, createHST, HSTNode, FieldTriggerEngine, getGlobalTriggerEngine, registerGlobalAction, registerTransitionAction, setFieldRollback, triggerTransition, markOperationIrreversible, SchemaValidator, createValidator, validateSchema, useOperationLog, useOperationLogStore, useUndoRedoShortcuts, withBatch, useValidationStore, };
24
- export default plugin;
25
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,mBAAmB,wBAAwB,CAAA;AAC3C,mBAAmB,yBAAyB,CAAA;AAE5C,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAA;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AACtD,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAA;AAC9F,OAAO,OAAO,MAAM,WAAW,CAAA;AAC/B,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAC1D,OAAO,EACN,kBAAkB,EAClB,sBAAsB,EACtB,yBAAyB,EACzB,oBAAoB,EACpB,wBAAwB,EACxB,gBAAgB,EAChB,iBAAiB,EACjB,MAAM,kBAAkB,CAAA;AACzB,OAAO,MAAM,MAAM,WAAW,CAAA;AAC9B,OAAO,QAAQ,MAAM,YAAY,CAAA;AACjC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,KAAK,OAAO,EAAE,MAAM,cAAc,CAAA;AAC3D,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AAC7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AACxD,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACrF,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;AAG7D,mBAAmB,SAAS,CAAA;AAG5B,YAAY,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAGxD,YAAY,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAG1D,OAAO,EAAE,kBAAkB,EAAE,CAAA;AAE7B,OAAO,EACN,OAAO,EACP,QAAQ,EACR,SAAS,EAET,eAAe,EACf,eAAe,EACf,WAAW,EACX,YAAY,EAEZ,oBAAoB,EAEpB,eAAe,EAEf,GAAG,EACH,SAAS,EACT,OAAO,EAEP,kBAAkB,EAClB,sBAAsB,EACtB,oBAAoB,EACpB,wBAAwB,EACxB,gBAAgB,EAChB,iBAAiB,EACjB,yBAAyB,EAEzB,eAAe,EACf,eAAe,EACf,cAAc,EAEd,eAAe,EACf,oBAAoB,EACpB,oBAAoB,EACpB,SAAS,EAET,kBAAkB,GAElB,CAAA;AAGD,eAAe,MAAM,CAAA"}
package/dist/src/index.js DELETED
@@ -1,39 +0,0 @@
1
- import { useClientAction } from './client-action';
2
- import { executeClientHandler } from './client-handler';
3
- import { useLazyLink } from './composables/lazy-link';
4
- import { useStonecrop } from './composables/stonecrop';
5
- import { useOperationLog, useUndoRedoShortcuts, withBatch } from './composables/operation-log';
6
- import Doctype from './doctype';
7
- import { DRAFT_RECORD_ID, isDraftRecordId } from './draft';
8
- import { FieldTriggerEngine, getGlobalTriggerEngine, markOperationIrreversible, registerGlobalAction, registerTransitionAction, setFieldRollback, triggerTransition, } from './field-triggers';
9
- import plugin from './plugins';
10
- import Registry from './registry';
11
- import { Stonecrop } from './stonecrop';
12
- import { HST, createHST } from './stores/hst';
13
- import { useOperationLogStore } from './stores/operation-log';
14
- import { useValidationStore } from './stores/validation';
15
- import { SchemaValidator, createValidator, validateSchema } from './schema-validator';
16
- import { ValidationSeverity } from './types/schema-validator';
17
- // Export enum as value (enums need runtime export, not just type)
18
- export { ValidationSeverity };
19
- export { Doctype, Registry, Stonecrop,
20
- // Unsaved-record identity, shared with the desktop shell
21
- DRAFT_RECORD_ID, isDraftRecordId, useLazyLink, useStonecrop,
22
- // clientHandler executor
23
- executeClientHandler,
24
- // The one blessed write path, shared by every Vue host
25
- useClientAction,
26
- // HST exports for advanced usage
27
- HST, createHST,
28
- // Field trigger system exports
29
- FieldTriggerEngine, getGlobalTriggerEngine, registerGlobalAction, registerTransitionAction, setFieldRollback, triggerTransition, markOperationIrreversible,
30
- // Schema validator exports
31
- SchemaValidator, createValidator, validateSchema,
32
- // Operation log exports
33
- useOperationLog, useOperationLogStore, useUndoRedoShortcuts, withBatch,
34
- // Field-validation store
35
- useValidationStore,
36
- // Utility functions
37
- };
38
- // Default export is the Vue plugin
39
- export default plugin;
@@ -1,35 +0,0 @@
1
- import { type Plugin } from 'vue';
2
- /**
3
- * Stonecrop Vue plugin
4
- * @param app - The Vue app instance
5
- * @param options - The plugin options
6
- * @example
7
- * ```ts
8
- * import { createApp } from 'vue'
9
- * import Stonecrop from '@stonecrop/stonecrop'
10
- * import { StonecropClient } from '@stonecrop/graphql-client'
11
- * import router from './router'
12
- *
13
- * const client = new StonecropClient({ endpoint: '/graphql' })
14
- *
15
- * const app = createApp(App)
16
- * app.use(Stonecrop, {
17
- * router,
18
- * client,
19
- * getMeta: async (routeContext) => {
20
- * // routeContext contains: { path, segments }
21
- * // use the client to fetch doctype meta
22
- * return client.getMeta({ doctype: routeContext.segments[0] })
23
- * },
24
- * autoInitializeRouter: true,
25
- * onRouterInitialized: async (registry, stonecrop) => {
26
- * // your custom initialization logic here
27
- * }
28
- * })
29
- * app.mount('#app')
30
- * ```
31
- * @public
32
- */
33
- declare const plugin: Plugin;
34
- export default plugin;
35
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,KAAK,MAAM,EAAY,MAAM,KAAK,CAAA;AA2BhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,QAAA,MAAM,MAAM,EAAE,MAoDb,CAAA;AAED,eAAe,MAAM,CAAA"}