mindoodb 0.0.97 → 0.0.99

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 (166) hide show
  1. package/README-server.md +15 -0
  2. package/README.md +1 -0
  3. package/dist/appendonlystores/network/ClientNetworkContentAddressedStore.d.ts +7 -0
  4. package/dist/appendonlystores/network/ClientNetworkContentAddressedStore.d.ts.map +1 -1
  5. package/dist/appendonlystores/network/ClientNetworkContentAddressedStore.js +17 -9
  6. package/dist/appendonlystores/network/ClientNetworkContentAddressedStore.js.map +1 -1
  7. package/dist/appendonlystores/network/HttpTransport.d.ts.map +1 -1
  8. package/dist/appendonlystores/network/HttpTransport.js +1 -0
  9. package/dist/appendonlystores/network/HttpTransport.js.map +1 -1
  10. package/dist/appendonlystores/network/ServerNetworkContentAddressedStore.d.ts +18 -0
  11. package/dist/appendonlystores/network/ServerNetworkContentAddressedStore.d.ts.map +1 -1
  12. package/dist/appendonlystores/network/ServerNetworkContentAddressedStore.js +41 -1
  13. package/dist/appendonlystores/network/ServerNetworkContentAddressedStore.js.map +1 -1
  14. package/dist/browser/index.mjs +76 -0
  15. package/dist/core/BaseMindooDB.d.ts +2 -0
  16. package/dist/core/BaseMindooDB.d.ts.map +1 -1
  17. package/dist/core/BaseMindooDB.js +73 -53
  18. package/dist/core/BaseMindooDB.js.map +1 -1
  19. package/dist/core/BaseMindooTenant.d.ts +44 -1
  20. package/dist/core/BaseMindooTenant.d.ts.map +1 -1
  21. package/dist/core/BaseMindooTenant.js +176 -42
  22. package/dist/core/BaseMindooTenant.js.map +1 -1
  23. package/dist/core/BaseMindooTenantDirectory.d.ts +11 -0
  24. package/dist/core/BaseMindooTenantDirectory.d.ts.map +1 -1
  25. package/dist/core/BaseMindooTenantDirectory.js +137 -92
  26. package/dist/core/BaseMindooTenantDirectory.js.map +1 -1
  27. package/dist/core/MindooDBServerAdmin.d.ts +1 -1
  28. package/dist/core/MindooDBServerAdmin.d.ts.map +1 -1
  29. package/dist/core/appendonlystores/migration/StoreMigration.d.ts +41 -1
  30. package/dist/core/appendonlystores/migration/StoreMigration.d.ts.map +1 -1
  31. package/dist/core/appendonlystores/migration/StoreMigration.js +126 -0
  32. package/dist/core/appendonlystores/migration/StoreMigration.js.map +1 -1
  33. package/dist/core/appendonlystores/sqlite/SqliteContentAddressedStore.d.ts.map +1 -1
  34. package/dist/core/appendonlystores/sqlite/SqliteContentAddressedStore.js +29 -0
  35. package/dist/core/appendonlystores/sqlite/SqliteContentAddressedStore.js.map +1 -1
  36. package/dist/core/appendonlystores/syncStores.d.ts +6 -0
  37. package/dist/core/appendonlystores/syncStores.d.ts.map +1 -1
  38. package/dist/core/appendonlystores/syncStores.js +21 -0
  39. package/dist/core/appendonlystores/syncStores.js.map +1 -1
  40. package/dist/core/appendonlystores/types.d.ts +8 -0
  41. package/dist/core/appendonlystores/types.d.ts.map +1 -1
  42. package/dist/core/appendonlystores/types.js.map +1 -1
  43. package/dist/core/builtinDbInvariants.d.ts +26 -1
  44. package/dist/core/builtinDbInvariants.d.ts.map +1 -1
  45. package/dist/core/builtinDbInvariants.js +52 -2
  46. package/dist/core/builtinDbInvariants.js.map +1 -1
  47. package/dist/core/index.d.ts +2 -0
  48. package/dist/core/index.d.ts.map +1 -1
  49. package/dist/core/index.js +3 -0
  50. package/dist/core/index.js.map +1 -1
  51. package/dist/core/joinrequests/crypto.d.ts +110 -0
  52. package/dist/core/joinrequests/crypto.d.ts.map +1 -0
  53. package/dist/core/joinrequests/crypto.js +340 -0
  54. package/dist/core/joinrequests/crypto.js.map +1 -0
  55. package/dist/core/joinrequests/index.d.ts +4 -0
  56. package/dist/core/joinrequests/index.d.ts.map +1 -0
  57. package/dist/core/joinrequests/index.js +29 -0
  58. package/dist/core/joinrequests/index.js.map +1 -0
  59. package/dist/core/joinrequests/invitations.d.ts +257 -0
  60. package/dist/core/joinrequests/invitations.d.ts.map +1 -0
  61. package/dist/core/joinrequests/invitations.js +703 -0
  62. package/dist/core/joinrequests/invitations.js.map +1 -0
  63. package/dist/core/joinrequests/types.d.ts +208 -0
  64. package/dist/core/joinrequests/types.d.ts.map +1 -0
  65. package/dist/core/joinrequests/types.js +43 -0
  66. package/dist/core/joinrequests/types.js.map +1 -0
  67. package/dist/core/recovery/PaperRescueDevice.d.ts +101 -0
  68. package/dist/core/recovery/PaperRescueDevice.d.ts.map +1 -0
  69. package/dist/core/recovery/PaperRescueDevice.js +205 -0
  70. package/dist/core/recovery/PaperRescueDevice.js.map +1 -0
  71. package/dist/core/recovery/RecoveryContactsDocument.d.ts +86 -0
  72. package/dist/core/recovery/RecoveryContactsDocument.d.ts.map +1 -0
  73. package/dist/core/recovery/RecoveryContactsDocument.js +91 -0
  74. package/dist/core/recovery/RecoveryContactsDocument.js.map +1 -0
  75. package/dist/core/recovery/RecoveryContactsManager.d.ts +176 -0
  76. package/dist/core/recovery/RecoveryContactsManager.d.ts.map +1 -0
  77. package/dist/core/recovery/RecoveryContactsManager.js +455 -0
  78. package/dist/core/recovery/RecoveryContactsManager.js.map +1 -0
  79. package/dist/core/recovery/index.d.ts +9 -0
  80. package/dist/core/recovery/index.d.ts.map +1 -0
  81. package/dist/core/recovery/index.js +48 -0
  82. package/dist/core/recovery/index.js.map +1 -0
  83. package/dist/core/recovery/recoverWithContacts.d.ts +56 -0
  84. package/dist/core/recovery/recoverWithContacts.d.ts.map +1 -0
  85. package/dist/core/recovery/recoverWithContacts.js +142 -0
  86. package/dist/core/recovery/recoverWithContacts.js.map +1 -0
  87. package/dist/core/recovery/recoveryPackage.d.ts +80 -0
  88. package/dist/core/recovery/recoveryPackage.d.ts.map +1 -0
  89. package/dist/core/recovery/recoveryPackage.js +182 -0
  90. package/dist/core/recovery/recoveryPackage.js.map +1 -0
  91. package/dist/core/recovery/rescueApproval.d.ts +39 -0
  92. package/dist/core/recovery/rescueApproval.d.ts.map +1 -0
  93. package/dist/core/recovery/rescueApproval.js +52 -0
  94. package/dist/core/recovery/rescueApproval.js.map +1 -0
  95. package/dist/core/recovery/rescueDevice.d.ts +51 -0
  96. package/dist/core/recovery/rescueDevice.d.ts.map +1 -0
  97. package/dist/core/recovery/rescueDevice.js +201 -0
  98. package/dist/core/recovery/rescueDevice.js.map +1 -0
  99. package/dist/core/recovery/shamir.d.ts +30 -0
  100. package/dist/core/recovery/shamir.d.ts.map +1 -0
  101. package/dist/core/recovery/shamir.js +133 -0
  102. package/dist/core/recovery/shamir.js.map +1 -0
  103. package/dist/core/types.d.ts +73 -1
  104. package/dist/core/types.d.ts.map +1 -1
  105. package/dist/core/types.js.map +1 -1
  106. package/dist/core/userkeys/UserKeyManager.d.ts +45 -0
  107. package/dist/core/userkeys/UserKeyManager.d.ts.map +1 -1
  108. package/dist/core/userkeys/UserKeyManager.js +121 -8
  109. package/dist/core/userkeys/UserKeyManager.js.map +1 -1
  110. package/dist/core/userkeys/generationSignature.d.ts +6 -0
  111. package/dist/core/userkeys/generationSignature.d.ts.map +1 -1
  112. package/dist/core/userkeys/generationSignature.js +1 -0
  113. package/dist/core/userkeys/generationSignature.js.map +1 -1
  114. package/dist/core/userkeys/resolveUserKeyDocument.d.ts.map +1 -1
  115. package/dist/core/userkeys/resolveUserKeyDocument.js +6 -6
  116. package/dist/core/userkeys/resolveUserKeyDocument.js.map +1 -1
  117. package/dist/core/userkeys/validateUserKeyDocument.d.ts +11 -1
  118. package/dist/core/userkeys/validateUserKeyDocument.d.ts.map +1 -1
  119. package/dist/core/userkeys/validateUserKeyDocument.js +18 -5
  120. package/dist/core/userkeys/validateUserKeyDocument.js.map +1 -1
  121. package/dist/node/appendonlystores/sqlite/FsBlobContentStore.d.ts +23 -0
  122. package/dist/node/appendonlystores/sqlite/FsBlobContentStore.d.ts.map +1 -0
  123. package/dist/node/appendonlystores/sqlite/FsBlobContentStore.js +119 -0
  124. package/dist/node/appendonlystores/sqlite/FsBlobContentStore.js.map +1 -0
  125. package/dist/node/appendonlystores/sqlite/NodeSqliteStore.d.ts +43 -0
  126. package/dist/node/appendonlystores/sqlite/NodeSqliteStore.d.ts.map +1 -0
  127. package/dist/node/appendonlystores/sqlite/NodeSqliteStore.js +121 -0
  128. package/dist/node/appendonlystores/sqlite/NodeSqliteStore.js.map +1 -0
  129. package/dist/node/appendonlystores/sqlite/ServerSqliteStore.d.ts +43 -0
  130. package/dist/node/appendonlystores/sqlite/ServerSqliteStore.d.ts.map +1 -0
  131. package/dist/node/appendonlystores/sqlite/ServerSqliteStore.js +279 -0
  132. package/dist/node/appendonlystores/sqlite/ServerSqliteStore.js.map +1 -0
  133. package/dist/node/server/MindooDBServer.d.ts +2 -0
  134. package/dist/node/server/MindooDBServer.d.ts.map +1 -1
  135. package/dist/node/server/MindooDBServer.js +46 -0
  136. package/dist/node/server/MindooDBServer.js.map +1 -1
  137. package/dist/node/server/StoreFactory.d.ts +5 -2
  138. package/dist/node/server/StoreFactory.d.ts.map +1 -1
  139. package/dist/node/server/StoreFactory.js +21 -4
  140. package/dist/node/server/StoreFactory.js.map +1 -1
  141. package/dist/node/server/TenantManager.d.ts +6 -0
  142. package/dist/node/server/TenantManager.d.ts.map +1 -1
  143. package/dist/node/server/TenantManager.js +17 -0
  144. package/dist/node/server/TenantManager.js.map +1 -1
  145. package/dist/node/server/server.js +2 -0
  146. package/dist/node/server/server.js.map +1 -1
  147. package/dist/server/JoinRequestService.d.ts +108 -0
  148. package/dist/server/JoinRequestService.d.ts.map +1 -0
  149. package/dist/server/JoinRequestService.js +454 -0
  150. package/dist/server/JoinRequestService.js.map +1 -0
  151. package/dist/server/TenantManager.d.ts +57 -1
  152. package/dist/server/TenantManager.d.ts.map +1 -1
  153. package/dist/server/TenantManager.js +273 -34
  154. package/dist/server/TenantManager.js.map +1 -1
  155. package/dist/server/http/MindooDBServerCore.d.ts +18 -0
  156. package/dist/server/http/MindooDBServerCore.d.ts.map +1 -1
  157. package/dist/server/http/MindooDBServerCore.js +230 -137
  158. package/dist/server/http/MindooDBServerCore.js.map +1 -1
  159. package/dist/server/serverConfig.d.ts.map +1 -1
  160. package/dist/server/serverConfig.js +17 -0
  161. package/dist/server/serverConfig.js.map +1 -1
  162. package/dist/server/types.d.ts +16 -1
  163. package/dist/server/types.d.ts.map +1 -1
  164. package/dist/server/types.js +6 -0
  165. package/dist/server/types.js.map +1 -1
  166. package/package.json +1 -1
