@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,92 +0,0 @@
1
- import type { HSTNode } from '../types/hst';
2
- interface RegistryGlobal {
3
- Registry?: {
4
- _root?: {
5
- registry: Record<string, any>;
6
- };
7
- };
8
- }
9
- declare global {
10
- interface Window extends RegistryGlobal {
11
- }
12
- const global: RegistryGlobal | undefined;
13
- }
14
- /**
15
- * Global HST Manager (Singleton)
16
- * Manages hierarchical state trees and provides access to the global registry.
17
- *
18
- * @public
19
- */
20
- declare class HST {
21
- private static instance;
22
- /**
23
- * Gets the singleton instance of HST
24
- * @returns The HST singleton instance
25
- */
26
- static getInstance(): HST;
27
- /**
28
- * Gets the global registry instance
29
- * @returns The global registry object or undefined if not found
30
- */
31
- getRegistry(): any;
32
- /**
33
- * Helper method to get doctype metadata from the registry
34
- * @param doctype - The name of the doctype to retrieve metadata for
35
- * @returns The doctype metadata object or undefined if not found
36
- */
37
- getDoctypeMeta(doctype: string): any;
38
- }
39
- declare class HSTProxy implements HSTNode {
40
- private target;
41
- private ancestorPath;
42
- private rootNode;
43
- private doctype;
44
- private hst;
45
- constructor(target: any, doctype: string, ancestorPath?: string, rootNode?: HSTNode | null);
46
- get(path: string): any;
47
- getNode(path: string): HSTNode;
48
- set(path: string, value: any, source?: 'user' | 'system' | 'sync' | 'undo' | 'redo'): void;
49
- has(path: string): boolean;
50
- getAncestor(): HSTNode | null;
51
- getRoot(): HSTNode;
52
- getPath(): string;
53
- getDepth(): number;
54
- getBreadcrumbs(): string[];
55
- /**
56
- * Trigger an XState transition with optional context data
57
- */
58
- triggerTransition(transition: string, context?: {
59
- currentState?: string;
60
- targetState?: string;
61
- fsmContext?: Record<string, any>;
62
- }): Promise<any>;
63
- private resolvePath;
64
- private resolveValue;
65
- private updateValue;
66
- private getProperty;
67
- private setProperty;
68
- private triggerFieldActions;
69
- private isVueReactive;
70
- private isPiniaStore;
71
- private isImmutable;
72
- private isPrimitive;
73
- /**
74
- * Parse a path string into segments, handling both dot notation and array bracket notation
75
- * @param path - The path string to parse (e.g., "order.456.line_items[0].product")
76
- * @returns Array of path segments (e.g., ['order', '456', 'line_items', '0', 'product'])
77
- */
78
- private parsePath;
79
- }
80
- /**
81
- * Factory function for HST creation
82
- * Creates a new HSTNode proxy for hierarchical state tree navigation.
83
- *
84
- * @param target - The target object to wrap with HST functionality
85
- * @param doctype - The document type identifier
86
- * @returns A new HSTNode proxy instance
87
- *
88
- * @public
89
- */
90
- declare function createHST(target: any, doctype: string): HSTNode;
91
- export { HSTProxy, HST, createHST, type HSTNode };
92
- //# sourceMappingURL=hst.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"hst.d.ts","sourceRoot":"","sources":["../../../src/stores/hst.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAe3C,UAAU,cAAc;IACvB,QAAQ,CAAC,EAAE;QACV,KAAK,CAAC,EAAE;YACP,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;SAC7B,CAAA;KACD,CAAA;CACD;AAiCD,OAAO,CAAC,MAAM,CAAC;IACd,UAAU,MAAO,SAAQ,cAAc;KAAG;IAC1C,MAAM,MAAM,EAAE,cAAc,GAAG,SAAS,CAAA;CACxC;AAED;;;;;GAKG;AACH,cAAM,GAAG;IACR,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAK;IAE5B;;;OAGG;IACH,MAAM,CAAC,WAAW,IAAI,GAAG;IAOzB;;;OAGG;IACH,WAAW,IAAI,GAAG;IAgClB;;;;OAIG;IACH,cAAc,CAAC,OAAO,EAAE,MAAM;CAO9B;AAGD,cAAM,QAAS,YAAW,OAAO;IAChC,OAAO,CAAC,MAAM,CAAK;IACnB,OAAO,CAAC,YAAY,CAAQ;IAC5B,OAAO,CAAC,QAAQ,CAAgB;IAChC,OAAO,CAAC,OAAO,CAAQ;IACvB,OAAO,CAAC,GAAG,CAAK;gBAEJ,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,YAAY,SAAK,EAAE,QAAQ,GAAE,OAAO,GAAG,IAAW;IAyB5F,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,GAAG;IAKtB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAsB9B,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,GAAE,MAAM,GAAG,QAAQ,GAAG,MAAM,GAAG,MAAM,GAAG,MAAe,GAAG,IAAI;IA6ClG,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAwC1B,WAAW,IAAI,OAAO,GAAG,IAAI;IAc7B,OAAO,IAAI,OAAO;IAIlB,OAAO,IAAI,MAAM;IAIjB,QAAQ,IAAI,MAAM;IAIlB,cAAc,IAAI,MAAM,EAAE;IAI1B;;OAEG;IACG,iBAAiB,CACtB,UAAU,EAAE,MAAM,EAClB,OAAO,CAAC,EAAE;QAAE,YAAY,CAAC,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;KAAE,GACzF,OAAO,CAAC,GAAG,CAAC;IAgEf,OAAO,CAAC,WAAW;IAKnB,OAAO,CAAC,YAAY;IAoBpB,OAAO,CAAC,WAAW;IAsBnB,OAAO,CAAC,WAAW;IAoBnB,OAAO,CAAC,WAAW;YAoBL,mBAAmB;IA6DjC,OAAO,CAAC,aAAa;IAIrB,OAAO,CAAC,YAAY;IAIpB,OAAO,CAAC,WAAW;IA8CnB,OAAO,CAAC,WAAW;IAcnB;;;;OAIG;IACH,OAAO,CAAC,SAAS;CAUjB;AAED;;;;;;;;;GASG;AACH,iBAAS,SAAS,CAAC,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAExD;AAGD,OAAO,EAAE,QAAQ,EAAE,GAAG,EAAE,SAAS,EAAE,KAAK,OAAO,EAAE,CAAA"}
@@ -1,487 +0,0 @@
1
- import { getGlobalTriggerEngine } from '../field-triggers';
2
- import { useOperationLogStore } from './operation-log';
3
- /**
4
- * Get the operation log store if available
5
- */
6
- function getOperationLogStore() {
7
- try {
8
- return useOperationLogStore();
9
- }
10
- catch {
11
- // Operation log is optional
12
- return null;
13
- }
14
- }
15
- /**
16
- * Global HST Manager (Singleton)
17
- * Manages hierarchical state trees and provides access to the global registry.
18
- *
19
- * @public
20
- */
21
- class HST {
22
- static instance;
23
- /**
24
- * Gets the singleton instance of HST
25
- * @returns The HST singleton instance
26
- */
27
- static getInstance() {
28
- if (!HST.instance) {
29
- HST.instance = new HST();
30
- }
31
- return HST.instance;
32
- }
33
- /**
34
- * Gets the global registry instance
35
- * @returns The global registry object or undefined if not found
36
- */
37
- getRegistry() {
38
- // In test environment, try different ways to access Registry
39
- // First, try the global Registry if it exists
40
- if (typeof globalThis !== 'undefined') {
41
- // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- Window interface extended with RegistryGlobal in declare global above; no other way to access globalThis properties
42
- const globalRegistry = globalThis.Registry?._root;
43
- if (globalRegistry) {
44
- return globalRegistry;
45
- }
46
- }
47
- // Try to access through window (browser environment)
48
- if (typeof window !== 'undefined') {
49
- const windowRegistry = window.Registry?._root;
50
- if (windowRegistry) {
51
- return windowRegistry;
52
- }
53
- }
54
- // Try to access through global (Node environment)
55
- if (typeof global !== 'undefined' && global) {
56
- const nodeRegistry = global.Registry?._root;
57
- if (nodeRegistry) {
58
- return nodeRegistry;
59
- }
60
- }
61
- // If we can't find it globally, it might not be set up
62
- // This is expected in test environments where Registry is created locally
63
- return undefined;
64
- }
65
- /**
66
- * Helper method to get doctype metadata from the registry
67
- * @param doctype - The name of the doctype to retrieve metadata for
68
- * @returns The doctype metadata object or undefined if not found
69
- */
70
- getDoctypeMeta(doctype) {
71
- const registry = this.getRegistry();
72
- if (registry && typeof registry === 'object' && 'registry' in registry) {
73
- return registry.registry[doctype];
74
- }
75
- return undefined;
76
- }
77
- }
78
- // Enhanced HST Proxy with tree navigation
79
- class HSTProxy {
80
- target;
81
- ancestorPath;
82
- rootNode;
83
- doctype;
84
- hst;
85
- constructor(target, doctype, ancestorPath = '', rootNode = null) {
86
- this.target = target;
87
- this.ancestorPath = ancestorPath;
88
- this.rootNode = rootNode || this;
89
- this.doctype = doctype;
90
- this.hst = HST.getInstance();
91
- return new Proxy(this, {
92
- get(hst, prop) {
93
- // Return HST methods directly
94
- if (prop in hst)
95
- return Reflect.get(hst, prop);
96
- // Handle property access - return tree nodes for navigation
97
- const path = String(prop);
98
- return hst.getNode(path);
99
- },
100
- set(hst, prop, value) {
101
- const path = String(prop);
102
- hst.set(path, value);
103
- return true;
104
- },
105
- });
106
- }
107
- get(path) {
108
- return this.resolveValue(path);
109
- }
110
- // Method to get a tree-wrapped node for navigation
111
- getNode(path) {
112
- const fullPath = this.resolvePath(path);
113
- const value = this.resolveValue(path);
114
- // Determine the correct doctype for this node based on the path
115
- const pathSegments = fullPath.split('.');
116
- let nodeDoctype = this.doctype;
117
- // If we're at the root level and this is a StonecropStore, use the first path segment as the doctype
118
- if (this.doctype === 'StonecropStore' && pathSegments.length >= 1) {
119
- nodeDoctype = pathSegments[0];
120
- }
121
- // Always wrap in HSTProxy for tree navigation
122
- if (typeof value === 'object' && value !== null && !this.isPrimitive(value)) {
123
- return new HSTProxy(value, nodeDoctype, fullPath, this.rootNode);
124
- }
125
- // For primitives, return a minimal wrapper that throws on tree operations
126
- return new HSTProxy(value, nodeDoctype, fullPath, this.rootNode);
127
- }
128
- set(path, value, source = 'user') {
129
- // Get current value for change context
130
- const fullPath = this.resolvePath(path);
131
- if (fullPath === undefined) {
132
- console.warn('HST.set: resolved path is undefined, skipping operation');
133
- return;
134
- }
135
- const beforeValue = this.has(path) ? this.get(path) : undefined;
136
- // Log operation if not from undo/redo and store is available
137
- if (source !== 'undo' && source !== 'redo') {
138
- const logStore = getOperationLogStore();
139
- if (logStore && typeof logStore.addOperation === 'function') {
140
- const pathSegments = fullPath.split('.');
141
- const doctype = this.doctype === 'StonecropStore' && pathSegments.length >= 1 ? pathSegments[0] : this.doctype;
142
- const recordId = pathSegments.length >= 2 ? pathSegments[1] : undefined;
143
- const fieldname = pathSegments.slice(2).join('.') || pathSegments[pathSegments.length - 1];
144
- // Detect if this is a DELETE operation (setting to undefined when a value existed)
145
- const isDelete = value === undefined && beforeValue !== undefined;
146
- const operationType = isDelete ? 'delete' : 'set';
147
- logStore.addOperation({
148
- type: operationType,
149
- path: fullPath,
150
- fieldname,
151
- beforeValue,
152
- afterValue: value,
153
- doctype,
154
- recordId,
155
- reversible: true, // Default to reversible, can be changed by field triggers
156
- }, source);
157
- }
158
- }
159
- // Update the value
160
- this.updateValue(path, value);
161
- // Trigger field actions asynchronously (don't block the set operation)
162
- void this.triggerFieldActions(fullPath, beforeValue, value);
163
- }
164
- has(path) {
165
- try {
166
- // Handle empty path case
167
- if (path === '') {
168
- return true; // empty path refers to the root object
169
- }
170
- const segments = this.parsePath(path);
171
- let current = this.target;
172
- for (let i = 0; i < segments.length; i++) {
173
- const segment = segments[i];
174
- if (current === null || current === undefined) {
175
- return false;
176
- }
177
- // Check if this is the last segment
178
- if (i === segments.length - 1) {
179
- // For the final property, check if it exists
180
- if (this.isImmutable(current)) {
181
- return current.has(segment);
182
- }
183
- else if (this.isPiniaStore(current)) {
184
- return (current.$state && segment in current.$state) || segment in current;
185
- }
186
- else {
187
- return segment in current;
188
- }
189
- }
190
- // Navigate to the next level
191
- current = this.getProperty(current, segment);
192
- }
193
- return false;
194
- }
195
- catch {
196
- return false;
197
- }
198
- }
199
- // Tree navigation methods
200
- getAncestor() {
201
- if (!this.ancestorPath)
202
- return null;
203
- const ancestorSegments = this.ancestorPath.split('.').slice(0, -1);
204
- const ancestorPath = ancestorSegments.join('.');
205
- if (ancestorPath === '') {
206
- return this.rootNode;
207
- }
208
- // Return a wrapped node, not raw data
209
- return this.rootNode.getNode(ancestorPath);
210
- }
211
- getRoot() {
212
- return this.rootNode;
213
- }
214
- getPath() {
215
- return this.ancestorPath;
216
- }
217
- getDepth() {
218
- return this.ancestorPath ? this.ancestorPath.split('.').length : 0;
219
- }
220
- getBreadcrumbs() {
221
- return this.ancestorPath ? this.ancestorPath.split('.') : [];
222
- }
223
- /**
224
- * Trigger an XState transition with optional context data
225
- */
226
- async triggerTransition(transition, context) {
227
- const triggerEngine = getGlobalTriggerEngine();
228
- // Determine doctype and recordId from the current path
229
- const pathSegments = this.ancestorPath.split('.');
230
- let doctype = this.doctype;
231
- let recordId;
232
- // If we're at the root level and this is a StonecropStore, use the first path segment as the doctype
233
- if (this.doctype === 'StonecropStore' && pathSegments.length >= 1) {
234
- doctype = pathSegments[0];
235
- }
236
- // Extract recordId from path if it follows the expected pattern
237
- if (pathSegments.length >= 2) {
238
- recordId = pathSegments[1];
239
- }
240
- // Build transition context
241
- const transitionContext = {
242
- path: this.ancestorPath,
243
- fieldname: '', // No specific field for transitions
244
- beforeValue: undefined,
245
- afterValue: undefined,
246
- operation: 'set',
247
- doctype,
248
- recordId,
249
- timestamp: new Date(),
250
- store: this.rootNode || undefined,
251
- transition,
252
- currentState: context?.currentState,
253
- targetState: context?.targetState,
254
- fsmContext: context?.fsmContext,
255
- };
256
- // Log FSM transition operation
257
- const logStore = getOperationLogStore();
258
- if (logStore && typeof logStore.addOperation === 'function') {
259
- logStore.addOperation({
260
- type: 'transition',
261
- path: this.ancestorPath,
262
- fieldname: transition,
263
- beforeValue: context?.currentState,
264
- afterValue: context?.targetState,
265
- doctype,
266
- recordId,
267
- reversible: false, // FSM transitions are generally not reversible
268
- metadata: {
269
- transition,
270
- currentState: context?.currentState,
271
- targetState: context?.targetState,
272
- fsmContext: context?.fsmContext,
273
- },
274
- }, 'user');
275
- }
276
- // Execute transition actions
277
- return await triggerEngine.executeTransitionActions(transitionContext);
278
- }
279
- // Private helper methods
280
- resolvePath(path) {
281
- if (path === '')
282
- return this.ancestorPath ?? '';
283
- return this.ancestorPath ? `${this.ancestorPath}.${path}` : path;
284
- }
285
- resolveValue(path) {
286
- // Handle empty path - return the target object
287
- if (path === '') {
288
- return this.target;
289
- }
290
- const segments = this.parsePath(path);
291
- let current = this.target;
292
- for (const segment of segments) {
293
- if (current === null || current === undefined) {
294
- return undefined;
295
- }
296
- current = this.getProperty(current, segment);
297
- }
298
- return current;
299
- }
300
- updateValue(path, value) {
301
- // Handle empty path case - should throw error
302
- if (path === '') {
303
- throw new Error('Cannot set value on empty path');
304
- }
305
- const segments = this.parsePath(path);
306
- const lastSegment = segments.pop();
307
- let current = this.target;
308
- // Navigate to ancestor object
309
- for (const segment of segments) {
310
- current = this.getProperty(current, segment);
311
- if (current === null || current === undefined) {
312
- throw new Error(`Cannot set property on null/undefined path: ${path}`);
313
- }
314
- }
315
- // Set the final property
316
- this.setProperty(current, lastSegment, value);
317
- }
318
- getProperty(obj, key) {
319
- // Immutable objects
320
- if (this.isImmutable(obj)) {
321
- return obj.get(key);
322
- }
323
- // Vue reactive object
324
- if (this.isVueReactive(obj)) {
325
- return obj[key];
326
- }
327
- // Pinia store
328
- if (this.isPiniaStore(obj)) {
329
- return obj.$state?.[key] ?? obj[key];
330
- }
331
- // Plain object
332
- return obj[key];
333
- }
334
- setProperty(obj, key, value) {
335
- // Immutable objects
336
- if (this.isImmutable(obj)) {
337
- throw new Error('Cannot directly mutate immutable objects. Use immutable update methods instead.');
338
- }
339
- // Pinia store
340
- if (this.isPiniaStore(obj)) {
341
- if (obj.$patch) {
342
- obj.$patch({ [key]: value });
343
- }
344
- else {
345
- obj[key] = value;
346
- }
347
- return;
348
- }
349
- // Vue reactive or plain object
350
- obj[key] = value;
351
- }
352
- async triggerFieldActions(fullPath, beforeValue, afterValue) {
353
- try {
354
- // Guard against undefined or null fullPath
355
- if (!fullPath || typeof fullPath !== 'string') {
356
- return;
357
- }
358
- // Skip triggering when the value did not actually change
359
- if (Object.is(beforeValue, afterValue)) {
360
- return;
361
- }
362
- const pathSegments = fullPath.split('.');
363
- // Only trigger field actions for actual field changes (at least 3 levels deep: doctype.recordId.fieldname)
364
- // Skip triggering for doctype-level or record-level changes
365
- if (pathSegments.length < 3) {
366
- return;
367
- }
368
- const triggerEngine = getGlobalTriggerEngine();
369
- const fieldname = pathSegments.slice(2).join('.') || pathSegments[pathSegments.length - 1];
370
- // Determine the correct doctype for this path using the same logic as getNode()
371
- // The path should be in format: "doctype.recordId.fieldname"
372
- let doctype = this.doctype;
373
- // If we're at the root level and this is a StonecropStore, use the first path segment as the doctype
374
- if (this.doctype === 'StonecropStore' && pathSegments.length >= 1) {
375
- doctype = pathSegments[0];
376
- }
377
- let recordId;
378
- // Extract recordId from path if it follows the expected pattern
379
- if (pathSegments.length >= 2) {
380
- recordId = pathSegments[1];
381
- }
382
- const context = {
383
- path: fullPath,
384
- fieldname,
385
- beforeValue,
386
- afterValue,
387
- operation: 'set',
388
- doctype,
389
- recordId,
390
- timestamp: new Date(),
391
- store: this.rootNode || undefined, // Pass the root store for snapshot/rollback capabilities
392
- };
393
- await triggerEngine.executeFieldTriggers(context);
394
- }
395
- catch (error) {
396
- // Silently handle trigger errors to not break the main flow
397
- // In production, you might want to log this error
398
- if (error instanceof Error) {
399
- console.warn('Field trigger error:', error.message);
400
- // Optional: emit an event or call error handler
401
- }
402
- }
403
- }
404
- isVueReactive(obj) {
405
- return obj && typeof obj === 'object' && '__v_isReactive' in obj && obj.__v_isReactive === true;
406
- }
407
- isPiniaStore(obj) {
408
- return obj && typeof obj === 'object' && ('$state' in obj || '$patch' in obj || '$id' in obj);
409
- }
410
- isImmutable(obj) {
411
- if (!obj || typeof obj !== 'object') {
412
- return false;
413
- }
414
- const hasGetMethod = 'get' in obj && typeof obj.get === 'function';
415
- const hasSetMethod = 'set' in obj && typeof obj.set === 'function';
416
- const hasHasMethod = 'has' in obj && typeof obj.has === 'function';
417
- const hasImmutableMarkers = '__ownerID' in obj ||
418
- '_map' in obj ||
419
- '_list' in obj ||
420
- '_origin' in obj ||
421
- '_capacity' in obj ||
422
- '_defaultValues' in obj ||
423
- '_tail' in obj ||
424
- '_root' in obj ||
425
- ('size' in obj && hasGetMethod && hasSetMethod);
426
- let constructorName;
427
- try {
428
- if ('constructor' in obj && obj.constructor && typeof obj.constructor === 'object' && 'name' in obj.constructor) {
429
- // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- obj.constructor.name accessed after 'name' in check; obj is any throughout this method
430
- const nameValue = obj.constructor.name;
431
- constructorName = typeof nameValue === 'string' ? nameValue : undefined;
432
- }
433
- }
434
- catch {
435
- constructorName = undefined;
436
- }
437
- const isImmutableConstructor = constructorName &&
438
- (constructorName.includes('Map') ||
439
- constructorName.includes('List') ||
440
- constructorName.includes('Set') ||
441
- constructorName.includes('Stack') ||
442
- constructorName.includes('Seq')) &&
443
- (hasGetMethod || hasSetMethod);
444
- return Boolean((hasGetMethod && hasSetMethod && hasHasMethod && hasImmutableMarkers) ||
445
- (hasGetMethod && hasSetMethod && isImmutableConstructor));
446
- }
447
- isPrimitive(value) {
448
- // Don't wrap primitive values, functions, or null/undefined
449
- return (value === null ||
450
- value === undefined ||
451
- typeof value === 'string' ||
452
- typeof value === 'number' ||
453
- typeof value === 'boolean' ||
454
- typeof value === 'function' ||
455
- typeof value === 'symbol' ||
456
- typeof value === 'bigint');
457
- }
458
- /**
459
- * Parse a path string into segments, handling both dot notation and array bracket notation
460
- * @param path - The path string to parse (e.g., "order.456.line_items[0].product")
461
- * @returns Array of path segments (e.g., ['order', '456', 'line_items', '0', 'product'])
462
- */
463
- parsePath(path) {
464
- if (!path)
465
- return [];
466
- // Replace array bracket notation with dot notation
467
- // items[0] → items.0
468
- // items[0][1] → items.0.1
469
- const normalizedPath = path.replace(/\[(\d+)\]/g, '.$1');
470
- return normalizedPath.split('.').filter(segment => segment.length > 0);
471
- }
472
- }
473
- /**
474
- * Factory function for HST creation
475
- * Creates a new HSTNode proxy for hierarchical state tree navigation.
476
- *
477
- * @param target - The target object to wrap with HST functionality
478
- * @param doctype - The document type identifier
479
- * @returns A new HSTNode proxy instance
480
- *
481
- * @public
482
- */
483
- function createHST(target, doctype) {
484
- return new HSTProxy(target, doctype, '', null);
485
- }
486
- // Export everything
487
- export { HSTProxy, HST, createHST };
@@ -1,9 +0,0 @@
1
- import { HST } from './hst';
2
- declare const hst: HST;
3
- declare const pinia: import("pinia").Pinia;
4
- export { hst, pinia };
5
- export { useOperationLogStore } from './operation-log';
6
- export { useValidationStore } from './validation';
7
- export type { ValidationError } from './validation';
8
- export type { HSTNode } from './hst';
9
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/stores/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAA;AAE3B,QAAA,MAAM,GAAG,KAAoB,CAAA;AAC7B,QAAA,MAAM,KAAK,uBAAgB,CAAA;AAU3B,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,CAAA;AACrB,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAA;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AACjD,YAAY,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AACnD,YAAY,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA"}
@@ -1,13 +0,0 @@
1
- import { createPinia } from 'pinia';
2
- import { PiniaSharedState } from 'pinia-shared-state';
3
- import { HST } from './hst';
4
- const hst = HST.getInstance();
5
- const pinia = createPinia();
6
- // Pass the plugin to your application's pinia plugin
7
- pinia.use(PiniaSharedState({
8
- enable: true,
9
- initialize: true,
10
- }));
11
- export { hst, pinia };
12
- export { useOperationLogStore } from './operation-log';
13
- export { useValidationStore } from './validation';