accounts 0.17.1 → 0.17.2
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/CHANGELOG.md +6 -0
- package/dist/cli/Provider.d.ts.map +1 -1
- package/dist/cli/Provider.js +3 -1
- package/dist/cli/Provider.js.map +1 -1
- package/dist/cli/adapter.d.ts.map +1 -1
- package/dist/cli/adapter.js +2 -26
- package/dist/cli/adapter.js.map +1 -1
- package/dist/cli/storage.js +3 -2
- package/dist/cli/storage.js.map +1 -1
- package/dist/core/Provider.d.ts.map +1 -1
- package/dist/core/Provider.js +4 -2
- package/dist/core/Provider.js.map +1 -1
- package/dist/core/adapters/internal/fromRequest.d.ts.map +1 -1
- package/dist/core/adapters/internal/fromRequest.js +2 -1
- package/dist/core/adapters/internal/fromRequest.js.map +1 -1
- package/dist/core/internal/withDedupe.d.ts +3 -2
- package/dist/core/internal/withDedupe.d.ts.map +1 -1
- package/dist/core/internal/withDedupe.js +6 -5
- package/dist/core/internal/withDedupe.js.map +1 -1
- package/dist/core/zod/rpc.d.ts +0 -603
- package/dist/core/zod/rpc.d.ts.map +1 -1
- package/dist/server/internal/handlers/auth.d.ts +0 -20
- package/dist/server/internal/handlers/auth.d.ts.map +1 -1
- package/dist/server/internal/handlers/oidcProvider.d.ts +0 -7
- package/dist/server/internal/handlers/oidcProvider.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/cli/Provider.localnet.test.ts +124 -9
- package/src/cli/Provider.ts +4 -0
- package/src/cli/adapter.ts +3 -27
- package/src/cli/storage.test.ts +20 -1
- package/src/cli/storage.ts +2 -2
- package/src/core/Provider.localnet.test.ts +24 -18
- package/src/core/Provider.ts +4 -2
- package/src/core/adapters/internal/fromRequest.ts +2 -1
- package/src/core/internal/withDedupe.test.ts +17 -0
- package/src/core/internal/withDedupe.ts +7 -5
|
@@ -5,6 +5,7 @@ import { z } from 'zod/mini'
|
|
|
5
5
|
import * as Adapter from '../../Adapter.js'
|
|
6
6
|
import type * as Keystore from '../../Keystore.js'
|
|
7
7
|
import * as Rpc from '../../zod/rpc.js'
|
|
8
|
+
import * as u from '../../zod/utils.js'
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* Builds an adapter that forwards wallet RPC to a remote wallet through a
|
|
@@ -29,7 +30,7 @@ export function fromRequest(options: fromRequest.Options): Adapter.Adapter {
|
|
|
29
30
|
} = options
|
|
30
31
|
|
|
31
32
|
return Adapter.define(
|
|
32
|
-
{ ...(icon ? { icon } : {}), name, rdns },
|
|
33
|
+
{ ...(icon ? { icon } : {}), name, rdns, schema: z.object({ address: u.address() }) },
|
|
33
34
|
({ getAccount, getClient, store }) => {
|
|
34
35
|
// Late-bind the store so the request channel can reconcile local
|
|
35
36
|
// connection state (e.g. a wallet `accountsChanged` notification).
|
|
@@ -41,6 +41,23 @@ describe('withDedupe', () => {
|
|
|
41
41
|
expect(b).toMatchInlineSnapshot(`2`)
|
|
42
42
|
})
|
|
43
43
|
|
|
44
|
+
test('behavior: separate caches execute independently', async () => {
|
|
45
|
+
let calls = 0
|
|
46
|
+
const fn = () => Promise.resolve(++calls)
|
|
47
|
+
|
|
48
|
+
const [a, b] = await Promise.all([
|
|
49
|
+
withDedupe(fn, { cache: new Map(), id: 'same' }),
|
|
50
|
+
withDedupe(fn, { cache: new Map(), id: 'same' }),
|
|
51
|
+
])
|
|
52
|
+
|
|
53
|
+
expect([a, b]).toMatchInlineSnapshot(`
|
|
54
|
+
[
|
|
55
|
+
1,
|
|
56
|
+
2,
|
|
57
|
+
]
|
|
58
|
+
`)
|
|
59
|
+
})
|
|
60
|
+
|
|
44
61
|
test('behavior: cache is cleared after promise resolves', async () => {
|
|
45
62
|
const fn = () => Promise.resolve('ok')
|
|
46
63
|
|
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
/** Deduplicates in-flight promises by key. */
|
|
2
2
|
export function withDedupe<data>(
|
|
3
3
|
fn: () => Promise<data>,
|
|
4
|
-
{ enabled = true, id }: withDedupe.Options,
|
|
4
|
+
{ cache = withDedupe.cache, enabled = true, id }: withDedupe.Options,
|
|
5
5
|
): Promise<data> {
|
|
6
6
|
if (!enabled || !id) return fn()
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
const cached = cache.get(id)
|
|
8
|
+
if (cached) return cached as Promise<data>
|
|
9
|
+
const promise = fn().finally(() => cache.delete(id))
|
|
10
|
+
cache.set(id, promise)
|
|
10
11
|
return promise
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
export declare namespace withDedupe {
|
|
14
15
|
type Options = {
|
|
16
|
+
cache?: Map<string, Promise<unknown>> | undefined
|
|
15
17
|
enabled?: boolean | undefined
|
|
16
18
|
id?: string | undefined
|
|
17
19
|
}
|
|
18
20
|
}
|
|
19
21
|
|
|
20
|
-
withDedupe.cache = new Map<string, Promise<
|
|
22
|
+
withDedupe.cache = new Map<string, Promise<unknown>>()
|