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