@stonecrop/stonecrop 0.31.0 → 0.33.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. package/dist/stonecrop.js +3548 -2740
  2. package/dist/stonecrop.js.map +1 -1
  3. package/dist/tsdoc-metadata.json +1 -1
  4. package/package.json +33 -27
  5. package/dist/src/client-action.d.ts +0 -31
  6. package/dist/src/client-action.d.ts.map +0 -1
  7. package/dist/src/client-action.js +0 -169
  8. package/dist/src/client-handler.d.ts +0 -43
  9. package/dist/src/client-handler.d.ts.map +0 -1
  10. package/dist/src/client-handler.js +0 -42
  11. package/dist/src/composables/lazy-link.d.ts +0 -25
  12. package/dist/src/composables/lazy-link.d.ts.map +0 -1
  13. package/dist/src/composables/lazy-link.js +0 -124
  14. package/dist/src/composables/operation-log.d.ts +0 -136
  15. package/dist/src/composables/operation-log.d.ts.map +0 -1
  16. package/dist/src/composables/operation-log.js +0 -224
  17. package/dist/src/composables/stonecrop.d.ts +0 -37
  18. package/dist/src/composables/stonecrop.d.ts.map +0 -1
  19. package/dist/src/composables/stonecrop.js +0 -433
  20. package/dist/src/doctype.d.ts +0 -243
  21. package/dist/src/doctype.d.ts.map +0 -1
  22. package/dist/src/doctype.js +0 -325
  23. package/dist/src/draft.d.ts +0 -35
  24. package/dist/src/draft.d.ts.map +0 -1
  25. package/dist/src/draft.js +0 -36
  26. package/dist/src/exceptions.d.ts +0 -14
  27. package/dist/src/exceptions.d.ts.map +0 -1
  28. package/dist/src/exceptions.js +0 -16
  29. package/dist/src/field-triggers.d.ts +0 -184
  30. package/dist/src/field-triggers.d.ts.map +0 -1
  31. package/dist/src/field-triggers.js +0 -577
  32. package/dist/src/index.d.ts +0 -25
  33. package/dist/src/index.d.ts.map +0 -1
  34. package/dist/src/index.js +0 -39
  35. package/dist/src/plugins/index.d.ts +0 -35
  36. package/dist/src/plugins/index.d.ts.map +0 -1
  37. package/dist/src/plugins/index.js +0 -98
  38. package/dist/src/registry.d.ts +0 -161
  39. package/dist/src/registry.d.ts.map +0 -1
  40. package/dist/src/registry.js +0 -384
  41. package/dist/src/schema-validator.d.ts +0 -78
  42. package/dist/src/schema-validator.d.ts.map +0 -1
  43. package/dist/src/schema-validator.js +0 -398
  44. package/dist/src/stonecrop.d.ts +0 -539
  45. package/dist/src/stonecrop.d.ts.map +0 -1
  46. package/dist/src/stonecrop.js +0 -610
  47. package/dist/src/stores/hst.d.ts +0 -92
  48. package/dist/src/stores/hst.d.ts.map +0 -1
  49. package/dist/src/stores/hst.js +0 -487
  50. package/dist/src/stores/index.d.ts +0 -9
  51. package/dist/src/stores/index.d.ts.map +0 -1
  52. package/dist/src/stores/index.js +0 -13
  53. package/dist/src/stores/operation-log.d.ts +0 -262
  54. package/dist/src/stores/operation-log.d.ts.map +0 -1
  55. package/dist/src/stores/operation-log.js +0 -571
  56. package/dist/src/stores/validation.d.ts +0 -83
  57. package/dist/src/stores/validation.d.ts.map +0 -1
  58. package/dist/src/stores/validation.js +0 -104
  59. package/dist/src/types/client-action.d.ts +0 -121
  60. package/dist/src/types/client-action.d.ts.map +0 -1
  61. package/dist/src/types/client-action.js +0 -0
  62. package/dist/src/types/composable.d.ts +0 -268
  63. package/dist/src/types/composable.d.ts.map +0 -1
  64. package/dist/src/types/composable.js +0 -0
  65. package/dist/src/types/doctype.d.ts +0 -34
  66. package/dist/src/types/doctype.d.ts.map +0 -1
  67. package/dist/src/types/doctype.js +0 -0
  68. package/dist/src/types/field-triggers.d.ts +0 -186
  69. package/dist/src/types/field-triggers.d.ts.map +0 -1
  70. package/dist/src/types/field-triggers.js +0 -4
  71. package/dist/src/types/hst.d.ts +0 -70
  72. package/dist/src/types/hst.d.ts.map +0 -1
  73. package/dist/src/types/hst.js +0 -0
  74. package/dist/src/types/index.d.ts +0 -11
  75. package/dist/src/types/index.d.ts.map +0 -1
  76. package/dist/src/types/index.js +0 -11
  77. package/dist/src/types/operation-log.d.ts +0 -163
  78. package/dist/src/types/operation-log.d.ts.map +0 -1
  79. package/dist/src/types/operation-log.js +0 -0
  80. package/dist/src/types/plugin.d.ts +0 -37
  81. package/dist/src/types/plugin.d.ts.map +0 -1
  82. package/dist/src/types/plugin.js +0 -0
  83. package/dist/src/types/registry.d.ts +0 -11
  84. package/dist/src/types/registry.d.ts.map +0 -1
  85. package/dist/src/types/registry.js +0 -0
  86. package/dist/src/types/schema-validator.d.ts +0 -66
  87. package/dist/src/types/schema-validator.d.ts.map +0 -1
  88. package/dist/src/types/schema-validator.js +0 -13
  89. package/dist/src/types/stonecrop.d.ts +0 -32
  90. package/dist/src/types/stonecrop.d.ts.map +0 -1
  91. package/dist/src/types/stonecrop.js +0 -0
  92. package/dist/stonecrop.tsbuildinfo +0 -1
  93. package/src/client-action.ts +0 -207
  94. package/src/client-handler.ts +0 -55
  95. package/src/composables/lazy-link.ts +0 -145
  96. package/src/composables/operation-log.ts +0 -257
  97. package/src/composables/stonecrop.ts +0 -556
  98. package/src/doctype.ts +0 -360
  99. package/src/draft.ts +0 -38
  100. package/src/exceptions.ts +0 -16
  101. package/src/field-triggers.ts +0 -686
  102. package/src/index.ts +0 -81
  103. package/src/plugins/index.ts +0 -113
  104. package/src/registry.ts +0 -433
  105. package/src/schema-validator.ts +0 -476
  106. package/src/stonecrop.ts +0 -721
  107. package/src/stores/hst.ts +0 -626
  108. package/src/stores/index.ts +0 -21
  109. package/src/stores/operation-log.ts +0 -675
  110. package/src/stores/validation.ts +0 -138
  111. package/src/types/client-action.ts +0 -121
  112. package/src/types/composable.ts +0 -288
  113. package/src/types/doctype.ts +0 -35
  114. package/src/types/field-triggers.ts +0 -201
  115. package/src/types/hst.ts +0 -77
  116. package/src/types/index.ts +0 -11
  117. package/src/types/operation-log.ts +0 -202
  118. package/src/types/plugin.ts +0 -38
  119. package/src/types/registry.ts +0 -10
  120. package/src/types/schema-validator.ts +0 -69
  121. package/src/types/stonecrop.ts +0 -33
