@stonecrop/schema 0.25.0 → 0.27.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 +23 -0
- package/dist/cli.js +85 -59
- package/dist/cli.js.map +1 -1
- package/dist/index.js +68 -61
- package/dist/index.js.map +1 -1
- package/dist/schema.d.ts +256 -13
- package/dist/src/cli.js +53 -6
- package/dist/src/component-meta.d.ts.map +1 -1
- package/dist/src/component-meta.js +1 -0
- package/dist/src/converter/aggregate.d.ts +127 -0
- package/dist/src/converter/aggregate.d.ts.map +1 -0
- package/dist/src/converter/aggregate.js +235 -0
- package/dist/src/converter/authored.d.ts +43 -0
- package/dist/src/converter/authored.d.ts.map +1 -0
- package/dist/src/converter/authored.js +52 -0
- package/dist/src/converter/heuristics.d.ts +2 -2
- package/dist/src/converter/heuristics.d.ts.map +1 -1
- package/dist/src/converter/heuristics.js +43 -4
- package/dist/src/converter/index.d.ts +3 -1
- package/dist/src/converter/index.d.ts.map +1 -1
- package/dist/src/converter/index.js +2 -0
- package/dist/src/converter/merge.d.ts +25 -10
- package/dist/src/converter/merge.d.ts.map +1 -1
- package/dist/src/converter/merge.js +17 -26
- package/dist/src/doctype.d.ts +38 -0
- package/dist/src/doctype.d.ts.map +1 -1
- package/dist/src/doctype.js +55 -1
- package/dist/src/field.d.ts +59 -8
- package/dist/src/field.d.ts.map +1 -1
- package/dist/src/field.js +84 -14
- package/dist/src/index.d.ts +3 -3
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +3 -3
- package/dist/validation-BjRDR6sh.js +1000 -0
- package/dist/validation-BjRDR6sh.js.map +1 -0
- package/package.json +3 -1
- package/dist/validation-CQtfIFHQ.js +0 -583
- package/dist/validation-CQtfIFHQ.js.map +0 -1
|
@@ -1,583 +0,0 @@
|
|
|
1
|
-
import { isScalarType as K, isEnumType as V, isObjectType as k, isNonNullType as v, isListType as z, isNamedType as B, buildSchema as W, buildClientSchema as J } from "graphql";
|
|
2
|
-
import { z as e } from "zod";
|
|
3
|
-
function Ne(t) {
|
|
4
|
-
return t.replace(/_([a-z])/g, (n, i) => i.toUpperCase());
|
|
5
|
-
}
|
|
6
|
-
function $e(t) {
|
|
7
|
-
return t.replace(/[A-Z]/g, (n) => `_${n.toLowerCase()}`);
|
|
8
|
-
}
|
|
9
|
-
function ve(t) {
|
|
10
|
-
return t.split("_").map((n) => n.charAt(0).toUpperCase() + n.slice(1).toLowerCase()).join(" ");
|
|
11
|
-
}
|
|
12
|
-
function G(t) {
|
|
13
|
-
const n = t.replace(/([A-Z])/g, " $1").trim();
|
|
14
|
-
return n.charAt(0).toUpperCase() + n.slice(1);
|
|
15
|
-
}
|
|
16
|
-
function Q(t) {
|
|
17
|
-
return t.split(/[-_\s]+/).map((n) => n.charAt(0).toUpperCase() + n.slice(1).toLowerCase()).join("");
|
|
18
|
-
}
|
|
19
|
-
function T(t) {
|
|
20
|
-
return t.replace(/([a-z])([A-Z])/g, "$1-$2").replace(/[\s_]+/g, "-").toLowerCase();
|
|
21
|
-
}
|
|
22
|
-
function Me(t) {
|
|
23
|
-
return t.replace(/([a-z])([A-Z])/g, "$1_$2").replace(/[\s-]+/g, "_").toLowerCase();
|
|
24
|
-
}
|
|
25
|
-
const H = {
|
|
26
|
-
String: { component: "ATextInput" },
|
|
27
|
-
Int: { component: "ANumericInput" },
|
|
28
|
-
Float: { component: "ANumericInput" },
|
|
29
|
-
Boolean: { component: "ACheckbox" },
|
|
30
|
-
ID: { component: "ATextInput" }
|
|
31
|
-
}, Y = {
|
|
32
|
-
// Arbitrary precision / large numbers — all numeric variants render with ANumericInput.
|
|
33
|
-
BigFloat: { component: "ANumericInput" },
|
|
34
|
-
BigDecimal: { component: "ANumericInput" },
|
|
35
|
-
Decimal: { component: "ANumericInput" },
|
|
36
|
-
BigInt: { component: "ANumericInput" },
|
|
37
|
-
Long: { component: "ANumericInput" },
|
|
38
|
-
// Identifiers
|
|
39
|
-
UUID: { component: "ATextInput" },
|
|
40
|
-
// Date / Time — no dedicated Time SFC exists; Time falls back to a plain text input.
|
|
41
|
-
DateTime: { component: "ADateTime" },
|
|
42
|
-
Datetime: { component: "ADateTime" },
|
|
43
|
-
Date: { component: "ADate" },
|
|
44
|
-
Time: { component: "ATextInput" },
|
|
45
|
-
Interval: { component: "ADuration" },
|
|
46
|
-
Duration: { component: "ADuration" },
|
|
47
|
-
// Structured data
|
|
48
|
-
JSON: { component: "ACodeEditor" },
|
|
49
|
-
JSONObject: { component: "ACodeEditor" },
|
|
50
|
-
JsonNode: { component: "ACodeEditor" }
|
|
51
|
-
}, Z = /* @__PURE__ */ new Set(["Cursor"]);
|
|
52
|
-
function X(t) {
|
|
53
|
-
const n = { ...Y };
|
|
54
|
-
for (const [i, o] of Object.entries(H))
|
|
55
|
-
n[i] = o;
|
|
56
|
-
if (t)
|
|
57
|
-
for (const [i, o] of Object.entries(t))
|
|
58
|
-
n[i] = { component: o.component ?? "ATextInput" };
|
|
59
|
-
return n;
|
|
60
|
-
}
|
|
61
|
-
const ee = [
|
|
62
|
-
"Connection",
|
|
63
|
-
"Edge",
|
|
64
|
-
"Input",
|
|
65
|
-
"Patch",
|
|
66
|
-
"Payload",
|
|
67
|
-
"Condition",
|
|
68
|
-
"Filter",
|
|
69
|
-
"OrderBy",
|
|
70
|
-
"Aggregate",
|
|
71
|
-
"AggregateResult",
|
|
72
|
-
"AggregateFilter",
|
|
73
|
-
"DeleteResponse",
|
|
74
|
-
"InsertResponse",
|
|
75
|
-
"UpdateResponse",
|
|
76
|
-
"MutationResponse"
|
|
77
|
-
], te = /* @__PURE__ */ new Set(["Query", "Mutation", "Subscription"]);
|
|
78
|
-
function ne(t, n) {
|
|
79
|
-
if (t.startsWith("__") || te.has(t) || t === "Node")
|
|
80
|
-
return !1;
|
|
81
|
-
for (const o of ee)
|
|
82
|
-
if (t.endsWith(o))
|
|
83
|
-
return !1;
|
|
84
|
-
const i = n.getFields();
|
|
85
|
-
return Object.keys(i).length !== 0;
|
|
86
|
-
}
|
|
87
|
-
const ie = /* @__PURE__ */ new Set(["nodeId", "__typename", "clientMutationId"]);
|
|
88
|
-
function oe(t, n, i) {
|
|
89
|
-
return !ie.has(t);
|
|
90
|
-
}
|
|
91
|
-
function _(t) {
|
|
92
|
-
let n = !1, i = !1, o = t;
|
|
93
|
-
if (v(o) && (n = !0, o = o.ofType), z(o) && (i = !0, o = o.ofType, v(o) && (o = o.ofType)), !B(o))
|
|
94
|
-
throw new Error(`Expected a named GraphQL type, got: ${String(o)}`);
|
|
95
|
-
return { namedType: o, required: n, isList: i };
|
|
96
|
-
}
|
|
97
|
-
function ae(t) {
|
|
98
|
-
const i = t.getFields().edges;
|
|
99
|
-
if (!i) return;
|
|
100
|
-
const { namedType: o, isList: a } = _(i.type);
|
|
101
|
-
if (!a || !k(o)) return;
|
|
102
|
-
const f = o.getFields().node;
|
|
103
|
-
if (!f) return;
|
|
104
|
-
const { namedType: g } = _(f.type);
|
|
105
|
-
if (k(g))
|
|
106
|
-
return g.name;
|
|
107
|
-
}
|
|
108
|
-
function re(t, n, i, o = {}) {
|
|
109
|
-
const { namedType: a, required: p, isList: f } = _(n.type), g = X(o.customScalars), r = {
|
|
110
|
-
kind: "field",
|
|
111
|
-
fieldname: t,
|
|
112
|
-
label: G(t),
|
|
113
|
-
component: "ATextInput"
|
|
114
|
-
};
|
|
115
|
-
if (p && (r.required = !0), K(a)) {
|
|
116
|
-
if (Z.has(a.name))
|
|
117
|
-
return r._unmapped = !0, o.includeUnmappedMeta && (r._graphqlType = a.name), r;
|
|
118
|
-
if (a.name === "ID") {
|
|
119
|
-
const u = Q(t);
|
|
120
|
-
if (i.has(u))
|
|
121
|
-
return r.component = "AFormLink", r.doctype = T(u), r;
|
|
122
|
-
}
|
|
123
|
-
const c = g[a.name];
|
|
124
|
-
return c ? r.component = c.component : (r._unmapped = !0, o.includeUnmappedMeta && (r._graphqlType = a.name)), r;
|
|
125
|
-
}
|
|
126
|
-
if (V(a))
|
|
127
|
-
return r.component = "ADropdown", r.options = a.getValues().map((c) => c.name), r;
|
|
128
|
-
if (k(a)) {
|
|
129
|
-
if (!f && i.has(a.name))
|
|
130
|
-
return r.component = "AFormLink", r.doctype = T(a.name), r;
|
|
131
|
-
const c = ae(a);
|
|
132
|
-
return c && i.has(c) ? (r.component = "ATable", r._isLink = !0, r.doctype = T(c), r.cardinality = "noneOrMany", r) : f && i.has(a.name) ? (r.component = "ATable", r._isLink = !0, r.doctype = T(a.name), r.cardinality = "noneOrMany", r) : (r._unmapped = !0, o.includeUnmappedMeta && (r._graphqlType = a.name), r);
|
|
133
|
-
}
|
|
134
|
-
return r._unmapped = !0, o.includeUnmappedMeta && (r._graphqlType = a.name), r;
|
|
135
|
-
}
|
|
136
|
-
const se = e.object({
|
|
137
|
-
/** The table view type */
|
|
138
|
-
view: e.enum(["list", "uncounted", "list-expansion", "tree", "gantt", "tree-gantt"]).optional(),
|
|
139
|
-
/** Allow the table to use the full width of its container */
|
|
140
|
-
fullWidth: e.boolean().optional(),
|
|
141
|
-
/** Default expansion state for tree views */
|
|
142
|
-
defaultTreeExpansion: e.enum(["root", "branch", "leaf"]).optional(),
|
|
143
|
-
/** Enable dependency graph connections for Gantt views */
|
|
144
|
-
dependencyGraph: e.boolean().optional()
|
|
145
|
-
}).meta({
|
|
146
|
-
title: "TableViewConfig",
|
|
147
|
-
description: "JSON-safe view configuration for table fields in doctype authoring"
|
|
148
|
-
}), le = e.union([
|
|
149
|
-
e.array(e.string()),
|
|
150
|
-
// Select choices: ["A", "B", "C"]
|
|
151
|
-
e.record(e.string(), e.unknown())
|
|
152
|
-
// Config: \{ precision: 10, scale: 2 \}
|
|
153
|
-
]).meta({
|
|
154
|
-
title: "FieldOptions",
|
|
155
|
-
description: "Field options - flexible bag for type-specific configuration"
|
|
156
|
-
}), ce = e.looseObject({
|
|
157
|
-
/** Error message to display when validation fails */
|
|
158
|
-
errorMessage: e.string()
|
|
159
|
-
}).meta({
|
|
160
|
-
title: "FieldValidation",
|
|
161
|
-
description: "Validation configuration for form fields"
|
|
162
|
-
});
|
|
163
|
-
function M(t) {
|
|
164
|
-
if (typeof t != "object" || t === null || Array.isArray(t)) return t;
|
|
165
|
-
const n = t;
|
|
166
|
-
return "kind" in n ? t : "schema" in n ? { kind: "fieldset", ...n } : "columns" in n ? { kind: "table", ...n } : { kind: "field", ...n };
|
|
167
|
-
}
|
|
168
|
-
function de(t) {
|
|
169
|
-
const n = M(t);
|
|
170
|
-
if (typeof n != "object" || n === null) return n;
|
|
171
|
-
const i = n;
|
|
172
|
-
return i.kind === "fieldset" && Array.isArray(i.schema) ? { ...i, schema: i.schema.map(de) } : n;
|
|
173
|
-
}
|
|
174
|
-
const pe = [
|
|
175
|
-
"fieldname",
|
|
176
|
-
"primaryKey",
|
|
177
|
-
"required",
|
|
178
|
-
"options",
|
|
179
|
-
"cardinality",
|
|
180
|
-
"doctype"
|
|
181
|
-
];
|
|
182
|
-
function q(t) {
|
|
183
|
-
return t.find((n) => n.kind === "field" && !!n.primaryKey);
|
|
184
|
-
}
|
|
185
|
-
function O(t) {
|
|
186
|
-
const n = [];
|
|
187
|
-
for (const i of t)
|
|
188
|
-
i.kind === "fieldset" ? n.push(...O(i.schema)) : n.push(i);
|
|
189
|
-
return n;
|
|
190
|
-
}
|
|
191
|
-
function me(t, n) {
|
|
192
|
-
if (n)
|
|
193
|
-
return O(t).find(
|
|
194
|
-
(i) => i.kind === "field" && !i.computed && i.fieldname === n
|
|
195
|
-
);
|
|
196
|
-
}
|
|
197
|
-
function qe(t) {
|
|
198
|
-
return q(t)?.fieldname ?? "id";
|
|
199
|
-
}
|
|
200
|
-
function Ee(t, n) {
|
|
201
|
-
const i = q(t), o = i ? [n[i.fieldname], n.id] : [n.id];
|
|
202
|
-
for (const a of o) {
|
|
203
|
-
if (typeof a == "number") return String(a);
|
|
204
|
-
if (typeof a == "string" && a !== "") return a;
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
function ue() {
|
|
208
|
-
const t = e.object({
|
|
209
|
-
kind: e.literal("field"),
|
|
210
|
-
fieldname: e.string().min(1),
|
|
211
|
-
component: e.string().min(1),
|
|
212
|
-
primaryKey: e.boolean().optional(),
|
|
213
|
-
computed: e.boolean().optional(),
|
|
214
|
-
language: e.string().optional(),
|
|
215
|
-
doctype: e.string().min(1).optional(),
|
|
216
|
-
label: e.string().optional(),
|
|
217
|
-
width: e.string().optional(),
|
|
218
|
-
align: e.enum(["left", "center", "right", "start", "end"]).optional(),
|
|
219
|
-
edit: e.boolean().optional(),
|
|
220
|
-
mask: e.string().optional(),
|
|
221
|
-
format: e.string().optional(),
|
|
222
|
-
mode: e.enum(["edit", "read", "display"]).optional(),
|
|
223
|
-
options: le.optional(),
|
|
224
|
-
required: e.boolean().optional(),
|
|
225
|
-
readOnly: e.boolean().optional(),
|
|
226
|
-
hidden: e.boolean().optional(),
|
|
227
|
-
default: e.unknown().optional(),
|
|
228
|
-
validation: ce.optional(),
|
|
229
|
-
cardinality: e.enum(["atMostOne", "one", "noneOrMany", "atLeastOne"]).optional(),
|
|
230
|
-
source: e.literal("introspected").optional()
|
|
231
|
-
}).meta({ title: "ValueField" }), n = e.object({
|
|
232
|
-
kind: e.literal("table"),
|
|
233
|
-
fieldname: e.string().min(1),
|
|
234
|
-
component: e.string().optional(),
|
|
235
|
-
label: e.string().optional(),
|
|
236
|
-
// Validates that each column has fieldname; allows all other ColumnSchema properties
|
|
237
|
-
columns: e.array(e.object({ fieldname: e.string().min(1) }).passthrough()),
|
|
238
|
-
config: se.optional(),
|
|
239
|
-
mode: e.enum(["edit", "read", "display"]).optional()
|
|
240
|
-
}).meta({ title: "TableField" });
|
|
241
|
-
let i = e.never();
|
|
242
|
-
const o = e.object({
|
|
243
|
-
kind: e.literal("fieldset"),
|
|
244
|
-
fieldname: e.string().min(1),
|
|
245
|
-
component: e.string().optional(),
|
|
246
|
-
label: e.string().optional(),
|
|
247
|
-
collapsible: e.boolean().optional(),
|
|
248
|
-
mode: e.enum(["edit", "read", "display"]).optional(),
|
|
249
|
-
schema: e.lazy(() => i.array())
|
|
250
|
-
}).meta({ title: "FieldsetField" }), a = e.discriminatedUnion("kind", [t, o, n]);
|
|
251
|
-
return i = e.preprocess(M, a), { ValueFieldSchema: t, TableFieldSchema: n, FieldsetFieldSchema: o, DoctypeFieldSchema: i };
|
|
252
|
-
}
|
|
253
|
-
const D = ue(), xe = D.ValueFieldSchema, Ue = D.FieldsetFieldSchema, Pe = D.TableFieldSchema, C = D.DoctypeFieldSchema;
|
|
254
|
-
function L(t) {
|
|
255
|
-
const n = [];
|
|
256
|
-
for (const i of t)
|
|
257
|
-
Array.isArray(i.schema) ? n.push(...L(i.schema.filter(j))) : n.push(i);
|
|
258
|
-
return n;
|
|
259
|
-
}
|
|
260
|
-
function j(t) {
|
|
261
|
-
return typeof t == "object" && t !== null && !Array.isArray(t);
|
|
262
|
-
}
|
|
263
|
-
function A(t) {
|
|
264
|
-
return t === void 0 ? "—" : JSON.stringify(t);
|
|
265
|
-
}
|
|
266
|
-
function Re(t, n) {
|
|
267
|
-
const i = Array.isArray(t.fields) ? t.fields.filter(j) : [], o = new Map(n.fields.map((s) => [s.fieldname, s])), a = new Set(Object.keys(n.links ?? {})), p = {
|
|
268
|
-
doctype: typeof t.name == "string" ? t.name : "(unnamed)",
|
|
269
|
-
mode: "clean",
|
|
270
|
-
tagged: [],
|
|
271
|
-
orphan: [],
|
|
272
|
-
omitted: [],
|
|
273
|
-
componentDrift: [],
|
|
274
|
-
requiredDrift: [],
|
|
275
|
-
identityDrift: []
|
|
276
|
-
}, f = (s) => {
|
|
277
|
-
if (Array.isArray(s.schema))
|
|
278
|
-
return { ...s, schema: s.schema.filter(j).map(f) };
|
|
279
|
-
const y = typeof s.fieldname == "string" ? s.fieldname : "", d = o.get(y);
|
|
280
|
-
if (!d)
|
|
281
|
-
return s.computed !== !0 && !a.has(y) && p.orphan.push(y), s;
|
|
282
|
-
p.tagged.push(y), d.component !== s.component && p.componentDrift.push(`${y}: authored=${A(s.component)} schema=${A(d.component)}`), !!d.required != !!s.required && p.requiredDrift.push(`${y}: authored=${!!s.required} schema=${!!d.required}`);
|
|
283
|
-
for (const m of pe) {
|
|
284
|
-
if (m === "fieldname" || m === "required") continue;
|
|
285
|
-
const h = s[m], F = d[m];
|
|
286
|
-
h === void 0 && F === void 0 || JSON.stringify(h) !== JSON.stringify(F) && p.identityDrift.push(`${y}.${m}: authored=${A(h)} schema=${A(F)}`);
|
|
287
|
-
}
|
|
288
|
-
return { ...s, source: "introspected" };
|
|
289
|
-
}, g = { ...t, fields: i.map(f) }, r = new Set(L(i).map((s) => s.fieldname));
|
|
290
|
-
p.omitted = n.fields.map((s) => s.fieldname).filter((s) => !r.has(s));
|
|
291
|
-
const c = L(i).find((s) => s.primaryKey === !0), u = n.fields.find((s) => s.primaryKey === !0);
|
|
292
|
-
return c && u && c.fieldname !== u.fieldname ? (p.mode = "partial", p.reason = `authored primary key '${String(c.fieldname)}' is not the derivable '${u.fieldname}' — left as authored`) : c && !u ? (p.mode = "partial", p.reason = `authored primary key '${String(c.fieldname)}' is not derivable from the schema — left as authored`) : !c && u && (p.mode = "partial", p.reason = `schema suggests '${u.fieldname}' as primary key but the doctype declares none — not applied`), { doctype: g, drift: p };
|
|
293
|
-
}
|
|
294
|
-
function Ke(t) {
|
|
295
|
-
const n = [];
|
|
296
|
-
t.reason && n.push(` ${t.doctype}: ${t.reason}`);
|
|
297
|
-
const i = (o, a) => {
|
|
298
|
-
a.length && n.push(` ${t.doctype}: ${o} ${a.join("; ")}`);
|
|
299
|
-
};
|
|
300
|
-
return i("identity drift", t.identityDrift), i("component drift", t.componentDrift), i("required drift", t.requiredDrift), i("authored fields with no schema field:", t.orphan), i("schema fields not modelled:", t.omitted), n;
|
|
301
|
-
}
|
|
302
|
-
function Ve(t, n = {}) {
|
|
303
|
-
const i = fe(t), o = i.getTypeMap(), a = /* @__PURE__ */ new Set(), p = i.getQueryType(), f = i.getMutationType(), g = i.getSubscriptionType();
|
|
304
|
-
p && a.add(p.name), f && a.add(f.name), g && a.add(g.name);
|
|
305
|
-
const r = n.isEntityType ?? ne, c = /* @__PURE__ */ new Set();
|
|
306
|
-
for (const [d, m] of Object.entries(o))
|
|
307
|
-
k(m) && (a.has(d) || r(d, m) && c.add(d));
|
|
308
|
-
let u = c;
|
|
309
|
-
if (n.include) {
|
|
310
|
-
const d = new Set(n.include);
|
|
311
|
-
u = new Set([...c].filter((m) => d.has(m)));
|
|
312
|
-
}
|
|
313
|
-
if (n.exclude) {
|
|
314
|
-
const d = new Set(n.exclude);
|
|
315
|
-
u = new Set([...u].filter((m) => !d.has(m)));
|
|
316
|
-
}
|
|
317
|
-
const s = n.isEntityField ?? oe, y = [];
|
|
318
|
-
for (const d of u) {
|
|
319
|
-
const m = o[d];
|
|
320
|
-
if (!k(m)) continue;
|
|
321
|
-
const h = m.getFields(), F = "id" in h && "rowId" in h;
|
|
322
|
-
F && n.onWarning?.(
|
|
323
|
-
`${d}: schema exposes both 'id' (Relay identifier) and 'rowId' (the real column). Skipping 'id' and emitting 'rowId' verbatim — no primary key can be derived. Override the '_attributeName' and 'nodeIdFieldName' inflectors so the column keeps its own name.`
|
|
324
|
-
);
|
|
325
|
-
const N = Object.entries(h).filter(
|
|
326
|
-
([l, b]) => s(l, b, m) && !(F && l === "id")
|
|
327
|
-
).map(([l, b]) => {
|
|
328
|
-
if (n.classifyField) {
|
|
329
|
-
const S = n.classifyField(l, b, m);
|
|
330
|
-
if (S != null)
|
|
331
|
-
return {
|
|
332
|
-
kind: "field",
|
|
333
|
-
fieldname: l,
|
|
334
|
-
label: S.label ?? l,
|
|
335
|
-
component: S.component ?? "ATextInput",
|
|
336
|
-
...S
|
|
337
|
-
};
|
|
338
|
-
}
|
|
339
|
-
return re(l, b, c, n);
|
|
340
|
-
}), x = N.find(
|
|
341
|
-
(l) => l.fieldname === "id" && l.required && !l.doctype && !l._isLink
|
|
342
|
-
)?.fieldname, w = {}, U = N.filter((l) => l._isLink && l.doctype && l.cardinality ? (w[l.fieldname] = {
|
|
343
|
-
target: l.doctype,
|
|
344
|
-
cardinality: l.cardinality
|
|
345
|
-
}, !1) : !0).map((l) => {
|
|
346
|
-
const b = l.fieldname === x ? { primaryKey: !0 } : {};
|
|
347
|
-
if (!n.includeUnmappedMeta) {
|
|
348
|
-
const { _graphqlType: _e, _unmapped: Le, _isLink: je, ...R } = l;
|
|
349
|
-
return Object.assign(R, b, { source: "introspected" });
|
|
350
|
-
}
|
|
351
|
-
const { _isLink: S, ...P } = l;
|
|
352
|
-
return Object.assign(P, b, { source: "introspected" });
|
|
353
|
-
}), $ = n.doctypeNames?.[d] ?? d, I = {
|
|
354
|
-
name: $,
|
|
355
|
-
slug: T($),
|
|
356
|
-
fields: U
|
|
357
|
-
};
|
|
358
|
-
Object.keys(w).length > 0 && (I.links = w), n.includeUnmappedMeta && (I._graphqlTypeName = d), y.push(I);
|
|
359
|
-
}
|
|
360
|
-
return y;
|
|
361
|
-
}
|
|
362
|
-
function fe(t) {
|
|
363
|
-
return typeof t == "string" ? W(t) : J(t);
|
|
364
|
-
}
|
|
365
|
-
const ye = e.enum(["atMostOne", "one", "noneOrMany", "atLeastOne"]).meta({
|
|
366
|
-
title: "Cardinality",
|
|
367
|
-
description: "Cardinality for relationship links between doctypes"
|
|
368
|
-
}), ge = e.object({
|
|
369
|
-
/** Fetch method type */
|
|
370
|
-
method: e.literal("sync"),
|
|
371
|
-
/** Optional limit on number of records to fetch */
|
|
372
|
-
limit: e.number().int().positive().optional()
|
|
373
|
-
}).meta({
|
|
374
|
-
title: "SyncFetch",
|
|
375
|
-
description: "Sync fetch strategy - data is fetched in the initial query"
|
|
376
|
-
}), he = e.object({
|
|
377
|
-
/** Fetch method type */
|
|
378
|
-
method: e.literal("lazy")
|
|
379
|
-
}).meta({
|
|
380
|
-
title: "LazyFetch",
|
|
381
|
-
description: "Lazy fetch strategy - data is fetched on demand in a separate query"
|
|
382
|
-
}), be = e.object({
|
|
383
|
-
/** Fetch method type */
|
|
384
|
-
method: e.literal("custom"),
|
|
385
|
-
/** Serialized handler function to invoke */
|
|
386
|
-
handler: e.string()
|
|
387
|
-
}).meta({
|
|
388
|
-
title: "CustomFetch",
|
|
389
|
-
description: "Custom fetch strategy - uses a custom handler function"
|
|
390
|
-
}), Fe = e.discriminatedUnion("method", [ge, he, be]).meta({
|
|
391
|
-
title: "FetchStrategy",
|
|
392
|
-
description: "Fetch strategy for link data loading"
|
|
393
|
-
}), Se = e.object({
|
|
394
|
-
/** Target doctype slug */
|
|
395
|
-
target: e.string().min(1),
|
|
396
|
-
/** Cardinality of the relationship */
|
|
397
|
-
cardinality: ye,
|
|
398
|
-
/** Backlink fieldname on the target doctype that points back to this link */
|
|
399
|
-
backlink: e.string().optional(),
|
|
400
|
-
/** Override default rendering component (AForm for 1:1, ATable for 1:many) */
|
|
401
|
-
component: e.string().optional(),
|
|
402
|
-
/** Fieldname of the corresponding Link field in the fields array */
|
|
403
|
-
fieldname: e.string().min(1).optional(),
|
|
404
|
-
/** Fetch strategy for loading nested data */
|
|
405
|
-
fetch: Fe.optional(),
|
|
406
|
-
/** Whether to block workflow actions until nested data is loaded (default: true) */
|
|
407
|
-
blockWorkflows: e.boolean().optional()
|
|
408
|
-
}).meta({
|
|
409
|
-
title: "LinkDeclaration",
|
|
410
|
-
description: "Declares a relationship from one doctype to another"
|
|
411
|
-
}), Te = e.object({
|
|
412
|
-
/** Display label for the action */
|
|
413
|
-
label: e.string().min(1),
|
|
414
|
-
/** Fields that must have values before action can execute */
|
|
415
|
-
requiredFields: e.array(e.string()).optional(),
|
|
416
|
-
/** Workflow states where this action is available */
|
|
417
|
-
allowedStates: e.array(e.string()).optional(),
|
|
418
|
-
/** The state the record transitions to after this action executes */
|
|
419
|
-
nextState: e.string().optional(),
|
|
420
|
-
/** True for stateless command actions with no workflow effect at all (print, email, etc.) */
|
|
421
|
-
stateless: e.boolean().optional(),
|
|
422
|
-
/**
|
|
423
|
-
* True for an internal self-transition: the action runs within the current state without
|
|
424
|
-
* advancing the workflow (e.g. `save`, which mutates record data but stays put). Scoped by
|
|
425
|
-
* `allowedStates`, rendered as a self-loop in the graph, and has no `nextState`. Distinct from
|
|
426
|
-
* `stateless` (which has no workflow presence at all): a self-transition is graph-owned and,
|
|
427
|
-
* unlike a stateless command, persists record data on dispatch.
|
|
428
|
-
*/
|
|
429
|
-
selfTransition: e.boolean().optional(),
|
|
430
|
-
/** JS function body stored as a string; executed client-side via AsyncFunction with injected API surface */
|
|
431
|
-
clientHandler: e.string().optional()
|
|
432
|
-
}).meta({
|
|
433
|
-
title: "ActionDefinition",
|
|
434
|
-
description: "Action definition within a workflow"
|
|
435
|
-
}), ke = e.object({
|
|
436
|
-
/** Optional display label; the map key is the trigger's identity */
|
|
437
|
-
label: e.string().optional(),
|
|
438
|
-
/** Fieldnames whose edits fire this trigger (fires when any listed field changes) */
|
|
439
|
-
on: e.array(e.string()),
|
|
440
|
-
/** JS function body stored as a string; run client-side with `{ record, value, setError }`. Advisory. */
|
|
441
|
-
clientHandler: e.string()
|
|
442
|
-
}).meta({
|
|
443
|
-
title: "TriggerDefinition",
|
|
444
|
-
description: "Reactive field-validation trigger — advisory client-side"
|
|
445
|
-
});
|
|
446
|
-
function ze(t, n) {
|
|
447
|
-
const i = t.allowedStates;
|
|
448
|
-
return !i || i.length === 0 ? !0 : i.includes(n);
|
|
449
|
-
}
|
|
450
|
-
const Ae = e.record(
|
|
451
|
-
e.string(),
|
|
452
|
-
e.object({
|
|
453
|
-
position: e.object({ x: e.number(), y: e.number() }).optional(),
|
|
454
|
-
targetPosition: e.enum(["left", "top", "right", "bottom"]).optional(),
|
|
455
|
-
sourcePosition: e.enum(["left", "top", "right", "bottom"]).optional()
|
|
456
|
-
})
|
|
457
|
-
), De = e.object({
|
|
458
|
-
/** List of workflow states */
|
|
459
|
-
states: e.array(e.string()).optional(),
|
|
460
|
-
/** Actions available in this workflow */
|
|
461
|
-
actions: e.record(e.string(), Te).optional(),
|
|
462
|
-
/** Reactive field-validation triggers (advisory, client-side), keyed by trigger name */
|
|
463
|
-
triggers: e.record(e.string(), ke).optional(),
|
|
464
|
-
/**
|
|
465
|
-
* DocBuilder node positions keyed by state name — authoring view-state. Persisted here so a
|
|
466
|
-
* doctype author's manual graph arrangement survives reloads; like `triggers`, it is client-only
|
|
467
|
-
* and never enters the runtime GraphQL SDL. See {@link (WorkflowLayout:variable)}.
|
|
468
|
-
*/
|
|
469
|
-
layout: Ae.optional()
|
|
470
|
-
}).meta({
|
|
471
|
-
title: "WorkflowMeta",
|
|
472
|
-
description: "Workflow metadata - states and actions for a doctype"
|
|
473
|
-
}), E = e.object({
|
|
474
|
-
/** Display name of the doctype */
|
|
475
|
-
name: e.string().min(1),
|
|
476
|
-
/** URL-friendly slug (kebab-case) */
|
|
477
|
-
slug: e.string().min(1).optional(),
|
|
478
|
-
/**
|
|
479
|
-
* Field on this doctype used when displaying a reference to one of its records.
|
|
480
|
-
* When a record elsewhere holds an inline foreign key to this doctype, the middleware
|
|
481
|
-
* returns that field as `{ id, displayText }`, reading `displayText` from this field.
|
|
482
|
-
*/
|
|
483
|
-
displayField: e.string().min(1).optional(),
|
|
484
|
-
/** Field definitions (a link field is one carrying `doctype`) */
|
|
485
|
-
fields: e.array(C),
|
|
486
|
-
/** Relationship links to other doctypes */
|
|
487
|
-
links: e.record(e.string(), Se).optional(),
|
|
488
|
-
/** Workflow configuration */
|
|
489
|
-
workflow: De.optional(),
|
|
490
|
-
/** Parent doctype for inheritance */
|
|
491
|
-
inherits: e.string().optional()
|
|
492
|
-
}).meta({
|
|
493
|
-
title: "DoctypeMeta",
|
|
494
|
-
description: "Doctype metadata - complete definition of a doctype"
|
|
495
|
-
}).superRefine((t, n) => {
|
|
496
|
-
const i = t.fields.filter((o) => o.kind === "field" && o.primaryKey);
|
|
497
|
-
if (i.length > 1 && n.addIssue({
|
|
498
|
-
code: "custom",
|
|
499
|
-
path: ["fields"],
|
|
500
|
-
message: `Doctype declares ${i.length} primaryKey fields (${i.map((o) => o.kind === "field" ? o.fieldname : "").join(
|
|
501
|
-
", "
|
|
502
|
-
)}); a record is identified by exactly one field. A composite database key is mapped to a single identity by the adapter, so a doctype never declares its parts`
|
|
503
|
-
}), t.displayField && !me(t.fields, t.displayField)) {
|
|
504
|
-
const o = O(t.fields).find((a) => a.fieldname === t.displayField);
|
|
505
|
-
n.addIssue({
|
|
506
|
-
code: "custom",
|
|
507
|
-
path: ["displayField"],
|
|
508
|
-
message: o ? `displayField "${t.displayField}" names a computed field, which has no column to read a display value from` : `displayField "${t.displayField}" is not declared on this doctype`
|
|
509
|
-
});
|
|
510
|
-
}
|
|
511
|
-
}), we = "__display";
|
|
512
|
-
function Be(t) {
|
|
513
|
-
return `${t}${we}`;
|
|
514
|
-
}
|
|
515
|
-
function We(t) {
|
|
516
|
-
const n = C.safeParse(t);
|
|
517
|
-
return n.success ? { success: !0, errors: [] } : {
|
|
518
|
-
success: !1,
|
|
519
|
-
errors: n.error.issues.map((i) => ({
|
|
520
|
-
path: i.path,
|
|
521
|
-
message: i.message
|
|
522
|
-
}))
|
|
523
|
-
};
|
|
524
|
-
}
|
|
525
|
-
function Je(t) {
|
|
526
|
-
const n = E.safeParse(t);
|
|
527
|
-
return n.success ? { success: !0, errors: [] } : {
|
|
528
|
-
success: !1,
|
|
529
|
-
errors: n.error.issues.map((i) => ({
|
|
530
|
-
path: i.path,
|
|
531
|
-
message: i.message
|
|
532
|
-
}))
|
|
533
|
-
};
|
|
534
|
-
}
|
|
535
|
-
function Ge(t) {
|
|
536
|
-
return C.parse(t);
|
|
537
|
-
}
|
|
538
|
-
function Qe(t) {
|
|
539
|
-
return E.parse(t);
|
|
540
|
-
}
|
|
541
|
-
export {
|
|
542
|
-
Te as A,
|
|
543
|
-
Ne as B,
|
|
544
|
-
ve as C,
|
|
545
|
-
C as D,
|
|
546
|
-
Q as E,
|
|
547
|
-
Ue as F,
|
|
548
|
-
H as G,
|
|
549
|
-
T as H,
|
|
550
|
-
Z as I,
|
|
551
|
-
We as J,
|
|
552
|
-
we as L,
|
|
553
|
-
Pe as T,
|
|
554
|
-
xe as V,
|
|
555
|
-
Y as W,
|
|
556
|
-
pe as a,
|
|
557
|
-
se as b,
|
|
558
|
-
Ve as c,
|
|
559
|
-
ke as d,
|
|
560
|
-
Ae as e,
|
|
561
|
-
Ke as f,
|
|
562
|
-
De as g,
|
|
563
|
-
X as h,
|
|
564
|
-
G as i,
|
|
565
|
-
$e as j,
|
|
566
|
-
re as k,
|
|
567
|
-
oe as l,
|
|
568
|
-
Re as m,
|
|
569
|
-
ne as n,
|
|
570
|
-
O as o,
|
|
571
|
-
me as p,
|
|
572
|
-
q,
|
|
573
|
-
qe as r,
|
|
574
|
-
Ee as s,
|
|
575
|
-
ze as t,
|
|
576
|
-
Be as u,
|
|
577
|
-
Je as v,
|
|
578
|
-
de as w,
|
|
579
|
-
Qe as x,
|
|
580
|
-
Ge as y,
|
|
581
|
-
Me as z
|
|
582
|
-
};
|
|
583
|
-
//# sourceMappingURL=validation-CQtfIFHQ.js.map
|