@feltdb/feltkit 0.3.12 → 0.3.13
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/README.md +4 -3
- package/dist/app.d.ts +18 -0
- package/dist/app.js +22 -0
- package/dist/app.js.map +1 -1
- package/dist/appboundry/build.js +10 -2
- package/dist/appboundry/build.js.map +1 -1
- package/dist/appboundry/host.js +2 -2
- package/dist/appboundry/host.js.map +1 -1
- package/dist/cli/main.d.ts +5 -0
- package/dist/cli/main.js +139 -40
- package/dist/cli/main.js.map +1 -1
- package/dist/client/index.d.ts +3 -0
- package/dist/client/index.js +3 -0
- package/dist/client/index.js.map +1 -1
- package/dist/dashboard/assets/index-BSnW2DC-.js +15 -0
- package/dist/dashboard/assets/{index-91I1zDK-.css → index-BXTNQAg1.css} +1 -1
- package/dist/dashboard/index.html +3 -3
- package/dist/docs.d.ts +12 -0
- package/dist/docs.js +42 -0
- package/dist/docs.js.map +1 -0
- package/dist/errors.d.ts +15 -0
- package/dist/errors.js +9 -0
- package/dist/errors.js.map +1 -1
- package/dist/platform/changes.js +4 -2
- package/dist/platform/changes.js.map +1 -1
- package/dist/platform/deployments.js +8 -6
- package/dist/platform/deployments.js.map +1 -1
- package/dist/runtime/activity.d.ts +25 -0
- package/dist/runtime/activity.js +38 -12
- package/dist/runtime/activity.js.map +1 -1
- package/dist/runtime/agent.d.ts +16 -0
- package/dist/runtime/agent.js +92 -28
- package/dist/runtime/agent.js.map +1 -1
- package/dist/runtime/backup-environment.d.ts +8 -1
- package/dist/runtime/backup-environment.js +44 -12
- package/dist/runtime/backup-environment.js.map +1 -1
- package/dist/runtime/backup.d.ts +45 -3
- package/dist/runtime/backup.js +237 -68
- package/dist/runtime/backup.js.map +1 -1
- package/dist/runtime/capabilities.js +4 -2
- package/dist/runtime/capabilities.js.map +1 -1
- package/dist/runtime/changes.js +2 -2
- package/dist/runtime/changes.js.map +1 -1
- package/dist/runtime/data.d.ts +30 -3
- package/dist/runtime/data.js +136 -32
- package/dist/runtime/data.js.map +1 -1
- package/dist/runtime/decisions.js +2 -1
- package/dist/runtime/decisions.js.map +1 -1
- package/dist/runtime/integrations.js +14 -6
- package/dist/runtime/integrations.js.map +1 -1
- package/dist/runtime/loader.js +22 -2
- package/dist/runtime/loader.js.map +1 -1
- package/dist/runtime/readiness.js +6 -1
- package/dist/runtime/readiness.js.map +1 -1
- package/dist/runtime/runtime.d.ts +24 -6
- package/dist/runtime/runtime.js +75 -19
- package/dist/runtime/runtime.js.map +1 -1
- package/dist/runtime/services.d.ts +19 -5
- package/dist/runtime/services.js +14 -4
- package/dist/runtime/services.js.map +1 -1
- package/dist/runtime/sessions.js +4 -3
- package/dist/runtime/sessions.js.map +1 -1
- package/dist/runtime/state-contract.js +3 -3
- package/dist/runtime/state-contract.js.map +1 -1
- package/dist/server/admin.d.ts +2 -2
- package/dist/server/admin.js +37 -12
- package/dist/server/admin.js.map +1 -1
- package/dist/server/index.d.ts +2 -1
- package/dist/server/index.js +45 -8
- package/dist/server/index.js.map +1 -1
- package/dist/server/mcp.js +1 -1
- package/dist/server/mcp.js.map +1 -1
- package/dist/testing/index.d.ts +6 -2
- package/dist/testing/index.js +28 -4
- package/dist/testing/index.js.map +1 -1
- package/docs/AGENT-OPERATIONS.md +515 -0
- package/docs/APPBOUNDRY.md +240 -0
- package/docs/ARCHITECTURE.md +126 -0
- package/docs/BACKUP.md +115 -0
- package/docs/GUARANTEES.md +457 -0
- package/docs/PATH-TO-PRODUCTION.md +117 -0
- package/docs/README.md +15 -0
- package/docs/SECURITY.md +182 -0
- package/docs/TRANSACTIONS.md +216 -0
- package/docs/UPSTREAM-GAPS.md +270 -0
- package/docs/WHY-FELTKIT.md +64 -0
- package/docs/assets/feltkit-logo-dark.png +0 -0
- package/docs/assets/feltkit-logo.png +0 -0
- package/package.json +9 -7
- package/skills/.claude-plugin/marketplace.json +1 -1
- package/skills/.claude-plugin/plugin.json +3 -3
- package/skills/feltkit-agent/SKILL.md +9 -5
- package/skills/feltkit-build/SKILL.md +10 -1
- package/skills/feltkit-data/SKILL.md +9 -3
- package/skills/feltkit-services/SKILL.md +7 -3
- package/dist/dashboard/assets/index-BhFOquA7.js +0 -15
- package/dist/dashboard/theme.js +0 -11
package/dist/cli/main.js
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
* The `feltkit` command.
|
|
3
3
|
*/
|
|
4
4
|
import { spawn } from "node:child_process";
|
|
5
|
-
import { existsSync, mkdirSync, readdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
5
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
6
6
|
import { dirname, extname, join, relative, resolve } from "node:path";
|
|
7
|
-
import { createHash } from "node:crypto";
|
|
7
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
8
8
|
import { fileURLToPath } from "node:url";
|
|
9
9
|
import { FeltKitError, isFeltKitError } from "../errors.js";
|
|
10
10
|
import { resolveEnvironment } from "../runtime/environment.js";
|
|
@@ -14,8 +14,8 @@ import { deploymentArtifact, productionEnv, readDeployment, writeDeployment } fr
|
|
|
14
14
|
import { readAdminToken, readRuntimeRecord } from "../runtime/projects.js";
|
|
15
15
|
import { chooseRoles, defaultOwnerId, issueProductionSession, loadProjectFor, studioLink } from "../server/production.js";
|
|
16
16
|
import { blockedHint, describePlan } from "../runtime/state-contract.js";
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
17
|
+
import { fileSink, verifyBackupFile } from "../runtime/backup.js";
|
|
18
|
+
import { backupEnvironmentTo, restoreEnvironmentFile } from "../runtime/backup-environment.js";
|
|
19
19
|
import { createGrant, operatorKey } from "../server/operators.js";
|
|
20
20
|
import { assessReadiness } from "../runtime/readiness.js";
|
|
21
21
|
import { EnvironmentCredentials, looksLikeSecret, toCredentialRef } from "../runtime/credentials.js";
|
|
@@ -26,12 +26,27 @@ import { BUILD_DIR, SDK_VERSION, artifactEnv, build, codegen, doctor, startDev,
|
|
|
26
26
|
import { scaffold, ScaffoldError } from "create-feltkit";
|
|
27
27
|
import { DEPLOY_TARGETS, deploy, lower } from "./deploy.js";
|
|
28
28
|
import { createInterface } from "node:readline/promises";
|
|
29
|
+
import { createInterface as createLineReader } from "node:readline";
|
|
30
|
+
import { Readable } from "node:stream";
|
|
29
31
|
import { feltdbContract, formatContract } from "../runtime/contract.js";
|
|
30
32
|
import { checkSkills, installSkills, shippedSkills, skillsTarget } from "./skills.js";
|
|
31
33
|
import { c, line, printInspect, symbols } from "./output.js";
|
|
34
|
+
import { PACKAGE_PAGE, SHIPPED_DOCS, docFile, docUrl } from "../docs.js";
|
|
35
|
+
/** Flags that may be given more than once; their values are joined with commas (`--role a --role b` = `a,b`). */
|
|
36
|
+
const REPEATABLE = new Set(["role"]);
|
|
32
37
|
export function parseArgs(argv) {
|
|
33
38
|
const positional = [];
|
|
34
39
|
const flags = {};
|
|
40
|
+
const set = (key, value) => {
|
|
41
|
+
const previous = flags[key];
|
|
42
|
+
if (previous !== undefined && typeof value === "string" && typeof previous === "string") {
|
|
43
|
+
if (!REPEATABLE.has(key))
|
|
44
|
+
throw new FeltKitError("INVALID_ARGUMENT", `--${key} was given more than once ("${previous}" and "${value}"); give it once.`);
|
|
45
|
+
flags[key] = `${previous},${value}`;
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
flags[key] = value;
|
|
49
|
+
};
|
|
35
50
|
for (let i = 0; i < argv.length; i++) {
|
|
36
51
|
const arg = argv[i];
|
|
37
52
|
if (arg === "--") {
|
|
@@ -41,13 +56,13 @@ export function parseArgs(argv) {
|
|
|
41
56
|
if (arg.startsWith("--")) {
|
|
42
57
|
const [key, inline] = arg.slice(2).split("=", 2);
|
|
43
58
|
if (key.startsWith("no-"))
|
|
44
|
-
|
|
59
|
+
set(key.slice(3), false);
|
|
45
60
|
else if (inline !== undefined)
|
|
46
|
-
|
|
61
|
+
set(key, inline);
|
|
47
62
|
else if (argv[i + 1] && !argv[i + 1].startsWith("-"))
|
|
48
|
-
|
|
63
|
+
set(key, argv[++i]);
|
|
49
64
|
else
|
|
50
|
-
|
|
65
|
+
set(key, true);
|
|
51
66
|
}
|
|
52
67
|
else if (arg.startsWith("-") && arg.length > 1) {
|
|
53
68
|
flags[arg.slice(1)] = true;
|
|
@@ -88,6 +103,7 @@ ${c.bold("Commands")}
|
|
|
88
103
|
contract Write the FeltDB application contract (for Managed FeltDB)
|
|
89
104
|
doctor Check the project and installation for problems
|
|
90
105
|
skills <action> Install, update, or check the FeltKit skills for coding agents
|
|
106
|
+
docs [<name>] List FeltKit's documentation (shipped in the package), or print one document
|
|
91
107
|
|
|
92
108
|
${c.bold("Options")}
|
|
93
109
|
--port <n> Port for dev/start (default 3000)
|
|
@@ -95,13 +111,36 @@ ${c.bold("Options")}
|
|
|
95
111
|
--json Machine-readable output (inspect, session, doctor)
|
|
96
112
|
--help Show help for a command
|
|
97
113
|
|
|
98
|
-
Docs:
|
|
114
|
+
Docs: \`feltkit docs\` (shipped in node_modules/@feltdb/feltkit/docs) · ${PACKAGE_PAGE}`;
|
|
115
|
+
/**
|
|
116
|
+
* Help for `feltkit <command> [<action>] --help`: with an action the command's help documents
|
|
117
|
+
* (`feltkit credential remove …`), only that action's lines; otherwise the whole command.
|
|
118
|
+
*/
|
|
119
|
+
export function helpFor(command, action) {
|
|
120
|
+
const text = COMMAND_HELP[command];
|
|
121
|
+
if (!text)
|
|
122
|
+
return HELP;
|
|
123
|
+
if (!action)
|
|
124
|
+
return text;
|
|
125
|
+
const blocks = [];
|
|
126
|
+
for (const row of text.split("\n")) {
|
|
127
|
+
if (row.startsWith("feltkit ") || !blocks.length)
|
|
128
|
+
blocks.push([row]);
|
|
129
|
+
else
|
|
130
|
+
blocks.at(-1).push(row);
|
|
131
|
+
}
|
|
132
|
+
const own = blocks.filter((b) => b[0].startsWith(`feltkit ${command} ${action}`));
|
|
133
|
+
return own.length ? own.map((b) => b.join("\n")).join("\n") : text;
|
|
134
|
+
}
|
|
99
135
|
const COMMAND_HELP = {
|
|
136
|
+
docs: "feltkit docs List the documentation shipped with this install\n" +
|
|
137
|
+
"feltkit docs <name> Print one document (e.g. feltkit docs guarantees)\n" +
|
|
138
|
+
" Offline: the files are in node_modules/@feltdb/feltkit/docs. --json lists name, file and public URL.",
|
|
100
139
|
backup: "feltkit backup create [--env development] [--out <file>]\n" +
|
|
101
140
|
"feltkit backup verify <file>\n" +
|
|
102
141
|
"feltkit backup list [--dir .feltkit/backups]\n" +
|
|
103
142
|
"feltkit backup restore <file> --env <env>\n" +
|
|
104
|
-
" One application's state (feltkit.backup/1
|
|
143
|
+
" One application's state (feltkit.backup/1; `feltkit docs backup`): its contract, migration history, records,\n" +
|
|
105
144
|
" AppPort Services records and outbox; never sessions. `create` reads a running development server through\n" +
|
|
106
145
|
" its admin API (calls pause while it reads), else the stopped environment directly. `restore` writes only\n" +
|
|
107
146
|
" into a new, empty environment, after verifying the whole backup; an interrupted restore is refused at start.\n" +
|
|
@@ -207,7 +246,7 @@ const COMMAND_HELP = {
|
|
|
207
246
|
" deployment, .env.local; else .feltkit/<env>/operator-key). With a recorded deployment it prints a link that signs\n" +
|
|
208
247
|
" in with it; otherwise paste it into Studio. It becomes an operator session holding exactly these declared roles.",
|
|
209
248
|
op: "feltkit op [list] [--json]\n" +
|
|
210
|
-
" FeltKit's development and operations capabilities (application dev.feltkit.platform
|
|
249
|
+
" FeltKit's development and operations capabilities (application dev.feltkit.platform; `feltkit docs agent-operations`):\n" +
|
|
211
250
|
" each with its typed input, effect and the permission it requires.\n" +
|
|
212
251
|
"feltkit op <capability> --input '<json>' [--project <dir>] [--root <dir>] [--json]\n" +
|
|
213
252
|
" Invokes one as the workspace owner, through the same AppPort application agents use over /appport and /mcp\n" +
|
|
@@ -235,6 +274,30 @@ async function adminRequest(record, token, path, init = {}) {
|
|
|
235
274
|
throw new FeltKitError(body?.error?.code ?? "INTERNAL", body?.error?.message ?? `Admin API answered ${response.status}`);
|
|
236
275
|
return body;
|
|
237
276
|
}
|
|
277
|
+
/** A running server's backup (POST /backup, NDJSON), passed line by line to `sink`. Returns its header. */
|
|
278
|
+
async function adminBackup(record, token, sink) {
|
|
279
|
+
const response = await fetch(`${record.url}/_feltkit/api/backup`, { method: "POST", headers: { "x-feltkit-admin": token, "Content-Type": "application/json" } });
|
|
280
|
+
if (!response.ok || !response.body) {
|
|
281
|
+
const body = (await response.json().catch(() => null));
|
|
282
|
+
throw new FeltKitError(body?.error?.code ?? "INTERNAL", body?.error?.message ?? `Admin API answered ${response.status}`);
|
|
283
|
+
}
|
|
284
|
+
let header = null;
|
|
285
|
+
const lines = createLineReader({ input: Readable.fromWeb(response.body), crlfDelay: Infinity });
|
|
286
|
+
for await (const text of lines) {
|
|
287
|
+
if (!text)
|
|
288
|
+
continue;
|
|
289
|
+
if (header === null)
|
|
290
|
+
header = JSON.parse(text);
|
|
291
|
+
else if (text.startsWith('{"error":')) {
|
|
292
|
+
const { error } = JSON.parse(text);
|
|
293
|
+
throw new FeltKitError((error?.code ?? "INTERNAL"), `The server stopped the backup: ${error?.message ?? "unknown error"}`);
|
|
294
|
+
}
|
|
295
|
+
await sink(text);
|
|
296
|
+
}
|
|
297
|
+
if (header === null)
|
|
298
|
+
throw new FeltKitError("INTERNAL", "The server's backup was empty.");
|
|
299
|
+
return header;
|
|
300
|
+
}
|
|
238
301
|
/** Use the running server for an environment if there is one; otherwise open the environment directly. */
|
|
239
302
|
async function withEnvironment(projectDir, envName, remote, local) {
|
|
240
303
|
const runtimeDir = join(projectDir, ".feltkit", envName);
|
|
@@ -356,7 +419,7 @@ export async function main(argv = process.argv.slice(2), deps = {}) {
|
|
|
356
419
|
return 0;
|
|
357
420
|
}
|
|
358
421
|
if (flags.help || flags.h) {
|
|
359
|
-
line(
|
|
422
|
+
line(helpFor(command, positional[0]));
|
|
360
423
|
return 0;
|
|
361
424
|
}
|
|
362
425
|
if (command === "--version" || command === "version" || flags.version) {
|
|
@@ -411,6 +474,28 @@ export async function main(argv = process.argv.slice(2), deps = {}) {
|
|
|
411
474
|
line(c.dim("Publish it to Managed FeltDB with `npx feltdb publish --contract " + (flags.out ?? "feltdb.contract.json") + " --yes`."));
|
|
412
475
|
return 0;
|
|
413
476
|
}
|
|
477
|
+
case "docs": {
|
|
478
|
+
const wanted = positional[0]?.toUpperCase().replace(/\.MD$/, "");
|
|
479
|
+
if (!wanted) {
|
|
480
|
+
if (json)
|
|
481
|
+
line(JSON.stringify(SHIPPED_DOCS.map(([name, what]) => ({ name, what, file: docFile(name), url: docUrl(name) })), null, 2));
|
|
482
|
+
else {
|
|
483
|
+
line(`${c.bold("FeltKit documentation")} ${c.dim(SDK_VERSION)}, shipped in this install. \`feltkit docs <name>\` prints one.\n`);
|
|
484
|
+
for (const [name, what] of SHIPPED_DOCS)
|
|
485
|
+
line(` ${name.replace(/\.md$/, "").toLowerCase().padEnd(20)} ${what}`);
|
|
486
|
+
line(`\n${c.dim(`Files: ${dirname(docFile(SHIPPED_DOCS[0][0]))}`)}\n${c.dim(`Public: ${docUrl()} · ${PACKAGE_PAGE}`)}`);
|
|
487
|
+
}
|
|
488
|
+
return 0;
|
|
489
|
+
}
|
|
490
|
+
const doc = SHIPPED_DOCS.find(([name]) => name.replace(/\.md$/, "") === wanted);
|
|
491
|
+
if (!doc)
|
|
492
|
+
throw new FeltKitError("NOT_FOUND", `No document called "${positional[0]}".`, { hint: `Run \`feltkit docs\` for the list: ${SHIPPED_DOCS.map(([n]) => n.replace(/\.md$/, "").toLowerCase()).join(", ")}.` });
|
|
493
|
+
const file = docFile(doc[0]);
|
|
494
|
+
if (!existsSync(file))
|
|
495
|
+
throw new FeltKitError("CONFIGURATION", `${doc[0]} is not in this install (${file}).`, { hint: `Read it at ${docUrl(doc[0])}.` });
|
|
496
|
+
line(readFileSync(file, "utf8").replace(/\n$/, ""));
|
|
497
|
+
return 0;
|
|
498
|
+
}
|
|
414
499
|
case "codegen": {
|
|
415
500
|
const changed = codegen(projectDir);
|
|
416
501
|
line(`${symbols.ok} feltkit/_generated/api.ts ${changed ? "updated" : "already up to date"}`);
|
|
@@ -670,30 +755,44 @@ export async function main(argv = process.argv.slice(2), deps = {}) {
|
|
|
670
755
|
if (action === "create") {
|
|
671
756
|
const runtimeDir = join(projectDir, ".feltkit", envName);
|
|
672
757
|
const record = readRuntimeRecord(runtimeDir);
|
|
673
|
-
|
|
758
|
+
// Written line by line to a partial file beside its destination, verified from disk, then renamed.
|
|
759
|
+
const explicit = typeof flags.out === "string" ? resolve(flags.out) : null;
|
|
760
|
+
if (explicit && existsSync(explicit))
|
|
761
|
+
throw new FeltKitError("CONFLICT", `${explicit} exists; a backup never overwrites a file.`);
|
|
762
|
+
const partial = explicit ? `${explicit}.partial` : join(projectDir, ".feltkit", "backups", envName, `.backup-${randomUUID()}.partial`);
|
|
763
|
+
mkdirSync(dirname(partial), { recursive: true });
|
|
764
|
+
let header;
|
|
674
765
|
let source;
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
766
|
+
const file = fileSink(partial);
|
|
767
|
+
try {
|
|
768
|
+
if (record) {
|
|
769
|
+
if (envName === "production")
|
|
770
|
+
throw new FeltKitError("CONFIGURATION", `A production server is running (pid ${record.pid}); its admin API answers verified operators only. Stop it to back up its state directly.`);
|
|
771
|
+
const token = readAdminToken(runtimeDir);
|
|
772
|
+
if (!token)
|
|
773
|
+
throw new FeltKitError("CONFIGURATION", `A ${envName} server is running (pid ${record.pid}) but its admin token is missing.`);
|
|
774
|
+
header = await adminBackup(record, token, file.sink);
|
|
775
|
+
source = `running server (pid ${record.pid}; calls paused while it read)`;
|
|
776
|
+
}
|
|
777
|
+
else {
|
|
778
|
+
const { app, environment } = await environmentFor();
|
|
779
|
+
header = await backupEnvironmentTo(environment, app, file.sink);
|
|
780
|
+
source = "the stopped environment, directly";
|
|
781
|
+
}
|
|
782
|
+
await file.close();
|
|
783
|
+
await verifyBackupFile(partial);
|
|
683
784
|
}
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
785
|
+
catch (error) {
|
|
786
|
+
await file.close().catch(() => undefined);
|
|
787
|
+
rmSync(partial, { force: true });
|
|
788
|
+
throw error;
|
|
688
789
|
}
|
|
689
|
-
const
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
if (existsSync(out))
|
|
790
|
+
const out = explicit ?? join(dirname(partial), `${header.application.name}-${header.createdAt.replace(/[:.]/g, "-")}.ndjson`);
|
|
791
|
+
if (existsSync(out)) {
|
|
792
|
+
rmSync(partial, { force: true });
|
|
693
793
|
throw new FeltKitError("CONFLICT", `${out} exists; a backup never overwrites a file.`);
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
renameSync(`${out}.partial`, out);
|
|
794
|
+
}
|
|
795
|
+
renameSync(partial, out);
|
|
697
796
|
if (json)
|
|
698
797
|
line(JSON.stringify({ path: out, source, header }, null, 2));
|
|
699
798
|
else
|
|
@@ -704,25 +803,25 @@ export async function main(argv = process.argv.slice(2), deps = {}) {
|
|
|
704
803
|
const file = positional[1];
|
|
705
804
|
if (!file)
|
|
706
805
|
throw new FeltKitError("INVALID_ARGUMENT", "Usage: feltkit backup verify <file>");
|
|
707
|
-
const { header, records } =
|
|
806
|
+
const { header, records } = await verifyBackupFile(resolve(file));
|
|
708
807
|
if (json)
|
|
709
|
-
line(JSON.stringify({ ok: true, header, records
|
|
808
|
+
line(JSON.stringify({ ok: true, header, records }, null, 2));
|
|
710
809
|
else
|
|
711
|
-
line(`${symbols.ok} ${file}: ${header.application.name} ${header.application.version} (${header.environment}, ${header.createdAt}); ${records
|
|
810
|
+
line(`${symbols.ok} ${file}: ${header.application.name} ${header.application.version} (${header.environment}, ${header.createdAt}); ${records} records; contract ${header.contract ? `${header.contract.name} v${header.contract.version} ${header.contract.hash.slice(0, 19)}…` : "none"}; FeltKit ${header.feltkit}, FeltDB ${header.feltdb}.`);
|
|
712
811
|
return 0;
|
|
713
812
|
}
|
|
714
813
|
if (action === "list") {
|
|
715
814
|
const dir = resolve(typeof flags.dir === "string" ? flags.dir : join(projectDir, ".feltkit", "backups"));
|
|
716
815
|
const files = existsSync(dir) ? readdirSync(dir, { recursive: true, withFileTypes: true }).filter((e) => e.isFile() && e.name.endsWith(".ndjson")).map((e) => join(e.parentPath ?? e.path ?? dir, e.name)).sort() : [];
|
|
717
|
-
const items = files.map((path) => {
|
|
816
|
+
const items = await Promise.all(files.map(async (path) => {
|
|
718
817
|
try {
|
|
719
|
-
const { header, records } =
|
|
720
|
-
return { path, ok: true, application: header.application, environment: header.environment, createdAt: header.createdAt, contract: header.contract ? { version: header.contract.version, hash: header.contract.hash } : null, records
|
|
818
|
+
const { header, records } = await verifyBackupFile(path);
|
|
819
|
+
return { path, ok: true, application: header.application, environment: header.environment, createdAt: header.createdAt, contract: header.contract ? { version: header.contract.version, hash: header.contract.hash } : null, records };
|
|
721
820
|
}
|
|
722
821
|
catch (error) {
|
|
723
822
|
return { path, ok: false, error: error.message };
|
|
724
823
|
}
|
|
725
|
-
});
|
|
824
|
+
}));
|
|
726
825
|
if (json)
|
|
727
826
|
line(JSON.stringify({ dir, items }, null, 2));
|
|
728
827
|
else if (!items.length)
|
|
@@ -739,7 +838,7 @@ export async function main(argv = process.argv.slice(2), deps = {}) {
|
|
|
739
838
|
if (readRuntimeRecord(join(projectDir, ".feltkit", envName)))
|
|
740
839
|
throw new FeltKitError("CONFLICT", `A ${envName} server is running; a restore writes only into a new, empty environment. Nothing was written.`);
|
|
741
840
|
const { app, environment } = await environmentFor();
|
|
742
|
-
const { header, records } = await
|
|
841
|
+
const { header, records } = await restoreEnvironmentFile(resolve(file), environment, app);
|
|
743
842
|
if (json)
|
|
744
843
|
line(JSON.stringify({ restored: true, environment: envName, header, records }, null, 2));
|
|
745
844
|
else
|