@totemsdk/omnia-host 0.10.0 → 0.11.0

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.
@@ -1,10 +1,11 @@
1
1
  import { type OmniaChannel, type ChannelSigner } from '@totemsdk/omnia';
2
- /** SQLite-backed Map facade accepted by @totemsdk/omnia's ChannelStore type. */
2
+ /**
3
+ * Synchronous Map facade accepted by @totemsdk/omnia's ChannelStore type,
4
+ * persisted through `@totemsdk/storage` (`SyncSqliteStore`, same codec/envelope
5
+ * as `SqliteStore`). Legacy `omnia_channels` tables are migrated on open.
6
+ */
3
7
  export declare class SqliteChannelStore extends Map<string, OmniaChannel> {
4
- private readonly db;
5
- private readonly readStatement;
6
- private readonly writeStatement;
7
- private readonly deleteStatement;
8
+ private readonly kv;
8
9
  /**
9
10
  * CAN-002: a recovered channel loses `localSigner` (it is not serializable),
10
11
  * so the router's `counterpartPkd()` cannot tell which party is local and
@@ -15,6 +16,8 @@ export declare class SqliteChannelStore extends Map<string, OmniaChannel> {
15
16
  /** Attach the host's signer so recovered channels carry it (CAN-002). */
16
17
  setLocalSigner(signer?: ChannelSigner): void;
17
18
  private rebind;
19
+ private channelKeys;
20
+ private idOf;
18
21
  get(channelId: string): OmniaChannel | undefined;
19
22
  set(channelId: string, channel: OmniaChannel): this;
20
23
  has(channelId: string): boolean;
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.SqliteChannelStore = void 0;
7
- const better_sqlite3_1 = __importDefault(require("better-sqlite3"));
4
+ const sqlite_sync_1 = require("@totemsdk/storage/sqlite-sync");
8
5
  const omnia_1 = require("@totemsdk/omnia");
6
+ const PREFIX = 'omnia:channel:';
7
+ const FORMAT_KEY = 'omnia:store:channel:format';
8
+ const STORE_FORMAT = 1;
9
9
  function iterator(values) {
10
10
  let index = 0;
11
11
  return {
@@ -22,12 +22,13 @@ function iterator(values) {
22
22
  },
23
23
  };
24
24
  }
25
- /** SQLite-backed Map facade accepted by @totemsdk/omnia's ChannelStore type. */
25
+ /**
26
+ * Synchronous Map facade accepted by @totemsdk/omnia's ChannelStore type,
27
+ * persisted through `@totemsdk/storage` (`SyncSqliteStore`, same codec/envelope
28
+ * as `SqliteStore`). Legacy `omnia_channels` tables are migrated on open.
29
+ */
26
30
  class SqliteChannelStore extends Map {
27
- db;
28
- readStatement;
29
- writeStatement;
30
- deleteStatement;
31
+ kv;
31
32
  /**
32
33
  * CAN-002: a recovered channel loses `localSigner` (it is not serializable),
33
34
  * so the router's `counterpartPkd()` cannot tell which party is local and
@@ -36,24 +37,20 @@ class SqliteChannelStore extends Map {
36
37
  localSigner;
37
38
  constructor(dbPath) {
38
39
  super();
39
- this.db = new better_sqlite3_1.default(dbPath);
40
- this.db.pragma('journal_mode = WAL');
41
- this.db.exec(`
42
- CREATE TABLE IF NOT EXISTS omnia_channels (
43
- channel_id TEXT PRIMARY KEY,
44
- channel_json TEXT NOT NULL,
45
- updated_at INTEGER NOT NULL
46
- )
47
- `);
48
- this.readStatement = this.db.prepare('SELECT channel_json FROM omnia_channels WHERE channel_id = ?');
49
- this.writeStatement = this.db.prepare(`
50
- INSERT INTO omnia_channels (channel_id, channel_json, updated_at)
51
- VALUES (?, ?, ?)
52
- ON CONFLICT(channel_id) DO UPDATE SET
53
- channel_json = excluded.channel_json,
54
- updated_at = excluded.updated_at
55
- `);
56
- this.deleteStatement = this.db.prepare('DELETE FROM omnia_channels WHERE channel_id = ?');
40
+ this.kv = new sqlite_sync_1.SyncSqliteStore(dbPath);
41
+ const version = this.kv.get(FORMAT_KEY);
42
+ if (version !== null && version !== STORE_FORMAT) {
43
+ this.kv.close();
44
+ throw new Error(`Unsupported SqliteChannelStore format ${version} (this build supports ${STORE_FORMAT}) — refusing to open`);
45
+ }
46
+ if (version === null) {
47
+ // One-time migration from the pre-storage direct-SQLite table.
48
+ this.kv.migrateLegacyTable('omnia_channels', (row) => ({
49
+ key: PREFIX + String(row['channel_id']),
50
+ value: String(row['channel_json']),
51
+ }));
52
+ this.kv.set(FORMAT_KEY, STORE_FORMAT);
53
+ }
57
54
  }
58
55
  /** Attach the host's signer so recovered channels carry it (CAN-002). */
59
56
  setLocalSigner(signer) {
@@ -62,36 +59,42 @@ class SqliteChannelStore extends Map {
62
59
  rebind(channel) {
63
60
  return this.localSigner ? { ...channel, localSigner: this.localSigner } : channel;
64
61
  }
62
+ channelKeys() {
63
+ return this.kv.keys().filter((key) => key.startsWith(PREFIX));
64
+ }
65
+ idOf(key) {
66
+ return key.slice(PREFIX.length);
67
+ }
65
68
  get(channelId) {
66
- const row = this.readStatement.get(channelId);
67
- return row ? this.rebind((0, omnia_1.recoverChannel)(row.channel_json)) : undefined;
69
+ const snapshot = this.kv.get(PREFIX + channelId);
70
+ return snapshot ? this.rebind((0, omnia_1.recoverChannel)(snapshot)) : undefined;
68
71
  }
69
72
  set(channelId, channel) {
70
- this.writeStatement.run(channelId, (0, omnia_1.serializeChannelSnapshot)(channel), Date.now());
73
+ this.kv.set(PREFIX + channelId, (0, omnia_1.serializeChannelSnapshot)(channel));
71
74
  return this;
72
75
  }
73
76
  has(channelId) {
74
- return this.readStatement.get(channelId) !== undefined;
77
+ return this.kv.has(PREFIX + channelId);
75
78
  }
76
79
  delete(channelId) {
77
- return this.deleteStatement.run(channelId).changes > 0;
80
+ return this.kv.remove(PREFIX + channelId);
78
81
  }
79
82
  clear() {
80
- this.db.exec('DELETE FROM omnia_channels');
83
+ for (const key of this.channelKeys())
84
+ this.kv.remove(key);
81
85
  }
82
86
  get size() {
83
- const row = this.db.prepare('SELECT COUNT(*) AS count FROM omnia_channels').get();
84
- return row.count;
87
+ return this.channelKeys().length;
85
88
  }
86
89
  entries() {
87
- const rows = this.db.prepare('SELECT channel_id, channel_json FROM omnia_channels ORDER BY channel_id').iterate();
88
- return iterator(Array.from(rows, (row) => [
89
- row.channel_id,
90
- this.rebind((0, omnia_1.recoverChannel)(row.channel_json)),
91
- ]));
90
+ const rows = this.channelKeys().map((key) => {
91
+ const snapshot = this.kv.get(key);
92
+ return [this.idOf(key), this.rebind((0, omnia_1.recoverChannel)(snapshot))];
93
+ });
94
+ return iterator(rows);
92
95
  }
93
96
  keys() {
94
- return iterator(Array.from(this.entries(), ([channelId]) => channelId));
97
+ return iterator(this.channelKeys().map((key) => this.idOf(key)));
95
98
  }
96
99
  values() {
97
100
  return iterator(Array.from(this.entries(), ([, channel]) => channel));
@@ -104,7 +107,7 @@ class SqliteChannelStore extends Map {
104
107
  callbackfn(value, key, this);
105
108
  }
106
109
  close() {
107
- this.db.close();
110
+ this.kv.close();
108
111
  }
109
112
  }
110
113
  exports.SqliteChannelStore = SqliteChannelStore;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@totemsdk/omnia-host",
3
- "version": "0.10.0",
3
+ "version": "0.11.0",
4
4
  "description": "Durable Omnia node daemon for channel lifecycle, routing, and control APIs",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -17,27 +17,29 @@
17
17
  "files": [
18
18
  "dist",
19
19
  "README.md",
20
- "LICENSE"
20
+ "LICENSE",
21
+ "NOTICE"
21
22
  ],
22
23
  "dependencies": {
23
- "better-sqlite3": "^12.2.0",
24
24
  "ws": "^8.21.1",
25
- "@totemsdk/chain-provider": "^0.3.0",
26
25
  "@totemsdk/core": "^1.4.0",
27
26
  "@totemsdk/identity": "^1.0.2",
27
+ "@totemsdk/chain-provider": "^0.3.0",
28
+ "@totemsdk/liquidity-bond": "^0.3.1",
28
29
  "@totemsdk/manifest": "^2.0.1",
29
- "@totemsdk/omnia": "^2.3.0",
30
+ "@totemsdk/minima-rpc": "^0.4.0",
31
+ "@totemsdk/omnia": "^2.3.1",
30
32
  "@totemsdk/omnia-factory": "^0.7.0",
31
33
  "@totemsdk/omnia-router": "^0.4.0",
34
+ "@totemsdk/omnia-pool": "^0.5.3",
32
35
  "@totemsdk/omnia-splice": "^0.3.0",
33
- "@totemsdk/storage": "^0.1.0",
36
+ "@totemsdk/p2p-hub": "^0.1.0",
34
37
  "@totemsdk/omnia-vtxo": "^0.6.1",
35
- "@totemsdk/minima-rpc": "^0.4.0",
38
+ "@totemsdk/storage": "^0.2.0",
36
39
  "@totemsdk/wots-lease": "^1.0.1"
37
40
  },
38
41
  "devDependencies": {
39
42
  "@types/jest": "^30.0.0",
40
- "@types/better-sqlite3": "^7.6.13",
41
43
  "@types/node": "^20.19.43",
42
44
  "@types/ws": "^8.5.0",
43
45
  "jest": "^30.4.2",
@@ -51,7 +53,7 @@
51
53
  "publishConfig": {
52
54
  "access": "public"
53
55
  },
54
- "license": "MIT",
56
+ "license": "Apache-2.0",
55
57
  "author": "Totem SDK",
56
58
  "homepage": "https://docs.totem.ing",
57
59
  "repository": {