@stonecrop/stonecrop 0.10.11 → 0.10.13

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 (58) hide show
  1. package/dist/composables/stonecrop.js +26 -110
  2. package/dist/field-triggers.js +5 -6
  3. package/dist/index.js +9 -6
  4. package/dist/plugins/index.js +4 -1
  5. package/dist/registry.js +62 -61
  6. package/dist/schema-validator.js +1 -13
  7. package/dist/src/composables/stonecrop.d.ts +2 -74
  8. package/dist/src/composables/stonecrop.d.ts.map +1 -1
  9. package/dist/src/doctype.d.ts +1 -27
  10. package/dist/src/doctype.d.ts.map +1 -1
  11. package/dist/src/field-triggers.d.ts.map +1 -1
  12. package/dist/src/index.d.ts +6 -9
  13. package/dist/src/index.d.ts.map +1 -1
  14. package/dist/src/plugins/index.d.ts.map +1 -1
  15. package/dist/src/registry.d.ts +13 -10
  16. package/dist/src/registry.d.ts.map +1 -1
  17. package/dist/src/schema-validator.d.ts +1 -62
  18. package/dist/src/schema-validator.d.ts.map +1 -1
  19. package/dist/src/stonecrop.d.ts +38 -17
  20. package/dist/src/stonecrop.d.ts.map +1 -1
  21. package/dist/src/stores/operation-log.d.ts +1 -1
  22. package/dist/src/types/composable.d.ts +230 -0
  23. package/dist/src/types/composable.d.ts.map +1 -0
  24. package/dist/src/types/doctype.d.ts +57 -0
  25. package/dist/src/types/doctype.d.ts.map +1 -0
  26. package/dist/src/types/index.d.ts +6 -67
  27. package/dist/src/types/index.d.ts.map +1 -1
  28. package/dist/src/types/plugin.d.ts +37 -0
  29. package/dist/src/types/plugin.d.ts.map +1 -0
  30. package/dist/src/types/schema-validator.d.ts +64 -0
  31. package/dist/src/types/schema-validator.d.ts.map +1 -0
  32. package/dist/src/types/stonecrop.d.ts +17 -0
  33. package/dist/src/types/stonecrop.d.ts.map +1 -0
  34. package/dist/stonecrop.css +1 -0
  35. package/dist/stonecrop.d.ts +206 -14
  36. package/dist/stonecrop.js +1751 -1631
  37. package/dist/stonecrop.js.map +1 -1
  38. package/dist/types/composable.js +0 -0
  39. package/dist/types/doctype.js +0 -0
  40. package/dist/types/index.js +7 -2
  41. package/dist/types/plugin.js +0 -0
  42. package/dist/types/schema-validator.js +13 -0
  43. package/dist/types/stonecrop.js +0 -0
  44. package/package.json +4 -4
  45. package/src/composables/stonecrop.ts +34 -218
  46. package/src/doctype.ts +2 -29
  47. package/src/field-triggers.ts +5 -6
  48. package/src/index.ts +12 -19
  49. package/src/plugins/index.ts +4 -1
  50. package/src/registry.ts +61 -66
  51. package/src/schema-validator.ts +3 -66
  52. package/src/stonecrop.ts +148 -17
  53. package/src/types/composable.ts +245 -0
  54. package/src/types/doctype.ts +60 -0
  55. package/src/types/index.ts +7 -74
  56. package/src/types/plugin.ts +38 -0
  57. package/src/types/schema-validator.ts +67 -0
  58. package/src/types/stonecrop.ts +17 -0
