@greendrake/rpc 0.1.0 → 0.2.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.
- package/package.json +3 -3
- package/src/ResponseCache.ts +1 -1
- package/src/RpcClient.ts +1 -1
- package/src/WebSocketPipe.ts +2 -2
- package/src/WsTransport.ts +2 -2
- package/src/errors.ts +1 -1
- package/src/http.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@greendrake/rpc",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "RPC client over JSON: typed method-map API, HTTP and reconnecting WebSocket transports, pluggable codec and headers, TTL response cache",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Eugene Greendrake <eugene@greendrake.nz>",
|
|
@@ -34,10 +34,10 @@
|
|
|
34
34
|
},
|
|
35
35
|
"prettier": "@greendrake/dev-config/prettier",
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@greendrake/util": "0.
|
|
37
|
+
"@greendrake/util": "0.2.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@greendrake/dev-config": "0.
|
|
40
|
+
"@greendrake/dev-config": "0.2.0",
|
|
41
41
|
"typescript": "6.0.3"
|
|
42
42
|
}
|
|
43
43
|
}
|
package/src/ResponseCache.ts
CHANGED
|
@@ -20,7 +20,7 @@ export interface CacheLookup {
|
|
|
20
20
|
// in-session.
|
|
21
21
|
export class ResponseCache {
|
|
22
22
|
readonly #config: CacheConfig
|
|
23
|
-
readonly #scope
|
|
23
|
+
readonly #scope: (() => string | undefined) | undefined
|
|
24
24
|
readonly #entries = new Map<string, CacheEntry>()
|
|
25
25
|
|
|
26
26
|
// `scope` names the request property that is not an argument yet decides
|
package/src/RpcClient.ts
CHANGED
|
@@ -11,7 +11,7 @@ export class RpcClient<M extends MethodMapConstraint<M> = MethodMap> {
|
|
|
11
11
|
// Supplies the caller's UI language tag per request. Evaluated per call,
|
|
12
12
|
// like HttpTransport's headers provider, so a locale switch takes effect on
|
|
13
13
|
// the next call rather than at construction.
|
|
14
|
-
readonly #locale
|
|
14
|
+
readonly #locale: (() => string | undefined) | undefined
|
|
15
15
|
|
|
16
16
|
constructor(transport: Transport, locale?: () => string | undefined) {
|
|
17
17
|
this.transport = transport
|
package/src/WebSocketPipe.ts
CHANGED
|
@@ -30,13 +30,13 @@ const DEFAULT_RECONNECT_DELAY_MS = 3000
|
|
|
30
30
|
export class WebSocketPipe extends Emitter<WebSocketPipeEvents> {
|
|
31
31
|
readonly #url: string
|
|
32
32
|
readonly #delayMs: (attempt: number) => number
|
|
33
|
-
#ws
|
|
33
|
+
#ws: WebSocket | undefined
|
|
34
34
|
#promise?: Promise<void>
|
|
35
35
|
// A reconnect waiting out its delay: the timer to cancel, and the resolver
|
|
36
36
|
// that advances the armed promise into the attempt. Set only while
|
|
37
37
|
// waiting — cleared the moment the attempt starts — so its presence is
|
|
38
38
|
// exactly the condition reconnectNow() acts on.
|
|
39
|
-
#scheduledReconnect
|
|
39
|
+
#scheduledReconnect: { timer: ReturnType<typeof setTimeout>; start: () => void } | undefined
|
|
40
40
|
#attempt = 0
|
|
41
41
|
#disposed = false
|
|
42
42
|
|
package/src/WsTransport.ts
CHANGED
|
@@ -58,7 +58,7 @@ interface PendingCall {
|
|
|
58
58
|
export class WsTransport<PEvents extends PushMapConstraint<PEvents> = Record<never, never>, PData extends PushMapConstraint<PData> = Record<never, never>> implements Transport {
|
|
59
59
|
readonly pipe: WebSocketPipe
|
|
60
60
|
readonly #codec: Codec
|
|
61
|
-
readonly #auth
|
|
61
|
+
readonly #auth: WsAuthStrategy | undefined
|
|
62
62
|
// Who this transport is to be bound as — cached the moment the credential
|
|
63
63
|
// is handed over, not once a bind succeeds. It states what every
|
|
64
64
|
// connection of this transport should authenticate as, independently of
|
|
@@ -70,7 +70,7 @@ export class WsTransport<PEvents extends PushMapConstraint<PEvents> = Record<nev
|
|
|
70
70
|
// each connection binds exactly once — authenticate() and the reconnect
|
|
71
71
|
// handler converge on this record rather than both putting an auth frame
|
|
72
72
|
// on the same socket.
|
|
73
|
-
#binding
|
|
73
|
+
#binding: { token: string; done: Promise<unknown> } | undefined
|
|
74
74
|
// In-flight calls keyed by request id. A dropped socket never delivers
|
|
75
75
|
// their responses, so they are failed explicitly on close.
|
|
76
76
|
readonly #pending = new Map<string, PendingCall>()
|
package/src/errors.ts
CHANGED
|
@@ -11,7 +11,7 @@ export class NotFoundError extends OneOutcomeError {
|
|
|
11
11
|
// gone — leaving anything that matches on codes (session teardown, the
|
|
12
12
|
// bubbled-error list) unable to see a `*_NOT_FOUND` at all. Absent when the
|
|
13
13
|
// app raises a not-found of its own, from a route that resolved to nothing.
|
|
14
|
-
readonly code
|
|
14
|
+
readonly code: string | undefined
|
|
15
15
|
|
|
16
16
|
constructor(code?: string) {
|
|
17
17
|
super('Not found')
|
package/src/http.ts
CHANGED
|
@@ -25,7 +25,7 @@ export class HttpTransport implements Transport {
|
|
|
25
25
|
const response = await safeFetch(this.#options.url, {
|
|
26
26
|
...this.#options.requestInit,
|
|
27
27
|
method: 'POST',
|
|
28
|
-
headers: this.#options.headers?.(),
|
|
28
|
+
headers: this.#options.headers?.() ?? {},
|
|
29
29
|
body: this.#codec.encode(JSON.stringify(request))
|
|
30
30
|
})
|
|
31
31
|
const text = this.#codec.decode(await response.text())
|