@stonecrop/stonecrop 0.30.0 → 0.32.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. package/dist/stonecrop.js +3548 -2740
  2. package/dist/stonecrop.js.map +1 -1
  3. package/dist/tsdoc-metadata.json +1 -1
  4. package/package.json +33 -27
  5. package/dist/src/client-action.d.ts +0 -31
  6. package/dist/src/client-action.d.ts.map +0 -1
  7. package/dist/src/client-action.js +0 -169
  8. package/dist/src/client-handler.d.ts +0 -43
  9. package/dist/src/client-handler.d.ts.map +0 -1
  10. package/dist/src/client-handler.js +0 -42
  11. package/dist/src/composables/lazy-link.d.ts +0 -25
  12. package/dist/src/composables/lazy-link.d.ts.map +0 -1
  13. package/dist/src/composables/lazy-link.js +0 -124
  14. package/dist/src/composables/operation-log.d.ts +0 -136
  15. package/dist/src/composables/operation-log.d.ts.map +0 -1
  16. package/dist/src/composables/operation-log.js +0 -224
  17. package/dist/src/composables/stonecrop.d.ts +0 -37
  18. package/dist/src/composables/stonecrop.d.ts.map +0 -1
  19. package/dist/src/composables/stonecrop.js +0 -433
  20. package/dist/src/doctype.d.ts +0 -243
  21. package/dist/src/doctype.d.ts.map +0 -1
  22. package/dist/src/doctype.js +0 -325
  23. package/dist/src/draft.d.ts +0 -35
  24. package/dist/src/draft.d.ts.map +0 -1
  25. package/dist/src/draft.js +0 -36
  26. package/dist/src/exceptions.d.ts +0 -14
  27. package/dist/src/exceptions.d.ts.map +0 -1
  28. package/dist/src/exceptions.js +0 -16
  29. package/dist/src/field-triggers.d.ts +0 -184
  30. package/dist/src/field-triggers.d.ts.map +0 -1
  31. package/dist/src/field-triggers.js +0 -577
  32. package/dist/src/index.d.ts +0 -25
  33. package/dist/src/index.d.ts.map +0 -1
  34. package/dist/src/index.js +0 -39
  35. package/dist/src/plugins/index.d.ts +0 -35
  36. package/dist/src/plugins/index.d.ts.map +0 -1
  37. package/dist/src/plugins/index.js +0 -98
  38. package/dist/src/registry.d.ts +0 -161
  39. package/dist/src/registry.d.ts.map +0 -1
  40. package/dist/src/registry.js +0 -384
  41. package/dist/src/schema-validator.d.ts +0 -78
  42. package/dist/src/schema-validator.d.ts.map +0 -1
  43. package/dist/src/schema-validator.js +0 -398
  44. package/dist/src/stonecrop.d.ts +0 -539
  45. package/dist/src/stonecrop.d.ts.map +0 -1
  46. package/dist/src/stonecrop.js +0 -610
  47. package/dist/src/stores/hst.d.ts +0 -92
  48. package/dist/src/stores/hst.d.ts.map +0 -1
  49. package/dist/src/stores/hst.js +0 -487
  50. package/dist/src/stores/index.d.ts +0 -9
  51. package/dist/src/stores/index.d.ts.map +0 -1
  52. package/dist/src/stores/index.js +0 -13
  53. package/dist/src/stores/operation-log.d.ts +0 -262
  54. package/dist/src/stores/operation-log.d.ts.map +0 -1
  55. package/dist/src/stores/operation-log.js +0 -571
  56. package/dist/src/stores/validation.d.ts +0 -83
  57. package/dist/src/stores/validation.d.ts.map +0 -1
  58. package/dist/src/stores/validation.js +0 -104
  59. package/dist/src/types/client-action.d.ts +0 -121
  60. package/dist/src/types/client-action.d.ts.map +0 -1
  61. package/dist/src/types/client-action.js +0 -0
  62. package/dist/src/types/composable.d.ts +0 -268
  63. package/dist/src/types/composable.d.ts.map +0 -1
  64. package/dist/src/types/composable.js +0 -0
  65. package/dist/src/types/doctype.d.ts +0 -34
  66. package/dist/src/types/doctype.d.ts.map +0 -1
  67. package/dist/src/types/doctype.js +0 -0
  68. package/dist/src/types/field-triggers.d.ts +0 -186
  69. package/dist/src/types/field-triggers.d.ts.map +0 -1
  70. package/dist/src/types/field-triggers.js +0 -4
  71. package/dist/src/types/hst.d.ts +0 -70
  72. package/dist/src/types/hst.d.ts.map +0 -1
  73. package/dist/src/types/hst.js +0 -0
  74. package/dist/src/types/index.d.ts +0 -11
  75. package/dist/src/types/index.d.ts.map +0 -1
  76. package/dist/src/types/index.js +0 -11
  77. package/dist/src/types/operation-log.d.ts +0 -163
  78. package/dist/src/types/operation-log.d.ts.map +0 -1
  79. package/dist/src/types/operation-log.js +0 -0
  80. package/dist/src/types/plugin.d.ts +0 -37
  81. package/dist/src/types/plugin.d.ts.map +0 -1
  82. package/dist/src/types/plugin.js +0 -0
  83. package/dist/src/types/registry.d.ts +0 -11
  84. package/dist/src/types/registry.d.ts.map +0 -1
  85. package/dist/src/types/registry.js +0 -0
  86. package/dist/src/types/schema-validator.d.ts +0 -66
  87. package/dist/src/types/schema-validator.d.ts.map +0 -1
  88. package/dist/src/types/schema-validator.js +0 -13
  89. package/dist/src/types/stonecrop.d.ts +0 -32
  90. package/dist/src/types/stonecrop.d.ts.map +0 -1
  91. package/dist/src/types/stonecrop.js +0 -0
  92. package/dist/stonecrop.tsbuildinfo +0 -1
  93. package/src/client-action.ts +0 -207
  94. package/src/client-handler.ts +0 -55
  95. package/src/composables/lazy-link.ts +0 -145
  96. package/src/composables/operation-log.ts +0 -257
  97. package/src/composables/stonecrop.ts +0 -556
  98. package/src/doctype.ts +0 -360
  99. package/src/draft.ts +0 -38
  100. package/src/exceptions.ts +0 -16
  101. package/src/field-triggers.ts +0 -686
  102. package/src/index.ts +0 -81
  103. package/src/plugins/index.ts +0 -113
  104. package/src/registry.ts +0 -433
  105. package/src/schema-validator.ts +0 -476
  106. package/src/stonecrop.ts +0 -721
  107. package/src/stores/hst.ts +0 -626
  108. package/src/stores/index.ts +0 -21
  109. package/src/stores/operation-log.ts +0 -675
  110. package/src/stores/validation.ts +0 -138
  111. package/src/types/client-action.ts +0 -121
  112. package/src/types/composable.ts +0 -288
  113. package/src/types/doctype.ts +0 -35
  114. package/src/types/field-triggers.ts +0 -201
  115. package/src/types/hst.ts +0 -77
  116. package/src/types/index.ts +0 -11
  117. package/src/types/operation-log.ts +0 -202
  118. package/src/types/plugin.ts +0 -38
  119. package/src/types/registry.ts +0 -10
  120. package/src/types/schema-validator.ts +0 -69
  121. package/src/types/stonecrop.ts +0 -33