@@ -0,0 +1,245 @@
1
+ import { SchemaTypes } from '@stonecrop/aform'
2
+ import type { Ref, ComputedRef } from 'vue'
3
+
4
+ import type Doctype from '../doctype'
5
+ import type { HSTNode } from '../stores/hst'
6
+ import type { HSTOperation, OperationLogConfig, OperationLogSnapshot } from './operation-log'
7
+
8
+ /**
9
+ * Operation Log API - nested object containing all operation log functionality
10
+ * @public
11
+ */
12
+ export type OperationLogAPI = {
13
+ /**
14
+ * List of all recorded operations in the log.
15
+ * Each operation represents a state change that can be undone/redone.
16
+ */
17
+ operations: Ref<HSTOperation[]>
18
+ /**
19
+ * Current position in the operation log.
20
+ * -1 means no operations, 0 means at first operation, etc.
21
+ */
22
+ currentIndex: Ref<number>
23
+ /**
24
+ * Computed snapshot of undo/redo state.
25
+ * Use this for UI indicators (buttons, menu state).
26
+ */
27
+ undoRedoState: ComputedRef<{
28
+ canUndo: boolean
29
+ canRedo: boolean
30
+ undoCount: number
31
+ redoCount: number
32
+ currentIndex: number
33
+ }>
34
+ /**
35
+ * Whether undo is currently available.
36
+ * True when there are operations that can be undone.
37
+ */
38
+ canUndo: ComputedRef<boolean>
39
+ /**
40
+ * Whether redo is currently available.
41
+ * True when there are undone operations that can be redone.
42
+ */
43
+ canRedo: ComputedRef<boolean>
44
+ /**
45
+ * Number of operations available to undo.
46
+ */
47
+ undoCount: ComputedRef<number>
48
+ /**
49
+ * Number of operations available to redo.
50
+ */
51
+ redoCount: ComputedRef<number>
52
+ /**
53
+ * Undo the last operation.
54
+ * @param hstStore - The HST node to apply the inverse operation to
55
+ * @returns True if undo succeeded, false if nothing to undo
56
+ */
57
+ undo: (hstStore: HSTNode) => boolean
58
+ /**
59
+ * Redo the last undone operation.
60
+ * @param hstStore - The HST node to apply the operation to
61
+ * @returns True if redo succeeded, false if nothing to redo
62
+ */
63
+ redo: (hstStore: HSTNode) => boolean
64
+ /**
65
+ * Start batching multiple operations together.
66
+ * Call before a series of changes that should be undone/redone as a unit.
67
+ */
68
+ startBatch: () => void
69
+ /**
70
+ * Commit the current batch of operations.
71
+ * @param description - Optional description for the batch
72
+ * @returns The batch operation ID, or null if no batch in progress
73
+ */
74
+ commitBatch: (description?: string) => string | null
75
+ /**
76
+ * Cancel the current batch without committing.
77
+ * Discards all operations added since startBatch().
78
+ */
79
+ cancelBatch: () => void
80
+ /**
81
+ * Clear all operations from the log.
82
+ * Resets the log to its initial empty state.
83
+ */
84
+ clear: () => void
85
+ /**
86
+ * Get all operations for a specific doctype.
87
+ * @param doctype - The doctype name to filter by
88
+ * @param recordId - Optional record ID to further filter
89
+ * @returns Array of matching operations
90
+ */
91
+ getOperationsFor: (doctype: string, recordId?: string) => HSTOperation[]
92
+ /**
93
+ * Get a serializable snapshot of the operation log.
94
+ * Use for debugging, logging, or state persistence.
95
+ * @returns Snapshot containing operations and current index
96
+ */
97
+ getSnapshot: () => OperationLogSnapshot
98
+ /**
99
+ * Mark an operation as irreversible.
100
+ * Irreversible operations cannot be undone.
101
+ * @param operationId - The operation ID to mark
102
+ * @param reason - Human-readable reason why it cannot be undone
103
+ */
104
+ markIrreversible: (operationId: string, reason: string) => void
105
+ /**
106
+ * Log a custom action (non-HST operation).
107
+ * Use for tracking server calls, external side effects, etc.
108
+ * @param doctype - The doctype this action relates to
109
+ * @param actionName - Name of the action (e.g., 'save', 'submit')
110
+ * @param recordIds - Optional array of affected record IDs
111
+ * @param result - Optional result status
112
+ * @param error - Optional error message if result is 'failure'
113
+ * @returns The logged operation ID
114
+ */
115
+ logAction: (
116
+ doctype: string,
117
+ actionName: string,
118
+ recordIds?: string[],
119
+ result?: 'success' | 'failure' | 'pending',
120
+ error?: string
121
+ ) => string
122
+ /**
123
+ * Configure operation log options.
124
+ * @param options - Partial configuration to merge with existing settings
125
+ */
126
+ configure: (options: Partial<OperationLogConfig>) => void
127
+ }
128
+
129
+ /**
130
+ * Base Stonecrop composable return type - includes operation log functionality
131
+ * @public
132
+ */
133
+ export type BaseStonecropReturn = {
134
+ /**
135
+ * Reactive reference to the Stonecrop singleton instance.
136
+ * Use this to access class methods like `getRecord()`, `addRecord()`, `runAction()`.
137
+ */
138
+ stonecrop: Ref<Stonecrop | undefined>
139
+ /**
140
+ * Operation log API for undo/redo functionality.
141
+ * Use `operationLog.undo()` and `operationLog.redo()` for user-triggered operations.
142
+ * Use `operationLog.startBatch()` / `operationLog.commitBatch()` for grouping operations.
143
+ */
144
+ operationLog: OperationLogAPI
145
+ }
146
+
147
+ /**
148
+ * HST-enabled Stonecrop composable return type
149
+ * @public
150
+ */
151
+ export type HSTStonecropReturn = BaseStonecropReturn & {
152
+ /**
153
+ * Generates a fully-qualified HST path for a field.
154
+ * Use this in nested components to create paths like "customer.123.address".
155
+ * @param fieldname - The field name to append to the path
156
+ * @param recordId - Optional record ID (defaults to current record)
157
+ * @returns The full HST path string
158
+ */
159
+ provideHSTPath: (fieldname: string, recordId?: string) => string
160
+ /**
161
+ * Handles a field value change and updates HST.
162
+ * Call this from form input handlers to persist changes to the store.
163
+ * @param changeData - Object containing path, value, fieldname, and optional recordId
164
+ */
165
+ handleHSTChange: (changeData: HSTChangeData) => void
166
+ /**
167
+ * Reactive reference to the HST node for this doctype/record.
168
+ * Use this to read current form state or subscribe to changes.
169
+ */
170
+ hstStore: Ref<HSTNode | undefined>
171
+ /**
172
+ * Reactive form data bound to HST.
173
+ * Use this as the v-model target for form inputs. Changes sync to hstStore.
174
+ */
175
+ formData: Ref<Record<string, any>>
176
+ /**
177
+ * Resolved schema with nested Doctype fields expanded.
178
+ * Use this to iterate over fields for rendering, excluding nested doctypes handled separately.
179
+ */
180
+ resolvedSchema: Ref<SchemaTypes[]>
181
+ /**
182
+ * Loads or initializes nested doctype data.
183
+ * Use this when rendering a nested form component. Checks HST first, then initializes defaults.
184
+ * @param parentPath - The HST path to check for existing data
185
+ * @param childDoctype - The nested doctype metadata
186
+ * @param recordId - Optional record ID (reserved for future API fetch)
187
+ * @returns The loaded or initialized data object
188
+ */
189
+ loadNestedData: (parentPath: string, childDoctype: Doctype, recordId?: string) => Record<string, any>
190
+ /**
191
+ * Collects a complete record payload with all nested data from HST.
192
+ * Use this before submitting to an API. Recursively includes 1:1 and 1:many nested records.
193
+ * @param doctype - The doctype metadata
194
+ * @param recordId - The record ID to collect
195
+ * @returns The complete record payload ready for API submission
196
+ */
197
+ collectRecordPayload: (doctype: Doctype, recordId: string) => Record<string, any>
198
+ /**
199
+ * Creates a nested context for a child doctype component.
200
+ * Use this in parent components to pass scoped handlers to child components.
201
+ * @param basePath - The parent HST path prefix
202
+ * @param childDoctype - The child doctype metadata
203
+ * @returns Scoped provideHSTPath and handleHSTChange functions
204
+ */
205
+ createNestedContext: (
206
+ basePath: string,
207
+ childDoctype: Doctype
208
+ ) => {
209
+ provideHSTPath: (fieldname: string) => string
210
+ handleHSTChange: (changeData: HSTChangeData) => void
211
+ }
212
+ /**
213
+ * Loading state for async doctype resolution.
214
+ * True while fetching doctype by slug string from registry.
215
+ */
216
+ isLoading: Ref<boolean>
217
+ /**
218
+ * Error state for doctype resolution failures.
219
+ * Set when doctype slug lookup fails.
220
+ */
221
+ error: Ref<Error | null>
222
+ /**
223
+ * Resolved doctype instance.
224
+ * Available immediately if Doctype instance passed, after async resolution if slug string passed.
225
+ */
226
+ resolvedDoctype: Ref<Doctype | undefined>
227
+ }
228
+
229
+ // Import Stonecrop class for the BaseStonecropReturn type (circular reference handled via import)
230
+ import type { Stonecrop } from '../stonecrop'
231
+
232
+ /**
233
+ * HST Change data structure
234
+ * @public
235
+ */
236
+ export type HSTChangeData = {
237
+ /** Full HST path to the changed field */
238
+ path: string
239
+ /** New value for the field */
240
+ value: any
241
+ /** Field name that changed */
242
+ fieldname: string
243
+ /** Optional record ID */
244
+ recordId?: string
245
+ }
@@ -0,0 +1,60 @@
1
+ import type { SchemaTypes } from '@stonecrop/aform'
2
+ import type { WorkflowMeta } from '@stonecrop/schema'
3
+ import { List, Map } from 'immutable'
4
+ import type { AnyStateNodeConfig, UnknownMachineConfig } from 'xstate'
5
+
6
+ /**
7
+ * Immutable Doctype type for Stonecrop instances
8
+ * @public
9
+ */
10
+ export type ImmutableDoctype = {
11
+ readonly schema?: List<SchemaTypes>
12
+ readonly workflow?: UnknownMachineConfig | AnyStateNodeConfig | WorkflowMeta
13
+ readonly actions?: Map<string, string[]>
14
+ }
15
+
16
+ /**
17
+ * Mutable Doctype type for Stonecrop instances
18
+ * @public
19
+ */
20
+ export type MutableDoctype = {
21
+ doctype?: string
22
+ schema?: SchemaTypes[]
23
+ workflow?: UnknownMachineConfig | AnyStateNodeConfig | WorkflowMeta
24
+ actions?: Record<string, string[]>
25
+ }
26
+
27
+ /**
28
+ * Schema type for Stonecrop instances
29
+ * @public
30
+ */
31
+ export type Schema = {
32
+ doctype: string
33
+ schema: List<SchemaTypes>
34
+ }
35
+
36
+ /**
37
+ * Plain object representation of doctype configuration for serialization/API responses.
38
+ * Compatible with the DoctypeMeta type from \@stonecrop/schema.
39
+ * @public
40
+ */
41
+ export type DoctypeConfig = {
42
+ /** Display name of the doctype */
43
+ name: string
44
+ /** URL-friendly slug (kebab-case) */
45
+ slug?: string
46
+ /** Database table name */
47
+ tableName?: string
48
+ /** Field definitions */
49
+ fields?: SchemaTypes[]
50
+ /** Workflow configuration (XState format or simple WorkflowMeta) */
51
+ workflow?: UnknownMachineConfig | WorkflowMeta
52
+ /** Actions and their field triggers */
53
+ actions?: Record<string, string[]>
54
+ /** Parent doctype for inheritance */
55
+ inherits?: string
56
+ /** Doctype to use for list views */
57
+ listDoctype?: string
58
+ /** Parent doctype for child tables */
59
+ parentDoctype?: string
60
+ }
@@ -1,76 +1,9 @@
1
- import type { DataClient, WorkflowMeta } from '@stonecrop/schema'
2
- import type { SchemaTypes } from '@stonecrop/aform'
3
- import { List, Map } from 'immutable'
4
- import type { Component } from 'vue'
5
- import type { Router } from 'vue-router'
6
- import type { AnyStateNodeConfig, UnknownMachineConfig } from 'xstate'
7
-
8
- import type Doctype from '../doctype'
9
- import Registry from '../registry'
10
- import { Stonecrop } from '../stonecrop'
11
- import type { RouteContext } from './registry'
12
-
13
- /**
14
- * Immutable Doctype type for Stonecrop instances
15
- * @public
16
- */
17
- export type ImmutableDoctype = {
18
- readonly schema?: List<SchemaTypes> // TODO: allow schema to be a function
19
- readonly workflow?: UnknownMachineConfig | AnyStateNodeConfig | WorkflowMeta
20
- readonly actions?: Map<string, string[]>
21
- }
22
-
23
- /**
24
- * Mutable Doctype type for Stonecrop instances
25
- * @public
26
- */
27
- export type MutableDoctype = {
28
- doctype?: string
29
- schema?: SchemaTypes[] // TODO: allow schema to be a function
30
- workflow?: UnknownMachineConfig | AnyStateNodeConfig | WorkflowMeta
31
- actions?: Record<string, string[]>
32
- }
33
-
34
- /**
35
- * Schema type for Stonecrop instances
36
- * @public
37
- */
38
- export type Schema = {
39
- doctype: string
40
- schema: List<SchemaTypes>
41
- }
42
-
43
- /**
44
- * Install options for Stonecrop Vue plugin
45
- * @public
46
- */
47
- export type InstallOptions = {
48
- router?: Router
49
- components?: Record<string, Component>
50
- getMeta?: (routeContext: RouteContext) => Doctype | Promise<Doctype>
51
- /**
52
- * Data client for fetching doctype metadata and records.
53
- * Use \@stonecrop/graphql-client's StonecropClient for GraphQL backends,
54
- * or implement DataClient for custom data sources.
55
- *
56
- * Can be set later via `useStonecropRegistry().setClient()` for deferred configuration.
57
- *
58
- * @example
59
- * ```ts
60
- * import { StonecropClient } from '@stonecrop/graphql-client'
61
- *
62
- * const client = new StonecropClient({ endpoint: '/graphql' })
63
- * app.use(StonecropPlugin, { client })
64
- * ```
65
- */
66
- client?: DataClient
67
- /** Automatically run initialization callback after app mounting (default: false) */
68
- autoInitializeRouter?: boolean
69
- /** Callback function called after plugin is ready and mounted */
70
- onRouterInitialized?: (registry: Registry, stonecrop: Stonecrop) => void | Promise<void>
71
- }
72
-
73
- // Re-export types
1
+ // Re-export all type files
2
+ export * from './composable'
3
+ export * from './doctype'
74
4
  export * from './field-triggers'
