@stonecrop/graphql-middleware 0.11.1 → 0.11.3
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/README.md +59 -63
- package/dist/graphql-middleware.d.ts +167 -0
- package/dist/index.js +426 -223
- package/dist/index.js.map +1 -1
- package/dist/plugin/postgraphile.js +221 -18
- package/dist/src/index.d.ts +4 -2
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/plugin/postgraphile.d.ts +56 -16
- package/dist/src/plugin/postgraphile.d.ts.map +1 -1
- package/dist/src/typeDefs.d.ts +7 -0
- package/dist/src/typeDefs.d.ts.map +1 -0
- package/dist/src/types/index.d.ts +1 -0
- package/dist/src/types/index.d.ts.map +1 -1
- package/dist/src/types/query.d.ts +132 -0
- package/dist/src/types/query.d.ts.map +1 -0
- package/dist/typeDefs.js +79 -0
- package/dist/types/query.js +3 -0
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,184 +1,184 @@
|
|
|
1
|
-
import { readdirSync as
|
|
2
|
-
import { join as
|
|
3
|
-
import { validateDoctype as
|
|
4
|
-
import { loadOne as
|
|
5
|
-
import { extendSchema as
|
|
6
|
-
import
|
|
7
|
-
const
|
|
8
|
-
class
|
|
9
|
-
constructor(t,
|
|
10
|
-
const
|
|
1
|
+
import { readdirSync as W, statSync as _, readFileSync as P } from "node:fs";
|
|
2
|
+
import { join as U } from "node:path";
|
|
3
|
+
import { validateDoctype as E, parseDoctype as I, toPascalCase as A, snakeToCamel as H } from "@stonecrop/schema";
|
|
4
|
+
import { loadOne as M, object as R, constant as Q, lambda as V } from "postgraphile/grafast";
|
|
5
|
+
import { extendSchema as z, gql as J } from "postgraphile/utils";
|
|
6
|
+
import j from "pluralize";
|
|
7
|
+
const N = /* @__PURE__ */ new Map();
|
|
8
|
+
class O extends Error {
|
|
9
|
+
constructor(t, n) {
|
|
10
|
+
const c = n.map((o) => ` ${o.path.join(".")}: ${o.message}`).join(`
|
|
11
11
|
`);
|
|
12
12
|
super(`Invalid doctype definition in ${t}:
|
|
13
|
-
${
|
|
13
|
+
${c}`), this.file = t, this.errors = n, this.name = "DoctypeValidationError";
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
|
-
function
|
|
17
|
-
const
|
|
18
|
-
for (const
|
|
19
|
-
const
|
|
20
|
-
|
|
16
|
+
function G(e, t = {}) {
|
|
17
|
+
const n = W(e);
|
|
18
|
+
for (const c of n) {
|
|
19
|
+
const o = U(e, c);
|
|
20
|
+
_(o).isDirectory() ? G(o, t) : c.endsWith(".json") && Y(o, t);
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
|
-
function
|
|
24
|
-
const
|
|
25
|
-
let
|
|
23
|
+
function Y(e, t) {
|
|
24
|
+
const n = P(e, "utf-8");
|
|
25
|
+
let c;
|
|
26
26
|
try {
|
|
27
|
-
|
|
28
|
-
} catch (
|
|
29
|
-
const
|
|
27
|
+
c = JSON.parse(n);
|
|
28
|
+
} catch (s) {
|
|
29
|
+
const i = {
|
|
30
30
|
path: [],
|
|
31
|
-
message: `Invalid JSON: ${
|
|
31
|
+
message: `Invalid JSON: ${s instanceof Error ? s.message : String(s)}`
|
|
32
32
|
};
|
|
33
33
|
if (t.continueOnError) {
|
|
34
|
-
t.onError?.(e, [
|
|
34
|
+
t.onError?.(e, [i]);
|
|
35
35
|
return;
|
|
36
36
|
}
|
|
37
|
-
throw new
|
|
37
|
+
throw new O(e, [i]);
|
|
38
38
|
}
|
|
39
|
-
const
|
|
40
|
-
if (!
|
|
39
|
+
const o = E(c);
|
|
40
|
+
if (!o.success) {
|
|
41
41
|
if (t.continueOnError) {
|
|
42
|
-
t.onError?.(e,
|
|
42
|
+
t.onError?.(e, o.errors);
|
|
43
43
|
return;
|
|
44
44
|
}
|
|
45
|
-
throw new
|
|
45
|
+
throw new O(e, o.errors);
|
|
46
46
|
}
|
|
47
|
-
const
|
|
48
|
-
|
|
47
|
+
const r = I(c);
|
|
48
|
+
N.set(r.name, r);
|
|
49
49
|
}
|
|
50
|
-
function
|
|
51
|
-
for (const [
|
|
52
|
-
const
|
|
53
|
-
if (!
|
|
50
|
+
function be(e, t = {}) {
|
|
51
|
+
for (const [n, c] of Object.entries(e)) {
|
|
52
|
+
const o = { ...c, name: n }, r = E(o);
|
|
53
|
+
if (!r.success) {
|
|
54
54
|
if (t.continueOnError) {
|
|
55
|
-
t.onError?.(
|
|
55
|
+
t.onError?.(n, r.errors);
|
|
56
56
|
continue;
|
|
57
57
|
}
|
|
58
|
-
throw new
|
|
58
|
+
throw new O(n, r.errors);
|
|
59
59
|
}
|
|
60
|
-
const
|
|
61
|
-
|
|
60
|
+
const s = I(o);
|
|
61
|
+
N.set(s.name, s);
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
|
-
function
|
|
65
|
-
return
|
|
64
|
+
function k(e) {
|
|
65
|
+
return N.get(e);
|
|
66
66
|
}
|
|
67
|
-
function
|
|
68
|
-
return Array.from(
|
|
67
|
+
function K() {
|
|
68
|
+
return Array.from(N.values());
|
|
69
69
|
}
|
|
70
|
-
function
|
|
71
|
-
return
|
|
70
|
+
function Me(e) {
|
|
71
|
+
return N.has(e);
|
|
72
72
|
}
|
|
73
|
-
function
|
|
74
|
-
|
|
73
|
+
function Re() {
|
|
74
|
+
N.clear();
|
|
75
75
|
}
|
|
76
|
-
function
|
|
76
|
+
function Oe() {
|
|
77
77
|
const e = [];
|
|
78
|
-
for (const t of
|
|
79
|
-
t.inherits && !
|
|
78
|
+
for (const t of N.values()) {
|
|
79
|
+
t.inherits && !N.has(t.inherits) && e.push({
|
|
80
80
|
path: [t.name, "inherits"],
|
|
81
81
|
message: `References unknown doctype: ${t.inherits}`
|
|
82
82
|
});
|
|
83
|
-
for (const
|
|
84
|
-
|
|
85
|
-
path: [t.name, "fields",
|
|
86
|
-
message: `Link references unknown doctype: ${
|
|
83
|
+
for (const n of t.fields)
|
|
84
|
+
n.fieldtype === "Link" && typeof n.options == "string" && (N.has(n.options) || e.push({
|
|
85
|
+
path: [t.name, "fields", n.fieldname, "options"],
|
|
86
|
+
message: `Link references unknown doctype: ${n.options}`
|
|
87
87
|
}));
|
|
88
88
|
}
|
|
89
89
|
return e;
|
|
90
90
|
}
|
|
91
|
-
const
|
|
92
|
-
function
|
|
93
|
-
|
|
91
|
+
const b = /* @__PURE__ */ new Map();
|
|
92
|
+
function X(e, t) {
|
|
93
|
+
b.set(e, t);
|
|
94
94
|
}
|
|
95
|
-
function
|
|
96
|
-
return
|
|
95
|
+
function Z(e) {
|
|
96
|
+
return b.get(e);
|
|
97
97
|
}
|
|
98
|
-
function
|
|
99
|
-
return
|
|
98
|
+
function Ae(e) {
|
|
99
|
+
return b.has(e);
|
|
100
100
|
}
|
|
101
|
-
function
|
|
102
|
-
|
|
101
|
+
function Fe() {
|
|
102
|
+
b.clear();
|
|
103
103
|
}
|
|
104
|
-
const
|
|
105
|
-
const [
|
|
106
|
-
for (const
|
|
107
|
-
|
|
108
|
-
if (
|
|
109
|
-
throw new Error(`Missing required fields: ${
|
|
104
|
+
const ee = async (e, t) => {
|
|
105
|
+
const [n] = e, { doctype: c } = t, o = [];
|
|
106
|
+
for (const r of c.fields)
|
|
107
|
+
r.required && (n[r.fieldname] === void 0 || n[r.fieldname] === null) && o.push(r.label ?? r.fieldname);
|
|
108
|
+
if (o.length > 0)
|
|
109
|
+
throw new Error(`Missing required fields: ${o.join(", ")}`);
|
|
110
110
|
return { valid: !0 };
|
|
111
|
-
},
|
|
112
|
-
const [
|
|
113
|
-
for (const
|
|
114
|
-
const
|
|
115
|
-
if (
|
|
116
|
-
const
|
|
117
|
-
|
|
111
|
+
}, te = async (e, t) => {
|
|
112
|
+
const [n] = e, { doctype: c } = t, o = [];
|
|
113
|
+
for (const r of c.fields) {
|
|
114
|
+
const s = n[r.fieldname];
|
|
115
|
+
if (s == null) continue;
|
|
116
|
+
const i = ne(r, s);
|
|
117
|
+
i && o.push(i);
|
|
118
118
|
}
|
|
119
|
-
if (
|
|
120
|
-
for (const [
|
|
121
|
-
const
|
|
122
|
-
if (
|
|
123
|
-
|
|
119
|
+
if (c.links)
|
|
120
|
+
for (const [r, s] of Object.entries(c.links)) {
|
|
121
|
+
const i = n[r];
|
|
122
|
+
if (i == null) continue;
|
|
123
|
+
s.cardinality === "noneOrMany" || s.cardinality === "atLeastOne" ? Array.isArray(i) || o.push(`${r}: expected array, got ${typeof i}`) : (typeof i != "object" || Array.isArray(i)) && o.push(`${r}: expected object, got ${typeof i}`);
|
|
124
124
|
}
|
|
125
|
-
if (
|
|
125
|
+
if (o.length > 0)
|
|
126
126
|
throw new Error(`Field type validation failed:
|
|
127
|
-
${
|
|
127
|
+
${o.join(`
|
|
128
128
|
`)}`);
|
|
129
129
|
return { valid: !0 };
|
|
130
130
|
};
|
|
131
|
-
function
|
|
132
|
-
const { fieldname:
|
|
133
|
-
switch (
|
|
131
|
+
function ne(e, t) {
|
|
132
|
+
const { fieldname: n, fieldtype: c, cardinality: o } = e;
|
|
133
|
+
switch (c) {
|
|
134
134
|
case "Int":
|
|
135
135
|
if (typeof t != "number" || !Number.isInteger(t))
|
|
136
|
-
return `${
|
|
136
|
+
return `${n}: expected integer, got ${typeof t}`;
|
|
137
137
|
break;
|
|
138
138
|
case "Float":
|
|
139
139
|
case "Decimal":
|
|
140
140
|
case "Currency":
|
|
141
141
|
case "Quantity":
|
|
142
142
|
if (typeof t != "number" && typeof t != "string")
|
|
143
|
-
return `${
|
|
143
|
+
return `${n}: expected number, got ${typeof t}`;
|
|
144
144
|
break;
|
|
145
145
|
case "Check":
|
|
146
146
|
if (typeof t != "boolean")
|
|
147
|
-
return `${
|
|
147
|
+
return `${n}: expected boolean, got ${typeof t}`;
|
|
148
148
|
break;
|
|
149
149
|
case "Data":
|
|
150
150
|
case "Text":
|
|
151
151
|
case "Code":
|
|
152
152
|
case "Link":
|
|
153
153
|
if (typeof t != "string")
|
|
154
|
-
return `${
|
|
154
|
+
return `${n}: expected string, got ${typeof t}`;
|
|
155
155
|
break;
|
|
156
156
|
case "Date":
|
|
157
157
|
case "Time":
|
|
158
158
|
case "Datetime":
|
|
159
159
|
if (typeof t != "string" && !(t instanceof Date))
|
|
160
|
-
return `${
|
|
160
|
+
return `${n}: expected date string or Date, got ${typeof t}`;
|
|
161
161
|
break;
|
|
162
162
|
case "JSON":
|
|
163
163
|
if (typeof t != "object")
|
|
164
|
-
return `${
|
|
164
|
+
return `${n}: expected object, got ${typeof t}`;
|
|
165
165
|
break;
|
|
166
166
|
}
|
|
167
167
|
return null;
|
|
168
168
|
}
|
|
169
|
-
const
|
|
170
|
-
validateRequiredFields:
|
|
171
|
-
validateFieldTypes:
|
|
172
|
-
noop:
|
|
169
|
+
const oe = async () => ({ ok: !0 }), re = {
|
|
170
|
+
validateRequiredFields: ee,
|
|
171
|
+
validateFieldTypes: te,
|
|
172
|
+
noop: oe
|
|
173
173
|
};
|
|
174
|
-
function
|
|
175
|
-
for (const [e, t] of Object.entries(
|
|
176
|
-
|
|
174
|
+
function Be() {
|
|
175
|
+
for (const [e, t] of Object.entries(re))
|
|
176
|
+
X(e, t);
|
|
177
177
|
}
|
|
178
|
-
const
|
|
179
|
-
const t = e.inflection?.recordFieldName ??
|
|
180
|
-
return
|
|
181
|
-
typeDefs:
|
|
178
|
+
const De = (e) => {
|
|
179
|
+
const t = e.inflection?.recordFieldName ?? ie, n = e.inflection?.connectionFieldName ?? ce, c = e.inflection?.orderByTypeName ?? se, o = e.inflection?.recordArgName ?? ae, r = e.inflection?.recordArgType ?? le, s = e.inflection?.reverseConnectionName ?? F;
|
|
180
|
+
return z(() => ({
|
|
181
|
+
typeDefs: J`
|
|
182
182
|
type StonecropFieldMeta {
|
|
183
183
|
fieldname: String!
|
|
184
184
|
fieldtype: String!
|
|
@@ -225,6 +225,7 @@ const Se = (e) => {
|
|
|
225
225
|
type StonecropRecordResult {
|
|
226
226
|
data: JSON
|
|
227
227
|
doctype: String!
|
|
228
|
+
unknownLinks: [String!]
|
|
228
229
|
}
|
|
229
230
|
|
|
230
231
|
type StonecropRecordsResult {
|
|
@@ -242,7 +243,7 @@ const Se = (e) => {
|
|
|
242
243
|
extend type Query {
|
|
243
244
|
stonecropMeta(doctype: String!): StonecropDoctypeMeta
|
|
244
245
|
stonecropAllMeta: [StonecropDoctypeMeta!]!
|
|
245
|
-
stonecropRecord(doctype: String!, id: String
|
|
246
|
+
stonecropRecord(doctype: String!, id: String!, options: JSON): StonecropRecordResult
|
|
246
247
|
stonecropRecords(
|
|
247
248
|
doctype: String!
|
|
248
249
|
filters: JSON
|
|
@@ -259,64 +260,87 @@ const Se = (e) => {
|
|
|
259
260
|
objects: {
|
|
260
261
|
Query: {
|
|
261
262
|
plans: {
|
|
262
|
-
stonecropMeta(
|
|
263
|
-
return
|
|
263
|
+
stonecropMeta(i, { $doctype: l }) {
|
|
264
|
+
return V(l, (y) => k(y) ?? null);
|
|
264
265
|
},
|
|
265
266
|
stonecropAllMeta() {
|
|
266
|
-
return
|
|
267
|
+
return Q(K());
|
|
267
268
|
},
|
|
268
|
-
stonecropRecord(
|
|
269
|
-
return
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
269
|
+
stonecropRecord(i, { $doctype: l, $id: y, $options: p }) {
|
|
270
|
+
return M(
|
|
271
|
+
R({ doctype: l, id: y, options: p }),
|
|
272
|
+
async (d) => await Promise.all(
|
|
273
|
+
d.map(async (f) => {
|
|
274
|
+
const u = k(f.doctype);
|
|
275
|
+
if (!u)
|
|
276
|
+
throw new Error(`Unknown doctype: ${f.doctype}`);
|
|
277
|
+
if (!u.tableName)
|
|
278
|
+
throw new Error(`Doctype ${f.doctype} has no table mapping`);
|
|
279
|
+
const a = f.options ?? {}, h = ue(
|
|
280
|
+
u,
|
|
281
|
+
t,
|
|
282
|
+
o,
|
|
283
|
+
r,
|
|
284
|
+
k,
|
|
285
|
+
a.includeNested ? {
|
|
286
|
+
includeNested: a.includeNested,
|
|
287
|
+
maxDepth: a.maxDepth
|
|
288
|
+
} : void 0,
|
|
289
|
+
s
|
|
290
|
+
), g = await e.executor.query(h, {
|
|
291
|
+
[o(u.tableName)]: f.id
|
|
292
|
+
});
|
|
293
|
+
let S = ge({ result: g, meta: u, recordFieldName: t });
|
|
294
|
+
a.includeNested && S && u.links && (S = ye({
|
|
295
|
+
record: S,
|
|
296
|
+
meta: u,
|
|
297
|
+
getMeta: k,
|
|
298
|
+
reverseConnectionNameFn: s
|
|
299
|
+
}));
|
|
300
|
+
const m = Array.isArray(a.includeNested) && u.links ? a.includeNested.filter((w) => !(w in u.links)) : void 0;
|
|
301
|
+
return {
|
|
302
|
+
data: S,
|
|
303
|
+
doctype: f.doctype,
|
|
304
|
+
...m ? { unknownLinks: m } : {}
|
|
305
|
+
};
|
|
306
|
+
})
|
|
307
|
+
)
|
|
308
|
+
);
|
|
285
309
|
},
|
|
286
|
-
stonecropRecords(
|
|
287
|
-
return
|
|
288
|
-
|
|
289
|
-
doctype:
|
|
290
|
-
filters:
|
|
291
|
-
orderBy:
|
|
292
|
-
limit:
|
|
293
|
-
offset:
|
|
310
|
+
stonecropRecords(i, { $doctype: l, $filters: y, $orderBy: p, $limit: d, $offset: f }) {
|
|
311
|
+
return M(
|
|
312
|
+
R({
|
|
313
|
+
doctype: l,
|
|
314
|
+
filters: y,
|
|
315
|
+
orderBy: p,
|
|
316
|
+
limit: d,
|
|
317
|
+
offset: f
|
|
294
318
|
}),
|
|
295
|
-
async (
|
|
296
|
-
|
|
297
|
-
const
|
|
298
|
-
if (!
|
|
299
|
-
throw new Error(`Unknown doctype: ${
|
|
300
|
-
if (!
|
|
301
|
-
throw new Error(`Doctype ${
|
|
302
|
-
const
|
|
303
|
-
|
|
319
|
+
async (u) => await Promise.all(
|
|
320
|
+
u.map(async (a) => {
|
|
321
|
+
const h = k(a.doctype);
|
|
322
|
+
if (!h)
|
|
323
|
+
throw new Error(`Unknown doctype: ${a.doctype}`);
|
|
324
|
+
if (!h.tableName)
|
|
325
|
+
throw new Error(`Doctype ${a.doctype} has no table mapping`);
|
|
326
|
+
const g = pe(
|
|
327
|
+
h,
|
|
304
328
|
{
|
|
305
|
-
limit:
|
|
306
|
-
offset:
|
|
307
|
-
orderBy:
|
|
329
|
+
limit: a.limit,
|
|
330
|
+
offset: a.offset,
|
|
331
|
+
orderBy: a.orderBy
|
|
308
332
|
},
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
),
|
|
312
|
-
limit:
|
|
313
|
-
offset:
|
|
314
|
-
orderBy:
|
|
315
|
-
}),
|
|
333
|
+
n,
|
|
334
|
+
c
|
|
335
|
+
), S = await e.executor.query(g, {
|
|
336
|
+
limit: a.limit,
|
|
337
|
+
offset: a.offset,
|
|
338
|
+
orderBy: a.orderBy
|
|
339
|
+
}), m = me({ result: S, meta: h, connectionFieldName: n });
|
|
316
340
|
return {
|
|
317
|
-
data:
|
|
318
|
-
doctype:
|
|
319
|
-
count:
|
|
341
|
+
data: m,
|
|
342
|
+
doctype: a.doctype,
|
|
343
|
+
count: m.length
|
|
320
344
|
};
|
|
321
345
|
})
|
|
322
346
|
)
|
|
@@ -326,51 +350,51 @@ const Se = (e) => {
|
|
|
326
350
|
},
|
|
327
351
|
Mutation: {
|
|
328
352
|
plans: {
|
|
329
|
-
stonecropAction(
|
|
330
|
-
return
|
|
331
|
-
|
|
332
|
-
doctype:
|
|
333
|
-
action:
|
|
334
|
-
actionArgs:
|
|
353
|
+
stonecropAction(i, { $doctype: l, $action: y, $args: p }) {
|
|
354
|
+
return M(
|
|
355
|
+
R({
|
|
356
|
+
doctype: l,
|
|
357
|
+
action: y,
|
|
358
|
+
actionArgs: p
|
|
335
359
|
}),
|
|
336
|
-
async (
|
|
337
|
-
|
|
338
|
-
const
|
|
339
|
-
if (!
|
|
360
|
+
async (d) => await Promise.all(
|
|
361
|
+
d.map(async (f) => {
|
|
362
|
+
const u = k(f.doctype);
|
|
363
|
+
if (!u)
|
|
340
364
|
return {
|
|
341
365
|
success: !1,
|
|
342
366
|
data: null,
|
|
343
|
-
error: `Unknown doctype: ${
|
|
367
|
+
error: `Unknown doctype: ${f.doctype}`
|
|
344
368
|
};
|
|
345
|
-
const
|
|
346
|
-
if (!
|
|
369
|
+
const a = u.workflow?.actions?.[f.action];
|
|
370
|
+
if (!a)
|
|
347
371
|
return {
|
|
348
372
|
success: !1,
|
|
349
373
|
data: null,
|
|
350
|
-
error: `Unknown action: ${
|
|
374
|
+
error: `Unknown action: ${f.action} on ${f.doctype}`
|
|
351
375
|
};
|
|
352
|
-
const
|
|
353
|
-
if (!
|
|
376
|
+
const h = a.handler, g = Z(h);
|
|
377
|
+
if (!g)
|
|
354
378
|
return {
|
|
355
379
|
success: !1,
|
|
356
380
|
data: null,
|
|
357
|
-
error: `Handler not registered: ${
|
|
381
|
+
error: `Handler not registered: ${h}`
|
|
358
382
|
};
|
|
359
|
-
const
|
|
360
|
-
doctype:
|
|
383
|
+
const S = {
|
|
384
|
+
doctype: u,
|
|
361
385
|
executor: e.executor
|
|
362
386
|
};
|
|
363
387
|
try {
|
|
364
388
|
return {
|
|
365
389
|
success: !0,
|
|
366
|
-
data: await
|
|
390
|
+
data: await g(f.actionArgs ?? [], S),
|
|
367
391
|
error: null
|
|
368
392
|
};
|
|
369
|
-
} catch (
|
|
393
|
+
} catch (m) {
|
|
370
394
|
return {
|
|
371
395
|
success: !1,
|
|
372
396
|
data: null,
|
|
373
|
-
error:
|
|
397
|
+
error: m instanceof Error ? m.message : String(m)
|
|
374
398
|
};
|
|
375
399
|
}
|
|
376
400
|
})
|
|
@@ -382,81 +406,260 @@ const Se = (e) => {
|
|
|
382
406
|
}
|
|
383
407
|
}));
|
|
384
408
|
};
|
|
385
|
-
function
|
|
386
|
-
const t =
|
|
387
|
-
return `${
|
|
409
|
+
function ie(e) {
|
|
410
|
+
const t = j.singular(e);
|
|
411
|
+
return `${H(t)}ById`;
|
|
388
412
|
}
|
|
389
|
-
function
|
|
413
|
+
function ce(e) {
|
|
390
414
|
return `all${A(e)}`;
|
|
391
415
|
}
|
|
392
|
-
function
|
|
416
|
+
function se(e) {
|
|
393
417
|
return `${A(e)}OrderBy`;
|
|
394
418
|
}
|
|
395
|
-
function
|
|
419
|
+
function ae(e) {
|
|
396
420
|
return "id";
|
|
397
421
|
}
|
|
398
|
-
function
|
|
422
|
+
function le(e) {
|
|
399
423
|
return "UUID!";
|
|
400
424
|
}
|
|
401
|
-
|
|
425
|
+
function F(e) {
|
|
426
|
+
const t = j.plural(e.target.replace(/-/g, "_")), n = A(t), c = e.backlink || e.doctype, o = c.charAt(0).toUpperCase() + c.slice(1);
|
|
427
|
+
return `${n}By${o}Id`;
|
|
428
|
+
}
|
|
429
|
+
function B(e) {
|
|
430
|
+
return e === "noneOrMany" || e === "atLeastOne";
|
|
431
|
+
}
|
|
432
|
+
const q = 50, de = /* @__PURE__ */ new Set(["Link"]);
|
|
402
433
|
function D(e) {
|
|
403
|
-
return e.fields.filter((t) => !
|
|
434
|
+
return e.fields.filter((t) => !de.has(t.fieldtype)).map((t) => t.fieldname).join(`
|
|
404
435
|
`);
|
|
405
436
|
}
|
|
406
|
-
function
|
|
407
|
-
|
|
437
|
+
function T(e) {
|
|
438
|
+
return e.fetch !== void 0 ? e.fetch : B(e.cardinality) ? { method: "sync", limit: q } : { method: "lazy" };
|
|
439
|
+
}
|
|
440
|
+
function fe(e) {
|
|
441
|
+
return e.blockWorkflows !== void 0 ? e.blockWorkflows : T(e).method === "sync";
|
|
442
|
+
}
|
|
443
|
+
function C(e) {
|
|
444
|
+
const { links: t, meta: n, includeSet: c, getMeta: o, seen: r, depth: s, maxDepth: i, reverseConnectionNameFn: l } = e;
|
|
445
|
+
if (i !== void 0 && s >= i) return "";
|
|
446
|
+
const y = [];
|
|
447
|
+
for (const [p, d] of Object.entries(t)) {
|
|
448
|
+
if (i !== void 0 && s >= i) break;
|
|
449
|
+
const f = fe(d), u = d.blockWorkflows === !0;
|
|
450
|
+
if (c && !c.has(p) && !u)
|
|
451
|
+
continue;
|
|
452
|
+
const a = T(d);
|
|
453
|
+
if (f === !1 || a.method !== "sync" && !u)
|
|
454
|
+
continue;
|
|
455
|
+
const g = o(d.target);
|
|
456
|
+
if (!g) continue;
|
|
457
|
+
const S = r.has(d.target);
|
|
458
|
+
S || r.add(d.target);
|
|
459
|
+
const m = D(g);
|
|
460
|
+
let w = "";
|
|
461
|
+
if (!S && g.links && g.tableName && (i === void 0 || s + 1 < i)) {
|
|
462
|
+
const $ = C({
|
|
463
|
+
links: g.links,
|
|
464
|
+
meta: g,
|
|
465
|
+
includeSet: null,
|
|
466
|
+
getMeta: o,
|
|
467
|
+
seen: r,
|
|
468
|
+
depth: s + 1,
|
|
469
|
+
maxDepth: i,
|
|
470
|
+
reverseConnectionNameFn: l
|
|
471
|
+
});
|
|
472
|
+
$ && (w = `
|
|
473
|
+
` + $), r.delete(d.target);
|
|
474
|
+
}
|
|
475
|
+
const v = m + w;
|
|
476
|
+
if (B(d.cardinality)) {
|
|
477
|
+
const $ = {
|
|
478
|
+
doctype: n.slug || n.name,
|
|
479
|
+
linkName: p,
|
|
480
|
+
backlink: d.backlink,
|
|
481
|
+
target: d.target
|
|
482
|
+
}, L = l ? l($) : F($), x = a.method === "sync" && a.limit !== void 0 ? `first: ${a.limit}` : a.method === "sync" ? `first: ${q}` : "";
|
|
483
|
+
y.push(`
|
|
484
|
+
${L}${x ? `(${x})` : ""} {
|
|
485
|
+
nodes {
|
|
486
|
+
${v}
|
|
487
|
+
}
|
|
488
|
+
}`);
|
|
489
|
+
} else
|
|
490
|
+
y.push(`
|
|
491
|
+
${p} {
|
|
492
|
+
${v}
|
|
493
|
+
}`);
|
|
494
|
+
}
|
|
495
|
+
return y.join("");
|
|
496
|
+
}
|
|
497
|
+
function ue(e, t, n, c, o, r, s) {
|
|
498
|
+
const i = t(e.tableName), l = n(e.tableName), y = c(e.tableName), p = /* @__PURE__ */ new Set([e.slug || e.name]);
|
|
499
|
+
let d = D(e);
|
|
500
|
+
if (r?.includeNested && e.links) {
|
|
501
|
+
const f = Array.isArray(r.includeNested) ? new Set(r.includeNested) : null, u = C({
|
|
502
|
+
links: e.links,
|
|
503
|
+
meta: e,
|
|
504
|
+
includeSet: f,
|
|
505
|
+
getMeta: o,
|
|
506
|
+
seen: p,
|
|
507
|
+
depth: 0,
|
|
508
|
+
maxDepth: r.maxDepth,
|
|
509
|
+
reverseConnectionNameFn: s
|
|
510
|
+
});
|
|
511
|
+
u && (d += `
|
|
512
|
+
` + u);
|
|
513
|
+
}
|
|
408
514
|
return `
|
|
409
|
-
query GetRecord($${
|
|
410
|
-
${
|
|
411
|
-
${
|
|
515
|
+
query GetRecord($${l}: ${y}) {
|
|
516
|
+
${i}(${l}: $${l}) {
|
|
517
|
+
${d}
|
|
412
518
|
}
|
|
413
519
|
}
|
|
414
520
|
`;
|
|
415
521
|
}
|
|
416
|
-
function
|
|
417
|
-
const
|
|
418
|
-
t.limit && (
|
|
419
|
-
const y =
|
|
522
|
+
function pe(e, t, n, c) {
|
|
523
|
+
const o = D(e), r = n(e.tableName), s = c(e.tableName), i = [], l = [];
|
|
524
|
+
t.limit && (i.push("$limit: Int"), l.push("first: $limit")), t.offset && (i.push("$offset: Int"), l.push("offset: $offset")), t.orderBy && (i.push(`$orderBy: [${s}!]`), l.push("orderBy: $orderBy"));
|
|
525
|
+
const y = i.length > 0 ? `(${i.join(", ")})` : "", p = l.length > 0 ? `(${l.join(", ")})` : "";
|
|
420
526
|
return `
|
|
421
527
|
query GetRecords${y} {
|
|
422
|
-
${
|
|
528
|
+
${r}${p} {
|
|
423
529
|
nodes {
|
|
424
|
-
${
|
|
530
|
+
${o}
|
|
425
531
|
}
|
|
426
532
|
}
|
|
427
533
|
}
|
|
428
534
|
`;
|
|
429
535
|
}
|
|
430
|
-
function
|
|
431
|
-
const
|
|
432
|
-
return
|
|
536
|
+
function ye(e) {
|
|
537
|
+
const { record: t, meta: n, getMeta: c, reverseConnectionNameFn: o } = e;
|
|
538
|
+
if (!n.links) return t;
|
|
539
|
+
const r = { ...t };
|
|
540
|
+
for (const [s, i] of Object.entries(n.links))
|
|
541
|
+
if (B(i.cardinality)) {
|
|
542
|
+
if (!c(i.target)) continue;
|
|
543
|
+
const p = {
|
|
544
|
+
doctype: n.slug || n.name,
|
|
545
|
+
linkName: s,
|
|
546
|
+
backlink: i.backlink || s,
|
|
547
|
+
target: i.target
|
|
548
|
+
}, d = o ? o(p) : F(p), f = r[d];
|
|
549
|
+
f?.nodes ? (r[s] = f.nodes, delete r[d]) : (r[s] = [], delete r[d]);
|
|
550
|
+
}
|
|
551
|
+
return r;
|
|
552
|
+
}
|
|
553
|
+
function ge(e) {
|
|
554
|
+
const { result: t, meta: n, recordFieldName: c } = e, o = c(n.tableName);
|
|
555
|
+
return t[o];
|
|
433
556
|
}
|
|
434
|
-
function
|
|
435
|
-
const
|
|
436
|
-
return
|
|
557
|
+
function me(e) {
|
|
558
|
+
const { result: t, meta: n, connectionFieldName: c } = e, o = c(n.tableName);
|
|
559
|
+
return t[o]?.nodes ?? [];
|
|
437
560
|
}
|
|
561
|
+
const ve = J`
|
|
562
|
+
type StonecropFieldMeta {
|
|
563
|
+
fieldname: String!
|
|
564
|
+
fieldtype: String!
|
|
565
|
+
component: String
|
|
566
|
+
label: String
|
|
567
|
+
width: String
|
|
568
|
+
align: String
|
|
569
|
+
required: Boolean
|
|
570
|
+
readOnly: Boolean
|
|
571
|
+
edit: Boolean
|
|
572
|
+
hidden: Boolean
|
|
573
|
+
default: JSON
|
|
574
|
+
options: JSON
|
|
575
|
+
mask: String
|
|
576
|
+
precision: Int
|
|
577
|
+
scale: Int
|
|
578
|
+
mode: String
|
|
579
|
+
validation: JSON
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
type StonecropWorkflowAction {
|
|
583
|
+
label: String!
|
|
584
|
+
handler: String!
|
|
585
|
+
requiredFields: [String!]
|
|
586
|
+
allowedStates: [String!]
|
|
587
|
+
confirm: Boolean
|
|
588
|
+
args: JSON
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
type StonecropWorkflowMeta {
|
|
592
|
+
states: [String!]
|
|
593
|
+
actions: [StonecropWorkflowAction!]
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
type StonecropDoctypeMeta {
|
|
597
|
+
name: String!
|
|
598
|
+
slug: String
|
|
599
|
+
tableName: String
|
|
600
|
+
fields: [StonecropFieldMeta!]!
|
|
601
|
+
workflow: StonecropWorkflowMeta
|
|
602
|
+
inherits: String
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
type StonecropRecordResult {
|
|
606
|
+
data: JSON
|
|
607
|
+
doctype: String!
|
|
608
|
+
unknownLinks: [String!]
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
type StonecropRecordsResult {
|
|
612
|
+
data: [JSON!]!
|
|
613
|
+
doctype: String!
|
|
614
|
+
count: Int!
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
type StonecropActionResult {
|
|
618
|
+
success: Boolean!
|
|
619
|
+
data: JSON
|
|
620
|
+
error: String
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
extend type Query {
|
|
624
|
+
stonecropMeta(doctype: String!): StonecropDoctypeMeta
|
|
625
|
+
stonecropAllMeta: [StonecropDoctypeMeta!]!
|
|
626
|
+
stonecropRecord(doctype: String!, id: String!, options: JSON): StonecropRecordResult
|
|
627
|
+
stonecropRecords(doctype: String!, filters: JSON, orderBy: String, limit: Int, offset: Int): StonecropRecordsResult
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
extend type Mutation {
|
|
631
|
+
stonecropAction(doctype: String!, action: String!, args: JSON): StonecropActionResult!
|
|
632
|
+
}
|
|
633
|
+
`;
|
|
438
634
|
export {
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
635
|
+
O as DoctypeValidationError,
|
|
636
|
+
de as RELATION_FIELDTYPES,
|
|
637
|
+
pe as buildListQuery,
|
|
638
|
+
ue as buildRecordQuery,
|
|
639
|
+
re as builtinHandlers,
|
|
640
|
+
Fe as clearHandlers,
|
|
641
|
+
Re as clearRegistry,
|
|
642
|
+
De as createStonecropPlugin,
|
|
643
|
+
ce as defaultConnectionFieldName,
|
|
644
|
+
se as defaultOrderByTypeName,
|
|
645
|
+
ae as defaultRecordArgName,
|
|
646
|
+
le as defaultRecordArgType,
|
|
647
|
+
ie as defaultRecordFieldName,
|
|
648
|
+
F as defaultReverseConnectionName,
|
|
649
|
+
me as extractListResult,
|
|
650
|
+
ge as extractSingleResult,
|
|
651
|
+
K as getAllMeta,
|
|
652
|
+
Z as getHandler,
|
|
653
|
+
k as getMeta,
|
|
654
|
+
Ae as hasHandler,
|
|
655
|
+
Me as hasMeta,
|
|
656
|
+
G as loadDoctypes,
|
|
657
|
+
be as loadDoctypesFromObject,
|
|
658
|
+
ye as mergeNestedResults,
|
|
457
659
|
D as queryableFieldNames,
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
660
|
+
Be as registerBuiltinHandlers,
|
|
661
|
+
X as registerHandler,
|
|
662
|
+
ve as typeDefs,
|
|
663
|
+
Oe as validateReferences
|
|
461
664
|
};
|
|
462
665
|
//# sourceMappingURL=index.js.map
|