@stonecrop/schema 0.8.5 → 0.8.7
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 +329 -0
- package/dist/cli.cjs +40 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +130 -0
- package/dist/index-COrltkHl.js +400 -0
- package/dist/index-aeXXzPET.cjs +1 -0
- package/dist/index.cjs +1 -26
- package/dist/index.d.ts +226 -169
- package/dist/index.js +29 -6142
- package/package.json +8 -2
|
@@ -0,0 +1,400 @@
|
|
|
1
|
+
import { z as e } from "zod";
|
|
2
|
+
import { isScalarType as E, isEnumType as M, isObjectType as g, isNonNullType as _, isListType as v, buildSchema as x, buildClientSchema as P } from "graphql";
|
|
3
|
+
const j = e.enum([
|
|
4
|
+
"Data",
|
|
5
|
+
// Short text, varchar
|
|
6
|
+
"Text",
|
|
7
|
+
// Long text
|
|
8
|
+
"Int",
|
|
9
|
+
// Integer
|
|
10
|
+
"Float",
|
|
11
|
+
// Floating point (IEEE 754)
|
|
12
|
+
"Decimal",
|
|
13
|
+
// Arbitrary precision decimal
|
|
14
|
+
"Check",
|
|
15
|
+
// Boolean/checkbox
|
|
16
|
+
"Date",
|
|
17
|
+
// Date only
|
|
18
|
+
"Time",
|
|
19
|
+
// Time only
|
|
20
|
+
"Datetime",
|
|
21
|
+
// Date and time
|
|
22
|
+
"Duration",
|
|
23
|
+
// Time interval
|
|
24
|
+
"DateRange",
|
|
25
|
+
// Date range
|
|
26
|
+
"JSON",
|
|
27
|
+
// JSON data
|
|
28
|
+
"Code",
|
|
29
|
+
// Code/source (with syntax highlighting)
|
|
30
|
+
"Link",
|
|
31
|
+
// Reference to another doctype
|
|
32
|
+
"Doctype",
|
|
33
|
+
// Child doctype (renders as table)
|
|
34
|
+
"Attach",
|
|
35
|
+
// File attachment
|
|
36
|
+
"Currency",
|
|
37
|
+
// Currency value
|
|
38
|
+
"Quantity",
|
|
39
|
+
// Quantity with unit
|
|
40
|
+
"Select"
|
|
41
|
+
// Dropdown selection
|
|
42
|
+
]), R = {
|
|
43
|
+
// Text
|
|
44
|
+
Data: { component: "ATextInput", fieldtype: "Data" },
|
|
45
|
+
Text: { component: "ATextInput", fieldtype: "Text" },
|
|
46
|
+
// Numeric
|
|
47
|
+
Int: { component: "ANumericInput", fieldtype: "Int" },
|
|
48
|
+
Float: { component: "ANumericInput", fieldtype: "Float" },
|
|
49
|
+
Decimal: { component: "ADecimalInput", fieldtype: "Decimal" },
|
|
50
|
+
// Boolean
|
|
51
|
+
Check: { component: "ACheckbox", fieldtype: "Check" },
|
|
52
|
+
// Date/Time
|
|
53
|
+
Date: { component: "ADatePicker", fieldtype: "Date" },
|
|
54
|
+
Time: { component: "ATimeInput", fieldtype: "Time" },
|
|
55
|
+
Datetime: { component: "ADatetimePicker", fieldtype: "Datetime" },
|
|
56
|
+
Duration: { component: "ADurationInput", fieldtype: "Duration" },
|
|
57
|
+
DateRange: { component: "ADateRangePicker", fieldtype: "DateRange" },
|
|
58
|
+
// Structured
|
|
59
|
+
JSON: { component: "ACodeEditor", fieldtype: "JSON" },
|
|
60
|
+
Code: { component: "ACodeEditor", fieldtype: "Code" },
|
|
61
|
+
// Relational
|
|
62
|
+
Link: { component: "ALink", fieldtype: "Link" },
|
|
63
|
+
Doctype: { component: "ATable", fieldtype: "Doctype" },
|
|
64
|
+
// Files
|
|
65
|
+
Attach: { component: "AFileAttach", fieldtype: "Attach" },
|
|
66
|
+
// Specialized
|
|
67
|
+
Currency: { component: "ACurrencyInput", fieldtype: "Currency" },
|
|
68
|
+
Quantity: { component: "AQuantityInput", fieldtype: "Quantity" },
|
|
69
|
+
Select: { component: "ADropdown", fieldtype: "Select" }
|
|
70
|
+
};
|
|
71
|
+
function ae(t) {
|
|
72
|
+
return R[t]?.component ?? "ATextInput";
|
|
73
|
+
}
|
|
74
|
+
const U = e.union([
|
|
75
|
+
e.string(),
|
|
76
|
+
// Link/Doctype target: "customer"
|
|
77
|
+
e.array(e.string()),
|
|
78
|
+
// Select choices: ["A", "B", "C"]
|
|
79
|
+
e.record(e.string(), e.unknown())
|
|
80
|
+
// Config: \{ precision: 10, scale: 2 \}
|
|
81
|
+
]), q = e.object({
|
|
82
|
+
/** Error message to display when validation fails */
|
|
83
|
+
errorMessage: e.string()
|
|
84
|
+
}).passthrough(), S = e.object({
|
|
85
|
+
// === CORE (required) ===
|
|
86
|
+
/** Unique identifier for the field within its doctype */
|
|
87
|
+
fieldname: e.string().min(1),
|
|
88
|
+
/** Semantic field type - determines behavior and default component */
|
|
89
|
+
fieldtype: j,
|
|
90
|
+
// === COMPONENT (optional - derived from fieldtype when not specified) ===
|
|
91
|
+
/** Vue component to render this field. If not specified, derived from TYPE_MAP */
|
|
92
|
+
component: e.string().optional(),
|
|
93
|
+
// === DISPLAY ===
|
|
94
|
+
/** Human-readable label for the field */
|
|
95
|
+
label: e.string().optional(),
|
|
96
|
+
/** Width of the field (CSS value, e.g., "40ch", "200px") */
|
|
97
|
+
width: e.string().optional(),
|
|
98
|
+
/** Text alignment within the field */
|
|
99
|
+
align: e.enum(["left", "center", "right", "start", "end"]).optional(),
|
|
100
|
+
// === BEHAVIOR ===
|
|
101
|
+
/** Whether the field is required */
|
|
102
|
+
required: e.boolean().optional(),
|
|
103
|
+
/** Whether the field is read-only */
|
|
104
|
+
readOnly: e.boolean().optional(),
|
|
105
|
+
/** Whether the field is editable (for table cells) */
|
|
106
|
+
edit: e.boolean().optional(),
|
|
107
|
+
/** Whether the field is hidden from the UI */
|
|
108
|
+
hidden: e.boolean().optional(),
|
|
109
|
+
// === VALUE ===
|
|
110
|
+
/** Current value of the field */
|
|
111
|
+
value: e.unknown().optional(),
|
|
112
|
+
/** Default value for new records */
|
|
113
|
+
default: e.unknown().optional(),
|
|
114
|
+
// === TYPE-SPECIFIC ===
|
|
115
|
+
/**
|
|
116
|
+
* Type-specific options:
|
|
117
|
+
* - Link: target doctype slug ("customer")
|
|
118
|
+
* - Doctype: child doctype slug ("sales-order-item")
|
|
119
|
+
* - Select: choices array (["Draft", "Submitted"])
|
|
120
|
+
* - Decimal: \{ precision, scale \}
|
|
121
|
+
* - Code: \{ language \}
|
|
122
|
+
*/
|
|
123
|
+
options: U.optional(),
|
|
124
|
+
/** Input mask pattern (e.g., "##/##/####" for dates) */
|
|
125
|
+
mask: e.string().optional(),
|
|
126
|
+
// === VALIDATION ===
|
|
127
|
+
/** Validation configuration */
|
|
128
|
+
validation: q.optional()
|
|
129
|
+
}), J = e.object({
|
|
130
|
+
/** Display label for the action */
|
|
131
|
+
label: e.string().min(1),
|
|
132
|
+
/** Handler function name or path */
|
|
133
|
+
handler: e.string().min(1),
|
|
134
|
+
/** Fields that must have values before action can execute */
|
|
135
|
+
requiredFields: e.array(e.string()).optional(),
|
|
136
|
+
/** Workflow states where this action is available */
|
|
137
|
+
allowedStates: e.array(e.string()).optional(),
|
|
138
|
+
/** Whether to show a confirmation dialog */
|
|
139
|
+
confirm: e.boolean().optional(),
|
|
140
|
+
/** Additional arguments for the action */
|
|
141
|
+
args: e.record(e.string(), e.unknown()).optional()
|
|
142
|
+
}), Q = e.object({
|
|
143
|
+
/** List of workflow states */
|
|
144
|
+
states: e.array(e.string()).optional(),
|
|
145
|
+
/** Actions available in this workflow */
|
|
146
|
+
actions: e.record(e.string(), J).optional()
|
|
147
|
+
}), k = e.object({
|
|
148
|
+
/** Display name of the doctype */
|
|
149
|
+
name: e.string().min(1),
|
|
150
|
+
/** URL-friendly slug (kebab-case) */
|
|
151
|
+
slug: e.string().min(1).optional(),
|
|
152
|
+
/** Database table name */
|
|
153
|
+
tableName: e.string().optional(),
|
|
154
|
+
/** Field definitions */
|
|
155
|
+
fields: e.array(S),
|
|
156
|
+
/** Workflow configuration */
|
|
157
|
+
workflow: Q.optional(),
|
|
158
|
+
/** Parent doctype for inheritance */
|
|
159
|
+
inherits: e.string().optional(),
|
|
160
|
+
/** Doctype to use for list views */
|
|
161
|
+
listDoctype: e.string().optional(),
|
|
162
|
+
/** Parent doctype for child tables */
|
|
163
|
+
parentDoctype: e.string().optional()
|
|
164
|
+
});
|
|
165
|
+
function re(t) {
|
|
166
|
+
const n = S.safeParse(t);
|
|
167
|
+
return n.success ? { success: !0, errors: [] } : {
|
|
168
|
+
success: !1,
|
|
169
|
+
errors: n.error.issues.map((i) => ({
|
|
170
|
+
path: i.path,
|
|
171
|
+
message: i.message
|
|
172
|
+
}))
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
function pe(t) {
|
|
176
|
+
const n = k.safeParse(t);
|
|
177
|
+
return n.success ? { success: !0, errors: [] } : {
|
|
178
|
+
success: !1,
|
|
179
|
+
errors: n.error.issues.map((i) => ({
|
|
180
|
+
path: i.path,
|
|
181
|
+
message: i.message
|
|
182
|
+
}))
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
function se(t) {
|
|
186
|
+
return S.parse(t);
|
|
187
|
+
}
|
|
188
|
+
function ce(t) {
|
|
189
|
+
return k.parse(t);
|
|
190
|
+
}
|
|
191
|
+
function le(t) {
|
|
192
|
+
return t.replace(/_([a-z])/g, (n, i) => i.toUpperCase());
|
|
193
|
+
}
|
|
194
|
+
function ue(t) {
|
|
195
|
+
return t.replace(/[A-Z]/g, (n) => `_${n.toLowerCase()}`);
|
|
196
|
+
}
|
|
197
|
+
function de(t) {
|
|
198
|
+
return t.split("_").map((n) => n.charAt(0).toUpperCase() + n.slice(1).toLowerCase()).join(" ");
|
|
199
|
+
}
|
|
200
|
+
function W(t) {
|
|
201
|
+
const n = t.replace(/([A-Z])/g, " $1").trim();
|
|
202
|
+
return n.charAt(0).toUpperCase() + n.slice(1);
|
|
203
|
+
}
|
|
204
|
+
function fe(t) {
|
|
205
|
+
return t.split(/[-_\s]+/).map((n) => n.charAt(0).toUpperCase() + n.slice(1).toLowerCase()).join("");
|
|
206
|
+
}
|
|
207
|
+
function A(t) {
|
|
208
|
+
return t.replace(/([a-z])([A-Z])/g, "$1-$2").replace(/[\s_]+/g, "-").toLowerCase();
|
|
209
|
+
}
|
|
210
|
+
function $(t) {
|
|
211
|
+
return t.replace(/([a-z])([A-Z])/g, "$1_$2").replace(/[\s-]+/g, "_").toLowerCase();
|
|
212
|
+
}
|
|
213
|
+
const B = {
|
|
214
|
+
String: { component: "ATextInput", fieldtype: "Data" },
|
|
215
|
+
Int: { component: "ANumericInput", fieldtype: "Int" },
|
|
216
|
+
Float: { component: "ANumericInput", fieldtype: "Float" },
|
|
217
|
+
Boolean: { component: "ACheckbox", fieldtype: "Check" },
|
|
218
|
+
ID: { component: "ATextInput", fieldtype: "Data" }
|
|
219
|
+
}, z = {
|
|
220
|
+
// Arbitrary precision / large numbers
|
|
221
|
+
BigFloat: { component: "ADecimalInput", fieldtype: "Decimal" },
|
|
222
|
+
BigDecimal: { component: "ADecimalInput", fieldtype: "Decimal" },
|
|
223
|
+
Decimal: { component: "ADecimalInput", fieldtype: "Decimal" },
|
|
224
|
+
BigInt: { component: "ANumericInput", fieldtype: "Int" },
|
|
225
|
+
Long: { component: "ANumericInput", fieldtype: "Int" },
|
|
226
|
+
// Identifiers
|
|
227
|
+
UUID: { component: "ATextInput", fieldtype: "Data" },
|
|
228
|
+
// Date / Time
|
|
229
|
+
DateTime: { component: "ADatetimePicker", fieldtype: "Datetime" },
|
|
230
|
+
Datetime: { component: "ADatetimePicker", fieldtype: "Datetime" },
|
|
231
|
+
Date: { component: "ADatePicker", fieldtype: "Date" },
|
|
232
|
+
Time: { component: "ATimeInput", fieldtype: "Time" },
|
|
233
|
+
Interval: { component: "ADurationInput", fieldtype: "Duration" },
|
|
234
|
+
Duration: { component: "ADurationInput", fieldtype: "Duration" },
|
|
235
|
+
// Structured data
|
|
236
|
+
JSON: { component: "ACodeEditor", fieldtype: "JSON" },
|
|
237
|
+
JSONObject: { component: "ACodeEditor", fieldtype: "JSON" },
|
|
238
|
+
JsonNode: { component: "ACodeEditor", fieldtype: "JSON" }
|
|
239
|
+
}, G = /* @__PURE__ */ new Set(["Cursor"]);
|
|
240
|
+
function Z(t) {
|
|
241
|
+
const n = { ...z };
|
|
242
|
+
for (const [i, a] of Object.entries(B))
|
|
243
|
+
n[i] = a;
|
|
244
|
+
if (t)
|
|
245
|
+
for (const [i, a] of Object.entries(t))
|
|
246
|
+
n[i] = {
|
|
247
|
+
component: a.component ?? "ATextInput",
|
|
248
|
+
fieldtype: a.fieldtype ?? "Data"
|
|
249
|
+
};
|
|
250
|
+
return n;
|
|
251
|
+
}
|
|
252
|
+
const Y = [
|
|
253
|
+
"Connection",
|
|
254
|
+
"Edge",
|
|
255
|
+
"Input",
|
|
256
|
+
"Patch",
|
|
257
|
+
"Payload",
|
|
258
|
+
"Condition",
|
|
259
|
+
"Filter",
|
|
260
|
+
"OrderBy",
|
|
261
|
+
"Aggregate",
|
|
262
|
+
"AggregateResult",
|
|
263
|
+
"AggregateFilter",
|
|
264
|
+
"DeleteResponse",
|
|
265
|
+
"InsertResponse",
|
|
266
|
+
"UpdateResponse",
|
|
267
|
+
"MutationResponse"
|
|
268
|
+
], K = /* @__PURE__ */ new Set(["Query", "Mutation", "Subscription"]);
|
|
269
|
+
function V(t, n) {
|
|
270
|
+
if (t.startsWith("__") || K.has(t) || t === "Node")
|
|
271
|
+
return !1;
|
|
272
|
+
for (const a of Y)
|
|
273
|
+
if (t.endsWith(a))
|
|
274
|
+
return !1;
|
|
275
|
+
const i = n.getFields();
|
|
276
|
+
return Object.keys(i).length !== 0;
|
|
277
|
+
}
|
|
278
|
+
const H = /* @__PURE__ */ new Set(["nodeId", "__typename", "clientMutationId"]);
|
|
279
|
+
function X(t, n, i) {
|
|
280
|
+
return !H.has(t);
|
|
281
|
+
}
|
|
282
|
+
function I(t) {
|
|
283
|
+
let n = !1, i = !1, a = t;
|
|
284
|
+
return _(a) && (n = !0, a = a.ofType), v(a) && (i = !0, a = a.ofType, _(a) && (a = a.ofType)), { namedType: a, required: n, isList: i };
|
|
285
|
+
}
|
|
286
|
+
function ee(t) {
|
|
287
|
+
const i = t.getFields().edges;
|
|
288
|
+
if (!i) return;
|
|
289
|
+
const { namedType: a, isList: r } = I(i.type);
|
|
290
|
+
if (!r || !g(a)) return;
|
|
291
|
+
const u = a.getFields().node;
|
|
292
|
+
if (!u) return;
|
|
293
|
+
const { namedType: f } = I(u.type);
|
|
294
|
+
if (g(f))
|
|
295
|
+
return f.name;
|
|
296
|
+
}
|
|
297
|
+
function te(t, n, i, a = {}) {
|
|
298
|
+
const { namedType: r, required: m, isList: u } = I(n.type), f = Z(a.customScalars), o = {
|
|
299
|
+
fieldname: t,
|
|
300
|
+
label: W(t),
|
|
301
|
+
component: "ATextInput",
|
|
302
|
+
fieldtype: "Data"
|
|
303
|
+
};
|
|
304
|
+
if (m && (o.required = !0), E(r)) {
|
|
305
|
+
if (G.has(r.name))
|
|
306
|
+
return o._unmapped = !0, a.includeUnmappedMeta && (o._graphqlType = r.name), o;
|
|
307
|
+
const s = f[r.name];
|
|
308
|
+
return s ? (o.component = s.component, o.fieldtype = s.fieldtype) : (o._unmapped = !0, a.includeUnmappedMeta && (o._graphqlType = r.name)), o;
|
|
309
|
+
}
|
|
310
|
+
if (M(r))
|
|
311
|
+
return o.component = "ADropdown", o.fieldtype = "Select", o.options = r.getValues().map((s) => s.name), o;
|
|
312
|
+
if (g(r)) {
|
|
313
|
+
if (!u && i.has(r.name))
|
|
314
|
+
return o.component = "ALink", o.fieldtype = "Link", o.options = A(r.name), o;
|
|
315
|
+
const s = ee(r);
|
|
316
|
+
return s && i.has(s) ? (o.component = "ATable", o.fieldtype = "Doctype", o.options = A(s), o) : u && i.has(r.name) ? (o.component = "ATable", o.fieldtype = "Doctype", o.options = A(r.name), o) : (o._unmapped = !0, a.includeUnmappedMeta && (o._graphqlType = r.name), o);
|
|
317
|
+
}
|
|
318
|
+
return o._unmapped = !0, a.includeUnmappedMeta && (o._graphqlType = r.name), o;
|
|
319
|
+
}
|
|
320
|
+
function me(t, n = {}) {
|
|
321
|
+
const i = ne(t), a = i.getTypeMap(), r = /* @__PURE__ */ new Set(), m = i.getQueryType(), u = i.getMutationType(), f = i.getSubscriptionType();
|
|
322
|
+
m && r.add(m.name), u && r.add(u.name), f && r.add(f.name);
|
|
323
|
+
const o = n.isEntityType ?? V, s = /* @__PURE__ */ new Set();
|
|
324
|
+
for (const [p, c] of Object.entries(a))
|
|
325
|
+
g(c) && (r.has(p) || o(p, c) && s.add(p));
|
|
326
|
+
let T = s;
|
|
327
|
+
if (n.include) {
|
|
328
|
+
const p = new Set(n.include);
|
|
329
|
+
T = new Set([...s].filter((c) => p.has(c)));
|
|
330
|
+
}
|
|
331
|
+
if (n.exclude) {
|
|
332
|
+
const p = new Set(n.exclude);
|
|
333
|
+
T = new Set([...T].filter((c) => !p.has(c)));
|
|
334
|
+
}
|
|
335
|
+
const L = n.isEntityField ?? X, N = n.deriveTableName ?? ((p) => $(p)), b = [];
|
|
336
|
+
for (const p of T) {
|
|
337
|
+
const c = a[p];
|
|
338
|
+
if (!g(c)) continue;
|
|
339
|
+
const w = c.getFields(), C = n.typeOverrides?.[p], O = Object.entries(w).filter(([l, y]) => L(l, y, c)).map(([l, y]) => {
|
|
340
|
+
if (n.classifyField) {
|
|
341
|
+
const d = n.classifyField(l, y, c);
|
|
342
|
+
if (d != null)
|
|
343
|
+
return {
|
|
344
|
+
fieldname: l,
|
|
345
|
+
label: d.label ?? l,
|
|
346
|
+
component: d.component ?? "ATextInput",
|
|
347
|
+
fieldtype: d.fieldtype ?? "Data",
|
|
348
|
+
...d
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
const h = te(l, y, s, n);
|
|
352
|
+
return C?.[l] ? { ...h, ...C[l] } : h;
|
|
353
|
+
}).map((l) => {
|
|
354
|
+
if (!n.includeUnmappedMeta) {
|
|
355
|
+
const { _graphqlType: y, _unmapped: h, ...d } = l;
|
|
356
|
+
return d;
|
|
357
|
+
}
|
|
358
|
+
return l;
|
|
359
|
+
}), D = {
|
|
360
|
+
name: p,
|
|
361
|
+
slug: A(p),
|
|
362
|
+
fields: O
|
|
363
|
+
}, F = N(p);
|
|
364
|
+
F && (D.tableName = F), n.includeUnmappedMeta && (D._graphqlTypeName = p), b.push(D);
|
|
365
|
+
}
|
|
366
|
+
return b;
|
|
367
|
+
}
|
|
368
|
+
function ne(t) {
|
|
369
|
+
return typeof t == "string" ? x(t) : P(t);
|
|
370
|
+
}
|
|
371
|
+
export {
|
|
372
|
+
J as A,
|
|
373
|
+
k as D,
|
|
374
|
+
S as F,
|
|
375
|
+
B as G,
|
|
376
|
+
G as I,
|
|
377
|
+
j as S,
|
|
378
|
+
R as T,
|
|
379
|
+
z as W,
|
|
380
|
+
U as a,
|
|
381
|
+
q as b,
|
|
382
|
+
Q as c,
|
|
383
|
+
Z as d,
|
|
384
|
+
W as e,
|
|
385
|
+
ue as f,
|
|
386
|
+
te as g,
|
|
387
|
+
me as h,
|
|
388
|
+
X as i,
|
|
389
|
+
V as j,
|
|
390
|
+
ae as k,
|
|
391
|
+
se as l,
|
|
392
|
+
$ as m,
|
|
393
|
+
de as n,
|
|
394
|
+
A as o,
|
|
395
|
+
ce as p,
|
|
396
|
+
re as q,
|
|
397
|
+
le as s,
|
|
398
|
+
fe as t,
|
|
399
|
+
pe as v
|
|
400
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const e=require("zod"),l=require("graphql"),_=e.z.enum(["Data","Text","Int","Float","Decimal","Check","Date","Time","Datetime","Duration","DateRange","JSON","Code","Link","Doctype","Attach","Currency","Quantity","Select"]),L={Data:{component:"ATextInput",fieldtype:"Data"},Text:{component:"ATextInput",fieldtype:"Text"},Int:{component:"ANumericInput",fieldtype:"Int"},Float:{component:"ANumericInput",fieldtype:"Float"},Decimal:{component:"ADecimalInput",fieldtype:"Decimal"},Check:{component:"ACheckbox",fieldtype:"Check"},Date:{component:"ADatePicker",fieldtype:"Date"},Time:{component:"ATimeInput",fieldtype:"Time"},Datetime:{component:"ADatetimePicker",fieldtype:"Datetime"},Duration:{component:"ADurationInput",fieldtype:"Duration"},DateRange:{component:"ADateRangePicker",fieldtype:"DateRange"},JSON:{component:"ACodeEditor",fieldtype:"JSON"},Code:{component:"ACodeEditor",fieldtype:"Code"},Link:{component:"ALink",fieldtype:"Link"},Doctype:{component:"ATable",fieldtype:"Doctype"},Attach:{component:"AFileAttach",fieldtype:"Attach"},Currency:{component:"ACurrencyInput",fieldtype:"Currency"},Quantity:{component:"AQuantityInput",fieldtype:"Quantity"},Select:{component:"ADropdown",fieldtype:"Select"}};function B(t){return L[t]?.component??"ATextInput"}const k=e.z.union([e.z.string(),e.z.array(e.z.string()),e.z.record(e.z.string(),e.z.unknown())]),N=e.z.object({errorMessage:e.z.string()}).passthrough(),D=e.z.object({fieldname:e.z.string().min(1),fieldtype:_,component:e.z.string().optional(),label:e.z.string().optional(),width:e.z.string().optional(),align:e.z.enum(["left","center","right","start","end"]).optional(),required:e.z.boolean().optional(),readOnly:e.z.boolean().optional(),edit:e.z.boolean().optional(),hidden:e.z.boolean().optional(),value:e.z.unknown().optional(),default:e.z.unknown().optional(),options:k.optional(),mask:e.z.string().optional(),validation:N.optional()}),O=e.z.object({label:e.z.string().min(1),handler:e.z.string().min(1),requiredFields:e.z.array(e.z.string()).optional(),allowedStates:e.z.array(e.z.string()).optional(),confirm:e.z.boolean().optional(),args:e.z.record(e.z.string(),e.z.unknown()).optional()}),E=e.z.object({states:e.z.array(e.z.string()).optional(),actions:e.z.record(e.z.string(),O).optional()}),z=e.z.object({name:e.z.string().min(1),slug:e.z.string().min(1).optional(),tableName:e.z.string().optional(),fields:e.z.array(D),workflow:E.optional(),inherits:e.z.string().optional(),listDoctype:e.z.string().optional(),parentDoctype:e.z.string().optional()});function G(t){const n=D.safeParse(t);return n.success?{success:!0,errors:[]}:{success:!1,errors:n.error.issues.map(i=>({path:i.path,message:i.message}))}}function Y(t){const n=z.safeParse(t);return n.success?{success:!0,errors:[]}:{success:!1,errors:n.error.issues.map(i=>({path:i.path,message:i.message}))}}function Z(t){return D.parse(t)}function K(t){return z.parse(t)}function V(t){return t.replace(/_([a-z])/g,(n,i)=>i.toUpperCase())}function H(t){return t.replace(/[A-Z]/g,n=>`_${n.toLowerCase()}`)}function X(t){return t.split("_").map(n=>n.charAt(0).toUpperCase()+n.slice(1).toLowerCase()).join(" ")}function M(t){const n=t.replace(/([A-Z])/g," $1").trim();return n.charAt(0).toUpperCase()+n.slice(1)}function ee(t){return t.split(/[-_\s]+/).map(n=>n.charAt(0).toUpperCase()+n.slice(1).toLowerCase()).join("")}function T(t){return t.replace(/([a-z])([A-Z])/g,"$1-$2").replace(/[\s_]+/g,"-").toLowerCase()}function w(t){return t.replace(/([a-z])([A-Z])/g,"$1_$2").replace(/[\s-]+/g,"_").toLowerCase()}const v={String:{component:"ATextInput",fieldtype:"Data"},Int:{component:"ANumericInput",fieldtype:"Int"},Float:{component:"ANumericInput",fieldtype:"Float"},Boolean:{component:"ACheckbox",fieldtype:"Check"},ID:{component:"ATextInput",fieldtype:"Data"}},P={BigFloat:{component:"ADecimalInput",fieldtype:"Decimal"},BigDecimal:{component:"ADecimalInput",fieldtype:"Decimal"},Decimal:{component:"ADecimalInput",fieldtype:"Decimal"},BigInt:{component:"ANumericInput",fieldtype:"Int"},Long:{component:"ANumericInput",fieldtype:"Int"},UUID:{component:"ATextInput",fieldtype:"Data"},DateTime:{component:"ADatetimePicker",fieldtype:"Datetime"},Datetime:{component:"ADatetimePicker",fieldtype:"Datetime"},Date:{component:"ADatePicker",fieldtype:"Date"},Time:{component:"ATimeInput",fieldtype:"Time"},Interval:{component:"ADurationInput",fieldtype:"Duration"},Duration:{component:"ADurationInput",fieldtype:"Duration"},JSON:{component:"ACodeEditor",fieldtype:"JSON"},JSONObject:{component:"ACodeEditor",fieldtype:"JSON"},JsonNode:{component:"ACodeEditor",fieldtype:"JSON"}},j=new Set(["Cursor"]);function x(t){const n={...P};for(const[i,a]of Object.entries(v))n[i]=a;if(t)for(const[i,a]of Object.entries(t))n[i]={component:a.component??"ATextInput",fieldtype:a.fieldtype??"Data"};return n}const te=["Connection","Edge","Input","Patch","Payload","Condition","Filter","OrderBy","Aggregate","AggregateResult","AggregateFilter","DeleteResponse","InsertResponse","UpdateResponse","MutationResponse"],ne=new Set(["Query","Mutation","Subscription"]);function R(t,n){if(t.startsWith("__")||ne.has(t)||t==="Node")return!1;for(const a of te)if(t.endsWith(a))return!1;const i=n.getFields();return Object.keys(i).length!==0}const oe=new Set(["nodeId","__typename","clientMutationId"]);function q(t,n,i){return!oe.has(t)}function I(t){let n=!1,i=!1,a=t;return l.isNonNullType(a)&&(n=!0,a=a.ofType),l.isListType(a)&&(i=!0,a=a.ofType,l.isNonNullType(a)&&(a=a.ofType)),{namedType:a,required:n,isList:i}}function ie(t){const i=t.getFields().edges;if(!i)return;const{namedType:a,isList:r}=I(i.type);if(!r||!l.isObjectType(a))return;const d=a.getFields().node;if(!d)return;const{namedType:m}=I(d.type);if(l.isObjectType(m))return m.name}function U(t,n,i,a={}){const{namedType:r,required:y,isList:d}=I(n.type),m=x(a.customScalars),o={fieldname:t,label:M(t),component:"ATextInput",fieldtype:"Data"};if(y&&(o.required=!0),l.isScalarType(r)){if(j.has(r.name))return o._unmapped=!0,a.includeUnmappedMeta&&(o._graphqlType=r.name),o;const c=m[r.name];return c?(o.component=c.component,o.fieldtype=c.fieldtype):(o._unmapped=!0,a.includeUnmappedMeta&&(o._graphqlType=r.name)),o}if(l.isEnumType(r))return o.component="ADropdown",o.fieldtype="Select",o.options=r.getValues().map(c=>c.name),o;if(l.isObjectType(r)){if(!d&&i.has(r.name))return o.component="ALink",o.fieldtype="Link",o.options=T(r.name),o;const c=ie(r);return c&&i.has(c)?(o.component="ATable",o.fieldtype="Doctype",o.options=T(c),o):d&&i.has(r.name)?(o.component="ATable",o.fieldtype="Doctype",o.options=T(r.name),o):(o._unmapped=!0,a.includeUnmappedMeta&&(o._graphqlType=r.name),o)}return o._unmapped=!0,a.includeUnmappedMeta&&(o._graphqlType=r.name),o}function ae(t,n={}){const i=re(t),a=i.getTypeMap(),r=new Set,y=i.getQueryType(),d=i.getMutationType(),m=i.getSubscriptionType();y&&r.add(y.name),d&&r.add(d.name),m&&r.add(m.name);const o=n.isEntityType??R,c=new Set;for(const[p,s]of Object.entries(a))l.isObjectType(s)&&(r.has(p)||o(p,s)&&c.add(p));let A=c;if(n.include){const p=new Set(n.include);A=new Set([...c].filter(s=>p.has(s)))}if(n.exclude){const p=new Set(n.exclude);A=new Set([...A].filter(s=>!p.has(s)))}const Q=n.isEntityField??q,J=n.deriveTableName??(p=>w(p)),b=[];for(const p of A){const s=a[p];if(!l.isObjectType(s))continue;const W=s.getFields(),C=n.typeOverrides?.[p],$=Object.entries(W).filter(([u,g])=>Q(u,g,s)).map(([u,g])=>{if(n.classifyField){const f=n.classifyField(u,g,s);if(f!=null)return{fieldname:u,label:f.label??u,component:f.component??"ATextInput",fieldtype:f.fieldtype??"Data",...f}}const h=U(u,g,c,n);return C?.[u]?{...h,...C[u]}:h}).map(u=>{if(!n.includeUnmappedMeta){const{_graphqlType:g,_unmapped:h,...f}=u;return f}return u}),S={name:p,slug:T(p),fields:$},F=J(p);F&&(S.tableName=F),n.includeUnmappedMeta&&(S._graphqlTypeName=p),b.push(S)}return b}function re(t){return typeof t=="string"?l.buildSchema(t):l.buildClientSchema(t)}exports.ActionDefinition=O;exports.DoctypeMeta=z;exports.FieldMeta=D;exports.FieldOptions=k;exports.FieldValidation=N;exports.GQL_SCALAR_MAP=v;exports.INTERNAL_SCALARS=j;exports.StonecropFieldType=_;exports.TYPE_MAP=L;exports.WELL_KNOWN_SCALARS=P;exports.WorkflowMeta=E;exports.buildScalarMap=x;exports.camelToLabel=M;exports.camelToSnake=H;exports.classifyFieldType=U;exports.convertGraphQLSchema=ae;exports.defaultIsEntityField=q;exports.defaultIsEntityType=R;exports.getDefaultComponent=B;exports.parseDoctype=K;exports.parseField=Z;exports.pascalToSnake=w;exports.snakeToCamel=V;exports.snakeToLabel=X;exports.toPascalCase=ee;exports.toSlug=T;exports.validateDoctype=Y;exports.validateField=G;
|