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