@stonecrop/graphql-middleware 0.13.4 → 0.13.6
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 +224 -207
- package/dist/index.js.map +1 -1
- package/dist/src/debug.js +2 -2
- package/dist/src/plugin/postgraphile.d.ts.map +1 -1
- package/dist/src/plugin/postgraphile.js +66 -26
- package/dist/src/registry/actions.d.ts.map +1 -1
- package/dist/src/registry/actions.js +2 -0
- package/dist/src/registry/doctypes.js +1 -1
- package/package.json +7 -9
package/dist/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { readdirSync as
|
|
2
|
-
import { join as
|
|
3
|
-
import { validateDoctype as
|
|
4
|
-
import { sideEffectWithPgClient as
|
|
5
|
-
import { object as Q, constant as
|
|
6
|
-
import { gql as
|
|
7
|
-
import { PostGraphileAmberPreset as
|
|
8
|
-
import { makePgService as
|
|
9
|
-
const
|
|
1
|
+
import { readdirSync as ne, statSync as oe, readFileSync as re } from "node:fs";
|
|
2
|
+
import { join as ie } from "node:path";
|
|
3
|
+
import { validateDoctype as ee, parseDoctype as te, camelToSnake as x, pascalToSnake as se } from "@stonecrop/schema";
|
|
4
|
+
import { sideEffectWithPgClient as ce, loadOneWithPgClient as X } from "@dataplan/pg";
|
|
5
|
+
import { object as Q, constant as ae, lambda as le } from "postgraphile/grafast";
|
|
6
|
+
import { gql as de, extendSchema as fe, wrapPlans as ue } from "postgraphile/utils";
|
|
7
|
+
import { PostGraphileAmberPreset as pe } from "postgraphile/presets/amber";
|
|
8
|
+
import { makePgService as Ke } from "postgraphile/adaptors/pg";
|
|
9
|
+
const $ = /* @__PURE__ */ new Map();
|
|
10
10
|
class V extends Error {
|
|
11
11
|
constructor(e, n) {
|
|
12
12
|
const o = n.map((r) => ` ${r.path.join(".")}: ${r.message}`).join(`
|
|
@@ -17,15 +17,15 @@ ${o}`), this.file = e, this.errors = n, this.name = "DoctypeValidationError";
|
|
|
17
17
|
file;
|
|
18
18
|
errors;
|
|
19
19
|
}
|
|
20
|
-
function
|
|
21
|
-
const n =
|
|
20
|
+
function ye(t, e = {}) {
|
|
21
|
+
const n = ne(t);
|
|
22
22
|
for (const o of n) {
|
|
23
|
-
const r =
|
|
24
|
-
|
|
23
|
+
const r = ie(t, o);
|
|
24
|
+
oe(r).isDirectory() ? ye(r, e) : o.endsWith(".json") && ge(r, e);
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
|
-
function
|
|
28
|
-
const n =
|
|
27
|
+
function ge(t, e) {
|
|
28
|
+
const n = re(t, "utf-8");
|
|
29
29
|
let o;
|
|
30
30
|
try {
|
|
31
31
|
o = JSON.parse(n);
|
|
@@ -40,7 +40,7 @@ function ye(t, e) {
|
|
|
40
40
|
}
|
|
41
41
|
throw new V(t, [a]);
|
|
42
42
|
}
|
|
43
|
-
const r =
|
|
43
|
+
const r = ee(o);
|
|
44
44
|
if (!r.success) {
|
|
45
45
|
if (e.continueOnError) {
|
|
46
46
|
e.onError?.(t, r.errors);
|
|
@@ -48,12 +48,12 @@ function ye(t, e) {
|
|
|
48
48
|
}
|
|
49
49
|
throw new V(t, r.errors);
|
|
50
50
|
}
|
|
51
|
-
const s =
|
|
52
|
-
|
|
51
|
+
const s = te(o);
|
|
52
|
+
$.set(s.name, s);
|
|
53
53
|
}
|
|
54
|
-
function
|
|
54
|
+
function Le(t, e = {}) {
|
|
55
55
|
for (const [n, o] of Object.entries(t)) {
|
|
56
|
-
const r = { ...o, name: n }, s =
|
|
56
|
+
const r = { ...typeof o == "object" && o !== null ? o : {}, name: n }, s = ee(r);
|
|
57
57
|
if (!s.success) {
|
|
58
58
|
if (e.continueOnError) {
|
|
59
59
|
e.onError?.(n, s.errors);
|
|
@@ -61,66 +61,66 @@ function Ie(t, e = {}) {
|
|
|
61
61
|
}
|
|
62
62
|
throw new V(n, s.errors);
|
|
63
63
|
}
|
|
64
|
-
const c =
|
|
65
|
-
|
|
64
|
+
const c = te(r);
|
|
65
|
+
$.set(c.name, c);
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
|
-
function
|
|
69
|
-
const e =
|
|
68
|
+
function I(t) {
|
|
69
|
+
const e = $.get(t);
|
|
70
70
|
if (e) return e;
|
|
71
|
-
for (const n of
|
|
71
|
+
for (const n of $.values())
|
|
72
72
|
if (n.slug === t) return n;
|
|
73
73
|
}
|
|
74
|
-
function
|
|
75
|
-
return Array.from(
|
|
74
|
+
function me() {
|
|
75
|
+
return Array.from($.values());
|
|
76
76
|
}
|
|
77
|
-
function
|
|
78
|
-
return
|
|
77
|
+
function Pe(t) {
|
|
78
|
+
return $.has(t);
|
|
79
79
|
}
|
|
80
|
-
function
|
|
81
|
-
|
|
80
|
+
function Te() {
|
|
81
|
+
$.clear();
|
|
82
82
|
}
|
|
83
|
-
function
|
|
83
|
+
function He() {
|
|
84
84
|
const t = [];
|
|
85
|
-
for (const e of
|
|
86
|
-
e.inherits &&
|
|
85
|
+
for (const e of $.values()) {
|
|
86
|
+
e.inherits && !$.has(e.inherits) && t.push({
|
|
87
87
|
path: [e.name, "inherits"],
|
|
88
88
|
message: `References unknown doctype: ${e.inherits}`
|
|
89
89
|
});
|
|
90
90
|
for (const n of e.fields)
|
|
91
|
-
n.fieldtype === "Link" && typeof n.options == "string" && (
|
|
91
|
+
n.fieldtype === "Link" && typeof n.options == "string" && ($.has(n.options) || t.push({
|
|
92
92
|
path: [e.name, "fields", n.fieldname, "options"],
|
|
93
93
|
message: `Link references unknown doctype: ${n.options}`
|
|
94
94
|
}));
|
|
95
95
|
}
|
|
96
96
|
return t;
|
|
97
97
|
}
|
|
98
|
-
const
|
|
99
|
-
function
|
|
100
|
-
|
|
98
|
+
const T = /* @__PURE__ */ new Map();
|
|
99
|
+
function he(t, e) {
|
|
100
|
+
T.set(t, e);
|
|
101
101
|
}
|
|
102
|
-
function
|
|
103
|
-
return
|
|
102
|
+
function Se(t) {
|
|
103
|
+
return T.get(t);
|
|
104
104
|
}
|
|
105
|
-
function
|
|
106
|
-
return
|
|
105
|
+
function Je(t) {
|
|
106
|
+
return T.has(t);
|
|
107
107
|
}
|
|
108
|
-
function
|
|
109
|
-
|
|
108
|
+
function We() {
|
|
109
|
+
T.clear();
|
|
110
110
|
}
|
|
111
|
-
const
|
|
111
|
+
const $e = async (t, e) => {
|
|
112
112
|
const [n] = t, { doctype: o } = e, r = [];
|
|
113
113
|
for (const s of o.fields)
|
|
114
114
|
s.required && (n[s.fieldname] === void 0 || n[s.fieldname] === null) && r.push(s.label ?? s.fieldname);
|
|
115
115
|
if (r.length > 0)
|
|
116
116
|
throw new Error(`Missing required fields: ${r.join(", ")}`);
|
|
117
117
|
return { valid: !0 };
|
|
118
|
-
},
|
|
118
|
+
}, we = async (t, e) => {
|
|
119
119
|
const [n] = t, { doctype: o } = e, r = [];
|
|
120
120
|
for (const s of o.fields) {
|
|
121
121
|
const c = n[s.fieldname];
|
|
122
122
|
if (c == null) continue;
|
|
123
|
-
const a =
|
|
123
|
+
const a = ke(s, c);
|
|
124
124
|
a && r.push(a);
|
|
125
125
|
}
|
|
126
126
|
if (o.links)
|
|
@@ -135,7 +135,7 @@ ${r.join(`
|
|
|
135
135
|
`)}`);
|
|
136
136
|
return { valid: !0 };
|
|
137
137
|
};
|
|
138
|
-
function
|
|
138
|
+
function ke(t, e) {
|
|
139
139
|
const { fieldname: n, fieldtype: o } = t;
|
|
140
140
|
switch (o) {
|
|
141
141
|
case "Int":
|
|
@@ -173,26 +173,26 @@ function we(t, e) {
|
|
|
173
173
|
}
|
|
174
174
|
return null;
|
|
175
175
|
}
|
|
176
|
-
const
|
|
177
|
-
validateRequiredFields:
|
|
178
|
-
validateFieldTypes:
|
|
179
|
-
noop:
|
|
176
|
+
const Ee = async () => ({ ok: !0 }), be = {
|
|
177
|
+
validateRequiredFields: $e,
|
|
178
|
+
validateFieldTypes: we,
|
|
179
|
+
noop: Ee
|
|
180
180
|
};
|
|
181
|
-
function
|
|
182
|
-
for (const [t, e] of Object.entries(
|
|
183
|
-
|
|
181
|
+
function qe() {
|
|
182
|
+
for (const [t, e] of Object.entries(be))
|
|
183
|
+
he(t, e);
|
|
184
184
|
}
|
|
185
185
|
const Y = /* @__PURE__ */ new Map();
|
|
186
|
-
function
|
|
186
|
+
function _e(t, e) {
|
|
187
187
|
Y.set(t, e);
|
|
188
188
|
}
|
|
189
|
-
function
|
|
189
|
+
function Me(t) {
|
|
190
190
|
return Y.get(t);
|
|
191
191
|
}
|
|
192
|
-
function
|
|
192
|
+
function Qe() {
|
|
193
193
|
Y.clear();
|
|
194
194
|
}
|
|
195
|
-
const
|
|
195
|
+
const Oe = de`
|
|
196
196
|
type StonecropFieldMeta {
|
|
197
197
|
fieldname: String!
|
|
198
198
|
fieldtype: String!
|
|
@@ -270,101 +270,101 @@ const Me = le`
|
|
|
270
270
|
extend type Mutation {
|
|
271
271
|
stonecropAction(doctype: String!, action: String!, args: JSON): StonecropActionResult!
|
|
272
272
|
}
|
|
273
|
-
`,
|
|
273
|
+
`, Ue = (t = {}) => {
|
|
274
274
|
const e = t.debug ? (n, o) => (console.log(`[@stonecrop/graphql-middleware] ${o.text}`, o.values ?? []), n.query(o)) : (n, o) => n.query(o);
|
|
275
|
-
return
|
|
275
|
+
return fe((n) => {
|
|
276
276
|
const o = n.input?.pgRegistry?.pgExecutors, r = o ? Object.values(o)[0] : void 0;
|
|
277
277
|
if (!r)
|
|
278
278
|
throw new Error("StonecropPlugin: no pgExecutors found — ensure pgServices is configured");
|
|
279
279
|
return {
|
|
280
|
-
typeDefs:
|
|
280
|
+
typeDefs: Oe,
|
|
281
281
|
objects: {
|
|
282
282
|
Query: {
|
|
283
283
|
plans: {
|
|
284
284
|
stonecropMeta(s, { $doctype: c }) {
|
|
285
|
-
return
|
|
285
|
+
return le(c, (a) => I(String(a)) ?? null);
|
|
286
286
|
},
|
|
287
287
|
stonecropAllMeta() {
|
|
288
|
-
return
|
|
288
|
+
return ae(me());
|
|
289
289
|
},
|
|
290
|
-
stonecropRecord(s, { $doctype: c, $id: a, $options:
|
|
291
|
-
return
|
|
290
|
+
stonecropRecord(s, { $doctype: c, $id: a, $options: w }) {
|
|
291
|
+
return X(
|
|
292
292
|
r,
|
|
293
|
-
Q({ doctype: c, id: a, options:
|
|
294
|
-
async (
|
|
293
|
+
Q({ doctype: c, id: a, options: w }),
|
|
294
|
+
async (b, u) => {
|
|
295
295
|
const g = /* @__PURE__ */ new Map();
|
|
296
|
-
for (let i = 0; i <
|
|
297
|
-
const
|
|
298
|
-
g.has(
|
|
296
|
+
for (let i = 0; i < u.length; i++) {
|
|
297
|
+
const p = String(u[i].doctype);
|
|
298
|
+
g.has(p) || g.set(p, []), g.get(p).push(i);
|
|
299
299
|
}
|
|
300
|
-
const m =
|
|
301
|
-
for (const [i,
|
|
302
|
-
const d =
|
|
300
|
+
const m = Array.from({ length: u.length });
|
|
301
|
+
for (const [i, p] of g) {
|
|
302
|
+
const d = I(i);
|
|
303
303
|
if (!d) {
|
|
304
|
-
for (const
|
|
304
|
+
for (const f of p) m[f] = { data: null, doctype: i };
|
|
305
305
|
continue;
|
|
306
306
|
}
|
|
307
|
-
const
|
|
308
|
-
if (!
|
|
309
|
-
for (const
|
|
307
|
+
const R = Z(d);
|
|
308
|
+
if (!R) {
|
|
309
|
+
for (const f of p) m[f] = { data: null, doctype: i };
|
|
310
310
|
continue;
|
|
311
311
|
}
|
|
312
|
-
const
|
|
313
|
-
text: `SELECT ${
|
|
314
|
-
values: [
|
|
315
|
-
}),
|
|
316
|
-
for (const
|
|
317
|
-
const
|
|
318
|
-
if (!
|
|
319
|
-
m[
|
|
312
|
+
const H = x(R.fieldname), k = U(d), D = p.map((f) => String(u[f].id)), { rows: J } = await e(b, {
|
|
313
|
+
text: `SELECT ${k} FROM ${B(d.name, t.tables)} WHERE "${H}"::text = ANY($1::text[])`,
|
|
314
|
+
values: [D]
|
|
315
|
+
}), L = new Map(J.map((f) => [String(f[R.fieldname]), f]));
|
|
316
|
+
for (const f of p) {
|
|
317
|
+
const C = String(u[f].id), v = L.get(C);
|
|
318
|
+
if (!v) {
|
|
319
|
+
m[f] = { data: null, doctype: i };
|
|
320
320
|
continue;
|
|
321
321
|
}
|
|
322
|
-
const
|
|
322
|
+
const l = { ...v }, y = u[f].options ?? {}, M = y.includeNested === !0, h = Array.isArray(y.includeNested) ? new Set(y.includeNested) : null;
|
|
323
323
|
if (d.links)
|
|
324
|
-
for (const [
|
|
325
|
-
const
|
|
326
|
-
if (!(
|
|
327
|
-
if (q === "custom") {
|
|
328
|
-
const A =
|
|
329
|
-
O && (
|
|
324
|
+
for (const [S, E] of Object.entries(d.links)) {
|
|
325
|
+
const N = E.fetch, W = E.cardinality === "noneOrMany" || E.cardinality === "atLeastOne", q = N?.method ?? (W ? "sync" : "lazy"), G = N?.method === "sync" ? N.limit : W ? 50 : void 0;
|
|
326
|
+
if (!(M || (h ? h.has(S) : q === "sync"))) continue;
|
|
327
|
+
if (q === "custom" && N?.method === "custom") {
|
|
328
|
+
const A = N.handler, O = Me(A);
|
|
329
|
+
O && (l[S] = await O(b, l, E));
|
|
330
330
|
continue;
|
|
331
331
|
}
|
|
332
|
-
if (q !== "sync" && !
|
|
333
|
-
const
|
|
334
|
-
if (!
|
|
335
|
-
const
|
|
332
|
+
if (q !== "sync" && !h?.has(S)) continue;
|
|
333
|
+
const j = I(E.target);
|
|
334
|
+
if (!j) continue;
|
|
335
|
+
const K = U(j);
|
|
336
336
|
if (W) {
|
|
337
|
-
if (!
|
|
338
|
-
const A = x(
|
|
339
|
-
let O = `SELECT ${
|
|
340
|
-
const
|
|
341
|
-
|
|
342
|
-
const { rows: _ } = await e(
|
|
337
|
+
if (!E.backlink) continue;
|
|
338
|
+
const A = x(E.backlink);
|
|
339
|
+
let O = `SELECT ${K} FROM ${B(j.name, t.tables)} WHERE "${A}"::text = $1`;
|
|
340
|
+
const P = [C];
|
|
341
|
+
G != null && (O += " LIMIT $2", P.push(G));
|
|
342
|
+
const { rows: _ } = await e(b, {
|
|
343
343
|
text: O,
|
|
344
|
-
values:
|
|
344
|
+
values: P
|
|
345
345
|
});
|
|
346
|
-
|
|
346
|
+
l[S] = _;
|
|
347
347
|
} else {
|
|
348
|
-
if (!
|
|
349
|
-
const A =
|
|
348
|
+
if (!E.fieldname) continue;
|
|
349
|
+
const A = l[E.fieldname];
|
|
350
350
|
if (A == null) {
|
|
351
|
-
|
|
351
|
+
l[S] = null;
|
|
352
352
|
continue;
|
|
353
353
|
}
|
|
354
|
-
const O =
|
|
354
|
+
const O = Z(j);
|
|
355
355
|
if (!O) continue;
|
|
356
|
-
const
|
|
357
|
-
text: `SELECT ${
|
|
356
|
+
const P = x(O.fieldname), { rows: _ } = await e(b, {
|
|
357
|
+
text: `SELECT ${K} FROM ${B(j.name, t.tables)} WHERE "${P}" = $1`,
|
|
358
358
|
values: [A]
|
|
359
359
|
});
|
|
360
|
-
|
|
360
|
+
l[S] = _[0] ?? null;
|
|
361
361
|
}
|
|
362
362
|
}
|
|
363
|
-
const
|
|
364
|
-
m[
|
|
365
|
-
data:
|
|
363
|
+
const F = h && d.links ? [...h].filter((S) => !(S in d.links)) : void 0;
|
|
364
|
+
m[f] = {
|
|
365
|
+
data: l,
|
|
366
366
|
doctype: i,
|
|
367
|
-
unknownLinks:
|
|
367
|
+
unknownLinks: F?.length ? F : void 0
|
|
368
368
|
};
|
|
369
369
|
}
|
|
370
370
|
}
|
|
@@ -372,61 +372,63 @@ const Me = le`
|
|
|
372
372
|
}
|
|
373
373
|
);
|
|
374
374
|
},
|
|
375
|
-
stonecropRecords(s, { $doctype: c, $filters: a, $orderBy:
|
|
376
|
-
return
|
|
375
|
+
stonecropRecords(s, { $doctype: c, $filters: a, $orderBy: w, $limit: b, $offset: u }) {
|
|
376
|
+
return X(
|
|
377
377
|
r,
|
|
378
378
|
Q({
|
|
379
379
|
doctype: c,
|
|
380
380
|
filters: a,
|
|
381
|
-
orderBy:
|
|
382
|
-
limit:
|
|
383
|
-
offset:
|
|
381
|
+
orderBy: w,
|
|
382
|
+
limit: b,
|
|
383
|
+
offset: u
|
|
384
384
|
}),
|
|
385
385
|
async (g, m) => await Promise.all(
|
|
386
386
|
m.map(async (i) => {
|
|
387
|
-
const
|
|
388
|
-
if (!
|
|
389
|
-
return { data: [], doctype:
|
|
390
|
-
const
|
|
387
|
+
const p = String(i.doctype), d = I(p);
|
|
388
|
+
if (!d)
|
|
389
|
+
return { data: [], doctype: p, count: 0 };
|
|
390
|
+
const R = new Set(z(d.fields).map((l) => l.fieldname)), H = U(d), k = [], D = [];
|
|
391
391
|
if (i.filters != null)
|
|
392
|
-
for (const [
|
|
393
|
-
if (!
|
|
394
|
-
throw new Error(`Unknown filter field: ${
|
|
395
|
-
|
|
392
|
+
for (const [l, y] of Object.entries(i.filters)) {
|
|
393
|
+
if (!R.has(l))
|
|
394
|
+
throw new Error(`Unknown filter field: ${l} for doctype ${d.name}`);
|
|
395
|
+
k.push(y), D.push(`"${x(l)}" = $${k.length}`);
|
|
396
396
|
}
|
|
397
|
-
const J =
|
|
398
|
-
let
|
|
397
|
+
const J = D.length > 0 ? ` WHERE ${D.join(" AND ")}` : "";
|
|
398
|
+
let L = "";
|
|
399
399
|
if (i.orderBy != null) {
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
400
|
+
if (typeof i.orderBy != "string")
|
|
401
|
+
throw new Error(`Invalid orderBy: expected string, got ${typeof i.orderBy}`);
|
|
402
|
+
const l = i.orderBy, y = l.lastIndexOf("_");
|
|
403
|
+
if (y <= 0)
|
|
404
|
+
throw new Error(`Invalid orderBy format: "${l}". Expected FIELD_ASC or FIELD_DESC`);
|
|
405
|
+
const M = l.slice(y + 1).toUpperCase();
|
|
406
|
+
if (M !== "ASC" && M !== "DESC")
|
|
407
|
+
throw new Error(`Invalid orderBy direction: "${M}". Must be ASC or DESC`);
|
|
408
|
+
const h = l.slice(0, y);
|
|
409
|
+
if (!R.has(h))
|
|
410
|
+
throw new Error(`Unknown orderBy field: "${h}" for doctype ${d.name}`);
|
|
411
|
+
L = ` ORDER BY "${x(h)}" ${M}`;
|
|
410
412
|
}
|
|
411
|
-
let
|
|
412
|
-
i.limit != null && (
|
|
413
|
-
const { rows:
|
|
414
|
-
text: `SELECT ${
|
|
415
|
-
values:
|
|
413
|
+
let f = "";
|
|
414
|
+
i.limit != null && (k.push(i.limit), f += ` LIMIT $${k.length}`), i.offset != null && (k.push(i.offset), f += ` OFFSET $${k.length}`);
|
|
415
|
+
const { rows: C } = await e(g, {
|
|
416
|
+
text: `SELECT ${H} FROM ${B(d.name, t.tables)}${J}${L}${f}`,
|
|
417
|
+
values: k
|
|
416
418
|
});
|
|
417
|
-
let
|
|
419
|
+
let v = C.length;
|
|
418
420
|
if (i.limit != null || i.offset != null) {
|
|
419
|
-
const
|
|
421
|
+
const l = [], y = [];
|
|
420
422
|
if (i.filters != null)
|
|
421
|
-
for (const [
|
|
422
|
-
|
|
423
|
-
const
|
|
424
|
-
text: `SELECT COUNT(*) AS
|
|
425
|
-
values:
|
|
423
|
+
for (const [F, S] of Object.entries(i.filters))
|
|
424
|
+
R.has(F) && (l.push(S), y.push(`"${x(F)}" = $${l.length}`));
|
|
425
|
+
const M = y.length > 0 ? ` WHERE ${y.join(" AND ")}` : "", { rows: h } = await e(g, {
|
|
426
|
+
text: `SELECT COUNT(*) AS row_count FROM ${B(d.name, t.tables)}${M}`,
|
|
427
|
+
values: l
|
|
426
428
|
});
|
|
427
|
-
|
|
429
|
+
v = parseInt(h[0]?.row_count ?? "0", 10);
|
|
428
430
|
}
|
|
429
|
-
return { data:
|
|
431
|
+
return { data: C, doctype: p, count: v };
|
|
430
432
|
})
|
|
431
433
|
)
|
|
432
434
|
);
|
|
@@ -435,35 +437,35 @@ const Me = le`
|
|
|
435
437
|
},
|
|
436
438
|
Mutation: {
|
|
437
439
|
plans: {
|
|
438
|
-
stonecropAction(s, { $doctype: c, $action: a, $args:
|
|
439
|
-
return
|
|
440
|
+
stonecropAction(s, { $doctype: c, $action: a, $args: w }) {
|
|
441
|
+
return ce(
|
|
440
442
|
r,
|
|
441
|
-
Q({ doctype: c, action: a, actionArgs:
|
|
442
|
-
async (
|
|
443
|
-
const g =
|
|
443
|
+
Q({ doctype: c, action: a, actionArgs: w }),
|
|
444
|
+
async (b, u) => {
|
|
445
|
+
const g = I(String(u.doctype));
|
|
444
446
|
if (!g)
|
|
445
447
|
return {
|
|
446
448
|
success: !1,
|
|
447
449
|
data: null,
|
|
448
|
-
error: `Unknown doctype: ${
|
|
450
|
+
error: `Unknown doctype: ${u.doctype}`
|
|
449
451
|
};
|
|
450
|
-
const m = g.workflow?.actions?.[
|
|
452
|
+
const m = g.workflow?.actions?.[u.action];
|
|
451
453
|
if (!m)
|
|
452
454
|
return {
|
|
453
455
|
success: !1,
|
|
454
456
|
data: null,
|
|
455
|
-
error: `Unknown action: ${
|
|
457
|
+
error: `Unknown action: ${u.action} on ${u.doctype}`
|
|
456
458
|
};
|
|
457
|
-
const i =
|
|
459
|
+
const i = Se(m.handler);
|
|
458
460
|
if (!i)
|
|
459
461
|
return {
|
|
460
462
|
success: !1,
|
|
461
463
|
data: null,
|
|
462
464
|
error: `Handler not registered: ${m.handler}`
|
|
463
465
|
};
|
|
464
|
-
const
|
|
466
|
+
const p = { doctype: g, pgClient: b };
|
|
465
467
|
try {
|
|
466
|
-
return { success: !0, data: await i(
|
|
468
|
+
return { success: !0, data: await i(u.actionArgs ?? [], p), error: null };
|
|
467
469
|
} catch (d) {
|
|
468
470
|
return {
|
|
469
471
|
success: !1,
|
|
@@ -480,37 +482,52 @@ const Me = le`
|
|
|
480
482
|
};
|
|
481
483
|
});
|
|
482
484
|
};
|
|
483
|
-
function
|
|
484
|
-
const e =
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
485
|
+
function z(t) {
|
|
486
|
+
const e = [];
|
|
487
|
+
for (const n of t)
|
|
488
|
+
if (n.fieldtype === "Fieldset") {
|
|
489
|
+
const o = (n.schema ?? []).filter(
|
|
490
|
+
(r) => typeof r.fieldname == "string" && typeof r.fieldtype == "string"
|
|
491
|
+
);
|
|
492
|
+
e.push(...z(o));
|
|
493
|
+
} else
|
|
494
|
+
e.push(n);
|
|
495
|
+
return e;
|
|
496
|
+
}
|
|
497
|
+
function Re(t, e) {
|
|
488
498
|
const n = [];
|
|
489
|
-
for (const o of t
|
|
499
|
+
for (const o of z(t)) {
|
|
490
500
|
if (o.fieldtype === "Display" || o.fieldtype === "Link" && e.has(o.fieldname)) continue;
|
|
491
501
|
const r = x(o.fieldname);
|
|
492
502
|
n.push(r !== o.fieldname ? `"${r}" AS "${o.fieldname}"` : `"${o.fieldname}"`);
|
|
493
503
|
}
|
|
494
|
-
return n
|
|
504
|
+
return n;
|
|
505
|
+
}
|
|
506
|
+
function U(t) {
|
|
507
|
+
const e = /* @__PURE__ */ new Set();
|
|
508
|
+
if (t.links)
|
|
509
|
+
for (const [n, o] of Object.entries(t.links))
|
|
510
|
+
e.add(o.fieldname ?? n);
|
|
511
|
+
return Re(t.fields, e).join(", ");
|
|
495
512
|
}
|
|
496
|
-
function
|
|
513
|
+
function Z(t) {
|
|
497
514
|
return t.fields.find((e) => e.fieldtype === "PrimaryKey");
|
|
498
515
|
}
|
|
499
|
-
function
|
|
500
|
-
const n = e?.[t] ??
|
|
516
|
+
function B(t, e) {
|
|
517
|
+
const n = e?.[t] ?? se(t), o = n.indexOf(".");
|
|
501
518
|
return o > 0 ? `"${n.slice(0, o)}"."${n.slice(o + 1)}"` : `"${n}"`;
|
|
502
519
|
}
|
|
503
|
-
const
|
|
520
|
+
const Ve = (t = {}) => {
|
|
504
521
|
const { logPlans: e = !0, logTiming: n = !1 } = t, o = (r, s) => ({
|
|
505
522
|
plan: (c) => {
|
|
506
523
|
e && console.log(`[@stonecrop/graphql-middleware] Building plan for ${r}.${s}`);
|
|
507
|
-
const a = n ? Date.now() : 0,
|
|
524
|
+
const a = n ? Date.now() : 0, w = c();
|
|
508
525
|
return n && console.log(
|
|
509
526
|
`[@stonecrop/graphql-middleware] Plan built for ${r}.${s} in ${Date.now() - a}ms`
|
|
510
|
-
),
|
|
527
|
+
), w;
|
|
511
528
|
}
|
|
512
529
|
});
|
|
513
|
-
return
|
|
530
|
+
return ue({
|
|
514
531
|
Query: {
|
|
515
532
|
stonecropRecord: o("Query", "stonecropRecord"),
|
|
516
533
|
stonecropRecords: o("Query", "stonecropRecords"),
|
|
@@ -521,7 +538,7 @@ const Qe = (t = {}) => {
|
|
|
521
538
|
stonecropAction: o("Mutation", "stonecropAction")
|
|
522
539
|
}
|
|
523
540
|
});
|
|
524
|
-
},
|
|
541
|
+
}, xe = {
|
|
525
542
|
name: "StonecropFieldCasingPlugin",
|
|
526
543
|
version: "0.0.0",
|
|
527
544
|
inflection: {
|
|
@@ -531,33 +548,33 @@ const Qe = (t = {}) => {
|
|
|
531
548
|
}
|
|
532
549
|
}
|
|
533
550
|
}
|
|
534
|
-
},
|
|
535
|
-
extends: [
|
|
536
|
-
plugins: t?.fieldCasing === "pascal" ? [
|
|
537
|
-
}),
|
|
551
|
+
}, Ae = (t) => ({
|
|
552
|
+
extends: [pe],
|
|
553
|
+
plugins: t?.fieldCasing === "pascal" ? [xe] : []
|
|
554
|
+
}), Ye = Ae();
|
|
538
555
|
export {
|
|
539
556
|
V as DoctypeValidationError,
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
557
|
+
Ye as StonecropPreset,
|
|
558
|
+
be as builtinHandlers,
|
|
559
|
+
Qe as clearFetchHandlers,
|
|
560
|
+
We as clearHandlers,
|
|
561
|
+
Te as clearRegistry,
|
|
562
|
+
Ve as createDebugPlugin,
|
|
563
|
+
Ue as createStonecropPlugin,
|
|
564
|
+
Ae as createStonecropPreset,
|
|
565
|
+
me as getAllMeta,
|
|
566
|
+
Me as getFetchHandler,
|
|
567
|
+
Se as getHandler,
|
|
568
|
+
I as getMeta,
|
|
569
|
+
Je as hasHandler,
|
|
570
|
+
Pe as hasMeta,
|
|
571
|
+
ye as loadDoctypes,
|
|
572
|
+
Le as loadDoctypesFromObject,
|
|
573
|
+
Ke as makePgService,
|
|
574
|
+
qe as registerBuiltinHandlers,
|
|
575
|
+
_e as registerFetchHandler,
|
|
576
|
+
he as registerHandler,
|
|
577
|
+
Oe as typeDefs,
|
|
578
|
+
He as validateReferences
|
|
562
579
|
};
|
|
563
580
|
//# sourceMappingURL=index.js.map
|