@softistx/mongo-backup 0.0.0-stage → 0.4.1

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.
Files changed (72) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +484 -2
  3. package/dist/backups/key-file.d.ts +30 -0
  4. package/dist/backups/key-file.d.ts.map +1 -0
  5. package/dist/backups/mongo-backups.d.ts +33 -0
  6. package/dist/backups/mongo-backups.d.ts.map +1 -0
  7. package/dist/backups/operations.d.ts +55 -0
  8. package/dist/backups/operations.d.ts.map +1 -0
  9. package/dist/backups/options.d.ts +60 -0
  10. package/dist/backups/options.d.ts.map +1 -0
  11. package/dist/backups/plan.d.ts +20 -0
  12. package/dist/backups/plan.d.ts.map +1 -0
  13. package/dist/chunks/index-j0tptz7w.js +97 -0
  14. package/dist/chunks/index-j0tptz7w.js.map +11 -0
  15. package/dist/cli.d.ts +3 -0
  16. package/dist/cli.d.ts.map +1 -0
  17. package/dist/cli.js +31 -0
  18. package/dist/cli.js.map +10 -0
  19. package/dist/errors.d.ts +43 -0
  20. package/dist/errors.d.ts.map +1 -0
  21. package/dist/format/bson-stream.d.ts +13 -0
  22. package/dist/format/bson-stream.d.ts.map +1 -0
  23. package/dist/format/change.d.ts +61 -0
  24. package/dist/format/change.d.ts.map +1 -0
  25. package/dist/format/document.d.ts +7 -0
  26. package/dist/format/document.d.ts.map +1 -0
  27. package/dist/format/metadata.d.ts +14 -0
  28. package/dist/format/metadata.d.ts.map +1 -0
  29. package/dist/format/names.d.ts +22 -0
  30. package/dist/format/names.d.ts.map +1 -0
  31. package/dist/format/position.d.ts +29 -0
  32. package/dist/format/position.d.ts.map +1 -0
  33. package/dist/index.d.ts +17 -0
  34. package/dist/index.d.ts.map +1 -0
  35. package/dist/index.js +1340 -0
  36. package/dist/index.js.map +32 -0
  37. package/dist/restore/landing.d.ts +26 -0
  38. package/dist/restore/landing.d.ts.map +1 -0
  39. package/dist/restore/options.d.ts +59 -0
  40. package/dist/restore/options.d.ts.map +1 -0
  41. package/dist/restore/restore-collections.d.ts +12 -0
  42. package/dist/restore/restore-collections.d.ts.map +1 -0
  43. package/dist/source/catalog.d.ts +28 -0
  44. package/dist/source/catalog.d.ts.map +1 -0
  45. package/dist/source/changes.d.ts +12 -0
  46. package/dist/source/changes.d.ts.map +1 -0
  47. package/dist/source/collections.d.ts +20 -0
  48. package/dist/source/collections.d.ts.map +1 -0
  49. package/dist/source/events.d.ts +46 -0
  50. package/dist/source/events.d.ts.map +1 -0
  51. package/dist/source/followed.d.ts +13 -0
  52. package/dist/source/followed.d.ts.map +1 -0
  53. package/dist/source/mongo-source.d.ts +24 -0
  54. package/dist/source/mongo-source.d.ts.map +1 -0
  55. package/dist/source/snapshot.d.ts +17 -0
  56. package/dist/source/snapshot.d.ts.map +1 -0
  57. package/dist/target/changes.d.ts +8 -0
  58. package/dist/target/changes.d.ts.map +1 -0
  59. package/dist/target/collection.d.ts +20 -0
  60. package/dist/target/collection.d.ts.map +1 -0
  61. package/dist/target/mongo-target.d.ts +22 -0
  62. package/dist/target/mongo-target.d.ts.map +1 -0
  63. package/docs/README.md +28 -0
  64. package/docs/guide/errors.md +411 -0
  65. package/docs/guide/format.md +179 -0
  66. package/docs/guide/getting-started.md +716 -0
  67. package/docs/guide/incremental.md +323 -0
  68. package/docs/guide/operations.md +237 -0
  69. package/docs/guide/restore.md +684 -0
  70. package/docs/roadmap.md +61 -0
  71. package/docs/troubleshooting.md +1257 -0
  72. package/package.json +70 -5
