grafeo-ogm 1.9.1 → 1.10.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/CHANGELOG.md +21 -0
- package/README.md +23 -0
- package/dist/cjs/cli/commands/init.d.ts +3 -0
- package/dist/cjs/cli/commands/init.d.ts.map +1 -0
- package/dist/cjs/cli/commands/init.js +273 -0
- package/dist/cjs/cli/commands/init.js.map +1 -0
- package/dist/cjs/cli/detect.d.ts +18 -0
- package/dist/cjs/cli/detect.d.ts.map +1 -0
- package/dist/cjs/cli/detect.js +142 -0
- package/dist/cjs/cli/detect.js.map +1 -0
- package/dist/cjs/cli/index.d.ts.map +1 -1
- package/dist/cjs/cli/index.js +35 -0
- package/dist/cjs/cli/index.js.map +1 -1
- package/dist/cjs/cli/types.d.ts +6 -0
- package/dist/cjs/cli/types.d.ts.map +1 -1
- package/dist/esm/cli/commands/init.d.ts +3 -0
- package/dist/esm/cli/commands/init.d.ts.map +1 -0
- package/dist/esm/cli/commands/init.js +237 -0
- package/dist/esm/cli/commands/init.js.map +1 -0
- package/dist/esm/cli/detect.d.ts +18 -0
- package/dist/esm/cli/detect.d.ts.map +1 -0
- package/dist/esm/cli/detect.js +106 -0
- package/dist/esm/cli/detect.js.map +1 -0
- package/dist/esm/cli/index.d.ts.map +1 -1
- package/dist/esm/cli/index.js +35 -0
- package/dist/esm/cli/index.js.map +1 -1
- package/dist/esm/cli/types.d.ts +6 -0
- package/dist/esm/cli/types.d.ts.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.10.0 (2026-06-13) — 🚀 `grafeo init`
|
|
4
|
+
|
|
5
|
+
> **The fastest way into grafeo.** `grafeo init` sets a project up in one step — and for the *existing* grafeo user adopting the CLI, it auto-wires itself: it finds your schema and your generated types and writes a ready `grafeo.config.ts` pointing at them. Greenfield? It scaffolds a starter schema (the Neo4j movie graph) and config. Either way you get an npm `generate` script. Interactive by default, fully non-interactive (`--yes`) for CI, and non-destructive throughout.
|
|
6
|
+
|
|
7
|
+
### ✨ `grafeo init` — scaffold, or auto-detect an existing project
|
|
8
|
+
|
|
9
|
+
- **Autodetection.** In a project that already uses grafeo, `init` locates the SDL schema (by its `@node`/`@relationship` directives — a bare GraphQL file is *not* mistaken for it) and a previously generated types file (by the generator's header line), and pre-fills `grafeo.config.ts` with those paths. Multiple schema candidates → it asks which.
|
|
10
|
+
- **Greenfield scaffold.** With nothing to detect (or `--fresh`), it writes a starter `schema.graphql` — the classic Neo4j movie example (`Movie`/`Person`, `ACTED_IN`/`DIRECTED`) — and a config.
|
|
11
|
+
- **npm script.** Adds `"generate": "grafeo generate"` to `package.json` (an existing `generate` script is preserved, never clobbered).
|
|
12
|
+
- **Optional seed.** `--seed` scaffolds an upsert-based `seed.ts` stub.
|
|
13
|
+
- **Non-destructive.** Never overwrites an existing config/schema/seed without `--force` (or an interactive confirmation); re-running `init` is safe.
|
|
14
|
+
- **No secrets, no new deps.** Connection settings reference `NEO4J_*` env vars (never prompted); prompts use `node:readline/promises`. The runtime footprint is unchanged.
|
|
15
|
+
|
|
16
|
+
Flags: `--schema`, `--out`, `--seed`, `--fresh`, `--yes`, `--force`. The README quickstart now leads with `npx grafeo init`.
|
|
17
|
+
|
|
18
|
+
### Tests
|
|
19
|
+
|
|
20
|
+
New `detect` + `init` coverage (14 cases): autodetection (single/multiple/none, directive-gated, marker-anchored), greenfield scaffold, `--fresh`, non-destructive config/seed writes, npm-script add/preserve, non-interactive `--yes`, no-secret-prompt, and a regression test that a quote-bearing path is safely escaped into the config (no injection). Full suite green; lint, format, type-check clean.
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
3
24
|
## 1.9.1 (2026-06-13) — 🩹 `grafeo generate` formatting DX
|
|
4
25
|
|
|
5
26
|
> **A first-run papercut from the 1.9.0 CLI.** Prettier is a *dev* dependency (kept out of the runtime footprint on purpose), so a consumer who runs `grafeo generate` without prettier installed got a terse `Prettier formatting failed; output written without formatting.` — accurate, but unhelpful. The output was always valid TypeScript; only the message was poor. `1.9.1` makes that path friendly and honest.
|
package/README.md
CHANGED
|
@@ -128,6 +128,8 @@ yarn add grafeo-ogm neo4j-driver graphql
|
|
|
128
128
|
|
|
129
129
|
### 1. Define your schema
|
|
130
130
|
|
|
131
|
+
> **Fastest start:** `npx grafeo init` scaffolds a starter `schema.graphql` + `grafeo.config.ts` for you — and auto-detects an existing setup. See [CLI → `grafeo init`](#cli). Prefer to do it by hand? Define a `schema.graphql`:
|
|
132
|
+
|
|
131
133
|
```graphql
|
|
132
134
|
# schema.graphql
|
|
133
135
|
type Book @node
|
|
@@ -228,6 +230,7 @@ grafeo-ogm ships a `grafeo` binary (installed with the package — no global ins
|
|
|
228
230
|
|
|
229
231
|
| Command | Purpose |
|
|
230
232
|
|---|---|
|
|
233
|
+
| `grafeo init` | Scaffold a project — or auto-detect an existing one — wiring config, schema, and an npm script |
|
|
231
234
|
| `grafeo generate` | Generate TypeScript types from your SDL — one-shot, `--watch`, or `--verify` CI gate |
|
|
232
235
|
| `grafeo db push` | Diff SDL-declared constraints/indexes against the live database and apply them |
|
|
233
236
|
| `grafeo db seed` | Run your seed script with a constructed, connected OGM |
|
|
@@ -262,6 +265,26 @@ export default defineConfig({
|
|
|
262
265
|
|
|
263
266
|
> **Config and seed files run as trusted code.** `grafeo.config.ts` and your seed script are executed in-process (via [jiti](https://github.com/unjs/jiti)) with your database credentials — the same trust model as Prisma/Drizzle. Only run `grafeo` in a directory whose config and seed files you control.
|
|
264
267
|
|
|
268
|
+
### `grafeo init`
|
|
269
|
+
|
|
270
|
+
Sets up a project in one step. In an **existing** grafeo project it auto-detects your schema (by its `@node`/`@relationship` directives) and a previously generated types file (by the generator's header marker), and writes a `grafeo.config.ts` wired to them. With **nothing to detect** (or `--fresh`), it scaffolds a starter `schema.graphql` — the Neo4j movie example — plus the config. Either way it adds a `"generate": "grafeo generate"` npm script.
|
|
271
|
+
|
|
272
|
+
```bash
|
|
273
|
+
npx grafeo init # interactive: detect or scaffold, confirm the paths
|
|
274
|
+
npx grafeo init --yes # non-interactive: accept detected values / defaults (CI)
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
| Flag | Description |
|
|
278
|
+
|---|---|
|
|
279
|
+
| `--schema <path>` | schema path (skip detection/prompt) |
|
|
280
|
+
| `--out <path>` | generated-types output path |
|
|
281
|
+
| `--seed` | also scaffold a `seed.ts` upsert stub |
|
|
282
|
+
| `--fresh` | ignore a detected setup and scaffold a new project |
|
|
283
|
+
| `--yes` | non-interactive: detected values / defaults, no prompts |
|
|
284
|
+
| `--force` | overwrite an existing `grafeo.config.ts` / `seed.ts` |
|
|
285
|
+
|
|
286
|
+
`init` is **non-destructive** — it never overwrites your config, schema, or seed without `--force` (or an interactive confirmation), and connection settings reference `NEO4J_*` env vars (it never prompts for a password).
|
|
287
|
+
|
|
265
288
|
### `grafeo generate`
|
|
266
289
|
|
|
267
290
|
Compiles your SDL to TypeScript types (wraps `generateTypes()` — see [Type Generation](#type-generation) for the programmatic API and the full option list).
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/init.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AA6JtC,wBAAsB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,CA8GxE"}
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.runInit = runInit;
|
|
37
|
+
const fs = __importStar(require("node:fs"));
|
|
38
|
+
const path = __importStar(require("node:path"));
|
|
39
|
+
const node_util_1 = require("node:util");
|
|
40
|
+
const detect_1 = require("../detect");
|
|
41
|
+
const errors_1 = require("../errors");
|
|
42
|
+
function parseInitFlags(argv) {
|
|
43
|
+
try {
|
|
44
|
+
const { values } = (0, node_util_1.parseArgs)({
|
|
45
|
+
args: argv,
|
|
46
|
+
options: {
|
|
47
|
+
schema: { type: 'string' },
|
|
48
|
+
out: { type: 'string' },
|
|
49
|
+
seed: { type: 'boolean' },
|
|
50
|
+
fresh: { type: 'boolean' },
|
|
51
|
+
yes: { type: 'boolean' },
|
|
52
|
+
force: { type: 'boolean' },
|
|
53
|
+
debug: { type: 'boolean' },
|
|
54
|
+
},
|
|
55
|
+
strict: true,
|
|
56
|
+
allowPositionals: false,
|
|
57
|
+
});
|
|
58
|
+
return values;
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
62
|
+
throw new errors_1.CliError(`init: ${message}`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
// The classic Neo4j movie graph, expressed in grafeo SDL — recognizable to
|
|
66
|
+
// Neo4j users and it exercises relationship arity/direction both ways.
|
|
67
|
+
const MOVIE_SCHEMA = `# grafeo schema — the Neo4j movie example.
|
|
68
|
+
# Run \`npx grafeo generate\` (or \`npm run generate\`) to emit typed models.
|
|
69
|
+
|
|
70
|
+
type Movie @node {
|
|
71
|
+
title: String! @unique
|
|
72
|
+
released: Int
|
|
73
|
+
tagline: String
|
|
74
|
+
actors: [Person!]! @relationship(type: "ACTED_IN", direction: IN)
|
|
75
|
+
directors: [Person!]! @relationship(type: "DIRECTED", direction: IN)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
type Person @node {
|
|
79
|
+
name: String! @id @unique
|
|
80
|
+
born: Int
|
|
81
|
+
actedIn: [Movie!]! @relationship(type: "ACTED_IN", direction: OUT)
|
|
82
|
+
directed: [Movie!]! @relationship(type: "DIRECTED", direction: OUT)
|
|
83
|
+
}
|
|
84
|
+
`;
|
|
85
|
+
const SEED_STUB = `import type { OGM } from 'grafeo-ogm';
|
|
86
|
+
|
|
87
|
+
// Prefer upsert over create so repeated seeds converge instead of duplicating.
|
|
88
|
+
export default async function seed(ogm: OGM) {
|
|
89
|
+
const Movie = ogm.model('Movie');
|
|
90
|
+
await Movie.upsert({
|
|
91
|
+
where: { title: 'The Matrix' },
|
|
92
|
+
create: { title: 'The Matrix', released: 1999 },
|
|
93
|
+
update: { released: 1999 },
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
`;
|
|
97
|
+
function renderConfig(schemaPath, outPath, includeSeed) {
|
|
98
|
+
// JSON.stringify, NOT string-templating: the paths come from --schema/--out
|
|
99
|
+
// /prompts and this file is later EXECUTED by jiti, so a raw `'${path}'`
|
|
100
|
+
// would let a quote in the path break out and inject code (and an innocent
|
|
101
|
+
// apostrophe would produce a broken config). JSON.stringify emits a fully
|
|
102
|
+
// escaped, valid string literal.
|
|
103
|
+
const seedLine = includeSeed ? `\n seed: './seed.ts',` : '';
|
|
104
|
+
return `import { defineConfig } from 'grafeo-ogm';
|
|
105
|
+
|
|
106
|
+
export default defineConfig({
|
|
107
|
+
schema: ${JSON.stringify(rel(schemaPath))},
|
|
108
|
+
out: ${JSON.stringify(rel(outPath))},
|
|
109
|
+
database: {
|
|
110
|
+
uri: process.env.NEO4J_URI,
|
|
111
|
+
username: process.env.NEO4J_USERNAME,
|
|
112
|
+
// Never commit a password — set NEO4J_PASSWORD in your environment.
|
|
113
|
+
password: process.env.NEO4J_PASSWORD,
|
|
114
|
+
},${seedLine}
|
|
115
|
+
});
|
|
116
|
+
`;
|
|
117
|
+
}
|
|
118
|
+
/** Normalize a path to a `./`-prefixed relative form for the config file. */
|
|
119
|
+
function rel(p) {
|
|
120
|
+
const normalized = p.replace(/\\/g, '/');
|
|
121
|
+
return normalized.startsWith('.') ? normalized : `./${normalized}`;
|
|
122
|
+
}
|
|
123
|
+
function writeFileEnsuringDir(absPath, content) {
|
|
124
|
+
fs.mkdirSync(path.dirname(absPath), { recursive: true });
|
|
125
|
+
fs.writeFileSync(absPath, content, 'utf-8');
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Add `"generate": "grafeo generate"` to package.json scripts. Non-destructive:
|
|
129
|
+
* an existing `generate` script is preserved. Returns what happened so the
|
|
130
|
+
* summary can report it.
|
|
131
|
+
*/
|
|
132
|
+
function wireGenerateScript(cwd) {
|
|
133
|
+
const pkgPath = path.join(cwd, 'package.json');
|
|
134
|
+
if (!fs.existsSync(pkgPath))
|
|
135
|
+
return 'none';
|
|
136
|
+
// Strip a UTF-8 BOM (common on Windows-edited files) so parse doesn't fail.
|
|
137
|
+
const raw = fs.readFileSync(pkgPath, 'utf-8').replace(/^\uFEFF/, '');
|
|
138
|
+
let pkg;
|
|
139
|
+
try {
|
|
140
|
+
pkg = JSON.parse(raw);
|
|
141
|
+
}
|
|
142
|
+
catch {
|
|
143
|
+
return 'none';
|
|
144
|
+
}
|
|
145
|
+
// Only treat `scripts` as a map when it's actually an object — otherwise a
|
|
146
|
+
// malformed value would be spread into garbage.
|
|
147
|
+
const scripts = typeof pkg.scripts === 'object' && pkg.scripts !== null
|
|
148
|
+
? pkg.scripts
|
|
149
|
+
: {};
|
|
150
|
+
if (scripts.generate)
|
|
151
|
+
return 'kept';
|
|
152
|
+
pkg.scripts = {
|
|
153
|
+
...scripts,
|
|
154
|
+
generate: 'grafeo generate',
|
|
155
|
+
};
|
|
156
|
+
const indent = /^\t/m.test(raw) ? '\t' : 2;
|
|
157
|
+
fs.writeFileSync(pkgPath, `${JSON.stringify(pkg, null, indent)}\n`, 'utf-8');
|
|
158
|
+
return 'added';
|
|
159
|
+
}
|
|
160
|
+
/** Pick the schema among detected candidates (prompt only when ambiguous). */
|
|
161
|
+
async function chooseSchema(candidates, io, canPrompt) {
|
|
162
|
+
if (candidates.length === 1)
|
|
163
|
+
return candidates[0];
|
|
164
|
+
if (canPrompt && io.prompt) {
|
|
165
|
+
io.out('Multiple grafeo schemas found:');
|
|
166
|
+
candidates.forEach((c, i) => io.out(` ${i + 1}) ${c}`));
|
|
167
|
+
const answer = await io.prompt('Which is your schema? (number)', '1');
|
|
168
|
+
const idx = Number.parseInt(answer, 10) - 1;
|
|
169
|
+
if (Number.isInteger(idx) && idx >= 0 && idx < candidates.length)
|
|
170
|
+
return candidates[idx];
|
|
171
|
+
}
|
|
172
|
+
return candidates[0];
|
|
173
|
+
}
|
|
174
|
+
async function runInit(argv, io) {
|
|
175
|
+
const flags = parseInitFlags(argv);
|
|
176
|
+
const yes = flags.yes === true;
|
|
177
|
+
const force = flags.force === true;
|
|
178
|
+
const canPrompt = io.interactive === true && !yes;
|
|
179
|
+
const detection = (0, detect_1.detectProject)(io.cwd, io.env);
|
|
180
|
+
const hasDetected = detection.schemaCandidates.length > 0 || detection.generatedTypes != null;
|
|
181
|
+
// Detected setup vs fresh start.
|
|
182
|
+
let fresh = flags.fresh === true;
|
|
183
|
+
if (hasDetected && !fresh && canPrompt && io.confirm) {
|
|
184
|
+
const detail = [
|
|
185
|
+
detection.schemaCandidates[0]
|
|
186
|
+
? `schema: ${detection.schemaCandidates[0]}`
|
|
187
|
+
: null,
|
|
188
|
+
detection.generatedTypes ? `types: ${detection.generatedTypes}` : null,
|
|
189
|
+
]
|
|
190
|
+
.filter(Boolean)
|
|
191
|
+
.join(', ');
|
|
192
|
+
const useDetected = await io.confirm(`Existing grafeo setup detected (${detail}) — wire the config to it?`);
|
|
193
|
+
fresh = !useDetected;
|
|
194
|
+
}
|
|
195
|
+
const useDetected = hasDetected && !fresh;
|
|
196
|
+
// Resolve schema path: flag > detected > prompt/default.
|
|
197
|
+
let schemaPath = flags.schema;
|
|
198
|
+
if (!schemaPath && useDetected)
|
|
199
|
+
schemaPath = await chooseSchema(detection.schemaCandidates, io, canPrompt);
|
|
200
|
+
if (!schemaPath)
|
|
201
|
+
schemaPath =
|
|
202
|
+
canPrompt && io.prompt
|
|
203
|
+
? await io.prompt('Schema path?', 'schema.graphql')
|
|
204
|
+
: 'schema.graphql';
|
|
205
|
+
// Resolve output path: flag > detected > prompt/default.
|
|
206
|
+
let outPath = flags.out;
|
|
207
|
+
if (!outPath && useDetected && detection.generatedTypes)
|
|
208
|
+
outPath = detection.generatedTypes;
|
|
209
|
+
if (!outPath)
|
|
210
|
+
outPath =
|
|
211
|
+
canPrompt && io.prompt
|
|
212
|
+
? await io.prompt('Generated types output path?', 'grafeo.generated.ts')
|
|
213
|
+
: 'grafeo.generated.ts';
|
|
214
|
+
const created = [];
|
|
215
|
+
const kept = [];
|
|
216
|
+
// Scaffold the schema only when it doesn't already exist.
|
|
217
|
+
const schemaAbs = path.resolve(io.cwd, schemaPath);
|
|
218
|
+
if (fs.existsSync(schemaAbs))
|
|
219
|
+
kept.push(schemaPath);
|
|
220
|
+
else {
|
|
221
|
+
writeFileEnsuringDir(schemaAbs, MOVIE_SCHEMA);
|
|
222
|
+
created.push(schemaPath);
|
|
223
|
+
}
|
|
224
|
+
const wantSeed = flags.seed === true;
|
|
225
|
+
// Write grafeo.config.ts — never clobber an existing one without consent.
|
|
226
|
+
const configAbs = path.resolve(io.cwd, 'grafeo.config.ts');
|
|
227
|
+
const config = renderConfig(schemaPath, outPath, wantSeed);
|
|
228
|
+
if (fs.existsSync(configAbs) && !force) {
|
|
229
|
+
const overwrite = canPrompt && io.confirm
|
|
230
|
+
? await io.confirm('grafeo.config.ts exists — overwrite it?')
|
|
231
|
+
: false;
|
|
232
|
+
if (!overwrite) {
|
|
233
|
+
if (!canPrompt)
|
|
234
|
+
throw new errors_1.CliError('grafeo.config.ts already exists. Re-run with --force to overwrite.');
|
|
235
|
+
kept.push('grafeo.config.ts');
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
fs.writeFileSync(configAbs, config, 'utf-8');
|
|
239
|
+
created.push('grafeo.config.ts');
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
fs.writeFileSync(configAbs, config, 'utf-8');
|
|
244
|
+
created.push('grafeo.config.ts');
|
|
245
|
+
}
|
|
246
|
+
// Optional seed stub.
|
|
247
|
+
if (wantSeed) {
|
|
248
|
+
const seedAbs = path.resolve(io.cwd, 'seed.ts');
|
|
249
|
+
if (fs.existsSync(seedAbs) && !force)
|
|
250
|
+
kept.push('seed.ts');
|
|
251
|
+
else {
|
|
252
|
+
fs.writeFileSync(seedAbs, SEED_STUB, 'utf-8');
|
|
253
|
+
created.push('seed.ts');
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
// Wire an npm script (non-destructive).
|
|
257
|
+
const pkgNote = wireGenerateScript(io.cwd);
|
|
258
|
+
// Summary + next step.
|
|
259
|
+
for (const f of created)
|
|
260
|
+
io.out(`✓ created ${f}`);
|
|
261
|
+
for (const f of kept)
|
|
262
|
+
io.out(`• kept ${f} (already present)`);
|
|
263
|
+
if (pkgNote === 'added')
|
|
264
|
+
io.out('✓ added "generate" script to package.json');
|
|
265
|
+
else if (pkgNote === 'kept')
|
|
266
|
+
io.out('• kept existing "generate" script in package.json');
|
|
267
|
+
io.out('');
|
|
268
|
+
io.out(pkgNote === 'added'
|
|
269
|
+
? 'Next: `npm run generate` (or `npx grafeo generate`)'
|
|
270
|
+
: 'Next: `npx grafeo generate`');
|
|
271
|
+
return 0;
|
|
272
|
+
}
|
|
273
|
+
//# sourceMappingURL=init.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init.js","sourceRoot":"","sources":["../../../../src/cli/commands/init.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkKA,0BA8GC;AAhRD,4CAA8B;AAC9B,gDAAkC;AAClC,yCAAsC;AACtC,sCAA0C;AAC1C,sCAAqC;AAarC,SAAS,cAAc,CAAC,IAAc;IACpC,IAAI,CAAC;QACH,MAAM,EAAE,MAAM,EAAE,GAAG,IAAA,qBAAS,EAAC;YAC3B,IAAI,EAAE,IAAI;YACV,OAAO,EAAE;gBACP,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;gBAC1B,GAAG,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;gBACvB,IAAI,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE;gBACzB,KAAK,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE;gBAC1B,GAAG,EAAE,EAAE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CAAC,UAAU,CAAC,oBAAoB,CAAC,CAAC;IAC9D,IAAI,OAAO,KAAK,OAAO;QAAE,EAAE,CAAC,GAAG,CAAC,2CAA2C,CAAC,CAAC;SACxE,IAAI,OAAO,KAAK,MAAM;QACzB,EAAE,CAAC,GAAG,CAAC,mDAAmD,CAAC,CAAC;IAC9D,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACX,EAAE,CAAC,GAAG,CACJ,OAAO,KAAK,OAAO;QACjB,CAAC,CAAC,qDAAqD;QACvD,CAAC,CAAC,6BAA6B,CAClC,CAAC;IACF,OAAO,CAAC,CAAC;AACX,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** What `grafeo init` found (or didn't) in an existing project. */
|
|
2
|
+
export interface DetectionResult {
|
|
3
|
+
/** `.graphql`/`.gql` files that carry grafeo directives (relative to cwd). */
|
|
4
|
+
schemaCandidates: string[];
|
|
5
|
+
/** A previously generated types file, identified by the header marker. */
|
|
6
|
+
generatedTypes?: string;
|
|
7
|
+
/** An existing grafeo.config.{ts,js,json}, if present. */
|
|
8
|
+
existingConfig?: string;
|
|
9
|
+
/** True if a NEO4J_* env var or a .env mentioning one is present. */
|
|
10
|
+
hasNeo4jEnv: boolean;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Scan `cwd` for an existing grafeo setup so `init` can wire itself up. Pure
|
|
14
|
+
* filesystem reads — shallow, with generated/VCS dirs skipped — so it stays
|
|
15
|
+
* fast and never walks `node_modules`.
|
|
16
|
+
*/
|
|
17
|
+
export declare function detectProject(cwd: string, env: NodeJS.ProcessEnv): DetectionResult;
|
|
18
|
+
//# sourceMappingURL=detect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detect.d.ts","sourceRoot":"","sources":["../../../src/cli/detect.ts"],"names":[],"mappings":"AAGA,mEAAmE;AACnE,MAAM,WAAW,eAAe;IAC9B,8EAA8E;IAC9E,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,0EAA0E;IAC1E,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,0DAA0D;IAC1D,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,qEAAqE;IACrE,WAAW,EAAE,OAAO,CAAC;CACtB;AA2DD;;;;GAIG;AACH,wBAAgB,aAAa,CAC3B,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,MAAM,CAAC,UAAU,GACrB,eAAe,CAyCjB"}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.detectProject = detectProject;
|
|
37
|
+
const fs = __importStar(require("node:fs"));
|
|
38
|
+
const path = __importStar(require("node:path"));
|
|
39
|
+
// Directories never worth scanning — large, generated, or VCS internals.
|
|
40
|
+
const SKIP_DIRS = new Set([
|
|
41
|
+
'node_modules',
|
|
42
|
+
'dist',
|
|
43
|
+
'build',
|
|
44
|
+
'.git',
|
|
45
|
+
'.next',
|
|
46
|
+
'coverage',
|
|
47
|
+
'.turbo',
|
|
48
|
+
]);
|
|
49
|
+
const MAX_DEPTH = 3;
|
|
50
|
+
const CONFIG_NAMES = [
|
|
51
|
+
'grafeo.config.ts',
|
|
52
|
+
'grafeo.config.js',
|
|
53
|
+
'grafeo.config.json',
|
|
54
|
+
];
|
|
55
|
+
// Generated files open with a `// Generated by <pkg> generateTypes()` header
|
|
56
|
+
// line (utility-types emitter). Anchor to the line start so a doc comment that
|
|
57
|
+
// merely mentions the phrase isn't misdetected, and allow any package name so
|
|
58
|
+
// files generated under an npm alias still match.
|
|
59
|
+
const GENERATED_MARKER = /^\/\/\s*Generated by .+ generateTypes\(\)/m;
|
|
60
|
+
// A schema is grafeo's only if it actually uses grafeo's directives — a bare
|
|
61
|
+
// GraphQL file in the tree must not be mistaken for the OGM schema.
|
|
62
|
+
const GRAFEO_DIRECTIVE = /@(node|relationship|relationshipProperties)\b/;
|
|
63
|
+
function walk(root, depth, out) {
|
|
64
|
+
let entries;
|
|
65
|
+
try {
|
|
66
|
+
entries = fs.readdirSync(root, { withFileTypes: true });
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
for (const entry of entries) {
|
|
72
|
+
if (entry.name.startsWith('.') && entry.name !== '.env')
|
|
73
|
+
continue;
|
|
74
|
+
const full = path.join(root, entry.name);
|
|
75
|
+
if (entry.isDirectory()) {
|
|
76
|
+
if (depth >= MAX_DEPTH || SKIP_DIRS.has(entry.name))
|
|
77
|
+
continue;
|
|
78
|
+
walk(full, depth + 1, out);
|
|
79
|
+
}
|
|
80
|
+
else if (entry.isFile())
|
|
81
|
+
out.push(full);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function readHead(file, bytes = 4096) {
|
|
85
|
+
try {
|
|
86
|
+
const fd = fs.openSync(file, 'r');
|
|
87
|
+
try {
|
|
88
|
+
const buf = Buffer.alloc(bytes);
|
|
89
|
+
const read = fs.readSync(fd, buf, 0, bytes, 0);
|
|
90
|
+
return buf.toString('utf-8', 0, read);
|
|
91
|
+
}
|
|
92
|
+
finally {
|
|
93
|
+
fs.closeSync(fd);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
return '';
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Scan `cwd` for an existing grafeo setup so `init` can wire itself up. Pure
|
|
102
|
+
* filesystem reads — shallow, with generated/VCS dirs skipped — so it stays
|
|
103
|
+
* fast and never walks `node_modules`.
|
|
104
|
+
*/
|
|
105
|
+
function detectProject(cwd, env) {
|
|
106
|
+
const files = [];
|
|
107
|
+
walk(cwd, 0, files);
|
|
108
|
+
const schemaCandidates = [];
|
|
109
|
+
let generatedTypes;
|
|
110
|
+
for (const file of files) {
|
|
111
|
+
const ext = path.extname(file);
|
|
112
|
+
const rel = path.relative(cwd, file);
|
|
113
|
+
if (ext === '.graphql' || ext === '.gql') {
|
|
114
|
+
// Only count it as the schema if it actually uses grafeo directives.
|
|
115
|
+
// Head-read (guarded + capped) like the .ts sniff — directives sit at the
|
|
116
|
+
// top of real schemas, and this avoids reading (or throwing on) a huge or
|
|
117
|
+
// unreadable file.
|
|
118
|
+
if (GRAFEO_DIRECTIVE.test(readHead(file, 65536)))
|
|
119
|
+
schemaCandidates.push(rel);
|
|
120
|
+
}
|
|
121
|
+
else if (ext === '.ts' && !generatedTypes)
|
|
122
|
+
if (GENERATED_MARKER.test(readHead(file)))
|
|
123
|
+
generatedTypes = rel;
|
|
124
|
+
}
|
|
125
|
+
// Prefer a file literally named schema.graphql when several candidates exist.
|
|
126
|
+
schemaCandidates.sort((a, b) => {
|
|
127
|
+
const an = path.basename(a) === 'schema.graphql' ? 0 : 1;
|
|
128
|
+
const bn = path.basename(b) === 'schema.graphql' ? 0 : 1;
|
|
129
|
+
return an - bn || a.localeCompare(b);
|
|
130
|
+
});
|
|
131
|
+
let existingConfig;
|
|
132
|
+
for (const name of CONFIG_NAMES)
|
|
133
|
+
if (fs.existsSync(path.join(cwd, name))) {
|
|
134
|
+
existingConfig = name;
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
const hasNeo4jEnv = Object.keys(env).some((k) => k.startsWith('NEO4J_')) ||
|
|
138
|
+
(fs.existsSync(path.join(cwd, '.env')) &&
|
|
139
|
+
/^\s*NEO4J_/m.test(readHead(path.join(cwd, '.env'))));
|
|
140
|
+
return { schemaCandidates, generatedTypes, existingConfig, hasNeo4jEnv };
|
|
141
|
+
}
|
|
142
|
+
//# sourceMappingURL=detect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detect.js","sourceRoot":"","sources":["../../../src/cli/detect.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6EA,sCA4CC;AAzHD,4CAA8B;AAC9B,gDAAkC;AAclC,yEAAyE;AACzE,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC;IACxB,cAAc;IACd,MAAM;IACN,OAAO;IACP,MAAM;IACN,OAAO;IACP,UAAU;IACV,QAAQ;CACT,CAAC,CAAC;AACH,MAAM,SAAS,GAAG,CAAC,CAAC;AACpB,MAAM,YAA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../src/cli/index.ts"],"names":[],"mappings":";AAGA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/cli/index.ts"],"names":[],"mappings":";AAGA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAoErC;;;GAGG;AACH,wBAAsB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,CAoFrE"}
|
package/dist/cjs/cli/index.js
CHANGED
|
@@ -40,6 +40,7 @@ const errors_1 = require("./errors");
|
|
|
40
40
|
const HELP = `grafeo — CLI for grafeo-ogm
|
|
41
41
|
|
|
42
42
|
Usage:
|
|
43
|
+
grafeo init [--schema <path>] [--out <path>] [--seed] [--fresh] [--yes] [--force]
|
|
43
44
|
grafeo generate [--schema <path>] [--out <path>] [--watch] [--verify] [--poll <ms>]
|
|
44
45
|
grafeo db push [--schema <path>] [--dry-run] [--force-drop] [--yes]
|
|
45
46
|
[--uri <bolt-uri>] [--username <user>] [--database <name>]
|
|
@@ -56,6 +57,21 @@ Configuration:
|
|
|
56
57
|
NEO4J_DATABASE. The password is never accepted as a flag.`;
|
|
57
58
|
/** Focused per-command help, shown for \`grafeo <command> --help\`. */
|
|
58
59
|
const COMMAND_HELP = {
|
|
60
|
+
init: `grafeo init — scaffold (or auto-detect) a grafeo project
|
|
61
|
+
|
|
62
|
+
Usage:
|
|
63
|
+
grafeo init [--schema <path>] [--out <path>] [--seed] [--fresh] [--yes] [--force]
|
|
64
|
+
|
|
65
|
+
Detects an existing grafeo schema + generated types and wires grafeo.config.ts
|
|
66
|
+
to them. With nothing to detect (or --fresh), scaffolds a starter schema
|
|
67
|
+
(the Neo4j movie example) and config.
|
|
68
|
+
|
|
69
|
+
--schema <path> schema path (skip detection/prompt)
|
|
70
|
+
--out <path> generated-types output path
|
|
71
|
+
--seed also scaffold a seed.ts stub
|
|
72
|
+
--fresh ignore any detected setup and scaffold a new project
|
|
73
|
+
--yes non-interactive: accept detected values / defaults, no prompts
|
|
74
|
+
--force overwrite an existing grafeo.config.ts / seed.ts`,
|
|
59
75
|
generate: `grafeo generate — generate TypeScript types from your SDL
|
|
60
76
|
|
|
61
77
|
Usage:
|
|
@@ -132,6 +148,10 @@ async function main(argv, io) {
|
|
|
132
148
|
return 0;
|
|
133
149
|
}
|
|
134
150
|
// Commands load lazily so `generate` never pays for neo4j-driver.
|
|
151
|
+
if (command === 'init') {
|
|
152
|
+
const { runInit } = await Promise.resolve().then(() => __importStar(require('./commands/init')));
|
|
153
|
+
return await runInit(commandArgs, io);
|
|
154
|
+
}
|
|
135
155
|
if (command === 'generate') {
|
|
136
156
|
const { runGenerate } = await Promise.resolve().then(() => __importStar(require('./commands/generate')));
|
|
137
157
|
return await runGenerate(commandArgs, io);
|
|
@@ -179,6 +199,21 @@ if (typeof require !== 'undefined' && require.main === module) {
|
|
|
179
199
|
rl.close();
|
|
180
200
|
}
|
|
181
201
|
},
|
|
202
|
+
// Free-text prompt for `grafeo init` (path entry, candidate selection).
|
|
203
|
+
prompt: async (question, defaultValue) => {
|
|
204
|
+
const rl = readline.createInterface({
|
|
205
|
+
input: process.stdin,
|
|
206
|
+
output: process.stdout,
|
|
207
|
+
});
|
|
208
|
+
try {
|
|
209
|
+
const suffix = defaultValue ? ` (${defaultValue})` : '';
|
|
210
|
+
const answer = (await rl.question(`${question}${suffix} `)).trim();
|
|
211
|
+
return answer || defaultValue || '';
|
|
212
|
+
}
|
|
213
|
+
finally {
|
|
214
|
+
rl.close();
|
|
215
|
+
}
|
|
216
|
+
},
|
|
182
217
|
};
|
|
183
218
|
void main(process.argv.slice(2), io).then((code) => {
|
|
184
219
|
process.exitCode = code;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/cli/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;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AG,QAAQ,CAAC,eAAe,CAAC;gBAClC,KAAK,EAAE,OAAO,CAAC,KAAK;gBACpB,MAAM,EAAE,OAAO,CAAC,MAAM;aACvB,CAAC,CAAC;YACH,IAAI,CAAC;gBACH,MAAM,MAAM,GAAG,YAAY,CAAC,CAAC,CAAC,KAAK,YAAY,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;gBACxD,MAAM,MAAM,GAAG,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,GAAG,QAAQ,GAAG,MAAM,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;gBACnE,OAAO,MAAM,IAAI,YAAY,IAAI,EAAE,CAAC;YACtC,CAAC;oBAAS,CAAC;gBACT,EAAE,CAAC,KAAK,EAAE,CAAC;YACb,CAAC;QACH,CAAC;KACF,CAAC;IACF,KAAK,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE;QACjD,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;IAC1B,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/cjs/cli/types.d.ts
CHANGED
|
@@ -61,6 +61,12 @@ export interface CliIO {
|
|
|
61
61
|
interactive?: boolean;
|
|
62
62
|
/** Prompt for yes/no confirmation (only called when interactive). */
|
|
63
63
|
confirm?(question: string): Promise<boolean>;
|
|
64
|
+
/**
|
|
65
|
+
* Prompt for a free-text answer (only called when interactive). Returns the
|
|
66
|
+
* trimmed input, or `defaultValue` when the user enters nothing. Used by
|
|
67
|
+
* `grafeo init` for path entry and detected-vs-fresh selection.
|
|
68
|
+
*/
|
|
69
|
+
prompt?(question: string, defaultValue?: string): Promise<string>;
|
|
64
70
|
/**
|
|
65
71
|
* Cooperative shutdown for long-running commands (`generate --watch`).
|
|
66
72
|
* The bin runs without one (Ctrl-C kills the process); tests abort it
|
|
@@ -1 +1 @@
|
|
|
1
|
-
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xE"}
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import * as fs from 'node:fs';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
import { parseArgs } from 'node:util';
|
|
4
|
+
import { detectProject } from '../detect';
|
|
5
|
+
import { CliError } from '../errors';
|
|
6
|
+
function parseInitFlags(argv) {
|
|
7
|
+
try {
|
|
8
|
+
const { values } = parseArgs({
|
|
9
|
+
args: argv,
|
|
10
|
+
options: {
|
|
11
|
+
schema: { type: 'string' },
|
|
12
|
+
out: { type: 'string' },
|
|
13
|
+
seed: { type: 'boolean' },
|
|
14
|
+
fresh: { type: 'boolean' },
|
|
15
|
+
yes: { type: 'boolean' },
|
|
16
|
+
force: { type: 'boolean' },
|
|
17
|
+
debug: { type: 'boolean' },
|
|
18
|
+
},
|
|
19
|
+
strict: true,
|
|
20
|
+
allowPositionals: false,
|
|
21
|
+
});
|
|
22
|
+
return values;
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
26
|
+
throw new CliError(`init: ${message}`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
// The classic Neo4j movie graph, expressed in grafeo SDL — recognizable to
|
|
30
|
+
// Neo4j users and it exercises relationship arity/direction both ways.
|
|
31
|
+
const MOVIE_SCHEMA = `# grafeo schema — the Neo4j movie example.
|
|
32
|
+
# Run \`npx grafeo generate\` (or \`npm run generate\`) to emit typed models.
|
|
33
|
+
|
|
34
|
+
type Movie @node {
|
|
35
|
+
title: String! @unique
|
|
36
|
+
released: Int
|
|
37
|
+
tagline: String
|
|
38
|
+
actors: [Person!]! @relationship(type: "ACTED_IN", direction: IN)
|
|
39
|
+
directors: [Person!]! @relationship(type: "DIRECTED", direction: IN)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
type Person @node {
|
|
43
|
+
name: String! @id @unique
|
|
44
|
+
born: Int
|
|
45
|
+
actedIn: [Movie!]! @relationship(type: "ACTED_IN", direction: OUT)
|
|
46
|
+
directed: [Movie!]! @relationship(type: "DIRECTED", direction: OUT)
|
|
47
|
+
}
|
|
48
|
+
`;
|
|
49
|
+
const SEED_STUB = `import type { OGM } from 'grafeo-ogm';
|
|
50
|
+
|
|
51
|
+
// Prefer upsert over create so repeated seeds converge instead of duplicating.
|
|
52
|
+
export default async function seed(ogm: OGM) {
|
|
53
|
+
const Movie = ogm.model('Movie');
|
|
54
|
+
await Movie.upsert({
|
|
55
|
+
where: { title: 'The Matrix' },
|
|
56
|
+
create: { title: 'The Matrix', released: 1999 },
|
|
57
|
+
update: { released: 1999 },
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
`;
|
|
61
|
+
function renderConfig(schemaPath, outPath, includeSeed) {
|
|
62
|
+
// JSON.stringify, NOT string-templating: the paths come from --schema/--out
|
|
63
|
+
// /prompts and this file is later EXECUTED by jiti, so a raw `'${path}'`
|
|
64
|
+
// would let a quote in the path break out and inject code (and an innocent
|
|
65
|
+
// apostrophe would produce a broken config). JSON.stringify emits a fully
|
|
66
|
+
// escaped, valid string literal.
|
|
67
|
+
const seedLine = includeSeed ? `\n seed: './seed.ts',` : '';
|
|
68
|
+
return `import { defineConfig } from 'grafeo-ogm';
|
|
69
|
+
|
|
70
|
+
export default defineConfig({
|
|
71
|
+
schema: ${JSON.stringify(rel(schemaPath))},
|
|
72
|
+
out: ${JSON.stringify(rel(outPath))},
|
|
73
|
+
database: {
|
|
74
|
+
uri: process.env.NEO4J_URI,
|
|
75
|
+
username: process.env.NEO4J_USERNAME,
|
|
76
|
+
// Never commit a password — set NEO4J_PASSWORD in your environment.
|
|
77
|
+
password: process.env.NEO4J_PASSWORD,
|
|
78
|
+
},${seedLine}
|
|
79
|
+
});
|
|
80
|
+
`;
|
|
81
|
+
}
|
|
82
|
+
/** Normalize a path to a `./`-prefixed relative form for the config file. */
|
|
83
|
+
function rel(p) {
|
|
84
|
+
const normalized = p.replace(/\\/g, '/');
|
|
85
|
+
return normalized.startsWith('.') ? normalized : `./${normalized}`;
|
|
86
|
+
}
|
|
87
|
+
function writeFileEnsuringDir(absPath, content) {
|
|
88
|
+
fs.mkdirSync(path.dirname(absPath), { recursive: true });
|
|
89
|
+
fs.writeFileSync(absPath, content, 'utf-8');
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Add `"generate": "grafeo generate"` to package.json scripts. Non-destructive:
|
|
93
|
+
* an existing `generate` script is preserved. Returns what happened so the
|
|
94
|
+
* summary can report it.
|
|
95
|
+
*/
|
|
96
|
+
function wireGenerateScript(cwd) {
|
|
97
|
+
const pkgPath = path.join(cwd, 'package.json');
|
|
98
|
+
if (!fs.existsSync(pkgPath))
|
|
99
|
+
return 'none';
|
|
100
|
+
// Strip a UTF-8 BOM (common on Windows-edited files) so parse doesn't fail.
|
|
101
|
+
const raw = fs.readFileSync(pkgPath, 'utf-8').replace(/^\uFEFF/, '');
|
|
102
|
+
let pkg;
|
|
103
|
+
try {
|
|
104
|
+
pkg = JSON.parse(raw);
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
return 'none';
|
|
108
|
+
}
|
|
109
|
+
// Only treat `scripts` as a map when it's actually an object — otherwise a
|
|
110
|
+
// malformed value would be spread into garbage.
|
|
111
|
+
const scripts = typeof pkg.scripts === 'object' && pkg.scripts !== null
|
|
112
|
+
? pkg.scripts
|
|
113
|
+
: {};
|
|
114
|
+
if (scripts.generate)
|
|
115
|
+
return 'kept';
|
|
116
|
+
pkg.scripts = {
|
|
117
|
+
...scripts,
|
|
118
|
+
generate: 'grafeo generate',
|
|
119
|
+
};
|
|
120
|
+
const indent = /^\t/m.test(raw) ? '\t' : 2;
|
|
121
|
+
fs.writeFileSync(pkgPath, `${JSON.stringify(pkg, null, indent)}\n`, 'utf-8');
|
|
122
|
+
return 'added';
|
|
123
|
+
}
|
|
124
|
+
/** Pick the schema among detected candidates (prompt only when ambiguous). */
|
|
125
|
+
async function chooseSchema(candidates, io, canPrompt) {
|
|
126
|
+
if (candidates.length === 1)
|
|
127
|
+
return candidates[0];
|
|
128
|
+
if (canPrompt && io.prompt) {
|
|
129
|
+
io.out('Multiple grafeo schemas found:');
|
|
130
|
+
candidates.forEach((c, i) => io.out(` ${i + 1}) ${c}`));
|
|
131
|
+
const answer = await io.prompt('Which is your schema? (number)', '1');
|
|
132
|
+
const idx = Number.parseInt(answer, 10) - 1;
|
|
133
|
+
if (Number.isInteger(idx) && idx >= 0 && idx < candidates.length)
|
|
134
|
+
return candidates[idx];
|
|
135
|
+
}
|
|
136
|
+
return candidates[0];
|
|
137
|
+
}
|
|
138
|
+
export async function runInit(argv, io) {
|
|
139
|
+
const flags = parseInitFlags(argv);
|
|
140
|
+
const yes = flags.yes === true;
|
|
141
|
+
const force = flags.force === true;
|
|
142
|
+
const canPrompt = io.interactive === true && !yes;
|
|
143
|
+
const detection = detectProject(io.cwd, io.env);
|
|
144
|
+
const hasDetected = detection.schemaCandidates.length > 0 || detection.generatedTypes != null;
|
|
145
|
+
// Detected setup vs fresh start.
|
|
146
|
+
let fresh = flags.fresh === true;
|
|
147
|
+
if (hasDetected && !fresh && canPrompt && io.confirm) {
|
|
148
|
+
const detail = [
|
|
149
|
+
detection.schemaCandidates[0]
|
|
150
|
+
? `schema: ${detection.schemaCandidates[0]}`
|
|
151
|
+
: null,
|
|
152
|
+
detection.generatedTypes ? `types: ${detection.generatedTypes}` : null,
|
|
153
|
+
]
|
|
154
|
+
.filter(Boolean)
|
|
155
|
+
.join(', ');
|
|
156
|
+
const useDetected = await io.confirm(`Existing grafeo setup detected (${detail}) — wire the config to it?`);
|
|
157
|
+
fresh = !useDetected;
|
|
158
|
+
}
|
|
159
|
+
const useDetected = hasDetected && !fresh;
|
|
160
|
+
// Resolve schema path: flag > detected > prompt/default.
|
|
161
|
+
let schemaPath = flags.schema;
|
|
162
|
+
if (!schemaPath && useDetected)
|
|
163
|
+
schemaPath = await chooseSchema(detection.schemaCandidates, io, canPrompt);
|
|
164
|
+
if (!schemaPath)
|
|
165
|
+
schemaPath =
|
|
166
|
+
canPrompt && io.prompt
|
|
167
|
+
? await io.prompt('Schema path?', 'schema.graphql')
|
|
168
|
+
: 'schema.graphql';
|
|
169
|
+
// Resolve output path: flag > detected > prompt/default.
|
|
170
|
+
let outPath = flags.out;
|
|
171
|
+
if (!outPath && useDetected && detection.generatedTypes)
|
|
172
|
+
outPath = detection.generatedTypes;
|
|
173
|
+
if (!outPath)
|
|
174
|
+
outPath =
|
|
175
|
+
canPrompt && io.prompt
|
|
176
|
+
? await io.prompt('Generated types output path?', 'grafeo.generated.ts')
|
|
177
|
+
: 'grafeo.generated.ts';
|
|
178
|
+
const created = [];
|
|
179
|
+
const kept = [];
|
|
180
|
+
// Scaffold the schema only when it doesn't already exist.
|
|
181
|
+
const schemaAbs = path.resolve(io.cwd, schemaPath);
|
|
182
|
+
if (fs.existsSync(schemaAbs))
|
|
183
|
+
kept.push(schemaPath);
|
|
184
|
+
else {
|
|
185
|
+
writeFileEnsuringDir(schemaAbs, MOVIE_SCHEMA);
|
|
186
|
+
created.push(schemaPath);
|
|
187
|
+
}
|
|
188
|
+
const wantSeed = flags.seed === true;
|
|
189
|
+
// Write grafeo.config.ts — never clobber an existing one without consent.
|
|
190
|
+
const configAbs = path.resolve(io.cwd, 'grafeo.config.ts');
|
|
191
|
+
const config = renderConfig(schemaPath, outPath, wantSeed);
|
|
192
|
+
if (fs.existsSync(configAbs) && !force) {
|
|
193
|
+
const overwrite = canPrompt && io.confirm
|
|
194
|
+
? await io.confirm('grafeo.config.ts exists — overwrite it?')
|
|
195
|
+
: false;
|
|
196
|
+
if (!overwrite) {
|
|
197
|
+
if (!canPrompt)
|
|
198
|
+
throw new CliError('grafeo.config.ts already exists. Re-run with --force to overwrite.');
|
|
199
|
+
kept.push('grafeo.config.ts');
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
fs.writeFileSync(configAbs, config, 'utf-8');
|
|
203
|
+
created.push('grafeo.config.ts');
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
fs.writeFileSync(configAbs, config, 'utf-8');
|
|
208
|
+
created.push('grafeo.config.ts');
|
|
209
|
+
}
|
|
210
|
+
// Optional seed stub.
|
|
211
|
+
if (wantSeed) {
|
|
212
|
+
const seedAbs = path.resolve(io.cwd, 'seed.ts');
|
|
213
|
+
if (fs.existsSync(seedAbs) && !force)
|
|
214
|
+
kept.push('seed.ts');
|
|
215
|
+
else {
|
|
216
|
+
fs.writeFileSync(seedAbs, SEED_STUB, 'utf-8');
|
|
217
|
+
created.push('seed.ts');
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
// Wire an npm script (non-destructive).
|
|
221
|
+
const pkgNote = wireGenerateScript(io.cwd);
|
|
222
|
+
// Summary + next step.
|
|
223
|
+
for (const f of created)
|
|
224
|
+
io.out(`✓ created ${f}`);
|
|
225
|
+
for (const f of kept)
|
|
226
|
+
io.out(`• kept ${f} (already present)`);
|
|
227
|
+
if (pkgNote === 'added')
|
|
228
|
+
io.out('✓ added "generate" script to package.json');
|
|
229
|
+
else if (pkgNote === 'kept')
|
|
230
|
+
io.out('• kept existing "generate" script in package.json');
|
|
231
|
+
io.out('');
|
|
232
|
+
io.out(pkgNote === 'added'
|
|
233
|
+
? 'Next: `npm run generate` (or `npx grafeo generate`)'
|
|
234
|
+
: 'Next: `npx grafeo generate`');
|
|
235
|
+
return 0;
|
|
236
|
+
}
|
|
237
|
+
//# sourceMappingURL=init.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init.js","sourceRoot":"","sources":["../../../../src/cli/commands/init.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MA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Aa,CAAC,OAAO,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;YAC9C,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAC1B,CAAC;IACH,CAAC;IAED,wCAAwC;IACxC,MAAM,OAAO,GAAG,kBAAkB,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;IAE3C,uBAAuB;IACvB,KAAK,MAAM,CAAC,IAAI,OAAO;QAAE,EAAE,CAAC,GAAG,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC;IAClD,KAAK,MAAM,CAAC,IAAI,IAAI;QAAE,EAAE,CAAC,GAAG,CAAC,UAAU,CAAC,oBAAoB,CAAC,CAAC;IAC9D,IAAI,OAAO,KAAK,OAAO;QAAE,EAAE,CAAC,GAAG,CAAC,2CAA2C,CAAC,CAAC;SACxE,IAAI,OAAO,KAAK,MAAM;QACzB,EAAE,CAAC,GAAG,CAAC,mDAAmD,CAAC,CAAC;IAC9D,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACX,EAAE,CAAC,GAAG,CACJ,OAAO,KAAK,OAAO;QACjB,CAAC,CAAC,qDAAqD;QACvD,CAAC,CAAC,6BAA6B,CAClC,CAAC;IACF,OAAO,CAAC,CAAC;AACX,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** What `grafeo init` found (or didn't) in an existing project. */
|
|
2
|
+
export interface DetectionResult {
|
|
3
|
+
/** `.graphql`/`.gql` files that carry grafeo directives (relative to cwd). */
|
|
4
|
+
schemaCandidates: string[];
|
|
5
|
+
/** A previously generated types file, identified by the header marker. */
|
|
6
|
+
generatedTypes?: string;
|
|
7
|
+
/** An existing grafeo.config.{ts,js,json}, if present. */
|
|
8
|
+
existingConfig?: string;
|
|
9
|
+
/** True if a NEO4J_* env var or a .env mentioning one is present. */
|
|
10
|
+
hasNeo4jEnv: boolean;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Scan `cwd` for an existing grafeo setup so `init` can wire itself up. Pure
|
|
14
|
+
* filesystem reads — shallow, with generated/VCS dirs skipped — so it stays
|
|
15
|
+
* fast and never walks `node_modules`.
|
|
16
|
+
*/
|
|
17
|
+
export declare function detectProject(cwd: string, env: NodeJS.ProcessEnv): DetectionResult;
|
|
18
|
+
//# sourceMappingURL=detect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detect.d.ts","sourceRoot":"","sources":["../../../src/cli/detect.ts"],"names":[],"mappings":"AAGA,mEAAmE;AACnE,MAAM,WAAW,eAAe;IAC9B,8EAA8E;IAC9E,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,0EAA0E;IAC1E,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,0DAA0D;IAC1D,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,qEAAqE;IACrE,WAAW,EAAE,OAAO,CAAC;CACtB;AA2DD;;;;GAIG;AACH,wBAAgB,aAAa,CAC3B,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,MAAM,CAAC,UAAU,GACrB,eAAe,CAyCjB"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import * as fs from 'node:fs';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
// Directories never worth scanning — large, generated, or VCS internals.
|
|
4
|
+
const SKIP_DIRS = new Set([
|
|
5
|
+
'node_modules',
|
|
6
|
+
'dist',
|
|
7
|
+
'build',
|
|
8
|
+
'.git',
|
|
9
|
+
'.next',
|
|
10
|
+
'coverage',
|
|
11
|
+
'.turbo',
|
|
12
|
+
]);
|
|
13
|
+
const MAX_DEPTH = 3;
|
|
14
|
+
const CONFIG_NAMES = [
|
|
15
|
+
'grafeo.config.ts',
|
|
16
|
+
'grafeo.config.js',
|
|
17
|
+
'grafeo.config.json',
|
|
18
|
+
];
|
|
19
|
+
// Generated files open with a `// Generated by <pkg> generateTypes()` header
|
|
20
|
+
// line (utility-types emitter). Anchor to the line start so a doc comment that
|
|
21
|
+
// merely mentions the phrase isn't misdetected, and allow any package name so
|
|
22
|
+
// files generated under an npm alias still match.
|
|
23
|
+
const GENERATED_MARKER = /^\/\/\s*Generated by .+ generateTypes\(\)/m;
|
|
24
|
+
// A schema is grafeo's only if it actually uses grafeo's directives — a bare
|
|
25
|
+
// GraphQL file in the tree must not be mistaken for the OGM schema.
|
|
26
|
+
const GRAFEO_DIRECTIVE = /@(node|relationship|relationshipProperties)\b/;
|
|
27
|
+
function walk(root, depth, out) {
|
|
28
|
+
let entries;
|
|
29
|
+
try {
|
|
30
|
+
entries = fs.readdirSync(root, { withFileTypes: true });
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
for (const entry of entries) {
|
|
36
|
+
if (entry.name.startsWith('.') && entry.name !== '.env')
|
|
37
|
+
continue;
|
|
38
|
+
const full = path.join(root, entry.name);
|
|
39
|
+
if (entry.isDirectory()) {
|
|
40
|
+
if (depth >= MAX_DEPTH || SKIP_DIRS.has(entry.name))
|
|
41
|
+
continue;
|
|
42
|
+
walk(full, depth + 1, out);
|
|
43
|
+
}
|
|
44
|
+
else if (entry.isFile())
|
|
45
|
+
out.push(full);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function readHead(file, bytes = 4096) {
|
|
49
|
+
try {
|
|
50
|
+
const fd = fs.openSync(file, 'r');
|
|
51
|
+
try {
|
|
52
|
+
const buf = Buffer.alloc(bytes);
|
|
53
|
+
const read = fs.readSync(fd, buf, 0, bytes, 0);
|
|
54
|
+
return buf.toString('utf-8', 0, read);
|
|
55
|
+
}
|
|
56
|
+
finally {
|
|
57
|
+
fs.closeSync(fd);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
return '';
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Scan `cwd` for an existing grafeo setup so `init` can wire itself up. Pure
|
|
66
|
+
* filesystem reads — shallow, with generated/VCS dirs skipped — so it stays
|
|
67
|
+
* fast and never walks `node_modules`.
|
|
68
|
+
*/
|
|
69
|
+
export function detectProject(cwd, env) {
|
|
70
|
+
const files = [];
|
|
71
|
+
walk(cwd, 0, files);
|
|
72
|
+
const schemaCandidates = [];
|
|
73
|
+
let generatedTypes;
|
|
74
|
+
for (const file of files) {
|
|
75
|
+
const ext = path.extname(file);
|
|
76
|
+
const rel = path.relative(cwd, file);
|
|
77
|
+
if (ext === '.graphql' || ext === '.gql') {
|
|
78
|
+
// Only count it as the schema if it actually uses grafeo directives.
|
|
79
|
+
// Head-read (guarded + capped) like the .ts sniff — directives sit at the
|
|
80
|
+
// top of real schemas, and this avoids reading (or throwing on) a huge or
|
|
81
|
+
// unreadable file.
|
|
82
|
+
if (GRAFEO_DIRECTIVE.test(readHead(file, 65536)))
|
|
83
|
+
schemaCandidates.push(rel);
|
|
84
|
+
}
|
|
85
|
+
else if (ext === '.ts' && !generatedTypes)
|
|
86
|
+
if (GENERATED_MARKER.test(readHead(file)))
|
|
87
|
+
generatedTypes = rel;
|
|
88
|
+
}
|
|
89
|
+
// Prefer a file literally named schema.graphql when several candidates exist.
|
|
90
|
+
schemaCandidates.sort((a, b) => {
|
|
91
|
+
const an = path.basename(a) === 'schema.graphql' ? 0 : 1;
|
|
92
|
+
const bn = path.basename(b) === 'schema.graphql' ? 0 : 1;
|
|
93
|
+
return an - bn || a.localeCompare(b);
|
|
94
|
+
});
|
|
95
|
+
let existingConfig;
|
|
96
|
+
for (const name of CONFIG_NAMES)
|
|
97
|
+
if (fs.existsSync(path.join(cwd, name))) {
|
|
98
|
+
existingConfig = name;
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
const hasNeo4jEnv = Object.keys(env).some((k) => k.startsWith('NEO4J_')) ||
|
|
102
|
+
(fs.existsSync(path.join(cwd, '.env')) &&
|
|
103
|
+
/^\s*NEO4J_/m.test(readHead(path.join(cwd, '.env'))));
|
|
104
|
+
return { schemaCandidates, generatedTypes, existingConfig, hasNeo4jEnv };
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=detect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detect.js","sourceRoot":"","sources":["../../../src/cli/detect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAclC,yEAAyE;AACzE,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC;IACxB,cAAc;IACd,MAAM;IACN,OAAO;IACP,MAAM;IACN,OAAO;IACP,UAAU;IACV,QAAQ;CACT,CAAC,CAAC;AACH,MAAM,SAAS,GAAG,CAAC,CAAC;AACpB,MAAM,YAAY,GAAG;IACnB,kBAAkB;IAClB,kBAAkB;IAClB,oBAAoB;CACrB,CAAC;AACF,6EAA6E;AAC7E,+EAA+E;AAC/E,8EAA8E;AAC9E,kDAAkD;AAClD,MAAM,gBAAgB,GAAG,4CAA4C,CAAC;AACtE,6EAA6E;AAC7E,oEAAoE;AACpE,MAAM,gBAAgB,GAAG,+CAA+C,CAAC;AAEzE,SAAS,IAAI,CAAC,IAAY,EAAE,KAAa,EAAE,GAAa;IACtD,IAAI,OAAoB,CAAC;IACzB,IAAI,CAAC;QACH,OAAO,GAAG,EAAE,CAAC,WAAW,CAAC,IAAI,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;IAC1D,CAAC;IAAC,MAAM,CAAC;QACP,OAAO;IACT,CAAC;IACD,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;QAC5B,IAAI,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,IAAI,KAAK,MAAM;YAAE,SAAS;QAClE,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;QACzC,IAAI,KAAK,CAAC,WAAW,EAAE,EAAE,CAAC;YACxB,IA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I,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;QACpD,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;YACpC,aAAa,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IAE1D,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,cAAc,EAAE,WAAW,EAAE,CAAC;AAC3E,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/cli/index.ts"],"names":[],"mappings":";AAGA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/cli/index.ts"],"names":[],"mappings":";AAGA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAoErC;;;GAGG;AACH,wBAAsB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,CAoFrE"}
|
package/dist/esm/cli/index.js
CHANGED
|
@@ -4,6 +4,7 @@ import { CliError, renderError } from './errors';
|
|
|
4
4
|
const HELP = `grafeo — CLI for grafeo-ogm
|
|
5
5
|
|
|
6
6
|
Usage:
|
|
7
|
+
grafeo init [--schema <path>] [--out <path>] [--seed] [--fresh] [--yes] [--force]
|
|
7
8
|
grafeo generate [--schema <path>] [--out <path>] [--watch] [--verify] [--poll <ms>]
|
|
8
9
|
grafeo db push [--schema <path>] [--dry-run] [--force-drop] [--yes]
|
|
9
10
|
[--uri <bolt-uri>] [--username <user>] [--database <name>]
|
|
@@ -20,6 +21,21 @@ Configuration:
|
|
|
20
21
|
NEO4J_DATABASE. The password is never accepted as a flag.`;
|
|
21
22
|
/** Focused per-command help, shown for \`grafeo <command> --help\`. */
|
|
22
23
|
const COMMAND_HELP = {
|
|
24
|
+
init: `grafeo init — scaffold (or auto-detect) a grafeo project
|
|
25
|
+
|
|
26
|
+
Usage:
|
|
27
|
+
grafeo init [--schema <path>] [--out <path>] [--seed] [--fresh] [--yes] [--force]
|
|
28
|
+
|
|
29
|
+
Detects an existing grafeo schema + generated types and wires grafeo.config.ts
|
|
30
|
+
to them. With nothing to detect (or --fresh), scaffolds a starter schema
|
|
31
|
+
(the Neo4j movie example) and config.
|
|
32
|
+
|
|
33
|
+
--schema <path> schema path (skip detection/prompt)
|
|
34
|
+
--out <path> generated-types output path
|
|
35
|
+
--seed also scaffold a seed.ts stub
|
|
36
|
+
--fresh ignore any detected setup and scaffold a new project
|
|
37
|
+
--yes non-interactive: accept detected values / defaults, no prompts
|
|
38
|
+
--force overwrite an existing grafeo.config.ts / seed.ts`,
|
|
23
39
|
generate: `grafeo generate — generate TypeScript types from your SDL
|
|
24
40
|
|
|
25
41
|
Usage:
|
|
@@ -96,6 +112,10 @@ export async function main(argv, io) {
|
|
|
96
112
|
return 0;
|
|
97
113
|
}
|
|
98
114
|
// Commands load lazily so `generate` never pays for neo4j-driver.
|
|
115
|
+
if (command === 'init') {
|
|
116
|
+
const { runInit } = await import('./commands/init');
|
|
117
|
+
return await runInit(commandArgs, io);
|
|
118
|
+
}
|
|
99
119
|
if (command === 'generate') {
|
|
100
120
|
const { runGenerate } = await import('./commands/generate');
|
|
101
121
|
return await runGenerate(commandArgs, io);
|
|
@@ -143,6 +163,21 @@ if (typeof require !== 'undefined' && require.main === module) {
|
|
|
143
163
|
rl.close();
|
|
144
164
|
}
|
|
145
165
|
},
|
|
166
|
+
// Free-text prompt for `grafeo init` (path entry, candidate selection).
|
|
167
|
+
prompt: async (question, defaultValue) => {
|
|
168
|
+
const rl = readline.createInterface({
|
|
169
|
+
input: process.stdin,
|
|
170
|
+
output: process.stdout,
|
|
171
|
+
});
|
|
172
|
+
try {
|
|
173
|
+
const suffix = defaultValue ? ` (${defaultValue})` : '';
|
|
174
|
+
const answer = (await rl.question(`${question}${suffix} `)).trim();
|
|
175
|
+
return answer || defaultValue || '';
|
|
176
|
+
}
|
|
177
|
+
finally {
|
|
178
|
+
rl.close();
|
|
179
|
+
}
|
|
180
|
+
},
|
|
146
181
|
};
|
|
147
182
|
void main(process.argv.slice(2), io).then((code) => {
|
|
148
183
|
process.exitCode = code;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/cli/index.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,QAAQ,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAGjD,MAAM,IAAI,GAAG
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/cli/index.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,QAAQ,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAGjD,MAAM,IAAI,GAAG;;;;;;;;;;;;;;;;;4DAiB+C,CAAC;AAE7D,uEAAuE;AACvE,MAAM,YAAY,GAA2B;IAC3C,IAAI,EAAE;;;;;;;;;;;;;;oEAc4D;IAClE,QAAQ,EAAE;;;;;;;;;kFASsE;IAChF,SAAS,EAAE;;;;;;;;;;gFAUmE;IAC9E,SAAS,EAAE;;;;;;kFAMqE;CACjF,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,IAAI,CAAC,IAAc,EAAE,EAAS;IAClD,qEAAqE;IACrE,oEAAoE;IACpE,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,YAAY,IAAI,CAAC,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;QACrE,OAAO,WAAW,CAChB,IAAI,QAAQ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CAAC;IAC1B,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/esm/cli/types.d.ts
CHANGED
|
@@ -61,6 +61,12 @@ export interface CliIO {
|
|
|
61
61
|
interactive?: boolean;
|
|
62
62
|
/** Prompt for yes/no confirmation (only called when interactive). */
|
|
63
63
|
confirm?(question: string): Promise<boolean>;
|
|
64
|
+
/**
|
|
65
|
+
* Prompt for a free-text answer (only called when interactive). Returns the
|
|
66
|
+
* trimmed input, or `defaultValue` when the user enters nothing. Used by
|
|
67
|
+
* `grafeo init` for path entry and detected-vs-fresh selection.
|
|
68
|
+
*/
|
|
69
|
+
prompt?(question: string, defaultValue?: string): Promise<string>;
|
|
64
70
|
/**
|
|
65
71
|
* Cooperative shutdown for long-running commands (`generate --watch`).
|
|
66
72
|
* The bin runs without one (Ctrl-C kills the process); tests abort it
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/cli/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAEvE,kFAAkF;AAClF,MAAM,WAAW,oBAAoB;IACnC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;;;GAKG;AACH,MAAM,WAAW,uBAAuB;IACtC,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,QAAQ,GAAG,WAAW,CAAC;CACrC;AAED,qDAAqD;AACrD,MAAM,WAAW,YAAY;IAC3B,qEAAqE;IACrE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,sEAAsE;IACtE,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,qDAAqD;IACrD,QA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AC;IACtB,qEAAqE;IACrE,OAAO,CAAC,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAC7C;;;;OAIG;IACH,MAAM,CAAC,CAAC,QAAQ,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAClE;;;;OAIG;IACH,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "grafeo-ogm",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.0",
|
|
4
4
|
"description": "Type-safe Neo4j ORM / OGM for TypeScript. Define your graph in GraphQL SDL, get fully typed Prisma-like CRUD, optimized Cypher, and zero-config code generation. Community successor to @neo4j/graphql-ogm.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Alejandro Guzman",
|