@arkade-os/swap 0.1.0-rc.9 → 0.1.1

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.
Files changed (57) hide show
  1. package/README.md +261 -252
  2. package/dist/advanced.cjs +6613 -3224
  3. package/dist/advanced.d.cts +328 -283
  4. package/dist/advanced.d.ts +328 -283
  5. package/dist/advanced.js +347 -34
  6. package/dist/chunk-A3SHHRX4.js +104 -0
  7. package/dist/chunk-FMRAV77W.js +3065 -0
  8. package/dist/chunk-T4FHBWZI.js +3459 -0
  9. package/dist/{chunk-NS3K6BZG.js → chunk-YHESEL4I.js} +1792 -636
  10. package/dist/index.cjs +6901 -3901
  11. package/dist/index.d.cts +71 -243
  12. package/dist/index.d.ts +71 -243
  13. package/dist/index.js +131 -167
  14. package/dist/lockupContract-CIXkJPxV.d.ts +148 -0
  15. package/dist/lockupContract-CkhWMKCo.d.cts +148 -0
  16. package/dist/node/index.cjs +61 -10
  17. package/dist/node/index.d.cts +307 -635
  18. package/dist/node/index.d.ts +307 -635
  19. package/dist/node/index.js +65 -10
  20. package/dist/nostr.cjs +427 -49
  21. package/dist/nostr.d.cts +59 -70
  22. package/dist/nostr.d.ts +59 -70
  23. package/dist/nostr.js +268 -36
  24. package/dist/offer-BPD2ortO.d.ts +269 -0
  25. package/dist/offer-Diff5Flc.d.cts +269 -0
  26. package/dist/offerFillPlan-B-5ae_gQ.d.cts +1671 -0
  27. package/dist/offerFillPlan-CJzneX6F.d.ts +1671 -0
  28. package/dist/protocol.cjs +5717 -4275
  29. package/dist/protocol.d.cts +258 -328
  30. package/dist/protocol.d.ts +258 -328
  31. package/dist/protocol.js +200 -224
  32. package/dist/repositories/realm/index.cjs +55 -11
  33. package/dist/repositories/realm/index.d.cts +18 -30
  34. package/dist/repositories/realm/index.d.ts +18 -30
  35. package/dist/repositories/realm/index.js +49 -12
  36. package/dist/repositories/sqlite/index.cjs +61 -10
  37. package/dist/repositories/sqlite/index.d.cts +7 -6
  38. package/dist/repositories/sqlite/index.d.ts +7 -6
  39. package/dist/repositories/sqlite/index.js +57 -11
  40. package/dist/repository-BBVRh9ez.d.ts +2357 -0
  41. package/dist/repository-C4pvymhs.d.cts +2357 -0
  42. package/dist/{rfq-BO6o7NwS.d.ts → rfq-C0tHOvn6.d.cts} +323 -444
  43. package/dist/{rfq-BO6o7NwS.d.cts → rfq-C0tHOvn6.d.ts} +323 -444
  44. package/dist/watch-7BiRa4oB.d.ts +74 -0
  45. package/dist/watch-Bxq-lx_6.d.cts +74 -0
  46. package/package.json +10 -10
  47. package/dist/chunk-JFKGMPMH.js +0 -3456
  48. package/dist/chunk-LLG7RD2T.js +0 -1499
  49. package/dist/chunk-U7VWWTL6.js +0 -66
  50. package/dist/errors-CNISbN0M.d.ts +0 -2218
  51. package/dist/errors-DwNhIP0N.d.cts +0 -2218
  52. package/dist/lockupContract-C8-Mcg69.d.ts +0 -664
  53. package/dist/lockupContract-mIt4syse.d.cts +0 -664
  54. package/dist/repository-CGPLbjBe.d.ts +0 -3489
  55. package/dist/repository-DSGGq0ct.d.cts +0 -3489
  56. package/dist/watch-DWyVqyEN.d.cts +0 -96
  57. package/dist/watch-DmvHNX6T.d.ts +0 -96
@@ -33,9 +33,20 @@ import {
33
33
  runInTransaction,
34
34
  sanitizeTablePrefix
35
35
  } from "@arkade-os/sdk/repositories/sqlite";
36
+ import { assertPageRequest as assertPageRequest2, pageResult as pageResult2 } from "@arkade-os/sdk";
36
37
 
37
38
  // src/repository.ts
39
+ import {
40
+ assertPageRequest,
41
+ collectPages,
42
+ pageResult
43
+ } from "@arkade-os/sdk";
38
44
  var marketsCacheKey = (network, registry) => `arkade-intents-markets-${network}-${registry}`;
45
+ function assertRfqSwapPageFilter(filter) {
46
+ if (filter.since !== void 0 && (!Number.isSafeInteger(filter.since) || filter.since < 0)) {
47
+ throw new RangeError("RFQ history since must be non-negative Unix seconds");
48
+ }
49
+ }
39
50
 
40
51
  // src/repositories/sqlite/repository.ts
