@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
@@ -1,104 +0,0 @@
1
- import { defineStore } from 'pinia';
2
- import { ref, computed } from 'vue';
3
- import { executeClientHandler } from '../client-handler';
4
- /**
5
- * Reactive per-field validation error store + the advisory field-validation trigger engine.
6
- *
7
- * Holds the errors produced by field-validation triggers (see `TriggerDefinition` in
8
- * `@stonecrop/schema`) and runs a trigger's `clientHandler` on demand. Errors are **namespaced
9
- * by trigger**: re-running a trigger clears its own prior contributions before repopulating, so a
10
- * corrected value clears its stale error without disturbing other triggers.
11
- *
12
- * The engine is **advisory** and does **no rollback** — an invalid value stays in the record so the
13
- * user can fix it; validity is reported separately via `isValid` (read by the save gate) and
14
- * the per-field messages are surfaced via `errorsByField` / `errorsFor` for display.
15
- *
16
- * @public
17
- */
18
- export const useValidationStore = defineStore('stonecrop-validation', () => {
19
- const errors = ref([]);
20
- /** True when no field currently carries a validation error. */
21
- const isValid = computed(() => errors.value.length === 0);
22
- /** Errors grouped by field — the shape a renderer consumes (e.g. AForm `:errors`). */
23
- const errorsByField = computed(() => {
24
- const map = {};
25
- for (const e of errors.value) {
26
- if (!map[e.field])
27
- map[e.field] = [];
28
- map[e.field].push(e.message);
29
- }
30
- return map;
31
- });
32
- /** Messages currently displayed on `field`. */
33
- function errorsFor(field) {
34
- return errors.value.filter(e => e.field === field).map(e => e.message);
35
- }
36
- /** Record an error contributed by `trigger`, displayed on `field`. */
37
- function setError(trigger, field, message) {
38
- errors.value.push({ trigger, field, message });
39
- }
40
- /** Remove every error contributed by `trigger` (its namespace). */
41
- function clearTrigger(trigger) {
42
- errors.value = errors.value.filter(e => e.trigger !== trigger);
43
- }
44
- /** Remove every validation error. */
45
- function clearAll() {
46
- errors.value = [];
47
- }
48
- /**
49
- * Run a single trigger against a read-only snapshot of `record`. Clears the trigger's prior
50
- * errors, then executes its `clientHandler` with `{ record, value, setError }`. Fails **open** —
51
- * a throwing validator warns and records nothing, so a broken validator never blocks the user.
52
- */
53
- async function runTrigger(name, def, record, value) {
54
- clearTrigger(name);
55
- // Shallow-frozen copy: the validator reads siblings but can neither mutate the record nor
56
- // reassign fields (advisory reads only) — and mutation can't leak back to the caller.
57
- const frozen = Object.freeze({ ...record });
58
- const boundSetError = (field, message) => setError(name, field, message);
59
- try {
60
- await executeClientHandler(def.clientHandler, { record: frozen, value, setError: boundSetError });
61
- }
62
- catch (error) {
63
- // Advisory by design: a broken validator must never block save (a bug in one trigger must
64
- // not trap the user, especially in production). It fails OPEN — but a throw is an error in
65
- // the author's code, so surface it loudly (error severity, trigger named) rather than
66
- // silently: a broken validator that just "does nothing" is the real footgun here.
67
- if (typeof console !== 'undefined') {
68
- console.error(`Validation trigger "${name}" threw and was ignored (advisory — save is not blocked). ` +
69
- `Fix its clientHandler:`, error);
70
- }
71
- }
72
- }
73
- /**
74
- * Run every trigger whose `on` set includes `changedField`, passing that field's current value.
75
- * Call on the edit path (desktop-driven) so editing either bound field re-validates the pair.
76
- */
77
- async function validateField(triggers, changedField, record) {
78
- const runs = [];
79
- for (const [name, def] of Object.entries(triggers)) {
80
- if (def.on.includes(changedField)) {
81
- runs.push(runTrigger(name, def, record, record[changedField]));
82
- }
83
- }
84
- await Promise.all(runs);
85
- }
86
- /**
87
- * Run **all** triggers (no fired-field filter) — the authoritative client gate at save-attempt,
88
- * covering triggers whose fields were never edited. `value` is undefined (no single changed field).
89
- */
90
- async function validateRecord(triggers, record) {
91
- await Promise.all(Object.entries(triggers).map(([name, def]) => runTrigger(name, def, record, undefined)));
92
- }
93
- return {
94
- errors,
95
- isValid,
96
- errorsByField,
97
- errorsFor,
98
- setError,
99
- clearTrigger,
100
- clearAll,
101
- validateField,
102
- validateRecord,
103
- };
104
- });
@@ -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
- * Result of dispatching an action to its server handler.
21
- * @public
22
- */
23
- export type ActionDispatchResult = {
24
- success: boolean;
25
- data: unknown;
26
- error: string | null;
27
- };
28
- /**
29
- * An action that did not complete, described well enough for a host to render it.
30
- *
31
- * An object rather than a bare message on purpose: a notification says *what* failed, and the
32
- * action, doctype and record are all known at the point of failure. It is also the shape that can
33
- * gain a field later without breaking a host that already destructures it.
34
- *
35
- * @public
36
- */
37
- export interface ActionFailure {
38
- /** Human-readable reason — the server's own message where there is one. */
39
- message: string;
40
- /** The action that was clicked, not necessarily the one a `clientHandler` dispatched. */
41
- action: string;
42
- /** Slug of the doctype the action was raised on. */
43
- doctype: string;
44
- /** Record the action was raised against; the `new` route segment for an unsaved record. */
45
- recordId: string;
46
- /** The thrown value, present only when the failure was a throw rather than a refused dispatch. */
47
- cause?: unknown;
48
- }
49
- /**
50
- * Everything known about a dispatch at the point the argument array is built.
51
- * @public
52
- */
53
- export interface ActionArgsContext {
54
- /** Slug of the doctype the action was raised on. */
55
- doctype: string;
56
- /** The action being dispatched. */
57
- action: string;
58
- /** The route's record segment — {@link DRAFT_RECORD_ID} for an unsaved record. */
59
- recordId: string;
60
- /** Whether `recordId` is the draft segment rather than a real identity. */
61
- isDraft: boolean;
62
- /** The form snapshot being sent. */
63
- data: Record<string, unknown>;
64
- /** Extra fields a `clientHandler` passed to `runAction`. */
65
- extra?: Record<string, unknown>;
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
- * Host overrides for `useClientAction`.
81
- *
82
- * These are the three things that legitimately differ between applications: how your backend wants
83
- * an action's arguments shaped, where the user should end up after a create, and how a failure is
84
- * shown. Everything else is framework behaviour and is deliberately not configurable — in
85
- * particular, resolving a record's identity and keying it into HST stay sealed, because that is
86
- * the rule the adapter re-derives server-side, and every host that re-derived it got it wrong.
87
- *
88
- * @public
89
- */
90
- export interface UseClientActionOptions {
91
- /**
92
- * Called instead of the built-in alert when an action fails. Supply this to route failures into
93
- * the host's own notification system, or pass a no-op to suppress them entirely.
94
- *
95
- * It fully replaces the default, console log included — a host that wants one writes it.
96
- */
97
- onError?: (failure: ActionFailure) => void;
98
- /**
99
- * Build the opaque argument array handed to `DataClient.runAction`.
100
- *
101
- * The default is `[{ id, data }]`, omitting `id` entirely for a draft — the envelope every
102
- * in-repo server handler destructures. Supply this when your backend expects another shape —
103
- * positional `[recordId, data]`, for instance. Nothing validates the array, so both ends of
104
- * your own stack have to agree on it.
105
- *
106
- * Whatever you return is sent verbatim. It does not affect how the *result* is stored — that
107
- * is keyed off the returned record's declared identity, not off what was sent.
108
- */
109
- buildArgs?: (context: ActionArgsContext) => unknown[];
110
- /**
111
- * Move the user to where a record ended up when the server settled on a different identity —
112
- * the create case, and any action that rewrites a natural key.
113
- *
114
- * The default is `router.replace('/{doctype}/{recordId}')`. `replace`, not `push`: the route
115
- * being left behind was never a record, so going Back to `/{doctype}/new` would show an empty
116
- * form that creates yet another record. Supply this for a locale prefix, a nested path, or to
117
- * stay put; the store has already been updated either way.
118
- */
119
- followRecord?: (context: FollowRecordContext) => void | Promise<void>;
120
- }
121
- //# sourceMappingURL=client-action.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"client-action.d.ts","sourceRoot":"","sources":["../../../src/types/client-action.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAChC,kEAAkE;IAClE,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CA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AAK,IAAI,CAAA;IAC1C;;;;;;;;;;OAUG;IACH,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,iBAAiB,KAAK,OAAO,EAAE,CAAA;IACrD;;;;;;;;OAQG;IACH,YAAY,CAAC,EAAE,CAAC,OAAO,EAAE,mBAAmB,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CACrE"}
File without changes
@@ -1,268 +0,0 @@
1
- import type { ResolvedField } from '@stonecrop/aform';
2
- import type { Ref, ComputedRef } from 'vue';
3
- import type Doctype from '../doctype';
4
- import type { HSTNode } from './hst';
5
- import type { HSTOperation, OperationLogConfig, OperationLogSnapshot } from './operation-log';
6
- /**
7
- * Operation Log API - nested object containing all operation log functionality
8
- * @public
9
- */
10
- export type OperationLogAPI = {
11
- /**
12
- * List of all recorded operations in the log.
13
- * Each operation represents a state change that can be undone/redone.
14
- */
15
- operations: Ref<HSTOperation[]>;
16
- /**
17
- * Current position in the operation log.
18
- * -1 means no operations, 0 means at first operation, etc.
19
- */
20
- currentIndex: Ref<number>;
21
- /**
22
- * Computed snapshot of undo/redo state.
23
- * Use this for UI indicators (buttons, menu state).
24
- */
25
- undoRedoState: ComputedRef<{
26
- canUndo: boolean;
27
- canRedo: boolean;
28
- undoCount: number;
29
- redoCount: number;
30
- currentIndex: number;
31
- }>;
32
- /**
33
- * Whether undo is currently available.
34
- * True when there are operations that can be undone.
35
- */
36
- canUndo: ComputedRef<boolean>;
37
- /**
38
- * Whether redo is currently available.
39
- * True when there are undone operations that can be redone.
40
- */
41
- canRedo: ComputedRef<boolean>;
42
- /**
43
- * Number of operations available to undo.
44
- */
45
- undoCount: ComputedRef<number>;
46
- /**
47
- * Number of operations available to redo.
48
- */
49
- redoCount: ComputedRef<number>;
50
- /**
51
- * Undo the last operation.
52
- * @param hstStore - The HST node to apply the inverse operation to
53
- * @returns True if undo succeeded, false if nothing to undo
54
- */
55
- undo: (hstStore: HSTNode) => boolean;
56
- /**
57
- * Redo the last undone operation.
58
- * @param hstStore - The HST node to apply the operation to
59
- * @returns True if redo succeeded, false if nothing to redo
60
- */
61
- redo: (hstStore: HSTNode) => boolean;
62
- /**
63
- * Start batching multiple operations together.
64
- * Call before a series of changes that should be undone/redone as a unit.
65
- */
66
- startBatch: () => void;
67
- /**
68
- * Commit the current batch of operations.
69
- * @param description - Optional description for the batch
70
- * @returns The batch operation ID, or null if no batch in progress
71
- */
72
- commitBatch: (description?: string) => string | null;
73
- /**
74
- * Cancel the current batch without committing.
75
- * Discards all operations added since startBatch().
76
- */
77
- cancelBatch: () => void;
78
- /**
79
- * Clear all operations from the log.
80
- * Resets the log to its initial empty state.
81
- */
82
- clear: () => void;
83
- /**
84
- * Get all operations for a specific doctype.
85
- * @param doctype - The doctype name to filter by
86
- * @param recordId - Optional record ID to further filter
87
- * @returns Array of matching operations
88
- */
89
- getOperationsFor: (doctype: string, recordId?: string) => HSTOperation[];
90
- /**
91
- * Get a serializable snapshot of the operation log.
92
- * Use for debugging, logging, or state persistence.
93
- * @returns Snapshot containing operations and current index
94
- */
95
- getSnapshot: () => OperationLogSnapshot;
96
- /**
97
- * Mark an operation as irreversible.
98
- * Irreversible operations cannot be undone.
99
- * @param operationId - The operation ID to mark
100
- * @param reason - Human-readable reason why it cannot be undone
101
- */
102
- markIrreversible: (operationId: string, reason: string) => void;
103
- /**
104
- * Log a custom action (non-HST operation).
105
- * Use for tracking server calls, external side effects, etc.
106
- * @param doctype - The doctype this action relates to
107
- * @param actionName - Name of the action (e.g., 'save', 'submit')
108
- * @param recordIds - Optional array of affected record IDs
109
- * @param result - Optional result status
110
- * @param error - Optional error message if result is 'failure'
111
- * @returns The logged operation ID
112
- */
113
- logAction: (doctype: string, actionName: string, recordIds?: string[], result?: 'success' | 'failure' | 'pending', error?: string) => string;
114
- /**
115
- * Configure operation log options.
116
- * @param options - Partial configuration to merge with existing settings
117
- */
118
- configure: (options: Partial<OperationLogConfig>) => void;
119
- };
120
- /**
121
- * Base Stonecrop composable return type - includes operation log functionality
122
- * @public
123
- */
124
- export type BaseStonecropReturn = {
125
- /**
126
- * Reactive reference to the Stonecrop singleton instance.
127
- * Use this to access class methods like `getRecord()`, `addRecord()`, `runAction()`.
128
- */
129
- stonecrop: Ref<Stonecrop | undefined>;
130
- /**
131
- * Operation log API for undo/redo functionality.
132
- * Use `operationLog.undo()` and `operationLog.redo()` for user-triggered operations.
133
- * Use `operationLog.startBatch()` / `operationLog.commitBatch()` for grouping operations.
134
- */
135
- operationLog: OperationLogAPI;
136
- };
137
- /**
138
- * HST-enabled Stonecrop composable return type
139
- * @public
140
- */
141
- export type HSTStonecropReturn = BaseStonecropReturn & {
142
- /**
143
- * Generates a fully-qualified HST path for a field.
144
- * Use this in nested components to create paths like "customer.123.address".
145
- * @param fieldname - The field name to append to the path
146
- * @param recordId - Optional record ID (defaults to current record)
147
- * @returns The full HST path string
148
- */
149
- provideHSTPath: (fieldname: string, recordId?: string) => string;
150
- /**
151
- * Handles a field value change and updates HST.
152
- * Call this from form input handlers to persist changes to the store.
153
- * @param changeData - Object containing path, value, fieldname, and optional recordId
154
- */
155
- handleHSTChange: (changeData: HSTChangeData) => void;
156
- /**
157
- * Reactive reference to the HST node for this doctype/record.
158
- * Use this to read current form state or subscribe to changes.
159
- */
160
- hstStore: Ref<HSTNode | undefined>;
161
- /**
162
- * Reactive form data bound to HST.
163
- * Use this as the v-model target for form inputs. Changes sync to hstStore.
164
- */
165
- formData: Ref<Record<string, any>>;
166
- /**
167
- * Resolved schema with nested Doctype fields expanded.
168
- * Use this to iterate over fields for rendering, excluding nested doctypes handled separately.
169
- */
170
- resolvedSchema: Ref<ResolvedField[]>;
171
- /**
172
- * Scaffold empty descendant records from defaults for all descendant links.
173
- * @param path - The HST path where initialized data should be stored
174
- * @param doctype - The doctype to initialize
175
- */
176
- initializeNestedData: (path: string, doctype: Doctype) => void;
177
- /**
178
- * Fetch a record and its nested data from the server.
179
- * Stores each field at its own HST path per the field-level convention.
180
- * @param path - The HST path (e.g., "recipe.r1")
181
- * @param doctype - The doctype to fetch
182
- * @param recordId - Record ID to fetch
183
- * @param options - Query options (includeNested to control which links are fetched)
184
- * @throws Error with code "CLIENT_REQUIRED" if no data client is configured
185
- * @throws Error with code "RECORD_NOT_FOUND" if the server returns null
186
- */
187
- fetchNestedData: (path: string, doctype: Doctype, recordId: string, options?: {
188
- includeNested?: boolean | string[];
189
- }) => Promise<void>;
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 descendant 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 descendantDoctype - The descendant doctype metadata
203
- * @returns Scoped provideHSTPath and handleHSTChange functions
204
- */
205
- createNestedContext: (basePath: string, descendantDoctype: Doctype) => {
206
- provideHSTPath: (fieldname: string) => string;
207
- handleHSTChange: (changeData: HSTChangeData) => void;
208
- };
209
- /**
210
- * Loading state for async doctype resolution.
211
- * True while fetching doctype by slug string from registry.
212
- */
213
- isLoading: Ref<boolean>;
214
- /**
215
- * Error state for doctype resolution failures.
216
- * Set when doctype slug lookup fails.
217
- */
218
- error: Ref<Error | null>;
219
- /**
220
- * Resolved doctype instance.
221
- * Available immediately if Doctype instance passed, after async resolution if slug string passed.
222
- */
223
- resolvedDoctype: Ref<Doctype | undefined>;
224
- /**
225
- * Computed ref indicating whether workflow actions are ready to run.
226
- * True when all links with blockWorkflows are loaded in HST.
227
- * Use with v-bind:disabled="!isWorkflowReady" on action buttons.
228
- */
229
- isWorkflowReady: ComputedRef<boolean>;
230
- /**
231
- * List of link fieldnames that are blocking workflow execution.
232
- * Empty array when isWorkflowReady is true.
233
- */
234
- blockedLinks: ComputedRef<string[]>;
235
- };
236
- import type { Stonecrop } from '../stonecrop';
237
- /**
238
- * HST Change data structure
239
- * @public
240
- */
241
- export type HSTChangeData = {
242
- /** Full HST path to the changed field */
243
- path: string;
244
- /** New value for the field */
245
- value: any;
246
- /** Field name that changed */
247
- fieldname: string;
248
- /** Optional record ID */
249
- recordId?: string;
250
- };
251
- /**
252
- * Lazy link state for a single link field.
253
- * Provides reactive state and reload capability for lazy-loaded links.
254
- * @public
255
- */
256
- export type LazyLink = {
257
- /** True while fetching data */
258
- loading: Ref<boolean>;
259
- /** True after successful fetch (permanent until reload) */
260
- loaded: Ref<boolean>;
261
- /** Error state, if any */
262
- error: Ref<Error | null>;
263
- /** Explicitly trigger a fetch for this link */
264
- reload: () => Promise<void>;
265
- /** The loaded data from HST, or undefined if not loaded */
266
- data: ComputedRef;
267
- };
268
- //# sourceMappingURL=composable.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"composable.d.ts","sourceRoot":"","sources":["../../../src/types/composable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AACrD,OAAO,KAAK,EAAE,GAAG,EAAE,WAAW,EAAE,MAAM,KAAK,CAAA;AAE3C,OAAO,KAAK,OAAO,MAAM,YAAY,CAAA;AACrC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AACpC,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAA;AAE7F;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG;IAC7B;;;OAGG;IACH,UAAU,EAAE,GAAG,CAAC,YAAY,EAAE,CAAC,CAAA;IAC/B;;;OAGG;IACH,YAAY,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IACzB;;;OAGG;IACH,aAAa,EAAE,WAAW,CAAC;QAC1B,OAAO,EAAE,OAAO,CAAA;QAChB,OAAO,EAAE,OAAO,CAAA;QAChB,SAAS,EAAE,MAAM,CAAA;QACjB,SAA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 +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
- * Immutable Doctype type for Stonecrop instances. App authors should use
6
- * `Doctype.fromObject()` rather than constructing this shape manually.
7
- * @public
8
- */
9
- export type ImmutableDoctype = {
10
- readonly schema?: List<DoctypeField>;
11
- readonly workflow?: UnknownMachineConfig | AnyStateNodeConfig | WorkflowMeta;
12
- };
13
- /**
14
- * Plain object representation of doctype configuration for serialization/API responses.
15
- * Extends DoctypeMeta with Stonecrop-specific properties: actions, slug, inherits.
16
- * @public
17
- */
18
- export type DoctypeConfig = {
19
- /** Display name of the doctype */
20
- name: string;
21
- /** URL-friendly slug (kebab-case) */
22
- slug?: string;
23
- /** Field used when displaying a reference to one of this doctype's records */
24
- displayField?: string;
25
- /** Field definitions (a link field is one carrying `doctype`) */
26
- fields?: DoctypeField[];
27
- /** Relationship links to other doctypes */
28
- links?: Record<string, LinkDeclaration>;
29
- /** Workflow configuration (XState format or simple WorkflowMeta) */
30
- workflow?: UnknownMachineConfig | WorkflowMeta;
31
- /** Ancestor doctype for inheritance */
32
- inherits?: string;
33
- };
34
- //# sourceMappingURL=doctype.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"doctype.d.ts","sourceRoot":"","sources":["../../../src/types/doctype.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AACpF,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,KAAK,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,QAAQ,CAAA;AAEtE;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC9B,QAAQ,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,YAAY,CAAC,CAAA;IACpC,QAAQ,CAAC,QAAQ,CAAC,EAAE,oBAAoB,GAAG,kBAAkB,GAAG,YAAY,CAAA;CAC5E,CAAA;AAED;;;;GAIG;AACH,MAAM,MAAM,aAAa,GAAG;IAC3B,kCAAkC;IAClC,IAAI,EAAE,MAAM,CAAA;IACZ,qCAAqC;IACrC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,8EAA8E;IAC9E,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,iEAAiE;IACjE,MAAM,CAAC,EAAE,YAAY,EAAE,CAAA;IACvB,2CAA2C;IAC3C,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAA;IACvC,oEAAoE;IACpE,QAAQ,CAAC,EAAE,oBAAoB,GAAG,YAAY,CAAA;IAC9C,uCAAuC;IACvC,QAAQ,CAAC,EAAE,MAAM,CAAA;CACjB,CAAA"}
File without changes