75
- export * from './registry'
76
5
  export * from './operation-log'
6
+ export * from './plugin'
7
+ export * from './registry'
8
+ export * from './schema-validator'
9
+ export * from './stonecrop'
@@ -0,0 +1,38 @@
1
+ import type { DataClient } from '@stonecrop/schema'
2
+ import type { Component } from 'vue'
3
+ import type { Router } from 'vue-router'
4
+
5
+ import type Doctype from '../doctype'
6
+ import type Registry from '../registry'
7
+ import type { Stonecrop } from '../stonecrop'
8
+ import type { RouteContext } from './registry'
9
+
10
+ /**
11
+ * Install options for Stonecrop Vue plugin
12
+ * @public
13
+ */
14
+ export type InstallOptions = {
15
+ router?: Router
16
+ components?: Record<string, Component>
17
+ getMeta?: (routeContext: RouteContext) => Doctype | Promise<Doctype>
18
+ /**
19
+ * Data client for fetching doctype metadata and records.
20
+ * Use \@stonecrop/graphql-client's StonecropClient for GraphQL backends,
21
+ * or implement DataClient for custom data sources.
22
+ *
23
+ * Can be set later via `useStonecropRegistry().setClient()` for deferred configuration.
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * import { StonecropClient } from '@stonecrop/graphql-client'
28
+ *
29
+ * const client = new StonecropClient({ endpoint: '/graphql' })
30
+ * app.use(StonecropPlugin, { client })
31
+ * ```
32
+ */
33
+ client?: DataClient
34
+ /** Automatically run initialization callback after app mounting (default: false) */
35
+ autoInitializeRouter?: boolean
36
+ /** Callback function called after plugin is ready and mounted */
37
+ onRouterInitialized?: (registry: Registry, stonecrop: Stonecrop) => void | Promise<void>
38
+ }
@@ -0,0 +1,67 @@
1
+ import type Registry from '../registry'
2
+
3
+ /**
4
+ * Validation severity levels
5
+ * @public
6
+ */
7
+ export enum ValidationSeverity {
8
+ /** Blocking error that prevents save */
9
+ ERROR = 'error',
10
+ /** Advisory warning that allows save */
11
+ WARNING = 'warning',
12
+ /** Informational message */
13
+ INFO = 'info',
14
+ }
15
+
16
+ /**
17
+ * Validation issue
18
+ * @public
19
+ */
20
+ export interface ValidationIssue {
21
+ /** Severity level */
22
+ severity: ValidationSeverity
23
+ /** Validation rule that failed */
24
+ rule: string
25
+ /** Human-readable message */
26
+ message: string
27
+ /** Doctype name */
28
+ doctype?: string
29
+ /** Field name if applicable */
30
+ fieldname?: string
31
+ /** Additional context */
32
+ context?: Record<string, unknown>
33
+ }
34
+
35
+ /**
36
+ * Validation result
37
+ * @public
38
+ */
39
+ export interface ValidationResult {
40
+ /** Whether validation passed (no blocking errors) */
41
+ valid: boolean
42
+ /** List of validation issues */
43
+ issues: ValidationIssue[]
44
+ /** Count of errors */
45
+ errorCount: number
46
+ /** Count of warnings */
47
+ warningCount: number
48
+ /** Count of info messages */
49
+ infoCount: number
50
+ }
51
+
52
+ /**
53
+ * Schema validator options
54
+ * @public
55
+ */
56
+ export interface ValidatorOptions {
57
+ /** Registry instance for doctype lookups */
58
+ registry?: Registry
59
+ /** Whether to validate Link field targets */
60
+ validateLinkTargets?: boolean
61
+ /** Whether to validate workflow reachability */
62
+ validateWorkflows?: boolean
63
+ /** Whether to validate action registration */
64
+ validateActions?: boolean
65
+ /** Whether to validate required schema properties */
66
+ validateRequiredProperties?: boolean
67
+ }
@@ -0,0 +1,17 @@
1
+ import type { DataClient } from '@stonecrop/schema'
2
+
3
+ /**
4
+ * Options for constructing a Stonecrop instance directly.
5
+ * When using the Vue plugin, pass these via `InstallOptions` instead.
6
+ * @public
7
+ */
8
+ export interface StonecropOptions {
9
+ /**
10
+ * Data client for fetching doctype metadata and records.
11
+ * Use \@stonecrop/graphql-client's StonecropClient for GraphQL backends,
12
+ * or implement DataClient for custom data sources.
13
+ *
14
+ * Can be set later via `setClient()` for deferred configuration.
15
+ */
16
+ client?: DataClient
17
+ }