@stonecrop/stonecrop 0.13.14 → 0.15.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 (95) hide show
  1. package/README.md +6 -3
  2. package/dist/src/doctype.d.ts +42 -7
  3. package/dist/src/doctype.d.ts.map +1 -1
  4. package/dist/src/doctype.js +77 -18
  5. package/dist/src/index.d.ts +5 -1
  6. package/dist/src/index.d.ts.map +1 -1
  7. package/dist/src/index.js +6 -0
  8. package/dist/src/registry.d.ts +1 -1
  9. package/dist/src/registry.d.ts.map +1 -1
  10. package/dist/src/registry.js +46 -38
  11. package/dist/src/schema-validator.d.ts.map +1 -1
  12. package/dist/src/schema-validator.js +44 -47
  13. package/dist/src/stonecrop.d.ts +0 -6
  14. package/dist/src/stonecrop.d.ts.map +1 -1
  15. package/dist/src/stores/index.d.ts +2 -0
  16. package/dist/src/stores/index.d.ts.map +1 -1
  17. package/dist/src/stores/index.js +1 -0
  18. package/dist/src/stores/operation-log.d.ts +0 -6
  19. package/dist/src/stores/operation-log.d.ts.map +1 -1
  20. package/dist/src/stores/operation-log.js +0 -1
  21. package/dist/src/stores/validation.d.ts +83 -0
  22. package/dist/src/stores/validation.d.ts.map +1 -0
  23. package/dist/src/stores/validation.js +104 -0
  24. package/dist/src/types/doctype.d.ts +1 -1
  25. package/dist/src/types/doctype.d.ts.map +1 -1
  26. package/dist/src/types/operation-log.d.ts +0 -2
  27. package/dist/src/types/operation-log.d.ts.map +1 -1
  28. package/dist/stonecrop.d.ts +166 -22
  29. package/dist/stonecrop.js +5235 -1950
  30. package/dist/stonecrop.js.map +1 -1
  31. package/package.json +23 -23
  32. package/src/client-handler.ts +55 -0
  33. package/src/doctype.ts +83 -22
  34. package/src/index.ts +12 -0
  35. package/src/registry.ts +45 -40
  36. package/src/schema-validator.ts +52 -48
  37. package/src/stores/index.ts +2 -0
  38. package/src/stores/operation-log.ts +0 -1
  39. package/src/stores/validation.ts +138 -0
  40. package/src/types/doctype.ts +1 -1
  41. package/src/types/operation-log.ts +0 -3
  42. package/dist/composable.js +0 -1
  43. package/dist/composables/lazy-link.js +0 -125
  44. package/dist/composables/operation-log.js +0 -224
  45. package/dist/composables/stonecrop.js +0 -504
  46. package/dist/composables/use-lazy-link-state.js +0 -125
  47. package/dist/composables/use-stonecrop.js +0 -476
  48. package/dist/doctype.js +0 -242
  49. package/dist/exceptions.js +0 -16
  50. package/dist/field-triggers.js +0 -575
  51. package/dist/index.js +0 -27
  52. package/dist/operation-log-DB-dGNT9.js +0 -593
  53. package/dist/operation-log-DB-dGNT9.js.map +0 -1
  54. package/dist/plugins/index.js +0 -99
  55. package/dist/registry.js +0 -423
  56. package/dist/schema-validator.js +0 -407
  57. package/dist/src/composable.d.ts +0 -11
  58. package/dist/src/composable.d.ts.map +0 -1
  59. package/dist/src/composable.js +0 -477
  60. package/dist/src/composables/use-lazy-link-state.d.ts +0 -25
  61. package/dist/src/composables/use-lazy-link-state.d.ts.map +0 -1
  62. package/dist/src/composables/use-stonecrop.d.ts +0 -93
  63. package/dist/src/composables/use-stonecrop.d.ts.map +0 -1
  64. package/dist/src/composables/useNestedSchema.d.ts +0 -110
  65. package/dist/src/composables/useNestedSchema.d.ts.map +0 -1
  66. package/dist/src/composables/useNestedSchema.js +0 -155
  67. package/dist/src/stores/data.d.ts +0 -11
  68. package/dist/src/stores/data.d.ts.map +0 -1
  69. package/dist/src/stores/xstate.d.ts +0 -31
  70. package/dist/src/stores/xstate.d.ts.map +0 -1
  71. package/dist/src/tsdoc-metadata.json +0 -11
  72. package/dist/src/utils.d.ts +0 -24
  73. package/dist/src/utils.d.ts.map +0 -1
  74. package/dist/stonecrop.css +0 -1
  75. package/dist/stonecrop.umd.cjs +0 -6
  76. package/dist/stonecrop.umd.cjs.map +0 -1
  77. package/dist/stores/data.js +0 -7
  78. package/dist/stores/hst.js +0 -496
  79. package/dist/stores/index.js +0 -12
  80. package/dist/stores/operation-log.js +0 -580
  81. package/dist/stores/xstate.js +0 -29
  82. package/dist/tests/setup.d.ts +0 -5
  83. package/dist/tests/setup.d.ts.map +0 -1
  84. package/dist/tests/setup.js +0 -15
  85. package/dist/types/composable.js +0 -0
  86. package/dist/types/doctype.js +0 -0
  87. package/dist/types/field-triggers.js +0 -4
  88. package/dist/types/hst.js +0 -0
  89. package/dist/types/index.js +0 -10
  90. package/dist/types/operation-log.js +0 -0
  91. package/dist/types/plugin.js +0 -0
  92. package/dist/types/registry.js +0 -0
  93. package/dist/types/schema-validator.js +0 -13
  94. package/dist/types/stonecrop.js +0 -0
  95. package/dist/utils.js +0 -46
