@sharadox/database-web-library 0.0.0-stage → 0.1.0-database-backup.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.
Files changed (105) hide show
  1. package/LICENCA.md +76 -0
  2. package/LICENSE.md +76 -0
  3. package/NOTICE.md +3 -0
  4. package/README.md +151 -2
  5. package/distribution/backup-command/index.d.ts +21 -0
  6. package/distribution/backup-command/index.d.ts.map +1 -0
  7. package/distribution/backup-command/index.js +87 -0
  8. package/distribution/backup-command/index.js.map +1 -0
  9. package/distribution/backup-command/type.d.ts +17 -0
  10. package/distribution/backup-command/type.d.ts.map +1 -0
  11. package/distribution/backup-command/type.js +2 -0
  12. package/distribution/backup-command/type.js.map +1 -0
  13. package/distribution/backup-dump/index.d.ts +20 -0
  14. package/distribution/backup-dump/index.d.ts.map +1 -0
  15. package/distribution/backup-dump/index.js +44 -0
  16. package/distribution/backup-dump/index.js.map +1 -0
  17. package/distribution/backup-dump/type.d.ts +9 -0
  18. package/distribution/backup-dump/type.d.ts.map +1 -0
  19. package/distribution/backup-dump/type.js +2 -0
  20. package/distribution/backup-dump/type.js.map +1 -0
  21. package/distribution/backup-encryption/index.d.ts +17 -0
  22. package/distribution/backup-encryption/index.d.ts.map +1 -0
  23. package/distribution/backup-encryption/index.js +38 -0
  24. package/distribution/backup-encryption/index.js.map +1 -0
  25. package/distribution/backup-storage/index.d.ts +11 -0
  26. package/distribution/backup-storage/index.d.ts.map +1 -0
  27. package/distribution/backup-storage/index.js +27 -0
  28. package/distribution/backup-storage/index.js.map +1 -0
  29. package/distribution/backup-storage/type.d.ts +16 -0
  30. package/distribution/backup-storage/type.d.ts.map +1 -0
  31. package/distribution/backup-storage/type.js +2 -0
  32. package/distribution/backup-storage/type.js.map +1 -0
  33. package/distribution/database/index.d.ts +15 -0
  34. package/distribution/database/index.d.ts.map +1 -0
  35. package/distribution/database/index.js +17 -0
  36. package/distribution/database/index.js.map +1 -0
  37. package/distribution/database-backup/index.d.ts +20 -0
  38. package/distribution/database-backup/index.d.ts.map +1 -0
  39. package/distribution/database-backup/index.js +49 -0
  40. package/distribution/database-backup/index.js.map +1 -0
  41. package/distribution/database-backup/type.d.ts +28 -0
  42. package/distribution/database-backup/type.d.ts.map +1 -0
  43. package/distribution/database-backup/type.js +2 -0
  44. package/distribution/database-backup/type.js.map +1 -0
  45. package/distribution/database-configuration/index.d.ts +10 -0
  46. package/distribution/database-configuration/index.d.ts.map +1 -0
  47. package/distribution/database-configuration/index.js +20 -0
  48. package/distribution/database-configuration/index.js.map +1 -0
  49. package/distribution/database-configuration/type.d.ts +6 -0
  50. package/distribution/database-configuration/type.d.ts.map +1 -0
  51. package/distribution/database-configuration/type.js +2 -0
  52. package/distribution/database-configuration/type.js.map +1 -0
  53. package/distribution/es-lint-plugin/index.d.ts +29 -0
  54. package/distribution/es-lint-plugin/index.d.ts.map +1 -0
  55. package/distribution/es-lint-plugin/index.js +56 -0
  56. package/distribution/es-lint-plugin/index.js.map +1 -0
  57. package/distribution/git-hub-web-identity/index.d.ts +9 -0
  58. package/distribution/git-hub-web-identity/index.d.ts.map +1 -0
  59. package/distribution/git-hub-web-identity/index.js +18 -0
  60. package/distribution/git-hub-web-identity/index.js.map +1 -0
  61. package/distribution/memory-backup-storage/index.d.ts +12 -0
  62. package/distribution/memory-backup-storage/index.d.ts.map +1 -0
  63. package/distribution/memory-backup-storage/index.js +22 -0
  64. package/distribution/memory-backup-storage/index.js.map +1 -0
  65. package/distribution/memory-database/index.d.ts +14 -0
  66. package/distribution/memory-database/index.d.ts.map +1 -0
  67. package/distribution/memory-database/index.js +20 -0
  68. package/distribution/memory-database/index.js.map +1 -0
  69. package/distribution/memory-database/type.d.ts +9 -0
  70. package/distribution/memory-database/type.d.ts.map +1 -0
  71. package/distribution/memory-database/type.js +2 -0
  72. package/distribution/memory-database/type.js.map +1 -0
  73. package/distribution/migration/index.d.ts +13 -0
  74. package/distribution/migration/index.d.ts.map +1 -0
  75. package/distribution/migration/index.js +64 -0
  76. package/distribution/migration/index.js.map +1 -0
  77. package/distribution/migration/type.d.ts +11 -0
  78. package/distribution/migration/type.d.ts.map +1 -0
  79. package/distribution/migration/type.js +2 -0
  80. package/distribution/migration/type.js.map +1 -0
  81. package/distribution/migration-error/index.d.ts +18 -0
  82. package/distribution/migration-error/index.d.ts.map +1 -0
  83. package/distribution/migration-error/index.js +20 -0
  84. package/distribution/migration-error/index.js.map +1 -0
  85. package/distribution/migration-error/type.d.ts +7 -0
  86. package/distribution/migration-error/type.d.ts.map +1 -0
  87. package/distribution/migration-error/type.js +2 -0
  88. package/distribution/migration-error/type.js.map +1 -0
  89. package/distribution/migration-file/index.d.ts +11 -0
  90. package/distribution/migration-file/index.d.ts.map +1 -0
  91. package/distribution/migration-file/index.js +32 -0
  92. package/distribution/migration-file/index.js.map +1 -0
  93. package/distribution/pglite-pool/index.d.ts +15 -0
  94. package/distribution/pglite-pool/index.d.ts.map +1 -0
  95. package/distribution/pglite-pool/index.js +44 -0
  96. package/distribution/pglite-pool/index.js.map +1 -0
  97. package/distribution/restore-drill/index.d.ts +12 -0
  98. package/distribution/restore-drill/index.d.ts.map +1 -0
  99. package/distribution/restore-drill/index.js +35 -0
  100. package/distribution/restore-drill/index.js.map +1 -0
  101. package/distribution/restore-drill/type.d.ts +20 -0
  102. package/distribution/restore-drill/type.d.ts.map +1 -0
  103. package/distribution/restore-drill/type.js +2 -0
  104. package/distribution/restore-drill/type.js.map +1 -0
  105. package/package.json +103 -3
