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