package/package.json CHANGED
@@ -1,21 +1,22 @@
1
1
  {
2
2
  "name": "@stonecrop/stonecrop",
3
- "version": "0.13.14",
4
- "license": "MIT",
5
- "type": "module",
6
- "author": {
7
- "name": "Tyler Matteson",
8
- "email": "tyler@agritheory.com"
3
+ "version": "0.15.0",
4
+ "description": "Schema-driven framework with XState workflows and HST state management",
5
+ "bugs": {
6
+ "url": "https://github.com/agritheory/stonecrop/issues"
9
7
  },
10
8
  "repository": {
11
9
  "type": "git",
12
10
  "url": "https://github.com/agritheory/stonecrop",
13
11
  "directory": "stonecrop"
14
12
  },
15
- "bugs": {
16
- "url": "https://github.com/agritheory/stonecrop/issues"
13
+ "license": "MIT",
14
+ "author": {
15
+ "name": "Tyler Matteson",
16
+ "email": "tyler@agritheory.com"
17
17
  },
18
- "types": "./dist/stonecrop.d.ts",
18
+ "sideEffects": false,
19
+ "type": "module",
19
20
  "exports": {
20
21
  ".": {
21
22
  "types": "./dist/stonecrop.d.ts",
@@ -23,23 +24,18 @@
23
24
  },
24
25
  "./types": "./dist/src/types/index.d.ts"
25
26
  },
27
+ "types": "./dist/stonecrop.d.ts",
26
28
  "files": [
27
29
  "dist/*",
28
30
  "src/*"
29
31
  ],
30
- "sideEffects": false,
31
32
  "dependencies": {
32
33
  "@vueuse/core": "^14.2.1",
33
34
  "immutable": "^5.1.4",
34
35
  "pinia-shared-state": "^1.0.1",
35
36
  "pinia-xstate": "^3.0.0",
36
37
  "xstate": "^5.25.0",
37
- "@stonecrop/schema": "0.13.14"
38
- },
39
- "peerDependencies": {
40
- "pinia": "^3.0.4",
41
- "vue": "^3.5.33",
42
- "vue-router": "^5.0.6"
38
+ "@stonecrop/schema": "0.15.0"
43
39
  },
44
40
  "devDependencies": {
45
41
  "@microsoft/api-documenter": "^7.30.5",
@@ -56,17 +52,21 @@
56
52
  "vitest": "^4.1.5",
57
53
  "vue": "^3.5.33",
58
54
  "vue-router": "^5.0.6",
59
- "@stonecrop/aform": "0.13.14",
60
- "@stonecrop/atable": "0.13.14",
55
+ "@stonecrop/atable": "0.15.0",
56
+ "@stonecrop/aform": "0.15.0",
61
57
  "stonecrop-rig": "0.7.0"
62
58
  },
63
- "description": "Schema-driven framework with XState workflows and HST state management",
64
- "publishConfig": {
65
- "access": "public"
59
+ "peerDependencies": {
60
+ "pinia": "^3.0.4",
61
+ "vue": "^3.5.33",
62
+ "vue-router": "^5.0.6"
66
63
  },
67
64
  "engines": {
68
65
  "node": ">=24.0.0"
69
66
  },
67
+ "publishConfig": {
68
+ "access": "public"
69
+ },
70
70
  "scripts": {
71
71
  "_phase:build": "heft build && vite build && rushx docs",
72
72
  "build": "heft build && vite build && rushx docs",
@@ -75,8 +75,8 @@
75
75
  "lint:fix": "oxlint --fix",
76
76
  "preview": "vite preview",
77
77
  "test": "vitest run --coverage.enabled false",
78
- "test:watch": "vitest watch",
79
78
  "test:coverage": "vitest run --coverage",
80
- "test:ui": "vitest --ui"
79
+ "test:ui": "vitest --ui",
80
+ "test:watch": "vitest watch"
81
81
  }
82
82
  }
@@ -0,0 +1,55 @@
1
+ /**
2
+ * clientHandler execution
3
+ * Pure executor for docbuilder-authored client handlers.
4
+ * @packageDocumentation
5
+ */
6
+
7
+ /**
8
+ * Named capabilities injected into a clientHandler body as function parameters.
9
+ * The caller (the assembly composable) owns what each name resolves to — typically
10
+ * `router`, `record`, `runAction`, and a read-only `graphql`.
11
+ *
12
+ * @public
13
+ */
14
+ export type ClientHandlerApi = Record<string, unknown>
15
+
16
+ // AsyncFunction is not a global; reach it via an async function's constructor so authored
17
+ // bodies can use top-level `await` without writing an async wrapper.
18
+ // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- an async function's constructor is always the AsyncFunction constructor
19
+ const AsyncFunction = Object.getPrototypeOf(async () => {}).constructor as new (
20
+ ...args: string[]
21
+ ) => (...args: unknown[]) => Promise<unknown>
22
+
23
+ /**
24
+ * Execute a docbuilder-authored `clientHandler` body against an injected API map.
25
+ *
26
+ * `code` is a function *body* (statements), not a full function — authored in the
27
+ * docbuilder code editor and stored on `ActionDefinition.clientHandler`. It is compiled
28
+ * with the AsyncFunction constructor, so `await` works directly. Each key of `api`
29
+ * becomes a parameter name bound to its value, so a handler can reference `router`,
30
+ * `record`, `runAction`, etc. by name.
31
+ *
32
+ * This executor is deliberately concern-free: it performs no routing, dispatch, or HST
33
+ * writes itself — the caller assembles `api`. The injected set is an *intent* contract,
34
+ * not a sandbox (an AsyncFunction body can still reach `fetch`/`window`); enforcement of
35
+ * what a handler may actually do lives server-side, not here.
36
+ *
37
+ * Errors are propagated to the caller as a rejected promise — syntax errors at compile
38
+ * time and thrown errors / rejections at run time — so callers handle both uniformly.
39
+ *
40
+ * @param code - the clientHandler body, e.g. `"router.push('/users')"`
41
+ * @param api - named capabilities injected as parameters (default: none)
42
+ * @returns whatever the body returns (typically `void`)
43
+ *
44
+ * @example
45
+ * ```ts
46
+ * await executeClientHandler("await runAction('Assign', [record.id])", { runAction, record })
47
+ * ```
48
+ *
49
+ * @public
50
+ */
51
+ export async function executeClientHandler(code: string, api: ClientHandlerApi = {}): Promise<unknown> {
52
+ const names = Object.keys(api)
53
+ const fn = new AsyncFunction(...names, code)
54
+ return fn(...names.map(name => api[name]))
55
+ }
package/src/doctype.ts CHANGED
@@ -1,4 +1,5 @@
1
- import type { DoctypeField, LinkDeclaration, WorkflowMeta } from '@stonecrop/schema'
1
+ import type { DoctypeField, LinkDeclaration, TriggerDefinition, WorkflowMeta } from '@stonecrop/schema'
2
+ import { isActionAllowedInState, normalizeFieldKind } from '@stonecrop/schema'
2
3
  import { List, Map } from 'immutable'
3
4
  import { Component } from 'vue'
4
5
 
@@ -110,8 +111,8 @@ export default class Doctype {
110
111
  * const planDoctype = Doctype.fromObject({
111
112
  * name: 'Plan',
112
113
  * fields: [
113
- * { fieldname: 'title', label: 'Title', fieldtype: 'Data' },
114
- * { fieldname: 'status', label: 'Status', fieldtype: 'Data' },
114
+ * { fieldname: 'title', label: 'Title', component: 'ATextInput' },
115
+ * { fieldname: 'status', label: 'Status', component: 'ATextInput' },
115
116
  * ],
116
117
  * workflow: {
117
118
  * id: 'plan',
@@ -124,7 +125,13 @@ export default class Doctype {
124
125
  * @public
125
126
  */
126
127
  static fromObject(config: DoctypeConfig): Doctype {
127
- const schema = config.fields ? List(config.fields) : List<DoctypeField>()
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>()
128
135
  const actions = config.actions ? Map(config.actions) : Map<string, string[]>()
129
136
 
130
137
  return new Doctype(config.name, schema, config.workflow, actions, undefined, config.links)
@@ -192,18 +199,16 @@ export default class Doctype {
192
199
  const actions = (workflow as WorkflowMeta).actions
193
200
  if (!actions) return []
194
201
 
195
- return Object.entries(actions)
196
- .filter(([, actionDef]) => {
197
- const allowedStates = actionDef.allowedStates
198
- // If no allowedStates specified, action is available in all valid states
199
- if (!allowedStates || allowedStates.length === 0) return true
200
- return allowedStates.includes(currentState)
201
- })
202
- .map(([name]) => ({
203
- name,
204
- // WorkflowMeta doesn't define target states - transitions are handled server-side
205
- targetState: currentState,
206
- }))
202
+ return (
203
+ Object.entries(actions)
204
+ // Exclude stateless Commands — they change no state and are surfaced separately
205
+ // via getAvailableCommands(). Genuine transitions carry a nextState.
206
+ .filter(([, actionDef]) => !actionDef.stateless && isActionAllowedInState(actionDef, currentState))
207
+ .map(([name, actionDef]) => ({
208
+ name,
209
+ targetState: actionDef.nextState ?? currentState,
210
+ }))
211
+ )
207
212
  }
208
213
 
209
214
  // XState format: use the on property of the state
@@ -217,6 +222,63 @@ export default class Doctype {
217
222
  }))
218
223
  }
219
224
 
225
+ /**
226
+ * Returns the stateless **Commands** available in a given workflow state — side-effect
227
+ * actions (save/print/email…) that do not change workflow state. Unlike transitions,
228
+ * Commands may exist on a workflow that declares no `states` (a commands-only doctype),
229
+ * and a Command with no `allowedStates` is available in every state.
230
+ *
231
+ * Only meaningful for WorkflowMeta format; XState workflows have no Commands.
232
+ *
233
+ * @param currentState - The record's current state, used to honor a Command's `allowedStates`
234
+ * @returns Array of command descriptors with `name`
235
+ *
236
+ * @example
237
+ * ```ts
238
+ * const commands = doctype.getAvailableCommands('Draft')
239
+ * // [{ name: 'Print' }]
240
+ * ```
241
+ *
242
+ * @public
243
+ */
244
+ getAvailableCommands(currentState?: string): Array<{ name: string }> {
245
+ const workflow = this.workflow
246
+ if (!workflow) return []
247
+
248
+ // Only WorkflowMeta carries an `actions` map; XState workflows have no Commands.
249
+ // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- probing the workflow union for the optional WorkflowMeta actions map
250
+ const actions = (workflow as WorkflowMeta).actions
251
+ if (!actions) return []
252
+
253
+ return Object.entries(actions)
254
+ .filter(([, actionDef]) => actionDef.stateless === true && isActionAllowedInState(actionDef, currentState ?? ''))
255
+ .map(([name]) => ({ name }))
256
+ }
257
+
258
+ /**
259
+ * Returns the field-validation **triggers** declared on this doctype's workflow (advisory,
260
+ * client-side). Keyed by trigger name. Returns undefined when the workflow is absent, is an
261
+ * XState machine (no triggers), or simply declares none.
262
+ *
263
+ * @returns The `workflow.triggers` map, or undefined
264
+ *
265
+ * @example
266
+ * ```ts
267
+ * const triggers = doctype.getTriggers()
268
+ * // { dateOrder: { on: ['start_date', 'end_date'], clientHandler: '…' } }
269
+ * ```
270
+ *
271
+ * @public
272
+ */
273
+ getTriggers(): Record<string, TriggerDefinition> | undefined {
274
+ const workflow = this.workflow
275
+ if (!workflow) return undefined
276
+
277
+ // Only WorkflowMeta carries a `triggers` map; XState workflows have none.
278
+ // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- probing the workflow union for the optional WorkflowMeta triggers map
279
+ return (workflow as WorkflowMeta).triggers
280
+ }
281
+
220
282
  /**
221
283
  * Returns metadata for a specific action, if available.
222
284
  * Only works with WorkflowMeta format; returns undefined for XState format.
@@ -227,7 +289,7 @@ export default class Doctype {
227
289
  * @example
228
290
  * ```ts
229
291
  * const actionMeta = doctype.getActionMeta('submit')
230
- * // { label: 'Submit', handler: 'plan:submit', allowedStates: ['draft'] }
292
+ * // { label: 'Submit', allowedStates: ['draft'] }
231
293
  * ```
232
294
  *
233
295
  * @public
@@ -235,17 +297,16 @@ export default class Doctype {
235
297
  getActionMeta(actionName: string):
236
298
  | {
237
299
  label: string
238
- handler: string
239
300
  requiredFields?: string[]
240
301
  allowedStates?: string[]
241
- confirm?: boolean
242
- args?: Record<string, unknown>
243
302
  }
244
303
  | undefined {
245
304
  const workflow = this.workflow
246
- if (!workflow || !Array.isArray(workflow.states)) return undefined
305
+ if (!workflow) return undefined
247
306
 
248
- // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- Array.isArray(workflow.states) confirms WorkflowMeta format above
307
+ // Only WorkflowMeta carries an `actions` map (with labels); XState workflows have none.
308
+ // Don't require a `states` array — a commands-only doctype has labeled actions but no states.
309
+ // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- probing the workflow union for the optional WorkflowMeta actions map
249
310
  const actions = (workflow as WorkflowMeta).actions
250
311
  return actions?.[actionName]
251
312
  }
package/src/index.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export type * from '@stonecrop/aform/types'
2
2
  export type * from '@stonecrop/atable/types'
3
3
 
4
+ import { executeClientHandler } from './client-handler'
4
5
  import { useLazyLink } from './composables/lazy-link'
5
6
  import { useStonecrop } from './composables/stonecrop'
6
7
  import { useOperationLog, useUndoRedoShortcuts, withBatch } from './composables/operation-log'
@@ -19,12 +20,19 @@ import Registry from './registry'
19
20
  import { Stonecrop, getStonecrop } from './stonecrop'
20
21
  import { HST, createHST, type HSTNode } from './stores/hst'
21
22
  import { useOperationLogStore } from './stores/operation-log'
23
+ import { useValidationStore } from './stores/validation'
22
24
  import { SchemaValidator, createValidator, validateSchema } from './schema-validator'
23
25
  import { ValidationSeverity } from './types/schema-validator'
24
26
 
25
27
  // Export all types from ./types
26
28
  export type * from './types'
27
29
 
30
+ // clientHandler executor types
31
+ export type { ClientHandlerApi } from './client-handler'
32
+
33
+ // Field-validation store types
34
+ export type { ValidationError } from './stores/validation'
35
+
28
36
  // Export enum as value (enums need runtime export, not just type)
29
37
  export { ValidationSeverity }
30
38
 
@@ -34,6 +42,8 @@ export {
34
42
  Stonecrop,
35
43
  useLazyLink,
36
44
  useStonecrop,
45
+ // clientHandler executor
46
+ executeClientHandler,
37
47
  // HST exports for advanced usage
38
48
  HST,
39
49
  createHST,
@@ -55,6 +65,8 @@ export {
55
65
  useOperationLogStore,
56
66
  useUndoRedoShortcuts,
57
67
  withBatch,
68
+ // Field-validation store
69
+ useValidationStore,
58
70
  // Utility functions
59
71
  getStonecrop,
60
72
  }
package/src/registry.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { ResolvedField, ResolvedLink, ResolvedScalar, ResolvedTable, ResolvedFieldset } from '@stonecrop/aform'
2
2
  import type { ColumnSchema, DoctypeField, LinkDeclaration, TableViewConfig, ValueField } from '@stonecrop/schema'
3
+ import { componentCategory, componentLinkExpansion, resolveLinkRenderMode } from '@stonecrop/schema'
3
4
  import { Router } from 'vue-router'
4
5
 
5
6
  import Doctype from './doctype'
@@ -165,23 +166,22 @@ export default class Registry {
165
166
  const resolved: ResolvedField[] = []
166
167
 
167
168
  for (const field of fields) {
168
- if (field.kind === 'field' && field.fieldtype === 'Link') {
169
- const link = links.get(field.fieldname)
170
- if (!link) {
171
- // Unresolved link — warn and produce a scalar with component: 'AFormLink'
172
- const linkDoctype = typeof field.options === 'string' ? field.options : undefined
173
- if (linkDoctype === undefined) {
174
- console.warn(
175
- `[Stonecrop] Link field "${field.fieldname}" has no \`options\` or corresponding \`links\` declaration. ` +
176
- `AFormLink will be created without a \`doctype\` prop, so navigation will not work. ` +
177
- `Add \`"options": "<doctype-slug>"\` to the field definition.`
178
- )
179
- }
169
+ // A field is a link when it carries `doctype` (the marker) or has a LinkDeclaration.
170
+ const linkDecl = field.kind === 'field' ? links.get(field.fieldname) : undefined
171
+ if (field.kind === 'field' && (linkDecl || field.doctype)) {
172
+ const link = linkDecl
173
+ // The declaration's target wins over the field's own `doctype`.
174
+ const linkTarget = link?.target ?? field.doctype
175
+
176
+ // An undeclared link, or a declared one whose component renders an inline picker,
177
+ // stays a scalar: the target is not expanded, it only needs the slug for async
178
+ // display-text resolution and navigation.
179
+ if (!link || resolveLinkRenderMode(link, field.component) === 'inline') {
180
180
  const { cardinality: _c, ...rest } = field
181
181
  resolved.push({
182
182
  ...rest,
183
183
  component: rest.component || 'AFormLink',
184
- ...(linkDoctype !== undefined ? { doctype: linkDoctype } : {}),
184
+ ...(linkTarget !== undefined ? { doctype: linkTarget } : {}),
185
185
  })
186
186
  continue
187
187
  }
@@ -195,9 +195,9 @@ export default class Registry {
195
195
  }
196
196
 
197
197
  const childSchema = this.resolveSchema(targetDoctype, new Set(visited))
198
- const { fieldtype: _ft, options: _opt, cardinality: _card, kind: _kind, ...fieldRest } = field
198
+ const { options: _opt, cardinality: _card, kind: _kind, ...fieldRest } = field
199
199
 
200
- if (link.cardinality === 'noneOrMany' || link.cardinality === 'atLeastOne') {
200
+ if (resolveLinkRenderMode(link, field.component) === 'table') {
201
201
  resolved.push(this.buildTableConfig(field, childSchema, link.component))
202
202
  } else {
203
203
  const linkEntry: ResolvedLink = {
@@ -229,7 +229,18 @@ export default class Registry {
229
229
  }
230
230
  resolved.push(tableEntry)
231
231
  } else {
232
- // Scalar field (kind: 'field', not a Link) — strip cardinality
232
+ // Scalar field (kind: 'field', not a link) — strip cardinality.
233
+ // A link-rendering component with nothing to point at renders an empty picker (or an
234
+ // empty embedded form), which is indistinguishable from "the record has no value".
235
+ // Link-ness comes from `doctype`/`links`, so this is a field that named a link
236
+ // component and forgot the target.
237
+ if (field.kind === 'field' && componentLinkExpansion(field.component)) {
238
+ console.warn(
239
+ `[Stonecrop] Field "${field.fieldname}" renders with "${field.component}", which is a link component, ` +
240
+ `but the field is not a link: it has no \`doctype\` and no \`links\` declaration. It will render ` +
241
+ `as a plain field. Add \`"doctype": "<doctype-slug>"\` to the field definition.`
242
+ )
243
+ }
233
244
  const { cardinality: _c, ...rest } = field
234
245
  resolved.push({ ...rest })
235
246
  }
@@ -250,7 +261,7 @@ export default class Registry {
250
261
  .map(({ kind: _k, ...col }) => col)
251
262
 
252
263
  const config: TableViewConfig = (field as ValueField & { config?: TableViewConfig }).config ?? { view: 'list' }
253
- const { fieldtype: _ft, options: _opt, cardinality: _card, ...fieldRest } = field
264
+ const { options: _opt, cardinality: _card, ...fieldRest } = field
254
265
 
255
266
  return {
256
267
  ...fieldRest,
@@ -268,7 +279,7 @@ export default class Registry {
268
279
  *
269
280
  * - `kind: 'table'` or `kind: 'link'` → `[]` or `{}`
270
281
  * - `kind: 'fieldset'` → recursively initializes children as `{}`
271
- * - `kind: 'field'` → derives default from `fieldtype`; falls back to `null`
282
+ * - `kind: 'field'` → derives the default from the component's category; falls back to `null`
272
283
  *
273
284
  * @param schema - The resolved schema array to derive defaults from
274
285
  * @returns A plain object with default values for each field
@@ -285,32 +296,26 @@ export default class Registry {
285
296
  } else if (field.kind === 'fieldset') {
286
297
  record[field.fieldname] = this.initializeRecord(field.schema)
287
298
  } else {
288
- // kind: 'field' — derive from fieldtype
299
+ // kind: 'field' — the empty default comes from the component's category.
289
300
  const fieldDefault = field.default
290
301
  if (fieldDefault !== undefined) {
291
302
  record[field.fieldname] = fieldDefault
292
303
  } else {
293
- switch (field.fieldtype) {
294
- case 'Data':
295
- case 'Text':
296
- case 'Code':
297
- record[field.fieldname] = ''
298
- break
299
- case 'Check':
300
- record[field.fieldname] = false
301
- break
302
- case 'Int':
303
- case 'Float':
304
- case 'Decimal':
305
- case 'Currency':
306
- case 'Quantity':
307
- record[field.fieldname] = 0
308
- break
309
- case 'JSON':
310
- record[field.fieldname] = {}
311
- break
312
- default:
313
- record[field.fieldname] = null
304
+ const category = componentCategory(field.component)
305
+ if (category === 'text') {
306
+ record[field.fieldname] = ''
307
+ } else if (category === 'number') {
308
+ record[field.fieldname] = 0
309
+ } else if (category === 'boolean') {
310
+ record[field.fieldname] = false
311
+ } else if (category === 'code' && field.language) {
312
+ // A JSON editor starts from an empty object; any other language from empty source.
313
+ record[field.fieldname] = field.language === 'json' ? {} : ''
314
+ } else {
315
+ // date / datetime / select / link / attach — plus two cases with no better answer
316
+ // than "no value": an unknown (custom) component, and a code field whose missing
317
+ // `language` doesn't say which kind of empty it wants.
318
+ record[field.fieldname] = null
314
319
  }
315
320
  }
316
321
  }
@@ -6,6 +6,7 @@
6
6
 
7
7
  import type { DoctypeField } from '@stonecrop/schema'
8
8
  import type { LinkDeclaration } from '@stonecrop/schema'
9
+ import { componentLinkExpansion } from '@stonecrop/schema'
9
10
  import type { List, Map as ImmutableMap } from 'immutable'
10
11
  import type { AnyStateNodeConfig } from 'xstate'
11
12
 
@@ -59,7 +60,7 @@ export class SchemaValidator {
59
60
 
60
61
  // Validate required properties
61
62
  if (this.options.validateRequiredProperties) {
62
- issues.push(...this.validateRequiredProperties(doctype, schemaArray))
63
+ issues.push(...this.validateRequiredProperties(doctype, schemaArray, links))
63
64
  }
64
65
 
65
66
  // Validate Link field targets
@@ -102,7 +103,11 @@ export class SchemaValidator {
102
103
  * Validates that required schema properties are present
103
104
  * @internal
104
105
  */
105
- private validateRequiredProperties(doctype: string, schema: DoctypeField[]): ValidationIssue[] {
106
+ private validateRequiredProperties(
107
+ doctype: string,
108
+ schema: DoctypeField[],
109
+ links?: Record<string, LinkDeclaration>
110
+ ): ValidationIssue[] {
106
111
  const issues: ValidationIssue[] = []
107
112
 
108
113
  for (const field of schema) {
@@ -118,12 +123,34 @@ export class SchemaValidator {
118
123
  continue
119
124
  }
120
125
 
121
- // ValueField requires fieldtype; fieldset/table have their own structural requirements
122
- if (field.kind === 'field' && !field.component && !field.fieldtype) {
126
+ // A value field renders through its component and has no other rendering axis;
127
+ // fieldset/table have their own structural requirements.
128
+ if (field.kind === 'field' && !field.component) {
129
+ issues.push({
130
+ severity: ValidationSeverity.ERROR,
131
+ rule: 'required-component',
132
+ message: `Field "${field.fieldname}" must have a component property`,
133
+ doctype,
134
+ fieldname: field.fieldname,
135
+ })
136
+ }
137
+
138
+ // A link component with nothing to point at renders an empty picker, which looks exactly
139
+ // like a record that has no value — so this fails silently at runtime rather than loudly.
140
+ // Link-ness comes from `doctype` or a `links` declaration, so this is a field that named
141
+ // a link component and gave it neither.
142
+ if (
143
+ field.kind === 'field' &&
144
+ componentLinkExpansion(field.component) &&
145
+ !field.doctype &&
146
+ !links?.[field.fieldname]
147
+ ) {
123
148
  issues.push({
124
149
  severity: ValidationSeverity.ERROR,
125
- rule: 'required-component-or-fieldtype',
126
- message: `Field "${field.fieldname}" must have either component or fieldtype property`,
150
+ rule: 'link-component-without-doctype',
151
+ message:
152
+ `Field "${field.fieldname}" renders with "${field.component}", which is a link component, ` +
153
+ `but has no \`doctype\` to name its target`,
127
154
  doctype,
128
155
  fieldname: field.fieldname,
129
156
  })
@@ -131,7 +158,7 @@ export class SchemaValidator {
131
158
 
132
159
  // Validate nested schemas recursively (fieldset only; table columns are ColumnSchema not DoctypeField)
133
160
  if (field.kind === 'fieldset') {
134
- issues.push(...this.validateRequiredProperties(doctype, field.schema))
161
+ issues.push(...this.validateRequiredProperties(doctype, field.schema, links))
135
162
  }
136
163
  }
137
164
 
@@ -146,30 +173,14 @@ export class SchemaValidator {
146
173
  const issues: ValidationIssue[] = []
147
174
 
148
175
  for (const field of schema) {
149
- if (field.kind === 'field' && field.fieldtype === 'Link') {
150
- const options = field.options
151
- if (!options) {
152
- issues.push({
153
- severity: ValidationSeverity.ERROR,
154
- rule: 'link-missing-options',
155
- message: `Link field "${field.fieldname}" is missing options property (target doctype)`,
156
- doctype,
157
- fieldname: field.fieldname,
158
- })
159
- continue
160
- }
161
-
162
- const targetDoctype = typeof options === 'string' ? options : ''
163
- if (!targetDoctype) {
164
- issues.push({
165
- severity: ValidationSeverity.ERROR,
166
- rule: 'link-invalid-options',
167
- message: `Link field "${field.fieldname}" has invalid options format (expected string doctype name)`,
168
- doctype,
169
- fieldname: field.fieldname,
170
- })
171
- continue
172
- }
176
+ // `doctype` is both the link marker and its target, and the schema types it as a
177
+ // non-empty string — so there is no "missing target" or "malformed target" state left
178
+ // to check here. The rules that did (`link-missing-options`, `link-invalid-options`)
179
+ // were removed with the `options`-as-link-target convention; the case they actually
180
+ // guarded — a link component with no target — is now `link-component-without-doctype`,
181
+ // which fires in validateRequiredProperties whether or not a registry is configured.
182
+ if (field.kind === 'field' && field.doctype) {
183
+ const targetDoctype = field.doctype
173
184
  const targetMeta = registry.registry[targetDoctype] || registry.registry[targetDoctype.toLowerCase()]
174
185
 
175
186
  if (!targetMeta) {
@@ -205,10 +216,10 @@ export class SchemaValidator {
205
216
  ): ValidationIssue[] {
206
217
  const issues: ValidationIssue[] = []
207
218
 
208
- // Build a map of Link fields by fieldname for quick lookup
219
+ // Build a map of link fields by fieldname for quick lookup
209
220
  const linkFieldsByFieldname = new Map<string, DoctypeField>()
210
221
  for (const field of schema) {
211
- if (field.kind === 'field' && field.fieldtype === 'Link') {
222
+ if (field.kind === 'field' && field.doctype) {
212
223
  linkFieldsByFieldname.set(field.fieldname, field)
213
224
  }
214
225
  }
@@ -269,7 +280,8 @@ export class SchemaValidator {
269
280
  if (link.fieldname) {
270
281
  const linkField = linkFieldsByFieldname.get(link.fieldname)
271
282
  if (linkField && linkField.kind === 'field') {
272
- const linkFieldTarget = typeof linkField.options === 'string' ? linkField.options : undefined
283
+ // Map membership implies `doctype` is set — that is the map's build condition.
284
+ const linkFieldTarget = linkField.doctype
273
285
  if (linkFieldTarget && linkFieldTarget !== link.target) {
274
286
  issues.push({
275
287
  severity: ValidationSeverity.ERROR,
@@ -284,20 +296,12 @@ export class SchemaValidator {
284
296
  }
285
297
  }
286
298
 
287
- // Check that every Link field has a corresponding link declaration
288
- // A Link field corresponds to a link if the link's fieldname property matches the field's fieldname
289
- for (const [fieldname, _field] of linkFieldsByFieldname) {
290
- const hasCorrespondingLink = Object.values(links).some(link => link.fieldname === fieldname)
291
- if (!hasCorrespondingLink) {
292
- issues.push({
293
- severity: ValidationSeverity.ERROR,
294
- rule: 'link-field-without-declaration',
295
- message: `Link field "${fieldname}" has no corresponding link declaration`,
296
- doctype,
297
- fieldname,
298
- })
299
- }
300
- }
299
+ // NOTE: there is deliberately no "every link field needs a declaration" rule. A plain foreign
300
+ // key is a link with no `links` entry — the map is additive, carrying expansion metadata
301
+ // (backlink/fetch/cardinality), and is not required. Such a rule would contradict
302
+ // `Registry.resolveFields`, which resolves undeclared links to inline pickers, and would flag
303
+ // every doctype that mixes an expanded relation with a plain FK (e.g. `country`: a `links`
304
+ // map for states/languages/subdivisions plus a plain `continent` picker).
301
305
 
302
306
  return issues
303
307
  }