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