package/src/doctype.ts DELETED
@@ -1,360 +0,0 @@
1
- import type { DoctypeField, LinkDeclaration, TriggerDefinition, WorkflowMeta } from '@stonecrop/schema'
2
- import { getRecordIdentity, getRecordIdField, isActionAllowedInState, normalizeFieldKind } from '@stonecrop/schema'
3
- import { List } from 'immutable'
4
- import { Component } from 'vue'
5
-
6
- import type { DoctypeConfig, ImmutableDoctype } from './types/doctype'
7
-
8
- /**
9
- * Doctype runtime class with Immutable.js collections for HST change tracking.
10
- * @public
11
- */
12
- export default class Doctype {
13
- /**
14
- * The doctype name
15
- * @public
16
- * @readonly
17
- */
18
- readonly doctype: string
19
-
20
- /**
21
- * Alias for doctype (for DoctypeLike interface compatibility)
22
- * @public
23
- * @readonly
24
- */
25
- get name(): string {
26
- return this.doctype
27
- }
28
-
29
- /**
30
- * The doctype schema
31
- * @public
32
- * @readonly
33
- */
34
- readonly schema: ImmutableDoctype['schema']
35
-
36
- /**
37
- * The doctype workflow
38
- * @public
39
- * @readonly
40
- */
41
- readonly workflow: ImmutableDoctype['workflow']
42
-
43
- /**
44
- * The doctype component
45
- * @public
46
- * @readonly
47
- */
48
- readonly component?: Component
49
-
50
- /**
51
- * Relationship links to other doctypes
52
- * @public
53
- * @readonly
54
- */
55
- readonly links?: Record<string, LinkDeclaration>
56
-
57
- /**
58
- * Field on this doctype used when displaying a reference to one of its records.
59
- * @public
60
- * @readonly
61
- */
62
- readonly displayField?: string
63
-
64
- /**
65
- * Creates a new Doctype instance
66
- * @param doctype - The doctype name
67
- * @param schema - The doctype schema definition
68
- * @param workflow - The doctype workflow configuration (XState machine)
69
- * @param component - Optional Vue component for rendering the doctype
70
- * @param links - Optional relationship links to other doctypes
71
- * @param displayField - Optional field used when displaying references to this doctype
72
- */
73
- constructor(
74
- doctype: string,
75
- schema: ImmutableDoctype['schema'],
76
- workflow: ImmutableDoctype['workflow'],
77
- component?: Component,
78
- links?: Record<string, LinkDeclaration>,
79
- displayField?: string
80
- ) {
81
- this.doctype = doctype
82
- this.schema = schema
83
- this.workflow = workflow
84
- this.component = component
85
- this.links = links
86
- this.displayField = displayField
87
- }
88
-
89
- /**
90
- * Creates a Doctype instance from a plain configuration object.
91
- * Handles conversion of arrays to Immutable.js collections internally.
92
- *
93
- * This is the recommended way to create a Doctype from API responses
94
- * or configuration files, as it encapsulates the Immutable.js construction
95
- * that the framework uses internally.
96
- *
97
- * @param config - Plain object with doctype configuration (typically from API response)
98
- * @returns A new Doctype instance with Immutable.js collections
99
- *
100
- * @example
101
- * ```ts
102
- * // From an API response
103
- * const response = await client.getMeta({ doctype: 'plan' })
104
- * const doctype = Doctype.fromObject(response)
105
- * registry.addDoctype(doctype)
106
- * ```
107
- *
108
- * @example
109
- * ```ts
110
- * // From a configuration object
111
- * const planDoctype = Doctype.fromObject({
112
- * name: 'Plan',
113
- * fields: [
114
- * { fieldname: 'title', label: 'Title', component: 'ATextInput' },
115
- * { fieldname: 'status', label: 'Status', component: 'ATextInput' },
116
- * ],
117
- * workflow: {
118
- * id: 'plan',
119
- * initial: 'draft',
120
- * states: { draft: {}, submitted: {} }
121
- * }
122
- * })
123
- * ```
124
- *
125
- * @public
126
- */
127
- static fromObject(config: DoctypeConfig): Doctype {
128
- // Authored JSON may omit the `kind` discriminant; the Zod schema injects it via a
129
- // preprocess, but this path bypasses Zod. Normalize here so the registry's
130
- // `resolveFields` (which gates link/fieldset handling on `field.kind`) sees the same
131
- // shape a parsed doctype would — otherwise links silently fail to expand.
132
- // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- normalizeFieldKind only injects the `kind` discriminant; the field shape is otherwise preserved
133
- const fields = config.fields?.map(normalizeFieldKind) as DoctypeField[] | undefined
134
- const schema = fields ? List(fields) : List<DoctypeField>()
135
-
136
- return new Doctype(config.name, schema, config.workflow, undefined, config.links, config.displayField)
137
- }
138
-
139
- /**
140
- * Returns the raw authoring schema as a plain array.
141
- * For the resolved schema suitable for AForm, use `registry.resolveSchema(doctype)`.
142
- *
143
- * @returns Array of raw DoctypeField authoring definitions
144
- *
145
- * @example
146
- * ```ts
147
- * const fields = doctype.getSchemaArray()
148
- * // Pass to resolveSchema for AForm-ready output:
149
- * const resolved = registry.resolveSchema(doctype)
150
- * ```
151
- *
152
- * @public
153
- */
154
- getSchemaArray(): DoctypeField[] {
155
- if (!this.schema) return []
156
- return this.schema.toArray()
157
- }
158
-
159
- /**
160
- * Resolve a record's identity using this doctype's declared `primaryKey`, falling back to `id`.
161
- *
162
- * Lives here rather than at the call site because the doctype owns its schema — and because the
163
- * rule must match the server's, which builds its SQL identity predicate from the same declared
164
- * field via `@stonecrop/schema`'s `getPrimaryKeyField`.
165
- *
166
- * @param record - the record to read the identity from
167
- * @returns the identity as a string, or `undefined` when neither the declared key nor `id` yields one
168
- *
169
- * @public
170
- */
171
- getRecordId(record: Record<string, unknown>): string | undefined {
172
- return getRecordIdentity(this.getSchemaArray(), record)
173
- }
174
-
175
- /**
176
- * The field a record of this doctype is identified by: the declared `primaryKey`, or `id`
177
- * when nothing is declared.
178
- *
179
- * The client-side twin of the adapters' `recordLookupField`. Both are the same call to
180
- * `@stonecrop/schema`'s `getRecordIdField`, so the field a caller reads an identity out of is
181
- * the same field the adapter builds its lookup predicate on.
182
- *
183
- * Use this to ask whether a record *states* its own identity. `getRecordId` deliberately
184
- * falls back to `id` when the declared key is missing, which is right for resolving a link
185
- * from a record already in hand and wrong for deciding whether a server response settled on
186
- * a new identity: a response that omits a natural key would resolve through that fallback to
187
- * a surrogate the adapter cannot look up.
188
- *
189
- * @returns The identifying fieldname
190
- *
191
- * @public
192
- */
193
- get recordIdField(): string {
194
- return getRecordIdField(this.getSchemaArray())
195
- }
196
-
197
- /**
198
- * Returns the transitions available from a given workflow state, derived from the
199
- * doctype's workflow configuration. Supports both XState format and WorkflowMeta format.
200
- *
201
- * @param currentState - The state name to read transitions from
202
- * @returns Array of transition descriptors with `name` and `targetState`
203
- *
204
- * @example
205
- * ```ts
206
- * const transitions = doctype.getAvailableTransitions('draft')
207
- * // [{ name: 'SUBMIT', targetState: 'submitted' }]
208
- * ```
209
- *
210
- * @public
211
- */
212
- getAvailableTransitions(currentState: string): Array<{ name: string; targetState: string }> {
213
- const workflow = this.workflow
214
- if (!workflow) return []
215
-
216
- // Check if this is WorkflowMeta format (states is an array) or XState format (states is an object)
217
- if (Array.isArray(workflow.states)) {
218
- // WorkflowMeta format: validate state exists and filter actions by allowedStates
219
- const states = workflow.states
220
- if (!states.includes(currentState)) return []
221
-
222
- // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- Array.isArray(workflow.states) confirms WorkflowMeta format above
223
- const actions = (workflow as WorkflowMeta).actions
224
- if (!actions) return []
225
-
226
- return (
227
- Object.entries(actions)
228
- // Exclude stateless Commands — they change no state and are surfaced separately
229
- // via getAvailableCommands(). Genuine transitions carry a nextState.
230
- .filter(([, actionDef]) => !actionDef.stateless && isActionAllowedInState(actionDef, currentState))
231
- .map(([name, actionDef]) => ({
232
- name,
233
- targetState: actionDef.nextState ?? currentState,
234
- }))
235
- )
236
- }
237
-
238
- // XState format: use the on property of the state
239
- const states = workflow.states
240
- if (!states) return []
241
- const stateConfig = states[currentState]
242
- if (!stateConfig?.on) return []
243
- return Object.entries(stateConfig.on).map(([name, target]) => ({
244
- name,
245
- targetState: typeof target === 'string' ? target : 'unknown',
246
- }))
247
- }
248
-
249
- /**
250
- * Returns the stateless **Commands** available in a given workflow state — side-effect
251
- * actions (save/print/email…) that do not change workflow state. Unlike transitions,
252
- * Commands may exist on a workflow that declares no `states` (a commands-only doctype),
253
- * and a Command with no `allowedStates` is available in every state.
254
- *
255
- * Only meaningful for WorkflowMeta format; XState workflows have no Commands.
256
- *
257
- * @param currentState - The record's current state, used to honor a Command's `allowedStates`
258
- * @returns Array of command descriptors with `name`
259
- *
260
- * @example
261
- * ```ts
262
- * const commands = doctype.getAvailableCommands('Draft')
263
- * // [{ name: 'Print' }]
264
- * ```
265
- *
266
- * @public
267
- */
268
- getAvailableCommands(currentState?: string): Array<{ name: string }> {
269
- const workflow = this.workflow
270
- if (!workflow) return []
271
-
272
- // Only WorkflowMeta carries an `actions` map; XState workflows have no Commands.
273
- // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- probing the workflow union for the optional WorkflowMeta actions map
274
- const actions = (workflow as WorkflowMeta).actions
275
- if (!actions) return []
276
-
277
- return Object.entries(actions)
278
- .filter(([, actionDef]) => actionDef.stateless === true && isActionAllowedInState(actionDef, currentState ?? ''))
279
- .map(([name]) => ({ name }))
280
- }
281
-
282
- /**
283
- * Returns the field-validation **triggers** declared on this doctype's workflow (advisory,
284
- * client-side). Keyed by trigger name. Returns undefined when the workflow is absent, is an
285
- * XState machine (no triggers), or simply declares none.
286
- *
287
- * @returns The `workflow.triggers` map, or undefined
288
- *
289
- * @example
290
- * ```ts
291
- * const triggers = doctype.getTriggers()
292
- * // { dateOrder: { on: ['start_date', 'end_date'], clientHandler: '…' } }
293
- * ```
294
- *
295
- * @public
296
- */
297
- getTriggers(): Record<string, TriggerDefinition> | undefined {
298
- const workflow = this.workflow
299
- if (!workflow) return undefined
300
-
301
- // Only WorkflowMeta carries a `triggers` map; XState workflows have none.
302
- // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- probing the workflow union for the optional WorkflowMeta triggers map
303
- return (workflow as WorkflowMeta).triggers
304
- }
305
-
306
- /**
307
- * Returns metadata for a specific action, if available.
308
- * Only works with WorkflowMeta format; returns undefined for XState format.
309
- *
310
- * @param actionName - The action name to get metadata for
311
- * @returns Action metadata or undefined
312
- *
313
- * @example
314
- * ```ts
315
- * const actionMeta = doctype.getActionMeta('submit')
316
- * // { label: 'Submit', allowedStates: ['draft'] }
317
- * ```
318
- *
319
- * @public
320
- */
321
- getActionMeta(actionName: string):
322
- | {
323
- label: string
324
- requiredFields?: string[]
325
- allowedStates?: string[]
326
- }
327
- | undefined {
328
- const workflow = this.workflow
329
- if (!workflow) return undefined
330
-
331
- // Only WorkflowMeta carries an `actions` map (with labels); XState workflows have none.
332
- // Don't require a `states` array — a commands-only doctype has labeled actions but no states.
333
- // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- probing the workflow union for the optional WorkflowMeta actions map
334
- const actions = (workflow as WorkflowMeta).actions
335
- return actions?.[actionName]
336
- }
337
-
338
- /**
339
- * Converts the registered doctype string to a slug (kebab-case). The following conversions are made:
340
- * - It replaces camelCase and PascalCase with kebab-case strings
341
- * - It replaces spaces and underscores with hyphens
342
- * - It converts the string to lowercase
343
- *
344
- * @returns The slugified doctype string
345
- *
346
- * @example
347
- * ```ts
348
- * const doctype = new Doctype('TaskItem', schema, workflow, actions)
349
- * console.log(doctype.slug) // 'task-item'
350
- * ```
351
- *
352
- * @public
353
- */
354
- get slug() {
355
- return this.doctype
356
- .replace(/([a-z])([A-Z])/g, '$1-$2')
357
- .replace(/[\s_]+/g, '-')
358
- .toLowerCase()
359
- }
360
- }
package/src/draft.ts DELETED
@@ -1,38 +0,0 @@
1
- /**
2
- * The route identity of a record the user is composing that does not exist on the server yet.
3
- *
4
- * Rejected: minting `new-<timestamp>` so a draft had a store key too. Nothing ever created that
5
- * HST node, so every write to `doctype.<draftId>.<field>` threw on the missing ancestor, and the
6
- * form's data survived only because Vue cached the empty object the getter returned and the form
7
- * mutated it in place — any invalidation discarded the edits silently. Seeding the node instead
8
- * makes the draft a phantom row, because `getRecords` lists every key under the doctype.
9
- *
10
- * So a draft is held off-HST by whoever renders the form, and reaches the server as an action
11
- * carrying no record id, which the write path already reads as "create".
12
- */
13
-
14
- /**
15
- * The record-id segment a draft route carries: `/{doctype}/new`.
16
- *
17
- * Route only — never a store key, and never sent: an action dispatched for a draft omits the id
18
- * rather than sending this.
19
- *
20
- * @public
21
- */
22
- export const DRAFT_RECORD_ID = 'new'
23
-
24
- /**
25
- * Whether a record id refers to a record that has not been saved yet.
26
- *
27
- * Guard anything that assumes the record exists — fetching it, resolving its links, judging
28
- * workflow readiness — with this rather than the literal. The shell and this package once spelled
29
- * the rule differently, which left every guard here dead.
30
- *
31
- * @param recordId - The record id to test
32
- * @returns `true` when the id is the draft segment, `false` for a real identity or no id at all
33
- *
34
- * @public
35
- */
36
- export function isDraftRecordId(recordId: string | null | undefined): boolean {
37
- return recordId === DRAFT_RECORD_ID
38
- }
package/src/exceptions.ts DELETED
@@ -1,16 +0,0 @@
1
- /**
2
- * NotImplementedError
3
- * @param message {string} - The error message
4
- * @class
5
- * @description This error is thrown when a method has not been implemented
6
- * @example
7
- * throw new NotImplementedError('Method not implemented')
8
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error|Error}
9
- * @public
10
- */
11
- export class NotImplementedError extends Error {
12
- constructor(message: string = '') {
13
- super(message)
14
- this.name = 'NotImplemented'
15
- }
16
- }