@stonecrop/stonecrop 0.4.37 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +92 -3
- package/dist/src/composable.d.ts +74 -8
- package/dist/src/composable.d.ts.map +1 -1
- package/dist/src/composable.js +348 -0
- package/dist/src/composables/operation-log.d.ts +136 -0
- package/dist/src/composables/operation-log.d.ts.map +1 -0
- package/dist/src/composables/operation-log.js +221 -0
- package/dist/src/doctype.d.ts +9 -1
- package/dist/src/doctype.d.ts.map +1 -1
- package/dist/{doctype.js → src/doctype.js} +9 -3
- package/dist/src/field-triggers.d.ts +178 -0
- package/dist/src/field-triggers.d.ts.map +1 -0
- package/dist/src/field-triggers.js +564 -0
- package/dist/src/index.d.ts +12 -4
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +18 -0
- package/dist/src/plugins/index.d.ts +11 -13
- package/dist/src/plugins/index.d.ts.map +1 -1
- package/dist/src/plugins/index.js +90 -0
- package/dist/src/registry.d.ts +9 -3
- package/dist/src/registry.d.ts.map +1 -1
- package/dist/{registry.js → src/registry.js} +14 -1
- package/dist/src/stonecrop.d.ts +350 -114
- package/dist/src/stonecrop.d.ts.map +1 -1
- package/dist/src/stonecrop.js +251 -0
- package/dist/src/stores/hst.d.ts +157 -0
- package/dist/src/stores/hst.d.ts.map +1 -0
- package/dist/src/stores/hst.js +483 -0
- package/dist/src/stores/index.d.ts +5 -1
- package/dist/src/stores/index.d.ts.map +1 -1
- package/dist/{stores → src/stores}/index.js +4 -1
- package/dist/src/stores/operation-log.d.ts +268 -0
- package/dist/src/stores/operation-log.d.ts.map +1 -0
- package/dist/src/stores/operation-log.js +571 -0
- package/dist/src/types/field-triggers.d.ts +186 -0
- package/dist/src/types/field-triggers.d.ts.map +1 -0
- package/dist/src/types/field-triggers.js +4 -0
- package/dist/src/types/index.d.ts +13 -2
- package/dist/src/types/index.d.ts.map +1 -1
- package/dist/src/types/index.js +4 -0
- package/dist/src/types/operation-log.d.ts +165 -0
- package/dist/src/types/operation-log.d.ts.map +1 -0
- package/dist/src/types/registry.d.ts +11 -0
- package/dist/src/types/registry.d.ts.map +1 -0
- package/dist/src/types/registry.js +0 -0
- package/dist/stonecrop.d.ts +1555 -159
- package/dist/stonecrop.js +1974 -7028
- package/dist/stonecrop.js.map +1 -1
- package/dist/stonecrop.umd.cjs +4 -8
- package/dist/stonecrop.umd.cjs.map +1 -1
- package/dist/tests/setup.d.ts +5 -0
- package/dist/tests/setup.d.ts.map +1 -0
- package/dist/tests/setup.js +15 -0
- package/package.json +5 -4
- package/src/composable.ts +481 -31
- package/src/composables/operation-log.ts +254 -0
- package/src/doctype.ts +9 -3
- package/src/field-triggers.ts +671 -0
- package/src/index.ts +50 -4
- package/src/plugins/index.ts +70 -22
- package/src/registry.ts +18 -3
- package/src/stonecrop.ts +246 -155
- package/src/stores/hst.ts +703 -0
- package/src/stores/index.ts +6 -1
- package/src/stores/operation-log.ts +671 -0
- package/src/types/field-triggers.ts +201 -0
- package/src/types/index.ts +17 -6
- package/src/types/operation-log.ts +205 -0
- package/src/types/registry.ts +10 -0
- package/dist/composable.js +0 -50
- package/dist/index.js +0 -6
- package/dist/plugins/index.js +0 -49
- package/dist/src/stores/data.d.ts +0 -11
- package/dist/src/stores/data.d.ts.map +0 -1
- package/dist/stores/data.js +0 -7
- package/src/stores/data.ts +0 -8
- /package/dist/{exceptions.js → src/exceptions.js} +0 -0
- /package/dist/{types/index.js → src/types/operation-log.js} +0 -0
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import type { HSTNode } from '../stores/hst';
|
|
2
|
+
import type { OperationLogConfig } from '../types/operation-log';
|
|
3
|
+
/**
|
|
4
|
+
* Composable for operation log management
|
|
5
|
+
* Provides easy access to undo/redo functionality and operation history
|
|
6
|
+
*
|
|
7
|
+
* @param config - Optional configuration for the operation log
|
|
8
|
+
* @returns Operation log interface
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const { undo, redo, canUndo, canRedo, operations, configure } = useOperationLog()
|
|
13
|
+
*
|
|
14
|
+
* // Configure the log
|
|
15
|
+
* configure({
|
|
16
|
+
* maxOperations: 50,
|
|
17
|
+
* enableCrossTabSync: true,
|
|
18
|
+
* enablePersistence: true
|
|
19
|
+
* })
|
|
20
|
+
*
|
|
21
|
+
* // Undo/redo
|
|
22
|
+
* await undo(hstStore)
|
|
23
|
+
* await redo(hstStore)
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @public
|
|
27
|
+
*/
|
|
28
|
+
export declare function useOperationLog(config?: Partial<OperationLogConfig>): {
|
|
29
|
+
operations: import("vue").Ref<{
|
|
30
|
+
id: string;
|
|
31
|
+
type: import("..").HSTOperationType;
|
|
32
|
+
path: string;
|
|
33
|
+
fieldname: string;
|
|
34
|
+
beforeValue: any;
|
|
35
|
+
afterValue: any;
|
|
36
|
+
doctype: string;
|
|
37
|
+
recordId?: string | undefined;
|
|
38
|
+
timestamp: Date;
|
|
39
|
+
source?: import("..").OperationSource | undefined;
|
|
40
|
+
reversible: boolean;
|
|
41
|
+
irreversibleReason?: string | undefined;
|
|
42
|
+
transition?: string | undefined;
|
|
43
|
+
currentState?: string | undefined;
|
|
44
|
+
targetState?: string | undefined;
|
|
45
|
+
actionName?: string | undefined;
|
|
46
|
+
actionRecordIds?: string[] | undefined;
|
|
47
|
+
actionResult?: "success" | "failure" | "pending" | undefined;
|
|
48
|
+
actionError?: string | undefined;
|
|
49
|
+
userId?: string | undefined;
|
|
50
|
+
metadata?: Record<string, any> | undefined;
|
|
51
|
+
parentOperationId?: string | undefined;
|
|
52
|
+
childOperationIds?: string[] | undefined;
|
|
53
|
+
}[], import("..").HSTOperation[] | {
|
|
54
|
+
id: string;
|
|
55
|
+
type: import("..").HSTOperationType;
|
|
56
|
+
path: string;
|
|
57
|
+
fieldname: string;
|
|
58
|
+
beforeValue: any;
|
|
59
|
+
afterValue: any;
|
|
60
|
+
doctype: string;
|
|
61
|
+
recordId?: string | undefined;
|
|
62
|
+
timestamp: Date;
|
|
63
|
+
source?: import("..").OperationSource | undefined;
|
|
64
|
+
reversible: boolean;
|
|
65
|
+
irreversibleReason?: string | undefined;
|
|
66
|
+
transition?: string | undefined;
|
|
67
|
+
currentState?: string | undefined;
|
|
68
|
+
targetState?: string | undefined;
|
|
69
|
+
actionName?: string | undefined;
|
|
70
|
+
actionRecordIds?: string[] | undefined;
|
|
71
|
+
actionResult?: "success" | "failure" | "pending" | undefined;
|
|
72
|
+
actionError?: string | undefined;
|
|
73
|
+
userId?: string | undefined;
|
|
74
|
+
metadata?: Record<string, any> | undefined;
|
|
75
|
+
parentOperationId?: string | undefined;
|
|
76
|
+
childOperationIds?: string[] | undefined;
|
|
77
|
+
}[]>;
|
|
78
|
+
currentIndex: import("vue").Ref<number, number>;
|
|
79
|
+
undoRedoState: import("vue").ComputedRef<import("..").UndoRedoState>;
|
|
80
|
+
canUndo: import("vue").ComputedRef<boolean>;
|
|
81
|
+
canRedo: import("vue").ComputedRef<boolean>;
|
|
82
|
+
undoCount: import("vue").ComputedRef<number>;
|
|
83
|
+
redoCount: import("vue").ComputedRef<number>;
|
|
84
|
+
undo: (hstStore: HSTNode) => boolean;
|
|
85
|
+
redo: (hstStore: HSTNode) => boolean;
|
|
86
|
+
startBatch: () => void;
|
|
87
|
+
commitBatch: (description?: string) => string | null;
|
|
88
|
+
cancelBatch: () => void;
|
|
89
|
+
clear: () => void;
|
|
90
|
+
getOperationsFor: (doctype: string, recordId?: string) => import("..").HSTOperation[];
|
|
91
|
+
getSnapshot: () => import("..").OperationLogSnapshot;
|
|
92
|
+
markIrreversible: (operationId: string, reason: string) => void;
|
|
93
|
+
logAction: (doctype: string, actionName: string, recordIds?: string[], result?: "success" | "failure" | "pending", error?: string) => string;
|
|
94
|
+
configure: (options: Partial<OperationLogConfig>) => void;
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* Keyboard shortcut handler for undo/redo
|
|
98
|
+
* Automatically binds Ctrl+Z (undo) and Ctrl+Shift+Z/Ctrl+Y (redo) using VueUse
|
|
99
|
+
*
|
|
100
|
+
* @param hstStore - The HST store to operate on
|
|
101
|
+
* @param enabled - Whether shortcuts are enabled (default: true)
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```typescript
|
|
105
|
+
* import { onMounted } from 'vue'
|
|
106
|
+
*
|
|
107
|
+
* const stonecrop = useStonecrop({ doctype, recordId })
|
|
108
|
+
* useUndoRedoShortcuts(stonecrop.hstStore)
|
|
109
|
+
* ```
|
|
110
|
+
*
|
|
111
|
+
* @public
|
|
112
|
+
*/
|
|
113
|
+
export declare function useUndoRedoShortcuts(hstStore: HSTNode, enabled?: boolean): void;
|
|
114
|
+
/**
|
|
115
|
+
* Batch operation helper
|
|
116
|
+
* Wraps a function execution in a batch operation
|
|
117
|
+
*
|
|
118
|
+
* @param fn - The function to execute within a batch
|
|
119
|
+
* @param description - Optional description for the batch
|
|
120
|
+
* @returns The batch operation ID
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```typescript
|
|
124
|
+
* const { withBatch } = useOperationLog()
|
|
125
|
+
*
|
|
126
|
+
* const batchId = await withBatch(() => {
|
|
127
|
+
* hstStore.set('task.123.title', 'New Title')
|
|
128
|
+
* hstStore.set('task.123.status', 'active')
|
|
129
|
+
* hstStore.set('task.123.priority', 'high')
|
|
130
|
+
* }, 'Update task details')
|
|
131
|
+
* ```
|
|
132
|
+
*
|
|
133
|
+
* @public
|
|
134
|
+
*/
|
|
135
|
+
export declare function withBatch<T>(fn: () => T | Promise<T>, description?: string): Promise<string | null>;
|
|
136
|
+
//# sourceMappingURL=operation-log.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operation-log.d.ts","sourceRoot":"","sources":["../../../src/composables/operation-log.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAE5C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAA;AAEhE;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,eAAe,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,kBAAkB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAiB3C,OAAO,KAAG,OAAO;qBAOjB,OAAO,KAAG,OAAO;;gCAcN,MAAM,KAAG,MAAM,GAAG,IAAI;;;gCAqBtB,MAAM,aAAa,MAAM;;oCAgBrB,MAAM,UAAU,MAAM;yBAcnD,MAAM,cACH,MAAM,cACN,MAAM,EAAE,WACZ,SAAS,GAAG,SAAS,GAAG,SAAS,UACjC,MAAM,KACZ,MAAM;yBAQmB,OAAO,CAAC,kBAAkB,CAAC;EA2BvD;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,OAAO,EAAE,OAAO,UAAO,QAqCrE;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,SAAS,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAYzG"}
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import { useMagicKeys, whenever } from '@vueuse/core';
|
|
2
|
+
import { storeToRefs } from 'pinia';
|
|
3
|
+
import { inject } from 'vue';
|
|
4
|
+
import { useOperationLogStore } from '../stores/operation-log';
|
|
5
|
+
/**
|
|
6
|
+
* Composable for operation log management
|
|
7
|
+
* Provides easy access to undo/redo functionality and operation history
|
|
8
|
+
*
|
|
9
|
+
* @param config - Optional configuration for the operation log
|
|
10
|
+
* @returns Operation log interface
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const { undo, redo, canUndo, canRedo, operations, configure } = useOperationLog()
|
|
15
|
+
*
|
|
16
|
+
* // Configure the log
|
|
17
|
+
* configure({
|
|
18
|
+
* maxOperations: 50,
|
|
19
|
+
* enableCrossTabSync: true,
|
|
20
|
+
* enablePersistence: true
|
|
21
|
+
* })
|
|
22
|
+
*
|
|
23
|
+
* // Undo/redo
|
|
24
|
+
* await undo(hstStore)
|
|
25
|
+
* await redo(hstStore)
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @public
|
|
29
|
+
*/
|
|
30
|
+
export function useOperationLog(config) {
|
|
31
|
+
// Try to use the injected store from the Stonecrop plugin first
|
|
32
|
+
// This ensures we use the same Pinia instance as the app
|
|
33
|
+
const injectedStore = inject('$operationLogStore', undefined);
|
|
34
|
+
const store = injectedStore || useOperationLogStore();
|
|
35
|
+
// Apply configuration if provided
|
|
36
|
+
if (config) {
|
|
37
|
+
store.configure(config);
|
|
38
|
+
}
|
|
39
|
+
// Extract reactive state
|
|
40
|
+
const { operations, currentIndex, undoRedoState, canUndo, canRedo, undoCount, redoCount } = storeToRefs(store);
|
|
41
|
+
/**
|
|
42
|
+
* Undo the last operation
|
|
43
|
+
*/
|
|
44
|
+
function undo(hstStore) {
|
|
45
|
+
return store.undo(hstStore);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Redo the next operation
|
|
49
|
+
*/
|
|
50
|
+
function redo(hstStore) {
|
|
51
|
+
return store.redo(hstStore);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Start a batch operation
|
|
55
|
+
*/
|
|
56
|
+
function startBatch() {
|
|
57
|
+
store.startBatch();
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Commit the current batch
|
|
61
|
+
*/
|
|
62
|
+
function commitBatch(description) {
|
|
63
|
+
return store.commitBatch(description);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Cancel the current batch
|
|
67
|
+
*/
|
|
68
|
+
function cancelBatch() {
|
|
69
|
+
store.cancelBatch();
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Clear all operations
|
|
73
|
+
*/
|
|
74
|
+
function clear() {
|
|
75
|
+
store.clear();
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Get operations for a specific doctype/record
|
|
79
|
+
*/
|
|
80
|
+
function getOperationsFor(doctype, recordId) {
|
|
81
|
+
return store.getOperationsFor(doctype, recordId);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Get a snapshot of the operation log
|
|
85
|
+
*/
|
|
86
|
+
function getSnapshot() {
|
|
87
|
+
return store.getSnapshot();
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Mark an operation as irreversible
|
|
91
|
+
* @param operationId - The ID of the operation to mark
|
|
92
|
+
* @param reason - The reason why the operation is irreversible
|
|
93
|
+
*/
|
|
94
|
+
function markIrreversible(operationId, reason) {
|
|
95
|
+
store.markIrreversible(operationId, reason);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Log an action execution (stateless actions like print, email, etc.)
|
|
99
|
+
* @param doctype - The doctype the action was executed on
|
|
100
|
+
* @param actionName - The name of the action that was executed
|
|
101
|
+
* @param recordIds - Optional array of record IDs the action was executed on
|
|
102
|
+
* @param result - The result of the action execution
|
|
103
|
+
* @param error - Optional error message if action failed
|
|
104
|
+
* @returns The operation ID
|
|
105
|
+
*/
|
|
106
|
+
function logAction(doctype, actionName, recordIds, result = 'success', error) {
|
|
107
|
+
return store.logAction(doctype, actionName, recordIds, result, error);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Update configuration
|
|
111
|
+
* @param options - Configuration options to update
|
|
112
|
+
*/
|
|
113
|
+
function configure(options) {
|
|
114
|
+
store.configure(options);
|
|
115
|
+
}
|
|
116
|
+
return {
|
|
117
|
+
// State
|
|
118
|
+
operations,
|
|
119
|
+
currentIndex,
|
|
120
|
+
undoRedoState,
|
|
121
|
+
canUndo,
|
|
122
|
+
canRedo,
|
|
123
|
+
undoCount,
|
|
124
|
+
redoCount,
|
|
125
|
+
// Methods
|
|
126
|
+
undo,
|
|
127
|
+
redo,
|
|
128
|
+
startBatch,
|
|
129
|
+
commitBatch,
|
|
130
|
+
cancelBatch,
|
|
131
|
+
clear,
|
|
132
|
+
getOperationsFor,
|
|
133
|
+
getSnapshot,
|
|
134
|
+
markIrreversible,
|
|
135
|
+
logAction,
|
|
136
|
+
configure,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Keyboard shortcut handler for undo/redo
|
|
141
|
+
* Automatically binds Ctrl+Z (undo) and Ctrl+Shift+Z/Ctrl+Y (redo) using VueUse
|
|
142
|
+
*
|
|
143
|
+
* @param hstStore - The HST store to operate on
|
|
144
|
+
* @param enabled - Whether shortcuts are enabled (default: true)
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* ```typescript
|
|
148
|
+
* import { onMounted } from 'vue'
|
|
149
|
+
*
|
|
150
|
+
* const stonecrop = useStonecrop({ doctype, recordId })
|
|
151
|
+
* useUndoRedoShortcuts(stonecrop.hstStore)
|
|
152
|
+
* ```
|
|
153
|
+
*
|
|
154
|
+
* @public
|
|
155
|
+
*/
|
|
156
|
+
export function useUndoRedoShortcuts(hstStore, enabled = true) {
|
|
157
|
+
if (!enabled)
|
|
158
|
+
return;
|
|
159
|
+
const { undo, redo, canUndo, canRedo } = useOperationLog();
|
|
160
|
+
const keys = useMagicKeys();
|
|
161
|
+
// Undo shortcuts: Ctrl+Z or Cmd+Z (Mac)
|
|
162
|
+
whenever(keys['Ctrl+Z'], () => {
|
|
163
|
+
if (canUndo.value) {
|
|
164
|
+
undo(hstStore);
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
whenever(keys['Meta+Z'], () => {
|
|
168
|
+
if (canUndo.value) {
|
|
169
|
+
undo(hstStore);
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
// Redo shortcuts: Ctrl+Shift+Z, Cmd+Shift+Z (Mac), or Ctrl+Y
|
|
173
|
+
whenever(keys['Ctrl+Shift+Z'], () => {
|
|
174
|
+
if (canRedo.value) {
|
|
175
|
+
redo(hstStore);
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
whenever(keys['Meta+Shift+Z'], () => {
|
|
179
|
+
if (canRedo.value) {
|
|
180
|
+
redo(hstStore);
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
whenever(keys['Ctrl+Y'], () => {
|
|
184
|
+
if (canRedo.value) {
|
|
185
|
+
redo(hstStore);
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Batch operation helper
|
|
191
|
+
* Wraps a function execution in a batch operation
|
|
192
|
+
*
|
|
193
|
+
* @param fn - The function to execute within a batch
|
|
194
|
+
* @param description - Optional description for the batch
|
|
195
|
+
* @returns The batch operation ID
|
|
196
|
+
*
|
|
197
|
+
* @example
|
|
198
|
+
* ```typescript
|
|
199
|
+
* const { withBatch } = useOperationLog()
|
|
200
|
+
*
|
|
201
|
+
* const batchId = await withBatch(() => {
|
|
202
|
+
* hstStore.set('task.123.title', 'New Title')
|
|
203
|
+
* hstStore.set('task.123.status', 'active')
|
|
204
|
+
* hstStore.set('task.123.priority', 'high')
|
|
205
|
+
* }, 'Update task details')
|
|
206
|
+
* ```
|
|
207
|
+
*
|
|
208
|
+
* @public
|
|
209
|
+
*/
|
|
210
|
+
export async function withBatch(fn, description) {
|
|
211
|
+
const { startBatch, commitBatch, cancelBatch } = useOperationLog();
|
|
212
|
+
startBatch();
|
|
213
|
+
try {
|
|
214
|
+
await fn();
|
|
215
|
+
return commitBatch(description);
|
|
216
|
+
}
|
|
217
|
+
catch (error) {
|
|
218
|
+
cancelBatch();
|
|
219
|
+
throw error;
|
|
220
|
+
}
|
|
221
|
+
}
|
package/dist/src/doctype.d.ts
CHANGED
|
@@ -24,7 +24,7 @@ export default class DoctypeMeta {
|
|
|
24
24
|
*/
|
|
25
25
|
readonly workflow: ImmutableDoctype['workflow'];
|
|
26
26
|
/**
|
|
27
|
-
* The doctype actions
|
|
27
|
+
* The doctype actions and field triggers
|
|
28
28
|
* @public
|
|
29
29
|
* @readonly
|
|
30
30
|
*/
|
|
@@ -35,6 +35,14 @@ export default class DoctypeMeta {
|
|
|
35
35
|
* @readonly
|
|
36
36
|
*/
|
|
37
37
|
readonly component?: Component;
|
|
38
|
+
/**
|
|
39
|
+
* Creates a new DoctypeMeta instance
|
|
40
|
+
* @param doctype - The doctype name
|
|
41
|
+
* @param schema - The doctype schema definition
|
|
42
|
+
* @param workflow - The doctype workflow configuration (XState machine)
|
|
43
|
+
* @param actions - The doctype actions and field triggers
|
|
44
|
+
* @param component - Optional Vue component for rendering the doctype
|
|
45
|
+
*/
|
|
38
46
|
constructor(doctype: string, schema: ImmutableDoctype['schema'], workflow: ImmutableDoctype['workflow'], actions: ImmutableDoctype['actions'], component?: Component);
|
|
39
47
|
/**
|
|
40
48
|
* Converts the registered doctype string to a slug (kebab-case). The following conversions are made:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"doctype.d.ts","sourceRoot":"","sources":["../../src/doctype.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,KAAK,CAAA;AAE/B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAE/C;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,WAAW;IAC/B;;;;OAIG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IAExB;;;;OAIG;IACH,QAAQ,CAAC,MAAM,EAAE,gBAAgB,CAAC,QAAQ,CAAC,CAAA;IAE3C;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,EAAE,gBAAgB,CAAC,UAAU,CAAC,CAAA;IAE/C;;;;OAIG;IACH,QAAQ,CAAC,OAAO,EAAE,gBAAgB,CAAC,SAAS,CAAC,CAAA;IAE7C;;;;OAIG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"doctype.d.ts","sourceRoot":"","sources":["../../src/doctype.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,KAAK,CAAA;AAE/B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAE/C;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,WAAW;IAC/B;;;;OAIG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IAExB;;;;OAIG;IACH,QAAQ,CAAC,MAAM,EAAE,gBAAgB,CAAC,QAAQ,CAAC,CAAA;IAE3C;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,EAAE,gBAAgB,CAAC,UAAU,CAAC,CAAA;IAE/C;;;;OAIG;IACH,QAAQ,CAAC,OAAO,EAAE,gBAAgB,CAAC,SAAS,CAAC,CAAA;IAE7C;;;;OAIG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,SAAS,CAAA;IAE9B;;;;;;;OAOG;gBAEF,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,gBAAgB,CAAC,QAAQ,CAAC,EAClC,QAAQ,EAAE,gBAAgB,CAAC,UAAU,CAAC,EACtC,OAAO,EAAE,gBAAgB,CAAC,SAAS,CAAC,EACpC,SAAS,CAAC,EAAE,SAAS;IAStB;;;;;;;;;;;;;;;OAeG;IACH,IAAI,IAAI,WAKP;CACD"}
|
|
@@ -22,7 +22,7 @@ export default class DoctypeMeta {
|
|
|
22
22
|
*/
|
|
23
23
|
workflow;
|
|
24
24
|
/**
|
|
25
|
-
* The doctype actions
|
|
25
|
+
* The doctype actions and field triggers
|
|
26
26
|
* @public
|
|
27
27
|
* @readonly
|
|
28
28
|
*/
|
|
@@ -33,8 +33,14 @@ export default class DoctypeMeta {
|
|
|
33
33
|
* @readonly
|
|
34
34
|
*/
|
|
35
35
|
component;
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
/**
|
|
37
|
+
* Creates a new DoctypeMeta instance
|
|
38
|
+
* @param doctype - The doctype name
|
|
39
|
+
* @param schema - The doctype schema definition
|
|
40
|
+
* @param workflow - The doctype workflow configuration (XState machine)
|
|
41
|
+
* @param actions - The doctype actions and field triggers
|
|
42
|
+
* @param component - Optional Vue component for rendering the doctype
|
|
43
|
+
*/
|
|
38
44
|
constructor(doctype, schema, workflow, actions, component) {
|
|
39
45
|
this.doctype = doctype;
|
|
40
46
|
this.schema = schema;
|
|
@@ -0,0 +1,178 @@
|
|
|
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
|
+
* Register a global XState transition action function
|
|
32
|
+
* @param name - The name of the transition action
|
|
33
|
+
* @param fn - The transition action function
|
|
34
|
+
*/
|
|
35
|
+
registerTransitionAction(name: string, fn: TransitionActionFunction): void;
|
|
36
|
+
/**
|
|
37
|
+
* Configure rollback behavior for a specific field trigger
|
|
38
|
+
* @param doctype - The doctype name
|
|
39
|
+
* @param fieldname - The field name
|
|
40
|
+
* @param enableRollback - Whether to enable rollback
|
|
41
|
+
*/
|
|
42
|
+
setFieldRollback(doctype: string, fieldname: string, enableRollback: boolean): void;
|
|
43
|
+
/**
|
|
44
|
+
* Get rollback configuration for a specific field trigger
|
|
45
|
+
*/
|
|
46
|
+
private getFieldRollback;
|
|
47
|
+
/**
|
|
48
|
+
* Register actions from a doctype - both regular actions and field triggers
|
|
49
|
+
* Separates XState transitions (uppercase) from field triggers (lowercase)
|
|
50
|
+
* @param doctype - The doctype name
|
|
51
|
+
* @param actions - The actions to register (supports Immutable Map, Map, or plain object)
|
|
52
|
+
*/
|
|
53
|
+
registerDoctypeActions(doctype: string, actions: ImmutableMap<string, string[]> | Map<string, string[]> | Record<string, string[]> | undefined): void;
|
|
54
|
+
/**
|
|
55
|
+
* Categorize an action as either a field trigger or XState transition
|
|
56
|
+
* Uses uppercase convention: UPPERCASE = transition, lowercase/mixed = field trigger
|
|
57
|
+
*/
|
|
58
|
+
private categorizeAction;
|
|
59
|
+
/**
|
|
60
|
+
* Determine if a key represents an XState transition
|
|
61
|
+
* Transitions are identified by being all uppercase
|
|
62
|
+
*/
|
|
63
|
+
private isTransitionKey;
|
|
64
|
+
/**
|
|
65
|
+
* Execute field triggers for a changed field
|
|
66
|
+
* @param context - The field change context
|
|
67
|
+
* @param options - Execution options (timeout and enableRollback)
|
|
68
|
+
*/
|
|
69
|
+
executeFieldTriggers(context: FieldChangeContext, options?: {
|
|
70
|
+
timeout?: number;
|
|
71
|
+
enableRollback?: boolean;
|
|
72
|
+
}): Promise<FieldTriggerExecutionResult>;
|
|
73
|
+
/**
|
|
74
|
+
* Execute XState transition actions
|
|
75
|
+
* Similar to field triggers but specifically for FSM state transitions
|
|
76
|
+
* @param context - The transition change context
|
|
77
|
+
* @param options - Execution options (timeout)
|
|
78
|
+
*/
|
|
79
|
+
executeTransitionActions(context: TransitionChangeContext, options?: {
|
|
80
|
+
timeout?: number;
|
|
81
|
+
}): Promise<TransitionExecutionResult[]>;
|
|
82
|
+
/**
|
|
83
|
+
* Find transition actions for a specific doctype and transition
|
|
84
|
+
*/
|
|
85
|
+
private findTransitionActions;
|
|
86
|
+
/**
|
|
87
|
+
* Execute a single transition action by name
|
|
88
|
+
*/
|
|
89
|
+
private executeTransitionAction;
|
|
90
|
+
/**
|
|
91
|
+
* Find field triggers for a specific doctype and field
|
|
92
|
+
* Field triggers are identified by keys that look like field paths (contain dots or match field names)
|
|
93
|
+
*/
|
|
94
|
+
private findFieldTriggers;
|
|
95
|
+
/**
|
|
96
|
+
* Determine if an action key represents a field trigger
|
|
97
|
+
* Field triggers can be:
|
|
98
|
+
* - Exact field name match: "emailAddress"
|
|
99
|
+
* - Wildcard patterns: "emailAddress.*", "*.is_primary"
|
|
100
|
+
* - Nested field paths: "address.street", "contact.email"
|
|
101
|
+
*/
|
|
102
|
+
private isFieldTriggerKey;
|
|
103
|
+
/**
|
|
104
|
+
* Match a field pattern against a field name
|
|
105
|
+
* Supports wildcards (*) for dynamic segments
|
|
106
|
+
*/
|
|
107
|
+
private matchFieldPattern;
|
|
108
|
+
/**
|
|
109
|
+
* Execute a single action by name
|
|
110
|
+
*/
|
|
111
|
+
private executeAction;
|
|
112
|
+
/**
|
|
113
|
+
* Execute a function with timeout
|
|
114
|
+
*/
|
|
115
|
+
private executeWithTimeout;
|
|
116
|
+
/**
|
|
117
|
+
* Capture a snapshot of the record state before executing actions
|
|
118
|
+
* This creates a deep copy of the record data for potential rollback
|
|
119
|
+
*/
|
|
120
|
+
private captureSnapshot;
|
|
121
|
+
/**
|
|
122
|
+
* Restore a previously captured snapshot
|
|
123
|
+
* This reverts the record to its state before actions were executed
|
|
124
|
+
*/
|
|
125
|
+
private restoreSnapshot;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Get or create the global field trigger engine singleton
|
|
129
|
+
* @param options - Optional configuration for the field trigger engine
|
|
130
|
+
* @public
|
|
131
|
+
*/
|
|
132
|
+
export declare function getGlobalTriggerEngine(options?: FieldTriggerOptions): FieldTriggerEngine;
|
|
133
|
+
/**
|
|
134
|
+
* Register a global action function that can be used in field triggers
|
|
135
|
+
* @param name - The name of the action to register
|
|
136
|
+
* @param fn - The action function to execute when the trigger fires
|
|
137
|
+
* @public
|
|
138
|
+
*/
|
|
139
|
+
export declare function registerGlobalAction(name: string, fn: FieldActionFunction): void;
|
|
140
|
+
/**
|
|
141
|
+
* Register a global XState transition action function
|
|
142
|
+
* @param name - The name of the transition action to register
|
|
143
|
+
* @param fn - The transition action function to execute
|
|
144
|
+
* @public
|
|
145
|
+
*/
|
|
146
|
+
export declare function registerTransitionAction(name: string, fn: TransitionActionFunction): void;
|
|
147
|
+
/**
|
|
148
|
+
* Configure rollback behavior for a specific field trigger
|
|
149
|
+
* @param doctype - The doctype name
|
|
150
|
+
* @param fieldname - The field name
|
|
151
|
+
* @param enableRollback - Whether to enable automatic rollback for this field
|
|
152
|
+
* @public
|
|
153
|
+
*/
|
|
154
|
+
export declare function setFieldRollback(doctype: string, fieldname: string, enableRollback: boolean): void;
|
|
155
|
+
/**
|
|
156
|
+
* Manually trigger an XState transition for a specific doctype/record
|
|
157
|
+
* This can be called directly when you need to execute transition actions programmatically
|
|
158
|
+
* @param doctype - The doctype name
|
|
159
|
+
* @param transition - The XState transition name to trigger
|
|
160
|
+
* @param options - Optional configuration for the transition
|
|
161
|
+
* @public
|
|
162
|
+
*/
|
|
163
|
+
export declare function triggerTransition(doctype: string, transition: string, options?: {
|
|
164
|
+
recordId?: string;
|
|
165
|
+
currentState?: string;
|
|
166
|
+
targetState?: string;
|
|
167
|
+
fsmContext?: Record<string, any>;
|
|
168
|
+
path?: string;
|
|
169
|
+
}): Promise<any>;
|
|
170
|
+
/**
|
|
171
|
+
* Mark a specific operation as irreversible.
|
|
172
|
+
* Used to prevent undo of critical operations like publishing or deletion.
|
|
173
|
+
* @param operationId - The ID of the operation to mark as irreversible
|
|
174
|
+
* @param reason - Human-readable reason why the operation cannot be undone
|
|
175
|
+
* @public
|
|
176
|
+
*/
|
|
177
|
+
export declare function markOperationIrreversible(operationId: string | undefined, reason: string): void;
|
|
178
|
+
//# sourceMappingURL=field-triggers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"field-triggers.d.ts","sourceRoot":"","sources":["../../src/field-triggers.ts"],"names":[],"mappings":"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"}
|