@openlfcp/storage-node 0.2.0-beta.1 → 0.2.0-beta.10
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/sqlite.js +43 -1
- package/package.json +3 -3
package/dist/sqlite.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { actorSequence, bytesEqual, dataEpoch, LfcpError, toHex, UINT64_MAX, } from "@openlfcp/core";
|
|
2
|
-
import { LocalStateKeyring, nextActorSequence, reseal, } from "@openlfcp/storage";
|
|
2
|
+
import { LocalStateKeyring, nextActorSequence, reseal, resourceSent, } from "@openlfcp/storage";
|
|
3
3
|
import Database from "better-sqlite3";
|
|
4
4
|
import { migrate } from "./schema.js";
|
|
5
5
|
/** uint64 as 20-digit zero-padded TEXT (sorts numerically, never overflows). */
|
|
@@ -321,6 +321,30 @@ export class SqliteLfcpStorage {
|
|
|
321
321
|
current: current,
|
|
322
322
|
});
|
|
323
323
|
}
|
|
324
|
+
for (const w of writes) {
|
|
325
|
+
if (w.op !== "delete-resource")
|
|
326
|
+
continue;
|
|
327
|
+
const r = blob(w.resourceId);
|
|
328
|
+
const resource = this.#get("SELECT local_principal FROM resources WHERE resource_id = ?", r);
|
|
329
|
+
const sync = this.#get("SELECT * FROM sync_state WHERE resource_id = ?", r);
|
|
330
|
+
const detail = resourceSent({
|
|
331
|
+
local: resource === undefined || resource.local_principal === null
|
|
332
|
+
? null
|
|
333
|
+
: as(resource.local_principal),
|
|
334
|
+
outbound: this.#all("SELECT * FROM outbound WHERE resource_id = ?", r).map(outboundItem),
|
|
335
|
+
syncState: sync === undefined ? undefined : syncStateRow(sync),
|
|
336
|
+
actors: this.#all(`SELECT DISTINCT actor AS p FROM data_units WHERE resource_id = ?
|
|
337
|
+
UNION SELECT DISTINCT sender FROM key_packages WHERE resource_id = ?
|
|
338
|
+
UNION SELECT DISTINCT publisher FROM snapshots WHERE resource_id = ?`, r, r, r).map((x) => as(x.p)),
|
|
339
|
+
});
|
|
340
|
+
if (detail !== null)
|
|
341
|
+
return Object.freeze({
|
|
342
|
+
ok: false,
|
|
343
|
+
reason: "RESOURCE_SENT",
|
|
344
|
+
resourceId: Uint8Array.from(w.resourceId),
|
|
345
|
+
detail,
|
|
346
|
+
});
|
|
347
|
+
}
|
|
324
348
|
for (const w of writes) {
|
|
325
349
|
if (w.op !== "expect-previous-unit")
|
|
326
350
|
continue;
|
|
@@ -505,6 +529,24 @@ export class SqliteLfcpStorage {
|
|
|
505
529
|
else
|
|
506
530
|
db.prepare("INSERT INTO local_marks (key, value) VALUES (?, ?) ON CONFLICT (key) DO UPDATE SET value = excluded.value").run(w.key, w.value);
|
|
507
531
|
return;
|
|
532
|
+
case "delete-resource":
|
|
533
|
+
// The sequence counters stay: a number is never reused.
|
|
534
|
+
for (const table of [
|
|
535
|
+
"control_records",
|
|
536
|
+
"control_heads",
|
|
537
|
+
"control_conflicts",
|
|
538
|
+
"epochs",
|
|
539
|
+
"data_units",
|
|
540
|
+
"key_packages",
|
|
541
|
+
"snapshots",
|
|
542
|
+
"resources",
|
|
543
|
+
"routes",
|
|
544
|
+
"outbound",
|
|
545
|
+
"profile_checkpoints",
|
|
546
|
+
"sync_state",
|
|
547
|
+
])
|
|
548
|
+
db.prepare(`DELETE FROM ${table} WHERE resource_id = ?`).run(blob(w.resourceId));
|
|
549
|
+
return;
|
|
508
550
|
case "put-profile-checkpoint": {
|
|
509
551
|
const c = w.checkpoint;
|
|
510
552
|
db.prepare(`INSERT INTO profile_checkpoints (resource_id, data_profile, state, actor_seq, units) VALUES (?, ?, ?, ?, ?)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openlfcp/storage-node",
|
|
3
|
-
"version": "0.2.0-beta.
|
|
3
|
+
"version": "0.2.0-beta.10",
|
|
4
4
|
"description": "Durable Node.js storage for LFCP clients: SQLite (better-sqlite3) and a file secret store. Node only.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"openlfcp",
|
|
@@ -43,8 +43,8 @@
|
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"better-sqlite3": "13.0.3",
|
|
46
|
-
"@openlfcp/core": "^0.2.0-beta.
|
|
47
|
-
"@openlfcp/storage": "^0.2.0-beta.
|
|
46
|
+
"@openlfcp/core": "^0.2.0-beta.10",
|
|
47
|
+
"@openlfcp/storage": "^0.2.0-beta.10"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@types/better-sqlite3": "9.6.0",
|