@stonecrop/stonecrop 0.31.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,138 +0,0 @@
1
- import { defineStore } from 'pinia'
2
- import { ref, computed } from 'vue'
3
-
4
- import type { TriggerDefinition } from '@stonecrop/schema'
5
- import { executeClientHandler } from '../client-handler'
6
-
7
- /**
8
- * A single validation error contributed by a trigger, displayed on a field.
9
- * @public
10
- */
11
- export interface ValidationError {
12
- /** The trigger that produced this error — the namespace a re-run clears before repopulating */
13
- trigger: string
14
- /** The fieldname the error displays on (the `setError` target, not necessarily a fired field) */
15
- field: string
16
- /** The message to display */
17
- message: string
18
- }
19
-
20
- /**
21
- * Reactive per-field validation error store + the advisory field-validation trigger engine.
22
- *
23
- * Holds the errors produced by field-validation triggers (see `TriggerDefinition` in
24
- * `@stonecrop/schema`) and runs a trigger's `clientHandler` on demand. Errors are **namespaced
25
- * by trigger**: re-running a trigger clears its own prior contributions before repopulating, so a
26
- * corrected value clears its stale error without disturbing other triggers.
27
- *
28
- * The engine is **advisory** and does **no rollback** — an invalid value stays in the record so the
29
- * user can fix it; validity is reported separately via `isValid` (read by the save gate) and
30
- * the per-field messages are surfaced via `errorsByField` / `errorsFor` for display.
31
- *
32
- * @public
33
- */
34
- export const useValidationStore = defineStore('stonecrop-validation', () => {
35
- const errors = ref<ValidationError[]>([])
36
-
37
- /** True when no field currently carries a validation error. */
38
- const isValid = computed(() => errors.value.length === 0)
39
-
40
- /** Errors grouped by field — the shape a renderer consumes (e.g. AForm `:errors`). */
41
- const errorsByField = computed<Record<string, string[]>>(() => {
42
- const map: Record<string, string[]> = {}
43
- for (const e of errors.value) {
44
- if (!map[e.field]) map[e.field] = []
45
- map[e.field].push(e.message)
46
- }
47
- return map
48
- })
49
-
50
- /** Messages currently displayed on `field`. */
51
- function errorsFor(field: string): string[] {
52
- return errors.value.filter(e => e.field === field).map(e => e.message)
53
- }
54
-
55
- /** Record an error contributed by `trigger`, displayed on `field`. */
56
- function setError(trigger: string, field: string, message: string) {
57
- errors.value.push({ trigger, field, message })
58
- }
59
-
60
- /** Remove every error contributed by `trigger` (its namespace). */
61
- function clearTrigger(trigger: string) {
62
- errors.value = errors.value.filter(e => e.trigger !== trigger)
63
- }
64
-
65
- /** Remove every validation error. */
66
- function clearAll() {
67
- errors.value = []
68
- }
69
-
70
- /**
71
- * Run a single trigger against a read-only snapshot of `record`. Clears the trigger's prior
72
- * errors, then executes its `clientHandler` with `{ record, value, setError }`. Fails **open** —
73
- * a throwing validator warns and records nothing, so a broken validator never blocks the user.
74
- */
75
- async function runTrigger(name: string, def: TriggerDefinition, record: Record<string, unknown>, value: unknown) {
76
- clearTrigger(name)
77
- // Shallow-frozen copy: the validator reads siblings but can neither mutate the record nor
78
- // reassign fields (advisory reads only) — and mutation can't leak back to the caller.
79
- const frozen = Object.freeze({ ...record })
80
- const boundSetError = (field: string, message: string) => setError(name, field, message)
81
- try {
82
- await executeClientHandler(def.clientHandler, { record: frozen, value, setError: boundSetError })
83
- } catch (error) {
84
- // Advisory by design: a broken validator must never block save (a bug in one trigger must
85
- // not trap the user, especially in production). It fails OPEN — but a throw is an error in
86
- // the author's code, so surface it loudly (error severity, trigger named) rather than
87
- // silently: a broken validator that just "does nothing" is the real footgun here.
88
- if (typeof console !== 'undefined') {
89
- console.error(
90
- `Validation trigger "${name}" threw and was ignored (advisory — save is not blocked). ` +
91
- `Fix its clientHandler:`,
92
- error
93
- )
94
- }
95
- }
96
- }
97
-
98
- /**
99
- * Run every trigger whose `on` set includes `changedField`, passing that field's current value.
100
- * Call on the edit path (desktop-driven) so editing either bound field re-validates the pair.
101
- */
102
- async function validateField(
103
- triggers: Record<string, TriggerDefinition>,
104
- changedField: string,
105
- record: Record<string, unknown>
106
- ): Promise<void> {
107
- const runs: Promise<void>[] = []
108
- for (const [name, def] of Object.entries(triggers)) {
109
- if (def.on.includes(changedField)) {
110
- runs.push(runTrigger(name, def, record, record[changedField]))
111
- }
112
- }
113
- await Promise.all(runs)
114
- }
115
-
116
- /**
117
- * Run **all** triggers (no fired-field filter) — the authoritative client gate at save-attempt,
118
- * covering triggers whose fields were never edited. `value` is undefined (no single changed field).
119
- */
120
- async function validateRecord(
121
- triggers: Record<string, TriggerDefinition>,
122
- record: Record<string, unknown>
123
- ): Promise<void> {
124
- await Promise.all(Object.entries(triggers).map(([name, def]) => runTrigger(name, def, record, undefined)))
125
- }
126
-
127
- return {
128
- errors,
129
- isValid,
130
- errorsByField,
131
- errorsFor,
132
- setError,
133
- clearTrigger,
134
- clearAll,
135
- validateField,
136
- validateRecord,
137
- }
138
- })
@@ -1,121 +0,0 @@
1
- /**
2
- * Payload emitted with the 'action' event when the user triggers a declared action —
3
- * an FSM transition or a stateless Command.
4
- *
5
- * Defined here rather than in `@stonecrop/desktop` because the shell that *emits* it and the
6
- * runner that *consumes* it now live in different packages, and desktop already depends on this
7
- * one. `@stonecrop/desktop` re-exports it, so a host importing it from there is unaffected.
8
- *
9
- * @public
10
- */
11
- export type ActionEventPayload = {
12
- /** The declared action name (e.g. 'SAVE', 'SUBMIT', 'APPROVE') */
13
- name: string
14
- doctype: string
15
- recordId: string
16
- /** Snapshot of the form data at the time the action was triggered */
17
- data: Record<string, any>
18
- }
19
-
20
- /**
21
- * Result of dispatching an action to its server handler.
22
- * @public
23
- */
24
- export type ActionDispatchResult = { success: boolean; data: unknown; error: string | null }
25
-
26
- /**
27
- * An action that did not complete, described well enough for a host to render it.
28
- *
29
- * An object rather than a bare message on purpose: a notification says *what* failed, and the
30
- * action, doctype and record are all known at the point of failure. It is also the shape that can
31
- * gain a field later without breaking a host that already destructures it.
32
- *
33
- * @public
34
- */
35
- export interface ActionFailure {
36
- /** Human-readable reason — the server's own message where there is one. */
37
- message: string
38
- /** The action that was clicked, not necessarily the one a `clientHandler` dispatched. */
39
- action: string
40
- /** Slug of the doctype the action was raised on. */
41
- doctype: string
42
- /** Record the action was raised against; the `new` route segment for an unsaved record. */
43
- recordId: string
44
- /** The thrown value, present only when the failure was a throw rather than a refused dispatch. */
45
- cause?: unknown
46
- }
47
-
48
- /**
49
- * Everything known about a dispatch at the point the argument array is built.
50
- * @public
51
- */
52
- export interface ActionArgsContext {
53
- /** Slug of the doctype the action was raised on. */
54
- doctype: string
55
- /** The action being dispatched. */
56
- action: string
57
- /** The route's record segment — {@link DRAFT_RECORD_ID} for an unsaved record. */
58
- recordId: string
59
- /** Whether `recordId` is the draft segment rather than a real identity. */
60
- isDraft: boolean
61
- /** The form snapshot being sent. */
62
- data: Record<string, unknown>
63
- /** Extra fields a `clientHandler` passed to `runAction`. */
64
- extra?: Record<string, unknown>
65
- }
66
-
67
- /**
68
- * Where a record ended up after the server settled its identity.
69
- * @public
70
- */
71
- export interface FollowRecordContext {
72
- /** Slug of the doctype the action was raised on. */
73
- doctype: string
74
- /** The identity the server settled on — where the record now lives. */
75
- recordId: string
76
- /** The identity that was dispatched, which is no longer valid. */
77
- previousRecordId: string
78
- }
79
-
80
- /**
81
- * Host overrides for `useClientAction`.
82
- *
83
- * These are the three things that legitimately differ between applications: how your backend wants
84
- * an action's arguments shaped, where the user should end up after a create, and how a failure is
85
- * shown. Everything else is framework behaviour and is deliberately not configurable — in
86
- * particular, resolving a record's identity and keying it into HST stay sealed, because that is
87
- * the rule the adapter re-derives server-side, and every host that re-derived it got it wrong.
88
- *
89
- * @public
90
- */
91
- export interface UseClientActionOptions {
92
- /**
93
- * Called instead of the built-in alert when an action fails. Supply this to route failures into
94
- * the host's own notification system, or pass a no-op to suppress them entirely.
95
- *
96
- * It fully replaces the default, console log included — a host that wants one writes it.
97
- */
98
- onError?: (failure: ActionFailure) => void
99
- /**
100
- * Build the opaque argument array handed to `DataClient.runAction`.
101
- *
102
- * The default is `[{ id, data }]`, omitting `id` entirely for a draft — the envelope every
103
- * in-repo server handler destructures. Supply this when your backend expects another shape —
104
- * positional `[recordId, data]`, for instance. Nothing validates the array, so both ends of
105
- * your own stack have to agree on it.
106
- *
107
- * Whatever you return is sent verbatim. It does not affect how the *result* is stored — that
108
- * is keyed off the returned record's declared identity, not off what was sent.
109
- */
110
- buildArgs?: (context: ActionArgsContext) => unknown[]
111
- /**
112
- * Move the user to where a record ended up when the server settled on a different identity —
113
- * the create case, and any action that rewrites a natural key.
114
- *
115
- * The default is `router.replace('/{doctype}/{recordId}')`. `replace`, not `push`: the route
116
- * being left behind was never a record, so going Back to `/{doctype}/new` would show an empty
117
- * form that creates yet another record. Supply this for a locale prefix, a nested path, or to
118
- * stay put; the store has already been updated either way.
119
- */
120
- followRecord?: (context: FollowRecordContext) => void | Promise<void>
121
- }
@@ -1,288 +0,0 @@
1
- import type { ResolvedField } from '@stonecrop/aform'
2
- import type { Ref, ComputedRef } from 'vue'
3
-
4
- import type Doctype from '../doctype'
5
- import type { HSTNode } from './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<ResolvedField[]>
181
- /**
182
- * Scaffold empty descendant records from defaults for all descendant links.
183
- * @param path - The HST path where initialized data should be stored
184
- * @param doctype - The doctype to initialize
185
- */
186
- initializeNestedData: (path: string, doctype: Doctype) => void
187
-
188
- /**
189
- * Fetch a record and its nested data from the server.
190
- * Stores each field at its own HST path per the field-level convention.
191
- * @param path - The HST path (e.g., "recipe.r1")
192
- * @param doctype - The doctype to fetch
193
- * @param recordId - Record ID to fetch
194
- * @param options - Query options (includeNested to control which links are fetched)
195
- * @throws Error with code "CLIENT_REQUIRED" if no data client is configured
196
- * @throws Error with code "RECORD_NOT_FOUND" if the server returns null
197
- */
198
- fetchNestedData: (
199
- path: string,
200
- doctype: Doctype,
201
- recordId: string,
202
- options?: { includeNested?: boolean | string[] }
203
- ) => Promise<void>
204
- /**
205
- * Collects a complete record payload with all nested data from HST.
206
- * Use this before submitting to an API. Recursively includes 1:1 and 1:many nested records.
207
- * @param doctype - The doctype metadata
208
- * @param recordId - The record ID to collect
209
- * @returns The complete record payload ready for API submission
210
- */
211
- collectRecordPayload: (doctype: Doctype, recordId: string) => Record<string, any>
212
- /**
213
- * Creates a nested context for a descendant doctype component.
214
- * Use this in parent components to pass scoped handlers to child components.
215
- * @param basePath - The parent HST path prefix
216
- * @param descendantDoctype - The descendant doctype metadata
217
- * @returns Scoped provideHSTPath and handleHSTChange functions
218
- */
219
- createNestedContext: (
220
- basePath: string,
221
- descendantDoctype: Doctype
222
- ) => {
223
- provideHSTPath: (fieldname: string) => string
224
- handleHSTChange: (changeData: HSTChangeData) => void
225
- }
226
- /**
227
- * Loading state for async doctype resolution.
228
- * True while fetching doctype by slug string from registry.
229
- */
230
- isLoading: Ref<boolean>
231
- /**
232
- * Error state for doctype resolution failures.
233
- * Set when doctype slug lookup fails.
234
- */
235
- error: Ref<Error | null>
236
- /**
237
- * Resolved doctype instance.
238
- * Available immediately if Doctype instance passed, after async resolution if slug string passed.
239
- */
240
- resolvedDoctype: Ref<Doctype | undefined>
241
- /**
242
- * Computed ref indicating whether workflow actions are ready to run.
243
- * True when all links with blockWorkflows are loaded in HST.
244
- * Use with v-bind:disabled="!isWorkflowReady" on action buttons.
245
- */
246
- isWorkflowReady: ComputedRef<boolean>
247
- /**
248
- * List of link fieldnames that are blocking workflow execution.
249
- * Empty array when isWorkflowReady is true.
250
- */
251
- blockedLinks: ComputedRef<string[]>
252
- }
253
-
254
- // Import Stonecrop class for the BaseStonecropReturn type (circular reference handled via import)
255
- import type { Stonecrop } from '../stonecrop'
256
-
257
- /**
258
- * HST Change data structure
259
- * @public
260
- */
261
- export type HSTChangeData = {
262
- /** Full HST path to the changed field */
263
- path: string
264
- /** New value for the field */
265
- value: any
266
- /** Field name that changed */
267
- fieldname: string
268
- /** Optional record ID */
269
- recordId?: string
270
- }
271
-
272
- /**
273
- * Lazy link state for a single link field.
274
- * Provides reactive state and reload capability for lazy-loaded links.
275
- * @public
276
- */
277
- export type LazyLink = {
278
- /** True while fetching data */
279
- loading: Ref<boolean>
280
- /** True after successful fetch (permanent until reload) */
281
- loaded: Ref<boolean>
282
- /** Error state, if any */
283
- error: Ref<Error | null>
284
- /** Explicitly trigger a fetch for this link */
285
- reload: () => Promise<void>
286
- /** The loaded data from HST, or undefined if not loaded */
287
- data: ComputedRef
288
- }
@@ -1,35 +0,0 @@
1
- import type { DoctypeField, LinkDeclaration, WorkflowMeta } from '@stonecrop/schema'
2
- import { List } from 'immutable'
3
- import type { AnyStateNodeConfig, UnknownMachineConfig } from 'xstate'
4
-
5
- /**
6
- * Immutable Doctype type for Stonecrop instances. App authors should use
7
- * `Doctype.fromObject()` rather than constructing this shape manually.
8
- * @public
9
- */
10
- export type ImmutableDoctype = {
11
- readonly schema?: List<DoctypeField>
12
- readonly workflow?: UnknownMachineConfig | AnyStateNodeConfig | WorkflowMeta
13
- }
14
-
15
- /**
16
- * Plain object representation of doctype configuration for serialization/API responses.
17
- * Extends DoctypeMeta with Stonecrop-specific properties: actions, slug, inherits.
18
- * @public
19
- */
20
- export type DoctypeConfig = {
21
- /** Display name of the doctype */
22
- name: string
23
- /** URL-friendly slug (kebab-case) */
24
- slug?: string
25
- /** Field used when displaying a reference to one of this doctype's records */
26
- displayField?: string
27
- /** Field definitions (a link field is one carrying `doctype`) */
28
- fields?: DoctypeField[]
29
- /** Relationship links to other doctypes */
30
- links?: Record<string, LinkDeclaration>
31
- /** Workflow configuration (XState format or simple WorkflowMeta) */
32
- workflow?: UnknownMachineConfig | WorkflowMeta
33
- /** Ancestor doctype for inheritance */
34
- inherits?: string
35
- }