@orpc/pinia-colada 0.0.0 → 2.0.0-beta.20

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 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/).
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, UseMutationOptions, DefineQueryOptions, UseInfiniteQueryData, DefineInfiniteQueryOptions, DefineQueryOptionsTagged, DefineInfiniteQueryOptionsTagged, DefineMutationOptionsTagged, UseInfiniteQueryFnContext, EntryKeyTagged, _EmptyObject } from '@pinia/colada';
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
- type UseMutationFnContext = Parameters<UseMutationOptions<any, any>['mutation']>[1];
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
- export { CompositeRouterUtilsPlugin, OPERATION_CONTEXT_SYMBOL, OPERATION_CONTEXT_SYMBOL as PINIA_COLADA_OPERATION_CONTEXT_SYMBOL, ProcedureUtils, SharedUtils, createContractJsonifiedUtilsFactory, createContractUtilsFactory, createRouterUtils as createPiniaColadaUtils, createRouterUtils, generateOperationKey, liveQuery, serializableStreamedQuery };
422
- export type { ContractJsonifiedUtilsFactory, ContractJsonifiedUtilsFactoryOptions, ContractUtilsFactory, ContractUtilsFactoryOptions, InferLiveQueryOutput, InferStreamedQueryOutput, InfiniteKeyOptions, InfiniteOptionsIn, InfiniteOptionsOut, MutationKeyOptions, MutationOptionsIn, MutationOptionsOut, OperationContext, OperationKey, OperationKeyOptions, OperationKeyPrefixOptions, OperationType, 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 };
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, UseMutationOptions, DefineQueryOptions, UseInfiniteQueryData, DefineInfiniteQueryOptions, DefineQueryOptionsTagged, DefineInfiniteQueryOptionsTagged, DefineMutationOptionsTagged, UseInfiniteQueryFnContext, EntryKeyTagged, _EmptyObject } from '@pinia/colada';
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
- type UseMutationFnContext = Parameters<UseMutationOptions<any, any>['mutation']>[1];
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
- export { CompositeRouterUtilsPlugin, OPERATION_CONTEXT_SYMBOL, OPERATION_CONTEXT_SYMBOL as PINIA_COLADA_OPERATION_CONTEXT_SYMBOL, ProcedureUtils, SharedUtils, createContractJsonifiedUtilsFactory, createContractUtilsFactory, createRouterUtils as createPiniaColadaUtils, createRouterUtils, generateOperationKey, liveQuery, serializableStreamedQuery };
422
- export type { ContractJsonifiedUtilsFactory, ContractJsonifiedUtilsFactoryOptions, ContractUtilsFactory, ContractUtilsFactoryOptions, InferLiveQueryOutput, InferStreamedQueryOutput, InfiniteKeyOptions, InfiniteOptionsIn, InfiniteOptionsOut, MutationKeyOptions, MutationOptionsIn, MutationOptionsOut, OperationContext, OperationKey, OperationKeyOptions, OperationKeyPrefixOptions, OperationType, 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 };
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, isTypescriptObject } from '@orpc/shared';
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,15 +506,17 @@ 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
- prefix: options.prefix,
442
- ...options.scoped,
443
- queryInterceptors: [...toArray(options.queryInterceptors), ...toArray(options.scoped?.queryInterceptors)],
444
- streamedInterceptors: [...toArray(options.streamedInterceptors), ...toArray(options.scoped?.streamedInterceptors)],
445
- liveInterceptors: [...toArray(options.liveInterceptors), ...toArray(options.scoped?.liveInterceptors)],
446
- infiniteInterceptors: [...toArray(options.infiniteInterceptors), ...toArray(options.scoped?.infiniteInterceptors)],
447
- mutationInterceptors: [...toArray(options.mutationInterceptors), ...toArray(options.scoped?.mutationInterceptors)]
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) {
@@ -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
- export { CompositeRouterUtilsPlugin, OPERATION_CONTEXT_SYMBOL, OPERATION_CONTEXT_SYMBOL as PINIA_COLADA_OPERATION_CONTEXT_SYMBOL, ProcedureUtils, SharedUtils, createContractJsonifiedUtilsFactory, createContractUtilsFactory, createRouterUtils as createPiniaColadaUtils, createRouterUtils, generateOperationKey, liveQuery, serializableStreamedQuery };
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": "0.0.0",
4
+ "version": "2.0.0-beta.20",
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": "2.0.0-beta.20",
36
+ "@orpc/openapi": "2.0.0-beta.20",
37
+ "@orpc/shared": "2.0.0-beta.20",
38
+ "@orpc/contract": "2.0.0-beta.20"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@pinia/colada": "^1.4.2",