@orpc/pinia-colada 2.0.0-beta.48 → 2.0.0-beta.49
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 +4 -4
- package/dist/contract-utils.d.ts +37 -0
- package/dist/contract-utils.js +42 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +14 -0
- package/dist/key.d.ts +45 -0
- package/dist/key.js +47 -0
- package/dist/live-query.d.ts +8 -0
- package/dist/live-query.js +38 -0
- package/dist/meta.d.ts +42 -0
- package/dist/meta.js +55 -0
- package/dist/plugin.d.ts +46 -0
- package/dist/plugin.js +25 -0
- package/dist/procedure-utils.d.ts +190 -0
- package/dist/procedure-utils.js +399 -0
- package/dist/router-utils.d.ts +67 -0
- package/dist/router-utils.js +69 -0
- package/dist/shared-utils.d.ts +13 -0
- package/dist/shared-utils.js +21 -0
- package/dist/ssr.d.ts +22 -0
- package/dist/ssr.js +24 -0
- package/dist/stream-query.d.ts +42 -0
- package/dist/stream-query.js +59 -0
- package/dist/types.d.ts +80 -0
- package/dist/types.js +7 -0
- package/package.json +31 -33
- package/dist/contract-utils.d.mts +0 -35
- package/dist/contract-utils.mjs +0 -23
- package/dist/index.d.mts +0 -19
- package/dist/index.mjs +0 -11
- package/dist/key.d.mts +0 -57
- package/dist/key.mjs +0 -29
- package/dist/live-query.d.mts +0 -7
- package/dist/live-query.mjs +0 -24
- package/dist/meta.d.mts +0 -55
- package/dist/meta.mjs +0 -37
- package/dist/plugin.d.mts +0 -46
- package/dist/plugin.mjs +0 -25
- package/dist/procedure-utils.d.mts +0 -245
- package/dist/procedure-utils.mjs +0 -394
- package/dist/router-utils.d.mts +0 -57
- package/dist/router-utils.mjs +0 -51
- package/dist/shared-utils.d.mts +0 -13
- package/dist/shared-utils.mjs +0 -17
- package/dist/stream-query.d.mts +0 -30
- package/dist/stream-query.mjs +0 -45
- package/dist/types.d.mts +0 -125
- package/dist/types.mjs +0 -2
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { RECURSIVE_CLIENT_UNWRAP_KEYS } from '@orpc/client';
|
|
2
|
+
import { bindMethods, isNonPrimitive, pick, toArray } from '@orpc/shared';
|
|
3
|
+
import { CompositeRouterUtilsPlugin } from './plugin.js';
|
|
4
|
+
import { isProcedureUtilsOptions, mergeProcedureUtilsOptions, ProcedureUtils, } from './procedure-utils.js';
|
|
5
|
+
import { SharedUtils } from './shared-utils.js';
|
|
6
|
+
/**
|
|
7
|
+
* Creates Pinia Colada utils from a client, exposing query/mutation
|
|
8
|
+
* option builders for every procedure in the router.
|
|
9
|
+
*
|
|
10
|
+
* @remarks
|
|
11
|
+
* **Note**: Both client-side and server-side clients are supported.
|
|
12
|
+
*
|
|
13
|
+
* @see {@link https://orpc.dev/docs/integrations/pinia-colada | Pinia Colada Integration}
|
|
14
|
+
*/
|
|
15
|
+
export function createRouterUtils(client, options = {}) {
|
|
16
|
+
const plugin = new CompositeRouterUtilsPlugin(options.plugins);
|
|
17
|
+
options = plugin.init(options);
|
|
18
|
+
return createRouterUtilsInternal(client, options, plugin);
|
|
19
|
+
}
|
|
20
|
+
function createRouterUtilsInternal(client, options, plugin) {
|
|
21
|
+
const path = toArray(options.path);
|
|
22
|
+
const utils = typeof client === 'function' &&
|
|
23
|
+
(options.scoped === undefined || isProcedureUtilsOptions(options.scoped))
|
|
24
|
+
? bindMethods(new ProcedureUtils(path, client, plugin.initProcedureOptions(path, mergeProcedureUtilsOptions(pick(options, [
|
|
25
|
+
'prefix',
|
|
26
|
+
'serializer',
|
|
27
|
+
'queryInterceptors',
|
|
28
|
+
'streamedInterceptors',
|
|
29
|
+
'liveInterceptors',
|
|
30
|
+
'infiniteInterceptors',
|
|
31
|
+
'mutationInterceptors',
|
|
32
|
+
]), options.scoped ?? {}))), { unbound: ['call'] })
|
|
33
|
+
: bindMethods(new SharedUtils(path, options));
|
|
34
|
+
const cache = new Map();
|
|
35
|
+
const recursive = new Proxy(utils, {
|
|
36
|
+
get(target, prop) {
|
|
37
|
+
const value = Reflect.get(target, prop);
|
|
38
|
+
if (RECURSIVE_CLIENT_UNWRAP_KEYS.has(prop)) {
|
|
39
|
+
return value ?? Reflect.get(Object.prototype, prop);
|
|
40
|
+
}
|
|
41
|
+
const nextClient = Reflect.get(client, prop);
|
|
42
|
+
if (typeof prop !== 'string' || !isNonPrimitive(nextClient)) {
|
|
43
|
+
return value;
|
|
44
|
+
}
|
|
45
|
+
let result = cache.get(prop);
|
|
46
|
+
if (result === undefined) {
|
|
47
|
+
const nextUtils = createRouterUtilsInternal(nextClient, {
|
|
48
|
+
...options,
|
|
49
|
+
path: [...path, prop],
|
|
50
|
+
scoped: options.scoped?.[prop],
|
|
51
|
+
}, plugin);
|
|
52
|
+
result =
|
|
53
|
+
typeof value !== 'function'
|
|
54
|
+
? nextUtils
|
|
55
|
+
: new Proxy(value, {
|
|
56
|
+
get(target, prop) {
|
|
57
|
+
if (typeof prop !== 'string' || RECURSIVE_CLIENT_UNWRAP_KEYS.has(prop)) {
|
|
58
|
+
return Reflect.get(target, prop);
|
|
59
|
+
}
|
|
60
|
+
return Reflect.get(nextUtils, prop);
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
cache.set(prop, result);
|
|
64
|
+
}
|
|
65
|
+
return result;
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
return recursive;
|
|
69
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { OperationKey, OperationKeyBaseOptions, OperationKeyOptions } from './key.ts';
|
|
2
|
+
import type { OperationType } from './types.ts';
|
|
3
|
+
export declare class SharedUtils<TInput> {
|
|
4
|
+
protected readonly path: string[];
|
|
5
|
+
protected readonly options: OperationKeyBaseOptions;
|
|
6
|
+
constructor(path: string[], options: OperationKeyBaseOptions);
|
|
7
|
+
/**
|
|
8
|
+
* Generate a **partial matching** key for actions like revalidating queries, checking mutation status, etc.
|
|
9
|
+
*
|
|
10
|
+
* @see {@link https://orpc.dev/docs/integrations/pinia-colada#querymutation-key | Pinia Colada Integration - Query/Mutation Key}
|
|
11
|
+
*/
|
|
12
|
+
key<TType extends OperationType>(options?: Omit<OperationKeyOptions<TType, TInput>, keyof OperationKeyBaseOptions>): OperationKey<TType, TInput>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { generateOperationKey } from './key.js';
|
|
2
|
+
export class SharedUtils {
|
|
3
|
+
path;
|
|
4
|
+
options;
|
|
5
|
+
constructor(path, options) {
|
|
6
|
+
this.path = path;
|
|
7
|
+
this.options = options;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Generate a **partial matching** key for actions like revalidating queries, checking mutation status, etc.
|
|
11
|
+
*
|
|
12
|
+
* @see {@link https://orpc.dev/docs/integrations/pinia-colada#querymutation-key | Pinia Colada Integration - Query/Mutation Key}
|
|
13
|
+
*/
|
|
14
|
+
key(options = {}) {
|
|
15
|
+
return generateOperationKey(this.path, {
|
|
16
|
+
...options,
|
|
17
|
+
prefix: this.options.prefix,
|
|
18
|
+
serializer: this.options.serializer,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
}
|
package/dist/ssr.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { AnyNestedClient, InferClientContext, InferClientError } from '@orpc/client';
|
|
2
|
+
import type { RouterUtilsPlugin } from './plugin.ts';
|
|
3
|
+
import type { ProcedureUtilsOptions } from './procedure-utils.ts';
|
|
4
|
+
export interface StreamQuerySSRUtilsPluginOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Whether utils run on the server, where streamed and live queries always settle at their first data.
|
|
7
|
+
* Defaults to `true` when there is no global `window`, or in Deno.
|
|
8
|
+
*/
|
|
9
|
+
isServer?: boolean | undefined;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Router utils plugin for SSR of streamed and live queries: sets `settleOnFirstData: true` on the server,
|
|
13
|
+
* and `staleTime: 0` in the browser, so hydrated data is stale and its stream reopens when a component mounts.
|
|
14
|
+
*
|
|
15
|
+
* @see {@link https://orpc.dev/docs/integrations/pinia-colada#streamed-and-live-queries-in-ssr | Pinia Colada Integration - Streamed and Live Queries in SSR}
|
|
16
|
+
*/
|
|
17
|
+
export declare class StreamQuerySSRUtilsPlugin<T extends AnyNestedClient = AnyNestedClient> implements RouterUtilsPlugin<T> {
|
|
18
|
+
readonly name = "~stream-query-ssr";
|
|
19
|
+
private readonly defaults;
|
|
20
|
+
constructor(options?: StreamQuerySSRUtilsPluginOptions);
|
|
21
|
+
initProcedureOptions(_path: string[], options: ProcedureUtilsOptions<InferClientContext<T>, any, any, InferClientError<T>>): ProcedureUtilsOptions<InferClientContext<T>, any, any, InferClientError<T>>;
|
|
22
|
+
}
|
package/dist/ssr.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { mergeProcedureUtilsOptions } from './procedure-utils.js';
|
|
2
|
+
/**
|
|
3
|
+
* Router utils plugin for SSR of streamed and live queries: sets `settleOnFirstData: true` on the server,
|
|
4
|
+
* and `staleTime: 0` in the browser, so hydrated data is stale and its stream reopens when a component mounts.
|
|
5
|
+
*
|
|
6
|
+
* @see {@link https://orpc.dev/docs/integrations/pinia-colada#streamed-and-live-queries-in-ssr | Pinia Colada Integration - Streamed and Live Queries in SSR}
|
|
7
|
+
*/
|
|
8
|
+
export class StreamQuerySSRUtilsPlugin {
|
|
9
|
+
name = '~stream-query-ssr';
|
|
10
|
+
defaults;
|
|
11
|
+
constructor(options = {}) {
|
|
12
|
+
// the server always settles, even when observed, and keeps the staleTime so components sharing a query do not reopen it
|
|
13
|
+
this.defaults =
|
|
14
|
+
(options.isServer ?? (!('window' in globalThis) || 'Deno' in globalThis))
|
|
15
|
+
? { settleOnFirstData: true }
|
|
16
|
+
: { staleTime: 0 };
|
|
17
|
+
}
|
|
18
|
+
initProcedureOptions(_path, options) {
|
|
19
|
+
return mergeProcedureUtilsOptions({
|
|
20
|
+
streamedOptions: this.defaults,
|
|
21
|
+
liveOptions: this.defaults,
|
|
22
|
+
}, options);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { Promisable } from '@orpc/shared';
|
|
2
|
+
import type { UseQueryFnContext } from './types.ts';
|
|
3
|
+
export interface SerializableStreamedQueryOptions {
|
|
4
|
+
/**
|
|
5
|
+
* What a fetch does with existing data once its stream connects.
|
|
6
|
+
* Until then the data stays, so an entry with data never returns to `pending`.
|
|
7
|
+
*
|
|
8
|
+
* - `'reset'`: the data becomes `[]`, then each chunk is appended.
|
|
9
|
+
* - `'append'`: the data is kept (trimmed to `maxChunks`), and each chunk is appended.
|
|
10
|
+
*
|
|
11
|
+
* @default 'reset'
|
|
12
|
+
*/
|
|
13
|
+
refetchMode?: 'append' | 'reset' | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* Limits the number of data chunks stored in the query result.
|
|
16
|
+
* Older chunks are removed when the limit is reached.
|
|
17
|
+
*
|
|
18
|
+
* @default Number.POSITIVE_INFINITY (unlimited)
|
|
19
|
+
*/
|
|
20
|
+
maxChunks?: number | undefined;
|
|
21
|
+
}
|
|
22
|
+
export interface SettleOnFirstDataOptions {
|
|
23
|
+
/**
|
|
24
|
+
* Settles the fetch at its first data (streamed: when the stream connects; live: on the first event)
|
|
25
|
+
* instead of following the stream to its end. The stream is closed and the data kept.
|
|
26
|
+
* The stream reopens on mount only once the entry is stale (e.g. with `staleTime: 0`, as `StreamQuerySSRUtilsPlugin` sets in the browser).
|
|
27
|
+
* Use it only where nothing watches the stream, such as server rendering:
|
|
28
|
+
* a refetch while a component uses the query would also settle, closing its stream.
|
|
29
|
+
*
|
|
30
|
+
* @default false
|
|
31
|
+
*/
|
|
32
|
+
settleOnFirstData?: boolean | undefined;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* A Pinia Colada query function that accumulates streamed chunks into an array,
|
|
36
|
+
* publishing each chunk to the cache entry as it arrives.
|
|
37
|
+
*
|
|
38
|
+
* Inspired by [TanStack Query streamedQuery](https://tanstack.com/query/latest/docs/reference/streamedQuery) where:
|
|
39
|
+
* - Options are serializable
|
|
40
|
+
* - The output is predictable
|
|
41
|
+
*/
|
|
42
|
+
export declare function serializableStreamedQuery<T>(queryFn: (context: UseQueryFnContext) => Promisable<AsyncIterable<T>>, { refetchMode, maxChunks, settleOnFirstData, }?: SerializableStreamedQueryOptions & SettleOnFirstDataOptions): (context: UseQueryFnContext) => Promise<T[]>;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { throwIfAborted } from '@orpc/shared';
|
|
2
|
+
/**
|
|
3
|
+
* A Pinia Colada query function that accumulates streamed chunks into an array,
|
|
4
|
+
* publishing each chunk to the cache entry as it arrives.
|
|
5
|
+
*
|
|
6
|
+
* Inspired by [TanStack Query streamedQuery](https://tanstack.com/query/latest/docs/reference/streamedQuery) where:
|
|
7
|
+
* - Options are serializable
|
|
8
|
+
* - The output is predictable
|
|
9
|
+
*/
|
|
10
|
+
export function serializableStreamedQuery(queryFn, { refetchMode = 'reset', maxChunks = Number.POSITIVE_INFINITY, settleOnFirstData = false, } = {}) {
|
|
11
|
+
return async (context) => {
|
|
12
|
+
const { entry, signal } = context;
|
|
13
|
+
const write = (data) => {
|
|
14
|
+
entry.state.value = { status: 'success', data, error: null };
|
|
15
|
+
return data;
|
|
16
|
+
};
|
|
17
|
+
// a fetch cut short (cancelled, superseded, or its last component left) reopens when used again
|
|
18
|
+
const markStale = () => {
|
|
19
|
+
entry.when = 0;
|
|
20
|
+
};
|
|
21
|
+
if (signal.aborted) {
|
|
22
|
+
markStale();
|
|
23
|
+
}
|
|
24
|
+
signal.addEventListener('abort', markStale, { once: true });
|
|
25
|
+
const stream = await queryFn(context);
|
|
26
|
+
// close without reading, so a generator the query no longer wants never starts
|
|
27
|
+
if (signal.aborted) {
|
|
28
|
+
await stream[Symbol.asyncIterator]().return?.();
|
|
29
|
+
throw signal.reason;
|
|
30
|
+
}
|
|
31
|
+
const current = entry.state.value.data;
|
|
32
|
+
let data = write(refetchMode === 'append' && current ? limitArraySize(current, maxChunks) : []);
|
|
33
|
+
if (settleOnFirstData) {
|
|
34
|
+
await stream[Symbol.asyncIterator]().return?.();
|
|
35
|
+
return data;
|
|
36
|
+
}
|
|
37
|
+
for await (const chunk of stream) {
|
|
38
|
+
throwIfAborted(signal);
|
|
39
|
+
// read the entry, so writes made during the stream are kept
|
|
40
|
+
const current = entry.state.value.data ?? [];
|
|
41
|
+
data = write(limitArraySize([...current, chunk], maxChunks));
|
|
42
|
+
}
|
|
43
|
+
// a stream that ends on abort must not be stored as fresh data
|
|
44
|
+
throwIfAborted(signal);
|
|
45
|
+
// Colada writes the returned data again, so return the entry data to keep later writes
|
|
46
|
+
const cached = entry.state.value.data;
|
|
47
|
+
if (cached === undefined) {
|
|
48
|
+
return data;
|
|
49
|
+
}
|
|
50
|
+
// only an array is trimmed; another value written after the stream (e.g. `null`) is kept as is
|
|
51
|
+
return Array.isArray(cached) ? limitArraySize(cached, maxChunks) : cached;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function limitArraySize(items, maxSize) {
|
|
55
|
+
if (items.length <= maxSize) {
|
|
56
|
+
return items;
|
|
57
|
+
}
|
|
58
|
+
return items.slice(items.length - maxSize);
|
|
59
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { ClientContext } from '@orpc/client';
|
|
2
|
+
import type { DefineInfiniteQueryOptions, DefineInfiniteQueryOptionsTagged, DefineMutationOptionsTagged, DefineQueryOptions, DefineQueryOptionsTagged, EntryKey, UseInfiniteQueryData, UseMutationOptions, UseMutationOptionsGlobal, UseQueryOptions } from '@pinia/colada';
|
|
3
|
+
import type { SerializableStreamedQueryOptions, SettleOnFirstDataOptions } from './stream-query.ts';
|
|
4
|
+
export type InferStreamedQueryOutput<TOutput> = TOutput extends AsyncIterable<infer U> ? U[] : never;
|
|
5
|
+
export type InferLiveQueryOutput<TOutput> = TOutput extends AsyncIterable<infer U> ? U : never;
|
|
6
|
+
export type UseQueryFnContext = Parameters<UseQueryOptions<any>['query']>[0];
|
|
7
|
+
/**
|
|
8
|
+
* The context passed to the mutation function, including the merged
|
|
9
|
+
* `UseMutationGlobalContext` values provided by a global `onMutate` hook.
|
|
10
|
+
*/
|
|
11
|
+
export type UseMutationFnContext = Parameters<NonNullable<UseMutationOptionsGlobal['onSuccess']>>[2];
|
|
12
|
+
/**
|
|
13
|
+
* The symbol under which Pinia Colada utils attach operation details
|
|
14
|
+
* (key and operation type) to the client context.
|
|
15
|
+
*
|
|
16
|
+
* @see {@link https://orpc.dev/docs/integrations/pinia-colada#client-context | Pinia Colada Integration - Client Context}
|
|
17
|
+
*/
|
|
18
|
+
export declare const OPERATION_CONTEXT_SYMBOL: unique symbol;
|
|
19
|
+
export type OperationType = 'query' | 'streamed' | 'live' | 'infinite' | 'mutation';
|
|
20
|
+
/**
|
|
21
|
+
* A client context automatically populated by Pinia Colada utils,
|
|
22
|
+
* exposing the operation key and type of the calling operation.
|
|
23
|
+
*
|
|
24
|
+
* @see {@link https://orpc.dev/docs/integrations/pinia-colada#client-context | Pinia Colada Integration - Client Context}
|
|
25
|
+
*/
|
|
26
|
+
export interface OperationContext {
|
|
27
|
+
[OPERATION_CONTEXT_SYMBOL]?: {
|
|
28
|
+
key: EntryKey;
|
|
29
|
+
type: OperationType;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export type QueryKeyOptions<TInput> = (undefined extends TInput ? {
|
|
33
|
+
input?: TInput;
|
|
34
|
+
} : {
|
|
35
|
+
input: TInput;
|
|
36
|
+
}) | {
|
|
37
|
+
key: EntryKey;
|
|
38
|
+
};
|
|
39
|
+
export type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TInitialData extends TOutput | undefined> = (undefined extends TInput ? {
|
|
40
|
+
input?: TInput;
|
|
41
|
+
} : {
|
|
42
|
+
input: TInput;
|
|
43
|
+
}) & (object extends TClientContext ? {
|
|
44
|
+
context?: TClientContext | undefined;
|
|
45
|
+
} : {
|
|
46
|
+
context: TClientContext;
|
|
47
|
+
}) & Omit<DefineQueryOptions<TOutput, TError, TInitialData>, 'key' | 'query'> & Partial<Pick<DefineQueryOptions<TOutput, TError, TInitialData>, 'key' | 'query'>>;
|
|
48
|
+
export type QueryOptionsOut<TOutput, TError, TInitialData extends TOutput | undefined> = DefineQueryOptionsTagged<TOutput, TError, TInitialData>;
|
|
49
|
+
export type StreamedKeyOptions<TInput> = ((undefined extends TInput ? {
|
|
50
|
+
input?: TInput;
|
|
51
|
+
} : {
|
|
52
|
+
input: TInput;
|
|
53
|
+
}) & {
|
|
54
|
+
fnOptions?: SerializableStreamedQueryOptions | undefined;
|
|
55
|
+
}) | {
|
|
56
|
+
key: EntryKey;
|
|
57
|
+
};
|
|
58
|
+
export type StreamedOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TInitialData extends TOutput | undefined> = QueryOptionsIn<TClientContext, TInput, TOutput, TError, TInitialData> & {
|
|
59
|
+
fnOptions?: SerializableStreamedQueryOptions | undefined;
|
|
60
|
+
} & SettleOnFirstDataOptions;
|
|
61
|
+
export type StreamedOptionsOut<TOutput, TError, TInitialData extends TOutput | undefined> = QueryOptionsOut<TOutput, TError, TInitialData>;
|
|
62
|
+
export type LiveOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TInitialData extends TOutput | undefined> = QueryOptionsIn<TClientContext, TInput, TOutput, TError, TInitialData> & SettleOnFirstDataOptions;
|
|
63
|
+
export type InfiniteKeyOptions<TInput, TPageParam> = Pick<InfiniteOptionsIn<any, TInput, any, any, TPageParam, any>, 'input' | 'initialPageParam'> | {
|
|
64
|
+
key: EntryKey;
|
|
65
|
+
};
|
|
66
|
+
export type InfiniteOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TPageParam, TInitialData extends UseInfiniteQueryData<TOutput, TPageParam> | undefined> = {
|
|
67
|
+
input: (pageParam: TPageParam) => TInput;
|
|
68
|
+
} & (object extends TClientContext ? {
|
|
69
|
+
context?: TClientContext | undefined;
|
|
70
|
+
} : {
|
|
71
|
+
context: TClientContext;
|
|
72
|
+
}) & Omit<DefineInfiniteQueryOptions<TOutput, TError, TPageParam, TInitialData>, 'key' | 'query'> & Partial<Pick<DefineInfiniteQueryOptions<TOutput, TError, TPageParam, TInitialData>, 'key' | 'query'>>;
|
|
73
|
+
export type InfiniteOptionsOut<TOutput, TError, TPageParam, TInitialData extends UseInfiniteQueryData<TOutput, TPageParam> | undefined> = DefineInfiniteQueryOptionsTagged<TOutput, TError, TPageParam, TInitialData>;
|
|
74
|
+
export type MutationKeyOptions<TInput> = Pick<MutationOptionsIn<any, TInput, any, any, any>, 'key'>;
|
|
75
|
+
export type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TMutationContext extends Record<any, any>> = (object extends TClientContext ? {
|
|
76
|
+
context?: TClientContext | undefined;
|
|
77
|
+
} : {
|
|
78
|
+
context: TClientContext;
|
|
79
|
+
}) & Omit<UseMutationOptions<TOutput, TInput, TError, TMutationContext>, 'mutation'> & Partial<Pick<UseMutationOptions<TOutput, TInput, TError, TMutationContext>, 'mutation'>>;
|
|
80
|
+
export type MutationOptionsOut<TInput, TOutput, TError, TMutationContext extends Record<any, any>> = DefineMutationOptionsTagged<TOutput, TInput, TError, TMutationContext>;
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The symbol under which Pinia Colada utils attach operation details
|
|
3
|
+
* (key and operation type) to the client context.
|
|
4
|
+
*
|
|
5
|
+
* @see {@link https://orpc.dev/docs/integrations/pinia-colada#client-context | Pinia Colada Integration - Client Context}
|
|
6
|
+
*/
|
|
7
|
+
export const OPERATION_CONTEXT_SYMBOL = /* @__PURE__ */ Symbol.for('ORPC_PINIA_COLADA_OPERATION_CONTEXT');
|
package/package.json
CHANGED
|
@@ -1,59 +1,57 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/pinia-colada",
|
|
3
|
-
"
|
|
4
|
-
"version": "2.0.0-beta.48",
|
|
3
|
+
"version": "2.0.0-beta.49",
|
|
5
4
|
"description": "Pinia Colada integration for oRPC: typesafe queries and mutations for Vue",
|
|
6
|
-
"
|
|
7
|
-
|
|
8
|
-
"
|
|
9
|
-
"
|
|
5
|
+
"keywords": [
|
|
6
|
+
"mutation",
|
|
7
|
+
"orpc",
|
|
8
|
+
"pinia",
|
|
9
|
+
"pinia-colada",
|
|
10
|
+
"query",
|
|
11
|
+
"typesafe",
|
|
12
|
+
"typescript",
|
|
13
|
+
"vue"
|
|
10
14
|
],
|
|
11
15
|
"homepage": "https://orpc.dev",
|
|
16
|
+
"license": "MIT",
|
|
12
17
|
"repository": {
|
|
13
18
|
"type": "git",
|
|
14
19
|
"url": "git+https://github.com/middleapi/orpc.git",
|
|
15
20
|
"directory": "packages/pinia-colada"
|
|
16
21
|
},
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"pinia",
|
|
21
|
-
"pinia-colada",
|
|
22
|
-
"query",
|
|
23
|
-
"mutation",
|
|
24
|
-
"typescript",
|
|
25
|
-
"typesafe"
|
|
22
|
+
"funding": [
|
|
23
|
+
"https://github.com/sponsors/dinwwwh",
|
|
24
|
+
"https://opencollective.com/middleapi"
|
|
26
25
|
],
|
|
26
|
+
"files": [
|
|
27
|
+
"dist"
|
|
28
|
+
],
|
|
29
|
+
"type": "module",
|
|
27
30
|
"sideEffects": false,
|
|
28
31
|
"exports": {
|
|
29
32
|
"./package.json": "./package.json",
|
|
30
33
|
".": {
|
|
31
|
-
"types": "./dist/index.d.
|
|
32
|
-
"import": "./dist/index.
|
|
33
|
-
"default": "./dist/index.
|
|
34
|
+
"types": "./dist/index.d.ts",
|
|
35
|
+
"import": "./dist/index.js",
|
|
36
|
+
"default": "./dist/index.js"
|
|
34
37
|
}
|
|
35
38
|
},
|
|
36
|
-
"files": [
|
|
37
|
-
"dist"
|
|
38
|
-
],
|
|
39
|
-
"peerDependencies": {
|
|
40
|
-
"@pinia/colada": ">=1.2.0",
|
|
41
|
-
"vue": ">=3.5.17"
|
|
42
|
-
},
|
|
43
39
|
"dependencies": {
|
|
44
|
-
"@orpc/client": "2.0.0-beta.
|
|
45
|
-
"@orpc/contract": "2.0.0-beta.
|
|
46
|
-
"@orpc/openapi": "2.0.0-beta.
|
|
47
|
-
"@orpc/shared": "2.0.0-beta.
|
|
40
|
+
"@orpc/client": "2.0.0-beta.49",
|
|
41
|
+
"@orpc/contract": "2.0.0-beta.49",
|
|
42
|
+
"@orpc/openapi": "2.0.0-beta.49",
|
|
43
|
+
"@orpc/shared": "2.0.0-beta.49"
|
|
48
44
|
},
|
|
49
45
|
"devDependencies": {
|
|
50
|
-
"@pinia/colada": "^1.4.
|
|
46
|
+
"@pinia/colada": "^1.4.9",
|
|
51
47
|
"@vue/test-utils": "^2.5.1",
|
|
52
48
|
"pinia": "^4.1.0",
|
|
53
49
|
"vue": "^3.5.44",
|
|
54
50
|
"zod": "^4.6.7"
|
|
55
51
|
},
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
|
|
52
|
+
"peerDependencies": {
|
|
53
|
+
"@pinia/colada": ">=1.4.9",
|
|
54
|
+
"vue": ">=3.5.17"
|
|
55
|
+
},
|
|
56
|
+
"scripts": {}
|
|
59
57
|
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import type { ClientContext } from "@orpc/client";
|
|
2
|
-
import type { ContractClientFactory, RouterContract, RouterContractClient } from "@orpc/contract";
|
|
3
|
-
import type { ContractJsonifiedClientFactory, JsonifiedClient } from "@orpc/openapi";
|
|
4
|
-
import type { RouterUtils, RouterUtilsOptions } from "./router-utils.mjs";
|
|
5
|
-
export interface ContractUtilsFactory<TClientContext extends ClientContext> {
|
|
6
|
-
<T extends RouterContract>(contract: T): RouterUtils<RouterContractClient<T, TClientContext>>;
|
|
7
|
-
}
|
|
8
|
-
export interface ContractUtilsFactoryOptions<TClientContext extends ClientContext> extends Omit<RouterUtilsOptions<RouterContractClient<RouterContract, TClientContext>>, "path"> {}
|
|
9
|
-
/**
|
|
10
|
-
* Creates a factory that builds Pinia Colada utils directly from a contract,
|
|
11
|
-
* using the given contract client factory. Useful for scaling large projects
|
|
12
|
-
* where each part only needs a slice of the router.
|
|
13
|
-
*
|
|
14
|
-
* @remarks
|
|
15
|
-
* **Note**: The contract must define a `path` meta matching its position in the root router contract.
|
|
16
|
-
*
|
|
17
|
-
* @see {@link https://orpc.dev/docs/contract/client-factory#pinia-colada-integration | Contract Client Factory - Pinia Colada Integration}
|
|
18
|
-
*/
|
|
19
|
-
export declare function createContractUtilsFactory<TClientContext extends ClientContext>(clientFactory: ContractClientFactory<TClientContext>, options: ContractUtilsFactoryOptions<TClientContext>): ContractUtilsFactory<TClientContext>;
|
|
20
|
-
export interface ContractJsonifiedUtilsFactory<TClientContext extends ClientContext> {
|
|
21
|
-
<T extends RouterContract>(contract: T): RouterUtils<JsonifiedClient<RouterContractClient<T, TClientContext>>>;
|
|
22
|
-
}
|
|
23
|
-
export interface ContractJsonifiedUtilsFactoryOptions<TClientContext extends ClientContext> extends Omit<RouterUtilsOptions<JsonifiedClient<RouterContractClient<RouterContract, TClientContext>>>, "path"> {}
|
|
24
|
-
/**
|
|
25
|
-
* Like `createContractUtilsFactory`, but for clients whose types are wrapped in `JsonifiedClient`,
|
|
26
|
-
* such as clients using OpenAPI Link.
|
|
27
|
-
*
|
|
28
|
-
* @remarks
|
|
29
|
-
* Takes a client factory created by `createContractJsonifiedClientFactory` from `@orpc/openapi`.
|
|
30
|
-
*
|
|
31
|
-
* **Note**: The contract must define a `path` meta matching its position in the root router contract.
|
|
32
|
-
*
|
|
33
|
-
* @see {@link https://orpc.dev/docs/contract/client-factory#pinia-colada-integration | Contract Client Factory - Pinia Colada Integration}
|
|
34
|
-
*/
|
|
35
|
-
export declare function createContractJsonifiedUtilsFactory<TClientContext extends ClientContext>(clientFactory: ContractJsonifiedClientFactory<TClientContext>, options: ContractJsonifiedUtilsFactoryOptions<TClientContext>): ContractJsonifiedUtilsFactory<TClientContext>;
|
package/dist/contract-utils.mjs
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { resolveBasePathMeta } from "@orpc/contract";
|
|
2
|
-
import { get } from "@orpc/shared";
|
|
3
|
-
import { createRouterUtils } from "./router-utils.mjs";
|
|
4
|
-
|
|
5
|
-
export function createContractUtilsFactory(clientFactory, options) {
|
|
6
|
-
const factory = (contract) => {
|
|
7
|
-
const client = clientFactory(contract);
|
|
8
|
-
const path = resolveBasePathMeta(contract);
|
|
9
|
-
if (path === undefined) {
|
|
10
|
-
throw new TypeError("ContractUtilsFactory: procedure contract must define `meta.path` that matches its path in the root router contract.");
|
|
11
|
-
}
|
|
12
|
-
return createRouterUtils(client, {
|
|
13
|
-
...options,
|
|
14
|
-
path,
|
|
15
|
-
scoped: get(options.scoped, path)
|
|
16
|
-
});
|
|
17
|
-
};
|
|
18
|
-
return factory;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function createContractJsonifiedUtilsFactory(clientFactory, options) {
|
|
22
|
-
return createContractUtilsFactory(clientFactory, options);
|
|
23
|
-
}
|
package/dist/index.d.mts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export * from "./contract-utils.mjs";
|
|
2
|
-
export type { OperationKey, OperationKeyBaseOptions, OperationKeyOptions, OperationKeyPrefixOptions } from "./key.mjs";
|
|
3
|
-
export * from "./meta.mjs";
|
|
4
|
-
export type { RouterUtilsPlugin } from "./plugin.mjs";
|
|
5
|
-
export { mergeProcedureUtilsOptions, ProcedureUtils } from "./procedure-utils.mjs";
|
|
6
|
-
export type { ProcedureUtilsInfiniteInterceptor, ProcedureUtilsInfiniteInterceptorOptions, ProcedureUtilsLiveInterceptor, ProcedureUtilsLiveInterceptorOptions, ProcedureUtilsModifier, ProcedureUtilsMutationInterceptor, ProcedureUtilsMutationInterceptorOptions, ProcedureUtilsOptions, ProcedureUtilsQueryInterceptor, ProcedureUtilsQueryInterceptorOptions, ProcedureUtilsStreamedInterceptor, ProcedureUtilsStreamedInterceptorOptions } from "./procedure-utils.mjs";
|
|
7
|
-
export * from "./router-utils.mjs";
|
|
8
|
-
export {
|
|
9
|
-
/**
|
|
10
|
-
* @deprecated Use `createRouterUtils` instead.
|
|
11
|
-
*/
|
|
12
|
-
createRouterUtils as createORPCVueColadaUtils } from "./router-utils.mjs";
|
|
13
|
-
export { createRouterUtils as createPiniaColadaUtils } from "./router-utils.mjs";
|
|
14
|
-
export { SharedUtils } from "./shared-utils.mjs";
|
|
15
|
-
export type { SerializableStreamedQueryOptions } from "./stream-query.mjs";
|
|
16
|
-
export * from "./types.mjs";
|
|
17
|
-
export { OPERATION_CONTEXT_SYMBOL as PINIA_COLADA_OPERATION_CONTEXT_SYMBOL, type OperationContext as PiniaColadaOperationContext } from "./types.mjs";
|
|
18
|
-
export type { AnyNestedClient } from "@orpc/client";
|
|
19
|
-
export type { Public } from "@orpc/shared";
|
package/dist/index.mjs
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export * from "./contract-utils.mjs";
|
|
2
|
-
export * from "./meta.mjs";
|
|
3
|
-
export { mergeProcedureUtilsOptions, ProcedureUtils } from "./procedure-utils.mjs";
|
|
4
|
-
export * from "./router-utils.mjs";
|
|
5
|
-
export {
|
|
6
|
-
|
|
7
|
-
createRouterUtils as createORPCVueColadaUtils } from "./router-utils.mjs";
|
|
8
|
-
export { createRouterUtils as createPiniaColadaUtils } from "./router-utils.mjs";
|
|
9
|
-
export { SharedUtils } from "./shared-utils.mjs";
|
|
10
|
-
export * from "./types.mjs";
|
|
11
|
-
export { OPERATION_CONTEXT_SYMBOL as PINIA_COLADA_OPERATION_CONTEXT_SYMBOL } from "./types.mjs";
|
package/dist/key.d.mts
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import type { PartialDeep, Public } from "@orpc/shared";
|
|
2
|
-
import type { EntryKey } from "@pinia/colada";
|
|
3
|
-
import type { SerializableStreamedQueryOptions } from "./stream-query.mjs";
|
|
4
|
-
import type { OperationType } from "./types.mjs";
|
|
5
|
-
import { RPCJsonSerializer } from "@orpc/client";
|
|
6
|
-
export interface OperationKeyPrefixOptions {
|
|
7
|
-
/**
|
|
8
|
-
* Prepended as the first element of the key when present.
|
|
9
|
-
* Use this to avoid key conflicts when multiple router utils share the same client.
|
|
10
|
-
*/
|
|
11
|
-
prefix?: string | undefined;
|
|
12
|
-
}
|
|
13
|
-
export interface OperationKeyBaseOptions extends OperationKeyPrefixOptions {
|
|
14
|
-
/**
|
|
15
|
-
* Serializes inputs into JSON-compatible values when building keys.
|
|
16
|
-
* Pass the serializer your link uses so custom types produce consistent keys.
|
|
17
|
-
*
|
|
18
|
-
* @default new RPCJsonSerializer()
|
|
19
|
-
*/
|
|
20
|
-
serializer?: Public<RPCJsonSerializer> | undefined;
|
|
21
|
-
}
|
|
22
|
-
export type OperationKeyOptions<
|
|
23
|
-
TType extends OperationType,
|
|
24
|
-
TInput
|
|
25
|
-
> = OperationKeyBaseOptions & {
|
|
26
|
-
type?: TType | undefined;
|
|
27
|
-
input?: PartialDeep<TInput> | undefined;
|
|
28
|
-
fnOptions?: (TType extends "streamed" ? SerializableStreamedQueryOptions : never) | undefined;
|
|
29
|
-
};
|
|
30
|
-
type OperationKeyContent<
|
|
31
|
-
TType extends OperationType,
|
|
32
|
-
TInput
|
|
33
|
-
> = Omit<OperationKeyOptions<TType, TInput>, keyof OperationKeyBaseOptions> & {
|
|
34
|
-
/**
|
|
35
|
-
* Serializer types of non-JSON values in `input`, keyed by their JSON-encoded path,
|
|
36
|
-
* so inputs with the same JSON form (like a `Date` and its ISO string) produce different keys.
|
|
37
|
-
* Keyed by path (not a list) so partial keys still match.
|
|
38
|
-
*/
|
|
39
|
-
inputMeta?: Record<string, string[]> | undefined;
|
|
40
|
-
};
|
|
41
|
-
export type OperationKey<
|
|
42
|
-
TType extends OperationType,
|
|
43
|
-
TInput
|
|
44
|
-
> = EntryKey & ([path: string[], options: OperationKeyContent<TType, TInput>] | [prefix: string, path: string[], options: OperationKeyContent<TType, TInput>]);
|
|
45
|
-
/**
|
|
46
|
-
* Generate a Pinia Colada entry key for a procedure.
|
|
47
|
-
*
|
|
48
|
-
* The input is serialized to JSON-compatible values because Pinia Colada
|
|
49
|
-
* requires entry keys to be serializable.
|
|
50
|
-
*
|
|
51
|
-
* @see {@link https://orpc.dev/docs/integrations/pinia-colada#querymutation-key | Pinia Colada Integration - Query/Mutation Key}
|
|
52
|
-
*/
|
|
53
|
-
export declare function generateOperationKey<
|
|
54
|
-
TType extends OperationType,
|
|
55
|
-
TInput
|
|
56
|
-
>(path: string[], options?: OperationKeyOptions<TType, TInput>): OperationKey<TType, TInput>;
|
|
57
|
-
export {};
|
package/dist/key.mjs
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { RPCJsonSerializer } from "@orpc/client";
|
|
2
|
-
import { stringifyJSON } from "@orpc/shared";
|
|
3
|
-
const defaultSerializer = /* @__PURE__ */ new RPCJsonSerializer();
|
|
4
|
-
|
|
5
|
-
export function generateOperationKey(path, options = {}) {
|
|
6
|
-
return [
|
|
7
|
-
...options.prefix !== undefined ? [options.prefix] : [],
|
|
8
|
-
path,
|
|
9
|
-
{
|
|
10
|
-
...options.input !== undefined ? serializeInput(options.serializer ?? defaultSerializer, options.input) : {},
|
|
11
|
-
...options.type !== undefined ? { type: options.type } : {},
|
|
12
|
-
...options.fnOptions !== undefined ? { fnOptions: options.fnOptions } : {}
|
|
13
|
-
}
|
|
14
|
-
];
|
|
15
|
-
}
|
|
16
|
-
function serializeInput(serializer, input) {
|
|
17
|
-
const { json, meta } = serializer.serializeJson(input);
|
|
18
|
-
if (!meta?.length) {
|
|
19
|
-
return { input: json };
|
|
20
|
-
}
|
|
21
|
-
const inputMeta = {};
|
|
22
|
-
for (const [type, ...segments] of meta) {
|
|
23
|
-
(inputMeta[stringifyJSON(segments)] ??= []).push(type);
|
|
24
|
-
}
|
|
25
|
-
return {
|
|
26
|
-
input: json,
|
|
27
|
-
inputMeta
|
|
28
|
-
};
|
|
29
|
-
}
|
package/dist/live-query.d.mts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { Promisable } from "@orpc/shared";
|
|
2
|
-
import type { UseQueryFnContext } from "./types.mjs";
|
|
3
|
-
/**
|
|
4
|
-
* A Pinia Colada query function that publishes each streamed chunk to the
|
|
5
|
-
* cache entry as it arrives, replacing the previous value.
|
|
6
|
-
*/
|
|
7
|
-
export declare function liveQuery<T>(queryFn: (context: UseQueryFnContext) => Promisable<AsyncIterable<T>>): (context: UseQueryFnContext) => Promise<T>;
|
package/dist/live-query.mjs
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { stringifyJSON } from "@orpc/shared";
|
|
2
|
-
|
|
3
|
-
export function liveQuery(queryFn) {
|
|
4
|
-
return async (context) => {
|
|
5
|
-
const { entry, signal } = context;
|
|
6
|
-
const stream = await queryFn(context);
|
|
7
|
-
let last;
|
|
8
|
-
for await (const chunk of stream) {
|
|
9
|
-
if (signal.aborted) {
|
|
10
|
-
throw signal.reason;
|
|
11
|
-
}
|
|
12
|
-
last = { chunk };
|
|
13
|
-
entry.state.value = {
|
|
14
|
-
status: "success",
|
|
15
|
-
data: chunk,
|
|
16
|
-
error: null
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
if (!last) {
|
|
20
|
-
throw new TypeError(`Live query for ${stringifyJSON(entry.key)} did not yield any data. Ensure the query function returns an AsyncIterable with at least one chunk.`);
|
|
21
|
-
}
|
|
22
|
-
return last.chunk;
|
|
23
|
-
};
|
|
24
|
-
}
|