@stonecrop/graphql-middleware 0.11.2 → 0.11.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/graphql-middleware.d.ts +2 -0
- package/dist/index.js +153 -144
- package/dist/index.js.map +1 -1
- package/dist/plugin/postgraphile.js +14 -6
- package/dist/registry/doctypes.js +9 -1
- package/dist/src/plugin/postgraphile.d.ts.map +1 -1
- package/dist/src/registry/doctypes.d.ts.map +1 -1
- package/dist/src/types/query.d.ts +2 -0
- package/dist/src/types/query.d.ts.map +1 -1
- package/package.json +2 -2
|
@@ -286,6 +286,8 @@ export declare interface MergeNestedResultsParams {
|
|
|
286
286
|
meta: DoctypeMeta;
|
|
287
287
|
/** Lookup function to get doctype metadata by slug */
|
|
288
288
|
getMeta: (slug: string) => DoctypeMeta | undefined;
|
|
289
|
+
/** Function to derive the reverse connection field name from link params */
|
|
290
|
+
reverseConnectionNameFn?: (params: ReverseConnectionParams) => string;
|
|
289
291
|
}
|
|
290
292
|
|
|
291
293
|
/**
|
package/dist/index.js
CHANGED
|
@@ -1,87 +1,90 @@
|
|
|
1
|
-
import { readdirSync as
|
|
2
|
-
import { join as
|
|
3
|
-
import { validateDoctype as E, parseDoctype as I, toPascalCase as
|
|
1
|
+
import { readdirSync as _, statSync as U, readFileSync as H } from "node:fs";
|
|
2
|
+
import { join as P } from "node:path";
|
|
3
|
+
import { validateDoctype as E, parseDoctype as I, toPascalCase as J, snakeToCamel as O } from "@stonecrop/schema";
|
|
4
4
|
import { loadOne as M, object as R, constant as Q, lambda as V } from "postgraphile/grafast";
|
|
5
|
-
import { extendSchema as z, gql as
|
|
6
|
-
import
|
|
7
|
-
const
|
|
8
|
-
class
|
|
5
|
+
import { extendSchema as z, gql as j } from "postgraphile/utils";
|
|
6
|
+
import q from "pluralize";
|
|
7
|
+
const N = /* @__PURE__ */ new Map();
|
|
8
|
+
class A extends Error {
|
|
9
9
|
constructor(t, n) {
|
|
10
|
-
const
|
|
10
|
+
const c = n.map((o) => ` ${o.path.join(".")}: ${o.message}`).join(`
|
|
11
11
|
`);
|
|
12
12
|
super(`Invalid doctype definition in ${t}:
|
|
13
|
-
${
|
|
13
|
+
${c}`), this.file = t, this.errors = n, this.name = "DoctypeValidationError";
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
function G(e, t = {}) {
|
|
17
|
-
const n =
|
|
18
|
-
for (const
|
|
19
|
-
const o =
|
|
20
|
-
|
|
17
|
+
const n = _(e);
|
|
18
|
+
for (const c of n) {
|
|
19
|
+
const o = P(e, c);
|
|
20
|
+
U(o).isDirectory() ? G(o, t) : c.endsWith(".json") && Y(o, t);
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
function Y(e, t) {
|
|
24
|
-
const n =
|
|
25
|
-
let
|
|
24
|
+
const n = H(e, "utf-8");
|
|
25
|
+
let c;
|
|
26
26
|
try {
|
|
27
|
-
|
|
27
|
+
c = JSON.parse(n);
|
|
28
28
|
} catch (s) {
|
|
29
|
-
const
|
|
29
|
+
const i = {
|
|
30
30
|
path: [],
|
|
31
31
|
message: `Invalid JSON: ${s instanceof Error ? s.message : String(s)}`
|
|
32
32
|
};
|
|
33
33
|
if (t.continueOnError) {
|
|
34
|
-
t.onError?.(e, [
|
|
34
|
+
t.onError?.(e, [i]);
|
|
35
35
|
return;
|
|
36
36
|
}
|
|
37
|
-
throw new
|
|
37
|
+
throw new A(e, [i]);
|
|
38
38
|
}
|
|
39
|
-
const o = E(
|
|
39
|
+
const o = E(c);
|
|
40
40
|
if (!o.success) {
|
|
41
41
|
if (t.continueOnError) {
|
|
42
42
|
t.onError?.(e, o.errors);
|
|
43
43
|
return;
|
|
44
44
|
}
|
|
45
|
-
throw new
|
|
45
|
+
throw new A(e, o.errors);
|
|
46
46
|
}
|
|
47
|
-
const r = I(
|
|
48
|
-
|
|
47
|
+
const r = I(c);
|
|
48
|
+
N.set(r.name, r);
|
|
49
49
|
}
|
|
50
50
|
function be(e, t = {}) {
|
|
51
|
-
for (const [n,
|
|
52
|
-
const o = { ...
|
|
51
|
+
for (const [n, c] of Object.entries(e)) {
|
|
52
|
+
const o = { ...c, name: n }, r = E(o);
|
|
53
53
|
if (!r.success) {
|
|
54
54
|
if (t.continueOnError) {
|
|
55
55
|
t.onError?.(n, r.errors);
|
|
56
56
|
continue;
|
|
57
57
|
}
|
|
58
|
-
throw new
|
|
58
|
+
throw new A(n, r.errors);
|
|
59
59
|
}
|
|
60
60
|
const s = I(o);
|
|
61
|
-
|
|
61
|
+
N.set(s.name, s);
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
|
-
function
|
|
65
|
-
|
|
64
|
+
function k(e) {
|
|
65
|
+
const t = N.get(e);
|
|
66
|
+
if (t) return t;
|
|
67
|
+
for (const n of N.values())
|
|
68
|
+
if (n.slug === e) return n;
|
|
66
69
|
}
|
|
67
70
|
function K() {
|
|
68
|
-
return Array.from(
|
|
71
|
+
return Array.from(N.values());
|
|
69
72
|
}
|
|
70
73
|
function Me(e) {
|
|
71
|
-
return
|
|
74
|
+
return N.has(e);
|
|
72
75
|
}
|
|
73
76
|
function Re() {
|
|
74
|
-
|
|
77
|
+
N.clear();
|
|
75
78
|
}
|
|
76
79
|
function Oe() {
|
|
77
80
|
const e = [];
|
|
78
|
-
for (const t of
|
|
79
|
-
t.inherits && !
|
|
81
|
+
for (const t of N.values()) {
|
|
82
|
+
t.inherits && !N.has(t.inherits) && e.push({
|
|
80
83
|
path: [t.name, "inherits"],
|
|
81
84
|
message: `References unknown doctype: ${t.inherits}`
|
|
82
85
|
});
|
|
83
86
|
for (const n of t.fields)
|
|
84
|
-
n.fieldtype === "Link" && typeof n.options == "string" && (
|
|
87
|
+
n.fieldtype === "Link" && typeof n.options == "string" && (N.has(n.options) || e.push({
|
|
85
88
|
path: [t.name, "fields", n.fieldname, "options"],
|
|
86
89
|
message: `Link references unknown doctype: ${n.options}`
|
|
87
90
|
}));
|
|
@@ -98,29 +101,29 @@ function Z(e) {
|
|
|
98
101
|
function Ae(e) {
|
|
99
102
|
return b.has(e);
|
|
100
103
|
}
|
|
101
|
-
function
|
|
104
|
+
function Fe() {
|
|
102
105
|
b.clear();
|
|
103
106
|
}
|
|
104
107
|
const ee = async (e, t) => {
|
|
105
|
-
const [n] = e, { doctype:
|
|
106
|
-
for (const r of
|
|
108
|
+
const [n] = e, { doctype: c } = t, o = [];
|
|
109
|
+
for (const r of c.fields)
|
|
107
110
|
r.required && (n[r.fieldname] === void 0 || n[r.fieldname] === null) && o.push(r.label ?? r.fieldname);
|
|
108
111
|
if (o.length > 0)
|
|
109
112
|
throw new Error(`Missing required fields: ${o.join(", ")}`);
|
|
110
113
|
return { valid: !0 };
|
|
111
114
|
}, te = async (e, t) => {
|
|
112
|
-
const [n] = e, { doctype:
|
|
113
|
-
for (const r of
|
|
115
|
+
const [n] = e, { doctype: c } = t, o = [];
|
|
116
|
+
for (const r of c.fields) {
|
|
114
117
|
const s = n[r.fieldname];
|
|
115
118
|
if (s == null) continue;
|
|
116
|
-
const
|
|
117
|
-
|
|
119
|
+
const i = ne(r, s);
|
|
120
|
+
i && o.push(i);
|
|
118
121
|
}
|
|
119
|
-
if (
|
|
120
|
-
for (const [r, s] of Object.entries(
|
|
121
|
-
const
|
|
122
|
-
if (
|
|
123
|
-
s.cardinality === "noneOrMany" || s.cardinality === "atLeastOne" ? Array.isArray(
|
|
122
|
+
if (c.links)
|
|
123
|
+
for (const [r, s] of Object.entries(c.links)) {
|
|
124
|
+
const i = n[r];
|
|
125
|
+
if (i == null) continue;
|
|
126
|
+
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
127
|
}
|
|
125
128
|
if (o.length > 0)
|
|
126
129
|
throw new Error(`Field type validation failed:
|
|
@@ -129,8 +132,8 @@ ${o.join(`
|
|
|
129
132
|
return { valid: !0 };
|
|
130
133
|
};
|
|
131
134
|
function ne(e, t) {
|
|
132
|
-
const { fieldname: n, fieldtype:
|
|
133
|
-
switch (
|
|
135
|
+
const { fieldname: n, fieldtype: c, cardinality: o } = e;
|
|
136
|
+
switch (c) {
|
|
134
137
|
case "Int":
|
|
135
138
|
if (typeof t != "number" || !Number.isInteger(t))
|
|
136
139
|
return `${n}: expected integer, got ${typeof t}`;
|
|
@@ -171,14 +174,14 @@ const oe = async () => ({ ok: !0 }), re = {
|
|
|
171
174
|
validateFieldTypes: te,
|
|
172
175
|
noop: oe
|
|
173
176
|
};
|
|
174
|
-
function
|
|
177
|
+
function Be() {
|
|
175
178
|
for (const [e, t] of Object.entries(re))
|
|
176
179
|
X(e, t);
|
|
177
180
|
}
|
|
178
|
-
const
|
|
179
|
-
const t = e.inflection?.recordFieldName ?? ie, n = e.inflection?.connectionFieldName ?? ce,
|
|
181
|
+
const De = (e) => {
|
|
182
|
+
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;
|
|
180
183
|
return z(() => ({
|
|
181
|
-
typeDefs:
|
|
184
|
+
typeDefs: j`
|
|
182
185
|
type StonecropFieldMeta {
|
|
183
186
|
fieldname: String!
|
|
184
187
|
fieldtype: String!
|
|
@@ -260,60 +263,65 @@ const Fe = (e) => {
|
|
|
260
263
|
objects: {
|
|
261
264
|
Query: {
|
|
262
265
|
plans: {
|
|
263
|
-
stonecropMeta(
|
|
264
|
-
return V(l, (y) =>
|
|
266
|
+
stonecropMeta(i, { $doctype: l }) {
|
|
267
|
+
return V(l, (y) => k(y) ?? null);
|
|
265
268
|
},
|
|
266
269
|
stonecropAllMeta() {
|
|
267
270
|
return Q(K());
|
|
268
271
|
},
|
|
269
|
-
stonecropRecord(
|
|
272
|
+
stonecropRecord(i, { $doctype: l, $id: y, $options: p }) {
|
|
270
273
|
return M(
|
|
271
274
|
R({ doctype: l, id: y, options: p }),
|
|
272
275
|
async (d) => await Promise.all(
|
|
273
|
-
d.map(async (
|
|
274
|
-
const
|
|
275
|
-
if (!
|
|
276
|
-
throw new Error(`Unknown doctype: ${
|
|
277
|
-
if (!
|
|
278
|
-
throw new Error(`Doctype ${
|
|
279
|
-
const a =
|
|
280
|
-
|
|
276
|
+
d.map(async (f) => {
|
|
277
|
+
const u = k(f.doctype);
|
|
278
|
+
if (!u)
|
|
279
|
+
throw new Error(`Unknown doctype: ${f.doctype}`);
|
|
280
|
+
if (!u.tableName)
|
|
281
|
+
throw new Error(`Doctype ${f.doctype} has no table mapping`);
|
|
282
|
+
const a = f.options ?? {}, h = ue(
|
|
283
|
+
u,
|
|
281
284
|
t,
|
|
282
285
|
o,
|
|
283
286
|
r,
|
|
284
|
-
|
|
287
|
+
k,
|
|
285
288
|
a.includeNested ? {
|
|
286
289
|
includeNested: a.includeNested,
|
|
287
290
|
maxDepth: a.maxDepth
|
|
288
291
|
} : void 0,
|
|
289
292
|
s
|
|
290
293
|
), g = await e.executor.query(h, {
|
|
291
|
-
[o(
|
|
294
|
+
[o(u.tableName)]: f.id
|
|
292
295
|
});
|
|
293
|
-
let S = ge({ result: g, meta:
|
|
294
|
-
a.includeNested && S &&
|
|
295
|
-
|
|
296
|
+
let S = ge({ result: g, meta: u, recordFieldName: t });
|
|
297
|
+
a.includeNested && S && u.links && (S = ye({
|
|
298
|
+
record: S,
|
|
299
|
+
meta: u,
|
|
300
|
+
getMeta: k,
|
|
301
|
+
reverseConnectionNameFn: s
|
|
302
|
+
}));
|
|
303
|
+
const m = Array.isArray(a.includeNested) && u.links ? a.includeNested.filter((w) => !(w in u.links)) : void 0;
|
|
296
304
|
return {
|
|
297
305
|
data: S,
|
|
298
|
-
doctype:
|
|
306
|
+
doctype: f.doctype,
|
|
299
307
|
...m ? { unknownLinks: m } : {}
|
|
300
308
|
};
|
|
301
309
|
})
|
|
302
310
|
)
|
|
303
311
|
);
|
|
304
312
|
},
|
|
305
|
-
stonecropRecords(
|
|
313
|
+
stonecropRecords(i, { $doctype: l, $filters: y, $orderBy: p, $limit: d, $offset: f }) {
|
|
306
314
|
return M(
|
|
307
315
|
R({
|
|
308
316
|
doctype: l,
|
|
309
317
|
filters: y,
|
|
310
318
|
orderBy: p,
|
|
311
319
|
limit: d,
|
|
312
|
-
offset:
|
|
320
|
+
offset: f
|
|
313
321
|
}),
|
|
314
|
-
async (
|
|
315
|
-
|
|
316
|
-
const h =
|
|
322
|
+
async (u) => await Promise.all(
|
|
323
|
+
u.map(async (a) => {
|
|
324
|
+
const h = k(a.doctype);
|
|
317
325
|
if (!h)
|
|
318
326
|
throw new Error(`Unknown doctype: ${a.doctype}`);
|
|
319
327
|
if (!h.tableName)
|
|
@@ -326,7 +334,7 @@ const Fe = (e) => {
|
|
|
326
334
|
orderBy: a.orderBy
|
|
327
335
|
},
|
|
328
336
|
n,
|
|
329
|
-
|
|
337
|
+
c
|
|
330
338
|
), S = await e.executor.query(g, {
|
|
331
339
|
limit: a.limit,
|
|
332
340
|
offset: a.offset,
|
|
@@ -345,7 +353,7 @@ const Fe = (e) => {
|
|
|
345
353
|
},
|
|
346
354
|
Mutation: {
|
|
347
355
|
plans: {
|
|
348
|
-
stonecropAction(
|
|
356
|
+
stonecropAction(i, { $doctype: l, $action: y, $args: p }) {
|
|
349
357
|
return M(
|
|
350
358
|
R({
|
|
351
359
|
doctype: l,
|
|
@@ -353,20 +361,20 @@ const Fe = (e) => {
|
|
|
353
361
|
actionArgs: p
|
|
354
362
|
}),
|
|
355
363
|
async (d) => await Promise.all(
|
|
356
|
-
d.map(async (
|
|
357
|
-
const
|
|
358
|
-
if (!
|
|
364
|
+
d.map(async (f) => {
|
|
365
|
+
const u = k(f.doctype);
|
|
366
|
+
if (!u)
|
|
359
367
|
return {
|
|
360
368
|
success: !1,
|
|
361
369
|
data: null,
|
|
362
|
-
error: `Unknown doctype: ${
|
|
370
|
+
error: `Unknown doctype: ${f.doctype}`
|
|
363
371
|
};
|
|
364
|
-
const a =
|
|
372
|
+
const a = u.workflow?.actions?.[f.action];
|
|
365
373
|
if (!a)
|
|
366
374
|
return {
|
|
367
375
|
success: !1,
|
|
368
376
|
data: null,
|
|
369
|
-
error: `Unknown action: ${
|
|
377
|
+
error: `Unknown action: ${f.action} on ${f.doctype}`
|
|
370
378
|
};
|
|
371
379
|
const h = a.handler, g = Z(h);
|
|
372
380
|
if (!g)
|
|
@@ -376,13 +384,13 @@ const Fe = (e) => {
|
|
|
376
384
|
error: `Handler not registered: ${h}`
|
|
377
385
|
};
|
|
378
386
|
const S = {
|
|
379
|
-
doctype:
|
|
387
|
+
doctype: u,
|
|
380
388
|
executor: e.executor
|
|
381
389
|
};
|
|
382
390
|
try {
|
|
383
391
|
return {
|
|
384
392
|
success: !0,
|
|
385
|
-
data: await g(
|
|
393
|
+
data: await g(f.actionArgs ?? [], S),
|
|
386
394
|
error: null
|
|
387
395
|
};
|
|
388
396
|
} catch (m) {
|
|
@@ -402,14 +410,14 @@ const Fe = (e) => {
|
|
|
402
410
|
}));
|
|
403
411
|
};
|
|
404
412
|
function ie(e) {
|
|
405
|
-
const t =
|
|
406
|
-
return `${
|
|
413
|
+
const t = q.singular(e);
|
|
414
|
+
return `${O(t)}ById`;
|
|
407
415
|
}
|
|
408
416
|
function ce(e) {
|
|
409
|
-
return `all${
|
|
417
|
+
return `all${J(e)}`;
|
|
410
418
|
}
|
|
411
419
|
function se(e) {
|
|
412
|
-
return `${
|
|
420
|
+
return `${J(e)}OrderBy`;
|
|
413
421
|
}
|
|
414
422
|
function ae(e) {
|
|
415
423
|
return "id";
|
|
@@ -417,43 +425,43 @@ function ae(e) {
|
|
|
417
425
|
function le(e) {
|
|
418
426
|
return "UUID!";
|
|
419
427
|
}
|
|
420
|
-
function
|
|
421
|
-
const t =
|
|
428
|
+
function F(e) {
|
|
429
|
+
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);
|
|
422
430
|
return `${n}By${o}Id`;
|
|
423
431
|
}
|
|
424
|
-
function
|
|
432
|
+
function B(e) {
|
|
425
433
|
return e === "noneOrMany" || e === "atLeastOne";
|
|
426
434
|
}
|
|
427
|
-
const
|
|
428
|
-
function
|
|
435
|
+
const C = 50, de = /* @__PURE__ */ new Set(["Link"]);
|
|
436
|
+
function D(e) {
|
|
429
437
|
return e.fields.filter((t) => !de.has(t.fieldtype)).map((t) => t.fieldname).join(`
|
|
430
438
|
`);
|
|
431
439
|
}
|
|
432
440
|
function T(e) {
|
|
433
|
-
return e.fetch !== void 0 ? e.fetch :
|
|
441
|
+
return e.fetch !== void 0 ? e.fetch : B(e.cardinality) ? { method: "sync", limit: C } : { method: "lazy" };
|
|
434
442
|
}
|
|
435
443
|
function fe(e) {
|
|
436
444
|
return e.blockWorkflows !== void 0 ? e.blockWorkflows : T(e).method === "sync";
|
|
437
445
|
}
|
|
438
446
|
function L(e) {
|
|
439
|
-
const { links: t, meta: n, includeSet:
|
|
440
|
-
if (
|
|
447
|
+
const { links: t, meta: n, includeSet: c, getMeta: o, seen: r, depth: s, maxDepth: i, reverseConnectionNameFn: l } = e;
|
|
448
|
+
if (i !== void 0 && s >= i) return "";
|
|
441
449
|
const y = [];
|
|
442
450
|
for (const [p, d] of Object.entries(t)) {
|
|
443
|
-
if (
|
|
444
|
-
const
|
|
445
|
-
if (
|
|
451
|
+
if (i !== void 0 && s >= i) break;
|
|
452
|
+
const f = fe(d), u = d.blockWorkflows === !0;
|
|
453
|
+
if (c && !c.has(p) && !u)
|
|
446
454
|
continue;
|
|
447
455
|
const a = T(d);
|
|
448
|
-
if (
|
|
456
|
+
if (f === !1 || a.method !== "sync" && !u)
|
|
449
457
|
continue;
|
|
450
458
|
const g = o(d.target);
|
|
451
459
|
if (!g) continue;
|
|
452
460
|
const S = r.has(d.target);
|
|
453
461
|
S || r.add(d.target);
|
|
454
|
-
const m =
|
|
462
|
+
const m = D(g);
|
|
455
463
|
let w = "";
|
|
456
|
-
if (!S && g.links && g.tableName && (
|
|
464
|
+
if (!S && g.links && g.tableName && (i === void 0 || s + 1 < i)) {
|
|
457
465
|
const $ = L({
|
|
458
466
|
links: g.links,
|
|
459
467
|
meta: g,
|
|
@@ -461,63 +469,63 @@ function L(e) {
|
|
|
461
469
|
getMeta: o,
|
|
462
470
|
seen: r,
|
|
463
471
|
depth: s + 1,
|
|
464
|
-
maxDepth:
|
|
472
|
+
maxDepth: i,
|
|
465
473
|
reverseConnectionNameFn: l
|
|
466
474
|
});
|
|
467
475
|
$ && (w = `
|
|
468
476
|
` + $), r.delete(d.target);
|
|
469
477
|
}
|
|
470
|
-
const
|
|
471
|
-
if (
|
|
478
|
+
const v = m + w;
|
|
479
|
+
if (B(d.cardinality)) {
|
|
472
480
|
const $ = {
|
|
473
481
|
doctype: n.slug || n.name,
|
|
474
482
|
linkName: p,
|
|
475
483
|
backlink: d.backlink,
|
|
476
484
|
target: d.target
|
|
477
|
-
}, W = l ? l($) :
|
|
485
|
+
}, W = l ? l($) : F($), x = a.method === "sync" && a.limit !== void 0 ? `first: ${a.limit}` : a.method === "sync" ? `first: ${C}` : "";
|
|
478
486
|
y.push(`
|
|
479
|
-
${W}${
|
|
487
|
+
${W}${x ? `(${x})` : ""} {
|
|
480
488
|
nodes {
|
|
481
|
-
${
|
|
489
|
+
${v}
|
|
482
490
|
}
|
|
483
491
|
}`);
|
|
484
492
|
} else
|
|
485
493
|
y.push(`
|
|
486
494
|
${p} {
|
|
487
|
-
${
|
|
495
|
+
${v}
|
|
488
496
|
}`);
|
|
489
497
|
}
|
|
490
498
|
return y.join("");
|
|
491
499
|
}
|
|
492
|
-
function ue(e, t, n,
|
|
493
|
-
const
|
|
494
|
-
let d =
|
|
500
|
+
function ue(e, t, n, c, o, r, s) {
|
|
501
|
+
const i = t(e.tableName), l = n(e.tableName), y = c(e.tableName), p = /* @__PURE__ */ new Set([e.slug || e.name]);
|
|
502
|
+
let d = D(e);
|
|
495
503
|
if (r?.includeNested && e.links) {
|
|
496
|
-
const
|
|
504
|
+
const f = Array.isArray(r.includeNested) ? new Set(r.includeNested) : null, u = L({
|
|
497
505
|
links: e.links,
|
|
498
506
|
meta: e,
|
|
499
|
-
includeSet:
|
|
507
|
+
includeSet: f,
|
|
500
508
|
getMeta: o,
|
|
501
509
|
seen: p,
|
|
502
510
|
depth: 0,
|
|
503
511
|
maxDepth: r.maxDepth,
|
|
504
512
|
reverseConnectionNameFn: s
|
|
505
513
|
});
|
|
506
|
-
|
|
507
|
-
` +
|
|
514
|
+
u && (d += `
|
|
515
|
+
` + u);
|
|
508
516
|
}
|
|
509
517
|
return `
|
|
510
518
|
query GetRecord($${l}: ${y}) {
|
|
511
|
-
${
|
|
519
|
+
${i}(${l}: $${l}) {
|
|
512
520
|
${d}
|
|
513
521
|
}
|
|
514
522
|
}
|
|
515
523
|
`;
|
|
516
524
|
}
|
|
517
|
-
function pe(e, t, n,
|
|
518
|
-
const o =
|
|
519
|
-
t.limit && (
|
|
520
|
-
const y =
|
|
525
|
+
function pe(e, t, n, c) {
|
|
526
|
+
const o = D(e), r = n(e.tableName), s = c(e.tableName), i = [], l = [];
|
|
527
|
+
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"));
|
|
528
|
+
const y = i.length > 0 ? `(${i.join(", ")})` : "", p = l.length > 0 ? `(${l.join(", ")})` : "";
|
|
521
529
|
return `
|
|
522
530
|
query GetRecords${y} {
|
|
523
531
|
${r}${p} {
|
|
@@ -529,30 +537,31 @@ function pe(e, t, n, i) {
|
|
|
529
537
|
`;
|
|
530
538
|
}
|
|
531
539
|
function ye(e) {
|
|
532
|
-
const { record: t, meta: n, getMeta:
|
|
540
|
+
const { record: t, meta: n, getMeta: c, reverseConnectionNameFn: o } = e;
|
|
533
541
|
if (!n.links) return t;
|
|
534
|
-
const
|
|
535
|
-
for (const [
|
|
536
|
-
if (
|
|
537
|
-
if (!i
|
|
538
|
-
const
|
|
542
|
+
const r = { ...t };
|
|
543
|
+
for (const [s, i] of Object.entries(n.links))
|
|
544
|
+
if (B(i.cardinality)) {
|
|
545
|
+
if (!c(i.target)) continue;
|
|
546
|
+
const p = {
|
|
539
547
|
doctype: n.slug || n.name,
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
d
|
|
548
|
+
linkName: s,
|
|
549
|
+
backlink: i.backlink || s,
|
|
550
|
+
target: i.target
|
|
551
|
+
}, d = o ? o(p) : F(p), f = r[d];
|
|
552
|
+
f?.nodes ? (r[s] = f.nodes, delete r[d]) : (r[s] = [], delete r[d]);
|
|
544
553
|
}
|
|
545
|
-
return
|
|
554
|
+
return r;
|
|
546
555
|
}
|
|
547
556
|
function ge(e) {
|
|
548
|
-
const { result: t, meta: n, recordFieldName:
|
|
557
|
+
const { result: t, meta: n, recordFieldName: c } = e, o = c(n.tableName);
|
|
549
558
|
return t[o];
|
|
550
559
|
}
|
|
551
560
|
function me(e) {
|
|
552
|
-
const { result: t, meta: n, connectionFieldName:
|
|
561
|
+
const { result: t, meta: n, connectionFieldName: c } = e, o = c(n.tableName);
|
|
553
562
|
return t[o]?.nodes ?? [];
|
|
554
563
|
}
|
|
555
|
-
const
|
|
564
|
+
const ve = j`
|
|
556
565
|
type StonecropFieldMeta {
|
|
557
566
|
fieldname: String!
|
|
558
567
|
fieldtype: String!
|
|
@@ -626,34 +635,34 @@ const xe = J`
|
|
|
626
635
|
}
|
|
627
636
|
`;
|
|
628
637
|
export {
|
|
629
|
-
|
|
638
|
+
A as DoctypeValidationError,
|
|
630
639
|
de as RELATION_FIELDTYPES,
|
|
631
640
|
pe as buildListQuery,
|
|
632
641
|
ue as buildRecordQuery,
|
|
633
642
|
re as builtinHandlers,
|
|
634
|
-
|
|
643
|
+
Fe as clearHandlers,
|
|
635
644
|
Re as clearRegistry,
|
|
636
|
-
|
|
645
|
+
De as createStonecropPlugin,
|
|
637
646
|
ce as defaultConnectionFieldName,
|
|
638
647
|
se as defaultOrderByTypeName,
|
|
639
648
|
ae as defaultRecordArgName,
|
|
640
649
|
le as defaultRecordArgType,
|
|
641
650
|
ie as defaultRecordFieldName,
|
|
642
|
-
|
|
651
|
+
F as defaultReverseConnectionName,
|
|
643
652
|
me as extractListResult,
|
|
644
653
|
ge as extractSingleResult,
|
|
645
654
|
K as getAllMeta,
|
|
646
655
|
Z as getHandler,
|
|
647
|
-
|
|
656
|
+
k as getMeta,
|
|
648
657
|
Ae as hasHandler,
|
|
649
658
|
Me as hasMeta,
|
|
650
659
|
G as loadDoctypes,
|
|
651
660
|
be as loadDoctypesFromObject,
|
|
652
661
|
ye as mergeNestedResults,
|
|
653
|
-
|
|
654
|
-
|
|
662
|
+
D as queryableFieldNames,
|
|
663
|
+
Be as registerBuiltinHandlers,
|
|
655
664
|
X as registerHandler,
|
|
656
|
-
|
|
665
|
+
ve as typeDefs,
|
|
657
666
|
Oe as validateReferences
|
|
658
667
|
};
|
|
659
668
|
//# 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\treturn doctypeRegistry.get(name)\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 }\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({ record: data as Record<string, unknown>, meta, getMeta })\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\tconst targetPascal = toPascalCase(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() + fkSource.slice(1)\n\treturn `${targetPascal}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? `first: ${DEFAULT_SYNC_LIMIT}`\n\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 } = 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 = 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","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","targetPascal","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;AACD;AAmBO,SAASG,EAAaC,GAAaC,IAA+B,IAAU;AAClF,QAAMC,IAAUC,EAAYH,CAAG;AAE/B,aAAWI,KAASF,GAAS;AAC5B,UAAMG,IAAWC,EAAKN,GAAKI,CAAK;AAGhC,IAFaG,EAASF,CAAQ,EAErB,gBACRN,EAAaM,GAAUJ,CAAO,IACpBG,EAAM,SAAS,OAAO,KAChCI,EAAgBH,GAAUJ,CAAO;AAAA,EAEnC;AACD;AAKA,SAASO,EAAgBC,GAAkBR,GAAoC;AAC9E,QAAMS,IAAUC,EAAaF,GAAU,OAAO;AAC9C,MAAIG;AAEJ,MAAI;AACH,IAAAA,IAAO,KAAK,MAAMF,C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AOoG,EAAOd,CAAe;AAAA,IAE/B;AAGD,SAAOc;AACR;AAMA,SAAShE,GAAoBoB,GAA4C;AACxE,QAAM,EAAE,QAAArF,GAAQ,MAAA6D,GAAM,iBAAAxB,EAAA,IAAoBgD,GACpCgC,IAAYhF,EAAgBwB,EAAK,SAAU;AACjD,SAAQ7D,EAAmCqH,CAAS;AACrD;AAOA,SAAS5C,GAAkBY,GAA4C;AACtE,QAAM,EAAE,QAAArF,GAAQ,MAAA6D,GAAM,qBAAAtB,EAAA,IAAwB8C,GACxCsC,IAAiBpF,EAAoBsB,EAAK,SAAU;AAI1D,SAHoB7D,EAAmC2H,CAAc,GAGlD,SAAS,CAAA;AAC7B;ACpwBO,MAAMQ,KAAWjF;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;"}
|
|
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 }\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? `first: ${DEFAULT_SYNC_LIMIT}`\n\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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D,EAAmC4H,CAAc,GAGlD,SAAS,CAAA;AAC7B;AC5wBO,MAAMQ,KAAWjF;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;"}
|
|
@@ -133,7 +133,12 @@ export const createStonecropPlugin = (options) => {
|
|
|
133
133
|
});
|
|
134
134
|
let data = extractSingleResult({ result, meta, recordFieldName });
|
|
135
135
|
if (recordOptions.includeNested && data && meta.links) {
|
|
136
|
-
data = mergeNestedResults({
|
|
136
|
+
data = mergeNestedResults({
|
|
137
|
+
record: data,
|
|
138
|
+
meta,
|
|
139
|
+
getMeta,
|
|
140
|
+
reverseConnectionNameFn: reverseConnectionName,
|
|
141
|
+
});
|
|
137
142
|
}
|
|
138
143
|
const unknownLinks = Array.isArray(recordOptions.includeNested) && meta.links
|
|
139
144
|
? recordOptions.includeNested.filter((name) => !(name in meta.links))
|
|
@@ -302,12 +307,13 @@ function defaultRecordArgType(_tableName) {
|
|
|
302
307
|
*/
|
|
303
308
|
function defaultReverseConnectionName(params) {
|
|
304
309
|
const targetPlural = pluralize.plural(params.target.replace(/-/g, '_'));
|
|
305
|
-
|
|
310
|
+
// Use camelCase for target (matches PostGraphile Amber convention: recipeTasksByRecipeId)
|
|
311
|
+
const targetCamel = snakeToCamel(targetPlural);
|
|
306
312
|
// Use backlink if provided, otherwise derive from parent table name
|
|
307
313
|
const fkSource = params.backlink || params.doctype;
|
|
308
314
|
// FK column name: uppercase first char, preserve rest of camelCase
|
|
309
|
-
const fkPascal = fkSource.charAt(0).toUpperCase() + fkSource.slice(1);
|
|
310
|
-
return `${
|
|
315
|
+
const fkPascal = fkSource.charAt(0).toUpperCase() + snakeToCamel(fkSource).slice(1);
|
|
316
|
+
return `${targetCamel}By${fkPascal}Id`;
|
|
311
317
|
}
|
|
312
318
|
/**
|
|
313
319
|
* Check if a cardinality represents a "many" relationship
|
|
@@ -519,7 +525,7 @@ function buildListQuery(meta, args, connectionFieldName, orderByTypeName) {
|
|
|
519
525
|
* @public
|
|
520
526
|
*/
|
|
521
527
|
function mergeNestedResults(params) {
|
|
522
|
-
const { record, meta, getMeta } = params;
|
|
528
|
+
const { record, meta, getMeta, reverseConnectionNameFn } = params;
|
|
523
529
|
if (!meta.links)
|
|
524
530
|
return record;
|
|
525
531
|
const merged = { ...record };
|
|
@@ -535,7 +541,9 @@ function mergeNestedResults(params) {
|
|
|
535
541
|
backlink: link.backlink || fieldname,
|
|
536
542
|
target: link.target,
|
|
537
543
|
};
|
|
538
|
-
const connectionField =
|
|
544
|
+
const connectionField = reverseConnectionNameFn
|
|
545
|
+
? reverseConnectionNameFn(reverseParams)
|
|
546
|
+
: defaultReverseConnectionName(reverseParams);
|
|
539
547
|
const connectionResult = merged[connectionField];
|
|
540
548
|
if (connectionResult?.nodes) {
|
|
541
549
|
merged[fieldname] = connectionResult.nodes;
|
|
@@ -98,7 +98,15 @@ export function loadDoctypesFromObject(doctypes, options = {}) {
|
|
|
98
98
|
* @public
|
|
99
99
|
*/
|
|
100
100
|
export function getMeta(name) {
|
|
101
|
-
|
|
101
|
+
const direct = doctypeRegistry.get(name);
|
|
102
|
+
if (direct)
|
|
103
|
+
return direct;
|
|
104
|
+
// Fallback: find by slug (links reference doctypes by slug, not name)
|
|
105
|
+
for (const doctype of doctypeRegistry.values()) {
|
|
106
|
+
if (doctype.slug === name)
|
|
107
|
+
return doctype;
|
|
108
|
+
}
|
|
109
|
+
return undefined;
|
|
102
110
|
}
|
|
103
111
|
/**
|
|
104
112
|
* Get all loaded doctypes
|
|
@@ -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,0BAA0B;QAC1B,OAAO,EAAE,MAAM,CAAA;QACf,6BAA6B;QAC7B,QAAQ,EAAE,MAAM,CAAA;QAChB,yEAAyE;QACzE,QAAQ,CAAC,EAAE,MAAM,CAAA;QACjB,0BAA0B;QAC1B,MAAM,EAAE,MAAM,CAAA;KACd,KAAK,MAAM,CAAA;CACZ;AAED;;;GAGG;AACH,MAAM,WAAW,sBAAsB;IACtC,qCAAqC;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":3,"file":"doctypes.d.ts","sourceRoot":"","sources":["../../../src/registry/doctypes.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAIrE;;;GAGG;AACH,qBAAa,sBAAuB,SAAQ,KAAK;IAE/C,4DAA4D;aAC5C,IAAI,EAAE,MAAM;IAC5B,sCAAsC;aACtB,MAAM,EAAE,eAAe,EAAE;;IAHzC,4DAA4D;IAC5C,IAAI,EAAE,MAAM;IAC5B,sCAAsC;IACtB,MAAM,EAAE,eAAe,EAAE;CAM1C;AAED;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IACnC,2DAA2D;IAC3D,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,kEAAkE;IAClE,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,KAAK,IAAI,CAAA;CAC3D;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,mBAAwB,GAAG,IAAI,CAajF;AAsCD;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,GAAE,mBAAwB,GAAG,IAAI,CAgBjH;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS,
|
|
1
|
+
{"version":3,"file":"doctypes.d.ts","sourceRoot":"","sources":["../../../src/registry/doctypes.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAIrE;;;GAGG;AACH,qBAAa,sBAAuB,SAAQ,KAAK;IAE/C,4DAA4D;aAC5C,IAAI,EAAE,MAAM;IAC5B,sCAAsC;aACtB,MAAM,EAAE,eAAe,EAAE;;IAHzC,4DAA4D;IAC5C,IAAI,EAAE,MAAM;IAC5B,sCAAsC;IACtB,MAAM,EAAE,eAAe,EAAE;CAM1C;AAED;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IACnC,2DAA2D;IAC3D,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,kEAAkE;IAClE,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,KAAK,IAAI,CAAA;CAC3D;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,mBAAwB,GAAG,IAAI,CAajF;AAsCD;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,GAAE,mBAAwB,GAAG,IAAI,CAgBjH;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS,CAQ7D;AAED;;;GAGG;AACH,wBAAgB,UAAU,IAAI,WAAW,EAAE,CAE1C;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE7C;AAED;;;GAGG;AACH,wBAAgB,aAAa,IAAI,IAAI,CAEpC;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,IAAI,eAAe,EAAE,CA0BtD"}
|
|
@@ -102,6 +102,8 @@ export interface MergeNestedResultsParams {
|
|
|
102
102
|
meta: DoctypeMeta;
|
|
103
103
|
/** Lookup function to get doctype metadata by slug */
|
|
104
104
|
getMeta: (slug: string) => DoctypeMeta | undefined;
|
|
105
|
+
/** Function to derive the reverse connection field name from link params */
|
|
106
|
+
reverseConnectionNameFn?: (params: ReverseConnectionParams) => string;
|
|
105
107
|
}
|
|
106
108
|
/**
|
|
107
109
|
* Parameters for extractSingleResult
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../../src/types/query.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AE,WAAW,CAAA;IACjB,iEAAiE;IACjE,eAAe,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,MAAM,CAAA;CAC9C;AAED;;;GAGG;AACH,MAAM,WAAW,uBAAuB;IACvC,2BAA2B;IAC3B,MAAM,EAAE,OAAO,CAAA;IACf,uBAAuB;IACvB,IAAI,EAAE,WAAW,CAAA;IACjB,qEAAqE;IACrE,mBAAmB,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,MAAM,CAAA;CAClD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stonecrop/graphql-middleware",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"types": "./dist/graphql-middleware.d.ts",
|
|
6
6
|
"exports": {
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"graphql": "^16.12.0",
|
|
18
18
|
"pluralize": "^8.0.0",
|
|
19
19
|
"postgraphile": "^5.0.0-rc.7",
|
|
20
|
-
"@stonecrop/schema": "0.11.
|
|
20
|
+
"@stonecrop/schema": "0.11.4"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@rushstack/heft": "^1.2.0",
|