@@ -0,0 +1,119 @@
1
+ "use strict";
2
+ /**
3
+ * Payloads of a SQLite store kept as one immutable file per content hash,
4
+ * below `<root>/<h0h1>/<h2h3>/<hash>` (see {@link ExternalContentStore}).
5
+ *
6
+ * Large payloads (attachment chunks) stay out of the SQLite file, so a file
7
+ * backup only copies new blobs, and the database file stays small. Every
8
+ * write goes tmp → fsync → rename → directory fsync, so a blob is durable
9
+ * before the SQLite row that references it commits.
10
+ */
11
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
12
+ if (k2 === undefined) k2 = k;
13
+ var desc = Object.getOwnPropertyDescriptor(m, k);
14
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
15
+ desc = { enumerable: true, get: function() { return m[k]; } };
16
+ }
17
+ Object.defineProperty(o, k2, desc);
18
+ }) : (function(o, m, k, k2) {
19
+ if (k2 === undefined) k2 = k;
20
+ o[k2] = m[k];
21
+ }));
22
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
23
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
24
+ }) : function(o, v) {
25
+ o["default"] = v;
26
+ });
27
+ var __importStar = (this && this.__importStar) || (function () {
28
+ var ownKeys = function(o) {
29
+ ownKeys = Object.getOwnPropertyNames || function (o) {
30
+ var ar = [];
31
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
32
+ return ar;
33
+ };
34
+ return ownKeys(o);
35
+ };
36
+ return function (mod) {
37
+ if (mod && mod.__esModule) return mod;
38
+ var result = {};
39
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
40
+ __setModuleDefault(result, mod);
41
+ return result;
42
+ };
43
+ })();
44
+ Object.defineProperty(exports, "__esModule", { value: true });
45
+ exports.FsBlobContentStore = exports.DEFAULT_BLOB_THRESHOLD_BYTES = void 0;
46
+ const promises_1 = require("fs/promises");
47
+ const path = __importStar(require("path"));
48
+ /** Payloads of at least this size go to files (smaller ones stay inline in SQLite). */
49
+ exports.DEFAULT_BLOB_THRESHOLD_BYTES = 64 * 1024;
50
+ function assertSafeHash(hash) {
51
+ // Content hashes are hex; anything else must not become a path.
52
+ if (!/^[A-Za-z0-9_-]{4,}$/.test(hash)) {
53
+ throw new Error(`Invalid content hash for blob storage: ${hash}`);
54
+ }
55
+ }
56
+ async function syncDirectory(dir) {
57
+ try {
58
+ const handle = await (0, promises_1.open)(dir, "r");
59
+ try {
60
+ await handle.sync();
61
+ }
62
+ finally {
63
+ await handle.close();
64
+ }
65
+ }
66
+ catch {
67
+ // Not supported on every platform (e.g. Windows); the rename stays atomic.
68
+ }
69
+ }
70
+ class FsBlobContentStore {
71
+ constructor(root, thresholdBytes = exports.DEFAULT_BLOB_THRESHOLD_BYTES) {
72
+ this.root = root;
73
+ this.thresholdBytes = thresholdBytes;
74
+ }
75
+ pathFor(hash) {
76
+ assertSafeHash(hash);
77
+ return path.join(this.root, hash.slice(0, 2), hash.slice(2, 4), hash);
78
+ }
79
+ async put(hash, bytes) {
80
+ const finalPath = this.pathFor(hash);
81
+ const dir = path.dirname(finalPath);
82
+ await (0, promises_1.mkdir)(dir, { recursive: true });
83
+ const tmpPath = `${finalPath}.tmp-${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2)}`;
84
+ const handle = await (0, promises_1.open)(tmpPath, "w");
85
+ try {
86
+ await handle.writeFile(bytes);
87
+ await handle.sync();
88
+ }
89
+ finally {
90
+ await handle.close();
91
+ }
92
+ await (0, promises_1.rename)(tmpPath, finalPath);
93
+ await syncDirectory(dir);
94
+ }
95
+ async get(hash) {
96
+ try {
97
+ const buffer = await (0, promises_1.readFile)(this.pathFor(hash));
98
+ return new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
99
+ }
100
+ catch (error) {
101
+ if (error.code === "ENOENT") {
102
+ return null;
103
+ }
104
+ throw error;
105
+ }
106
+ }
107
+ async delete(hash) {
108
+ await (0, promises_1.unlink)(this.pathFor(hash)).catch((error) => {
109
+ if (error.code !== "ENOENT") {
110
+ throw error;
111
+ }
112
+ });
113
+ }
114
+ async clear() {
115
+ await (0, promises_1.rm)(this.root, { recursive: true, force: true });
116
+ }
117
+ }
118
+ exports.FsBlobContentStore = FsBlobContentStore;
119
+ //# sourceMappingURL=FsBlobContentStore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FsBlobContentStore.js","sourceRoot":"","sources":["../../../../src/node/appendonlystores/sqlite/FsBlobContentStore.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,0CAAwE;AACxE,2CAA6B;AAI7B,uFAAuF;AAC1E,QAAA,4BAA4B,GAAG,EAAE,GAAG,IAAI,CAAC;AAEtD,SAAS,cAAc,CAAC,IAAY;IAClC,gEAAgE;IAChE,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QACtC,MAAM,IAAI,KAAK,CAAC,0CAA0C,IAAI,EAAE,CAAC,CAAC;IACpE,CAAC;AACH,CAAC;AAED,KAAK,UAAU,aAAa,CAAC,GAAW;IACtC,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,IAAA,eAAI,EAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QACpC,IAAI,CAAC;YACH,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;QACtB,CAAC;gBAAS,CAAC;YACT,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;QACvB,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,2EAA2E;IAC7E,CAAC;AACH,CAAC;AAED,MA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B,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,IAAY;QACpB,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,IAAA,mBAAQ,EAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;YAClD,OAAO,IAAI,UAAU,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC;QAC7E,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAK,KAA+B,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;gBACvD,OAAO,IAAI,CAAC;YACd,CAAC;YACD,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,IAAY;QACvB,MAAM,IAAA,iBAAM,EAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,KAA4B,EAAE,EAAE;YACtE,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;gBAC5B,MAAM,KAAK,CAAC;YACd,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,KAAK;QACT,MAAM,IAAA,aAAE,EAAC,IAAI,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IACxD,CAAC;CACF;AAlDD,gDAkDC"}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * SQLite-backed content-addressed stores for Node (the server's `"sqlite"`
3
+ * store type): {@link SqliteContentAddressedStore} on `node:sqlite`, with
4
+ * payloads of at least 64 KB kept as files by {@link FsBlobContentStore}.
5
+ *
6
+ * On-disk layout per store directory:
7
+ *
8
+ * ```
9
+ * <dir>/
10
+ * store.db (+ -wal, -shm) entries, metadata, small payloads, indexes
11
+ * blobs/ab/cd/<hash> large payloads, one immutable file each
12
+ * ```
13
+ *
14
+ * The database runs in WAL mode with `synchronous=FULL`: a push the server
15
+ * acknowledged survives a power loss. For backups, copy `store.db` with the
16
+ * SQLite backup API (`VACUUM INTO`) or replicate it continuously with
17
+ * Litestream; the blobs never change after they are written.
18
+ */
19
+ import type { DatabaseSync as DatabaseSyncType } from "node:sqlite";
20
+ import { SqliteContentAddressedStore } from "../../../core/appendonlystores/sqlite/SqliteContentAddressedStore";
21
+ import { type SqliteExecutor } from "../../../core/appendonlystores/sqlite/SqliteDriver";
22
+ import type { OpenStoreOptions, StoreKind } from "../../../core/appendonlystores/types";
23
+ import type { Logger } from "../../../core/logging";
24
+ /** File name of the SQLite database inside a store directory. */
25
+ export declare const SQLITE_STORE_FILE = "store.db";
26
+ /** Directory of the payload files inside a store directory. */
27
+ export declare const SQLITE_BLOB_DIR = "blobs";
28
+ /** {@link SqliteExecutor} over a synchronous `node:sqlite` connection. */
29
+ export declare function createNodeSqliteExecutor(db: DatabaseSyncType): SqliteExecutor;
30
+ /** Opens (or creates) the SQLite database of a store directory with the server pragmas. */
31
+ export declare function openNodeSqliteDatabase(dir: string): DatabaseSyncType;
32
+ export interface NodeSqliteStoreOptions extends OpenStoreOptions {
33
+ /** Payloads of at least this many bytes are kept as files (default 64 KB). */
34
+ blobThresholdBytes?: number;
35
+ }
36
+ export interface NodeSqliteStoreHandle {
37
+ store: SqliteContentAddressedStore;
38
+ /** Closes the database connection; the store must not be used afterwards. */
39
+ close(): void;
40
+ }
41
+ /** A {@link SqliteContentAddressedStore} kept in `dir` (see module docs for the layout). */
42
+ export declare function openNodeSqliteStore(dir: string, dbId: string, storeKind: StoreKind, logger?: Logger, options?: NodeSqliteStoreOptions): NodeSqliteStoreHandle;
43
+ //# sourceMappingURL=NodeSqliteStore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NodeSqliteStore.d.ts","sourceRoot":"","sources":["../../../../src/node/appendonlystores/sqlite/NodeSqliteStore.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAIH,OAAO,KAAK,EAAE,YAAY,IAAI,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEpE,OAAO,EAAE,2BAA2B,EAAE,MAAM,mEAAmE,CAAC;AAChH,OAAO,EAEL,KAAK,cAAc,EAEpB,MAAM,oDAAoD,CAAC;AAC5D,OAAO,KAAK,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,sCAAsC,CAAC;AACxF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAGpD,iEAAiE;AACjE,eAAO,MAAM,iBAAiB,aAAa,CAAC;AAC5C,+DAA+D;AAC/D,eAAO,MAAM,eAAe,UAAU,CAAC;AAkBvC,0EAA0E;AAC1E,wBAAgB,wBAAwB,CAAC,EAAE,EAAE,gBAAgB,GAAG,cAAc,CAgB7E;AAED,2FAA2F;AAC3F,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,MAAM,GAAG,gBAAgB,CAUpE;AAED,MAAM,WAAW,sBAAuB,SAAQ,gBAAgB;IAC9D,8EAA8E;IAC9E,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,MAAM,WAAW,qBAAqB;IACpC,KAAK,EAAE,2BAA2B,CAAC;IACnC,6EAA6E;IAC7E,KAAK,IAAI,IAAI,CAAC;CACf;AAED,4FAA4F;AAC5F,wBAAgB,mBAAmB,CACjC,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,SAAS,EACpB,MAAM,CAAC,EAAE,MAAM,EACf,OAAO,GAAE,sBAA2B,GACnC,qBAAqB,CAavB"}
@@ -0,0 +1,121 @@
1
+ "use strict";
2
+ /**
3
+ * SQLite-backed content-addressed stores for Node (the server's `"sqlite"`
4
+ * store type): {@link SqliteContentAddressedStore} on `node:sqlite`, with
5
+ * payloads of at least 64 KB kept as files by {@link FsBlobContentStore}.
6
+ *
7
+ * On-disk layout per store directory:
8
+ *
9
+ * ```
10
+ * <dir>/
11
+ * store.db (+ -wal, -shm) entries, metadata, small payloads, indexes
12
+ * blobs/ab/cd/<hash> large payloads, one immutable file each
13
+ * ```
14
+ *
15
+ * The database runs in WAL mode with `synchronous=FULL`: a push the server
16
+ * acknowledged survives a power loss. For backups, copy `store.db` with the
17
+ * SQLite backup API (`VACUUM INTO`) or replicate it continuously with
18
+ * Litestream; the blobs never change after they are written.
19
+ */
20
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
21
+ if (k2 === undefined) k2 = k;
22
+ var desc = Object.getOwnPropertyDescriptor(m, k);
23
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
24
+ desc = { enumerable: true, get: function() { return m[k]; } };
25
+ }
26
+ Object.defineProperty(o, k2, desc);
27
+ }) : (function(o, m, k, k2) {
28
+ if (k2 === undefined) k2 = k;
29
+ o[k2] = m[k];
30
+ }));
31
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
32
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
33
+ }) : function(o, v) {
34
+ o["default"] = v;
35
+ });
36
+ var __importStar = (this && this.__importStar) || (function () {
37
+ var ownKeys = function(o) {
38
+ ownKeys = Object.getOwnPropertyNames || function (o) {
39
+ var ar = [];
40
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
41
+ return ar;
42
+ };
43
+ return ownKeys(o);
44
+ };
45
+ return function (mod) {
46
+ if (mod && mod.__esModule) return mod;
47
+ var result = {};
48
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
49
+ __setModuleDefault(result, mod);
50
+ return result;
51
+ };
52
+ })();
53
+ Object.defineProperty(exports, "__esModule", { value: true });
54
+ exports.SQLITE_BLOB_DIR = exports.SQLITE_STORE_FILE = void 0;
55
+ exports.createNodeSqliteExecutor = createNodeSqliteExecutor;
56
+ exports.openNodeSqliteDatabase = openNodeSqliteDatabase;
57
+ exports.openNodeSqliteStore = openNodeSqliteStore;
58
+ const fs_1 = require("fs");
59
+ const path = __importStar(require("path"));
60
+ const SqliteContentAddressedStore_1 = require("../../../core/appendonlystores/sqlite/SqliteContentAddressedStore");
61
+ const SqliteDriver_1 = require("../../../core/appendonlystores/sqlite/SqliteDriver");
62
+ const FsBlobContentStore_1 = require("./FsBlobContentStore");
63
+ /** File name of the SQLite database inside a store directory. */
64
+ exports.SQLITE_STORE_FILE = "store.db";
65
+ /** Directory of the payload files inside a store directory. */
66
+ exports.SQLITE_BLOB_DIR = "blobs";
67
+ let nodeSqlite = null;
68
+ /** `node:sqlite`, loaded on first use so other store types do not need it. */
69
+ function loadNodeSqlite() {
70
+ if (!nodeSqlite) {
71
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
72
+ nodeSqlite = require("node:sqlite");
73
+ }
74
+ return nodeSqlite;
75
+ }
76
+ function toParams(params = []) {
77
+ return params;
78
+ }
79
+ /** {@link SqliteExecutor} over a synchronous `node:sqlite` connection. */
80
+ function createNodeSqliteExecutor(db) {
81
+ return {
82
+ async exec(sql) {
83
+ db.exec(sql);
84
+ },
85
+ async run(sql, params) {
86
+ const result = db.prepare(sql).run(...toParams(params));
87
+ return { changes: Number(result.changes) };
88
+ },
89
+ async get(sql, params) {
90
+ return db.prepare(sql).get(...toParams(params));
91
+ },
92
+ async all(sql, params) {
93
+ return db.prepare(sql).all(...toParams(params));
94
+ },
95
+ };
96
+ }
97
+ /** Opens (or creates) the SQLite database of a store directory with the server pragmas. */
98
+ function openNodeSqliteDatabase(dir) {
99
+ (0, fs_1.mkdirSync)(dir, { recursive: true });
100
+ const { DatabaseSync } = loadNodeSqlite();
101
+ const db = new DatabaseSync(path.join(dir, exports.SQLITE_STORE_FILE));
102
+ // auto_vacuum only takes effect before the first table is created.
103
+ db.exec("PRAGMA auto_vacuum = INCREMENTAL;");
104
+ db.exec("PRAGMA journal_mode = WAL;");
105
+ db.exec("PRAGMA synchronous = FULL;");
106
+ db.exec("PRAGMA busy_timeout = 5000;");
107
+ return db;
108
+ }
109
+ /** A {@link SqliteContentAddressedStore} kept in `dir` (see module docs for the layout). */
110
+ function openNodeSqliteStore(dir, dbId, storeKind, logger, options = {}) {
111
+ const db = openNodeSqliteDatabase(dir);
112
+ const backend = (0, SqliteDriver_1.createSqlBackend)(createNodeSqliteExecutor(db), {
113
+ externalContent: new FsBlobContentStore_1.FsBlobContentStore(path.join(dir, exports.SQLITE_BLOB_DIR), options.blobThresholdBytes ?? FsBlobContentStore_1.DEFAULT_BLOB_THRESHOLD_BYTES),
114
+ });
115
+ const store = new SqliteContentAddressedStore_1.SqliteContentAddressedStore(dbId, storeKind, backend, logger, options);
116
+ return {
117
+ store,
118
+ close: () => db.close(),
119
+ };
120
+ }
121
+ //# sourceMappingURL=NodeSqliteStore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NodeSqliteStore.js","sourceRoot":"","sources":["../../../../src/node/appendonlystores/sqlite/NodeSqliteStore.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCH,4DAgBC;AAGD,wDAUC;AAcD,kDAmBC;AAlGD,2BAA+B;AAC/B,2CAA6B;AAG7B,mHAAgH;AAChH,qFAI4D;AAG5D,6DAAwF;AAExF,iEAAiE;AACpD,QAAA,iBAAiB,GAAG,UAAU,CAAC;AAC5C,+DAA+D;AAClD,QAAA,eAAe,GAAG,OAAO,CAAC;AAGvC,IAAI,UAAU,GAA4B,IAAI,CAAC;AAE/C,8EAA8E;AAC9E,SAAS,cAAc;IACrB,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,iEAAiE;QACjE,UAAU,GAAG,OAAO,CAAC,aAAa,CAAqB,CAAC;IAC1D,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC;AAED,SAAS,QAAQ,CAAC,SAAwB,EAAE;IAC1C,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,0EAA0E;AAC1E,SAAgB,w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AC,6BAA6B,CAAC,CAAC;IACvC,OAAO,EAAE,CAAC;AACZ,CAAC;AAaD,4FAA4F;AAC5F,SAAgB,mBAAmB,CACjC,GAAW,EACX,IAAY,EACZ,SAAoB,EACpB,MAAe,EACf,UAAkC,EAAE;IAEpC,MAAM,EAAE,GAAG,sBAAsB,CAAC,GAAG,CAAC,CAAC;IACvC,MAAM,OAAO,GAAG,IAAA,+BAAgB,EAAC,wBAAwB,CAAC,EAAE,CAAC,EAAE;QAC7D,eAAe,EAAE,IAAI,uCAAkB,CACrC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,uBAAe,CAAC,EAC/B,OAAO,CAAC,kBAAkB,IAAI,iDAA4B,CAC3D;KACF,CAAC,CAAC;IACH,MAAM,KAAK,GAAG,IAAI,yDAA2B,CAAC,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IACzF,OAAO;QACL,KAAK;QACL,KAAK,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,KAAK,EAAE;KACxB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * The server's `"sqlite"` store type, including the one-time move of an
3
+ * existing `"file"` store ({@link BasicOnDiskContentAddressedStore}) into
4
+ * SQLite.
5
+ *
6
+ * Both store types share the directory `<basePath>/<dbId>/<storeKind>/`. A
7
+ * marker file `store-backend.json` records which backend owns it. The move
8
+ * runs on first use of the store, before any call is answered:
9
+ *
10
+ * 1. copy every entry in receipt order, saving a checkpoint after each batch
11
+ * (`sqlite-migration.json`), so a crash resumes where it stopped;
12
+ * 2. verify ids, metadata (signatures, witness receipts) and a payload sample;
13
+ * 3. only then write the marker, and move the file store's data into
14
+ * `legacy-file-store/` (kept for a manual rollback; delete it by hand).
15
+ *
16
+ * If copying or verifying fails, the SQLite files are removed and the file
17
+ * store keeps serving; the move is retried on the next start, at most
18
+ * {@link MAX_MIGRATION_ATTEMPTS} times.
19
+ */
20
+ import type { ContentAddressedStore, OpenStoreOptions, StoreKind } from "../../../core/appendonlystores/types";
21
+ import { type Logger } from "../../../core/logging";
22
+ export declare const STORE_BACKEND_FILE = "store-backend.json";
23
+ export declare const SQLITE_MIGRATION_STATE_FILE = "sqlite-migration.json";
24
+ export declare const LEGACY_FILE_STORE_DIR = "legacy-file-store";
25
+ export declare const MAX_MIGRATION_ATTEMPTS = 3;
26
+ /** Store directory of `dbId`/`storeKind` below `basePath`, shared by the file and sqlite types. */
27
+ export declare function storeDirectory(basePath: string, dbId: string, storeKind: StoreKind): string;
28
+ /** Whether `dir` already belongs to the sqlite backend (its marker is written). */
29
+ export declare function isSqliteStoreDirectory(dir: string): boolean;
30
+ export interface ServerSqliteStoreOptions extends OpenStoreOptions {
31
+ basePath: string;
32
+ blobThresholdBytes?: number;
33
+ /** Entries per copy batch while moving a file store (default 200). */
34
+ migrationBatchSize?: number;
35
+ /** Payloads compared byte by byte after the move (default 200). */
36
+ migrationPayloadSample?: number;
37
+ }
38
+ /**
39
+ * Opens the sqlite store of `dbId`/`storeKind` below `options.basePath`,
40
+ * moving an existing file store into it first (see module docs).
41
+ */
42
+ export declare function openServerSqliteStore(dbId: string, storeKind: StoreKind, options: ServerSqliteStoreOptions, logger?: Logger): ContentAddressedStore;
43
+ //# sourceMappingURL=ServerSqliteStore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ServerSqliteStore.d.ts","sourceRoot":"","sources":["../../../../src/node/appendonlystores/sqlite/ServerSqliteStore.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAWH,OAAO,KAAK,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,sCAAsC,CAAC;AAC/G,OAAO,EAAoC,KAAK,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAKtF,eAAO,MAAM,kBAAkB,uBAAuB,CAAC;AACvD,eAAO,MAAM,2BAA2B,0BAA0B,CAAC;AACnE,eAAO,MAAM,qBAAqB,sBAAsB,CAAC;AACzD,eAAO,MAAM,sBAAsB,IAAI,CAAC;AA0DxC,mGAAmG;AACnG,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,GAAG,MAAM,CAE3F;AAED,mFAAmF;AACnF,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAE3D;AAuBD,MAAM,WAAW,wBAAyB,SAAQ,gBAAgB;IAChE,QAAQ,EAAE,MAAM,CAAC;IACjB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,sEAAsE;IACtE,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,mEAAmE;IACnE,sBAAsB,CAAC,EAAE,MAAM,CAAC;CACjC;AA6ID;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,SAAS,EACpB,OAAO,EAAE,wBAAwB,EACjC,MAAM,CAAC,EAAE,MAAM,GACd,qBAAqB,CAgBvB"}
@@ -0,0 +1,279 @@
1
+ "use strict";
2
+ /**
3
+ * The server's `"sqlite"` store type, including the one-time move of an
4
+ * existing `"file"` store ({@link BasicOnDiskContentAddressedStore}) into
5
+ * SQLite.
6
+ *
7
+ * Both store types share the directory `<basePath>/<dbId>/<storeKind>/`. A
8
+ * marker file `store-backend.json` records which backend owns it. The move
9
+ * runs on first use of the store, before any call is answered:
10
+ *
11
+ * 1. copy every entry in receipt order, saving a checkpoint after each batch
12
+ * (`sqlite-migration.json`), so a crash resumes where it stopped;
13
+ * 2. verify ids, metadata (signatures, witness receipts) and a payload sample;
14
+ * 3. only then write the marker, and move the file store's data into
15
+ * `legacy-file-store/` (kept for a manual rollback; delete it by hand).
16
+ *
17
+ * If copying or verifying fails, the SQLite files are removed and the file
18
+ * store keeps serving; the move is retried on the next start, at most
19
+ * {@link MAX_MIGRATION_ATTEMPTS} times.
20
+ */
21
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
22
+ if (k2 === undefined) k2 = k;
23
+ var desc = Object.getOwnPropertyDescriptor(m, k);
24
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
25
+ desc = { enumerable: true, get: function() { return m[k]; } };
26
+ }
27
+ Object.defineProperty(o, k2, desc);
28
+ }) : (function(o, m, k, k2) {
29
+ if (k2 === undefined) k2 = k;
30
+ o[k2] = m[k];
31
+ }));
32
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
33
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
34
+ }) : function(o, v) {
35
+ o["default"] = v;
36
+ });
37
+ var __importStar = (this && this.__importStar) || (function () {
38
+ var ownKeys = function(o) {
39
+ ownKeys = Object.getOwnPropertyNames || function (o) {
40
+ var ar = [];
41
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
42
+ return ar;
43
+ };
44
+ return ownKeys(o);
45
+ };
46
+ return function (mod) {
47
+ if (mod && mod.__esModule) return mod;
48
+ var result = {};
49
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
50
+ __setModuleDefault(result, mod);
51
+ return result;
52
+ };
53
+ })();
54
+ Object.defineProperty(exports, "__esModule", { value: true });
55
+ exports.MAX_MIGRATION_ATTEMPTS = exports.LEGACY_FILE_STORE_DIR = exports.SQLITE_MIGRATION_STATE_FILE = exports.STORE_BACKEND_FILE = void 0;
56
+ exports.storeDirectory = storeDirectory;
57
+ exports.isSqliteStoreDirectory = isSqliteStoreDirectory;
58
+ exports.openServerSqliteStore = openServerSqliteStore;
59
+ const fs_1 = require("fs");
60
+ const promises_1 = require("fs/promises");
61
+ const path = __importStar(require("path"));
62
+ const StoreMigration_1 = require("../../../core/appendonlystores/migration/StoreMigration");
63
+ const logging_1 = require("../../../core/logging");
64
+ const SqliteContentAddressedStore_1 = require("../../../core/appendonlystores/sqlite/SqliteContentAddressedStore");
65
+ const BasicOnDiskContentAddressedStore_1 = require("../BasicOnDiskContentAddressedStore");
66
+ const NodeSqliteStore_1 = require("./NodeSqliteStore");
67
+ exports.STORE_BACKEND_FILE = "store-backend.json";
68
+ exports.SQLITE_MIGRATION_STATE_FILE = "sqlite-migration.json";
69
+ exports.LEGACY_FILE_STORE_DIR = "legacy-file-store";
70
+ exports.MAX_MIGRATION_ATTEMPTS = 3;
71
+ /** How often a running move logs its progress. */
72
+ const PROGRESS_LOG_INTERVAL_MS = 5000;
73
+ /** What `BasicOnDiskContentAddressedStore` keeps in a store directory. */
74
+ const FILE_STORE_PARTS = ["entries", "content", "metadata-index.json", "metadata-segments", "store-epoch.json"];
75
+ function readJson(file) {
76
+ try {
77
+ return JSON.parse((0, fs_1.readFileSync)(file, "utf-8"));
78
+ }
79
+ catch {
80
+ return null;
81
+ }
82
+ }
83
+ async function writeJsonDurably(file, value) {
84
+ const tmp = `${file}.tmp-${process.pid}-${Date.now()}`;
85
+ const handle = await (0, promises_1.open)(tmp, "w");
86
+ try {
87
+ await handle.writeFile(JSON.stringify(value));
88
+ await handle.sync();
89
+ }
90
+ finally {
91
+ await handle.close();
92
+ }
93
+ await (0, promises_1.rename)(tmp, file);
94
+ try {
95
+ const dir = await (0, promises_1.open)(path.dirname(file), "r");
96
+ await dir.sync().finally(() => dir.close());
97
+ }
98
+ catch {
99
+ // Directory fsync is not supported everywhere; the rename stays atomic.
100
+ }
101
+ }
102
+ /** Synchronous {@link writeJsonDurably}, for the marker of a new store. */
103
+ function writeJsonDurablySync(file, value) {
104
+ const tmp = `${file}.tmp-${process.pid}-${Date.now()}`;
105
+ const fd = (0, fs_1.openSync)(tmp, "w");
106
+ try {
107
+ (0, fs_1.writeSync)(fd, JSON.stringify(value));
108
+ (0, fs_1.fsyncSync)(fd);
109
+ }
110
+ finally {
111
+ (0, fs_1.closeSync)(fd);
112
+ }
113
+ (0, fs_1.renameSync)(tmp, file);
114
+ }
115
+ /** Store directory of `dbId`/`storeKind` below `basePath`, shared by the file and sqlite types. */
116
+ function storeDirectory(basePath, dbId, storeKind) {
117
+ return path.join(basePath, dbId, storeKind);
118
+ }
119
+ /** Whether `dir` already belongs to the sqlite backend (its marker is written). */
120
+ function isSqliteStoreDirectory(dir) {
121
+ return readJson(path.join(dir, exports.STORE_BACKEND_FILE))?.backend === "sqlite";
122
+ }
123
+ function hasFileStoreData(dir) {
124
+ return (0, fs_1.existsSync)(path.join(dir, "entries"));
125
+ }
126
+ function removeSqliteFiles(dir) {
127
+ for (const name of [NodeSqliteStore_1.SQLITE_STORE_FILE, `${NodeSqliteStore_1.SQLITE_STORE_FILE}-wal`, `${NodeSqliteStore_1.SQLITE_STORE_FILE}-shm`, NodeSqliteStore_1.SQLITE_BLOB_DIR]) {
128
+ (0, fs_1.rmSync)(path.join(dir, name), { recursive: true, force: true });
129
+ }
130
+ }
131
+ function moveFileStoreToLegacy(dir) {
132
+ const legacy = path.join(dir, exports.LEGACY_FILE_STORE_DIR);
133
+ (0, fs_1.mkdirSync)(legacy, { recursive: true });
134
+ for (const part of FILE_STORE_PARTS) {
135
+ const from = path.join(dir, part);
136
+ if ((0, fs_1.existsSync)(from)) {
137
+ (0, fs_1.renameSync)(from, path.join(legacy, part));
138
+ }
139
+ }
140
+ }
141
+ /**
142
+ * Moves the file store in `dir` into SQLite. Resolves with the store that
143
+ * should serve: the SQLite store after a verified move, else the file store.
144
+ */
145
+ async function migrateFileStore(dir, dbId, storeKind, logger, options) {
146
+ const statePath = path.join(dir, exports.SQLITE_MIGRATION_STATE_FILE);
147
+ const state = readJson(statePath) ?? { attempts: 0, checkpoint: null };
148
+ const source = new BasicOnDiskContentAddressedStore_1.BasicOnDiskContentAddressedStore(dbId, storeKind, logger, { basePath: options.basePath });
149
+ if (state.attempts >= exports.MAX_MIGRATION_ATTEMPTS) {
150
+ logger.error(`Moving ${dbId}/${storeKind} to sqlite failed ${state.attempts} times; serving the file store. ` +
151
+ `Delete ${statePath} to try again.`);
152
+ return source;
153
+ }
154
+ state.attempts += 1;
155
+ await writeJsonDurably(statePath, state);
156
+ let target = null;
157
+ const startedAt = Date.now();
158
+ try {
159
+ if (!state.checkpoint) {
160
+ // A fresh attempt: drop whatever an earlier failed attempt left behind.
161
+ removeSqliteFiles(dir);
162
+ }
163
+ target = (0, NodeSqliteStore_1.openNodeSqliteStore)(dir, dbId, storeKind, logger, { blobThresholdBytes: options.blobThresholdBytes });
164
+ const total = (await source.getAllIds()).length;
165
+ logger.info(state.checkpoint
166
+ ? `Resuming move of ${dbId}/${storeKind} to sqlite at ${state.checkpoint.copied}/${total} entries ` +
167
+ `(attempt ${state.attempts}/${exports.MAX_MIGRATION_ATTEMPTS})`
168
+ : `Moving ${dbId}/${storeKind} from file to sqlite: ${total} entries ` +
169
+ `(attempt ${state.attempts}/${exports.MAX_MIGRATION_ATTEMPTS})`);
170
+ let lastProgressAt = Date.now();
171
+ const done = await (0, StoreMigration_1.copyStoreResumable)(source, target.store, {
172
+ batchSize: options.migrationBatchSize,
173
+ checkpoint: state.checkpoint,
174
+ onCheckpoint: async (checkpoint) => {
175
+ await writeJsonDurably(statePath, { ...state, checkpoint });
176
+ if (Date.now() - lastProgressAt >= PROGRESS_LOG_INTERVAL_MS) {
177
+ lastProgressAt = Date.now();
178
+ const percent = total > 0 ? Math.round((checkpoint.copied / total) * 100) : 100;
179
+ logger.info(`Moving ${dbId}/${storeKind} to sqlite: ${checkpoint.copied}/${total} entries (${percent} %)`);
180
+ }
181
+ },
182
+ });
183
+ logger.info(`Moving ${dbId}/${storeKind} to sqlite: copied ${done.copied} entries, verifying`);
184
+ const verification = await (0, StoreMigration_1.verifyStoreCopy)(source, target.store, {
185
+ payloadSample: options.migrationPayloadSample ?? 200,
186
+ });
187
+ if (!verification.ok) {
188
+ throw new Error(`verification failed: ${verification.problem}`);
189
+ }
190
+ const marker = {
191
+ backend: "sqlite",
192
+ migratedFrom: "file",
193
+ entries: verification.targetEntries,
194
+ migratedAt: Date.now(),
195
+ };
196
+ // The switch: from here on the directory belongs to sqlite.
197
+ await writeJsonDurably(path.join(dir, exports.STORE_BACKEND_FILE), marker);
198
+ (0, fs_1.rmSync)(statePath, { force: true });
199
+ moveFileStoreToLegacy(dir);
200
+ logger.info(`Moved ${dbId}/${storeKind} to sqlite: ${verification.targetEntries} entries ` +
201
+ `(${done.copied} copied in this run, ${verification.payloadsCompared} payloads verified) ` +
202
+ `in ${Date.now() - startedAt} ms; old files in ${exports.LEGACY_FILE_STORE_DIR}/`);
203
+ return target.store;
204
+ }
205
+ catch (error) {
206
+ logger.error(`Moving ${dbId}/${storeKind} to sqlite failed (attempt ${state.attempts}/${exports.MAX_MIGRATION_ATTEMPTS}); ` +
207
+ `serving the file store: ${String(error)}`);
208
+ target?.close();
209
+ removeSqliteFiles(dir);
210
+ await writeJsonDurably(statePath, { attempts: state.attempts, checkpoint: null });
211
+ return source;
212
+ }
213
+ }
214
+ /**
215
+ * A store that answers every call from `resolve()`'s result, waiting for it
216
+ * first. Lets a synchronous factory hand out a store whose backend is only
217
+ * known after an asynchronous migration. Optional methods are offered as the
218
+ * SQLite store offers them.
219
+ */
220
+ function deferredStore(dbId, storeKind, resolve) {
221
+ let active = null;
222
+ let pending = null;
223
+ const ready = () => {
224
+ if (!pending) {
225
+ pending = resolve().then((store) => (active = store));
226
+ }
227
+ return pending;
228
+ };
229
+ const shape = Object.create(SqliteContentAddressedStore_1.SqliteContentAddressedStore.prototype);
230
+ const syncAnswers = {
231
+ getId: () => dbId,
232
+ getStoreKind: () => storeKind,
233
+ getCacheIdentity: () => `sqlite:${dbId}:${storeKind}`,
234
+ getIndexBuildStatus: () => ({ phase: "building", indexingEnabled: true, progress01: 0 }),
235
+ };
236
+ return new Proxy(shape, {
237
+ get(_shape, property) {
238
+ if (active) {
239
+ const value = Reflect.get(active, property);
240
+ return typeof value === "function" ? value.bind(active) : value;
241
+ }
242
+ if (typeof property === "string" && syncAnswers[property]) {
243
+ return syncAnswers[property];
244
+ }
245
+ const value = Reflect.get(shape, property);
246
+ if (typeof value !== "function" || typeof property !== "string") {
247
+ return value;
248
+ }
249
+ return async (...args) => {
250
+ const store = await ready();
251
+ const method = Reflect.get(store, property);
252
+ if (typeof method !== "function") {
253
+ throw new Error(`${property} is not supported by the active store of ${dbId}/${storeKind}`);
254
+ }
255
+ return method.apply(store, args);
256
+ };
257
+ },
258
+ });
259
+ }
260
+ /**
261
+ * Opens the sqlite store of `dbId`/`storeKind` below `options.basePath`,
262
+ * moving an existing file store into it first (see module docs).
263
+ */
264
+ function openServerSqliteStore(dbId, storeKind, options, logger) {
265
+ const log = logger ?? new logging_1.MindooLogger((0, logging_1.getDefaultLogLevel)(), `ServerSqliteStore:${dbId}:${storeKind}`, true);
266
+ const dir = storeDirectory(options.basePath, dbId, storeKind);
267
+ const openOptions = { ...options, blobThresholdBytes: options.blobThresholdBytes };
268
+ if (isSqliteStoreDirectory(dir) || !hasFileStoreData(dir)) {
269
+ const handle = (0, NodeSqliteStore_1.openNodeSqliteStore)(dir, dbId, storeKind, log, openOptions);
270
+ if (!isSqliteStoreDirectory(dir)) {
271
+ // A new store: claim the directory right away (nothing to move).
272
+ writeJsonDurablySync(path.join(dir, exports.STORE_BACKEND_FILE), { backend: "sqlite" });
273
+ }
274
+ return handle.store;
275
+ }
276
+ // A file store lives here: move it on first use.
277
+ return deferredStore(dbId, storeKind, () => migrateFileStore(dir, dbId, storeKind, log, options));
278
+ }
279
+ //# sourceMappingURL=ServerSqliteStore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ServerSqliteStore.js","sourceRoot":"","sources":["../../../../src/node/appendonlystores/sqlite/ServerSqliteStore.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;GAkBG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+EH,wCAEC;AAGD,wDAEC;AA+KD,sDAqBC;AAxRD,2BAAwH;AACxH,0CAA2C;AAC3C,2CAA6B;AAE7B,4FAIiE;AAEjE,mDA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AM,CAAC,KAAK,CAAC;IACtB,CAAC;IAED,iDAAiD;IACjD,OAAO,aAAa,CAAC,IAAI,EAAE,SAAS,EAAE,GAAG,EAAE,CAAC,gBAAgB,CAAC,GAAG,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC;AACpG,CAAC"}
@@ -44,6 +44,8 @@ declare global {
44
44
  }
45
45
  }
46
46
  }
47
+ /** Idle time before a tenant is unloaded, from `MINDOODB_TENANT_IDLE_MINUTES` (0 = never). */
48
+ export declare function tenantIdleMs(value: string | undefined): number;
47
49
  export declare class MindooDBServer {
48
50
  private app;
49
51
  /** In-process change feed backing the SSE endpoint (sync-v5, phase 5). */