@stonecrop/graphql-middleware 0.8.10 → 0.8.12

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