@stonecrop/graphql-middleware 0.12.1 → 0.12.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -92,6 +92,16 @@ The middleware loads doctype definitions from JSON files. Each file defines a do
92
92
 
93
93
  The `links` object declares relationships used when `includeNested` is requested. The `workflow` object enables action dispatch.
94
94
 
95
+ ### Display-only fields
96
+
97
+ Fields with `fieldtype: "Display"` are excluded from the auto-generated scalar query. Use this for composite UI components (e.g. a canvas visualisation) that have no backing database column:
98
+
99
+ ```json
100
+ { "fieldname": "planner", "fieldtype": "Display", "component": "Planner", "label": "Resource Planner" }
101
+ ```
102
+
103
+ All other non-`Link` fieldtypes are assumed to map to a scalar DB column and are included in the query.
104
+
95
105
  ## Actions
96
106
 
97
107
  Actions are custom logic triggered by the client. Register handlers with `registerHandler`:
@@ -26,7 +26,7 @@ export declare type ActionHandler = (args: unknown[], context: ActionContext) =>
26
26
  * Build a GraphQL connection query to fetch a list of records.
27
27
  * Only declares variables ($limit, $offset, $orderBy) that are actually used in the query,
28
28
  * avoiding GraphQL spec §5.8.3 violations from unused variable declarations.
29
- * Excludes Link and Doctype relation fields from the selection set.
29
+ * Excludes Link relation fields and Display fields from the selection set.
30
30
  * @public
31
31
  */
32
32
  export declare function buildListQuery(meta: DoctypeMeta, args: BuildListQueryArgs, connectionFieldName: (t: string) => string, orderByTypeName: (t: string) => string): string;
@@ -291,8 +291,10 @@ export declare interface MergeNestedResultsParams {
291
291
  }
292
292
 
293
293
  /**
294
- * Filter fields to only those directly queryable as scalars, excluding Link and Doctype
295
- * relation fields that require GraphQL sub-selections.
294
+ * Filter fields to only those directly queryable as scalars.
295
+ * Excludes Display fields (no backing DB column) and Link fields that have an
296
+ * explicit `links` declaration (those require sub-selection, not scalar reads).
297
+ * Link fields without a `links` declaration are scalar FK UUID columns and ARE included.
296
298
  * @public
297
299
  */
298
300
  export declare function queryableFieldNames(meta: DoctypeMeta): string;
@@ -312,8 +314,13 @@ export declare function registerBuiltinHandlers(): void;
312
314
  export declare function registerHandler(name: string, handler: ActionHandler): void;
313
315
 
314
316
  /**
315
- * Fieldtypes that map to GraphQL object/connection types and require sub-selections.
316
- * These fields are excluded from generated query field selections.
317
+ * Fieldtypes unconditionally excluded from the generated scalar query selection set.
318
+ * - `'Display'`: display-only composite component with no backing DB column
319
+ *
320
+ * Note: `'Link'` fields are NOT blanket-excluded here. Scalar FK UUID columns use
321
+ * `fieldtype: 'Link'` and ARE queryable. Only Link fields that also appear in the
322
+ * doctype's `links` declaration (i.e. those that resolve to a sub-object or connection)
323
+ * are excluded — that logic lives in `queryableFieldNames`.
317
324
  * @public
318
325
  */
319
326
  export declare const RELATION_FIELDTYPES: Set<string>;
package/dist/index.js CHANGED
@@ -1,44 +1,44 @@
1
1
  import { readdirSync as _, statSync as U, readFileSync as H } from "node:fs";
2
2
  import { join as P } from "node:path";
3
- import { validateDoctype as E, parseDoctype as I, toPascalCase as J, snakeToCamel as O } from "@stonecrop/schema";
4
- import { loadOne as M, object as R, constant as Q, lambda as V } from "postgraphile/grafast";
5
- import { extendSchema as z, gql as j } from "postgraphile/utils";
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
6
  import q from "pluralize";
7
- const N = /* @__PURE__ */ new Map();
7
+ const k = /* @__PURE__ */ new Map();
8
8
  class A extends Error {
9
9
  constructor(t, n) {
10
- const c = n.map((o) => ` ${o.path.join(".")}: ${o.message}`).join(`
10
+ const i = n.map((o) => ` ${o.path.join(".")}: ${o.message}`).join(`
11
11
  `);
12
12
  super(`Invalid doctype definition in ${t}:
13
- ${c}`), this.file = t, this.errors = n, this.name = "DoctypeValidationError";
13
+ ${i}`), this.file = t, this.errors = n, this.name = "DoctypeValidationError";
14
14
  }
15
15
  file;
16
16
  errors;
17
17
  }
18
18
  function G(e, t = {}) {
19
19
  const n = _(e);
20
- for (const c of n) {
21
- const o = P(e, c);
22
- U(o).isDirectory() ? G(o, t) : c.endsWith(".json") && Y(o, t);
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);
23
23
  }
24
24
  }
