mindoodb 0.0.98 → 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.
- package/README-server.md +15 -0
- package/dist/appendonlystores/network/HttpTransport.d.ts.map +1 -1
- package/dist/appendonlystores/network/HttpTransport.js +1 -0
- package/dist/appendonlystores/network/HttpTransport.js.map +1 -1
- package/dist/appendonlystores/network/ServerNetworkContentAddressedStore.d.ts +6 -0
- package/dist/appendonlystores/network/ServerNetworkContentAddressedStore.d.ts.map +1 -1
- package/dist/appendonlystores/network/ServerNetworkContentAddressedStore.js +22 -1
- package/dist/appendonlystores/network/ServerNetworkContentAddressedStore.js.map +1 -1
- package/dist/browser/index.mjs +6 -0
- package/dist/core/BaseMindooTenant.d.ts +13 -2
- package/dist/core/BaseMindooTenant.d.ts.map +1 -1
- package/dist/core/BaseMindooTenant.js +35 -1
- package/dist/core/BaseMindooTenant.js.map +1 -1
- package/dist/core/MindooDBServerAdmin.d.ts +1 -1
- package/dist/core/MindooDBServerAdmin.d.ts.map +1 -1
- package/dist/core/appendonlystores/migration/StoreMigration.d.ts +41 -1
- package/dist/core/appendonlystores/migration/StoreMigration.d.ts.map +1 -1
- package/dist/core/appendonlystores/migration/StoreMigration.js +126 -0
- package/dist/core/appendonlystores/migration/StoreMigration.js.map +1 -1
- package/dist/core/appendonlystores/sqlite/SqliteContentAddressedStore.d.ts.map +1 -1
- package/dist/core/appendonlystores/sqlite/SqliteContentAddressedStore.js +29 -0
- package/dist/core/appendonlystores/sqlite/SqliteContentAddressedStore.js.map +1 -1
- package/dist/core/appendonlystores/syncStores.d.ts +6 -0
- package/dist/core/appendonlystores/syncStores.d.ts.map +1 -1
- package/dist/core/appendonlystores/syncStores.js +21 -0
- package/dist/core/appendonlystores/syncStores.js.map +1 -1
- package/dist/core/appendonlystores/types.d.ts +8 -0
- package/dist/core/appendonlystores/types.d.ts.map +1 -1
- package/dist/core/appendonlystores/types.js.map +1 -1
- package/dist/core/recovery/PaperRescueDevice.d.ts +17 -8
- package/dist/core/recovery/PaperRescueDevice.d.ts.map +1 -1
- package/dist/core/recovery/PaperRescueDevice.js +38 -15
- package/dist/core/recovery/PaperRescueDevice.js.map +1 -1
- package/dist/core/recovery/RecoveryContactsDocument.d.ts +2 -7
- package/dist/core/recovery/RecoveryContactsDocument.d.ts.map +1 -1
- package/dist/core/recovery/RecoveryContactsDocument.js +3 -4
- package/dist/core/recovery/RecoveryContactsDocument.js.map +1 -1
- package/dist/core/recovery/RecoveryContactsManager.d.ts +82 -1
- package/dist/core/recovery/RecoveryContactsManager.d.ts.map +1 -1
- package/dist/core/recovery/RecoveryContactsManager.js +143 -10
- package/dist/core/recovery/RecoveryContactsManager.js.map +1 -1
- package/dist/core/recovery/index.d.ts +4 -3
- package/dist/core/recovery/index.d.ts.map +1 -1
- package/dist/core/recovery/index.js +8 -1
- package/dist/core/recovery/index.js.map +1 -1
- package/dist/core/recovery/recoverWithContacts.d.ts +22 -2
- package/dist/core/recovery/recoverWithContacts.d.ts.map +1 -1
- package/dist/core/recovery/recoverWithContacts.js +69 -30
- package/dist/core/recovery/recoverWithContacts.js.map +1 -1
- package/dist/core/recovery/recoveryPackage.d.ts +8 -0
- package/dist/core/recovery/recoveryPackage.d.ts.map +1 -1
- package/dist/core/recovery/recoveryPackage.js +1 -0
- package/dist/core/recovery/recoveryPackage.js.map +1 -1
- package/dist/core/recovery/rescueApproval.d.ts +39 -0
- package/dist/core/recovery/rescueApproval.d.ts.map +1 -0
- package/dist/core/recovery/rescueApproval.js +52 -0
- package/dist/core/recovery/rescueApproval.js.map +1 -0
- package/dist/core/types.d.ts +11 -2
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core/types.js.map +1 -1
- package/dist/core/userkeys/UserKeyManager.d.ts +16 -0
- package/dist/core/userkeys/UserKeyManager.d.ts.map +1 -1
- package/dist/core/userkeys/UserKeyManager.js +45 -0
- package/dist/core/userkeys/UserKeyManager.js.map +1 -1
- package/dist/node/appendonlystores/sqlite/FsBlobContentStore.d.ts +23 -0
- package/dist/node/appendonlystores/sqlite/FsBlobContentStore.d.ts.map +1 -0
- package/dist/node/appendonlystores/sqlite/FsBlobContentStore.js +119 -0
- package/dist/node/appendonlystores/sqlite/FsBlobContentStore.js.map +1 -0
- package/dist/node/appendonlystores/sqlite/NodeSqliteStore.d.ts +43 -0
- package/dist/node/appendonlystores/sqlite/NodeSqliteStore.d.ts.map +1 -0
- package/dist/node/appendonlystores/sqlite/NodeSqliteStore.js +121 -0
- package/dist/node/appendonlystores/sqlite/NodeSqliteStore.js.map +1 -0
- package/dist/node/appendonlystores/sqlite/ServerSqliteStore.d.ts +43 -0
- package/dist/node/appendonlystores/sqlite/ServerSqliteStore.d.ts.map +1 -0
- package/dist/node/appendonlystores/sqlite/ServerSqliteStore.js +279 -0
- package/dist/node/appendonlystores/sqlite/ServerSqliteStore.js.map +1 -0
- package/dist/node/server/StoreFactory.d.ts +5 -2
- package/dist/node/server/StoreFactory.d.ts.map +1 -1
- package/dist/node/server/StoreFactory.js +17 -3
- package/dist/node/server/StoreFactory.js.map +1 -1
- package/dist/node/server/TenantManager.d.ts +6 -0
- package/dist/node/server/TenantManager.d.ts.map +1 -1
- package/dist/node/server/TenantManager.js +17 -0
- package/dist/node/server/TenantManager.js.map +1 -1
- package/dist/server/TenantManager.d.ts +7 -1
- package/dist/server/TenantManager.d.ts.map +1 -1
- package/dist/server/TenantManager.js +2 -1
- package/dist/server/TenantManager.js.map +1 -1
- package/dist/server/http/MindooDBServerCore.d.ts.map +1 -1
- package/dist/server/http/MindooDBServerCore.js +1 -0
- package/dist/server/http/MindooDBServerCore.js.map +1 -1
- package/dist/server/types.d.ts +1 -1
- package/dist/server/types.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -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,wBAAwB,CAAC,EAAoB;IAC3D,OAAO;QACL,KAAK,CAAC,IAAI,CAAC,GAAG;YACZ,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACf,CAAC;QACD,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM;YACnB,MAAM,MAAM,GAAG,EAAE,CAAC,OAAO,CAAC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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,mDAAsF;AACtF,mHAAgH;AAChH,0FAAuF;AACvF,uDAAwH;AAE3G,QAAA,kBAAkB,GAAG,oBAAoB,CAAC;AAC1C,QAAA,2BAA2B,GAAG,uBAAuB,CAAC;AACtD,QAAA,qBAAqB,GAAG,mBAAmB,CAAC;AAC5C,QAAA,sBAAsB,GAAG,CAAC,CAAC;AACxC,kDAAkD;AAClD,MAAM,wBAAwB,GAAG,IAAK,CAAC;AAEvC,0EAA0E;AAC1E,MAAM,gBAAgB,GAAG,CA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ances based on configuration.
|
|
8
8
|
*
|
|
9
|
-
* Supports "inmemory" stores (volatile, for testing)
|
|
10
|
-
*
|
|
9
|
+
* Supports "inmemory" stores (volatile, for testing), "file" stores (one file
|
|
10
|
+
* per entry, BasicOnDiskContentAddressedStore) and "sqlite" stores (SQLite
|
|
11
|
+
* plus one file per large payload; an existing file store is moved into it
|
|
12
|
+
* on first use, see ServerSqliteStore).
|
|
11
13
|
*/
|
|
12
14
|
export declare class StoreFactory {
|
|
13
15
|
private config;
|
|
@@ -31,6 +33,7 @@ export declare class StoreFactory {
|
|
|
31
33
|
* Create a new store instance of the specified type.
|
|
32
34
|
*/
|
|
33
35
|
private createStore;
|
|
36
|
+
private storesBasePath;
|
|
34
37
|
/**
|
|
35
38
|
* Get all cached stores.
|
|
36
39
|
* Useful for cleanup or iteration.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StoreFactory.d.ts","sourceRoot":"","sources":["../../../src/node/server/StoreFactory.ts"],"names":[],"mappings":"AAAA;;GAEG;
|
|
1
|
+
{"version":3,"file":"StoreFactory.d.ts","sourceRoot":"","sources":["../../../src/node/server/StoreFactory.ts"],"names":[],"mappings":"AAAA;;GAEG;AASH,OAAO,EAAE,SAAS,EAAE,KAAK,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AACzE,OAAO,KAAK,EAAa,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAGlE;;;;;;;GAOG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,MAAM,CAAe;IAC7B,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,OAAO,CAAS;IAExB,qEAAqE;IACrE,OAAO,CAAC,MAAM,CAAiD;gBAEnD,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,OAAO,CAAC,EAAE,MAAM;IAMpE;;;;;OAKG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,GAAG,qBAAqB;IAwBnE;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAWzB;;OAEG;IACH,OAAO,CAAC,WAAW;IA0BnB,OAAO,CAAC,cAAc;IAItB;;;OAGG;IACH,YAAY,IAAI,GAAG,CAAC,MAAM,EAAE,qBAAqB,CAAC;IAIlD;;;OAGG;IACH,UAAU,IAAI,IAAI;CAInB"}
|
|
@@ -6,12 +6,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.StoreFactory = void 0;
|
|
7
7
|
const InMemoryContentAddressedStore_1 = require("../../core/appendonlystores/InMemoryContentAddressedStore");
|
|
8
8
|
const BasicOnDiskContentAddressedStore_1 = require("../appendonlystores/BasicOnDiskContentAddressedStore");
|
|
9
|
+
const ServerSqliteStore_1 = require("../appendonlystores/sqlite/ServerSqliteStore");
|
|
9
10
|
const LogLevel_1 = require("../../core/logging/LogLevel");
|
|
10
11
|
/**
|
|
11
12
|
* Factory for creating ContentAddressedStore instances based on configuration.
|
|
12
13
|
*
|
|
13
|
-
* Supports "inmemory" stores (volatile, for testing)
|
|
14
|
-
*
|
|
14
|
+
* Supports "inmemory" stores (volatile, for testing), "file" stores (one file
|
|
15
|
+
* per entry, BasicOnDiskContentAddressedStore) and "sqlite" stores (SQLite
|
|
16
|
+
* plus one file per large payload; an existing file store is moved into it
|
|
17
|
+
* on first use, see ServerSqliteStore).
|
|
15
18
|
*/
|
|
16
19
|
class StoreFactory {
|
|
17
20
|
constructor(tenantId, config, dataDir) {
|
|
@@ -65,13 +68,24 @@ class StoreFactory {
|
|
|
65
68
|
case "inmemory":
|
|
66
69
|
return new InMemoryContentAddressedStore_1.InMemoryContentAddressedStore(dbId, storeKind);
|
|
67
70
|
case "file": {
|
|
68
|
-
const basePath =
|
|
71
|
+
const basePath = this.storesBasePath();
|
|
72
|
+
if ((0, ServerSqliteStore_1.isSqliteStoreDirectory)((0, ServerSqliteStore_1.storeDirectory)(basePath, dbId, storeKind))) {
|
|
73
|
+
// Already moved to sqlite: its file data is gone (legacy-file-store/).
|
|
74
|
+
console.warn(`[StoreFactory] ${this.tenantId}/${dbId}/${storeKind} was moved to sqlite; ` +
|
|
75
|
+
`serving it as sqlite although its store type is "file"`);
|
|
76
|
+
return (0, ServerSqliteStore_1.openServerSqliteStore)(dbId, storeKind, { basePath });
|
|
77
|
+
}
|
|
69
78
|
return new BasicOnDiskContentAddressedStore_1.BasicOnDiskContentAddressedStore(dbId, storeKind, undefined, { basePath });
|
|
70
79
|
}
|
|
80
|
+
case "sqlite":
|
|
81
|
+
return (0, ServerSqliteStore_1.openServerSqliteStore)(dbId, storeKind, { basePath: this.storesBasePath() });
|
|
71
82
|
default:
|
|
72
83
|
throw new Error(`Unknown store type: ${storeType}`);
|
|
73
84
|
}
|
|
74
85
|
}
|
|
86
|
+
storesBasePath() {
|
|
87
|
+
return `${this.dataDir}/${this.tenantId}/stores`;
|
|
88
|
+
}
|
|
75
89
|
/**
|
|
76
90
|
* Get all cached stores.
|
|
77
91
|
* Useful for cleanup or iteration.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StoreFactory.js","sourceRoot":"","sources":["../../../src/node/server/StoreFactory.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,6GAA0G;AAC1G,2GAAwG;
|
|
1
|
+
{"version":3,"file":"StoreFactory.js","sourceRoot":"","sources":["../../../src/node/server/StoreFactory.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,6GAA0G;AAC1G,2GAAwG;AACxG,oFAIsD;AAGtD,0DAA2E;AAE3E;;;;;;;GAOG;AACH,MAAa,YAAY;IAQvB,YAAY,QAAgB,EAAE,MAAoB,EAAE,OAAgB;QAHpE,qEAAqE;QAC7D,WAAM,GAAuC,IAAI,GAAG,EAAE,CAAC;QAG7D,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,OAAO,IAAI,GAAG,CAAC;IAChC,CAAC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
@@ -6,6 +6,7 @@
|
|
|
6
6
|
import { NodeCryptoAdapter } from "../crypto/NodeCryptoAdapter";
|
|
7
7
|
import { TenantManager as CoreTenantManager } from "../../server/TenantManager";
|
|
8
8
|
import type { ServerStoreProvider } from "../../server/ServerDataStore";
|
|
9
|
+
import type { StoreType } from "../../server/types";
|
|
9
10
|
import { FsServerDataStore } from "./FsServerDataStore";
|
|
10
11
|
import { StoreFactory } from "./StoreFactory";
|
|
11
12
|
export { SimpleMindooDirectory, type LoadedTenant, type RegisterTenantResult, } from "../../server/TenantManager";
|
|
@@ -17,6 +18,11 @@ export declare class NodeServerStoreProvider implements ServerStoreProvider {
|
|
|
17
18
|
createTenantStores(tenantId: string, config: ConstructorParameters<typeof StoreFactory>[1]): StoreFactory;
|
|
18
19
|
listDatabases(tenantId: string): string[];
|
|
19
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Store type for newly registered tenants from `MINDOODB_DEFAULT_STORE_TYPE`
|
|
23
|
+
* (`file` when unset). Existing tenants keep the type in their config.json.
|
|
24
|
+
*/
|
|
25
|
+
export declare function defaultStoreTypeFromEnv(env?: NodeJS.ProcessEnv): StoreType;
|
|
20
26
|
export declare class TenantManager extends CoreTenantManager {
|
|
21
27
|
private readonly dataDir;
|
|
22
28
|
constructor(dataDir: string, serverPassword?: string);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TenantManager.d.ts","sourceRoot":"","sources":["../../../src/node/server/TenantManager.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,aAAa,IAAI,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAChF,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACxE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,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Q,CAAC,SAAS;gBADT,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,iBAAiB;IAG/C,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,qBAAqB,CAAC,OAAO,YAAY,CAAC,CAAC,CAAC,CAAC,GAAG,YAAY;IAIzG,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE;CAiB1C;AAID;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,GAAG,GAAE,MAAM,CAAC,UAAwB,GAAG,SAAS,CAWvF;AAUD,qBAAa,aAAc,SAAQ,iBAAiB;IAClD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;gBAErB,OAAO,EAAE,MAAM,EAAE,cAAc,CAAC,EAAE,MAAM;IAYpD,UAAU,IAAI,MAAM;IAIX,gBAAgB,IAAI,iBAAiB;CAG/C"}
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
8
|
exports.TenantManager = exports.NodeServerStoreProvider = exports.SimpleMindooDirectory = void 0;
|
|
9
|
+
exports.defaultStoreTypeFromEnv = defaultStoreTypeFromEnv;
|
|
9
10
|
const fs_1 = require("fs");
|
|
10
11
|
const path_1 = require("path");
|
|
11
12
|
const NodeCryptoAdapter_1 = require("../crypto/NodeCryptoAdapter");
|
|
@@ -38,6 +39,21 @@ class NodeServerStoreProvider {
|
|
|
38
39
|
}
|
|
39
40
|
}
|
|
40
41
|
exports.NodeServerStoreProvider = NodeServerStoreProvider;
|
|
42
|
+
const STORE_TYPES = ["file", "sqlite", "inmemory"];
|
|
43
|
+
/**
|
|
44
|
+
* Store type for newly registered tenants from `MINDOODB_DEFAULT_STORE_TYPE`
|
|
45
|
+
* (`file` when unset). Existing tenants keep the type in their config.json.
|
|
46
|
+
*/
|
|
47
|
+
function defaultStoreTypeFromEnv(env = process.env) {
|
|
48
|
+
const raw = env.MINDOODB_DEFAULT_STORE_TYPE?.trim().toLowerCase();
|
|
49
|
+
if (!raw) {
|
|
50
|
+
return "file";
|
|
51
|
+
}
|
|
52
|
+
if (!STORE_TYPES.includes(raw)) {
|
|
53
|
+
throw new Error(`MINDOODB_DEFAULT_STORE_TYPE must be one of ${STORE_TYPES.join(", ")}, got "${env.MINDOODB_DEFAULT_STORE_TYPE}"`);
|
|
54
|
+
}
|
|
55
|
+
return raw;
|
|
56
|
+
}
|
|
41
57
|
function ensureDataDir(dataDir) {
|
|
42
58
|
if (!(0, fs_1.existsSync)(dataDir)) {
|
|
43
59
|
(0, fs_1.mkdirSync)(dataDir, { recursive: true });
|
|
@@ -53,6 +69,7 @@ class TenantManager extends TenantManager_1.TenantManager {
|
|
|
53
69
|
storeProvider: new NodeServerStoreProvider(dataDir, dataStore),
|
|
54
70
|
cryptoAdapter: new NodeCryptoAdapter_1.NodeCryptoAdapter(),
|
|
55
71
|
serverPassword,
|
|
72
|
+
defaultStoreTypeForNewTenants: defaultStoreTypeFromEnv(),
|
|
56
73
|
});
|
|
57
74
|
this.dataDir = dataDir;
|
|
58
75
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TenantManager.js","sourceRoot":"","sources":["../../../src/node/server/TenantManager.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;
|
|
1
|
+
{"version":3,"file":"TenantManager.js","sourceRoot":"","sources":["../../../src/node/server/TenantManager.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAsDH,0DAWC;AA/DD,2BAAkE;AAClE,+BAA4B;AAE5B,mEAAgE;AAChE,8DAAgF;AAGhF,2DAAwD;AACxD,iDAA8C;AAE9C,4DAIoC;AAHlC,sHAAA,qBAAqB,OAAA;AAKvB,8EAA8E;AAC9E,MAAa,uBAAuB;IAClC,YACmB,OAAe,EACf,SAA4B;QAD5B,YAAO,GAAP,OAAO,CAAQ;QACf,cAAS,GAAT,SAAS,CAAmB;IAC5C,CAAC;IAEJ,kBAAkB,CAAC,QAAgB,EAAE,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