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