@cyphra/cli 0.1.0 → 0.2.0
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 +21 -0
- package/README.md +0 -2
- package/dist/index.js +409 -85
- package/dist/index.js.map +1 -1
- package/package.json +18 -8
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Cyphra contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
Command-line interface for Cyphra.
|
|
4
4
|
|
|
5
|
-
Installing the **`cyphra`** meta-package pulls in **`@cyphra/cli`** as a dependency, so you get the `cyphra` binary without a second install step. Use this package on its own when you only need the CLI (for example `pnpm add -D @cyphra/cli`).
|
|
6
|
-
|
|
7
5
|
## Commands
|
|
8
6
|
|
|
9
7
|
- `cyphra init` — scaffold `cyphra.json`, `schema.cyphra`, `migrations/`, `.env.example`
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,131 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// src/index.ts
|
|
4
|
+
import { createRequire } from "module";
|
|
4
5
|
import { Command } from "commander";
|
|
5
6
|
|
|
6
|
-
// src/commands/
|
|
7
|
-
import {
|
|
7
|
+
// src/commands/dev.ts
|
|
8
|
+
import { spawnSync } from "child_process";
|
|
9
|
+
import { access, writeFile } from "fs/promises";
|
|
8
10
|
import path from "path";
|
|
11
|
+
var DEV_USER = "neo4j";
|
|
12
|
+
var DEV_PASSWORD = "cyphra-dev-password";
|
|
13
|
+
function docker(args, opts = {}) {
|
|
14
|
+
const r = spawnSync("docker", args, { encoding: "utf8" });
|
|
15
|
+
if (r.error) {
|
|
16
|
+
throw new Error("Docker is required for `cyphra dev` (could not run the docker CLI).");
|
|
17
|
+
}
|
|
18
|
+
if (r.status !== 0 && !opts.quiet) {
|
|
19
|
+
throw new Error(`docker ${args[0]} failed: ${(r.stderr || r.stdout).trim()}`);
|
|
20
|
+
}
|
|
21
|
+
return r;
|
|
22
|
+
}
|
|
23
|
+
function devContainerName(cwd) {
|
|
24
|
+
const base = path.basename(cwd).toLowerCase().replace(/[^a-z0-9_.-]/g, "-").replace(/^[^a-z0-9]+/, "");
|
|
25
|
+
return `cyphra-dev-${base || "project"}`;
|
|
26
|
+
}
|
|
27
|
+
function state(name) {
|
|
28
|
+
const r = docker(["inspect", "-f", "{{.State.Running}}", name], { quiet: true });
|
|
29
|
+
if (r.status !== 0) return "missing";
|
|
30
|
+
return r.stdout.trim() === "true" ? "running" : "stopped";
|
|
31
|
+
}
|
|
32
|
+
async function waitReady(name, timeoutMs = 12e4) {
|
|
33
|
+
const deadline = Date.now() + timeoutMs;
|
|
34
|
+
while (Date.now() < deadline) {
|
|
35
|
+
const r = docker(
|
|
36
|
+
["exec", name, "cypher-shell", "-u", DEV_USER, "-p", DEV_PASSWORD, "RETURN 1"],
|
|
37
|
+
{
|
|
38
|
+
quiet: true
|
|
39
|
+
}
|
|
40
|
+
);
|
|
41
|
+
if (r.status === 0) return;
|
|
42
|
+
await new Promise((res) => setTimeout(res, 2e3));
|
|
43
|
+
}
|
|
44
|
+
throw new Error(`Neo4j in ${name} did not become ready in time (see: docker logs ${name}).`);
|
|
45
|
+
}
|
|
46
|
+
async function runDev(cwd, opts) {
|
|
47
|
+
const name = devContainerName(cwd);
|
|
48
|
+
const volume = `${name}-data`;
|
|
49
|
+
if (opts.stop) {
|
|
50
|
+
if (state(name) === "running") docker(["stop", name]);
|
|
51
|
+
console.log(`Stopped ${name}.`);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (opts.reset) {
|
|
55
|
+
docker(["rm", "-f", name], { quiet: true });
|
|
56
|
+
docker(["volume", "rm", volume], { quiet: true });
|
|
57
|
+
console.log(`Removed ${name} and its data volume.`);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const port = opts.port ?? 7687;
|
|
61
|
+
const httpPort = opts.httpPort ?? 7474;
|
|
62
|
+
const s = state(name);
|
|
63
|
+
if (s === "missing") {
|
|
64
|
+
docker([
|
|
65
|
+
"run",
|
|
66
|
+
"-d",
|
|
67
|
+
"--name",
|
|
68
|
+
name,
|
|
69
|
+
"-p",
|
|
70
|
+
`127.0.0.1:${port}:7687`,
|
|
71
|
+
"-p",
|
|
72
|
+
`127.0.0.1:${httpPort}:7474`,
|
|
73
|
+
"-e",
|
|
74
|
+
`NEO4J_AUTH=${DEV_USER}/${DEV_PASSWORD}`,
|
|
75
|
+
"-v",
|
|
76
|
+
`${volume}:/data`,
|
|
77
|
+
opts.image ?? "neo4j:5"
|
|
78
|
+
]);
|
|
79
|
+
console.log(`Started ${name}; waiting for Neo4j\u2026`);
|
|
80
|
+
} else if (s === "stopped") {
|
|
81
|
+
docker(["start", name]);
|
|
82
|
+
console.log(`Restarted ${name}; waiting for Neo4j\u2026`);
|
|
83
|
+
}
|
|
84
|
+
await waitReady(name);
|
|
85
|
+
const portLine = docker(["port", name, "7687/tcp"]).stdout.trim().split("\n")[0] ?? "";
|
|
86
|
+
const hostPort = portLine.split(":").pop() || String(port);
|
|
87
|
+
const env = [
|
|
88
|
+
`NEO4J_URI=bolt://127.0.0.1:${hostPort}`,
|
|
89
|
+
`NEO4J_USER=${DEV_USER}`,
|
|
90
|
+
`NEO4J_PASSWORD=${DEV_PASSWORD}`,
|
|
91
|
+
""
|
|
92
|
+
].join("\n");
|
|
93
|
+
const envPath = path.join(cwd, ".env");
|
|
94
|
+
const hasEnv = await access(envPath).then(
|
|
95
|
+
() => true,
|
|
96
|
+
() => false
|
|
97
|
+
);
|
|
98
|
+
if (!hasEnv) {
|
|
99
|
+
await writeFile(
|
|
100
|
+
envPath,
|
|
101
|
+
`# Written by \`cyphra dev\` (local container ${name})
|
|
102
|
+
${env}`,
|
|
103
|
+
"utf8"
|
|
104
|
+
);
|
|
105
|
+
console.log("Wrote .env");
|
|
106
|
+
}
|
|
107
|
+
console.log(`Neo4j is ready (browser: http://127.0.0.1:${httpPort}).`);
|
|
108
|
+
if (hasEnv) console.log(`Connection settings (add to your .env if needed):
|
|
109
|
+
${env}`);
|
|
110
|
+
console.log("Stop with `cyphra dev --stop`; delete all data with `cyphra dev --reset`.");
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// src/commands/generate.ts
|
|
114
|
+
import { readFile, writeFile as writeFile2 } from "fs/promises";
|
|
115
|
+
import path2 from "path";
|
|
116
|
+
import { parseSchema, renderCyphraGenSource, validateSchema } from "@cyphra/schema";
|
|
117
|
+
async function runGenerate(cwd, config) {
|
|
118
|
+
const source = await readFile(config.schema, "utf8");
|
|
119
|
+
const doc = parseSchema(source);
|
|
120
|
+
validateSchema(doc);
|
|
121
|
+
const out = renderCyphraGenSource(doc, { runtimeImport: config.runtimeImport });
|
|
122
|
+
await writeFile2(config.generate, out, "utf8");
|
|
123
|
+
console.log(`Wrote ${path2.relative(cwd, config.generate)}`);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// src/commands/init.ts
|
|
127
|
+
import { mkdir, writeFile as writeFile3 } from "fs/promises";
|
|
128
|
+
import path3 from "path";
|
|
9
129
|
var defaultSchema = `node Example {
|
|
10
130
|
id String @id @default(cuid())
|
|
11
131
|
}
|
|
@@ -15,39 +135,54 @@ var defaultEnvExample = `# NEO4J_URI=neo4j+s://xxxx.databases.neo4j.io
|
|
|
15
135
|
# NEO4J_PASSWORD=secret
|
|
16
136
|
# NEO4J_DATABASE=neo4j
|
|
17
137
|
`;
|
|
138
|
+
async function writeIfMissing(file, content) {
|
|
139
|
+
try {
|
|
140
|
+
await writeFile3(file, content, { encoding: "utf8", flag: "wx" });
|
|
141
|
+
return true;
|
|
142
|
+
} catch (err) {
|
|
143
|
+
if (err.code === "EEXIST") return false;
|
|
144
|
+
throw err;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
18
147
|
async function runInit(cwd) {
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
148
|
+
const created = [];
|
|
149
|
+
const skipped = [];
|
|
150
|
+
const track = (name, ok) => (ok ? created : skipped).push(name);
|
|
151
|
+
track(
|
|
152
|
+
"cyphra.json",
|
|
153
|
+
await writeIfMissing(
|
|
154
|
+
path3.join(cwd, "cyphra.json"),
|
|
155
|
+
JSON.stringify(
|
|
156
|
+
{
|
|
157
|
+
schema: "./schema.cyphra",
|
|
158
|
+
migrations: "./migrations",
|
|
159
|
+
generate: "./cyphra.gen.ts"
|
|
160
|
+
},
|
|
161
|
+
null,
|
|
162
|
+
2
|
|
163
|
+
) + "\n"
|
|
164
|
+
)
|
|
32
165
|
);
|
|
33
|
-
await
|
|
34
|
-
await mkdir(
|
|
35
|
-
await
|
|
36
|
-
await
|
|
37
|
-
console.log(
|
|
166
|
+
track("schema.cyphra", await writeIfMissing(path3.join(cwd, "schema.cyphra"), defaultSchema));
|
|
167
|
+
await mkdir(path3.join(cwd, "migrations"), { recursive: true });
|
|
168
|
+
await writeIfMissing(path3.join(cwd, "migrations", ".gitkeep"), "");
|
|
169
|
+
track(".env.example", await writeIfMissing(path3.join(cwd, ".env.example"), defaultEnvExample));
|
|
170
|
+
if (created.length) console.log(`Created ${created.join(", ")}, migrations/`);
|
|
171
|
+
if (skipped.length) console.log(`Kept existing ${skipped.join(", ")}`);
|
|
172
|
+
console.log("Next: `cyphra dev` (local Neo4j), `cyphra generate`, `cyphra migrate dev`.");
|
|
38
173
|
}
|
|
39
174
|
|
|
40
175
|
// src/config.ts
|
|
41
|
-
import { readFile } from "fs/promises";
|
|
42
|
-
import
|
|
176
|
+
import { readFile as readFile2 } from "fs/promises";
|
|
177
|
+
import path5 from "path";
|
|
43
178
|
|
|
44
179
|
// src/paths.ts
|
|
45
|
-
import
|
|
180
|
+
import path4 from "path";
|
|
46
181
|
function resolveUnderRoot(root, p) {
|
|
47
|
-
const absRoot =
|
|
48
|
-
const resolved =
|
|
49
|
-
const rel =
|
|
50
|
-
if (rel.startsWith("..") ||
|
|
182
|
+
const absRoot = path4.resolve(root);
|
|
183
|
+
const resolved = path4.resolve(absRoot, p);
|
|
184
|
+
const rel = path4.relative(absRoot, resolved);
|
|
185
|
+
if (rel.startsWith("..") || path4.isAbsolute(rel)) {
|
|
51
186
|
throw new Error(`Path escapes project root: ${p}`);
|
|
52
187
|
}
|
|
53
188
|
return resolved;
|
|
@@ -55,8 +190,8 @@ function resolveUnderRoot(root, p) {
|
|
|
55
190
|
|
|
56
191
|
// src/config.ts
|
|
57
192
|
async function loadConfig(cwd) {
|
|
58
|
-
const configPath =
|
|
59
|
-
const raw = await
|
|
193
|
+
const configPath = path5.join(cwd, "cyphra.json");
|
|
194
|
+
const raw = await readFile2(configPath, "utf8");
|
|
60
195
|
const data = JSON.parse(raw);
|
|
61
196
|
if (!data || typeof data !== "object") {
|
|
62
197
|
throw new Error("cyphra.json must be a JSON object");
|
|
@@ -68,10 +203,15 @@ async function loadConfig(cwd) {
|
|
|
68
203
|
throw new Error('cyphra.json requires string fields "schema" and "migrations"');
|
|
69
204
|
}
|
|
70
205
|
const generatePath = typeof generateRaw === "string" ? generateRaw : "./cyphra.gen.ts";
|
|
206
|
+
const runtimeImportRaw = data.runtimeImport;
|
|
207
|
+
if (runtimeImportRaw !== void 0 && typeof runtimeImportRaw !== "string") {
|
|
208
|
+
throw new Error('cyphra.json "runtimeImport" must be a string');
|
|
209
|
+
}
|
|
71
210
|
return {
|
|
72
211
|
schema: resolveUnderRoot(cwd, schema),
|
|
73
212
|
migrations: resolveUnderRoot(cwd, migrations),
|
|
74
|
-
generate: resolveUnderRoot(cwd, generatePath)
|
|
213
|
+
generate: resolveUnderRoot(cwd, generatePath),
|
|
214
|
+
runtimeImport: runtimeImportRaw ?? "cyphra"
|
|
75
215
|
};
|
|
76
216
|
}
|
|
77
217
|
|
|
@@ -95,25 +235,31 @@ function clientFromEnv(debug = false) {
|
|
|
95
235
|
|
|
96
236
|
// src/loadMigrations.ts
|
|
97
237
|
import { createHash } from "crypto";
|
|
98
|
-
import { readdir, readFile as
|
|
99
|
-
import
|
|
238
|
+
import { readdir, readFile as readFile3 } from "fs/promises";
|
|
239
|
+
import path6 from "path";
|
|
100
240
|
import { pathToFileURL } from "url";
|
|
101
241
|
function assertDirUnderRoot(dir, root) {
|
|
102
|
-
const absRoot =
|
|
103
|
-
const absDir =
|
|
104
|
-
const rel =
|
|
105
|
-
if (rel.startsWith("..") ||
|
|
242
|
+
const absRoot = path6.resolve(root);
|
|
243
|
+
const absDir = path6.resolve(dir);
|
|
244
|
+
const rel = path6.relative(absRoot, absDir);
|
|
245
|
+
if (rel.startsWith("..") || path6.isAbsolute(rel)) {
|
|
106
246
|
throw new Error("Migrations directory must be inside the project root");
|
|
107
247
|
}
|
|
108
248
|
}
|
|
109
249
|
async function loadMigrationsFromDir(migrationsDir, root) {
|
|
110
250
|
assertDirUnderRoot(migrationsDir, root);
|
|
111
|
-
|
|
251
|
+
let entries;
|
|
252
|
+
try {
|
|
253
|
+
entries = await readdir(migrationsDir);
|
|
254
|
+
} catch (err) {
|
|
255
|
+
if (err.code === "ENOENT") return [];
|
|
256
|
+
throw err;
|
|
257
|
+
}
|
|
112
258
|
const files = entries.filter((f) => f.endsWith(".js") || f.endsWith(".mjs")).sort();
|
|
113
259
|
const out = [];
|
|
114
260
|
for (const f of files) {
|
|
115
|
-
const full =
|
|
116
|
-
const src = await
|
|
261
|
+
const full = path6.join(migrationsDir, f);
|
|
262
|
+
const src = await readFile3(full, "utf8");
|
|
117
263
|
const checksum = createHash("sha256").update(src).digest("hex");
|
|
118
264
|
const href = pathToFileURL(full).href;
|
|
119
265
|
const mod = await import(href);
|
|
@@ -142,11 +288,130 @@ async function runMigrate(cwd, verbose) {
|
|
|
142
288
|
}
|
|
143
289
|
}
|
|
144
290
|
|
|
291
|
+
// src/commands/migrateDev.ts
|
|
292
|
+
import { mkdir as mkdir2, readFile as readFile4, writeFile as writeFile4 } from "fs/promises";
|
|
293
|
+
import path7 from "path";
|
|
294
|
+
import {
|
|
295
|
+
EMPTY_SCHEMA_MODEL,
|
|
296
|
+
diffSchemaModels,
|
|
297
|
+
isEmptyPlan,
|
|
298
|
+
renderMigrationSource
|
|
299
|
+
} from "@cyphra/migrator";
|
|
300
|
+
import { parseSchema as parseSchema2, resolveSchema } from "@cyphra/schema";
|
|
301
|
+
var SNAPSHOT_FILE = "schema.snapshot.json";
|
|
302
|
+
async function readSnapshot(config) {
|
|
303
|
+
try {
|
|
304
|
+
const raw = await readFile4(path7.join(config.migrations, SNAPSHOT_FILE), "utf8");
|
|
305
|
+
return JSON.parse(raw);
|
|
306
|
+
} catch (err) {
|
|
307
|
+
if (err.code === "ENOENT") return null;
|
|
308
|
+
throw err;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
async function currentModel(config) {
|
|
312
|
+
return resolveSchema(parseSchema2(await readFile4(config.schema, "utf8")));
|
|
313
|
+
}
|
|
314
|
+
async function planMigration(config) {
|
|
315
|
+
const prev = await readSnapshot(config);
|
|
316
|
+
const next = await currentModel(config);
|
|
317
|
+
return { plan: diffSchemaModels(prev ?? EMPTY_SCHEMA_MODEL, next), next, first: prev === null };
|
|
318
|
+
}
|
|
319
|
+
function timestamp(d = /* @__PURE__ */ new Date()) {
|
|
320
|
+
const p = (n) => String(n).padStart(2, "0");
|
|
321
|
+
return `${d.getUTCFullYear()}${p(d.getUTCMonth() + 1)}${p(d.getUTCDate())}${p(d.getUTCHours())}${p(d.getUTCMinutes())}${p(d.getUTCSeconds())}`;
|
|
322
|
+
}
|
|
323
|
+
function printWarnings(plan) {
|
|
324
|
+
for (const w of plan.warnings) console.warn(`warning: ${w}`);
|
|
325
|
+
const destructive = plan.steps.filter((s) => s.kind === "destructive").length;
|
|
326
|
+
if (destructive) {
|
|
327
|
+
console.warn(
|
|
328
|
+
`warning: ${destructive} destructive step(s) were generated commented-out; uncomment them to apply.`
|
|
329
|
+
);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
async function runMigrateDiff(config) {
|
|
333
|
+
const { plan } = await planMigration(config);
|
|
334
|
+
if (isEmptyPlan(plan)) {
|
|
335
|
+
console.log("No schema changes since the last migration.");
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
console.log(
|
|
339
|
+
renderMigrationSource(plan, { name: "preview", runtimeImport: config.runtimeImport })
|
|
340
|
+
);
|
|
341
|
+
printWarnings(plan);
|
|
342
|
+
}
|
|
343
|
+
async function createMigrationFromSchema(cwd, config, name) {
|
|
344
|
+
const { plan, next } = await planMigration(config);
|
|
345
|
+
if (isEmptyPlan(plan)) {
|
|
346
|
+
console.log("No schema changes since the last migration.");
|
|
347
|
+
return null;
|
|
348
|
+
}
|
|
349
|
+
const safe = (name ?? "schema").replace(/[^a-zA-Z0-9_-]/g, "_") || "schema";
|
|
350
|
+
const stem = `${timestamp()}_${safe}`;
|
|
351
|
+
await mkdir2(config.migrations, { recursive: true });
|
|
352
|
+
const file = path7.join(config.migrations, `${stem}.mjs`);
|
|
353
|
+
await writeFile4(
|
|
354
|
+
file,
|
|
355
|
+
renderMigrationSource(plan, { name: stem, runtimeImport: config.runtimeImport }),
|
|
356
|
+
{ encoding: "utf8", flag: "wx" }
|
|
357
|
+
);
|
|
358
|
+
await writeFile4(
|
|
359
|
+
path7.join(config.migrations, SNAPSHOT_FILE),
|
|
360
|
+
JSON.stringify(next, null, 2) + "\n",
|
|
361
|
+
"utf8"
|
|
362
|
+
);
|
|
363
|
+
console.log(`Created ${path7.relative(cwd, file)} (${plan.steps.length} step(s))`);
|
|
364
|
+
printWarnings(plan);
|
|
365
|
+
return file;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
// src/commands/migrateStatus.ts
|
|
369
|
+
import { isEmptyPlan as isEmptyPlan2, listAppliedMigrations } from "@cyphra/migrator";
|
|
370
|
+
async function runMigrateStatus(cwd, config) {
|
|
371
|
+
let ok = true;
|
|
372
|
+
const { plan } = await planMigration(config);
|
|
373
|
+
if (!isEmptyPlan2(plan)) {
|
|
374
|
+
ok = false;
|
|
375
|
+
console.log(
|
|
376
|
+
`Schema has ${plan.steps.length} change(s) not captured in a migration: run \`cyphra migrate dev\`.`
|
|
377
|
+
);
|
|
378
|
+
}
|
|
379
|
+
const files = await loadMigrationsFromDir(config.migrations, cwd);
|
|
380
|
+
const client = clientFromEnv(false);
|
|
381
|
+
try {
|
|
382
|
+
const applied = await client.withSession((s) => listAppliedMigrations(s));
|
|
383
|
+
const appliedByName = new Map(applied.map((a) => [a.name, a]));
|
|
384
|
+
const fileNames = new Set(files.map((f) => f.name));
|
|
385
|
+
for (const f of files) {
|
|
386
|
+
const a = appliedByName.get(f.name);
|
|
387
|
+
if (!a) {
|
|
388
|
+
ok = false;
|
|
389
|
+
console.log(`pending ${f.name}`);
|
|
390
|
+
} else if (a.checksum && a.checksum !== f.checksum) {
|
|
391
|
+
ok = false;
|
|
392
|
+
console.log(`modified ${f.name} (changed after it was applied)`);
|
|
393
|
+
} else {
|
|
394
|
+
console.log(`applied ${f.name}`);
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
for (const a of applied) {
|
|
398
|
+
if (!fileNames.has(a.name)) {
|
|
399
|
+
ok = false;
|
|
400
|
+
console.log(`missing ${a.name} (applied, but no file in ${config.migrations})`);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
if (files.length === 0 && applied.length === 0) console.log("No migrations yet.");
|
|
404
|
+
} finally {
|
|
405
|
+
await client.close();
|
|
406
|
+
}
|
|
407
|
+
return ok;
|
|
408
|
+
}
|
|
409
|
+
|
|
145
410
|
// src/commands/migrationCreate.ts
|
|
146
|
-
import { writeFile as
|
|
147
|
-
import
|
|
148
|
-
function migrationFileBody(name) {
|
|
149
|
-
return `import { defineMigration } from
|
|
411
|
+
import { mkdir as mkdir3, writeFile as writeFile5 } from "fs/promises";
|
|
412
|
+
import path8 from "path";
|
|
413
|
+
function migrationFileBody(name, runtimeImport) {
|
|
414
|
+
return `import { defineMigration } from ${JSON.stringify(runtimeImport)};
|
|
150
415
|
|
|
151
416
|
export default defineMigration({
|
|
152
417
|
name: ${JSON.stringify(name)},
|
|
@@ -156,39 +421,68 @@ export default defineMigration({
|
|
|
156
421
|
});
|
|
157
422
|
`;
|
|
158
423
|
}
|
|
159
|
-
async function runMigrationCreate(cwd, migrationsDir, stem) {
|
|
424
|
+
async function runMigrationCreate(cwd, migrationsDir, stem, runtimeImport = "cyphra") {
|
|
160
425
|
const safe = stem.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
161
426
|
const fileName = `${safe}.mjs`;
|
|
162
|
-
const full =
|
|
163
|
-
await
|
|
164
|
-
|
|
427
|
+
const full = path8.join(migrationsDir, fileName);
|
|
428
|
+
await mkdir3(migrationsDir, { recursive: true });
|
|
429
|
+
await writeFile5(full, migrationFileBody(safe, runtimeImport), { encoding: "utf8", flag: "wx" });
|
|
430
|
+
console.log(`Created ${path8.relative(cwd, full)}`);
|
|
165
431
|
}
|
|
166
432
|
|
|
167
|
-
// src/commands/
|
|
168
|
-
import {
|
|
169
|
-
import
|
|
170
|
-
import {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
const
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
433
|
+
// src/commands/pull.ts
|
|
434
|
+
import { access as access2, writeFile as writeFile6 } from "fs/promises";
|
|
435
|
+
import path9 from "path";
|
|
436
|
+
import { introspectDatabase, schemaFromIntrospection } from "@cyphra/migrator";
|
|
437
|
+
import { parseSchema as parseSchema3, printSchemaDocument, resolveSchema as resolveSchema2 } from "@cyphra/schema";
|
|
438
|
+
async function runPull(cwd, config, opts) {
|
|
439
|
+
const client = clientFromEnv(false);
|
|
440
|
+
let source;
|
|
441
|
+
let warnings;
|
|
442
|
+
try {
|
|
443
|
+
const result = schemaFromIntrospection(await introspectDatabase(client));
|
|
444
|
+
warnings = result.warnings;
|
|
445
|
+
const header = [
|
|
446
|
+
"// Generated by `cyphra pull`. Review it: relation names are guessed from relationship types,",
|
|
447
|
+
"// every relation is to-many, and required-ness reflects the data at the time of the pull.",
|
|
448
|
+
"",
|
|
449
|
+
""
|
|
450
|
+
].join("\n");
|
|
451
|
+
source = header + printSchemaDocument(result.doc);
|
|
452
|
+
} finally {
|
|
453
|
+
await client.close();
|
|
454
|
+
}
|
|
455
|
+
resolveSchema2(parseSchema3(source));
|
|
456
|
+
if (opts.print) {
|
|
457
|
+
process.stdout.write(source);
|
|
458
|
+
} else {
|
|
459
|
+
const exists = await access2(config.schema).then(
|
|
460
|
+
() => true,
|
|
461
|
+
() => false
|
|
462
|
+
);
|
|
463
|
+
if (exists && !opts.force) {
|
|
464
|
+
throw new Error(
|
|
465
|
+
`${path9.relative(cwd, config.schema)} already exists: pass --force to overwrite or --print to write to stdout.`
|
|
466
|
+
);
|
|
467
|
+
}
|
|
468
|
+
await writeFile6(config.schema, source, "utf8");
|
|
469
|
+
console.log(`Wrote ${path9.relative(cwd, config.schema)}`);
|
|
470
|
+
}
|
|
471
|
+
for (const w of warnings) console.warn(`warning: ${w}`);
|
|
178
472
|
}
|
|
179
473
|
|
|
180
474
|
// src/commands/push.ts
|
|
181
|
-
import { readFile as
|
|
475
|
+
import { readFile as readFile5 } from "fs/promises";
|
|
182
476
|
import {
|
|
183
477
|
applyConstraintStatements,
|
|
184
478
|
constraintStatementsFromSchema,
|
|
185
479
|
indexStatementsFromSchema
|
|
186
480
|
} from "@cyphra/migrator";
|
|
187
|
-
import { parseSchema as
|
|
481
|
+
import { parseSchema as parseSchema4 } from "@cyphra/schema";
|
|
188
482
|
async function runPush(cwd) {
|
|
189
483
|
const config = await loadConfig(cwd);
|
|
190
|
-
const source = await
|
|
191
|
-
const doc =
|
|
484
|
+
const source = await readFile5(config.schema, "utf8");
|
|
485
|
+
const doc = parseSchema4(source);
|
|
192
486
|
const constraints = constraintStatementsFromSchema(doc);
|
|
193
487
|
const indexes = indexStatementsFromSchema(doc);
|
|
194
488
|
const statements = [...constraints, ...indexes];
|
|
@@ -204,12 +498,12 @@ async function runPush(cwd) {
|
|
|
204
498
|
}
|
|
205
499
|
|
|
206
500
|
// src/commands/schemaDdl.ts
|
|
207
|
-
import { readFile as
|
|
501
|
+
import { readFile as readFile6 } from "fs/promises";
|
|
208
502
|
import { constraintStatementsFromSchema as constraintStatementsFromSchema2, indexStatementsFromSchema as indexStatementsFromSchema2 } from "@cyphra/migrator";
|
|
209
|
-
import { parseSchema as
|
|
503
|
+
import { parseSchema as parseSchema5 } from "@cyphra/schema";
|
|
210
504
|
async function runSchemaDdl(config) {
|
|
211
|
-
const source = await
|
|
212
|
-
const doc =
|
|
505
|
+
const source = await readFile6(config.schema, "utf8");
|
|
506
|
+
const doc = parseSchema5(source);
|
|
213
507
|
for (const stmt of constraintStatementsFromSchema2(doc)) {
|
|
214
508
|
console.log(stmt);
|
|
215
509
|
}
|
|
@@ -219,46 +513,76 @@ async function runSchemaDdl(config) {
|
|
|
219
513
|
}
|
|
220
514
|
|
|
221
515
|
// src/commands/schemaPrint.ts
|
|
222
|
-
import { readFile as
|
|
223
|
-
import { parseSchema as
|
|
516
|
+
import { readFile as readFile7 } from "fs/promises";
|
|
517
|
+
import { parseSchema as parseSchema6, printSchemaDocument as printSchemaDocument2, validateSchema as validateSchema2 } from "@cyphra/schema";
|
|
224
518
|
async function runSchemaPrint(config) {
|
|
225
|
-
const raw = await
|
|
226
|
-
const doc =
|
|
519
|
+
const raw = await readFile7(config.schema, "utf8");
|
|
520
|
+
const doc = parseSchema6(raw);
|
|
227
521
|
validateSchema2(doc);
|
|
228
|
-
process.stdout.write(
|
|
522
|
+
process.stdout.write(printSchemaDocument2(doc));
|
|
229
523
|
}
|
|
230
524
|
|
|
231
525
|
// src/commands/validateSchema.ts
|
|
232
|
-
import { readFile as
|
|
233
|
-
import
|
|
234
|
-
import { parseSchema as
|
|
526
|
+
import { readFile as readFile8 } from "fs/promises";
|
|
527
|
+
import path10 from "path";
|
|
528
|
+
import { parseSchema as parseSchema7, resolveSchema as resolveSchema3, validateSchema as validateSchema3 } from "@cyphra/schema";
|
|
235
529
|
async function runValidateSchema(cwd, config) {
|
|
236
|
-
const raw = await
|
|
237
|
-
const doc =
|
|
530
|
+
const raw = await readFile8(config.schema, "utf8");
|
|
531
|
+
const doc = parseSchema7(raw);
|
|
238
532
|
validateSchema3(doc);
|
|
239
|
-
|
|
533
|
+
resolveSchema3(doc);
|
|
534
|
+
const rel = path10.relative(cwd, config.schema);
|
|
240
535
|
console.log(`OK \u2014 ${rel} (${doc.declarations.length} declaration(s))`);
|
|
241
536
|
}
|
|
242
537
|
|
|
243
538
|
// src/index.ts
|
|
539
|
+
try {
|
|
540
|
+
process.loadEnvFile?.(".env");
|
|
541
|
+
} catch {
|
|
542
|
+
}
|
|
543
|
+
var { version } = createRequire(import.meta.url)("../package.json");
|
|
244
544
|
var program = new Command();
|
|
245
|
-
program.name("cyphra").description("Cyphra
|
|
246
|
-
program.command("init").description(
|
|
545
|
+
program.name("cyphra").description("Cyphra: typed ORM, migrations and tooling for Neo4j").version(version);
|
|
546
|
+
program.command("init").description(
|
|
547
|
+
"Create cyphra.json, schema.cyphra, migrations/ and .env.example (existing files are kept)"
|
|
548
|
+
).action(async () => {
|
|
247
549
|
await runInit(process.cwd());
|
|
248
550
|
});
|
|
551
|
+
program.command("dev").description("Run a local Neo4j 5 in Docker for this project and write .env").option("--stop", "stop the container").option("--reset", "remove the container and its data volume").option("--port <port>", "host Bolt port (default 7687)", (v) => Number(v)).option("--http-port <port>", "host HTTP/browser port (default 7474)", (v) => Number(v)).option("--image <image>", "Docker image (default neo4j:5)").action(
|
|
552
|
+
async (opts) => {
|
|
553
|
+
await runDev(process.cwd(), opts);
|
|
554
|
+
}
|
|
555
|
+
);
|
|
249
556
|
var migrate = program.command("migrate").description("Migration commands");
|
|
557
|
+
migrate.command("dev").description(
|
|
558
|
+
"Generate a migration from schema changes since the last one, then apply pending migrations"
|
|
559
|
+
).option("-n, --name <name>", "migration name (default: schema)").option("--create-only", "write the migration without applying it").action(async (opts) => {
|
|
560
|
+
const cwd = process.cwd();
|
|
561
|
+
const config = await loadConfig(cwd);
|
|
562
|
+
await createMigrationFromSchema(cwd, config, opts.name);
|
|
563
|
+
if (!opts.createOnly) await runMigrate(cwd, true);
|
|
564
|
+
});
|
|
565
|
+
migrate.command("diff").description("Print the migration `migrate dev` would generate (no database, no files written)").action(async () => {
|
|
566
|
+
await runMigrateDiff(await loadConfig(process.cwd()));
|
|
567
|
+
});
|
|
250
568
|
migrate.command("deploy").description("Apply pending migrations").action(async () => {
|
|
251
569
|
await runMigrate(process.cwd(), false);
|
|
252
570
|
});
|
|
253
|
-
migrate.command("
|
|
254
|
-
|
|
571
|
+
migrate.command("status").description("Show applied / pending / modified migrations and uncaptured schema changes").action(async () => {
|
|
572
|
+
const cwd = process.cwd();
|
|
573
|
+
const ok = await runMigrateStatus(cwd, await loadConfig(cwd));
|
|
574
|
+
if (!ok) process.exitCode = 1;
|
|
255
575
|
});
|
|
256
|
-
program.command("migration:create").argument("<name>", "Migration file stem (e.g. add-index)").description("Create
|
|
576
|
+
program.command("migration:create").argument("<name>", "Migration file stem (e.g. add-index)").description("Create an empty .mjs migration to write by hand").action(async (name) => {
|
|
257
577
|
const cwd = process.cwd();
|
|
258
578
|
const config = await loadConfig(cwd);
|
|
259
|
-
await runMigrationCreate(cwd, config.migrations, name);
|
|
579
|
+
await runMigrationCreate(cwd, config.migrations, name, config.runtimeImport);
|
|
580
|
+
});
|
|
581
|
+
program.command("pull").description("Introspect the database and write schema.cyphra").option("--force", "overwrite an existing schema file").option("--print", "write the schema to stdout instead of the schema file").action(async (opts) => {
|
|
582
|
+
const cwd = process.cwd();
|
|
583
|
+
await runPull(cwd, await loadConfig(cwd), opts);
|
|
260
584
|
});
|
|
261
|
-
program.command("push").description("
|
|
585
|
+
program.command("push").description("Apply schema constraints and indexes directly (prototyping; prefer migrate dev)").action(async () => {
|
|
262
586
|
await runPush(process.cwd());
|
|
263
587
|
});
|
|
264
588
|
program.command("validate").description("Parse and validate schema.cyphra").action(async () => {
|
|
@@ -266,7 +590,7 @@ program.command("validate").description("Parse and validate schema.cyphra").acti
|
|
|
266
590
|
const config = await loadConfig(cwd);
|
|
267
591
|
await runValidateSchema(cwd, config);
|
|
268
592
|
});
|
|
269
|
-
program.command("generate").description("
|
|
593
|
+
program.command("generate").description("Generate the typed client (cyphra.gen.ts) from the schema").action(async () => {
|
|
270
594
|
const cwd = process.cwd();
|
|
271
595
|
const config = await loadConfig(cwd);
|
|
272
596
|
await runGenerate(cwd, config);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/commands/init.ts","../src/config.ts","../src/paths.ts","../src/clientFromEnv.ts","../src/loadMigrations.ts","../src/commands/migrate.ts","../src/commands/migrationCreate.ts","../src/commands/generate.ts","../src/commands/push.ts","../src/commands/schemaDdl.ts","../src/commands/schemaPrint.ts","../src/commands/validateSchema.ts"],"sourcesContent":["import { Command } from \"commander\";\nimport { runInit } from \"./commands/init.js\";\nimport { runMigrate } from \"./commands/migrate.js\";\nimport { runMigrationCreate } from \"./commands/migrationCreate.js\";\nimport { runGenerate } from \"./commands/generate.js\";\nimport { runPush } from \"./commands/push.js\";\nimport { runSchemaDdl } from \"./commands/schemaDdl.js\";\nimport { runSchemaPrint } from \"./commands/schemaPrint.js\";\nimport { runValidateSchema } from \"./commands/validateSchema.js\";\nimport { loadConfig } from \"./config.js\";\n\nconst program = new Command();\nprogram.name(\"cyphra\").description(\"Cyphra toolkit for Neo4j\").version(\"0.0.0\");\n\nprogram\n .command(\"init\")\n .description(\"Create cyphra.json, schema.cyphra, migrations/, .env.example\")\n .action(async () => {\n await runInit(process.cwd());\n });\n\nconst migrate = program.command(\"migrate\").description(\"Migration commands\");\n\nmigrate\n .command(\"deploy\")\n .description(\"Apply pending migrations\")\n .action(async () => {\n await runMigrate(process.cwd(), false);\n });\n\nmigrate\n .command(\"dev\")\n .description(\"Apply pending migrations (verbose)\")\n .action(async () => {\n await runMigrate(process.cwd(), true);\n });\n\nprogram\n .command(\"migration:create\")\n .argument(\"<name>\", \"Migration file stem (e.g. add-index)\")\n .description(\"Create a new .mjs migration\")\n .action(async (name: string) => {\n const cwd = process.cwd();\n const config = await loadConfig(cwd);\n await runMigrationCreate(cwd, config.migrations, name);\n });\n\nprogram\n .command(\"push\")\n .description(\"Push schema constraints to Neo4j\")\n .action(async () => {\n await runPush(process.cwd());\n });\n\nprogram\n .command(\"validate\")\n .description(\"Parse and validate schema.cyphra\")\n .action(async () => {\n const cwd = process.cwd();\n const config = await loadConfig(cwd);\n await runValidateSchema(cwd, config);\n });\n\nprogram\n .command(\"generate\")\n .description(\"Emit cyphra.gen.ts (labels, relationship types) from the schema\")\n .action(async () => {\n const cwd = process.cwd();\n const config = await loadConfig(cwd);\n await runGenerate(cwd, config);\n });\n\nconst schemaCmd = program.command(\"schema\").description(\"Schema utilities\");\n\nschemaCmd\n .command(\"print\")\n .description(\"Pretty-print schema.cyphra to stdout (canonical formatting)\")\n .action(async () => {\n const cwd = process.cwd();\n const config = await loadConfig(cwd);\n await runSchemaPrint(config);\n });\n\nschemaCmd\n .command(\"ddl\")\n .description(\"Print constraint + range-index DDL for push (no database connection)\")\n .action(async () => {\n const cwd = process.cwd();\n const config = await loadConfig(cwd);\n await runSchemaDdl(config);\n });\n\nprogram.parseAsync(process.argv).catch((err: unknown) => {\n console.error(err instanceof Error ? err.message : err);\n process.exitCode = 1;\n});\n","import { mkdir, writeFile } from \"node:fs/promises\";\nimport path from \"node:path\";\n\nconst defaultSchema = `node Example {\n id String @id @default(cuid())\n}\n`;\n\nconst defaultEnvExample = `# NEO4J_URI=neo4j+s://xxxx.databases.neo4j.io\n# NEO4J_USER=neo4j\n# NEO4J_PASSWORD=secret\n# NEO4J_DATABASE=neo4j\n`;\n\n/**\n * Scaffold `cyphra.json`, `schema.cyphra`, `migrations/`, and `.env.example`.\n *\n * @param cwd - Project directory.\n */\nexport async function runInit(cwd: string): Promise<void> {\n const configPath = path.join(cwd, \"cyphra.json\");\n await writeFile(\n configPath,\n JSON.stringify(\n {\n schema: \"./schema.cyphra\",\n migrations: \"./migrations\",\n generate: \"./cyphra.gen.ts\",\n },\n null,\n 2,\n ) + \"\\n\",\n \"utf8\",\n );\n await writeFile(path.join(cwd, \"schema.cyphra\"), defaultSchema, \"utf8\");\n await mkdir(path.join(cwd, \"migrations\"), { recursive: true });\n await writeFile(path.join(cwd, \"migrations\", \".gitkeep\"), \"\", \"utf8\");\n await writeFile(path.join(cwd, \".env.example\"), defaultEnvExample, \"utf8\");\n console.log(\"Created cyphra.json, schema.cyphra, migrations/, .env.example\");\n}\n","import { readFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { resolveUnderRoot } from \"./paths.js\";\n\nexport type CyphraConfig = {\n readonly schema: string;\n readonly migrations: string;\n /** Absolute path for `cyphra generate` output (default `./cyphra.gen.ts`). */\n readonly generate: string;\n};\n\n/**\n * Load `cyphra.json` from the working directory.\n *\n * @param cwd - Current working directory (absolute).\n */\nexport async function loadConfig(cwd: string): Promise<CyphraConfig> {\n const configPath = path.join(cwd, \"cyphra.json\");\n const raw = await readFile(configPath, \"utf8\");\n const data = JSON.parse(raw) as unknown;\n if (!data || typeof data !== \"object\") {\n throw new Error(\"cyphra.json must be a JSON object\");\n }\n const schema = (data as Record<string, unknown>).schema;\n const migrations = (data as Record<string, unknown>).migrations;\n const generateRaw = (data as Record<string, unknown>).generate;\n if (typeof schema !== \"string\" || typeof migrations !== \"string\") {\n throw new Error('cyphra.json requires string fields \"schema\" and \"migrations\"');\n }\n const generatePath = typeof generateRaw === \"string\" ? generateRaw : \"./cyphra.gen.ts\";\n return {\n schema: resolveUnderRoot(cwd, schema),\n migrations: resolveUnderRoot(cwd, migrations),\n generate: resolveUnderRoot(cwd, generatePath),\n };\n}\n","import path from \"node:path\";\n\n/**\n * Resolve `p` under `root` and throw if the result escapes `root` (path traversal guard).\n *\n * @param root - Project root directory (absolute).\n * @param p - Path segment or relative path from config.\n * @returns Absolute normalized path under `root`.\n */\nexport function resolveUnderRoot(root: string, p: string): string {\n const absRoot = path.resolve(root);\n const resolved = path.resolve(absRoot, p);\n const rel = path.relative(absRoot, resolved);\n if (rel.startsWith(\"..\") || path.isAbsolute(rel)) {\n throw new Error(`Path escapes project root: ${p}`);\n }\n return resolved;\n}\n","import { CyphraClient } from \"@cyphra/runtime\";\n\n/**\n * Build a {@link CyphraClient} from `NEO4J_URI`, `NEO4J_USER`, `NEO4J_PASSWORD`, optional `NEO4J_DATABASE`.\n *\n * @param debug - Forwarded to client options.\n */\nexport function clientFromEnv(debug = false): CyphraClient {\n const uri = process.env.NEO4J_URI;\n const user = process.env.NEO4J_USER;\n const password = process.env.NEO4J_PASSWORD;\n if (!uri || !user || !password) {\n throw new Error(\"Set NEO4J_URI, NEO4J_USER, and NEO4J_PASSWORD in the environment\");\n }\n return new CyphraClient({\n uri,\n user,\n password,\n database: process.env.NEO4J_DATABASE,\n debug,\n });\n}\n","import { createHash } from \"node:crypto\";\nimport { readdir, readFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport type { LoadedMigration, MigrationDefinition } from \"@cyphra/migrator\";\n\nfunction assertDirUnderRoot(dir: string, root: string): void {\n const absRoot = path.resolve(root);\n const absDir = path.resolve(dir);\n const rel = path.relative(absRoot, absDir);\n if (rel.startsWith(\"..\") || path.isAbsolute(rel)) {\n throw new Error(\"Migrations directory must be inside the project root\");\n }\n}\n\n/**\n * Load sorted `.js` / `.mjs` migration modules from a directory.\n *\n * @param migrationsDir - Absolute migrations directory (from config).\n * @param root - Project root for validation.\n */\nexport async function loadMigrationsFromDir(\n migrationsDir: string,\n root: string,\n): Promise<LoadedMigration[]> {\n assertDirUnderRoot(migrationsDir, root);\n const entries = await readdir(migrationsDir);\n const files = entries.filter((f) => f.endsWith(\".js\") || f.endsWith(\".mjs\")).sort();\n const out: LoadedMigration[] = [];\n for (const f of files) {\n const full = path.join(migrationsDir, f);\n const src = await readFile(full, \"utf8\");\n const checksum = createHash(\"sha256\").update(src).digest(\"hex\");\n const href = pathToFileURL(full).href;\n const mod = (await import(href)) as { default?: MigrationDefinition };\n const def = mod.default;\n if (!def?.name || typeof def.up !== \"function\") {\n throw new Error(`Migration ${f} must export default defineMigration({ name, up })`);\n }\n out.push({ name: def.name, checksum, definition: def });\n }\n return out;\n}\n","import { loadConfig } from \"../config.js\";\nimport { clientFromEnv } from \"../clientFromEnv.js\";\nimport { loadMigrationsFromDir } from \"../loadMigrations.js\";\nimport { runPendingMigrations } from \"@cyphra/migrator\";\n\n/**\n * Apply pending migrations (deploy / dev — same behavior; dev may pass verbose later).\n *\n * @param cwd - Project root.\n * @param verbose - Log applied migration names.\n */\nexport async function runMigrate(cwd: string, verbose: boolean): Promise<void> {\n const config = await loadConfig(cwd);\n const client = clientFromEnv(verbose);\n try {\n const loaded = await loadMigrationsFromDir(config.migrations, cwd);\n const applied = await runPendingMigrations(client, loaded);\n if (verbose || applied.length > 0) {\n console.log(applied.length ? `Applied: ${applied.join(\", \")}` : \"No pending migrations\");\n }\n } finally {\n await client.close();\n }\n}\n","import { writeFile } from \"node:fs/promises\";\nimport path from \"node:path\";\n\nfunction migrationFileBody(name: string): string {\n return `import { defineMigration } from \"@cyphra/migrator\";\n\nexport default defineMigration({\n name: ${JSON.stringify(name)},\n async up({ db }) {\n await db.run\\`RETURN 1 AS ok\\`;\n },\n});\n`;\n}\n\n/**\n * Create a new `.mjs` migration stub under `migrations/`.\n *\n * @param cwd - Project root.\n * @param migrationsDir - Absolute migrations directory.\n * @param stem - File stem used for file name and migration `name`.\n */\nexport async function runMigrationCreate(\n cwd: string,\n migrationsDir: string,\n stem: string,\n): Promise<void> {\n const safe = stem.replace(/[^a-zA-Z0-9_-]/g, \"_\");\n const fileName = `${safe}.mjs`;\n const full = path.join(migrationsDir, fileName);\n await writeFile(full, migrationFileBody(safe), \"utf8\");\n console.log(`Created ${path.relative(cwd, full)}`);\n}\n","import { readFile, writeFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { parseSchema, renderCyphraGenSource, validateSchema } from \"@cyphra/schema\";\nimport type { CyphraConfig } from \"../config.js\";\n\n/**\n * Emit `cyphra.gen.ts` (or configured path) from the schema file.\n *\n * @param cwd - Project root.\n * @param config - Loaded config with absolute schema and output paths.\n */\nexport async function runGenerate(cwd: string, config: CyphraConfig): Promise<void> {\n const source = await readFile(config.schema, \"utf8\");\n const doc = parseSchema(source);\n validateSchema(doc);\n const out = renderCyphraGenSource(doc);\n await writeFile(config.generate, out, \"utf8\");\n console.log(`Wrote ${path.relative(cwd, config.generate)}`);\n}\n","import { readFile } from \"node:fs/promises\";\nimport {\n applyConstraintStatements,\n constraintStatementsFromSchema,\n indexStatementsFromSchema,\n} from \"@cyphra/migrator\";\nimport { parseSchema } from \"@cyphra/schema\";\nimport { loadConfig } from \"../config.js\";\nimport { clientFromEnv } from \"../clientFromEnv.js\";\n\n/**\n * Parse `schema.cyphra` and apply generated constraints.\n *\n * @param cwd - Project root.\n */\nexport async function runPush(cwd: string): Promise<void> {\n const config = await loadConfig(cwd);\n const source = await readFile(config.schema, \"utf8\");\n const doc = parseSchema(source);\n const constraints = constraintStatementsFromSchema(doc);\n const indexes = indexStatementsFromSchema(doc);\n const statements = [...constraints, ...indexes];\n const client = clientFromEnv(false);\n try {\n await applyConstraintStatements(client, statements);\n console.log(\n `Applied ${constraints.length} constraint statement(s) and ${indexes.length} range index statement(s)`,\n );\n } finally {\n await client.close();\n }\n}\n","import { readFile } from \"node:fs/promises\";\nimport { constraintStatementsFromSchema, indexStatementsFromSchema } from \"@cyphra/migrator\";\nimport { parseSchema } from \"@cyphra/schema\";\nimport type { CyphraConfig } from \"../config.js\";\n\n/**\n * Print `CREATE CONSTRAINT` / `CREATE RANGE INDEX` lines for the schema (same order as `cyphra push`).\n * Does not connect to Neo4j.\n *\n * @param config - Config with absolute schema path.\n */\nexport async function runSchemaDdl(config: CyphraConfig): Promise<void> {\n const source = await readFile(config.schema, \"utf8\");\n const doc = parseSchema(source);\n for (const stmt of constraintStatementsFromSchema(doc)) {\n console.log(stmt);\n }\n for (const stmt of indexStatementsFromSchema(doc)) {\n console.log(stmt);\n }\n}\n","import { readFile } from \"node:fs/promises\";\nimport { parseSchema, printSchemaDocument, validateSchema } from \"@cyphra/schema\";\nimport type { CyphraConfig } from \"../config.js\";\n\n/**\n * Print a canonical `.cyphra` rendering of the schema to stdout.\n *\n * @param config - Config with absolute schema path.\n */\nexport async function runSchemaPrint(config: CyphraConfig): Promise<void> {\n const raw = await readFile(config.schema, \"utf8\");\n const doc = parseSchema(raw);\n validateSchema(doc);\n process.stdout.write(printSchemaDocument(doc));\n}\n","import { readFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { parseSchema, validateSchema } from \"@cyphra/schema\";\nimport type { CyphraConfig } from \"../config.js\";\n\n/**\n * Parse and semantically validate `schema.cyphra`.\n *\n * @param cwd - Project root (for relative log paths).\n * @param config - Config with absolute schema path.\n */\nexport async function runValidateSchema(cwd: string, config: CyphraConfig): Promise<void> {\n const raw = await readFile(config.schema, \"utf8\");\n const doc = parseSchema(raw);\n validateSchema(doc);\n const rel = path.relative(cwd, config.schema);\n console.log(`OK — ${rel} (${doc.declarations.length} declaration(s))`);\n}\n"],"mappings":";;;AAAA,SAAS,eAAe;;;ACAxB,SAAS,OAAO,iBAAiB;AACjC,OAAO,UAAU;AAEjB,IAAM,gBAAgB;AAAA;AAAA;AAAA;AAKtB,IAAM,oBAAoB;AAAA;AAAA;AAAA;AAAA;AAW1B,eAAsB,QAAQ,KAA4B;AACxD,QAAM,aAAa,KAAK,KAAK,KAAK,aAAa;AAC/C,QAAM;AAAA,IACJ;AAAA,IACA,KAAK;AAAA,MACH;AAAA,QACE,QAAQ;AAAA,QACR,YAAY;AAAA,QACZ,UAAU;AAAA,MACZ;AAAA,MACA;AAAA,MACA;AAAA,IACF,IAAI;AAAA,IACJ;AAAA,EACF;AACA,QAAM,UAAU,KAAK,KAAK,KAAK,eAAe,GAAG,eAAe,MAAM;AACtE,QAAM,MAAM,KAAK,KAAK,KAAK,YAAY,GAAG,EAAE,WAAW,KAAK,CAAC;AAC7D,QAAM,UAAU,KAAK,KAAK,KAAK,cAAc,UAAU,GAAG,IAAI,MAAM;AACpE,QAAM,UAAU,KAAK,KAAK,KAAK,cAAc,GAAG,mBAAmB,MAAM;AACzE,UAAQ,IAAI,+DAA+D;AAC7E;;;ACvCA,SAAS,gBAAgB;AACzB,OAAOA,WAAU;;;ACDjB,OAAO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ACnC,QAAM,kBAAkB,KAAK,MAAM;AACrC,CAAC;AAEH,QACG,QAAQ,UAAU,EAClB,YAAY,iEAAiE,EAC7E,OAAO,YAAY;AAClB,QAAM,MAAM,QAAQ,IAAI;AACxB,QAAM,SAAS,MAAM,WAAW,GAAG;AACnC,QAAM,YAAY,KAAK,MAAM;AAC/B,CAAC;AAEH,IAAM,YAAY,QAAQ,QAAQ,QAAQ,EAAE,YAAY,kBAAkB;AAE1E,UACG,QAAQ,OAAO,EACf,YAAY,6DAA6D,EACzE,OAAO,YAAY;AAClB,QAAM,MAAM,QAAQ,IAAI;AACxB,QAAM,SAAS,MAAM,WAAW,GAAG;AACnC,QAAM,eAAe,MAAM;AAC7B,CAAC;AAEH,UACG,QAAQ,KAAK,EACb,YAAY,sEAAsE,EAClF,OAAO,YAAY;AAClB,QAAM,MAAM,QAAQ,IAAI;AACxB,QAAM,SAAS,MAAM,WAAW,GAAG;AACnC,QAAM,aAAa,MAAM;AAC3B,CAAC;AAEH,QAAQ,WAAW,QAAQ,IAAI,EAAE,MAAM,CAAC,QAAiB;AACvD,UAAQ,MAAM,eAAe,QAAQ,IAAI,UAAU,GAAG;AACtD,UAAQ,WAAW;AACrB,CAAC;","names":["path","path","path","readFile","path","writeFile","path","readFile","writeFile","path","readFile","parseSchema","readFile","parseSchema","readFile","constraintStatementsFromSchema","indexStatementsFromSchema","parseSchema","readFile","parseSchema","validateSchema","readFile","path","parseSchema","validateSchema"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/commands/dev.ts","../src/commands/generate.ts","../src/commands/init.ts","../src/config.ts","../src/paths.ts","../src/clientFromEnv.ts","../src/loadMigrations.ts","../src/commands/migrate.ts","../src/commands/migrateDev.ts","../src/commands/migrateStatus.ts","../src/commands/migrationCreate.ts","../src/commands/pull.ts","../src/commands/push.ts","../src/commands/schemaDdl.ts","../src/commands/schemaPrint.ts","../src/commands/validateSchema.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { createRequire } from \"node:module\";\nimport { Command } from \"commander\";\nimport { runDev } from \"./commands/dev.js\";\nimport { runGenerate } from \"./commands/generate.js\";\nimport { runInit } from \"./commands/init.js\";\nimport { runMigrate } from \"./commands/migrate.js\";\nimport { createMigrationFromSchema, runMigrateDiff } from \"./commands/migrateDev.js\";\nimport { runMigrateStatus } from \"./commands/migrateStatus.js\";\nimport { runMigrationCreate } from \"./commands/migrationCreate.js\";\nimport { runPull } from \"./commands/pull.js\";\nimport { runPush } from \"./commands/push.js\";\nimport { runSchemaDdl } from \"./commands/schemaDdl.js\";\nimport { runSchemaPrint } from \"./commands/schemaPrint.js\";\nimport { runValidateSchema } from \"./commands/validateSchema.js\";\nimport { loadConfig } from \"./config.js\";\n\n// Load ./.env (Node 20.12+) so NEO4J_* settings written by `cyphra dev` are picked up.\ntry {\n process.loadEnvFile?.(\".env\");\n} catch {\n // no .env: rely on the environment\n}\n\nconst { version } = createRequire(import.meta.url)(\"../package.json\") as { version: string };\n\nconst program = new Command();\nprogram\n .name(\"cyphra\")\n .description(\"Cyphra: typed ORM, migrations and tooling for Neo4j\")\n .version(version);\n\nprogram\n .command(\"init\")\n .description(\n \"Create cyphra.json, schema.cyphra, migrations/ and .env.example (existing files are kept)\",\n )\n .action(async () => {\n await runInit(process.cwd());\n });\n\nprogram\n .command(\"dev\")\n .description(\"Run a local Neo4j 5 in Docker for this project and write .env\")\n .option(\"--stop\", \"stop the container\")\n .option(\"--reset\", \"remove the container and its data volume\")\n .option(\"--port <port>\", \"host Bolt port (default 7687)\", (v) => Number(v))\n .option(\"--http-port <port>\", \"host HTTP/browser port (default 7474)\", (v) => Number(v))\n .option(\"--image <image>\", \"Docker image (default neo4j:5)\")\n .action(\n async (opts: {\n stop?: boolean;\n reset?: boolean;\n port?: number;\n httpPort?: number;\n image?: string;\n }) => {\n await runDev(process.cwd(), opts);\n },\n );\n\nconst migrate = program.command(\"migrate\").description(\"Migration commands\");\n\nmigrate\n .command(\"dev\")\n .description(\n \"Generate a migration from schema changes since the last one, then apply pending migrations\",\n )\n .option(\"-n, --name <name>\", \"migration name (default: schema)\")\n .option(\"--create-only\", \"write the migration without applying it\")\n .action(async (opts: { name?: string; createOnly?: boolean }) => {\n const cwd = process.cwd();\n const config = await loadConfig(cwd);\n await createMigrationFromSchema(cwd, config, opts.name);\n if (!opts.createOnly) await runMigrate(cwd, true);\n });\n\nmigrate\n .command(\"diff\")\n .description(\"Print the migration `migrate dev` would generate (no database, no files written)\")\n .action(async () => {\n await runMigrateDiff(await loadConfig(process.cwd()));\n });\n\nmigrate\n .command(\"deploy\")\n .description(\"Apply pending migrations\")\n .action(async () => {\n await runMigrate(process.cwd(), false);\n });\n\nmigrate\n .command(\"status\")\n .description(\"Show applied / pending / modified migrations and uncaptured schema changes\")\n .action(async () => {\n const cwd = process.cwd();\n const ok = await runMigrateStatus(cwd, await loadConfig(cwd));\n if (!ok) process.exitCode = 1;\n });\n\nprogram\n .command(\"migration:create\")\n .argument(\"<name>\", \"Migration file stem (e.g. add-index)\")\n .description(\"Create an empty .mjs migration to write by hand\")\n .action(async (name: string) => {\n const cwd = process.cwd();\n const config = await loadConfig(cwd);\n await runMigrationCreate(cwd, config.migrations, name, config.runtimeImport);\n });\n\nprogram\n .command(\"pull\")\n .description(\"Introspect the database and write schema.cyphra\")\n .option(\"--force\", \"overwrite an existing schema file\")\n .option(\"--print\", \"write the schema to stdout instead of the schema file\")\n .action(async (opts: { force?: boolean; print?: boolean }) => {\n const cwd = process.cwd();\n await runPull(cwd, await loadConfig(cwd), opts);\n });\n\nprogram\n .command(\"push\")\n .description(\"Apply schema constraints and indexes directly (prototyping; prefer migrate dev)\")\n .action(async () => {\n await runPush(process.cwd());\n });\n\nprogram\n .command(\"validate\")\n .description(\"Parse and validate schema.cyphra\")\n .action(async () => {\n const cwd = process.cwd();\n const config = await loadConfig(cwd);\n await runValidateSchema(cwd, config);\n });\n\nprogram\n .command(\"generate\")\n .description(\"Generate the typed client (cyphra.gen.ts) from the schema\")\n .action(async () => {\n const cwd = process.cwd();\n const config = await loadConfig(cwd);\n await runGenerate(cwd, config);\n });\n\nconst schemaCmd = program.command(\"schema\").description(\"Schema utilities\");\n\nschemaCmd\n .command(\"print\")\n .description(\"Pretty-print schema.cyphra to stdout (canonical formatting)\")\n .action(async () => {\n const cwd = process.cwd();\n const config = await loadConfig(cwd);\n await runSchemaPrint(config);\n });\n\nschemaCmd\n .command(\"ddl\")\n .description(\"Print constraint + range-index DDL for push (no database connection)\")\n .action(async () => {\n const cwd = process.cwd();\n const config = await loadConfig(cwd);\n await runSchemaDdl(config);\n });\n\nprogram.parseAsync(process.argv).catch((err: unknown) => {\n console.error(err instanceof Error ? err.message : err);\n process.exitCode = 1;\n});\n","import { spawnSync } from \"node:child_process\";\nimport { access, writeFile } from \"node:fs/promises\";\nimport path from \"node:path\";\n\nexport type DevOptions = {\n readonly stop?: boolean;\n readonly reset?: boolean;\n readonly port?: number;\n readonly httpPort?: number;\n readonly image?: string;\n};\n\n/** Local-only credentials: the container only listens on 127.0.0.1. */\nexport const DEV_USER = \"neo4j\";\nexport const DEV_PASSWORD = \"cyphra-dev-password\";\n\nfunction docker(args: string[], opts: { quiet?: boolean } = {}) {\n const r = spawnSync(\"docker\", args, { encoding: \"utf8\" });\n if (r.error) {\n throw new Error(\"Docker is required for `cyphra dev` (could not run the docker CLI).\");\n }\n if (r.status !== 0 && !opts.quiet) {\n throw new Error(`docker ${args[0]} failed: ${(r.stderr || r.stdout).trim()}`);\n }\n return r;\n}\n\nexport function devContainerName(cwd: string): string {\n const base = path\n .basename(cwd)\n .toLowerCase()\n .replace(/[^a-z0-9_.-]/g, \"-\")\n .replace(/^[^a-z0-9]+/, \"\");\n return `cyphra-dev-${base || \"project\"}`;\n}\n\nfunction state(name: string): \"missing\" | \"running\" | \"stopped\" {\n const r = docker([\"inspect\", \"-f\", \"{{.State.Running}}\", name], { quiet: true });\n if (r.status !== 0) return \"missing\";\n return r.stdout.trim() === \"true\" ? \"running\" : \"stopped\";\n}\n\nasync function waitReady(name: string, timeoutMs = 120_000): Promise<void> {\n const deadline = Date.now() + timeoutMs;\n while (Date.now() < deadline) {\n const r = docker(\n [\"exec\", name, \"cypher-shell\", \"-u\", DEV_USER, \"-p\", DEV_PASSWORD, \"RETURN 1\"],\n {\n quiet: true,\n },\n );\n if (r.status === 0) return;\n await new Promise((res) => setTimeout(res, 2000));\n }\n throw new Error(`Neo4j in ${name} did not become ready in time (see: docker logs ${name}).`);\n}\n\n/**\n * `cyphra dev`: run a local Neo4j 5 in Docker for this project (data persisted in a named volume),\n * wait until it accepts connections, and write `.env` if the project has none.\n */\nexport async function runDev(cwd: string, opts: DevOptions): Promise<void> {\n const name = devContainerName(cwd);\n const volume = `${name}-data`;\n\n if (opts.stop) {\n if (state(name) === \"running\") docker([\"stop\", name]);\n console.log(`Stopped ${name}.`);\n return;\n }\n if (opts.reset) {\n docker([\"rm\", \"-f\", name], { quiet: true });\n docker([\"volume\", \"rm\", volume], { quiet: true });\n console.log(`Removed ${name} and its data volume.`);\n return;\n }\n\n const port = opts.port ?? 7687;\n const httpPort = opts.httpPort ?? 7474;\n const s = state(name);\n if (s === \"missing\") {\n docker([\n \"run\",\n \"-d\",\n \"--name\",\n name,\n \"-p\",\n `127.0.0.1:${port}:7687`,\n \"-p\",\n `127.0.0.1:${httpPort}:7474`,\n \"-e\",\n `NEO4J_AUTH=${DEV_USER}/${DEV_PASSWORD}`,\n \"-v\",\n `${volume}:/data`,\n opts.image ?? \"neo4j:5\",\n ]);\n console.log(`Started ${name}; waiting for Neo4j…`);\n } else if (s === \"stopped\") {\n docker([\"start\", name]);\n console.log(`Restarted ${name}; waiting for Neo4j…`);\n }\n await waitReady(name);\n\n const portLine = docker([\"port\", name, \"7687/tcp\"]).stdout.trim().split(\"\\n\")[0] ?? \"\";\n const hostPort = portLine.split(\":\").pop() || String(port);\n const env = [\n `NEO4J_URI=bolt://127.0.0.1:${hostPort}`,\n `NEO4J_USER=${DEV_USER}`,\n `NEO4J_PASSWORD=${DEV_PASSWORD}`,\n \"\",\n ].join(\"\\n\");\n\n const envPath = path.join(cwd, \".env\");\n const hasEnv = await access(envPath).then(\n () => true,\n () => false,\n );\n if (!hasEnv) {\n await writeFile(\n envPath,\n `# Written by \\`cyphra dev\\` (local container ${name})\\n${env}`,\n \"utf8\",\n );\n console.log(\"Wrote .env\");\n }\n console.log(`Neo4j is ready (browser: http://127.0.0.1:${httpPort}).`);\n if (hasEnv) console.log(`Connection settings (add to your .env if needed):\\n${env}`);\n console.log(\"Stop with `cyphra dev --stop`; delete all data with `cyphra dev --reset`.\");\n}\n","import { readFile, writeFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { parseSchema, renderCyphraGenSource, validateSchema } from \"@cyphra/schema\";\nimport type { CyphraConfig } from \"../config.js\";\n\n/**\n * Emit `cyphra.gen.ts` (or configured path) from the schema file.\n *\n * @param cwd - Project root.\n * @param config - Loaded config with absolute schema and output paths.\n */\nexport async function runGenerate(cwd: string, config: CyphraConfig): Promise<void> {\n const source = await readFile(config.schema, \"utf8\");\n const doc = parseSchema(source);\n validateSchema(doc);\n const out = renderCyphraGenSource(doc, { runtimeImport: config.runtimeImport });\n await writeFile(config.generate, out, \"utf8\");\n console.log(`Wrote ${path.relative(cwd, config.generate)}`);\n}\n","import { mkdir, writeFile } from \"node:fs/promises\";\nimport path from \"node:path\";\n\nconst defaultSchema = `node Example {\n id String @id @default(cuid())\n}\n`;\n\nconst defaultEnvExample = `# NEO4J_URI=neo4j+s://xxxx.databases.neo4j.io\n# NEO4J_USER=neo4j\n# NEO4J_PASSWORD=secret\n# NEO4J_DATABASE=neo4j\n`;\n\nasync function writeIfMissing(file: string, content: string): Promise<boolean> {\n try {\n await writeFile(file, content, { encoding: \"utf8\", flag: \"wx\" });\n return true;\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === \"EEXIST\") return false;\n throw err;\n }\n}\n\n/**\n * Scaffold `cyphra.json`, `schema.cyphra`, `migrations/`, and `.env.example`.\n *\n * @param cwd - Project directory.\n */\nexport async function runInit(cwd: string): Promise<void> {\n const created: string[] = [];\n const skipped: string[] = [];\n const track = (name: string, ok: boolean) => (ok ? created : skipped).push(name);\n track(\n \"cyphra.json\",\n await writeIfMissing(\n path.join(cwd, \"cyphra.json\"),\n JSON.stringify(\n {\n schema: \"./schema.cyphra\",\n migrations: \"./migrations\",\n generate: \"./cyphra.gen.ts\",\n },\n null,\n 2,\n ) + \"\\n\",\n ),\n );\n track(\"schema.cyphra\", await writeIfMissing(path.join(cwd, \"schema.cyphra\"), defaultSchema));\n await mkdir(path.join(cwd, \"migrations\"), { recursive: true });\n await writeIfMissing(path.join(cwd, \"migrations\", \".gitkeep\"), \"\");\n track(\".env.example\", await writeIfMissing(path.join(cwd, \".env.example\"), defaultEnvExample));\n if (created.length) console.log(`Created ${created.join(\", \")}, migrations/`);\n if (skipped.length) console.log(`Kept existing ${skipped.join(\", \")}`);\n console.log(\"Next: `cyphra dev` (local Neo4j), `cyphra generate`, `cyphra migrate dev`.\");\n}\n","import { readFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { resolveUnderRoot } from \"./paths.js\";\n\nexport type CyphraConfig = {\n readonly schema: string;\n readonly migrations: string;\n /** Absolute path for `cyphra generate` output (default `./cyphra.gen.ts`). */\n readonly generate: string;\n /** Module the generated client imports from (default `\"cyphra\"`). */\n readonly runtimeImport: string;\n};\n\n/**\n * Load `cyphra.json` from the working directory.\n *\n * @param cwd - Current working directory (absolute).\n */\nexport async function loadConfig(cwd: string): Promise<CyphraConfig> {\n const configPath = path.join(cwd, \"cyphra.json\");\n const raw = await readFile(configPath, \"utf8\");\n const data = JSON.parse(raw) as unknown;\n if (!data || typeof data !== \"object\") {\n throw new Error(\"cyphra.json must be a JSON object\");\n }\n const schema = (data as Record<string, unknown>).schema;\n const migrations = (data as Record<string, unknown>).migrations;\n const generateRaw = (data as Record<string, unknown>).generate;\n if (typeof schema !== \"string\" || typeof migrations !== \"string\") {\n throw new Error('cyphra.json requires string fields \"schema\" and \"migrations\"');\n }\n const generatePath = typeof generateRaw === \"string\" ? generateRaw : \"./cyphra.gen.ts\";\n const runtimeImportRaw = (data as Record<string, unknown>).runtimeImport;\n if (runtimeImportRaw !== undefined && typeof runtimeImportRaw !== \"string\") {\n throw new Error('cyphra.json \"runtimeImport\" must be a string');\n }\n return {\n schema: resolveUnderRoot(cwd, schema),\n migrations: resolveUnderRoot(cwd, migrations),\n generate: resolveUnderRoot(cwd, generatePath),\n runtimeImport: runtimeImportRaw ?? \"cyphra\",\n };\n}\n","import path from \"node:path\";\n\n/**\n * Resolve `p` under `root` and throw if the result escapes `root` (path traversal guard).\n *\n * @param root - Project root directory (absolute).\n * @param p - Path segment or relative path from config.\n * @returns Absolute normalized path under `root`.\n */\nexport function resolveUnderRoot(root: string, p: string): string {\n const absRoot = path.resolve(root);\n const resolved = path.resolve(absRoot, p);\n const rel = path.relative(absRoot, resolved);\n if (rel.startsWith(\"..\") || path.isAbsolute(rel)) {\n throw new Error(`Path escapes project root: ${p}`);\n }\n return resolved;\n}\n","import { CyphraClient } from \"@cyphra/runtime\";\n\n/**\n * Build a {@link CyphraClient} from `NEO4J_URI`, `NEO4J_USER`, `NEO4J_PASSWORD`, optional `NEO4J_DATABASE`.\n *\n * @param debug - Forwarded to client options.\n */\nexport function clientFromEnv(debug = false): CyphraClient {\n const uri = process.env.NEO4J_URI;\n const user = process.env.NEO4J_USER;\n const password = process.env.NEO4J_PASSWORD;\n if (!uri || !user || !password) {\n throw new Error(\"Set NEO4J_URI, NEO4J_USER, and NEO4J_PASSWORD in the environment\");\n }\n return new CyphraClient({\n uri,\n user,\n password,\n database: process.env.NEO4J_DATABASE,\n debug,\n });\n}\n","import { createHash } from \"node:crypto\";\nimport { readdir, readFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport type { LoadedMigration, MigrationDefinition } from \"@cyphra/migrator\";\n\nfunction assertDirUnderRoot(dir: string, root: string): void {\n const absRoot = path.resolve(root);\n const absDir = path.resolve(dir);\n const rel = path.relative(absRoot, absDir);\n if (rel.startsWith(\"..\") || path.isAbsolute(rel)) {\n throw new Error(\"Migrations directory must be inside the project root\");\n }\n}\n\n/**\n * Load sorted `.js` / `.mjs` migration modules from a directory.\n *\n * @param migrationsDir - Absolute migrations directory (from config).\n * @param root - Project root for validation.\n */\nexport async function loadMigrationsFromDir(\n migrationsDir: string,\n root: string,\n): Promise<LoadedMigration[]> {\n assertDirUnderRoot(migrationsDir, root);\n let entries: string[];\n try {\n entries = await readdir(migrationsDir);\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === \"ENOENT\") return [];\n throw err;\n }\n const files = entries.filter((f) => f.endsWith(\".js\") || f.endsWith(\".mjs\")).sort();\n const out: LoadedMigration[] = [];\n for (const f of files) {\n const full = path.join(migrationsDir, f);\n const src = await readFile(full, \"utf8\");\n const checksum = createHash(\"sha256\").update(src).digest(\"hex\");\n const href = pathToFileURL(full).href;\n const mod = (await import(href)) as { default?: MigrationDefinition };\n const def = mod.default;\n if (!def?.name || typeof def.up !== \"function\") {\n throw new Error(`Migration ${f} must export default defineMigration({ name, up })`);\n }\n out.push({ name: def.name, checksum, definition: def });\n }\n return out;\n}\n","import { loadConfig } from \"../config.js\";\nimport { clientFromEnv } from \"../clientFromEnv.js\";\nimport { loadMigrationsFromDir } from \"../loadMigrations.js\";\nimport { runPendingMigrations } from \"@cyphra/migrator\";\n\n/**\n * Apply pending migrations (deploy / dev — same behavior; dev may pass verbose later).\n *\n * @param cwd - Project root.\n * @param verbose - Log applied migration names.\n */\nexport async function runMigrate(cwd: string, verbose: boolean): Promise<void> {\n const config = await loadConfig(cwd);\n const client = clientFromEnv(verbose);\n try {\n const loaded = await loadMigrationsFromDir(config.migrations, cwd);\n const applied = await runPendingMigrations(client, loaded);\n if (verbose || applied.length > 0) {\n console.log(applied.length ? `Applied: ${applied.join(\", \")}` : \"No pending migrations\");\n }\n } finally {\n await client.close();\n }\n}\n","import { mkdir, readFile, writeFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport {\n EMPTY_SCHEMA_MODEL,\n diffSchemaModels,\n isEmptyPlan,\n renderMigrationSource,\n type MigrationPlan,\n} from \"@cyphra/migrator\";\nimport { parseSchema, resolveSchema, type SchemaModel } from \"@cyphra/schema\";\nimport type { CyphraConfig } from \"../config.js\";\n\n/** File (inside the migrations directory) holding the schema as of the latest migration. */\nexport const SNAPSHOT_FILE = \"schema.snapshot.json\";\n\nexport async function readSnapshot(config: CyphraConfig): Promise<SchemaModel | null> {\n try {\n const raw = await readFile(path.join(config.migrations, SNAPSHOT_FILE), \"utf8\");\n return JSON.parse(raw) as SchemaModel;\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === \"ENOENT\") return null;\n throw err;\n }\n}\n\nexport async function currentModel(config: CyphraConfig): Promise<SchemaModel> {\n return resolveSchema(parseSchema(await readFile(config.schema, \"utf8\")));\n}\n\n/** Plan the migration between the snapshot and the current schema. */\nexport async function planMigration(\n config: CyphraConfig,\n): Promise<{ plan: MigrationPlan; next: SchemaModel; first: boolean }> {\n const prev = await readSnapshot(config);\n const next = await currentModel(config);\n return { plan: diffSchemaModels(prev ?? EMPTY_SCHEMA_MODEL, next), next, first: prev === null };\n}\n\nfunction timestamp(d = new Date()): string {\n const p = (n: number) => String(n).padStart(2, \"0\");\n return `${d.getUTCFullYear()}${p(d.getUTCMonth() + 1)}${p(d.getUTCDate())}${p(d.getUTCHours())}${p(d.getUTCMinutes())}${p(d.getUTCSeconds())}`;\n}\n\nfunction printWarnings(plan: MigrationPlan): void {\n for (const w of plan.warnings) console.warn(`warning: ${w}`);\n const destructive = plan.steps.filter((s) => s.kind === \"destructive\").length;\n if (destructive) {\n console.warn(\n `warning: ${destructive} destructive step(s) were generated commented-out; uncomment them to apply.`,\n );\n }\n}\n\n/** `cyphra migrate diff`: print the migration that `migrate dev` would generate. */\nexport async function runMigrateDiff(config: CyphraConfig): Promise<void> {\n const { plan } = await planMigration(config);\n if (isEmptyPlan(plan)) {\n console.log(\"No schema changes since the last migration.\");\n return;\n }\n console.log(\n renderMigrationSource(plan, { name: \"preview\", runtimeImport: config.runtimeImport }),\n );\n printWarnings(plan);\n}\n\n/**\n * `cyphra migrate dev`: write a migration for schema changes since the last snapshot (if any).\n *\n * @returns Path of the created migration, or `null` when the schema is unchanged.\n */\nexport async function createMigrationFromSchema(\n cwd: string,\n config: CyphraConfig,\n name: string | undefined,\n): Promise<string | null> {\n const { plan, next } = await planMigration(config);\n if (isEmptyPlan(plan)) {\n console.log(\"No schema changes since the last migration.\");\n return null;\n }\n const safe = (name ?? \"schema\").replace(/[^a-zA-Z0-9_-]/g, \"_\") || \"schema\";\n const stem = `${timestamp()}_${safe}`;\n await mkdir(config.migrations, { recursive: true });\n const file = path.join(config.migrations, `${stem}.mjs`);\n await writeFile(\n file,\n renderMigrationSource(plan, { name: stem, runtimeImport: config.runtimeImport }),\n { encoding: \"utf8\", flag: \"wx\" },\n );\n await writeFile(\n path.join(config.migrations, SNAPSHOT_FILE),\n JSON.stringify(next, null, 2) + \"\\n\",\n \"utf8\",\n );\n console.log(`Created ${path.relative(cwd, file)} (${plan.steps.length} step(s))`);\n printWarnings(plan);\n return file;\n}\n","import { isEmptyPlan, listAppliedMigrations } from \"@cyphra/migrator\";\nimport type { CyphraConfig } from \"../config.js\";\nimport { clientFromEnv } from \"../clientFromEnv.js\";\nimport { loadMigrationsFromDir } from \"../loadMigrations.js\";\nimport { planMigration } from \"./migrateDev.js\";\n\n/**\n * `cyphra migrate status`: pending / applied migrations, edited-after-apply files, and schema changes\n * not yet captured in a migration. Exits non-zero when something needs attention.\n */\nexport async function runMigrateStatus(cwd: string, config: CyphraConfig): Promise<boolean> {\n let ok = true;\n const { plan } = await planMigration(config);\n if (!isEmptyPlan(plan)) {\n ok = false;\n console.log(\n `Schema has ${plan.steps.length} change(s) not captured in a migration: run \\`cyphra migrate dev\\`.`,\n );\n }\n\n const files = await loadMigrationsFromDir(config.migrations, cwd);\n const client = clientFromEnv(false);\n try {\n const applied = await client.withSession((s) => listAppliedMigrations(s));\n const appliedByName = new Map(applied.map((a) => [a.name, a]));\n const fileNames = new Set(files.map((f) => f.name));\n\n for (const f of files) {\n const a = appliedByName.get(f.name);\n if (!a) {\n ok = false;\n console.log(`pending ${f.name}`);\n } else if (a.checksum && a.checksum !== f.checksum) {\n ok = false;\n console.log(`modified ${f.name} (changed after it was applied)`);\n } else {\n console.log(`applied ${f.name}`);\n }\n }\n for (const a of applied) {\n if (!fileNames.has(a.name)) {\n ok = false;\n console.log(`missing ${a.name} (applied, but no file in ${config.migrations})`);\n }\n }\n if (files.length === 0 && applied.length === 0) console.log(\"No migrations yet.\");\n } finally {\n await client.close();\n }\n return ok;\n}\n","import { mkdir, writeFile } from \"node:fs/promises\";\nimport path from \"node:path\";\n\nfunction migrationFileBody(name: string, runtimeImport: string): string {\n return `import { defineMigration } from ${JSON.stringify(runtimeImport)};\n\nexport default defineMigration({\n name: ${JSON.stringify(name)},\n async up({ db }) {\n await db.run\\`RETURN 1 AS ok\\`;\n },\n});\n`;\n}\n\n/**\n * Create a new `.mjs` migration stub under `migrations/`.\n *\n * @param cwd - Project root.\n * @param migrationsDir - Absolute migrations directory.\n * @param stem - File stem used for file name and migration `name`.\n */\nexport async function runMigrationCreate(\n cwd: string,\n migrationsDir: string,\n stem: string,\n runtimeImport = \"cyphra\",\n): Promise<void> {\n const safe = stem.replace(/[^a-zA-Z0-9_-]/g, \"_\");\n const fileName = `${safe}.mjs`;\n const full = path.join(migrationsDir, fileName);\n await mkdir(migrationsDir, { recursive: true });\n await writeFile(full, migrationFileBody(safe, runtimeImport), { encoding: \"utf8\", flag: \"wx\" });\n console.log(`Created ${path.relative(cwd, full)}`);\n}\n","import { access, writeFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { introspectDatabase, schemaFromIntrospection } from \"@cyphra/migrator\";\nimport { parseSchema, printSchemaDocument, resolveSchema } from \"@cyphra/schema\";\nimport type { CyphraConfig } from \"../config.js\";\nimport { clientFromEnv } from \"../clientFromEnv.js\";\n\n/**\n * `cyphra pull`: introspect the database (read-only) and write a `.cyphra` schema.\n */\nexport async function runPull(\n cwd: string,\n config: CyphraConfig,\n opts: { force?: boolean; print?: boolean },\n): Promise<void> {\n const client = clientFromEnv(false);\n let source: string;\n let warnings: string[];\n try {\n const result = schemaFromIntrospection(await introspectDatabase(client));\n warnings = result.warnings;\n const header = [\n \"// Generated by `cyphra pull`. Review it: relation names are guessed from relationship types,\",\n \"// every relation is to-many, and required-ness reflects the data at the time of the pull.\",\n \"\",\n \"\",\n ].join(\"\\n\");\n source = header + printSchemaDocument(result.doc);\n } finally {\n await client.close();\n }\n // The output must round-trip through our own parser and resolver.\n resolveSchema(parseSchema(source));\n\n if (opts.print) {\n process.stdout.write(source);\n } else {\n const exists = await access(config.schema).then(\n () => true,\n () => false,\n );\n if (exists && !opts.force) {\n throw new Error(\n `${path.relative(cwd, config.schema)} already exists: pass --force to overwrite or --print to write to stdout.`,\n );\n }\n await writeFile(config.schema, source, \"utf8\");\n console.log(`Wrote ${path.relative(cwd, config.schema)}`);\n }\n for (const w of warnings) console.warn(`warning: ${w}`);\n}\n","import { readFile } from \"node:fs/promises\";\nimport {\n applyConstraintStatements,\n constraintStatementsFromSchema,\n indexStatementsFromSchema,\n} from \"@cyphra/migrator\";\nimport { parseSchema } from \"@cyphra/schema\";\nimport { loadConfig } from \"../config.js\";\nimport { clientFromEnv } from \"../clientFromEnv.js\";\n\n/**\n * Parse `schema.cyphra` and apply generated constraints.\n *\n * @param cwd - Project root.\n */\nexport async function runPush(cwd: string): Promise<void> {\n const config = await loadConfig(cwd);\n const source = await readFile(config.schema, \"utf8\");\n const doc = parseSchema(source);\n const constraints = constraintStatementsFromSchema(doc);\n const indexes = indexStatementsFromSchema(doc);\n const statements = [...constraints, ...indexes];\n const client = clientFromEnv(false);\n try {\n await applyConstraintStatements(client, statements);\n console.log(\n `Applied ${constraints.length} constraint statement(s) and ${indexes.length} range index statement(s)`,\n );\n } finally {\n await client.close();\n }\n}\n","import { readFile } from \"node:fs/promises\";\nimport { constraintStatementsFromSchema, indexStatementsFromSchema } from \"@cyphra/migrator\";\nimport { parseSchema } from \"@cyphra/schema\";\nimport type { CyphraConfig } from \"../config.js\";\n\n/**\n * Print `CREATE CONSTRAINT` / `CREATE RANGE INDEX` lines for the schema (same order as `cyphra push`).\n * Does not connect to Neo4j.\n *\n * @param config - Config with absolute schema path.\n */\nexport async function runSchemaDdl(config: CyphraConfig): Promise<void> {\n const source = await readFile(config.schema, \"utf8\");\n const doc = parseSchema(source);\n for (const stmt of constraintStatementsFromSchema(doc)) {\n console.log(stmt);\n }\n for (const stmt of indexStatementsFromSchema(doc)) {\n console.log(stmt);\n }\n}\n","import { readFile } from \"node:fs/promises\";\nimport { parseSchema, printSchemaDocument, validateSchema } from \"@cyphra/schema\";\nimport type { CyphraConfig } from \"../config.js\";\n\n/**\n * Print a canonical `.cyphra` rendering of the schema to stdout.\n *\n * @param config - Config with absolute schema path.\n */\nexport async function runSchemaPrint(config: CyphraConfig): Promise<void> {\n const raw = await readFile(config.schema, \"utf8\");\n const doc = parseSchema(raw);\n validateSchema(doc);\n process.stdout.write(printSchemaDocument(doc));\n}\n","import { readFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { parseSchema, resolveSchema, validateSchema } from \"@cyphra/schema\";\nimport type { CyphraConfig } from \"../config.js\";\n\n/**\n * Parse and semantically validate `schema.cyphra`.\n *\n * @param cwd - Project root (for relative log paths).\n * @param config - Config with absolute schema path.\n */\nexport async function runValidateSchema(cwd: string, config: CyphraConfig): Promise<void> {\n const raw = await readFile(config.schema, \"utf8\");\n const doc = parseSchema(raw);\n validateSchema(doc);\n resolveSchema(doc);\n const rel = path.relative(cwd, config.schema);\n console.log(`OK — ${rel} (${doc.declarations.length} declaration(s))`);\n}\n"],"mappings":";;;AACA,SAAS,qBAAqB;AAC9B,SAAS,eAAe;;;ACFxB,SAAS,iBAAiB;AAC1B,SAAS,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GAAG;AACnC,QAAM,aAAa,MAAM;AAC3B,CAAC;AAEH,QAAQ,WAAW,QAAQ,IAAI,EAAE,MAAM,CAAC,QAAiB;AACvD,UAAQ,MAAM,eAAe,QAAQ,IAAI,UAAU,GAAG;AACtD,UAAQ,WAAW;AACrB,CAAC;","names":["writeFile","path","writeFile","path","readFile","path","path","path","readFile","readFile","path","mkdir","readFile","writeFile","path","parseSchema","isEmptyPlan","isEmptyPlan","mkdir","writeFile","path","access","writeFile","path","parseSchema","resolveSchema","resolveSchema","parseSchema","access","path","writeFile","readFile","parseSchema","readFile","parseSchema","readFile","constraintStatementsFromSchema","indexStatementsFromSchema","parseSchema","readFile","parseSchema","printSchemaDocument","validateSchema","readFile","path","parseSchema","resolveSchema","validateSchema"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cyphra/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Cyphra CLI: init, migrate, push",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
@@ -15,15 +15,25 @@
|
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"commander": "^12.1.0",
|
|
18
|
-
"@cyphra/
|
|
19
|
-
"@cyphra/schema": "0.
|
|
20
|
-
"@cyphra/
|
|
18
|
+
"@cyphra/migrator": "0.2.0",
|
|
19
|
+
"@cyphra/schema": "0.2.0",
|
|
20
|
+
"@cyphra/runtime": "0.2.0"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"@types/node": "^22.
|
|
24
|
-
"tsup": "^8.
|
|
25
|
-
"typescript": "^5.
|
|
26
|
-
"vitest": "^
|
|
23
|
+
"@types/node": "^22.20.5",
|
|
24
|
+
"tsup": "^8.5.1",
|
|
25
|
+
"typescript": "^5.9.3",
|
|
26
|
+
"vitest": "^4.1.12"
|
|
27
|
+
},
|
|
28
|
+
"license": "MIT",
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "git+https://github.com/Cyphra-dev/cyphra.git",
|
|
32
|
+
"directory": "packages/cli"
|
|
33
|
+
},
|
|
34
|
+
"homepage": "https://cyphra-doc.vercel.app",
|
|
35
|
+
"bugs": {
|
|
36
|
+
"url": "https://github.com/Cyphra-dev/cyphra/issues"
|
|
27
37
|
},
|
|
28
38
|
"scripts": {
|
|
29
39
|
"build": "tsup",
|