@@ -0,0 +1,60 @@
1
+ import type { KeepPolicy, Repository } from '@softistx/backup';
2
+ import type { Db, Document } from 'mongodb';
3
+ import type { CollectionFilter } from '../source/collections.js';
4
+ /** A full backup a week, incrementals in between. */
5
+ export declare const DEFAULT_FULL_EVERY: number;
6
+ /** A day hour by hour, two weeks day by day, two months week by week, a year month by month. */
7
+ export declare const DEFAULT_KEEP: KeepPolicy;
8
+ export interface MongoBackupsOptions {
9
+ /** The database backed up. */
10
+ db: Db;
11
+ /** Where backups go: an absolute folder, or `@softistx/backup` repositories — `s3Repository` among them. */
12
+ repository: string | Repository | readonly [Repository, ...Repository[]];
13
+ /** The file `nxgt-mongo-backup keygen` wrote: an absolute path. */
14
+ keyFile: string;
15
+ /** The backup's name in the repository. The database's name by default. */
16
+ name?: string | undefined;
17
+ /** The collections backed up. All of them by default. */
18
+ collections?: CollectionFilter | undefined;
19
+ /** How old the newest full backup may grow before `run` makes another. A week by default. */
20
+ fullEvery?: number | undefined;
21
+ /** What `run` keeps after each backup; `false` keeps everything. `DEFAULT_KEEP` by default. */
22
+ keep?: KeepPolicy | false | undefined;
23
+ /** Where objects and changes are staged. The system's temporary folder by default. */
24
+ tmpDir?: string | undefined;
25
+ }
26
+ /** Which backup to restore, where to, and how much of it. */
27
+ export type RestoreAtOptions = RestoreWhole | RestoreDocuments;
28
+ interface RestoreCommon {
29
+ /** The database to restore into: another, or the one backed up. */
30
+ into: Db;
31
+ /** A backup's id, or a time: the newest backup made at or before it. The newest by default. */
32
+ at?: string | Date | undefined;
33
+ /** Some collections and views only, by their name at the backup's time. */
34
+ collections?: CollectionFilter | undefined;
35
+ /** Other names to restore them under. */
36
+ as?: Readonly<Record<string, string>> | ((name: string) => string) | undefined;
37
+ }
38
+ /** Collections and views whole, each landed whole or not at all. */
39
+ interface RestoreWhole extends RestoreCommon {
40
+ documents?: undefined;
41
+ /** Replace collections and views already there, rather than refuse them. */
42
+ replace?: boolean | undefined;
43
+ }
44
+ /** Some documents only, merged into what is there: `existing` says how. */
45
+ interface RestoreDocuments extends RestoreCommon {
46
+ documents: {
47
+ filter: Document;
48
+ existing: 'replace' | 'keep';
49
+ };
50
+ replace?: never;
51
+ }
52
+ declare const RULES: readonly ["last", "hourly", "daily", "weekly", "monthly", "yearly", "within", "maxTotalSize"];
53
+ type Missing = Exclude<keyof KeepPolicy, (typeof RULES)[number]>;
54
+ /** Fails to compile when KeepPolicy gains a rule RULES lacks. */
55
+ export declare const RULES_COVER_KEEP: [Missing] extends [never] ? true : never;
56
+ /** What `restore` refuses before it reads a backup; `restoreCollections` checks the rest. */
57
+ export declare function checkRestore(at: RestoreAtOptions, where: string): void;
58
+ export declare function checkOptions(options: MongoBackupsOptions): void;
59
+ export {};
60
+ //# sourceMappingURL=options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../src/backups/options.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,KAAK,EAAE,EAAE,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAK9D,qDAAqD;AACrD,eAAO,MAAM,kBAAkB,QAAU,CAAC;AAE1C,gGAAgG;AAChG,eAAO,MAAM,YAAY,EAAE,UAK1B,CAAC;AAEF,MAAM,WAAW,mBAAmB;IACnC,8BAA8B;IAC9B,EAAE,EAAE,EAAE,CAAC;IACP,4GAA4G;IAC5G,UAAU,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS,CAAC,UAAU,EAAE,GAAG,UAAU,EAAE,CAAC,CAAC;IACzE,mEAAmE;IACnE,OAAO,EAAE,MAAM,CAAC;IAChB,2EAA2E;IAC3E,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,yDAAyD;IACzD,WAAW,CAAC,EAAE,gBAAgB,GAAG,SAAS,CAAC;IAC3C,6FAA6F;IAC7F,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,+FAA+F;IAC/F,IAAI,CAAC,EAAE,UAAU,GAAG,KAAK,GAAG,SAAS,CAAC;IACtC,sFAAsF;IACtF,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC5B;AAED,6DAA6D;AAC7D,MAAM,MAAM,gBAAgB,GAAG,YAAY,GAAG,gBAAgB,CAAC;AAE/D,UAAU,a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/** What a drill restored: each collection and its documents. */
4
+ export interface DrillReport {
5
+ id: string;
6
+ collections: {
7
+ name: string;
8
+ documents: number;
9
+ }[];
10
+ }
11
+ /** A full backup when none is younger than `fullEvery`, an incremental otherwise. */
12
+ export declare function kindFor(backups: readonly BackupInfo[], now: Date, fullEvery: number): 'full' | 'incremental';
13
+ /**
14
+ * The backup `at` names: an id as it is, a time as the newest backup made
15
+ * at or before it, nothing as the newest of all.
16
+ */
17
+ export declare function chosenBackup(backups: readonly BackupInfo[], at: string | Date | undefined, where: string): string;
18
+ /** Each collection of `db` — views and `system.*` apart — and its documents. */
19
+ export declare function countsOf(db: Db): Promise<DrillReport['collections']>;
20
+ //# sourceMappingURL=plan.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plan.d.ts","sourceRoot":"","sources":["../../src/backups/plan.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAGlC,gEAAgE;AAChE,MAAM,WAAW,WAAW;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CACnD;AAED,qFAAqF;AACrF,wBAAgB,OAAO,CACtB,OAAO,EAAE,SAAS,UAAU,EAAE,EAC9B,GAAG,EAAE,IAAI,EACT,SAAS,EAAE,MAAM,GACf,MAAM,GAAG,aAAa,CAOxB;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAC3B,OAAO,EAAE,SAAS,UAAU,EAAE,EAC9B,EAAE,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAC7B,KAAK,EAAE,MAAM,GACX,MAAM,CAeR;AAED,gFAAgF;AAChF,wBAAsB,QAAQ,CAAC,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC,CAW1E"}
@@ -0,0 +1,97 @@
1
+ // src/backups/key-file.ts
2
+ import { createPublicKey } from "node:crypto";
3
+ import { open, unlink } from "node:fs/promises";
4
+ import { dirname } from "node:path";
5
+ import { generateSigningKeys } from "@softistx/backup";
6
+ import { generateIdentity, identityToRecipient } from "age-encryption";
7
+
8
+ // src/errors.ts
9
+ class MongoBackupError2 extends Error {
10
+ name = "MongoBackupError";
11
+ code;
12
+ constructor(message, code, options) {
13
+ super(message, options);
14
+ this.code = code;
15
+ }
16
+ }
17
+ function serverCode(error) {
18
+ const code = error?.code;
19
+ const value = code?.valueOf?.();
20
+ return typeof value === "number" ? value : undefined;
21
+ }
22
+ var BEHIND = /^mongo(Source|Target): /;
23
+ function renamed(p, where) {
24
+ return p.catch((error) => {
25
+ if (!(error instanceof Error) || !BEHIND.test(error.message))
26
+ throw error;
27
+ const message = error.message.replace(BEHIND, `${where}: `);
28
+ throw error instanceof MongoBackupError2 ? new MongoBackupError2(message, error.code, { cause: error }) : new TypeError(message, { cause: error });
29
+ });
30
+ }
31
+
32
+ // src/backups/key-file.ts
33
+ var HEADER = `# @softistx/mongo-backup key file: an age identity, then an Ed25519 signing key.
34
+ ` + `# Keep it secret, and keep a copy away from the backups: without it they are noise.
35
+ `;
36
+ var IDENTITY = /^AGE-SECRET-KEY-1[0-9A-Z]+$/m;
37
+ var PEM = /-----BEGIN PRIVATE KEY-----\n[A-Za-z0-9+/=\n]+-----END PRIVATE KEY-----\n?/;
38
+ var unusable = (where, what, cause) => new MongoBackupError2(`${where}: ${what}`, "KEY_FILE", cause === undefined ? undefined : { cause });
39
+ async function generateKeyFile2(path) {
40
+ const identity = await generateIdentity();
41
+ const { privateKey } = generateSigningKeys();
42
+ const file = await open(path, "wx", 384);
43
+ try {
44
+ await file.writeFile(`${HEADER}${identity}
45
+ ${privateKey}`);
46
+ await file.sync();
47
+ } catch (error) {
48
+ await file.close().catch(() => {
49
+ return;
50
+ });
51
+ await unlink(path).catch(() => {
52
+ return;
53
+ });
54
+ throw error;
55
+ }
56
+ await file.close();
57
+ const folder = await open(dirname(path), "r");
58
+ await folder.sync().finally(() => folder.close());
59
+ return { recipient: await identityToRecipient(identity) };
60
+ }
61
+ async function readKeyFile2(path, where = "readKeyFile") {
62
+ const file = await open(path, "r").catch((error) => {
63
+ if (error.code !== "ENOENT")
64
+ throw error;
65
+ throw unusable(where, "there is no key file there; write one with nxgt-mongo-backup keygen", error);
66
+ });
67
+ let text;
68
+ try {
69
+ if (((await file.stat()).mode & 63) !== 0) {
70
+ throw unusable(where, "others than its owner can read or write the key file; chmod 600 it");
71
+ }
72
+ text = await file.readFile("utf8");
73
+ } finally {
74
+ await file.close();
75
+ }
76
+ return keysIn(text, where);
77
+ }
78
+ async function keysIn(text, where) {
79
+ const identity = text.match(IDENTITY)?.[0];
80
+ const signingKey = text.match(PEM)?.[0];
81
+ if (identity && signingKey) {
82
+ try {
83
+ const key = createPublicKey(signingKey);
84
+ if (key.asymmetricKeyType !== "ed25519")
85
+ throw new Error;
86
+ const publicKey = key.export({ type: "spki", format: "pem" }).toString();
87
+ const recipient = await identityToRecipient(identity);
88
+ return { identity, recipient, signingKey, publicKey };
89
+ } catch {}
90
+ }
91
+ throw unusable(where, "the key file is not one keygen wrote");
92
+ }
93
+
94
+ export { MongoBackupError2, serverCode, renamed, generateKeyFile2, readKeyFile2 };
95
+
96
+ //# debugId=C6BC4985B6E23EB764756E2164756E21
97
+ //# sourceMappingURL=index-j0tptz7w.js.map
@@ -0,0 +1,11 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/backups/key-file.ts", "../src/errors.ts"],
4
+ "sourcesContent": [
5
+ "import { createPublicKey } from 'node:crypto';\nimport { open, unlink } from 'node:fs/promises';\nimport { dirname } from 'node:path';\nimport { generateSigningKeys } from '@softistx/backup';\nimport { generateIdentity, identityToRecipient } from 'age-encryption';\nimport { MongoBackupError } from '../errors';\n\n/** The keys a backup job needs, all read from one file. */\nexport interface BackupKeys {\n\t/** The age secret key: to read backups, an incremental's base included. */\n\tidentity: string;\n\t/** Its public half, `age1…`: every backup is encrypted to it. */\n\trecipient: string;\n\t/** The Ed25519 private key, PEM: every manifest is signed with it. */\n\tsigningKey: string;\n\t/** Its public half, PEM: a manifest must be signed by it to be read. */\n\tpublicKey: string;\n}\n\nconst HEADER =\n\t'# @softistx/mongo-backup key file: an age identity, then an Ed25519 signing key.\\n' +\n\t'# Keep it secret, and keep a copy away from the backups: without it they are noise.\\n';\n\nconst IDENTITY = /^AGE-SECRET-KEY-1[0-9A-Z]+$/m;\nconst PEM =\n\t/-----BEGIN PRIVATE KEY-----\\n[A-Za-z0-9+/=\\n]+-----END PRIVATE KEY-----\\n?/;\n\nconst unusable = (where: string, what: string, cause?: unknown) =>\n\tnew MongoBackupError(\n\t\t`${where}: ${what}`,\n\t\t'KEY_FILE',\n\t\tcause === undefined ? undefined : { cause },\n\t);\n\n/**\n * Writes a new key file at `path`, readable by its owner alone, synced with\n * its folder, and gives its recipient — the public half, safe to print. A\n * file already there is never overwritten: the backups made with it would\n * be lost with it. A write that fails removes the file it created.\n */\nexport async function generateKeyFile(\n\tpath: string,\n): Promise<{ recipient: string }> {\n\tconst identity = await generateIdentity();\n\tconst { privateKey } = generateSigningKeys();\n\tconst file = await open(path, 'wx', 0o600);\n\ttry {\n\t\tawait file.writeFile(`${HEADER}${identity}\\n${privateKey}`);\n\t\tawait file.sync();\n\t} catch (error) {\n\t\tawait file.close().catch(() => undefined);\n\t\tawait unlink(path).catch(() => undefined);\n\t\tthrow error;\n\t}\n\tawait file.close();\n\tconst folder = await open(dirname(path), 'r');\n\tawait folder.sync().finally(() => folder.close());\n\treturn { recipient: await identityToRecipient(identity) };\n}\n\n/**\n * The keys in the file at `path`, checked and read through one descriptor.\n * `KEY_FILE` when it is not there (the system's error as its `cause`), when\n * others than its owner can read it — as ssh refuses such a key — and when\n * it is not one `generateKeyFile` wrote; any other failure to open it is the\n * system's, as it is. No message quotes the file's content. `where` names\n * the call in messages.\n */\nexport async function readKeyFile(\n\tpath: string,\n\twhere = 'readKeyFile',\n): Promise<BackupKeys> {\n\tconst file = await open(path, 'r').catch((error: unknown) => {\n\t\tif ((error as { code?: unknown }).code !== 'ENOENT') throw error;\n\t\tthrow unusable(\n\t\t\twhere,\n\t\t\t'there is no key file there; write one with nxgt-mongo-backup keygen',\n\t\t\terror,\n\t\t);\n\t});\n\tlet text: string;\n\ttry {\n\t\tif (((await file.stat()).mode & 0o077) !== 0) {\n\t\t\tthrow unusable(\n\t\t\t\twhere,\n\t\t\t\t'others than its owner can read or write the key file; chmod 600 it',\n\t\t\t);\n\t\t}\n\t\ttext = await file.readFile('utf8');\n\t} finally {\n\t\tawait file.close();\n\t}\n\treturn keysIn(text, where);\n}\n\nasync function keysIn(text: string, where: string): Promise<BackupKeys> {\n\tconst identity = text.match(IDENTITY)?.[0];\n\tconst signingKey = text.match(PEM)?.[0];\n\tif (identity && signingKey) {\n\t\t// Either throws with the key in its message: neither is kept.\n\t\ttry {\n\t\t\tconst key = createPublicKey(signingKey);\n\t\t\tif (key.asymmetricKeyType !== 'ed25519') throw new Error();\n\t\t\tconst publicKey = key.export({ type: 'spki', format: 'pem' }).toString();\n\t\t\tconst recipient = await identityToRecipient(identity);\n\t\t\treturn { identity, recipient, signingKey, publicKey };\n\t\t} catch {}\n\t}\n\tthrow unusable(where, 'the key file is not one keygen wrote');\n}\n",
6
+ "export type MongoBackupErrorCode =\n\t/** The snapshot outlived what the server keeps of its history. */\n\t| 'SNAPSHOT_TOO_OLD'\n\t/** The collections or their indexes kept changing while the snapshot was taken. */\n\t| 'CHANGING'\n\t/** The change stream cannot resume from the recorded position. */\n\t| 'HISTORY_LOST'\n\t/** The database holds something this version does not back up. */\n\t| 'UNSUPPORTED'\n\t/** A collection or view the restore would write is already there. */\n\t| 'EXISTS'\n\t/** An entry is not one this version wrote. */\n\t| 'MALFORMED'\n\t/** A collection a restore names is not in the backup, or no backup is there to restore. */\n\t| 'NOT_FOUND'\n\t/** The key file is not one `keygen` wrote, or others can read it. */\n\t| 'KEY_FILE';\n\n/**\n * What `@softistx/mongo-backup` throws, told apart by `code`. Its message says\n * what went wrong and never quotes a value, a document or a collection's\n * name — only the backup's own name, which the caller configured: a backup\n * error ends up in logs.\n */\nexport class MongoBackupError extends Error {\n\toverride readonly name = 'MongoBackupError';\n\treadonly code: MongoBackupErrorCode;\n\n\tconstructor(\n\t\tmessage: string,\n\t\tcode: MongoBackupErrorCode,\n\t\toptions?: { cause?: unknown },\n\t) {\n\t\tsuper(message, options);\n\t\tthis.code = code;\n\t}\n}\n\n/**\n * The server's numeric error code, if `error` carries one. A command read\n * with `promoteValues: false` — a change stream that keeps number kinds —\n * gives it as a BSON `Int32`, not a number.\n */\nexport function serverCode(error: unknown): number | undefined {\n\tconst code = (error as { code?: unknown } | null)?.code;\n\tconst value = (code as { valueOf?: () => unknown } | null)?.valueOf?.();\n\treturn typeof value === 'number' ? value : undefined;\n}\n\nconst BEHIND = /^mongo(Source|Target): /;\n\n/**\n * `p`, its `mongoSource:` and `mongoTarget:` refusals told as `where` — the\n * call the consumer wrote — with the same class and code, the original as\n * `cause`. Any other error passes as it is.\n */\nexport function renamed<T>(p: Promise<T>, where: string): Promise<T> {\n\treturn p.catch((error: unknown) => {\n\t\tif (!(error instanceof Error) || !BEHIND.test(error.message)) throw error;\n\t\tconst message = error.message.replace(BEHIND, `${where}: `);\n\t\tthrow error instanceof MongoBackupError\n\t\t\t? new MongoBackupError(message, error.code, { cause: error })\n\t\t\t: new TypeError(message, { cause: error });\n\t});\n}\n"
7
+ ],
8
+ "mappings": ";AAAA;AACA;AACA;AACA;AACA;;;ACoBO,MAAM,0BAAyB,MAAM;AAAA,EACzB,OAAO;AAAA,EAChB;AAAA,EAET,WAAW,CACV,SACA,MACA,SACC;AAAA,IACD,MAAM,SAAS,OAAO;AAAA,IACtB,KAAK,OAAO;AAAA;AAEd;AAOO,SAAS,UAAU,CAAC,OAAoC;AAAA,EAC9D,MAAM,OAAQ,OAAq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ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env bun
2
+ export {};
3
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
package/dist/cli.js ADDED
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env bun
2
+ import {
3
+ generateKeyFile2
4
+ } from "./chunks/index-j0tptz7w.js";
5
+
6
+ // src/cli.ts
7
+ import { isAbsolute, resolve } from "node:path";
8
+ var USAGE = "usage: nxgt-mongo-backup keygen <path>";
9
+ var [command, path] = Bun.argv.slice(2);
10
+ if (command === "--help" || command === "-h") {
11
+ console.log(USAGE);
12
+ process.exit(0);
13
+ }
14
+ if (command !== "keygen" || !path) {
15
+ console.error(USAGE);
16
+ process.exit(2);
17
+ }
18
+ var file = isAbsolute(path) ? path : resolve(path);
19
+ try {
20
+ const { recipient } = await generateKeyFile2(file);
21
+ console.log(`key file written: ${file}`);
22
+ console.log(`recipient: ${recipient}`);
23
+ console.log("keep a copy of it away from the backups");
24
+ } catch (error) {
25
+ const code = error.code;
26
+ console.error(code === "EEXIST" ? `${file} is already there: it is never overwritten` : `keygen failed: ${error.message}`);
27
+ process.exit(1);
28
+ }
29
+
30
+ //# debugId=6D1CC0F9F71AACD064756E2164756E21
31
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/cli.ts"],
4
+ "sourcesContent": [
5
+ "#!/usr/bin/env bun\n/**\n * The `nxgt-mongo-backup` bin. One command, `keygen <path>`: a new key file\n * for `mongoBackups`, readable by its owner alone. It prints the recipient\n * — the public half — and never a secret.\n */\nimport { isAbsolute, resolve } from 'node:path';\nimport { generateKeyFile } from './backups/key-file';\n\nconst USAGE = 'usage: nxgt-mongo-backup keygen <path>';\nconst [command, path] = Bun.argv.slice(2);\nif (command === '--help' || command === '-h') {\n\tconsole.log(USAGE);\n\tprocess.exit(0);\n}\nif (command !== 'keygen' || !path) {\n\tconsole.error(USAGE);\n\tprocess.exit(2);\n}\nconst file = isAbsolute(path) ? path : resolve(path);\ntry {\n\tconst { recipient } = await generateKeyFile(file);\n\tconsole.log(`key file written: ${file}`);\n\tconsole.log(`recipient: ${recipient}`);\n\tconsole.log('keep a copy of it away from the backups');\n} catch (error) {\n\tconst code = (error as { code?: unknown }).code;\n\tconsole.error(\n\t\tcode === 'EEXIST'\n\t\t\t? `${file} is already there: it is never overwritten`\n\t\t\t: `keygen failed: ${(error as Error).message}`,\n\t);\n\tprocess.exit(1);\n}\n"
6
+ ],
7
+ "mappings": ";;;;;;AAMA;AAGA,IAAM,QAAQ;AACd,KAAO,SAAS,QAAQ,IAAI,KAAK,MAAM,CAAC;AACxC,IAAI,YAAY,YAAY,YAAY,MAAM;AAAA,EAC7C,QAAQ,IAAI,KAAK;AAAA,EACjB,QAAQ,KAAK,CAAC;AACf;AACA,IAAI,YAAY,YAAY,CAAC,MAAM;AAAA,EAClC,QAAQ,MAAM,KAAK;AAAA,EACnB,QAAQ,KAAK,CAAC;AACf;AACA,IAAM,OAAO,WAAW,IAAI,IAAI,OAAO,QAAQ,IAAI;AACnD,IAAI;AAAA,EACH,QAAQ,cAAc,MAAM,iBAAgB,IAAI;AAAA,EAChD,QAAQ,IAAI,qBAAqB,MAAM;AAAA,EACvC,QAAQ,IAAI,cAAc,WAAW;AAAA,EACrC,QAAQ,IAAI,yCAAyC;AAAA,EACpD,OAAO,OAAO;AAAA,EACf,MAAM,OAAQ,MAA6B;AAAA,EAC3C,QAAQ,MACP,SAAS,WACN,GAAG,mDACH,kBAAmB,MAAgB,SACvC;AAAA,EACA,QAAQ,KAAK,CAAC;AAAA;",
8
+ "debugId": "6D1CC0F9F71AACD064756E2164756E21",
9
+ "names": []
10
+ }
@@ -0,0 +1,43 @@
1
+ export type MongoBackupErrorCode =
2
+ /** The snapshot outlived what the server keeps of its history. */
3
+ 'SNAPSHOT_TOO_OLD'
4
+ /** The collections or their indexes kept changing while the snapshot was taken. */
5
+ | 'CHANGING'
6
+ /** The change stream cannot resume from the recorded position. */
7
+ | 'HISTORY_LOST'
8
+ /** The database holds something this version does not back up. */
9
+ | 'UNSUPPORTED'
10
+ /** A collection or view the restore would write is already there. */
11
+ | 'EXISTS'
12
+ /** An entry is not one this version wrote. */
13
+ | 'MALFORMED'
14
+ /** A collection a restore names is not in the backup, or no backup is there to restore. */
15
+ | 'NOT_FOUND'
16
+ /** The key file is not one `keygen` wrote, or others can read it. */
17
+ | 'KEY_FILE';
18
+ /**
19
+ * What `@softistx/mongo-backup` throws, told apart by `code`. Its message says
20
+ * what went wrong and never quotes a value, a document or a collection's
21
+ * name — only the backup's own name, which the caller configured: a backup
22
+ * error ends up in logs.
23
+ */
24
+ export declare class MongoBackupError extends Error {
25
+ readonly name = "MongoBackupError";
26
+ readonly code: MongoBackupErrorCode;
27
+ constructor(message: string, code: MongoBackupErrorCode, options?: {
28
+ cause?: unknown;
29
+ });
30
+ }
31
+ /**
32
+ * The server's numeric error code, if `error` carries one. A command read
33
+ * with `promoteValues: false` — a change stream that keeps number kinds —
34
+ * gives it as a BSON `Int32`, not a number.
35
+ */
36
+ export declare function serverCode(error: unknown): number | undefined;
37
+ /**
38
+ * `p`, its `mongoSource:` and `mongoTarget:` refusals told as `where` — the
39
+ * call the consumer wrote — with the same class and code, the original as
40
+ * `cause`. Any other error passes as it is.
41
+ */
42
+ export declare function renamed<T>(p: Promise<T>, where: string): Promise<T>;
43
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,oBAAoB;AAC/B,kEAAkE;AAChE,kBAAkB;AACpB,mFAAmF;GACjF,UAAU;AACZ,kEAAkE;GAChE,cAAc;AAChB,kEAAkE;GAChE,aAAa;AACf,qEAAqE;GACnE,QAAQ;AACV,8CAA8C;GAC5C,WAAW;AACb,2FAA2F;GACzF,WAAW;AACb,qEAAqE;GACnE,UAAU,CAAC;AAEd;;;;;GAKG;AACH,qBAAa,gBAAiB,SAAQ,KAAK;IAC1C,SAAkB,IAAI,sBAAsB;IAC5C,QAAQ,CAAC,IAAI,EAAE,oBAAoB,CAAC;gBAGnC,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,oBAAoB,EAC1B,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE;CAK9B;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAI7D;AAID;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CAQnE"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * The largest document read back: the server's 16 MiB, and room for the
3
+ * fields a change record adds around one.
4
+ */
5
+ export declare const DOCUMENT_MAX_BYTES: number;
6
+ /**
7
+ * The BSON documents of a stream of concatenated ones — each its own bytes,
8
+ * length first, as `mongodump` writes them. Each is filled in place as the
9
+ * chunks arrive, so a large one is copied once. A length that is not one,
10
+ * or a stream that ends inside a document, is `MALFORMED`.
11
+ */
12
+ export declare function bsonDocuments(stream: ReadableStream<Uint8Array>, where: string): AsyncGenerator<Uint8Array>;
13
+ //# sourceMappingURL=bson-stream.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bson-stream.d.ts","sourceRoot":"","sources":["../../src/format/bson-stream.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,eAAO,MAAM,kBAAkB,QAAmB,CAAC;AAEnD;;;;;GAKG;AACH,wBAAuB,aAAa,CACnC,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,EAClC,KAAK,EAAE,MAAM,GACX,cAAc,CAAC,UAAU,CAAC,CAwC5B"}
@@ -0,0 +1,61 @@
1
+ import { type Document } from 'mongodb';
2
+ /**
3
+ * One change as a backup records it: what applying it again needs, and no
4
+ * more — a document written, updated or deleted, or a collection created,
5
+ * indexed, modified, renamed or dropped.
6
+ */
7
+ export type Change = {
8
+ op: 'insert' | 'replace';
9
+ coll: string;
10
+ key: Document;
11
+ doc: Document;
12
+ } | {
13
+ op: 'update';
14
+ coll: string;
15
+ key: Document;
16
+ set: Document;
17
+ unset: string[];
18
+ truncated: {
19
+ field: string;
20
+ newSize: number;
21
+ }[];
22
+ } | {
23
+ op: 'delete';
24
+ coll: string;
25
+ key: Document;
26
+ } | {
27
+ op: 'create';
28
+ coll: string;
29
+ options: Document;
30
+ } | {
31
+ op: 'createIndexes';
32
+ coll: string;
33
+ indexes: Document[];
34
+ } | {
35
+ op: 'dropIndexes';
36
+ coll: string;
37
+ names: string[];
38
+ } | {
39
+ op: 'modify';
40
+ coll: string;
41
+ changes: Document;
42
+ } | {
43
+ op: 'drop';
44
+ coll: string;
45
+ } | {
46
+ op: 'rename';
47
+ coll: string;
48
+ to: string;
49
+ dropTarget: boolean;
50
+ } | {
51
+ op: 'dropDatabase';
52
+ };
53
+ /** What BSON keeps exactly: no number becomes another kind of number. */
54
+ export declare const EXACT: {
55
+ readonly promoteValues: false;
56
+ readonly bsonRegExp: true;
57
+ };
58
+ export declare function writeChange(change: Change): Uint8Array;
59
+ /** The change a record holds, or nothing when it is not one this version wrote. */
60
+ export declare function readChange(bytes: Uint8Array): Change | undefined;
61
+ //# sourceMappingURL=change.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"change.d.ts","sourceRoot":"","sources":["../../src/format/change.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,KAAK,QAAQ,EAAE,MAAM,SAAS,CAAC;AAG9C;;;;GAIG;AACH,MAAM,MAAM,MAAM,GACf;IAAE,EAAE,EAAE,QAAQ,GAAG,SAAS,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,QAAQ,C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nF,wBAAgB,UAAU,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,GAAG,SAAS,CA6ChE"}
@@ -0,0 +1,7 @@
1
+ import type { Document } from 'mongodb';
2
+ /**
3
+ * Whether `value` is a document: an object that is neither an array nor a
4
+ * BSON value — read with `promoteValues: false`, an `Int32` is an object too.
5
+ */
6
+ export declare function isDocument(value: unknown): value is Document;
7
+ //# sourceMappingURL=document.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"document.d.ts","sourceRoot":"","sources":["../../src/format/document.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAExC;;;GAGG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,QAAQ,CAO5D"}
@@ -0,0 +1,14 @@
1
+ import { type Document } from 'mongodb';
2
+ /** What a backup records of a collection or a view, besides its documents. */
3
+ export interface Metadata {
4
+ type: 'collection' | 'view';
5
+ /** What `listCollections` gave as its options: validator, collation, capped… */
6
+ options: Document;
7
+ /** Its indexes as `listIndexes` gave them, `_id` apart. */
8
+ indexes: Document[];
9
+ }
10
+ /** `metadata` as the backup records it: canonical Extended JSON. */
11
+ export declare function writeMetadata(metadata: Metadata): string;
12
+ /** The metadata an entry holds, or nothing when it is not one this version wrote. */
13
+ export declare function readMetadata(text: string): Metadata | undefined;
14
+ //# sourceMappingURL=metadata.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metadata.d.ts","sourceRoot":"","sources":["../../src/format/metadata.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,KAAK,QAAQ,EAAE,MAAM,SAAS,CAAC;AAK9C,8EAA8E;AAC9E,MAAM,WAAW,QAAQ;IACxB,IAAI,EAAE,YAAY,GAAG,MAAM,CAAC;IAC5B,gFAAgF;IAChF,OAAO,EAAE,QAAQ,CAAC;IAClB,2DAA2D;IAC3D,OAAO,EAAE,QAAQ,EAAE,CAAC;CACpB;AAED,oEAAoE;AACpE,wBAAgB,aAAa,CAAC,QAAQ,EAAE,QAAQ,GAAG,MAAM,CAKxD;AAED,qFAAqF;AACrF,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS,CAsB/D"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * How entries are named: `metadata/<collection>` (its options and indexes,
3
+ * as canonical Extended JSON), `documents/<collection>` (its documents, as
4
+ * concatenated BSON, the format `mongodump` writes), `changes/<n>` (the
5
+ * changes an incremental or differential backup read, as concatenated BSON,
6
+ * numbered in the order they apply).
7
+ */
8
+ export declare const METADATA = "metadata/";
9
+ export declare const DOCUMENTS = "documents/";
10
+ export declare const CHANGES = "changes/";
11
+ export type EntryName = {
12
+ kind: 'metadata' | 'documents';
13
+ collection: string;
14
+ } | {
15
+ kind: 'changes';
16
+ sequence: number;
17
+ };
18
+ /** What an entry name says, or nothing when it is not one this version writes. */
19
+ export declare function parseName(name: string): EntryName | undefined;
20
+ /** The name of the `sequence`th changes entry. */
21
+ export declare function changesName(sequence: number): string;
22
+ //# sourceMappingURL=names.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"names.d.ts","sourceRoot":"","sources":["../../src/format/names.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,eAAO,MAAM,QAAQ,cAAc,CAAC;AACpC,eAAO,MAAM,SAAS,eAAe,CAAC;AACtC,eAAO,MAAM,OAAO,aAAa,CAAC;AAElC,MAAM,MAAM,SAAS,GAClB;IAAE,IAAI,EAAE,UAAU,GAAG,WAAW,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,GACtD;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC;AAEzC,kFAAkF;AAClF,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,CAgB7D;AAED,kDAAkD;AAClD,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEpD"}
@@ -0,0 +1,29 @@
1
+ import { type Document, type Timestamp } from 'mongodb';
2
+ /**
3
+ * Where a change stream starts: just after the cluster time a full backup's
4
+ * snapshot read at, or after the last change an incremental one read.
5
+ */
6
+ export type Resume = {
7
+ startAtOperationTime: Timestamp;
8
+ } | {
9
+ startAfter: Document;
10
+ };
11
+ /**
12
+ * Where the next incremental backup starts, and how the collections and
13
+ * views it follows differ from those of the chain's full backup — each of
14
+ * which has its `metadata/<name>` entry, so the position stays small
15
+ * however many there are. A change to `collections` takes effect at the
16
+ * next full backup, never halfway through a chain.
17
+ */
18
+ export interface Position {
19
+ resume: Resume;
20
+ /** Followed now, with no metadata entry: created since the full backup. */
21
+ added: string[];
22
+ /** Not followed any more, though the full backup holds them. */
23
+ removed: string[];
24
+ }
25
+ /** `position` as the backup records it: canonical Extended JSON. */
26
+ export declare function writePosition(position: Position): string;
27
+ /** The position a backup recorded, or nothing when it is not one this version wrote. */
28
+ export declare function readPosition(text: string | undefined): Position | undefined;
29
+ //# sourceMappingURL=position.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"position.d.ts","sourceRoot":"","sources":["../../src/format/position.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,KAAK,QAAQ,EAAE,KAAK,SAAS,EAAE,MAAM,SAAS,CAAC;AAK9D;;;GAGG;AACH,MAAM,MAAM,MAAM,GACf;IAAE,oBAAoB,EAAE,SAAS,CAAA;CAAE,GACnC;IAAE,UAAU,EAAE,QAAQ,CAAA;CAAE,CAAC;AAE5B;;;;;;GAMG;AACH,MAAM,WAAW,QAAQ;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,2EAA2E;IAC3E,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,gEAAgE;IAChE,OAAO,EAAE,MAAM,EAAE,CAAC;CAClB;AAED,oEAAoE;AACpE,wBAAgB,aAAa,CAAC,QAAQ,EAAE,QAAQ,GAAG,MAAM,CAUxD;AAaD,wFAAwF;AACxF,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,QAAQ,GAAG,SAAS,CAe3E"}
@@ -0,0 +1,17 @@
1
+ export type { BackupKeys } from './backups/key-file.js';
2
+ export { generateKeyFile, readKeyFile } from './backups/key-file.js';
3
+ export type { MongoBackups, RestoreReport, RunReport, } from './backups/mongo-backups.js';
4
+ export { mongoBackups } from './backups/mongo-backups.js';
5
+ export type { MongoBackupsOptions, RestoreAtOptions } from './backups/options.js';
6
+ export { DEFAULT_FULL_EVERY, DEFAULT_KEEP } from './backups/options.js';
7
+ export type { DrillReport } from './backups/plan.js';
8
+ export type { MongoBackupErrorCode } from './errors.js';
9
+ export { MongoBackupError } from './errors.js';
10
+ export type { DocumentSelection, RestoreCollectionsOptions, RestoredCollections, Restorer, } from './restore/options.js';
11
+ export { restoreCollections } from './restore/restore-collections.js';
12
+ export type { CollectionFilter } from './source/collections.js';
13
+ export type { MongoSourceOptions } from './source/mongo-source.js';
14
+ export { mongoSource } from './source/mongo-source.js';
15
+ export type { MongoTargetOptions } from './target/mongo-target.js';
16
+ export { mongoTarget } from './target/mongo-target.js';
17
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAClE,YAAY,EACX,YAAY,EACZ,aAAa,EACb,SAAS,GACT,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,YAAY,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC/E,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACrE,YAAY,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,YAAY,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC5C,YAAY,EACX,iBAAiB,EACjB,yBAAyB,EACzB,mBAAmB,EACnB,QAAQ,GACR,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,YAAY,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,YAAY,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,YAAY,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC"}