@noy-db/create 0.5.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 +283 -0
- package/dist/bin/create.d.ts +1 -0
- package/dist/bin/create.js +724 -0
- package/dist/bin/create.js.map +1 -0
- package/dist/bin/noy-db.d.ts +1 -0
- package/dist/bin/noy-db.js +548 -0
- package/dist/bin/noy-db.js.map +1 -0
- package/dist/index.d.ts +665 -0
- package/dist/index.js +902 -0
- package/dist/index.js.map +1 -0
- package/package.json +70 -0
- package/templates/nuxt-default/README.md +38 -0
- package/templates/nuxt-default/_gitignore +32 -0
- package/templates/nuxt-default/app/app.vue +37 -0
- package/templates/nuxt-default/app/pages/index.vue +21 -0
- package/templates/nuxt-default/app/pages/invoices.vue +62 -0
- package/templates/nuxt-default/app/stores/invoices.ts +23 -0
- package/templates/nuxt-default/nuxt.config.ts +30 -0
- package/templates/nuxt-default/package.json +28 -0
- package/templates/nuxt-default/tsconfig.json +3 -0
|
@@ -0,0 +1,548 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/bin/noy-db.ts
|
|
4
|
+
import pc from "picocolors";
|
|
5
|
+
|
|
6
|
+
// src/commands/add.ts
|
|
7
|
+
import { promises as fs } from "fs";
|
|
8
|
+
import path from "path";
|
|
9
|
+
function validateCollectionName(name) {
|
|
10
|
+
if (!name) return "Collection name is required";
|
|
11
|
+
if (!/^[a-z][a-z0-9-]*$/.test(name)) {
|
|
12
|
+
return "Collection name must start with a lowercase letter and contain only lowercase letters, digits, or hyphens";
|
|
13
|
+
}
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
async function addCollection(options) {
|
|
17
|
+
const err = validateCollectionName(options.name);
|
|
18
|
+
if (err) throw new Error(err);
|
|
19
|
+
const cwd = options.cwd ?? process.cwd();
|
|
20
|
+
const compartment = options.compartment ?? "default";
|
|
21
|
+
const name = options.name;
|
|
22
|
+
const PascalName = name.split("-").map((s) => s.length === 0 ? s : (s[0]?.toUpperCase() ?? "") + s.slice(1)).join("");
|
|
23
|
+
const useFnName = `use${PascalName}`;
|
|
24
|
+
const storePath = path.join(cwd, "app", "stores", `${name}.ts`);
|
|
25
|
+
const pagePath = path.join(cwd, "app", "pages", `${name}.vue`);
|
|
26
|
+
for (const target of [storePath, pagePath]) {
|
|
27
|
+
if (await pathExists(target)) {
|
|
28
|
+
throw new Error(`Refusing to overwrite existing file: ${target}`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
await fs.mkdir(path.dirname(storePath), { recursive: true });
|
|
32
|
+
await fs.mkdir(path.dirname(pagePath), { recursive: true });
|
|
33
|
+
await fs.writeFile(storePath, renderStore(name, PascalName, useFnName, compartment), "utf8");
|
|
34
|
+
await fs.writeFile(pagePath, renderPage(name, PascalName, useFnName), "utf8");
|
|
35
|
+
return { files: [storePath, pagePath] };
|
|
36
|
+
}
|
|
37
|
+
async function pathExists(p) {
|
|
38
|
+
try {
|
|
39
|
+
await fs.access(p);
|
|
40
|
+
return true;
|
|
41
|
+
} catch {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function renderStore(name, PascalName, useFnName, compartment) {
|
|
46
|
+
return `// Generated by \`noy-db add ${name}\`.
|
|
47
|
+
//
|
|
48
|
+
// Edit the ${PascalName} interface to match your domain, then call
|
|
49
|
+
// \`${useFnName}()\` from any component.
|
|
50
|
+
//
|
|
51
|
+
// defineNoydbStore is auto-imported by @noy-db/nuxt. The compartment
|
|
52
|
+
// id is the tenant/company namespace \u2014 change it if you have multiple.
|
|
53
|
+
|
|
54
|
+
export interface ${PascalName} {
|
|
55
|
+
id: string
|
|
56
|
+
name: string
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export const ${useFnName} = defineNoydbStore<${PascalName}>('${name}', {
|
|
60
|
+
compartment: '${compartment}',
|
|
61
|
+
})
|
|
62
|
+
`;
|
|
63
|
+
}
|
|
64
|
+
function renderPage(name, PascalName, useFnName) {
|
|
65
|
+
return `<!--
|
|
66
|
+
Generated by \`noy-db add ${name}\`.
|
|
67
|
+
Visit /${name} in your dev server.
|
|
68
|
+
-->
|
|
69
|
+
<script setup lang="ts">
|
|
70
|
+
const ${name} = ${useFnName}()
|
|
71
|
+
await ${name}.$ready
|
|
72
|
+
|
|
73
|
+
function addOne() {
|
|
74
|
+
${name}.add({
|
|
75
|
+
id: crypto.randomUUID(),
|
|
76
|
+
name: 'New ${PascalName}',
|
|
77
|
+
})
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function removeOne(id: string) {
|
|
81
|
+
${name}.remove(id)
|
|
82
|
+
}
|
|
83
|
+
</script>
|
|
84
|
+
|
|
85
|
+
<template>
|
|
86
|
+
<main>
|
|
87
|
+
<h1>${PascalName}</h1>
|
|
88
|
+
<button @click="addOne">Add ${PascalName}</button>
|
|
89
|
+
<ul>
|
|
90
|
+
<li v-for="item in ${name}.items" :key="item.id">
|
|
91
|
+
{{ item.name }}
|
|
92
|
+
<button @click="removeOne(item.id)">Delete</button>
|
|
93
|
+
</li>
|
|
94
|
+
</ul>
|
|
95
|
+
</main>
|
|
96
|
+
</template>
|
|
97
|
+
`;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// src/commands/verify.ts
|
|
101
|
+
import { createNoydb } from "@noy-db/core";
|
|
102
|
+
import { memory } from "@noy-db/memory";
|
|
103
|
+
async function verifyIntegrity() {
|
|
104
|
+
const start = performance.now();
|
|
105
|
+
try {
|
|
106
|
+
const db = await createNoydb({
|
|
107
|
+
adapter: memory(),
|
|
108
|
+
user: "noy-db-verify",
|
|
109
|
+
// The passphrase here is throwaway — the in-memory adapter never
|
|
110
|
+
// persists anything, and the KEK is destroyed when we call close()
|
|
111
|
+
// a few lines down. We use a non-trivial value just to exercise
|
|
112
|
+
// PBKDF2 properly.
|
|
113
|
+
secret: "noy-db-verify-passphrase-2026"
|
|
114
|
+
});
|
|
115
|
+
const company = await db.openCompartment("verify-co");
|
|
116
|
+
const collection = company.collection("verify");
|
|
117
|
+
const original = { id: "verify-1", n: 42 };
|
|
118
|
+
await collection.put("verify-1", original);
|
|
119
|
+
const got = await collection.get("verify-1");
|
|
120
|
+
if (!got || got.id !== original.id || got.n !== original.n) {
|
|
121
|
+
return fail(start, `Round-trip mismatch: got ${JSON.stringify(got)}`);
|
|
122
|
+
}
|
|
123
|
+
const found = collection.query().where("n", "==", 42).toArray();
|
|
124
|
+
if (found.length !== 1) {
|
|
125
|
+
return fail(start, `Query DSL mismatch: expected 1 result, got ${found.length}`);
|
|
126
|
+
}
|
|
127
|
+
db.close();
|
|
128
|
+
return {
|
|
129
|
+
ok: true,
|
|
130
|
+
message: "noy-db integrity check passed",
|
|
131
|
+
durationMs: Math.round(performance.now() - start)
|
|
132
|
+
};
|
|
133
|
+
} catch (err) {
|
|
134
|
+
return fail(start, `Integrity check threw: ${err.message}`);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
function fail(start, message) {
|
|
138
|
+
return {
|
|
139
|
+
ok: false,
|
|
140
|
+
message,
|
|
141
|
+
durationMs: Math.round(performance.now() - start)
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// src/commands/rotate.ts
|
|
146
|
+
import { createNoydb as createNoydb2 } from "@noy-db/core";
|
|
147
|
+
import { jsonFile } from "@noy-db/file";
|
|
148
|
+
|
|
149
|
+
// src/commands/shared.ts
|
|
150
|
+
import { password, isCancel, cancel } from "@clack/prompts";
|
|
151
|
+
var VALID_ROLES = ["owner", "admin", "operator", "viewer", "client"];
|
|
152
|
+
var defaultReadPassphrase = async (label) => {
|
|
153
|
+
const value = await password({
|
|
154
|
+
message: label,
|
|
155
|
+
// Basic sanity: reject empty strings up front. We don't enforce
|
|
156
|
+
// length here because the caller's KEK-derivation step will
|
|
157
|
+
// reject weak passphrases with its own, richer error.
|
|
158
|
+
validate: (v) => v.length === 0 ? "Passphrase cannot be empty" : void 0
|
|
159
|
+
});
|
|
160
|
+
if (isCancel(value)) {
|
|
161
|
+
cancel("Cancelled.");
|
|
162
|
+
process.exit(1);
|
|
163
|
+
}
|
|
164
|
+
return value;
|
|
165
|
+
};
|
|
166
|
+
function assertRole(input) {
|
|
167
|
+
if (!VALID_ROLES.includes(input)) {
|
|
168
|
+
throw new Error(
|
|
169
|
+
`Invalid role "${input}" \u2014 must be one of: ${VALID_ROLES.join(", ")}`
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
return input;
|
|
173
|
+
}
|
|
174
|
+
function parseCollectionList(input) {
|
|
175
|
+
if (!input) return null;
|
|
176
|
+
const parts = input.split(",").map((s) => s.trim()).filter((s) => s.length > 0);
|
|
177
|
+
return parts.length > 0 ? parts : null;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// src/commands/rotate.ts
|
|
181
|
+
async function rotate(options) {
|
|
182
|
+
const readPassphrase = options.readPassphrase ?? defaultReadPassphrase;
|
|
183
|
+
const buildAdapter = options.buildAdapter ?? ((dir) => jsonFile({ dir }));
|
|
184
|
+
const createDb = options.createDb ?? createNoydb2;
|
|
185
|
+
const secret = await readPassphrase(`Passphrase for ${options.user}`);
|
|
186
|
+
let db = null;
|
|
187
|
+
try {
|
|
188
|
+
db = await createDb({
|
|
189
|
+
adapter: buildAdapter(options.dir),
|
|
190
|
+
user: options.user,
|
|
191
|
+
secret
|
|
192
|
+
});
|
|
193
|
+
const compartment = await db.openCompartment(options.compartment);
|
|
194
|
+
const targets = options.collections && options.collections.length > 0 ? options.collections : await compartment.collections();
|
|
195
|
+
if (targets.length === 0) {
|
|
196
|
+
throw new Error(
|
|
197
|
+
`Compartment "${options.compartment}" has no collections to rotate.`
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
await db.rotate(options.compartment, targets);
|
|
201
|
+
return { rotated: targets };
|
|
202
|
+
} finally {
|
|
203
|
+
db?.close();
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// src/commands/add-user.ts
|
|
208
|
+
import { createNoydb as createNoydb3 } from "@noy-db/core";
|
|
209
|
+
import { jsonFile as jsonFile2 } from "@noy-db/file";
|
|
210
|
+
async function addUser(options) {
|
|
211
|
+
const readPassphrase = options.readPassphrase ?? defaultReadPassphrase;
|
|
212
|
+
const buildAdapter = options.buildAdapter ?? ((dir) => jsonFile2({ dir }));
|
|
213
|
+
const createDb = options.createDb ?? createNoydb3;
|
|
214
|
+
if ((options.role === "operator" || options.role === "client") && (!options.permissions || Object.keys(options.permissions).length === 0)) {
|
|
215
|
+
throw new Error(
|
|
216
|
+
`Role "${options.role}" requires explicit --collections \u2014 e.g. --collections invoices:rw,clients:ro`
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
const callerSecret = await readPassphrase(
|
|
220
|
+
`Your passphrase (${options.callerUser})`
|
|
221
|
+
);
|
|
222
|
+
const newSecret = await readPassphrase(
|
|
223
|
+
`New passphrase for ${options.newUserId}`
|
|
224
|
+
);
|
|
225
|
+
const confirmSecret = await readPassphrase(
|
|
226
|
+
`Confirm passphrase for ${options.newUserId}`
|
|
227
|
+
);
|
|
228
|
+
if (newSecret !== confirmSecret) {
|
|
229
|
+
throw new Error(`Passphrases do not match \u2014 grant aborted.`);
|
|
230
|
+
}
|
|
231
|
+
let db = null;
|
|
232
|
+
try {
|
|
233
|
+
db = await createDb({
|
|
234
|
+
adapter: buildAdapter(options.dir),
|
|
235
|
+
user: options.callerUser,
|
|
236
|
+
secret: callerSecret
|
|
237
|
+
});
|
|
238
|
+
const grantOpts = {
|
|
239
|
+
userId: options.newUserId,
|
|
240
|
+
displayName: options.newUserDisplayName ?? options.newUserId,
|
|
241
|
+
role: options.role,
|
|
242
|
+
passphrase: newSecret,
|
|
243
|
+
...options.permissions ? { permissions: options.permissions } : {}
|
|
244
|
+
};
|
|
245
|
+
await db.grant(options.compartment, grantOpts);
|
|
246
|
+
return {
|
|
247
|
+
userId: options.newUserId,
|
|
248
|
+
role: options.role
|
|
249
|
+
};
|
|
250
|
+
} finally {
|
|
251
|
+
db?.close();
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// src/commands/backup.ts
|
|
256
|
+
import { promises as fs2 } from "fs";
|
|
257
|
+
import path2 from "path";
|
|
258
|
+
import { createNoydb as createNoydb4 } from "@noy-db/core";
|
|
259
|
+
import { jsonFile as jsonFile3 } from "@noy-db/file";
|
|
260
|
+
function resolveBackupTarget(target, cwd = process.cwd()) {
|
|
261
|
+
let raw = target;
|
|
262
|
+
if (target.startsWith("file://")) {
|
|
263
|
+
raw = target.slice("file://".length);
|
|
264
|
+
} else if (target.includes("://")) {
|
|
265
|
+
throw new Error(
|
|
266
|
+
`Unsupported backup target scheme: "${target.split("://")[0]}://". Only file:// and plain filesystem paths are supported in v0.5. S3 backups will land in a follow-up.`
|
|
267
|
+
);
|
|
268
|
+
}
|
|
269
|
+
return path2.resolve(cwd, raw);
|
|
270
|
+
}
|
|
271
|
+
async function backup(options) {
|
|
272
|
+
const readPassphrase = options.readPassphrase ?? defaultReadPassphrase;
|
|
273
|
+
const buildAdapter = options.buildAdapter ?? ((dir) => jsonFile3({ dir }));
|
|
274
|
+
const createDb = options.createDb ?? createNoydb4;
|
|
275
|
+
const absolutePath = resolveBackupTarget(options.target);
|
|
276
|
+
const secret = await readPassphrase(`Passphrase for ${options.user}`);
|
|
277
|
+
let db = null;
|
|
278
|
+
try {
|
|
279
|
+
db = await createDb({
|
|
280
|
+
adapter: buildAdapter(options.dir),
|
|
281
|
+
user: options.user,
|
|
282
|
+
secret
|
|
283
|
+
});
|
|
284
|
+
const compartment = await db.openCompartment(options.compartment);
|
|
285
|
+
const serialized = await compartment.dump();
|
|
286
|
+
await fs2.mkdir(path2.dirname(absolutePath), { recursive: true });
|
|
287
|
+
await fs2.writeFile(absolutePath, serialized, "utf8");
|
|
288
|
+
return {
|
|
289
|
+
path: absolutePath,
|
|
290
|
+
bytes: Buffer.byteLength(serialized, "utf8")
|
|
291
|
+
};
|
|
292
|
+
} finally {
|
|
293
|
+
db?.close();
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
// src/bin/noy-db.ts
|
|
298
|
+
var HELP = `Usage: noy-db <command> [args]
|
|
299
|
+
|
|
300
|
+
Commands:
|
|
301
|
+
add <collection> Scaffold a new collection store + page
|
|
302
|
+
add user <userId> <role> [options] Grant a new user access to a compartment
|
|
303
|
+
verify In-memory crypto integrity check
|
|
304
|
+
rotate [options] Rotate DEKs for a compartment
|
|
305
|
+
backup <target> [options] Dump a compartment to a file
|
|
306
|
+
help Show this message
|
|
307
|
+
|
|
308
|
+
Common options for rotate / add user / backup:
|
|
309
|
+
--dir <path> Data directory (file adapter). Default: ./data
|
|
310
|
+
--compartment <name> Compartment (tenant) name. Required.
|
|
311
|
+
--user <id> Your user id in the compartment. Required.
|
|
312
|
+
--collections <list> Comma-separated collection list. Format:
|
|
313
|
+
rotate: invoices,clients
|
|
314
|
+
add user: invoices:rw,clients:ro (operator/client only)
|
|
315
|
+
|
|
316
|
+
Examples:
|
|
317
|
+
noy-db add invoices
|
|
318
|
+
noy-db add user accountant-ann operator --dir ./data --compartment demo-co --user owner-alice --collections invoices:rw,clients:ro
|
|
319
|
+
noy-db verify
|
|
320
|
+
noy-db rotate --dir ./data --compartment demo-co --user owner-alice
|
|
321
|
+
noy-db backup ./backups/demo-co-2026-04-07.json --dir ./data --compartment demo-co --user owner-alice
|
|
322
|
+
|
|
323
|
+
Run from the root of a project that already has a noy-db file
|
|
324
|
+
adapter directory in place. For new projects, use
|
|
325
|
+
\`npm create @noy-db\` instead.
|
|
326
|
+
`;
|
|
327
|
+
async function main() {
|
|
328
|
+
const [, , command, ...rest] = process.argv;
|
|
329
|
+
switch (command) {
|
|
330
|
+
case void 0:
|
|
331
|
+
case "help":
|
|
332
|
+
case "-h":
|
|
333
|
+
case "--help":
|
|
334
|
+
process.stdout.write(HELP);
|
|
335
|
+
return;
|
|
336
|
+
case "add":
|
|
337
|
+
await runAdd(rest);
|
|
338
|
+
return;
|
|
339
|
+
case "verify":
|
|
340
|
+
await runVerify();
|
|
341
|
+
return;
|
|
342
|
+
case "rotate":
|
|
343
|
+
await runRotate(rest);
|
|
344
|
+
return;
|
|
345
|
+
case "backup":
|
|
346
|
+
await runBackup(rest);
|
|
347
|
+
return;
|
|
348
|
+
default:
|
|
349
|
+
process.stderr.write(`${pc.red("error:")} unknown command '${command}'
|
|
350
|
+
|
|
351
|
+
${HELP}`);
|
|
352
|
+
process.exit(2);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
async function runAdd(args) {
|
|
356
|
+
const first = args[0];
|
|
357
|
+
if (first === "user") {
|
|
358
|
+
await runAddUser(args.slice(1));
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
if (!first) {
|
|
362
|
+
process.stderr.write(
|
|
363
|
+
`${pc.red("error:")} \`noy-db add\` requires either a collection name or the \`user\` subcommand
|
|
364
|
+
|
|
365
|
+
Examples:
|
|
366
|
+
noy-db add invoices
|
|
367
|
+
noy-db add user alice operator ...
|
|
368
|
+
`
|
|
369
|
+
);
|
|
370
|
+
process.exit(2);
|
|
371
|
+
}
|
|
372
|
+
try {
|
|
373
|
+
const result = await addCollection({ name: first });
|
|
374
|
+
process.stdout.write(`${pc.green("\u2714")} Created:
|
|
375
|
+
`);
|
|
376
|
+
for (const file of result.files) {
|
|
377
|
+
process.stdout.write(` ${pc.dim("\u2192")} ${file}
|
|
378
|
+
`);
|
|
379
|
+
}
|
|
380
|
+
process.stdout.write(
|
|
381
|
+
`
|
|
382
|
+
Next: visit ${pc.cyan(`/${first}`)} in your dev server, then edit ${pc.bold(`app/stores/${first}.ts`)} to match your domain.
|
|
383
|
+
`
|
|
384
|
+
);
|
|
385
|
+
} catch (err) {
|
|
386
|
+
process.stderr.write(`${pc.red("error:")} ${err.message}
|
|
387
|
+
`);
|
|
388
|
+
process.exit(1);
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
async function runVerify() {
|
|
392
|
+
process.stdout.write(`${pc.dim("\u25B8 Running noy-db integrity check\u2026")}
|
|
393
|
+
`);
|
|
394
|
+
const result = await verifyIntegrity();
|
|
395
|
+
if (result.ok) {
|
|
396
|
+
process.stdout.write(`${pc.green("\u2714")} ${result.message} ${pc.dim(`(${result.durationMs}ms)`)}
|
|
397
|
+
`);
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
process.stderr.write(`${pc.red("\u2718")} ${result.message} ${pc.dim(`(${result.durationMs}ms)`)}
|
|
401
|
+
`);
|
|
402
|
+
process.exit(1);
|
|
403
|
+
}
|
|
404
|
+
async function runAddUser(args) {
|
|
405
|
+
const userId = args[0];
|
|
406
|
+
const roleInput = args[1];
|
|
407
|
+
if (!userId || !roleInput) {
|
|
408
|
+
process.stderr.write(
|
|
409
|
+
`${pc.red("error:")} \`noy-db add user\` requires <userId> <role>
|
|
410
|
+
|
|
411
|
+
Example: noy-db add user ann operator --dir ./data --compartment demo-co --user owner-alice --collections invoices:rw
|
|
412
|
+
`
|
|
413
|
+
);
|
|
414
|
+
process.exit(2);
|
|
415
|
+
}
|
|
416
|
+
let role;
|
|
417
|
+
try {
|
|
418
|
+
role = assertRole(roleInput);
|
|
419
|
+
} catch (err) {
|
|
420
|
+
process.stderr.write(`${pc.red("error:")} ${err.message}
|
|
421
|
+
`);
|
|
422
|
+
process.exit(2);
|
|
423
|
+
return;
|
|
424
|
+
}
|
|
425
|
+
const flags = parseFlags(args.slice(2));
|
|
426
|
+
const dir = flags.dir ?? "./data";
|
|
427
|
+
const compartment = requireFlag(flags, "compartment");
|
|
428
|
+
const callerUser = requireFlag(flags, "user");
|
|
429
|
+
const permissions = parsePermissions(flags["collections"]);
|
|
430
|
+
const opts = {
|
|
431
|
+
dir,
|
|
432
|
+
compartment,
|
|
433
|
+
callerUser,
|
|
434
|
+
newUserId: userId,
|
|
435
|
+
role
|
|
436
|
+
};
|
|
437
|
+
if (flags["display-name"]) opts.newUserDisplayName = flags["display-name"];
|
|
438
|
+
if (permissions) opts.permissions = permissions;
|
|
439
|
+
try {
|
|
440
|
+
const result = await addUser(opts);
|
|
441
|
+
process.stdout.write(
|
|
442
|
+
`${pc.green("\u2714")} Granted ${pc.bold(result.role)} access to ${pc.cyan(result.userId)} in compartment ${pc.cyan(compartment)}.
|
|
443
|
+
`
|
|
444
|
+
);
|
|
445
|
+
} catch (err) {
|
|
446
|
+
process.stderr.write(`${pc.red("error:")} ${err.message}
|
|
447
|
+
`);
|
|
448
|
+
process.exit(1);
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
async function runRotate(args) {
|
|
452
|
+
const flags = parseFlags(args);
|
|
453
|
+
const dir = flags.dir ?? "./data";
|
|
454
|
+
const compartment = requireFlag(flags, "compartment");
|
|
455
|
+
const user = requireFlag(flags, "user");
|
|
456
|
+
const opts = { dir, compartment, user };
|
|
457
|
+
const collections = parseCollectionList(flags["collections"]);
|
|
458
|
+
if (collections) opts.collections = collections;
|
|
459
|
+
try {
|
|
460
|
+
const result = await rotate(opts);
|
|
461
|
+
process.stdout.write(
|
|
462
|
+
`${pc.green("\u2714")} Rotated ${pc.bold(String(result.rotated.length))} collection(s) in ${pc.cyan(compartment)}:
|
|
463
|
+
`
|
|
464
|
+
);
|
|
465
|
+
for (const name of result.rotated) {
|
|
466
|
+
process.stdout.write(` ${pc.dim("\u2192")} ${name}
|
|
467
|
+
`);
|
|
468
|
+
}
|
|
469
|
+
} catch (err) {
|
|
470
|
+
process.stderr.write(`${pc.red("error:")} ${err.message}
|
|
471
|
+
`);
|
|
472
|
+
process.exit(1);
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
async function runBackup(args) {
|
|
476
|
+
const target = args[0];
|
|
477
|
+
if (!target) {
|
|
478
|
+
process.stderr.write(
|
|
479
|
+
`${pc.red("error:")} \`noy-db backup\` requires a target path
|
|
480
|
+
|
|
481
|
+
Example: noy-db backup ./backups/demo.json --dir ./data --compartment demo-co --user owner-alice
|
|
482
|
+
`
|
|
483
|
+
);
|
|
484
|
+
process.exit(2);
|
|
485
|
+
}
|
|
486
|
+
const flags = parseFlags(args.slice(1));
|
|
487
|
+
const dir = flags.dir ?? "./data";
|
|
488
|
+
const compartment = requireFlag(flags, "compartment");
|
|
489
|
+
const user = requireFlag(flags, "user");
|
|
490
|
+
try {
|
|
491
|
+
const result = await backup({ dir, compartment, user, target });
|
|
492
|
+
process.stdout.write(
|
|
493
|
+
`${pc.green("\u2714")} Wrote backup: ${pc.cyan(result.path)} ${pc.dim(`(${result.bytes} bytes)`)}
|
|
494
|
+
`
|
|
495
|
+
);
|
|
496
|
+
} catch (err) {
|
|
497
|
+
process.stderr.write(`${pc.red("error:")} ${err.message}
|
|
498
|
+
`);
|
|
499
|
+
process.exit(1);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
function parseFlags(args) {
|
|
503
|
+
const out = {};
|
|
504
|
+
for (let i = 0; i < args.length; i++) {
|
|
505
|
+
const arg = args[i];
|
|
506
|
+
if (!arg || !arg.startsWith("--")) continue;
|
|
507
|
+
const key = arg.slice(2);
|
|
508
|
+
const next = args[i + 1];
|
|
509
|
+
if (next && !next.startsWith("--")) {
|
|
510
|
+
out[key] = next;
|
|
511
|
+
i++;
|
|
512
|
+
} else {
|
|
513
|
+
out[key] = "true";
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
return out;
|
|
517
|
+
}
|
|
518
|
+
function requireFlag(flags, name) {
|
|
519
|
+
const value = flags[name];
|
|
520
|
+
if (!value) {
|
|
521
|
+
process.stderr.write(
|
|
522
|
+
`${pc.red("error:")} missing required flag --${name}
|
|
523
|
+
`
|
|
524
|
+
);
|
|
525
|
+
process.exit(2);
|
|
526
|
+
}
|
|
527
|
+
return value;
|
|
528
|
+
}
|
|
529
|
+
function parsePermissions(input) {
|
|
530
|
+
if (!input) return null;
|
|
531
|
+
const out = {};
|
|
532
|
+
for (const pair of input.split(",").map((s) => s.trim()).filter(Boolean)) {
|
|
533
|
+
const [name, mode] = pair.split(":");
|
|
534
|
+
if (!name || !mode || mode !== "rw" && mode !== "ro") {
|
|
535
|
+
throw new Error(
|
|
536
|
+
`Invalid --collections entry "${pair}" \u2014 expected "name:rw" or "name:ro"`
|
|
537
|
+
);
|
|
538
|
+
}
|
|
539
|
+
out[name] = mode;
|
|
540
|
+
}
|
|
541
|
+
return Object.keys(out).length > 0 ? out : null;
|
|
542
|
+
}
|
|
543
|
+
main().catch((err) => {
|
|
544
|
+
process.stderr.write(`${pc.red("fatal:")} ${err.message}
|
|
545
|
+
`);
|
|
546
|
+
process.exit(1);
|
|
547
|
+
});
|
|
548
|
+
//# sourceMappingURL=noy-db.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/bin/noy-db.ts","../../src/commands/add.ts","../../src/commands/verify.ts","../../src/commands/rotate.ts","../../src/commands/shared.ts","../../src/commands/add-user.ts","../../src/commands/backup.ts"],"sourcesContent":["#!/usr/bin/env node\n/**\n * The `noy-db` bin. Invoked from inside an existing project by\n * `pnpm exec noy-db <command>`, `npx noy-db <command>`, etc.\n *\n * Subcommands (v0.5.0):\n *\n * add <collection> Scaffold store + page files\n * add user <id> <role> [--collections…] Grant a new user access\n * verify In-memory integrity check\n * rotate --compartment … --user … Rotate DEKs for a compartment\n * backup <target> --compartment … … Dump a compartment to a file\n * help Show usage\n *\n * Future subcommands (deferred to a follow-up):\n * seed Re-run the project's seeder script (needs\n * a design decision on how seed scripts auth)\n * backup s3://... S3 targets (would bundle @aws-sdk; lives in\n * an optional companion package instead)\n * restore <file> Load a dumped backup into a compartment\n *\n * ## Dispatcher design\n *\n * The dispatcher is intentionally dead simple: read argv[2], pick\n * a handler, pass the remaining args. No flag DSL, no auto-help\n * generation. Each subcommand's argv parser lives next to the\n * subcommand itself so the wiring is obvious and the pure\n * subcommand functions stay testable in isolation.\n *\n * ## Passphrase handling invariants\n *\n * Every subcommand that unlocks a compartment goes through the\n * shared `defaultReadPassphrase` helper (see `commands/shared.ts`).\n * That helper:\n *\n * - Uses @clack/prompts `password()` so nothing echoes to stdout\n * - Never logs the returned value\n * - Validates \"not empty\" up front; the real strength check\n * happens inside the core's KEK derivation\n * - Aborts the process on Ctrl-C before any I/O happens\n *\n * The passphrase never leaves the closure in which it was read —\n * every subcommand closes the Noydb instance in a `finally` block\n * so the KEK is cleared from memory on the way out.\n */\n\nimport pc from 'picocolors'\nimport { addCollection } from '../commands/add.js'\nimport { verifyIntegrity } from '../commands/verify.js'\nimport { rotate, type RotateOptions } from '../commands/rotate.js'\nimport { addUser, type AddUserOptions } from '../commands/add-user.js'\nimport { backup } from '../commands/backup.js'\nimport { assertRole, parseCollectionList } from '../commands/shared.js'\n\nconst HELP = `Usage: noy-db <command> [args]\n\nCommands:\n add <collection> Scaffold a new collection store + page\n add user <userId> <role> [options] Grant a new user access to a compartment\n verify In-memory crypto integrity check\n rotate [options] Rotate DEKs for a compartment\n backup <target> [options] Dump a compartment to a file\n help Show this message\n\nCommon options for rotate / add user / backup:\n --dir <path> Data directory (file adapter). Default: ./data\n --compartment <name> Compartment (tenant) name. Required.\n --user <id> Your user id in the compartment. Required.\n --collections <list> Comma-separated collection list. Format:\n rotate: invoices,clients\n add user: invoices:rw,clients:ro (operator/client only)\n\nExamples:\n noy-db add invoices\n noy-db add user accountant-ann operator --dir ./data --compartment demo-co --user owner-alice --collections invoices:rw,clients:ro\n noy-db verify\n noy-db rotate --dir ./data --compartment demo-co --user owner-alice\n noy-db backup ./backups/demo-co-2026-04-07.json --dir ./data --compartment demo-co --user owner-alice\n\nRun from the root of a project that already has a noy-db file\nadapter directory in place. For new projects, use\n\\`npm create @noy-db\\` instead.\n`\n\nasync function main(): Promise<void> {\n const [, , command, ...rest] = process.argv\n\n switch (command) {\n case undefined:\n case 'help':\n case '-h':\n case '--help':\n process.stdout.write(HELP)\n return\n\n case 'add':\n await runAdd(rest)\n return\n\n case 'verify':\n await runVerify()\n return\n\n case 'rotate':\n await runRotate(rest)\n return\n\n case 'backup':\n await runBackup(rest)\n return\n\n default:\n process.stderr.write(`${pc.red('error:')} unknown command '${command}'\\n\\n${HELP}`)\n process.exit(2)\n }\n}\n\n// ─── `add` dispatcher — branches between `add <collection>` and `add user …` ─\n\nasync function runAdd(args: string[]): Promise<void> {\n const first = args[0]\n if (first === 'user') {\n await runAddUser(args.slice(1))\n return\n }\n // Legacy path: `noy-db add <collection>` scaffolds store + page files.\n if (!first) {\n process.stderr.write(\n `${pc.red('error:')} \\`noy-db add\\` requires either a collection name or the \\`user\\` subcommand\\n\\n` +\n `Examples:\\n noy-db add invoices\\n noy-db add user alice operator ...\\n`,\n )\n process.exit(2)\n }\n try {\n const result = await addCollection({ name: first })\n process.stdout.write(`${pc.green('✔')} Created:\\n`)\n for (const file of result.files) {\n process.stdout.write(` ${pc.dim('→')} ${file}\\n`)\n }\n process.stdout.write(\n `\\nNext: visit ${pc.cyan(`/${first}`)} in your dev server, then edit ${pc.bold(`app/stores/${first}.ts`)} to match your domain.\\n`,\n )\n } catch (err) {\n process.stderr.write(`${pc.red('error:')} ${(err as Error).message}\\n`)\n process.exit(1)\n }\n}\n\n// ─── `verify` ──────────────────────────────────────────────────────────\n\nasync function runVerify(): Promise<void> {\n process.stdout.write(`${pc.dim('▸ Running noy-db integrity check…')}\\n`)\n const result = await verifyIntegrity()\n if (result.ok) {\n process.stdout.write(`${pc.green('✔')} ${result.message} ${pc.dim(`(${result.durationMs}ms)`)}\\n`)\n return\n }\n process.stderr.write(`${pc.red('✘')} ${result.message} ${pc.dim(`(${result.durationMs}ms)`)}\\n`)\n process.exit(1)\n}\n\n// ─── `add user` ────────────────────────────────────────────────────────\n\nasync function runAddUser(args: string[]): Promise<void> {\n // Positional: userId, role. Then flag bag.\n const userId = args[0]\n const roleInput = args[1]\n if (!userId || !roleInput) {\n process.stderr.write(\n `${pc.red('error:')} \\`noy-db add user\\` requires <userId> <role>\\n\\n` +\n `Example: noy-db add user ann operator --dir ./data --compartment demo-co --user owner-alice --collections invoices:rw\\n`,\n )\n process.exit(2)\n }\n\n let role\n try {\n role = assertRole(roleInput)\n } catch (err) {\n process.stderr.write(`${pc.red('error:')} ${(err as Error).message}\\n`)\n process.exit(2)\n return\n }\n\n const flags = parseFlags(args.slice(2))\n const dir = flags.dir ?? './data'\n const compartment = requireFlag(flags, 'compartment')\n const callerUser = requireFlag(flags, 'user')\n\n const permissions = parsePermissions(flags['collections'])\n\n const opts: AddUserOptions = {\n dir,\n compartment,\n callerUser,\n newUserId: userId,\n role,\n }\n if (flags['display-name']) opts.newUserDisplayName = flags['display-name']\n if (permissions) opts.permissions = permissions\n\n try {\n const result = await addUser(opts)\n process.stdout.write(\n `${pc.green('✔')} Granted ${pc.bold(result.role)} access to ${pc.cyan(result.userId)} in compartment ${pc.cyan(compartment)}.\\n`,\n )\n } catch (err) {\n process.stderr.write(`${pc.red('error:')} ${(err as Error).message}\\n`)\n process.exit(1)\n }\n}\n\n// ─── `rotate` ──────────────────────────────────────────────────────────\n\nasync function runRotate(args: string[]): Promise<void> {\n const flags = parseFlags(args)\n const dir = flags.dir ?? './data'\n const compartment = requireFlag(flags, 'compartment')\n const user = requireFlag(flags, 'user')\n\n const opts: RotateOptions = { dir, compartment, user }\n const collections = parseCollectionList(flags['collections'])\n if (collections) opts.collections = collections\n\n try {\n const result = await rotate(opts)\n process.stdout.write(\n `${pc.green('✔')} Rotated ${pc.bold(String(result.rotated.length))} collection(s) in ${pc.cyan(compartment)}:\\n`,\n )\n for (const name of result.rotated) {\n process.stdout.write(` ${pc.dim('→')} ${name}\\n`)\n }\n } catch (err) {\n process.stderr.write(`${pc.red('error:')} ${(err as Error).message}\\n`)\n process.exit(1)\n }\n}\n\n// ─── `backup` ──────────────────────────────────────────────────────────\n\nasync function runBackup(args: string[]): Promise<void> {\n const target = args[0]\n if (!target) {\n process.stderr.write(\n `${pc.red('error:')} \\`noy-db backup\\` requires a target path\\n\\n` +\n `Example: noy-db backup ./backups/demo.json --dir ./data --compartment demo-co --user owner-alice\\n`,\n )\n process.exit(2)\n }\n\n const flags = parseFlags(args.slice(1))\n const dir = flags.dir ?? './data'\n const compartment = requireFlag(flags, 'compartment')\n const user = requireFlag(flags, 'user')\n\n try {\n const result = await backup({ dir, compartment, user, target })\n process.stdout.write(\n `${pc.green('✔')} Wrote backup: ${pc.cyan(result.path)} ${pc.dim(`(${result.bytes} bytes)`)}\\n`,\n )\n } catch (err) {\n process.stderr.write(`${pc.red('error:')} ${(err as Error).message}\\n`)\n process.exit(1)\n }\n}\n\n// ─── Shared argv helpers ───────────────────────────────────────────────\n\n/**\n * Parse a sequence of `--key value` flag pairs into a record.\n * Boolean flags (`--flag` with no value) become `\"true\"`. Unknown\n * shapes (positional args after the known set) are ignored — the\n * caller has already peeled positionals before passing in.\n */\nfunction parseFlags(args: string[]): Record<string, string> {\n const out: Record<string, string> = {}\n for (let i = 0; i < args.length; i++) {\n const arg = args[i]\n if (!arg || !arg.startsWith('--')) continue\n const key = arg.slice(2)\n const next = args[i + 1]\n if (next && !next.startsWith('--')) {\n out[key] = next\n i++\n } else {\n out[key] = 'true'\n }\n }\n return out\n}\n\nfunction requireFlag(flags: Record<string, string>, name: string): string {\n const value = flags[name]\n if (!value) {\n process.stderr.write(\n `${pc.red('error:')} missing required flag --${name}\\n`,\n )\n process.exit(2)\n }\n return value\n}\n\n/**\n * Parse `--collections invoices:rw,clients:ro` into a\n * `{ invoices: 'rw', clients: 'ro' }` record. Returns `null` when\n * the input is empty or undefined.\n */\nfunction parsePermissions(\n input: string | undefined,\n): Record<string, 'rw' | 'ro'> | null {\n if (!input) return null\n const out: Record<string, 'rw' | 'ro'> = {}\n for (const pair of input.split(',').map((s) => s.trim()).filter(Boolean)) {\n const [name, mode] = pair.split(':')\n if (!name || !mode || (mode !== 'rw' && mode !== 'ro')) {\n throw new Error(\n `Invalid --collections entry \"${pair}\" — expected \"name:rw\" or \"name:ro\"`,\n )\n }\n out[name] = mode\n }\n return Object.keys(out).length > 0 ? out : null\n}\n\nmain().catch((err: unknown) => {\n process.stderr.write(`${pc.red('fatal:')} ${(err as Error).message}\\n`)\n process.exit(1)\n})\n","/**\n * `noy-db add <collection>` — scaffold a new collection inside an existing\n * Nuxt 4 project that already has `@noy-db/nuxt` configured.\n *\n * The command writes two files:\n *\n * 1. `app/stores/<collection>.ts` — a `defineNoydbStore<T>()` call with\n * a placeholder `T` interface and one example field. The user fills\n * in the real shape after the file is created.\n *\n * 2. `app/pages/<collection>.vue` — a minimal CRUD page that lists,\n * adds, and deletes records. The store ID and collection name are\n * derived from the argument; everything else is boilerplate.\n *\n * The command refuses to overwrite existing files. If either target\n * already exists it logs which one and exits non-zero — the user has to\n * delete or move the file first. There's no `--force` because forcing an\n * overwrite of generated UI code is almost always a footgun in disguise.\n */\n\nimport { promises as fs } from 'node:fs'\nimport path from 'node:path'\n\nexport interface AddCollectionOptions {\n /** The collection name. Must be a lowercase identifier. */\n name: string\n /** Project root. Defaults to `process.cwd()`. */\n cwd?: string\n /** Compartment id to embed in the generated store. Defaults to `default`. */\n compartment?: string\n}\n\n/**\n * Result returned to callers (the bin entry uses this to format output;\n * tests assert on the file paths).\n */\nexport interface AddCollectionResult {\n /** Files written, in the order they were created. */\n files: string[]\n}\n\n/**\n * Lowercase identifier check, narrower than the project-name check —\n * collection names become Vue component names, Pinia store IDs, AND TS\n * symbols, so we keep them simple: letters, digits, hyphens, must start\n * with a letter.\n */\nexport function validateCollectionName(name: string): string | null {\n if (!name) return 'Collection name is required'\n if (!/^[a-z][a-z0-9-]*$/.test(name)) {\n return 'Collection name must start with a lowercase letter and contain only lowercase letters, digits, or hyphens'\n }\n return null\n}\n\nexport async function addCollection(\n options: AddCollectionOptions,\n): Promise<AddCollectionResult> {\n const err = validateCollectionName(options.name)\n if (err) throw new Error(err)\n\n const cwd = options.cwd ?? process.cwd()\n const compartment = options.compartment ?? 'default'\n const name = options.name\n\n // Convert kebab-case to PascalCase for the TS interface name and the\n // Vue helper variable.\n const PascalName = name\n .split('-')\n .map((s) => (s.length === 0 ? s : (s[0]?.toUpperCase() ?? '') + s.slice(1)))\n .join('')\n const useFnName = `use${PascalName}`\n\n const storePath = path.join(cwd, 'app', 'stores', `${name}.ts`)\n const pagePath = path.join(cwd, 'app', 'pages', `${name}.vue`)\n\n // Refuse to overwrite. Doing both checks before writing either file\n // means a partial write is impossible — either both files land or\n // neither does.\n for (const target of [storePath, pagePath]) {\n if (await pathExists(target)) {\n throw new Error(`Refusing to overwrite existing file: ${target}`)\n }\n }\n\n await fs.mkdir(path.dirname(storePath), { recursive: true })\n await fs.mkdir(path.dirname(pagePath), { recursive: true })\n\n await fs.writeFile(storePath, renderStore(name, PascalName, useFnName, compartment), 'utf8')\n await fs.writeFile(pagePath, renderPage(name, PascalName, useFnName), 'utf8')\n\n return { files: [storePath, pagePath] }\n}\n\nasync function pathExists(p: string): Promise<boolean> {\n try {\n await fs.access(p)\n return true\n } catch {\n return false\n }\n}\n\n/**\n * Renders the `app/stores/<name>.ts` file. The interface is intentionally\n * minimal — `id` and `name` are the only fields. The user is expected to\n * extend it after generation; we'd rather not lock them into a domain\n * shape we guessed.\n */\nfunction renderStore(\n name: string,\n PascalName: string,\n useFnName: string,\n compartment: string,\n): string {\n return `// Generated by \\`noy-db add ${name}\\`.\n//\n// Edit the ${PascalName} interface to match your domain, then call\n// \\`${useFnName}()\\` from any component.\n//\n// defineNoydbStore is auto-imported by @noy-db/nuxt. The compartment\n// id is the tenant/company namespace — change it if you have multiple.\n\nexport interface ${PascalName} {\n id: string\n name: string\n}\n\nexport const ${useFnName} = defineNoydbStore<${PascalName}>('${name}', {\n compartment: '${compartment}',\n})\n`\n}\n\n/**\n * Renders the `app/pages/<name>.vue` page — list + add + delete. Picks\n * the simplest possible template-renderer pattern (`v-for`, no fancy\n * components) so the generated file is easy to read and modify.\n */\nfunction renderPage(name: string, PascalName: string, useFnName: string): string {\n return `<!--\n Generated by \\`noy-db add ${name}\\`.\n Visit /${name} in your dev server.\n-->\n<script setup lang=\"ts\">\nconst ${name} = ${useFnName}()\nawait ${name}.$ready\n\nfunction addOne() {\n ${name}.add({\n id: crypto.randomUUID(),\n name: 'New ${PascalName}',\n })\n}\n\nfunction removeOne(id: string) {\n ${name}.remove(id)\n}\n</script>\n\n<template>\n <main>\n <h1>${PascalName}</h1>\n <button @click=\"addOne\">Add ${PascalName}</button>\n <ul>\n <li v-for=\"item in ${name}.items\" :key=\"item.id\">\n {{ item.name }}\n <button @click=\"removeOne(item.id)\">Delete</button>\n </li>\n </ul>\n </main>\n</template>\n`\n}\n","/**\n * `noy-db verify` — end-to-end integrity check.\n *\n * Opens an in-memory NOYDB instance, writes a record, reads it back,\n * decrypts it, and asserts the round-trip is byte-identical. The check\n * exercises the full crypto path (PBKDF2 → KEK → DEK → AES-GCM) without\n * touching any user data on disk.\n *\n * Why an in-memory check is the right scope:\n * - It validates that @noy-db/core, @noy-db/memory, and the user's\n * installed Node version all agree on Web Crypto. That's the most\n * common silent failure for first-time installers.\n * - It cannot accidentally corrupt user data because there isn't any.\n * - It runs in well under one second, so users actually run it.\n *\n * What this command does NOT do (intentionally):\n * - Open the user's actual compartment file/dynamo/s3/browser store.\n * That requires the user's passphrase — not something we want a CLI\n * `verify` command to prompt for. The full passphrase-driven verify\n * belongs in `nuxi noydb verify` once the auth story for CLIs lands\n * in v0.4. For now `noy-db verify` is the dependency-graph smoke test.\n */\n\nimport { createNoydb } from '@noy-db/core'\nimport { memory } from '@noy-db/memory'\n\nexport interface VerifyResult {\n /** `true` if the round-trip succeeded; `false` if anything diverged. */\n ok: boolean\n /** Human-readable status. Always set, even on success. */\n message: string\n /** Wall-clock time the integrity check took, in ms. */\n durationMs: number\n}\n\n/**\n * Runs the end-to-end check. Pure function — no console output, no\n * `process.exit`. The bin wrapper handles formatting and exit codes so\n * the function is trivial to call from tests.\n */\nexport async function verifyIntegrity(): Promise<VerifyResult> {\n const start = performance.now()\n try {\n const db = await createNoydb({\n adapter: memory(),\n user: 'noy-db-verify',\n // The passphrase here is throwaway — the in-memory adapter never\n // persists anything, and the KEK is destroyed when we call close()\n // a few lines down. We use a non-trivial value just to exercise\n // PBKDF2 properly.\n secret: 'noy-db-verify-passphrase-2026',\n })\n const company = await db.openCompartment('verify-co')\n const collection = company.collection<{ id: string; n: number }>('verify')\n\n // Round-trip a single record. We pick a value that's small enough\n // to print on failure but large enough to ensure encryption isn't\n // accidentally a no-op.\n const original = { id: 'verify-1', n: 42 }\n await collection.put('verify-1', original)\n const got = await collection.get('verify-1')\n if (!got || got.id !== original.id || got.n !== original.n) {\n return fail(start, `Round-trip mismatch: got ${JSON.stringify(got)}`)\n }\n\n // Make sure the query DSL works too — this catches the case where\n // the user's @noy-db/core install is at v0.2 (no query DSL) but the\n // CLI was updated to v0.3.\n const found = collection.query().where('n', '==', 42).toArray()\n if (found.length !== 1) {\n return fail(start, `Query DSL mismatch: expected 1 result, got ${found.length}`)\n }\n\n db.close()\n\n return {\n ok: true,\n message: 'noy-db integrity check passed',\n durationMs: Math.round(performance.now() - start),\n }\n } catch (err) {\n return fail(start, `Integrity check threw: ${(err as Error).message}`)\n }\n}\n\nfunction fail(start: number, message: string): VerifyResult {\n return {\n ok: false,\n message,\n durationMs: Math.round(performance.now() - start),\n }\n}\n","/**\n * `noy-db rotate` — rotate the DEKs for one or more collections in\n * a compartment.\n *\n * What it does\n * ------------\n * For each target collection:\n *\n * 1. Generate a fresh DEK\n * 2. Decrypt every record with the old DEK\n * 3. Re-encrypt every record with the new DEK\n * 4. Re-wrap the new DEK into every remaining user's keyring\n *\n * The old DEKs become unreachable as soon as the keyring files are\n * updated. This is the \"just rotate\" path — nobody is revoked,\n * everybody keeps their current permissions, but the key material\n * is replaced.\n *\n * Why expose this as a CLI command\n * --------------------------------\n * Two real-world scenarios:\n *\n * 1. **Suspected key leak.** An operator lost a laptop, a\n * developer accidentally pasted a passphrase into a Slack\n * channel, a USB stick went missing. Even if you think the\n * passphrase is safe, rotating is cheap insurance.\n *\n * 2. **Scheduled rotation.** Some compliance regimes require\n * periodic key rotation regardless of exposure. A CLI makes\n * this scriptable from cron or a CI job.\n *\n * This module is test-first: all inputs are plain options, the\n * passphrase reader is injected, and the Noydb factory is\n * injectable. The production bin is a thin wrapper that defaults\n * those injections to their real implementations.\n */\n\nimport { createNoydb, type Noydb, type NoydbAdapter } from '@noy-db/core'\nimport { jsonFile } from '@noy-db/file'\nimport type { ReadPassphrase } from './shared.js'\nimport { defaultReadPassphrase } from './shared.js'\n\nexport interface RotateOptions {\n /** Directory containing the compartment data (file adapter only). */\n dir: string\n /** Compartment (tenant) name to rotate keys in. */\n compartment: string\n /** The user id of the operator running the rotate. */\n user: string\n /**\n * Explicit list of collections to rotate. When undefined, the\n * rotation targets every collection the user has a DEK for —\n * resolved at run time by reading the compartment snapshot.\n */\n collections?: string[]\n /** Injected passphrase reader. Defaults to the clack implementation. */\n readPassphrase?: ReadPassphrase\n /**\n * Injected Noydb factory. Production code leaves this undefined\n * and gets `createNoydb`; tests pass a constructor that builds\n * against an in-memory adapter.\n */\n createDb?: typeof createNoydb\n /**\n * Injected adapter factory. Production code leaves this undefined\n * and gets `jsonFile`; tests pass one that returns the shared\n * in-memory adapter their fixture used.\n */\n buildAdapter?: (dir: string) => NoydbAdapter\n}\n\nexport interface RotateResult {\n /** The collections that were actually rotated. */\n rotated: string[]\n}\n\n/**\n * Run the rotate flow against a file-adapter compartment. Returns\n * the list of collections that were rotated so callers can display\n * it to the user.\n *\n * Throws `Error` on any auth/adapter/rotate failure. The bin\n * catches these and prints a friendly message; direct callers\n * (tests) can inspect the error message to assert specific\n * failure modes.\n */\nexport async function rotate(options: RotateOptions): Promise<RotateResult> {\n const readPassphrase = options.readPassphrase ?? defaultReadPassphrase\n const buildAdapter = options.buildAdapter ?? ((dir) => jsonFile({ dir }))\n const createDb = options.createDb ?? createNoydb\n\n // Read the passphrase BEFORE opening the database. This way a\n // cancelled prompt (Ctrl-C at the password entry) leaves the\n // adapter completely untouched — no files opened, no locks held.\n const secret = await readPassphrase(`Passphrase for ${options.user}`)\n\n let db: Noydb | null = null\n try {\n db = await createDb({\n adapter: buildAdapter(options.dir),\n user: options.user,\n secret,\n })\n\n // Resolve \"all collections\" by asking the compartment. This\n // happens BEFORE rotate() is called, so the list is stable\n // across the operation — adding a new collection mid-rotate\n // would be a race we're not guarding against (single-writer\n // assumption applies).\n const compartment = await db.openCompartment(options.compartment)\n const targets = options.collections && options.collections.length > 0\n ? options.collections\n : await compartment.collections()\n\n if (targets.length === 0) {\n throw new Error(\n `Compartment \"${options.compartment}\" has no collections to rotate.`,\n )\n }\n\n await db.rotate(options.compartment, targets)\n return { rotated: targets }\n } finally {\n // Always close the DB on exit — success or failure. Close()\n // clears the KEK and DEKs from process memory, which is the\n // final line of defense if the passphrase somehow leaked\n // into a log line above this block.\n db?.close()\n }\n}\n","/**\n * Shared primitives for the interactive `noy-db` subcommands that\n * need to unlock a real compartment.\n *\n * Three things live here:\n *\n * 1. `ReadPassphrase` — a tiny interface for \"prompt the user for\n * a passphrase\", with a test-friendly default. Subcommands take\n * this as an injected dependency so tests can short-circuit\n * the prompt without spawning a pty.\n *\n * 2. `defaultReadPassphrase` — the production implementation,\n * built on `@clack/prompts` `password()`. Never echoes the\n * value to the terminal, never logs it, clears it from the\n * returned promise after the caller consumes it.\n *\n * 3. `assertRole` — narrow unknown string input to the Role type\n * with a consistent error message.\n *\n * ## Why pull this out\n *\n * `rotate`, `addUser`, and `backup` all need the same \"prompt for\n * a passphrase\" shape and the same \"open a file adapter and get\n * back a Noydb instance\" shape. Duplicating it in three files would\n * drift over time; centralizing means one place to audit the\n * passphrase-handling contract (never log, never persist, clear\n * local variables after use).\n */\n\nimport { password, isCancel, cancel } from '@clack/prompts'\nimport type { Role } from '@noy-db/core'\n\nconst VALID_ROLES = ['owner', 'admin', 'operator', 'viewer', 'client'] as const\n\n/**\n * Asynchronous passphrase reader. Production code passes\n * `defaultReadPassphrase`; tests pass a stub that returns a fixed\n * string without touching stdin.\n *\n * The `label` is shown to the user as the prompt message. It\n * should never contain the expected passphrase or any secret.\n */\nexport type ReadPassphrase = (label: string) => Promise<string>\n\n/**\n * Clack-based passphrase prompt. Cancellation (Ctrl-C) aborts the\n * process with exit code 1 — prompts are always the first thing to\n * fire in a subcommand, so aborting here doesn't leave the system\n * in a half-mutated state.\n */\nexport const defaultReadPassphrase: ReadPassphrase = async (label) => {\n const value = await password({\n message: label,\n // Basic sanity: reject empty strings up front. We don't enforce\n // length here because the caller's KEK-derivation step will\n // reject weak passphrases with its own, richer error.\n validate: (v) => (v.length === 0 ? 'Passphrase cannot be empty' : undefined),\n })\n if (isCancel(value)) {\n cancel('Cancelled.')\n process.exit(1)\n }\n return value\n}\n\n/**\n * Narrow an unknown string to the `Role` type from @noy-db/core.\n * Used by the `add user` subcommand to validate the role argument\n * before passing it to `noydb.grant()`.\n */\nexport function assertRole(input: string): Role {\n if (!(VALID_ROLES as readonly string[]).includes(input)) {\n throw new Error(\n `Invalid role \"${input}\" — must be one of: ${VALID_ROLES.join(', ')}`,\n )\n }\n return input as Role\n}\n\n/**\n * Split a comma-separated collection list into an array of names,\n * trimming whitespace and dropping empties. Returns null if the\n * input itself is empty or undefined — the caller decides whether\n * that means \"all collections\" or \"error\".\n */\nexport function parseCollectionList(input: string | undefined): string[] | null {\n if (!input) return null\n const parts = input\n .split(',')\n .map((s) => s.trim())\n .filter((s) => s.length > 0)\n return parts.length > 0 ? parts : null\n}\n","/**\n * `noy-db add user <id> <role>` — grant a new user access to a\n * compartment.\n *\n * What it does\n * ------------\n * Wraps `noydb.grant()` in the CLI's auth-prompt ritual:\n *\n * 1. Prompt the caller for their own passphrase (to unlock the\n * caller's keyring and derive the wrapping key).\n * 2. Prompt for the new user's passphrase.\n * 3. Prompt for confirmation of the new passphrase.\n * 4. Reject on mismatch.\n * 5. Call `noydb.grant(compartment, { userId, role, passphrase, permissions })`.\n *\n * For owner/admin/viewer roles, every collection is granted\n * automatically (the core keyring.ts grant logic handles that via\n * the `permissions` field). For operator/client, the caller must\n * pass a `--collections` list because those roles need explicit\n * per-collection permissions.\n *\n * ## What this does NOT do\n *\n * - No email/invite flow — v0.5 is about local-CLI key management,\n * not out-of-band user enrollment.\n * - No rollback on partial failure — `grant()` is atomic at the\n * core level (keyring file writes last, after DEK wrapping), so\n * partial-state-on-crash is already handled.\n */\n\nimport { createNoydb, type Noydb, type NoydbAdapter, type Role } from '@noy-db/core'\nimport { jsonFile } from '@noy-db/file'\nimport type { ReadPassphrase } from './shared.js'\nimport { defaultReadPassphrase } from './shared.js'\n\nexport interface AddUserOptions {\n /** Directory containing the compartment data (file adapter only). */\n dir: string\n /** Compartment (tenant) name to grant access to. */\n compartment: string\n /** The user id of the caller running the grant. */\n callerUser: string\n /** The new user's id (must not already exist in the compartment keyring). */\n newUserId: string\n /** The new user's display name — shown in UI and audit logs. Defaults to `newUserId`. */\n newUserDisplayName?: string\n /** The new user's role. */\n role: Role\n /**\n * Per-collection permissions. Required when `role` is operator or\n * client; ignored for owner/admin/viewer (they get everything\n * via the core's resolvePermissions logic).\n *\n * Shape: `{ invoices: 'rw', clients: 'ro' }`. CLI callers pass\n * `--collections invoices:rw,clients:ro` and the argv parser\n * converts it to this shape.\n */\n permissions?: Record<string, 'rw' | 'ro'>\n /** Injected passphrase reader. Defaults to the clack implementation. */\n readPassphrase?: ReadPassphrase\n /** Injected Noydb factory. */\n createDb?: typeof createNoydb\n /** Injected adapter factory. */\n buildAdapter?: (dir: string) => NoydbAdapter\n}\n\nexport interface AddUserResult {\n /** The userId that was granted access. */\n userId: string\n /** The role they were granted. */\n role: Role\n}\n\n/**\n * Run the grant flow. Two passphrase prompts: caller's, then new\n * user's (twice for confirmation). Calls `noydb.grant()` with the\n * collected values.\n */\nexport async function addUser(options: AddUserOptions): Promise<AddUserResult> {\n const readPassphrase = options.readPassphrase ?? defaultReadPassphrase\n const buildAdapter = options.buildAdapter ?? ((dir) => jsonFile({ dir }))\n const createDb = options.createDb ?? createNoydb\n\n // Operator/client roles NEED explicit permissions. Reject here\n // rather than in the middle of the grant, so the caller sees the\n // problem before any I/O happens.\n if (\n (options.role === 'operator' || options.role === 'client') &&\n (!options.permissions || Object.keys(options.permissions).length === 0)\n ) {\n throw new Error(\n `Role \"${options.role}\" requires explicit --collections — e.g. --collections invoices:rw,clients:ro`,\n )\n }\n\n const callerSecret = await readPassphrase(\n `Your passphrase (${options.callerUser})`,\n )\n const newSecret = await readPassphrase(\n `New passphrase for ${options.newUserId}`,\n )\n const confirmSecret = await readPassphrase(\n `Confirm passphrase for ${options.newUserId}`,\n )\n\n if (newSecret !== confirmSecret) {\n throw new Error(`Passphrases do not match — grant aborted.`)\n }\n\n let db: Noydb | null = null\n try {\n db = await createDb({\n adapter: buildAdapter(options.dir),\n user: options.callerUser,\n secret: callerSecret,\n })\n\n // Build the grant options. Only include `permissions` when the\n // caller actually supplied them — otherwise the core's\n // resolvePermissions fills in the role defaults. The spread\n // (rather than post-assignment) keeps the object literal\n // compatible with `GrantOptions`'s readonly `permissions`.\n const grantOpts: Parameters<Noydb['grant']>[1] = {\n userId: options.newUserId,\n displayName: options.newUserDisplayName ?? options.newUserId,\n role: options.role,\n passphrase: newSecret,\n ...(options.permissions ? { permissions: options.permissions } : {}),\n }\n\n await db.grant(options.compartment, grantOpts)\n\n return {\n userId: options.newUserId,\n role: options.role,\n }\n } finally {\n db?.close()\n }\n}\n","/**\n * `noy-db backup <target>` — dump a compartment to a local file.\n *\n * What it does\n * ------------\n * Wraps `compartment.dump()` in the CLI's auth-prompt ritual, then\n * writes the serialized backup to the requested path. As of v0.4,\n * `dump()` already produces a verifiable backup (embedded\n * ledgerHead, full `_ledger` / `_ledger_deltas` snapshots) — the\n * CLI just moves bytes; the integrity guarantees come from core.\n *\n * ## Target URI support\n *\n * v0.5.0 ships **`file://` only** (or a plain filesystem path).\n * The issue spec originally called for `s3://` as well, but\n * wiring @aws-sdk into @noy-db/create would defeat the\n * zero-runtime-deps story for the CLI package. S3 backup is\n * deferred to a follow-up that can live in @noy-db/s3-cli or a\n * similar optional companion package.\n *\n * Accepted forms:\n * - `file:///absolute/path.json`\n * - `file://./relative/path.json`\n * - `/absolute/path.json` (treated as `file://`)\n * - `./relative/path.json` (treated as `file://`)\n *\n * ## What this does NOT do\n *\n * - No encryption of the backup BEYOND what noy-db already does.\n * The dumped file is a valid noy-db backup, which means\n * individual records are still encrypted but the keyring is\n * included (wrapped with each user's KEK). Anyone who loads\n * the backup still needs the correct passphrase to read.\n * - No restore — that's a separate subcommand tracked as a\n * follow-up. For now users can restore via\n * `compartment.load(backupString)` from their own app code.\n */\n\nimport { promises as fs } from 'node:fs'\nimport path from 'node:path'\nimport { createNoydb, type Noydb, type NoydbAdapter } from '@noy-db/core'\nimport { jsonFile } from '@noy-db/file'\nimport type { ReadPassphrase } from './shared.js'\nimport { defaultReadPassphrase } from './shared.js'\n\nexport interface BackupOptions {\n /** Directory containing the compartment data (file adapter only). */\n dir: string\n /** Compartment (tenant) name to back up. */\n compartment: string\n /** The user id of the operator running the backup. */\n user: string\n /**\n * Where to write the backup. Accepts a `file://` URI or a plain\n * filesystem path. Relative paths resolve against `process.cwd()`.\n */\n target: string\n /** Injected passphrase reader. */\n readPassphrase?: ReadPassphrase\n /** Injected Noydb factory. */\n createDb?: typeof createNoydb\n /** Injected adapter factory. */\n buildAdapter?: (dir: string) => NoydbAdapter\n}\n\nexport interface BackupResult {\n /** Absolute filesystem path the backup was written to. */\n path: string\n /** Size of the serialized backup in bytes. */\n bytes: number\n}\n\n/**\n * Parse a backup target into an absolute filesystem path. Rejects\n * unsupported URI schemes (s3://, https://, etc.) early so the\n * caller doesn't silently write to the wrong place.\n */\nexport function resolveBackupTarget(target: string, cwd: string = process.cwd()): string {\n // Strip the `file://` prefix if present. The rest of the string\n // is treated as a filesystem path. We accept both `file:///abs`\n // (three slashes, absolute) and `file://./rel` (two slashes,\n // relative) because real-world users write both.\n let raw = target\n if (target.startsWith('file://')) {\n raw = target.slice('file://'.length)\n } else if (target.includes('://')) {\n // Any other scheme is unsupported.\n throw new Error(\n `Unsupported backup target scheme: \"${target.split('://')[0]}://\". ` +\n `Only file:// and plain filesystem paths are supported in v0.5. ` +\n `S3 backups will land in a follow-up.`,\n )\n }\n return path.resolve(cwd, raw)\n}\n\nexport async function backup(options: BackupOptions): Promise<BackupResult> {\n const readPassphrase = options.readPassphrase ?? defaultReadPassphrase\n const buildAdapter = options.buildAdapter ?? ((dir) => jsonFile({ dir }))\n const createDb = options.createDb ?? createNoydb\n\n // Resolve the target FIRST so a bad URI fails before any\n // passphrase is collected. This keeps the UX clean: a typo in\n // `s3://bucket/x` rejects without asking for a secret the user\n // would then have to type again.\n const absolutePath = resolveBackupTarget(options.target)\n\n const secret = await readPassphrase(`Passphrase for ${options.user}`)\n\n let db: Noydb | null = null\n try {\n db = await createDb({\n adapter: buildAdapter(options.dir),\n user: options.user,\n secret,\n })\n const compartment = await db.openCompartment(options.compartment)\n const serialized = await compartment.dump()\n\n // Make sure the parent directory exists. If the user passed\n // `./backups/2026/demo.json` and `./backups/2026` doesn't\n // exist yet, we create it. This is the common case for\n // scripted rotations dropping into a date-based folder.\n await fs.mkdir(path.dirname(absolutePath), { recursive: true })\n await fs.writeFile(absolutePath, serialized, 'utf8')\n\n return {\n path: absolutePath,\n bytes: Buffer.byteLength(serialized, 'utf8'),\n }\n } finally {\n db?.close()\n }\n}\n"],"mappings":";;;AA8CA,OAAO,QAAQ;;;AC1Bf,SAAS,YAAY,UAAU;AAC/B,OAAO,UAAU;AA0BV,SAAS,uBAAuB,MAA6B;AAClE,MAAI,CAAC,KAAM,QAAO;AAClB,MAAI,CAAC,oBAAoB,KAAK,IAAI,GAAG;AACnC,WAAO;AAAA,EACT;AACA,SAAO;AACT;AAEA,eAAsB,cACpB,SAC8B;AAC9B,QAAM,MAAM,uBAAuB,QAAQ,IAAI;AAC/C,MAAI,IAAK,OAAM,IAAI,MAAM,GAAG;AAE5B,QAAM,MAAM,QAAQ,OAAO,QAAQ,IAAI;AACvC,QAAM,cAAc,QAAQ,eA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EAAE,KAAK,CAAC,EAAE,OAAO,OAAO,GAAG;AACxE,UAAM,CAAC,MAAM,IAAI,IAAI,KAAK,MAAM,GAAG;AACnC,QAAI,CAAC,QAAQ,CAAC,QAAS,SAAS,QAAQ,SAAS,MAAO;AACtD,YAAM,IAAI;AAAA,QACR,gCAAgC,IAAI;AAAA,MACtC;AAAA,IACF;AACA,QAAI,IAAI,IAAI;AAAA,EACd;AACA,SAAO,OAAO,KAAK,GAAG,EAAE,SAAS,IAAI,MAAM;AAC7C;AAEA,KAAK,EAAE,MAAM,CAAC,QAAiB;AAC7B,UAAQ,OAAO,MAAM,GAAG,GAAG,IAAI,QAAQ,CAAC,IAAK,IAAc,OAAO;AAAA,CAAI;AACtE,UAAQ,KAAK,CAAC;AAChB,CAAC;","names":["createNoydb","createNoydb","createNoydb","jsonFile","jsonFile","createNoydb","fs","path","createNoydb","jsonFile","path","jsonFile","createNoydb","fs"]}
|