@stonecrop/schema 0.46.1 → 0.48.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/cli.js +1 -1
- package/dist/{converter-Bp-392jp.js → converter-BAIfP9rG.js} +61 -32
- package/dist/converter-BAIfP9rG.js.map +1 -0
- package/dist/{record-BTIWvDBA.js → flatten-BaPZLJ2O.js} +46 -30
- package/dist/flatten-BaPZLJ2O.js.map +1 -0
- package/dist/index.js +4 -4
- package/dist/record.js +69 -2
- package/dist/record.js.map +1 -0
- package/dist/schema.d.ts +53 -8
- package/package.json +1 -1
- package/dist/converter-Bp-392jp.js.map +0 -1
- package/dist/flatten-Bx2cfvw3.js +0 -37
- package/dist/flatten-Bx2cfvw3.js.map +0 -1
- package/dist/record-BTIWvDBA.js.map +0 -1
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { t as flattenFields } from "./flatten-Bx2cfvw3.js";
|
|
2
1
|
//#region src/component-meta.ts
|
|
3
2
|
/**
|
|
4
3
|
* Canonical component → semantic category. Only the components Stonecrop ships with appear here;
|
|
@@ -52,6 +51,27 @@ function componentLinkExpansion(component) {
|
|
|
52
51
|
return component ? COMPONENT_LINK_EXPANSION[component] : void 0;
|
|
53
52
|
}
|
|
54
53
|
/**
|
|
54
|
+
* The parts of its value each component edits, each held in a field of the record (a field's
|
|
55
|
+
* `parts` names which). A component absent here edits a single value, so its field declares no
|
|
56
|
+
* parts.
|
|
57
|
+
* @public
|
|
58
|
+
*/
|
|
59
|
+
var COMPONENT_PARTS = {
|
|
60
|
+
AQuantityInput: ["qty", "uom"],
|
|
61
|
+
ACurrencyInput: [
|
|
62
|
+
"amount",
|
|
63
|
+
"currency",
|
|
64
|
+
"exchangeRate"
|
|
65
|
+
]
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Resolve the parts a component edits, or `undefined` for one that edits a single value.
|
|
69
|
+
* @public
|
|
70
|
+
*/
|
|
71
|
+
function componentParts(component) {
|
|
72
|
+
return component ? COMPONENT_PARTS[component] : void 0;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
55
75
|
* Decide how a *declared* link (one with a `LinkDeclaration`) renders.
|
|
56
76
|
*
|
|
57
77
|
* Two independent axes: the **component** picks inline vs expand, and when expanding the
|
|
@@ -87,44 +107,40 @@ function resolveLinkRenderMode(link, fieldComponent) {
|
|
|
87
107
|
*/
|
|
88
108
|
var CANONICAL_COMPONENTS = [.../* @__PURE__ */ new Set([...Object.keys(COMPONENT_CATEGORY), ...Object.keys(COMPONENT_LINK_EXPANSION)])].toSorted();
|
|
89
109
|
//#endregion
|
|
90
|
-
//#region src/
|
|
110
|
+
//#region src/flatten.ts
|
|
91
111
|
/**
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
* The adapter returns an inline link as `{ id, displayText }`, so that is what a record holds
|
|
95
|
-
* everywhere it is read — the store, a list row, a form field. A column takes the id alone, so
|
|
96
|
-
* this is the single definition of the shape a record leaves in, and it belongs at the boundary
|
|
97
|
-
* a record crosses on its way to the server, never on the way into the store.
|
|
112
|
+
* Recursively flatten Fieldset containers into a flat array of non-container fields.
|
|
113
|
+
* Fieldset entries are replaced by their children; all other fields pass through.
|
|
98
114
|
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
115
|
+
* A fieldset is a layout grouping, not a scope: every field inside one is a field of the doctype,
|
|
116
|
+
* with a column of its own and a name a link can bind to. Anything asking "what does this doctype
|
|
117
|
+
* declare" must therefore descend, and the two ways to get that wrong point opposite ways — the
|
|
118
|
+
* SELECT builder would omit real columns, while a validator would report a working declaration as
|
|
119
|
+
* broken.
|
|
103
120
|
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
121
|
+
* Lives here rather than in the adapter because both sides need it: the middleware builds SQL from
|
|
122
|
+
* it, and `DoctypeMeta`'s own validation asks the same question at the load gate. It sat in the
|
|
123
|
+
* adapter while the validator hand-rolled a top-level-only scan, and that is exactly the second
|
|
124
|
+
* failure this comment names — a `displayField` inside a fieldset was rejected at authoring time
|
|
125
|
+
* and would have worked at runtime.
|
|
108
126
|
*
|
|
109
|
-
* A
|
|
110
|
-
*
|
|
127
|
+
* A module of its own, importing nothing at runtime, because callers need the descent without
|
|
128
|
+
* needing the rest of `field.ts` — which defines the Zod schemas, so a runtime edge to it is a
|
|
129
|
+
* runtime edge to Zod. Zod reaching a Nitro SSR entry collides with the `process` Nitro imports
|
|
130
|
+
* there and takes the server down with a `SyntaxError` per request, which no build reports.
|
|
131
|
+
* `field.ts` still calls this and `index.ts` still exports it, so nothing outside moves.
|
|
111
132
|
*
|
|
112
133
|
* @param fields - the doctype's top-level fields
|
|
113
|
-
* @
|
|
114
|
-
* @returns a shallow copy with every inline link reduced to its id
|
|
134
|
+
* @returns every non-container field, fieldset children included
|
|
115
135
|
* @public
|
|
116
136
|
*/
|
|
117
|
-
function
|
|
118
|
-
const
|
|
119
|
-
if (
|
|
120
|
-
|
|
121
|
-
for (const [key, value] of Object.entries(result)) {
|
|
122
|
-
if (!inline.has(key) || value === null || typeof value !== "object" || Array.isArray(value)) continue;
|
|
123
|
-
if ("id" in value) result[key] = value.id;
|
|
124
|
-
}
|
|
137
|
+
function flattenFields(fields) {
|
|
138
|
+
const result = [];
|
|
139
|
+
for (const f of fields) if (f.kind === "fieldset") result.push(...flattenFields(f.schema));
|
|
140
|
+
else result.push(f);
|
|
125
141
|
return result;
|
|
126
142
|
}
|
|
127
143
|
//#endregion
|
|
128
|
-
export {
|
|
144
|
+
export { COMPONENT_PARTS as a, componentParts as c, COMPONENT_LINK_EXPANSION as i, resolveLinkRenderMode as l, CANONICAL_COMPONENTS as n, componentCategory as o, COMPONENT_CATEGORY as r, componentLinkExpansion as s, flattenFields as t };
|
|
129
145
|
|
|
130
|
-
//# sourceMappingURL=
|
|
146
|
+
//# sourceMappingURL=flatten-BaPZLJ2O.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flatten-BaPZLJ2O.js","names":[],"sources":["../src/component-meta.ts","../src/flatten.ts"],"sourcesContent":["/**\n * Semantic category for a rendering component.\n *\n * `component` is the primary field axis, so the runtime consumers that need to know what a field\n * *means* (atable cell formatting / filter widgets, record-default init) derive it from here. This\n * is the single source of \"what kind of value does this component render\", keyed by the canonical\n * registered component names — each consumer maps the category to its own concern (filter widget,\n * default value, …).\n *\n * @public\n */\nexport type ComponentCategory =\n\t| 'text'\n\t| 'number'\n\t| 'boolean'\n\t| 'date'\n\t| 'datetime'\n\t| 'duration'\n\t| 'select'\n\t| 'code'\n\t| 'link'\n\t| 'attach'\n\t| 'quantity'\n\t| 'currency'\n\t| 'semver'\n\n/**\n * Canonical component → semantic category. Only the components Stonecrop ships with appear here;\n * custom/unknown component names have no category and consumers fall back to their default.\n * @public\n */\nexport const COMPONENT_CATEGORY: Record<string, ComponentCategory> = {\n\tATextInput: 'text',\n\tATextboxInput: 'text',\n\tANumericInput: 'number',\n\tACheckbox: 'boolean',\n\tADate: 'date',\n\tADatePicker: 'date',\n\tADateSelection: 'date',\n\tADateTime: 'datetime',\n\tADuration: 'duration',\n\tADateRange: 'date',\n\tADropdown: 'select',\n\tASegmentedControl: 'select',\n\tACodeEditor: 'code',\n\tAFormLink: 'link',\n\tAFileAttach: 'attach',\n\tAQuantityInput: 'quantity',\n\tACurrencyInput: 'currency',\n\tASemverInput: 'semver',\n}\n\n/**\n * Resolve a component's semantic category, or `undefined` for an unknown (custom) component —\n * callers treat that as \"no opinion\" and use their own default.\n * @public\n */\nexport function componentCategory(component?: string): ComponentCategory | undefined {\n\treturn component ? COMPONENT_CATEGORY[component] : undefined\n}\n\n/**\n * Whether a link component expands its target doctype, or renders the link inline.\n *\n * This is the *only* axis the component decides. It deliberately does not choose between an\n * embedded record and an embedded table: `cardinality` states whether the value is a scalar or\n * an array, which is a fact about the data rather than a rendering preference, so a component\n * must not be able to override it (an `AForm` over a `noneOrMany` link would be handed an array\n * it cannot render). Component names encode both axes — `AFormLink`/`ATableLink` are the inline\n * pair, `AForm`/`ATable` the expanding pair — but only the inline/expand half is authoritative.\n *\n * @public\n */\nexport type LinkExpansion = 'inline' | 'expand'\n\n/**\n * Canonical link component → expansion. Only components Stonecrop ships with appear here; an\n * unmapped (custom) component has none, and callers treat that as `expand` — the behaviour that\n * predates this map, so a custom component can never silently collapse a link to a picker.\n * @public\n */\nexport const COMPONENT_LINK_EXPANSION: Record<string, LinkExpansion> = {\n\tAFormLink: 'inline',\n\tAForm: 'expand',\n\tATable: 'expand',\n}\n\n/**\n * Resolve a component's link expansion, or `undefined` for an absent/unmapped component.\n * @public\n */\nexport function componentLinkExpansion(component?: string): LinkExpansion | undefined {\n\treturn component ? COMPONENT_LINK_EXPANSION[component] : undefined\n}\n\n/**\n * The parts of its value each component edits, each held in a field of the record (a field's\n * `parts` names which). A component absent here edits a single value, so its field declares no\n * parts.\n * @public\n */\nexport const COMPONENT_PARTS: Record<string, readonly string[]> = {\n\tAQuantityInput: ['qty', 'uom'],\n\tACurrencyInput: ['amount', 'currency', 'exchangeRate'],\n}\n\n/**\n * Resolve the parts a component edits, or `undefined` for one that edits a single value.\n * @public\n */\nexport function componentParts(component?: string): readonly string[] | undefined {\n\treturn component ? COMPONENT_PARTS[component] : undefined\n}\n\n/**\n * How a link field renders.\n *\n * - `inline` — a scalar id-picker; the target is *not* expanded (the field keeps its own value\n * and carries a `doctype` prop for async display-text resolution and navigation).\n *\n * - `record` — the target doctype is resolved and embedded as a nested form.\n *\n * - `table` — the target doctype is resolved and embedded as a child table.\n *\n * @public\n */\nexport type LinkRenderMode = 'inline' | 'record' | 'table'\n\n/**\n * Decide how a *declared* link (one with a `LinkDeclaration`) renders.\n *\n * Two independent axes: the **component** picks inline vs expand, and when expanding the\n * **cardinality** picks record vs table (many → table). The declaration's component wins over the\n * field's, matching the precedence the resolver already uses for the rendered component.\n *\n * This is the single definition of \"does this link expand\", on both sides of the wire: the client\n * builds its nested schema from it, and the server must still SELECT an `inline` link's FK column.\n * Call it; never re-derive the rule at the call site, or the two will drift and the client will\n * render a table for a column the server never selected.\n *\n * @param link - the link declaration (only `component` and `cardinality` are consulted)\n * @param fieldComponent - the linked field's own `component`, used when the declaration names none\n * @public\n */\nexport function resolveLinkRenderMode(\n\tlink: { component?: string; cardinality?: string },\n\tfieldComponent?: string\n): LinkRenderMode {\n\tif (componentLinkExpansion(link.component ?? fieldComponent) === 'inline') return 'inline'\n\treturn link.cardinality === 'noneOrMany' || link.cardinality === 'atLeastOne' ? 'table' : 'record'\n}\n\n/**\n * Every component Stonecrop ships with that can render a value field, sorted by name.\n *\n * The union of the two maps above is the definition, not a copy of it: a shipped component either\n * categorises a value ({@link COMPONENT_CATEGORY}) or is one of the link containers that has no\n * value of its own ({@link COMPONENT_LINK_EXPANSION}'s `AForm`/`ATable`). `AFieldset` is absent by\n * the same rule — it is a `kind: 'fieldset'` container, so it is never a value field's component.\n *\n * `component` is an **open** axis: any string is valid, and naming a custom component is how an app\n * renders a field Stonecrop ships no widget for. This list is therefore the set to *suggest* to an\n * author, and to check first-party data against — never a set to validate arbitrary input against.\n *\n * @public\n */\nexport const CANONICAL_COMPONENTS: readonly string[] = [\n\t...new Set([...Object.keys(COMPONENT_CATEGORY), ...Object.keys(COMPONENT_LINK_EXPANSION)]),\n].toSorted()\n","import type { DoctypeField, TableField, ValueField } from './field'\n\n/**\n * Recursively flatten Fieldset containers into a flat array of non-container fields.\n * Fieldset entries are replaced by their children; all other fields pass through.\n *\n * A fieldset is a layout grouping, not a scope: every field inside one is a field of the doctype,\n * with a column of its own and a name a link can bind to. Anything asking \"what does this doctype\n * declare\" must therefore descend, and the two ways to get that wrong point opposite ways — the\n * SELECT builder would omit real columns, while a validator would report a working declaration as\n * broken.\n *\n * Lives here rather than in the adapter because both sides need it: the middleware builds SQL from\n * it, and `DoctypeMeta`'s own validation asks the same question at the load gate. It sat in the\n * adapter while the validator hand-rolled a top-level-only scan, and that is exactly the second\n * failure this comment names — a `displayField` inside a fieldset was rejected at authoring time\n * and would have worked at runtime.\n *\n * A module of its own, importing nothing at runtime, because callers need the descent without\n * needing the rest of `field.ts` — which defines the Zod schemas, so a runtime edge to it is a\n * runtime edge to Zod. Zod reaching a Nitro SSR entry collides with the `process` Nitro imports\n * there and takes the server down with a `SyntaxError` per request, which no build reports.\n * `field.ts` still calls this and `index.ts` still exports it, so nothing outside moves.\n *\n * @param fields - the doctype's top-level fields\n * @returns every non-container field, fieldset children included\n * @public\n */\nexport function flattenFields(fields: readonly DoctypeField[]): (ValueField | TableField)[] {\n\tconst result: (ValueField | TableField)[] = []\n\tfor (const f of fields) {\n\t\tif (f.kind === 'fieldset') {\n\t\t\tresult.push(...flattenFields(f.schema))\n\t\t} else {\n\t\t\tresult.push(f)\n\t\t}\n\t}\n\treturn result\n}\n"],"mappings":";;;;;;AA+BA,IAAa,qBAAwD;CACpE,YAAY;CACZ,eAAe;CACf,eAAe;CACf,WAAW;CACX,OAAO;CACP,aAAa;CACb,gBAAgB;CAChB,WAAW;CACX,WAAW;CACX,YAAY;CACZ,WAAW;CACX,mBAAmB;CACnB,aAAa;CACb,WAAW;CACX,aAAa;CACb,gBAAgB;CAChB,gBAAgB;CAChB,cAAc;AACf;;;;;;AAOA,SAAgB,kBAAkB,WAAmD;CACpF,OAAO,YAAY,mBAAmB,aAAa,KAAA;AACpD;;;;;;;AAsBA,IAAa,2BAA0D;CACtE,WAAW;CACX,OAAO;CACP,QAAQ;AACT;;;;;AAMA,SAAgB,uBAAuB,WAA+C;CACrF,OAAO,YAAY,yBAAyB,aAAa,KAAA;AAC1D;;;;;;;AAQA,IAAa,kBAAqD;CACjE,gBAAgB,CAAC,OAAO,KAAK;CAC7B,gBAAgB;EAAC;EAAU;EAAY;CAAc;AACtD;;;;;AAMA,SAAgB,eAAe,WAAmD;CACjF,OAAO,YAAY,gBAAgB,aAAa,KAAA;AACjD;;;;;;;;;;;;;;;;;AAgCA,SAAgB,sBACf,MACA,gBACiB;CACjB,IAAI,uBAAuB,KAAK,aAAa,cAAc,MAAM,UAAU,OAAO;CAClF,OAAO,KAAK,gBAAgB,gBAAgB,KAAK,gBAAgB,eAAe,UAAU;AAC3F;;;;;;;;;;;;;;;AAgBA,IAAa,uBAA0C,CACtD,mBAAG,IAAI,IAAI,CAAC,GAAG,OAAO,KAAK,kBAAkB,GAAG,GAAG,OAAO,KAAK,wBAAwB,CAAC,CAAC,CAC1F,CAAC,CAAC,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AC5IX,SAAgB,cAAc,QAA8D;CAC3F,MAAM,SAAsC,CAAC;CAC7C,KAAK,MAAM,KAAK,QACf,IAAI,EAAE,SAAS,YACd,OAAO,KAAK,GAAG,cAAc,EAAE,MAAM,CAAC;MAEtC,OAAO,KAAK,CAAC;CAGf,OAAO;AACR"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { A as TableFieldSchema, C as WorkflowMeta, D as DoctypeFieldSchema, E as linkDisplayFieldname, F as getRecordIdentity, I as inferFieldKind, L as normalizeFieldKind, M as getDisplayField, N as getPrimaryKeyField, O as FieldsetFieldSchema, P as getRecordIdField, R as stripFieldKind, S as WorkflowLayout, T as isActionAllowedInState, _ as validateDoctype, a as aggregateDoctypeName, b as LINK_DISPLAY_SUFFIX, c as classifyFieldType, d as GQL_SCALAR_MAP, f as INTERNAL_SCALARS, g as parseField, h as parseDoctype, j as ValueFieldSchema, k as INTROSPECTED_IDENTITY_PROPS, l as defaultIsEntityField, m as buildScalarMap, n as formatDoctypeDrift, o as buildAggregateDoctype, p as WELL_KNOWN_SCALARS, r as mergeIntrospectedDoctype, s as planGeneration, t as convertGraphQLSchema, u as defaultIsEntityType, v as validateField, w as getDoctypeSlug, x as TriggerDefinition, y as ActionDefinition, z as TableViewConfig } from "./converter-
|
|
2
|
-
import { a as
|
|
3
|
-
import {
|
|
1
|
+
import { A as TableFieldSchema, C as WorkflowMeta, D as DoctypeFieldSchema, E as linkDisplayFieldname, F as getRecordIdentity, I as inferFieldKind, L as normalizeFieldKind, M as getDisplayField, N as getPrimaryKeyField, O as FieldsetFieldSchema, P as getRecordIdField, R as stripFieldKind, S as WorkflowLayout, T as isActionAllowedInState, _ as validateDoctype, a as aggregateDoctypeName, b as LINK_DISPLAY_SUFFIX, c as classifyFieldType, d as GQL_SCALAR_MAP, f as INTERNAL_SCALARS, g as parseField, h as parseDoctype, j as ValueFieldSchema, k as INTROSPECTED_IDENTITY_PROPS, l as defaultIsEntityField, m as buildScalarMap, n as formatDoctypeDrift, o as buildAggregateDoctype, p as WELL_KNOWN_SCALARS, r as mergeIntrospectedDoctype, s as planGeneration, t as convertGraphQLSchema, u as defaultIsEntityType, v as validateField, w as getDoctypeSlug, x as TriggerDefinition, y as ActionDefinition, z as TableViewConfig } from "./converter-BAIfP9rG.js";
|
|
2
|
+
import { a as COMPONENT_PARTS, c as componentParts, i as COMPONENT_LINK_EXPANSION, l as resolveLinkRenderMode, n as CANONICAL_COMPONENTS, o as componentCategory, r as COMPONENT_CATEGORY, s as componentLinkExpansion, t as flattenFields } from "./flatten-BaPZLJ2O.js";
|
|
3
|
+
import { partsPatch, readParts, unwrapInlineLinks } from "./record.js";
|
|
4
4
|
import { camelToLabel, camelToSnake, pascalToSnake, snakeToCamel, snakeToLabel, toPascalCase, toSlug } from "./naming.js";
|
|
5
5
|
//#region src/badge.ts
|
|
6
6
|
var BADGE_VARIANTS = /* @__PURE__ */ new Set([
|
|
@@ -133,6 +133,6 @@ function hasBadgeOptions(options) {
|
|
|
133
133
|
return isSelectChoiceMap(options);
|
|
134
134
|
}
|
|
135
135
|
//#endregion
|
|
136
|
-
export { ActionDefinition, CANONICAL_COMPONENTS, COMPONENT_CATEGORY, COMPONENT_LINK_EXPANSION, DoctypeFieldSchema, FieldsetFieldSchema, GQL_SCALAR_MAP, INTERNAL_SCALARS, INTROSPECTED_IDENTITY_PROPS, LINK_DISPLAY_SUFFIX, TableFieldSchema, TableViewConfig, TriggerDefinition, ValueFieldSchema, WELL_KNOWN_SCALARS, WorkflowLayout, WorkflowMeta, aggregateDoctypeName, buildAggregateDoctype, buildScalarMap, camelToLabel, camelToSnake, classifyFieldType, componentCategory, componentLinkExpansion, convertGraphQLSchema, defaultIsEntityField, defaultIsEntityType, flattenFields, formatDoctypeDrift, getDisplayField, getDoctypeSlug, getPrimaryKeyField, getRecordIdField, getRecordIdentity, hasBadgeOptions, inferFieldKind, isActionAllowedInState, isBadgeDescriptor, isSelectChoiceMap, isSelectOptions, linkDisplayFieldname, lookupBadge, mergeIntrospectedDoctype, normalizeFieldKind, parseDoctype, parseField, pascalToSnake, planGeneration, resolveLinkRenderMode, selectChoices, snakeToCamel, snakeToLabel, stripFieldKind, toPascalCase, toSlug, unwrapInlineLinks, validateDoctype, validateField };
|
|
136
|
+
export { ActionDefinition, CANONICAL_COMPONENTS, COMPONENT_CATEGORY, COMPONENT_LINK_EXPANSION, COMPONENT_PARTS, DoctypeFieldSchema, FieldsetFieldSchema, GQL_SCALAR_MAP, INTERNAL_SCALARS, INTROSPECTED_IDENTITY_PROPS, LINK_DISPLAY_SUFFIX, TableFieldSchema, TableViewConfig, TriggerDefinition, ValueFieldSchema, WELL_KNOWN_SCALARS, WorkflowLayout, WorkflowMeta, aggregateDoctypeName, buildAggregateDoctype, buildScalarMap, camelToLabel, camelToSnake, classifyFieldType, componentCategory, componentLinkExpansion, componentParts, convertGraphQLSchema, defaultIsEntityField, defaultIsEntityType, flattenFields, formatDoctypeDrift, getDisplayField, getDoctypeSlug, getPrimaryKeyField, getRecordIdField, getRecordIdentity, hasBadgeOptions, inferFieldKind, isActionAllowedInState, isBadgeDescriptor, isSelectChoiceMap, isSelectOptions, linkDisplayFieldname, lookupBadge, mergeIntrospectedDoctype, normalizeFieldKind, parseDoctype, parseField, partsPatch, pascalToSnake, planGeneration, readParts, resolveLinkRenderMode, selectChoices, snakeToCamel, snakeToLabel, stripFieldKind, toPascalCase, toSlug, unwrapInlineLinks, validateDoctype, validateField };
|
|
137
137
|
|
|
138
138
|
//# sourceMappingURL=index.js.map
|
package/dist/record.js
CHANGED
|
@@ -1,2 +1,69 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
|
|
1
|
+
import { s as componentLinkExpansion, t as flattenFields } from "./flatten-BaPZLJ2O.js";
|
|
2
|
+
//#region src/record.ts
|
|
3
|
+
/**
|
|
4
|
+
* Reduce a record's *inline* link values to the ids that get persisted.
|
|
5
|
+
*
|
|
6
|
+
* The adapter returns an inline link as `{ id, displayText }`, so that is what a record holds
|
|
7
|
+
* everywhere it is read — the store, a list row, a form field. A column takes the id alone, so
|
|
8
|
+
* this is the single definition of the shape a record leaves in, and it belongs at the boundary
|
|
9
|
+
* a record crosses on its way to the server, never on the way into the store.
|
|
10
|
+
*
|
|
11
|
+
* Doing it on the way in destroys the text the adapter looked up: nothing else holds it, so the
|
|
12
|
+
* field that resolved a moment ago renders its raw id, and the same record then renders
|
|
13
|
+
* differently depending on whether anything had edited the form yet. That is the bug this exists
|
|
14
|
+
* to prevent, and its damage is a wrong render, not a throw.
|
|
15
|
+
*
|
|
16
|
+
* Only *inline* links may be reduced. An inline link's value is indistinguishable by inspection
|
|
17
|
+
* from an expanded one (`{ id, ...the whole target record }`), so `component` — which states
|
|
18
|
+
* which of the two a field is — is what tells them apart, via {@link componentLinkExpansion}.
|
|
19
|
+
* Reducing an expanded link would send the id in place of the record.
|
|
20
|
+
*
|
|
21
|
+
* A fieldset's children are the record's own keys, since a fieldset is layout, so they are
|
|
22
|
+
* reduced where every other field is.
|
|
23
|
+
*
|
|
24
|
+
* @param fields - the doctype's top-level fields
|
|
25
|
+
* @param record - the record to reduce; not mutated
|
|
26
|
+
* @returns a shallow copy with every inline link reduced to its id
|
|
27
|
+
* @public
|
|
28
|
+
*/
|
|
29
|
+
function unwrapInlineLinks(fields, record) {
|
|
30
|
+
const inline = new Set(flattenFields(fields).filter((field) => field.kind === "field" && Boolean(field.doctype)).filter((field) => componentLinkExpansion(field.component) === "inline").map((field) => field.fieldname));
|
|
31
|
+
if (inline.size === 0) return record;
|
|
32
|
+
const result = { ...record };
|
|
33
|
+
for (const [key, value] of Object.entries(result)) {
|
|
34
|
+
if (!inline.has(key) || value === null || typeof value !== "object" || Array.isArray(value)) continue;
|
|
35
|
+
if ("id" in value) result[key] = value.id;
|
|
36
|
+
}
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* A field's value, read part by part from the fields its `parts` names.
|
|
41
|
+
*
|
|
42
|
+
* @param parts - the field's `parts`: the field holding each part, keyed by part
|
|
43
|
+
* @param record - the record holding those fields
|
|
44
|
+
* @returns the value, keyed by part
|
|
45
|
+
* @public
|
|
46
|
+
*/
|
|
47
|
+
function readParts(parts, record) {
|
|
48
|
+
return Object.fromEntries(Object.entries(parts).map(([part, fieldname]) => [part, record[fieldname]]));
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The fields to set after a field's component edits its value: one per part that changed. A part
|
|
52
|
+
* left alone keeps exactly what the record holds, and anything the component derives (a stock
|
|
53
|
+
* quantity, a conversion factor) is no part, so it is never written.
|
|
54
|
+
*
|
|
55
|
+
* @param parts - the field's `parts`: the field holding each part, keyed by part
|
|
56
|
+
* @param record - the record before the edit
|
|
57
|
+
* @param value - the component's edited value, keyed by part
|
|
58
|
+
* @returns the changed fields and their new values
|
|
59
|
+
* @public
|
|
60
|
+
*/
|
|
61
|
+
function partsPatch(parts, record, value) {
|
|
62
|
+
const patch = {};
|
|
63
|
+
for (const [part, fieldname] of Object.entries(parts)) if (!Object.is(value[part], record[fieldname])) patch[fieldname] = value[part];
|
|
64
|
+
return patch;
|
|
65
|
+
}
|
|
66
|
+
//#endregion
|
|
67
|
+
export { partsPatch, readParts, unwrapInlineLinks };
|
|
68
|
+
|
|
69
|
+
//# sourceMappingURL=record.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"record.js","names":[],"sources":["../src/record.ts"],"sourcesContent":["import { componentLinkExpansion } from './component-meta'\nimport type { DoctypeField } from './field'\nimport { flattenFields } from './flatten'\n\n/**\n * Reduce a record's *inline* link values to the ids that get persisted.\n *\n * The adapter returns an inline link as `{ id, displayText }`, so that is what a record holds\n * everywhere it is read — the store, a list row, a form field. A column takes the id alone, so\n * this is the single definition of the shape a record leaves in, and it belongs at the boundary\n * a record crosses on its way to the server, never on the way into the store.\n *\n * Doing it on the way in destroys the text the adapter looked up: nothing else holds it, so the\n * field that resolved a moment ago renders its raw id, and the same record then renders\n * differently depending on whether anything had edited the form yet. That is the bug this exists\n * to prevent, and its damage is a wrong render, not a throw.\n *\n * Only *inline* links may be reduced. An inline link's value is indistinguishable by inspection\n * from an expanded one (`{ id, ...the whole target record }`), so `component` — which states\n * which of the two a field is — is what tells them apart, via {@link componentLinkExpansion}.\n * Reducing an expanded link would send the id in place of the record.\n *\n * A fieldset's children are the record's own keys, since a fieldset is layout, so they are\n * reduced where every other field is.\n *\n * @param fields - the doctype's top-level fields\n * @param record - the record to reduce; not mutated\n * @returns a shallow copy with every inline link reduced to its id\n * @public\n */\nexport function unwrapInlineLinks(fields: readonly DoctypeField[], record: Record<string, any>): Record<string, any> {\n\tconst inline = new Set(\n\t\tflattenFields(fields)\n\t\t\t.filter(field => field.kind === 'field' && Boolean(field.doctype))\n\t\t\t.filter(field => componentLinkExpansion(field.component) === 'inline')\n\t\t\t.map(field => field.fieldname)\n\t)\n\tif (inline.size === 0) return record\n\n\tconst result: Record<string, any> = { ...record }\n\tfor (const [key, value] of Object.entries(result)) {\n\t\tif (!inline.has(key) || value === null || typeof value !== 'object' || Array.isArray(value)) continue\n\t\t// `'id' in value` rather than a truthiness test: an inline link that was never resolved\n\t\t// is still a bare scalar, and reducing it a second time would be a no-op at best.\n\t\tif ('id' in value) result[key] = value.id\n\t}\n\treturn result\n}\n\n/**\n * A field's value, read part by part from the fields its `parts` names.\n *\n * @param parts - the field's `parts`: the field holding each part, keyed by part\n * @param record - the record holding those fields\n * @returns the value, keyed by part\n * @public\n */\nexport function readParts(\n\tparts: Readonly<Record<string, string>>,\n\trecord: Readonly<Record<string, unknown>>\n): Record<string, unknown> {\n\treturn Object.fromEntries(Object.entries(parts).map(([part, fieldname]) => [part, record[fieldname]]))\n}\n\n/**\n * The fields to set after a field's component edits its value: one per part that changed. A part\n * left alone keeps exactly what the record holds, and anything the component derives (a stock\n * quantity, a conversion factor) is no part, so it is never written.\n *\n * @param parts - the field's `parts`: the field holding each part, keyed by part\n * @param record - the record before the edit\n * @param value - the component's edited value, keyed by part\n * @returns the changed fields and their new values\n * @public\n */\nexport function partsPatch(\n\tparts: Readonly<Record<string, string>>,\n\trecord: Readonly<Record<string, unknown>>,\n\tvalue: Readonly<Record<string, unknown>>\n): Record<string, unknown> {\n\tconst patch: Record<string, unknown> = {}\n\tfor (const [part, fieldname] of Object.entries(parts)) {\n\t\tif (!Object.is(value[part], record[fieldname])) patch[fieldname] = value[part]\n\t}\n\treturn patch\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,SAAgB,kBAAkB,QAAiC,QAAkD;CACpH,MAAM,SAAS,IAAI,IAClB,cAAc,MAAM,CAAC,CACnB,QAAO,UAAS,MAAM,SAAS,WAAW,QAAQ,MAAM,OAAO,CAAC,CAAC,CACjE,QAAO,UAAS,uBAAuB,MAAM,SAAS,MAAM,QAAQ,CAAC,CACrE,KAAI,UAAS,MAAM,SAAS,CAC/B;CACA,IAAI,OAAO,SAAS,GAAG,OAAO;CAE9B,MAAM,SAA8B,EAAE,GAAG,OAAO;CAChD,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,MAAM,GAAG;EAClD,IAAI,CAAC,OAAO,IAAI,GAAG,KAAK,UAAU,QAAQ,OAAO,UAAU,YAAY,MAAM,QAAQ,KAAK,GAAG;EAG7F,IAAI,QAAQ,OAAO,OAAO,OAAO,MAAM;CACxC;CACA,OAAO;AACR;;;;;;;;;AAUA,SAAgB,UACf,OACA,QAC0B;CAC1B,OAAO,OAAO,YAAY,OAAO,QAAQ,KAAK,CAAC,CAAC,KAAK,CAAC,MAAM,eAAe,CAAC,MAAM,OAAO,UAAU,CAAC,CAAC;AACtG;;;;;;;;;;;;AAaA,SAAgB,WACf,OACA,QACA,OAC0B;CAC1B,MAAM,QAAiC,CAAC;CACxC,KAAK,MAAM,CAAC,MAAM,cAAc,OAAO,QAAQ,KAAK,GACnD,IAAI,CAAC,OAAO,GAAG,MAAM,OAAO,OAAO,UAAU,GAAG,MAAM,aAAa,MAAM;CAE1E,OAAO;AACR"}
|
package/dist/schema.d.ts
CHANGED
|
@@ -213,10 +213,10 @@ export declare const CANONICAL_COMPONENTS: readonly string[];
|
|
|
213
213
|
* @public
|
|
214
214
|
*/
|
|
215
215
|
export declare const Cardinality: z.ZodEnum<{
|
|
216
|
-
atMostOne: "atMostOne";
|
|
217
|
-
one: "one";
|
|
218
216
|
noneOrMany: "noneOrMany";
|
|
219
217
|
atLeastOne: "atLeastOne";
|
|
218
|
+
atMostOne: "atMostOne";
|
|
219
|
+
one: "one";
|
|
220
220
|
}>;
|
|
221
221
|
|
|
222
222
|
/**
|
|
@@ -430,6 +430,14 @@ export declare const COMPONENT_CATEGORY: Record<string, ComponentCategory>;
|
|
|
430
430
|
*/
|
|
431
431
|
export declare const COMPONENT_LINK_EXPANSION: Record<string, LinkExpansion>;
|
|
432
432
|
|
|
433
|
+
/**
|
|
434
|
+
* The parts of its value each component edits, each held in a field of the record (a field's
|
|
435
|
+
* `parts` names which). A component absent here edits a single value, so its field declares no
|
|
436
|
+
* parts.
|
|
437
|
+
* @public
|
|
438
|
+
*/
|
|
439
|
+
export declare const COMPONENT_PARTS: Record<string, readonly string[]>;
|
|
440
|
+
|
|
433
441
|
/**
|
|
434
442
|
* Semantic category for a rendering component.
|
|
435
443
|
*
|
|
@@ -456,6 +464,12 @@ export declare function componentCategory(component?: string): ComponentCategory
|
|
|
456
464
|
*/
|
|
457
465
|
export declare function componentLinkExpansion(component?: string): LinkExpansion | undefined;
|
|
458
466
|
|
|
467
|
+
/**
|
|
468
|
+
* Resolve the parts a component edits, or `undefined` for one that edits a single value.
|
|
469
|
+
* @public
|
|
470
|
+
*/
|
|
471
|
+
export declare function componentParts(component?: string): readonly string[] | undefined;
|
|
472
|
+
|
|
459
473
|
/**
|
|
460
474
|
* Output of GraphQL schema conversion — one per entity type.
|
|
461
475
|
*
|
|
@@ -668,10 +682,10 @@ export declare const DoctypeMeta: z.ZodObject<{
|
|
|
668
682
|
links: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
669
683
|
target: z.ZodString;
|
|
670
684
|
cardinality: z.ZodEnum<{
|
|
671
|
-
atMostOne: "atMostOne";
|
|
672
|
-
one: "one";
|
|
673
685
|
noneOrMany: "noneOrMany";
|
|
674
686
|
atLeastOne: "atLeastOne";
|
|
687
|
+
atMostOne: "atMostOne";
|
|
688
|
+
one: "one";
|
|
675
689
|
}>;
|
|
676
690
|
backlink: z.ZodOptional<z.ZodString>;
|
|
677
691
|
component: z.ZodOptional<z.ZodString>;
|
|
@@ -1402,10 +1416,10 @@ export declare const LINK_DISPLAY_SUFFIX = "__display";
|
|
|
1402
1416
|
export declare const LinkDeclaration: z.ZodObject<{
|
|
1403
1417
|
target: z.ZodString;
|
|
1404
1418
|
cardinality: z.ZodEnum<{
|
|
1405
|
-
atMostOne: "atMostOne";
|
|
1406
|
-
one: "one";
|
|
1407
1419
|
noneOrMany: "noneOrMany";
|
|
1408
1420
|
atLeastOne: "atLeastOne";
|
|
1421
|
+
atMostOne: "atMostOne";
|
|
1422
|
+
one: "one";
|
|
1409
1423
|
}>;
|
|
1410
1424
|
backlink: z.ZodOptional<z.ZodString>;
|
|
1411
1425
|
component: z.ZodOptional<z.ZodString>;
|
|
@@ -1555,6 +1569,19 @@ export declare function parseDoctype(data: unknown): DoctypeMeta;
|
|
|
1555
1569
|
*/
|
|
1556
1570
|
export declare function parseField(data: unknown): DoctypeField;
|
|
1557
1571
|
|
|
1572
|
+
/**
|
|
1573
|
+
* The fields to set after a field's component edits its value: one per part that changed. A part
|
|
1574
|
+
* left alone keeps exactly what the record holds, and anything the component derives (a stock
|
|
1575
|
+
* quantity, a conversion factor) is no part, so it is never written.
|
|
1576
|
+
*
|
|
1577
|
+
* @param parts - the field's `parts`: the field holding each part, keyed by part
|
|
1578
|
+
* @param record - the record before the edit
|
|
1579
|
+
* @param value - the component's edited value, keyed by part
|
|
1580
|
+
* @returns the changed fields and their new values
|
|
1581
|
+
* @public
|
|
1582
|
+
*/
|
|
1583
|
+
export declare function partsPatch(parts: Readonly<Record<string, string>>, record: Readonly<Record<string, unknown>>, value: Readonly<Record<string, unknown>>): Record<string, unknown>;
|
|
1584
|
+
|
|
1558
1585
|
/**
|
|
1559
1586
|
* Convert PascalCase to snake_case (e.g., for deriving table names from type names)
|
|
1560
1587
|
* @param pascal - PascalCase string
|
|
@@ -1586,6 +1613,16 @@ export declare function pascalToSnake(pascal: string): string;
|
|
|
1586
1613
|
*/
|
|
1587
1614
|
export declare function planGeneration(entities: readonly ConvertedGraphQLDoctype[], options?: GenerationPlanOptions): GenerationPlanEntry[];
|
|
1588
1615
|
|
|
1616
|
+
/**
|
|
1617
|
+
* A field's value, read part by part from the fields its `parts` names.
|
|
1618
|
+
*
|
|
1619
|
+
* @param parts - the field's `parts`: the field holding each part, keyed by part
|
|
1620
|
+
* @param record - the record holding those fields
|
|
1621
|
+
* @returns the value, keyed by part
|
|
1622
|
+
* @public
|
|
1623
|
+
*/
|
|
1624
|
+
export declare function readParts(parts: Readonly<Record<string, string>>, record: Readonly<Record<string, unknown>>): Record<string, unknown>;
|
|
1625
|
+
|
|
1589
1626
|
/**
|
|
1590
1627
|
* Decide how a *declared* link (one with a `LinkDeclaration`) renders.
|
|
1591
1628
|
*
|
|
@@ -1946,6 +1983,13 @@ export declare interface ValueField {
|
|
|
1946
1983
|
/** Type-specific options: Select choices, Decimal precision config, etc. A link's target is not
|
|
1947
1984
|
* here — it is `doctype`. */
|
|
1948
1985
|
options?: FieldOptions;
|
|
1986
|
+
/**
|
|
1987
|
+
* For a component that edits a value made of several parts, the field holding each part, keyed
|
|
1988
|
+
* by part: `{ qty: 'quantity', uom: 'uom' }` for `AQuantityInput`. One part is this field itself;
|
|
1989
|
+
* the others are fields of the same record, which several fields may share (an order's totals
|
|
1990
|
+
* share its currency). The component reads each part from its field and writes it back there.
|
|
1991
|
+
*/
|
|
1992
|
+
parts?: Record<string, string>;
|
|
1949
1993
|
/** Whether the field is required */
|
|
1950
1994
|
required?: boolean;
|
|
1951
1995
|
/** Whether the field is read-only */
|
|
@@ -1999,6 +2043,7 @@ export declare const ValueFieldSchema: z.ZodObject<{
|
|
|
1999
2043
|
display: "display";
|
|
2000
2044
|
}>>;
|
|
2001
2045
|
options: z.ZodOptional<z.ZodUnion<readonly [z.ZodArray<z.ZodString>, z.ZodRecord<z.ZodString, z.ZodUnknown>]>>;
|
|
2046
|
+
parts: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
2002
2047
|
required: z.ZodOptional<z.ZodBoolean>;
|
|
2003
2048
|
readOnly: z.ZodOptional<z.ZodBoolean>;
|
|
2004
2049
|
hidden: z.ZodOptional<z.ZodBoolean>;
|
|
@@ -2007,10 +2052,10 @@ export declare const ValueFieldSchema: z.ZodObject<{
|
|
|
2007
2052
|
errorMessage: z.ZodString;
|
|
2008
2053
|
}, z.core.$loose>>;
|
|
2009
2054
|
cardinality: z.ZodOptional<z.ZodEnum<{
|
|
2010
|
-
atMostOne: "atMostOne";
|
|
2011
|
-
one: "one";
|
|
2012
2055
|
noneOrMany: "noneOrMany";
|
|
2013
2056
|
atLeastOne: "atLeastOne";
|
|
2057
|
+
atMostOne: "atMostOne";
|
|
2058
|
+
one: "one";
|
|
2014
2059
|
}>>;
|
|
2015
2060
|
source: z.ZodOptional<z.ZodLiteral<"introspected">>;
|
|
2016
2061
|
config: z.ZodOptional<z.ZodObject<{
|