@@ -0,0 +1,11 @@
1
+ import type { BackupStorage, BackupStorageOptions } from "@sharadox/database-web-library/backup-storage/type";
2
+ /**
3
+ * Backups in an S3 bucket, under the environment's folder. The bucket's Object Lock (compliance mode) keeps every
4
+ * file for its retention, so nobody, not even the account's owner, can delete or change one: this storage only
5
+ * writes, reads and lists.
6
+ *
7
+ * @example
8
+ * const storage = createBackupStorage({ bucket, region: "eu-central-1", prefix: "production", credentials });
9
+ */
10
+ export declare function createBackupStorage({ bucket, region, prefix, credentials }: BackupStorageOptions): BackupStorage;
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/backup-storage/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,oDAAoD,CAAC;AAE9G;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,EAAE,oBAAoB,GAAG,aAAa,CAgBhH"}
@@ -0,0 +1,27 @@
1
+ import { GetObjectCommand, ListObjectsV2Command, PutObjectCommand, S3Client } from "@aws-sdk/client-s3";
2
+ /**
3
+ * Backups in an S3 bucket, under the environment's folder. The bucket's Object Lock (compliance mode) keeps every
4
+ * file for its retention, so nobody, not even the account's owner, can delete or change one: this storage only
5
+ * writes, reads and lists.
6
+ *
7
+ * @example
8
+ * const storage = createBackupStorage({ bucket, region: "eu-central-1", prefix: "production", credentials });
9
+ */
10
+ export function createBackupStorage({ bucket, region, prefix, credentials }) {
11
+ const client = new S3Client({ region, credentials });
12
+ const at = (name) => `${prefix}/${name}`;
13
+ return {
14
+ put: async (name, bytes, contentType) => {
15
+ await client.send(new PutObjectCommand({ Bucket: bucket, Key: at(name), Body: bytes, ContentType: contentType }));
16
+ },
17
+ get: async (name) => {
18
+ const object = await client.send(new GetObjectCommand({ Bucket: bucket, Key: at(name) }));
19
+ return object.Body.transformToByteArray();
20
+ },
21
+ list: async (start) => {
22
+ const listing = await client.send(new ListObjectsV2Command({ Bucket: bucket, Prefix: at(start) }));
23
+ return (listing.Contents ?? []).map(({ Key }) => Key.slice(prefix.length + 1)).sort();
24
+ },
25
+ };
26
+ }
27
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/backup-storage/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAA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EAAE,EAAE,EAAE,CAAC,GAAI,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QACzF,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,16 @@
1
+ /** Where backups are kept (an S3 bucket with Object Lock, or memory in tests). Nothing can be deleted through it. */
2
+ export interface BackupStorage {
3
+ put(name: string, bytes: Uint8Array, contentType: string): Promise<void>;
4
+ get(name: string): Promise<Uint8Array>;
5
+ /** The names under `prefix`, in name order (which is time order for backups). */
6
+ list(prefix: string): Promise<string[]>;
7
+ }
8
+ export interface BackupStorageOptions {
9
+ bucket: string;
10
+ region: string;
11
+ /** The environment's folder in the bucket (`production`). */
12
+ prefix: string;
13
+ /** Short-lived AWS credentials (from the job's own identity, never a stored key). */
14
+ credentials: import("@aws-sdk/client-s3").S3ClientConfig["credentials"];
15
+ }
16
+ //# sourceMappingURL=type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/backup-storage/type.ts"],"names":[],"mappings":"AAAA,qHAAqH;AACrH,MAAM,WAAW,aAAa;IAC5B,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACzE,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IACvC,iFAAiF;IACjF,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;CACzC;AAED,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,6DAA6D;IAC7D,MAAM,EAAE,MAAM,CAAC;IACf,qFAAqF;IACrF,WAAW,EAAE,OAAO,oBAAoB,EAAE,cAAc,CAAC,aAAa,CAAC,CAAC;CACzE"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.js","sourceRoot":"","sources":["../../source/backup-storage/type.ts"],"names":[],"mappings":""}
@@ -0,0 +1,15 @@
1
+ import { Kysely } from "kysely";
2
+ import type { DatabaseConfiguration } from "@sharadox/database-web-library/database-configuration/type";
3
+ /**
4
+ * The production database: Kysely, typed by the schema, over a Neon connection pool (Postgres over WebSockets, made
5
+ * for serverless functions). Nothing connects until the first query. Every value goes to Postgres as a bound
6
+ * parameter; see the `no-raw-sql` lint rule.
7
+ *
8
+ * @example
9
+ * import { createDatabase } from "@sharadox/database-web-library/database";
10
+ * import { readDatabaseConfiguration } from "@sharadox/database-web-library/database-configuration";
11
+ * const database = createDatabase<Schema>(readDatabaseConfiguration());
12
+ * const account = await database.selectFrom("account").selectAll().where("id", "=", id).executeTakeFirst();
13
+ */
14
+ export declare function createDatabase<Schema>({ connectionString }: DatabaseConfiguration): Kysely<Schema>;
15
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/database/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAmB,MAAM,QAAQ,CAAC;AACjD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4DAA4D,CAAC;AAExG;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,EAAE,gBAAgB,EAAE,EAAE,qBAAqB,GAAG,MAAM,CAAC,MAAM,CAAC,CAElG"}
@@ -0,0 +1,17 @@
1
+ import { Pool } from "@neondatabase/serverless";
2
+ import { Kysely, PostgresDialect } from "kysely";
3
+ /**
4
+ * The production database: Kysely, typed by the schema, over a Neon connection pool (Postgres over WebSockets, made
5
+ * for serverless functions). Nothing connects until the first query. Every value goes to Postgres as a bound
6
+ * parameter; see the `no-raw-sql` lint rule.
7
+ *
8
+ * @example
9
+ * import { createDatabase } from "@sharadox/database-web-library/database";
10
+ * import { readDatabaseConfiguration } from "@sharadox/database-web-library/database-configuration";
11
+ * const database = createDatabase<Schema>(readDatabaseConfiguration());
12
+ * const account = await database.selectFrom("account").selectAll().where("id", "=", id).executeTakeFirst();
13
+ */
14
+ export function createDatabase({ connectionString }) {
15
+ return new Kysely({ dialect: new PostgresDialect({ pool: new Pool({ connectionString }) }) });
16
+ }
17
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/database/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAGjD;;;;;;;;;;GAUG;AACH,MAAM,UAAU,cAAc,CAAS,EAAE,gBAAgB,EAAyB;IAChF,OAAO,IAAI,MAAM,CAAS,EAAE,OAAO,EAAE,IAAI,eAAe,CAAC,EAAE,IAAI,EAAE,IAAI,IAAI,CAAC,EAAE,gBAAgB,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;AACxG,CAAC"}
@@ -0,0 +1,20 @@
1
+ import { type Kysely } from "kysely";
2
+ import type { BackupOptions, BackupResult } from "@sharadox/database-web-library/database-backup/type";
3
+ /**
4
+ * Rows per table in the public schema, for the backup's manifest and the restore drill's check. Table names come
5
+ * from the catalog and are quoted as identifiers.
6
+ *
7
+ * @example
8
+ * await tableCounts(database); // { account: 12, contact: 14, … }
9
+ */
10
+ export declare function tableCounts<Schema>(database: Kysely<Schema>): Promise<Record<string, number>>;
11
+ /**
12
+ * Makes one backup: the dump, compressed (gzip) and encrypted (AES-256-GCM), stored as
13
+ * `YYYY/MM/DD/<time>.sql.gz.enc` with a manifest beside it (`<time>.json`: when, size, SHA-256 and rows per table).
14
+ * The bucket's Object Lock then keeps it, unchangeable, for its retention (35 days).
15
+ *
16
+ * @example
17
+ * await backupDatabase({ dump: () => dumpDatabase(url), counts: () => tableCounts(database), storage, key });
18
+ */
19
+ export declare function backupDatabase({ dump, counts, storage, key, now, }: BackupOptions): Promise<BackupResult>;
20
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/database-backup/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAO,KAAK,MAAM,EAAE,MAAM,QAAQ,CAAC;AAE1C,OAAO,KAAK,EAAkB,aAAa,EAAE,YAAY,EAAE,MAAM,qDAAqD,CAAC;AAEvH;;;;;;GAMG;AACH,wBAAsB,WAAW,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAYnG;AAED;;;;;;;GAOG;AACH,wBAAsB,cAAc,CAAC,EACnC,IAAI,EACJ,MAAM,EACN,OAAO,EACP,GAAG,EACH,GAAgB,GACjB,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC,CAiBvC"}
@@ -0,0 +1,49 @@
1
+ import { createHash } from "node:crypto";
2
+ import { gzipSync } from "node:zlib";
3
+ import { sql } from "kysely";
4
+ import { encryptBackup } from "@sharadox/database-web-library/backup-encryption";
5
+ /**
6
+ * Rows per table in the public schema, for the backup's manifest and the restore drill's check. Table names come
7
+ * from the catalog and are quoted as identifiers.
8
+ *
9
+ * @example
10
+ * await tableCounts(database); // { account: 12, contact: 14, … }
11
+ */
12
+ export async function tableCounts(database) {
13
+ const tables = await sql `select tablename as name from pg_tables
14
+ where schemaname = 'public' order by tablename`.execute(database);
15
+ const counts = {};
16
+ for (const { name } of tables.rows) {
17
+ // Schema-qualified: a replayed dump leaves the session with an empty search path.
18
+ const { rows } = await sql `select count(*) as count from ${sql.table(`public.${name}`)}`.execute(database);
19
+ counts[name] = Number(rows[0].count);
20
+ }
21
+ return counts;
22
+ }
23
+ /**
24
+ * Makes one backup: the dump, compressed (gzip) and encrypted (AES-256-GCM), stored as
25
+ * `YYYY/MM/DD/<time>.sql.gz.enc` with a manifest beside it (`<time>.json`: when, size, SHA-256 and rows per table).
26
+ * The bucket's Object Lock then keeps it, unchangeable, for its retention (35 days).
27
+ *
28
+ * @example
29
+ * await backupDatabase({ dump: () => dumpDatabase(url), counts: () => tableCounts(database), storage, key });
30
+ */
31
+ export async function backupDatabase({ dump, counts, storage, key, now = Date.now(), }) {
32
+ const created = new Date(now);
33
+ const tables = await counts();
34
+ const sealed = encryptBackup(gzipSync(await dump()), key);
35
+ const day = created.toISOString().slice(0, 10).replaceAll("-", "/");
36
+ const name = `${day}/${created.toISOString().slice(0, 19).replaceAll(":", "-")}Z`;
37
+ const file = `${name}.sql.gz.enc`;
38
+ const manifest = {
39
+ createdAt: created.toISOString(),
40
+ file,
41
+ bytes: sealed.length,
42
+ sha256: createHash("sha256").update(sealed).digest("hex"),
43
+ tables,
44
+ };
45
+ await storage.put(file, sealed, "application/octet-stream");
46
+ await storage.put(`${name}.json`, new TextEncoder().encode(JSON.stringify(manifest, null, 2)), "application/json");
47
+ return { file, manifest: `${name}.json`, tables };
48
+ }
49
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/database-backup/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,GAAG,EAAe,MAAM,QAAQ,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,kDAAkD,CAAC;AAGjF;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAS,QAAwB;IAChE,MAAM,MAAM,GAAG,MAAM,GAAG,CAAkB;mDACO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IACpE,MAAM,MAAM,GAA2B,EAAE,CAAC;IAC1C,KAAK,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,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;QACzD,MAAM;KACP,CAAC;IACF,MAAM,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,0BAA0B,CAAC,CAAC;IAC5D,MAAM,OAAO,CAAC,GAAG,CAAC,GAAG,IAAI,OAAO,EAAE,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,kBAAkB,CAAC,CAAC;IACnH,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,IAAI,OAAO,EAAE,MAAM,EAAE,CAAC;AACpD,CAAC"}
@@ -0,0 +1,28 @@
1
+ import type { BackupStorage } from "@sharadox/database-web-library/backup-storage/type";
2
+ export interface BackupOptions {
3
+ /** Makes the plain SQL dump (`dumpDatabase`). */
4
+ dump: () => Promise<Uint8Array>;
5
+ /** Rows per table at the time of the dump (`tableCounts`), which the restore drill checks. */
6
+ counts: () => Promise<Record<string, number>>;
7
+ storage: BackupStorage;
8
+ /** `BACKUP_ENCRYPTION_KEY`: at least 32 characters, kept apart from the backups. */
9
+ key: string;
10
+ /** Milliseconds since 1970 (now by default). */
11
+ now?: number;
12
+ }
13
+ /** What a backup wrote: its file, and the rows it holds per table. */
14
+ export interface BackupResult {
15
+ file: string;
16
+ manifest: string;
17
+ tables: Record<string, number>;
18
+ }
19
+ /** Stored beside each backup file. */
20
+ export interface BackupManifest {
21
+ createdAt: string;
22
+ file: string;
23
+ bytes: number;
24
+ /** Of the encrypted file. */
25
+ sha256: string;
26
+ tables: Record<string, number>;
27
+ }
28
+ //# sourceMappingURL=type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/database-backup/type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oDAAoD,CAAC;AAExF,MAAM,WAAW,aAAa;IAC5B,iDAAiD;IACjD,IAAI,EAAE,MAAM,OAAO,CAAC,UAAU,CAAC,CAAC;IAChC,8FAA8F;IAC9F,MAAM,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAC9C,OAAO,EAAE,aAAa,CAAC;IACvB,oFAAoF;IACpF,GAAG,EAAE,MAAM,CAAC;IACZ,gDAAgD;IAChD,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,sEAAsE;AACtE,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAChC;AAED,sCAAsC;AACtC,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,6BAA6B;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAChC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.js","sourceRoot":"","sources":["../../source/database-backup/type.ts"],"names":[],"mappings":""}
@@ -0,0 +1,10 @@
1
+ import type { DatabaseConfiguration } from "@sharadox/database-web-library/database-configuration/type";
2
+ /**
3
+ * Reads the database's address from the environment (`DATABASE_URL`, as Vercel's Neon integration sets it). Throws a
4
+ * message naming the variable, never its value (it holds the password).
5
+ *
6
+ * @example
7
+ * const database = createDatabase<Schema>(readDatabaseConfiguration());
8
+ */
9
+ export declare function readDatabaseConfiguration(environment?: Record<string, string | undefined>): DatabaseConfiguration;
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/database-configuration/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4DAA4D,CAAC;AAQxG;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CACvC,WAAW,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAe,GAC5D,qBAAqB,CAIvB"}
@@ -0,0 +1,20 @@
1
+ import { z } from "zod";
2
+ const schema = z.object({
3
+ DATABASE_URL: z
4
+ .string({ error: "DATABASE_URL is missing" })
5
+ .regex(/^postgres(?:ql)?:\/\//, { error: "DATABASE_URL must be a postgres:// or postgresql:// address" }),
6
+ });
7
+ /**
8
+ * Reads the database's address from the environment (`DATABASE_URL`, as Vercel's Neon integration sets it). Throws a
9
+ * message naming the variable, never its value (it holds the password).
10
+ *
11
+ * @example
12
+ * const database = createDatabase<Schema>(readDatabaseConfiguration());
13
+ */
14
+ export function readDatabaseConfiguration(environment = process.env) {
15
+ const result = schema.safeParse(environment);
16
+ if (!result.success)
17
+ throw new Error(result.error.issues.map(({ message }) => message).join("; "));
18
+ return { connectionString: result.data.DATABASE_URL };
19
+ }
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/database-configuration/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC;IACtB,YAAY,EAAE,CAAC;SACZ,MAAM,CAAC,EAAE,KAAK,EAAE,yBAAyB,EAAE,CAAC;SAC5C,KAAK,CAAC,uBAAuB,EAAE,EAAE,KAAK,EAAE,6DAA6D,EAAE,CAAC;CAC5G,CAAC,CAAC;AAEH;;;;;;GAMG;AACH,MAAM,UAAU,yBAAyB,CACvC,cAAkD,OAAO,CAAC,GAAG;IAE7D,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IAC7C,IAAI,CAAC,MAAM,CAAC,OAAO;QAAE,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IACnG,OAAO,EAAE,gBAAgB,EAAE,MAAM,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC;AACxD,CAAC"}
@@ -0,0 +1,6 @@
1
+ /** How to reach the database. */
2
+ export interface DatabaseConfiguration {
3
+ /** `postgresql://…` (Neon gives it with `?sslmode=require`). A secret: it holds the password. */
4
+ connectionString: string;
5
+ }
6
+ //# sourceMappingURL=type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/database-configuration/type.ts"],"names":[],"mappings":"AAAA,iCAAiC;AACjC,MAAM,WAAW,qBAAqB;IACpC,iGAAiG;IACjG,gBAAgB,EAAE,MAAM,CAAC;CAC1B"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.js","sourceRoot":"","sources":["../../source/database-configuration/type.ts"],"names":[],"mappings":""}
@@ -0,0 +1,29 @@
1
+ import type { Linter, Rule } from "eslint";
2
+ /**
3
+ * ESLint rule `no-raw-sql`: values reach the database only as bound parameters, never inside the SQL text. Reports
4
+ * `sql.raw()`, `sql.lit()`, `CompiledQuery.raw()` and any `.unsafe()`, and a `.query()` whose SQL is built with `+`
5
+ * or a template with `${…}`. Kysely's tagged ``sql`…${value}…` `` stays allowed: its values are parameters. The rare
6
+ * reviewed exception (running a migration file) disables the rule on that line, with the reason.
7
+ */
8
+ export declare const noRawSql: Rule.RuleModule;
9
+ /**
10
+ * The ESLint plugin of database-web-library, with `configs.recommended` turning `no-raw-sql` on.
11
+ *
12
+ * @example
13
+ * // eslint.config.mjs
14
+ * import { nodeConfiguration } from "@sharadox/es-lint-configuration-web-library/node";
15
+ * import { databaseEsLintPlugin } from "@sharadox/database-web-library/es-lint-plugin";
16
+ * export default [...nodeConfiguration(), ...databaseEsLintPlugin.configs.recommended];
17
+ */
18
+ export declare const databaseEsLintPlugin: {
19
+ meta: {
20
+ name: string;
21
+ };
22
+ rules: {
23
+ "no-raw-sql": Rule.RuleModule;
24
+ };
25
+ configs: {
26
+ recommended: Linter.Config[];
27
+ };
28
+ };
29
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/es-lint-plugin/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAU,MAAM,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAanD;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,EAAE,IAAI,CAAC,UAmB3B,CAAC;AAWF;;;;;;;;GAQG;AACH,eAAO,MAAM,oBAAoB;;;;;;;aAfhB;QAAE,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,CAAA;KAAE;CAeP,CAAC"}
@@ -0,0 +1,56 @@
1
+ /** Calls that send text to the database as SQL, unchecked: `sql.raw`, `sql.lit`, `CompiledQuery.raw`, `.unsafe`. */
2
+ const RAW = new Map([
3
+ ["sql", new Set(["raw", "lit"])],
4
+ ["CompiledQuery", new Set(["raw"])],
5
+ ]);
6
+ /** Whether SQL text is put together from pieces at run time (a template with values, or `+`). */
7
+ const isBuilt = (node) => node?.type === "BinaryExpression" ||
8
+ (node?.type === "TemplateLiteral" && node.expressions.length > 0);
9
+ /**
10
+ * ESLint rule `no-raw-sql`: values reach the database only as bound parameters, never inside the SQL text. Reports
11
+ * `sql.raw()`, `sql.lit()`, `CompiledQuery.raw()` and any `.unsafe()`, and a `.query()` whose SQL is built with `+`
12
+ * or a template with `${…}`. Kysely's tagged ``sql`…${value}…` `` stays allowed: its values are parameters. The rare
13
+ * reviewed exception (running a migration file) disables the rule on that line, with the reason.
14
+ */
15
+ export const noRawSql = {
16
+ meta: {
17
+ type: "problem",
18
+ docs: { description: "Send values to the database as parameters, never inside SQL text" },
19
+ messages: {
20
+ raw: "Raw SQL can carry injected text: build the query with Kysely, or ``sql`…${value}…` `` (values become parameters).",
21
+ built: "This SQL is put together from pieces at run time: pass the values as parameters ($1, $2…) instead.",
22
+ },
23
+ schema: [],
24
+ },
25
+ create: (context) => ({
26
+ CallExpression(node) {
27
+ if (node.callee.type !== "MemberExpression" || node.callee.property.type !== "Identifier")
28
+ return;
29
+ const method = node.callee.property.name;
30
+ const object = node.callee.object.type === "Identifier" ? node.callee.object.name : "";
31
+ if (method === "unsafe" || RAW.get(object)?.has(method))
32
+ context.report({ node, messageId: "raw" });
33
+ else if (method === "query" && isBuilt(node.arguments[0]))
34
+ context.report({ node, messageId: "built" });
35
+ },
36
+ }),
37
+ };
38
+ const plugin = {
39
+ meta: { name: "@sharadox/database-web-library/es-lint-plugin" },
40
+ rules: { "no-raw-sql": noRawSql },
41
+ configs: {},
42
+ };
43
+ plugin.configs.recommended = [
44
+ { plugins: { "@sharadox/database": plugin }, rules: { "@sharadox/database/no-raw-sql": "error" } },
45
+ ];
46
+ /**
47
+ * The ESLint plugin of database-web-library, with `configs.recommended` turning `no-raw-sql` on.
48
+ *
49
+ * @example
50
+ * // eslint.config.mjs
51
+ * import { nodeConfiguration } from "@sharadox/es-lint-configuration-web-library/node";
52
+ * import { databaseEsLintPlugin } from "@sharadox/database-web-library/es-lint-plugin";
53
+ * export default [...nodeConfiguration(), ...databaseEsLintPlugin.configs.recommended];
54
+ */
55
+ export const databaseEsLintPlugin = plugin;
56
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/es-lint-plugin/index.ts"],"names":[],"mappings":"AAEA,oHAAoH;AACpH,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC;IAClB,CAAC,KAAK,EAAE,IAAI,GAAG,CAAC,CAAC,K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,IAAI,MAAM,KAAK,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;gBAAE,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,CAAC;QAC1G,CAAC;KACF,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,GAAG;IACb,IAAI,EAAE,EAAE,IAAI,EAAE,+CAA+C,EAAE;IAC/D,KAAK,EAAE,EAAE,YAAY,EAAE,QAAQ,EAAE;IACjC,OAAO,EAAE,EAAsC;CACxB,CAAC;AAC1B,MAAM,CAAC,OAAO,CAAC,WAAW,GAAG;IAC3B,EAAE,OAAO,EAAE,EAAE,oBAAoB,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,EAAE,+BAA+B,EAAE,OAAO,EAAE,EAAE;CACnG,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,MAAM,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * The GitHub Actions job's identity token for AWS (audience `sts.amazonaws.com`), to take an IAM role without any
3
+ * stored key. The job needs `permissions: { id-token: write }`.
4
+ *
5
+ * @example
6
+ * const credentials = fromWebToken({ roleArn, webIdentityToken: await gitHubWebIdentityToken() });
7
+ */
8
+ export declare function gitHubWebIdentityToken(environment?: Record<string, string | undefined>): Promise<string>;
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/git-hub-web-identity/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAsB,sBAAsB,CAC1C,WAAW,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAe,GAC5D,OAAO,CAAC,MAAM,CAAC,CAOjB"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * The GitHub Actions job's identity token for AWS (audience `sts.amazonaws.com`), to take an IAM role without any
3
+ * stored key. The job needs `permissions: { id-token: write }`.
4
+ *
5
+ * @example
6
+ * const credentials = fromWebToken({ roleArn, webIdentityToken: await gitHubWebIdentityToken() });
7
+ */
8
+ export async function gitHubWebIdentityToken(environment = process.env) {
9
+ const url = environment.ACTIONS_ID_TOKEN_REQUEST_URL;
10
+ const token = environment.ACTIONS_ID_TOKEN_REQUEST_TOKEN;
11
+ if (!url || !token)
12
+ throw new Error("no GitHub Actions identity: the job needs permissions id-token: write");
13
+ const response = await fetch(`${url}&audience=sts.amazonaws.com`, { headers: { authorization: `Bearer ${token}` } });
14
+ if (!response.ok)
15
+ throw new Error(`GitHub refused the identity token (${response.status})`);
16
+ return (await response.json()).value;
17
+ }
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/git-hub-web-identity/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,cAAkD,OAAO,CAAC,GAAG;IAE7D,MAAM,GAAG,GAAG,WAAW,CAAC,4BAA4B,CAAC;IACrD,MAAM,KAAK,GAAG,WAAW,CAAC,8BAA8B,CAAC;IACzD,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK;QAAE,MAAM,IAAI,KAAK,CAAC,uEAAuE,CAAC,CAAC;IAC7G,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,GAAG,6BAA6B,EAAE,EAAE,OAAO,EAAE,EAAE,aAAa,EAAE,UAAU,KAAK,EAAE,EAAE,EAAE,CAAC,CAAC;IACrH,IAAI,CAAC,QAAQ,CAAC,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,sCAAsC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC;IAC5F,OAAQ,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAuB,CAAC,KAAK,CAAC;AAC9D,CAAC"}
@@ -0,0 +1,12 @@
1
+ import type { BackupStorage } from "@sharadox/database-web-library/backup-storage/type";
2
+ /**
3
+ * Backup storage in memory, for tests and trying the backup locally: `files` shows what was stored.
4
+ *
5
+ * @example
6
+ * const storage = createMemoryBackupStorage();
7
+ * await backupDatabase({ dump, counts, storage, key });
8
+ */
9
+ export declare function createMemoryBackupStorage(): BackupStorage & {
10
+ files: Map<string, Uint8Array>;
11
+ };
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/memory-backup-storage/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oDAAoD,CAAC;AAExF;;;;;;GAMG;AACH,wBAAgB,yBAAyB,IAAI,aAAa,GAAG;IAAE,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAA;CAAE,CAY9F"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Backup storage in memory, for tests and trying the backup locally: `files` shows what was stored.
3
+ *
4
+ * @example
5
+ * const storage = createMemoryBackupStorage();
6
+ * await backupDatabase({ dump, counts, storage, key });
7
+ */
8
+ export function createMemoryBackupStorage() {
9
+ const files = new Map();
10
+ return {
11
+ files,
12
+ put: async (name, bytes) => void files.set(name, bytes),
13
+ get: async (name) => {
14
+ const bytes = files.get(name);
15
+ if (!bytes)
16
+ throw new Error(`no backup file "${name}"`);
17
+ return bytes;
18
+ },
19
+ list: async (prefix) => [...files.keys()].filter((name) => name.startsWith(prefix)).sort(),
20
+ };
21
+ }
22
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/memory-backup-storage/index.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,MAAM,UAAU,yBAAyB;IACvC,MAAM,KAAK,GAAG,IAAI,GAAG,EAAsB,CAAC;IAC5C,OAAO;QACL,KAAK;QACL,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC;QACvD,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;YAClB,MAAM,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YAC9B,IAAI,CAAC,KAAK;gBAAE,MAAM,IAAI,KAAK,CAAC,mBAAmB,IAAI,GAAG,CAAC,CAAC;YACxD,OAAO,KAAK,CAAC;QACf,CAAC;QACD,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,EAAE;KAC3F,CAAC;AACJ,CAAC"}
@@ -0,0 +1,14 @@
1
+ import type { MemoryDatabase } from "@sharadox/database-web-library/memory-database/type";
2
+ /**
3
+ * A fresh, empty Postgres 18 in memory (PGlite), behind the same Kysely as production: for unit tests of anything
4
+ * that uses a database, with no server, network or cost. Needs `@electric-sql/pglite` installed (a development
5
+ * dependency is enough).
6
+ *
7
+ * @example
8
+ * const { database, close } = await createMemoryDatabase<Schema>();
9
+ * await migrate(database, await readMigrations(new URL("../migration/", import.meta.url)));
10
+ * // … test …
11
+ * await close();
12
+ */
13
+ export declare function createMemoryDatabase<Schema>(): Promise<MemoryDatabase<Schema>>;
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/memory-database/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qDAAqD,CAAC;AAE1F;;;;;;;;;;GAUG;AACH,wBAAsB,oBAAoB,CAAC,MAAM,KAAK,OAAO,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAIpF"}
@@ -0,0 +1,20 @@
1
+ import { PGlite } from "@electric-sql/pglite";
2
+ import { Kysely, PostgresDialect } from "kysely";
3
+ import { pglitePool } from "@sharadox/database-web-library/pglite-pool";
4
+ /**
5
+ * A fresh, empty Postgres 18 in memory (PGlite), behind the same Kysely as production: for unit tests of anything
6
+ * that uses a database, with no server, network or cost. Needs `@electric-sql/pglite` installed (a development
7
+ * dependency is enough).
8
+ *
9
+ * @example
10
+ * const { database, close } = await createMemoryDatabase<Schema>();
11
+ * await migrate(database, await readMigrations(new URL("../migration/", import.meta.url)));
12
+ * // … test …
13
+ * await close();
14
+ */
15
+ export async function createMemoryDatabase() {
16
+ const pglite = await PGlite.create();
17
+ const database = new Kysely({ dialect: new PostgresDialect({ pool: pglitePool(pglite) }) });
18
+ return { database, close: () => database.destroy() };
19
+ }
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/memory-database/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,4CAA4C,CAAC;AAGxE;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB;IACxC,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,MAAM,EAAE,CAAC;IACrC,MAAM,QAAQ,GAAG,IAAI,MAAM,CAAS,EAAE,OAAO,EAAE,IAAI,eAAe,CAAC,EAAE,IAAI,EAAE,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;IACpG,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC;AACvD,CAAC"}
@@ -0,0 +1,9 @@
1
+ import type { Kysely } from "kysely";
2
+ /** A database in memory and the way to close it. */
3
+ export interface MemoryDatabase<Schema> {
4
+ /** Kysely, typed by the schema. */
5
+ database: Kysely<Schema>;
6
+ /** Closes the database; it is gone afterwards. */
7
+ close(): Promise<void>;
8
+ }
9
+ //# sourceMappingURL=type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/memory-database/type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAErC,oDAAoD;AACpD,MAAM,WAAW,cAAc,CAAC,MAAM;IACpC,mCAAmC;IACnC,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;IACzB,kDAAkD;IAClD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.js","sourceRoot":"","sources":["../../source/memory-database/type.ts"],"names":[],"mappings":""}
@@ -0,0 +1,13 @@
1
+ import { type Kysely } from "kysely";
2
+ import type { MigrateOptions, Migration } from "@sharadox/database-web-library/migration/type";
3
+ /**
4
+ * Brings a database up to date: applies, in order, the migrations it hasn't applied yet, all in one transaction (all
5
+ * or none) behind a lock (two deployments never migrate at once), and records each with a checksum of its SQL.
6
+ * Forward only: it refuses (`MigrationError`) when an applied migration was edited or removed, or a new one is
7
+ * numbered before one already applied. Returns the names it applied.
8
+ *
9
+ * @example
10
+ * const applied = await migrate(database, await readMigrations(new URL("../../migration/", import.meta.url)));
11
+ */
12
+ export declare function migrate<Schema>(database: Kysely<Schema>, migrations: Migration[], { table }?: MigrateOptions): Promise<string[]>;
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/migration/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAO,KAAK,MAAM,EAAE,MAAM,QAAQ,CAAC;AAE1C,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,+CAA+C,CAAC;AAmB/F;;;;;;;;GAQG;AACH,wBAAsB,OAAO,CAAC,MAAM,EAClC,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,EACxB,UAAU,EAAE,SAAS,EAAE,EACvB,EAAE,KAA0B,EAAE,GAAE,cAAmB,GAClD,OAAO,CAAC,MAAM,EAAE,CAAC,CAuCnB"}