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