package/src/stores/hst.ts DELETED
@@ -1,626 +0,0 @@
1
- import { getGlobalTriggerEngine } from '../field-triggers'
2
- import { useOperationLogStore } from './operation-log'
3
- import type { FieldChangeContext, TransitionChangeContext } from '../types/field-triggers'
4
- import type { HSTNode } from '../types/hst'
5
-
6
- /**
7
- * Get the operation log store if available
8
- */
9
- function getOperationLogStore() {
10
- try {
11
- return useOperationLogStore()
12
- } catch {
13
- // Operation log is optional
14
- return null
15
- }
16
- }
17
-
18
- // Type definitions for global Registry
19
- interface RegistryGlobal {
20
- Registry?: {
21
- _root?: {
22
- registry: Record<string, any>
23
- }
24
- }
25
- }
26
-
27
- // Interface for Immutable-like objects
28
- interface ImmutableLike {
29
- get(key: string): any
30
- set(key: string, value: any): ImmutableLike
31
- has(key: string): boolean
32
- size?: number
33
- __ownerID?: any
34
- _map?: any
35
- _list?: any
36
- _origin?: any
37
- _capacity?: any
38
- _defaultValues?: any
39
- _tail?: any
40
- _root?: any
41
- }
42
-
43
- // Interface for Vue reactive objects
44
- interface VueReactive {
45
- __v_isReactive: boolean
46
- [key: string]: any
47
- }
48
-
49
- // Interface for Pinia stores
50
- interface PiniaStore {
51
- $state?: Record<string, any>
52
- $patch?: (partial: Record<string, any>) => void
53
- $id?: string
54
- [key: string]: any
55
- }
56
-
57
- // Extend global interfaces
58
- declare global {
59
- interface Window extends RegistryGlobal {}
60
- const global: RegistryGlobal | undefined
61
- }
62
-
63
- /**
64
- * Global HST Manager (Singleton)
65
- * Manages hierarchical state trees and provides access to the global registry.
66
- *
67
- * @public
68
- */
69
- class HST {
70
- private static instance: HST
71
-
72
- /**
73
- * Gets the singleton instance of HST
74
- * @returns The HST singleton instance
75
- */
76
- static getInstance(): HST {
77
- if (!HST.instance) {
78
- HST.instance = new HST()
79
- }
80
- return HST.instance
81
- }
82
-
83
- /**
84
- * Gets the global registry instance
85
- * @returns The global registry object or undefined if not found
86
- */
87
- getRegistry(): any {
88
- // In test environment, try different ways to access Registry
89
- // First, try the global Registry if it exists
90
- if (typeof globalThis !== 'undefined') {
91
- // 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
92
- const globalRegistry = (globalThis as unknown as RegistryGlobal).Registry?._root
93
- if (globalRegistry) {
94
- return globalRegistry
95
- }
96
- }
97
-
98
- // Try to access through window (browser environment)
99
- if (typeof window !== 'undefined') {
100
- const windowRegistry = window.Registry?._root
101
- if (windowRegistry) {
102
- return windowRegistry
103
- }
104
- }
105
-
106
- // Try to access through global (Node environment)
107
- if (typeof global !== 'undefined' && global) {
108
- const nodeRegistry = global.Registry?._root
109
- if (nodeRegistry) {
110
- return nodeRegistry
111
- }
112
- }
113
-
114
- // If we can't find it globally, it might not be set up
115
- // This is expected in test environments where Registry is created locally
116
- return undefined
117
- }
118
-
119
- /**
120
- * Helper method to get doctype metadata from the registry
121
- * @param doctype - The name of the doctype to retrieve metadata for
122
- * @returns The doctype metadata object or undefined if not found
123
- */
124
- getDoctypeMeta(doctype: string) {
125
- const registry = this.getRegistry()
126
- if (registry && typeof registry === 'object' && 'registry' in registry) {
127
- return registry.registry[doctype]
128
- }
129
- return undefined
130
- }
131
- }
132
-
133
- // Enhanced HST Proxy with tree navigation
134
- class HSTProxy implements HSTNode {
135
- private target: any
136
- private ancestorPath: string
137
- private rootNode: HSTNode | null
138
- private doctype: string
139
- private hst: HST
140
-
141
- constructor(target: any, doctype: string, ancestorPath = '', rootNode: HSTNode | null = null) {
142
- this.target = target
143
- this.ancestorPath = ancestorPath
144
- this.rootNode = rootNode || this
145
- this.doctype = doctype
146
- this.hst = HST.getInstance()
147
-
148
- return new Proxy(this, {
149
- get(hst, prop) {
150
- // Return HST methods directly
151
- if (prop in hst) return Reflect.get(hst, prop)
152
-
153
- // Handle property access - return tree nodes for navigation
154
- const path = String(prop)
155
- return hst.getNode(path)
156
- },
157
-
158
- set(hst, prop, value) {
159
- const path = String(prop)
160
- hst.set(path, value)
161
- return true
162
- },
163
- })
164
- }
165
-
166
- get(path: string): any {
167
- return this.resolveValue(path)
168
- }
169
-
170
- // Method to get a tree-wrapped node for navigation
171
- getNode(path: string): HSTNode {
172
- const fullPath = this.resolvePath(path)
173
- const value = this.resolveValue(path)
174
-
175
- // Determine the correct doctype for this node based on the path
176
- const pathSegments = fullPath.split('.')
177
- let nodeDoctype = this.doctype
178
-
179
- // If we're at the root level and this is a StonecropStore, use the first path segment as the doctype
180
- if (this.doctype === 'StonecropStore' && pathSegments.length >= 1) {
181
- nodeDoctype = pathSegments[0]
182
- }
183
-
184
- // Always wrap in HSTProxy for tree navigation
185
- if (typeof value === 'object' && value !== null && !this.isPrimitive(value)) {
186
- return new HSTProxy(value, nodeDoctype, fullPath, this.rootNode)
187
- }
188
-
189
- // For primitives, return a minimal wrapper that throws on tree operations
190
- return new HSTProxy(value, nodeDoctype, fullPath, this.rootNode)
191
- }
192
-
193
- set(path: string, value: any, source: 'user' | 'system' | 'sync' | 'undo' | 'redo' = 'user'): void {
194
- // Get current value for change context
195
- const fullPath = this.resolvePath(path)
196
- if (fullPath === undefined) {
197
- console.warn('HST.set: resolved path is undefined, skipping operation')
198
- return
199
- }
200
- const beforeValue = this.has(path) ? this.get(path) : undefined
201
-
202
- // Log operation if not from undo/redo and store is available
203
- if (source !== 'undo' && source !== 'redo') {
204
- const logStore = getOperationLogStore()
205
- if (logStore && typeof logStore.addOperation === 'function') {
206
- const pathSegments = fullPath.split('.')
207
- const doctype = this.doctype === 'StonecropStore' && pathSegments.length >= 1 ? pathSegments[0] : this.doctype
208
- const recordId = pathSegments.length >= 2 ? pathSegments[1] : undefined
209
- const fieldname = pathSegments.slice(2).join('.') || pathSegments[pathSegments.length - 1]
210
-
211
- // Detect if this is a DELETE operation (setting to undefined when a value existed)
212
- const isDelete = value === undefined && beforeValue !== undefined
213
- const operationType: 'set' | 'delete' = isDelete ? 'delete' : 'set'
214
-
215
- logStore.addOperation(
216
- {
217
- type: operationType,
218
- path: fullPath,
219
- fieldname,
220
- beforeValue,
221
- afterValue: value,
222
- doctype,
223
- recordId,
224
- reversible: true, // Default to reversible, can be changed by field triggers
225
- },
226
- source
227
- )
228
- }
229
- }
230
-
231
- // Update the value
232
- this.updateValue(path, value)
233
-
234
- // Trigger field actions asynchronously (don't block the set operation)
235
- void this.triggerFieldActions(fullPath, beforeValue, value)
236
- }
237
-
238
- has(path: string): boolean {
239
- try {
240
- // Handle empty path case
241
- if (path === '') {
242
- return true // empty path refers to the root object
243
- }
244
-
245
- const segments = this.parsePath(path)
246
- let current = this.target
247
-
248
- for (let i = 0; i < segments.length; i++) {
249
- const segment = segments[i]
250
-
251
- if (current === null || current === undefined) {
252
- return false
253
- }
254
-
255
- // Check if this is the last segment
256
- if (i === segments.length - 1) {
257
- // For the final property, check if it exists
258
- if (this.isImmutable(current)) {
259
- return current.has(segment)
260
- } else if (this.isPiniaStore(current)) {
261
- return (current.$state && segment in current.$state) || segment in current
262
- } else {
263
- return segment in current
264
- }
265
- }
266
-
267
- // Navigate to the next level
268
- current = this.getProperty(current, segment)
269
- }
270
-
271
- return false
272
- } catch {
273
- return false
274
- }
275
- }
276
-
277
- // Tree navigation methods
278
- getAncestor(): HSTNode | null {
279
- if (!this.ancestorPath) return null
280
-
281
- const ancestorSegments = this.ancestorPath.split('.').slice(0, -1)
282
- const ancestorPath = ancestorSegments.join('.')
283
-
284
- if (ancestorPath === '') {
285
- return this.rootNode
286
- }
287
-
288
- // Return a wrapped node, not raw data
289
- return this.rootNode!.getNode(ancestorPath)
290
- }
291
-
292
- getRoot(): HSTNode {
293
- return this.rootNode!
294
- }
295
-
296
- getPath(): string {
297
- return this.ancestorPath
298
- }
299
-
300
- getDepth(): number {
301
- return this.ancestorPath ? this.ancestorPath.split('.').length : 0
302
- }
303
-
304
- getBreadcrumbs(): string[] {
305
- return this.ancestorPath ? this.ancestorPath.split('.') : []
306
- }
307
-
308
- /**
309
- * Trigger an XState transition with optional context data
310
- */
311
- async triggerTransition(
312
- transition: string,
313
- context?: { currentState?: string; targetState?: string; fsmContext?: Record<string, any> }
314
- ): Promise<any> {
315
- const triggerEngine = getGlobalTriggerEngine()
316
-
317
- // Determine doctype and recordId from the current path
318
- const pathSegments = this.ancestorPath.split('.')
319
- let doctype = this.doctype
320
- let recordId: string | undefined
321
-
322
- // If we're at the root level and this is a StonecropStore, use the first path segment as the doctype
323
- if (this.doctype === 'StonecropStore' && pathSegments.length >= 1) {
324
- doctype = pathSegments[0]
325
- }
326
-
327
- // Extract recordId from path if it follows the expected pattern
328
- if (pathSegments.length >= 2) {
329
- recordId = pathSegments[1]
330
- }
331
-
332
- // Build transition context
333
- const transitionContext: TransitionChangeContext = {
334
- path: this.ancestorPath,
335
- fieldname: '', // No specific field for transitions
336
- beforeValue: undefined,
337
- afterValue: undefined,
338
- operation: 'set',
339
- doctype,
340
- recordId,
341
- timestamp: new Date(),
342
- store: this.rootNode || undefined,
343
- transition,
344
- currentState: context?.currentState,
345
- targetState: context?.targetState,
346
- fsmContext: context?.fsmContext,
347
- }
348
-
349
- // Log FSM transition operation
350
- const logStore = getOperationLogStore()
351
- if (logStore && typeof logStore.addOperation === 'function') {
352
- logStore.addOperation(
353
- {
354
- type: 'transition' as const,
355
- path: this.ancestorPath,
356
- fieldname: transition,
357
- beforeValue: context?.currentState,
358
- afterValue: context?.targetState,
359
- doctype,
360
- recordId,
361
- reversible: false, // FSM transitions are generally not reversible
362
- metadata: {
363
- transition,
364
- currentState: context?.currentState,
365
- targetState: context?.targetState,
366
- fsmContext: context?.fsmContext,
367
- },
368
- },
369
- 'user'
370
- )
371
- }
372
-
373
- // Execute transition actions
374
- return await triggerEngine.executeTransitionActions(transitionContext)
375
- }
376
-
377
- // Private helper methods
378
- private resolvePath(path: string): string {
379
- if (path === '') return this.ancestorPath ?? ''
380
- return this.ancestorPath ? `${this.ancestorPath}.${path}` : path
381
- }
382
-
383
- private resolveValue(path: string): any {
384
- // Handle empty path - return the target object
385
- if (path === '') {
386
- return this.target
387
- }
388
-
389
- const segments = this.parsePath(path)
390
- let current = this.target
391
-
392
- for (const segment of segments) {
393
- if (current === null || current === undefined) {
394
- return undefined
395
- }
396
-
397
- current = this.getProperty(current, segment)
398
- }
399
-
400
- return current
401
- }
402
-
403
- private updateValue(path: string, value: any): void {
404
- // Handle empty path case - should throw error
405
- if (path === '') {
406
- throw new Error('Cannot set value on empty path')
407
- }
408
-
409
- const segments = this.parsePath(path)
410
- const lastSegment = segments.pop()!
411
- let current = this.target
412
-
413
- // Navigate to ancestor object
414
- for (const segment of segments) {
415
- current = this.getProperty(current, segment)
416
- if (current === null || current === undefined) {
417
- throw new Error(`Cannot set property on null/undefined path: ${path}`)
418
- }
419
- }
420
-
421
- // Set the final property
422
- this.setProperty(current, lastSegment, value)
423
- }
424
-
425
- private getProperty(obj: any, key: string): any {
426
- // Immutable objects
427
- if (this.isImmutable(obj)) {
428
- return obj.get(key)
429
- }
430
-
431
- // Vue reactive object
432
- if (this.isVueReactive(obj)) {
433
- return obj[key]
434
- }
435
-
436
- // Pinia store
437
- if (this.isPiniaStore(obj)) {
438
- return obj.$state?.[key] ?? obj[key]
439
- }
440
-
441
- // Plain object
442
- return obj[key]
443
- }
444
-
445
- private setProperty(obj: any, key: string, value: any): void {
446
- // Immutable objects
447
- if (this.isImmutable(obj)) {
448
- throw new Error('Cannot directly mutate immutable objects. Use immutable update methods instead.')
449
- }
450
-
451
- // Pinia store
452
- if (this.isPiniaStore(obj)) {
453
- if (obj.$patch) {
454
- obj.$patch({ [key]: value })
455
- } else {
456
- obj[key] = value
457
- }
458
- return
459
- }
460
-
461
- // Vue reactive or plain object
462
- obj[key] = value
463
- }
464
-
465
- private async triggerFieldActions(fullPath: string, beforeValue: any, afterValue: any): Promise<void> {
466
- try {
467
- // Guard against undefined or null fullPath
468
- if (!fullPath || typeof fullPath !== 'string') {
469
- return
470
- }
471
-
472
- // Skip triggering when the value did not actually change
473
- if (Object.is(beforeValue, afterValue)) {
474
- return
475
- }
476
-
477
- const pathSegments = fullPath.split('.')
478
-
479
- // Only trigger field actions for actual field changes (at least 3 levels deep: doctype.recordId.fieldname)
480
- // Skip triggering for doctype-level or record-level changes
481
- if (pathSegments.length < 3) {
482
- return
483
- }
484
-
485
- const triggerEngine = getGlobalTriggerEngine()
486
- const fieldname = pathSegments.slice(2).join('.') || pathSegments[pathSegments.length - 1]
487
-
488
- // Determine the correct doctype for this path using the same logic as getNode()
489
- // The path should be in format: "doctype.recordId.fieldname"
490
- let doctype = this.doctype
491
-
492
- // If we're at the root level and this is a StonecropStore, use the first path segment as the doctype
493
- if (this.doctype === 'StonecropStore' && pathSegments.length >= 1) {
494
- doctype = pathSegments[0]
495
- }
496
-
497
- let recordId: string | undefined
498
-
499
- // Extract recordId from path if it follows the expected pattern
500
- if (pathSegments.length >= 2) {
501
- recordId = pathSegments[1]
502
- }
503
-
504
- const context: FieldChangeContext = {
505
- path: fullPath,
506
- fieldname,
507
- beforeValue,
508
- afterValue,
509
- operation: 'set',
510
- doctype,
511
- recordId,
512
- timestamp: new Date(),
513
- store: this.rootNode || undefined, // Pass the root store for snapshot/rollback capabilities
514
- }
515
-
516
- await triggerEngine.executeFieldTriggers(context)
517
- } catch (error) {
518
- // Silently handle trigger errors to not break the main flow
519
- // In production, you might want to log this error
520
- if (error instanceof Error) {
521
- console.warn('Field trigger error:', error.message)
522
- // Optional: emit an event or call error handler
523
- }
524
- }
525
- }
526
- private isVueReactive(obj: any): obj is VueReactive {
527
- return obj && typeof obj === 'object' && '__v_isReactive' in obj && obj.__v_isReactive === true
528
- }
529
-
530
- private isPiniaStore(obj: any): obj is PiniaStore {
531
- return obj && typeof obj === 'object' && ('$state' in obj || '$patch' in obj || '$id' in obj)
532
- }
533
-
534
- private isImmutable(obj: any): obj is ImmutableLike {
535
- if (!obj || typeof obj !== 'object') {
536
- return false
537
- }
538
-
539
- const hasGetMethod = 'get' in obj && typeof obj.get === 'function'
540
- const hasSetMethod = 'set' in obj && typeof obj.set === 'function'
541
- const hasHasMethod = 'has' in obj && typeof obj.has === 'function'
542
-
543
- const hasImmutableMarkers =
544
- '__ownerID' in obj ||
545
- '_map' in obj ||
546
- '_list' in obj ||
547
- '_origin' in obj ||
548
- '_capacity' in obj ||
549
- '_defaultValues' in obj ||
550
- '_tail' in obj ||
551
- '_root' in obj ||
552
- ('size' in obj && hasGetMethod && hasSetMethod)
553
-
554
- let constructorName: string | undefined
555
- try {
556
- if ('constructor' in obj && obj.constructor && typeof obj.constructor === 'object' && 'name' in obj.constructor) {
557
- // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- obj.constructor.name accessed after 'name' in check; obj is any throughout this method
558
- const nameValue = (obj.constructor as { name: unknown }).name
559
- constructorName = typeof nameValue === 'string' ? nameValue : undefined
560
- }
561
- } catch {
562
- constructorName = undefined
563
- }
564
-
565
- const isImmutableConstructor =
566
- constructorName &&
567
- (constructorName.includes('Map') ||
568
- constructorName.includes('List') ||
569
- constructorName.includes('Set') ||
570
- constructorName.includes('Stack') ||
571
- constructorName.includes('Seq')) &&
572
- (hasGetMethod || hasSetMethod)
573
-
574
- return Boolean(
575
- (hasGetMethod && hasSetMethod && hasHasMethod && hasImmutableMarkers) ||
576
- (hasGetMethod && hasSetMethod && isImmutableConstructor)
577
- )
578
- }
579
-
580
- private isPrimitive(value: any): boolean {
581
- // Don't wrap primitive values, functions, or null/undefined
582
- return (
583
- value === null ||
584
- value === undefined ||
585
- typeof value === 'string' ||
586
- typeof value === 'number' ||
587
- typeof value === 'boolean' ||
588
- typeof value === 'function' ||
589
- typeof value === 'symbol' ||
590
- typeof value === 'bigint'
591
- )
592
- }
593
-
594
- /**
595
- * Parse a path string into segments, handling both dot notation and array bracket notation
596
- * @param path - The path string to parse (e.g., "order.456.line_items[0].product")
597
- * @returns Array of path segments (e.g., ['order', '456', 'line_items', '0', 'product'])
598
- */
599
- private parsePath(path: string): string[] {
600
- if (!path) return []
601
-
602
- // Replace array bracket notation with dot notation
603
- // items[0] → items.0
604
- // items[0][1] → items.0.1
605
- const normalizedPath = path.replace(/\[(\d+)\]/g, '.$1')
606
-
607
- return normalizedPath.split('.').filter(segment => segment.length > 0)
608
- }
609
- }
610
-
611
- /**
612
- * Factory function for HST creation
613
- * Creates a new HSTNode proxy for hierarchical state tree navigation.
614
- *
615
- * @param target - The target object to wrap with HST functionality
616
- * @param doctype - The document type identifier
617
- * @returns A new HSTNode proxy instance
618
- *
619
- * @public
620
- */
621
- function createHST(target: any, doctype: string): HSTNode {
622
- return new HSTProxy(target, doctype, '', null)
623
- }
624
-
625
- // Export everything
626
- export { HSTProxy, HST, createHST, type HSTNode }
@@ -1,21 +0,0 @@
1
- import { createPinia } from 'pinia'
2
- import { PiniaSharedState } from 'pinia-shared-state'
3
-
4
- import { HST } from './hst'
5
-
6
- const hst = HST.getInstance()
7
- const pinia = createPinia()
8
-
9
- // Pass the plugin to your application's pinia plugin
10
- pinia.use(
11
- PiniaSharedState({
12
- enable: true,
13
- initialize: true,
14
- })
15
- )
16
-
17
- export { hst, pinia }
18
- export { useOperationLogStore } from './operation-log'
19
- export { useValidationStore } from './validation'
20
- export type { ValidationError } from './validation'
21
- export type { HSTNode } from './hst'