@breeztech/breez-sdk-spark 0.13.9-debug → 0.13.11-dev1
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/breez-sdk-spark.tgz +0 -0
- package/bundler/breez_sdk_spark_wasm.d.ts +1113 -1050
- package/bundler/breez_sdk_spark_wasm.js +5 -1
- package/bundler/breez_sdk_spark_wasm_bg.js +1493 -1628
- package/bundler/breez_sdk_spark_wasm_bg.wasm +0 -0
- package/bundler/breez_sdk_spark_wasm_bg.wasm.d.ts +14 -6
- package/deno/breez_sdk_spark_wasm.d.ts +1113 -1050
- package/deno/breez_sdk_spark_wasm.js +1394 -1284
- package/deno/breez_sdk_spark_wasm_bg.wasm +0 -0
- package/deno/breez_sdk_spark_wasm_bg.wasm.d.ts +14 -6
- package/nodejs/breez_sdk_spark_wasm.d.ts +1113 -1050
- package/nodejs/breez_sdk_spark_wasm.js +2527 -2654
- package/nodejs/breez_sdk_spark_wasm_bg.wasm +0 -0
- package/nodejs/breez_sdk_spark_wasm_bg.wasm.d.ts +14 -6
- package/nodejs/index.js +34 -0
- package/nodejs/index.mjs +5 -4
- package/nodejs/mysql-storage/errors.cjs +19 -0
- package/nodejs/mysql-storage/index.cjs +1366 -0
- package/nodejs/mysql-storage/migrations.cjs +387 -0
- package/nodejs/mysql-storage/package.json +9 -0
- package/nodejs/mysql-token-store/errors.cjs +9 -0
- package/nodejs/mysql-token-store/index.cjs +988 -0
- package/nodejs/mysql-token-store/migrations.cjs +255 -0
- package/nodejs/mysql-token-store/package.json +9 -0
- package/nodejs/mysql-tree-store/errors.cjs +9 -0
- package/nodejs/mysql-tree-store/index.cjs +939 -0
- package/nodejs/mysql-tree-store/migrations.cjs +221 -0
- package/nodejs/mysql-tree-store/package.json +9 -0
- package/nodejs/package.json +3 -0
- package/nodejs/postgres-storage/index.cjs +147 -92
- package/nodejs/postgres-storage/migrations.cjs +85 -4
- package/nodejs/postgres-token-store/index.cjs +186 -101
- package/nodejs/postgres-token-store/migrations.cjs +92 -3
- package/nodejs/postgres-tree-store/index.cjs +177 -93
- package/nodejs/postgres-tree-store/migrations.cjs +80 -3
- package/package.json +1 -1
- package/ssr/index.js +19 -14
- package/web/breez_sdk_spark_wasm.d.ts +1267 -1195
- package/web/breez_sdk_spark_wasm.js +2295 -2169
- package/web/breez_sdk_spark_wasm_bg.wasm +0 -0
- package/web/breez_sdk_spark_wasm_bg.wasm.d.ts +14 -6
|
@@ -22,8 +22,16 @@ class TreeStoreMigrationManager {
|
|
|
22
22
|
/**
|
|
23
23
|
* Run all pending migrations inside a single transaction with an advisory lock.
|
|
24
24
|
* @param {import('pg').Pool} pool
|
|
25
|
+
* @param {Buffer|Uint8Array} identity - 33-byte secp256k1 compressed pubkey
|
|
26
|
+
* identifying the tenant. Used to backfill `user_id` columns in the
|
|
27
|
+
* multi-tenant scoping migration. Required.
|
|
25
28
|
*/
|
|
26
|
-
async migrate(pool) {
|
|
29
|
+
async migrate(pool, identity) {
|
|
30
|
+
if (!identity || identity.length !== 33) {
|
|
31
|
+
throw new TreeStoreError(
|
|
32
|
+
"tenant identity (33-byte secp256k1 pubkey) is required"
|
|
33
|
+
);
|
|
34
|
+
}
|
|
27
35
|
const client = await pool.connect();
|
|
28
36
|
try {
|
|
29
37
|
await client.query("BEGIN");
|
|
@@ -45,7 +53,7 @@ class TreeStoreMigrationManager {
|
|
|
45
53
|
);
|
|
46
54
|
const currentVersion = versionResult.rows[0].version;
|
|
47
55
|
|
|
48
|
-
const migrations = this._getMigrations();
|
|
56
|
+
const migrations = this._getMigrations(identity);
|
|
49
57
|
|
|
50
58
|
if (currentVersion >= migrations.length) {
|
|
51
59
|
this._log("info", `Tree store database is up to date (version ${currentVersion})`);
|
|
@@ -96,8 +104,16 @@ class TreeStoreMigrationManager {
|
|
|
96
104
|
|
|
97
105
|
/**
|
|
98
106
|
* Migrations matching the Rust PostgresTreeStore schema exactly.
|
|
107
|
+
*
|
|
108
|
+
* @param {Buffer|Uint8Array} identity - tenant identity inlined as a hex
|
|
109
|
+
* BYTEA literal in the multi-tenant scoping migration. Safe because the
|
|
110
|
+
* bytes come from a typed secp256k1 pubkey (`[0-9a-f]{66}` after hex
|
|
111
|
+
* encoding) — not user-controlled input.
|
|
99
112
|
*/
|
|
100
|
-
_getMigrations() {
|
|
113
|
+
_getMigrations(identity) {
|
|
114
|
+
const idHex = Buffer.from(identity).toString("hex");
|
|
115
|
+
const idLit = `'\\x${idHex}'::bytea`;
|
|
116
|
+
|
|
101
117
|
return [
|
|
102
118
|
{
|
|
103
119
|
name: "Create tree store tables",
|
|
@@ -143,6 +159,67 @@ class TreeStoreMigrationManager {
|
|
|
143
159
|
`INSERT INTO tree_swap_status (id) VALUES (1) ON CONFLICT DO NOTHING`,
|
|
144
160
|
],
|
|
145
161
|
},
|
|
162
|
+
{
|
|
163
|
+
// Mirrors Rust migration 3 in spark-postgres/src/tree_store.rs.
|
|
164
|
+
// Adds user_id to every tree-store table, backfills with the connecting
|
|
165
|
+
// tenant's identity, and rewrites primary keys / FKs / indexes to lead
|
|
166
|
+
// with user_id. The composite FK uses NO ACTION (the default) instead
|
|
167
|
+
// of the previous single-column ON DELETE SET NULL — PG-only column-list
|
|
168
|
+
// SET NULL is PG15+, and a whole-row SET NULL would null user_id (NOT
|
|
169
|
+
// NULL). cleanupStaleReservations now releases leaves explicitly.
|
|
170
|
+
name: "Multi-tenant scoping: add user_id and rewrite primary keys",
|
|
171
|
+
sql: [
|
|
172
|
+
// Drop the old single-column FK FIRST, before touching the
|
|
173
|
+
// tree_reservations PK it depends on.
|
|
174
|
+
`ALTER TABLE tree_leaves
|
|
175
|
+
DROP CONSTRAINT IF EXISTS tree_leaves_reservation_id_fkey`,
|
|
176
|
+
|
|
177
|
+
// tree_reservations: scope by user_id.
|
|
178
|
+
`ALTER TABLE tree_reservations ADD COLUMN user_id BYTEA`,
|
|
179
|
+
`UPDATE tree_reservations SET user_id = ${idLit}`,
|
|
180
|
+
`ALTER TABLE tree_reservations
|
|
181
|
+
ALTER COLUMN user_id SET NOT NULL,
|
|
182
|
+
DROP CONSTRAINT IF EXISTS tree_reservations_pkey,
|
|
183
|
+
ADD PRIMARY KEY (user_id, id)`,
|
|
184
|
+
|
|
185
|
+
// tree_leaves: add user_id, rekey, and re-add the composite FK.
|
|
186
|
+
`ALTER TABLE tree_leaves ADD COLUMN user_id BYTEA`,
|
|
187
|
+
`UPDATE tree_leaves SET user_id = ${idLit}`,
|
|
188
|
+
`ALTER TABLE tree_leaves
|
|
189
|
+
ALTER COLUMN user_id SET NOT NULL,
|
|
190
|
+
DROP CONSTRAINT IF EXISTS tree_leaves_pkey,
|
|
191
|
+
ADD PRIMARY KEY (user_id, id),
|
|
192
|
+
ADD FOREIGN KEY (user_id, reservation_id)
|
|
193
|
+
REFERENCES tree_reservations(user_id, id)`,
|
|
194
|
+
`DROP INDEX IF EXISTS idx_tree_leaves_available`,
|
|
195
|
+
`DROP INDEX IF EXISTS idx_tree_leaves_reservation`,
|
|
196
|
+
`DROP INDEX IF EXISTS idx_tree_leaves_added_at`,
|
|
197
|
+
`CREATE INDEX idx_tree_leaves_user_available
|
|
198
|
+
ON tree_leaves(user_id, status, is_missing_from_operators)
|
|
199
|
+
WHERE status = 'Available' AND is_missing_from_operators = FALSE`,
|
|
200
|
+
`CREATE INDEX idx_tree_leaves_user_reservation
|
|
201
|
+
ON tree_leaves(user_id, reservation_id)
|
|
202
|
+
WHERE reservation_id IS NOT NULL`,
|
|
203
|
+
`CREATE INDEX idx_tree_leaves_user_added_at ON tree_leaves(user_id, added_at)`,
|
|
204
|
+
|
|
205
|
+
// tree_spent_leaves: scope by user_id.
|
|
206
|
+
`ALTER TABLE tree_spent_leaves ADD COLUMN user_id BYTEA`,
|
|
207
|
+
`UPDATE tree_spent_leaves SET user_id = ${idLit}`,
|
|
208
|
+
`ALTER TABLE tree_spent_leaves
|
|
209
|
+
ALTER COLUMN user_id SET NOT NULL,
|
|
210
|
+
DROP CONSTRAINT IF EXISTS tree_spent_leaves_pkey,
|
|
211
|
+
ADD PRIMARY KEY (user_id, leaf_id)`,
|
|
212
|
+
|
|
213
|
+
// tree_swap_status was a singleton (PK id=1, CHECK id=1). Drop the id
|
|
214
|
+
// column (CASCADE removes both PK and CHECK), then re-key by user_id.
|
|
215
|
+
`ALTER TABLE tree_swap_status DROP COLUMN id CASCADE`,
|
|
216
|
+
`ALTER TABLE tree_swap_status ADD COLUMN user_id BYTEA`,
|
|
217
|
+
`UPDATE tree_swap_status SET user_id = ${idLit}`,
|
|
218
|
+
`ALTER TABLE tree_swap_status
|
|
219
|
+
ALTER COLUMN user_id SET NOT NULL,
|
|
220
|
+
ADD PRIMARY KEY (user_id)`,
|
|
221
|
+
],
|
|
222
|
+
},
|
|
146
223
|
];
|
|
147
224
|
}
|
|
148
225
|
}
|
package/package.json
CHANGED
package/ssr/index.js
CHANGED
|
@@ -23,9 +23,14 @@ export default async function init(wasmInput) {
|
|
|
23
23
|
return _initPromise;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
export function
|
|
27
|
-
if (!_module) _notInitialized('
|
|
28
|
-
return _module.
|
|
26
|
+
export function connect(...args) {
|
|
27
|
+
if (!_module) _notInitialized('connect');
|
|
28
|
+
return _module.connect(...args);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function connectWithSigner(...args) {
|
|
32
|
+
if (!_module) _notInitialized('connectWithSigner');
|
|
33
|
+
return _module.connectWithSigner(...args);
|
|
29
34
|
}
|
|
30
35
|
|
|
31
36
|
export function defaultConfig(...args) {
|
|
@@ -33,19 +38,19 @@ export function defaultConfig(...args) {
|
|
|
33
38
|
return _module.defaultConfig(...args);
|
|
34
39
|
}
|
|
35
40
|
|
|
36
|
-
export function connect(...args) {
|
|
37
|
-
if (!_module) _notInitialized('connect');
|
|
38
|
-
return _module.connect(...args);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
41
|
export function defaultExternalSigner(...args) {
|
|
42
42
|
if (!_module) _notInitialized('defaultExternalSigner');
|
|
43
43
|
return _module.defaultExternalSigner(...args);
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
export function
|
|
47
|
-
if (!_module) _notInitialized('
|
|
48
|
-
return _module.
|
|
46
|
+
export function defaultMysqlStorageConfig(...args) {
|
|
47
|
+
if (!_module) _notInitialized('defaultMysqlStorageConfig');
|
|
48
|
+
return _module.defaultMysqlStorageConfig(...args);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function defaultPostgresStorageConfig(...args) {
|
|
52
|
+
if (!_module) _notInitialized('defaultPostgresStorageConfig');
|
|
53
|
+
return _module.defaultPostgresStorageConfig(...args);
|
|
49
54
|
}
|
|
50
55
|
|
|
51
56
|
export function getSparkStatus(...args) {
|
|
@@ -53,9 +58,9 @@ export function getSparkStatus(...args) {
|
|
|
53
58
|
return _module.getSparkStatus(...args);
|
|
54
59
|
}
|
|
55
60
|
|
|
56
|
-
export function
|
|
57
|
-
if (!_module) _notInitialized('
|
|
58
|
-
return _module.
|
|
61
|
+
export function initLogging(...args) {
|
|
62
|
+
if (!_module) _notInitialized('initLogging');
|
|
63
|
+
return _module.initLogging(...args);
|
|
59
64
|
}
|
|
60
65
|
|
|
61
66
|
export function task_worker_entry_point(...args) {
|