@loradb/lora-graphql 0.16.2
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/LICENSE +87 -0
- package/README.md +994 -0
- package/dist/analyze/cypher-check.d.ts +8 -0
- package/dist/analyze/diff.d.ts +32 -0
- package/dist/analyze/indexes.d.ts +61 -0
- package/dist/analyze/lint.d.ts +6 -0
- package/dist/analyze/plans.d.ts +31 -0
- package/dist/analyze/statistics.d.ts +19 -0
- package/dist/cli.d.ts +6 -0
- package/dist/cli.js +631 -0
- package/dist/cli.js.map +1 -0
- package/dist/codegen.d.ts +32 -0
- package/dist/compile/aggregate.d.ts +17 -0
- package/dist/compile/auth.d.ts +46 -0
- package/dist/compile/context.d.ts +43 -0
- package/dist/compile/cursor.d.ts +4 -0
- package/dist/compile/cypher.d.ts +175 -0
- package/dist/compile/filter.d.ts +19 -0
- package/dist/compile/hmac.d.ts +4 -0
- package/dist/compile/read.d.ts +89 -0
- package/dist/compile/selection.d.ts +18 -0
- package/dist/diff-BVP1Jzh3.js +99 -0
- package/dist/diff-BVP1Jzh3.js.map +1 -0
- package/dist/driver-C8vA5fV-.js +9127 -0
- package/dist/driver-C8vA5fV-.js.map +1 -0
- package/dist/driver.d.ts +117 -0
- package/dist/errors.d.ts +20 -0
- package/dist/execute/changes.d.ts +61 -0
- package/dist/execute/cypher-mutation.d.ts +4 -0
- package/dist/execute/feed.d.ts +10 -0
- package/dist/execute/mutate.d.ts +57 -0
- package/dist/execute/transaction.d.ts +17 -0
- package/dist/guards.d.ts +42 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/dist/lora-graphql.d.ts +291 -0
- package/dist/migrate.d.ts +8 -0
- package/dist/model/build.d.ts +25 -0
- package/dist/model/cypher-lexer.d.ts +10 -0
- package/dist/model/directives.d.ts +3 -0
- package/dist/model/points.d.ts +12 -0
- package/dist/model/relations.d.ts +7 -0
- package/dist/model/types.d.ts +311 -0
- package/dist/observe.d.ts +72 -0
- package/dist/schema/build.d.ts +38 -0
- package/dist/schema/global-id.d.ts +6 -0
- package/dist/schema/guard.d.ts +5 -0
- package/dist/schema/mutations.d.ts +44 -0
- package/dist/schema/names.d.ts +37 -0
- package/dist/schema/scalars.d.ts +9 -0
- package/dist/testing.d.ts +36 -0
- package/dist/testing.js +56 -0
- package/dist/testing.js.map +1 -0
- package/package.json +85 -0
package/dist/cli.js
ADDED
|
@@ -0,0 +1,631 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { stat as B, readdir as ne, readFile as se, mkdir as ae, writeFile as _ } from "node:fs/promises";
|
|
3
|
+
import { join as D, relative as oe } from "node:path";
|
|
4
|
+
import { parse as A, Kind as p, visit as G, print as z, typeFromAST as ie, isNonNullType as U, isListType as re, getNamedType as ue, isEnumType as ce, isInputObjectType as le } from "graphql";
|
|
5
|
+
import { d as fe } from "./diff-BVP1Jzh3.js";
|
|
6
|
+
import { m as H, d as de, M as pe, L as M, l as Q, f as F, o as V, b as me, i as he, r as ge, u as ve } from "./driver-C8vA5fV-.js";
|
|
7
|
+
const we = /* @__PURE__ */ new Set(["Query", "Mutation", "Subscription"]), x = {
|
|
8
|
+
coalesce: "@coalesce is not supported: it hides predicates from indexes; store a value instead",
|
|
9
|
+
subscriptionsAuthorization: "@subscriptionsAuthorization is not supported: SUBSCRIBE rules go in @authorization",
|
|
10
|
+
shareable: "federation (@shareable) is not supported",
|
|
11
|
+
external: "federation (@external) is not supported",
|
|
12
|
+
requires: "federation (@requires) is not supported",
|
|
13
|
+
provides: "federation (@provides) is not supported",
|
|
14
|
+
exclude: "@exclude: use @query / @mutation to choose operations",
|
|
15
|
+
vector: "@vector on types (with a provider) is not supported: put @vector(dimensions:, similarity:) on a [Float!] field"
|
|
16
|
+
}, Te = [
|
|
17
|
+
["_NOT_IN", "IN"],
|
|
18
|
+
["_STARTS_WITH", "STARTS_WITH"],
|
|
19
|
+
["_ENDS_WITH", "ENDS_WITH"],
|
|
20
|
+
["_CONTAINS", "CONTAINS"],
|
|
21
|
+
["_INCLUDES", "INCLUDES"],
|
|
22
|
+
["_GTE", "GTE"],
|
|
23
|
+
["_LTE", "LTE"],
|
|
24
|
+
["_GT", "GT"],
|
|
25
|
+
["_LT", "LT"],
|
|
26
|
+
["_IN", "IN"],
|
|
27
|
+
["_EQ", "EQ"]
|
|
28
|
+
], Ee = {
|
|
29
|
+
eq: "EQ",
|
|
30
|
+
in: "IN",
|
|
31
|
+
lt: "LT",
|
|
32
|
+
lte: "LTE",
|
|
33
|
+
gt: "GT",
|
|
34
|
+
gte: "GTE",
|
|
35
|
+
contains: "CONTAINS",
|
|
36
|
+
startsWith: "STARTS_WITH",
|
|
37
|
+
endsWith: "ENDS_WITH",
|
|
38
|
+
includes: "INCLUDES",
|
|
39
|
+
caseInsensitive: "CASE_INSENSITIVE"
|
|
40
|
+
};
|
|
41
|
+
function be(t, n = []) {
|
|
42
|
+
const o = A(t, { noLocation: !0 }), s = [], e = o.definitions.filter(
|
|
43
|
+
(i) => i.kind === p.OBJECT_TYPE_DEFINITION && !we.has(i.name.value) && !y(i.directives, "relationshipProperties") && !y(i.directives, "jwt")
|
|
44
|
+
), c = new Set(e.map((i) => i.name.value)), a = n.length > 0 ? ye(n, e) : void 0, u = G(o, {
|
|
45
|
+
ObjectTypeDefinition(i) {
|
|
46
|
+
if (!c.has(i.name.value)) return;
|
|
47
|
+
const r = i.name.value;
|
|
48
|
+
let l = Y(
|
|
49
|
+
i.directives ?? [],
|
|
50
|
+
r,
|
|
51
|
+
void 0,
|
|
52
|
+
s
|
|
53
|
+
);
|
|
54
|
+
y(l, "node") || (l = [...l, I("node")]);
|
|
55
|
+
const f = a?.mutations.get(r);
|
|
56
|
+
y(l, "mutation") || (a ? f && f.size > 0 && (l = [
|
|
57
|
+
...l,
|
|
58
|
+
I("mutation", {
|
|
59
|
+
operations: R([...f].sort())
|
|
60
|
+
})
|
|
61
|
+
]) : (l = [...l, I("mutation")], s.push(
|
|
62
|
+
`${r}: @mutation added (@neo4j/graphql generates mutations for every type); remove it or narrow its operations`
|
|
63
|
+
)));
|
|
64
|
+
const m = (i.fields ?? []).filter((v) => y(v.directives, "id"));
|
|
65
|
+
m.length === 0 ? s.push(
|
|
66
|
+
`${r}: no @id field; add a required @key field (the sort tie-breaker and mutation address)`
|
|
67
|
+
) : m.length > 1 && s.push(`${r}: several @id fields; keep one as the @key`);
|
|
68
|
+
const h = (i.fields ?? []).map(
|
|
69
|
+
(v) => Ne(v, r, a, s)
|
|
70
|
+
);
|
|
71
|
+
return { ...i, directives: l, fields: h };
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
return { typeDefs: z(u), todos: s };
|
|
75
|
+
}
|
|
76
|
+
function Ne(t, n, o, s) {
|
|
77
|
+
let e = Y(
|
|
78
|
+
t.directives ?? [],
|
|
79
|
+
n,
|
|
80
|
+
t.name.value,
|
|
81
|
+
s
|
|
82
|
+
);
|
|
83
|
+
e.find((u) => u.name.value === "id") && (e = e.filter(
|
|
84
|
+
(u) => u.name.value !== "id" && u.name.value !== "unique"
|
|
85
|
+
), e.push(I("key", { generate: K(!0) })));
|
|
86
|
+
const a = o?.filters.get(n)?.get(t.name.value);
|
|
87
|
+
return a && a.size > 0 && !y(e, "filterable") && e.push(
|
|
88
|
+
y(e, "relationship") ? I("filterable") : I("filterable", { byValue: R([...a].sort()) })
|
|
89
|
+
), o?.sorts.get(n)?.has(t.name.value) && !y(e, "sortable") && e.push(I("sortable")), { ...t, directives: e };
|
|
90
|
+
}
|
|
91
|
+
function Y(t, n, o, s) {
|
|
92
|
+
const e = o ? `${n}.${o}` : n, c = [];
|
|
93
|
+
for (const a of t) {
|
|
94
|
+
const u = a.name.value;
|
|
95
|
+
if (u in x) {
|
|
96
|
+
s.push(`${e}: ${x[u]}`);
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
if (u === "key" && !o) {
|
|
100
|
+
s.push(`${e}: federation @key(fields:) is not supported`);
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
if (u === "unique") {
|
|
104
|
+
c.push(I("unique"));
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
if (u === "relationship") {
|
|
108
|
+
c.push(Se(a, e, s));
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
if (u === "fulltext") {
|
|
112
|
+
c.push(ke(a, "indexes", "indexName", "name"));
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
if (u === "subscription") {
|
|
116
|
+
c.push(Ie(a, e, s));
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
(u === "authorization" || u === "authentication") && s.push(
|
|
120
|
+
`${e}: check the @${u} rule's filters: operators are written { field: { eq: ... } } here`
|
|
121
|
+
), c.push(a);
|
|
122
|
+
}
|
|
123
|
+
return c;
|
|
124
|
+
}
|
|
125
|
+
function Se(t, n, o) {
|
|
126
|
+
const s = [];
|
|
127
|
+
for (const e of t.arguments ?? []) {
|
|
128
|
+
const c = e.name.value;
|
|
129
|
+
if (c === "queryDirection" && e.value.kind === p.ENUM) {
|
|
130
|
+
e.value.value.includes("UNDIRECTED") && s.push(L("queryDirection", Z("UNDIRECTED")));
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
if (c === "nestedOperations" && e.value.kind === p.LIST) {
|
|
134
|
+
const a = e.value.values.filter(
|
|
135
|
+
(u) => u.kind === p.ENUM && u.value !== "CONNECT_OR_CREATE"
|
|
136
|
+
);
|
|
137
|
+
a.length < e.value.values.length && o.push(`${n}: connectOrCreate is not supported; use upsert`), s.push(L("nestedOperations", { kind: p.LIST, values: a }));
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
s.push(e);
|
|
141
|
+
}
|
|
142
|
+
return { ...t, arguments: s };
|
|
143
|
+
}
|
|
144
|
+
function Ie(t, n, o) {
|
|
145
|
+
const s = t.arguments?.find((a) => a.name.value === "events")?.value;
|
|
146
|
+
if (!s || s.kind !== p.LIST) return t;
|
|
147
|
+
const e = /* @__PURE__ */ new Set();
|
|
148
|
+
let c = !1;
|
|
149
|
+
for (const a of s.values)
|
|
150
|
+
a.kind === p.ENUM && (a.value.startsWith("CREATED") && !a.value.includes("RELATIONSHIP") ? e.add("CREATE") : a.value.startsWith("UPDATED") ? e.add("UPDATE") : a.value.startsWith("DELETED") && !a.value.includes("RELATIONSHIP") ? e.add("DELETE") : a.value.includes("RELATIONSHIP") && (c = !0));
|
|
151
|
+
return o.push(
|
|
152
|
+
`${n}: subscriptions see writes made through this library (or the engine change feed), not CDC`
|
|
153
|
+
), I("subscription", {
|
|
154
|
+
operations: R([...e].sort()),
|
|
155
|
+
...c ? { relationships: K(!0) } : {}
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
function ye(t, n) {
|
|
159
|
+
const o = {
|
|
160
|
+
filters: /* @__PURE__ */ new Map(),
|
|
161
|
+
sorts: /* @__PURE__ */ new Map(),
|
|
162
|
+
mutations: /* @__PURE__ */ new Map()
|
|
163
|
+
}, s = /* @__PURE__ */ new Map();
|
|
164
|
+
for (const r of n)
|
|
165
|
+
s.set(H(r.name.value), r), s.set(De(r.name.value), r);
|
|
166
|
+
const e = new Map(n.map((r) => [r.name.value, r])), c = (r, l, f) => {
|
|
167
|
+
const m = o.filters.get(r) ?? /* @__PURE__ */ new Map(), h = m.get(l) ?? /* @__PURE__ */ new Set();
|
|
168
|
+
h.add(f), m.set(l, h), o.filters.set(r, m);
|
|
169
|
+
}, a = (r, l) => {
|
|
170
|
+
if (l.kind === p.OBJECT)
|
|
171
|
+
for (const f of l.fields) {
|
|
172
|
+
const m = f.name.value;
|
|
173
|
+
if (m === "AND" || m === "OR") {
|
|
174
|
+
if (f.value.kind === p.LIST)
|
|
175
|
+
for (const w of f.value.values) a(r, w);
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
if (m === "NOT") {
|
|
179
|
+
a(r, f.value);
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
const h = /^(.+)_(SOME|ALL|NONE|SINGLE)$/.exec(m);
|
|
183
|
+
if (h) {
|
|
184
|
+
const w = r.fields?.find((C) => C.name.value === h[1]), N = w && e.get(J(w));
|
|
185
|
+
w && N && (c(r.name.value, h[1], "EQ"), a(N, f.value));
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
const v = Te.find(([w]) => m.endsWith(w)), g = v ? m.slice(0, -v[0].length) : m, T = r.fields?.find((w) => w.name.value === g);
|
|
189
|
+
if (!T) continue;
|
|
190
|
+
const b = e.get(J(T));
|
|
191
|
+
if (b) {
|
|
192
|
+
if (c(r.name.value, g, "EQ"), f.value.kind === p.OBJECT) {
|
|
193
|
+
for (const w of f.value.fields) a(b, w.value);
|
|
194
|
+
a(b, f.value);
|
|
195
|
+
}
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
if (v) c(r.name.value, g, v[1]);
|
|
199
|
+
else if (f.value.kind === p.OBJECT)
|
|
200
|
+
for (const w of f.value.fields) {
|
|
201
|
+
const N = Ee[w.name.value];
|
|
202
|
+
N && c(r.name.value, g, N);
|
|
203
|
+
}
|
|
204
|
+
else c(r.name.value, g, "EQ");
|
|
205
|
+
}
|
|
206
|
+
}, u = (r, l) => {
|
|
207
|
+
for (const f of r?.selections ?? []) {
|
|
208
|
+
if (f.kind !== p.FIELD) continue;
|
|
209
|
+
const m = f.name.value;
|
|
210
|
+
if (l) {
|
|
211
|
+
const h = /^(create|update|delete|upsert)(.+)$/.exec(m), v = m.replace(/(Connection|Aggregate)$/, ""), g = s.get(v) ?? (h ? s.get(X(h[2])) : void 0);
|
|
212
|
+
if (g && h) {
|
|
213
|
+
const T = o.mutations.get(g.name.value) ?? /* @__PURE__ */ new Set(), b = h[1].toUpperCase();
|
|
214
|
+
b === "UPSERT" ? (T.add("CREATE"), T.add("UPDATE")) : T.add(b), o.mutations.set(g.name.value, T);
|
|
215
|
+
}
|
|
216
|
+
if (g)
|
|
217
|
+
for (const T of f.arguments ?? []) i(g, T);
|
|
218
|
+
}
|
|
219
|
+
u(f.selectionSet, !1);
|
|
220
|
+
}
|
|
221
|
+
}, i = (r, l) => {
|
|
222
|
+
if (l.name.value === "where" && a(r, l.value), l.name.value === "sort" || l.name.value === "options") {
|
|
223
|
+
const f = o.sorts.get(r.name.value) ?? /* @__PURE__ */ new Set(), m = (h) => {
|
|
224
|
+
if (h.kind === p.LIST) h.values.forEach(m);
|
|
225
|
+
else if (h.kind === p.OBJECT)
|
|
226
|
+
for (const v of h.fields)
|
|
227
|
+
v.name.value === "sort" ? m(v.value) : v.value.kind === p.ENUM && f.add(v.name.value);
|
|
228
|
+
};
|
|
229
|
+
m(l.value), o.sorts.set(r.name.value, f);
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
for (const r of t)
|
|
233
|
+
for (const l of r.definitions)
|
|
234
|
+
l.kind === p.OPERATION_DEFINITION && u(l.selectionSet, !0);
|
|
235
|
+
return o;
|
|
236
|
+
}
|
|
237
|
+
function J(t) {
|
|
238
|
+
let n = t.type;
|
|
239
|
+
for (; n.kind !== p.NAMED_TYPE; ) n = n.type;
|
|
240
|
+
return n.name.value;
|
|
241
|
+
}
|
|
242
|
+
function y(t, n) {
|
|
243
|
+
return (t ?? []).some((o) => o.name.value === n);
|
|
244
|
+
}
|
|
245
|
+
function I(t, n = {}) {
|
|
246
|
+
return {
|
|
247
|
+
kind: p.DIRECTIVE,
|
|
248
|
+
name: { kind: p.NAME, value: t },
|
|
249
|
+
arguments: Object.entries(n).map(([o, s]) => L(o, s))
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
function L(t, n) {
|
|
253
|
+
return { kind: p.ARGUMENT, name: { kind: p.NAME, value: t }, value: n };
|
|
254
|
+
}
|
|
255
|
+
const Z = (t) => ({
|
|
256
|
+
kind: p.ENUM,
|
|
257
|
+
value: t
|
|
258
|
+
}), K = (t) => ({
|
|
259
|
+
kind: p.BOOLEAN,
|
|
260
|
+
value: t
|
|
261
|
+
}), R = (t) => ({
|
|
262
|
+
kind: p.LIST,
|
|
263
|
+
values: t.map(Z)
|
|
264
|
+
});
|
|
265
|
+
function ke(t, n, o, s) {
|
|
266
|
+
return {
|
|
267
|
+
...t,
|
|
268
|
+
arguments: (t.arguments ?? []).map(
|
|
269
|
+
(e) => e.name.value === n && e.value.kind === p.LIST ? L(n, {
|
|
270
|
+
kind: p.LIST,
|
|
271
|
+
values: e.value.values.map(
|
|
272
|
+
(c) => c.kind === p.OBJECT ? {
|
|
273
|
+
...c,
|
|
274
|
+
fields: c.fields.map(
|
|
275
|
+
(a) => a.name.value === o ? { ...a, name: { kind: p.NAME, value: s } } : a
|
|
276
|
+
)
|
|
277
|
+
} : c
|
|
278
|
+
)
|
|
279
|
+
}) : e
|
|
280
|
+
)
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
const Oe = {
|
|
284
|
+
person: "people",
|
|
285
|
+
man: "men",
|
|
286
|
+
woman: "women",
|
|
287
|
+
child: "children",
|
|
288
|
+
mouse: "mice",
|
|
289
|
+
goose: "geese",
|
|
290
|
+
foot: "feet",
|
|
291
|
+
tooth: "teeth"
|
|
292
|
+
};
|
|
293
|
+
function De(t) {
|
|
294
|
+
const n = X(t), o = n.toLowerCase();
|
|
295
|
+
for (const [s, e] of Object.entries(Oe))
|
|
296
|
+
if (o.endsWith(s))
|
|
297
|
+
return n.slice(0, n.length - s.length) + e;
|
|
298
|
+
return H(t);
|
|
299
|
+
}
|
|
300
|
+
function X(t) {
|
|
301
|
+
return t.charAt(0).toLowerCase() + t.slice(1);
|
|
302
|
+
}
|
|
303
|
+
const W = `lora-graphql <command>
|
|
304
|
+
|
|
305
|
+
print <schema.graphql> the public SDL clients see
|
|
306
|
+
directives the directive definitions, for editors
|
|
307
|
+
requirements <schema.graphql> [--ddl] constraints and indexes the API needs
|
|
308
|
+
check <schema.graphql> [--operations <file|dir>]... [--json]
|
|
309
|
+
[--variables <file>] [--baseline <file> [--update-baseline]]
|
|
310
|
+
[--row-budget <n>] [--database <dir> [--name <db>]]
|
|
311
|
+
CI gate: model, lint, @cypher statements and
|
|
312
|
+
the plans of your operations, on an in-memory
|
|
313
|
+
LoraDB (or an existing one with --database)
|
|
314
|
+
compile <schema.graphql> --operations <file|dir>... [--out <dir>]
|
|
315
|
+
persisted-operation manifest.json and
|
|
316
|
+
operations.d.ts types
|
|
317
|
+
analyze <schema.graphql> --database <dir> [--name <db>] [--sample <n>]
|
|
318
|
+
statistics JSON for useStatistics()
|
|
319
|
+
migrate neo4j <schema.graphql> [--operations <file|dir>]...
|
|
320
|
+
rewrite an @neo4j/graphql SDL; TODOs for
|
|
321
|
+
what has no equivalent
|
|
322
|
+
diff <old.graphql> <new.graphql> [--allow-breaking] [--json]
|
|
323
|
+
database statements and API changes`;
|
|
324
|
+
async function $e(t, n = Fe) {
|
|
325
|
+
const [o, ...s] = t, e = /* @__PURE__ */ new Set(), c = /* @__PURE__ */ new Map(), a = [], u = [];
|
|
326
|
+
for (let i = 0; i < s.length; i++) {
|
|
327
|
+
const r = s[i];
|
|
328
|
+
r === "--operations" ? u.push(s[++i] ?? "") : Le.has(r) ? c.set(r, s[++i] ?? "") : r.startsWith("--") ? e.add(r) : a.push(r);
|
|
329
|
+
}
|
|
330
|
+
try {
|
|
331
|
+
switch (o) {
|
|
332
|
+
case "print":
|
|
333
|
+
return await Ae(k(a, 1), n);
|
|
334
|
+
case "directives":
|
|
335
|
+
return n.out(de.trim()), 0;
|
|
336
|
+
case "requirements":
|
|
337
|
+
return await qe(k(a, 1), e.has("--ddl"), n);
|
|
338
|
+
case "check":
|
|
339
|
+
return await Ce(k(a, 1), u, e, c, n);
|
|
340
|
+
case "compile":
|
|
341
|
+
return await je(k(a, 1), u, c, n);
|
|
342
|
+
case "analyze":
|
|
343
|
+
return await Me(k(a, 1), c, n);
|
|
344
|
+
case "migrate": {
|
|
345
|
+
const [i, r] = k(a, 2);
|
|
346
|
+
if (i !== "neo4j") throw new $("migrate supports neo4j");
|
|
347
|
+
const l = [];
|
|
348
|
+
for (const m of u)
|
|
349
|
+
for (const h of await q(m)) l.push(A(h.source));
|
|
350
|
+
const f = be(await E(r), l);
|
|
351
|
+
for (const m of f.todos) n.out(`# TODO(migrate): ${m}`);
|
|
352
|
+
return f.todos.length > 0 && n.out(""), n.out(f.typeDefs), 0;
|
|
353
|
+
}
|
|
354
|
+
case "diff": {
|
|
355
|
+
const [i, r] = k(a, 2);
|
|
356
|
+
return await Ue(i, r, e, n);
|
|
357
|
+
}
|
|
358
|
+
default:
|
|
359
|
+
return n.err(W), 2;
|
|
360
|
+
}
|
|
361
|
+
} catch (i) {
|
|
362
|
+
return i instanceof $ ? (n.err(`${i.message}
|
|
363
|
+
|
|
364
|
+
${W}`), 2) : i instanceof pe ? (n.err(i.message), 1) : (n.err(i instanceof Error ? i.message : String(i)), 1);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
class $ extends Error {
|
|
368
|
+
}
|
|
369
|
+
const Le = /* @__PURE__ */ new Set([
|
|
370
|
+
"--out",
|
|
371
|
+
"--variables",
|
|
372
|
+
"--baseline",
|
|
373
|
+
"--row-budget",
|
|
374
|
+
"--database",
|
|
375
|
+
"--name",
|
|
376
|
+
"--sample"
|
|
377
|
+
]);
|
|
378
|
+
function k(t, n) {
|
|
379
|
+
if (t.length < n)
|
|
380
|
+
throw new $(`expected ${n} file argument(s)`);
|
|
381
|
+
return t;
|
|
382
|
+
}
|
|
383
|
+
const E = (t) => se(t, "utf8");
|
|
384
|
+
function ee(t) {
|
|
385
|
+
const n = {
|
|
386
|
+
run: () => Promise.reject(new Error("no database"))
|
|
387
|
+
};
|
|
388
|
+
return new M({ typeDefs: t, driver: n });
|
|
389
|
+
}
|
|
390
|
+
async function Ae([t], n) {
|
|
391
|
+
return n.out(ee(await E(t)).printPublicSchema()), 0;
|
|
392
|
+
}
|
|
393
|
+
async function qe([t], n, o) {
|
|
394
|
+
const s = me(await E(t));
|
|
395
|
+
for (const e of he(s))
|
|
396
|
+
o.out(
|
|
397
|
+
n ? `${ge(e)};` : `${V(e)}, because ${e.reason}`
|
|
398
|
+
);
|
|
399
|
+
return 0;
|
|
400
|
+
}
|
|
401
|
+
async function te(t, n) {
|
|
402
|
+
try {
|
|
403
|
+
const { createDatabase: o } = await import("@loradb/lora-node");
|
|
404
|
+
return o;
|
|
405
|
+
} catch {
|
|
406
|
+
t.err(
|
|
407
|
+
`${n} needs @loradb/lora-node: npm install --save-dev @loradb/lora-node`
|
|
408
|
+
);
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
async function Ce([t], n, o, s, e) {
|
|
413
|
+
const c = o.has("--json"), a = await E(t), u = await te(e, "check");
|
|
414
|
+
if (!u) return 1;
|
|
415
|
+
const i = s.get("--database"), r = await u(
|
|
416
|
+
i ? s.get("--name") ?? "app" : void 0,
|
|
417
|
+
i ? { databaseDir: i } : {}
|
|
418
|
+
), l = new M({
|
|
419
|
+
typeDefs: a,
|
|
420
|
+
driver: Q(r)
|
|
421
|
+
});
|
|
422
|
+
i || await l.assertSchema({ create: !0 });
|
|
423
|
+
const f = l.getSchema(), m = s.has("--variables") ? JSON.parse(await E(s.get("--variables"))) : {}, h = [];
|
|
424
|
+
for (const d of n)
|
|
425
|
+
for (const S of await q(d))
|
|
426
|
+
for (const O of Re(f, S.path, S.source)) {
|
|
427
|
+
const P = m[O.name] ?? m[O.name.split("#")[1] ?? ""];
|
|
428
|
+
h.push(P ? { ...O, variables: P } : O);
|
|
429
|
+
}
|
|
430
|
+
const v = s.has("--row-budget") ? Number(s.get("--row-budget")) : void 0, g = await l.check({
|
|
431
|
+
operations: h,
|
|
432
|
+
...v !== void 0 ? { rowBudget: v } : {}
|
|
433
|
+
}), T = s.get("--baseline"), b = {};
|
|
434
|
+
for (const d of g.plans)
|
|
435
|
+
b[`${d.operation} › ${d.field}`] = d.reports.map((S) => S.operators);
|
|
436
|
+
const w = [];
|
|
437
|
+
if (T) {
|
|
438
|
+
let d;
|
|
439
|
+
try {
|
|
440
|
+
d = JSON.parse(await E(T));
|
|
441
|
+
} catch {
|
|
442
|
+
d = void 0;
|
|
443
|
+
}
|
|
444
|
+
if (o.has("--update-baseline") || !d)
|
|
445
|
+
await _(T, JSON.stringify(b, null, 2) + `
|
|
446
|
+
`);
|
|
447
|
+
else
|
|
448
|
+
for (const S of /* @__PURE__ */ new Set([
|
|
449
|
+
...Object.keys(d),
|
|
450
|
+
...Object.keys(b)
|
|
451
|
+
]))
|
|
452
|
+
JSON.stringify(d[S]) !== JSON.stringify(b[S]) && w.push(S);
|
|
453
|
+
}
|
|
454
|
+
const N = g.ok && w.length === 0;
|
|
455
|
+
if (c)
|
|
456
|
+
return e.out(JSON.stringify({ ...g, ok: N, planChanges: w }, null, 2)), N ? 0 : 1;
|
|
457
|
+
for (const d of g.warnings) e.out(`warning ${F(d)}`);
|
|
458
|
+
for (const d of g.lint) e.out(`lint ${F(d)}`);
|
|
459
|
+
for (const d of g.unused)
|
|
460
|
+
e.out(
|
|
461
|
+
`unused ${d.type} index ${d.name} on :${d.labels.join(":")}(${d.properties.join(", ")})`
|
|
462
|
+
);
|
|
463
|
+
for (const d of g.missing)
|
|
464
|
+
e.out(`error missing ${V(d)}`);
|
|
465
|
+
for (const d of g.cypher)
|
|
466
|
+
e.out(`error ${d.type}.${d.field}: ${d.message}`);
|
|
467
|
+
for (const d of g.errors)
|
|
468
|
+
e.out(`error ${d.operation}: ${d.message}`);
|
|
469
|
+
for (const d of g.plans)
|
|
470
|
+
for (const S of d.reports)
|
|
471
|
+
for (const O of S.findings)
|
|
472
|
+
e.out(`error ${d.operation} › ${d.field}: ${O.message}`);
|
|
473
|
+
for (const d of w)
|
|
474
|
+
e.out(
|
|
475
|
+
`error ${d}: the plan differs from the baseline (--update-baseline to accept)`
|
|
476
|
+
);
|
|
477
|
+
const C = g.plans.length;
|
|
478
|
+
return e.out(
|
|
479
|
+
N ? `ok ${C} root field(s) in ${h.length} operation(s) seek as expected` : "failed"
|
|
480
|
+
), N ? 0 : 1;
|
|
481
|
+
}
|
|
482
|
+
async function _e(t) {
|
|
483
|
+
const n = {};
|
|
484
|
+
for (const o of t) {
|
|
485
|
+
if ((await B(o)).isFile() && o.endsWith(".json")) {
|
|
486
|
+
Object.assign(
|
|
487
|
+
n,
|
|
488
|
+
JSON.parse(await E(o))
|
|
489
|
+
);
|
|
490
|
+
continue;
|
|
491
|
+
}
|
|
492
|
+
for (const e of await q(o)) {
|
|
493
|
+
const c = A(e.source), a = new Map(
|
|
494
|
+
c.definitions.filter(
|
|
495
|
+
(i) => i.kind === p.FRAGMENT_DEFINITION
|
|
496
|
+
).map((i) => [i.name.value, i])
|
|
497
|
+
), u = oe(process.cwd(), e.path);
|
|
498
|
+
c.definitions.filter(
|
|
499
|
+
(i) => i.kind === p.OPERATION_DEFINITION
|
|
500
|
+
).forEach((i, r) => {
|
|
501
|
+
const l = `${u}#${i.name?.value ?? r + 1}`;
|
|
502
|
+
n[l] = z({
|
|
503
|
+
kind: p.DOCUMENT,
|
|
504
|
+
definitions: [i, ...ve(i, a)]
|
|
505
|
+
});
|
|
506
|
+
});
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
return n;
|
|
510
|
+
}
|
|
511
|
+
async function je([t], n, o, s) {
|
|
512
|
+
if (n.length === 0)
|
|
513
|
+
throw new $("compile needs --operations <file|dir>");
|
|
514
|
+
const e = ee(await E(t)), c = e.buildManifest(
|
|
515
|
+
await _e(n)
|
|
516
|
+
), a = o.get("--out") ?? "lora-graphql";
|
|
517
|
+
return await ae(a, { recursive: !0 }), await _(
|
|
518
|
+
D(a, "manifest.json"),
|
|
519
|
+
JSON.stringify(c) + `
|
|
520
|
+
`
|
|
521
|
+
), await _(
|
|
522
|
+
D(a, "operations.d.ts"),
|
|
523
|
+
e.generateTypes(c)
|
|
524
|
+
), s.out(
|
|
525
|
+
`wrote ${Object.keys(c.operations).length} operation(s) to ${D(a, "manifest.json")} and ${D(a, "operations.d.ts")}`
|
|
526
|
+
), 0;
|
|
527
|
+
}
|
|
528
|
+
async function Me([t], n, o) {
|
|
529
|
+
const s = n.get("--database");
|
|
530
|
+
if (!s) throw new $("analyze needs --database <dir>");
|
|
531
|
+
const e = await te(o, "analyze");
|
|
532
|
+
if (!e) return 1;
|
|
533
|
+
const c = await e(n.get("--name") ?? "app", {
|
|
534
|
+
databaseDir: s
|
|
535
|
+
}), a = new M({
|
|
536
|
+
typeDefs: await E(t),
|
|
537
|
+
driver: Q(c)
|
|
538
|
+
}), u = n.has("--sample") ? Number(n.get("--sample")) : void 0, i = await a.analyze(u !== void 0 ? { sample: u } : {});
|
|
539
|
+
return o.out(JSON.stringify(i, null, 2)), c.dispose?.(), 0;
|
|
540
|
+
}
|
|
541
|
+
async function q(t) {
|
|
542
|
+
if ((await B(t)).isFile()) return [{ path: t, source: await E(t) }];
|
|
543
|
+
const o = [];
|
|
544
|
+
for (const s of await ne(t, { withFileTypes: !0 })) {
|
|
545
|
+
const e = D(t, s.name);
|
|
546
|
+
s.isDirectory() ? o.push(...await q(e)) : /\.(graphql|gql)$/.test(s.name) && o.push({ path: e, source: await E(e) });
|
|
547
|
+
}
|
|
548
|
+
return o;
|
|
549
|
+
}
|
|
550
|
+
function Re(t, n, o) {
|
|
551
|
+
const s = A(o), e = new Map(
|
|
552
|
+
s.definitions.filter(
|
|
553
|
+
(a) => a.kind === p.FRAGMENT_DEFINITION
|
|
554
|
+
).map((a) => [a.name.value, a])
|
|
555
|
+
), c = (a) => {
|
|
556
|
+
const u = /* @__PURE__ */ new Map(), i = (r) => G(r, {
|
|
557
|
+
FragmentSpread(l) {
|
|
558
|
+
const f = e.get(l.name.value);
|
|
559
|
+
f && !u.has(f.name.value) && (u.set(f.name.value, f), i(f));
|
|
560
|
+
}
|
|
561
|
+
});
|
|
562
|
+
return i(a), [...u.values()];
|
|
563
|
+
};
|
|
564
|
+
return s.definitions.filter(
|
|
565
|
+
(a) => a.kind === p.OPERATION_DEFINITION && a.operation === "query"
|
|
566
|
+
).map((a, u) => {
|
|
567
|
+
const i = {};
|
|
568
|
+
for (const r of a.variableDefinitions ?? []) {
|
|
569
|
+
if (r.defaultValue || r.type.kind !== p.NON_NULL_TYPE) continue;
|
|
570
|
+
const l = ie(t, r.type);
|
|
571
|
+
l && (i[r.variable.name.value] = j(l));
|
|
572
|
+
}
|
|
573
|
+
return {
|
|
574
|
+
name: `${n}${a.name ? `#${a.name.value}` : `#${u + 1}`}`,
|
|
575
|
+
document: { kind: p.DOCUMENT, definitions: [a, ...c(a)] },
|
|
576
|
+
variables: i
|
|
577
|
+
};
|
|
578
|
+
});
|
|
579
|
+
}
|
|
580
|
+
const Pe = {
|
|
581
|
+
String: "x",
|
|
582
|
+
ID: "x",
|
|
583
|
+
Int: 1,
|
|
584
|
+
Float: 1,
|
|
585
|
+
Boolean: !0,
|
|
586
|
+
BigInt: "1",
|
|
587
|
+
Date: "2026-01-01",
|
|
588
|
+
Time: "12:00:00Z",
|
|
589
|
+
LocalTime: "12:00:00",
|
|
590
|
+
DateTime: "2026-01-01T12:00:00Z",
|
|
591
|
+
LocalDateTime: "2026-01-01T12:00:00",
|
|
592
|
+
Duration: "P1D"
|
|
593
|
+
};
|
|
594
|
+
function j(t) {
|
|
595
|
+
const n = U(t) ? t.ofType : t;
|
|
596
|
+
if (re(n)) return [j(n.ofType)];
|
|
597
|
+
const o = ue(n);
|
|
598
|
+
if (ce(o)) return o.getValues()[0]?.value;
|
|
599
|
+
if (le(o)) {
|
|
600
|
+
const s = {};
|
|
601
|
+
for (const e of Object.values(o.getFields()))
|
|
602
|
+
U(e.type) && e.defaultValue === void 0 && (s[e.name] = j(e.type));
|
|
603
|
+
return s;
|
|
604
|
+
}
|
|
605
|
+
return Pe[o.name] ?? "x";
|
|
606
|
+
}
|
|
607
|
+
async function Ue(t, n, o, s) {
|
|
608
|
+
const e = fe(await E(t), await E(n)), c = e.api.breaking.length > 0, a = c && !o.has("--allow-breaking") ? 1 : 0;
|
|
609
|
+
if (o.has("--json"))
|
|
610
|
+
return s.out(JSON.stringify(e, null, 2)), a;
|
|
611
|
+
s.out("# Database"), e.database.statements.length === 0 && s.out("no changes");
|
|
612
|
+
for (const u of e.database.statements)
|
|
613
|
+
s.out(`${u.destructive ? "// destructive: " : "// "}${u.reason}`), s.out(`${u.text};`);
|
|
614
|
+
s.out(`
|
|
615
|
+
# API`), !c && e.api.dangerous.length === 0 && s.out("no changes");
|
|
616
|
+
for (const u of e.api.breaking) s.out(`breaking ${u.description}`);
|
|
617
|
+
for (const u of e.api.dangerous) s.out(`dangerous ${u.description}`);
|
|
618
|
+
for (const u of e.notes) s.out(`note ${u}`);
|
|
619
|
+
return a;
|
|
620
|
+
}
|
|
621
|
+
const Fe = {
|
|
622
|
+
out: (t) => process.stdout.write(t + `
|
|
623
|
+
`),
|
|
624
|
+
err: (t) => process.stderr.write(t + `
|
|
625
|
+
`)
|
|
626
|
+
}, xe = typeof process < "u" && process.argv[1] !== void 0 && /lora-graphql(\.js)?$|cli\.js$/.test(process.argv[1]);
|
|
627
|
+
xe && $e(process.argv.slice(2)).then((t) => process.exit(t));
|
|
628
|
+
export {
|
|
629
|
+
$e as main
|
|
630
|
+
};
|
|
631
|
+
//# sourceMappingURL=cli.js.map
|