From 3132b8c59aa97ceb92ab2c0bf5abaa4911584607 Mon Sep 17 00:00:00 2001 From: Jon Staab Date: Tue, 28 Oct 2025 13:23:25 -0700 Subject: [PATCH] Make sorting/limit more resilient in repository --- package.json | 2 +- packages/app/package.json | 2 +- packages/content/package.json | 2 +- packages/editor/package.json | 2 +- packages/feeds/package.json | 2 +- packages/lib/package.json | 2 +- packages/lib/src/Tools.ts | 6 +++--- packages/net/__tests__/repository.test.ts | 4 ---- packages/net/package.json | 2 +- packages/net/src/diff.ts | 2 +- packages/net/src/repository.ts | 6 +----- packages/router/package.json | 2 +- packages/signer/package.json | 2 +- packages/store/package.json | 2 +- packages/util/package.json | 2 +- 15 files changed, 16 insertions(+), 24 deletions(-) diff --git a/package.json b/package.json index 30d8e24..bfb26ff 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@welshman", "private": true, - "version": "0.6.2", + "version": "0.6.3", "workspaces": [ "packages/*" ], diff --git a/packages/app/package.json b/packages/app/package.json index 9c8544c..aa9515f 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -1,6 +1,6 @@ { "name": "@welshman/app", - "version": "0.6.2", + "version": "0.6.3", "author": "hodlbod", "license": "MIT", "description": "A collection of svelte stores for use in building nostr client applications.", diff --git a/packages/content/package.json b/packages/content/package.json index 8c2460d..3eb0122 100644 --- a/packages/content/package.json +++ b/packages/content/package.json @@ -1,6 +1,6 @@ { "name": "@welshman/content", - "version": "0.6.2", + "version": "0.6.3", "author": "hodlbod", "license": "MIT", "description": "A collection of utilities for parsing nostr note content.", diff --git a/packages/editor/package.json b/packages/editor/package.json index cc5c6e6..011d700 100644 --- a/packages/editor/package.json +++ b/packages/editor/package.json @@ -1,6 +1,6 @@ { "name": "@welshman/editor", - "version": "0.6.2", + "version": "0.6.3", "author": "hodlbod", "license": "MIT", "description": "A batteries-included nostr editor.", diff --git a/packages/feeds/package.json b/packages/feeds/package.json index 6747aec..901b27e 100644 --- a/packages/feeds/package.json +++ b/packages/feeds/package.json @@ -1,6 +1,6 @@ { "name": "@welshman/feeds", - "version": "0.6.2", + "version": "0.6.3", "author": "hodlbod", "license": "MIT", "description": "Utilities for building dynamic nostr feeds.", diff --git a/packages/lib/package.json b/packages/lib/package.json index c432ba1..abd1499 100644 --- a/packages/lib/package.json +++ b/packages/lib/package.json @@ -1,6 +1,6 @@ { "name": "@welshman/lib", - "version": "0.6.2", + "version": "0.6.3", "author": "hodlbod", "license": "MIT", "description": "A collection of utilities.", diff --git a/packages/lib/src/Tools.ts b/packages/lib/src/Tools.ts index 7709c65..8e6e3d1 100644 --- a/packages/lib/src/Tools.ts +++ b/packages/lib/src/Tools.ts @@ -1517,9 +1517,9 @@ export const prop = /** Returns a function that adds/updates a property on object */ export const assoc = - (k: K, v: T) => - (o: U) => - ({...o, [k as K]: v}) as U & Record + (k: K, v: T) => + (o: U): U => + ({...o, [k]: v}) as U /** Returns a function that removes a property on object */ export const dissoc = diff --git a/packages/net/__tests__/repository.test.ts b/packages/net/__tests__/repository.test.ts index 041f852..62e28f4 100644 --- a/packages/net/__tests__/repository.test.ts +++ b/packages/net/__tests__/repository.test.ts @@ -154,10 +154,6 @@ describe("Repository", () => { repo = new Repository() }) - it("should throw on invalid queries", () => { - expect(() => repo.query([{limit: 10}], {shouldSort: false})).toThrow() - }) - it("should query by ids", () => { const event = createEvent(1) repo.publish(event) diff --git a/packages/net/package.json b/packages/net/package.json index 9ef481c..d4295c6 100644 --- a/packages/net/package.json +++ b/packages/net/package.json @@ -1,6 +1,6 @@ { "name": "@welshman/net", - "version": "0.6.2", + "version": "0.6.3", "author": "hodlbod", "license": "MIT", "description": "Utilities for connecting with nostr relays.", diff --git a/packages/net/src/diff.ts b/packages/net/src/diff.ts index fd13422..6970b4f 100644 --- a/packages/net/src/diff.ts +++ b/packages/net/src/diff.ts @@ -207,7 +207,7 @@ export const pull = async ({context, ...options}: PullOptions) => { await Promise.all( Array.from(idsByRelay.entries()).map(([relay, allIds]) => { return Promise.all( - chunk(500, allIds).map( + chunk(100, allIds).map( ids => new Promise(resolve => requestOne({ diff --git a/packages/net/src/repository.ts b/packages/net/src/repository.ts index 5e85b21..b419d6b 100644 --- a/packages/net/src/repository.ts +++ b/packages/net/src/repository.ts @@ -154,15 +154,11 @@ export class Repository extends Emitter { ) => { const result: TrustedEvent[][] = [] for (const originalFilter of filters) { - if (originalFilter.limit !== undefined && !shouldSort) { - throw new Error("Unable to skip sorting if limit is defined") - } - // Attempt to fulfill the query using one of our indexes. Fall back to all events. const applied = this._applyAnyFilter(originalFilter) const filter = applied?.filter || originalFilter const events = applied ? this._getEvents(applied!.ids) : this.dump() - const sorted = this._sortEvents(shouldSort && Boolean(filter.limit), events) + const sorted = this._sortEvents(shouldSort || Boolean(filter.limit), events) const chunk: TrustedEvent[] = [] for (const event of sorted) { diff --git a/packages/router/package.json b/packages/router/package.json index 1d0afc2..78e59e1 100644 --- a/packages/router/package.json +++ b/packages/router/package.json @@ -1,6 +1,6 @@ { "name": "@welshman/router", - "version": "0.6.2", + "version": "0.6.3", "author": "hodlbod", "license": "MIT", "description": "A collection of utilities for nostr relay selection.", diff --git a/packages/signer/package.json b/packages/signer/package.json index 8e50d5b..c9aba03 100644 --- a/packages/signer/package.json +++ b/packages/signer/package.json @@ -1,6 +1,6 @@ { "name": "@welshman/signer", - "version": "0.6.2", + "version": "0.6.3", "author": "hodlbod", "license": "MIT", "description": "A nostr signer implemenation supporting several login methods.", diff --git a/packages/store/package.json b/packages/store/package.json index 6eebb99..0b9f5d2 100644 --- a/packages/store/package.json +++ b/packages/store/package.json @@ -1,6 +1,6 @@ { "name": "@welshman/store", - "version": "0.6.2", + "version": "0.6.3", "author": "hodlbod", "license": "MIT", "description": "A collection of utilities based on svelte/store for use with welshman", diff --git a/packages/util/package.json b/packages/util/package.json index afc9702..30f6a6b 100644 --- a/packages/util/package.json +++ b/packages/util/package.json @@ -1,6 +1,6 @@ { "name": "@welshman/util", - "version": "0.6.2", + "version": "0.6.3", "author": "hodlbod", "license": "MIT", "description": "A collection of nostr-related utilities.",