@bitcobblers/wod-wiki-storage 0.43.2150 → 0.43.2152
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/dist/idb/index.cjs +42 -1
- package/dist/idb/index.cjs.map +1 -1
- package/dist/idb/index.d.cts +41 -2
- package/dist/idb/index.d.ts +41 -2
- package/dist/idb/index.mjs +37 -2
- package/dist/idb/index.mjs.map +1 -1
- package/package.json +6 -6
package/dist/idb/index.cjs
CHANGED
|
@@ -128,6 +128,31 @@ var STORE_DEFS = [
|
|
|
128
128
|
{ name: "memberships", keyPath: ["id"], indexes: [], system: true }
|
|
129
129
|
];
|
|
130
130
|
|
|
131
|
+
// src/idb/catalog.ts
|
|
132
|
+
var DEFAULT_LOCAL_DATABASE_NAME = "wodwiki-db";
|
|
133
|
+
function isValidLocalDatabaseName(name) {
|
|
134
|
+
return typeof name === "string" && /^[A-Za-z0-9][A-Za-z0-9._-]{0,99}$/.test(name);
|
|
135
|
+
}
|
|
136
|
+
async function listLocalDatabases() {
|
|
137
|
+
const idb = globalThis.indexedDB;
|
|
138
|
+
if (!idb || typeof idb.databases !== "function") return [];
|
|
139
|
+
const entries = await idb.databases().catch(() => []);
|
|
140
|
+
return entries.flatMap(
|
|
141
|
+
(entry) => typeof entry.name === "string" ? [{ name: entry.name, version: typeof entry.version === "number" ? entry.version : null }] : []
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
async function deleteLocalDatabase(name) {
|
|
145
|
+
if (!isValidLocalDatabaseName(name)) throw new Error(`Invalid local database name "${String(name)}".`);
|
|
146
|
+
const idb = globalThis.indexedDB;
|
|
147
|
+
if (!idb) return;
|
|
148
|
+
await new Promise((resolve, reject) => {
|
|
149
|
+
const request = idb.deleteDatabase(name);
|
|
150
|
+
request.onsuccess = () => resolve();
|
|
151
|
+
request.onerror = () => reject(request.error ?? new Error(`Failed to delete local database "${name}".`));
|
|
152
|
+
request.onblocked = () => resolve();
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
|
|
131
156
|
// src/membership.ts
|
|
132
157
|
var USER_OWNED_STORES = [
|
|
133
158
|
"notes",
|
|
@@ -386,7 +411,18 @@ async function readLegacyRows(db, table) {
|
|
|
386
411
|
const rows = await db.query(`SELECT "data" FROM "${table}"`);
|
|
387
412
|
return rows.map((row) => decodeRowJson(String(row.data), BINARY_FIELD[table]));
|
|
388
413
|
}
|
|
389
|
-
var IDB_DB_NAME =
|
|
414
|
+
var IDB_DB_NAME = DEFAULT_LOCAL_DATABASE_NAME;
|
|
415
|
+
async function createLocalDatabase(name) {
|
|
416
|
+
if (!isValidLocalDatabaseName(name)) throw new Error(`Invalid local database name "${String(name)}".`);
|
|
417
|
+
if (name === DEFAULT_LOCAL_DATABASE_NAME) throw new Error("The default database cannot be created here.");
|
|
418
|
+
const storage = new IndexedDBStorage({ dbName: name });
|
|
419
|
+
try {
|
|
420
|
+
await storage.open();
|
|
421
|
+
} finally {
|
|
422
|
+
await storage.close().catch(() => void 0);
|
|
423
|
+
}
|
|
424
|
+
return { name, version: DB_VERSION };
|
|
425
|
+
}
|
|
390
426
|
var OUTBOX_STORE = "sync_outbox";
|
|
391
427
|
var SYNC_STATE_STORE = "sync_state";
|
|
392
428
|
var LOCAL_SYNC_STORES = [
|
|
@@ -1454,9 +1490,14 @@ async function migrateSegmentsToBlocks(db, tx) {
|
|
|
1454
1490
|
db.deleteObjectStore("segments");
|
|
1455
1491
|
}
|
|
1456
1492
|
|
|
1493
|
+
exports.DEFAULT_LOCAL_DATABASE_NAME = DEFAULT_LOCAL_DATABASE_NAME;
|
|
1457
1494
|
exports.IDB_DB_NAME = IDB_DB_NAME;
|
|
1458
1495
|
exports.IndexedDBStorage = IndexedDBStorage;
|
|
1459
1496
|
exports.convertSyncSource = convertSyncSource;
|
|
1497
|
+
exports.createLocalDatabase = createLocalDatabase;
|
|
1498
|
+
exports.deleteLocalDatabase = deleteLocalDatabase;
|
|
1499
|
+
exports.isValidLocalDatabaseName = isValidLocalDatabaseName;
|
|
1500
|
+
exports.listLocalDatabases = listLocalDatabases;
|
|
1460
1501
|
exports.subscribeOutboxWrites = subscribeOutboxWrites;
|
|
1461
1502
|
//# sourceMappingURL=index.cjs.map
|
|
1462
1503
|
//# sourceMappingURL=index.cjs.map
|