@stonecrop/graphql-middleware 0.18.0 → 0.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,176 +1,170 @@
1
- import { readdirSync as ge, statSync as me, readFileSync as ye } from "node:fs";
2
- import { join as we } from "node:path";
3
- import { validateDoctype as ue, parseDoctype as fe, isActionAllowedInState as Se, camelToSnake as A, resolveLinkRenderMode as oe, pascalToSnake as $e, getRecordIdField as ke } from "@stonecrop/schema";
4
- import { sideEffectWithPgClient as Ee, loadOneWithPgClient as ce } from "@dataplan/pg";
5
- import { object as ee, constant as be, lambda as ve } from "postgraphile/grafast";
6
- import { gql as Re, extendSchema as Ae, wrapPlans as Me } from "postgraphile/utils";
7
- import { PostGraphileAmberPreset as Oe } from "postgraphile/presets/amber";
8
- import { makePgService as rt } from "postgraphile/adaptors/pg";
9
- function V(t) {
10
- const e = [];
11
- for (const o of t)
12
- o.kind === "fieldset" ? e.push(...V(o.schema)) : e.push(o);
13
- return e;
14
- }
15
- function X(t) {
16
- return V(t).filter((e) => e.kind === "field" && !e.computed);
1
+ import { readdirSync as Se, statSync as $e, readFileSync as ke } from "node:fs";
2
+ import { join as Ee } from "node:path";
3
+ import { flattenFields as z, validateDoctype as pe, parseDoctype as ge, isActionAllowedInState as be, pascalToSnake as ve, camelToSnake as R, linkDisplayFieldname as Re, getDisplayField as Ae, getRecordIdField as me, resolveLinkRenderMode as re } from "@stonecrop/schema";
4
+ import { sideEffectWithPgClient as Me, loadOneWithPgClient as ce } from "@dataplan/pg";
5
+ import { object as te, constant as Oe, lambda as Fe } from "postgraphile/grafast";
6
+ import { gql as xe, extendSchema as Te, wrapPlans as Le } from "postgraphile/utils";
7
+ import { PostGraphileAmberPreset as Ne } from "postgraphile/presets/amber";
8
+ import { makePgService as dt } from "postgraphile/adaptors/pg";
9
+ function Z(e) {
10
+ return z(e).filter((t) => t.kind === "field" && !t.computed);
17
11
  }
18
- const P = /* @__PURE__ */ new Map();
19
- class re extends Error {
20
- constructor(e, o) {
12
+ const W = /* @__PURE__ */ new Map();
13
+ class ie extends Error {
14
+ constructor(t, o) {
21
15
  const n = o.map((r) => ` ${r.path.join(".")}: ${r.message}`).join(`
22
16
  `);
23
- super(`Invalid doctype definition in ${e}:
24
- ${n}`), this.file = e, this.errors = o, this.name = "DoctypeValidationError";
17
+ super(`Invalid doctype definition in ${t}:
18
+ ${n}`), this.file = t, this.errors = o, this.name = "DoctypeValidationError";
25
19
  }
26
20
  file;
27
21
  errors;
28
22
  }
29
- function xe(t, e = {}) {
30
- const o = ge(t);
23
+ function De(e, t = {}) {
24
+ const o = Se(e);
31
25
  for (const n of o) {
32
- const r = we(t, n);
33
- me(r).isDirectory() ? xe(r, e) : n.endsWith(".json") && Te(r, e);
26
+ const r = Ee(e, n);
27
+ $e(r).isDirectory() ? De(r, t) : n.endsWith(".json") && Ie(r, t);
34
28
  }
35
29
  }
36
- function Te(t, e) {
37
- const o = ye(t, "utf-8");
30
+ function Ie(e, t) {
31
+ const o = ke(e, "utf-8");
38
32
  let n;
39
33
  try {
40
34
  n = JSON.parse(o);
41
- } catch (l) {
42
- const d = {
35
+ } catch (a) {
36
+ const u = {
43
37
  path: [],
44
- message: `Invalid JSON: ${l instanceof Error ? l.message : String(l)}`
38
+ message: `Invalid JSON: ${a instanceof Error ? a.message : String(a)}`
45
39
  };
46
- if (e.continueOnError) {
47
- e.onError?.(t, [d]);
40
+ if (t.continueOnError) {
41
+ t.onError?.(e, [u]);
48
42
  return;
49
43
  }
50
- throw new re(t, [d]);
44
+ throw new ie(e, [u]);
51
45
  }
52
- const r = ue(n);
46
+ const r = pe(n);
53
47
  if (!r.success) {
54
- if (e.continueOnError) {
55
- e.onError?.(t, r.errors);
48
+ if (t.continueOnError) {
49
+ t.onError?.(e, r.errors);
56
50
  return;
57
51
  }
58
- throw new re(t, r.errors);
52
+ throw new ie(e, r.errors);
59
53
  }
60
- const i = fe(n);
61
- P.set(i.name, i);
54
+ const i = ge(n);
55
+ W.set(i.name, i);
62
56
  }
63
- function Qe(t, e = {}) {
64
- for (const [o, n] of Object.entries(t)) {
65
- const r = { ...typeof n == "object" && n !== null ? n : {}, name: o }, i = ue(r);
57
+ function et(e, t = {}) {
58
+ for (const [o, n] of Object.entries(e)) {
59
+ const r = { ...typeof n == "object" && n !== null ? n : {}, name: o }, i = pe(r);
66
60
  if (!i.success) {
67
- if (e.continueOnError) {
68
- e.onError?.(o, i.errors);
61
+ if (t.continueOnError) {
62
+ t.onError?.(o, i.errors);
69
63
  continue;
70
64
  }
71
- throw new re(o, i.errors);
65
+ throw new ie(o, i.errors);
72
66
  }
73
- const l = fe(r);
74
- P.set(l.name, l);
67
+ const a = ge(r);
68
+ W.set(a.name, a);
75
69
  }
76
70
  }
77
- function I(t) {
78
- const e = P.get(t);
79
- if (e) return e;
80
- for (const o of P.values())
81
- if (o.slug === t) return o;
71
+ function L(e) {
72
+ const t = W.get(e);
73
+ if (t) return t;
74
+ for (const o of W.values())
75
+ if (o.slug === e) return o;
82
76
  }
83
- function he() {
84
- return Array.from(P.values());
77
+ function ye() {
78
+ return Array.from(W.values());
85
79
  }
86
- function Ve(t) {
87
- return P.has(t);
80
+ function tt(e) {
81
+ return W.has(e);
88
82
  }
89
- function ze() {
90
- P.clear();
83
+ function nt() {
84
+ W.clear();
91
85
  }
92
- function Le() {
93
- const t = [];
94
- for (const e of P.values()) {
95
- e.inherits && I(e.inherits) === void 0 && t.push({
96
- path: [e.name, "inherits"],
97
- message: `References unknown doctype: ${e.inherits}`
86
+ function Be() {
87
+ const e = [];
88
+ for (const t of W.values()) {
89
+ t.inherits && L(t.inherits) === void 0 && e.push({
90
+ path: [t.name, "inherits"],
91
+ message: `References unknown doctype: ${t.inherits}`
98
92
  });
99
- const o = V(e.fields);
93
+ const o = z(t.fields);
100
94
  for (const n of o) {
101
95
  if (n.kind !== "field") continue;
102
96
  const r = n.doctype;
103
- r !== void 0 && I(r) === void 0 && t.push({
104
- path: [e.name, "fields", n.fieldname, "doctype"],
97
+ r !== void 0 && L(r) === void 0 && e.push({
98
+ path: [t.name, "fields", n.fieldname, "doctype"],
105
99
  message: `Link references unknown doctype: ${r}`
106
100
  });
107
101
  }
108
- if (e.links) {
109
- const n = new Set(o.map((i) => i.fieldname)), r = new Set(X(e.fields).map((i) => i.fieldname));
110
- for (const [i, l] of Object.entries(e.links)) {
111
- if (I(l.target) === void 0 && t.push({
112
- path: [e.name, "links", i, "target"],
113
- message: `Link references unknown doctype: ${l.target}`
114
- }), l.fetch?.method === "custom") continue;
115
- if (l.cardinality === "noneOrMany" || l.cardinality === "atLeastOne") {
116
- l.backlink || t.push({
117
- path: [e.name, "links", i, "backlink"],
118
- message: `Link "${i}" is ${l.cardinality} but names no \`backlink\`, so the runtime cannot find the target rows and drops the link with no error. Name the field on "${l.target}" that points back to this doctype.`
102
+ if (t.links) {
103
+ const n = new Set(o.map((i) => i.fieldname)), r = new Set(Z(t.fields).map((i) => i.fieldname));
104
+ for (const [i, a] of Object.entries(t.links)) {
105
+ if (L(a.target) === void 0 && e.push({
106
+ path: [t.name, "links", i, "target"],
107
+ message: `Link references unknown doctype: ${a.target}`
108
+ }), a.fetch?.method === "custom") continue;
109
+ if (a.cardinality === "noneOrMany" || a.cardinality === "atLeastOne") {
110
+ a.backlink || e.push({
111
+ path: [t.name, "links", i, "backlink"],
112
+ message: `Link "${i}" is ${a.cardinality} but names no \`backlink\`, so the runtime cannot find the target rows and drops the link with no error. Name the field on "${a.target}" that points back to this doctype.`
119
113
  });
120
114
  continue;
121
115
  }
122
- const d = l.fieldname ?? i;
123
- r.has(d) || t.push({
116
+ const u = a.fieldname ?? i;
117
+ r.has(u) || e.push({
124
118
  // Point at whichever half actually carries the binding: the `fieldname`
125
119
  // property when it is set, otherwise the key itself. Naming `target` here
126
120
  // would send the reader to the one part that resolved correctly.
127
- path: l.fieldname ? [e.name, "links", i, "fieldname"] : [e.name, "links", i],
121
+ path: a.fieldname ? [t.name, "links", i, "fieldname"] : [t.name, "links", i],
128
122
  // Two different repairs, so two different diagnoses: a name nothing declares
129
123
  // is a typo, while a name that resolves to a column-less field is a binding
130
124
  // pointed at the wrong one of several real fields.
131
- message: n.has(d) ? `Link "${i}" binds to field "${d}", which has no database column of its own — it is computed, or a container rather than a value — so there is no foreign key to read and the record read fails on the missing column. Bind the link to the field holding the foreign key.` : `Link "${i}" binds to field "${d}", which this doctype does not declare, so it resolves to null with no error. Declare that field, or set \`fieldname\` to the field holding the foreign key. (A link's key is its fieldname unless \`fieldname\` overrides it.)`
125
+ message: n.has(u) ? `Link "${i}" binds to field "${u}", which has no database column of its own — it is computed, or a container rather than a value — so there is no foreign key to read and the record read fails on the missing column. Bind the link to the field holding the foreign key.` : `Link "${i}" binds to field "${u}", which this doctype does not declare, so it resolves to null with no error. Declare that field, or set \`fieldname\` to the field holding the foreign key. (A link's key is its fieldname unless \`fieldname\` overrides it.)`
132
126
  });
133
127
  }
134
128
  }
135
129
  }
136
- return t;
130
+ return e;
137
131
  }
138
- const ie = /* @__PURE__ */ new Map();
139
- function Ye(t, e) {
140
- ie.set(t, e);
132
+ const ae = /* @__PURE__ */ new Map();
133
+ function ot(e, t) {
134
+ ae.set(e, t);
141
135
  }
142
- function Ne(t) {
143
- return ie.get(t);
136
+ function je(e) {
137
+ return ae.get(e);
144
138
  }
145
- function Xe() {
146
- ie.clear();
139
+ function rt() {
140
+ ae.clear();
147
141
  }
148
- async function De(t, e, o) {
149
- const n = t.label ?? "unknown", r = t.selfTransition === !0, i = r || t.nextState != null;
150
- if (!i && !e.runEffect)
142
+ async function Ce(e, t, o) {
143
+ const n = e.label ?? "unknown", r = e.selfTransition === !0, i = r || e.nextState != null;
144
+ if (!i && !t.runEffect)
151
145
  return {
152
146
  success: !1,
153
147
  data: null,
154
148
  error: `Action "${n}" has no workflow transition and no server-side effect is wired — nothing was executed. Give it a nextState or selfTransition in the doctype, or register a server-side handler for it on the adapter.`
155
149
  };
156
- if (r && !e.writeData && !e.runEffect)
150
+ if (r && !t.writeData && !t.runEffect)
157
151
  return {
158
152
  success: !1,
159
153
  data: null,
160
154
  error: `Action "${n}" persists record data in place, which this backend does not support.`
161
155
  };
162
- const l = (t.allowedStates?.length ?? 0) > 0;
163
- let d;
164
- if (l || i) {
165
- const v = await e.readState();
166
- if (v === null) {
167
- if (r && e.writeData) {
168
- const R = await e.writeData(o ?? {}, !1);
169
- return !R || Object.keys(R).length === 0 ? {
156
+ const a = (e.allowedStates?.length ?? 0) > 0;
157
+ let u;
158
+ if (a || i) {
159
+ const k = await t.readState();
160
+ if (k === null) {
161
+ if (r && t.writeData) {
162
+ const E = await t.writeData(o ?? {}, !1);
163
+ return !E || Object.keys(E).length === 0 ? {
170
164
  success: !1,
171
165
  data: null,
172
166
  error: `Action "${n}" targets a record that does not exist, and the backend did not create it.`
173
- } : { success: !0, data: R, error: null };
167
+ } : { success: !0, data: E, error: null };
174
168
  }
175
169
  return {
176
170
  success: !1,
@@ -178,32 +172,84 @@ async function De(t, e, o) {
178
172
  error: `Action "${n}" targets a record that does not exist — nothing was executed.`
179
173
  };
180
174
  }
181
- d = v ?? "";
175
+ u = k ?? "";
182
176
  }
183
- if (!Se(t, d ?? ""))
177
+ if (!be(e, u ?? ""))
184
178
  return {
185
179
  success: !1,
186
180
  data: null,
187
- error: `Action not allowed from state: ${d || "(unknown)"}`
181
+ error: `Action not allowed from state: ${u || "(unknown)"}`
188
182
  };
189
- let b;
190
- if (e.runEffect)
183
+ let $;
184
+ if (t.runEffect)
191
185
  try {
192
- b = await e.runEffect(d);
193
- } catch (v) {
186
+ $ = await t.runEffect(u);
187
+ } catch (k) {
194
188
  return {
195
189
  success: !1,
196
190
  data: null,
197
- error: `Action "${n}" failed: ${v instanceof Error ? v.message : String(v)}`
191
+ error: `Action "${n}" failed: ${k instanceof Error ? k.message : String(k)}`
198
192
  };
199
193
  }
200
- return r ? { success: !0, data: (e.writeData ? await e.writeData(o ?? {}, !0) : b) ?? null, error: null } : t.nextState == null ? { success: !0, data: b ?? null, error: null } : (await e.writeState(t.nextState), {
194
+ return r ? { success: !0, data: (t.writeData ? await t.writeData(o ?? {}, !0) : $) ?? null, error: null } : e.nextState == null ? { success: !0, data: $ ?? null, error: null } : (await t.writeState(e.nextState), {
201
195
  success: !0,
202
- data: b ?? { state: t.nextState },
196
+ data: $ ?? { state: e.nextState },
203
197
  error: null
204
198
  });
205
199
  }
206
- const Fe = Re`
200
+ function P(e, t) {
201
+ const o = t?.[e] ?? ve(e), n = o.indexOf(".");
202
+ return n > 0 ? `"${o.slice(0, n)}"."${o.slice(n + 1)}"` : `"${o}"`;
203
+ }
204
+ function de(e) {
205
+ if (!(e == null || typeof e == "object")) {
206
+ if (typeof e == "string") return e === "" ? void 0 : e;
207
+ if (typeof e == "number" || typeof e == "boolean" || typeof e == "bigint")
208
+ return String(e);
209
+ }
210
+ }
211
+ function Pe(e, t) {
212
+ const o = [];
213
+ for (const n of z(e.fields)) {
214
+ if (n.kind !== "field" || !n.doctype) continue;
215
+ const r = L(n.doctype);
216
+ if (!r) continue;
217
+ const i = Ae(r.fields, r.displayField);
218
+ i && o.push({
219
+ fieldname: n.fieldname,
220
+ displayField: i.fieldname,
221
+ targetPkFieldname: me(r.fields),
222
+ targetTable: P(r.name, t)
223
+ });
224
+ }
225
+ return o;
226
+ }
227
+ async function ue(e, t, o, n, r) {
228
+ const i = Pe(t, n);
229
+ i.length === 0 || o.length === 0 || await Promise.all(
230
+ i.map(async (a) => {
231
+ const u = /* @__PURE__ */ new Set();
232
+ for (const y of o) {
233
+ const f = de(y[a.fieldname]);
234
+ f !== void 0 && u.add(f);
235
+ }
236
+ if (u.size === 0) return;
237
+ const $ = R(a.targetPkFieldname), k = R(a.displayField), E = k !== a.displayField ? `"${k}" AS "${a.displayField}"` : `"${a.displayField}"`, { rows: h } = await r(e, {
238
+ text: `SELECT "${$}" AS "${a.targetPkFieldname}", ${E} FROM ${a.targetTable} WHERE "${$}"::text = ANY($1::text[])`,
239
+ values: [Array.from(u)]
240
+ }), m = /* @__PURE__ */ new Map();
241
+ for (const y of h)
242
+ m.set(String(y[a.targetPkFieldname]), y[a.displayField]);
243
+ for (const y of o) {
244
+ const f = de(y[a.fieldname]);
245
+ if (f === void 0) continue;
246
+ const s = m.get(f);
247
+ s == null || s === "" || (y[Re(a.fieldname)] = s);
248
+ }
249
+ })
250
+ );
251
+ }
252
+ const We = xe`
207
253
  type StonecropFieldMeta {
208
254
  kind: String!
209
255
  fieldname: String!
@@ -247,6 +293,7 @@ const Fe = Re`
247
293
  type StonecropDoctypeMeta {
248
294
  name: String!
249
295
  slug: String
296
+ displayField: String
250
297
  fields: [StonecropFieldMeta!]!
251
298
  workflow: StonecropWorkflowMeta
252
299
  inherits: String
@@ -313,186 +360,191 @@ const Fe = Re`
313
360
  stonecropAction(doctype: String!, action: String!, args: JSON): StonecropActionResult!
314
361
  }
315
362
  `;
316
- class le extends Error {
317
- constructor(e) {
318
- super(e.error ?? "Action failed"), this.outcome = e, this.name = "ActionRolledBack";
363
+ class fe extends Error {
364
+ constructor(t) {
365
+ super(t.error ?? "Action failed"), this.outcome = t, this.name = "ActionRolledBack";
319
366
  }
320
367
  outcome;
321
368
  }
322
- const de = "__stonecropLinkFk_", Q = "status", Ze = (t = {}) => {
323
- const e = t.debug ? (n, r) => (console.log(`[@stonecrop/graphql-middleware] ${r.text}`, r.values ?? []), n.query(r)) : (n, r) => n.query(r), o = t.defaultRecordLimit === void 0 ? 200 : t.defaultRecordLimit;
324
- return Ae((n) => {
369
+ const he = "__stonecropLinkFk_", Q = "status", it = (e = {}) => {
370
+ const t = e.debug ? (n, r) => (console.log(`[@stonecrop/graphql-middleware] ${r.text}`, r.values ?? []), n.query(r)) : (n, r) => n.query(r), o = e.defaultRecordLimit === void 0 ? 200 : e.defaultRecordLimit;
371
+ return Te((n) => {
325
372
  const r = n.input?.pgRegistry?.pgExecutors, i = r ? Object.values(r)[0] : void 0;
326
373
  if (!i)
327
374
  throw new Error("StonecropPlugin: no pgExecutors found — ensure pgServices is configured");
328
- return t.actionHandlers && Be(t.actionHandlers), je(), {
329
- typeDefs: Fe,
375
+ return e.actionHandlers && qe(e.actionHandlers), Ue(), {
376
+ typeDefs: We,
330
377
  objects: {
331
378
  Query: {
332
379
  plans: {
333
- stonecropMeta(l, { $doctype: d }) {
334
- return ve(d, (b) => I(String(b)) ?? null);
380
+ stonecropMeta(a, { $doctype: u }) {
381
+ return Fe(u, ($) => L(String($)) ?? null);
335
382
  },
336
383
  stonecropAllMeta() {
337
- return be(he());
384
+ return Oe(ye());
338
385
  },
339
- stonecropRecord(l, { $doctype: d, $id: b, $options: v }) {
386
+ stonecropRecord(a, { $doctype: u, $id: $, $options: k }) {
340
387
  return ce(
341
388
  i,
342
- ee({ doctype: d, id: b, options: v }),
343
- async (R, h) => {
344
- const w = /* @__PURE__ */ new Map();
345
- for (let g = 0; g < h.length; g++) {
346
- const c = String(h[g].doctype);
347
- w.has(c) || w.set(c, []), w.get(c).push(g);
389
+ te({ doctype: u, id: $, options: k }),
390
+ async (E, h) => {
391
+ const m = /* @__PURE__ */ new Map();
392
+ for (let f = 0; f < h.length; f++) {
393
+ const s = String(h[f].doctype);
394
+ m.has(s) || m.set(s, []), m.get(s).push(f);
348
395
  }
349
- const M = Array.from({ length: h.length });
350
- for (const [g, c] of w) {
351
- const m = I(g);
352
- if (!m) {
353
- for (const a of c) M[a] = { data: null, doctype: g };
396
+ const y = Array.from({ length: h.length });
397
+ for (const [f, s] of m) {
398
+ const w = L(f);
399
+ if (!w) {
400
+ for (const c of s) y[c] = { data: null, doctype: f };
354
401
  continue;
355
402
  }
356
- const p = te(m);
357
- if (!p) throw ne(g);
358
- const B = A(p.fieldname), H = Y(m), O = c.map((a) => String(h[a].id)), D = new Map(V(m.fields).map((a) => [a.fieldname, a])), L = [];
359
- for (const [a, f] of Object.entries(m.links ?? {})) {
360
- if (f.cardinality === "noneOrMany" || f.cardinality === "atLeastOne") continue;
361
- const y = f.fieldname ?? a;
362
- oe(f, D.get(y)?.component) !== "inline" && L.push({ fieldname: y, alias: `${de}${y}` });
403
+ const g = ne(w);
404
+ if (!g) throw oe(f);
405
+ const I = R(g.fieldname), q = X(w), F = s.map((c) => String(h[c].id)), N = new Map(z(w.fields).map((c) => [c.fieldname, c])), T = [];
406
+ for (const [c, p] of Object.entries(w.links ?? {})) {
407
+ if (p.cardinality === "noneOrMany" || p.cardinality === "atLeastOne") continue;
408
+ const M = p.fieldname ?? c;
409
+ re(p, N.get(M)?.component) !== "inline" && T.push({ fieldname: M, alias: `${he}${M}` });
363
410
  }
364
- const q = [
365
- H,
366
- ...L.map(({ fieldname: a, alias: f }) => `"${A(a)}" AS "${f}"`)
367
- ].filter(Boolean).join(", "), { rows: s } = await e(R, {
368
- text: `SELECT ${q} FROM ${W(m.name, t.tables)} WHERE "${B}"::text = ANY($1::text[])`,
369
- values: [O]
370
- }), $ = new Map(s.map((a) => [String(a[p.fieldname]), a]));
371
- if (s.length !== $.size)
411
+ const U = [
412
+ q,
413
+ ...T.map(({ fieldname: c, alias: p }) => `"${R(c)}" AS "${p}"`)
414
+ ].filter(Boolean).join(", "), { rows: l } = await t(E, {
415
+ text: `SELECT ${U} FROM ${P(w.name, e.tables)} WHERE "${I}"::text = ANY($1::text[])`,
416
+ values: [F]
417
+ }), b = new Map(l.map((c) => [String(c[g.fieldname]), c]));
418
+ if (l.length !== b.size)
372
419
  throw new Error(
373
- `Doctype "${g}" declares "${p.fieldname}" as its identity, but that column is not unique in ${W(m.name, t.tables)} — ${s.length} rows matched ${$.size} distinct values, so a lookup cannot say which record it means. Declare a field that uniquely identifies a record, or add a unique constraint.`
420
+ `Doctype "${f}" declares "${g.fieldname}" as its identity, but that column is not unique in ${P(w.name, e.tables)} — ${l.length} rows matched ${b.size} distinct values, so a lookup cannot say which record it means. Declare a field that uniquely identifies a record, or add a unique constraint.`
374
421
  );
375
- for (const a of c) {
376
- const f = String(h[a].id), y = $.get(f);
377
- if (!y) {
378
- M[a] = { data: null, doctype: g };
422
+ const S = [];
423
+ for (const c of s) {
424
+ const p = String(h[c].id), M = b.get(p);
425
+ if (!M) {
426
+ y[c] = { data: null, doctype: f };
379
427
  continue;
380
428
  }
381
- const k = { ...y }, u = [], E = h[a].options ?? {}, N = E.includeNested === !0, S = Array.isArray(E.includeNested) ? new Set(E.includeNested) : null;
382
- if (m.links)
383
- for (const [x, T] of Object.entries(m.links)) {
384
- const j = T.fieldname ?? x, J = T.fetch, Z = T.cardinality === "noneOrMany" || T.cardinality === "atLeastOne", se = J?.method ?? (Z ? "sync" : "lazy"), pe = J?.method === "sync" ? J.limit : void 0, G = Z ? pe ?? o : void 0;
385
- if (!(N || (S ? S.has(x) : se === "sync"))) continue;
386
- if (se === "custom" && J?.method === "custom") {
387
- const _ = J.handler, C = Ne(_);
388
- C && (k[j] = await C(R, k, T));
429
+ const d = { ...M };
430
+ S.push(d);
431
+ const v = [], O = h[c].options ?? {}, A = O.includeNested === !0, x = Array.isArray(O.includeNested) ? new Set(O.includeNested) : null;
432
+ if (w.links)
433
+ for (const [B, D] of Object.entries(w.links)) {
434
+ const j = D.fieldname ?? B, K = D.fetch, ee = D.cardinality === "noneOrMany" || D.cardinality === "atLeastOne", se = K?.method ?? (ee ? "sync" : "lazy"), we = K?.method === "sync" ? K.limit : void 0, V = ee ? we ?? o : void 0;
435
+ if (!(A || (x ? x.has(B) : se === "sync"))) continue;
436
+ if (se === "custom" && K?.method === "custom") {
437
+ const J = K.handler, C = je(J);
438
+ C && (d[j] = await C(E, d, D));
389
439
  continue;
390
440
  }
391
- if (oe(T, D.get(j)?.component) === "inline") continue;
392
- const U = I(T.target);
393
- if (!U) continue;
394
- const ae = Y(U);
395
- if (Z) {
396
- if (!T.backlink) continue;
397
- const _ = A(T.backlink);
398
- let C = `SELECT ${ae} FROM ${W(U.name, t.tables)} WHERE "${_}"::text = $1`;
399
- const z = [f];
400
- G != null && (C += " LIMIT $2", z.push(G + 1));
401
- const { rows: K } = await e(R, {
441
+ if (re(D, N.get(j)?.component) === "inline") continue;
442
+ const _ = L(D.target);
443
+ if (!_) continue;
444
+ const le = X(_);
445
+ if (ee) {
446
+ if (!D.backlink) continue;
447
+ const J = R(D.backlink);
448
+ let C = `SELECT ${le} FROM ${P(_.name, e.tables)} WHERE "${J}"::text = $1`;
449
+ const Y = [p];
450
+ V != null && (C += " LIMIT $2", Y.push(V + 1));
451
+ const { rows: G } = await t(E, {
402
452
  text: C,
403
- values: z
453
+ values: Y
404
454
  });
405
- G != null && K.length > G ? (u.push(j), k[j] = K.slice(0, G)) : k[j] = K;
455
+ V != null && G.length > V ? (v.push(j), d[j] = G.slice(0, V)) : d[j] = G;
406
456
  } else {
407
- const _ = k[`${de}${j}`];
408
- if (_ == null) {
409
- k[j] = null;
457
+ const J = d[`${he}${j}`];
458
+ if (J == null) {
459
+ d[j] = null;
410
460
  continue;
411
461
  }
412
- const C = te(U);
413
- if (!C) throw ne(U.name);
414
- const z = A(C.fieldname), { rows: K } = await e(R, {
415
- text: `SELECT ${ae} FROM ${W(U.name, t.tables)} WHERE "${z}" = $1`,
416
- values: [_]
462
+ const C = ne(_);
463
+ if (!C) throw oe(_.name);
464
+ const Y = R(C.fieldname), { rows: G } = await t(E, {
465
+ text: `SELECT ${le} FROM ${P(_.name, e.tables)} WHERE "${Y}" = $1`,
466
+ values: [J]
417
467
  });
418
- k[j] = K[0] ?? null;
468
+ d[j] = G[0] ?? null;
419
469
  }
420
470
  }
421
- for (const { alias: x } of L) delete k[x];
422
- const F = S && m.links ? [...S].filter((x) => !(x in m.links)) : void 0;
423
- M[a] = {
424
- data: k,
425
- doctype: g,
426
- unknownLinks: F?.length ? F : void 0,
427
- truncatedLinks: u.length ? u : void 0
471
+ for (const { alias: B } of T) delete d[B];
472
+ const H = x && w.links ? [...x].filter((B) => !(B in w.links)) : void 0;
473
+ y[c] = {
474
+ data: d,
475
+ doctype: f,
476
+ unknownLinks: H?.length ? H : void 0,
477
+ truncatedLinks: v.length ? v : void 0
428
478
  };
429
479
  }
480
+ await ue(E, w, S, e.tables, t);
430
481
  }
431
- return M;
482
+ return y;
432
483
  }
433
484
  );
434
485
  },
435
- stonecropRecords(l, { $doctype: d, $filters: b, $orderBy: v, $limit: R, $offset: h, $includeTotal: w }) {
486
+ stonecropRecords(a, { $doctype: u, $filters: $, $orderBy: k, $limit: E, $offset: h, $includeTotal: m }) {
436
487
  return ce(
437
488
  i,
438
- ee({
439
- doctype: d,
440
- filters: b,
441
- orderBy: v,
442
- limit: R,
489
+ te({
490
+ doctype: u,
491
+ filters: $,
492
+ orderBy: k,
493
+ limit: E,
443
494
  offset: h,
444
- includeTotal: w
495
+ includeTotal: m
445
496
  }),
446
- async (M, g) => await Promise.all(
447
- g.map(async (c) => {
448
- const m = String(c.doctype), p = I(m);
449
- if (!p)
450
- return { data: [], doctype: m, hasMore: !1, count: c.includeTotal === !0 ? 0 : null };
451
- const B = new Set(V(p.fields).map((u) => u.fieldname)), H = Y(p), O = [], D = [];
452
- if (c.filters != null)
453
- for (const [u, E] of Object.entries(c.filters)) {
454
- if (!B.has(u))
455
- throw new Error(`Unknown filter field: ${u} for doctype ${p.name}`);
456
- O.push(E), D.push(`"${A(u)}" = $${O.length}`);
497
+ async (y, f) => await Promise.all(
498
+ f.map(async (s) => {
499
+ const w = String(s.doctype), g = L(w);
500
+ if (!g)
501
+ return { data: [], doctype: w, hasMore: !1, count: s.includeTotal === !0 ? 0 : null };
502
+ const I = new Set(z(g.fields).map((d) => d.fieldname)), q = X(g), F = [], N = [];
503
+ if (s.filters != null)
504
+ for (const [d, v] of Object.entries(s.filters)) {
505
+ if (!I.has(d))
506
+ throw new Error(`Unknown filter field: ${d} for doctype ${g.name}`);
507
+ F.push(v), N.push(`"${R(d)}" = $${F.length}`);
457
508
  }
458
- const L = D.length > 0 ? ` WHERE ${D.join(" AND ")}` : "";
459
- let q = "";
460
- if (c.orderBy != null) {
461
- if (typeof c.orderBy != "string")
462
- throw new Error(`Invalid orderBy: expected string, got ${typeof c.orderBy}`);
463
- const u = c.orderBy, E = u.lastIndexOf("_");
464
- if (E <= 0)
465
- throw new Error(`Invalid orderBy format: "${u}". Expected FIELD_ASC or FIELD_DESC`);
466
- const N = u.slice(E + 1).toUpperCase();
467
- if (N !== "ASC" && N !== "DESC")
468
- throw new Error(`Invalid orderBy direction: "${N}". Must be ASC or DESC`);
469
- const S = u.slice(0, E);
470
- if (!B.has(S))
471
- throw new Error(`Unknown orderBy field: "${S}" for doctype ${p.name}`);
472
- q = ` ORDER BY "${A(S)}" ${N}`;
509
+ const T = N.length > 0 ? ` WHERE ${N.join(" AND ")}` : "";
510
+ let U = "";
511
+ if (s.orderBy != null) {
512
+ if (typeof s.orderBy != "string")
513
+ throw new Error(`Invalid orderBy: expected string, got ${typeof s.orderBy}`);
514
+ const d = s.orderBy, v = d.lastIndexOf("_");
515
+ if (v <= 0)
516
+ throw new Error(`Invalid orderBy format: "${d}". Expected FIELD_ASC or FIELD_DESC`);
517
+ const O = d.slice(v + 1).toUpperCase();
518
+ if (O !== "ASC" && O !== "DESC")
519
+ throw new Error(`Invalid orderBy direction: "${O}". Must be ASC or DESC`);
520
+ const A = d.slice(0, v);
521
+ if (!I.has(A))
522
+ throw new Error(`Unknown orderBy field: "${A}" for doctype ${g.name}`);
523
+ U = ` ORDER BY "${R(A)}" ${O}`;
473
524
  }
474
- if (c.limit != null && typeof c.limit != "number")
475
- throw new Error(`Invalid limit: expected number, got ${typeof c.limit}`);
476
- const s = c.limit ?? o;
477
- let $ = "";
478
- s != null && (O.push(s + 1), $ += ` LIMIT $${O.length}`), c.offset != null && (O.push(c.offset), $ += ` OFFSET $${O.length}`);
479
- const { rows: a } = await e(M, {
480
- text: `SELECT ${H} FROM ${W(p.name, t.tables)}${L}${q}${$}`,
481
- values: O
482
- }), f = s != null && a.length > s, y = f ? a.slice(0, s ?? a.length) : a;
483
- let k = null;
484
- if (c.includeTotal === !0) {
485
- const u = [], E = [];
486
- if (c.filters != null)
487
- for (const [F, x] of Object.entries(c.filters))
488
- B.has(F) && (u.push(x), E.push(`"${A(F)}" = $${u.length}`));
489
- const N = E.length > 0 ? ` WHERE ${E.join(" AND ")}` : "", { rows: S } = await e(M, {
490
- text: `SELECT COUNT(*) AS row_count FROM ${W(p.name, t.tables)}${N}`,
491
- values: u
525
+ if (s.limit != null && typeof s.limit != "number")
526
+ throw new Error(`Invalid limit: expected number, got ${typeof s.limit}`);
527
+ const l = s.limit ?? o;
528
+ let b = "";
529
+ l != null && (F.push(l + 1), b += ` LIMIT $${F.length}`), s.offset != null && (F.push(s.offset), b += ` OFFSET $${F.length}`);
530
+ const { rows: S } = await t(y, {
531
+ text: `SELECT ${q} FROM ${P(g.name, e.tables)}${T}${U}${b}`,
532
+ values: F
533
+ }), c = l != null && S.length > l, p = [...c ? S.slice(0, l ?? S.length) : S];
534
+ await ue(y, g, p, e.tables, t);
535
+ let M = null;
536
+ if (s.includeTotal === !0) {
537
+ const d = [], v = [];
538
+ if (s.filters != null)
539
+ for (const [x, H] of Object.entries(s.filters))
540
+ I.has(x) && (d.push(H), v.push(`"${R(x)}" = $${d.length}`));
541
+ const O = v.length > 0 ? ` WHERE ${v.join(" AND ")}` : "", { rows: A } = await t(y, {
542
+ text: `SELECT COUNT(*) AS row_count FROM ${P(g.name, e.tables)}${O}`,
543
+ values: d
492
544
  });
493
- k = parseInt(S[0]?.row_count ?? "0", 10);
545
+ M = parseInt(A[0]?.row_count ?? "0", 10);
494
546
  }
495
- return { data: y, doctype: m, hasMore: f, count: k };
547
+ return { data: p, doctype: w, hasMore: c, count: M };
496
548
  })
497
549
  )
498
550
  );
@@ -501,67 +553,67 @@ const de = "__stonecropLinkFk_", Q = "status", Ze = (t = {}) => {
501
553
  },
502
554
  Mutation: {
503
555
  plans: {
504
- stonecropAction(l, { $doctype: d, $action: b, $args: v }) {
505
- return Ee(
556
+ stonecropAction(a, { $doctype: u, $action: $, $args: k }) {
557
+ return Me(
506
558
  i,
507
- ee({ doctype: d, action: b, actionArgs: v }),
508
- async (R, h) => {
509
- const w = I(String(h.doctype));
510
- if (!w)
559
+ te({ doctype: u, action: $, actionArgs: k }),
560
+ async (E, h) => {
561
+ const m = L(String(h.doctype));
562
+ if (!m)
511
563
  return {
512
564
  success: !1,
513
565
  data: null,
514
566
  error: `Unknown doctype: ${h.doctype}`
515
567
  };
516
- const M = w.workflow?.actions?.[h.action];
517
- if (!M)
568
+ const y = m.workflow?.actions?.[h.action];
569
+ if (!y)
518
570
  return {
519
571
  success: !1,
520
572
  data: null,
521
573
  error: `Unknown action: ${h.action} on ${h.doctype}`
522
574
  };
523
- const g = W(w.name, t.tables), c = () => {
524
- const s = te(w);
525
- if (!s) throw ne(String(h.doctype));
526
- return A(s.fieldname);
527
- }, m = Array.isArray(h.actionArgs) ? h.actionArgs : [], p = m[0]?.id, B = m[0]?.data ?? {}, H = t.actionHandlers?.[w.name]?.[String(h.action)], O = new Map(
528
- X(w.fields).filter((s) => A(s.fieldname) !== Q).map((s) => [s.fieldname, s])
529
- ), D = X(w.fields).some(
530
- (s) => A(s.fieldname) === Q
531
- ), L = [], q = (s) => {
532
- const $ = [], a = [];
533
- for (const [f, y] of Object.entries(s)) {
534
- if (!O.has(f)) {
535
- L.push(f);
575
+ const f = P(m.name, e.tables), s = () => {
576
+ const l = ne(m);
577
+ if (!l) throw oe(String(h.doctype));
578
+ return R(l.fieldname);
579
+ }, w = Array.isArray(h.actionArgs) ? h.actionArgs : [], g = w[0]?.id, I = w[0]?.data ?? {}, q = e.actionHandlers?.[m.name]?.[String(h.action)], F = new Map(
580
+ Z(m.fields).filter((l) => R(l.fieldname) !== Q).map((l) => [l.fieldname, l])
581
+ ), N = Z(m.fields).some(
582
+ (l) => R(l.fieldname) === Q
583
+ ), T = [], U = (l) => {
584
+ const b = [], S = [];
585
+ for (const [c, p] of Object.entries(l)) {
586
+ if (!F.has(c)) {
587
+ T.push(c);
536
588
  continue;
537
589
  }
538
- if (y !== null && typeof y == "object") {
539
- L.push(f);
590
+ if (p !== null && typeof p == "object") {
591
+ T.push(c);
540
592
  continue;
541
593
  }
542
- $.push(A(f)), a.push(y);
594
+ b.push(R(c)), S.push(p);
543
595
  }
544
- return { cols: $, values: a };
596
+ return { cols: b, values: S };
545
597
  };
546
598
  try {
547
- return await R.withTransaction(async (s) => {
548
- const $ = await De(
549
- M,
599
+ return await E.withTransaction(async (l) => {
600
+ const b = await Ce(
601
+ y,
550
602
  {
551
603
  readState: async () => {
552
- if (p == null) return null;
553
- const a = D ? `"${Q}"` : `"${c()}"`, { rows: f } = await e(s, {
554
- text: `SELECT ${a} FROM ${g} WHERE "${c()}"::text = $1 FOR UPDATE`,
555
- values: [String(p)]
604
+ if (g == null) return null;
605
+ const S = N ? `"${Q}"` : `"${s()}"`, { rows: c } = await t(l, {
606
+ text: `SELECT ${S} FROM ${f} WHERE "${s()}"::text = $1 FOR UPDATE`,
607
+ values: [String(g)]
556
608
  });
557
- if (f.length === 0) return null;
558
- if (D)
559
- return f[0][Q] ?? void 0;
609
+ if (c.length === 0) return null;
610
+ if (N)
611
+ return c[0][Q] ?? void 0;
560
612
  },
561
- writeState: async (a) => {
562
- await e(s, {
563
- text: `UPDATE ${g} SET "${Q}" = $1 WHERE "${c()}"::text = $2`,
564
- values: [a, String(p)]
613
+ writeState: async (S) => {
614
+ await t(l, {
615
+ text: `UPDATE ${f} SET "${Q}" = $1 WHERE "${s()}"::text = $2`,
616
+ values: [S, String(g)]
565
617
  });
566
618
  },
567
619
  // The upsert, and the only write path for record data. `exists`
@@ -573,53 +625,53 @@ const de = "__stonecropLinkFk_", Q = "status", Ze = (t = {}) => {
573
625
  // `itemId` would receive `item_id`, find no identity, and file a
574
626
  // created record nowhere — which is that exact bug, already once
575
627
  // shipped and patched downstream.
576
- writeData: async (a, f) => {
577
- const { cols: y, values: k } = q(a), u = Y(w);
578
- if (!f) {
579
- if (p != null)
628
+ writeData: async (S, c) => {
629
+ const { cols: p, values: M } = U(S), d = X(m);
630
+ if (!c) {
631
+ if (g != null)
580
632
  throw new Error(
581
- `Action "${M.label ?? h.action}" targets ${w.name} "${String(p)}", which no longer exists. Nothing was created — a record dispatched with an identity is an update, and creating one is what dispatching no identity means.`
633
+ `Action "${y.label ?? h.action}" targets ${m.name} "${String(g)}", which no longer exists. Nothing was created — a record dispatched with an identity is an update, and creating one is what dispatching no identity means.`
582
634
  );
583
- const S = y.length ? `INSERT INTO ${g} (${y.map((x) => `"${x}"`).join(", ")}) VALUES (${y.map((x, T) => `$${T + 1}`).join(", ")}) RETURNING ${u}` : `INSERT INTO ${g} DEFAULT VALUES RETURNING ${u}`, { rows: F } = await e(s, { text: S, values: k });
584
- return F[0] ?? {};
635
+ const A = p.length ? `INSERT INTO ${f} (${p.map((H) => `"${H}"`).join(", ")}) VALUES (${p.map((H, B) => `$${B + 1}`).join(", ")}) RETURNING ${d}` : `INSERT INTO ${f} DEFAULT VALUES RETURNING ${d}`, { rows: x } = await t(l, { text: A, values: M });
636
+ return x[0] ?? {};
585
637
  }
586
- if (y.length === 0) {
587
- const { rows: S } = await e(s, {
588
- text: `SELECT ${u} FROM ${g} WHERE "${c()}"::text = $1`,
589
- values: [String(p)]
638
+ if (p.length === 0) {
639
+ const { rows: A } = await t(l, {
640
+ text: `SELECT ${d} FROM ${f} WHERE "${s()}"::text = $1`,
641
+ values: [String(g)]
590
642
  });
591
- return S[0] ?? {};
643
+ return A[0] ?? {};
592
644
  }
593
- const E = y.map((S, F) => `"${S}" = $${F + 1}`).join(", "), { rows: N } = await e(s, {
594
- text: `UPDATE ${g} SET ${E} WHERE "${c()}"::text = $${y.length + 1} RETURNING ${u}`,
595
- values: [...k, String(p)]
645
+ const v = p.map((A, x) => `"${A}" = $${x + 1}`).join(", "), { rows: O } = await t(l, {
646
+ text: `UPDATE ${f} SET ${v} WHERE "${s()}"::text = $${p.length + 1} RETURNING ${d}`,
647
+ values: [...M, String(g)]
596
648
  });
597
- return N[0] ?? {};
649
+ return O[0] ?? {};
598
650
  },
599
- runEffect: H ? (a) => H({
600
- pgClient: s,
651
+ runEffect: q ? (S) => q({
652
+ pgClient: l,
601
653
  doctype: String(h.doctype),
602
654
  action: String(h.action),
603
- meta: w,
604
- recordId: p,
605
- data: B,
606
- args: m,
607
- currentState: a
655
+ meta: m,
656
+ recordId: g,
657
+ data: I,
658
+ args: w,
659
+ currentState: S
608
660
  }) : void 0
609
661
  },
610
662
  // The patch a self-transition persists. This adapter never passed it, which
611
663
  // was moot while it had no `writeData` — nothing consumed it. Wiring the write
612
664
  // without this argument saves an empty record and reports success.
613
- B
665
+ I
614
666
  );
615
- if (!$.success) throw new le($);
616
- return L.length ? { ...$, droppedFields: L } : $;
667
+ if (!b.success) throw new fe(b);
668
+ return T.length ? { ...b, droppedFields: T } : b;
617
669
  });
618
- } catch (s) {
619
- return s instanceof le ? s.outcome : {
670
+ } catch (l) {
671
+ return l instanceof fe ? l.outcome : {
620
672
  success: !1,
621
673
  data: null,
622
- error: s instanceof Error ? s.message : String(s)
674
+ error: l instanceof Error ? l.message : String(l)
623
675
  };
624
676
  }
625
677
  }
@@ -631,39 +683,39 @@ const de = "__stonecropLinkFk_", Q = "status", Ze = (t = {}) => {
631
683
  };
632
684
  });
633
685
  };
634
- function Ie(t, e) {
686
+ function He(e, t) {
635
687
  const o = [];
636
- for (const n of X(t)) {
637
- const r = e.get(n.fieldname);
638
- if (r && oe(r, n.component) !== "inline") continue;
639
- const i = A(n.fieldname);
688
+ for (const n of Z(e)) {
689
+ const r = t.get(n.fieldname);
690
+ if (r && re(r, n.component) !== "inline") continue;
691
+ const i = R(n.fieldname);
640
692
  o.push(i !== n.fieldname ? `"${i}" AS "${n.fieldname}"` : `"${n.fieldname}"`);
641
693
  }
642
694
  return o;
643
695
  }
644
- function Y(t) {
645
- const e = /* @__PURE__ */ new Map();
646
- if (t.links)
647
- for (const [o, n] of Object.entries(t.links))
648
- e.set(n.fieldname ?? o, n);
649
- return Ie(t.fields, e).join(", ");
696
+ function X(e) {
697
+ const t = /* @__PURE__ */ new Map();
698
+ if (e.links)
699
+ for (const [o, n] of Object.entries(e.links))
700
+ t.set(n.fieldname ?? o, n);
701
+ return He(e.fields, t).join(", ");
650
702
  }
651
- function te(t) {
652
- const e = ke(t.fields);
653
- return t.fields.find((o) => o.kind === "field" && o.fieldname === e);
703
+ function ne(e) {
704
+ const t = me(e.fields);
705
+ return e.fields.find((o) => o.kind === "field" && o.fieldname === t);
654
706
  }
655
- function Be(t) {
656
- const e = Object.entries(t);
657
- if (e.length === 0) return;
658
- if (he().length === 0) {
707
+ function qe(e) {
708
+ const t = Object.entries(e);
709
+ if (t.length === 0) return;
710
+ if (ye().length === 0) {
659
711
  console.warn(
660
712
  "[@stonecrop/graphql-middleware] Schema built with no doctypes registered, so the `actionHandlers` map could not be verified. Load doctypes before building the schema to have stale handler keys reported."
661
713
  );
662
714
  return;
663
715
  }
664
716
  const o = [];
665
- for (const [n, r] of e) {
666
- const i = I(n);
717
+ for (const [n, r] of t) {
718
+ const i = L(n);
667
719
  if (!i) {
668
720
  o.push(`"${n}": no doctype by that name is registered`);
669
721
  continue;
@@ -674,9 +726,9 @@ function Be(t) {
674
726
  );
675
727
  continue;
676
728
  }
677
- const l = i.workflow?.actions ?? {};
678
- for (const d of Object.keys(r))
679
- d in l || o.push(`"${n}.${d}": the doctype declares no action by that key`);
729
+ const a = i.workflow?.actions ?? {};
730
+ for (const u of Object.keys(r))
731
+ u in a || o.push(`"${n}.${u}": the doctype declares no action by that key`);
680
732
  }
681
733
  if (o.length > 0)
682
734
  throw new Error(
@@ -685,35 +737,31 @@ function Be(t) {
685
737
  `)}`
686
738
  );
687
739
  }
688
- function je() {
689
- const t = Le();
690
- if (t.length !== 0)
740
+ function Ue() {
741
+ const e = Be();
742
+ if (e.length !== 0)
691
743
  throw new Error(
692
- `StonecropPlugin: ${t.length} doctype reference${t.length === 1 ? "" : "s"} cannot be resolved and would silently drop the relation:
693
- ` + t.map((e) => `${e.path.join(".")}: ${e.message}`).join(`
744
+ `StonecropPlugin: ${e.length} doctype reference${e.length === 1 ? "" : "s"} cannot be resolved and would silently drop the relation:
745
+ ` + e.map((t) => `${t.path.join(".")}: ${t.message}`).join(`
694
746
  `)
695
747
  );
696
748
  }
697
- function ne(t) {
749
+ function oe(e) {
698
750
  return new Error(
699
- `Doctype "${t}" has no identity field: it declares no field with \`primaryKey: true\` and no field named \`id\`. Declare one of the two — records cannot be fetched or acted on until then.`
751
+ `Doctype "${e}" has no identity field: it declares no field with \`primaryKey: true\` and no field named \`id\`. Declare one of the two — records cannot be fetched or acted on until then.`
700
752
  );
701
753
  }
702
- function W(t, e) {
703
- const o = e?.[t] ?? $e(t), n = o.indexOf(".");
704
- return n > 0 ? `"${o.slice(0, n)}"."${o.slice(n + 1)}"` : `"${o}"`;
705
- }
706
- const et = (t = {}) => {
707
- const { logPlans: e = !0, logTiming: o = !1 } = t, n = (r, i) => ({
708
- plan: (l) => {
709
- e && console.log(`[@stonecrop/graphql-middleware] Building plan for ${r}.${i}`);
710
- const d = o ? Date.now() : 0, b = l();
754
+ const at = (e = {}) => {
755
+ const { logPlans: t = !0, logTiming: o = !1 } = e, n = (r, i) => ({
756
+ plan: (a) => {
757
+ t && console.log(`[@stonecrop/graphql-middleware] Building plan for ${r}.${i}`);
758
+ const u = o ? Date.now() : 0, $ = a();
711
759
  return o && console.log(
712
- `[@stonecrop/graphql-middleware] Plan built for ${r}.${i} in ${Date.now() - d}ms`
713
- ), b;
760
+ `[@stonecrop/graphql-middleware] Plan built for ${r}.${i} in ${Date.now() - u}ms`
761
+ ), $;
714
762
  }
715
763
  });
716
- return Me({
764
+ return Le({
717
765
  Query: {
718
766
  stonecropRecord: n("Query", "stonecropRecord"),
719
767
  stonecropRecords: n("Query", "stonecropRecords"),
@@ -724,37 +772,37 @@ const et = (t = {}) => {
724
772
  stonecropAction: n("Mutation", "stonecropAction")
725
773
  }
726
774
  });
727
- }, Ce = {
775
+ }, _e = {
728
776
  name: "StonecropFieldCasingPlugin",
729
777
  version: "0.0.0",
730
778
  inflection: {
731
779
  replace: {
732
- attribute(t, e, o) {
780
+ attribute(e, t, o) {
733
781
  return this.upperCamelCase(this._attributeName(o));
734
782
  }
735
783
  }
736
784
  }
737
- }, Pe = (t) => ({
738
- extends: [Oe],
739
- plugins: t?.fieldCasing === "pascal" ? [Ce] : []
740
- }), tt = Pe();
785
+ }, Je = (e) => ({
786
+ extends: [Ne],
787
+ plugins: e?.fieldCasing === "pascal" ? [_e] : []
788
+ }), st = Je();
741
789
  export {
742
- re as DoctypeValidationError,
743
- tt as StonecropPreset,
744
- De as applyGuardedTransition,
745
- Xe as clearFetchHandlers,
746
- ze as clearRegistry,
747
- et as createDebugPlugin,
748
- Ze as createStonecropPlugin,
749
- Pe as createStonecropPreset,
750
- he as getAllMeta,
751
- Ne as getFetchHandler,
752
- I as getMeta,
753
- Ve as hasMeta,
754
- xe as loadDoctypes,
755
- Qe as loadDoctypesFromObject,
756
- rt as makePgService,
757
- Ye as registerFetchHandler,
758
- Fe as typeDefs
790
+ ie as DoctypeValidationError,
791
+ st as StonecropPreset,
792
+ Ce as applyGuardedTransition,
793
+ rt as clearFetchHandlers,
794
+ nt as clearRegistry,
795
+ at as createDebugPlugin,
796
+ it as createStonecropPlugin,
797
+ Je as createStonecropPreset,
798
+ ye as getAllMeta,
799
+ je as getFetchHandler,
800
+ L as getMeta,
801
+ tt as hasMeta,
802
+ De as loadDoctypes,
803
+ et as loadDoctypesFromObject,
804
+ dt as makePgService,
805
+ ot as registerFetchHandler,
806
+ We as typeDefs
759
807
  };
760
808
  //# sourceMappingURL=index.js.map