@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.
- package/dist/stonecrop.js +3548 -2740
- package/dist/stonecrop.js.map +1 -1
- package/dist/tsdoc-metadata.json +1 -1
- package/package.json +33 -27
- package/dist/src/client-action.d.ts +0 -31
- package/dist/src/client-action.d.ts.map +0 -1
- package/dist/src/client-action.js +0 -169
- package/dist/src/client-handler.d.ts +0 -43
- package/dist/src/client-handler.d.ts.map +0 -1
- package/dist/src/client-handler.js +0 -42
- package/dist/src/composables/lazy-link.d.ts +0 -25
- package/dist/src/composables/lazy-link.d.ts.map +0 -1
- package/dist/src/composables/lazy-link.js +0 -124
- package/dist/src/composables/operation-log.d.ts +0 -136
- package/dist/src/composables/operation-log.d.ts.map +0 -1
- package/dist/src/composables/operation-log.js +0 -224
- package/dist/src/composables/stonecrop.d.ts +0 -37
- package/dist/src/composables/stonecrop.d.ts.map +0 -1
- package/dist/src/composables/stonecrop.js +0 -433
- package/dist/src/doctype.d.ts +0 -243
- package/dist/src/doctype.d.ts.map +0 -1
- package/dist/src/doctype.js +0 -325
- package/dist/src/draft.d.ts +0 -35
- package/dist/src/draft.d.ts.map +0 -1
- package/dist/src/draft.js +0 -36
- package/dist/src/exceptions.d.ts +0 -14
- package/dist/src/exceptions.d.ts.map +0 -1
- package/dist/src/exceptions.js +0 -16
- package/dist/src/field-triggers.d.ts +0 -184
- package/dist/src/field-triggers.d.ts.map +0 -1
- package/dist/src/field-triggers.js +0 -577
- package/dist/src/index.d.ts +0 -25
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/index.js +0 -39
- package/dist/src/plugins/index.d.ts +0 -35
- package/dist/src/plugins/index.d.ts.map +0 -1
- package/dist/src/plugins/index.js +0 -98
- package/dist/src/registry.d.ts +0 -161
- package/dist/src/registry.d.ts.map +0 -1
- package/dist/src/registry.js +0 -384
- package/dist/src/schema-validator.d.ts +0 -78
- package/dist/src/schema-validator.d.ts.map +0 -1
- package/dist/src/schema-validator.js +0 -398
- package/dist/src/stonecrop.d.ts +0 -539
- package/dist/src/stonecrop.d.ts.map +0 -1
- package/dist/src/stonecrop.js +0 -610
- package/dist/src/stores/hst.d.ts +0 -92
- package/dist/src/stores/hst.d.ts.map +0 -1
- package/dist/src/stores/hst.js +0 -487
- package/dist/src/stores/index.d.ts +0 -9
- package/dist/src/stores/index.d.ts.map +0 -1
- package/dist/src/stores/index.js +0 -13
- package/dist/src/stores/operation-log.d.ts +0 -262
- package/dist/src/stores/operation-log.d.ts.map +0 -1
- package/dist/src/stores/operation-log.js +0 -571
- package/dist/src/stores/validation.d.ts +0 -83
- package/dist/src/stores/validation.d.ts.map +0 -1
- package/dist/src/stores/validation.js +0 -104
- package/dist/src/types/client-action.d.ts +0 -121
- package/dist/src/types/client-action.d.ts.map +0 -1
- package/dist/src/types/client-action.js +0 -0
- package/dist/src/types/composable.d.ts +0 -268
- package/dist/src/types/composable.d.ts.map +0 -1
- package/dist/src/types/composable.js +0 -0
- package/dist/src/types/doctype.d.ts +0 -34
- package/dist/src/types/doctype.d.ts.map +0 -1
- package/dist/src/types/doctype.js +0 -0
- package/dist/src/types/field-triggers.d.ts +0 -186
- package/dist/src/types/field-triggers.d.ts.map +0 -1
- package/dist/src/types/field-triggers.js +0 -4
- package/dist/src/types/hst.d.ts +0 -70
- package/dist/src/types/hst.d.ts.map +0 -1
- package/dist/src/types/hst.js +0 -0
- package/dist/src/types/index.d.ts +0 -11
- package/dist/src/types/index.d.ts.map +0 -1
- package/dist/src/types/index.js +0 -11
- package/dist/src/types/operation-log.d.ts +0 -163
- package/dist/src/types/operation-log.d.ts.map +0 -1
- package/dist/src/types/operation-log.js +0 -0
- package/dist/src/types/plugin.d.ts +0 -37
- package/dist/src/types/plugin.d.ts.map +0 -1
- package/dist/src/types/plugin.js +0 -0
- package/dist/src/types/registry.d.ts +0 -11
- package/dist/src/types/registry.d.ts.map +0 -1
- package/dist/src/types/registry.js +0 -0
- package/dist/src/types/schema-validator.d.ts +0 -66
- package/dist/src/types/schema-validator.d.ts.map +0 -1
- package/dist/src/types/schema-validator.js +0 -13
- package/dist/src/types/stonecrop.d.ts +0 -32
- package/dist/src/types/stonecrop.d.ts.map +0 -1
- package/dist/src/types/stonecrop.js +0 -0
- package/dist/stonecrop.tsbuildinfo +0 -1
- package/src/client-action.ts +0 -207
- package/src/client-handler.ts +0 -55
- package/src/composables/lazy-link.ts +0 -145
- package/src/composables/operation-log.ts +0 -257
- package/src/composables/stonecrop.ts +0 -556
- package/src/doctype.ts +0 -360
- package/src/draft.ts +0 -38
- package/src/exceptions.ts +0 -16
- package/src/field-triggers.ts +0 -686
- package/src/index.ts +0 -81
- package/src/plugins/index.ts +0 -113
- package/src/registry.ts +0 -433
- package/src/schema-validator.ts +0 -476
- package/src/stonecrop.ts +0 -721
- package/src/stores/hst.ts +0 -626
- package/src/stores/index.ts +0 -21
- package/src/stores/operation-log.ts +0 -675
- package/src/stores/validation.ts +0 -138
- package/src/types/client-action.ts +0 -121
- package/src/types/composable.ts +0 -288
- package/src/types/doctype.ts +0 -35
- package/src/types/field-triggers.ts +0 -201
- package/src/types/hst.ts +0 -77
- package/src/types/index.ts +0 -11
- package/src/types/operation-log.ts +0 -202
- package/src/types/plugin.ts +0 -38
- package/src/types/registry.ts +0 -10
- package/src/types/schema-validator.ts +0 -69
- 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
|
-
}
|