orpc-fn 0.5.1 → 0.6.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/README.md +12 -3
- package/dist/live/scoped-change-bus.d.ts +11 -3
- package/dist/live/scoped-change-bus.d.ts.map +1 -1
- package/dist/live/scoped-change-bus.js +6 -2
- package/dist/live/scoped-change-bus.js.map +1 -1
- package/dist/vue.d.ts +10 -4
- package/dist/vue.d.ts.map +1 -1
- package/dist/vue.js +8 -6
- package/dist/vue.js.map +1 -1
- package/package.json +1 -1
- package/src/live/scoped-change-bus.ts +18 -5
- package/src/vue.ts +29 -14
package/README.md
CHANGED
|
@@ -132,7 +132,7 @@ The `subscribe` route runs builder middleware and the same fn guards/extras/meta
|
|
|
132
132
|
|
|
133
133
|
**`createPubSub`** returns a typed `subscribe` route plus `publish`, `publishMany` (one atomic round-trip across channels) and typed `getSubscriptionChannelName({ input, context })` / `getPublishChannelName(event)` methods. The shared partial-input `getChannelName` method is deprecated. Publishers pass the event schema's input type; subscribers, filters and channel resolvers get its output type. The raw event travels in oRPC's JSON format, so `Date`, `Map`, `Set` and `BigInt` survive, and each receiver parses it once. Options include `filterFn`, `authFn`, `mirrorChannel`, `overflowMarker`, `procedure`, configured guards and `meta`. Channels may be static or use `channel: { subscribe: ({ input, context }) => key, publish: (parsedEvent) => key }`. Carry publishing tenant keys in the event. A factory `namespace` prefixes channels, mirrors and backlog keys. Each pub/sub definition subscribes to each channel once and parses each payload once for all local subscribers. Each subscriber then runs its filter in arrival order as it reads; its bounded queue holds events before filtering, so `onDrop` counts unfiltered events. Abort and drain release a subscription at once, even one that is not being read. A lost subscription is retried with exponential backoff and jitter. `safePublish` logs a failed publish (`pubsub.publish_failed`) instead of throwing, as on `fnLive`. **`createPublisher`** is the publish-only half.
|
|
134
134
|
|
|
135
|
-
**`defineScopedChangeBus`** binds `createPubSub` to one scope rule, for buses that tell everyone in a scope (usually an organization) "this changed". Each bus names a channel `prefix`; events go to `${prefix}:${scope}`. Publishing is safe by default, since buses publish after committed writes. `bus.channel` lets an `fnLive` share the bus's events.
|
|
135
|
+
**`defineScopedChangeBus`** binds `createPubSub` to one scope rule, for buses that tell everyone in a scope (usually an organization) "this changed". Each bus names a channel `prefix`; events go to `${prefix}:${scope}`. Publishing is safe by default, since buses publish after committed writes. `inputSchema` defaults to `z.object({})`. `bus.channel` lets an `fnLive` share the bus's events, and `bus.channelFor({ organizationId })` returns a scope's full channel name, namespace included, e.g. for `backlogKey(...)`.
|
|
136
136
|
|
|
137
137
|
```ts
|
|
138
138
|
import { defineScopedChangeBus, invalidationStream } from 'orpc-fn/live'
|
|
@@ -144,7 +144,6 @@ const defineChangeBus = defineScopedChangeBus(createPubSub, {
|
|
|
144
144
|
export const dealChanges = defineChangeBus({
|
|
145
145
|
name: 'deal.subscribe',
|
|
146
146
|
prefix: 'deal:change',
|
|
147
|
-
inputSchema: z.object({}),
|
|
148
147
|
eventSchema: z.object({ organizationId: z.string(), dealId: z.string() })
|
|
149
148
|
})
|
|
150
149
|
```
|
|
@@ -368,6 +367,16 @@ const { useQuery, useMutation, invalidate } = useApiClient()
|
|
|
368
367
|
const orders = useQuery((o) => o.order.list.queryOptions({ input: { search: search.value } }))
|
|
369
368
|
const save = useMutation((o) => o.order.update.mutationOptions({ onSuccess: () => invalidate((o) => o.order.key()) }))
|
|
370
369
|
|
|
370
|
+
// Form state: `inputData` is typed from the route; `initialInput` is checked against it.
|
|
371
|
+
const { inputData: form, mutate } = useMutation((o) => o.order.update.mutationOptions(), {
|
|
372
|
+
initialInput: { id: props.id, data: {} }
|
|
373
|
+
})
|
|
374
|
+
|
|
375
|
+
// A helper that takes the composables: `ApiClient` is bound to the registered utils.
|
|
376
|
+
function invalidateOrders(invalidate: ApiClient['invalidate']) {
|
|
377
|
+
void invalidate((o) => o.order.key())
|
|
378
|
+
}
|
|
379
|
+
|
|
371
380
|
// The client half of `fnLive`: HTTP seeds the cache, the stream keeps it current.
|
|
372
381
|
const order = useLiveQuery(
|
|
373
382
|
() => ({ id: props.id }),
|
|
@@ -382,7 +391,7 @@ useInvalidationStream({}, (o) => o.realtime.subscribeChanges.call, {
|
|
|
382
391
|
})
|
|
383
392
|
```
|
|
384
393
|
|
|
385
|
-
`useOrpcSubscription` (also `useApiClient().useSubscription`) reconnects with jittered backoff and closes while the page is hidden (`respectVisibility: false` keeps it). `useLiveQuery` writes each stream event under the key it was opened for, so an event in flight from a previous input is dropped. A stream whose events are not the cached type (an `fnLive` patch route, or a `select`ed cache) does not compile without `applyEvent`, and the stream's input must match the query's unless you pass `subscriptionInput`. Use `mergeSeed` when the seed can resolve after stream events. For large live payloads such as chat timelines, pass vue-query's `shallow: true` in the query options so the data is not made deeply reactive; mutate it only through `setQueryData`. Live queries carry `meta.live`, so invalidation streams skip them. Leave `refetchType` at TanStack's `'active'`: `'all'` refetches every cached query of a domain on each event, including screens nobody has open, which refetch on their next visit anyway. `useSubscriptionInvalidates` treats a stream as a "something changed" ping, and `useQueryErrorMessage` is `userFacingErrorMessage` as a computed. A surface that talks to another API passes `orpc` to each composable instead of using `provideOrpc`.
|
|
394
|
+
`useApiClient()` also returns the utils as `orpc`, for calls outside a composable such as `queryClient.fetchQuery(orpc.unit.list.queryOptions({ input }))`. `useOrpcSubscription` (also `useApiClient().useSubscription`) reconnects with jittered backoff and closes while the page is hidden (`respectVisibility: false` keeps it). `useLiveQuery` writes each stream event under the key it was opened for, so an event in flight from a previous input is dropped. A stream whose events are not the cached type (an `fnLive` patch route, or a `select`ed cache) does not compile without `applyEvent`, and the stream's input must match the query's unless you pass `subscriptionInput`. Use `mergeSeed` when the seed can resolve after stream events. For large live payloads such as chat timelines, pass vue-query's `shallow: true` in the query options so the data is not made deeply reactive; mutate it only through `setQueryData`. Live queries carry `meta.live`, so invalidation streams skip them. Leave `refetchType` at TanStack's `'active'`: `'all'` refetches every cached query of a domain on each event, including screens nobody has open, which refetch on their next visit anyway. `useSubscriptionInvalidates` treats a stream as a "something changed" ping, and `useQueryErrorMessage` is `userFacingErrorMessage` as a computed. A surface that talks to another API passes `orpc` to each composable instead of using `provideOrpc`.
|
|
386
395
|
|
|
387
396
|
`orpc-fn/vue/testing` runs composables in a real app without a DOM: `withOrpcApp(setup, { utils })`, `createTestStream()` for a subscription the test drives (`await stream.push(event)` resolves once it was handled), and `createOrpcMock({ fn: mock })` for a deep stand-in of the utils.
|
|
388
397
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type ZodType, z } from 'zod';
|
|
2
2
|
import type { AnyFnContext, FnDefinition, FnRouteOptions, GuardOptions, ProcedureKey, ProcedureOption } from '../types.js';
|
|
3
3
|
import type { CreatePubSub, ObjectSchema, PubSub, PubSubOptions } from './pub-sub.js';
|
|
4
4
|
/** Where a change bus partitions its channels, e.g. one per organization. */
|
|
@@ -17,7 +17,13 @@ export type ChangeBusChannel<TContext, TEvent> = {
|
|
|
17
17
|
};
|
|
18
18
|
export type ScopedChangeBus<TDef extends FnDefinition, TInputSchema extends ObjectSchema, TEventSchema extends ZodType, TKey extends ProcedureKey<TDef>, TScopeEvent> = PubSub<TDef, TInputSchema, TEventSchema, TKey> & {
|
|
19
19
|
channel: ChangeBusChannel<AnyFnContext<TDef>, TScopeEvent>;
|
|
20
|
+
/**
|
|
21
|
+
* The full channel name for a scope, namespace included:
|
|
22
|
+
* `backlogKey(bus.channelFor({ organizationId }))` reads its backlog.
|
|
23
|
+
*/
|
|
24
|
+
channelFor: (scope: TScopeEvent) => string;
|
|
20
25
|
};
|
|
26
|
+
declare const noInput: z.ZodObject<{}, z.core.$strip>;
|
|
21
27
|
/**
|
|
22
28
|
* Binds the app's `createPubSub` to one scope rule, for buses that tell every
|
|
23
29
|
* subscriber in a scope "something changed". Each bus then names only its
|
|
@@ -32,14 +38,16 @@ export type ScopedChangeBus<TDef extends FnDefinition, TInputSchema extends Obje
|
|
|
32
38
|
* export const dealChanges = defineChangeBus({
|
|
33
39
|
* name: 'deal.subscribe',
|
|
34
40
|
* prefix: 'deal:change',
|
|
35
|
-
* inputSchema: z.object({}),
|
|
36
41
|
* eventSchema: z.object({ organizationId: z.string(), dealId: z.string() })
|
|
37
42
|
* })
|
|
38
43
|
* // fnLive({ live: { channel: dealChanges.channel, ... } }) shares the channel.
|
|
39
44
|
* ```
|
|
40
45
|
*/
|
|
41
|
-
export declare function defineScopedChangeBus<TDef extends FnDefinition, TScopeEvent>(createPubSub: CreatePubSub<TDef>, scope: ChangeBusScope<AnyFnContext<TDef>, TScopeEvent>): <
|
|
46
|
+
export declare function defineScopedChangeBus<TDef extends FnDefinition, TScopeEvent>(createPubSub: CreatePubSub<TDef>, scope: ChangeBusScope<AnyFnContext<TDef>, TScopeEvent>): <TEventSchema extends ZodType<TScopeEvent>, TInputSchema extends ObjectSchema = typeof noInput, TKey extends ProcedureKey<TDef> = TDef['default']>(options: Omit<PubSubOptions<TDef, TInputSchema, TEventSchema, NoInfer<TKey>>, 'channel' | 'inputSchema'> & GuardOptions<TDef['guards']> & Pick<FnRouteOptions<TDef, TKey, z.output<TInputSchema>>, 'meta' | 'guardResolvers'> & ProcedureOption<TDef, TKey> & {
|
|
42
47
|
/** Channel prefix; the scope key is appended as `${prefix}:${scope}`. */
|
|
43
48
|
prefix: string;
|
|
49
|
+
/** What the subscriber provides (default: no input). */
|
|
50
|
+
inputSchema?: TInputSchema;
|
|
44
51
|
}) => ScopedChangeBus<TDef, TInputSchema, TEventSchema, TKey, TScopeEvent>;
|
|
52
|
+
export {};
|
|
45
53
|
//# sourceMappingURL=scoped-change-bus.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scoped-change-bus.d.ts","sourceRoot":"","sources":["../../src/live/scoped-change-bus.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"scoped-change-bus.d.ts","sourceRoot":"","sources":["../../src/live/scoped-change-bus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,E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AAY,EAAE,YAAY,CAAC,IAAI,CAAC,EAChC,KAAK,EAAE,cAAc,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,WAAW,CAAC,IAGrD,YAAY,SAAS,OAAO,CAAC,WAAW,CAAC,EACzC,YAAY,SAAS,YAAY,GAAG,OAAO,OAAO,EAClD,IAAI,SAAS,YAAY,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,WAExC,IAAI,CACZ,aAAa,CAAC,IAAI,EAAE,YAAY,EAAE,YAAY,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,EAC9D,SAAS,GAAG,aAAa,CACzB,GACA,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,GAC5B,IAAI,CACH,cAAc,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,EAClD,MAAM,GAAG,gBAAgB,CACzB,GACD,eAAe,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG;IAC7B,yEAAyE;IACzE,MAAM,EAAE,MAAM,CAAA;IACd,wDAAwD;IACxD,WAAW,CAAC,EAAE,YAAY,CAAA;CAC1B,KACA,eAAe,CAAC,IAAI,EAAE,YAAY,EAAE,YAAY,EAAE,IAAI,EAAE,WAAW,CAAC,CAoBvE"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
const noInput = z.object({});
|
|
1
3
|
/**
|
|
2
4
|
* Binds the app's `createPubSub` to one scope rule, for buses that tell every
|
|
3
5
|
* subscriber in a scope "something changed". Each bus then names only its
|
|
@@ -12,7 +14,6 @@
|
|
|
12
14
|
* export const dealChanges = defineChangeBus({
|
|
13
15
|
* name: 'deal.subscribe',
|
|
14
16
|
* prefix: 'deal:change',
|
|
15
|
-
* inputSchema: z.object({}),
|
|
16
17
|
* eventSchema: z.object({ organizationId: z.string(), dealId: z.string() })
|
|
17
18
|
* })
|
|
18
19
|
* // fnLive({ live: { channel: dealChanges.channel, ... } }) shares the channel.
|
|
@@ -30,9 +31,12 @@ export function defineScopedChangeBus(createPubSub, scope) {
|
|
|
30
31
|
const bus = createPubSub({
|
|
31
32
|
safePublish: true,
|
|
32
33
|
...pubsubOptions,
|
|
34
|
+
inputSchema: pubsubOptions.inputSchema ?? noInput,
|
|
33
35
|
channel
|
|
34
36
|
});
|
|
35
|
-
|
|
37
|
+
// The scope reads only its own fields, so a scope stands in for an event.
|
|
38
|
+
const channelFor = bus.getPublishChannelName;
|
|
39
|
+
return { ...bus, channel, channelFor };
|
|
36
40
|
};
|
|
37
41
|
}
|
|
38
42
|
//# sourceMappingURL=scoped-change-bus.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scoped-change-bus.js","sourceRoot":"","sources":["../../src/live/scoped-change-bus.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"scoped-change-bus.js","sourceRoot":"","sources":["../../src/live/scoped-change-bus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,CAAC,EAAE,MAAM,KAAK,CAAA;AA6CrC,MAAM,OAAO,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;AAE5B;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,qBAAqB,CACpC,YAAgC,EAChC,KAAsD;IAEtD,OAAO,CAKN,OAcE,EACqE,EAAE;QACzE,MAAM,EAAE,MAAM,EAAE,GAAG,aAAa,EAAE,GAAG,OAAO,CAAA;QAC5C,MAAM,OAAO,GAAsD;YAClE,SAAS,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,GAAG,MAAM,IAAI,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE;YACnE,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,GAAG,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;SACvD,CAAA;QACD,qEAAqE;QACrE,wCAAwC;QACxC,MAAM,GAAG,GAAI,YAA4C,CAAC;YACzD,WAAW,EAAE,IAAI;YACjB,GAAG,aAAa;YAChB,WAAW,EAAE,aAAa,CAAC,WAAW,IAAI,OAAO;YACjD,OAAO;SACP,CAAmD,CAAA;QACpD,0EAA0E;QAC1E,MAAM,UAAU,GAAG,GAAG,CAAC,qBAEZ,CAAA;QACX,OAAO,EAAE,GAAG,GAAG,EAAE,OAAO,EAAE,UAAU,EAAE,CAAA;IACvC,CAAC,CAAA;AACF,CAAC","sourcesContent":["import { type ZodType, z } from 'zod'\nimport type {\n\tAnyFnContext,\n\tFnDefinition,\n\tFnRouteOptions,\n\tGuardOptions,\n\tProcedureKey,\n\tProcedureOption\n} from '../types.js'\nimport type {\n\tCreatePubSub,\n\tObjectSchema,\n\tPubSub,\n\tPubSubOptions\n} from './pub-sub.js'\n\n/** Where a change bus partitions its channels, e.g. one per organization. */\nexport type ChangeBusScope<TContext, TEvent> = {\n\t/** The subscriber's scope key, from its context. Throw to refuse the subscription. */\n\tsubscribe: (context: TContext) => string\n\t/** The event's scope key, carried in the event itself. */\n\tpublish: (event: TEvent) => string\n}\n\n/** A bus's channel definition; pass it to `fnLive` to share the bus's events. */\nexport type ChangeBusChannel<TContext, TEvent> = {\n\tsubscribe: (params: { context: TContext }) => string\n\tpublish: (event: TEvent) => string\n}\n\nexport type ScopedChangeBus<\n\tTDef extends FnDefinition,\n\tTInputSchema extends ObjectSchema,\n\tTEventSchema extends ZodType,\n\tTKey extends ProcedureKey<TDef>,\n\tTScopeEvent\n> = PubSub<TDef, TInputSchema, TEventSchema, TKey> & {\n\tchannel: ChangeBusChannel<AnyFnContext<TDef>, TScopeEvent>\n\t/**\n\t * The full channel name for a scope, namespace included:\n\t * `backlogKey(bus.channelFor({ organizationId }))` reads its backlog.\n\t */\n\tchannelFor: (scope: TScopeEvent) => string\n}\n\nconst noInput = z.object({})\n\n/**\n * Binds the app's `createPubSub` to one scope rule, for buses that tell every\n * subscriber in a scope \"something changed\". Each bus then names only its\n * channel prefix: events go to `${prefix}:${scope}`. Publishing is safe by\n * default (`safePublish: true`), because buses publish after committed writes.\n *\n * ```ts\n * const defineChangeBus = defineScopedChangeBus(createPubSub, {\n * subscribe: (context) => activeOrganizationId(context),\n * publish: (event: { organizationId: string }) => event.organizationId\n * })\n * export const dealChanges = defineChangeBus({\n * name: 'deal.subscribe',\n * prefix: 'deal:change',\n * eventSchema: z.object({ organizationId: z.string(), dealId: z.string() })\n * })\n * // fnLive({ live: { channel: dealChanges.channel, ... } }) shares the channel.\n * ```\n */\nexport function defineScopedChangeBus<TDef extends FnDefinition, TScopeEvent>(\n\tcreatePubSub: CreatePubSub<TDef>,\n\tscope: ChangeBusScope<AnyFnContext<TDef>, TScopeEvent>\n) {\n\treturn <\n\t\tTEventSchema extends ZodType<TScopeEvent>,\n\t\tTInputSchema extends ObjectSchema = typeof noInput,\n\t\tTKey extends ProcedureKey<TDef> = TDef['default']\n\t>(\n\t\toptions: Omit<\n\t\t\tPubSubOptions<TDef, TInputSchema, TEventSchema, NoInfer<TKey>>,\n\t\t\t'channel' | 'inputSchema'\n\t\t> &\n\t\t\tGuardOptions<TDef['guards']> &\n\t\t\tPick<\n\t\t\t\tFnRouteOptions<TDef, TKey, z.output<TInputSchema>>,\n\t\t\t\t'meta' | 'guardResolvers'\n\t\t\t> &\n\t\t\tProcedureOption<TDef, TKey> & {\n\t\t\t\t/** Channel prefix; the scope key is appended as `${prefix}:${scope}`. */\n\t\t\t\tprefix: string\n\t\t\t\t/** What the subscriber provides (default: no input). */\n\t\t\t\tinputSchema?: TInputSchema\n\t\t\t}\n\t): ScopedChangeBus<TDef, TInputSchema, TEventSchema, TKey, TScopeEvent> => {\n\t\tconst { prefix, ...pubsubOptions } = options\n\t\tconst channel: ChangeBusChannel<AnyFnContext<TDef>, TScopeEvent> = {\n\t\t\tsubscribe: ({ context }) => `${prefix}:${scope.subscribe(context)}`,\n\t\t\tpublish: (event) => `${prefix}:${scope.publish(event)}`\n\t\t}\n\t\t// The bus's context is one member of AnyFnContext, which the generic\n\t\t// signature of createPubSub cannot see.\n\t\tconst bus = (createPubSub as (options: object) => object)({\n\t\t\tsafePublish: true,\n\t\t\t...pubsubOptions,\n\t\t\tinputSchema: pubsubOptions.inputSchema ?? noInput,\n\t\t\tchannel\n\t\t}) as PubSub<TDef, TInputSchema, TEventSchema, TKey>\n\t\t// The scope reads only its own fields, so a scope stands in for an event.\n\t\tconst channelFor = bus.getPublishChannelName as (\n\t\t\tscope: TScopeEvent\n\t\t) => string\n\t\treturn { ...bus, channel, channelFor }\n\t}\n}\n"]}
|
package/dist/vue.d.ts
CHANGED
|
@@ -87,6 +87,8 @@ export interface UseSubscriptionReturn<TEvent> {
|
|
|
87
87
|
* pause while the page is hidden. Closed when the owning effect scope stops.
|
|
88
88
|
*/
|
|
89
89
|
export declare function useOrpcSubscription<TInput, TEvent, TOrpc = RegisteredOrpcUtils>(input: MaybeRefOrGetter<TInput>, subscribeFn: OrpcSubscribeFn<TInput, TEvent, TOrpc>, options?: UseSubscriptionOptions<TEvent, TOrpc>): UseSubscriptionReturn<TEvent>;
|
|
90
|
+
/** What {@link useApiClient} returns, e.g. `ApiClient['invalidate']` for a helper. */
|
|
91
|
+
export type ApiClient<TOrpc = RegisteredOrpcUtils> = ReturnType<typeof useBoundApiClient<TOrpc>>;
|
|
90
92
|
/**
|
|
91
93
|
* TanStack Query composables that receive the oRPC utils, so call sites read
|
|
92
94
|
* `useQuery((o) => o.order.get.queryOptions({ input }))`. Pass `orpc` to bind
|
|
@@ -94,12 +96,16 @@ export declare function useOrpcSubscription<TInput, TEvent, TOrpc = RegisteredOr
|
|
|
94
96
|
*/
|
|
95
97
|
export declare function useApiClient<TOrpc = RegisteredOrpcUtils>(clientOptions?: {
|
|
96
98
|
orpc?: MaybeRefOrGetter<TOrpc> | undefined;
|
|
97
|
-
}):
|
|
98
|
-
|
|
99
|
+
}): ApiClient<TOrpc>;
|
|
100
|
+
export declare function useApiClient(): ApiClient;
|
|
101
|
+
declare function useBoundApiClient<TOrpc>(orpc: MaybeRefOrGetter<TOrpc> | undefined): {
|
|
102
|
+
/** The utils themselves, for `queryClient.fetchQuery(orpc.x.queryOptions(...))` and the like. */
|
|
103
|
+
readonly orpc: TOrpc;
|
|
104
|
+
useQuery: <TQueryFnData, TError = Error, TData = TQueryFnData>(optionsFn: (orpc: TOrpc) => UseQueryOptions<TQueryFnData, TError, TData, TQueryFnData>) => UseQueryReturnType<TData, TError>;
|
|
99
105
|
useInfiniteQuery: <TQueryFnData, TError = Error, TData = InfiniteData<TQueryFnData, unknown>, TQueryKey extends QueryKey = readonly unknown[], TPageParam = unknown>(optionsFn: (orpc: TOrpc) => UseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>) => UseInfiniteQueryReturnType<TData, TError>;
|
|
100
106
|
useMutation: {
|
|
101
|
-
<TData = unknown, TError = Error, TVariables =
|
|
102
|
-
initialInput: TVariables
|
|
107
|
+
<TData = unknown, TError = Error, TVariables = unknown, TContext = unknown>(optionsFn: (orpc: TOrpc) => MutationObserverOptions<TData, TError, TVariables, TContext>, config: {
|
|
108
|
+
initialInput: NoInfer<TVariables>;
|
|
103
109
|
}): UseMutationReturnType<TData, TError, TVariables, TContext> & {
|
|
104
110
|
inputData: Ref<TVariables>;
|
|
105
111
|
mutate: (variables?: TVariables) => void;
|
package/dist/vue.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vue.d.ts","sourceRoot":"","sources":["../src/vue.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,YAAY,EACjB,KAAK,iBAAiB,EAGtB,KAAK,gBAAgB,EACrB,KAAK,YAAY,EACjB,KAAK,sBAAsB,EAC3B,KAAK,uBAAuB,EAC5B,KAAK,uBAAuB,EAC5B,KAAK,0BAA0B,EAC/B,KAAK,qBAAqB,EAC1B,KAAK,kBAAkB,EACvB,KAAK,OAAO,EAEZ,KAAK,QAAQ,EACb,KAAK,eAAe,EAGpB,QAAQ,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gBAAgB,CAAC,MAAM,CAAC,4CAMlC"}
|
package/dist/vue.js
CHANGED
|
@@ -140,14 +140,12 @@ export function useOrpcSubscription(input, subscribeFn, options = {}) {
|
|
|
140
140
|
clearEvents
|
|
141
141
|
};
|
|
142
142
|
}
|
|
143
|
-
/**
|
|
144
|
-
* TanStack Query composables that receive the oRPC utils, so call sites read
|
|
145
|
-
* `useQuery((o) => o.order.get.queryOptions({ input }))`. Pass `orpc` to bind
|
|
146
|
-
* another client than the provided one.
|
|
147
|
-
*/
|
|
148
143
|
export function useApiClient(clientOptions) {
|
|
144
|
+
return useBoundApiClient(clientOptions?.orpc);
|
|
145
|
+
}
|
|
146
|
+
function useBoundApiClient(orpc) {
|
|
149
147
|
const queryClient = useQueryClient();
|
|
150
|
-
const getO = useUtilsGetter(
|
|
148
|
+
const getO = useUtilsGetter(orpc);
|
|
151
149
|
// Each wrapper forwards TanStack's own generics, so `select`, typed errors,
|
|
152
150
|
// page params and oRPC's tagged keys infer exactly as with vue-query itself.
|
|
153
151
|
function useQuery(optionsFn) {
|
|
@@ -181,6 +179,10 @@ export function useApiClient(clientOptions) {
|
|
|
181
179
|
}
|
|
182
180
|
const keyOf = (keyFn) => keyFn(getO());
|
|
183
181
|
return {
|
|
182
|
+
/** The utils themselves, for `queryClient.fetchQuery(orpc.x.queryOptions(...))` and the like. */
|
|
183
|
+
get orpc() {
|
|
184
|
+
return getO();
|
|
185
|
+
},
|
|
184
186
|
useQuery,
|
|
185
187
|
useInfiniteQuery,
|
|
186
188
|
useMutation,
|
package/dist/vue.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vue.js","sourceRoot":"","sources":["../src/vue.ts"],"names":[],"mappings":"AAAA,OAAO,EAGN,YAAY,EACZ,OAAO,EAUP,gBAAgB,EAGhB,gBAAgB,IAAI,mBAAmB,EACvC,WAAW,IAAI,cAAc,EAC7B,QAAQ,IAAI,WAAW,EACvB,cAAc,EACd,MAAM,qBAAqB,CAAA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AK,CAAC,CAAA;QAC1B,OAAO,GAAG,CAAC,CAAC,CAAC,sBAAsB,CAAC,GAAG,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;IACnE,CAAC,CAAC,CAAA;AACH,CAAC","sourcesContent":["import {\n\ttype DefaultError,\n\ttype FetchQueryOptions,\n\tfocusManager,\n\thashKey,\n\ttype InferDataFromTag,\n\ttype InfiniteData,\n\ttype InvalidateQueryFilters,\n\ttype MutationObserverOptions,\n\ttype UseInfiniteQueryOptions,\n\ttype UseInfiniteQueryReturnType,\n\ttype UseMutationReturnType,\n\ttype UseQueryReturnType,\n\ttype Updater,\n\tkeepPreviousData,\n\ttype QueryKey,\n\ttype UseQueryOptions,\n\tuseInfiniteQuery as useVueInfiniteQuery,\n\tuseMutation as useVueMutation,\n\tuseQuery as useVueQuery,\n\tuseQueryClient\n} from '@tanstack/vue-query'\nimport {\n\ttype App,\n\tcomputed,\n\tgetCurrentScope,\n\thasInjectionContext,\n\ttype InjectionKey,\n\tinject,\n\ttype MaybeRefOrGetter,\n\tonScopeDispose,\n\ttype Ref,\n\tref,\n\tshallowRef,\n\ttoValue,\n\twatch\n} from 'vue'\nimport { userFacingErrorMessage } from './client.js'\nimport {\n\tcreateInvalidationCoordinator,\n\tcreateStreamScope,\n\tcreateSubscriptionRunner,\n\ttype InvalidationStreamOptions,\n\ttype LiveConnectionStatus,\n\tseedQueryFn\n} from './realtime.js'\n\nexport type { InvalidationDomain, LiveConnectionStatus } from './realtime.js'\n\n/**\n * Register your client types once so every composable infers them:\n *\n * ```ts\n * declare module 'orpc-fn/vue' {\n * interface Register { utils: typeof orpc; client: typeof client }\n * }\n * ```\n */\n// biome-ignore lint/suspicious/noEmptyInterface: filled in by app module augmentation\nexport interface Register {}\n\nexport type RegisteredOrpcUtils = Register extends { utils: infer T }\n\t? T\n\t: {\n\t\t\t'orpc-fn/vue: register your utils with `declare module \"orpc-fn/vue\" { interface Register { utils: typeof orpc } }`, or pass `orpc`': never\n\t\t}\nexport type RegisteredOrpcClient = Register extends { client: infer T }\n\t? T\n\t: unknown\n\n/** An explicit `<TData>`, else the data type oRPC tagged on the key. */\ntype CachedData<TData, TKey extends QueryKey> = [TData] extends [never]\n\t? InferDataFromTag<unknown, TKey>\n\t: TData\n\ntype ProvidedOrpc = { client: unknown; utils: unknown }\nconst orpcKey: InjectionKey<ProvidedOrpc> = Symbol('orpc-fn')\n\n/**\n * Make an oRPC client and its TanStack Query utils the app's default. A\n * surface that talks to another API (an embed with its own auth) passes\n * `orpc` to each composable instead and never needs this.\n */\nexport function provideOrpc<TClient, TUtils>(\n\tapp: App,\n\torpc: { client: TClient; utils: TUtils }\n): void {\n\tapp.provide(orpcKey, orpc)\n}\n\nconst missingOrpc = () =>\n\tnew Error(\n\t\t'orpc-fn/vue: no oRPC client provided. Call provideOrpc(app, { client, utils }) or pass `orpc` to the composable.'\n\t)\n\n/** The client and utils from {@link provideOrpc}. */\nexport function useOrpc(): {\n\tclient: RegisteredOrpcClient\n\tutils: RegisteredOrpcUtils\n} {\n\tconst provided = hasInjectionContext() ? inject(orpcKey, null) : null\n\tif (!provided) throw missingOrpc()\n\treturn provided as {\n\t\tclient: RegisteredOrpcClient\n\t\tutils: RegisteredOrpcUtils\n\t}\n}\n\n/** Resolve the provided utils now; fail only when they are needed and missing. */\nfunction useUtilsGetter<TOrpc>(\n\texplicit: MaybeRefOrGetter<TOrpc> | undefined\n): () => TOrpc {\n\tif (explicit) return () => toValue(explicit)\n\tconst provided = hasInjectionContext() ? inject(orpcKey, null) : null\n\treturn () => {\n\t\tif (!provided) throw missingOrpc()\n\t\treturn provided.utils as TOrpc\n\t}\n}\n\nlet documentVisible: Ref<boolean> | null = null\n/**\n * Whether the page is visible, from TanStack's `focusManager` (which follows\n * `visibilitychange` in browsers). Live streams pause while it is false.\n */\nfunction useDocumentVisible(): Ref<boolean> {\n\tif (!documentVisible) {\n\t\tconst visible = ref(focusManager.isFocused())\n\t\tfocusManager.subscribe((focused) => {\n\t\t\tvisible.value = focused\n\t\t})\n\t\tdocumentVisible = visible\n\t}\n\treturn documentVisible\n}\n\nfunction resolveQueryEnabled(enabled: unknown): boolean {\n\tif (enabled === undefined) return true\n\tif (typeof enabled === 'function') return Boolean(enabled())\n\treturn Boolean(toValue(enabled))\n}\n\n/**\n * Picks the stream to open from the utils. A procedure's `call` fits as is:\n * `(o) => o.order.watch.call`. The composable passes the input and an abort signal.\n */\nexport type OrpcSubscribeFn<TInput, TEvent, TOrpc = RegisteredOrpcUtils> = (\n\torpc: TOrpc\n) => (\n\tinput: TInput,\n\toptions: { signal: AbortSignal }\n) => Promise<AsyncIterable<TEvent>>\n\nexport interface UseSubscriptionOptions<TEvent, TOrpc = RegisteredOrpcUtils> {\n\t/** Start the stream on its own (default: true). With false, call `connect()`. */\n\timmediate?: MaybeRefOrGetter<boolean> | undefined\n\tonEvent?: (event: TEvent, meta?: { connectionId: number }) => void\n\tonError?: ((error: Error) => void) | undefined\n\t/** Every successful connect; `connectionId > 1` is a reconnect. */\n\tonConnect?: (connectionId: number) => void\n\tonClose?: () => void\n\t/** Events kept in `events` (default: 100). 1 keeps only `latestEvent`. */\n\tmaxEvents?: number\n\t/** Reconnect when the input changes (default: true). */\n\tautoReconnectOnInputChange?: boolean\n\t/**\n\t * After a connect, reconnect with backoff when the stream ends or errors\n\t * unexpectedly (proxy idle timeout, network blip). Deliberate teardown\n\t * does not retry. Default: true.\n\t */\n\tautoReconnectOnClose?: boolean\n\torpc?: MaybeRefOrGetter<TOrpc> | undefined\n\t/**\n\t * Close the stream while the page is hidden (default: true), so a\n\t * background tab holds no server connection. It reconnects, and a live\n\t * route re-sends its snapshot, when the page is visible again.\n\t */\n\trespectVisibility?: boolean | undefined\n}\n\nexport interface UseSubscriptionReturn<TEvent> {\n\tevents: Ref<TEvent[]>\n\tlatestEvent: Ref<TEvent | undefined>\n\tstatus: Ref<LiveConnectionStatus>\n\terror: Ref<Error | null>\n\tisConnected: Ref<boolean>\n\tconnect: () => Promise<void>\n\tdisconnect: () => Promise<void>\n\tclearEvents: () => void\n}\n\n/**\n * An oRPC event iterator as reactive state, with backoff reconnects and a\n * pause while the page is hidden. Closed when the owning effect scope stops.\n */\nexport function useOrpcSubscription<\n\tTInput,\n\tTEvent,\n\tTOrpc = RegisteredOrpcUtils\n>(\n\tinput: MaybeRefOrGetter<TInput>,\n\tsubscribeFn: OrpcSubscribeFn<TInput, TEvent, TOrpc>,\n\toptions: UseSubscriptionOptions<TEvent, TOrpc> = {}\n): UseSubscriptionReturn<TEvent> {\n\tconst {\n\t\timmediate = true,\n\t\tmaxEvents = 100,\n\t\tautoReconnectOnInputChange = true,\n\t\tautoReconnectOnClose = true,\n\t\trespectVisibility = true\n\t} = options\n\tconst getUtils = useUtilsGetter(options.orpc)\n\tconst visible = useDocumentVisible()\n\n\t// May a stream run at all? This gates a manual connect() too.\n\tconst isStreamAllowed = computed(() => !respectVisibility || visible.value)\n\t// Should it start on its own? That is what `immediate` means.\n\tconst shouldAutoConnect = computed(\n\t\t() => toValue(immediate) && isStreamAllowed.value\n\t)\n\n\t// Shallow: event payloads are replaced, never mutated, so deep proxies are wasted work.\n\tconst events = shallowRef<TEvent[]>([])\n\tconst latestEvent = shallowRef<TEvent | undefined>(undefined)\n\tconst status = ref<LiveConnectionStatus>('idle')\n\tconst error = ref<Error | null>(null)\n\n\tconst runner = createSubscriptionRunner<TEvent>({\n\t\topen: (signal) => subscribeFn(getUtils())(toValue(input), { signal }),\n\t\tcanConnect: () => isStreamAllowed.value,\n\t\tshouldReconnect: () => autoReconnectOnClose && shouldAutoConnect.value,\n\t\tonStatus: (next) => {\n\t\t\tstatus.value = next\n\t\t\tif (next === 'connecting') error.value = null\n\t\t},\n\t\tonEvent: (event, connectionId) => {\n\t\t\tlatestEvent.value = event\n\t\t\tif (maxEvents > 1) {\n\t\t\t\tevents.value = [...events.value.slice(-(maxEvents - 1)), event]\n\t\t\t}\n\t\t\toptions.onEvent?.(event, { connectionId })\n\t\t},\n\t\tonError: (err) => {\n\t\t\terror.value = err\n\t\t\toptions.onError?.(err)\n\t\t},\n\t\tonConnect: options.onConnect,\n\t\tonClose: options.onClose\n\t})\n\n\tfunction clearEvents() {\n\t\tevents.value = []\n\t\tlatestEvent.value = undefined\n\t}\n\n\tif (autoReconnectOnInputChange) {\n\t\twatch(\n\t\t\t() => toValue(input),\n\t\t\tasync () => {\n\t\t\t\tconst wasLive = runner.isLive()\n\t\t\t\tif (runner.getStatus() !== 'idle') {\n\t\t\t\t\tawait runner.disconnect()\n\t\t\t\t\tclearEvents()\n\t\t\t\t}\n\t\t\t\t// Reconnect in auto mode, or in manual mode when it was running.\n\t\t\t\tif (shouldAutoConnect.value || (wasLive && isStreamAllowed.value)) {\n\t\t\t\t\tawait runner.start()\n\t\t\t\t}\n\t\t\t},\n\t\t\t{ deep: true }\n\t\t)\n\t}\n\n\t// Visibility closes the stream in both modes; only the re-open waits for `immediate`.\n\twatch(\n\t\tisStreamAllowed,\n\t\t(allowed) => {\n\t\t\tif (!allowed) void runner.disconnect()\n\t\t\telse if (toValue(immediate)) {\n\t\t\t\terror.value = null\n\t\t\t\tvoid runner.start()\n\t\t\t}\n\t\t},\n\t\t{ immediate: true }\n\t)\n\n\twatch(\n\t\t() => toValue(immediate),\n\t\t(auto) => {\n\t\t\tif (!auto) void runner.disconnect()\n\t\t\telse if (isStreamAllowed.value) {\n\t\t\t\terror.value = null\n\t\t\t\tvoid runner.start()\n\t\t\t}\n\t\t}\n\t)\n\n\t// A detached effect scope may own the stream, not just a component.\n\tif (getCurrentScope()) onScopeDispose(() => void runner.dispose())\n\n\treturn {\n\t\tevents,\n\t\tlatestEvent,\n\t\tstatus,\n\t\terror,\n\t\tisConnected: computed(() => status.value === 'connected'),\n\t\tconnect: runner.connect,\n\t\tdisconnect: runner.disconnect,\n\t\tclearEvents\n\t}\n}\n\n/**\n * TanStack Query composables that receive the oRPC utils, so call sites read\n * `useQuery((o) => o.order.get.queryOptions({ input }))`. Pass `orpc` to bind\n * another client than the provided one.\n */\nexport function useApiClient<TOrpc = RegisteredOrpcUtils>(clientOptions?: {\n\torpc?: MaybeRefOrGetter<TOrpc> | undefined\n}) {\n\tconst queryClient = useQueryClient()\n\tconst getO = useUtilsGetter(clientOptions?.orpc)\n\n\t// Each wrapper forwards TanStack's own generics, so `select`, typed errors,\n\t// page params and oRPC's tagged keys infer exactly as with vue-query itself.\n\tfunction useQuery<\n\t\tTQueryFnData,\n\t\tTError = DefaultError,\n\t\tTData = TQueryFnData,\n\t\tTQueryKey extends QueryKey = QueryKey\n\t>(\n\t\toptionsFn: (\n\t\t\torpc: TOrpc\n\t\t) => UseQueryOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey>\n\t): UseQueryReturnType<TData, TError> {\n\t\t// A computed is a ref at runtime; TypeScript cannot relate a computed of\n\t\t// the generic options to vue-query's MaybeRef parameter, so it is asserted.\n\t\tconst options = computed(() => optionsFn(getO()))\n\t\treturn useVueQuery<TQueryFnData, TError, TData, TQueryKey>(\n\t\t\toptions as unknown as UseQueryOptions<\n\t\t\t\tTQueryFnData,\n\t\t\t\tTError,\n\t\t\t\tTData,\n\t\t\t\tTQueryFnData,\n\t\t\t\tTQueryKey\n\t\t\t>\n\t\t)\n\t}\n\n\t/** `useInfiniteQuery((o) => o.order.list.infiniteOptions({ input, initialPageParam, getNextPageParam }))` */\n\tfunction useInfiniteQuery<\n\t\tTQueryFnData,\n\t\tTError = DefaultError,\n\t\tTData = InfiniteData<TQueryFnData>,\n\t\tTQueryKey extends QueryKey = QueryKey,\n\t\tTPageParam = unknown\n\t>(\n\t\toptionsFn: (\n\t\t\torpc: TOrpc\n\t\t) => UseInfiniteQueryOptions<\n\t\t\tTQueryFnData,\n\t\t\tTError,\n\t\t\tTData,\n\t\t\tTQueryKey,\n\t\t\tTPageParam\n\t\t>\n\t): UseInfiniteQueryReturnType<TData, TError> {\n\t\tconst options = computed(() => optionsFn(getO()))\n\t\treturn useVueInfiniteQuery<\n\t\t\tTQueryFnData,\n\t\t\tTError,\n\t\t\tTData,\n\t\t\tTQueryKey,\n\t\t\tTPageParam\n\t\t>(\n\t\t\toptions as unknown as UseInfiniteQueryOptions<\n\t\t\t\tTQueryFnData,\n\t\t\t\tTError,\n\t\t\t\tTData,\n\t\t\t\tTQueryKey,\n\t\t\t\tTPageParam\n\t\t\t>\n\t\t)\n\t}\n\n\t/**\n\t * With `initialInput`, also returns `inputData`, a ref that `mutate()` and\n\t * `mutateAsync()` use when called without variables (form state).\n\t */\n\tfunction useMutation<\n\t\tTData = unknown,\n\t\tTError = DefaultError,\n\t\tTVariables = void,\n\t\tTContext = unknown\n\t>(\n\t\toptionsFn: (\n\t\t\torpc: TOrpc\n\t\t) => MutationObserverOptions<TData, TError, TVariables, TContext>,\n\t\tconfig: { initialInput: TVariables }\n\t): UseMutationReturnType<TData, TError, TVariables, TContext> & {\n\t\tinputData: Ref<TVariables>\n\t\tmutate: (variables?: TVariables) => void\n\t\tmutateAsync: (variables?: TVariables) => Promise<TData>\n\t}\n\tfunction useMutation<\n\t\tTData = unknown,\n\t\tTError = DefaultError,\n\t\tTVariables = void,\n\t\tTContext = unknown\n\t>(\n\t\toptionsFn: (\n\t\t\torpc: TOrpc\n\t\t) => MutationObserverOptions<TData, TError, TVariables, TContext>\n\t): UseMutationReturnType<TData, TError, TVariables, TContext>\n\tfunction useMutation<TData, TError, TVariables, TContext>(\n\t\toptionsFn: (\n\t\t\torpc: TOrpc\n\t\t) => MutationObserverOptions<TData, TError, TVariables, TContext>,\n\t\tconfig?: { initialInput: TVariables }\n\t) {\n\t\tconst mutation = useVueMutation(computed(() => optionsFn(getO())))\n\t\tif (config?.initialInput === undefined) return mutation\n\t\tconst inputData = ref(config.initialInput) as Ref<TVariables>\n\t\treturn {\n\t\t\t...mutation,\n\t\t\tinputData,\n\t\t\tmutate: (variables?: TVariables) =>\n\t\t\t\tmutation.mutate(variables ?? inputData.value),\n\t\t\tmutateAsync: (variables?: TVariables) =>\n\t\t\t\tmutation.mutateAsync(variables ?? inputData.value)\n\t\t}\n\t}\n\n\tfunction useSubscription<TInput, TEvent>(\n\t\tinput: MaybeRefOrGetter<TInput>,\n\t\tsubscribeFn: OrpcSubscribeFn<TInput, TEvent, TOrpc>,\n\t\toptions: UseSubscriptionOptions<TEvent, TOrpc> = {}\n\t) {\n\t\treturn useOrpcSubscription<TInput, TEvent, TOrpc>(input, subscribeFn, {\n\t\t\t...options,\n\t\t\torpc: getO\n\t\t})\n\t}\n\n\tconst keyOf = <TKey extends QueryKey>(keyFn: (orpc: TOrpc) => TKey) =>\n\t\tkeyFn(getO())\n\n\treturn {\n\t\tuseQuery,\n\t\tuseInfiniteQuery,\n\t\tuseMutation,\n\t\tuseSubscription,\n\t\tinvalidate: (\n\t\t\tkeyFn: (orpc: TOrpc) => QueryKey,\n\t\t\tfilters?: Omit<InvalidateQueryFilters, 'queryKey'>\n\t\t) => queryClient.invalidateQueries({ queryKey: keyOf(keyFn), ...filters }),\n\t\t/** Route preloading and hover-to-prefetch. */\n\t\tprefetch: <\n\t\t\tTQueryFnData,\n\t\t\tTError = DefaultError,\n\t\t\tTData = TQueryFnData,\n\t\t\tTQueryKey extends QueryKey = QueryKey\n\t\t>(\n\t\t\toptionsFn: (\n\t\t\t\torpc: TOrpc\n\t\t\t) => FetchQueryOptions<TQueryFnData, TError, TData, TQueryKey>\n\t\t) => queryClient.prefetchQuery(optionsFn(getO())),\n\t\t/** Data is typed from oRPC's tagged key; pass `<TData>` for an untagged one. */\n\t\tgetQueryData: <TData = never, TKey extends QueryKey = QueryKey>(\n\t\t\tkeyFn: (orpc: TOrpc) => TKey\n\t\t): CachedData<TData, TKey> | undefined =>\n\t\t\tqueryClient.getQueryData<CachedData<TData, TKey>>(keyOf(keyFn)),\n\t\t/** Optimistic updates, typed like `getQueryData`. */\n\t\tsetQueryData: <TData = never, TKey extends QueryKey = QueryKey>(\n\t\t\tkeyFn: (orpc: TOrpc) => TKey,\n\t\t\tupdater: Updater<\n\t\t\t\tCachedData<TData, TKey> | undefined,\n\t\t\t\tCachedData<TData, TKey> | undefined\n\t\t\t>\n\t\t) =>\n\t\t\tqueryClient.setQueryData<CachedData<TData, TKey>>(keyOf(keyFn), updater),\n\t\tcancelQueries: (keyFn: (orpc: TOrpc) => QueryKey) =>\n\t\t\tqueryClient.cancelQueries({ queryKey: keyOf(keyFn) }),\n\t\tremoveQueries: (keyFn: (orpc: TOrpc) => QueryKey) =>\n\t\t\tqueryClient.removeQueries({ queryKey: keyOf(keyFn) }),\n\t\tisFetching: (keyFn?: (orpc: TOrpc) => QueryKey) =>\n\t\t\tqueryClient.isFetching(keyFn ? { queryKey: keyOf(keyFn) } : {}),\n\t\tqueryClient\n\t}\n}\n\ntype ApplyEvent<TStreamEvent, TData> = (\n\tevent: TStreamEvent,\n\tprevious: TData | undefined\n) => TData | undefined\n\ntype LiveQueryOptions<\n\tTInput,\n\tTRouteData,\n\tTStreamEvent,\n\tTData,\n\tTOrpc,\n\tTSubscriptionInput\n> = {\n\timmediate?: MaybeRefOrGetter<boolean>\n\torpc?: MaybeRefOrGetter<TOrpc>\n\t/** Input for the stream when it differs from the query's. */\n\tsubscriptionInput?: MaybeRefOrGetter<TSubscriptionInput>\n\t/**\n\t * Convert the route output once at fetch time into a differently typed\n\t * cache; `applyEvent` then reduces stream events into that cache.\n\t */\n\tselect?: (data: TRouteData) => TData\n\t/**\n\t * The raw route output of a seed before `select` drops fields. `input` is\n\t * what the seed was fetched for, so a seed that resolves after the input\n\t * moved on can be told apart.\n\t */\n\tonSeed?: (data: TRouteData, input: TInput) => void\n\t/**\n\t * Fold a stream event into the cached data. Required when the stream sends\n\t * something other than the cached type (an `fnLive` patch route, or a\n\t * `select`ed cache). Return `undefined` to skip the write.\n\t */\n\tapplyEvent?: ApplyEvent<TStreamEvent, NoInfer<TData>>\n\tonEvent?: (event: TStreamEvent, meta?: { connectionId: number }) => void\n\tonError?: (error: Error) => void\n\t/**\n\t * Reconcile a fetched seed with what the stream already wrote. The HTTP\n\t * request can resolve last, so a plain overwrite would drop events that\n\t * arrived while it was in flight. Default: take the fetched value.\n\t */\n\tmergeSeed?: (\n\t\tfetched: NoInfer<TData>,\n\t\tcached: NoInfer<TData> | undefined\n\t) => NoInfer<TData>\n\t/**\n\t * Show the previous key's data while a new key loads (default: true). Pass\n\t * false when the key says which entity is shown, not just how it is\n\t * filtered: another conversation's timeline must not stand in for this one.\n\t */\n\tkeepPreviousData?: boolean\n\t/** Pause the stream while the page is hidden (default: true). */\n\trespectVisibility?: boolean\n}\n\ntype LiveQueryReturn<TData, TError> = ReturnType<\n\ttypeof useVueQuery<TData, TError>\n> & { liveStatus: Ref<LiveConnectionStatus> }\n\n/**\n * The client half of `fnLive`: the HTTP query seeds the cache, and the live\n * route's stream writes each snapshot into the same cache entry. Marked\n * `meta.live`, so invalidation streams leave it alone.\n *\n * One signature, not overloads: TypeScript fixes an untyped callback's\n * parameters at the first overload it tries, which made valid calls fail.\n */\nexport function useLiveQuery<\n\tTInput,\n\tTRouteData,\n\tTStreamEvent,\n\tTData = TRouteData,\n\tTError = Error,\n\tTOrpc = RegisteredOrpcUtils,\n\tTSubscriptionInput = TInput\n>(\n\tinput: MaybeRefOrGetter<TInput>,\n\tqueryOptionsFn: (\n\t\tinput: TInput,\n\t\torpc: TOrpc\n\t) => UseQueryOptions<TRouteData, TError> & { queryKey: QueryKey },\n\tsubscribeFn: OrpcSubscribeFn<\n\t\tNoInfer<TSubscriptionInput>,\n\t\tTStreamEvent,\n\t\tTOrpc\n\t>,\n\t...options: [TStreamEvent] extends [TData]\n\t\t? [\n\t\t\t\toptions?: LiveQueryOptions<\n\t\t\t\t\tTInput,\n\t\t\t\t\tTRouteData,\n\t\t\t\t\tTStreamEvent,\n\t\t\t\t\tTData,\n\t\t\t\t\tTOrpc,\n\t\t\t\t\tTSubscriptionInput\n\t\t\t\t>\n\t\t\t]\n\t\t: [\n\t\t\t\toptions: LiveQueryOptions<\n\t\t\t\t\tTInput,\n\t\t\t\t\tTRouteData,\n\t\t\t\t\tTStreamEvent,\n\t\t\t\t\tTData,\n\t\t\t\t\tTOrpc,\n\t\t\t\t\tTSubscriptionInput\n\t\t\t\t> & { applyEvent: ApplyEvent<TStreamEvent, NoInfer<TData>> }\n\t\t\t]\n): LiveQueryReturn<TData, TError>\nexport function useLiveQuery<\n\tTInput,\n\tTRouteData,\n\tTStreamEvent,\n\tTData,\n\tTError,\n\tTOrpc,\n\tTSubscriptionInput\n>(\n\tinput: MaybeRefOrGetter<TInput>,\n\tqueryOptionsFn: (\n\t\tinput: TInput,\n\t\torpc: TOrpc\n\t) => UseQueryOptions<TRouteData, TError> & { queryKey: QueryKey },\n\tsubscribeFn: OrpcSubscribeFn<TSubscriptionInput, TStreamEvent, TOrpc>,\n\toptions: LiveQueryOptions<\n\t\tTInput,\n\t\tTRouteData,\n\t\tTStreamEvent,\n\t\tTData,\n\t\tTOrpc,\n\t\tTSubscriptionInput\n\t> = {}\n): LiveQueryReturn<TData, TError> {\n\tconst queryClient = useQueryClient()\n\tconst getO = useUtilsGetter(options.orpc)\n\tconst visible = useDocumentVisible()\n\t// Without `applyEvent` the stream event is the cache type (the first overload).\n\tconst applyEvent =\n\t\toptions.applyEvent ?? ((event: TStreamEvent) => event as unknown as TData)\n\t// Recomputed when the input changes, not once per stream event.\n\tconst queryKey = computed(\n\t\t() => queryOptionsFn(toValue(input), getO()).queryKey\n\t)\n\tconst queryHash = computed(() => hashKey(queryKey.value))\n\tconst scope = createStreamScope()\n\n\tconst subscription = useOrpcSubscription(\n\t\tcomputed(\n\t\t\t() =>\n\t\t\t\t(options.subscriptionInput === undefined\n\t\t\t\t\t? toValue(input)\n\t\t\t\t\t: toValue(options.subscriptionInput)) as TSubscriptionInput\n\t\t),\n\t\tsubscribeFn,\n\t\t{\n\t\t\timmediate: options.immediate,\n\t\t\trespectVisibility: options.respectVisibility,\n\t\t\tonError: options.onError,\n\t\t\tmaxEvents: 1,\n\t\t\torpc: getO,\n\t\t\tonConnect: (connectionId) => scope.open(connectionId, queryHash.value),\n\t\t\tonEvent: (event, meta) => {\n\t\t\t\t// The consumer callback must not see an event for a scope no longer shown.\n\t\t\t\tif (!meta || !scope.owns(meta.connectionId, queryHash.value)) return\n\t\t\t\tconst key = queryKey.value\n\t\t\t\tconst next = applyEvent(event, queryClient.getQueryData<TData>(key))\n\t\t\t\tif (next !== undefined) queryClient.setQueryData(key, next)\n\t\t\t\toptions.onEvent?.(event, meta)\n\t\t\t}\n\t\t}\n\t)\n\n\tconst query = useVueQuery<TData, TError>(\n\t\tcomputed(() => {\n\t\t\tconst inputValue = toValue(input)\n\t\t\t// oRPC query options are plain objects at runtime; vue-query's type\n\t\t\t// wraps fields in MaybeRefDeep, so `queryFn` is read through one shape.\n\t\t\tconst raw = queryOptionsFn(inputValue, getO()) as unknown as {\n\t\t\t\tqueryKey: QueryKey\n\t\t\t\tqueryFn?: (context: unknown) => Promise<TRouteData>\n\t\t\t\tenabled?: unknown\n\t\t\t} & Record<string, unknown>\n\t\t\tconst wrapsSeed = options.select || options.mergeSeed\n\t\t\tconst queryFn =\n\t\t\t\traw.queryFn && wrapsSeed\n\t\t\t\t\t? seedQueryFn(raw.queryFn, {\n\t\t\t\t\t\t\tinput: inputValue,\n\t\t\t\t\t\t\treadCache: () => queryClient.getQueryData<TData>(raw.queryKey),\n\t\t\t\t\t\t\tselect: options.select,\n\t\t\t\t\t\t\tonSeed: options.onSeed,\n\t\t\t\t\t\t\tmergeSeed: options.mergeSeed\n\t\t\t\t\t\t})\n\t\t\t\t\t: raw.queryFn\n\t\t\treturn {\n\t\t\t\t...raw,\n\t\t\t\t...(queryFn ? { queryFn } : {}),\n\t\t\t\tenabled: visible.value && resolveQueryEnabled(raw.enabled),\n\t\t\t\t...(options.keepPreviousData === false\n\t\t\t\t\t? {}\n\t\t\t\t\t: { placeholderData: keepPreviousData }),\n\t\t\t\tstaleTime: Number.POSITIVE_INFINITY,\n\t\t\t\tmeta: { live: true }\n\t\t\t} as unknown as UseQueryOptions<TData, TError>\n\t\t})\n\t)\n\n\treturn Object.assign(query, { liveStatus: subscription.status })\n}\n\n/**\n * Treat a stream as a \"something changed\" ping: invalidate `keyFn` on each\n * event. Prefer {@link useLiveQuery} when the stream carries the data itself.\n */\nexport function useSubscriptionInvalidates<\n\tTInput,\n\tTEvent,\n\tTOrpc = RegisteredOrpcUtils\n>(\n\tinput: MaybeRefOrGetter<TInput>,\n\tsubscribeFn: OrpcSubscribeFn<TInput, TEvent, TOrpc>,\n\tkeyFn: (orpc: TOrpc) => QueryKey,\n\toptions: Pick<\n\t\tUseSubscriptionOptions<TEvent, TOrpc>,\n\t\t'immediate' | 'maxEvents' | 'respectVisibility' | 'orpc'\n\t> & {\n\t\tonEvent?: (event: TEvent) => void\n\t\t/** Return false to skip invalidation for this event. */\n\t\tshouldInvalidate?: (event: TEvent) => boolean\n\t} = {}\n): UseSubscriptionReturn<TEvent> {\n\tconst { onEvent, shouldInvalidate, ...subscriptionOptions } = options\n\tconst { useSubscription, invalidate } = useApiClient<TOrpc>({\n\t\torpc: options.orpc\n\t})\n\treturn useSubscription(input, subscribeFn, {\n\t\t...subscriptionOptions,\n\t\tonEvent: (event) => {\n\t\t\tonEvent?.(event)\n\t\t\tif (shouldInvalidate?.(event) === false) return\n\t\t\tvoid invalidate(keyFn)\n\t\t}\n\t})\n}\n\n/**\n * One app-wide stream of `{ domain }` change events that keeps list and count\n * queries fresh: each event invalidates its domain's query keys (debounced),\n * and a reconnect that proves healthy invalidates every domain to cover\n * events lost while it was down. Call once, in the signed-in shell.\n *\n * ```ts\n * useInvalidationStream({}, (o) => o.realtime.subscribeChanges.call, {\n * domains: { order: { debounceMs: 100, queryKeys: [orpc.order.key()] } }\n * })\n * ```\n */\nexport function useInvalidationStream<\n\tTInput,\n\tTEvent extends { domain: string },\n\tTOrpc = RegisteredOrpcUtils\n>(\n\tinput: MaybeRefOrGetter<TInput>,\n\tsubscribe: OrpcSubscribeFn<TInput, TEvent, TOrpc>,\n\toptions: InvalidationStreamOptions<TEvent> &\n\t\tPick<\n\t\t\tUseSubscriptionOptions<TEvent, TOrpc>,\n\t\t\t'immediate' | 'respectVisibility' | 'orpc'\n\t\t>\n): UseSubscriptionReturn<TEvent> {\n\tconst coordinator = createInvalidationCoordinator(useQueryClient(), options)\n\tif (getCurrentScope()) onScopeDispose(coordinator.dispose)\n\treturn useOrpcSubscription<TInput, TEvent, TOrpc>(input, subscribe, {\n\t\timmediate: options.immediate,\n\t\trespectVisibility: options.respectVisibility,\n\t\torpc: options.orpc,\n\t\tmaxEvents: 1,\n\t\tonEvent: coordinator.event,\n\t\tonConnect: coordinator.connect,\n\t\tonError: coordinator.lost,\n\t\tonClose: coordinator.lost\n\t})\n}\n\n/** Localized text for a failed query: your fallback unless the server marked its message user-safe. */\nexport function useQueryErrorMessage(\n\terror: MaybeRefOrGetter<unknown>,\n\tfallback: MaybeRefOrGetter<string>\n) {\n\treturn computed(() => {\n\t\tconst err = toValue(error)\n\t\treturn err ? userFacingErrorMessage(err, toValue(fallback)) : null\n\t})\n}\n"]}
|
|
1
|
+
{"version":3,"file":"vue.js","sourceRoot":"","sources":["../src/vue.ts"],"names":[],"mappings":"AAAA,OAAO,EAGN,YAAY,EACZ,OAAO,EAUP,gBAAgB,EAGhB,gBAAgB,IAAI,mBAAmB,EACvC,WAAW,IAAI,cAAc,EAC7B,QAAQ,IAAI,WAAW,EACvB,cAAc,EACd,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAEN,QAAQ,EACR,eAAe,EACf,mBAAmB,EAEnB,MAAM,EAEN,cAAc,EAEd,GAAG,EACH,UAAU,EACV,OAAO,EACP,KAAK,EACL,MAAM,KAAK,CAAA;AACZ,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AACpD,OAAO,EACN,6BAA6B,EAC7B,iBAAiB,EACjB,wBAAwB,EAGxB,WAAW,EACX,MAAM,eAAe,CAAA;AA+BtB,MAAM,OAAO,GAA+B,MAAM,CAAC,SAA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esContent":["import {\n\ttype DefaultError,\n\ttype FetchQueryOptions,\n\tfocusManager,\n\thashKey,\n\ttype InferDataFromTag,\n\ttype InfiniteData,\n\ttype InvalidateQueryFilters,\n\ttype MutationObserverOptions,\n\ttype UseInfiniteQueryOptions,\n\ttype UseInfiniteQueryReturnType,\n\ttype UseMutationReturnType,\n\ttype UseQueryReturnType,\n\ttype Updater,\n\tkeepPreviousData,\n\ttype QueryKey,\n\ttype UseQueryOptions,\n\tuseInfiniteQuery as useVueInfiniteQuery,\n\tuseMutation as useVueMutation,\n\tuseQuery as useVueQuery,\n\tuseQueryClient\n} from '@tanstack/vue-query'\nimport {\n\ttype App,\n\tcomputed,\n\tgetCurrentScope,\n\thasInjectionContext,\n\ttype InjectionKey,\n\tinject,\n\ttype MaybeRefOrGetter,\n\tonScopeDispose,\n\ttype Ref,\n\tref,\n\tshallowRef,\n\ttoValue,\n\twatch\n} from 'vue'\nimport { userFacingErrorMessage } from './client.js'\nimport {\n\tcreateInvalidationCoordinator,\n\tcreateStreamScope,\n\tcreateSubscriptionRunner,\n\ttype InvalidationStreamOptions,\n\ttype LiveConnectionStatus,\n\tseedQueryFn\n} from './realtime.js'\n\nexport type { InvalidationDomain, LiveConnectionStatus } from './realtime.js'\n\n/**\n * Register your client types once so every composable infers them:\n *\n * ```ts\n * declare module 'orpc-fn/vue' {\n * interface Register { utils: typeof orpc; client: typeof client }\n * }\n * ```\n */\n// biome-ignore lint/suspicious/noEmptyInterface: filled in by app module augmentation\nexport interface Register {}\n\nexport type RegisteredOrpcUtils = Register extends { utils: infer T }\n\t? T\n\t: {\n\t\t\t'orpc-fn/vue: register your utils with `declare module \"orpc-fn/vue\" { interface Register { utils: typeof orpc } }`, or pass `orpc`': never\n\t\t}\nexport type RegisteredOrpcClient = Register extends { client: infer T }\n\t? T\n\t: unknown\n\n/** An explicit `<TData>`, else the data type oRPC tagged on the key. */\ntype CachedData<TData, TKey extends QueryKey> = [TData] extends [never]\n\t? InferDataFromTag<unknown, TKey>\n\t: TData\n\ntype ProvidedOrpc = { client: unknown; utils: unknown }\nconst orpcKey: InjectionKey<ProvidedOrpc> = Symbol('orpc-fn')\n\n/**\n * Make an oRPC client and its TanStack Query utils the app's default. A\n * surface that talks to another API (an embed with its own auth) passes\n * `orpc` to each composable instead and never needs this.\n */\nexport function provideOrpc<TClient, TUtils>(\n\tapp: App,\n\torpc: { client: TClient; utils: TUtils }\n): void {\n\tapp.provide(orpcKey, orpc)\n}\n\nconst missingOrpc = () =>\n\tnew Error(\n\t\t'orpc-fn/vue: no oRPC client provided. Call provideOrpc(app, { client, utils }) or pass `orpc` to the composable.'\n\t)\n\n/** The client and utils from {@link provideOrpc}. */\nexport function useOrpc(): {\n\tclient: RegisteredOrpcClient\n\tutils: RegisteredOrpcUtils\n} {\n\tconst provided = hasInjectionContext() ? inject(orpcKey, null) : null\n\tif (!provided) throw missingOrpc()\n\treturn provided as {\n\t\tclient: RegisteredOrpcClient\n\t\tutils: RegisteredOrpcUtils\n\t}\n}\n\n/** Resolve the provided utils now; fail only when they are needed and missing. */\nfunction useUtilsGetter<TOrpc>(\n\texplicit: MaybeRefOrGetter<TOrpc> | undefined\n): () => TOrpc {\n\tif (explicit) return () => toValue(explicit)\n\tconst provided = hasInjectionContext() ? inject(orpcKey, null) : null\n\treturn () => {\n\t\tif (!provided) throw missingOrpc()\n\t\treturn provided.utils as TOrpc\n\t}\n}\n\nlet documentVisible: Ref<boolean> | null = null\n/**\n * Whether the page is visible, from TanStack's `focusManager` (which follows\n * `visibilitychange` in browsers). Live streams pause while it is false.\n */\nfunction useDocumentVisible(): Ref<boolean> {\n\tif (!documentVisible) {\n\t\tconst visible = ref(focusManager.isFocused())\n\t\tfocusManager.subscribe((focused) => {\n\t\t\tvisible.value = focused\n\t\t})\n\t\tdocumentVisible = visible\n\t}\n\treturn documentVisible\n}\n\nfunction resolveQueryEnabled(enabled: unknown): boolean {\n\tif (enabled === undefined) return true\n\tif (typeof enabled === 'function') return Boolean(enabled())\n\treturn Boolean(toValue(enabled))\n}\n\n/**\n * Picks the stream to open from the utils. A procedure's `call` fits as is:\n * `(o) => o.order.watch.call`. The composable passes the input and an abort signal.\n */\nexport type OrpcSubscribeFn<TInput, TEvent, TOrpc = RegisteredOrpcUtils> = (\n\torpc: TOrpc\n) => (\n\tinput: TInput,\n\toptions: { signal: AbortSignal }\n) => Promise<AsyncIterable<TEvent>>\n\nexport interface UseSubscriptionOptions<TEvent, TOrpc = RegisteredOrpcUtils> {\n\t/** Start the stream on its own (default: true). With false, call `connect()`. */\n\timmediate?: MaybeRefOrGetter<boolean> | undefined\n\tonEvent?: (event: TEvent, meta?: { connectionId: number }) => void\n\tonError?: ((error: Error) => void) | undefined\n\t/** Every successful connect; `connectionId > 1` is a reconnect. */\n\tonConnect?: (connectionId: number) => void\n\tonClose?: () => void\n\t/** Events kept in `events` (default: 100). 1 keeps only `latestEvent`. */\n\tmaxEvents?: number\n\t/** Reconnect when the input changes (default: true). */\n\tautoReconnectOnInputChange?: boolean\n\t/**\n\t * After a connect, reconnect with backoff when the stream ends or errors\n\t * unexpectedly (proxy idle timeout, network blip). Deliberate teardown\n\t * does not retry. Default: true.\n\t */\n\tautoReconnectOnClose?: boolean\n\torpc?: MaybeRefOrGetter<TOrpc> | undefined\n\t/**\n\t * Close the stream while the page is hidden (default: true), so a\n\t * background tab holds no server connection. It reconnects, and a live\n\t * route re-sends its snapshot, when the page is visible again.\n\t */\n\trespectVisibility?: boolean | undefined\n}\n\nexport interface UseSubscriptionReturn<TEvent> {\n\tevents: Ref<TEvent[]>\n\tlatestEvent: Ref<TEvent | undefined>\n\tstatus: Ref<LiveConnectionStatus>\n\terror: Ref<Error | null>\n\tisConnected: Ref<boolean>\n\tconnect: () => Promise<void>\n\tdisconnect: () => Promise<void>\n\tclearEvents: () => void\n}\n\n/**\n * An oRPC event iterator as reactive state, with backoff reconnects and a\n * pause while the page is hidden. Closed when the owning effect scope stops.\n */\nexport function useOrpcSubscription<\n\tTInput,\n\tTEvent,\n\tTOrpc = RegisteredOrpcUtils\n>(\n\tinput: MaybeRefOrGetter<TInput>,\n\tsubscribeFn: OrpcSubscribeFn<TInput, TEvent, TOrpc>,\n\toptions: UseSubscriptionOptions<TEvent, TOrpc> = {}\n): UseSubscriptionReturn<TEvent> {\n\tconst {\n\t\timmediate = true,\n\t\tmaxEvents = 100,\n\t\tautoReconnectOnInputChange = true,\n\t\tautoReconnectOnClose = true,\n\t\trespectVisibility = true\n\t} = options\n\tconst getUtils = useUtilsGetter(options.orpc)\n\tconst visible = useDocumentVisible()\n\n\t// May a stream run at all? This gates a manual connect() too.\n\tconst isStreamAllowed = computed(() => !respectVisibility || visible.value)\n\t// Should it start on its own? That is what `immediate` means.\n\tconst shouldAutoConnect = computed(\n\t\t() => toValue(immediate) && isStreamAllowed.value\n\t)\n\n\t// Shallow: event payloads are replaced, never mutated, so deep proxies are wasted work.\n\tconst events = shallowRef<TEvent[]>([])\n\tconst latestEvent = shallowRef<TEvent | undefined>(undefined)\n\tconst status = ref<LiveConnectionStatus>('idle')\n\tconst error = ref<Error | null>(null)\n\n\tconst runner = createSubscriptionRunner<TEvent>({\n\t\topen: (signal) => subscribeFn(getUtils())(toValue(input), { signal }),\n\t\tcanConnect: () => isStreamAllowed.value,\n\t\tshouldReconnect: () => autoReconnectOnClose && shouldAutoConnect.value,\n\t\tonStatus: (next) => {\n\t\t\tstatus.value = next\n\t\t\tif (next === 'connecting') error.value = null\n\t\t},\n\t\tonEvent: (event, connectionId) => {\n\t\t\tlatestEvent.value = event\n\t\t\tif (maxEvents > 1) {\n\t\t\t\tevents.value = [...events.value.slice(-(maxEvents - 1)), event]\n\t\t\t}\n\t\t\toptions.onEvent?.(event, { connectionId })\n\t\t},\n\t\tonError: (err) => {\n\t\t\terror.value = err\n\t\t\toptions.onError?.(err)\n\t\t},\n\t\tonConnect: options.onConnect,\n\t\tonClose: options.onClose\n\t})\n\n\tfunction clearEvents() {\n\t\tevents.value = []\n\t\tlatestEvent.value = undefined\n\t}\n\n\tif (autoReconnectOnInputChange) {\n\t\twatch(\n\t\t\t() => toValue(input),\n\t\t\tasync () => {\n\t\t\t\tconst wasLive = runner.isLive()\n\t\t\t\tif (runner.getStatus() !== 'idle') {\n\t\t\t\t\tawait runner.disconnect()\n\t\t\t\t\tclearEvents()\n\t\t\t\t}\n\t\t\t\t// Reconnect in auto mode, or in manual mode when it was running.\n\t\t\t\tif (shouldAutoConnect.value || (wasLive && isStreamAllowed.value)) {\n\t\t\t\t\tawait runner.start()\n\t\t\t\t}\n\t\t\t},\n\t\t\t{ deep: true }\n\t\t)\n\t}\n\n\t// Visibility closes the stream in both modes; only the re-open waits for `immediate`.\n\twatch(\n\t\tisStreamAllowed,\n\t\t(allowed) => {\n\t\t\tif (!allowed) void runner.disconnect()\n\t\t\telse if (toValue(immediate)) {\n\t\t\t\terror.value = null\n\t\t\t\tvoid runner.start()\n\t\t\t}\n\t\t},\n\t\t{ immediate: true }\n\t)\n\n\twatch(\n\t\t() => toValue(immediate),\n\t\t(auto) => {\n\t\t\tif (!auto) void runner.disconnect()\n\t\t\telse if (isStreamAllowed.value) {\n\t\t\t\terror.value = null\n\t\t\t\tvoid runner.start()\n\t\t\t}\n\t\t}\n\t)\n\n\t// A detached effect scope may own the stream, not just a component.\n\tif (getCurrentScope()) onScopeDispose(() => void runner.dispose())\n\n\treturn {\n\t\tevents,\n\t\tlatestEvent,\n\t\tstatus,\n\t\terror,\n\t\tisConnected: computed(() => status.value === 'connected'),\n\t\tconnect: runner.connect,\n\t\tdisconnect: runner.disconnect,\n\t\tclearEvents\n\t}\n}\n\n/** What {@link useApiClient} returns, e.g. `ApiClient['invalidate']` for a helper. */\nexport type ApiClient<TOrpc = RegisteredOrpcUtils> = ReturnType<\n\ttypeof useBoundApiClient<TOrpc>\n>\n\n/**\n * TanStack Query composables that receive the oRPC utils, so call sites read\n * `useQuery((o) => o.order.get.queryOptions({ input }))`. Pass `orpc` to bind\n * another client than the provided one.\n */\nexport function useApiClient<TOrpc = RegisteredOrpcUtils>(clientOptions?: {\n\torpc?: MaybeRefOrGetter<TOrpc> | undefined\n}): ApiClient<TOrpc>\n// `ReturnType<typeof useApiClient>` reads the last overload: the registered utils.\nexport function useApiClient(): ApiClient\nexport function useApiClient<TOrpc>(clientOptions?: {\n\torpc?: MaybeRefOrGetter<TOrpc> | undefined\n}): ApiClient<TOrpc> {\n\treturn useBoundApiClient(clientOptions?.orpc)\n}\n\nfunction useBoundApiClient<TOrpc>(orpc: MaybeRefOrGetter<TOrpc> | undefined) {\n\tconst queryClient = useQueryClient()\n\tconst getO = useUtilsGetter(orpc)\n\n\t// Each wrapper forwards TanStack's own generics, so `select`, typed errors,\n\t// page params and oRPC's tagged keys infer exactly as with vue-query itself.\n\tfunction useQuery<TQueryFnData, TError = DefaultError, TData = TQueryFnData>(\n\t\toptionsFn: (\n\t\t\torpc: TOrpc\n\t\t) => UseQueryOptions<TQueryFnData, TError, TData, TQueryFnData>\n\t): UseQueryReturnType<TData, TError> {\n\t\t// A computed is a ref at runtime; TypeScript cannot relate a computed of\n\t\t// the generic options to vue-query's MaybeRef parameter, so it is asserted.\n\t\tconst options = computed(() => optionsFn(getO()))\n\t\treturn useVueQuery<TQueryFnData, TError, TData>(\n\t\t\toptions as unknown as UseQueryOptions<\n\t\t\t\tTQueryFnData,\n\t\t\t\tTError,\n\t\t\t\tTData,\n\t\t\t\tTQueryFnData\n\t\t\t>\n\t\t)\n\t}\n\n\t/** `useInfiniteQuery((o) => o.order.list.infiniteOptions({ input, initialPageParam, getNextPageParam }))` */\n\tfunction useInfiniteQuery<\n\t\tTQueryFnData,\n\t\tTError = DefaultError,\n\t\tTData = InfiniteData<TQueryFnData>,\n\t\tTQueryKey extends QueryKey = QueryKey,\n\t\tTPageParam = unknown\n\t>(\n\t\toptionsFn: (\n\t\t\torpc: TOrpc\n\t\t) => UseInfiniteQueryOptions<\n\t\t\tTQueryFnData,\n\t\t\tTError,\n\t\t\tTData,\n\t\t\tTQueryKey,\n\t\t\tTPageParam\n\t\t>\n\t): UseInfiniteQueryReturnType<TData, TError> {\n\t\tconst options = computed(() => optionsFn(getO()))\n\t\treturn useVueInfiniteQuery<\n\t\t\tTQueryFnData,\n\t\t\tTError,\n\t\t\tTData,\n\t\t\tTQueryKey,\n\t\t\tTPageParam\n\t\t>(\n\t\t\toptions as unknown as UseInfiniteQueryOptions<\n\t\t\t\tTQueryFnData,\n\t\t\t\tTError,\n\t\t\t\tTData,\n\t\t\t\tTQueryKey,\n\t\t\t\tTPageParam\n\t\t\t>\n\t\t)\n\t}\n\n\t/**\n\t * With `initialInput`, also returns `inputData`, a ref that `mutate()` and\n\t * `mutateAsync()` use when called without variables (form state).\n\t */\n\t// The input type comes from the route alone; `initialInput` is only checked\n\t// against it. `unknown`, not `void`, lets `initialInput` pass the first\n\t// inference pass, which runs before the `(o) => ...` callback is read.\n\tfunction useMutation<\n\t\tTData = unknown,\n\t\tTError = DefaultError,\n\t\tTVariables = unknown,\n\t\tTContext = unknown\n\t>(\n\t\toptionsFn: (\n\t\t\torpc: TOrpc\n\t\t) => MutationObserverOptions<TData, TError, TVariables, TContext>,\n\t\tconfig: { initialInput: NoInfer<TVariables> }\n\t): UseMutationReturnType<TData, TError, TVariables, TContext> & {\n\t\tinputData: Ref<TVariables>\n\t\tmutate: (variables?: TVariables) => void\n\t\tmutateAsync: (variables?: TVariables) => Promise<TData>\n\t}\n\tfunction useMutation<\n\t\tTData = unknown,\n\t\tTError = DefaultError,\n\t\tTVariables = void,\n\t\tTContext = unknown\n\t>(\n\t\toptionsFn: (\n\t\t\torpc: TOrpc\n\t\t) => MutationObserverOptions<TData, TError, TVariables, TContext>\n\t): UseMutationReturnType<TData, TError, TVariables, TContext>\n\tfunction useMutation<TData, TError, TVariables, TContext>(\n\t\toptionsFn: (\n\t\t\torpc: TOrpc\n\t\t) => MutationObserverOptions<TData, TError, TVariables, TContext>,\n\t\tconfig?: { initialInput: TVariables }\n\t) {\n\t\tconst mutation = useVueMutation(computed(() => optionsFn(getO())))\n\t\tif (config?.initialInput === undefined) return mutation\n\t\tconst inputData = ref(config.initialInput) as Ref<TVariables>\n\t\treturn {\n\t\t\t...mutation,\n\t\t\tinputData,\n\t\t\tmutate: (variables?: TVariables) =>\n\t\t\t\tmutation.mutate(variables ?? inputData.value),\n\t\t\tmutateAsync: (variables?: TVariables) =>\n\t\t\t\tmutation.mutateAsync(variables ?? inputData.value)\n\t\t}\n\t}\n\n\tfunction useSubscription<TInput, TEvent>(\n\t\tinput: MaybeRefOrGetter<TInput>,\n\t\tsubscribeFn: OrpcSubscribeFn<TInput, TEvent, TOrpc>,\n\t\toptions: UseSubscriptionOptions<TEvent, TOrpc> = {}\n\t) {\n\t\treturn useOrpcSubscription<TInput, TEvent, TOrpc>(input, subscribeFn, {\n\t\t\t...options,\n\t\t\torpc: getO\n\t\t})\n\t}\n\n\tconst keyOf = <TKey extends QueryKey>(keyFn: (orpc: TOrpc) => TKey) =>\n\t\tkeyFn(getO())\n\n\treturn {\n\t\t/** The utils themselves, for `queryClient.fetchQuery(orpc.x.queryOptions(...))` and the like. */\n\t\tget orpc(): TOrpc {\n\t\t\treturn getO()\n\t\t},\n\t\tuseQuery,\n\t\tuseInfiniteQuery,\n\t\tuseMutation,\n\t\tuseSubscription,\n\t\tinvalidate: (\n\t\t\tkeyFn: (orpc: TOrpc) => QueryKey,\n\t\t\tfilters?: Omit<InvalidateQueryFilters, 'queryKey'>\n\t\t) => queryClient.invalidateQueries({ queryKey: keyOf(keyFn), ...filters }),\n\t\t/** Route preloading and hover-to-prefetch. */\n\t\tprefetch: <\n\t\t\tTQueryFnData,\n\t\t\tTError = DefaultError,\n\t\t\tTData = TQueryFnData,\n\t\t\tTQueryKey extends QueryKey = QueryKey\n\t\t>(\n\t\t\toptionsFn: (\n\t\t\t\torpc: TOrpc\n\t\t\t) => FetchQueryOptions<TQueryFnData, TError, TData, TQueryKey>\n\t\t) => queryClient.prefetchQuery(optionsFn(getO())),\n\t\t/** Data is typed from oRPC's tagged key; pass `<TData>` for an untagged one. */\n\t\tgetQueryData: <TData = never, TKey extends QueryKey = QueryKey>(\n\t\t\tkeyFn: (orpc: TOrpc) => TKey\n\t\t): CachedData<TData, TKey> | undefined =>\n\t\t\tqueryClient.getQueryData<CachedData<TData, TKey>>(keyOf(keyFn)),\n\t\t/** Optimistic updates, typed like `getQueryData`. */\n\t\tsetQueryData: <TData = never, TKey extends QueryKey = QueryKey>(\n\t\t\tkeyFn: (orpc: TOrpc) => TKey,\n\t\t\tupdater: Updater<\n\t\t\t\tCachedData<TData, TKey> | undefined,\n\t\t\t\tCachedData<TData, TKey> | undefined\n\t\t\t>\n\t\t) =>\n\t\t\tqueryClient.setQueryData<CachedData<TData, TKey>>(keyOf(keyFn), updater),\n\t\tcancelQueries: (keyFn: (orpc: TOrpc) => QueryKey) =>\n\t\t\tqueryClient.cancelQueries({ queryKey: keyOf(keyFn) }),\n\t\tremoveQueries: (keyFn: (orpc: TOrpc) => QueryKey) =>\n\t\t\tqueryClient.removeQueries({ queryKey: keyOf(keyFn) }),\n\t\tisFetching: (keyFn?: (orpc: TOrpc) => QueryKey) =>\n\t\t\tqueryClient.isFetching(keyFn ? { queryKey: keyOf(keyFn) } : {}),\n\t\tqueryClient\n\t}\n}\n\ntype ApplyEvent<TStreamEvent, TData> = (\n\tevent: TStreamEvent,\n\tprevious: TData | undefined\n) => TData | undefined\n\ntype LiveQueryOptions<\n\tTInput,\n\tTRouteData,\n\tTStreamEvent,\n\tTData,\n\tTOrpc,\n\tTSubscriptionInput\n> = {\n\timmediate?: MaybeRefOrGetter<boolean>\n\torpc?: MaybeRefOrGetter<TOrpc>\n\t/** Input for the stream when it differs from the query's. */\n\tsubscriptionInput?: MaybeRefOrGetter<TSubscriptionInput>\n\t/**\n\t * Convert the route output once at fetch time into a differently typed\n\t * cache; `applyEvent` then reduces stream events into that cache.\n\t */\n\tselect?: (data: TRouteData) => TData\n\t/**\n\t * The raw route output of a seed before `select` drops fields. `input` is\n\t * what the seed was fetched for, so a seed that resolves after the input\n\t * moved on can be told apart.\n\t */\n\tonSeed?: (data: TRouteData, input: TInput) => void\n\t/**\n\t * Fold a stream event into the cached data. Required when the stream sends\n\t * something other than the cached type (an `fnLive` patch route, or a\n\t * `select`ed cache). Return `undefined` to skip the write.\n\t */\n\tapplyEvent?: ApplyEvent<TStreamEvent, NoInfer<TData>>\n\tonEvent?: (event: TStreamEvent, meta?: { connectionId: number }) => void\n\tonError?: (error: Error) => void\n\t/**\n\t * Reconcile a fetched seed with what the stream already wrote. The HTTP\n\t * request can resolve last, so a plain overwrite would drop events that\n\t * arrived while it was in flight. Default: take the fetched value.\n\t */\n\tmergeSeed?: (\n\t\tfetched: NoInfer<TData>,\n\t\tcached: NoInfer<TData> | undefined\n\t) => NoInfer<TData>\n\t/**\n\t * Show the previous key's data while a new key loads (default: true). Pass\n\t * false when the key says which entity is shown, not just how it is\n\t * filtered: another conversation's timeline must not stand in for this one.\n\t */\n\tkeepPreviousData?: boolean\n\t/** Pause the stream while the page is hidden (default: true). */\n\trespectVisibility?: boolean\n}\n\ntype LiveQueryReturn<TData, TError> = ReturnType<\n\ttypeof useVueQuery<TData, TError>\n> & { liveStatus: Ref<LiveConnectionStatus> }\n\n/**\n * The client half of `fnLive`: the HTTP query seeds the cache, and the live\n * route's stream writes each snapshot into the same cache entry. Marked\n * `meta.live`, so invalidation streams leave it alone.\n *\n * One signature, not overloads: TypeScript fixes an untyped callback's\n * parameters at the first overload it tries, which made valid calls fail.\n */\nexport function useLiveQuery<\n\tTInput,\n\tTRouteData,\n\tTStreamEvent,\n\tTData = TRouteData,\n\tTError = Error,\n\tTOrpc = RegisteredOrpcUtils,\n\tTSubscriptionInput = TInput\n>(\n\tinput: MaybeRefOrGetter<TInput>,\n\tqueryOptionsFn: (\n\t\tinput: TInput,\n\t\torpc: TOrpc\n\t) => UseQueryOptions<TRouteData, TError> & { queryKey: QueryKey },\n\tsubscribeFn: OrpcSubscribeFn<\n\t\tNoInfer<TSubscriptionInput>,\n\t\tTStreamEvent,\n\t\tTOrpc\n\t>,\n\t...options: [TStreamEvent] extends [TData]\n\t\t? [\n\t\t\t\toptions?: LiveQueryOptions<\n\t\t\t\t\tTInput,\n\t\t\t\t\tTRouteData,\n\t\t\t\t\tTStreamEvent,\n\t\t\t\t\tTData,\n\t\t\t\t\tTOrpc,\n\t\t\t\t\tTSubscriptionInput\n\t\t\t\t>\n\t\t\t]\n\t\t: [\n\t\t\t\toptions: LiveQueryOptions<\n\t\t\t\t\tTInput,\n\t\t\t\t\tTRouteData,\n\t\t\t\t\tTStreamEvent,\n\t\t\t\t\tTData,\n\t\t\t\t\tTOrpc,\n\t\t\t\t\tTSubscriptionInput\n\t\t\t\t> & { applyEvent: ApplyEvent<TStreamEvent, NoInfer<TData>> }\n\t\t\t]\n): LiveQueryReturn<TData, TError>\nexport function useLiveQuery<\n\tTInput,\n\tTRouteData,\n\tTStreamEvent,\n\tTData,\n\tTError,\n\tTOrpc,\n\tTSubscriptionInput\n>(\n\tinput: MaybeRefOrGetter<TInput>,\n\tqueryOptionsFn: (\n\t\tinput: TInput,\n\t\torpc: TOrpc\n\t) => UseQueryOptions<TRouteData, TError> & { queryKey: QueryKey },\n\tsubscribeFn: OrpcSubscribeFn<TSubscriptionInput, TStreamEvent, TOrpc>,\n\toptions: LiveQueryOptions<\n\t\tTInput,\n\t\tTRouteData,\n\t\tTStreamEvent,\n\t\tTData,\n\t\tTOrpc,\n\t\tTSubscriptionInput\n\t> = {}\n): LiveQueryReturn<TData, TError> {\n\tconst queryClient = useQueryClient()\n\tconst getO = useUtilsGetter(options.orpc)\n\tconst visible = useDocumentVisible()\n\t// Without `applyEvent` the stream event is the cache type (the first overload).\n\tconst applyEvent =\n\t\toptions.applyEvent ?? ((event: TStreamEvent) => event as unknown as TData)\n\t// Recomputed when the input changes, not once per stream event.\n\tconst queryKey = computed(\n\t\t() => queryOptionsFn(toValue(input), getO()).queryKey\n\t)\n\tconst queryHash = computed(() => hashKey(queryKey.value))\n\tconst scope = createStreamScope()\n\n\tconst subscription = useOrpcSubscription(\n\t\tcomputed(\n\t\t\t() =>\n\t\t\t\t(options.subscriptionInput === undefined\n\t\t\t\t\t? toValue(input)\n\t\t\t\t\t: toValue(options.subscriptionInput)) as TSubscriptionInput\n\t\t),\n\t\tsubscribeFn,\n\t\t{\n\t\t\timmediate: options.immediate,\n\t\t\trespectVisibility: options.respectVisibility,\n\t\t\tonError: options.onError,\n\t\t\tmaxEvents: 1,\n\t\t\torpc: getO,\n\t\t\tonConnect: (connectionId) => scope.open(connectionId, queryHash.value),\n\t\t\tonEvent: (event, meta) => {\n\t\t\t\t// The consumer callback must not see an event for a scope no longer shown.\n\t\t\t\tif (!meta || !scope.owns(meta.connectionId, queryHash.value)) return\n\t\t\t\tconst key = queryKey.value\n\t\t\t\tconst next = applyEvent(event, queryClient.getQueryData<TData>(key))\n\t\t\t\tif (next !== undefined) queryClient.setQueryData(key, next)\n\t\t\t\toptions.onEvent?.(event, meta)\n\t\t\t}\n\t\t}\n\t)\n\n\tconst query = useVueQuery<TData, TError>(\n\t\tcomputed(() => {\n\t\t\tconst inputValue = toValue(input)\n\t\t\t// oRPC query options are plain objects at runtime; vue-query's type\n\t\t\t// wraps fields in MaybeRefDeep, so `queryFn` is read through one shape.\n\t\t\tconst raw = queryOptionsFn(inputValue, getO()) as unknown as {\n\t\t\t\tqueryKey: QueryKey\n\t\t\t\tqueryFn?: (context: unknown) => Promise<TRouteData>\n\t\t\t\tenabled?: unknown\n\t\t\t} & Record<string, unknown>\n\t\t\tconst wrapsSeed = options.select || options.mergeSeed\n\t\t\tconst queryFn =\n\t\t\t\traw.queryFn && wrapsSeed\n\t\t\t\t\t? seedQueryFn(raw.queryFn, {\n\t\t\t\t\t\t\tinput: inputValue,\n\t\t\t\t\t\t\treadCache: () => queryClient.getQueryData<TData>(raw.queryKey),\n\t\t\t\t\t\t\tselect: options.select,\n\t\t\t\t\t\t\tonSeed: options.onSeed,\n\t\t\t\t\t\t\tmergeSeed: options.mergeSeed\n\t\t\t\t\t\t})\n\t\t\t\t\t: raw.queryFn\n\t\t\treturn {\n\t\t\t\t...raw,\n\t\t\t\t...(queryFn ? { queryFn } : {}),\n\t\t\t\tenabled: visible.value && resolveQueryEnabled(raw.enabled),\n\t\t\t\t...(options.keepPreviousData === false\n\t\t\t\t\t? {}\n\t\t\t\t\t: { placeholderData: keepPreviousData }),\n\t\t\t\tstaleTime: Number.POSITIVE_INFINITY,\n\t\t\t\tmeta: { live: true }\n\t\t\t} as unknown as UseQueryOptions<TData, TError>\n\t\t})\n\t)\n\n\treturn Object.assign(query, { liveStatus: subscription.status })\n}\n\n/**\n * Treat a stream as a \"something changed\" ping: invalidate `keyFn` on each\n * event. Prefer {@link useLiveQuery} when the stream carries the data itself.\n */\nexport function useSubscriptionInvalidates<\n\tTInput,\n\tTEvent,\n\tTOrpc = RegisteredOrpcUtils\n>(\n\tinput: MaybeRefOrGetter<TInput>,\n\tsubscribeFn: OrpcSubscribeFn<TInput, TEvent, TOrpc>,\n\tkeyFn: (orpc: TOrpc) => QueryKey,\n\toptions: Pick<\n\t\tUseSubscriptionOptions<TEvent, TOrpc>,\n\t\t'immediate' | 'maxEvents' | 'respectVisibility' | 'orpc'\n\t> & {\n\t\tonEvent?: (event: TEvent) => void\n\t\t/** Return false to skip invalidation for this event. */\n\t\tshouldInvalidate?: (event: TEvent) => boolean\n\t} = {}\n): UseSubscriptionReturn<TEvent> {\n\tconst { onEvent, shouldInvalidate, ...subscriptionOptions } = options\n\tconst { useSubscription, invalidate } = useApiClient<TOrpc>({\n\t\torpc: options.orpc\n\t})\n\treturn useSubscription(input, subscribeFn, {\n\t\t...subscriptionOptions,\n\t\tonEvent: (event) => {\n\t\t\tonEvent?.(event)\n\t\t\tif (shouldInvalidate?.(event) === false) return\n\t\t\tvoid invalidate(keyFn)\n\t\t}\n\t})\n}\n\n/**\n * One app-wide stream of `{ domain }` change events that keeps list and count\n * queries fresh: each event invalidates its domain's query keys (debounced),\n * and a reconnect that proves healthy invalidates every domain to cover\n * events lost while it was down. Call once, in the signed-in shell.\n *\n * ```ts\n * useInvalidationStream({}, (o) => o.realtime.subscribeChanges.call, {\n * domains: { order: { debounceMs: 100, queryKeys: [orpc.order.key()] } }\n * })\n * ```\n */\nexport function useInvalidationStream<\n\tTInput,\n\tTEvent extends { domain: string },\n\tTOrpc = RegisteredOrpcUtils\n>(\n\tinput: MaybeRefOrGetter<TInput>,\n\tsubscribe: OrpcSubscribeFn<TInput, TEvent, TOrpc>,\n\toptions: InvalidationStreamOptions<TEvent> &\n\t\tPick<\n\t\t\tUseSubscriptionOptions<TEvent, TOrpc>,\n\t\t\t'immediate' | 'respectVisibility' | 'orpc'\n\t\t>\n): UseSubscriptionReturn<TEvent> {\n\tconst coordinator = createInvalidationCoordinator(useQueryClient(), options)\n\tif (getCurrentScope()) onScopeDispose(coordinator.dispose)\n\treturn useOrpcSubscription<TInput, TEvent, TOrpc>(input, subscribe, {\n\t\timmediate: options.immediate,\n\t\trespectVisibility: options.respectVisibility,\n\t\torpc: options.orpc,\n\t\tmaxEvents: 1,\n\t\tonEvent: coordinator.event,\n\t\tonConnect: coordinator.connect,\n\t\tonError: coordinator.lost,\n\t\tonClose: coordinator.lost\n\t})\n}\n\n/** Localized text for a failed query: your fallback unless the server marked its message user-safe. */\nexport function useQueryErrorMessage(\n\terror: MaybeRefOrGetter<unknown>,\n\tfallback: MaybeRefOrGetter<string>\n) {\n\treturn computed(() => {\n\t\tconst err = toValue(error)\n\t\treturn err ? userFacingErrorMessage(err, toValue(fallback)) : null\n\t})\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "orpc-fn",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Define a backend function once: a typed oRPC procedure with tracing, logging, guards, injected handler extras, nested calls and live queries over Redis.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type ZodType, z } from 'zod'
|
|
2
2
|
import type {
|
|
3
3
|
AnyFnContext,
|
|
4
4
|
FnDefinition,
|
|
@@ -36,8 +36,15 @@ export type ScopedChangeBus<
|
|
|
36
36
|
TScopeEvent
|
|
37
37
|
> = PubSub<TDef, TInputSchema, TEventSchema, TKey> & {
|
|
38
38
|
channel: ChangeBusChannel<AnyFnContext<TDef>, TScopeEvent>
|
|
39
|
+
/**
|
|
40
|
+
* The full channel name for a scope, namespace included:
|
|
41
|
+
* `backlogKey(bus.channelFor({ organizationId }))` reads its backlog.
|
|
42
|
+
*/
|
|
43
|
+
channelFor: (scope: TScopeEvent) => string
|
|
39
44
|
}
|
|
40
45
|
|
|
46
|
+
const noInput = z.object({})
|
|
47
|
+
|
|
41
48
|
/**
|
|
42
49
|
* Binds the app's `createPubSub` to one scope rule, for buses that tell every
|
|
43
50
|
* subscriber in a scope "something changed". Each bus then names only its
|
|
@@ -52,7 +59,6 @@ export type ScopedChangeBus<
|
|
|
52
59
|
* export const dealChanges = defineChangeBus({
|
|
53
60
|
* name: 'deal.subscribe',
|
|
54
61
|
* prefix: 'deal:change',
|
|
55
|
-
* inputSchema: z.object({}),
|
|
56
62
|
* eventSchema: z.object({ organizationId: z.string(), dealId: z.string() })
|
|
57
63
|
* })
|
|
58
64
|
* // fnLive({ live: { channel: dealChanges.channel, ... } }) shares the channel.
|
|
@@ -63,13 +69,13 @@ export function defineScopedChangeBus<TDef extends FnDefinition, TScopeEvent>(
|
|
|
63
69
|
scope: ChangeBusScope<AnyFnContext<TDef>, TScopeEvent>
|
|
64
70
|
) {
|
|
65
71
|
return <
|
|
66
|
-
TInputSchema extends ObjectSchema,
|
|
67
72
|
TEventSchema extends ZodType<TScopeEvent>,
|
|
73
|
+
TInputSchema extends ObjectSchema = typeof noInput,
|
|
68
74
|
TKey extends ProcedureKey<TDef> = TDef['default']
|
|
69
75
|
>(
|
|
70
76
|
options: Omit<
|
|
71
77
|
PubSubOptions<TDef, TInputSchema, TEventSchema, NoInfer<TKey>>,
|
|
72
|
-
'channel'
|
|
78
|
+
'channel' | 'inputSchema'
|
|
73
79
|
> &
|
|
74
80
|
GuardOptions<TDef['guards']> &
|
|
75
81
|
Pick<
|
|
@@ -79,6 +85,8 @@ export function defineScopedChangeBus<TDef extends FnDefinition, TScopeEvent>(
|
|
|
79
85
|
ProcedureOption<TDef, TKey> & {
|
|
80
86
|
/** Channel prefix; the scope key is appended as `${prefix}:${scope}`. */
|
|
81
87
|
prefix: string
|
|
88
|
+
/** What the subscriber provides (default: no input). */
|
|
89
|
+
inputSchema?: TInputSchema
|
|
82
90
|
}
|
|
83
91
|
): ScopedChangeBus<TDef, TInputSchema, TEventSchema, TKey, TScopeEvent> => {
|
|
84
92
|
const { prefix, ...pubsubOptions } = options
|
|
@@ -91,8 +99,13 @@ export function defineScopedChangeBus<TDef extends FnDefinition, TScopeEvent>(
|
|
|
91
99
|
const bus = (createPubSub as (options: object) => object)({
|
|
92
100
|
safePublish: true,
|
|
93
101
|
...pubsubOptions,
|
|
102
|
+
inputSchema: pubsubOptions.inputSchema ?? noInput,
|
|
94
103
|
channel
|
|
95
104
|
}) as PubSub<TDef, TInputSchema, TEventSchema, TKey>
|
|
96
|
-
|
|
105
|
+
// The scope reads only its own fields, so a scope stands in for an event.
|
|
106
|
+
const channelFor = bus.getPublishChannelName as (
|
|
107
|
+
scope: TScopeEvent
|
|
108
|
+
) => string
|
|
109
|
+
return { ...bus, channel, channelFor }
|
|
97
110
|
}
|
|
98
111
|
}
|
package/src/vue.ts
CHANGED
|
@@ -310,6 +310,11 @@ export function useOrpcSubscription<
|
|
|
310
310
|
}
|
|
311
311
|
}
|
|
312
312
|
|
|
313
|
+
/** What {@link useApiClient} returns, e.g. `ApiClient['invalidate']` for a helper. */
|
|
314
|
+
export type ApiClient<TOrpc = RegisteredOrpcUtils> = ReturnType<
|
|
315
|
+
typeof useBoundApiClient<TOrpc>
|
|
316
|
+
>
|
|
317
|
+
|
|
313
318
|
/**
|
|
314
319
|
* TanStack Query composables that receive the oRPC utils, so call sites read
|
|
315
320
|
* `useQuery((o) => o.order.get.queryOptions({ input }))`. Pass `orpc` to bind
|
|
@@ -317,32 +322,35 @@ export function useOrpcSubscription<
|
|
|
317
322
|
*/
|
|
318
323
|
export function useApiClient<TOrpc = RegisteredOrpcUtils>(clientOptions?: {
|
|
319
324
|
orpc?: MaybeRefOrGetter<TOrpc> | undefined
|
|
320
|
-
})
|
|
325
|
+
}): ApiClient<TOrpc>
|
|
326
|
+
// `ReturnType<typeof useApiClient>` reads the last overload: the registered utils.
|
|
327
|
+
export function useApiClient(): ApiClient
|
|
328
|
+
export function useApiClient<TOrpc>(clientOptions?: {
|
|
329
|
+
orpc?: MaybeRefOrGetter<TOrpc> | undefined
|
|
330
|
+
}): ApiClient<TOrpc> {
|
|
331
|
+
return useBoundApiClient(clientOptions?.orpc)
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
function useBoundApiClient<TOrpc>(orpc: MaybeRefOrGetter<TOrpc> | undefined) {
|
|
321
335
|
const queryClient = useQueryClient()
|
|
322
|
-
const getO = useUtilsGetter(
|
|
336
|
+
const getO = useUtilsGetter(orpc)
|
|
323
337
|
|
|
324
338
|
// Each wrapper forwards TanStack's own generics, so `select`, typed errors,
|
|
325
339
|
// page params and oRPC's tagged keys infer exactly as with vue-query itself.
|
|
326
|
-
function useQuery<
|
|
327
|
-
TQueryFnData,
|
|
328
|
-
TError = DefaultError,
|
|
329
|
-
TData = TQueryFnData,
|
|
330
|
-
TQueryKey extends QueryKey = QueryKey
|
|
331
|
-
>(
|
|
340
|
+
function useQuery<TQueryFnData, TError = DefaultError, TData = TQueryFnData>(
|
|
332
341
|
optionsFn: (
|
|
333
342
|
orpc: TOrpc
|
|
334
|
-
) => UseQueryOptions<TQueryFnData, TError, TData, TQueryFnData
|
|
343
|
+
) => UseQueryOptions<TQueryFnData, TError, TData, TQueryFnData>
|
|
335
344
|
): UseQueryReturnType<TData, TError> {
|
|
336
345
|
// A computed is a ref at runtime; TypeScript cannot relate a computed of
|
|
337
346
|
// the generic options to vue-query's MaybeRef parameter, so it is asserted.
|
|
338
347
|
const options = computed(() => optionsFn(getO()))
|
|
339
|
-
return useVueQuery<TQueryFnData, TError, TData
|
|
348
|
+
return useVueQuery<TQueryFnData, TError, TData>(
|
|
340
349
|
options as unknown as UseQueryOptions<
|
|
341
350
|
TQueryFnData,
|
|
342
351
|
TError,
|
|
343
352
|
TData,
|
|
344
|
-
TQueryFnData
|
|
345
|
-
TQueryKey
|
|
353
|
+
TQueryFnData
|
|
346
354
|
>
|
|
347
355
|
)
|
|
348
356
|
}
|
|
@@ -387,16 +395,19 @@ export function useApiClient<TOrpc = RegisteredOrpcUtils>(clientOptions?: {
|
|
|
387
395
|
* With `initialInput`, also returns `inputData`, a ref that `mutate()` and
|
|
388
396
|
* `mutateAsync()` use when called without variables (form state).
|
|
389
397
|
*/
|
|
398
|
+
// The input type comes from the route alone; `initialInput` is only checked
|
|
399
|
+
// against it. `unknown`, not `void`, lets `initialInput` pass the first
|
|
400
|
+
// inference pass, which runs before the `(o) => ...` callback is read.
|
|
390
401
|
function useMutation<
|
|
391
402
|
TData = unknown,
|
|
392
403
|
TError = DefaultError,
|
|
393
|
-
TVariables =
|
|
404
|
+
TVariables = unknown,
|
|
394
405
|
TContext = unknown
|
|
395
406
|
>(
|
|
396
407
|
optionsFn: (
|
|
397
408
|
orpc: TOrpc
|
|
398
409
|
) => MutationObserverOptions<TData, TError, TVariables, TContext>,
|
|
399
|
-
config: { initialInput: TVariables }
|
|
410
|
+
config: { initialInput: NoInfer<TVariables> }
|
|
400
411
|
): UseMutationReturnType<TData, TError, TVariables, TContext> & {
|
|
401
412
|
inputData: Ref<TVariables>
|
|
402
413
|
mutate: (variables?: TVariables) => void
|
|
@@ -446,6 +457,10 @@ export function useApiClient<TOrpc = RegisteredOrpcUtils>(clientOptions?: {
|
|
|
446
457
|
keyFn(getO())
|
|
447
458
|
|
|
448
459
|
return {
|
|
460
|
+
/** The utils themselves, for `queryClient.fetchQuery(orpc.x.queryOptions(...))` and the like. */
|
|
461
|
+
get orpc(): TOrpc {
|
|
462
|
+
return getO()
|
|
463
|
+
},
|
|
449
464
|
useQuery,
|
|
450
465
|
useInfiniteQuery,
|
|
451
466
|
useMutation,
|