@orpc/pinia-colada 2.0.0-beta.48 → 2.0.0-beta.50
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 +35 -0
- package/dist/contract-utils.js +42 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +7 -0
- package/dist/key.d.ts +36 -0
- package/dist/key.js +45 -0
- package/dist/live-query.js +34 -0
- package/dist/meta.d.ts +42 -0
- package/dist/meta.js +53 -0
- package/dist/plugin.d.ts +39 -0
- package/dist/plugin.js +19 -0
- package/dist/procedure-utils.d.ts +187 -0
- package/dist/procedure-utils.js +383 -0
- package/dist/router-utils.d.ts +62 -0
- package/dist/router-utils.js +54 -0
- package/dist/shared-utils.d.ts +13 -0
- package/dist/shared-utils.js +23 -0
- package/dist/ssr.d.ts +22 -0
- package/dist/ssr.js +22 -0
- package/dist/stream-query.d.ts +33 -0
- package/dist/stream-query.js +47 -0
- package/dist/types.d.ts +80 -0
- package/dist/types.js +9 -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
package/dist/router-utils.mjs
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { RECURSIVE_CLIENT_UNWRAP_KEYS } from "@orpc/client";
|
|
2
|
-
import { bindMethods, isTypescriptObject, pick, toArray } from "@orpc/shared";
|
|
3
|
-
import { CompositeRouterUtilsPlugin } from "./plugin.mjs";
|
|
4
|
-
import { isProcedureUtilsOptions, mergeProcedureUtilsOptions, ProcedureUtils } from "./procedure-utils.mjs";
|
|
5
|
-
import { SharedUtils } from "./shared-utils.mjs";
|
|
6
|
-
|
|
7
|
-
export function createRouterUtils(client, options = {}) {
|
|
8
|
-
const plugin = new CompositeRouterUtilsPlugin(options.plugins);
|
|
9
|
-
options = plugin.init(options);
|
|
10
|
-
return createRouterUtilsInternal(client, options, plugin);
|
|
11
|
-
}
|
|
12
|
-
function createRouterUtilsInternal(client, options, plugin) {
|
|
13
|
-
const path = toArray(options.path);
|
|
14
|
-
const utils = typeof client === "function" && (options.scoped === undefined || isProcedureUtilsOptions(options.scoped)) ? bindMethods(new ProcedureUtils(path, client, plugin.initProcedureOptions(path, mergeProcedureUtilsOptions(pick(options, [
|
|
15
|
-
"prefix",
|
|
16
|
-
"serializer",
|
|
17
|
-
"queryInterceptors",
|
|
18
|
-
"streamedInterceptors",
|
|
19
|
-
"liveInterceptors",
|
|
20
|
-
"infiniteInterceptors",
|
|
21
|
-
"mutationInterceptors"
|
|
22
|
-
]), options.scoped ?? {}))), { unbound: ["call"] }) : bindMethods(new SharedUtils(path, options));
|
|
23
|
-
const cache = new Map();
|
|
24
|
-
const recursive = new Proxy(utils, { get(target, prop) {
|
|
25
|
-
const value = Reflect.get(target, prop);
|
|
26
|
-
if (RECURSIVE_CLIENT_UNWRAP_KEYS.has(prop)) {
|
|
27
|
-
return value ?? Reflect.get(Object.prototype, prop);
|
|
28
|
-
}
|
|
29
|
-
const nextClient = Reflect.get(client, prop);
|
|
30
|
-
if (typeof prop !== "string" || !isTypescriptObject(nextClient)) {
|
|
31
|
-
return value;
|
|
32
|
-
}
|
|
33
|
-
let result = cache.get(prop);
|
|
34
|
-
if (result === undefined) {
|
|
35
|
-
const nextUtils = createRouterUtilsInternal(nextClient, {
|
|
36
|
-
...options,
|
|
37
|
-
path: [...path, prop],
|
|
38
|
-
scoped: options.scoped?.[prop]
|
|
39
|
-
}, plugin);
|
|
40
|
-
result = typeof value !== "function" ? nextUtils : new Proxy(value, { get(target, prop) {
|
|
41
|
-
if (typeof prop !== "string" || RECURSIVE_CLIENT_UNWRAP_KEYS.has(prop)) {
|
|
42
|
-
return Reflect.get(target, prop);
|
|
43
|
-
}
|
|
44
|
-
return Reflect.get(nextUtils, prop);
|
|
45
|
-
} });
|
|
46
|
-
cache.set(prop, result);
|
|
47
|
-
}
|
|
48
|
-
return result;
|
|
49
|
-
} });
|
|
50
|
-
return recursive;
|
|
51
|
-
}
|
package/dist/shared-utils.d.mts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { OperationKey, OperationKeyBaseOptions, OperationKeyOptions } from "./key.mjs";
|
|
2
|
-
import type { OperationType } from "./types.mjs";
|
|
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
|
-
}
|
package/dist/shared-utils.mjs
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { generateOperationKey } from "./key.mjs";
|
|
2
|
-
export class SharedUtils {
|
|
3
|
-
path;
|
|
4
|
-
options;
|
|
5
|
-
constructor(path, options) {
|
|
6
|
-
this.path = path;
|
|
7
|
-
this.options = options;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
key(options = {}) {
|
|
11
|
-
return generateOperationKey(this.path, {
|
|
12
|
-
...options,
|
|
13
|
-
prefix: this.options.prefix,
|
|
14
|
-
serializer: this.options.serializer
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
}
|
package/dist/stream-query.d.mts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { Promisable } from "@orpc/shared";
|
|
2
|
-
import type { UseQueryFnContext } from "./types.mjs";
|
|
3
|
-
export interface SerializableStreamedQueryOptions {
|
|
4
|
-
/**
|
|
5
|
-
* Determines how data is handled when the query is fetched again
|
|
6
|
-
*
|
|
7
|
-
* - `'reset'`: Clears existing data and returns the query to a pending state.
|
|
8
|
-
* - `'append'`: Adds new streamed chunks to the existing data.
|
|
9
|
-
* - `'replace'`: Buffers streamed data and replaces the cache after the stream completes.
|
|
10
|
-
*
|
|
11
|
-
* @default 'reset'
|
|
12
|
-
*/
|
|
13
|
-
refetchMode?: "append" | "reset" | "replace" | 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
|
-
/**
|
|
23
|
-
* A Pinia Colada query function that accumulates streamed chunks into an array,
|
|
24
|
-
* publishing each chunk to the cache entry as it arrives.
|
|
25
|
-
*
|
|
26
|
-
* Inspired by [TanStack Query streamedQuery](https://tanstack.com/query/latest/docs/reference/streamedQuery) where:
|
|
27
|
-
* - Options are serializable
|
|
28
|
-
* - The output is predictable
|
|
29
|
-
*/
|
|
30
|
-
export declare function serializableStreamedQuery<T>(queryFn: (context: UseQueryFnContext) => Promisable<AsyncIterable<T>>, { refetchMode, maxChunks }?: SerializableStreamedQueryOptions): (context: UseQueryFnContext) => Promise<T[]>;
|
package/dist/stream-query.mjs
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
export function serializableStreamedQuery(queryFn, { refetchMode = "reset", maxChunks = Number.POSITIVE_INFINITY } = {}) {
|
|
3
|
-
return async (context) => {
|
|
4
|
-
const { entry, signal } = context;
|
|
5
|
-
const previousData = entry.state.value.data;
|
|
6
|
-
const hasPreviousData = previousData !== undefined;
|
|
7
|
-
if (hasPreviousData && refetchMode === "reset") {
|
|
8
|
-
entry.state.value = {
|
|
9
|
-
status: "pending",
|
|
10
|
-
data: undefined,
|
|
11
|
-
error: null
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
const stream = await queryFn(context);
|
|
15
|
-
const shouldUpdateCacheDuringStream = !hasPreviousData || refetchMode !== "replace";
|
|
16
|
-
let result = hasPreviousData && refetchMode === "append" ? limitArraySize(previousData, maxChunks) : [];
|
|
17
|
-
if (shouldUpdateCacheDuringStream) {
|
|
18
|
-
entry.state.value = {
|
|
19
|
-
status: "success",
|
|
20
|
-
data: result,
|
|
21
|
-
error: null
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
for await (const chunk of stream) {
|
|
25
|
-
if (signal.aborted) {
|
|
26
|
-
throw signal.reason;
|
|
27
|
-
}
|
|
28
|
-
result = limitArraySize([...result, chunk], maxChunks);
|
|
29
|
-
if (shouldUpdateCacheDuringStream) {
|
|
30
|
-
entry.state.value = {
|
|
31
|
-
status: "success",
|
|
32
|
-
data: result,
|
|
33
|
-
error: null
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
return result;
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
function limitArraySize(items, maxSize) {
|
|
41
|
-
if (items.length <= maxSize) {
|
|
42
|
-
return items;
|
|
43
|
-
}
|
|
44
|
-
return items.slice(items.length - maxSize);
|
|
45
|
-
}
|
package/dist/types.d.mts
DELETED
|
@@ -1,125 +0,0 @@
|
|
|
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 } from "./stream-query.mjs";
|
|
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<
|
|
40
|
-
TClientContext extends ClientContext,
|
|
41
|
-
TInput,
|
|
42
|
-
TOutput,
|
|
43
|
-
TError,
|
|
44
|
-
TInitialData extends TOutput | undefined
|
|
45
|
-
> = (undefined extends TInput ? {
|
|
46
|
-
input?: TInput;
|
|
47
|
-
} : {
|
|
48
|
-
input: TInput;
|
|
49
|
-
}) & (object extends TClientContext ? {
|
|
50
|
-
context?: TClientContext | undefined;
|
|
51
|
-
} : {
|
|
52
|
-
context: TClientContext;
|
|
53
|
-
}) & Omit<DefineQueryOptions<TOutput, TError, TInitialData>, "key" | "query"> & Partial<Pick<DefineQueryOptions<TOutput, TError, TInitialData>, "key" | "query">>;
|
|
54
|
-
export type QueryOptionsOut<
|
|
55
|
-
TOutput,
|
|
56
|
-
TError,
|
|
57
|
-
TInitialData extends TOutput | undefined
|
|
58
|
-
> = DefineQueryOptionsTagged<TOutput, TError, TInitialData>;
|
|
59
|
-
export type StreamedKeyOptions<TInput> = (undefined extends TInput ? {
|
|
60
|
-
input?: TInput;
|
|
61
|
-
} : {
|
|
62
|
-
input: TInput;
|
|
63
|
-
}) & {
|
|
64
|
-
fnOptions?: SerializableStreamedQueryOptions | undefined;
|
|
65
|
-
} | {
|
|
66
|
-
key: EntryKey;
|
|
67
|
-
};
|
|
68
|
-
export type StreamedOptionsIn<
|
|
69
|
-
TClientContext extends ClientContext,
|
|
70
|
-
TInput,
|
|
71
|
-
TOutput,
|
|
72
|
-
TError,
|
|
73
|
-
TInitialData extends TOutput | undefined
|
|
74
|
-
> = QueryOptionsIn<TClientContext, TInput, TOutput, TError, TInitialData> & {
|
|
75
|
-
fnOptions?: SerializableStreamedQueryOptions | undefined;
|
|
76
|
-
};
|
|
77
|
-
export type StreamedOptionsOut<
|
|
78
|
-
TOutput,
|
|
79
|
-
TError,
|
|
80
|
-
TInitialData extends TOutput | undefined
|
|
81
|
-
> = QueryOptionsOut<TOutput, TError, TInitialData>;
|
|
82
|
-
export type InfiniteKeyOptions<
|
|
83
|
-
TInput,
|
|
84
|
-
TPageParam
|
|
85
|
-
> = Pick<InfiniteOptionsIn<any, TInput, any, any, TPageParam, any>, "input" | "initialPageParam"> | {
|
|
86
|
-
key: EntryKey;
|
|
87
|
-
};
|
|
88
|
-
export type InfiniteOptionsIn<
|
|
89
|
-
TClientContext extends ClientContext,
|
|
90
|
-
TInput,
|
|
91
|
-
TOutput,
|
|
92
|
-
TError,
|
|
93
|
-
TPageParam,
|
|
94
|
-
TInitialData extends UseInfiniteQueryData<TOutput, TPageParam> | undefined
|
|
95
|
-
> = {
|
|
96
|
-
input: (pageParam: TPageParam) => TInput;
|
|
97
|
-
} & (object extends TClientContext ? {
|
|
98
|
-
context?: TClientContext | undefined;
|
|
99
|
-
} : {
|
|
100
|
-
context: TClientContext;
|
|
101
|
-
}) & Omit<DefineInfiniteQueryOptions<TOutput, TError, TPageParam, TInitialData>, "key" | "query"> & Partial<Pick<DefineInfiniteQueryOptions<TOutput, TError, TPageParam, TInitialData>, "key" | "query">>;
|
|
102
|
-
export type InfiniteOptionsOut<
|
|
103
|
-
TOutput,
|
|
104
|
-
TError,
|
|
105
|
-
TPageParam,
|
|
106
|
-
TInitialData extends UseInfiniteQueryData<TOutput, TPageParam> | undefined
|
|
107
|
-
> = DefineInfiniteQueryOptionsTagged<TOutput, TError, TPageParam, TInitialData>;
|
|
108
|
-
export type MutationKeyOptions<TInput> = Pick<MutationOptionsIn<any, TInput, any, any, any>, "key">;
|
|
109
|
-
export type MutationOptionsIn<
|
|
110
|
-
TClientContext extends ClientContext,
|
|
111
|
-
TInput,
|
|
112
|
-
TOutput,
|
|
113
|
-
TError,
|
|
114
|
-
TMutationContext extends Record<any, any>
|
|
115
|
-
> = (object extends TClientContext ? {
|
|
116
|
-
context?: TClientContext | undefined;
|
|
117
|
-
} : {
|
|
118
|
-
context: TClientContext;
|
|
119
|
-
}) & Omit<UseMutationOptions<TOutput, TInput, TError, TMutationContext>, "mutation"> & Partial<Pick<UseMutationOptions<TOutput, TInput, TError, TMutationContext>, "mutation">>;
|
|
120
|
-
export type MutationOptionsOut<
|
|
121
|
-
TInput,
|
|
122
|
-
TOutput,
|
|
123
|
-
TError,
|
|
124
|
-
TMutationContext extends Record<any, any>
|
|
125
|
-
> = DefineMutationOptionsTagged<TOutput, TInput, TError, TMutationContext>;
|
package/dist/types.mjs
DELETED