41
52
  var DEFAULT_PREFIX = "arkade_";
@@ -94,6 +105,13 @@ var SQLiteAssetSwapRepository = class {
94
105
  updated_at INTEGER NOT NULL,
95
106
  data TEXT NOT NULL
96
107
  )`);
108
+ await this.db.run(
109
+ `CREATE INDEX IF NOT EXISTS idx_${this.prefix}rfq_updated ON ${this.rfqSwaps} (updated_at, rfq_id)`
110
+ );
111
+ await this.db.run(
112
+ `CREATE INDEX IF NOT EXISTS idx_${this.prefix}rfq_swaps_history ON ${this.rfqSwaps} (state, updated_at, rfq_id)`
113
+ );
114
+ await this.db.run(`DROP INDEX IF EXISTS idx_${this.prefix}rfq_swaps_page`);
97
115
  await this.db.run(
98
116
  `CREATE INDEX IF NOT EXISTS idx_${this.prefix}rfq_swaps_state ON ${this.rfqSwaps} (state)`
99
117
  );
@@ -131,10 +149,8 @@ var SQLiteAssetSwapRepository = class {
131
149
  );
132
150
  });
133
151
  }
134
- async getAllSwaps() {
135
- await this.ensureInit();
136
- const rows = await this.db.all(`SELECT data FROM ${this.swaps}`);
137
- return rows.map((r) => JSON.parse(r.data));
152
+ async getAssetSwapsPage(page) {
153
+ return this.pageTable(this.swaps, "id", page);
138
154
  }
139
155
  async saveRfqSwap(record) {
140
156
  await this.ensureInit();
@@ -154,10 +170,38 @@ var SQLiteAssetSwapRepository = class {
154
170
  );
155
171
  return row ? JSON.parse(row.data) : void 0;
156
172
  }
157
- async getAllRfqSwaps() {
173
+ async getRfqSwapsPage(filter, page) {
174
+ assertPageRequest2(page);
175
+ assertRfqSwapPageFilter(filter);
158
176
  await this.ensureInit();
159
- const rows = await this.db.all(`SELECT data FROM ${this.rfqSwaps}`);
160
- return rows.map((r) => JSON.parse(r.data));
177
+ const conditions = [];
178
+ const params = [];
179
+ if (filter.state !== void 0) {
180
+ conditions.push("state = ?");
181
+ params.push(filter.state);
182
+ }
183
+ if (filter.since !== void 0) {
184
+ conditions.push("updated_at >= ?");
185
+ params.push(filter.since);
186
+ }
187
+ if (page.after !== void 0) {
188
+ conditions.push("(updated_at, rfq_id) > (?, ?)");
189
+ params.push(page.after.updatedAt, page.after.rfqId);
190
+ }
191
+ const where = conditions.length ? ` WHERE ${conditions.join(" AND ")}` : "";
192
+ const rows = await this.db.all(
193
+ `SELECT data, updated_at, rfq_id FROM ${this.rfqSwaps}${where}
194
+ ORDER BY updated_at, rfq_id LIMIT ?`,
195
+ [...params, page.limit + 1]
196
+ );
197
+ const result = pageResult2(rows, page.limit, (row) => ({
198
+ updatedAt: row.updated_at,
199
+ rfqId: row.rfq_id
200
+ }));
201
+ return {
202
+ items: result.items.map((row) => JSON.parse(row.data)),
203
+ ...result.nextCursor === void 0 ? {} : { nextCursor: result.nextCursor }
204
+ };
161
205
  }
162
206
  async removeRfqSwap(rfqId) {
163
207
  await this.ensureInit();
@@ -183,10 +227,21 @@ var SQLiteAssetSwapRepository = class {
183
227
  );
184
228
  return row ? JSON.parse(row.data) : void 0;
185
229
  }
186
- async getAllSwapRecords() {
230
+ async getSwapRecordsPage(page) {
231
+ return this.pageTable(this.swapRecords, "id", page);
232
+ }
233
+ async pageTable(table, key, page) {
234
+ assertPageRequest2(page);
187
235
  await this.ensureInit();
188
- const rows = await this.db.all(`SELECT data FROM ${this.swapRecords}`);
189
- return rows.map((r) => JSON.parse(r.data));
236
+ const rows = await this.db.all(
237
+ page.after === void 0 ? `SELECT ${key} AS key, data FROM ${table} ORDER BY ${key} LIMIT ?` : `SELECT ${key} AS key, data FROM ${table} WHERE ${key} > ? ORDER BY ${key} LIMIT ?`,
238
+ page.after === void 0 ? [page.limit + 1] : [page.after, page.limit + 1]
239
+ );
240
+ const result = pageResult2(rows, page.limit, (row) => row.key);
241
+ return {
242
+ items: result.items.map((row) => JSON.parse(row.data)),
243
+ ...result.nextCursor === void 0 ? {} : { nextCursor: result.nextCursor }
244
+ };
190
245
  }
191
246
  async removeSwapRecord(id) {
192
247
  await this.ensureInit();