@stonecrop/graphql-middleware 0.8.9 → 0.8.11

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/index.js CHANGED
@@ -1,187 +1,187 @@
1
- import { validateDoctype as N, parseDoctype as D } from "@stonecrop/schema";
2
- import { ActionDefinition as ue, DoctypeMeta as fe, FieldMeta as me, FieldOptions as ge, FieldValidation as he, GQL_SCALAR_MAP as Se, StonecropFieldType as $e, TYPE_MAP as we, WELL_KNOWN_SCALARS as be, WorkflowMeta as Ne, camelToLabel as De, camelToSnake as Re, classifyFieldType as Me, convertGraphQLSchema as ke, defaultIsEntityField as Ae, defaultIsEntityType as qe, getDefaultComponent as Oe, parseDoctype as Fe, parseField as Be, pascalToSnake as Ce, snakeToCamel as Ee, snakeToLabel as je, toPascalCase as xe, toSlug as Te, validateDoctype as Ie, validateField as Je } from "@stonecrop/schema";
3
- import { readdirSync as k, statSync as A, readFileSync as q } from "node:fs";
4
- import { join as O } from "node:path";
5
- import { extendSchema as F, gql as B } from "postgraphile/utils";
6
- import { loadOne as S, object as $, constant as C, lambda as E } from "postgraphile/grafast";
7
- const p = /* @__PURE__ */ new Map();
1
+ import { readdirSync as O, statSync as x, readFileSync as B } from "node:fs";
2
+ import { join as M } from "node:path";
3
+ import { validateDoctype as R, parseDoctype as k, toPascalCase as A, snakeToCamel as F } from "@stonecrop/schema";
4
+ import { extendSchema as j, gql as q } from "postgraphile/utils";
5
+ import { loadOne as N, object as b, constant as T, lambda as I } from "postgraphile/grafast";
6
+ import J from "pluralize";
7
+ const u = /* @__PURE__ */ new Map();
8
8
  class w extends Error {
9
- constructor(e, r) {
10
- const n = r.map((o) => ` ${o.path.join(".")}: ${o.message}`).join(`
9
+ constructor(t, r) {
10
+ const o = r.map((n) => ` ${n.path.join(".")}: ${n.message}`).join(`
11
11
  `);
12
- super(`Invalid doctype definition in ${e}:
13
- ${n}`), this.file = e, this.errors = r, this.name = "DoctypeValidationError";
12
+ super(`Invalid doctype definition in ${t}:
13
+ ${o}`), this.file = t, this.errors = r, this.name = "DoctypeValidationError";
14
14
  }
15
15
  }
16
- function j(t, e = {}) {
17
- const r = k(t);
18
- for (const n of r) {
19
- const o = O(t, n);
20
- A(o).isDirectory() ? j(o, e) : n.endsWith(".json") && x(o, e);
16
+ function L(e, t = {}) {
17
+ const r = O(e);
18
+ for (const o of r) {
19
+ const n = M(e, o);
20
+ x(n).isDirectory() ? L(n, t) : o.endsWith(".json") && C(n, t);
21
21
  }
22
22
  }
23
- function x(t, e) {
24
- const r = q(t, "utf-8");
25
- let n;
23
+ function C(e, t) {
24
+ const r = B(e, "utf-8");
25
+ let o;
26
26
  try {
27
- n = JSON.parse(r);
28
- } catch (c) {
29
- const s = {
27
+ o = JSON.parse(r);
28
+ } catch (i) {
29
+ const a = {
30
30
  path: [],
31
- message: `Invalid JSON: ${c instanceof Error ? c.message : String(c)}`
31
+ message: `Invalid JSON: ${i instanceof Error ? i.message : String(i)}`
32
32
  };
33
- if (e.continueOnError) {
34
- e.onError?.(t, [s]);
33
+ if (t.continueOnError) {
34
+ t.onError?.(e, [a]);
35
35
  return;
36
36
  }
37
- throw new w(t, [s]);
37
+ throw new w(e, [a]);
38
38
  }
39
- const o = N(n);
40
- if (!o.success) {
41
- if (e.continueOnError) {
42
- e.onError?.(t, o.errors);
39
+ const n = R(o);
40
+ if (!n.success) {
41
+ if (t.continueOnError) {
42
+ t.onError?.(e, n.errors);
43
43
  return;
44
44
  }
45
- throw new w(t, o.errors);
45
+ throw new w(e, n.errors);
46
46
  }
47
- const a = D(n);
48
- p.set(a.name, a);
47
+ const c = k(o);
48
+ u.set(c.name, c);
49
49
  }
50
- function re(t, e = {}) {
51
- for (const [r, n] of Object.entries(t)) {
52
- const o = { ...n, name: r }, a = N(o);
53
- if (!a.success) {
54
- if (e.continueOnError) {
55
- e.onError?.(r, a.errors);
50
+ function de(e, t = {}) {
51
+ for (const [r, o] of Object.entries(e)) {
52
+ const n = { ...o, name: r }, c = R(n);
53
+ if (!c.success) {
54
+ if (t.continueOnError) {
55
+ t.onError?.(r, c.errors);
56
56
  continue;
57
57
  }
58
- throw new w(r, a.errors);
58
+ throw new w(r, c.errors);
59
59
  }
60
- const c = D(o);
61
- p.set(c.name, c);
60
+ const i = k(n);
61
+ u.set(i.name, i);
62
62
  }
63
63
  }
64
- function m(t) {
65
- return p.get(t);
64
+ function h(e) {
65
+ return u.get(e);
66
66
  }
67
- function T() {
68
- return Array.from(p.values());
67
+ function H() {
68
+ return Array.from(u.values());
69
69
  }
70
- function oe(t) {
71
- return p.has(t);
70
+ function fe(e) {
71
+ return u.has(e);
72
72
  }
73
- function ne() {
74
- p.clear();
73
+ function ue() {
74
+ u.clear();
75
75
  }
76
- function ae() {
77
- const t = [];
78
- for (const e of p.values()) {
79
- e.inherits && !p.has(e.inherits) && t.push({
80
- path: [e.name, "inherits"],
81
- message: `References unknown doctype: ${e.inherits}`
82
- }), e.listDoctype && !p.has(e.listDoctype) && t.push({
83
- path: [e.name, "listDoctype"],
84
- message: `References unknown doctype: ${e.listDoctype}`
85
- }), e.parentDoctype && !p.has(e.parentDoctype) && t.push({
86
- path: [e.name, "parentDoctype"],
87
- message: `References unknown doctype: ${e.parentDoctype}`
76
+ function pe() {
77
+ const e = [];
78
+ for (const t of u.values()) {
79
+ t.inherits && !u.has(t.inherits) && e.push({
80
+ path: [t.name, "inherits"],
81
+ message: `References unknown doctype: ${t.inherits}`
82
+ }), t.listDoctype && !u.has(t.listDoctype) && e.push({
83
+ path: [t.name, "listDoctype"],
84
+ message: `References unknown doctype: ${t.listDoctype}`
85
+ }), t.parentDoctype && !u.has(t.parentDoctype) && e.push({
86
+ path: [t.name, "parentDoctype"],
87
+ message: `References unknown doctype: ${t.parentDoctype}`
88
88
  });
89
- for (const r of e.fields)
90
- r.fieldtype === "Link" && typeof r.options == "string" && (p.has(r.options) || t.push({
91
- path: [e.name, "fields", r.fieldname, "options"],
89
+ for (const r of t.fields)
90
+ r.fieldtype === "Link" && typeof r.options == "string" && (u.has(r.options) || e.push({
91
+ path: [t.name, "fields", r.fieldname, "options"],
92
92
  message: `Link references unknown doctype: ${r.options}`
93
93
  }));
94
94
  }
95
- return t;
95
+ return e;
96
96
  }
97
- const g = /* @__PURE__ */ new Map();
98
- function I(t, e) {
99
- g.set(t, e);
97
+ const S = /* @__PURE__ */ new Map();
98
+ function _(e, t) {
99
+ S.set(e, t);
100
100
  }
101
- function J(t) {
102
- return g.get(t);
101
+ function U(e) {
102
+ return S.get(e);
103
103
  }
104
- function ce(t) {
105
- return g.has(t);
104
+ function ye(e) {
105
+ return S.has(e);
106
106
  }
107
- function se() {
108
- g.clear();
107
+ function me() {
108
+ S.clear();
109
109
  }
110
- const L = async (t, e) => {
111
- const [r] = t, { doctype: n } = e, o = [];
112
- for (const a of n.fields)
113
- a.required && (r[a.fieldname] === void 0 || r[a.fieldname] === null) && o.push(a.label ?? a.fieldname);
114
- if (o.length > 0)
115
- throw new Error(`Missing required fields: ${o.join(", ")}`);
110
+ const Q = async (e, t) => {
111
+ const [r] = e, { doctype: o } = t, n = [];
112
+ for (const c of o.fields)
113
+ c.required && (r[c.fieldname] === void 0 || r[c.fieldname] === null) && n.push(c.label ?? c.fieldname);
114
+ if (n.length > 0)
115
+ throw new Error(`Missing required fields: ${n.join(", ")}`);
116
116
  return { valid: !0 };
117
- }, _ = async (t, e) => {
118
- const [r] = t, { doctype: n } = e, o = [];
119
- for (const a of n.fields) {
120
- const c = r[a.fieldname];
121
- if (c == null) continue;
122
- const s = G(a.fieldname, c, a.fieldtype);
123
- s && o.push(s);
117
+ }, P = async (e, t) => {
118
+ const [r] = e, { doctype: o } = t, n = [];
119
+ for (const c of o.fields) {
120
+ const i = r[c.fieldname];
121
+ if (i == null) continue;
122
+ const a = V(c.fieldname, i, c.fieldtype);
123
+ a && n.push(a);
124
124
  }
125
- if (o.length > 0)
125
+ if (n.length > 0)
126
126
  throw new Error(`Field type validation failed:
127
- ${o.join(`
127
+ ${n.join(`
128
128
  `)}`);
129
129
  return { valid: !0 };
130
130
  };
131
- function G(t, e, r) {
131
+ function V(e, t, r) {
132
132
  switch (r) {
133
133
  case "Int":
134
- if (typeof e != "number" || !Number.isInteger(e))
135
- return `${t}: expected integer, got ${typeof e}`;
134
+ if (typeof t != "number" || !Number.isInteger(t))
135
+ return `${e}: expected integer, got ${typeof t}`;
136
136
  break;
137
137
  case "Float":
138
138
  case "Decimal":
139
139
  case "Currency":
140
140
  case "Quantity":
141
- if (typeof e != "number" && typeof e != "string")
142
- return `${t}: expected number, got ${typeof e}`;
141
+ if (typeof t != "number" && typeof t != "string")
142
+ return `${e}: expected number, got ${typeof t}`;
143
143
  break;
144
144
  case "Check":
145
- if (typeof e != "boolean")
146
- return `${t}: expected boolean, got ${typeof e}`;
145
+ if (typeof t != "boolean")
146
+ return `${e}: expected boolean, got ${typeof t}`;
147
147
  break;
148
148
  case "Data":
149
149
  case "Text":
150
150
  case "Code":
151
151
  case "Link":
152
- if (typeof e != "string")
153
- return `${t}: expected string, got ${typeof e}`;
152
+ if (typeof t != "string")
153
+ return `${e}: expected string, got ${typeof t}`;
154
154
  break;
155
155
  case "Date":
156
156
  case "Time":
157
157
  case "Datetime":
158
- if (typeof e != "string" && !(e instanceof Date))
159
- return `${t}: expected date string or Date, got ${typeof e}`;
158
+ if (typeof t != "string" && !(t instanceof Date))
159
+ return `${e}: expected date string or Date, got ${typeof t}`;
160
160
  break;
161
161
  case "JSON":
162
- if (typeof e != "object")
163
- return `${t}: expected object, got ${typeof e}`;
162
+ if (typeof t != "object")
163
+ return `${e}: expected object, got ${typeof t}`;
164
164
  break;
165
165
  case "Table":
166
- if (!Array.isArray(e))
167
- return `${t}: expected array, got ${typeof e}`;
166
+ if (!Array.isArray(t))
167
+ return `${e}: expected array, got ${typeof t}`;
168
168
  break;
169
169
  }
170
170
  return null;
171
171
  }
172
- const U = async () => ({ ok: !0 }), H = {
173
- validateRequiredFields: L,
174
- validateFieldTypes: _,
175
- noop: U
172
+ const W = async () => ({ ok: !0 }), G = {
173
+ validateRequiredFields: Q,
174
+ validateFieldTypes: P,
175
+ noop: W
176
176
  };
177
- function ie() {
178
- for (const [t, e] of Object.entries(H))
179
- I(t, e);
177
+ function ge() {
178
+ for (const [e, t] of Object.entries(G))
179
+ _(e, t);
180
180
  }
181
- const de = (t) => {
182
- const e = t.inflection?.recordFieldName ?? P, r = t.inflection?.connectionFieldName ?? Q, n = t.inflection?.orderByTypeName ?? W;
183
- return F(() => ({
184
- typeDefs: B`
181
+ const he = (e) => {
182
+ const t = e.inflection?.recordFieldName ?? v, r = e.inflection?.connectionFieldName ?? z, o = e.inflection?.orderByTypeName ?? Y, n = e.inflection?.recordArgName ?? K, c = e.inflection?.recordArgType ?? X;
183
+ return j(() => ({
184
+ typeDefs: q`
185
185
  type StonecropFieldMeta {
186
186
  fieldname: String!
187
187
  fieldtype: String!
@@ -250,62 +250,64 @@ const de = (t) => {
250
250
  objects: {
251
251
  Query: {
252
252
  plans: {
253
- stonecropMeta(o, { $doctype: a }) {
254
- return E(a, (c) => m(c) ?? null);
253
+ stonecropMeta(i, { $doctype: a }) {
254
+ return I(a, (d) => h(d) ?? null);
255
255
  },
256
256
  stonecropAllMeta() {
257
- return C(T());
257
+ return T(H());
258
258
  },
259
- stonecropRecord(o, { $doctype: a, $id: c }) {
260
- return S($({ doctype: a, id: c }), async (s) => await Promise.all(
261
- s.map(async (l) => {
262
- const d = m(l.doctype);
263
- if (!d)
264
- throw new Error(`Unknown doctype: ${l.doctype}`);
265
- if (!d.tableName)
266
- throw new Error(`Doctype ${l.doctype} has no table mapping`);
267
- const y = V(d, e), i = await t.executor.query(y, { id: l.id });
259
+ stonecropRecord(i, { $doctype: a, $id: d }) {
260
+ return N(b({ doctype: a, id: d }), async (p) => await Promise.all(
261
+ p.map(async (f) => {
262
+ const l = h(f.doctype);
263
+ if (!l)
264
+ throw new Error(`Unknown doctype: ${f.doctype}`);
265
+ if (!l.tableName)
266
+ throw new Error(`Doctype ${f.doctype} has no table mapping`);
267
+ const y = ee(l, t, n, c), s = await e.executor.query(y, {
268
+ [n(l.tableName)]: f.id
269
+ });
268
270
  return {
269
- data: z(i, d, e),
270
- doctype: l.doctype
271
+ data: re(s, l, t),
272
+ doctype: f.doctype
271
273
  };
272
274
  })
273
275
  ));
274
276
  },
275
- stonecropRecords(o, { $doctype: a, $filters: c, $orderBy: s, $limit: l, $offset: d }) {
276
- return S(
277
- $({
277
+ stonecropRecords(i, { $doctype: a, $filters: d, $orderBy: p, $limit: f, $offset: l }) {
278
+ return N(
279
+ b({
278
280
  doctype: a,
279
- filters: c,
280
- orderBy: s,
281
- limit: l,
282
- offset: d
281
+ filters: d,
282
+ orderBy: p,
283
+ limit: f,
284
+ offset: l
283
285
  }),
284
286
  async (y) => await Promise.all(
285
- y.map(async (i) => {
286
- const u = m(i.doctype);
287
- if (!u)
288
- throw new Error(`Unknown doctype: ${i.doctype}`);
289
- if (!u.tableName)
290
- throw new Error(`Doctype ${i.doctype} has no table mapping`);
291
- const h = v(
292
- u,
287
+ y.map(async (s) => {
288
+ const m = h(s.doctype);
289
+ if (!m)
290
+ throw new Error(`Unknown doctype: ${s.doctype}`);
291
+ if (!m.tableName)
292
+ throw new Error(`Doctype ${s.doctype} has no table mapping`);
293
+ const $ = te(
294
+ m,
293
295
  {
294
- limit: i.limit,
295
- offset: i.offset,
296
- orderBy: i.orderBy
296
+ limit: s.limit,
297
+ offset: s.offset,
298
+ orderBy: s.orderBy
297
299
  },
298
300
  r,
299
- n
300
- ), f = await t.executor.query(h, {
301
- limit: i.limit,
302
- offset: i.offset,
303
- orderBy: i.orderBy
304
- }), b = K(f, u, r);
301
+ o
302
+ ), g = await e.executor.query($, {
303
+ limit: s.limit,
304
+ offset: s.offset,
305
+ orderBy: s.orderBy
306
+ }), D = ne(g, m, r);
305
307
  return {
306
- data: b,
307
- doctype: i.doctype,
308
- count: b.length
308
+ data: D,
309
+ doctype: s.doctype,
310
+ count: D.length
309
311
  };
310
312
  })
311
313
  )
@@ -315,51 +317,51 @@ const de = (t) => {
315
317
  },
316
318
  Mutation: {
317
319
  plans: {
318
- stonecropAction(o, { $doctype: a, $action: c, $args: s }) {
319
- return S(
320
- $({
320
+ stonecropAction(i, { $doctype: a, $action: d, $args: p }) {
321
+ return N(
322
+ b({
321
323
  doctype: a,
322
- action: c,
323
- actionArgs: s
324
+ action: d,
325
+ actionArgs: p
324
326
  }),
325
- async (l) => await Promise.all(
326
- l.map(async (d) => {
327
- const y = m(d.doctype);
327
+ async (f) => await Promise.all(
328
+ f.map(async (l) => {
329
+ const y = h(l.doctype);
328
330
  if (!y)
329
331
  return {
330
332
  success: !1,
331
333
  data: null,
332
- error: `Unknown doctype: ${d.doctype}`
334
+ error: `Unknown doctype: ${l.doctype}`
333
335
  };
334
- const i = y.workflow?.actions?.[d.action];
335
- if (!i)
336
+ const s = y.workflow?.actions?.[l.action];
337
+ if (!s)
336
338
  return {
337
339
  success: !1,
338
340
  data: null,
339
- error: `Unknown action: ${d.action} on ${d.doctype}`
341
+ error: `Unknown action: ${l.action} on ${l.doctype}`
340
342
  };
341
- const u = J(i.handler);
342
- if (!u)
343
+ const m = U(s.handler);
344
+ if (!m)
343
345
  return {
344
346
  success: !1,
345
347
  data: null,
346
- error: `Handler not registered: ${i.handler}`
348
+ error: `Handler not registered: ${s.handler}`
347
349
  };
348
- const h = {
350
+ const $ = {
349
351
  doctype: y,
350
- executor: t.executor
352
+ executor: e.executor
351
353
  };
352
354
  try {
353
355
  return {
354
356
  success: !0,
355
- data: await u(d.actionArgs ?? [], h),
357
+ data: await m(l.actionArgs ?? [], $),
356
358
  error: null
357
359
  };
358
- } catch (f) {
360
+ } catch (g) {
359
361
  return {
360
362
  success: !1,
361
363
  data: null,
362
- error: f instanceof Error ? f.message : String(f)
364
+ error: g instanceof Error ? g.message : String(g)
363
365
  };
364
366
  }
365
367
  })
@@ -371,289 +373,81 @@ const de = (t) => {
371
373
  }
372
374
  }));
373
375
  };
374
- function R(t) {
375
- return t.replace(/_([a-z])/g, (e, r) => r.toUpperCase());
376
+ function v(e) {
377
+ const t = J.singular(e);
378
+ return `${F(t)}ById`;
376
379
  }
377
- function M(t) {
378
- const e = R(t);
379
- return e.charAt(0).toUpperCase() + e.slice(1);
380
+ function z(e) {
381
+ return `all${A(e)}`;
380
382
  }
381
- function P(t) {
382
- const e = t.replace(/s$/, "");
383
- return `${R(e)}ById`;
383
+ function Y(e) {
384
+ return `${A(e)}OrderBy`;
384
385
  }
385
- function Q(t) {
386
- return `all${M(t)}`;
386
+ function K(e) {
387
+ return "id";
387
388
  }
388
- function W(t) {
389
- return `${M(t)}OrderBy`;
389
+ function X(e) {
390
+ return "UUID!";
390
391
  }
391
- function V(t, e) {
392
- const r = t.fields.map((o) => o.fieldname).join(`
392
+ const Z = /* @__PURE__ */ new Set(["Link", "Doctype"]);
393
+ function E(e) {
394
+ return e.fields.filter((t) => !Z.has(t.fieldtype)).map((t) => t.fieldname).join(`
393
395
  `);
396
+ }
397
+ function ee(e, t, r, o) {
398
+ const n = E(e), c = t(e.tableName), i = r(e.tableName), a = o(e.tableName);
394
399
  return `
395
- query GetRecord($id: UUID!) {
396
- ${e(t.tableName)}(id: $id) {
397
- ${r}
400
+ query GetRecord($${i}: ${a}) {
401
+ ${c}(${i}: $${i}) {
402
+ ${n}
398
403
  }
399
404
  }
400
405
  `;
401
406
  }
402
- function v(t, e, r, n) {
403
- const o = t.fields.map((d) => d.fieldname).join(`
404
- `), a = r(t.tableName), c = n(t.tableName), s = [];
405
- e.limit && s.push("first: $limit"), e.offset && s.push("offset: $offset"), e.orderBy && s.push("orderBy: $orderBy");
406
- const l = s.length > 0 ? `(${s.join(", ")})` : "";
407
+ function te(e, t, r, o) {
408
+ const n = E(e), c = r(e.tableName), i = o(e.tableName), a = [], d = [];
409
+ t.limit && (a.push("$limit: Int"), d.push("first: $limit")), t.offset && (a.push("$offset: Int"), d.push("offset: $offset")), t.orderBy && (a.push(`$orderBy: [${i}!]`), d.push("orderBy: $orderBy"));
410
+ const p = a.length > 0 ? `(${a.join(", ")})` : "", f = d.length > 0 ? `(${d.join(", ")})` : "";
407
411
  return `
408
- query GetRecords($limit: Int, $offset: Int, $orderBy: [${c}!]) {
409
- ${a}${l} {
412
+ query GetRecords${p} {
413
+ ${c}${f} {
410
414
  nodes {
411
- ${o}
415
+ ${n}
412
416
  }
413
417
  }
414
418
  }
415
419
  `;
416
420
  }
417
- function z(t, e, r) {
418
- const n = r(e.tableName);
419
- return t[n];
420
- }
421
- function K(t, e, r) {
422
- const n = r(e.tableName);
423
- return t[n]?.nodes ?? [];
421
+ function re(e, t, r) {
422
+ const o = r(t.tableName);
423
+ return e[o];
424
424
  }
425
- class le {
426
- endpoint;
427
- headers;
428
- metaCache = /* @__PURE__ */ new Map();
429
- constructor(e) {
430
- this.endpoint = e.endpoint, this.headers = {
431
- "Content-Type": "application/json",
432
- ...e.headers
433
- };
434
- }
435
- /**
436
- * Execute a GraphQL query
437
- * @param query - GraphQL query string
438
- * @param variables - Query variables
439
- */
440
- async query(e, r) {
441
- const o = await (await fetch(this.endpoint, {
442
- method: "POST",
443
- headers: this.headers,
444
- body: JSON.stringify({ query: e, variables: r })
445
- })).json();
446
- if (o.errors?.length)
447
- throw new Error(o.errors[0].message);
448
- return o.data;
449
- }
450
- /**
451
- * Execute a GraphQL mutation
452
- * @param mutation - GraphQL mutation string
453
- * @param variables - Mutation variables
454
- */
455
- async mutate(e, r) {
456
- return this.query(e, r);
457
- }
458
- /**
459
- * Get doctype metadata
460
- * @param context - Route context containing doctype name
461
- */
462
- async getMeta(e) {
463
- const r = this.metaCache.get(e.doctype);
464
- if (r) return r;
465
- const n = await this.query(
466
- `
467
- query GetMeta($doctype: String!) {
468
- stonecropMeta(doctype: $doctype) {
469
- name
470
- slug
471
- tableName
472
- fields {
473
- fieldname
474
- fieldtype
475
- component
476
- label
477
- required
478
- readOnly
479
- options
480
- precision
481
- scale
482
- }
483
- workflow {
484
- states
485
- actions
486
- }
487
- inherits
488
- listDoctype
489
- parentDoctype
490
- }
491
- }
492
- `,
493
- { doctype: e.doctype }
494
- );
495
- return n.stonecropMeta && this.metaCache.set(e.doctype, n.stonecropMeta), n.stonecropMeta;
496
- }
497
- /**
498
- * Get all doctype metadata
499
- */
500
- async getAllMeta() {
501
- const e = await this.query(
502
- `
503
- query GetAllMeta {
504
- stonecropAllMeta {
505
- name
506
- slug
507
- tableName
508
- fields {
509
- fieldname
510
- fieldtype
511
- component
512
- label
513
- required
514
- readOnly
515
- options
516
- precision
517
- scale
518
- }
519
- workflow {
520
- states
521
- actions
522
- }
523
- inherits
524
- listDoctype
525
- parentDoctype
526
- }
527
- }
528
- `
529
- );
530
- for (const r of e.stonecropAllMeta)
531
- this.metaCache.set(r.name, r);
532
- return e.stonecropAllMeta;
533
- }
534
- /**
535
- * Get a single record by ID
536
- * @param doctype - Doctype metadata
537
- * @param recordId - Record ID to fetch
538
- */
539
- async getRecord(e, r) {
540
- return (await this.query(
541
- `
542
- query GetRecord($doctype: String!, $id: String!) {
543
- stonecropRecord(doctype: $doctype, id: $id) {
544
- data
545
- }
546
- }
547
- `,
548
- { doctype: e.name, id: r }
549
- )).stonecropRecord.data;
550
- }
551
- /**
552
- * Get multiple records with optional filtering and pagination
553
- * @param doctype - Doctype metadata
554
- * @param options - Query options (filters, orderBy, limit, offset)
555
- */
556
- async getRecords(e, r) {
557
- return (await this.query(
558
- `
559
- query GetRecords(
560
- $doctype: String!
561
- $filters: JSON
562
- $orderBy: String
563
- $limit: Int
564
- $offset: Int
565
- ) {
566
- stonecropRecords(
567
- doctype: $doctype
568
- filters: $filters
569
- orderBy: $orderBy
570
- limit: $limit
571
- offset: $offset
572
- ) {
573
- data
574
- count
575
- }
576
- }
577
- `,
578
- {
579
- doctype: e.name,
580
- ...r
581
- }
582
- )).stonecropRecords.data;
583
- }
584
- /**
585
- * Execute a doctype action
586
- * @param doctype - Doctype metadata
587
- * @param action - Action name to execute
588
- * @param args - Action arguments
589
- */
590
- async runAction(e, r, n) {
591
- return (await this.query(
592
- `
593
- mutation RunAction($doctype: String!, $action: String!, $args: JSON) {
594
- stonecropAction(doctype: $doctype, action: $action, args: $args) {
595
- success
596
- data
597
- error
598
- }
599
- }
600
- `,
601
- {
602
- doctype: e.name,
603
- action: r,
604
- args: n
605
- }
606
- )).stonecropAction;
607
- }
608
- /**
609
- * Clear the cached doctype metadata
610
- */
611
- clearMetaCache() {
612
- this.metaCache.clear();
613
- }
425
+ function ne(e, t, r) {
426
+ const o = r(t.tableName);
427
+ return e[o]?.nodes ?? [];
614
428
  }
615
429
  export {
616
- ue as ActionDefinition,
617
- fe as DoctypeMeta,
618
430
  w as DoctypeValidationError,
619
- me as FieldMeta,
620
- ge as FieldOptions,
621
- he as FieldValidation,
622
- Se as GQL_SCALAR_MAP,
623
- le as StonecropClient,
624
- $e as StonecropFieldType,
625
- we as TYPE_MAP,
626
- be as WELL_KNOWN_SCALARS,
627
- Ne as WorkflowMeta,
628
- H as builtinHandlers,
629
- De as camelToLabel,
630
- Re as camelToSnake,
631
- Me as classifyFieldType,
632
- se as clearHandlers,
633
- ne as clearRegistry,
634
- ke as convertGraphQLSchema,
635
- de as createStonecropPlugin,
636
- Ae as defaultIsEntityField,
637
- qe as defaultIsEntityType,
638
- T as getAllMeta,
639
- Oe as getDefaultComponent,
640
- J as getHandler,
641
- m as getMeta,
642
- ce as hasHandler,
643
- oe as hasMeta,
644
- j as loadDoctypes,
645
- re as loadDoctypesFromObject,
646
- Fe as parseDoctype,
647
- Be as parseField,
648
- Ce as pascalToSnake,
649
- ie as registerBuiltinHandlers,
650
- I as registerHandler,
651
- Ee as snakeToCamel,
652
- je as snakeToLabel,
653
- xe as toPascalCase,
654
- Te as toSlug,
655
- Ie as validateDoctype,
656
- Je as validateField,
657
- ae as validateReferences
431
+ Z as RELATION_FIELDTYPES,
432
+ te as buildListQuery,
433
+ ee as buildRecordQuery,
434
+ G as builtinHandlers,
435
+ me as clearHandlers,
436
+ ue as clearRegistry,
437
+ he as createStonecropPlugin,
438
+ z as defaultConnectionFieldName,
439
+ Y as defaultOrderByTypeName,
440
+ v as defaultRecordFieldName,
441
+ H as getAllMeta,
442
+ U as getHandler,
443
+ h as getMeta,
444
+ ye as hasHandler,
445
+ fe as hasMeta,
446
+ L as loadDoctypes,
447
+ de as loadDoctypesFromObject,
448
+ E as queryableFieldNames,
449
+ ge as registerBuiltinHandlers,
450
+ _ as registerHandler,
451
+ pe as validateReferences
658
452
  };
659
453
  //# sourceMappingURL=index.js.map