@stonecrop/schema 0.10.3 → 0.10.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -3,7 +3,7 @@ import { readFileSync as u, existsSync as S, mkdirSync as w, writeFileSync as x
3
3
  import { resolve as c, join as O } from "node:path";
4
4
  import { parseArgs as $ } from "node:util";
5
5
  import { getIntrospectionQuery as N } from "graphql";
6
- import { h as P, v as j } from "./index-CzoRIy1-.js";
6
+ import { h as P, v as j } from "./index-BatnoC-J.js";
7
7
  async function C(e, m) {
8
8
  const t = await fetch(e, {
9
9
  method: "POST",
package/dist/doctype.js CHANGED
@@ -4,7 +4,8 @@ import { FieldMeta } from './field';
4
4
  * Action definition within a workflow
5
5
  * @public
6
6
  */
7
- export const ActionDefinition = z.object({
7
+ export const ActionDefinition = z
8
+ .object({
8
9
  /** Display label for the action */
9
10
  label: z.string().min(1),
10
11
  /** Handler function name or path */
@@ -17,22 +18,32 @@ export const ActionDefinition = z.object({
17
18
  confirm: z.boolean().optional(),
18
19
  /** Additional arguments for the action */
19
20
  args: z.record(z.string(), z.unknown()).optional(),
21
+ })
22
+ .meta({
23
+ title: 'ActionDefinition',
24
+ description: 'Action definition within a workflow',
20
25
  });
21
26
  /**
22
27
  * Workflow metadata - states and actions for a doctype
23
28
  * @public
24
29
  */
25
- export const WorkflowMeta = z.object({
30
+ export const WorkflowMeta = z
31
+ .object({
26
32
  /** List of workflow states */
27
33
  states: z.array(z.string()).optional(),
28
34
  /** Actions available in this workflow */
29
35
  actions: z.record(z.string(), ActionDefinition).optional(),
36
+ })
37
+ .meta({
38
+ title: 'WorkflowMeta',
39
+ description: 'Workflow metadata - states and actions for a doctype',
30
40
  });
31
41
  /**
32
42
  * Doctype metadata - complete definition of a doctype
33
43
  * @public
34
44
  */
35
- export const DoctypeMeta = z.object({
45
+ export const DoctypeMeta = z
46
+ .object({
36
47
  /** Display name of the doctype */
37
48
  name: z.string().min(1),
38
49
  /** URL-friendly slug (kebab-case) */
@@ -49,4 +60,8 @@ export const DoctypeMeta = z.object({
49
60
  listDoctype: z.string().optional(),
50
61
  /** Parent doctype for child tables */
51
62
  parentDoctype: z.string().optional(),
63
+ })
64
+ .meta({
65
+ title: 'DoctypeMeta',
66
+ description: 'Doctype metadata - complete definition of a doctype',
52
67
  });
package/dist/field.js CHANGED
@@ -11,21 +11,29 @@ import { StonecropFieldType } from './fieldtype';
11
11
  *
12
12
  * @public
13
13
  */
14
- export const FieldOptions = z.union([
14
+ export const FieldOptions = z
15
+ .union([
15
16
  z.string(), // Link/Doctype target: "customer"
16
17
  z.array(z.string()), // Select choices: ["A", "B", "C"]
17
18
  z.record(z.string(), z.unknown()), // Config: \{ precision: 10, scale: 2 \}
18
- ]);
19
+ ])
20
+ .meta({
21
+ title: 'FieldOptions',
22
+ description: 'Field options - flexible bag for type-specific configuration',
23
+ });
19
24
  /**
20
25
  * Validation configuration for form fields
21
26
  * @public
22
27
  */
23
28
  export const FieldValidation = z
24
- .object({
29
+ .looseObject({
25
30
  /** Error message to display when validation fails */
26
31
  errorMessage: z.string(),
27
32
  })
28
- .passthrough();
33
+ .meta({
34
+ title: 'FieldValidation',
35
+ description: 'Validation configuration for form fields',
36
+ });
29
37
  /**
30
38
  * Unified field metadata - the single source of truth for field definitions.
31
39
  * Works for both forms (AForm) and tables (ATable).
@@ -34,7 +42,8 @@ export const FieldValidation = z
34
42
  *
35
43
  * @public
36
44
  */
37
- export const FieldMeta = z.object({
45
+ export const FieldMeta = z
46
+ .object({
38
47
  // === CORE (required) ===
39
48
  /** Unique identifier for the field within its doctype */
40
49
  fieldname: z.string().min(1),
@@ -86,4 +95,8 @@ export const FieldMeta = z.object({
86
95
  // === VALIDATION ===
87
96
  /** Validation configuration */
88
97
  validation: FieldValidation.optional(),
98
+ })
99
+ .meta({
100
+ title: 'FieldMeta',
101
+ description: 'Unified field metadata - the single source of truth for field definitions, works for both forms (AForm) and tables (ATable)',
89
102
  });
package/dist/fieldtype.js CHANGED
@@ -4,7 +4,8 @@ import { z } from 'zod';
4
4
  * These are consistent across forms and tables.
5
5
  * @public
6
6
  */
7
- export const StonecropFieldType = z.enum([
7
+ export const StonecropFieldType = z
8
+ .enum([
8
9
  'Data', // Short text, varchar
9
10
  'Text', // Long text
10
11
  'Int', // Integer
@@ -24,7 +25,11 @@ export const StonecropFieldType = z.enum([
24
25
  'Currency', // Currency value
25
26
  'Quantity', // Quantity with unit
26
27
  'Select', // Dropdown selection
27
- ]);
28
+ ])
29
+ .meta({
30
+ title: 'StonecropFieldType',
31
+ description: 'Semantic field types for Stonecrop doctypes, consistent across forms and tables',
32
+ });
28
33
  /**
29
34
  * Mapping from StonecropFieldType to default Vue component.
30
35
  * Components can be overridden in the field definition.
@@ -1,6 +1,6 @@
1
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 j } from "graphql";
3
- const P = e.enum([
2
+ import { isScalarType as M, isEnumType as E, isObjectType as g, isNonNullType as k, isListType as x, buildSchema as v, buildClientSchema as j } from "graphql";
3
+ const U = e.enum([
4
4
  "Data",
5
5
  // Short text, varchar
6
6
  "Text",
@@ -39,7 +39,10 @@ const P = e.enum([
39
39
  // Quantity with unit
40
40
  "Select"
41
41
  // Dropdown selection
42
- ]), R = {
42
+ ]).meta({
43
+ title: "StonecropFieldType",
44
+ description: "Semantic field types for Stonecrop doctypes, consistent across forms and tables"
45
+ }), P = {
43
46
  // Text
44
47
  Data: { component: "ATextInput", fieldtype: "Data" },
45
48
  Text: { component: "ATextInput", fieldtype: "Text" },
@@ -69,24 +72,30 @@ const P = e.enum([
69
72
  Select: { component: "ADropdown", fieldtype: "Select" }
70
73
  };
71
74
  function ae(t) {
72
- return R[t]?.component ?? "ATextInput";
75
+ return P[t]?.component ?? "ATextInput";
73
76
  }
74
- const U = e.union([
77
+ const R = e.union([
75
78
  e.string(),
76
79
  // Link/Doctype target: "customer"
77
80
  e.array(e.string()),
78
81
  // Select choices: ["A", "B", "C"]
79
82
  e.record(e.string(), e.unknown())
80
83
  // Config: \{ precision: 10, scale: 2 \}
81
- ]), q = e.object({
84
+ ]).meta({
85
+ title: "FieldOptions",
86
+ description: "Field options - flexible bag for type-specific configuration"
87
+ }), q = e.looseObject({
82
88
  /** Error message to display when validation fails */
83
89
  errorMessage: e.string()
84
- }).passthrough(), S = e.object({
90
+ }).meta({
91
+ title: "FieldValidation",
92
+ description: "Validation configuration for form fields"
93
+ }), I = e.object({
85
94
  // === CORE (required) ===
86
95
  /** Unique identifier for the field within its doctype */
87
96
  fieldname: e.string().min(1),
88
97
  /** Semantic field type - determines behavior and default component */
89
- fieldtype: P,
98
+ fieldtype: U,
90
99
  // === COMPONENT (optional - derived from fieldtype when not specified) ===
91
100
  /** Vue component to render this field. If not specified, derived from TYPE_MAP */
92
101
  component: e.string().optional(),
@@ -120,7 +129,7 @@ const U = e.union([
120
129
  * - Decimal: \{ precision, scale \}
121
130
  * - Code: \{ language \}
122
131
  */
123
- options: U.optional(),
132
+ options: R.optional(),
124
133
  /**
125
134
  * Input mask pattern. Accepts either a plain mask string or a stringified
126
135
  * arrow function that receives `locale` and returns a mask string.
@@ -133,6 +142,9 @@ const U = e.union([
133
142
  // === VALIDATION ===
134
143
  /** Validation configuration */
135
144
  validation: q.optional()
145
+ }).meta({
146
+ title: "FieldMeta",
147
+ description: "Unified field metadata - the single source of truth for field definitions, works for both forms (AForm) and tables (ATable)"
136
148
  }), J = e.object({
137
149
  /** Display label for the action */
138
150
  label: e.string().min(1),
@@ -146,12 +158,18 @@ const U = e.union([
146
158
  confirm: e.boolean().optional(),
147
159
  /** Additional arguments for the action */
148
160
  args: e.record(e.string(), e.unknown()).optional()
161
+ }).meta({
162
+ title: "ActionDefinition",
163
+ description: "Action definition within a workflow"
149
164
  }), Q = e.object({
150
165
  /** List of workflow states */
151
166
  states: e.array(e.string()).optional(),
152
167
  /** Actions available in this workflow */
153
168
  actions: e.record(e.string(), J).optional()
154
- }), k = e.object({
169
+ }).meta({
170
+ title: "WorkflowMeta",
171
+ description: "Workflow metadata - states and actions for a doctype"
172
+ }), _ = e.object({
155
173
  /** Display name of the doctype */
156
174
  name: e.string().min(1),
157
175
  /** URL-friendly slug (kebab-case) */
@@ -159,7 +177,7 @@ const U = e.union([
159
177
  /** Database table name */
160
178
  tableName: e.string().optional(),
161
179
  /** Field definitions */
162
- fields: e.array(S),
180
+ fields: e.array(I),
163
181
  /** Workflow configuration */
164
182
  workflow: Q.optional(),
165
183
  /** Parent doctype for inheritance */
@@ -168,9 +186,12 @@ const U = e.union([
168
186
  listDoctype: e.string().optional(),
169
187
  /** Parent doctype for child tables */
170
188
  parentDoctype: e.string().optional()
189
+ }).meta({
190
+ title: "DoctypeMeta",
191
+ description: "Doctype metadata - complete definition of a doctype"
171
192
  });
172
193
  function re(t) {
173
- const n = S.safeParse(t);
194
+ const n = I.safeParse(t);
174
195
  return n.success ? { success: !0, errors: [] } : {
175
196
  success: !1,
176
197
  errors: n.error.issues.map((i) => ({
@@ -180,7 +201,7 @@ function re(t) {
180
201
  };
181
202
  }
182
203
  function pe(t) {
183
- const n = k.safeParse(t);
204
+ const n = _.safeParse(t);
184
205
  return n.success ? { success: !0, errors: [] } : {
185
206
  success: !1,
186
207
  errors: n.error.issues.map((i) => ({
@@ -190,18 +211,18 @@ function pe(t) {
190
211
  };
191
212
  }
192
213
  function se(t) {
193
- return S.parse(t);
214
+ return I.parse(t);
194
215
  }
195
216
  function ce(t) {
196
- return k.parse(t);
217
+ return _.parse(t);
197
218
  }
198
219
  function le(t) {
199
220
  return t.replace(/_([a-z])/g, (n, i) => i.toUpperCase());
200
221
  }
201
- function ue(t) {
222
+ function de(t) {
202
223
  return t.replace(/[A-Z]/g, (n) => `_${n.toLowerCase()}`);
203
224
  }
204
- function de(t) {
225
+ function ue(t) {
205
226
  return t.split("_").map((n) => n.charAt(0).toUpperCase() + n.slice(1).toLowerCase()).join(" ");
206
227
  }
207
228
  function W(t) {
@@ -211,7 +232,7 @@ function W(t) {
211
232
  function fe(t) {
212
233
  return t.split(/[-_\s]+/).map((n) => n.charAt(0).toUpperCase() + n.slice(1).toLowerCase()).join("");
213
234
  }
214
- function A(t) {
235
+ function T(t) {
215
236
  return t.replace(/([a-z])([A-Z])/g, "$1-$2").replace(/[\s_]+/g, "-").toLowerCase();
216
237
  }
217
238
  function $(t) {
@@ -244,7 +265,7 @@ const B = {
244
265
  JSONObject: { component: "ACodeEditor", fieldtype: "JSON" },
245
266
  JsonNode: { component: "ACodeEditor", fieldtype: "JSON" }
246
267
  }, G = /* @__PURE__ */ new Set(["Cursor"]);
247
- function Z(t) {
268
+ function V(t) {
248
269
  const n = { ...z };
249
270
  for (const [i, a] of Object.entries(B))
250
271
  n[i] = a;
@@ -256,7 +277,7 @@ function Z(t) {
256
277
  };
257
278
  return n;
258
279
  }
259
- const Y = [
280
+ const Z = [
260
281
  "Connection",
261
282
  "Edge",
262
283
  "Input",
@@ -272,11 +293,11 @@ const Y = [
272
293
  "InsertResponse",
273
294
  "UpdateResponse",
274
295
  "MutationResponse"
275
- ], K = /* @__PURE__ */ new Set(["Query", "Mutation", "Subscription"]);
276
- function V(t, n) {
277
- if (t.startsWith("__") || K.has(t) || t === "Node")
296
+ ], Y = /* @__PURE__ */ new Set(["Query", "Mutation", "Subscription"]);
297
+ function K(t, n) {
298
+ if (t.startsWith("__") || Y.has(t) || t === "Node")
278
299
  return !1;
279
- for (const a of Y)
300
+ for (const a of Z)
280
301
  if (t.endsWith(a))
281
302
  return !1;
282
303
  const i = n.getFields();
@@ -286,123 +307,123 @@ const H = /* @__PURE__ */ new Set(["nodeId", "__typename", "clientMutationId"]);
286
307
  function X(t, n, i) {
287
308
  return !H.has(t);
288
309
  }
289
- function I(t) {
310
+ function S(t) {
290
311
  let n = !1, i = !1, a = t;
291
- return _(a) && (n = !0, a = a.ofType), v(a) && (i = !0, a = a.ofType, _(a) && (a = a.ofType)), { namedType: a, required: n, isList: i };
312
+ return k(a) && (n = !0, a = a.ofType), x(a) && (i = !0, a = a.ofType, k(a) && (a = a.ofType)), { namedType: a, required: n, isList: i };
292
313
  }
293
314
  function ee(t) {
294
315
  const i = t.getFields().edges;
295
316
  if (!i) return;
296
- const { namedType: a, isList: r } = I(i.type);
317
+ const { namedType: a, isList: r } = S(i.type);
297
318
  if (!r || !g(a)) return;
298
- const u = a.getFields().node;
299
- if (!u) return;
300
- const { namedType: f } = I(u.type);
319
+ const d = a.getFields().node;
320
+ if (!d) return;
321
+ const { namedType: f } = S(d.type);
301
322
  if (g(f))
302
323
  return f.name;
303
324
  }
304
325
  function te(t, n, i, a = {}) {
305
- const { namedType: r, required: m, isList: u } = I(n.type), f = Z(a.customScalars), o = {
326
+ const { namedType: r, required: m, isList: d } = S(n.type), f = V(a.customScalars), o = {
306
327
  fieldname: t,
307
328
  label: W(t),
308
329
  component: "ATextInput",
309
330
  fieldtype: "Data"
310
331
  };
311
- if (m && (o.required = !0), E(r)) {
332
+ if (m && (o.required = !0), M(r)) {
312
333
  if (G.has(r.name))
313
334
  return o._unmapped = !0, a.includeUnmappedMeta && (o._graphqlType = r.name), o;
314
335
  const s = f[r.name];
315
336
  return s ? (o.component = s.component, o.fieldtype = s.fieldtype) : (o._unmapped = !0, a.includeUnmappedMeta && (o._graphqlType = r.name)), o;
316
337
  }
317
- if (M(r))
338
+ if (E(r))
318
339
  return o.component = "ADropdown", o.fieldtype = "Select", o.options = r.getValues().map((s) => s.name), o;
319
340
  if (g(r)) {
320
- if (!u && i.has(r.name))
321
- return o.component = "ALink", o.fieldtype = "Link", o.options = A(r.name), o;
341
+ if (!d && i.has(r.name))
342
+ return o.component = "ALink", o.fieldtype = "Link", o.options = T(r.name), o;
322
343
  const s = ee(r);
323
- 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);
344
+ return s && i.has(s) ? (o.component = "ATable", o.fieldtype = "Doctype", o.options = T(s), 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);
324
345
  }
325
346
  return o._unmapped = !0, a.includeUnmappedMeta && (o._graphqlType = r.name), o;
326
347
  }
327
348
  function me(t, n = {}) {
328
- const i = ne(t), a = i.getTypeMap(), r = /* @__PURE__ */ new Set(), m = i.getQueryType(), u = i.getMutationType(), f = i.getSubscriptionType();
329
- m && r.add(m.name), u && r.add(u.name), f && r.add(f.name);
330
- const o = n.isEntityType ?? V, s = /* @__PURE__ */ new Set();
349
+ const i = ne(t), a = i.getTypeMap(), r = /* @__PURE__ */ new Set(), m = i.getQueryType(), d = i.getMutationType(), f = i.getSubscriptionType();
350
+ m && r.add(m.name), d && r.add(d.name), f && r.add(f.name);
351
+ const o = n.isEntityType ?? K, s = /* @__PURE__ */ new Set();
331
352
  for (const [p, c] of Object.entries(a))
332
353
  g(c) && (r.has(p) || o(p, c) && s.add(p));
333
- let T = s;
354
+ let A = s;
334
355
  if (n.include) {
335
356
  const p = new Set(n.include);
336
- T = new Set([...s].filter((c) => p.has(c)));
357
+ A = new Set([...s].filter((c) => p.has(c)));
337
358
  }
338
359
  if (n.exclude) {
339
360
  const p = new Set(n.exclude);
340
- T = new Set([...T].filter((c) => !p.has(c)));
361
+ A = new Set([...A].filter((c) => !p.has(c)));
341
362
  }
342
- const L = n.isEntityField ?? X, N = n.deriveTableName ?? ((p) => $(p)), b = [];
343
- for (const p of T) {
363
+ const w = n.isEntityField ?? X, L = n.deriveTableName ?? ((p) => $(p)), b = [];
364
+ for (const p of A) {
344
365
  const c = a[p];
345
366
  if (!g(c)) continue;
346
- const w = c.getFields(), C = n.typeOverrides?.[p], O = Object.entries(w).filter(([l, y]) => L(l, y, c)).map(([l, y]) => {
367
+ const N = c.getFields(), F = n.typeOverrides?.[p], O = Object.entries(N).filter(([l, y]) => w(l, y, c)).map(([l, y]) => {
347
368
  if (n.classifyField) {
348
- const d = n.classifyField(l, y, c);
349
- if (d != null)
369
+ const u = n.classifyField(l, y, c);
370
+ if (u != null)
350
371
  return {
351
372
  fieldname: l,
352
- label: d.label ?? l,
353
- component: d.component ?? "ATextInput",
354
- fieldtype: d.fieldtype ?? "Data",
355
- ...d
373
+ label: u.label ?? l,
374
+ component: u.component ?? "ATextInput",
375
+ fieldtype: u.fieldtype ?? "Data",
376
+ ...u
356
377
  };
357
378
  }
358
379
  const h = te(l, y, s, n);
359
- return C?.[l] ? { ...h, ...C[l] } : h;
380
+ return F?.[l] ? { ...h, ...F[l] } : h;
360
381
  }).map((l) => {
361
382
  if (!n.includeUnmappedMeta) {
362
- const { _graphqlType: y, _unmapped: h, ...d } = l;
363
- return d;
383
+ const { _graphqlType: y, _unmapped: h, ...u } = l;
384
+ return u;
364
385
  }
365
386
  return l;
366
387
  }), D = {
367
388
  name: p,
368
- slug: A(p),
389
+ slug: T(p),
369
390
  fields: O
370
- }, F = N(p);
371
- F && (D.tableName = F), n.includeUnmappedMeta && (D._graphqlTypeName = p), b.push(D);
391
+ }, C = L(p);
392
+ C && (D.tableName = C), n.includeUnmappedMeta && (D._graphqlTypeName = p), b.push(D);
372
393
  }
373
394
  return b;
374
395
  }
375
396
  function ne(t) {
376
- return typeof t == "string" ? x(t) : j(t);
397
+ return typeof t == "string" ? v(t) : j(t);
377
398
  }
378
399
  export {
379
400
  J as A,
380
- k as D,
381
- S as F,
401
+ _ as D,
402
+ I as F,
382
403
  B as G,
383
404
  G as I,
384
- P as S,
385
- R as T,
405
+ U as S,
406
+ P as T,
386
407
  z as W,
387
- U as a,
408
+ R as a,
388
409
  q as b,
389
410
  Q as c,
390
- Z as d,
411
+ V as d,
391
412
  W as e,
392
- ue as f,
413
+ de as f,
393
414
  te as g,
394
415
  me as h,
395
416
  X as i,
396
- V as j,
417
+ K as j,
397
418
  ae as k,
398
419
  se as l,
399
420
  $ as m,
400
- de as n,
401
- A as o,
421
+ ue as n,
422
+ T as o,
402
423
  ce as p,
403
424
  re as q,
404
425
  le as s,
405
426
  fe as t,
406
427
  pe as v
407
428
  };
408
- //# sourceMappingURL=index-CzoRIy1-.js.map
429
+ //# sourceMappingURL=index-BatnoC-J.js.map