@vastblast/capnweb 0.5.2 → 0.5.3
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/dist/index.d.cts +18 -9
- package/dist/index.d.ts +18 -9
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -12,6 +12,8 @@ import { IncomingMessage, ServerResponse, OutgoingHttpHeaders, OutgoingHttpHeade
|
|
|
12
12
|
// accept `WorkerEntrypoint` from `cloudflare:workers`, not any other class with the same shape)
|
|
13
13
|
declare const __RPC_STUB_BRAND: '__RPC_STUB_BRAND';
|
|
14
14
|
declare const __RPC_TARGET_BRAND: '__RPC_TARGET_BRAND';
|
|
15
|
+
// Distinguishes mapper placeholders from regular values so param unwrapping can accept them.
|
|
16
|
+
declare const __RPC_MAP_VALUE_BRAND: unique symbol;
|
|
15
17
|
interface RpcTargetBranded {
|
|
16
18
|
[__RPC_TARGET_BRAND]: never;
|
|
17
19
|
}
|
|
@@ -66,6 +68,11 @@ interface StubBase<T = unknown> extends Disposable {
|
|
|
66
68
|
onRpcBroken(callback: (error: any) => void): void;
|
|
67
69
|
}
|
|
68
70
|
|
|
71
|
+
// Marker carried by map() callback inputs. This lets primitive placeholders flow through params.
|
|
72
|
+
interface MapValuePlaceholder<T> {
|
|
73
|
+
[__RPC_MAP_VALUE_BRAND]: T;
|
|
74
|
+
}
|
|
75
|
+
|
|
69
76
|
// Types that can be passed over RPC.
|
|
70
77
|
// The reason for using a generic type here is to build a serializable subset of structured
|
|
71
78
|
// cloneable composite types. This allows types defined with the "interface" keyword to pass the
|
|
@@ -143,7 +150,12 @@ type UnstubifyInner<T> =
|
|
|
143
150
|
|
|
144
151
|
// You can put promises anywhere in the params and they'll be resolved before delivery.
|
|
145
152
|
// (This also covers RpcPromise, because it's defined as being a Promise.)
|
|
146
|
-
|
|
153
|
+
// Map placeholders are also allowed so primitive map callback inputs can be forwarded directly
|
|
154
|
+
// into RPC params.
|
|
155
|
+
type Unstubify<T> =
|
|
156
|
+
UnstubifyInner<T> |
|
|
157
|
+
Promise<UnstubifyInner<T>> |
|
|
158
|
+
MapValuePlaceholder<UnstubifyInner<T>>;
|
|
147
159
|
|
|
148
160
|
type UnstubifyAll<A extends readonly unknown[]> = { [I in keyof A]: Unstubify<A[I]> };
|
|
149
161
|
|
|
@@ -187,27 +199,24 @@ type TupleIndexKeys<T extends ReadonlyArray<unknown>> =
|
|
|
187
199
|
Extract<keyof T, `${number}`>;
|
|
188
200
|
type MapCallbackValue<T> =
|
|
189
201
|
// `Omit` removes call signatures, so re-intersect callable provider behavior.
|
|
190
|
-
T extends unknown
|
|
202
|
+
T extends unknown
|
|
203
|
+
? Omit<Result<T>, keyof Promise<unknown>> & MaybeCallableProvider<T> & MapValuePlaceholder<T>
|
|
204
|
+
: never;
|
|
191
205
|
type InvalidNativePromiseInMapResult<T, Seen = never> =
|
|
192
206
|
T extends unknown ? InvalidNativePromiseInMapResultImpl<T, Seen> : never;
|
|
193
207
|
type InvalidNativePromiseInMapResultImpl<T, Seen> =
|
|
194
208
|
[T] extends [Seen] ? never :
|
|
195
209
|
// RpcPromise is modeled as Promise & StubBase, so allow promise-like stub values.
|
|
196
210
|
T extends StubBase<any> ? never
|
|
197
|
-
// Native
|
|
198
|
-
: T extends
|
|
211
|
+
// Native thenables cannot be represented in map recordings, even when typed as PromiseLike.
|
|
212
|
+
: T extends PromiseLike<unknown> ? T
|
|
199
213
|
: T extends Map<infer K, infer V>
|
|
200
214
|
? InvalidNativePromiseInMapResult<K, Seen | T> | InvalidNativePromiseInMapResult<V, Seen | T>
|
|
201
215
|
: T extends Set<infer V> ? InvalidNativePromiseInMapResult<V, Seen | T>
|
|
202
|
-
: T extends [] ? never
|
|
203
|
-
: T extends [infer Head, ...infer Tail]
|
|
204
|
-
? InvalidNativePromiseInMapResult<Head, Seen | T>
|
|
205
|
-
| InvalidNativePromiseInMapResult<Tail[number], Seen | T>
|
|
206
216
|
: T extends readonly [] ? never
|
|
207
217
|
: T extends readonly [infer Head, ...infer Tail]
|
|
208
218
|
? InvalidNativePromiseInMapResult<Head, Seen | T>
|
|
209
219
|
| InvalidNativePromiseInMapResult<Tail[number], Seen | T>
|
|
210
|
-
: T extends Array<infer V> ? InvalidNativePromiseInMapResult<V, Seen | T>
|
|
211
220
|
: T extends ReadonlyArray<infer V> ? InvalidNativePromiseInMapResult<V, Seen | T>
|
|
212
221
|
: T extends { [key: string | number]: unknown }
|
|
213
222
|
? InvalidNativePromiseInMapResult<T[Extract<keyof T, string | number>], Seen | T>
|
package/dist/index.d.ts
CHANGED
|
@@ -12,6 +12,8 @@ import { IncomingMessage, ServerResponse, OutgoingHttpHeaders, OutgoingHttpHeade
|
|
|
12
12
|
// accept `WorkerEntrypoint` from `cloudflare:workers`, not any other class with the same shape)
|
|
13
13
|
declare const __RPC_STUB_BRAND: '__RPC_STUB_BRAND';
|
|
14
14
|
declare const __RPC_TARGET_BRAND: '__RPC_TARGET_BRAND';
|
|
15
|
+
// Distinguishes mapper placeholders from regular values so param unwrapping can accept them.
|
|
16
|
+
declare const __RPC_MAP_VALUE_BRAND: unique symbol;
|
|
15
17
|
interface RpcTargetBranded {
|
|
16
18
|
[__RPC_TARGET_BRAND]: never;
|
|
17
19
|
}
|
|
@@ -66,6 +68,11 @@ interface StubBase<T = unknown> extends Disposable {
|
|
|
66
68
|
onRpcBroken(callback: (error: any) => void): void;
|
|
67
69
|
}
|
|
68
70
|
|
|
71
|
+
// Marker carried by map() callback inputs. This lets primitive placeholders flow through params.
|
|
72
|
+
interface MapValuePlaceholder<T> {
|
|
73
|
+
[__RPC_MAP_VALUE_BRAND]: T;
|
|
74
|
+
}
|
|
75
|
+
|
|
69
76
|
// Types that can be passed over RPC.
|
|
70
77
|
// The reason for using a generic type here is to build a serializable subset of structured
|
|
71
78
|
// cloneable composite types. This allows types defined with the "interface" keyword to pass the
|
|
@@ -143,7 +150,12 @@ type UnstubifyInner<T> =
|
|
|
143
150
|
|
|
144
151
|
// You can put promises anywhere in the params and they'll be resolved before delivery.
|
|
145
152
|
// (This also covers RpcPromise, because it's defined as being a Promise.)
|
|
146
|
-
|
|
153
|
+
// Map placeholders are also allowed so primitive map callback inputs can be forwarded directly
|
|
154
|
+
// into RPC params.
|
|
155
|
+
type Unstubify<T> =
|
|
156
|
+
UnstubifyInner<T> |
|
|
157
|
+
Promise<UnstubifyInner<T>> |
|
|
158
|
+
MapValuePlaceholder<UnstubifyInner<T>>;
|
|
147
159
|
|
|
148
160
|
type UnstubifyAll<A extends readonly unknown[]> = { [I in keyof A]: Unstubify<A[I]> };
|
|
149
161
|
|
|
@@ -187,27 +199,24 @@ type TupleIndexKeys<T extends ReadonlyArray<unknown>> =
|
|
|
187
199
|
Extract<keyof T, `${number}`>;
|
|
188
200
|
type MapCallbackValue<T> =
|
|
189
201
|
// `Omit` removes call signatures, so re-intersect callable provider behavior.
|
|
190
|
-
T extends unknown
|
|
202
|
+
T extends unknown
|
|
203
|
+
? Omit<Result<T>, keyof Promise<unknown>> & MaybeCallableProvider<T> & MapValuePlaceholder<T>
|
|
204
|
+
: never;
|
|
191
205
|
type InvalidNativePromiseInMapResult<T, Seen = never> =
|
|
192
206
|
T extends unknown ? InvalidNativePromiseInMapResultImpl<T, Seen> : never;
|
|
193
207
|
type InvalidNativePromiseInMapResultImpl<T, Seen> =
|
|
194
208
|
[T] extends [Seen] ? never :
|
|
195
209
|
// RpcPromise is modeled as Promise & StubBase, so allow promise-like stub values.
|
|
196
210
|
T extends StubBase<any> ? never
|
|
197
|
-
// Native
|
|
198
|
-
: T extends
|
|
211
|
+
// Native thenables cannot be represented in map recordings, even when typed as PromiseLike.
|
|
212
|
+
: T extends PromiseLike<unknown> ? T
|
|
199
213
|
: T extends Map<infer K, infer V>
|
|
200
214
|
? InvalidNativePromiseInMapResult<K, Seen | T> | InvalidNativePromiseInMapResult<V, Seen | T>
|
|
201
215
|
: T extends Set<infer V> ? InvalidNativePromiseInMapResult<V, Seen | T>
|
|
202
|
-
: T extends [] ? never
|
|
203
|
-
: T extends [infer Head, ...infer Tail]
|
|
204
|
-
? InvalidNativePromiseInMapResult<Head, Seen | T>
|
|
205
|
-
| InvalidNativePromiseInMapResult<Tail[number], Seen | T>
|
|
206
216
|
: T extends readonly [] ? never
|
|
207
217
|
: T extends readonly [infer Head, ...infer Tail]
|
|
208
218
|
? InvalidNativePromiseInMapResult<Head, Seen | T>
|
|
209
219
|
| InvalidNativePromiseInMapResult<Tail[number], Seen | T>
|
|
210
|
-
: T extends Array<infer V> ? InvalidNativePromiseInMapResult<V, Seen | T>
|
|
211
220
|
: T extends ReadonlyArray<infer V> ? InvalidNativePromiseInMapResult<V, Seen | T>
|
|
212
221
|
: T extends { [key: string | number]: unknown }
|
|
213
222
|
? InvalidNativePromiseInMapResult<T[Extract<keyof T, string | number>], Seen | T>
|