@orpc/pinia-colada 0.0.0 → 1.14.11
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 +3 -2
- package/dist/index.d.mts +56 -6
- package/dist/index.d.ts +56 -6
- package/dist/index.mjs +117 -34
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -52,6 +52,7 @@ You can read the documentation [here](https://orpc.dev).
|
|
|
52
52
|
- [@orpc/ai-sdk](https://www.npmjs.com/package/@orpc/ai-sdk): Turn contracts and procedures into [AI SDK](https://ai-sdk.dev/) tools.
|
|
53
53
|
- [@orpc/tanstack-query](https://www.npmjs.com/package/@orpc/tanstack-query): Integrate with [TanStack Query](https://tanstack.com/query/latest).
|
|
54
54
|
- [@orpc/pinia-colada](https://www.npmjs.com/package/@orpc/pinia-colada): Integrate with [Pinia Colada](https://pinia-colada.esm.dev/).
|
|
55
|
+
- [@orpc/swr](https://www.npmjs.com/package/@orpc/swr): Integrate with [SWR](https://swr.vercel.app/).
|
|
55
56
|
- [@orpc/experimental-effect](https://www.npmjs.com/package/@orpc/experimental-effect): Integrate with [Effect](https://effect.website/).
|
|
56
57
|
- [@orpc/nest](https://www.npmjs.com/package/@orpc/nest): Implement your contract with [NestJS](https://nestjs.com/).
|
|
57
58
|
- [@orpc/bun](https://www.npmjs.com/package/@orpc/bun): Adapters for [Bun's Redis](https://bun.sh/).
|
|
@@ -108,11 +109,10 @@ Like what we build over at [middleapi](https://github.com/middleapi)? You can he
|
|
|
108
109
|
<td align="center"><a href="https://github.com/valerii15298?ref=orpc" target="_blank" rel="noopener" title="Valerii Petryniak"><img src="https://avatars.githubusercontent.com/u/44531564?u=88ac74d9bacd20401518441907acad21063cd397&v=4" width="139" alt="Valerii Petryniak"/><br />Valerii Petryniak</a></td>
|
|
109
110
|
<td align="center"><a href="https://github.com/letstri?ref=orpc" target="_blank" rel="noopener" title="Valerii Strilets"><img src="https://avatars.githubusercontent.com/u/13253748?u=c7b10399ccc8f8081e24db94ec32cd9858e86ac3&v=4" width="139" alt="Valerii Strilets"/><br />Valerii Strilets</a></td>
|
|
110
111
|
<td align="center"><a href="https://github.com/K-Mistele?ref=orpc" target="_blank" rel="noopener" title="Kyle Mistele"><img src="https://avatars.githubusercontent.com/u/18430555?u=3afebeb81de666e35aaac3ed46f14159d7603ffb&v=4" width="139" alt="Kyle Mistele"/><br />Kyle Mistele</a></td>
|
|
111
|
-
<td align="center"><a href="https://github.com/R44VC0RP?ref=orpc" target="_blank" rel="noopener" title="Ryan Vogel"><img src="https://avatars.githubusercontent.com/u/89211796?u=1857347b9787d8d8a7ea5bfc333f96be92d5a683&v=4" width="139" alt="Ryan Vogel"/><br />Ryan Vogel</a></td>
|
|
112
112
|
<td align="center"><a href="https://github.com/christ12938?ref=orpc" target="_blank" rel="noopener" title="christ12938"><img src="https://avatars.githubusercontent.com/u/25758598?v=4" width="139" alt="christ12938"/><br />christ12938</a></td>
|
|
113
|
+
<td align="center"><a href="https://github.com/Ryanjso?ref=orpc" target="_blank" rel="noopener" title="Ryan Soderberg"><img src="https://avatars.githubusercontent.com/u/39172778?u=5ed913c31d57e7221b75784abcad48c7ebddde27&v=4" width="139" alt="Ryan Soderberg"/><br />Ryan Soderberg</a></td>
|
|
113
114
|
</tr>
|
|
114
115
|
<tr>
|
|
115
|
-
<td align="center"><a href="https://github.com/Ryanjso?ref=orpc" target="_blank" rel="noopener" title="Ryan Soderberg"><img src="https://avatars.githubusercontent.com/u/39172778?u=5ed913c31d57e7221b75784abcad48c7ebddde27&v=4" width="139" alt="Ryan Soderberg"/><br />Ryan Soderberg</a></td>
|
|
116
116
|
<td align="center"><a href="https://github.com/itigoore01?ref=orpc" target="_blank" rel="noopener" title="shota"><img src="https://avatars.githubusercontent.com/u/11831107?u=c976a6dc7e055eb026304c46c99100ed22b0c8e0&v=4" width="139" alt="shota"/><br />shota</a></td>
|
|
117
117
|
</tr>
|
|
118
118
|
</table>
|
|
@@ -172,6 +172,7 @@ Like what we build over at [middleapi](https://github.com/middleapi)? You can he
|
|
|
172
172
|
<a href="https://github.com/nguyenlc1993?ref=orpc" target="_blank" rel="noopener" title="Lê Cao Nguyên"><img src="https://avatars.githubusercontent.com/u/13871971?u=83c8b69d9e35b589c4e1f066cc113b1d9461386f&v=4" width="32" height="32" alt="Lê Cao Nguyên" /></a>
|
|
173
173
|
<a href="https://github.com/wobsoriano?ref=orpc" target="_blank" rel="noopener" title="Robert Soriano"><img src="https://avatars.githubusercontent.com/u/13049130?u=6d72104182e7c9ed25934815313fb69107332111&v=4" width="32" height="32" alt="Robert Soriano" /></a>
|
|
174
174
|
<a href="https://github.com/andrewpeters9?ref=orpc" target="_blank" rel="noopener" title="Andrew Peters"><img src="https://avatars.githubusercontent.com/u/36251325?v=4" width="32" height="32" alt="Andrew Peters" /></a>
|
|
175
|
+
<a href="https://github.com/R44VC0RP?ref=orpc" target="_blank" rel="noopener" title="Ryan Vogel"><img src="https://avatars.githubusercontent.com/u/89211796?u=1857347b9787d8d8a7ea5bfc333f96be92d5a683&v=4" width="32" height="32" alt="Ryan Vogel" /></a>
|
|
175
176
|
<a href="https://github.com/SKostyukovich?ref=orpc" target="_blank" rel="noopener" title="SKostyukovich"><img src="https://avatars.githubusercontent.com/u/10700067?v=4" width="32" height="32" alt="SKostyukovich" /></a>
|
|
176
177
|
<a href="https://github.com/peter-adam-dy?ref=orpc" target="_blank" rel="noopener" title="Peter Adam"><img src="https://avatars.githubusercontent.com/u/132129459?u=4f3dbbb3b443990b56acb7d6a5d11ed2c555f6db&v=4" width="32" height="32" alt="Peter Adam" /></a>
|
|
177
178
|
<a href="https://github.com/FabworksHQ?ref=orpc" target="_blank" rel="noopener" title="Fabworks"><img src="https://avatars.githubusercontent.com/u/160179500?v=4" width="32" height="32" alt="Fabworks" /></a>
|
package/dist/index.d.mts
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import { ClientContext, Client, AnyNestedClient, InferClientContext, InferClientError } from '@orpc/client';
|
|
2
|
-
import { RouterContract, RouterContractClient, ContractClientFactory } from '@orpc/contract';
|
|
2
|
+
import { RouterContract, RouterContractClient, ContractClientFactory, AnySchema, ErrorMap, MetaPlugin, Meta, InferSchemaInput, InferSchemaOutput, ORPCErrorFromErrorMap } from '@orpc/contract';
|
|
3
3
|
import { JsonifiedClient } from '@orpc/openapi';
|
|
4
|
-
import { Promisable, PartialDeep, Interceptor, PromiseWithError, MaybeOptionalOptions, OrderablePlugin, Public } from '@orpc/shared';
|
|
5
|
-
import { EntryKey, UseQueryOptions,
|
|
4
|
+
import { Promisable, PartialDeep, Interceptor, PromiseWithError, MaybeOptionalOptions, OrderablePlugin, Public, ThrowableError } from '@orpc/shared';
|
|
5
|
+
import { EntryKey, UseQueryOptions, UseMutationOptionsGlobal, DefineQueryOptions, UseInfiniteQueryData, DefineInfiniteQueryOptions, UseMutationOptions, DefineQueryOptionsTagged, DefineInfiniteQueryOptionsTagged, DefineMutationOptionsTagged, UseInfiniteQueryFnContext, EntryKeyTagged, _EmptyObject } from '@pinia/colada';
|
|
6
6
|
|
|
7
7
|
type InferStreamedQueryOutput<TOutput> = TOutput extends AsyncIterable<infer U> ? U[] : never;
|
|
8
8
|
type InferLiveQueryOutput<TOutput> = TOutput extends AsyncIterable<infer U> ? U : never;
|
|
9
9
|
type UseQueryFnContext = Parameters<UseQueryOptions<any>['query']>[0];
|
|
10
|
-
|
|
10
|
+
/**
|
|
11
|
+
* The context passed to the mutation function, including the merged
|
|
12
|
+
* `UseMutationGlobalContext` values provided by a global `onMutate` hook.
|
|
13
|
+
*/
|
|
14
|
+
type UseMutationFnContext = Parameters<NonNullable<UseMutationOptionsGlobal['onSuccess']>>[2];
|
|
11
15
|
declare const OPERATION_CONTEXT_SYMBOL: unique symbol;
|
|
12
16
|
type OperationType = 'query' | 'streamed' | 'live' | 'infinite' | 'mutation';
|
|
13
17
|
interface OperationContext {
|
|
@@ -233,6 +237,15 @@ interface ProcedureUtilsOptions<TClientContext extends ClientContext, TInput, TO
|
|
|
233
237
|
*/
|
|
234
238
|
mutationOptions?: ProcedureUtilsModifier<MutationOptionsIn<TClientContext, TInput, TOutput, TError, Record<any, any>>>;
|
|
235
239
|
}
|
|
240
|
+
declare function isProcedureUtilsOptions(value: unknown): value is ProcedureUtilsOptions<any, any, any, any>;
|
|
241
|
+
/**
|
|
242
|
+
* Merge two procedure utils options where `override` takes priority.
|
|
243
|
+
* A key explicitly set to `undefined` in `override` resets the base value.
|
|
244
|
+
* When both sides define a key: interceptors are concatenated (base ones run first),
|
|
245
|
+
* modifiers are spread-merged when both are plain objects and composed (base applied
|
|
246
|
+
* first) otherwise, with plain objects applied as regular spread merges.
|
|
247
|
+
*/
|
|
248
|
+
declare function mergeProcedureUtilsOptions<TClientContext extends ClientContext, TInput, TOutput, TError>(base: ProcedureUtilsOptions<TClientContext, TInput, TOutput, TError>, override: ProcedureUtilsOptions<TClientContext, TInput, TOutput, TError>): ProcedureUtilsOptions<TClientContext, TInput, TOutput, TError>;
|
|
236
249
|
declare class ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError> extends SharedUtils<TInput> {
|
|
237
250
|
protected readonly options: ProcedureUtilsOptions<TClientContext, TInput, TOutput, TError>;
|
|
238
251
|
/**
|
|
@@ -418,5 +431,42 @@ declare function createContractJsonifiedUtilsFactory<TClientContext extends Clie
|
|
|
418
431
|
*/
|
|
419
432
|
declare function liveQuery<T>(queryFn: (context: UseQueryFnContext) => Promisable<AsyncIterable<T>>): (context: UseQueryFnContext) => Promise<T>;
|
|
420
433
|
|
|
421
|
-
|
|
422
|
-
|
|
434
|
+
type PiniaColadaMetaOptions<TClientContext extends ClientContext, TInput, TOutput, TError> = Omit<ProcedureUtilsOptions<TClientContext, TInput, TOutput, TError>, 'prefix'>;
|
|
435
|
+
interface PiniaColadaMetaPlugin<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> extends MetaPlugin<TInputSchema, TOutputSchema, TErrorMap> {
|
|
436
|
+
name: '~pinia-colada';
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* Define base Pinia Colada options and interceptors on a procedure contract.
|
|
440
|
+
* Applied multiple times, later options are spread-merged with higher priority
|
|
441
|
+
* while interceptors are concatenated. A key explicitly set to `undefined`
|
|
442
|
+
* resets the value from earlier applications instead of merging.
|
|
443
|
+
*
|
|
444
|
+
* Apply them to router utils with {@link ContractOptionsUtilsPlugin}.
|
|
445
|
+
*
|
|
446
|
+
* @see {@link https://orpc.dev/docs/integrations/pinia-colada#contract-options-plugin Pinia Colada Contract Options Plugin Docs}
|
|
447
|
+
*/
|
|
448
|
+
declare function piniaColada<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap>(options: PiniaColadaMetaOptions<ClientContext, InferSchemaInput<TInputSchema>, InferSchemaOutput<TOutputSchema>, ORPCErrorFromErrorMap<TErrorMap> | ThrowableError>): PiniaColadaMetaPlugin<TInputSchema, TOutputSchema, TErrorMap>;
|
|
449
|
+
declare function getPiniaColadaMeta(procedureOrLazy: {
|
|
450
|
+
'~orpc': {
|
|
451
|
+
meta: Meta;
|
|
452
|
+
};
|
|
453
|
+
}): PiniaColadaMetaOptions<ClientContext, unknown, unknown, ThrowableError> | undefined;
|
|
454
|
+
/**
|
|
455
|
+
* Router utils plugin that applies base options defined via {@link piniaColada}
|
|
456
|
+
* on the given router contract. Meta options act as the base layer: options defined
|
|
457
|
+
* on the utils override them, and utils interceptors run after meta interceptors.
|
|
458
|
+
*
|
|
459
|
+
* The contract shape must match the client the utils are created from,
|
|
460
|
+
* so pass the root router contract when utils paths start from the root.
|
|
461
|
+
*
|
|
462
|
+
* @see {@link https://orpc.dev/docs/integrations/pinia-colada#contract-options-plugin Pinia Colada Contract Options Plugin Docs}
|
|
463
|
+
*/
|
|
464
|
+
declare class ContractOptionsUtilsPlugin<T extends AnyNestedClient = AnyNestedClient> implements RouterUtilsPlugin<T> {
|
|
465
|
+
private readonly contract;
|
|
466
|
+
readonly name = "~contract-options";
|
|
467
|
+
constructor(contract: RouterContract);
|
|
468
|
+
initProcedureOptions(path: string[], options: ProcedureUtilsOptions<InferClientContext<T>, any, any, InferClientError<T>>): ProcedureUtilsOptions<InferClientContext<T>, any, any, InferClientError<T>>;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
export { CompositeRouterUtilsPlugin, ContractOptionsUtilsPlugin, OPERATION_CONTEXT_SYMBOL, OPERATION_CONTEXT_SYMBOL as PINIA_COLADA_OPERATION_CONTEXT_SYMBOL, ProcedureUtils, SharedUtils, createContractJsonifiedUtilsFactory, createContractUtilsFactory, createRouterUtils as createPiniaColadaUtils, createRouterUtils, generateOperationKey, getPiniaColadaMeta, isProcedureUtilsOptions, liveQuery, mergeProcedureUtilsOptions, piniaColada, serializableStreamedQuery };
|
|
472
|
+
export type { ContractJsonifiedUtilsFactory, ContractJsonifiedUtilsFactoryOptions, ContractUtilsFactory, ContractUtilsFactoryOptions, InferLiveQueryOutput, InferStreamedQueryOutput, InfiniteKeyOptions, InfiniteOptionsIn, InfiniteOptionsOut, MutationKeyOptions, MutationOptionsIn, MutationOptionsOut, OperationContext, OperationKey, OperationKeyOptions, OperationKeyPrefixOptions, OperationType, PiniaColadaMetaOptions, PiniaColadaMetaPlugin, OperationContext as PiniaColadaOperationContext, ProcedureUtilsInfiniteInterceptor, ProcedureUtilsInfiniteInterceptorOptions, ProcedureUtilsLiveInterceptor, ProcedureUtilsLiveInterceptorOptions, ProcedureUtilsModifier, ProcedureUtilsMutationInterceptor, ProcedureUtilsMutationInterceptorOptions, ProcedureUtilsOptions, ProcedureUtilsQueryInterceptor, ProcedureUtilsQueryInterceptorOptions, ProcedureUtilsStreamedInterceptor, ProcedureUtilsStreamedInterceptorOptions, QueryKeyOptions, QueryOptionsIn, QueryOptionsOut, RouterUtils, RouterUtilsOptions, RouterUtilsPlugin, RouterUtilsScoped, SerializableStreamedQueryOptions, StreamedKeyOptions, StreamedOptionsIn, StreamedOptionsOut, UseMutationFnContext, UseQueryFnContext };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import { ClientContext, Client, AnyNestedClient, InferClientContext, InferClientError } from '@orpc/client';
|
|
2
|
-
import { RouterContract, RouterContractClient, ContractClientFactory } from '@orpc/contract';
|
|
2
|
+
import { RouterContract, RouterContractClient, ContractClientFactory, AnySchema, ErrorMap, MetaPlugin, Meta, InferSchemaInput, InferSchemaOutput, ORPCErrorFromErrorMap } from '@orpc/contract';
|
|
3
3
|
import { JsonifiedClient } from '@orpc/openapi';
|
|
4
|
-
import { Promisable, PartialDeep, Interceptor, PromiseWithError, MaybeOptionalOptions, OrderablePlugin, Public } from '@orpc/shared';
|
|
5
|
-
import { EntryKey, UseQueryOptions,
|
|
4
|
+
import { Promisable, PartialDeep, Interceptor, PromiseWithError, MaybeOptionalOptions, OrderablePlugin, Public, ThrowableError } from '@orpc/shared';
|
|
5
|
+
import { EntryKey, UseQueryOptions, UseMutationOptionsGlobal, DefineQueryOptions, UseInfiniteQueryData, DefineInfiniteQueryOptions, UseMutationOptions, DefineQueryOptionsTagged, DefineInfiniteQueryOptionsTagged, DefineMutationOptionsTagged, UseInfiniteQueryFnContext, EntryKeyTagged, _EmptyObject } from '@pinia/colada';
|
|
6
6
|
|
|
7
7
|
type InferStreamedQueryOutput<TOutput> = TOutput extends AsyncIterable<infer U> ? U[] : never;
|
|
8
8
|
type InferLiveQueryOutput<TOutput> = TOutput extends AsyncIterable<infer U> ? U : never;
|
|
9
9
|
type UseQueryFnContext = Parameters<UseQueryOptions<any>['query']>[0];
|
|
10
|
-
|
|
10
|
+
/**
|
|
11
|
+
* The context passed to the mutation function, including the merged
|
|
12
|
+
* `UseMutationGlobalContext` values provided by a global `onMutate` hook.
|
|
13
|
+
*/
|
|
14
|
+
type UseMutationFnContext = Parameters<NonNullable<UseMutationOptionsGlobal['onSuccess']>>[2];
|
|
11
15
|
declare const OPERATION_CONTEXT_SYMBOL: unique symbol;
|
|
12
16
|
type OperationType = 'query' | 'streamed' | 'live' | 'infinite' | 'mutation';
|
|
13
17
|
interface OperationContext {
|
|
@@ -233,6 +237,15 @@ interface ProcedureUtilsOptions<TClientContext extends ClientContext, TInput, TO
|
|
|
233
237
|
*/
|
|
234
238
|
mutationOptions?: ProcedureUtilsModifier<MutationOptionsIn<TClientContext, TInput, TOutput, TError, Record<any, any>>>;
|
|
235
239
|
}
|
|
240
|
+
declare function isProcedureUtilsOptions(value: unknown): value is ProcedureUtilsOptions<any, any, any, any>;
|
|
241
|
+
/**
|
|
242
|
+
* Merge two procedure utils options where `override` takes priority.
|
|
243
|
+
* A key explicitly set to `undefined` in `override` resets the base value.
|
|
244
|
+
* When both sides define a key: interceptors are concatenated (base ones run first),
|
|
245
|
+
* modifiers are spread-merged when both are plain objects and composed (base applied
|
|
246
|
+
* first) otherwise, with plain objects applied as regular spread merges.
|
|
247
|
+
*/
|
|
248
|
+
declare function mergeProcedureUtilsOptions<TClientContext extends ClientContext, TInput, TOutput, TError>(base: ProcedureUtilsOptions<TClientContext, TInput, TOutput, TError>, override: ProcedureUtilsOptions<TClientContext, TInput, TOutput, TError>): ProcedureUtilsOptions<TClientContext, TInput, TOutput, TError>;
|
|
236
249
|
declare class ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError> extends SharedUtils<TInput> {
|
|
237
250
|
protected readonly options: ProcedureUtilsOptions<TClientContext, TInput, TOutput, TError>;
|
|
238
251
|
/**
|
|
@@ -418,5 +431,42 @@ declare function createContractJsonifiedUtilsFactory<TClientContext extends Clie
|
|
|
418
431
|
*/
|
|
419
432
|
declare function liveQuery<T>(queryFn: (context: UseQueryFnContext) => Promisable<AsyncIterable<T>>): (context: UseQueryFnContext) => Promise<T>;
|
|
420
433
|
|
|
421
|
-
|
|
422
|
-
|
|
434
|
+
type PiniaColadaMetaOptions<TClientContext extends ClientContext, TInput, TOutput, TError> = Omit<ProcedureUtilsOptions<TClientContext, TInput, TOutput, TError>, 'prefix'>;
|
|
435
|
+
interface PiniaColadaMetaPlugin<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> extends MetaPlugin<TInputSchema, TOutputSchema, TErrorMap> {
|
|
436
|
+
name: '~pinia-colada';
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* Define base Pinia Colada options and interceptors on a procedure contract.
|
|
440
|
+
* Applied multiple times, later options are spread-merged with higher priority
|
|
441
|
+
* while interceptors are concatenated. A key explicitly set to `undefined`
|
|
442
|
+
* resets the value from earlier applications instead of merging.
|
|
443
|
+
*
|
|
444
|
+
* Apply them to router utils with {@link ContractOptionsUtilsPlugin}.
|
|
445
|
+
*
|
|
446
|
+
* @see {@link https://orpc.dev/docs/integrations/pinia-colada#contract-options-plugin Pinia Colada Contract Options Plugin Docs}
|
|
447
|
+
*/
|
|
448
|
+
declare function piniaColada<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap>(options: PiniaColadaMetaOptions<ClientContext, InferSchemaInput<TInputSchema>, InferSchemaOutput<TOutputSchema>, ORPCErrorFromErrorMap<TErrorMap> | ThrowableError>): PiniaColadaMetaPlugin<TInputSchema, TOutputSchema, TErrorMap>;
|
|
449
|
+
declare function getPiniaColadaMeta(procedureOrLazy: {
|
|
450
|
+
'~orpc': {
|
|
451
|
+
meta: Meta;
|
|
452
|
+
};
|
|
453
|
+
}): PiniaColadaMetaOptions<ClientContext, unknown, unknown, ThrowableError> | undefined;
|
|
454
|
+
/**
|
|
455
|
+
* Router utils plugin that applies base options defined via {@link piniaColada}
|
|
456
|
+
* on the given router contract. Meta options act as the base layer: options defined
|
|
457
|
+
* on the utils override them, and utils interceptors run after meta interceptors.
|
|
458
|
+
*
|
|
459
|
+
* The contract shape must match the client the utils are created from,
|
|
460
|
+
* so pass the root router contract when utils paths start from the root.
|
|
461
|
+
*
|
|
462
|
+
* @see {@link https://orpc.dev/docs/integrations/pinia-colada#contract-options-plugin Pinia Colada Contract Options Plugin Docs}
|
|
463
|
+
*/
|
|
464
|
+
declare class ContractOptionsUtilsPlugin<T extends AnyNestedClient = AnyNestedClient> implements RouterUtilsPlugin<T> {
|
|
465
|
+
private readonly contract;
|
|
466
|
+
readonly name = "~contract-options";
|
|
467
|
+
constructor(contract: RouterContract);
|
|
468
|
+
initProcedureOptions(path: string[], options: ProcedureUtilsOptions<InferClientContext<T>, any, any, InferClientError<T>>): ProcedureUtilsOptions<InferClientContext<T>, any, any, InferClientError<T>>;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
export { CompositeRouterUtilsPlugin, ContractOptionsUtilsPlugin, OPERATION_CONTEXT_SYMBOL, OPERATION_CONTEXT_SYMBOL as PINIA_COLADA_OPERATION_CONTEXT_SYMBOL, ProcedureUtils, SharedUtils, createContractJsonifiedUtilsFactory, createContractUtilsFactory, createRouterUtils as createPiniaColadaUtils, createRouterUtils, generateOperationKey, getPiniaColadaMeta, isProcedureUtilsOptions, liveQuery, mergeProcedureUtilsOptions, piniaColada, serializableStreamedQuery };
|
|
472
|
+
export type { ContractJsonifiedUtilsFactory, ContractJsonifiedUtilsFactoryOptions, ContractUtilsFactory, ContractUtilsFactoryOptions, InferLiveQueryOutput, InferStreamedQueryOutput, InfiniteKeyOptions, InfiniteOptionsIn, InfiniteOptionsOut, MutationKeyOptions, MutationOptionsIn, MutationOptionsOut, OperationContext, OperationKey, OperationKeyOptions, OperationKeyPrefixOptions, OperationType, PiniaColadaMetaOptions, PiniaColadaMetaPlugin, OperationContext as PiniaColadaOperationContext, ProcedureUtilsInfiniteInterceptor, ProcedureUtilsInfiniteInterceptorOptions, ProcedureUtilsLiveInterceptor, ProcedureUtilsLiveInterceptorOptions, ProcedureUtilsModifier, ProcedureUtilsMutationInterceptor, ProcedureUtilsMutationInterceptorOptions, ProcedureUtilsOptions, ProcedureUtilsQueryInterceptor, ProcedureUtilsQueryInterceptorOptions, ProcedureUtilsStreamedInterceptor, ProcedureUtilsStreamedInterceptorOptions, QueryKeyOptions, QueryOptionsIn, QueryOptionsOut, RouterUtils, RouterUtilsOptions, RouterUtilsPlugin, RouterUtilsScoped, SerializableStreamedQueryOptions, StreamedKeyOptions, StreamedOptionsIn, StreamedOptionsOut, UseMutationFnContext, UseQueryFnContext };
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { resolveBasePathMeta } from '@orpc/contract';
|
|
2
|
-
import { sortPlugins, stringifyJSON, resolveMaybeOptionalOptions, intercept, isAsyncIteratorObject, toArray, bindMethods, getOrBind, get
|
|
1
|
+
import { resolveBasePathMeta, getRouterContract, ProcedureContract } from '@orpc/contract';
|
|
2
|
+
import { sortPlugins, stringifyJSON, resolveMaybeOptionalOptions, intercept, isTypescriptObject, isAsyncIteratorObject, toArray, bindMethods, getOrBind, get } from '@orpc/shared';
|
|
3
3
|
import { RPCJsonSerializer, RECURSIVE_CLIENT_UNWRAP_KEYS } from '@orpc/client';
|
|
4
4
|
|
|
5
5
|
class CompositeRouterUtilsPlugin {
|
|
@@ -110,6 +110,75 @@ function limitArraySize(items, maxSize) {
|
|
|
110
110
|
|
|
111
111
|
const OPERATION_CONTEXT_SYMBOL = Symbol.for("ORPC_PINIA_COLADA_OPERATION_CONTEXT");
|
|
112
112
|
|
|
113
|
+
const PROCEDURE_UTILS_INTERCEPTOR_KEYS = [
|
|
114
|
+
"queryInterceptors",
|
|
115
|
+
"streamedInterceptors",
|
|
116
|
+
"liveInterceptors",
|
|
117
|
+
"infiniteInterceptors",
|
|
118
|
+
"mutationInterceptors"
|
|
119
|
+
];
|
|
120
|
+
const PROCEDURE_UTILS_MODIFIER_KEYS = [
|
|
121
|
+
"queryKey",
|
|
122
|
+
"queryOptions",
|
|
123
|
+
"streamedKey",
|
|
124
|
+
"streamedOptions",
|
|
125
|
+
"liveKey",
|
|
126
|
+
"liveOptions",
|
|
127
|
+
"infiniteKey",
|
|
128
|
+
"infiniteOptions",
|
|
129
|
+
"mutationKey",
|
|
130
|
+
"mutationOptions"
|
|
131
|
+
];
|
|
132
|
+
function isProcedureUtilsOptions(value) {
|
|
133
|
+
if (!isTypescriptObject(value)) {
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
for (const key in value) {
|
|
137
|
+
if (value[key] === void 0) {
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
if (key === "prefix") {
|
|
141
|
+
if (typeof value[key] !== "string") {
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
} else if (PROCEDURE_UTILS_INTERCEPTOR_KEYS.includes(key)) {
|
|
145
|
+
if (!Array.isArray(value[key]) || value[key].some((i) => typeof i !== "function")) {
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
} else if (PROCEDURE_UTILS_MODIFIER_KEYS.includes(key)) {
|
|
149
|
+
if (!isTypescriptObject(value[key])) {
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return true;
|
|
155
|
+
}
|
|
156
|
+
function mergeProcedureUtilsModifier(base, override) {
|
|
157
|
+
if (typeof base !== "function" && typeof override !== "function") {
|
|
158
|
+
return { ...base, ...override };
|
|
159
|
+
}
|
|
160
|
+
const applyBase = typeof base === "function" ? base : (options) => ({ ...base, ...options });
|
|
161
|
+
const applyOverride = typeof override === "function" ? override : (options) => ({ ...override, ...options });
|
|
162
|
+
return (options) => applyOverride(applyBase(options));
|
|
163
|
+
}
|
|
164
|
+
function mergeProcedureUtilsOptions(base, override) {
|
|
165
|
+
const merged = { ...base, ...override };
|
|
166
|
+
for (const key of PROCEDURE_UTILS_INTERCEPTOR_KEYS) {
|
|
167
|
+
const baseValue = base[key];
|
|
168
|
+
const overrideValue = override[key];
|
|
169
|
+
if (baseValue && overrideValue) {
|
|
170
|
+
merged[key] = [...baseValue, ...overrideValue];
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
for (const key of PROCEDURE_UTILS_MODIFIER_KEYS) {
|
|
174
|
+
const baseValue = base[key];
|
|
175
|
+
const overrideValue = override[key];
|
|
176
|
+
if (baseValue && overrideValue) {
|
|
177
|
+
merged[key] = mergeProcedureUtilsModifier(baseValue, overrideValue);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
return merged;
|
|
181
|
+
}
|
|
113
182
|
class ProcedureUtils extends SharedUtils {
|
|
114
183
|
/**
|
|
115
184
|
* Calling corresponding procedure client
|
|
@@ -437,20 +506,22 @@ function createRouterUtilsInternal(client, options, plugin) {
|
|
|
437
506
|
const utils = typeof client === "function" && (options.scoped === void 0 || isProcedureUtilsOptions(options.scoped)) ? bindMethods(new ProcedureUtils(
|
|
438
507
|
path,
|
|
439
508
|
client,
|
|
440
|
-
plugin.initProcedureOptions(path,
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
509
|
+
plugin.initProcedureOptions(path, mergeProcedureUtilsOptions(
|
|
510
|
+
{
|
|
511
|
+
prefix: options.prefix,
|
|
512
|
+
queryInterceptors: options.queryInterceptors,
|
|
513
|
+
streamedInterceptors: options.streamedInterceptors,
|
|
514
|
+
liveInterceptors: options.liveInterceptors,
|
|
515
|
+
infiniteInterceptors: options.infiniteInterceptors,
|
|
516
|
+
mutationInterceptors: options.mutationInterceptors
|
|
517
|
+
},
|
|
518
|
+
options.scoped ?? {}
|
|
519
|
+
))
|
|
449
520
|
)) : bindMethods(new SharedUtils(path, options));
|
|
450
521
|
const recursive = new Proxy(utils, {
|
|
451
522
|
get(target, prop) {
|
|
452
523
|
const value = getOrBind(target, prop);
|
|
453
|
-
const nextClient =
|
|
524
|
+
const nextClient = client[prop];
|
|
454
525
|
if (typeof prop !== "string" || RECURSIVE_CLIENT_UNWRAP_KEYS.has(prop) || !isTypescriptObject(nextClient)) {
|
|
455
526
|
return value;
|
|
456
527
|
}
|
|
@@ -474,27 +545,6 @@ function createRouterUtilsInternal(client, options, plugin) {
|
|
|
474
545
|
});
|
|
475
546
|
return recursive;
|
|
476
547
|
}
|
|
477
|
-
function isProcedureUtilsOptions(value) {
|
|
478
|
-
if (!isTypescriptObject(value)) {
|
|
479
|
-
return false;
|
|
480
|
-
}
|
|
481
|
-
if (value.queryInterceptors !== void 0 && !Array.isArray(value.queryInterceptors)) {
|
|
482
|
-
return false;
|
|
483
|
-
}
|
|
484
|
-
if (value.streamedInterceptors !== void 0 && !Array.isArray(value.streamedInterceptors)) {
|
|
485
|
-
return false;
|
|
486
|
-
}
|
|
487
|
-
if (value.liveInterceptors !== void 0 && !Array.isArray(value.liveInterceptors)) {
|
|
488
|
-
return false;
|
|
489
|
-
}
|
|
490
|
-
if (value.infiniteInterceptors !== void 0 && !Array.isArray(value.infiniteInterceptors)) {
|
|
491
|
-
return false;
|
|
492
|
-
}
|
|
493
|
-
if (value.mutationInterceptors !== void 0 && !Array.isArray(value.mutationInterceptors)) {
|
|
494
|
-
return false;
|
|
495
|
-
}
|
|
496
|
-
return true;
|
|
497
|
-
}
|
|
498
548
|
|
|
499
549
|
function createContractUtilsFactory(clientFactory, options) {
|
|
500
550
|
const factory = (contract) => {
|
|
@@ -513,4 +563,37 @@ function createContractJsonifiedUtilsFactory(clientFactory, options) {
|
|
|
513
563
|
return createContractUtilsFactory(clientFactory, options);
|
|
514
564
|
}
|
|
515
565
|
|
|
516
|
-
|
|
566
|
+
function piniaColada(options) {
|
|
567
|
+
return {
|
|
568
|
+
name: "~pinia-colada",
|
|
569
|
+
init(meta) {
|
|
570
|
+
const current = meta["~pinia-colada"];
|
|
571
|
+
return {
|
|
572
|
+
...meta,
|
|
573
|
+
"~pinia-colada": current ? mergeProcedureUtilsOptions(current, options) : options
|
|
574
|
+
};
|
|
575
|
+
}
|
|
576
|
+
};
|
|
577
|
+
}
|
|
578
|
+
function getPiniaColadaMeta(procedureOrLazy) {
|
|
579
|
+
return procedureOrLazy["~orpc"].meta["~pinia-colada"];
|
|
580
|
+
}
|
|
581
|
+
class ContractOptionsUtilsPlugin {
|
|
582
|
+
constructor(contract) {
|
|
583
|
+
this.contract = contract;
|
|
584
|
+
}
|
|
585
|
+
name = "~contract-options";
|
|
586
|
+
initProcedureOptions(path, options) {
|
|
587
|
+
const procedure = getRouterContract(this.contract, path);
|
|
588
|
+
if (!(procedure instanceof ProcedureContract)) {
|
|
589
|
+
return options;
|
|
590
|
+
}
|
|
591
|
+
const base = getPiniaColadaMeta(procedure);
|
|
592
|
+
if (!base) {
|
|
593
|
+
return options;
|
|
594
|
+
}
|
|
595
|
+
return mergeProcedureUtilsOptions(base, options);
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
export { CompositeRouterUtilsPlugin, ContractOptionsUtilsPlugin, OPERATION_CONTEXT_SYMBOL, OPERATION_CONTEXT_SYMBOL as PINIA_COLADA_OPERATION_CONTEXT_SYMBOL, ProcedureUtils, SharedUtils, createContractJsonifiedUtilsFactory, createContractUtilsFactory, createRouterUtils as createPiniaColadaUtils, createRouterUtils, generateOperationKey, getPiniaColadaMeta, isProcedureUtilsOptions, liveQuery, mergeProcedureUtilsOptions, piniaColada, serializableStreamedQuery };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/pinia-colada",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "1.14.11",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.dev",
|
|
7
7
|
"repository": {
|
|
@@ -32,10 +32,10 @@
|
|
|
32
32
|
"vue": ">=3.5.17"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@orpc/client": "
|
|
36
|
-
"@orpc/contract": "
|
|
37
|
-
"@orpc/openapi": "
|
|
38
|
-
"@orpc/shared": "
|
|
35
|
+
"@orpc/client": "1.14.11",
|
|
36
|
+
"@orpc/contract": "1.14.11",
|
|
37
|
+
"@orpc/openapi": "1.14.11",
|
|
38
|
+
"@orpc/shared": "1.14.11"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@pinia/colada": "^1.4.2",
|