25
25
  function Y(e, t) {
26
26
  const n = H(e, "utf-8");
27
- let c;
27
+ let i;
28
28
  try {
29
- c = JSON.parse(n);
29
+ i = JSON.parse(n);
30
30
  } catch (s) {
31
- const i = {
31
+ const c = {
32
32
  path: [],
33
33
  message: `Invalid JSON: ${s instanceof Error ? s.message : String(s)}`
34
34
  };
35
35
  if (t.continueOnError) {
36
- t.onError?.(e, [i]);
36
+ t.onError?.(e, [c]);
37
37
  return;
38
38
  }
39
- throw new A(e, [i]);
39
+ throw new A(e, [c]);
40
40
  }
41
- const o = E(c);
41
+ const o = E(i);
42
42
  if (!o.success) {
43
43
  if (t.continueOnError) {
44
44
  t.onError?.(e, o.errors);
@@ -46,12 +46,12 @@ function Y(e, t) {
46
46
  }
47
47
  throw new A(e, o.errors);
48
48
  }
49
- const r = I(c);
50
- N.set(r.name, r);
49
+ const r = j(i);
50
+ k.set(r.name, r);
51
51
  }
52
52
  function be(e, t = {}) {
53
- for (const [n, c] of Object.entries(e)) {
54
- const o = { ...c, name: n }, r = E(o);
53
+ for (const [n, i] of Object.entries(e)) {
54
+ const o = { ...i, name: n }, r = E(o);
55
55
  if (!r.success) {
56
56
  if (t.continueOnError) {
57
57
  t.onError?.(n, r.errors);
@@ -59,34 +59,34 @@ function be(e, t = {}) {
59
59
  }
60
60
  throw new A(n, r.errors);
61
61
  }
62
- const s = I(o);
63
- N.set(s.name, s);
62
+ const s = j(o);
63
+ k.set(s.name, s);
64
64
  }
65
65
  }
66
- function k(e) {
67
- const t = N.get(e);
66
+ function N(e) {
67
+ const t = k.get(e);
68
68
  if (t) return t;
69
- for (const n of N.values())
69
+ for (const n of k.values())
70
70
  if (n.slug === e) return n;
71
71
  }
72
72
  function K() {
73
- return Array.from(N.values());
73
+ return Array.from(k.values());
74
74
  }
75
75
  function Me(e) {
76
- return N.has(e);
77
- }
78
- function Re() {
79
- N.clear();
76
+ return k.has(e);
80
77
  }
81
78
  function Oe() {
79
+ k.clear();
80
+ }
81
+ function Re() {
82
82
  const e = [];
83
- for (const t of N.values()) {
84
- t.inherits && !N.has(t.inherits) && e.push({
83
+ for (const t of k.values()) {
84
+ t.inherits && !k.has(t.inherits) && e.push({
85
85
  path: [t.name, "inherits"],
86
86
  message: `References unknown doctype: ${t.inherits}`
87
87
  });
88
88
  for (const n of t.fields)
89
- n.fieldtype === "Link" && typeof n.options == "string" && (N.has(n.options) || e.push({
89
+ n.fieldtype === "Link" && typeof n.options == "string" && (k.has(n.options) || e.push({
90
90
  path: [t.name, "fields", n.fieldname, "options"],
91
91
  message: `Link references unknown doctype: ${n.options}`
92
92
  }));
@@ -107,25 +107,25 @@ function Fe() {
107
107
  b.clear();
108
108
  }
109
109
  const ee = async (e, t) => {
110
- const [n] = e, { doctype: c } = t, o = [];
111
- for (const r of c.fields)
110
+ const [n] = e, { doctype: i } = t, o = [];
111
+ for (const r of i.fields)
112
112
  r.required && (n[r.fieldname] === void 0 || n[r.fieldname] === null) && o.push(r.label ?? r.fieldname);
113
113
  if (o.length > 0)
114
114
  throw new Error(`Missing required fields: ${o.join(", ")}`);
115
115
  return { valid: !0 };
116
116
  }, te = async (e, t) => {
117
- const [n] = e, { doctype: c } = t, o = [];
118
- for (const r of c.fields) {
117
+ const [n] = e, { doctype: i } = t, o = [];
118
+ for (const r of i.fields) {
119
119
  const s = n[r.fieldname];
120
120
  if (s == null) continue;
121
- const i = ne(r, s);
122
- i && o.push(i);
121
+ const c = ne(r, s);
122
+ c && o.push(c);
123
123
  }
124
- if (c.links)
125
- for (const [r, s] of Object.entries(c.links)) {
126
- const i = n[r];
127
- if (i == null) continue;
128
- s.cardinality === "noneOrMany" || s.cardinality === "atLeastOne" ? Array.isArray(i) || o.push(`${r}: expected array, got ${typeof i}`) : (typeof i != "object" || Array.isArray(i)) && o.push(`${r}: expected object, got ${typeof i}`);
124
+ if (i.links)
125
+ for (const [r, s] of Object.entries(i.links)) {
126
+ const c = n[r];
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}`);
129
129
  }
130
130
  if (o.length > 0)
131
131
  throw new Error(`Field type validation failed:
@@ -134,8 +134,8 @@ ${o.join(`
134
134
  return { valid: !0 };
135
135
  };
136
136
  function ne(e, t) {
137
- const { fieldname: n, fieldtype: c, cardinality: o } = e;
138
- switch (c) {
137
+ const { fieldname: n, fieldtype: i } = e;
138
+ switch (i) {
139
139
  case "Int":
140
140
  if (typeof t != "number" || !Number.isInteger(t))
141
141
  return `${n}: expected integer, got ${typeof t}`;
@@ -176,14 +176,14 @@ const oe = async () => ({ ok: !0 }), re = {
176
176
  validateFieldTypes: te,
177
177
  noop: oe
178
178
  };
179
- function Be() {
179
+ function De() {
180
180
  for (const [e, t] of Object.entries(re))
181
181
  X(e, t);
182
182
  }
183
- const De = (e) => {
184
- const t = e.inflection?.recordFieldName ?? ie, n = e.inflection?.connectionFieldName ?? ce, c = e.inflection?.orderByTypeName ?? se, o = e.inflection?.recordArgName ?? ae, r = e.inflection?.recordArgType ?? le, s = e.inflection?.reverseConnectionName ?? F;
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
185
  return z(() => ({
186
- typeDefs: j`
186
+ typeDefs: J`
187
187
  type StonecropFieldMeta {
188
188
  fieldname: String!
189
189
  fieldtype: String!
@@ -265,18 +265,18 @@ const De = (e) => {
265
265
  objects: {
266
266
  Query: {
267
267
  plans: {
268
- stonecropMeta(i, { $doctype: l }) {
269
- return V(l, (y) => k(y) ?? null);
268
+ stonecropMeta(c, { $doctype: l }) {
269
+ return V(l, (y) => N(y) ?? null);
270
270
  },
271
271
  stonecropAllMeta() {
272
272
  return Q(K());
273
273
  },
274
- stonecropRecord(i, { $doctype: l, $id: y, $options: p }) {
274
+ stonecropRecord(c, { $doctype: l, $id: y, $options: p }) {
275
275
  return M(
276
- R({ doctype: l, id: y, options: p }),
276
+ O({ doctype: l, id: y, options: p }),
277
277
  async (d) => await Promise.all(
278
278
  d.map(async (f) => {
279
- const u = k(f.doctype);
279
+ const u = N(f.doctype);
280
280
  if (!u)
281
281
  throw new Error(`Unknown doctype: ${f.doctype}`);
282
282
  if (!u.tableName)
@@ -286,7 +286,7 @@ const De = (e) => {
286
286
  t,
287
287
  o,
288
288
  r,
289
- k,
289
+ N,
290
290
  a.includeNested ? {
291
291
  includeNested: a.includeNested,
292
292
  maxDepth: a.maxDepth
@@ -299,7 +299,7 @@ const De = (e) => {
299
299
  a.includeNested && S && u.links && (S = ye({
300
300
  record: S,
301
301
  meta: u,
302
- getMeta: k,
302
+ getMeta: N,
303
303
  reverseConnectionNameFn: s
304
304
  }));
305
305
  const m = Array.isArray(a.includeNested) && u.links ? a.includeNested.filter((w) => !(w in u.links)) : void 0;
@@ -312,9 +312,9 @@ const De = (e) => {
312
312
  )
313
313
  );
314
314
  },
315
- stonecropRecords(i, { $doctype: l, $filters: y, $orderBy: p, $limit: d, $offset: f }) {
315
+ stonecropRecords(c, { $doctype: l, $filters: y, $orderBy: p, $limit: d, $offset: f }) {
316
316
  return M(
317
- R({
317
+ O({
318
318
  doctype: l,
319
319
  filters: y,
320
320
  orderBy: p,
@@ -323,7 +323,7 @@ const De = (e) => {
323
323
  }),
324
324
  async (u) => await Promise.all(
325
325
  u.map(async (a) => {
326
- const h = k(a.doctype);
326
+ const h = N(a.doctype);
327
327
  if (!h)
328
328
  throw new Error(`Unknown doctype: ${a.doctype}`);
329
329
  if (!h.tableName)
@@ -336,7 +336,7 @@ const De = (e) => {
336
336
  orderBy: a.orderBy
337
337
  },
338
338
  n,
339
- c
339
+ i
340
340
  ), S = await e.executor.query(g, {
341
341
  limit: a.limit,
342
342
  offset: a.offset,
@@ -355,16 +355,16 @@ const De = (e) => {
355
355
  },
356
356
  Mutation: {
357
357
  plans: {
358
- stonecropAction(i, { $doctype: l, $action: y, $args: p }) {
358
+ stonecropAction(c, { $doctype: l, $action: y, $args: p }) {
359
359
  return M(
360
- R({
360
+ O({
361
361
  doctype: l,
362
362
  action: y,
363
363
  actionArgs: p
364
364
  }),
365
365
  async (d) => await Promise.all(
366
366
  d.map(async (f) => {
367
- const u = k(f.doctype);
367
+ const u = N(f.doctype);
368
368
  if (!u)
369
369
  return {
370
370
  success: !1,
@@ -413,13 +413,13 @@ const De = (e) => {
413
413
  };
414
414
  function ie(e) {
415
415
  const t = q.singular(e);
416
- return `${O(t)}ById`;
416
+ return `${R(t)}ById`;
417
417
  }
418
418
  function ce(e) {
419
- return `all${J(e)}`;
419
+ return `all${I(e)}`;
420
420
  }
421
421
  function se(e) {
422
- return `${J(e)}OrderBy`;
422
+ return `${I(e)}OrderBy`;
423
423
  }
424
424
  function ae(e) {
425
425
  return "id";
@@ -428,31 +428,35 @@ function le(e) {
428
428
  return "UUID!";
429
429
  }
430
430
  function F(e) {
431
- const t = q.plural(e.target.replace(/-/g, "_")), n = O(t), c = e.backlink || e.doctype, o = c.charAt(0).toUpperCase() + O(c).slice(1);
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
432
  return `${n}By${o}Id`;
433
433
  }
434
- function B(e) {
434
+ function D(e) {
435
435
  return e === "noneOrMany" || e === "atLeastOne";
436
436
  }
437
- const C = 50, de = /* @__PURE__ */ new Set(["Link"]);
438
- function D(e) {
439
- return e.fields.filter((t) => !de.has(t.fieldtype)).map((t) => t.fieldname).join(`
437
+ const C = 50, de = /* @__PURE__ */ new Set(["Display"]);
438
+ function B(e) {
439
+ const t = /* @__PURE__ */ new Set();
440
+ if (e.links)
441
+ for (const [n, i] of Object.entries(e.links))
442
+ 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(`
440
444
  `);
441
445
  }
442
446
  function T(e) {
443
- return e.fetch !== void 0 ? e.fetch : B(e.cardinality) ? { method: "sync", limit: C } : { method: "lazy" };
447
+ return e.fetch !== void 0 ? e.fetch : D(e.cardinality) ? { method: "sync", limit: C } : { method: "lazy" };
444
448
  }
445
449
  function fe(e) {
446
450
  return e.blockWorkflows !== void 0 ? e.blockWorkflows : T(e).method === "sync";
447
451
  }
448
452
  function L(e) {
449
- const { links: t, meta: n, includeSet: c, getMeta: o, seen: r, depth: s, maxDepth: i, reverseConnectionNameFn: l } = e;
450
- if (i !== void 0 && s >= i) return "";
453
+ const { links: t, meta: n, includeSet: i, getMeta: o, seen: r, depth: s, maxDepth: c, reverseConnectionNameFn: l } = e;
454
+ if (c !== void 0 && s >= c) return "";
451
455
  const y = [];
452
456
  for (const [p, d] of Object.entries(t)) {
453
- if (i !== void 0 && s >= i) break;
457
+ if (c !== void 0 && s >= c) break;
454
458
  const f = fe(d), u = d.blockWorkflows === !0;
455
- if (c && !c.has(p) && !u)
459
+ if (i && !i.has(p) && !u)
456
460
  continue;
457
461
  const a = T(d);
458
462
  if (f === !1 || a.method !== "sync" && !u)
@@ -461,9 +465,9 @@ function L(e) {
461
465
  if (!g) continue;
462
466
  const S = r.has(d.target);
463
467
  S || r.add(d.target);
464
- const m = D(g);
468
+ const m = B(g);
465
469
  let w = "";
466
- if (!S && g.links && g.tableName && (i === void 0 || s + 1 < i)) {
470
+ if (!S && g.links && g.tableName && (c === void 0 || s + 1 < c)) {
467
471
  const $ = L({
468
472
  links: g.links,
469
473
  meta: g,
@@ -471,14 +475,14 @@ function L(e) {
471
475
  getMeta: o,
472
476
  seen: r,
473
477
  depth: s + 1,
474
- maxDepth: i,
478
+ maxDepth: c,
475
479
  reverseConnectionNameFn: l
476
480
  });
477
481
  $ && (w = `
478
482
  ` + $), r.delete(d.target);
479
483
  }
480
484
  const v = m + w;
481
- if (B(d.cardinality)) {
485
+ if (D(d.cardinality)) {
482
486
  const $ = {
483
487
  doctype: n.slug || n.name,
484
488
  linkName: p,
@@ -499,9 +503,9 @@ function L(e) {
499
503
  }
500
504
  return y.join("");
501
505
  }
502
- function ue(e, t, n, c, o, r, s) {
503
- const i = t(e.tableName), l = n(e.tableName), y = c(e.tableName), p = /* @__PURE__ */ new Set([e.slug || e.name]);
504
- let d = D(e);
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);
505
509
  if (r?.includeNested && e.links) {
506
510
  const f = Array.isArray(r.includeNested) ? new Set(r.includeNested) : null, u = L({
507
511
  links: e.links,
@@ -518,16 +522,16 @@ function ue(e, t, n, c, o, r, s) {
518
522
  }
519
523
  return `
520
524
  query GetRecord($${l}: ${y}) {
521
- ${i}(${l}: $${l}) {
525
+ ${c}(${l}: $${l}) {
522
526
  ${d}
523
527
  }
524
528
  }
525
529
  `;
526
530
  }
527
- function pe(e, t, n, c) {
528
- const o = D(e), r = n(e.tableName), s = c(e.tableName), i = [], l = [];
529
- t.limit && (i.push("$limit: Int"), l.push("first: $limit")), t.offset && (i.push("$offset: Int"), l.push("offset: $offset")), t.orderBy && (i.push(`$orderBy: [${s}!]`), l.push("orderBy: $orderBy"));
530
- const y = i.length > 0 ? `(${i.join(", ")})` : "", p = l.length > 0 ? `(${l.join(", ")})` : "";
531
+ 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(", ")})` : "";
531
535
  return `
532
536
  query GetRecords${y} {
533
537
  ${r}${p} {
@@ -539,31 +543,31 @@ function pe(e, t, n, c) {
539
543
  `;
540
544
  }
541
545
  function ye(e) {
542
- const { record: t, meta: n, getMeta: c, reverseConnectionNameFn: o } = e;
546
+ const { record: t, meta: n, getMeta: i, reverseConnectionNameFn: o } = e;
543
547
  if (!n.links) return t;
544
548
  const r = { ...t };
545
- for (const [s, i] of Object.entries(n.links))
546
- if (B(i.cardinality)) {
547
- if (!c(i.target)) continue;
549
+ for (const [s, c] of Object.entries(n.links))
550
+ if (D(c.cardinality)) {
551
+ if (!i(c.target)) continue;
548
552
  const p = {
549
553
  doctype: n.slug || n.name,
550
554
  linkName: s,
551
- backlink: i.backlink || s,
552
- target: i.target
555
+ backlink: c.backlink || s,
556
+ target: c.target
553
557
  }, d = o ? o(p) : F(p), f = r[d];
554
558
  f?.nodes ? (r[s] = f.nodes, delete r[d]) : (r[s] = [], delete r[d]);
555
559
  }
556
560
  return r;
557
561
  }
558
562
  function ge(e) {
559
- const { result: t, meta: n, recordFieldName: c } = e, o = c(n.tableName);
563
+ const { result: t, meta: n, recordFieldName: i } = e, o = i(n.tableName);
560
564
  return t[o];
561
565
  }
562
566
  function me(e) {
563
- const { result: t, meta: n, connectionFieldName: c } = e, o = c(n.tableName);
567
+ const { result: t, meta: n, connectionFieldName: i } = e, o = i(n.tableName);
564
568
  return t[o]?.nodes ?? [];
565
569
  }
566
- const ve = j`
570
+ const ve = J`
567
571
  type StonecropFieldMeta {
568
572
  fieldname: String!
569
573
  fieldtype: String!
@@ -643,8 +647,8 @@ export {
643
647
  ue as buildRecordQuery,
644
648
  re as builtinHandlers,
645
649
  Fe as clearHandlers,
646
- Re as clearRegistry,
647
- De as createStonecropPlugin,
650
+ Oe as clearRegistry,
651
+ Be as createStonecropPlugin,
648
652
  ce as defaultConnectionFieldName,
649
653
  se as defaultOrderByTypeName,
650
654
  ae as defaultRecordArgName,
@@ -655,16 +659,16 @@ export {
655
659
  ge as extractSingleResult,
656
660
  K as getAllMeta,
657
661
  Z as getHandler,
658
- k as getMeta,
662
+ N as getMeta,
659
663
  Ae as hasHandler,
660
664
  Me as hasMeta,
661
665
  G as loadDoctypes,
662
666
  be as loadDoctypesFromObject,
663
667
  ye as mergeNestedResults,
664
- D as queryableFieldNames,
665
- Be as registerBuiltinHandlers,
668
+ B as queryableFieldNames,
669
+ De as registerBuiltinHandlers,
666
670
  X as registerHandler,
667
671
  ve as typeDefs,
668
- Oe as validateReferences
672
+ Re as validateReferences
669
673
  };
670
674
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/registry/doctypes.ts","../src/registry/actions.ts","../src/plugin/postgraphile.ts","../src/typeDefs.ts"],"sourcesContent":["import { readFileSync, readdirSync, statSync } from 'node:fs'\nimport { join } from 'node:path'\n\nimport { parseDoctype, validateDoctype } from '@stonecrop/schema'\nimport type { DoctypeMeta, ValidationError } from '@stonecrop/schema'\n\nconst doctypeRegistry: Map<string, DoctypeMeta> = new Map()\n\n/**\n * Error thrown when a doctype definition fails validation\n * @public\n */\nexport class DoctypeValidationError extends Error {\n\tconstructor(\n\t\t/** File path or name where the validation error occurred */\n\t\tpublic readonly file: string,\n\t\t/** List of validation errors found */\n\t\tpublic readonly errors: ValidationError[]\n\t) {\n\t\tconst errorMessages = errors.map(e => ` ${e.path.join('.')}: ${e.message}`).join('\\n')\n\t\tsuper(`Invalid doctype definition in ${file}:\\n${errorMessages}`)\n\t\tthis.name = 'DoctypeValidationError'\n\t}\n}\n\n/**\n * Options for loading doctype definitions\n * @public\n */\nexport interface LoadDoctypesOptions {\n\t/** Continue loading other files if one fails validation */\n\tcontinueOnError?: boolean\n\t/** Callback for validation errors when continueOnError is true */\n\tonError?: (file: string, errors: ValidationError[]) => void\n}\n\n/**\n * Load doctype definitions from a directory of JSON files\n * @param dir - Directory path containing doctype JSON files\n * @param options - Options for loading doctypes (continueOnError, onError callback)\n * @public\n */\nexport function loadDoctypes(dir: string, options: LoadDoctypesOptions = {}): void {\n\tconst entries = readdirSync(dir)\n\n\tfor (const entry of entries) {\n\t\tconst fullPath = join(dir, entry)\n\t\tconst stat = statSync(fullPath)\n\n\t\tif (stat.isDirectory()) {\n\t\t\tloadDoctypes(fullPath, options)\n\t\t} else if (entry.endsWith('.json')) {\n\t\t\tloadDoctypeFile(fullPath, options)\n\t\t}\n\t}\n}\n\n/**\n * Load and validate a single doctype file\n */\nfunction loadDoctypeFile(filePath: string, options: LoadDoctypesOptions): void {\n\tconst content = readFileSync(filePath, 'utf-8')\n\tlet data: unknown\n\n\ttry {\n\t\tdata = JSON.parse(content)\n\t} catch (err) {\n\t\tconst parseError: ValidationError = {\n\t\t\tpath: [],\n\t\t\tmessage: `Invalid JSON: ${err instanceof Error ? err.message : String(err)}`,\n\t\t}\n\n\t\tif (options.continueOnError) {\n\t\t\toptions.onError?.(filePath, [parseError])\n\t\t\treturn\n\t\t}\n\t\tthrow new DoctypeValidationError(filePath, [parseError])\n\t}\n\n\tconst result = validateDoctype(data)\n\n\tif (!result.success) {\n\t\tif (options.continueOnError) {\n\t\t\toptions.onError?.(filePath, result.errors)\n\t\t\treturn\n\t\t}\n\t\tthrow new DoctypeValidationError(filePath, result.errors)\n\t}\n\n\tconst doctype = parseDoctype(data)\n\tdoctypeRegistry.set(doctype.name, doctype)\n}\n\n/**\n * Load doctypes from an object (for programmatic use)\n * @param doctypes - Object mapping doctype names to doctype definitions\n * @param options - Options for loading doctypes (continueOnError, onError callback)\n * @public\n */\nexport function loadDoctypesFromObject(doctypes: Record<string, unknown>, options: LoadDoctypesOptions = {}): void {\n\tfor (const [name, data] of Object.entries(doctypes)) {\n\t\tconst withName = { ...(data as object), name }\n\t\tconst result = validateDoctype(withName)\n\n\t\tif (!result.success) {\n\t\t\tif (options.continueOnError) {\n\t\t\t\toptions.onError?.(name, result.errors)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tthrow new DoctypeValidationError(name, result.errors)\n\t\t}\n\n\t\tconst doctype = parseDoctype(withName)\n\t\tdoctypeRegistry.set(doctype.name, doctype)\n\t}\n}\n\n/**\n * Get a doctype by name\n * @param name - Name of the doctype to retrieve\n * @public\n */\nexport function getMeta(name: string): DoctypeMeta | undefined {\n\tconst direct = doctypeRegistry.get(name)\n\tif (direct) return direct\n\t// Fallback: find by slug (links reference doctypes by slug, not name)\n\tfor (const doctype of doctypeRegistry.values()) {\n\t\tif (doctype.slug === name) return doctype\n\t}\n\treturn undefined\n}\n\n/**\n * Get all loaded doctypes\n * @public\n */\nexport function getAllMeta(): DoctypeMeta[] {\n\treturn Array.from(doctypeRegistry.values())\n}\n\n/**\n * Check if a doctype is registered\n * @param name - Name of the doctype to check\n * @public\n */\nexport function hasMeta(name: string): boolean {\n\treturn doctypeRegistry.has(name)\n}\n\n/**\n * Clear all registered doctypes\n * @public\n */\nexport function clearRegistry(): void {\n\tdoctypeRegistry.clear()\n}\n\n/**\n * Validate cross-doctype references (Link fields, inherits, etc.)\n * Call after all doctypes are loaded.\n * @public\n */\nexport function validateReferences(): ValidationError[] {\n\tconst errors: ValidationError[] = []\n\n\tfor (const doctype of doctypeRegistry.values()) {\n\t\t// Check inherits reference\n\t\tif (doctype.inherits && !doctypeRegistry.has(doctype.inherits)) {\n\t\t\terrors.push({\n\t\t\t\tpath: [doctype.name, 'inherits'],\n\t\t\t\tmessage: `References unknown doctype: ${doctype.inherits}`,\n\t\t\t})\n\t\t}\n\n\t\t// Check Link field targets\n\t\tfor (const field of doctype.fields) {\n\t\t\tif (field.fieldtype === 'Link' && typeof field.options === 'string') {\n\t\t\t\tif (!doctypeRegistry.has(field.options)) {\n\t\t\t\t\terrors.push({\n\t\t\t\t\t\tpath: [doctype.name, 'fields', field.fieldname, 'options'],\n\t\t\t\t\t\tmessage: `Link references unknown doctype: ${field.options}`,\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn errors\n}\n","import type { DoctypeMeta, FieldMeta } from '@stonecrop/schema'\nimport type { ActionHandler, ActionContext } from '../types'\n\nconst handlerRegistry: Map<string, ActionHandler> = new Map()\n\n/**\n * Register an action handler\n * @param name - Unique name for the action handler\n * @param handler - Action handler function to register\n * @public\n */\nexport function registerHandler(name: string, handler: ActionHandler): void {\n\thandlerRegistry.set(name, handler)\n}\n\n/**\n * Get a registered handler by name\n * @param name - Name of the action handler to retrieve\n * @public\n */\nexport function getHandler(name: string): ActionHandler | undefined {\n\treturn handlerRegistry.get(name)\n}\n\n/**\n * Check if a handler is registered\n * @param name - Name of the action handler to check\n * @public\n */\nexport function hasHandler(name: string): boolean {\n\treturn handlerRegistry.has(name)\n}\n\n/**\n * Clear all registered handlers\n * @public\n */\nexport function clearHandlers(): void {\n\thandlerRegistry.clear()\n}\n\n// =============================================================================\n// Built-in Handlers\n// =============================================================================\n\n/**\n * Validate that all required fields are present in a record\n */\nconst validateRequiredFields: ActionHandler = async (args, context) => {\n\tconst [record] = args as [Record<string, unknown>]\n\tconst { doctype } = context\n\n\tconst missing: string[] = []\n\tfor (const field of doctype.fields) {\n\t\tif (field.required && (record[field.fieldname] === undefined || record[field.fieldname] === null)) {\n\t\t\tmissing.push(field.label ?? field.fieldname)\n\t\t}\n\t}\n\n\tif (missing.length > 0) {\n\t\tthrow new Error(`Missing required fields: ${missing.join(', ')}`)\n\t}\n\n\treturn { valid: true }\n}\n\n/**\n * Validate field types match expected types\n */\nconst validateFieldTypes: ActionHandler = async (args, context) => {\n\tconst [record] = args as [Record<string, unknown>]\n\tconst { doctype } = context\n\n\tconst errors: string[] = []\n\n\tfor (const field of doctype.fields) {\n\t\tconst value = record[field.fieldname]\n\t\tif (value === undefined || value === null) continue\n\n\t\tconst error = validateFieldValue(field, value)\n\t\tif (error) errors.push(error)\n\t}\n\n\t// Validate link fields\n\tif (doctype.links) {\n\t\tfor (const [fieldname, link] of Object.entries(doctype.links)) {\n\t\t\tconst value = record[fieldname]\n\t\t\tif (value === undefined || value === null) continue\n\n\t\t\tconst isMany = link.cardinality === 'noneOrMany' || link.cardinality === 'atLeastOne'\n\t\t\tif (isMany) {\n\t\t\t\tif (!Array.isArray(value)) {\n\t\t\t\t\terrors.push(`${fieldname}: expected array, got ${typeof value}`)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif (typeof value !== 'object' || Array.isArray(value)) {\n\t\t\t\t\terrors.push(`${fieldname}: expected object, got ${typeof value}`)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tif (errors.length > 0) {\n\t\tthrow new Error(`Field type validation failed:\\n${errors.join('\\n')}`)\n\t}\n\n\treturn { valid: true }\n}\n\n/**\n * Validate a single field value against its expected type\n */\nfunction validateFieldValue(field: FieldMeta, value: unknown): string | null {\n\tconst { fieldname, fieldtype, cardinality } = field\n\n\tswitch (fieldtype) {\n\t\tcase 'Int':\n\t\t\tif (typeof value !== 'number' || !Number.isInteger(value)) {\n\t\t\t\treturn `${fieldname}: expected integer, got ${typeof value}`\n\t\t\t}\n\t\t\tbreak\n\n\t\tcase 'Float':\n\t\tcase 'Decimal':\n\t\tcase 'Currency':\n\t\tcase 'Quantity':\n\t\t\tif (typeof value !== 'number' && typeof value !== 'string') {\n\t\t\t\treturn `${fieldname}: expected number, got ${typeof value}`\n\t\t\t}\n\t\t\tbreak\n\n\t\tcase 'Check':\n\t\t\tif (typeof value !== 'boolean') {\n\t\t\t\treturn `${fieldname}: expected boolean, got ${typeof value}`\n\t\t\t}\n\t\t\tbreak\n\n\t\tcase 'Data':\n\t\tcase 'Text':\n\t\tcase 'Code':\n\t\tcase 'Link':\n\t\t\tif (typeof value !== 'string') {\n\t\t\t\treturn `${fieldname}: expected string, got ${typeof value}`\n\t\t\t}\n\t\t\tbreak\n\n\t\tcase 'Date':\n\t\tcase 'Time':\n\t\tcase 'Datetime':\n\t\t\tif (typeof value !== 'string' && !(value instanceof Date)) {\n\t\t\t\treturn `${fieldname}: expected date string or Date, got ${typeof value}`\n\t\t\t}\n\t\t\tbreak\n\n\t\tcase 'JSON':\n\t\t\tif (typeof value !== 'object') {\n\t\t\t\treturn `${fieldname}: expected object, got ${typeof value}`\n\t\t\t}\n\t\t\tbreak\n\t}\n\n\treturn null\n}\n\n/**\n * No-op handler for testing or placeholder actions\n */\nconst noop: ActionHandler = async () => {\n\treturn { ok: true }\n}\n\n/**\n * Built-in handlers available for registration\n * @public\n */\nexport const builtinHandlers: Record<string, ActionHandler> = {\n\tvalidateRequiredFields,\n\tvalidateFieldTypes,\n\tnoop,\n}\n\n/**\n * Register all built-in handlers\n * @public\n */\nexport function registerBuiltinHandlers(): void {\n\tfor (const [name, handler] of Object.entries(builtinHandlers)) {\n\t\tregisterHandler(name, handler)\n\t}\n}\n","import type { DoctypeMeta, LinkDeclaration, LazyFetch, SyncFetch } from '@stonecrop/schema'\nimport { snakeToCamel, toPascalCase } from '@stonecrop/schema'\nimport { constant, lambda, object, loadOne } from 'postgraphile/grafast'\nimport { GraphileConfig } from 'postgraphile/graphile-build'\nimport { extendSchema, gql } from 'postgraphile/utils'\nimport pluralize from 'pluralize'\n\nimport { getHandler, registerHandler } from '../registry/actions'\nimport { getMeta, getAllMeta } from '../registry/doctypes'\nimport type {\n\tActionContext,\n\tGraphQLExecutor,\n\tReverseConnectionParams,\n\tBuildRecordQueryOptions,\n\tBuildNestedSelectionsParams,\n\tBuildListQueryArgs,\n\tMergeNestedResultsParams,\n\tExtractSingleResultParams,\n\tExtractListResultParams,\n} from '../types'\n\n/**\n * Inflection callbacks for mapping table names to GraphQL query field names.\n * Override these when using a non-Amber inflection preset (e.g., V4, SimplifyInflection).\n *\n * Defaults match the PostGraphile Amber preset conventions.\n * @public\n */\nexport interface StonecropInflectionConfig {\n\t/**\n\t * Given a table name, return the GraphQL field name for fetching a single record by ID.\n\t * @example Amber default: \"sales_orders\" → \"salesOrderById\"\n\t * @example V4 preset: \"sales_orders\" → \"salesOrderByRowId\"\n\t */\n\trecordFieldName?: (tableName: string) => string\n\n\t/**\n\t * Given a table name, return the GraphQL field name for fetching a list/connection.\n\t * @example Amber default: \"sales_orders\" → \"allSalesOrders\"\n\t * @example SimplifyInflection: \"sales_orders\" → \"salesOrders\"\n\t */\n\tconnectionFieldName?: (tableName: string) => string\n\n\t/**\n\t * Given a table name, return the GraphQL OrderBy enum type name.\n\t * @example Amber default: \"sales_orders\" → \"SalesOrdersOrderBy\"\n\t */\n\torderByTypeName?: (tableName: string) => string\n\n\t/**\n\t * Given a table name, return the GraphQL argument name used to look up a record by PK.\n\t * @example Amber default (Relay Global ID): \"sales_orders\" → \"id\"\n\t * @example row_id PK: \"sales_orders\" → \"rowId\"\n\t */\n\trecordArgName?: (tableName: string) => string\n\n\t/**\n\t * Given a table name, return the GraphQL variable type for the PK argument.\n\t * @example Default UUID PK: \"sales_orders\" → \"UUID!\"\n\t * @example Integer PK: \"sales_orders\" → \"Int!\"\n\t */\n\trecordArgType?: (tableName: string) => string\n\n\t/**\n\t * Derive the GraphQL connection field name for a reverse-FK link.\n\t * PostGraphile convention: `{targetPlural}By{FkColumnPascal}Id`\n\t * - When backlink is provided: FK column is derived from the backlink field\n\t * - When backlink is absent: FK column is derived from the parent doctype\n\t * @example Recipe → RecipeTasksByRecipeId\n\t */\n\treverseConnectionName?: (params: {\n\t\t/** Parent doctype slug */\n\t\tdoctype: string\n\t\t/** Link key on the parent */\n\t\tlinkName: string\n\t\t/** Link field on the target that points back to the parent (optional) */\n\t\tbacklink?: string\n\t\t/** Target doctype slug */\n\t\ttarget: string\n\t}) => string\n}\n\n/**\n * Options for stonecropRecord queries\n * @public\n */\nexport interface StonecropRecordOptions {\n\t/** Include nested/related records */\n\tincludeNested?: boolean | string[]\n\t/** Maximum nesting depth */\n\tmaxDepth?: number\n}\n\n/**\n * Options for creating a Stonecrop PostGraphile plugin\n * @public\n */\nexport interface StonecropPluginOptions {\n\t/** GraphQL executor for running queries/mutations */\n\texecutor: GraphQLExecutor\n\n\t/**\n\t * Override inflection conventions for mapping table names to GraphQL field names.\n\t * Defaults to PostGraphile Amber preset conventions.\n\t */\n\tinflection?: StonecropInflectionConfig\n}\n\n/**\n * Create a PostGraphile plugin that extends the GraphQL schema with Stonecrop functionality\n * @param options - Plugin configuration options\n * @returns A PostGraphile plugin\n * @public\n */\nexport const createStonecropPlugin = (options: StonecropPluginOptions): GraphileConfig.Plugin => {\n\t// Resolve inflection callbacks with Amber defaults\n\tconst recordFieldName = options.inflection?.recordFieldName ?? defaultRecordFieldName\n\tconst connectionFieldName = options.inflection?.connectionFieldName ?? defaultConnectionFieldName\n\tconst orderByTypeName = options.inflection?.orderByTypeName ?? defaultOrderByTypeName\n\tconst recordArgName = options.inflection?.recordArgName ?? defaultRecordArgName\n\tconst recordArgType = options.inflection?.recordArgType ?? defaultRecordArgType\n\tconst reverseConnectionName = options.inflection?.reverseConnectionName ?? defaultReverseConnectionName\n\n\treturn extendSchema(() => {\n\t\treturn {\n\t\t\ttypeDefs: gql`\n\t\t\t\ttype StonecropFieldMeta {\n\t\t\t\t\tfieldname: String!\n\t\t\t\t\tfieldtype: String!\n\t\t\t\t\tcomponent: String\n\t\t\t\t\tlabel: String\n\t\t\t\t\twidth: String\n\t\t\t\t\talign: String\n\t\t\t\t\trequired: Boolean\n\t\t\t\t\treadOnly: Boolean\n\t\t\t\t\tedit: Boolean\n\t\t\t\t\thidden: Boolean\n\t\t\t\t\tdefault: JSON\n\t\t\t\t\toptions: JSON\n\t\t\t\t\tmask: String\n\t\t\t\t\tprecision: Int\n\t\t\t\t\tscale: Int\n\t\t\t\t\tmode: String\n\t\t\t\t\tvalidation: JSON\n\t\t\t\t}\n\n\t\t\t\ttype StonecropWorkflowAction {\n\t\t\t\t\tlabel: String!\n\t\t\t\t\thandler: String!\n\t\t\t\t\trequiredFields: [String!]\n\t\t\t\t\tallowedStates: [String!]\n\t\t\t\t\tconfirm: Boolean\n\t\t\t\t\targs: JSON\n\t\t\t\t}\n\n\t\t\t\ttype StonecropWorkflowMeta {\n\t\t\t\t\tstates: [String!]\n\t\t\t\t\tactions: [StonecropWorkflowAction!]\n\t\t\t\t}\n\n\t\t\t\ttype StonecropDoctypeMeta {\n\t\t\t\t\tname: String!\n\t\t\t\t\tslug: String\n\t\t\t\t\ttableName: String\n\t\t\t\t\tfields: [StonecropFieldMeta!]!\n\t\t\t\t\tworkflow: StonecropWorkflowMeta\n\t\t\t\t\tinherits: String\n\t\t\t\t}\n\n\t\t\t\ttype StonecropRecordResult {\n\t\t\t\t\tdata: JSON\n\t\t\t\t\tdoctype: String!\n\t\t\t\t\tunknownLinks: [String!]\n\t\t\t\t}\n\n\t\t\t\ttype StonecropRecordsResult {\n\t\t\t\t\tdata: [JSON!]!\n\t\t\t\t\tdoctype: String!\n\t\t\t\t\tcount: Int!\n\t\t\t\t}\n\n\t\t\t\ttype StonecropActionResult {\n\t\t\t\t\tsuccess: Boolean!\n\t\t\t\t\tdata: JSON\n\t\t\t\t\terror: String\n\t\t\t\t}\n\n\t\t\t\textend type Query {\n\t\t\t\t\tstonecropMeta(doctype: String!): StonecropDoctypeMeta\n\t\t\t\t\tstonecropAllMeta: [StonecropDoctypeMeta!]!\n\t\t\t\t\tstonecropRecord(doctype: String!, id: String!, options: JSON): StonecropRecordResult\n\t\t\t\t\tstonecropRecords(\n\t\t\t\t\t\tdoctype: String!\n\t\t\t\t\t\tfilters: JSON\n\t\t\t\t\t\torderBy: String\n\t\t\t\t\t\tlimit: Int\n\t\t\t\t\t\toffset: Int\n\t\t\t\t\t): StonecropRecordsResult\n\t\t\t\t}\n\n\t\t\t\textend type Mutation {\n\t\t\t\t\tstonecropAction(doctype: String!, action: String!, args: JSON): StonecropActionResult!\n\t\t\t\t}\n\t\t\t`,\n\n\t\t\tobjects: {\n\t\t\t\tQuery: {\n\t\t\t\t\tplans: {\n\t\t\t\t\t\tstonecropMeta(_: any, { $doctype }: any) {\n\t\t\t\t\t\t\treturn lambda($doctype, (doctype: unknown) => {\n\t\t\t\t\t\t\t\tconst meta = getMeta(doctype as string)\n\t\t\t\t\t\t\t\treturn meta ?? null\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t},\n\n\t\t\t\t\t\tstonecropAllMeta() {\n\t\t\t\t\t\t\treturn constant(getAllMeta())\n\t\t\t\t\t\t},\n\n\t\t\t\t\t\tstonecropRecord(_: any, { $doctype, $id, $options }: any) {\n\t\t\t\t\t\t\treturn loadOne(\n\t\t\t\t\t\t\t\tobject({ doctype: $doctype, id: $id, options: $options }),\n\t\t\t\t\t\t\t\tasync (specs: readonly any[]) => {\n\t\t\t\t\t\t\t\t\treturn await Promise.all(\n\t\t\t\t\t\t\t\t\t\tspecs.map(async spec => {\n\t\t\t\t\t\t\t\t\t\t\tconst meta = getMeta(spec.doctype)\n\t\t\t\t\t\t\t\t\t\t\tif (!meta) {\n\t\t\t\t\t\t\t\t\t\t\t\tthrow new Error(`Unknown doctype: ${spec.doctype}`)\n\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\tif (!meta.tableName) {\n\t\t\t\t\t\t\t\t\t\t\t\tthrow new Error(`Doctype ${spec.doctype} has no table mapping`)\n\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\tconst recordOptions = spec.options ?? {}\n\n\t\t\t\t\t\t\t\t\t\t\tconst query = buildRecordQuery(\n\t\t\t\t\t\t\t\t\t\t\t\tmeta,\n\t\t\t\t\t\t\t\t\t\t\t\trecordFieldName,\n\t\t\t\t\t\t\t\t\t\t\t\trecordArgName,\n\t\t\t\t\t\t\t\t\t\t\t\trecordArgType,\n\t\t\t\t\t\t\t\t\t\t\t\tgetMeta,\n\t\t\t\t\t\t\t\t\t\t\t\trecordOptions.includeNested\n\t\t\t\t\t\t\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tincludeNested: recordOptions.includeNested,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tmaxDepth: recordOptions.maxDepth,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\t\t\t\t\t\t\t\treverseConnectionName\n\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t\tconst result = await options.executor.query(query, {\n\t\t\t\t\t\t\t\t\t\t\t\t[recordArgName(meta.tableName!)]: spec.id,\n\t\t\t\t\t\t\t\t\t\t\t})\n\n\t\t\t\t\t\t\t\t\t\t\tlet data = extractSingleResult({ result, meta, recordFieldName })\n\n\t\t\t\t\t\t\t\t\t\t\tif (recordOptions.includeNested && data && meta.links) {\n\t\t\t\t\t\t\t\t\t\t\t\tdata = mergeNestedResults({\n\t\t\t\t\t\t\t\t\t\t\t\t\trecord: data as Record<string, unknown>,\n\t\t\t\t\t\t\t\t\t\t\t\t\tmeta,\n\t\t\t\t\t\t\t\t\t\t\t\t\tgetMeta,\n\t\t\t\t\t\t\t\t\t\t\t\t\treverseConnectionNameFn: reverseConnectionName,\n\t\t\t\t\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\tconst unknownLinks =\n\t\t\t\t\t\t\t\t\t\t\t\tArray.isArray(recordOptions.includeNested) && meta.links\n\t\t\t\t\t\t\t\t\t\t\t\t\t? recordOptions.includeNested.filter((name: string) => !(name in meta.links!))\n\t\t\t\t\t\t\t\t\t\t\t\t\t: undefined\n\n\t\t\t\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t\t\t\tdata,\n\t\t\t\t\t\t\t\t\t\t\t\tdoctype: spec.doctype,\n\t\t\t\t\t\t\t\t\t\t\t\t...(unknownLinks ? { unknownLinks } : {}),\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t},\n\n\t\t\t\t\t\tstonecropRecords(_: any, { $doctype, $filters, $orderBy, $limit, $offset }: any) {\n\t\t\t\t\t\t\treturn loadOne(\n\t\t\t\t\t\t\t\tobject({\n\t\t\t\t\t\t\t\t\tdoctype: $doctype,\n\t\t\t\t\t\t\t\t\tfilters: $filters,\n\t\t\t\t\t\t\t\t\torderBy: $orderBy,\n\t\t\t\t\t\t\t\t\tlimit: $limit,\n\t\t\t\t\t\t\t\t\toffset: $offset,\n\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\tasync (specs: readonly any[]) => {\n\t\t\t\t\t\t\t\t\treturn await Promise.all(\n\t\t\t\t\t\t\t\t\t\tspecs.map(async spec => {\n\t\t\t\t\t\t\t\t\t\t\tconst meta = getMeta(spec.doctype)\n\t\t\t\t\t\t\t\t\t\t\tif (!meta) {\n\t\t\t\t\t\t\t\t\t\t\t\tthrow new Error(`Unknown doctype: ${spec.doctype}`)\n\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\tif (!meta.tableName) {\n\t\t\t\t\t\t\t\t\t\t\t\tthrow new Error(`Doctype ${spec.doctype} has no table mapping`)\n\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\tconst query = buildListQuery(\n\t\t\t\t\t\t\t\t\t\t\t\tmeta,\n\t\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t\tlimit: spec.limit,\n\t\t\t\t\t\t\t\t\t\t\t\t\toffset: spec.offset,\n\t\t\t\t\t\t\t\t\t\t\t\t\torderBy: spec.orderBy,\n\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\tconnectionFieldName,\n\t\t\t\t\t\t\t\t\t\t\t\torderByTypeName\n\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t\tconst result = await options.executor.query(query, {\n\t\t\t\t\t\t\t\t\t\t\t\tlimit: spec.limit,\n\t\t\t\t\t\t\t\t\t\t\t\toffset: spec.offset,\n\t\t\t\t\t\t\t\t\t\t\t\torderBy: spec.orderBy,\n\t\t\t\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\t\t\t\tconst data = extractListResult({ result, meta, connectionFieldName })\n\n\t\t\t\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t\t\t\tdata,\n\t\t\t\t\t\t\t\t\t\t\t\tdoctype: spec.doctype,\n\t\t\t\t\t\t\t\t\t\t\t\tcount: data.length,\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\n\t\t\t\tMutation: {\n\t\t\t\t\tplans: {\n\t\t\t\t\t\tstonecropAction(_: any, { $doctype, $action, $args: $actionArgs }: any) {\n\t\t\t\t\t\t\treturn loadOne(\n\t\t\t\t\t\t\t\tobject({\n\t\t\t\t\t\t\t\t\tdoctype: $doctype,\n\t\t\t\t\t\t\t\t\taction: $action,\n\t\t\t\t\t\t\t\t\tactionArgs: $actionArgs,\n\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\tasync (specs: readonly any[]) => {\n\t\t\t\t\t\t\t\t\treturn await Promise.all(\n\t\t\t\t\t\t\t\t\t\tspecs.map(async spec => {\n\t\t\t\t\t\t\t\t\t\t\tconst meta = getMeta(spec.doctype)\n\t\t\t\t\t\t\t\t\t\t\tif (!meta) {\n\t\t\t\t\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t\t\t\t\tsuccess: false,\n\t\t\t\t\t\t\t\t\t\t\t\t\tdata: null,\n\t\t\t\t\t\t\t\t\t\t\t\t\terror: `Unknown doctype: ${spec.doctype}`,\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\tconst actionDef = meta.workflow?.actions?.[spec.action]\n\t\t\t\t\t\t\t\t\t\t\tif (!actionDef) {\n\t\t\t\t\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t\t\t\t\tsuccess: false,\n\t\t\t\t\t\t\t\t\t\t\t\t\tdata: null,\n\t\t\t\t\t\t\t\t\t\t\t\t\terror: `Unknown action: ${spec.action} on ${spec.doctype}`,\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\tconst handlerName = actionDef.handler\n\t\t\t\t\t\t\t\t\t\t\tconst handler = getHandler(handlerName)\n\t\t\t\t\t\t\t\t\t\t\tif (!handler) {\n\t\t\t\t\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t\t\t\t\tsuccess: false,\n\t\t\t\t\t\t\t\t\t\t\t\t\tdata: null,\n\t\t\t\t\t\t\t\t\t\t\t\t\terror: `Handler not registered: ${handlerName}`,\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\tconst actionContext: ActionContext = {\n\t\t\t\t\t\t\t\t\t\t\t\tdoctype: meta,\n\t\t\t\t\t\t\t\t\t\t\t\texecutor: options.executor,\n\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\t\t\t\tconst result = await handler(spec.actionArgs ?? [], actionContext)\n\t\t\t\t\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t\t\t\t\tsuccess: true,\n\t\t\t\t\t\t\t\t\t\t\t\t\tdata: result,\n\t\t\t\t\t\t\t\t\t\t\t\t\terror: null,\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t} catch (err) {\n\t\t\t\t\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t\t\t\t\tsuccess: false,\n\t\t\t\t\t\t\t\t\t\t\t\t\tdata: null,\n\t\t\t\t\t\t\t\t\t\t\t\t\terror: err instanceof Error ? err.message : String(err),\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t}\n\t})\n}\n\n// =============================================================================\n// Inflection helpers — default to PostGraphile Amber preset conventions\n// Uses `pluralize` for proper English singularization (handles irregular\n// plurals like statuses→status, categories→category, addresses→address).\n// snakeToCamel / toPascalCase are imported from @stonecrop/schema.\n// =============================================================================\n\n/**\n * Amber default: sales_orders → salesOrderById\n * Uses `pluralize` for proper singularization of irregular plurals.\n * Override via `StonecropInflectionConfig.recordFieldName` for non-standard PK columns.\n * @public\n */\nfunction defaultRecordFieldName(tableName: string): string {\n\tconst singular = pluralize.singular(tableName)\n\treturn `${snakeToCamel(singular)}ById`\n}\n\n/**\n * Amber default: sales_orders → allSalesOrders\n * @public\n */\nfunction defaultConnectionFieldName(tableName: string): string {\n\treturn `all${toPascalCase(tableName)}`\n}\n\n/**\n * Amber default: sales_orders → SalesOrdersOrderBy\n * @public\n */\nfunction defaultOrderByTypeName(tableName: string): string {\n\treturn `${toPascalCase(tableName)}OrderBy`\n}\n\n/**\n * Default PK argument name: 'id' (standard Relay Global ID pattern).\n * Override via `StonecropInflectionConfig.recordArgName` when using row_id columns;\n * PostGraphile Amber generates `rowId: UUID!` for those fields.\n * @public\n */\nfunction defaultRecordArgName(_tableName: string): string {\n\treturn 'id'\n}\n\n/**\n * Default PK argument type: 'UUID!' (PostGraphile Amber default for UUID PKs).\n * Override via `StonecropInflectionConfig.recordArgType` when using non-UUID PKs\n * such as integer serials or Relay Global IDs ('ID!').\n * @public\n */\nfunction defaultRecordArgType(_tableName: string): string {\n\treturn 'UUID!'\n}\n\n/**\n * Default reverse connection name: derives PostGraphile's connection field convention.\n * PostGraphile convention: `{targetPlural}By{FkColumnPascal}Id`\n * - When backlink is defined: FK column is derived from the backlink field name\n * - When backlink is absent: FK column is derived from the parent doctype's table name\n * @public\n */\nfunction defaultReverseConnectionName(params: {\n\tdoctype: string\n\tlinkName: string\n\tbacklink?: string\n\ttarget: string\n}): string {\n\tconst targetPlural = pluralize.plural(params.target.replace(/-/g, '_'))\n\t// Use camelCase for target (matches PostGraphile Amber convention: recipeTasksByRecipeId)\n\tconst targetCamel = snakeToCamel(targetPlural)\n\t// Use backlink if provided, otherwise derive from parent table name\n\tconst fkSource = params.backlink || params.doctype\n\t// FK column name: uppercase first char, preserve rest of camelCase\n\tconst fkPascal = fkSource.charAt(0).toUpperCase() + snakeToCamel(fkSource).slice(1)\n\treturn `${targetCamel}By${fkPascal}Id`\n}\n\n/**\n * Check if a cardinality represents a \"many\" relationship\n */\nfunction isManyCardinality(cardinality: string): boolean {\n\treturn cardinality === 'noneOrMany' || cardinality === 'atLeastOne'\n}\n\n// =============================================================================\n// Query builders — generate GraphQL queries to send to the underlying schema\n// =============================================================================\n\nconst DEFAULT_SYNC_LIMIT = 50\n\n/**\n * Fieldtypes that map to GraphQL object/connection types and require sub-selections.\n * These fields are excluded from generated query field selections.\n * @public\n */\nconst RELATION_FIELDTYPES = new Set(['Link'])\n\n/**\n * Filter fields to only those directly queryable as scalars, excluding Link and Doctype\n * relation fields that require GraphQL sub-selections.\n * @public\n */\nfunction queryableFieldNames(meta: DoctypeMeta): string {\n\treturn meta.fields\n\t\t.filter(f => !RELATION_FIELDTYPES.has(f.fieldtype))\n\t\t.map(f => f.fieldname)\n\t\t.join('\\n ')\n}\n\n/**\n * Get the effective fetch strategy for a link, applying cardinality-based defaults.\n */\nfunction getEffectiveFetchStrategy(link: LinkDeclaration): SyncFetch | LazyFetch {\n\tif (link.fetch !== undefined) {\n\t\treturn link.fetch as SyncFetch | LazyFetch\n\t}\n\n\tif (isManyCardinality(link.cardinality)) {\n\t\treturn { method: 'sync', limit: DEFAULT_SYNC_LIMIT }\n\t} else {\n\t\treturn { method: 'lazy' }\n\t}\n}\n\n/**\n * Get the effective blockWorkflows value for a link.\n */\nfunction getEffectiveBlockWorkflows(link: LinkDeclaration): boolean {\n\tif (link.blockWorkflows !== undefined) {\n\t\treturn link.blockWorkflows\n\t}\n\tconst effectiveFetch = getEffectiveFetchStrategy(link)\n\treturn effectiveFetch.method === 'sync'\n}\n\n/**\n * Build nested sub-selections for descendant links\n */\nfunction buildNestedSelections(params: BuildNestedSelectionsParams): string {\n\tconst { links, meta, includeSet, getMeta, seen, depth, maxDepth, reverseConnectionNameFn } = params\n\n\tif (maxDepth !== undefined && depth >= maxDepth) return ''\n\n\tconst selections: string[] = []\n\n\tfor (const [fieldname, link] of Object.entries(links)) {\n\t\tif (maxDepth !== undefined && depth >= maxDepth) break\n\n\t\tconst effectiveBlockWorkflows = getEffectiveBlockWorkflows(link)\n\t\tconst linkBlockWorkflowsExplicitTrue = link.blockWorkflows === true\n\n\t\tif (includeSet && !includeSet.has(fieldname) && !linkBlockWorkflowsExplicitTrue) {\n\t\t\tcontinue\n\t\t}\n\n\t\tconst effectiveFetch = getEffectiveFetchStrategy(link)\n\t\tconst shouldSkip =\n\t\t\teffectiveBlockWorkflows === false || (effectiveFetch.method !== 'sync' && !linkBlockWorkflowsExplicitTrue)\n\t\tif (shouldSkip) {\n\t\t\tcontinue\n\t\t}\n\n\t\tconst targetMeta = getMeta(link.target)\n\t\tif (!targetMeta) continue\n\n\t\tconst alreadySeen = seen.has(link.target)\n\t\tif (alreadySeen) {\n\t\t} else {\n\t\t\tseen.add(link.target)\n\t\t}\n\t\tconst scalarFields = queryableFieldNames(targetMeta)\n\n\t\tlet nestedLinks = ''\n\t\tif (!alreadySeen && targetMeta.links && targetMeta.tableName && (maxDepth === undefined || depth + 1 < maxDepth)) {\n\t\t\tconst innerSelections = buildNestedSelections({\n\t\t\t\tlinks: targetMeta.links,\n\t\t\t\tmeta: targetMeta,\n\t\t\t\tincludeSet: null,\n\t\t\t\tgetMeta,\n\t\t\t\tseen,\n\t\t\t\tdepth: depth + 1,\n\t\t\t\tmaxDepth,\n\t\t\t\treverseConnectionNameFn,\n\t\t\t})\n\t\t\tif (innerSelections) {\n\t\t\t\tnestedLinks = '\\n ' + innerSelections\n\t\t\t}\n\t\t\tseen.delete(link.target)\n\t\t}\n\n\t\tconst fullSelection = scalarFields + nestedLinks\n\n\t\tif (isManyCardinality(link.cardinality)) {\n\t\t\tconst reverseParams: ReverseConnectionParams = {\n\t\t\t\tdoctype: meta.slug || meta.name,\n\t\t\t\tlinkName: fieldname,\n\t\t\t\tbacklink: link.backlink,\n\t\t\t\ttarget: link.target,\n\t\t\t}\n\t\t\tconst connectionField = reverseConnectionNameFn\n\t\t\t\t? reverseConnectionNameFn(reverseParams)\n\t\t\t\t: defaultReverseConnectionName(reverseParams)\n\t\t\tconst limitArg =\n\t\t\t\teffectiveFetch.method === 'sync' && effectiveFetch.limit !== undefined\n\t\t\t\t\t? `first: ${effectiveFetch.limit}`\n\t\t\t\t\t: effectiveFetch.method === 'sync'\n\t\t\t\t\t\t? `first: ${DEFAULT_SYNC_LIMIT}`\n\t\t\t\t\t\t: ''\n\t\t\tselections.push(`\n\t\t\t${connectionField}${limitArg ? `(${limitArg})` : ''} {\n\t\t\t\tnodes {\n\t\t\t\t\t${fullSelection}\n\t\t\t\t}\n\t\t\t}`)\n\t\t} else {\n\t\t\tselections.push(`\n\t\t\t${fieldname} {\n\t\t\t\t${fullSelection}\n\t\t\t}`)\n\t\t}\n\t}\n\n\treturn selections.join('')\n}\n\n/**\n * Build a GraphQL query to fetch a single record by ID.\n * When includeNested is set, recursively includes descendant link sub-selections.\n * @public\n */\nfunction buildRecordQuery(\n\tmeta: DoctypeMeta,\n\trecordFieldName: (t: string) => string,\n\trecordArgName: (t: string) => string,\n\trecordArgType: (t: string) => string,\n\tgetMeta: (slug: string) => DoctypeMeta | undefined,\n\toptions?: BuildRecordQueryOptions,\n\treverseConnectionNameFn?: (params: ReverseConnectionParams) => string\n): string {\n\tconst queryName = recordFieldName(meta.tableName!)\n\tconst argName = recordArgName(meta.tableName!)\n\tconst argType = recordArgType(meta.tableName!)\n\n\tconst seen = new Set<string>([meta.slug || meta.name])\n\n\tlet selection = queryableFieldNames(meta)\n\n\tif (options?.includeNested && meta.links) {\n\t\tconst includeSet = Array.isArray(options.includeNested) ? new Set(options.includeNested) : null\n\n\t\tconst nestedSelections = buildNestedSelections({\n\t\t\tlinks: meta.links,\n\t\t\tmeta,\n\t\t\tincludeSet,\n\t\t\tgetMeta,\n\t\t\tseen,\n\t\t\tdepth: 0,\n\t\t\tmaxDepth: options.maxDepth,\n\t\t\treverseConnectionNameFn,\n\t\t})\n\n\t\tif (nestedSelections) {\n\t\t\tselection += '\\n ' + nestedSelections\n\t\t}\n\t}\n\n\treturn `\n\t\tquery GetRecord($${argName}: ${argType}) {\n\t\t\t${queryName}(${argName}: $${argName}) {\n\t\t\t\t${selection}\n\t\t\t}\n\t\t}\n\t`\n}\n\n/**\n * Build a GraphQL connection query to fetch a list of records.\n * Only declares variables ($limit, $offset, $orderBy) that are actually used in the query,\n * avoiding GraphQL spec §5.8.3 violations from unused variable declarations.\n * Excludes Link and Doctype relation fields from the selection set.\n * @public\n */\nfunction buildListQuery(\n\tmeta: DoctypeMeta,\n\targs: BuildListQueryArgs,\n\tconnectionFieldName: (t: string) => string,\n\torderByTypeName: (t: string) => string\n): string {\n\tconst fieldNames = queryableFieldNames(meta)\n\tconst connectionName = connectionFieldName(meta.tableName!)\n\tconst orderByType = orderByTypeName(meta.tableName!)\n\n\tconst varDecls: string[] = []\n\tconst queryArgs: string[] = []\n\tif (args.limit) {\n\t\tvarDecls.push('$limit: Int')\n\t\tqueryArgs.push(`first: $limit`)\n\t}\n\tif (args.offset) {\n\t\tvarDecls.push('$offset: Int')\n\t\tqueryArgs.push(`offset: $offset`)\n\t}\n\tif (args.orderBy) {\n\t\tvarDecls.push(`$orderBy: [${orderByType}!]`)\n\t\tqueryArgs.push(`orderBy: $orderBy`)\n\t}\n\n\tconst varStr = varDecls.length > 0 ? `(${varDecls.join(', ')})` : ''\n\tconst argsStr = queryArgs.length > 0 ? `(${queryArgs.join(', ')})` : ''\n\n\treturn `\n\t\tquery GetRecords${varStr} {\n\t\t\t${connectionName}${argsStr} {\n\t\t\t\tnodes {\n\t\t\t\t${fieldNames}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t`\n}\n\n/**\n * Merge nested connection results into flat arrays.\n * For `noneOrMany`/`atLeastOne` links, the query returns `{ nodes: [...] }`.\n * This flattens them to just `[]` for easier consumption.\n * @public\n */\nfunction mergeNestedResults(params: MergeNestedResultsParams): Record<string, unknown> {\n\tconst { record, meta, getMeta, reverseConnectionNameFn } = params\n\tif (!meta.links) return record\n\n\tconst merged = { ...record }\n\n\tfor (const [fieldname, link] of Object.entries(meta.links)) {\n\t\tconst isMany = isManyCardinality(link.cardinality)\n\n\t\tif (isMany) {\n\t\t\tconst targetMeta = getMeta(link.target)\n\t\t\tif (!targetMeta) continue\n\n\t\t\tconst reverseParams: ReverseConnectionParams = {\n\t\t\t\tdoctype: meta.slug || meta.name,\n\t\t\t\tlinkName: fieldname,\n\t\t\t\tbacklink: link.backlink || fieldname,\n\t\t\t\ttarget: link.target,\n\t\t\t}\n\t\t\tconst connectionField = reverseConnectionNameFn\n\t\t\t\t? reverseConnectionNameFn(reverseParams)\n\t\t\t\t: defaultReverseConnectionName(reverseParams)\n\t\t\tconst connectionResult = merged[connectionField] as { nodes?: unknown[] } | undefined\n\t\t\tif (connectionResult?.nodes) {\n\t\t\t\tmerged[fieldname] = connectionResult.nodes\n\t\t\t\tdelete merged[connectionField]\n\t\t\t} else {\n\t\t\t\tmerged[fieldname] = []\n\t\t\t\tdelete merged[connectionField]\n\t\t\t}\n\t\t}\n\t}\n\n\treturn merged\n}\n\n/**\n * Extract a single record from a PostGraphile query result using the record field name.\n * @public\n */\nfunction extractSingleResult(params: ExtractSingleResultParams): unknown {\n\tconst { result, meta, recordFieldName } = params\n\tconst queryName = recordFieldName(meta.tableName!)\n\treturn (result as Record<string, unknown>)[queryName]\n}\n\n/**\n * Extract the list of nodes from a PostGraphile connection query result.\n * Returns an empty array if the connection field is absent.\n * @public\n */\nfunction extractListResult(params: ExtractListResultParams): unknown[] {\n\tconst { result, meta, connectionFieldName } = params\n\tconst connectionName = connectionFieldName(meta.tableName!)\n\tconst connection = (result as Record<string, unknown>)[connectionName] as {\n\t\tnodes: unknown[]\n\t}\n\treturn connection?.nodes ?? []\n}\n\n// =============================================================================\n// Exported for testing and advanced usage\n// =============================================================================\n\nexport {\n\tdefaultRecordFieldName,\n\tdefaultConnectionFieldName,\n\tdefaultOrderByTypeName,\n\tdefaultRecordArgName,\n\tdefaultRecordArgType,\n\tdefaultReverseConnectionName,\n\tbuildRecordQuery,\n\tbuildListQuery,\n\tqueryableFieldNames,\n\tRELATION_FIELDTYPES,\n\textractSingleResult,\n\textractListResult,\n\tmergeNestedResults,\n}\n","import { gql } from 'postgraphile/utils'\n\n/**\n * GraphQL type definitions for Stonecrop's middleware API.\n * Includes stonecropMeta, stonecropRecord, stonecropRecords, stonecropAction, and related types.\n * @public\n */\nexport const typeDefs = gql`\n\ttype StonecropFieldMeta {\n\t\tfieldname: String!\n\t\tfieldtype: String!\n\t\tcomponent: String\n\t\tlabel: String\n\t\twidth: String\n\t\talign: String\n\t\trequired: Boolean\n\t\treadOnly: Boolean\n\t\tedit: Boolean\n\t\thidden: Boolean\n\t\tdefault: JSON\n\t\toptions: JSON\n\t\tmask: String\n\t\tprecision: Int\n\t\tscale: Int\n\t\tmode: String\n\t\tvalidation: JSON\n\t}\n\n\ttype StonecropWorkflowAction {\n\t\tlabel: String!\n\t\thandler: String!\n\t\trequiredFields: [String!]\n\t\tallowedStates: [String!]\n\t\tconfirm: Boolean\n\t\targs: JSON\n\t}\n\n\ttype StonecropWorkflowMeta {\n\t\tstates: [String!]\n\t\tactions: [StonecropWorkflowAction!]\n\t}\n\n\ttype StonecropDoctypeMeta {\n\t\tname: String!\n\t\tslug: String\n\t\ttableName: String\n\t\tfields: [StonecropFieldMeta!]!\n\t\tworkflow: StonecropWorkflowMeta\n\t\tinherits: String\n\t}\n\n\ttype StonecropRecordResult {\n\t\tdata: JSON\n\t\tdoctype: String!\n\t\tunknownLinks: [String!]\n\t}\n\n\ttype StonecropRecordsResult {\n\t\tdata: [JSON!]!\n\t\tdoctype: String!\n\t\tcount: Int!\n\t}\n\n\ttype StonecropActionResult {\n\t\tsuccess: Boolean!\n\t\tdata: JSON\n\t\terror: String\n\t}\n\n\textend type Query {\n\t\tstonecropMeta(doctype: String!): StonecropDoctypeMeta\n\t\tstonecropAllMeta: [StonecropDoctypeMeta!]!\n\t\tstonecropRecord(doctype: String!, id: String!, options: JSON): StonecropRecordResult\n\t\tstonecropRecords(doctype: String!, filters: JSON, orderBy: String, limit: Int, offset: Int): StonecropRecordsResult\n\t}\n\n\textend type Mutation {\n\t\tstonecropAction(doctype: String!, action: String!, args: JSON): StonecropActionResult!\n\t}\n`\n"],"names":["doctypeRegistry","DoctypeValidationError","file","errors","errorMessages","e","loadDoctypes","dir","options","entries","readdirSync","entry","fullPath","join","statSync","loadDoctypeFile","filePath","content","readFileSync","data","err","parseError","result","validateDoctype","doctype","parseDoctype","loadDoctypesFromObject","doctypes","name","withName","getMeta","direct","getAllMeta","hasMeta","clearRegistry","validateReferences","field","handlerRegistry","registerHandler","handler","getHandler","hasHandler","clearHandlers","validateRequiredFields","args","context","record","missing","validateFieldTypes","value","error","validateFieldValue","fieldname","link","fieldtype","cardinality","noop","builtinHandlers","registerBuiltinHandlers","createStonecropPlugin","recordFieldName","defaultRecordFieldName","connectionFieldName","defaultConnectionFieldName","orderByTypeName","defaultOrderByTypeName","recordArgName","defaultRecordArgName","recordArgType","defaultRecordArgType","reverseConnectionName","defaultReverseConnectionName","extendSchema","gql","_","$doctype","lambda","constant","$id","$options","loadOne","object","specs","spec","meta","recordOptions","query","buildRecordQuery","extractSingleResult","mergeNestedResults","unknownLinks","$filters","$orderBy","$limit","$offset","buildListQuery","extractListResult","$action","$actionArgs","actionDef","handlerName","actionContext","tableName","singular","pluralize","snakeToCamel","toPascalCase","_tableName","params","targetPlural","targetCamel","fkSource","fkPascal","isManyCardinality","DEFAULT_SYNC_LIMIT","RELATION_FIELDTYPES","queryableFieldNames","f","getEffectiveFetchStrategy","getEffectiveBlockWorkflows","buildNestedSelections","links","includeSet","seen","depth","maxDepth","reverseConnectionNameFn","selections","effectiveBlockWorkflows","linkBlockWorkflowsExplicitTrue","effectiveFetch","targetMeta","alreadySeen","scalarFields","nestedLinks","innerSelections","fullSelection","reverseParams","connectionField","limitArg","queryName","argName","argType","selection","nestedSelections","fieldNames","connectionName","orderByType","varDecls","queryArgs","varStr","argsStr","merged","connectionResult","typeDefs"],"mappings":";;;;;;AAMA,MAAMA,wBAAgD,IAAA;AAM/C,MAAMC,UAA+B,MAAM;AAAA,EACjD,YAEiBC,GAEAC,GACf;AACD,UAAMC,IAAgBD,EAAO,IAAI,CAAAE,MAAK,KAAKA,EAAE,KAAK,KAAK,GAAG,CAAC,KAAKA,EAAE,OAAO,EAAE,EAAE,KAAK;AAAA,CAAI;AACtF,UAAM,iCAAiCH,CAAI;AAAA,EAAME,CAAa,EAAE,GALhD,KAAA,OAAAF,GAEA,KAAA,SAAAC,GAIhB,KAAK,OAAO;AAAA,EACb;AAAA,EAPiB;AAAA,EAEA;AAMlB;AAmBO,SAASG,EAAaC,GAAaC,IAA+B,IAAU;AAClF,QAAMC,IAAUC,EAAYH,CAAG;AAE/B,aAAW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AA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;"}
1
+ {"version":3,"file":"index.js","sources":["../src/registry/doctypes.ts","../src/registry/actions.ts","../src/plugin/postgraphile.ts","../src/typeDefs.ts"],"sourcesContent":["import { readFileSync, readdirSync, statSync } from 'node:fs'\nimport { join } from 'node:path'\n\nimport { parseDoctype, validateDoctype } from '@stonecrop/schema'\nimport type { DoctypeMeta, ValidationError } from '@stonecrop/schema'\n\nconst doctypeRegistry: Map<string, DoctypeMeta> = new Map()\n\n/**\n * Error thrown when a doctype definition fails validation\n * @public\n */\nexport class DoctypeValidationError extends Error {\n\tconstructor(\n\t\t/** File path or name where the validation error occurred */\n\t\tpublic readonly file: string,\n\t\t/** List of validation errors found */\n\t\tpublic readonly errors: ValidationError[]\n\t) {\n\t\tconst errorMessages = errors.map(e => ` ${e.path.join('.')}: ${e.message}`).join('\\n')\n\t\tsuper(`Invalid doctype definition in ${file}:\\n${errorMessages}`)\n\t\tthis.name = 'DoctypeValidationError'\n\t}\n}\n\n/**\n * Options for loading doctype definitions\n * @public\n */\nexport interface LoadDoctypesOptions {\n\t/** Continue loading other files if one fails validation */\n\tcontinueOnError?: boolean\n\t/** Callback for validation errors when continueOnError is true */\n\tonError?: (file: string, errors: ValidationError[]) => void\n}\n\n/**\n * Load doctype definitions from a directory of JSON files\n * @param dir - Directory path containing doctype JSON files\n * @param options - Options for loading doctypes (continueOnError, onError callback)\n * @public\n */\nexport function loadDoctypes(dir: string, options: LoadDoctypesOptions = {}): void {\n\tconst entries = readdirSync(dir)\n\n\tfor (const entry of entries) {\n\t\tconst fullPath = join(dir, entry)\n\t\tconst stat = statSync(fullPath)\n\n\t\tif (stat.isDirectory()) {\n\t\t\tloadDoctypes(fullPath, options)\n\t\t} else if (entry.endsWith('.json')) {\n\t\t\tloadDoctypeFile(fullPath, options)\n\t\t}\n\t}\n}\n\n/**\n * Load and validate a single doctype file\n */\nfunction loadDoctypeFile(filePath: string, options: LoadDoctypesOptions): void {\n\tconst content = readFileSync(filePath, 'utf-8')\n\tlet data: unknown\n\n\ttry {\n\t\tdata = JSON.parse(content)\n\t} catch (err) {\n\t\tconst parseError: ValidationError = {\n\t\t\tpath: [],\n\t\t\tmessage: `Invalid JSON: ${err instanceof Error ? err.message : String(err)}`,\n\t\t}\n\n\t\tif (options.continueOnError) {\n\t\t\toptions.onError?.(filePath, [parseError])\n\t\t\treturn\n\t\t}\n\t\tthrow new DoctypeValidationError(filePath, [parseError])\n\t}\n\n\tconst result = validateDoctype(data)\n\n\tif (!result.success) {\n\t\tif (options.continueOnError) {\n\t\t\toptions.onError?.(filePath, result.errors)\n\t\t\treturn\n\t\t}\n\t\tthrow new DoctypeValidationError(filePath, result.errors)\n\t}\n\n\tconst doctype = parseDoctype(data)\n\tdoctypeRegistry.set(doctype.name, doctype)\n}\n\n/**\n * Load doctypes from an object (for programmatic use)\n * @param doctypes - Object mapping doctype names to doctype definitions\n * @param options - Options for loading doctypes (continueOnError, onError callback)\n * @public\n */\nexport function loadDoctypesFromObject(doctypes: Record<string, unknown>, options: LoadDoctypesOptions = {}): void {\n\tfor (const [name, data] of Object.entries(doctypes)) {\n\t\tconst withName = { ...(data as object), name }\n\t\tconst result = validateDoctype(withName)\n\n\t\tif (!result.success) {\n\t\t\tif (options.continueOnError) {\n\t\t\t\toptions.onError?.(name, result.errors)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tthrow new DoctypeValidationError(name, result.errors)\n\t\t}\n\n\t\tconst doctype = parseDoctype(withName)\n\t\tdoctypeRegistry.set(doctype.name, doctype)\n\t}\n}\n\n/**\n * Get a doctype by name\n * @param name - Name of the doctype to retrieve\n * @public\n */\nexport function getMeta(name: string): DoctypeMeta | undefined {\n\tconst direct = doctypeRegistry.get(name)\n\tif (direct) return direct\n\t// Fallback: find by slug (links reference doctypes by slug, not name)\n\tfor (const doctype of doctypeRegistry.values()) {\n\t\tif (doctype.slug === name) return doctype\n\t}\n\treturn undefined\n}\n\n/**\n * Get all loaded doctypes\n * @public\n */\nexport function getAllMeta(): DoctypeMeta[] {\n\treturn Array.from(doctypeRegistry.values())\n}\n\n/**\n * Check if a doctype is registered\n * @param name - Name of the doctype to check\n * @public\n */\nexport function hasMeta(name: string): boolean {\n\treturn doctypeRegistry.has(name)\n}\n\n/**\n * Clear all registered doctypes\n * @public\n */\nexport function clearRegistry(): void {\n\tdoctypeRegistry.clear()\n}\n\n/**\n * Validate cross-doctype references (Link fields, inherits, etc.)\n * Call after all doctypes are loaded.\n * @public\n */\nexport function validateReferences(): ValidationError[] {\n\tconst errors: ValidationError[] = []\n\n\tfor (const doctype of doctypeRegistry.values()) {\n\t\t// Check inherits reference\n\t\tif (doctype.inherits && !doctypeRegistry.has(doctype.inherits)) {\n\t\t\terrors.push({\n\t\t\t\tpath: [doctype.name, 'inherits'],\n\t\t\t\tmessage: `References unknown doctype: ${doctype.inherits}`,\n\t\t\t})\n\t\t}\n\n\t\t// Check Link field targets\n\t\tfor (const field of doctype.fields) {\n\t\t\tif (field.fieldtype === 'Link' && typeof field.options === 'string') {\n\t\t\t\tif (!doctypeRegistry.has(field.options)) {\n\t\t\t\t\terrors.push({\n\t\t\t\t\t\tpath: [doctype.name, 'fields', field.fieldname, 'options'],\n\t\t\t\t\t\tmessage: `Link references unknown doctype: ${field.options}`,\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn errors\n}\n","import type { FieldMeta } from '@stonecrop/schema'\nimport type { ActionHandler } from '../types'\n\nconst handlerRegistry: Map<string, ActionHandler> = new Map()\n\n/**\n * Register an action handler\n * @param name - Unique name for the action handler\n * @param handler - Action handler function to register\n * @public\n */\nexport function registerHandler(name: string, handler: ActionHandler): void {\n\thandlerRegistry.set(name, handler)\n}\n\n/**\n * Get a registered handler by name\n * @param name - Name of the action handler to retrieve\n * @public\n */\nexport function getHandler(name: string): ActionHandler | undefined {\n\treturn handlerRegistry.get(name)\n}\n\n/**\n * Check if a handler is registered\n * @param name - Name of the action handler to check\n * @public\n */\nexport function hasHandler(name: string): boolean {\n\treturn handlerRegistry.has(name)\n}\n\n/**\n * Clear all registered handlers\n * @public\n */\nexport function clearHandlers(): void {\n\thandlerRegistry.clear()\n}\n\n// =============================================================================\n// Built-in Handlers\n// =============================================================================\n\n/**\n * Validate that all required fields are present in a record\n */\nconst validateRequiredFields: ActionHandler = async (args, context) => {\n\tconst [record] = args as [Record<string, unknown>]\n\tconst { doctype } = context\n\n\tconst missing: string[] = []\n\tfor (const field of doctype.fields) {\n\t\tif (field.required && (record[field.fieldname] === undefined || record[field.fieldname] === null)) {\n\t\t\tmissing.push(field.label ?? field.fieldname)\n\t\t}\n\t}\n\n\tif (missing.length > 0) {\n\t\tthrow new Error(`Missing required fields: ${missing.join(', ')}`)\n\t}\n\n\treturn { valid: true }\n}\n\n/**\n * Validate field types match expected types\n */\nconst validateFieldTypes: ActionHandler = async (args, context) => {\n\tconst [record] = args as [Record<string, unknown>]\n\tconst { doctype } = context\n\n\tconst errors: string[] = []\n\n\tfor (const field of doctype.fields) {\n\t\tconst value = record[field.fieldname]\n\t\tif (value === undefined || value === null) continue\n\n\t\tconst error = validateFieldValue(field, value)\n\t\tif (error) errors.push(error)\n\t}\n\n\t// Validate link fields\n\tif (doctype.links) {\n\t\tfor (const [fieldname, link] of Object.entries(doctype.links)) {\n\t\t\tconst value = record[fieldname]\n\t\t\tif (value === undefined || value === null) continue\n\n\t\t\tconst isMany = link.cardinality === 'noneOrMany' || link.cardinality === 'atLeastOne'\n\t\t\tif (isMany) {\n\t\t\t\tif (!Array.isArray(value)) {\n\t\t\t\t\terrors.push(`${fieldname}: expected array, got ${typeof value}`)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif (typeof value !== 'object' || Array.isArray(value)) {\n\t\t\t\t\terrors.push(`${fieldname}: expected object, got ${typeof value}`)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tif (errors.length > 0) {\n\t\tthrow new Error(`Field type validation failed:\\n${errors.join('\\n')}`)\n\t}\n\n\treturn { valid: true }\n}\n\n/**\n * Validate a single field value against its expected type\n */\nfunction validateFieldValue(field: FieldMeta, value: unknown): string | null {\n\tconst { fieldname, fieldtype } = field\n\n\tswitch (fieldtype) {\n\t\tcase 'Int':\n\t\t\tif (typeof value !== 'number' || !Number.isInteger(value)) {\n\t\t\t\treturn `${fieldname}: expected integer, got ${typeof value}`\n\t\t\t}\n\t\t\tbreak\n\n\t\tcase 'Float':\n\t\tcase 'Decimal':\n\t\tcase 'Currency':\n\t\tcase 'Quantity':\n\t\t\tif (typeof value !== 'number' && typeof value !== 'string') {\n\t\t\t\treturn `${fieldname}: expected number, got ${typeof value}`\n\t\t\t}\n\t\t\tbreak\n\n\t\tcase 'Check':\n\t\t\tif (typeof value !== 'boolean') {\n\t\t\t\treturn `${fieldname}: expected boolean, got ${typeof value}`\n\t\t\t}\n\t\t\tbreak\n\n\t\tcase 'Data':\n\t\tcase 'Text':\n\t\tcase 'Code':\n\t\tcase 'Link':\n\t\t\tif (typeof value !== 'string') {\n\t\t\t\treturn `${fieldname}: expected string, got ${typeof value}`\n\t\t\t}\n\t\t\tbreak\n\n\t\tcase 'Date':\n\t\tcase 'Time':\n\t\tcase 'Datetime':\n\t\t\tif (typeof value !== 'string' && !(value instanceof Date)) {\n\t\t\t\treturn `${fieldname}: expected date string or Date, got ${typeof value}`\n\t\t\t}\n\t\t\tbreak\n\n\t\tcase 'JSON':\n\t\t\tif (typeof value !== 'object') {\n\t\t\t\treturn `${fieldname}: expected object, got ${typeof value}`\n\t\t\t}\n\t\t\tbreak\n\t}\n\n\treturn null\n}\n\n/**\n * No-op handler for testing or placeholder actions\n */\nconst noop: ActionHandler = async () => {\n\treturn { ok: true }\n}\n\n/**\n * Built-in handlers available for registration\n * @public\n */\nexport const builtinHandlers: Record<string, ActionHandler> = {\n\tvalidateRequiredFields,\n\tvalidateFieldTypes,\n\tnoop,\n}\n\n/**\n * Register all built-in handlers\n * @public\n */\nexport function registerBuiltinHandlers(): void {\n\tfor (const [name, handler] of Object.entries(builtinHandlers)) {\n\t\tregisterHandler(name, handler)\n\t}\n}\n","import type { DoctypeMeta, LinkDeclaration, LazyFetch, SyncFetch } from '@stonecrop/schema'\nimport { snakeToCamel, toPascalCase } from '@stonecrop/schema'\nimport { constant, lambda, object, loadOne } from 'postgraphile/grafast'\nimport { GraphileConfig } from 'postgraphile/graphile-build'\nimport { extendSchema, gql } from 'postgraphile/utils'\nimport pluralize from 'pluralize'\n\nimport { getHandler } from '../registry/actions'\nimport { getMeta, getAllMeta } from '../registry/doctypes'\nimport type {\n\tActionContext,\n\tGraphQLExecutor,\n\tReverseConnectionParams,\n\tBuildRecordQueryOptions,\n\tBuildNestedSelectionsParams,\n\tBuildListQueryArgs,\n\tMergeNestedResultsParams,\n\tExtractSingleResultParams,\n\tExtractListResultParams,\n} from '../types'\n\n/**\n * Inflection callbacks for mapping table names to GraphQL query field names.\n * Override these when using a non-Amber inflection preset (e.g., V4, SimplifyInflection).\n *\n * Defaults match the PostGraphile Amber preset conventions.\n * @public\n */\nexport interface StonecropInflectionConfig {\n\t/**\n\t * Given a table name, return the GraphQL field name for fetching a single record by ID.\n\t * @example Amber default: \"sales_orders\" → \"salesOrderById\"\n\t * @example V4 preset: \"sales_orders\" → \"salesOrderByRowId\"\n\t */\n\trecordFieldName?: (tableName: string) => string\n\n\t/**\n\t * Given a table name, return the GraphQL field name for fetching a list/connection.\n\t * @example Amber default: \"sales_orders\" → \"allSalesOrders\"\n\t * @example SimplifyInflection: \"sales_orders\" → \"salesOrders\"\n\t */\n\tconnectionFieldName?: (tableName: string) => string\n\n\t/**\n\t * Given a table name, return the GraphQL OrderBy enum type name.\n\t * @example Amber default: \"sales_orders\" → \"SalesOrdersOrderBy\"\n\t */\n\torderByTypeName?: (tableName: string) => string\n\n\t/**\n\t * Given a table name, return the GraphQL argument name used to look up a record by PK.\n\t * @example Amber default (Relay Global ID): \"sales_orders\" → \"id\"\n\t * @example row_id PK: \"sales_orders\" → \"rowId\"\n\t */\n\trecordArgName?: (tableName: string) => string\n\n\t/**\n\t * Given a table name, return the GraphQL variable type for the PK argument.\n\t * @example Default UUID PK: \"sales_orders\" → \"UUID!\"\n\t * @example Integer PK: \"sales_orders\" → \"Int!\"\n\t */\n\trecordArgType?: (tableName: string) => string\n\n\t/**\n\t * Derive the GraphQL connection field name for a reverse-FK link.\n\t * PostGraphile convention: `{targetPlural}By{FkColumnPascal}Id`\n\t * - When backlink is provided: FK column is derived from the backlink field\n\t * - When backlink is absent: FK column is derived from the parent doctype\n\t * @example Recipe → RecipeTasksByRecipeId\n\t */\n\treverseConnectionName?: (params: {\n\t\t/** Parent doctype slug */\n\t\tdoctype: string\n\t\t/** Link key on the parent */\n\t\tlinkName: string\n\t\t/** Link field on the target that points back to the parent (optional) */\n\t\tbacklink?: string\n\t\t/** Target doctype slug */\n\t\ttarget: string\n\t}) => string\n}\n\n/**\n * Options for stonecropRecord queries\n * @public\n */\nexport interface StonecropRecordOptions {\n\t/** Include nested/related records */\n\tincludeNested?: boolean | string[]\n\t/** Maximum nesting depth */\n\tmaxDepth?: number\n}\n\n/**\n * Options for creating a Stonecrop PostGraphile plugin\n * @public\n */\nexport interface StonecropPluginOptions {\n\t/** GraphQL executor for running queries/mutations */\n\texecutor: GraphQLExecutor\n\n\t/**\n\t * Override inflection conventions for mapping table names to GraphQL field names.\n\t * Defaults to PostGraphile Amber preset conventions.\n\t */\n\tinflection?: StonecropInflectionConfig\n}\n\n/**\n * Create a PostGraphile plugin that extends the GraphQL schema with Stonecrop functionality\n * @param options - Plugin configuration options\n * @returns A PostGraphile plugin\n * @public\n */\nexport const createStonecropPlugin = (options: StonecropPluginOptions): GraphileConfig.Plugin => {\n\t// Resolve inflection callbacks with Amber defaults\n\tconst recordFieldName = options.inflection?.recordFieldName ?? defaultRecordFieldName\n\tconst connectionFieldName = options.inflection?.connectionFieldName ?? defaultConnectionFieldName\n\tconst orderByTypeName = options.inflection?.orderByTypeName ?? defaultOrderByTypeName\n\tconst recordArgName = options.inflection?.recordArgName ?? defaultRecordArgName\n\tconst recordArgType = options.inflection?.recordArgType ?? defaultRecordArgType\n\tconst reverseConnectionName = options.inflection?.reverseConnectionName ?? defaultReverseConnectionName\n\n\treturn extendSchema(() => {\n\t\treturn {\n\t\t\ttypeDefs: gql`\n\t\t\t\ttype StonecropFieldMeta {\n\t\t\t\t\tfieldname: String!\n\t\t\t\t\tfieldtype: String!\n\t\t\t\t\tcomponent: String\n\t\t\t\t\tlabel: String\n\t\t\t\t\twidth: String\n\t\t\t\t\talign: String\n\t\t\t\t\trequired: Boolean\n\t\t\t\t\treadOnly: Boolean\n\t\t\t\t\tedit: Boolean\n\t\t\t\t\thidden: Boolean\n\t\t\t\t\tdefault: JSON\n\t\t\t\t\toptions: JSON\n\t\t\t\t\tmask: String\n\t\t\t\t\tprecision: Int\n\t\t\t\t\tscale: Int\n\t\t\t\t\tmode: String\n\t\t\t\t\tvalidation: JSON\n\t\t\t\t}\n\n\t\t\t\ttype StonecropWorkflowAction {\n\t\t\t\t\tlabel: String!\n\t\t\t\t\thandler: String!\n\t\t\t\t\trequiredFields: [String!]\n\t\t\t\t\tallowedStates: [String!]\n\t\t\t\t\tconfirm: Boolean\n\t\t\t\t\targs: JSON\n\t\t\t\t}\n\n\t\t\t\ttype StonecropWorkflowMeta {\n\t\t\t\t\tstates: [String!]\n\t\t\t\t\tactions: [StonecropWorkflowAction!]\n\t\t\t\t}\n\n\t\t\t\ttype StonecropDoctypeMeta {\n\t\t\t\t\tname: String!\n\t\t\t\t\tslug: String\n\t\t\t\t\ttableName: String\n\t\t\t\t\tfields: [StonecropFieldMeta!]!\n\t\t\t\t\tworkflow: StonecropWorkflowMeta\n\t\t\t\t\tinherits: String\n\t\t\t\t}\n\n\t\t\t\ttype StonecropRecordResult {\n\t\t\t\t\tdata: JSON\n\t\t\t\t\tdoctype: String!\n\t\t\t\t\tunknownLinks: [String!]\n\t\t\t\t}\n\n\t\t\t\ttype StonecropRecordsResult {\n\t\t\t\t\tdata: [JSON!]!\n\t\t\t\t\tdoctype: String!\n\t\t\t\t\tcount: Int!\n\t\t\t\t}\n\n\t\t\t\ttype StonecropActionResult {\n\t\t\t\t\tsuccess: Boolean!\n\t\t\t\t\tdata: JSON\n\t\t\t\t\terror: String\n\t\t\t\t}\n\n\t\t\t\textend type Query {\n\t\t\t\t\tstonecropMeta(doctype: String!): StonecropDoctypeMeta\n\t\t\t\t\tstonecropAllMeta: [StonecropDoctypeMeta!]!\n\t\t\t\t\tstonecropRecord(doctype: String!, id: String!, options: JSON): StonecropRecordResult\n\t\t\t\t\tstonecropRecords(\n\t\t\t\t\t\tdoctype: String!\n\t\t\t\t\t\tfilters: JSON\n\t\t\t\t\t\torderBy: String\n\t\t\t\t\t\tlimit: Int\n\t\t\t\t\t\toffset: Int\n\t\t\t\t\t): StonecropRecordsResult\n\t\t\t\t}\n\n\t\t\t\textend type Mutation {\n\t\t\t\t\tstonecropAction(doctype: String!, action: String!, args: JSON): StonecropActionResult!\n\t\t\t\t}\n\t\t\t`,\n\n\t\t\tobjects: {\n\t\t\t\tQuery: {\n\t\t\t\t\tplans: {\n\t\t\t\t\t\tstonecropMeta(_: any, { $doctype }: any) {\n\t\t\t\t\t\t\treturn lambda($doctype, (doctype: unknown) => {\n\t\t\t\t\t\t\t\tconst meta = getMeta(doctype as string)\n\t\t\t\t\t\t\t\treturn meta ?? null\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t},\n\n\t\t\t\t\t\tstonecropAllMeta() {\n\t\t\t\t\t\t\treturn constant(getAllMeta())\n\t\t\t\t\t\t},\n\n\t\t\t\t\t\tstonecropRecord(_: any, { $doctype, $id, $options }: any) {\n\t\t\t\t\t\t\treturn loadOne(\n\t\t\t\t\t\t\t\tobject({ doctype: $doctype, id: $id, options: $options }),\n\t\t\t\t\t\t\t\tasync (specs: readonly any[]) => {\n\t\t\t\t\t\t\t\t\treturn await Promise.all(\n\t\t\t\t\t\t\t\t\t\tspecs.map(async spec => {\n\t\t\t\t\t\t\t\t\t\t\tconst meta = getMeta(spec.doctype)\n\t\t\t\t\t\t\t\t\t\t\tif (!meta) {\n\t\t\t\t\t\t\t\t\t\t\t\tthrow new Error(`Unknown doctype: ${spec.doctype}`)\n\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\tif (!meta.tableName) {\n\t\t\t\t\t\t\t\t\t\t\t\tthrow new Error(`Doctype ${spec.doctype} has no table mapping`)\n\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\tconst recordOptions = spec.options ?? {}\n\n\t\t\t\t\t\t\t\t\t\t\tconst query = buildRecordQuery(\n\t\t\t\t\t\t\t\t\t\t\t\tmeta,\n\t\t\t\t\t\t\t\t\t\t\t\trecordFieldName,\n\t\t\t\t\t\t\t\t\t\t\t\trecordArgName,\n\t\t\t\t\t\t\t\t\t\t\t\trecordArgType,\n\t\t\t\t\t\t\t\t\t\t\t\tgetMeta,\n\t\t\t\t\t\t\t\t\t\t\t\trecordOptions.includeNested\n\t\t\t\t\t\t\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tincludeNested: recordOptions.includeNested,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tmaxDepth: recordOptions.maxDepth,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\t\t\t\t\t\t\t\treverseConnectionName\n\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t\tconst result = await options.executor.query(query, {\n\t\t\t\t\t\t\t\t\t\t\t\t[recordArgName(meta.tableName)]: spec.id,\n\t\t\t\t\t\t\t\t\t\t\t})\n\n\t\t\t\t\t\t\t\t\t\t\tlet data = extractSingleResult({ result, meta, recordFieldName })\n\n\t\t\t\t\t\t\t\t\t\t\tif (recordOptions.includeNested && data && meta.links) {\n\t\t\t\t\t\t\t\t\t\t\t\tdata = mergeNestedResults({\n\t\t\t\t\t\t\t\t\t\t\t\t\trecord: data as Record<string, unknown>,\n\t\t\t\t\t\t\t\t\t\t\t\t\tmeta,\n\t\t\t\t\t\t\t\t\t\t\t\t\tgetMeta,\n\t\t\t\t\t\t\t\t\t\t\t\t\treverseConnectionNameFn: reverseConnectionName,\n\t\t\t\t\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\tconst unknownLinks =\n\t\t\t\t\t\t\t\t\t\t\t\tArray.isArray(recordOptions.includeNested) && meta.links\n\t\t\t\t\t\t\t\t\t\t\t\t\t? recordOptions.includeNested.filter((name: string) => !(name in meta.links!))\n\t\t\t\t\t\t\t\t\t\t\t\t\t: undefined\n\n\t\t\t\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t\t\t\tdata,\n\t\t\t\t\t\t\t\t\t\t\t\tdoctype: spec.doctype,\n\t\t\t\t\t\t\t\t\t\t\t\t...(unknownLinks ? { unknownLinks } : {}),\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t},\n\n\t\t\t\t\t\tstonecropRecords(_: any, { $doctype, $filters, $orderBy, $limit, $offset }: any) {\n\t\t\t\t\t\t\treturn loadOne(\n\t\t\t\t\t\t\t\tobject({\n\t\t\t\t\t\t\t\t\tdoctype: $doctype,\n\t\t\t\t\t\t\t\t\tfilters: $filters,\n\t\t\t\t\t\t\t\t\torderBy: $orderBy,\n\t\t\t\t\t\t\t\t\tlimit: $limit,\n\t\t\t\t\t\t\t\t\toffset: $offset,\n\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\tasync (specs: readonly any[]) => {\n\t\t\t\t\t\t\t\t\treturn await Promise.all(\n\t\t\t\t\t\t\t\t\t\tspecs.map(async spec => {\n\t\t\t\t\t\t\t\t\t\t\tconst meta = getMeta(spec.doctype)\n\t\t\t\t\t\t\t\t\t\t\tif (!meta) {\n\t\t\t\t\t\t\t\t\t\t\t\tthrow new Error(`Unknown doctype: ${spec.doctype}`)\n\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\tif (!meta.tableName) {\n\t\t\t\t\t\t\t\t\t\t\t\tthrow new Error(`Doctype ${spec.doctype} has no table mapping`)\n\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\tconst query = buildListQuery(\n\t\t\t\t\t\t\t\t\t\t\t\tmeta,\n\t\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t\tlimit: spec.limit,\n\t\t\t\t\t\t\t\t\t\t\t\t\toffset: spec.offset,\n\t\t\t\t\t\t\t\t\t\t\t\t\torderBy: spec.orderBy,\n\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\tconnectionFieldName,\n\t\t\t\t\t\t\t\t\t\t\t\torderByTypeName\n\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t\tconst result = await options.executor.query(query, {\n\t\t\t\t\t\t\t\t\t\t\t\tlimit: spec.limit,\n\t\t\t\t\t\t\t\t\t\t\t\toffset: spec.offset,\n\t\t\t\t\t\t\t\t\t\t\t\torderBy: spec.orderBy,\n\t\t\t\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\t\t\t\tconst data = extractListResult({ result, meta, connectionFieldName })\n\n\t\t\t\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t\t\t\tdata,\n\t\t\t\t\t\t\t\t\t\t\t\tdoctype: spec.doctype,\n\t\t\t\t\t\t\t\t\t\t\t\tcount: data.length,\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\n\t\t\t\tMutation: {\n\t\t\t\t\tplans: {\n\t\t\t\t\t\tstonecropAction(_: any, { $doctype, $action, $args: $actionArgs }: any) {\n\t\t\t\t\t\t\treturn loadOne(\n\t\t\t\t\t\t\t\tobject({\n\t\t\t\t\t\t\t\t\tdoctype: $doctype,\n\t\t\t\t\t\t\t\t\taction: $action,\n\t\t\t\t\t\t\t\t\tactionArgs: $actionArgs,\n\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\tasync (specs: readonly any[]) => {\n\t\t\t\t\t\t\t\t\treturn await Promise.all(\n\t\t\t\t\t\t\t\t\t\tspecs.map(async spec => {\n\t\t\t\t\t\t\t\t\t\t\tconst meta = getMeta(spec.doctype)\n\t\t\t\t\t\t\t\t\t\t\tif (!meta) {\n\t\t\t\t\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t\t\t\t\tsuccess: false,\n\t\t\t\t\t\t\t\t\t\t\t\t\tdata: null,\n\t\t\t\t\t\t\t\t\t\t\t\t\terror: `Unknown doctype: ${spec.doctype}`,\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\tconst actionDef = meta.workflow?.actions?.[spec.action]\n\t\t\t\t\t\t\t\t\t\t\tif (!actionDef) {\n\t\t\t\t\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t\t\t\t\tsuccess: false,\n\t\t\t\t\t\t\t\t\t\t\t\t\tdata: null,\n\t\t\t\t\t\t\t\t\t\t\t\t\terror: `Unknown action: ${spec.action} on ${spec.doctype}`,\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\tconst handlerName = actionDef.handler\n\t\t\t\t\t\t\t\t\t\t\tconst handler = getHandler(handlerName)\n\t\t\t\t\t\t\t\t\t\t\tif (!handler) {\n\t\t\t\t\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t\t\t\t\tsuccess: false,\n\t\t\t\t\t\t\t\t\t\t\t\t\tdata: null,\n\t\t\t\t\t\t\t\t\t\t\t\t\terror: `Handler not registered: ${handlerName}`,\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\tconst actionContext: ActionContext = {\n\t\t\t\t\t\t\t\t\t\t\t\tdoctype: meta,\n\t\t\t\t\t\t\t\t\t\t\t\texecutor: options.executor,\n\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\t\t\t\tconst result = await handler(spec.actionArgs ?? [], actionContext)\n\t\t\t\t\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t\t\t\t\tsuccess: true,\n\t\t\t\t\t\t\t\t\t\t\t\t\tdata: result,\n\t\t\t\t\t\t\t\t\t\t\t\t\terror: null,\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t} catch (err) {\n\t\t\t\t\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t\t\t\t\tsuccess: false,\n\t\t\t\t\t\t\t\t\t\t\t\t\tdata: null,\n\t\t\t\t\t\t\t\t\t\t\t\t\terror: err instanceof Error ? err.message : String(err),\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t}\n\t})\n}\n\n// =============================================================================\n// Inflection helpers — default to PostGraphile Amber preset conventions\n// Uses `pluralize` for proper English singularization (handles irregular\n// plurals like statuses→status, categories→category, addresses→address).\n// snakeToCamel / toPascalCase are imported from @stonecrop/schema.\n// =============================================================================\n\n/**\n * Amber default: sales_orders → salesOrderById\n * Uses `pluralize` for proper singularization of irregular plurals.\n * Override via `StonecropInflectionConfig.recordFieldName` for non-standard PK columns.\n * @public\n */\nfunction defaultRecordFieldName(tableName: string): string {\n\tconst singular = pluralize.singular(tableName)\n\treturn `${snakeToCamel(singular)}ById`\n}\n\n/**\n * Amber default: sales_orders → allSalesOrders\n * @public\n */\nfunction defaultConnectionFieldName(tableName: string): string {\n\treturn `all${toPascalCase(tableName)}`\n}\n\n/**\n * Amber default: sales_orders → SalesOrdersOrderBy\n * @public\n */\nfunction defaultOrderByTypeName(tableName: string): string {\n\treturn `${toPascalCase(tableName)}OrderBy`\n}\n\n/**\n * Default PK argument name: 'id' (standard Relay Global ID pattern).\n * Override via `StonecropInflectionConfig.recordArgName` when using row_id columns;\n * PostGraphile Amber generates `rowId: UUID!` for those fields.\n * @public\n */\nfunction defaultRecordArgName(_tableName: string): string {\n\treturn 'id'\n}\n\n/**\n * Default PK argument type: 'UUID!' (PostGraphile Amber default for UUID PKs).\n * Override via `StonecropInflectionConfig.recordArgType` when using non-UUID PKs\n * such as integer serials or Relay Global IDs ('ID!').\n * @public\n */\nfunction defaultRecordArgType(_tableName: string): string {\n\treturn 'UUID!'\n}\n\n/**\n * Default reverse connection name: derives PostGraphile's connection field convention.\n * PostGraphile convention: `{targetPlural}By{FkColumnPascal}Id`\n * - When backlink is defined: FK column is derived from the backlink field name\n * - When backlink is absent: FK column is derived from the parent doctype's table name\n * @public\n */\nfunction defaultReverseConnectionName(params: {\n\tdoctype: string\n\tlinkName: string\n\tbacklink?: string\n\ttarget: string\n}): string {\n\tconst targetPlural = pluralize.plural(params.target.replace(/-/g, '_'))\n\t// Use camelCase for target (matches PostGraphile Amber convention: recipeTasksByRecipeId)\n\tconst targetCamel = snakeToCamel(targetPlural)\n\t// Use backlink if provided, otherwise derive from parent table name\n\tconst fkSource = params.backlink || params.doctype\n\t// FK column name: uppercase first char, preserve rest of camelCase\n\tconst fkPascal = fkSource.charAt(0).toUpperCase() + snakeToCamel(fkSource).slice(1)\n\treturn `${targetCamel}By${fkPascal}Id`\n}\n\n/**\n * Check if a cardinality represents a \"many\" relationship\n */\nfunction isManyCardinality(cardinality: string): boolean {\n\treturn cardinality === 'noneOrMany' || cardinality === 'atLeastOne'\n}\n\n// =============================================================================\n// Query builders — generate GraphQL queries to send to the underlying schema\n// =============================================================================\n\nconst DEFAULT_SYNC_LIMIT = 50\n\n/**\n * Fieldtypes unconditionally excluded from the generated scalar query selection set.\n * - `'Display'`: display-only composite component with no backing DB column\n *\n * Note: `'Link'` fields are NOT blanket-excluded here. Scalar FK UUID columns use\n * `fieldtype: 'Link'` and ARE queryable. Only Link fields that also appear in the\n * doctype's `links` declaration (i.e. those that resolve to a sub-object or connection)\n * are excluded — that logic lives in `queryableFieldNames`.\n * @public\n */\nconst RELATION_FIELDTYPES = new Set(['Display'])\n\n/**\n * Filter fields to only those directly queryable as scalars.\n * Excludes Display fields (no backing DB column) and Link fields that have an\n * explicit `links` declaration (those require sub-selection, not scalar reads).\n * Link fields without a `links` declaration are scalar FK UUID columns and ARE included.\n * @public\n */\nfunction queryableFieldNames(meta: DoctypeMeta): string {\n\tconst linkedFieldnames = new Set<string>()\n\tif (meta.links) {\n\t\tfor (const [key, link] of Object.entries(meta.links)) {\n\t\t\tlinkedFieldnames.add((link as any).fieldname ?? key)\n\t\t}\n\t}\n\treturn meta.fields\n\t\t.filter(f => {\n\t\t\tif (RELATION_FIELDTYPES.has(f.fieldtype)) return false\n\t\t\tif (f.fieldtype === 'Link' && linkedFieldnames.has(f.fieldname)) return false\n\t\t\treturn true\n\t\t})\n\t\t.map(f => f.fieldname)\n\t\t.join('\\n ')\n}\n\n/**\n * Get the effective fetch strategy for a link, applying cardinality-based defaults.\n */\nfunction getEffectiveFetchStrategy(link: LinkDeclaration): SyncFetch | LazyFetch {\n\tif (link.fetch !== undefined) {\n\t\treturn link.fetch as SyncFetch | LazyFetch\n\t}\n\n\tif (isManyCardinality(link.cardinality)) {\n\t\treturn { method: 'sync', limit: DEFAULT_SYNC_LIMIT }\n\t} else {\n\t\treturn { method: 'lazy' }\n\t}\n}\n\n/**\n * Get the effective blockWorkflows value for a link.\n */\nfunction getEffectiveBlockWorkflows(link: LinkDeclaration): boolean {\n\tif (link.blockWorkflows !== undefined) {\n\t\treturn link.blockWorkflows\n\t}\n\tconst effectiveFetch = getEffectiveFetchStrategy(link)\n\treturn effectiveFetch.method === 'sync'\n}\n\n/**\n * Build nested sub-selections for descendant links\n */\nfunction buildNestedSelections(params: BuildNestedSelectionsParams): string {\n\tconst { links, meta, includeSet, getMeta, seen, depth, maxDepth, reverseConnectionNameFn } = params\n\n\tif (maxDepth !== undefined && depth >= maxDepth) return ''\n\n\tconst selections: string[] = []\n\n\tfor (const [fieldname, link] of Object.entries(links)) {\n\t\tif (maxDepth !== undefined && depth >= maxDepth) break\n\n\t\tconst effectiveBlockWorkflows = getEffectiveBlockWorkflows(link)\n\t\tconst linkBlockWorkflowsExplicitTrue = link.blockWorkflows === true\n\n\t\tif (includeSet && !includeSet.has(fieldname) && !linkBlockWorkflowsExplicitTrue) {\n\t\t\tcontinue\n\t\t}\n\n\t\tconst effectiveFetch = getEffectiveFetchStrategy(link)\n\t\tconst shouldSkip =\n\t\t\teffectiveBlockWorkflows === false || (effectiveFetch.method !== 'sync' && !linkBlockWorkflowsExplicitTrue)\n\t\tif (shouldSkip) {\n\t\t\tcontinue\n\t\t}\n\n\t\tconst targetMeta = getMeta(link.target)\n\t\tif (!targetMeta) continue\n\n\t\tconst alreadySeen = seen.has(link.target)\n\t\tif (!alreadySeen) {\n\t\t\tseen.add(link.target)\n\t\t}\n\t\tconst scalarFields = queryableFieldNames(targetMeta)\n\n\t\tlet nestedLinks = ''\n\t\tif (!alreadySeen && targetMeta.links && targetMeta.tableName && (maxDepth === undefined || depth + 1 < maxDepth)) {\n\t\t\tconst innerSelections = buildNestedSelections({\n\t\t\t\tlinks: targetMeta.links,\n\t\t\t\tmeta: targetMeta,\n\t\t\t\tincludeSet: null,\n\t\t\t\tgetMeta,\n\t\t\t\tseen,\n\t\t\t\tdepth: depth + 1,\n\t\t\t\tmaxDepth,\n\t\t\t\treverseConnectionNameFn,\n\t\t\t})\n\t\t\tif (innerSelections) {\n\t\t\t\tnestedLinks = '\\n ' + innerSelections\n\t\t\t}\n\t\t\tseen.delete(link.target)\n\t\t}\n\n\t\tconst fullSelection = scalarFields + nestedLinks\n\n\t\tif (isManyCardinality(link.cardinality)) {\n\t\t\tconst reverseParams: ReverseConnectionParams = {\n\t\t\t\tdoctype: meta.slug || meta.name,\n\t\t\t\tlinkName: fieldname,\n\t\t\t\tbacklink: link.backlink,\n\t\t\t\ttarget: link.target,\n\t\t\t}\n\t\t\tconst connectionField = reverseConnectionNameFn\n\t\t\t\t? reverseConnectionNameFn(reverseParams)\n\t\t\t\t: defaultReverseConnectionName(reverseParams)\n\t\t\tconst limitArg =\n\t\t\t\teffectiveFetch.method === 'sync' && effectiveFetch.limit !== undefined\n\t\t\t\t\t? `first: ${effectiveFetch.limit}`\n\t\t\t\t\t: effectiveFetch.method === 'sync'\n\t\t\t\t\t\t? `first: ${DEFAULT_SYNC_LIMIT}`\n\t\t\t\t\t\t: ''\n\t\t\tselections.push(`\n\t\t\t${connectionField}${limitArg ? `(${limitArg})` : ''} {\n\t\t\t\tnodes {\n\t\t\t\t\t${fullSelection}\n\t\t\t\t}\n\t\t\t}`)\n\t\t} else {\n\t\t\tselections.push(`\n\t\t\t${fieldname} {\n\t\t\t\t${fullSelection}\n\t\t\t}`)\n\t\t}\n\t}\n\n\treturn selections.join('')\n}\n\n/**\n * Build a GraphQL query to fetch a single record by ID.\n * When includeNested is set, recursively includes descendant link sub-selections.\n * @public\n */\nfunction buildRecordQuery(\n\tmeta: DoctypeMeta,\n\trecordFieldName: (t: string) => string,\n\trecordArgName: (t: string) => string,\n\trecordArgType: (t: string) => string,\n\tgetMeta: (slug: string) => DoctypeMeta | undefined,\n\toptions?: BuildRecordQueryOptions,\n\treverseConnectionNameFn?: (params: ReverseConnectionParams) => string\n): string {\n\tconst queryName = recordFieldName(meta.tableName!)\n\tconst argName = recordArgName(meta.tableName!)\n\tconst argType = recordArgType(meta.tableName!)\n\n\tconst seen = new Set<string>([meta.slug || meta.name])\n\n\tlet selection = queryableFieldNames(meta)\n\n\tif (options?.includeNested && meta.links) {\n\t\tconst includeSet = Array.isArray(options.includeNested) ? new Set(options.includeNested) : null\n\n\t\tconst nestedSelections = buildNestedSelections({\n\t\t\tlinks: meta.links,\n\t\t\tmeta,\n\t\t\tincludeSet,\n\t\t\tgetMeta,\n\t\t\tseen,\n\t\t\tdepth: 0,\n\t\t\tmaxDepth: options.maxDepth,\n\t\t\treverseConnectionNameFn,\n\t\t})\n\n\t\tif (nestedSelections) {\n\t\t\tselection += '\\n ' + nestedSelections\n\t\t}\n\t}\n\n\treturn `\n\t\tquery GetRecord($${argName}: ${argType}) {\n\t\t\t${queryName}(${argName}: $${argName}) {\n\t\t\t\t${selection}\n\t\t\t}\n\t\t}\n\t`\n}\n\n/**\n * Build a GraphQL connection query to fetch a list of records.\n * Only declares variables ($limit, $offset, $orderBy) that are actually used in the query,\n * avoiding GraphQL spec §5.8.3 violations from unused variable declarations.\n * Excludes Link relation fields and Display fields from the selection set.\n * @public\n */\nfunction buildListQuery(\n\tmeta: DoctypeMeta,\n\targs: BuildListQueryArgs,\n\tconnectionFieldName: (t: string) => string,\n\torderByTypeName: (t: string) => string\n): string {\n\tconst fieldNames = queryableFieldNames(meta)\n\tconst connectionName = connectionFieldName(meta.tableName!)\n\tconst orderByType = orderByTypeName(meta.tableName!)\n\n\tconst varDecls: string[] = []\n\tconst queryArgs: string[] = []\n\tif (args.limit) {\n\t\tvarDecls.push('$limit: Int')\n\t\tqueryArgs.push(`first: $limit`)\n\t}\n\tif (args.offset) {\n\t\tvarDecls.push('$offset: Int')\n\t\tqueryArgs.push(`offset: $offset`)\n\t}\n\tif (args.orderBy) {\n\t\tvarDecls.push(`$orderBy: [${orderByType}!]`)\n\t\tqueryArgs.push(`orderBy: $orderBy`)\n\t}\n\n\tconst varStr = varDecls.length > 0 ? `(${varDecls.join(', ')})` : ''\n\tconst argsStr = queryArgs.length > 0 ? `(${queryArgs.join(', ')})` : ''\n\n\treturn `\n\t\tquery GetRecords${varStr} {\n\t\t\t${connectionName}${argsStr} {\n\t\t\t\tnodes {\n\t\t\t\t${fieldNames}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t`\n}\n\n/**\n * Merge nested connection results into flat arrays.\n * For `noneOrMany`/`atLeastOne` links, the query returns `{ nodes: [...] }`.\n * This flattens them to just `[]` for easier consumption.\n * @public\n */\nfunction mergeNestedResults(params: MergeNestedResultsParams): Record<string, unknown> {\n\tconst { record, meta, getMeta, reverseConnectionNameFn } = params\n\tif (!meta.links) return record\n\n\tconst merged = { ...record }\n\n\tfor (const [fieldname, link] of Object.entries(meta.links)) {\n\t\tconst isMany = isManyCardinality(link.cardinality)\n\n\t\tif (isMany) {\n\t\t\tconst targetMeta = getMeta(link.target)\n\t\t\tif (!targetMeta) continue\n\n\t\t\tconst reverseParams: ReverseConnectionParams = {\n\t\t\t\tdoctype: meta.slug || meta.name,\n\t\t\t\tlinkName: fieldname,\n\t\t\t\tbacklink: link.backlink || fieldname,\n\t\t\t\ttarget: link.target,\n\t\t\t}\n\t\t\tconst connectionField = reverseConnectionNameFn\n\t\t\t\t? reverseConnectionNameFn(reverseParams)\n\t\t\t\t: defaultReverseConnectionName(reverseParams)\n\t\t\tconst connectionResult = merged[connectionField] as { nodes?: unknown[] } | undefined\n\t\t\tif (connectionResult?.nodes) {\n\t\t\t\tmerged[fieldname] = connectionResult.nodes\n\t\t\t\tdelete merged[connectionField]\n\t\t\t} else {\n\t\t\t\tmerged[fieldname] = []\n\t\t\t\tdelete merged[connectionField]\n\t\t\t}\n\t\t}\n\t}\n\n\treturn merged\n}\n\n/**\n * Extract a single record from a PostGraphile query result using the record field name.\n * @public\n */\nfunction extractSingleResult(params: ExtractSingleResultParams): unknown {\n\tconst { result, meta, recordFieldName } = params\n\tconst queryName = recordFieldName(meta.tableName!)\n\treturn (result as Record<string, unknown>)[queryName]\n}\n\n/**\n * Extract the list of nodes from a PostGraphile connection query result.\n * Returns an empty array if the connection field is absent.\n * @public\n */\nfunction extractListResult(params: ExtractListResultParams): unknown[] {\n\tconst { result, meta, connectionFieldName } = params\n\tconst connectionName = connectionFieldName(meta.tableName!)\n\tconst connection = (result as Record<string, unknown>)[connectionName] as {\n\t\tnodes: unknown[]\n\t}\n\treturn connection?.nodes ?? []\n}\n\n// =============================================================================\n// Exported for testing and advanced usage\n// =============================================================================\n\nexport {\n\tdefaultRecordFieldName,\n\tdefaultConnectionFieldName,\n\tdefaultOrderByTypeName,\n\tdefaultRecordArgName,\n\tdefaultRecordArgType,\n\tdefaultReverseConnectionName,\n\tbuildRecordQuery,\n\tbuildListQuery,\n\tqueryableFieldNames,\n\tRELATION_FIELDTYPES,\n\textractSingleResult,\n\textractListResult,\n\tmergeNestedResults,\n}\n","import { gql } from 'postgraphile/utils'\n\n/**\n * GraphQL type definitions for Stonecrop's middleware API.\n * Includes stonecropMeta, stonecropRecord, stonecropRecords, stonecropAction, and related types.\n * @public\n */\nexport const typeDefs = gql`\n\ttype StonecropFieldMeta {\n\t\tfieldname: String!\n\t\tfieldtype: String!\n\t\tcomponent: String\n\t\tlabel: String\n\t\twidth: String\n\t\talign: String\n\t\trequired: Boolean\n\t\treadOnly: Boolean\n\t\tedit: Boolean\n\t\thidden: Boolean\n\t\tdefault: JSON\n\t\toptions: JSON\n\t\tmask: String\n\t\tprecision: Int\n\t\tscale: Int\n\t\tmode: String\n\t\tvalidation: JSON\n\t}\n\n\ttype StonecropWorkflowAction {\n\t\tlabel: String!\n\t\thandler: String!\n\t\trequiredFields: [String!]\n\t\tallowedStates: [String!]\n\t\tconfirm: Boolean\n\t\targs: JSON\n\t}\n\n\ttype StonecropWorkflowMeta {\n\t\tstates: [String!]\n\t\tactions: [StonecropWorkflowAction!]\n\t}\n\n\ttype StonecropDoctypeMeta {\n\t\tname: String!\n\t\tslug: String\n\t\ttableName: String\n\t\tfields: [StonecropFieldMeta!]!\n\t\tworkflow: StonecropWorkflowMeta\n\t\tinherits: String\n\t}\n\n\ttype StonecropRecordResult {\n\t\tdata: JSON\n\t\tdoctype: String!\n\t\tunknownLinks: [String!]\n\t}\n\n\ttype StonecropRecordsResult {\n\t\tdata: [JSON!]!\n\t\tdoctype: String!\n\t\tcount: Int!\n\t}\n\n\ttype StonecropActionResult {\n\t\tsuccess: Boolean!\n\t\tdata: JSON\n\t\terror: String\n\t}\n\n\textend type Query {\n\t\tstonecropMeta(doctype: String!): StonecropDoctypeMeta\n\t\tstonecropAllMeta: [StonecropDoctypeMeta!]!\n\t\tstonecropRecord(doctype: String!, id: String!, options: JSON): StonecropRecordResult\n\t\tstonecropRecords(doctype: String!, filters: JSON, orderBy: String, limit: Int, offset: Int): StonecropRecordsResult\n\t}\n\n\textend type Mutation {\n\t\tstonecropAction(doctype: String!, action: String!, args: JSON): StonecropActionResult!\n\t}\n`\n"],"names":["doctypeRegistry","DoctypeValidationError","file","errors","errorMessages","e","loadDoctypes","dir","options","entries","readdirSync","entry","fullPath","join","statSync","loadDoctypeFile","filePath","content","readFileSync","data","err","parseError","result","validateDoctype","doctype","parseDoctype","loadDoctypesFromObject","doctypes","name","withName","getMeta","direct","getAllMeta","hasMeta","clearRegistry","validateReferences","field","handlerRegistry","registerHandler","handler","getHandler","hasHandler","clearHandlers","validateRequiredFields","args","context","record","missing","validateFieldTypes","value","error","validateFieldValue","fieldname","link","fieldtype","noop","builtinHandlers","registerBuiltinHandlers","createStonecropPlugin","recordFieldName","defaultRecordFieldName","connectionFieldName","defaultConnectionFieldName","orderByTypeName","defaultOrderByTypeName","recordArgName","defaultRecordArgName","recordArgType","defaultRecordArgType","reverseConnectionName","defaultReverseConnectionName","extendSchema","gql","_","$doctype","lambda","constant","$id","$options","loadOne","object","specs","spec","meta","recordOptions","query","buildRecordQuery","extractSingleResult","mergeNestedResults","unknownLinks","$filters","$orderBy","$limit","$offset","buildListQuery","extractListResult","$action","$actionArgs","actionDef","handlerName","actionContext","tableName","singular","pluralize","snakeToCamel","toPascalCase","_tableName","params","targetPlural","targetCamel","fkSource","fkPascal","isManyCardinality","cardinality","DEFAULT_SYNC_LIMIT","RELATION_FIELDTYPES","queryableFieldNames","linkedFieldnames","key","f","getEffectiveFetchStrategy","getEffectiveBlockWorkflows","buildNestedSelections","links","includeSet","seen","depth","maxDepth","reverseConnectionNameFn","selections","effectiveBlockWorkflows","linkBlockWorkflowsExplicitTrue","effectiveFetch","targetMeta","alreadySeen","scalarFields","nestedLinks","innerSelections","fullSelection","reverseParams","connectionField","limitArg","queryName","argName","argType","selection","nestedSelections","fieldNames","connectionName","orderByType","varDecls","queryArgs","varStr","argsStr","merged","connectionResult","typeDefs"],"mappings":";;;;;;AAMA,MAAMA,wBAAgD,IAAA;AAM/C,MAAMC,UAA+B,MAAM;AAAA,EACjD,YAEiBC,GAEAC,GACf;AACD,UAAMC,IAAgBD,EAAO,IAAI,CAAAE,MAAK,KAAKA,EAAE,KAAK,KAAK,GAAG,CAAC,KAAKA,EAAE,OAAO,EAAE,EAAE,KAAK;AAAA,CAAI;AACtF,UAAM,iCAAiCH,CAAI;AAAA,EAAME,CAAa,EAAE,GALhD,KAAA,OAAAF,GAEA,KAAA,SAAAC,GAIhB,KAAK,OAAO;AAAA,EACb;AAAA,EAPiB;AAAA,EAEA;AAMlB;AAmBO,SAASG,EA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SAHoB7D,EAAmC8H,CAAc,GAGlD,SAAS,CAAA;AAC7B;AC5xBO,MAAMQ,KAAWpF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;"}
@@ -131,14 +131,21 @@ declare function defaultReverseConnectionName(params: {
131
131
  target: string;
132
132
  }): string;
133
133
  /**
134
- * Fieldtypes that map to GraphQL object/connection types and require sub-selections.
135
- * These fields are excluded from generated query field selections.
134
+ * Fieldtypes unconditionally excluded from the generated scalar query selection set.
135
+ * - `'Display'`: display-only composite component with no backing DB column
136
+ *
137
+ * Note: `'Link'` fields are NOT blanket-excluded here. Scalar FK UUID columns use
138
+ * `fieldtype: 'Link'` and ARE queryable. Only Link fields that also appear in the
139
+ * doctype's `links` declaration (i.e. those that resolve to a sub-object or connection)
140
+ * are excluded — that logic lives in `queryableFieldNames`.
136
141
  * @public
137
142
  */
138
143
  declare const RELATION_FIELDTYPES: Set<string>;
139
144
  /**
140
- * Filter fields to only those directly queryable as scalars, excluding Link and Doctype
141
- * relation fields that require GraphQL sub-selections.
145
+ * Filter fields to only those directly queryable as scalars.
146
+ * Excludes Display fields (no backing DB column) and Link fields that have an
147
+ * explicit `links` declaration (those require sub-selection, not scalar reads).
148
+ * Link fields without a `links` declaration are scalar FK UUID columns and ARE included.
142
149
  * @public
143
150
  */
144
151
  declare function queryableFieldNames(meta: DoctypeMeta): string;
@@ -152,7 +159,7 @@ declare function buildRecordQuery(meta: DoctypeMeta, recordFieldName: (t: string
152
159
  * Build a GraphQL connection query to fetch a list of records.
153
160
  * Only declares variables ($limit, $offset, $orderBy) that are actually used in the query,
154
161
  * avoiding GraphQL spec §5.8.3 violations from unused variable declarations.
155
- * Excludes Link and Doctype relation fields from the selection set.
162
+ * Excludes Link relation fields and Display fields from the selection set.
156
163
  * @public
157
164
  */
158
165
  declare function buildListQuery(meta: DoctypeMeta, args: BuildListQueryArgs, connectionFieldName: (t: string) => string, orderByTypeName: (t: string) => string): string;
@@ -1 +1 @@
1
- {"version":3,"file":"postgraphile.d.ts","sourceRoot":"","sources":["../../../src/plugin/postgraphile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAyC,MAAM,mBAAmB,CAAA;AAG3F,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAA;AAM5D,OAAO,KAAK,EAEX,eAAe,EACf,uBAAuB,EACvB,uBAAuB,EAEvB,kBAAkB,EAClB,wBAAwB,EACxB,yBAAyB,EACzB,uBAAuB,EACvB,MAAM,UAAU,CAAA;AAEjB;;;;;;GAMG;AACH,MAAM,WAAW,yBAAyB;IACzC;;;;OAIG;IACH,eAAe,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,MAAM,CAAA;IAE/C;;;;OAIG;IACH,mBAAmB,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,MAAM,CAAA;IAEnD;;;OAGG;IACH,eAAe,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,MAAM,CAAA;IAE/C;;;;OAIG;IACH,aAAa,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,MAAM,CAAA;IAE7C;;;;OAIG;IACH,aAAa,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,MAAM,CAAA;IAE7C;;;;;;OAMG;IACH,qBAAqB,CAAC,EAAE,CAAC,MAAM,EAAE;QAChC,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AM,KAAK,WAAW,GAAG,SAAS,EAClD,OAAO,CAAC,EAAE,uBAAuB,EACjC,uBAAuB,CAAC,EAAE,CAAC,MAAM,EAAE,uBAAuB,KAAK,MAAM,GACnE,MAAM,CAmCR;AAED;;;;;;GAMG;AACH,iBAAS,cAAc,CACtB,IAAI,EAAE,WAAW,EACjB,IAAI,EAAE,kBAAkB,EACxB,mBAAmB,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,EAC1C,eAAe,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,GACpC,MAAM,CAgCR;AAED;;;;;GAKG;AACH,iBAAS,kBAAkB,CAAC,MAAM,EAAE,wBAAwB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAkCrF;AAED;;;GAGG;AACH,iBAAS,mBAAmB,CAAC,MAAM,EAAE,yBAAyB,GAAG,OAAO,CAIvE;AAED;;;;GAIG;AACH,iBAAS,iBAAiB,CAAC,MAAM,EAAE,uBAAuB,GAAG,OAAO,EAAE,CAOrE;AAMD,OAAO,EACN,sBAAsB,EACtB,0BAA0B,EAC1B,sBAAsB,EACtB,oBAAoB,EACpB,oBAAoB,EACpB,4BAA4B,EAC5B,gBAAgB,EAChB,cAAc,EACd,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,iBAAiB,EACjB,kBAAkB,GAClB,CAAA"}
@@ -326,19 +326,38 @@ function isManyCardinality(cardinality) {
326
326
  // =============================================================================
327
327
  const DEFAULT_SYNC_LIMIT = 50;
328
328
  /**
329
- * Fieldtypes that map to GraphQL object/connection types and require sub-selections.
330
- * These fields are excluded from generated query field selections.
329
+ * Fieldtypes unconditionally excluded from the generated scalar query selection set.
330
+ * - `'Display'`: display-only composite component with no backing DB column
331
+ *
332
+ * Note: `'Link'` fields are NOT blanket-excluded here. Scalar FK UUID columns use
333
+ * `fieldtype: 'Link'` and ARE queryable. Only Link fields that also appear in the
334
+ * doctype's `links` declaration (i.e. those that resolve to a sub-object or connection)
335
+ * are excluded — that logic lives in `queryableFieldNames`.
331
336
  * @public
332
337
  */
333
- const RELATION_FIELDTYPES = new Set(['Link']);
338
+ const RELATION_FIELDTYPES = new Set(['Display']);
334
339
  /**
335
- * Filter fields to only those directly queryable as scalars, excluding Link and Doctype
336
- * relation fields that require GraphQL sub-selections.
340
+ * Filter fields to only those directly queryable as scalars.
341
+ * Excludes Display fields (no backing DB column) and Link fields that have an
342
+ * explicit `links` declaration (those require sub-selection, not scalar reads).
343
+ * Link fields without a `links` declaration are scalar FK UUID columns and ARE included.
337
344
  * @public
338
345
  */
339
346
  function queryableFieldNames(meta) {
347
+ const linkedFieldnames = new Set();
348
+ if (meta.links) {
349
+ for (const [key, link] of Object.entries(meta.links)) {
350
+ linkedFieldnames.add(link.fieldname ?? key);
351
+ }
352
+ }
340
353
  return meta.fields
341
- .filter(f => !RELATION_FIELDTYPES.has(f.fieldtype))
354
+ .filter(f => {
355
+ if (RELATION_FIELDTYPES.has(f.fieldtype))
356
+ return false;
357
+ if (f.fieldtype === 'Link' && linkedFieldnames.has(f.fieldname))
358
+ return false;
359
+ return true;
360
+ })
342
361
  .map(f => f.fieldname)
343
362
  .join('\n ');
344
363
  }
@@ -391,9 +410,7 @@ function buildNestedSelections(params) {
391
410
  if (!targetMeta)
392
411
  continue;
393
412
  const alreadySeen = seen.has(link.target);
394
- if (alreadySeen) {
395
- }
396
- else {
413
+ if (!alreadySeen) {
397
414
  seen.add(link.target);
398
415
  }
399
416
  const scalarFields = queryableFieldNames(targetMeta);
@@ -485,7 +502,7 @@ function buildRecordQuery(meta, recordFieldName, recordArgName, recordArgType, g
485
502
  * Build a GraphQL connection query to fetch a list of records.
486
503
  * Only declares variables ($limit, $offset, $orderBy) that are actually used in the query,
487
504
  * avoiding GraphQL spec §5.8.3 violations from unused variable declarations.
488
- * Excludes Link and Doctype relation fields from the selection set.
505
+ * Excludes Link relation fields and Display fields from the selection set.
489
506
  * @public
490
507
  */
491
508
  function buildListQuery(meta, args, connectionFieldName, orderByTypeName) {
@@ -1 +1 @@
1
- {"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../../../src/registry/actions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAiB,MAAM,UAAU,CAAA;AAI5D;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,GAAG,IAAI,CAE1E;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS,CAElE;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEhD;AAED;;;GAGG;AACH,wBAAgB,aAAa,IAAI,IAAI,CAEpC;AAoID;;;GAGG;AACH,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAIzD,CAAA;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,IAAI,IAAI,CAI9C"}
1
+ {"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../../../src/registry/actions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAI7C;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,GAAG,IAAI,CAE1E;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS,CAElE;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEhD;AAED;;;GAGG;AACH,wBAAgB,aAAa,IAAI,IAAI,CAEpC;AAoID;;;GAGG;AACH,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAIzD,CAAA;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,IAAI,IAAI,CAI9C"}
@@ -94,7 +94,7 @@ const validateFieldTypes = async (args, context) => {
94
94
  * Validate a single field value against its expected type
95
95
  */
96
96
  function validateFieldValue(field, value) {
97
- const { fieldname, fieldtype, cardinality } = field;
97
+ const { fieldname, fieldtype } = field;
98
98
  switch (fieldtype) {
99
99
  case 'Int':
100
100
  if (typeof value !== 'number' || !Number.isInteger(value)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stonecrop/graphql-middleware",
3
- "version": "0.12.1",
3
+ "version": "0.12.3",
4
4
  "type": "module",
5
5
  "types": "./dist/graphql-middleware.d.ts",
6
6
  "exports": {
@@ -17,15 +17,20 @@
17
17
  "graphql": "^16.13.2",
18
18
  "pluralize": "^8.0.0",
19
19
  "postgraphile": "^5.0.1",
20
- "@stonecrop/schema": "0.12.1"
20
+ "@stonecrop/schema": "0.12.3"
21
21
  },
22
22
  "devDependencies": {
23
+ "@eslint/js": "^10.0.1",
23
24
  "@rushstack/heft": "^1.2.17",
24
25
  "@types/node": "^24.12.4",
25
26
  "@types/pluralize": "^0.0.33",
26
27
  "@vitest/coverage-istanbul": "^4.1.5",
27
28
  "@vitest/ui": "^4.1.5",
29
+ "eslint": "^10.3.0",
30
+ "eslint-config-prettier": "^10.1.8",
31
+ "globals": "^17.6.0",
28
32
  "typescript": "^6.0.3",
33
+ "typescript-eslint": "^8.59.1",
29
34
  "vite": "^7.3.2",
30
35
  "vitest": "^4.1.5",
31
36
  "stonecrop-rig": "0.7.0"
@@ -34,6 +39,7 @@
34
39
  "_phase:build": "heft build && vite build && rushx docs",
35
40
  "build": "heft build && vite build && rushx docs",
36
41
  "docs": "bash ../common/scripts/run-docs.sh graphql_middleware",
42
+ "lint": "eslint .",
37
43
  "test": "vitest run --coverage.enabled false",
38
44
  "test:watch": "vitest watch",
39
45
  "test:coverage": "vitest run --coverage",