@stonecrop/graphql-middleware 0.12.5 → 0.12.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/dist/index.js CHANGED
@@ -1,13 +1,13 @@
1
- import { readdirSync as _, statSync as U, readFileSync as H } from "node:fs";
2
- import { join as P } from "node:path";
3
- import { validateDoctype as E, parseDoctype as j, toPascalCase as I, snakeToCamel as R } from "@stonecrop/schema";
4
- import { loadOne as M, object as O, constant as Q, lambda as V } from "postgraphile/grafast";
5
- import { extendSchema as z, gql as J } from "postgraphile/utils";
6
- import q from "pluralize";
1
+ import { readdirSync as W, statSync as _, readFileSync as U } from "node:fs";
2
+ import { join as H } from "node:path";
3
+ import { validateDoctype as E, parseDoctype as j, toPascalCase as I, snakeToCamel as F } from "@stonecrop/schema";
4
+ import { loadOne as M, object as O, constant as P, lambda as Q } from "postgraphile/grafast";
5
+ import { gql as V, extendSchema as z } from "postgraphile/utils";
6
+ import C from "pluralize";
7
7
  const k = /* @__PURE__ */ new Map();
8
- class A extends Error {
8
+ class R extends Error {
9
9
  constructor(t, n) {
10
- const i = n.map((o) => ` ${o.path.join(".")}: ${o.message}`).join(`
10
+ const i = n.map((r) => ` ${r.path.join(".")}: ${r.message}`).join(`
11
11
  `);
12
12
  super(`Invalid doctype definition in ${t}:
13
13
  ${i}`), this.file = t, this.errors = n, this.name = "DoctypeValidationError";
@@ -16,14 +16,14 @@ ${i}`), this.file = t, this.errors = n, this.name = "DoctypeValidationError";
16
16
  errors;
17
17
  }
18
18
  function G(e, t = {}) {
19
- const n = _(e);
19
+ const n = W(e);
20
20
  for (const i of n) {
21
- const o = P(e, i);
22
- U(o).isDirectory() ? G(o, t) : i.endsWith(".json") && Y(o, t);
21
+ const r = H(e, i);
22
+ _(r).isDirectory() ? G(r, t) : i.endsWith(".json") && Y(r, t);
23
23
  }
24
24
  }
25
25
  function Y(e, t) {
26
- const n = H(e, "utf-8");
26
+ const n = U(e, "utf-8");
27
27
  let i;
28
28
  try {
29
29
  i = JSON.parse(n);
@@ -36,34 +36,34 @@ function Y(e, t) {
36
36
  t.onError?.(e, [c]);
37
37
  return;
38
38
  }
39
- throw new A(e, [c]);
39
+ throw new R(e, [c]);
40
40
  }
41
- const o = E(i);
42
- if (!o.success) {
41
+ const r = E(i);
42
+ if (!r.success) {
43
43
  if (t.continueOnError) {
44
- t.onError?.(e, o.errors);
44
+ t.onError?.(e, r.errors);
45
45
  return;
46
46
  }
47
- throw new A(e, o.errors);
47
+ throw new R(e, r.errors);
48
48
  }
49
- const r = j(i);
50
- k.set(r.name, r);
49
+ const o = j(i);
50
+ k.set(o.name, o);
51
51
  }
52
- function be(e, t = {}) {
52
+ function Me(e, t = {}) {
53
53
  for (const [n, i] of Object.entries(e)) {
54
- const o = { ...i, name: n }, r = E(o);
55
- if (!r.success) {
54
+ const r = { ...i, name: n }, o = E(r);
55
+ if (!o.success) {
56
56
  if (t.continueOnError) {
57
- t.onError?.(n, r.errors);
57
+ t.onError?.(n, o.errors);
58
58
  continue;
59
59
  }
60
- throw new A(n, r.errors);
60
+ throw new R(n, o.errors);
61
61
  }
62
- const s = j(o);
62
+ const s = j(r);
63
63
  k.set(s.name, s);
64
64
  }
65
65
  }
66
- function N(e) {
66
+ function $(e) {
67
67
  const t = k.get(e);
68
68
  if (t) return t;
69
69
  for (const n of k.values())
@@ -72,10 +72,10 @@ function N(e) {
72
72
  function K() {
73
73
  return Array.from(k.values());
74
74
  }
75
- function Me(e) {
75
+ function Oe(e) {
76
76
  return k.has(e);
77
77
  }
78
- function Oe() {
78
+ function Fe() {
79
79
  k.clear();
80
80
  }
81
81
  function Re() {
@@ -93,43 +93,43 @@ function Re() {
93
93
  }
94
94
  return e;
95
95
  }
96
- const b = /* @__PURE__ */ new Map();
96
+ const w = /* @__PURE__ */ new Map();
97
97
  function X(e, t) {
98
- b.set(e, t);
98
+ w.set(e, t);
99
99
  }
100
100
  function Z(e) {
101
- return b.get(e);
101
+ return w.get(e);
102
102
  }
103
103
  function Ae(e) {
104
- return b.has(e);
104
+ return w.has(e);
105
105
  }
106
- function Fe() {
107
- b.clear();
106
+ function De() {
107
+ w.clear();
108
108
  }
109
109
  const ee = async (e, t) => {
110
- const [n] = e, { doctype: i } = t, o = [];
111
- for (const r of i.fields)
112
- r.required && (n[r.fieldname] === void 0 || n[r.fieldname] === null) && o.push(r.label ?? r.fieldname);
113
- if (o.length > 0)
114
- throw new Error(`Missing required fields: ${o.join(", ")}`);
110
+ const [n] = e, { doctype: i } = t, r = [];
111
+ for (const o of i.fields)
112
+ o.required && (n[o.fieldname] === void 0 || n[o.fieldname] === null) && r.push(o.label ?? o.fieldname);
113
+ if (r.length > 0)
114
+ throw new Error(`Missing required fields: ${r.join(", ")}`);
115
115
  return { valid: !0 };
116
116
  }, te = async (e, t) => {
117
- const [n] = e, { doctype: i } = t, o = [];
118
- for (const r of i.fields) {
119
- const s = n[r.fieldname];
117
+ const [n] = e, { doctype: i } = t, r = [];
118
+ for (const o of i.fields) {
119
+ const s = n[o.fieldname];
120
120
  if (s == null) continue;
121
- const c = ne(r, s);
122
- c && o.push(c);
121
+ const c = ne(o, s);
122
+ c && r.push(c);
123
123
  }
124
124
  if (i.links)
125
- for (const [r, s] of Object.entries(i.links)) {
126
- const c = n[r];
125
+ for (const [o, s] of Object.entries(i.links)) {
126
+ const c = n[o];
127
127
  if (c == null) continue;
128
- s.cardinality === "noneOrMany" || s.cardinality === "atLeastOne" ? Array.isArray(c) || o.push(`${r}: expected array, got ${typeof c}`) : (typeof c != "object" || Array.isArray(c)) && o.push(`${r}: expected object, got ${typeof c}`);
128
+ s.cardinality === "noneOrMany" || s.cardinality === "atLeastOne" ? Array.isArray(c) || r.push(`${o}: expected array, got ${typeof c}`) : (typeof c != "object" || Array.isArray(c)) && r.push(`${o}: expected object, got ${typeof c}`);
129
129
  }
130
- if (o.length > 0)
130
+ if (r.length > 0)
131
131
  throw new Error(`Field type validation failed:
132
- ${o.join(`
132
+ ${r.join(`
133
133
  `)}`);
134
134
  return { valid: !0 };
135
135
  };
@@ -171,181 +171,183 @@ function ne(e, t) {
171
171
  }
172
172
  return null;
173
173
  }
174
- const oe = async () => ({ ok: !0 }), re = {
174
+ const re = async () => ({ ok: !0 }), oe = {
175
175
  validateRequiredFields: ee,
176
176
  validateFieldTypes: te,
177
- noop: oe
177
+ noop: re
178
178
  };
179
- function De() {
180
- for (const [e, t] of Object.entries(re))
179
+ function ve() {
180
+ for (const [e, t] of Object.entries(oe))
181
181
  X(e, t);
182
182
  }
183
- const Be = (e) => {
184
- const t = e.inflection?.recordFieldName ?? ie, n = e.inflection?.connectionFieldName ?? ce, i = e.inflection?.orderByTypeName ?? se, o = e.inflection?.recordArgName ?? ae, r = e.inflection?.recordArgType ?? le, s = e.inflection?.reverseConnectionName ?? F;
185
- return z(() => ({
186
- typeDefs: J`
187
- type StonecropFieldMeta {
188
- fieldname: String!
189
- fieldtype: String!
190
- component: String
191
- label: String
192
- width: String
193
- align: String
194
- required: Boolean
195
- readOnly: Boolean
196
- edit: Boolean
197
- hidden: Boolean
198
- default: JSON
199
- options: JSON
200
- mask: String
201
- precision: Int
202
- scale: Int
203
- mode: String
204
- validation: JSON
205
- }
183
+ const ie = V`
184
+ type StonecropFieldMeta {
185
+ fieldname: String!
186
+ fieldtype: String!
187
+ component: String
188
+ label: String
189
+ width: String
190
+ align: String
191
+ required: Boolean
192
+ readOnly: Boolean
193
+ edit: Boolean
194
+ hidden: Boolean
195
+ default: JSON
196
+ options: JSON
197
+ mask: String
198
+ precision: Int
199
+ scale: Int
200
+ mode: String
201
+ validation: JSON
202
+ }
206
203
 
207
- type StonecropWorkflowAction {
208
- label: String!
209
- handler: String!
210
- requiredFields: [String!]
211
- allowedStates: [String!]
212
- confirm: Boolean
213
- args: JSON
214
- }
204
+ type StonecropWorkflowAction {
205
+ label: String!
206
+ handler: String!
207
+ requiredFields: [String!]
208
+ allowedStates: [String!]
209
+ confirm: Boolean
210
+ args: JSON
211
+ }
215
212
 
216
- type StonecropWorkflowMeta {
217
- states: [String!]
218
- actions: [StonecropWorkflowAction!]
219
- }
213
+ type StonecropWorkflowMeta {
214
+ states: [String!]
215
+ actions: [StonecropWorkflowAction!]
216
+ }
220
217
 
221
- type StonecropDoctypeMeta {
222
- name: String!
223
- slug: String
224
- tableName: String
225
- fields: [StonecropFieldMeta!]!
226
- workflow: StonecropWorkflowMeta
227
- inherits: String
228
- }
218
+ type StonecropDoctypeMeta {
219
+ name: String!
220
+ slug: String
221
+ tableName: String
222
+ fields: [StonecropFieldMeta!]!
223
+ workflow: StonecropWorkflowMeta
224
+ inherits: String
225
+ }
229
226
 
230
- type StonecropRecordResult {
231
- data: JSON
232
- doctype: String!
233
- unknownLinks: [String!]
234
- }
227
+ type StonecropRecordResult {
228
+ data: JSON
229
+ doctype: String!
230
+ unknownLinks: [String!]
231
+ }
235
232
 
236
- type StonecropRecordsResult {
237
- data: [JSON!]!
238
- doctype: String!
239
- count: Int!
240
- }
233
+ type StonecropRecordsResult {
234
+ data: [JSON!]!
235
+ doctype: String!
236
+ count: Int!
237
+ }
241
238
 
242
- type StonecropActionResult {
243
- success: Boolean!
244
- data: JSON
245
- error: String
246
- }
239
+ type StonecropActionResult {
240
+ success: Boolean!
241
+ data: JSON
242
+ error: String
243
+ }
247
244
 
248
- extend type Query {
249
- stonecropMeta(doctype: String!): StonecropDoctypeMeta
250
- stonecropAllMeta: [StonecropDoctypeMeta!]!
251
- stonecropRecord(doctype: String!, id: String!, options: JSON): StonecropRecordResult
252
- stonecropRecords(
253
- doctype: String!
254
- filters: JSON
255
- orderBy: String
256
- limit: Int
257
- offset: Int
258
- ): StonecropRecordsResult
259
- }
245
+ extend type Query {
246
+ stonecropMeta(doctype: String!): StonecropDoctypeMeta
247
+ stonecropAllMeta: [StonecropDoctypeMeta!]!
248
+ stonecropRecord(doctype: String!, id: String!, options: JSON): StonecropRecordResult
249
+ stonecropRecords(
250
+ doctype: String!
251
+ filters: JSON
252
+ orderBy: String
253
+ limit: Int
254
+ offset: Int
255
+ options: JSON
256
+ ): StonecropRecordsResult
257
+ }
260
258
 
261
- extend type Mutation {
262
- stonecropAction(doctype: String!, action: String!, args: JSON): StonecropActionResult!
263
- }
264
- `,
259
+ extend type Mutation {
260
+ stonecropAction(doctype: String!, action: String!, args: JSON): StonecropActionResult!
261
+ }
262
+ `, xe = (e) => {
263
+ const t = e.inflection?.recordFieldName ?? ce, n = e.inflection?.connectionFieldName ?? se, i = e.inflection?.orderByTypeName ?? ae, r = e.inflection?.recordArgName ?? le, o = e.inflection?.recordArgType ?? de, s = e.inflection?.reverseConnectionName ?? A;
264
+ return z(() => ({
265
+ typeDefs: ie,
265
266
  objects: {
266
267
  Query: {
267
268
  plans: {
268
- stonecropMeta(c, { $doctype: l }) {
269
- return V(l, (y) => N(y) ?? null);
269
+ stonecropMeta(c, { $doctype: a }) {
270
+ return Q(a, (p) => $(p) ?? null);
270
271
  },
271
272
  stonecropAllMeta() {
272
- return Q(K());
273
+ return P(K());
273
274
  },
274
- stonecropRecord(c, { $doctype: l, $id: y, $options: p }) {
275
+ stonecropRecord(c, { $doctype: a, $id: p, $options: u }) {
275
276
  return M(
276
- O({ doctype: l, id: y, options: p }),
277
- async (d) => await Promise.all(
278
- d.map(async (f) => {
279
- const u = N(f.doctype);
280
- if (!u)
281
- throw new Error(`Unknown doctype: ${f.doctype}`);
282
- if (!u.tableName)
283
- throw new Error(`Doctype ${f.doctype} has no table mapping`);
284
- const a = f.options ?? {}, h = ue(
285
- u,
277
+ O({ doctype: a, id: p, options: u }),
278
+ async (l) => await Promise.all(
279
+ l.map(async (d) => {
280
+ const f = $(d.doctype);
281
+ if (!f)
282
+ throw new Error(`Unknown doctype: ${d.doctype}`);
283
+ if (!f.tableName)
284
+ throw new Error(`Doctype ${d.doctype} has no table mapping`);
285
+ const y = d.options ?? {}, m = ye(
286
+ f,
286
287
  t,
287
- o,
288
288
  r,
289
- N,
290
- a.includeNested ? {
291
- includeNested: a.includeNested,
292
- maxDepth: a.maxDepth
289
+ o,
290
+ $,
291
+ y.includeNested ? {
292
+ includeNested: y.includeNested,
293
+ maxDepth: y.maxDepth
293
294
  } : void 0,
294
295
  s
295
- ), g = await e.executor.query(h, {
296
- [o(u.tableName)]: f.id
296
+ ), g = await e.executor.query(m, {
297
+ [r(f.tableName)]: d.id
297
298
  });
298
- let S = ge({ result: g, meta: u, recordFieldName: t });
299
- a.includeNested && S && u.links && (S = ye({
300
- record: S,
301
- meta: u,
302
- getMeta: N,
299
+ let h = ge({ result: g, meta: f, recordFieldName: t });
300
+ y.includeNested && h && f.links && (h = me({
301
+ record: h,
302
+ meta: f,
303
+ getMeta: $,
303
304
  reverseConnectionNameFn: s
304
305
  }));
305
- const m = Array.isArray(a.includeNested) && u.links ? a.includeNested.filter((w) => !(w in u.links)) : void 0;
306
+ const S = Array.isArray(y.includeNested) && f.links ? y.includeNested.filter((N) => !(N in f.links)) : void 0;
306
307
  return {
307
- data: S,
308
- doctype: f.doctype,
309
- ...m ? { unknownLinks: m } : {}
308
+ data: h,
309
+ doctype: d.doctype,
310
+ ...S ? { unknownLinks: S } : {}
310
311
  };
311
312
  })
312
313
  )
313
314
  );
314
315
  },
315
- stonecropRecords(c, { $doctype: l, $filters: y, $orderBy: p, $limit: d, $offset: f }) {
316
+ stonecropRecords(c, { $doctype: a, $filters: p, $orderBy: u, $limit: l, $offset: d, $options: f }) {
316
317
  return M(
317
318
  O({
318
- doctype: l,
319
- filters: y,
320
- orderBy: p,
321
- limit: d,
322
- offset: f
319
+ doctype: a,
320
+ filters: p,
321
+ orderBy: u,
322
+ limit: l,
323
+ offset: d,
324
+ options: f
323
325
  }),
324
- async (u) => await Promise.all(
325
- u.map(async (a) => {
326
- const h = N(a.doctype);
327
- if (!h)
328
- throw new Error(`Unknown doctype: ${a.doctype}`);
329
- if (!h.tableName)
330
- throw new Error(`Doctype ${a.doctype} has no table mapping`);
331
- const g = pe(
332
- h,
326
+ async (y) => await Promise.all(
327
+ y.map(async (m) => {
328
+ const g = $(m.doctype);
329
+ if (!g)
330
+ throw new Error(`Unknown doctype: ${m.doctype}`);
331
+ if (!g.tableName)
332
+ throw new Error(`Doctype ${m.doctype} has no table mapping`);
333
+ const h = pe(
334
+ g,
333
335
  {
334
- limit: a.limit,
335
- offset: a.offset,
336
- orderBy: a.orderBy
336
+ limit: m.limit,
337
+ offset: m.offset,
338
+ orderBy: m.orderBy
337
339
  },
338
340
  n,
339
341
  i
340
- ), S = await e.executor.query(g, {
341
- limit: a.limit,
342
- offset: a.offset,
343
- orderBy: a.orderBy
344
- }), m = me({ result: S, meta: h, connectionFieldName: n });
342
+ ), S = await e.executor.query(h, {
343
+ limit: m.limit,
344
+ offset: m.offset,
345
+ orderBy: m.orderBy
346
+ }), N = he({ result: S, meta: g, connectionFieldName: n });
345
347
  return {
346
- data: m,
347
- doctype: a.doctype,
348
- count: m.length
348
+ data: N,
349
+ doctype: m.doctype,
350
+ count: N.length
349
351
  };
350
352
  })
351
353
  )
@@ -355,51 +357,51 @@ const Be = (e) => {
355
357
  },
356
358
  Mutation: {
357
359
  plans: {
358
- stonecropAction(c, { $doctype: l, $action: y, $args: p }) {
360
+ stonecropAction(c, { $doctype: a, $action: p, $args: u }) {
359
361
  return M(
360
362
  O({
361
- doctype: l,
362
- action: y,
363
- actionArgs: p
363
+ doctype: a,
364
+ action: p,
365
+ actionArgs: u
364
366
  }),
365
- async (d) => await Promise.all(
366
- d.map(async (f) => {
367
- const u = N(f.doctype);
368
- if (!u)
367
+ async (l) => await Promise.all(
368
+ l.map(async (d) => {
369
+ const f = $(d.doctype);
370
+ if (!f)
369
371
  return {
370
372
  success: !1,
371
373
  data: null,
372
- error: `Unknown doctype: ${f.doctype}`
374
+ error: `Unknown doctype: ${d.doctype}`
373
375
  };
374
- const a = u.workflow?.actions?.[f.action];
375
- if (!a)
376
+ const y = f.workflow?.actions?.[d.action];
377
+ if (!y)
376
378
  return {
377
379
  success: !1,
378
380
  data: null,
379
- error: `Unknown action: ${f.action} on ${f.doctype}`
381
+ error: `Unknown action: ${d.action} on ${d.doctype}`
380
382
  };
381
- const h = a.handler, g = Z(h);
383
+ const m = y.handler, g = Z(m);
382
384
  if (!g)
383
385
  return {
384
386
  success: !1,
385
387
  data: null,
386
- error: `Handler not registered: ${h}`
388
+ error: `Handler not registered: ${m}`
387
389
  };
388
- const S = {
389
- doctype: u,
390
+ const h = {
391
+ doctype: f,
390
392
  executor: e.executor
391
393
  };
392
394
  try {
393
395
  return {
394
396
  success: !0,
395
- data: await g(f.actionArgs ?? [], S),
397
+ data: await g(d.actionArgs ?? [], h),
396
398
  error: null
397
399
  };
398
- } catch (m) {
400
+ } catch (S) {
399
401
  return {
400
402
  success: !1,
401
403
  data: null,
402
- error: m instanceof Error ? m.message : String(m)
404
+ error: S instanceof Error ? S.message : String(S)
403
405
  };
404
406
  }
405
407
  })
@@ -411,264 +413,191 @@ const Be = (e) => {
411
413
  }
412
414
  }));
413
415
  };
414
- function ie(e) {
415
- const t = q.singular(e);
416
- return `${R(t)}ById`;
417
- }
418
416
  function ce(e) {
419
- return `all${I(e)}`;
417
+ const t = C.singular(e);
418
+ return `${F(t)}ById`;
420
419
  }
421
420
  function se(e) {
422
- return `${I(e)}OrderBy`;
421
+ return `all${I(e)}`;
423
422
  }
424
423
  function ae(e) {
425
- return "id";
424
+ return `${I(e)}OrderBy`;
426
425
  }
427
426
  function le(e) {
427
+ return "id";
428
+ }
429
+ function de(e) {
428
430
  return "UUID!";
429
431
  }
430
- function F(e) {
431
- const t = q.plural(e.target.replace(/-/g, "_")), n = R(t), i = e.backlink || e.doctype, o = i.charAt(0).toUpperCase() + R(i).slice(1);
432
- return `${n}By${o}Id`;
432
+ function A(e) {
433
+ const t = C.plural(e.target.replace(/-/g, "_")), n = F(t), i = e.backlink || e.doctype, r = i.charAt(0).toUpperCase() + F(i).slice(1);
434
+ return `${n}By${r}Id`;
433
435
  }
434
436
  function D(e) {
435
437
  return e === "noneOrMany" || e === "atLeastOne";
436
438
  }
437
- const C = 50, de = /* @__PURE__ */ new Set(["Display"]);
438
- function B(e) {
439
+ const T = 50, fe = /* @__PURE__ */ new Set(["Display"]);
440
+ function v(e) {
439
441
  const t = /* @__PURE__ */ new Set();
440
442
  if (e.links)
441
443
  for (const [n, i] of Object.entries(e.links))
442
444
  t.add(i.fieldname ?? n);
443
- return e.fields.filter((n) => !(de.has(n.fieldtype) || n.fieldtype === "Link" && t.has(n.fieldname))).map((n) => n.fieldname).join(`
445
+ return e.fields.filter((n) => !(fe.has(n.fieldtype) || n.fieldtype === "Link" && t.has(n.fieldname))).map((n) => n.fieldname).join(`
444
446
  `);
445
447
  }
446
- function T(e) {
447
- return e.fetch !== void 0 ? e.fetch : D(e.cardinality) ? { method: "sync", limit: C } : { method: "lazy" };
448
+ function q(e) {
449
+ return e.fetch !== void 0 ? e.fetch : D(e.cardinality) ? { method: "sync", limit: T } : { method: "lazy" };
448
450
  }
449
- function fe(e) {
450
- return e.blockWorkflows !== void 0 ? e.blockWorkflows : T(e).method === "sync";
451
+ function ue(e) {
452
+ return e.blockWorkflows !== void 0 ? e.blockWorkflows : q(e).method === "sync";
451
453
  }
452
454
  function L(e) {
453
- const { links: t, meta: n, includeSet: i, getMeta: o, seen: r, depth: s, maxDepth: c, reverseConnectionNameFn: l } = e;
455
+ const { links: t, meta: n, includeSet: i, getMeta: r, seen: o, depth: s, maxDepth: c, reverseConnectionNameFn: a } = e;
454
456
  if (c !== void 0 && s >= c) return "";
455
- const y = [];
456
- for (const [p, d] of Object.entries(t)) {
457
+ const p = [];
458
+ for (const [u, l] of Object.entries(t)) {
457
459
  if (c !== void 0 && s >= c) break;
458
- const f = fe(d), u = d.blockWorkflows === !0;
459
- if (i && !i.has(p) && !u)
460
+ const d = ue(l), f = l.blockWorkflows === !0;
461
+ if (i && !i.has(u) && !f)
460
462
  continue;
461
- const a = T(d);
462
- if (f === !1 || a.method !== "sync" && !u)
463
+ const y = q(l);
464
+ if (d === !1 || y.method !== "sync" && !f)
463
465
  continue;
464
- const g = o(d.target);
466
+ const g = r(l.target);
465
467
  if (!g) continue;
466
- const S = r.has(d.target);
467
- S || r.add(d.target);
468
- const m = B(g);
469
- let w = "";
470
- if (!S && g.links && g.tableName && (c === void 0 || s + 1 < c)) {
471
- const $ = L({
468
+ const h = o.has(l.target);
469
+ h || o.add(l.target);
470
+ const S = v(g);
471
+ let N = "";
472
+ if (!h && g.links && g.tableName && (c === void 0 || s + 1 < c)) {
473
+ const b = L({
472
474
  links: g.links,
473
475
  meta: g,
474
476
  includeSet: null,
475
- getMeta: o,
476
- seen: r,
477
+ getMeta: r,
478
+ seen: o,
477
479
  depth: s + 1,
478
480
  maxDepth: c,
479
- reverseConnectionNameFn: l
481
+ reverseConnectionNameFn: a
480
482
  });
481
- $ && (w = `
482
- ` + $), r.delete(d.target);
483
+ b && (N = `
484
+ ` + b), o.delete(l.target);
483
485
  }
484
- const v = m + w;
485
- if (D(d.cardinality)) {
486
- const $ = {
486
+ const x = S + N;
487
+ if (D(l.cardinality)) {
488
+ const b = {
487
489
  doctype: n.slug || n.name,
488
- linkName: p,
489
- backlink: d.backlink,
490
- target: d.target
491
- }, W = l ? l($) : F($), x = a.method === "sync" && a.limit !== void 0 ? `first: ${a.limit}` : a.method === "sync" ? `first: ${C}` : "";
492
- y.push(`
493
- ${W}${x ? `(${x})` : ""} {
490
+ linkName: u,
491
+ backlink: l.backlink,
492
+ target: l.target
493
+ }, J = a ? a(b) : A(b), B = y.method === "sync" && y.limit !== void 0 ? `first: ${y.limit}` : y.method === "sync" ? `first: ${T}` : "";
494
+ p.push(`
495
+ ${J}${B ? `(${B})` : ""} {
494
496
  nodes {
495
- ${v}
497
+ ${x}
496
498
  }
497
499
  }`);
498
500
  } else
499
- y.push(`
500
- ${p} {
501
- ${v}
501
+ p.push(`
502
+ ${u} {
503
+ ${x}
502
504
  }`);
503
505
  }
504
- return y.join("");
506
+ return p.join("");
505
507
  }
506
- function ue(e, t, n, i, o, r, s) {
507
- const c = t(e.tableName), l = n(e.tableName), y = i(e.tableName), p = /* @__PURE__ */ new Set([e.slug || e.name]);
508
- let d = B(e);
509
- if (r?.includeNested && e.links) {
510
- const f = Array.isArray(r.includeNested) ? new Set(r.includeNested) : null, u = L({
508
+ function ye(e, t, n, i, r, o, s) {
509
+ const c = t(e.tableName), a = n(e.tableName), p = i(e.tableName), u = /* @__PURE__ */ new Set([e.slug || e.name]);
510
+ let l = v(e);
511
+ if (o?.includeNested && e.links) {
512
+ const d = Array.isArray(o.includeNested) ? new Set(o.includeNested) : null, f = L({
511
513
  links: e.links,
512
514
  meta: e,
513
- includeSet: f,
514
- getMeta: o,
515
- seen: p,
515
+ includeSet: d,
516
+ getMeta: r,
517
+ seen: u,
516
518
  depth: 0,
517
- maxDepth: r.maxDepth,
519
+ maxDepth: o.maxDepth,
518
520
  reverseConnectionNameFn: s
519
521
  });
520
- u && (d += `
521
- ` + u);
522
+ f && (l += `
523
+ ` + f);
522
524
  }
523
525
  return `
524
- query GetRecord($${l}: ${y}) {
525
- ${c}(${l}: $${l}) {
526
- ${d}
526
+ query GetRecord($${a}: ${p}) {
527
+ ${c}(${a}: $${a}) {
528
+ ${l}
527
529
  }
528
530
  }
529
531
  `;
530
532
  }
531
533
  function pe(e, t, n, i) {
532
- const o = B(e), r = n(e.tableName), s = i(e.tableName), c = [], l = [];
533
- t.limit && (c.push("$limit: Int"), l.push("first: $limit")), t.offset && (c.push("$offset: Int"), l.push("offset: $offset")), t.orderBy && (c.push(`$orderBy: [${s}!]`), l.push("orderBy: $orderBy"));
534
- const y = c.length > 0 ? `(${c.join(", ")})` : "", p = l.length > 0 ? `(${l.join(", ")})` : "";
534
+ const r = v(e), o = n(e.tableName), s = i(e.tableName), c = [], a = [];
535
+ t.limit && (c.push("$limit: Int"), a.push("first: $limit")), t.offset && (c.push("$offset: Int"), a.push("offset: $offset")), t.orderBy && (c.push(`$orderBy: [${s}!]`), a.push("orderBy: $orderBy"));
536
+ const p = c.length > 0 ? `(${c.join(", ")})` : "", u = a.length > 0 ? `(${a.join(", ")})` : "";
535
537
  return `
536
- query GetRecords${y} {
537
- ${r}${p} {
538
+ query GetRecords${p} {
539
+ ${o}${u} {
538
540
  nodes {
539
- ${o}
541
+ ${r}
540
542
  }
541
543
  }
542
544
  }
543
545
  `;
544
546
  }
545
- function ye(e) {
546
- const { record: t, meta: n, getMeta: i, reverseConnectionNameFn: o } = e;
547
+ function me(e) {
548
+ const { record: t, meta: n, getMeta: i, reverseConnectionNameFn: r } = e;
547
549
  if (!n.links) return t;
548
- const r = { ...t };
550
+ const o = { ...t };
549
551
  for (const [s, c] of Object.entries(n.links))
550
552
  if (D(c.cardinality)) {
551
553
  if (!i(c.target)) continue;
552
- const p = {
554
+ const u = {
553
555
  doctype: n.slug || n.name,
554
556
  linkName: s,
555
557
  backlink: c.backlink || s,
556
558
  target: c.target
557
- }, d = o ? o(p) : F(p), f = r[d];
558
- f?.nodes ? (r[s] = f.nodes, delete r[d]) : (r[s] = [], delete r[d]);
559
+ }, l = r ? r(u) : A(u), d = o[l];
560
+ d?.nodes ? (o[s] = d.nodes, delete o[l]) : (o[s] = [], delete o[l]);
559
561
  }
560
- return r;
562
+ return o;
561
563
  }
562
564
  function ge(e) {
563
- const { result: t, meta: n, recordFieldName: i } = e, o = i(n.tableName);
564
- return t[o];
565
+ const { result: t, meta: n, recordFieldName: i } = e, r = i(n.tableName);
566
+ return t[r];
565
567
  }
566
- function me(e) {
567
- const { result: t, meta: n, connectionFieldName: i } = e, o = i(n.tableName);
568
- return t[o]?.nodes ?? [];
568
+ function he(e) {
569
+ const { result: t, meta: n, connectionFieldName: i } = e, r = i(n.tableName);
570
+ return t[r]?.nodes ?? [];
569
571
  }
570
- const ve = J`
571
- type StonecropFieldMeta {
572
- fieldname: String!
573
- fieldtype: String!
574
- component: String
575
- label: String
576
- width: String
577
- align: String
578
- required: Boolean
579
- readOnly: Boolean
580
- edit: Boolean
581
- hidden: Boolean
582
- default: JSON
583
- options: JSON
584
- mask: String
585
- precision: Int
586
- scale: Int
587
- mode: String
588
- validation: JSON
589
- }
590
-
591
- type StonecropWorkflowAction {
592
- label: String!
593
- handler: String!
594
- requiredFields: [String!]
595
- allowedStates: [String!]
596
- confirm: Boolean
597
- args: JSON
598
- }
599
-
600
- type StonecropWorkflowMeta {
601
- states: [String!]
602
- actions: [StonecropWorkflowAction!]
603
- }
604
-
605
- type StonecropDoctypeMeta {
606
- name: String!
607
- slug: String
608
- tableName: String
609
- fields: [StonecropFieldMeta!]!
610
- workflow: StonecropWorkflowMeta
611
- inherits: String
612
- }
613
-
614
- type StonecropRecordResult {
615
- data: JSON
616
- doctype: String!
617
- unknownLinks: [String!]
618
- }
619
-
620
- type StonecropRecordsResult {
621
- data: [JSON!]!
622
- doctype: String!
623
- count: Int!
624
- }
625
-
626
- type StonecropActionResult {
627
- success: Boolean!
628
- data: JSON
629
- error: String
630
- }
631
-
632
- extend type Query {
633
- stonecropMeta(doctype: String!): StonecropDoctypeMeta
634
- stonecropAllMeta: [StonecropDoctypeMeta!]!
635
- stonecropRecord(doctype: String!, id: String!, options: JSON): StonecropRecordResult
636
- stonecropRecords(doctype: String!, filters: JSON, orderBy: String, limit: Int, offset: Int): StonecropRecordsResult
637
- }
638
-
639
- extend type Mutation {
640
- stonecropAction(doctype: String!, action: String!, args: JSON): StonecropActionResult!
641
- }
642
- `;
643
572
  export {
644
- A as DoctypeValidationError,
645
- de as RELATION_FIELDTYPES,
573
+ R as DoctypeValidationError,
574
+ fe as RELATION_FIELDTYPES,
646
575
  pe as buildListQuery,
647
- ue as buildRecordQuery,
648
- re as builtinHandlers,
649
- Fe as clearHandlers,
650
- Oe as clearRegistry,
651
- Be as createStonecropPlugin,
652
- ce as defaultConnectionFieldName,
653
- se as defaultOrderByTypeName,
654
- ae as defaultRecordArgName,
655
- le as defaultRecordArgType,
656
- ie as defaultRecordFieldName,
657
- F as defaultReverseConnectionName,
658
- me as extractListResult,
576
+ ye as buildRecordQuery,
577
+ oe as builtinHandlers,
578
+ De as clearHandlers,
579
+ Fe as clearRegistry,
580
+ xe as createStonecropPlugin,
581
+ se as defaultConnectionFieldName,
582
+ ae as defaultOrderByTypeName,
583
+ le as defaultRecordArgName,
584
+ de as defaultRecordArgType,
585
+ ce as defaultRecordFieldName,
586
+ A as defaultReverseConnectionName,
587
+ he as extractListResult,
659
588
  ge as extractSingleResult,
660
589
  K as getAllMeta,
661
590
  Z as getHandler,
662
- N as getMeta,
591
+ $ as getMeta,
663
592
  Ae as hasHandler,
664
- Me as hasMeta,
593
+ Oe as hasMeta,
665
594
  G as loadDoctypes,
666
- be as loadDoctypesFromObject,
667
- ye as mergeNestedResults,
668
- B as queryableFieldNames,
669
- De as registerBuiltinHandlers,
595
+ Me as loadDoctypesFromObject,
596
+ me as mergeNestedResults,
597
+ v as queryableFieldNames,
598
+ ve as registerBuiltinHandlers,
670
599
  X as registerHandler,
671
- ve as typeDefs,
600
+ ie as typeDefs,
672
601
  Re as validateReferences
673
602
  };
674
603
  //# sourceMappingURL=index.js.map