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