@stonecrop/graphql-middleware 0.8.8 → 0.8.10
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/graphql-middleware.d.ts +1222 -0
- package/dist/graphql_client.tsbuildinfo +1 -0
- package/dist/index.cjs +12 -12
- package/dist/index.cjs.map +1 -0
- package/dist/index.js +223 -222
- package/dist/index.js.map +1 -0
- package/dist/src/client/index.d.ts +1 -1
- package/dist/src/client/index.js +191 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +24 -0
- package/dist/src/plugin/postgraphile.d.ts +49 -1
- package/dist/src/plugin/postgraphile.d.ts.map +1 -1
- package/dist/src/plugin/postgraphile.js +330 -0
- package/dist/src/registry/actions.d.ts +1 -1
- package/dist/src/registry/actions.js +148 -0
- package/dist/src/registry/doctypes.d.ts +1 -1
- package/dist/src/registry/doctypes.js +167 -0
- package/dist/src/tsdoc-metadata.json +11 -0
- package/dist/src/types/index.d.ts +1 -1
- package/dist/src/types/index.js +2 -0
- package/dist/tests/query-builders.test.d.ts +2 -0
- package/dist/tests/query-builders.test.d.ts.map +1 -0
- package/dist/tests/query-builders.test.js +178 -0
- package/dist/tests/registry.test.js +4 -0
- package/package.json +7 -6
- package/dist/index.d.ts +0 -2
package/dist/index.js
CHANGED
|
@@ -1,135 +1,136 @@
|
|
|
1
|
-
import { validateDoctype as
|
|
2
|
-
import { ActionDefinition as
|
|
3
|
-
import { readdirSync as
|
|
1
|
+
import { validateDoctype as N, parseDoctype as D, toPascalCase as R, snakeToCamel as k } from "@stonecrop/schema";
|
|
2
|
+
import { ActionDefinition as he, DoctypeMeta as Se, FieldMeta as $e, FieldOptions as we, FieldValidation as be, GQL_SCALAR_MAP as Ne, StonecropFieldType as De, TYPE_MAP as Re, WELL_KNOWN_SCALARS as Me, WorkflowMeta as ke, camelToLabel as Ae, camelToSnake as qe, classifyFieldType as Oe, convertGraphQLSchema as Fe, defaultIsEntityField as Ee, defaultIsEntityType as Be, getDefaultComponent as Te, parseDoctype as Ce, parseField as je, pascalToSnake as xe, snakeToCamel as Ie, snakeToLabel as Le, toPascalCase as Je, toSlug as _e, validateDoctype as Ge, validateField as Pe } from "@stonecrop/schema";
|
|
3
|
+
import { readdirSync as A, statSync as q, readFileSync as O } from "node:fs";
|
|
4
4
|
import { join as F } from "node:path";
|
|
5
|
-
import { extendSchema as
|
|
6
|
-
import { loadOne as
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
import { extendSchema as E, gql as B } from "postgraphile/utils";
|
|
6
|
+
import { loadOne as S, object as $, constant as T, lambda as C } from "postgraphile/grafast";
|
|
7
|
+
import j from "pluralize";
|
|
8
|
+
const p = /* @__PURE__ */ new Map();
|
|
9
|
+
class w extends Error {
|
|
10
|
+
constructor(e, r) {
|
|
11
|
+
const n = r.map((o) => ` ${o.path.join(".")}: ${o.message}`).join(`
|
|
11
12
|
`);
|
|
12
13
|
super(`Invalid doctype definition in ${e}:
|
|
13
|
-
${n}`), this.file = e, this.errors =
|
|
14
|
+
${n}`), this.file = e, this.errors = r, this.name = "DoctypeValidationError";
|
|
14
15
|
}
|
|
15
16
|
}
|
|
16
|
-
function
|
|
17
|
-
const
|
|
18
|
-
for (const n of
|
|
19
|
-
const
|
|
20
|
-
|
|
17
|
+
function x(t, e = {}) {
|
|
18
|
+
const r = A(t);
|
|
19
|
+
for (const n of r) {
|
|
20
|
+
const o = F(t, n);
|
|
21
|
+
q(o).isDirectory() ? x(o, e) : n.endsWith(".json") && I(o, e);
|
|
21
22
|
}
|
|
22
23
|
}
|
|
23
24
|
function I(t, e) {
|
|
24
|
-
const
|
|
25
|
+
const r = O(t, "utf-8");
|
|
25
26
|
let n;
|
|
26
27
|
try {
|
|
27
|
-
n = JSON.parse(
|
|
28
|
-
} catch (
|
|
29
|
-
const
|
|
28
|
+
n = JSON.parse(r);
|
|
29
|
+
} catch (s) {
|
|
30
|
+
const c = {
|
|
30
31
|
path: [],
|
|
31
|
-
message: `Invalid JSON: ${
|
|
32
|
+
message: `Invalid JSON: ${s instanceof Error ? s.message : String(s)}`
|
|
32
33
|
};
|
|
33
34
|
if (e.continueOnError) {
|
|
34
|
-
e.onError?.(t, [
|
|
35
|
+
e.onError?.(t, [c]);
|
|
35
36
|
return;
|
|
36
37
|
}
|
|
37
|
-
throw new
|
|
38
|
+
throw new w(t, [c]);
|
|
38
39
|
}
|
|
39
|
-
const
|
|
40
|
-
if (!
|
|
40
|
+
const o = N(n);
|
|
41
|
+
if (!o.success) {
|
|
41
42
|
if (e.continueOnError) {
|
|
42
|
-
e.onError?.(t,
|
|
43
|
+
e.onError?.(t, o.errors);
|
|
43
44
|
return;
|
|
44
45
|
}
|
|
45
|
-
throw new
|
|
46
|
+
throw new w(t, o.errors);
|
|
46
47
|
}
|
|
47
|
-
const a =
|
|
48
|
-
|
|
48
|
+
const a = D(n);
|
|
49
|
+
p.set(a.name, a);
|
|
49
50
|
}
|
|
50
|
-
function
|
|
51
|
-
for (const [
|
|
52
|
-
const
|
|
51
|
+
function se(t, e = {}) {
|
|
52
|
+
for (const [r, n] of Object.entries(t)) {
|
|
53
|
+
const o = { ...n, name: r }, a = N(o);
|
|
53
54
|
if (!a.success) {
|
|
54
55
|
if (e.continueOnError) {
|
|
55
|
-
e.onError?.(
|
|
56
|
+
e.onError?.(r, a.errors);
|
|
56
57
|
continue;
|
|
57
58
|
}
|
|
58
|
-
throw new
|
|
59
|
+
throw new w(r, a.errors);
|
|
59
60
|
}
|
|
60
|
-
const
|
|
61
|
-
|
|
61
|
+
const s = D(o);
|
|
62
|
+
p.set(s.name, s);
|
|
62
63
|
}
|
|
63
64
|
}
|
|
64
|
-
function
|
|
65
|
-
return
|
|
65
|
+
function m(t) {
|
|
66
|
+
return p.get(t);
|
|
66
67
|
}
|
|
67
|
-
function
|
|
68
|
-
return Array.from(
|
|
68
|
+
function L() {
|
|
69
|
+
return Array.from(p.values());
|
|
69
70
|
}
|
|
70
|
-
function
|
|
71
|
-
return
|
|
71
|
+
function ce(t) {
|
|
72
|
+
return p.has(t);
|
|
72
73
|
}
|
|
73
|
-
function
|
|
74
|
-
|
|
74
|
+
function ie() {
|
|
75
|
+
p.clear();
|
|
75
76
|
}
|
|
76
|
-
function
|
|
77
|
+
function de() {
|
|
77
78
|
const t = [];
|
|
78
|
-
for (const e of
|
|
79
|
-
e.inherits && !
|
|
79
|
+
for (const e of p.values()) {
|
|
80
|
+
e.inherits && !p.has(e.inherits) && t.push({
|
|
80
81
|
path: [e.name, "inherits"],
|
|
81
82
|
message: `References unknown doctype: ${e.inherits}`
|
|
82
|
-
}), e.listDoctype && !
|
|
83
|
+
}), e.listDoctype && !p.has(e.listDoctype) && t.push({
|
|
83
84
|
path: [e.name, "listDoctype"],
|
|
84
85
|
message: `References unknown doctype: ${e.listDoctype}`
|
|
85
|
-
}), e.parentDoctype && !
|
|
86
|
+
}), e.parentDoctype && !p.has(e.parentDoctype) && t.push({
|
|
86
87
|
path: [e.name, "parentDoctype"],
|
|
87
88
|
message: `References unknown doctype: ${e.parentDoctype}`
|
|
88
89
|
});
|
|
89
|
-
for (const
|
|
90
|
-
|
|
91
|
-
path: [e.name, "fields",
|
|
92
|
-
message: `Link references unknown doctype: ${
|
|
90
|
+
for (const r of e.fields)
|
|
91
|
+
r.fieldtype === "Link" && typeof r.options == "string" && (p.has(r.options) || t.push({
|
|
92
|
+
path: [e.name, "fields", r.fieldname, "options"],
|
|
93
|
+
message: `Link references unknown doctype: ${r.options}`
|
|
93
94
|
}));
|
|
94
95
|
}
|
|
95
96
|
return t;
|
|
96
97
|
}
|
|
97
|
-
const
|
|
98
|
-
function
|
|
99
|
-
|
|
98
|
+
const g = /* @__PURE__ */ new Map();
|
|
99
|
+
function J(t, e) {
|
|
100
|
+
g.set(t, e);
|
|
100
101
|
}
|
|
101
102
|
function _(t) {
|
|
102
|
-
return
|
|
103
|
+
return g.get(t);
|
|
103
104
|
}
|
|
104
|
-
function
|
|
105
|
-
return
|
|
105
|
+
function le(t) {
|
|
106
|
+
return g.has(t);
|
|
106
107
|
}
|
|
107
|
-
function
|
|
108
|
-
|
|
108
|
+
function pe() {
|
|
109
|
+
g.clear();
|
|
109
110
|
}
|
|
110
111
|
const G = async (t, e) => {
|
|
111
|
-
const [
|
|
112
|
+
const [r] = t, { doctype: n } = e, o = [];
|
|
112
113
|
for (const a of n.fields)
|
|
113
|
-
a.required && (
|
|
114
|
-
if (
|
|
115
|
-
throw new Error(`Missing required fields: ${
|
|
114
|
+
a.required && (r[a.fieldname] === void 0 || r[a.fieldname] === null) && o.push(a.label ?? a.fieldname);
|
|
115
|
+
if (o.length > 0)
|
|
116
|
+
throw new Error(`Missing required fields: ${o.join(", ")}`);
|
|
116
117
|
return { valid: !0 };
|
|
117
|
-
},
|
|
118
|
-
const [
|
|
118
|
+
}, P = async (t, e) => {
|
|
119
|
+
const [r] = t, { doctype: n } = e, o = [];
|
|
119
120
|
for (const a of n.fields) {
|
|
120
|
-
const
|
|
121
|
-
if (
|
|
122
|
-
const
|
|
123
|
-
|
|
121
|
+
const s = r[a.fieldname];
|
|
122
|
+
if (s == null) continue;
|
|
123
|
+
const c = H(a.fieldname, s, a.fieldtype);
|
|
124
|
+
c && o.push(c);
|
|
124
125
|
}
|
|
125
|
-
if (
|
|
126
|
+
if (o.length > 0)
|
|
126
127
|
throw new Error(`Field type validation failed:
|
|
127
|
-
${
|
|
128
|
+
${o.join(`
|
|
128
129
|
`)}`);
|
|
129
130
|
return { valid: !0 };
|
|
130
131
|
};
|
|
131
|
-
function H(t, e,
|
|
132
|
-
switch (
|
|
132
|
+
function H(t, e, r) {
|
|
133
|
+
switch (r) {
|
|
133
134
|
case "Int":
|
|
134
135
|
if (typeof e != "number" || !Number.isInteger(e))
|
|
135
136
|
return `${t}: expected integer, got ${typeof e}`;
|
|
@@ -169,19 +170,19 @@ function H(t, e, o) {
|
|
|
169
170
|
}
|
|
170
171
|
return null;
|
|
171
172
|
}
|
|
172
|
-
const
|
|
173
|
+
const Q = async () => ({ ok: !0 }), U = {
|
|
173
174
|
validateRequiredFields: G,
|
|
174
|
-
validateFieldTypes:
|
|
175
|
-
noop:
|
|
175
|
+
validateFieldTypes: P,
|
|
176
|
+
noop: Q
|
|
176
177
|
};
|
|
177
|
-
function
|
|
178
|
-
for (const [t, e] of Object.entries(
|
|
179
|
-
|
|
178
|
+
function ye() {
|
|
179
|
+
for (const [t, e] of Object.entries(U))
|
|
180
|
+
J(t, e);
|
|
180
181
|
}
|
|
181
|
-
const
|
|
182
|
-
const e = t.inflection?.recordFieldName ?? W,
|
|
183
|
-
return
|
|
184
|
-
typeDefs:
|
|
182
|
+
const ue = (t) => {
|
|
183
|
+
const e = t.inflection?.recordFieldName ?? W, r = t.inflection?.connectionFieldName ?? v, n = t.inflection?.orderByTypeName ?? V;
|
|
184
|
+
return E(() => ({
|
|
185
|
+
typeDefs: B`
|
|
185
186
|
type StonecropFieldMeta {
|
|
186
187
|
fieldname: String!
|
|
187
188
|
fieldtype: String!
|
|
@@ -250,65 +251,62 @@ const pe = (t) => {
|
|
|
250
251
|
objects: {
|
|
251
252
|
Query: {
|
|
252
253
|
plans: {
|
|
253
|
-
stonecropMeta(
|
|
254
|
-
|
|
255
|
-
return x(c, (s) => h(s) ?? null);
|
|
254
|
+
stonecropMeta(o, { $doctype: a }) {
|
|
255
|
+
return C(a, (s) => m(s) ?? null);
|
|
256
256
|
},
|
|
257
257
|
stonecropAllMeta() {
|
|
258
|
-
return
|
|
258
|
+
return T(L());
|
|
259
259
|
},
|
|
260
|
-
stonecropRecord(
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
if (!u)
|
|
260
|
+
stonecropRecord(o, { $doctype: a, $id: s }) {
|
|
261
|
+
return S($({ doctype: a, id: s }), async (c) => await Promise.all(
|
|
262
|
+
c.map(async (d) => {
|
|
263
|
+
const l = m(d.doctype);
|
|
264
|
+
if (!l)
|
|
266
265
|
throw new Error(`Unknown doctype: ${d.doctype}`);
|
|
267
|
-
if (!
|
|
266
|
+
if (!l.tableName)
|
|
268
267
|
throw new Error(`Doctype ${d.doctype} has no table mapping`);
|
|
269
|
-
const
|
|
268
|
+
const y = z(l, e), i = await t.executor.query(y, { id: d.id });
|
|
270
269
|
return {
|
|
271
|
-
data:
|
|
270
|
+
data: X(i, l, e),
|
|
272
271
|
doctype: d.doctype
|
|
273
272
|
};
|
|
274
273
|
})
|
|
275
274
|
));
|
|
276
275
|
},
|
|
277
|
-
stonecropRecords(
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
offset: p
|
|
276
|
+
stonecropRecords(o, { $doctype: a, $filters: s, $orderBy: c, $limit: d, $offset: l }) {
|
|
277
|
+
return S(
|
|
278
|
+
$({
|
|
279
|
+
doctype: a,
|
|
280
|
+
filters: s,
|
|
281
|
+
orderBy: c,
|
|
282
|
+
limit: d,
|
|
283
|
+
offset: l
|
|
286
284
|
}),
|
|
287
|
-
async (
|
|
288
|
-
|
|
289
|
-
const
|
|
290
|
-
if (!
|
|
285
|
+
async (y) => await Promise.all(
|
|
286
|
+
y.map(async (i) => {
|
|
287
|
+
const u = m(i.doctype);
|
|
288
|
+
if (!u)
|
|
291
289
|
throw new Error(`Unknown doctype: ${i.doctype}`);
|
|
292
|
-
if (!
|
|
290
|
+
if (!u.tableName)
|
|
293
291
|
throw new Error(`Doctype ${i.doctype} has no table mapping`);
|
|
294
|
-
const
|
|
295
|
-
|
|
292
|
+
const h = K(
|
|
293
|
+
u,
|
|
296
294
|
{
|
|
297
295
|
limit: i.limit,
|
|
298
296
|
offset: i.offset,
|
|
299
297
|
orderBy: i.orderBy
|
|
300
298
|
},
|
|
301
|
-
|
|
299
|
+
r,
|
|
302
300
|
n
|
|
303
|
-
),
|
|
301
|
+
), f = await t.executor.query(h, {
|
|
304
302
|
limit: i.limit,
|
|
305
303
|
offset: i.offset,
|
|
306
304
|
orderBy: i.orderBy
|
|
307
|
-
}),
|
|
305
|
+
}), b = Z(f, u, r);
|
|
308
306
|
return {
|
|
309
|
-
data:
|
|
307
|
+
data: b,
|
|
310
308
|
doctype: i.doctype,
|
|
311
|
-
count:
|
|
309
|
+
count: b.length
|
|
312
310
|
};
|
|
313
311
|
})
|
|
314
312
|
)
|
|
@@ -318,52 +316,51 @@ const pe = (t) => {
|
|
|
318
316
|
},
|
|
319
317
|
Mutation: {
|
|
320
318
|
plans: {
|
|
321
|
-
stonecropAction(
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
actionArgs: d
|
|
319
|
+
stonecropAction(o, { $doctype: a, $action: s, $args: c }) {
|
|
320
|
+
return S(
|
|
321
|
+
$({
|
|
322
|
+
doctype: a,
|
|
323
|
+
action: s,
|
|
324
|
+
actionArgs: c
|
|
328
325
|
}),
|
|
329
|
-
async (
|
|
330
|
-
|
|
331
|
-
const
|
|
332
|
-
if (!
|
|
326
|
+
async (d) => await Promise.all(
|
|
327
|
+
d.map(async (l) => {
|
|
328
|
+
const y = m(l.doctype);
|
|
329
|
+
if (!y)
|
|
333
330
|
return {
|
|
334
331
|
success: !1,
|
|
335
332
|
data: null,
|
|
336
|
-
error: `Unknown doctype: ${
|
|
333
|
+
error: `Unknown doctype: ${l.doctype}`
|
|
337
334
|
};
|
|
338
|
-
const i =
|
|
335
|
+
const i = y.workflow?.actions?.[l.action];
|
|
339
336
|
if (!i)
|
|
340
337
|
return {
|
|
341
338
|
success: !1,
|
|
342
339
|
data: null,
|
|
343
|
-
error: `Unknown action: ${
|
|
340
|
+
error: `Unknown action: ${l.action} on ${l.doctype}`
|
|
344
341
|
};
|
|
345
|
-
const
|
|
346
|
-
if (!
|
|
342
|
+
const u = _(i.handler);
|
|
343
|
+
if (!u)
|
|
347
344
|
return {
|
|
348
345
|
success: !1,
|
|
349
346
|
data: null,
|
|
350
347
|
error: `Handler not registered: ${i.handler}`
|
|
351
348
|
};
|
|
352
|
-
const
|
|
353
|
-
doctype:
|
|
349
|
+
const h = {
|
|
350
|
+
doctype: y,
|
|
354
351
|
executor: t.executor
|
|
355
352
|
};
|
|
356
353
|
try {
|
|
357
354
|
return {
|
|
358
355
|
success: !0,
|
|
359
|
-
data: await
|
|
356
|
+
data: await u(l.actionArgs ?? [], h),
|
|
360
357
|
error: null
|
|
361
358
|
};
|
|
362
|
-
} catch (
|
|
359
|
+
} catch (f) {
|
|
363
360
|
return {
|
|
364
361
|
success: !1,
|
|
365
362
|
data: null,
|
|
366
|
-
error:
|
|
363
|
+
error: f instanceof Error ? f.message : String(f)
|
|
367
364
|
};
|
|
368
365
|
}
|
|
369
366
|
})
|
|
@@ -375,58 +372,54 @@ const pe = (t) => {
|
|
|
375
372
|
}
|
|
376
373
|
}));
|
|
377
374
|
};
|
|
378
|
-
function k(t) {
|
|
379
|
-
return t.replace(/_([a-z])/g, (e, o) => o.toUpperCase());
|
|
380
|
-
}
|
|
381
|
-
function A(t) {
|
|
382
|
-
const e = k(t);
|
|
383
|
-
return e.charAt(0).toUpperCase() + e.slice(1);
|
|
384
|
-
}
|
|
385
375
|
function W(t) {
|
|
386
|
-
const e =
|
|
376
|
+
const e = j.singular(t);
|
|
387
377
|
return `${k(e)}ById`;
|
|
388
378
|
}
|
|
379
|
+
function v(t) {
|
|
380
|
+
return `all${R(t)}`;
|
|
381
|
+
}
|
|
389
382
|
function V(t) {
|
|
390
|
-
return
|
|
383
|
+
return `${R(t)}OrderBy`;
|
|
391
384
|
}
|
|
392
|
-
|
|
393
|
-
|
|
385
|
+
const Y = /* @__PURE__ */ new Set(["Link", "Doctype"]);
|
|
386
|
+
function M(t) {
|
|
387
|
+
return t.fields.filter((e) => !Y.has(e.fieldtype)).map((e) => e.fieldname).join(`
|
|
388
|
+
`);
|
|
394
389
|
}
|
|
395
390
|
function z(t, e) {
|
|
396
|
-
const
|
|
397
|
-
`);
|
|
391
|
+
const r = M(t);
|
|
398
392
|
return `
|
|
399
393
|
query GetRecord($id: UUID!) {
|
|
400
394
|
${e(t.tableName)}(id: $id) {
|
|
401
|
-
${
|
|
395
|
+
${r}
|
|
402
396
|
}
|
|
403
397
|
}
|
|
404
398
|
`;
|
|
405
399
|
}
|
|
406
|
-
function K(t, e,
|
|
407
|
-
const r = t.
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
const y = s.length > 0 ? `(${s.join(", ")})` : "";
|
|
400
|
+
function K(t, e, r, n) {
|
|
401
|
+
const o = M(t), a = r(t.tableName), s = n(t.tableName), c = [], d = [];
|
|
402
|
+
e.limit && (c.push("$limit: Int"), d.push("first: $limit")), e.offset && (c.push("$offset: Int"), d.push("offset: $offset")), e.orderBy && (c.push(`$orderBy: [${s}!]`), d.push("orderBy: $orderBy"));
|
|
403
|
+
const l = c.length > 0 ? `(${c.join(", ")})` : "", y = d.length > 0 ? `(${d.join(", ")})` : "";
|
|
411
404
|
return `
|
|
412
|
-
query GetRecords
|
|
405
|
+
query GetRecords${l} {
|
|
413
406
|
${a}${y} {
|
|
414
407
|
nodes {
|
|
415
|
-
${
|
|
408
|
+
${o}
|
|
416
409
|
}
|
|
417
410
|
}
|
|
418
411
|
}
|
|
419
412
|
`;
|
|
420
413
|
}
|
|
421
|
-
function
|
|
422
|
-
const n =
|
|
414
|
+
function X(t, e, r) {
|
|
415
|
+
const n = r(e.tableName);
|
|
423
416
|
return t[n];
|
|
424
417
|
}
|
|
425
|
-
function
|
|
426
|
-
const n =
|
|
418
|
+
function Z(t, e, r) {
|
|
419
|
+
const n = r(e.tableName);
|
|
427
420
|
return t[n]?.nodes ?? [];
|
|
428
421
|
}
|
|
429
|
-
class
|
|
422
|
+
class fe {
|
|
430
423
|
endpoint;
|
|
431
424
|
headers;
|
|
432
425
|
metaCache = /* @__PURE__ */ new Map();
|
|
@@ -441,31 +434,31 @@ class ye {
|
|
|
441
434
|
* @param query - GraphQL query string
|
|
442
435
|
* @param variables - Query variables
|
|
443
436
|
*/
|
|
444
|
-
async query(e,
|
|
445
|
-
const
|
|
437
|
+
async query(e, r) {
|
|
438
|
+
const o = await (await fetch(this.endpoint, {
|
|
446
439
|
method: "POST",
|
|
447
440
|
headers: this.headers,
|
|
448
|
-
body: JSON.stringify({ query: e, variables:
|
|
441
|
+
body: JSON.stringify({ query: e, variables: r })
|
|
449
442
|
})).json();
|
|
450
|
-
if (
|
|
451
|
-
throw new Error(
|
|
452
|
-
return
|
|
443
|
+
if (o.errors?.length)
|
|
444
|
+
throw new Error(o.errors[0].message);
|
|
445
|
+
return o.data;
|
|
453
446
|
}
|
|
454
447
|
/**
|
|
455
448
|
* Execute a GraphQL mutation
|
|
456
449
|
* @param mutation - GraphQL mutation string
|
|
457
450
|
* @param variables - Mutation variables
|
|
458
451
|
*/
|
|
459
|
-
async mutate(e,
|
|
460
|
-
return this.query(e,
|
|
452
|
+
async mutate(e, r) {
|
|
453
|
+
return this.query(e, r);
|
|
461
454
|
}
|
|
462
455
|
/**
|
|
463
456
|
* Get doctype metadata
|
|
464
457
|
* @param context - Route context containing doctype name
|
|
465
458
|
*/
|
|
466
459
|
async getMeta(e) {
|
|
467
|
-
const
|
|
468
|
-
if (
|
|
460
|
+
const r = this.metaCache.get(e.doctype);
|
|
461
|
+
if (r) return r;
|
|
469
462
|
const n = await this.query(
|
|
470
463
|
`
|
|
471
464
|
query GetMeta($doctype: String!) {
|
|
@@ -531,8 +524,8 @@ class ye {
|
|
|
531
524
|
}
|
|
532
525
|
`
|
|
533
526
|
);
|
|
534
|
-
for (const
|
|
535
|
-
this.metaCache.set(
|
|
527
|
+
for (const r of e.stonecropAllMeta)
|
|
528
|
+
this.metaCache.set(r.name, r);
|
|
536
529
|
return e.stonecropAllMeta;
|
|
537
530
|
}
|
|
538
531
|
/**
|
|
@@ -540,7 +533,7 @@ class ye {
|
|
|
540
533
|
* @param doctype - Doctype metadata
|
|
541
534
|
* @param recordId - Record ID to fetch
|
|
542
535
|
*/
|
|
543
|
-
async getRecord(e,
|
|
536
|
+
async getRecord(e, r) {
|
|
544
537
|
return (await this.query(
|
|
545
538
|
`
|
|
546
539
|
query GetRecord($doctype: String!, $id: String!) {
|
|
@@ -549,7 +542,7 @@ class ye {
|
|
|
549
542
|
}
|
|
550
543
|
}
|
|
551
544
|
`,
|
|
552
|
-
{ doctype: e.name, id:
|
|
545
|
+
{ doctype: e.name, id: r }
|
|
553
546
|
)).stonecropRecord.data;
|
|
554
547
|
}
|
|
555
548
|
/**
|
|
@@ -557,7 +550,7 @@ class ye {
|
|
|
557
550
|
* @param doctype - Doctype metadata
|
|
558
551
|
* @param options - Query options (filters, orderBy, limit, offset)
|
|
559
552
|
*/
|
|
560
|
-
async getRecords(e,
|
|
553
|
+
async getRecords(e, r) {
|
|
561
554
|
return (await this.query(
|
|
562
555
|
`
|
|
563
556
|
query GetRecords(
|
|
@@ -581,7 +574,7 @@ class ye {
|
|
|
581
574
|
`,
|
|
582
575
|
{
|
|
583
576
|
doctype: e.name,
|
|
584
|
-
...
|
|
577
|
+
...r
|
|
585
578
|
}
|
|
586
579
|
)).stonecropRecords.data;
|
|
587
580
|
}
|
|
@@ -591,7 +584,7 @@ class ye {
|
|
|
591
584
|
* @param action - Action name to execute
|
|
592
585
|
* @param args - Action arguments
|
|
593
586
|
*/
|
|
594
|
-
async runAction(e,
|
|
587
|
+
async runAction(e, r, n) {
|
|
595
588
|
return (await this.query(
|
|
596
589
|
`
|
|
597
590
|
mutation RunAction($doctype: String!, $action: String!, $args: JSON) {
|
|
@@ -604,7 +597,7 @@ class ye {
|
|
|
604
597
|
`,
|
|
605
598
|
{
|
|
606
599
|
doctype: e.name,
|
|
607
|
-
action:
|
|
600
|
+
action: r,
|
|
608
601
|
args: n
|
|
609
602
|
}
|
|
610
603
|
)).stonecropAction;
|
|
@@ -617,46 +610,54 @@ class ye {
|
|
|
617
610
|
}
|
|
618
611
|
}
|
|
619
612
|
export {
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
Re as
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
pe as
|
|
640
|
-
|
|
613
|
+
he as ActionDefinition,
|
|
614
|
+
Se as DoctypeMeta,
|
|
615
|
+
w as DoctypeValidationError,
|
|
616
|
+
$e as FieldMeta,
|
|
617
|
+
we as FieldOptions,
|
|
618
|
+
be as FieldValidation,
|
|
619
|
+
Ne as GQL_SCALAR_MAP,
|
|
620
|
+
Y as RELATION_FIELDTYPES,
|
|
621
|
+
fe as StonecropClient,
|
|
622
|
+
De as StonecropFieldType,
|
|
623
|
+
Re as TYPE_MAP,
|
|
624
|
+
Me as WELL_KNOWN_SCALARS,
|
|
625
|
+
ke as WorkflowMeta,
|
|
626
|
+
K as buildListQuery,
|
|
627
|
+
z as buildRecordQuery,
|
|
628
|
+
U as builtinHandlers,
|
|
629
|
+
Ae as camelToLabel,
|
|
630
|
+
qe as camelToSnake,
|
|
631
|
+
Oe as classifyFieldType,
|
|
632
|
+
pe as clearHandlers,
|
|
633
|
+
ie as clearRegistry,
|
|
634
|
+
Fe as convertGraphQLSchema,
|
|
635
|
+
ue as createStonecropPlugin,
|
|
636
|
+
v as defaultConnectionFieldName,
|
|
637
|
+
Ee as defaultIsEntityField,
|
|
641
638
|
Be as defaultIsEntityType,
|
|
642
|
-
|
|
643
|
-
|
|
639
|
+
V as defaultOrderByTypeName,
|
|
640
|
+
W as defaultRecordFieldName,
|
|
641
|
+
L as getAllMeta,
|
|
642
|
+
Te as getDefaultComponent,
|
|
644
643
|
_ as getHandler,
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
644
|
+
m as getMeta,
|
|
645
|
+
le as hasHandler,
|
|
646
|
+
ce as hasMeta,
|
|
647
|
+
x as loadDoctypes,
|
|
648
|
+
se as loadDoctypesFromObject,
|
|
650
649
|
Ce as parseDoctype,
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
Je as
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
650
|
+
je as parseField,
|
|
651
|
+
xe as pascalToSnake,
|
|
652
|
+
M as queryableFieldNames,
|
|
653
|
+
ye as registerBuiltinHandlers,
|
|
654
|
+
J as registerHandler,
|
|
655
|
+
Ie as snakeToCamel,
|
|
656
|
+
Le as snakeToLabel,
|
|
657
|
+
Je as toPascalCase,
|
|
658
|
+
_e as toSlug,
|
|
659
|
+
Ge as validateDoctype,
|
|
660
|
+
Pe as validateField,
|
|
661
|
+
de as validateReferences
|
|
662
662
|
};
|
|
663
|
+
//# sourceMappingURL=index.js.map
|