@stonecrop/schema 0.30.0 → 0.32.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -10
- package/dist/cli.js +194 -121
- package/dist/cli.js.map +1 -1
- package/dist/converter-CLwduvT_.js +2102 -0
- package/dist/converter-CLwduvT_.js.map +1 -0
- package/dist/flatten-Bx2cfvw3.js +37 -0
- package/dist/flatten-Bx2cfvw3.js.map +1 -0
- package/dist/index.js +123 -117
- package/dist/index.js.map +1 -1
- package/dist/record-BQOOi83C.js +134 -0
- package/dist/record-BQOOi83C.js.map +1 -0
- package/dist/record.js +2 -6
- package/dist/tsdoc-metadata.json +1 -1
- package/package.json +34 -18
- package/dist/flatten-C1MjkzFh.js +0 -10
- package/dist/flatten-C1MjkzFh.js.map +0 -1
- package/dist/record-Bc0lI9Rq.js +0 -61
- package/dist/record-Bc0lI9Rq.js.map +0 -1
- package/dist/record.js.map +0 -1
- package/dist/schema.tsbuildinfo +0 -1
- package/dist/src/badge.d.ts +0 -74
- package/dist/src/badge.d.ts.map +0 -1
- package/dist/src/badge.js +0 -158
- package/dist/src/cli.d.ts +0 -3
- package/dist/src/cli.d.ts.map +0 -1
- package/dist/src/cli.js +0 -292
- package/dist/src/column-schema.d.ts +0 -163
- package/dist/src/column-schema.d.ts.map +0 -1
- package/dist/src/column-schema.js +0 -0
- package/dist/src/component-meta.d.ts +0 -96
- package/dist/src/component-meta.d.ts.map +0 -1
- package/dist/src/component-meta.js +0 -88
- package/dist/src/converter/aggregate.d.ts +0 -127
- package/dist/src/converter/aggregate.d.ts.map +0 -1
- package/dist/src/converter/aggregate.js +0 -235
- package/dist/src/converter/authored.d.ts +0 -43
- package/dist/src/converter/authored.d.ts.map +0 -1
- package/dist/src/converter/authored.js +0 -52
- package/dist/src/converter/heuristics.d.ts +0 -60
- package/dist/src/converter/heuristics.d.ts.map +0 -1
- package/dist/src/converter/heuristics.js +0 -304
- package/dist/src/converter/index.d.ts +0 -51
- package/dist/src/converter/index.d.ts.map +0 -1
- package/dist/src/converter/index.js +0 -195
- package/dist/src/converter/merge.d.ts +0 -102
- package/dist/src/converter/merge.d.ts.map +0 -1
- package/dist/src/converter/merge.js +0 -136
- package/dist/src/converter/scalars.d.ts +0 -46
- package/dist/src/converter/scalars.d.ts.map +0 -1
- package/dist/src/converter/scalars.js +0 -83
- package/dist/src/converter/types.d.ts +0 -157
- package/dist/src/converter/types.d.ts.map +0 -1
- package/dist/src/converter/types.js +0 -5
- package/dist/src/doctype.d.ts +0 -516
- package/dist/src/doctype.d.ts.map +0 -1
- package/dist/src/doctype.js +0 -343
- package/dist/src/field.d.ts +0 -423
- package/dist/src/field.d.ts.map +0 -1
- package/dist/src/field.js +0 -378
- package/dist/src/flatten.d.ts +0 -29
- package/dist/src/flatten.d.ts.map +0 -1
- package/dist/src/flatten.js +0 -38
- package/dist/src/index.d.ts +0 -16
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/index.js +0 -20
- package/dist/src/mode.d.ts +0 -15
- package/dist/src/mode.d.ts.map +0 -1
- package/dist/src/mode.js +0 -0
- package/dist/src/naming.d.ts +0 -80
- package/dist/src/naming.d.ts.map +0 -1
- package/dist/src/naming.js +0 -106
- package/dist/src/record.d.ts +0 -29
- package/dist/src/record.d.ts.map +0 -1
- package/dist/src/record.js +0 -55
- package/dist/src/table.d.ts +0 -33
- package/dist/src/table.d.ts.map +0 -1
- package/dist/src/table.js +0 -25
- package/dist/src/validation.d.ts +0 -54
- package/dist/src/validation.d.ts.map +0 -1
- package/dist/src/validation.js +0 -60
- package/dist/validation-C9P__pRF.js +0 -994
- package/dist/validation-C9P__pRF.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,131 +1,137 @@
|
|
|
1
|
-
import { A as
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { A as snakeToCamel, B as getPrimaryKeyField, C as WorkflowMeta, D as camelToLabel, E as linkDisplayFieldname, F as FieldsetFieldSchema, G as stripFieldKind, H as getRecordIdentity, I as INTROSPECTED_IDENTITY_PROPS, K as TableViewConfig, L as TableFieldSchema, M as toPascalCase, N as toSlug, O as camelToSnake, P as DoctypeFieldSchema, R as ValueFieldSchema, S as WorkflowLayout, T as isActionAllowedInState, U as inferFieldKind, V as getRecordIdField, W as normalizeFieldKind, _ 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 snakeToLabel, k as pascalToSnake, 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 getDisplayField } from "./converter-CLwduvT_.js";
|
|
2
|
+
import { a as componentCategory, i as COMPONENT_LINK_EXPANSION, n as CANONICAL_COMPONENTS, o as componentLinkExpansion, r as COMPONENT_CATEGORY, s as resolveLinkRenderMode, t as unwrapInlineLinks } from "./record-BQOOi83C.js";
|
|
3
|
+
import { t as flattenFields } from "./flatten-Bx2cfvw3.js";
|
|
4
|
+
//#region src/badge.ts
|
|
5
|
+
var BADGE_VARIANTS = /* @__PURE__ */ new Set([
|
|
6
|
+
"neutral",
|
|
7
|
+
"success",
|
|
8
|
+
"warning",
|
|
9
|
+
"danger",
|
|
10
|
+
"brand"
|
|
11
|
+
]);
|
|
12
|
+
var BADGE_SPEC_OBJECT_KEYS = /* @__PURE__ */ new Set([
|
|
13
|
+
"variant",
|
|
14
|
+
"color",
|
|
15
|
+
"label"
|
|
16
|
+
]);
|
|
17
|
+
function isOptionsRecord(options) {
|
|
18
|
+
return !Array.isArray(options);
|
|
7
19
|
}
|
|
8
|
-
function
|
|
9
|
-
|
|
20
|
+
function isBadgeVariant(value) {
|
|
21
|
+
return typeof value === "string" && BADGE_VARIANTS.has(value);
|
|
10
22
|
}
|
|
11
|
-
function
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
23
|
+
function isBadgeSpecObject(value) {
|
|
24
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) return false;
|
|
25
|
+
for (const key of Object.keys(value)) if (!BADGE_SPEC_OBJECT_KEYS.has(key)) return false;
|
|
26
|
+
const obj = value;
|
|
27
|
+
if (obj.variant !== void 0 && !isBadgeVariant(obj.variant)) return false;
|
|
28
|
+
if (obj.color !== void 0 && typeof obj.color !== "string") return false;
|
|
29
|
+
if (obj.label !== void 0 && typeof obj.label !== "string") return false;
|
|
30
|
+
return true;
|
|
17
31
|
}
|
|
18
|
-
function
|
|
19
|
-
|
|
32
|
+
function isBadgeSpec(value) {
|
|
33
|
+
return isBadgeVariant(value) || isBadgeSpecObject(value);
|
|
20
34
|
}
|
|
21
|
-
|
|
22
|
-
|
|
35
|
+
/**
|
|
36
|
+
* Narrows an options record to the structured `{ choices, badges }` form. A type predicate rather
|
|
37
|
+
* than a cast: `SelectOptions` requires `choices`, so asserting into it trips `no-unsafe-type-assertion`.
|
|
38
|
+
*/
|
|
39
|
+
function isStructuredSelectOptions(options) {
|
|
40
|
+
return Array.isArray(options.choices);
|
|
23
41
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
42
|
+
/**
|
|
43
|
+
* True when `value` is a resolved badge descriptor for ACell / ADropdown.
|
|
44
|
+
* @public
|
|
45
|
+
*/
|
|
46
|
+
function isBadgeDescriptor(value) {
|
|
47
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) return false;
|
|
48
|
+
const obj = value;
|
|
49
|
+
if (typeof obj.label !== "string") return false;
|
|
50
|
+
if (obj.variant !== void 0 && !isBadgeVariant(obj.variant)) return false;
|
|
51
|
+
if (obj.color !== void 0 && typeof obj.color !== "string") return false;
|
|
52
|
+
return true;
|
|
28
53
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
54
|
+
/**
|
|
55
|
+
* True when `options` is a Select choice map (`{ Open: "warning", ... }` or
|
|
56
|
+
* `{ choices: [...], badges: {...} }`), not a quantity/currency/code config bag.
|
|
57
|
+
* @public
|
|
58
|
+
*/
|
|
59
|
+
function isSelectChoiceMap(options) {
|
|
60
|
+
if (options === void 0 || Array.isArray(options) || !isOptionsRecord(options)) return false;
|
|
61
|
+
if (isStructuredSelectOptions(options)) {
|
|
62
|
+
const badges = options.badges;
|
|
63
|
+
if (badges === void 0) return false;
|
|
64
|
+
return Object.values(badges).every(isBadgeSpec);
|
|
65
|
+
}
|
|
66
|
+
const entries = Object.entries(options);
|
|
67
|
+
if (entries.length === 0) return false;
|
|
68
|
+
return entries.every(([, value]) => isBadgeSpec(value));
|
|
37
69
|
}
|
|
38
|
-
|
|
39
|
-
|
|
70
|
+
/**
|
|
71
|
+
* True when `options` uses the structured SelectOptions shape.
|
|
72
|
+
* @public
|
|
73
|
+
*/
|
|
74
|
+
function isSelectOptions(options) {
|
|
75
|
+
if (options === void 0 || Array.isArray(options) || !isOptionsRecord(options)) return false;
|
|
76
|
+
return isStructuredSelectOptions(options);
|
|
40
77
|
}
|
|
41
|
-
|
|
42
|
-
|
|
78
|
+
/**
|
|
79
|
+
* Dropdown / filter choice strings.
|
|
80
|
+
* @public
|
|
81
|
+
*/
|
|
82
|
+
function selectChoices(options) {
|
|
83
|
+
if (options === void 0) return [];
|
|
84
|
+
if (Array.isArray(options)) return options;
|
|
85
|
+
if (!isOptionsRecord(options)) return [];
|
|
86
|
+
if (isStructuredSelectOptions(options)) return options.choices;
|
|
87
|
+
if (isSelectChoiceMap(options)) return Object.keys(options);
|
|
88
|
+
return [];
|
|
43
89
|
}
|
|
44
|
-
function
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
90
|
+
function normalizeBadgeSpec(spec, key) {
|
|
91
|
+
if (isBadgeVariant(spec)) return {
|
|
92
|
+
label: key,
|
|
93
|
+
variant: spec
|
|
94
|
+
};
|
|
95
|
+
if (!isBadgeSpecObject(spec)) return { label: key };
|
|
96
|
+
return {
|
|
97
|
+
label: spec.label ?? key,
|
|
98
|
+
variant: spec.variant,
|
|
99
|
+
color: spec.color
|
|
100
|
+
};
|
|
50
101
|
}
|
|
51
|
-
function
|
|
52
|
-
|
|
53
|
-
|
|
102
|
+
function lookupFromBareMap(map, key) {
|
|
103
|
+
if (key === void 0 || key === "") return void 0;
|
|
104
|
+
if (!(key in map)) return void 0;
|
|
105
|
+
return normalizeBadgeSpec(map[key], key);
|
|
54
106
|
}
|
|
55
|
-
function
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
107
|
+
function lookupFromStructured(options, key) {
|
|
108
|
+
if (key === void 0 || key === "") return void 0;
|
|
109
|
+
const badges = options.badges;
|
|
110
|
+
if (!badges || !(key in badges)) return void 0;
|
|
111
|
+
return normalizeBadgeSpec(badges[key], key);
|
|
60
112
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
113
|
+
/**
|
|
114
|
+
* Resolve a stored choice value to a badge descriptor using field options.
|
|
115
|
+
* @public
|
|
116
|
+
*/
|
|
117
|
+
function lookupBadge(options, key) {
|
|
118
|
+
if (options === void 0 || key === void 0 || key === "") return void 0;
|
|
119
|
+
if (Array.isArray(options)) return void 0;
|
|
120
|
+
if (!isOptionsRecord(options)) return void 0;
|
|
121
|
+
if (isStructuredSelectOptions(options)) return lookupFromStructured(options, key);
|
|
122
|
+
if (isSelectChoiceMap(options)) return lookupFromBareMap(options, key);
|
|
66
123
|
}
|
|
67
|
-
|
|
68
|
-
|
|
124
|
+
/**
|
|
125
|
+
* Whether field options carry any badge mapping.
|
|
126
|
+
* @public
|
|
127
|
+
*/
|
|
128
|
+
function hasBadgeOptions(options) {
|
|
129
|
+
if (options === void 0 || Array.isArray(options)) return false;
|
|
130
|
+
if (!isOptionsRecord(options)) return false;
|
|
131
|
+
if (isStructuredSelectOptions(options)) return options.badges !== void 0 && Object.keys(options.badges).length > 0;
|
|
132
|
+
return isSelectChoiceMap(options);
|
|
69
133
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
ye as COMPONENT_LINK_EXPANSION,
|
|
75
|
-
T as DoctypeFieldSchema,
|
|
76
|
-
N as FieldsetFieldSchema,
|
|
77
|
-
C as GQL_SCALAR_MAP,
|
|
78
|
-
D as INTERNAL_SCALARS,
|
|
79
|
-
E as INTROSPECTED_IDENTITY_PROPS,
|
|
80
|
-
I as LINK_DISPLAY_SUFFIX,
|
|
81
|
-
L as TableFieldSchema,
|
|
82
|
-
_ as TableViewConfig,
|
|
83
|
-
h as TriggerDefinition,
|
|
84
|
-
p as ValueFieldSchema,
|
|
85
|
-
P as WELL_KNOWN_SCALARS,
|
|
86
|
-
B as WorkflowLayout,
|
|
87
|
-
R as WorkflowMeta,
|
|
88
|
-
j as aggregateDoctypeName,
|
|
89
|
-
M as buildAggregateDoctype,
|
|
90
|
-
w as buildScalarMap,
|
|
91
|
-
K as camelToLabel,
|
|
92
|
-
G as camelToSnake,
|
|
93
|
-
x as classifyFieldType,
|
|
94
|
-
Se as componentCategory,
|
|
95
|
-
be as componentLinkExpansion,
|
|
96
|
-
k as convertGraphQLSchema,
|
|
97
|
-
V as defaultIsEntityField,
|
|
98
|
-
W as defaultIsEntityType,
|
|
99
|
-
Fe as flattenFields,
|
|
100
|
-
Y as formatDoctypeDrift,
|
|
101
|
-
z as getDisplayField,
|
|
102
|
-
Q as getDoctypeSlug,
|
|
103
|
-
J as getPrimaryKeyField,
|
|
104
|
-
X as getRecordIdField,
|
|
105
|
-
q as getRecordIdentity,
|
|
106
|
-
v as hasBadgeOptions,
|
|
107
|
-
H as inferFieldKind,
|
|
108
|
-
U as isActionAllowedInState,
|
|
109
|
-
A as isBadgeDescriptor,
|
|
110
|
-
s as isSelectChoiceMap,
|
|
111
|
-
y as isSelectOptions,
|
|
112
|
-
Z as linkDisplayFieldname,
|
|
113
|
-
b as lookupBadge,
|
|
114
|
-
$ as mergeIntrospectedDoctype,
|
|
115
|
-
ee as normalizeFieldKind,
|
|
116
|
-
re as parseDoctype,
|
|
117
|
-
ae as parseField,
|
|
118
|
-
te as pascalToSnake,
|
|
119
|
-
ie as planGeneration,
|
|
120
|
-
ve as resolveLinkRenderMode,
|
|
121
|
-
S as selectChoices,
|
|
122
|
-
ne as snakeToCamel,
|
|
123
|
-
se as snakeToLabel,
|
|
124
|
-
le as stripFieldKind,
|
|
125
|
-
fe as toPascalCase,
|
|
126
|
-
oe as toSlug,
|
|
127
|
-
Oe as unwrapInlineLinks,
|
|
128
|
-
ce as validateDoctype,
|
|
129
|
-
de as validateField
|
|
130
|
-
};
|
|
131
|
-
//# sourceMappingURL=index.js.map
|
|
134
|
+
//#endregion
|
|
135
|
+
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
|
+
|
|
137
|
+
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/badge.ts"],"sourcesContent":["import type { FieldOptions } from './field'\n\n/**\n * Semantic badge variant. Maps to theme tokens `--sc-badge-{variant}-*`.\n * @public\n */\nexport type BadgeVariant = 'neutral' | 'success' | 'warning' | 'danger' | 'brand'\n\n/**\n * Where ABadge paints the same descriptor.\n * @public\n */\nexport type BadgePresentation = 'cell-fill' | 'input-accent'\n\n/**\n * Per-choice badge configuration in a Select options map.\n * @public\n */\nexport interface BadgeSpecObject {\n\tvariant?: BadgeVariant\n\tcolor?: string\n\tlabel?: string\n}\n\n/**\n * Value in a choice→badge map: shorthand variant or object form.\n * @public\n */\nexport type BadgeSpec = BadgeVariant | BadgeSpecObject\n\n/**\n * Select field options when choices carry badge colors.\n * @public\n */\nexport interface SelectOptions extends Record<string, unknown> {\n\tchoices: string[]\n\tbadges?: Record<string, BadgeSpec>\n}\n\n/**\n * Resolved badge for rendering. Returned by `format` or built from an options map.\n * @public\n */\nexport interface BadgeDescriptor {\n\tlabel: string\n\tvariant?: BadgeVariant\n\tcolor?: string\n}\n\nconst BADGE_VARIANTS = new Set<string>(['neutral', 'success', 'warning', 'danger', 'brand'])\n\nconst BADGE_SPEC_OBJECT_KEYS = new Set(['variant', 'color', 'label'])\n\nfunction isOptionsRecord(options: FieldOptions): options is Record<string, unknown> {\n\treturn !Array.isArray(options)\n}\n\nfunction isBadgeVariant(value: unknown): value is BadgeVariant {\n\treturn typeof value === 'string' && BADGE_VARIANTS.has(value)\n}\n\nfunction isBadgeSpecObject(value: unknown): value is BadgeSpecObject {\n\tif (value === null || typeof value !== 'object' || Array.isArray(value)) return false\n\tfor (const key of Object.keys(value)) {\n\t\tif (!BADGE_SPEC_OBJECT_KEYS.has(key)) return false\n\t}\n\tconst obj = value as BadgeSpecObject\n\tif (obj.variant !== undefined && !isBadgeVariant(obj.variant)) return false\n\tif (obj.color !== undefined && typeof obj.color !== 'string') return false\n\tif (obj.label !== undefined && typeof obj.label !== 'string') return false\n\treturn true\n}\n\nfunction isBadgeSpec(value: unknown): value is BadgeSpec {\n\treturn isBadgeVariant(value) || isBadgeSpecObject(value)\n}\n\n/**\n * Narrows an options record to the structured `{ choices, badges }` form. A type predicate rather\n * than a cast: `SelectOptions` requires `choices`, so asserting into it trips `no-unsafe-type-assertion`.\n */\nfunction isStructuredSelectOptions(options: Record<string, unknown>): options is SelectOptions {\n\treturn Array.isArray(options.choices)\n}\n\n/**\n * True when `value` is a resolved badge descriptor for ACell / ADropdown.\n * @public\n */\nexport function isBadgeDescriptor(value: unknown): value is BadgeDescriptor {\n\tif (value === null || typeof value !== 'object' || Array.isArray(value)) return false\n\t// Partial<> keeps this a widening assertion; asserting into BadgeDescriptor itself (required\n\t// `label`) narrows, which `no-unsafe-type-assertion` rejects.\n\tconst obj = value as Partial<BadgeDescriptor>\n\tif (typeof obj.label !== 'string') return false\n\tif (obj.variant !== undefined && !isBadgeVariant(obj.variant)) return false\n\tif (obj.color !== undefined && typeof obj.color !== 'string') return false\n\treturn true\n}\n\n/**\n * True when `options` is a Select choice map (`{ Open: \"warning\", ... }` or\n * `{ choices: [...], badges: {...} }`), not a quantity/currency/code config bag.\n * @public\n */\nexport function isSelectChoiceMap(options: FieldOptions | undefined): options is Record<string, BadgeSpec> {\n\tif (options === undefined || Array.isArray(options) || !isOptionsRecord(options)) return false\n\tif (isStructuredSelectOptions(options)) {\n\t\tconst badges = options.badges\n\t\tif (badges === undefined) return false\n\t\treturn Object.values(badges).every(isBadgeSpec)\n\t}\n\tconst entries = Object.entries(options)\n\tif (entries.length === 0) return false\n\treturn entries.every(([, value]) => isBadgeSpec(value))\n}\n\n/**\n * True when `options` uses the structured SelectOptions shape.\n * @public\n */\nexport function isSelectOptions(options: FieldOptions | undefined): options is SelectOptions {\n\tif (options === undefined || Array.isArray(options) || !isOptionsRecord(options)) return false\n\treturn isStructuredSelectOptions(options)\n}\n\n/**\n * Dropdown / filter choice strings.\n * @public\n */\nexport function selectChoices(options: FieldOptions | undefined): string[] {\n\tif (options === undefined) return []\n\tif (Array.isArray(options)) return options\n\tif (!isOptionsRecord(options)) return []\n\tif (isStructuredSelectOptions(options)) return options.choices\n\tif (isSelectChoiceMap(options)) return Object.keys(options)\n\treturn []\n}\n\nfunction normalizeBadgeSpec(spec: unknown, key: string): BadgeDescriptor {\n\tif (isBadgeVariant(spec)) {\n\t\treturn { label: key, variant: spec }\n\t}\n\t// A malformed spec still names a real choice, so keep the label and drop only the styling.\n\t// Reading `.variant`/`.color` off an unvalidated value is what let a misspelt variant reach the\n\t// DOM as an unmatched class, and threw outright on null.\n\tif (!isBadgeSpecObject(spec)) {\n\t\treturn { label: key }\n\t}\n\treturn {\n\t\tlabel: spec.label ?? key,\n\t\tvariant: spec.variant,\n\t\tcolor: spec.color,\n\t}\n}\n\nfunction lookupFromBareMap(map: Record<string, BadgeSpec>, key: string | undefined): BadgeDescriptor | undefined {\n\tif (key === undefined || key === '') return undefined\n\tif (!(key in map)) return undefined\n\treturn normalizeBadgeSpec(map[key], key)\n}\n\nfunction lookupFromStructured(options: SelectOptions, key: string | undefined): BadgeDescriptor | undefined {\n\tif (key === undefined || key === '') return undefined\n\tconst badges = options.badges\n\tif (!badges || !(key in badges)) return undefined\n\treturn normalizeBadgeSpec(badges[key], key)\n}\n\n/**\n * Resolve a stored choice value to a badge descriptor using field options.\n * @public\n */\nexport function lookupBadge(options: FieldOptions | undefined, key: string | undefined): BadgeDescriptor | undefined {\n\tif (options === undefined || key === undefined || key === '') return undefined\n\tif (Array.isArray(options)) return undefined\n\tif (!isOptionsRecord(options)) return undefined\n\tif (isStructuredSelectOptions(options)) return lookupFromStructured(options, key)\n\tif (isSelectChoiceMap(options)) return lookupFromBareMap(options, key)\n\treturn undefined\n}\n\n/**\n * Whether field options carry any badge mapping.\n * @public\n */\nexport function hasBadgeOptions(options: FieldOptions | undefined): boolean {\n\tif (options === undefined || Array.isArray(options)) return false\n\tif (!isOptionsRecord(options)) return false\n\tif (isStructuredSelectOptions(options)) return options.badges !== undefined && Object.keys(options.badges).length > 0\n\treturn isSelectChoiceMap(options)\n}\n"],"
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/badge.ts"],"sourcesContent":["import type { FieldOptions } from './field'\n\n/**\n * Semantic badge variant. Maps to theme tokens `--sc-badge-{variant}-*`.\n * @public\n */\nexport type BadgeVariant = 'neutral' | 'success' | 'warning' | 'danger' | 'brand'\n\n/**\n * Where ABadge paints the same descriptor.\n * @public\n */\nexport type BadgePresentation = 'cell-fill' | 'input-accent'\n\n/**\n * Per-choice badge configuration in a Select options map.\n * @public\n */\nexport interface BadgeSpecObject {\n\tvariant?: BadgeVariant\n\tcolor?: string\n\tlabel?: string\n}\n\n/**\n * Value in a choice→badge map: shorthand variant or object form.\n * @public\n */\nexport type BadgeSpec = BadgeVariant | BadgeSpecObject\n\n/**\n * Select field options when choices carry badge colors.\n * @public\n */\nexport interface SelectOptions extends Record<string, unknown> {\n\tchoices: string[]\n\tbadges?: Record<string, BadgeSpec>\n}\n\n/**\n * Resolved badge for rendering. Returned by `format` or built from an options map.\n * @public\n */\nexport interface BadgeDescriptor {\n\tlabel: string\n\tvariant?: BadgeVariant\n\tcolor?: string\n}\n\nconst BADGE_VARIANTS = new Set<string>(['neutral', 'success', 'warning', 'danger', 'brand'])\n\nconst BADGE_SPEC_OBJECT_KEYS = new Set(['variant', 'color', 'label'])\n\nfunction isOptionsRecord(options: FieldOptions): options is Record<string, unknown> {\n\treturn !Array.isArray(options)\n}\n\nfunction isBadgeVariant(value: unknown): value is BadgeVariant {\n\treturn typeof value === 'string' && BADGE_VARIANTS.has(value)\n}\n\nfunction isBadgeSpecObject(value: unknown): value is BadgeSpecObject {\n\tif (value === null || typeof value !== 'object' || Array.isArray(value)) return false\n\tfor (const key of Object.keys(value)) {\n\t\tif (!BADGE_SPEC_OBJECT_KEYS.has(key)) return false\n\t}\n\tconst obj = value as BadgeSpecObject\n\tif (obj.variant !== undefined && !isBadgeVariant(obj.variant)) return false\n\tif (obj.color !== undefined && typeof obj.color !== 'string') return false\n\tif (obj.label !== undefined && typeof obj.label !== 'string') return false\n\treturn true\n}\n\nfunction isBadgeSpec(value: unknown): value is BadgeSpec {\n\treturn isBadgeVariant(value) || isBadgeSpecObject(value)\n}\n\n/**\n * Narrows an options record to the structured `{ choices, badges }` form. A type predicate rather\n * than a cast: `SelectOptions` requires `choices`, so asserting into it trips `no-unsafe-type-assertion`.\n */\nfunction isStructuredSelectOptions(options: Record<string, unknown>): options is SelectOptions {\n\treturn Array.isArray(options.choices)\n}\n\n/**\n * True when `value` is a resolved badge descriptor for ACell / ADropdown.\n * @public\n */\nexport function isBadgeDescriptor(value: unknown): value is BadgeDescriptor {\n\tif (value === null || typeof value !== 'object' || Array.isArray(value)) return false\n\t// Partial<> keeps this a widening assertion; asserting into BadgeDescriptor itself (required\n\t// `label`) narrows, which `no-unsafe-type-assertion` rejects.\n\tconst obj = value as Partial<BadgeDescriptor>\n\tif (typeof obj.label !== 'string') return false\n\tif (obj.variant !== undefined && !isBadgeVariant(obj.variant)) return false\n\tif (obj.color !== undefined && typeof obj.color !== 'string') return false\n\treturn true\n}\n\n/**\n * True when `options` is a Select choice map (`{ Open: \"warning\", ... }` or\n * `{ choices: [...], badges: {...} }`), not a quantity/currency/code config bag.\n * @public\n */\nexport function isSelectChoiceMap(options: FieldOptions | undefined): options is Record<string, BadgeSpec> {\n\tif (options === undefined || Array.isArray(options) || !isOptionsRecord(options)) return false\n\tif (isStructuredSelectOptions(options)) {\n\t\tconst badges = options.badges\n\t\tif (badges === undefined) return false\n\t\treturn Object.values(badges).every(isBadgeSpec)\n\t}\n\tconst entries = Object.entries(options)\n\tif (entries.length === 0) return false\n\treturn entries.every(([, value]) => isBadgeSpec(value))\n}\n\n/**\n * True when `options` uses the structured SelectOptions shape.\n * @public\n */\nexport function isSelectOptions(options: FieldOptions | undefined): options is SelectOptions {\n\tif (options === undefined || Array.isArray(options) || !isOptionsRecord(options)) return false\n\treturn isStructuredSelectOptions(options)\n}\n\n/**\n * Dropdown / filter choice strings.\n * @public\n */\nexport function selectChoices(options: FieldOptions | undefined): string[] {\n\tif (options === undefined) return []\n\tif (Array.isArray(options)) return options\n\tif (!isOptionsRecord(options)) return []\n\tif (isStructuredSelectOptions(options)) return options.choices\n\tif (isSelectChoiceMap(options)) return Object.keys(options)\n\treturn []\n}\n\nfunction normalizeBadgeSpec(spec: unknown, key: string): BadgeDescriptor {\n\tif (isBadgeVariant(spec)) {\n\t\treturn { label: key, variant: spec }\n\t}\n\t// A malformed spec still names a real choice, so keep the label and drop only the styling.\n\t// Reading `.variant`/`.color` off an unvalidated value is what let a misspelt variant reach the\n\t// DOM as an unmatched class, and threw outright on null.\n\tif (!isBadgeSpecObject(spec)) {\n\t\treturn { label: key }\n\t}\n\treturn {\n\t\tlabel: spec.label ?? key,\n\t\tvariant: spec.variant,\n\t\tcolor: spec.color,\n\t}\n}\n\nfunction lookupFromBareMap(map: Record<string, BadgeSpec>, key: string | undefined): BadgeDescriptor | undefined {\n\tif (key === undefined || key === '') return undefined\n\tif (!(key in map)) return undefined\n\treturn normalizeBadgeSpec(map[key], key)\n}\n\nfunction lookupFromStructured(options: SelectOptions, key: string | undefined): BadgeDescriptor | undefined {\n\tif (key === undefined || key === '') return undefined\n\tconst badges = options.badges\n\tif (!badges || !(key in badges)) return undefined\n\treturn normalizeBadgeSpec(badges[key], key)\n}\n\n/**\n * Resolve a stored choice value to a badge descriptor using field options.\n * @public\n */\nexport function lookupBadge(options: FieldOptions | undefined, key: string | undefined): BadgeDescriptor | undefined {\n\tif (options === undefined || key === undefined || key === '') return undefined\n\tif (Array.isArray(options)) return undefined\n\tif (!isOptionsRecord(options)) return undefined\n\tif (isStructuredSelectOptions(options)) return lookupFromStructured(options, key)\n\tif (isSelectChoiceMap(options)) return lookupFromBareMap(options, key)\n\treturn undefined\n}\n\n/**\n * Whether field options carry any badge mapping.\n * @public\n */\nexport function hasBadgeOptions(options: FieldOptions | undefined): boolean {\n\tif (options === undefined || Array.isArray(options)) return false\n\tif (!isOptionsRecord(options)) return false\n\tif (isStructuredSelectOptions(options)) return options.badges !== undefined && Object.keys(options.badges).length > 0\n\treturn isSelectChoiceMap(options)\n}\n"],"mappings":";;;;AAiDA,IAAM,iCAAiB,IAAI,IAAY;CAAC;CAAW;CAAW;CAAW;CAAU;AAAO,CAAC;AAE3F,IAAM,yCAAyB,IAAI,IAAI;CAAC;CAAW;CAAS;AAAO,CAAC;AAEpE,SAAS,gBAAgB,SAA2D;CACnF,OAAO,CAAC,MAAM,QAAQ,OAAO;AAC9B;AAEA,SAAS,eAAe,OAAuC;CAC9D,OAAO,OAAO,UAAU,YAAY,eAAe,IAAI,KAAK;AAC7D;AAEA,SAAS,kBAAkB,OAA0C;CACpE,IAAI,UAAU,QAAQ,OAAO,UAAU,YAAY,MAAM,QAAQ,KAAK,GAAG,OAAO;CAChF,KAAK,MAAM,OAAO,OAAO,KAAK,KAAK,GAClC,IAAI,CAAC,uBAAuB,IAAI,GAAG,GAAG,OAAO;CAE9C,MAAM,MAAM;CACZ,IAAI,IAAI,YAAY,KAAA,KAAa,CAAC,eAAe,IAAI,OAAO,GAAG,OAAO;CACtE,IAAI,IAAI,UAAU,KAAA,KAAa,OAAO,IAAI,UAAU,UAAU,OAAO;CACrE,IAAI,IAAI,UAAU,KAAA,KAAa,OAAO,IAAI,UAAU,UAAU,OAAO;CACrE,OAAO;AACR;AAEA,SAAS,YAAY,OAAoC;CACxD,OAAO,eAAe,KAAK,KAAK,kBAAkB,KAAK;AACxD;;;;;AAMA,SAAS,0BAA0B,SAA4D;CAC9F,OAAO,MAAM,QAAQ,QAAQ,OAAO;AACrC;;;;;AAMA,SAAgB,kBAAkB,OAA0C;CAC3E,IAAI,UAAU,QAAQ,OAAO,UAAU,YAAY,MAAM,QAAQ,KAAK,GAAG,OAAO;CAGhF,MAAM,MAAM;CACZ,IAAI,OAAO,IAAI,UAAU,UAAU,OAAO;CAC1C,IAAI,IAAI,YAAY,KAAA,KAAa,CAAC,eAAe,IAAI,OAAO,GAAG,OAAO;CACtE,IAAI,IAAI,UAAU,KAAA,KAAa,OAAO,IAAI,UAAU,UAAU,OAAO;CACrE,OAAO;AACR;;;;;;AAOA,SAAgB,kBAAkB,SAAyE;CAC1G,IAAI,YAAY,KAAA,KAAa,MAAM,QAAQ,OAAO,KAAK,CAAC,gBAAgB,OAAO,GAAG,OAAO;CACzF,IAAI,0BAA0B,OAAO,GAAG;EACvC,MAAM,SAAS,QAAQ;EACvB,IAAI,WAAW,KAAA,GAAW,OAAO;EACjC,OAAO,OAAO,OAAO,MAAM,CAAC,CAAC,MAAM,WAAW;CAC/C;CACA,MAAM,UAAU,OAAO,QAAQ,OAAO;CACtC,IAAI,QAAQ,WAAW,GAAG,OAAO;CACjC,OAAO,QAAQ,OAAO,GAAG,WAAW,YAAY,KAAK,CAAC;AACvD;;;;;AAMA,SAAgB,gBAAgB,SAA6D;CAC5F,IAAI,YAAY,KAAA,KAAa,MAAM,QAAQ,OAAO,KAAK,CAAC,gBAAgB,OAAO,GAAG,OAAO;CACzF,OAAO,0BAA0B,OAAO;AACzC;;;;;AAMA,SAAgB,cAAc,SAA6C;CAC1E,IAAI,YAAY,KAAA,GAAW,OAAO,CAAC;CACnC,IAAI,MAAM,QAAQ,OAAO,GAAG,OAAO;CACnC,IAAI,CAAC,gBAAgB,OAAO,GAAG,OAAO,CAAC;CACvC,IAAI,0BAA0B,OAAO,GAAG,OAAO,QAAQ;CACvD,IAAI,kBAAkB,OAAO,GAAG,OAAO,OAAO,KAAK,OAAO;CAC1D,OAAO,CAAC;AACT;AAEA,SAAS,mBAAmB,MAAe,KAA8B;CACxE,IAAI,eAAe,IAAI,GACtB,OAAO;EAAE,OAAO;EAAK,SAAS;CAAK;CAKpC,IAAI,CAAC,kBAAkB,IAAI,GAC1B,OAAO,EAAE,OAAO,IAAI;CAErB,OAAO;EACN,OAAO,KAAK,SAAS;EACrB,SAAS,KAAK;EACd,OAAO,KAAK;CACb;AACD;AAEA,SAAS,kBAAkB,KAAgC,KAAsD;CAChH,IAAI,QAAQ,KAAA,KAAa,QAAQ,IAAI,OAAO,KAAA;CAC5C,IAAI,EAAE,OAAO,MAAM,OAAO,KAAA;CAC1B,OAAO,mBAAmB,IAAI,MAAM,GAAG;AACxC;AAEA,SAAS,qBAAqB,SAAwB,KAAsD;CAC3G,IAAI,QAAQ,KAAA,KAAa,QAAQ,IAAI,OAAO,KAAA;CAC5C,MAAM,SAAS,QAAQ;CACvB,IAAI,CAAC,UAAU,EAAE,OAAO,SAAS,OAAO,KAAA;CACxC,OAAO,mBAAmB,OAAO,MAAM,GAAG;AAC3C;;;;;AAMA,SAAgB,YAAY,SAAmC,KAAsD;CACpH,IAAI,YAAY,KAAA,KAAa,QAAQ,KAAA,KAAa,QAAQ,IAAI,OAAO,KAAA;CACrE,IAAI,MAAM,QAAQ,OAAO,GAAG,OAAO,KAAA;CACnC,IAAI,CAAC,gBAAgB,OAAO,GAAG,OAAO,KAAA;CACtC,IAAI,0BAA0B,OAAO,GAAG,OAAO,qBAAqB,SAAS,GAAG;CAChF,IAAI,kBAAkB,OAAO,GAAG,OAAO,kBAAkB,SAAS,GAAG;AAEtE;;;;;AAMA,SAAgB,gBAAgB,SAA4C;CAC3E,IAAI,YAAY,KAAA,KAAa,MAAM,QAAQ,OAAO,GAAG,OAAO;CAC5D,IAAI,CAAC,gBAAgB,OAAO,GAAG,OAAO;CACtC,IAAI,0BAA0B,OAAO,GAAG,OAAO,QAAQ,WAAW,KAAA,KAAa,OAAO,KAAK,QAAQ,MAAM,CAAC,CAAC,SAAS;CACpH,OAAO,kBAAkB,OAAO;AACjC"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { t as flattenFields } from "./flatten-Bx2cfvw3.js";
|
|
2
|
+
//#region src/component-meta.ts
|
|
3
|
+
/**
|
|
4
|
+
* Canonical component → semantic category. Only the components Stonecrop ships with appear here;
|
|
5
|
+
* custom/unknown component names have no category and consumers fall back to their default.
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
var COMPONENT_CATEGORY = {
|
|
9
|
+
ATextInput: "text",
|
|
10
|
+
ATextboxInput: "text",
|
|
11
|
+
ANumericInput: "number",
|
|
12
|
+
ACheckbox: "boolean",
|
|
13
|
+
ADate: "date",
|
|
14
|
+
ADatePicker: "date",
|
|
15
|
+
ADateSelection: "date",
|
|
16
|
+
ADateTime: "datetime",
|
|
17
|
+
ADuration: "text",
|
|
18
|
+
ADateRange: "date",
|
|
19
|
+
ADropdown: "select",
|
|
20
|
+
ASegmentedControl: "select",
|
|
21
|
+
ACodeEditor: "code",
|
|
22
|
+
AFormLink: "link",
|
|
23
|
+
AFileAttach: "attach",
|
|
24
|
+
AQuantityInput: "quantity",
|
|
25
|
+
ACurrencyInput: "currency"
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Resolve a component's semantic category, or `undefined` for an unknown (custom) component —
|
|
29
|
+
* callers treat that as "no opinion" and use their own default.
|
|
30
|
+
* @public
|
|
31
|
+
*/
|
|
32
|
+
function componentCategory(component) {
|
|
33
|
+
return component ? COMPONENT_CATEGORY[component] : void 0;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Canonical link component → expansion. Only components Stonecrop ships with appear here; an
|
|
37
|
+
* unmapped (custom) component has none, and callers treat that as `expand` — the behaviour that
|
|
38
|
+
* predates this map, so a custom component can never silently collapse a link to a picker.
|
|
39
|
+
* @public
|
|
40
|
+
*/
|
|
41
|
+
var COMPONENT_LINK_EXPANSION = {
|
|
42
|
+
AFormLink: "inline",
|
|
43
|
+
AForm: "expand",
|
|
44
|
+
ATable: "expand"
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Resolve a component's link expansion, or `undefined` for an absent/unmapped component.
|
|
48
|
+
* @public
|
|
49
|
+
*/
|
|
50
|
+
function componentLinkExpansion(component) {
|
|
51
|
+
return component ? COMPONENT_LINK_EXPANSION[component] : void 0;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Decide how a *declared* link (one with a `LinkDeclaration`) renders.
|
|
55
|
+
*
|
|
56
|
+
* Two independent axes: the **component** picks inline vs expand, and when expanding the
|
|
57
|
+
* **cardinality** picks record vs table (many → table). The declaration's component wins over the
|
|
58
|
+
* field's, matching the precedence the resolver already uses for the rendered component.
|
|
59
|
+
*
|
|
60
|
+
* This is the single definition of "does this link expand" — it is consumed by both the client
|
|
61
|
+
* resolver (which builds the nested schema) and the server column builder (which must still
|
|
62
|
+
* SELECT an `inline` link's FK column). Call it; never re-derive the rule at the call site, or
|
|
63
|
+
* the two will drift and the client will render a table for a column the server never selected.
|
|
64
|
+
*
|
|
65
|
+
* @param link - the link declaration (only `component` and `cardinality` are consulted)
|
|
66
|
+
* @param fieldComponent - the linked field's own `component`, used when the declaration names none
|
|
67
|
+
* @public
|
|
68
|
+
*/
|
|
69
|
+
function resolveLinkRenderMode(link, fieldComponent) {
|
|
70
|
+
if (componentLinkExpansion(link.component ?? fieldComponent) === "inline") return "inline";
|
|
71
|
+
return link.cardinality === "noneOrMany" || link.cardinality === "atLeastOne" ? "table" : "record";
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Every component Stonecrop ships with that can render a value field, sorted by name.
|
|
75
|
+
*
|
|
76
|
+
* The union of the two maps above is the definition, not a copy of it: a shipped component either
|
|
77
|
+
* categorises a value ({@link COMPONENT_CATEGORY}) or is one of the link containers that has no
|
|
78
|
+
* value of its own ({@link COMPONENT_LINK_EXPANSION}'s `AForm`/`ATable`). `AFieldset` is absent by
|
|
79
|
+
* the same rule — it is a `kind: 'fieldset'` container, so it is never a value field's component.
|
|
80
|
+
*
|
|
81
|
+
* `component` is an **open** axis: any string is valid, and naming a custom component is how an app
|
|
82
|
+
* renders a field Stonecrop ships no widget for. This list is therefore the set to *suggest* to an
|
|
83
|
+
* author, and to check first-party data against — never a set to validate arbitrary input against.
|
|
84
|
+
*
|
|
85
|
+
* @public
|
|
86
|
+
*/
|
|
87
|
+
var CANONICAL_COMPONENTS = [.../* @__PURE__ */ new Set([...Object.keys(COMPONENT_CATEGORY), ...Object.keys(COMPONENT_LINK_EXPANSION)])].toSorted();
|
|
88
|
+
//#endregion
|
|
89
|
+
//#region src/record.ts
|
|
90
|
+
/**
|
|
91
|
+
* Reduce a record's *inline* link values to the ids that get persisted.
|
|
92
|
+
*
|
|
93
|
+
* The adapter returns an inline link as `{ id, displayText }`, so that is what a record holds
|
|
94
|
+
* everywhere it is read — the store, a list row, a form field. A column takes the id alone, so
|
|
95
|
+
* this is the single definition of the shape a record leaves in, and it belongs at the boundary
|
|
96
|
+
* a record crosses on its way to the server, never on the way into the store.
|
|
97
|
+
*
|
|
98
|
+
* Doing it on the way in destroys the text the adapter looked up: nothing else holds it, so the
|
|
99
|
+
* field that resolved a moment ago renders its raw id, and the same record then renders
|
|
100
|
+
* differently depending on whether anything had edited the form yet. That is the bug this exists
|
|
101
|
+
* to prevent, and its damage is a wrong render, not a throw.
|
|
102
|
+
*
|
|
103
|
+
* Only *inline* links may be reduced. An inline link's value is indistinguishable by inspection
|
|
104
|
+
* from an expanded one (`{ id, ...the whole target record }`), so `component` — which states
|
|
105
|
+
* which of the two a field is — is what tells them apart, via {@link componentLinkExpansion}.
|
|
106
|
+
* Reducing an expanded link would send the id in place of the record.
|
|
107
|
+
*
|
|
108
|
+
* Fieldsets are descended into in both shapes a record appears in: flat, as the store and the
|
|
109
|
+
* server hold it, and nested under the fieldset's own key, as a form emits it.
|
|
110
|
+
*
|
|
111
|
+
* @param fields - the doctype's top-level fields
|
|
112
|
+
* @param record - the record to reduce; not mutated
|
|
113
|
+
* @returns a shallow copy with every inline link reduced to its id
|
|
114
|
+
* @public
|
|
115
|
+
*/
|
|
116
|
+
function unwrapInlineLinks(fields, record) {
|
|
117
|
+
const inline = new Set(flattenFields(fields).filter((field) => field.kind === "field" && Boolean(field.doctype)).filter((field) => componentLinkExpansion(field.component) === "inline").map((field) => field.fieldname));
|
|
118
|
+
if (inline.size === 0) return record;
|
|
119
|
+
return unwrapWith(inline, new Set(fields.filter((field) => field.kind === "fieldset").map((field) => field.fieldname)), record);
|
|
120
|
+
}
|
|
121
|
+
function unwrapWith(inline, fieldsets, record) {
|
|
122
|
+
const result = { ...record };
|
|
123
|
+
for (const [key, value] of Object.entries(result)) {
|
|
124
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) continue;
|
|
125
|
+
if (inline.has(key)) {
|
|
126
|
+
if ("id" in value) result[key] = value.id;
|
|
127
|
+
} else if (fieldsets.has(key)) result[key] = unwrapWith(inline, fieldsets, value);
|
|
128
|
+
}
|
|
129
|
+
return result;
|
|
130
|
+
}
|
|
131
|
+
//#endregion
|
|
132
|
+
export { componentCategory as a, COMPONENT_LINK_EXPANSION as i, CANONICAL_COMPONENTS as n, componentLinkExpansion as o, COMPONENT_CATEGORY as r, resolveLinkRenderMode as s, unwrapInlineLinks as t };
|
|
133
|
+
|
|
134
|
+
//# sourceMappingURL=record-BQOOi83C.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"record-BQOOi83C.js","names":[],"sources":["../src/component-meta.ts","../src/record.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| 'select'\n\t| 'code'\n\t| 'link'\n\t| 'attach'\n\t| 'quantity'\n\t| 'currency'\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: 'text',\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}\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 * 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 * - `record` — the target doctype is resolved and embedded as a nested form.\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\" — it is consumed by both the client\n * resolver (which builds the nested schema) and the server column builder (which must still\n * SELECT an `inline` link's FK column). Call it; never re-derive the rule at the call site, or\n * the two will drift and the client will 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 { 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 * Fieldsets are descended into in both shapes a record appears in: flat, as the store and the\n * server hold it, and nested under the fieldset's own key, as a form emits it.\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 fieldsets = new Set(fields.filter(field => field.kind === 'fieldset').map(field => field.fieldname))\n\treturn unwrapWith(inline, fieldsets, record)\n}\n\nfunction unwrapWith(\n\tinline: ReadonlySet<string>,\n\tfieldsets: ReadonlySet<string>,\n\trecord: Record<string, any>\n): Record<string, any> {\n\tconst result: Record<string, any> = { ...record }\n\tfor (const [key, value] of Object.entries(result)) {\n\t\tif (value === null || typeof value !== 'object' || Array.isArray(value)) continue\n\t\tif (inline.has(key)) {\n\t\t\t// `'id' in value` rather than a truthiness test: an inline link that was never resolved\n\t\t\t// is still a bare scalar, and reducing it a second time would be a no-op at best.\n\t\t\tif ('id' in value) result[key] = value.id\n\t\t} else if (fieldsets.has(key)) {\n\t\t\tresult[key] = unwrapWith(inline, fieldsets, value)\n\t\t}\n\t}\n\treturn result\n}\n"],"mappings":";;;;;;;AA6BA,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;AACjB;;;;;;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;;;;;;;;;;;;;;;;;AA8BA,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AClHX,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;CAG9B,OAAO,WAAW,QAAQ,IADJ,IAAI,OAAO,QAAO,UAAS,MAAM,SAAS,UAAU,CAAC,CAAC,KAAI,UAAS,MAAM,SAAS,CAC9E,GAAW,MAAM;AAC5C;AAEA,SAAS,WACR,QACA,WACA,QACsB;CACtB,MAAM,SAA8B,EAAE,GAAG,OAAO;CAChD,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,MAAM,GAAG;EAClD,IAAI,UAAU,QAAQ,OAAO,UAAU,YAAY,MAAM,QAAQ,KAAK,GAAG;EACzE,IAAI,OAAO,IAAI,GAAG,GAGb;OAAA,QAAQ,OAAO,OAAO,OAAO,MAAM;EAAA,OACjC,IAAI,UAAU,IAAI,GAAG,GAC3B,OAAO,OAAO,WAAW,QAAQ,WAAW,KAAK;CAEnD;CACA,OAAO;AACR"}
|
package/dist/record.js
CHANGED
package/dist/tsdoc-metadata.json
CHANGED
package/package.json
CHANGED
|
@@ -1,35 +1,50 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stonecrop/schema",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.32.0",
|
|
4
4
|
"description": "Stonecrop schema definitions and validation tooling",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"doctype",
|
|
7
|
+
"schema",
|
|
8
|
+
"stonecrop",
|
|
9
|
+
"validation"
|
|
10
|
+
],
|
|
11
|
+
"homepage": "https://github.com/agritheory/stonecrop#readme",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/agritheory/stonecrop/issues"
|
|
14
|
+
},
|
|
15
|
+
"author": {
|
|
16
|
+
"name": "Tyler Matteson",
|
|
17
|
+
"email": "tyler@agritheory.com"
|
|
18
|
+
},
|
|
5
19
|
"repository": {
|
|
6
20
|
"type": "git",
|
|
7
21
|
"url": "https://github.com/agritheory/stonecrop",
|
|
8
22
|
"directory": "schema"
|
|
9
23
|
},
|
|
10
|
-
"
|
|
24
|
+
"bin": {
|
|
25
|
+
"stonecrop-schema": "./dist/cli.js"
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"dist",
|
|
29
|
+
"!dist/src"
|
|
30
|
+
],
|
|
11
31
|
"type": "module",
|
|
32
|
+
"sideEffects": false,
|
|
33
|
+
"types": "./dist/schema.d.ts",
|
|
12
34
|
"exports": {
|
|
13
35
|
".": {
|
|
14
36
|
"types": "./dist/schema.d.ts",
|
|
15
37
|
"import": "./dist/index.js"
|
|
16
|
-
}
|
|
38
|
+
},
|
|
39
|
+
"./package.json": "./package.json"
|
|
17
40
|
},
|
|
18
|
-
"types": "./dist/schema.d.ts",
|
|
19
|
-
"bin": {
|
|
20
|
-
"stonecrop-schema": "./dist/cli.js"
|
|
21
|
-
},
|
|
22
|
-
"files": [
|
|
23
|
-
"dist"
|
|
24
|
-
],
|
|
25
41
|
"dependencies": {
|
|
26
42
|
"graphql": "^16.14.0",
|
|
27
43
|
"pluralize": "^8.0.0",
|
|
28
44
|
"zod": "^4.3.6"
|
|
29
45
|
},
|
|
30
46
|
"devDependencies": {
|
|
31
|
-
"@microsoft/api-
|
|
32
|
-
"@rushstack/heft": "^1.2.17",
|
|
47
|
+
"@microsoft/api-extractor": "^7.58.7",
|
|
33
48
|
"@types/node": "^24.12.4",
|
|
34
49
|
"@types/pluralize": "^0.0.33",
|
|
35
50
|
"@vitest/coverage-istanbul": "^4.1.5",
|
|
@@ -37,14 +52,15 @@
|
|
|
37
52
|
"oxlint": "1.67.0",
|
|
38
53
|
"oxlint-tsgolint": "0.23.0",
|
|
39
54
|
"typescript": "^6.0.3",
|
|
40
|
-
"vite": "^
|
|
41
|
-
"vitest": "^4.1.5"
|
|
42
|
-
|
|
55
|
+
"vite": "^8.2.2",
|
|
56
|
+
"vitest": "^4.1.5"
|
|
57
|
+
},
|
|
58
|
+
"engines": {
|
|
59
|
+
"node": ">=24.0.0"
|
|
43
60
|
},
|
|
44
61
|
"scripts": {
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"docs": "bash ../common/scripts/run-docs.sh schema",
|
|
62
|
+
"dev": "vite build --watch",
|
|
63
|
+
"docs": "bash ../tools/scripts/run-docs.sh schema",
|
|
48
64
|
"lint": "oxlint",
|
|
49
65
|
"lint:fix": "oxlint --fix",
|
|
50
66
|
"preview": "vite preview",
|
package/dist/flatten-C1MjkzFh.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"flatten-C1MjkzFh.js","sources":["../src/flatten.ts"],"sourcesContent":["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"],"names":["flattenFields","fields","result","f"],"mappings":"AA4BO,SAASA,EAAcC,GAA8D;AAC3F,QAAMC,IAAsC,CAAA;AAC5C,aAAWC,KAAKF;AACf,IAAIE,EAAE,SAAS,aACdD,EAAO,KAAK,GAAGF,EAAcG,EAAE,MAAM,CAAC,IAEtCD,EAAO,KAAKC,CAAC;AAGf,SAAOD;AACR;"}
|