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