@stonecrop/graphql-middleware 0.11.1 → 0.11.2
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 +165 -0
- package/dist/index.js +417 -220
- package/dist/index.js.map +1 -1
- package/dist/plugin/postgraphile.js +214 -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 +130 -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 i =
|
|
1
|
+
import { readdirSync as C, 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 k = /* @__PURE__ */ new Map();
|
|
8
|
+
class O extends Error {
|
|
9
|
+
constructor(t, n) {
|
|
10
|
+
const i = n.map((o) => ` ${o.path.join(".")}: ${o.message}`).join(`
|
|
11
11
|
`);
|
|
12
12
|
super(`Invalid doctype definition in ${t}:
|
|
13
|
-
${i}`), this.file = t, this.errors =
|
|
13
|
+
${i}`), this.file = t, this.errors = n, this.name = "DoctypeValidationError";
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
|
-
function
|
|
17
|
-
const
|
|
18
|
-
for (const i of
|
|
19
|
-
const
|
|
20
|
-
|
|
16
|
+
function G(e, t = {}) {
|
|
17
|
+
const n = C(e);
|
|
18
|
+
for (const i of n) {
|
|
19
|
+
const o = U(e, i);
|
|
20
|
+
_(o).isDirectory() ? G(o, t) : i.endsWith(".json") && Y(o, t);
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
|
-
function
|
|
24
|
-
const
|
|
23
|
+
function Y(e, t) {
|
|
24
|
+
const n = P(e, "utf-8");
|
|
25
25
|
let i;
|
|
26
26
|
try {
|
|
27
|
-
i = JSON.parse(
|
|
28
|
-
} catch (
|
|
29
|
-
const
|
|
27
|
+
i = JSON.parse(n);
|
|
28
|
+
} catch (s) {
|
|
29
|
+
const c = {
|
|
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, [c]);
|
|
35
35
|
return;
|
|
36
36
|
}
|
|
37
|
-
throw new
|
|
37
|
+
throw new O(e, [c]);
|
|
38
38
|
}
|
|
39
|
-
const
|
|
40
|
-
if (!
|
|
39
|
+
const o = E(i);
|
|
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(i);
|
|
48
|
+
k.set(r.name, r);
|
|
49
49
|
}
|
|
50
|
-
function
|
|
51
|
-
for (const [
|
|
52
|
-
const
|
|
53
|
-
if (!
|
|
50
|
+
function be(e, t = {}) {
|
|
51
|
+
for (const [n, i] of Object.entries(e)) {
|
|
52
|
+
const o = { ...i, 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
|
+
k.set(s.name, s);
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
|
-
function
|
|
65
|
-
return
|
|
64
|
+
function N(e) {
|
|
65
|
+
return k.get(e);
|
|
66
66
|
}
|
|
67
|
-
function
|
|
68
|
-
return Array.from(
|
|
67
|
+
function K() {
|
|
68
|
+
return Array.from(k.values());
|
|
69
69
|
}
|
|
70
|
-
function
|
|
71
|
-
return
|
|
70
|
+
function Me(e) {
|
|
71
|
+
return k.has(e);
|
|
72
72
|
}
|
|
73
|
-
function
|
|
74
|
-
|
|
73
|
+
function Re() {
|
|
74
|
+
k.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 k.values()) {
|
|
79
|
+
t.inherits && !k.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" && (k.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 Be() {
|
|
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: i } = t, o = [];
|
|
106
|
+
for (const r of i.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: i } = t, o = [];
|
|
113
|
+
for (const r of i.fields) {
|
|
114
|
+
const s = n[r.fieldname];
|
|
115
|
+
if (s == null) continue;
|
|
116
|
+
const c = ne(r, s);
|
|
117
|
+
c && o.push(c);
|
|
118
118
|
}
|
|
119
119
|
if (i.links)
|
|
120
|
-
for (const [
|
|
121
|
-
const
|
|
122
|
-
if (
|
|
123
|
-
|
|
120
|
+
for (const [r, s] of Object.entries(i.links)) {
|
|
121
|
+
const c = n[r];
|
|
122
|
+
if (c == null) continue;
|
|
123
|
+
s.cardinality === "noneOrMany" || s.cardinality === "atLeastOne" ? Array.isArray(c) || o.push(`${r}: expected array, got ${typeof c}`) : (typeof c != "object" || Array.isArray(c)) && o.push(`${r}: expected object, got ${typeof c}`);
|
|
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:
|
|
131
|
+
function ne(e, t) {
|
|
132
|
+
const { fieldname: n, fieldtype: i, cardinality: o } = e;
|
|
133
133
|
switch (i) {
|
|
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 De() {
|
|
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 Fe = (e) => {
|
|
179
|
+
const t = e.inflection?.recordFieldName ?? ie, n = e.inflection?.connectionFieldName ?? ce, i = e.inflection?.orderByTypeName ?? se, o = e.inflection?.recordArgName ?? ae, r = e.inflection?.recordArgType ?? le, s = e.inflection?.reverseConnectionName ?? B;
|
|
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,82 @@ const Se = (e) => {
|
|
|
259
260
|
objects: {
|
|
260
261
|
Query: {
|
|
261
262
|
plans: {
|
|
262
|
-
stonecropMeta(c, { $doctype:
|
|
263
|
-
return
|
|
263
|
+
stonecropMeta(c, { $doctype: l }) {
|
|
264
|
+
return V(l, (y) => N(y) ?? null);
|
|
264
265
|
},
|
|
265
266
|
stonecropAllMeta() {
|
|
266
|
-
return
|
|
267
|
+
return Q(K());
|
|
267
268
|
},
|
|
268
|
-
stonecropRecord(c, { $doctype:
|
|
269
|
-
return
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
269
|
+
stonecropRecord(c, { $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 (u) => {
|
|
274
|
+
const f = N(u.doctype);
|
|
275
|
+
if (!f)
|
|
276
|
+
throw new Error(`Unknown doctype: ${u.doctype}`);
|
|
277
|
+
if (!f.tableName)
|
|
278
|
+
throw new Error(`Doctype ${u.doctype} has no table mapping`);
|
|
279
|
+
const a = u.options ?? {}, h = ue(
|
|
280
|
+
f,
|
|
281
|
+
t,
|
|
282
|
+
o,
|
|
283
|
+
r,
|
|
284
|
+
N,
|
|
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(f.tableName)]: u.id
|
|
292
|
+
});
|
|
293
|
+
let S = ge({ result: g, meta: f, recordFieldName: t });
|
|
294
|
+
a.includeNested && S && f.links && (S = ye({ record: S, meta: f, getMeta: N }));
|
|
295
|
+
const m = Array.isArray(a.includeNested) && f.links ? a.includeNested.filter((w) => !(w in f.links)) : void 0;
|
|
296
|
+
return {
|
|
297
|
+
data: S,
|
|
298
|
+
doctype: u.doctype,
|
|
299
|
+
...m ? { unknownLinks: m } : {}
|
|
300
|
+
};
|
|
301
|
+
})
|
|
302
|
+
)
|
|
303
|
+
);
|
|
285
304
|
},
|
|
286
|
-
stonecropRecords(c, { $doctype:
|
|
287
|
-
return
|
|
288
|
-
|
|
289
|
-
doctype:
|
|
290
|
-
filters:
|
|
291
|
-
orderBy:
|
|
292
|
-
limit:
|
|
293
|
-
offset:
|
|
305
|
+
stonecropRecords(c, { $doctype: l, $filters: y, $orderBy: p, $limit: d, $offset: u }) {
|
|
306
|
+
return M(
|
|
307
|
+
R({
|
|
308
|
+
doctype: l,
|
|
309
|
+
filters: y,
|
|
310
|
+
orderBy: p,
|
|
311
|
+
limit: d,
|
|
312
|
+
offset: u
|
|
294
313
|
}),
|
|
295
|
-
async (
|
|
296
|
-
|
|
297
|
-
const
|
|
298
|
-
if (!
|
|
299
|
-
throw new Error(`Unknown doctype: ${
|
|
300
|
-
if (!
|
|
301
|
-
throw new Error(`Doctype ${
|
|
302
|
-
const
|
|
303
|
-
|
|
314
|
+
async (f) => await Promise.all(
|
|
315
|
+
f.map(async (a) => {
|
|
316
|
+
const h = N(a.doctype);
|
|
317
|
+
if (!h)
|
|
318
|
+
throw new Error(`Unknown doctype: ${a.doctype}`);
|
|
319
|
+
if (!h.tableName)
|
|
320
|
+
throw new Error(`Doctype ${a.doctype} has no table mapping`);
|
|
321
|
+
const g = pe(
|
|
322
|
+
h,
|
|
304
323
|
{
|
|
305
|
-
limit:
|
|
306
|
-
offset:
|
|
307
|
-
orderBy:
|
|
324
|
+
limit: a.limit,
|
|
325
|
+
offset: a.offset,
|
|
326
|
+
orderBy: a.orderBy
|
|
308
327
|
},
|
|
309
|
-
|
|
328
|
+
n,
|
|
310
329
|
i
|
|
311
|
-
),
|
|
312
|
-
limit:
|
|
313
|
-
offset:
|
|
314
|
-
orderBy:
|
|
315
|
-
}),
|
|
330
|
+
), S = await e.executor.query(g, {
|
|
331
|
+
limit: a.limit,
|
|
332
|
+
offset: a.offset,
|
|
333
|
+
orderBy: a.orderBy
|
|
334
|
+
}), m = me({ result: S, meta: h, connectionFieldName: n });
|
|
316
335
|
return {
|
|
317
|
-
data:
|
|
318
|
-
doctype:
|
|
319
|
-
count:
|
|
336
|
+
data: m,
|
|
337
|
+
doctype: a.doctype,
|
|
338
|
+
count: m.length
|
|
320
339
|
};
|
|
321
340
|
})
|
|
322
341
|
)
|
|
@@ -326,51 +345,51 @@ const Se = (e) => {
|
|
|
326
345
|
},
|
|
327
346
|
Mutation: {
|
|
328
347
|
plans: {
|
|
329
|
-
stonecropAction(c, { $doctype:
|
|
330
|
-
return
|
|
331
|
-
|
|
332
|
-
doctype:
|
|
333
|
-
action:
|
|
334
|
-
actionArgs:
|
|
348
|
+
stonecropAction(c, { $doctype: l, $action: y, $args: p }) {
|
|
349
|
+
return M(
|
|
350
|
+
R({
|
|
351
|
+
doctype: l,
|
|
352
|
+
action: y,
|
|
353
|
+
actionArgs: p
|
|
335
354
|
}),
|
|
336
|
-
async (
|
|
337
|
-
|
|
338
|
-
const
|
|
339
|
-
if (!
|
|
355
|
+
async (d) => await Promise.all(
|
|
356
|
+
d.map(async (u) => {
|
|
357
|
+
const f = N(u.doctype);
|
|
358
|
+
if (!f)
|
|
340
359
|
return {
|
|
341
360
|
success: !1,
|
|
342
361
|
data: null,
|
|
343
|
-
error: `Unknown doctype: ${
|
|
362
|
+
error: `Unknown doctype: ${u.doctype}`
|
|
344
363
|
};
|
|
345
|
-
const
|
|
346
|
-
if (!
|
|
364
|
+
const a = f.workflow?.actions?.[u.action];
|
|
365
|
+
if (!a)
|
|
347
366
|
return {
|
|
348
367
|
success: !1,
|
|
349
368
|
data: null,
|
|
350
|
-
error: `Unknown action: ${
|
|
369
|
+
error: `Unknown action: ${u.action} on ${u.doctype}`
|
|
351
370
|
};
|
|
352
|
-
const
|
|
353
|
-
if (!
|
|
371
|
+
const h = a.handler, g = Z(h);
|
|
372
|
+
if (!g)
|
|
354
373
|
return {
|
|
355
374
|
success: !1,
|
|
356
375
|
data: null,
|
|
357
|
-
error: `Handler not registered: ${
|
|
376
|
+
error: `Handler not registered: ${h}`
|
|
358
377
|
};
|
|
359
|
-
const
|
|
360
|
-
doctype:
|
|
378
|
+
const S = {
|
|
379
|
+
doctype: f,
|
|
361
380
|
executor: e.executor
|
|
362
381
|
};
|
|
363
382
|
try {
|
|
364
383
|
return {
|
|
365
384
|
success: !0,
|
|
366
|
-
data: await
|
|
385
|
+
data: await g(u.actionArgs ?? [], S),
|
|
367
386
|
error: null
|
|
368
387
|
};
|
|
369
|
-
} catch (
|
|
388
|
+
} catch (m) {
|
|
370
389
|
return {
|
|
371
390
|
success: !1,
|
|
372
391
|
data: null,
|
|
373
|
-
error:
|
|
392
|
+
error: m instanceof Error ? m.message : String(m)
|
|
374
393
|
};
|
|
375
394
|
}
|
|
376
395
|
})
|
|
@@ -382,81 +401,259 @@ const Se = (e) => {
|
|
|
382
401
|
}
|
|
383
402
|
}));
|
|
384
403
|
};
|
|
385
|
-
function
|
|
386
|
-
const t =
|
|
387
|
-
return `${
|
|
404
|
+
function ie(e) {
|
|
405
|
+
const t = j.singular(e);
|
|
406
|
+
return `${H(t)}ById`;
|
|
388
407
|
}
|
|
389
|
-
function
|
|
408
|
+
function ce(e) {
|
|
390
409
|
return `all${A(e)}`;
|
|
391
410
|
}
|
|
392
|
-
function
|
|
411
|
+
function se(e) {
|
|
393
412
|
return `${A(e)}OrderBy`;
|
|
394
413
|
}
|
|
395
|
-
function
|
|
414
|
+
function ae(e) {
|
|
396
415
|
return "id";
|
|
397
416
|
}
|
|
398
|
-
function
|
|
417
|
+
function le(e) {
|
|
399
418
|
return "UUID!";
|
|
400
419
|
}
|
|
401
|
-
|
|
420
|
+
function B(e) {
|
|
421
|
+
const t = j.plural(e.target.replace(/-/g, "_")), n = A(t), i = e.backlink || e.doctype, o = i.charAt(0).toUpperCase() + i.slice(1);
|
|
422
|
+
return `${n}By${o}Id`;
|
|
423
|
+
}
|
|
402
424
|
function D(e) {
|
|
403
|
-
return e
|
|
425
|
+
return e === "noneOrMany" || e === "atLeastOne";
|
|
426
|
+
}
|
|
427
|
+
const q = 50, de = /* @__PURE__ */ new Set(["Link"]);
|
|
428
|
+
function F(e) {
|
|
429
|
+
return e.fields.filter((t) => !de.has(t.fieldtype)).map((t) => t.fieldname).join(`
|
|
404
430
|
`);
|
|
405
431
|
}
|
|
406
|
-
function
|
|
407
|
-
|
|
432
|
+
function T(e) {
|
|
433
|
+
return e.fetch !== void 0 ? e.fetch : D(e.cardinality) ? { method: "sync", limit: q } : { method: "lazy" };
|
|
434
|
+
}
|
|
435
|
+
function fe(e) {
|
|
436
|
+
return e.blockWorkflows !== void 0 ? e.blockWorkflows : T(e).method === "sync";
|
|
437
|
+
}
|
|
438
|
+
function L(e) {
|
|
439
|
+
const { links: t, meta: n, includeSet: i, getMeta: o, seen: r, depth: s, maxDepth: c, reverseConnectionNameFn: l } = e;
|
|
440
|
+
if (c !== void 0 && s >= c) return "";
|
|
441
|
+
const y = [];
|
|
442
|
+
for (const [p, d] of Object.entries(t)) {
|
|
443
|
+
if (c !== void 0 && s >= c) break;
|
|
444
|
+
const u = fe(d), f = d.blockWorkflows === !0;
|
|
445
|
+
if (i && !i.has(p) && !f)
|
|
446
|
+
continue;
|
|
447
|
+
const a = T(d);
|
|
448
|
+
if (u === !1 || a.method !== "sync" && !f)
|
|
449
|
+
continue;
|
|
450
|
+
const g = o(d.target);
|
|
451
|
+
if (!g) continue;
|
|
452
|
+
const S = r.has(d.target);
|
|
453
|
+
S || r.add(d.target);
|
|
454
|
+
const m = F(g);
|
|
455
|
+
let w = "";
|
|
456
|
+
if (!S && g.links && g.tableName && (c === void 0 || s + 1 < c)) {
|
|
457
|
+
const $ = L({
|
|
458
|
+
links: g.links,
|
|
459
|
+
meta: g,
|
|
460
|
+
includeSet: null,
|
|
461
|
+
getMeta: o,
|
|
462
|
+
seen: r,
|
|
463
|
+
depth: s + 1,
|
|
464
|
+
maxDepth: c,
|
|
465
|
+
reverseConnectionNameFn: l
|
|
466
|
+
});
|
|
467
|
+
$ && (w = `
|
|
468
|
+
` + $), r.delete(d.target);
|
|
469
|
+
}
|
|
470
|
+
const x = m + w;
|
|
471
|
+
if (D(d.cardinality)) {
|
|
472
|
+
const $ = {
|
|
473
|
+
doctype: n.slug || n.name,
|
|
474
|
+
linkName: p,
|
|
475
|
+
backlink: d.backlink,
|
|
476
|
+
target: d.target
|
|
477
|
+
}, W = l ? l($) : B($), v = a.method === "sync" && a.limit !== void 0 ? `first: ${a.limit}` : a.method === "sync" ? `first: ${q}` : "";
|
|
478
|
+
y.push(`
|
|
479
|
+
${W}${v ? `(${v})` : ""} {
|
|
480
|
+
nodes {
|
|
481
|
+
${x}
|
|
482
|
+
}
|
|
483
|
+
}`);
|
|
484
|
+
} else
|
|
485
|
+
y.push(`
|
|
486
|
+
${p} {
|
|
487
|
+
${x}
|
|
488
|
+
}`);
|
|
489
|
+
}
|
|
490
|
+
return y.join("");
|
|
491
|
+
}
|
|
492
|
+
function ue(e, t, n, i, o, r, s) {
|
|
493
|
+
const c = t(e.tableName), l = n(e.tableName), y = i(e.tableName), p = /* @__PURE__ */ new Set([e.slug || e.name]);
|
|
494
|
+
let d = F(e);
|
|
495
|
+
if (r?.includeNested && e.links) {
|
|
496
|
+
const u = Array.isArray(r.includeNested) ? new Set(r.includeNested) : null, f = L({
|
|
497
|
+
links: e.links,
|
|
498
|
+
meta: e,
|
|
499
|
+
includeSet: u,
|
|
500
|
+
getMeta: o,
|
|
501
|
+
seen: p,
|
|
502
|
+
depth: 0,
|
|
503
|
+
maxDepth: r.maxDepth,
|
|
504
|
+
reverseConnectionNameFn: s
|
|
505
|
+
});
|
|
506
|
+
f && (d += `
|
|
507
|
+
` + f);
|
|
508
|
+
}
|
|
408
509
|
return `
|
|
409
|
-
query GetRecord($${
|
|
410
|
-
${
|
|
411
|
-
${
|
|
510
|
+
query GetRecord($${l}: ${y}) {
|
|
511
|
+
${c}(${l}: $${l}) {
|
|
512
|
+
${d}
|
|
412
513
|
}
|
|
413
514
|
}
|
|
414
515
|
`;
|
|
415
516
|
}
|
|
416
|
-
function
|
|
417
|
-
const
|
|
418
|
-
t.limit && (
|
|
419
|
-
const y =
|
|
517
|
+
function pe(e, t, n, i) {
|
|
518
|
+
const o = F(e), r = n(e.tableName), s = i(e.tableName), c = [], l = [];
|
|
519
|
+
t.limit && (c.push("$limit: Int"), l.push("first: $limit")), t.offset && (c.push("$offset: Int"), l.push("offset: $offset")), t.orderBy && (c.push(`$orderBy: [${s}!]`), l.push("orderBy: $orderBy"));
|
|
520
|
+
const y = c.length > 0 ? `(${c.join(", ")})` : "", p = l.length > 0 ? `(${l.join(", ")})` : "";
|
|
420
521
|
return `
|
|
421
522
|
query GetRecords${y} {
|
|
422
|
-
${
|
|
523
|
+
${r}${p} {
|
|
423
524
|
nodes {
|
|
424
|
-
${
|
|
525
|
+
${o}
|
|
425
526
|
}
|
|
426
527
|
}
|
|
427
528
|
}
|
|
428
529
|
`;
|
|
429
530
|
}
|
|
430
|
-
function
|
|
431
|
-
const i =
|
|
432
|
-
return
|
|
531
|
+
function ye(e) {
|
|
532
|
+
const { record: t, meta: n, getMeta: i } = e;
|
|
533
|
+
if (!n.links) return t;
|
|
534
|
+
const o = { ...t };
|
|
535
|
+
for (const [r, s] of Object.entries(n.links))
|
|
536
|
+
if (D(s.cardinality)) {
|
|
537
|
+
if (!i(s.target)) continue;
|
|
538
|
+
const y = {
|
|
539
|
+
doctype: n.slug || n.name,
|
|
540
|
+
backlink: s.backlink || r,
|
|
541
|
+
target: s.target
|
|
542
|
+
}, p = B(y), d = o[p];
|
|
543
|
+
d?.nodes ? (o[r] = d.nodes, delete o[p]) : (o[r] = [], delete o[p]);
|
|
544
|
+
}
|
|
545
|
+
return o;
|
|
546
|
+
}
|
|
547
|
+
function ge(e) {
|
|
548
|
+
const { result: t, meta: n, recordFieldName: i } = e, o = i(n.tableName);
|
|
549
|
+
return t[o];
|
|
433
550
|
}
|
|
434
|
-
function
|
|
435
|
-
const i =
|
|
436
|
-
return
|
|
551
|
+
function me(e) {
|
|
552
|
+
const { result: t, meta: n, connectionFieldName: i } = e, o = i(n.tableName);
|
|
553
|
+
return t[o]?.nodes ?? [];
|
|
437
554
|
}
|
|
555
|
+
const xe = J`
|
|
556
|
+
type StonecropFieldMeta {
|
|
557
|
+
fieldname: String!
|
|
558
|
+
fieldtype: String!
|
|
559
|
+
component: String
|
|
560
|
+
label: String
|
|
561
|
+
width: String
|
|
562
|
+
align: String
|
|
563
|
+
required: Boolean
|
|
564
|
+
readOnly: Boolean
|
|
565
|
+
edit: Boolean
|
|
566
|
+
hidden: Boolean
|
|
567
|
+
default: JSON
|
|
568
|
+
options: JSON
|
|
569
|
+
mask: String
|
|
570
|
+
precision: Int
|
|
571
|
+
scale: Int
|
|
572
|
+
mode: String
|
|
573
|
+
validation: JSON
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
type StonecropWorkflowAction {
|
|
577
|
+
label: String!
|
|
578
|
+
handler: String!
|
|
579
|
+
requiredFields: [String!]
|
|
580
|
+
allowedStates: [String!]
|
|
581
|
+
confirm: Boolean
|
|
582
|
+
args: JSON
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
type StonecropWorkflowMeta {
|
|
586
|
+
states: [String!]
|
|
587
|
+
actions: [StonecropWorkflowAction!]
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
type StonecropDoctypeMeta {
|
|
591
|
+
name: String!
|
|
592
|
+
slug: String
|
|
593
|
+
tableName: String
|
|
594
|
+
fields: [StonecropFieldMeta!]!
|
|
595
|
+
workflow: StonecropWorkflowMeta
|
|
596
|
+
inherits: String
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
type StonecropRecordResult {
|
|
600
|
+
data: JSON
|
|
601
|
+
doctype: String!
|
|
602
|
+
unknownLinks: [String!]
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
type StonecropRecordsResult {
|
|
606
|
+
data: [JSON!]!
|
|
607
|
+
doctype: String!
|
|
608
|
+
count: Int!
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
type StonecropActionResult {
|
|
612
|
+
success: Boolean!
|
|
613
|
+
data: JSON
|
|
614
|
+
error: String
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
extend type Query {
|
|
618
|
+
stonecropMeta(doctype: String!): StonecropDoctypeMeta
|
|
619
|
+
stonecropAllMeta: [StonecropDoctypeMeta!]!
|
|
620
|
+
stonecropRecord(doctype: String!, id: String!, options: JSON): StonecropRecordResult
|
|
621
|
+
stonecropRecords(doctype: String!, filters: JSON, orderBy: String, limit: Int, offset: Int): StonecropRecordsResult
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
extend type Mutation {
|
|
625
|
+
stonecropAction(doctype: String!, action: String!, args: JSON): StonecropActionResult!
|
|
626
|
+
}
|
|
627
|
+
`;
|
|
438
628
|
export {
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
629
|
+
O as DoctypeValidationError,
|
|
630
|
+
de as RELATION_FIELDTYPES,
|
|
631
|
+
pe as buildListQuery,
|
|
632
|
+
ue as buildRecordQuery,
|
|
633
|
+
re as builtinHandlers,
|
|
634
|
+
Be as clearHandlers,
|
|
635
|
+
Re as clearRegistry,
|
|
636
|
+
Fe as createStonecropPlugin,
|
|
637
|
+
ce as defaultConnectionFieldName,
|
|
638
|
+
se as defaultOrderByTypeName,
|
|
639
|
+
ae as defaultRecordArgName,
|
|
640
|
+
le as defaultRecordArgType,
|
|
641
|
+
ie as defaultRecordFieldName,
|
|
642
|
+
B as defaultReverseConnectionName,
|
|
643
|
+
me as extractListResult,
|
|
644
|
+
ge as extractSingleResult,
|
|
645
|
+
K as getAllMeta,
|
|
646
|
+
Z as getHandler,
|
|
647
|
+
N as getMeta,
|
|
648
|
+
Ae as hasHandler,
|
|
649
|
+
Me as hasMeta,
|
|
650
|
+
G as loadDoctypes,
|
|
651
|
+
be as loadDoctypesFromObject,
|
|
652
|
+
ye as mergeNestedResults,
|
|
653
|
+
F as queryableFieldNames,
|
|
654
|
+
De as registerBuiltinHandlers,
|
|
655
|
+
X as registerHandler,
|
|
656
|
+
xe as typeDefs,
|
|
657
|
+
Oe as validateReferences
|
|
461
658
|
};
|
|
462
659
|
//# sourceMappingURL=index.js.map
|