@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.
Files changed (48) hide show
  1. package/README.md +4 -4
  2. package/dist/contract-utils.d.ts +37 -0
  3. package/dist/contract-utils.js +42 -0
  4. package/dist/index.d.ts +20 -0
  5. package/dist/index.js +14 -0
  6. package/dist/key.d.ts +45 -0
  7. package/dist/key.js +47 -0
  8. package/dist/live-query.d.ts +8 -0
  9. package/dist/live-query.js +38 -0
  10. package/dist/meta.d.ts +42 -0
  11. package/dist/meta.js +55 -0
  12. package/dist/plugin.d.ts +46 -0
  13. package/dist/plugin.js +25 -0
  14. package/dist/procedure-utils.d.ts +190 -0
  15. package/dist/procedure-utils.js +399 -0
  16. package/dist/router-utils.d.ts +67 -0
  17. package/dist/router-utils.js +69 -0
  18. package/dist/shared-utils.d.ts +13 -0
  19. package/dist/shared-utils.js +21 -0
  20. package/dist/ssr.d.ts +22 -0
  21. package/dist/ssr.js +24 -0
  22. package/dist/stream-query.d.ts +42 -0
  23. package/dist/stream-query.js +59 -0
  24. package/dist/types.d.ts +80 -0
  25. package/dist/types.js +7 -0
  26. package/package.json +31 -33
  27. package/dist/contract-utils.d.mts +0 -35
  28. package/dist/contract-utils.mjs +0 -23
  29. package/dist/index.d.mts +0 -19
  30. package/dist/index.mjs +0 -11
  31. package/dist/key.d.mts +0 -57
  32. package/dist/key.mjs +0 -29
  33. package/dist/live-query.d.mts +0 -7
  34. package/dist/live-query.mjs +0 -24
  35. package/dist/meta.d.mts +0 -55
  36. package/dist/meta.mjs +0 -37
  37. package/dist/plugin.d.mts +0 -46
  38. package/dist/plugin.mjs +0 -25
  39. package/dist/procedure-utils.d.mts +0 -245
  40. package/dist/procedure-utils.mjs +0 -394
  41. package/dist/router-utils.d.mts +0 -57
  42. package/dist/router-utils.mjs +0 -51
  43. package/dist/shared-utils.d.mts +0 -13
  44. package/dist/shared-utils.mjs +0 -17
  45. package/dist/stream-query.d.mts +0 -30
  46. package/dist/stream-query.mjs +0 -45
  47. package/dist/types.d.mts +0 -125
  48. package/dist/types.mjs +0 -2
package/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  <img alt="codecov" src="https://codecov.io/gh/middleapi/orpc/branch/main/graph/badge.svg">
6
6
  </a>
7
7
  <a href="https://www.npmjs.com/package/@orpc/pinia-colada">
8
- <img alt="weekly downloads" src="https://img.shields.io/npm/dw/%40orpc%2Fpinia-colada?logo=npm" />
8
+ <img alt="monthly downloads" src="https://img.shields.io/npm/dm/%40orpc%2Fpinia-colada?logo=npm" />
9
9
  </a>
10
10
  <a href="https://app.codspeed.io/middleapi/orpc?utm_source=badge">
11
11
  <img alt="CodSpeed" src="https://img.shields.io/endpoint?url=https://codspeed.io/badge.json" />
@@ -41,10 +41,11 @@ export const router = {
41
41
  Then call them from a client that knows every input and output, without generating anything:
42
42
 
43
43
  ```ts
44
- import type { RouterClient } from '@orpc/server'
45
- import type { router } from './router'
46
44
  import { createORPCClient } from '@orpc/client'
47
45
  import { RPCLink } from '@orpc/client/fetch'
46
+ import type { RouterClient } from '@orpc/server'
47
+
48
+ import type { router } from './router'
48
49
 
49
50
  const link = new RPCLink({ origin: 'http://localhost:3000', url: '/rpc' })
50
51
  const client: RouterClient<typeof router> = createORPCClient(link)
@@ -208,7 +209,6 @@ With thanks to [40 past sponsors](https://orpc.dev/sponsors#past-sponsors) who h
208
209
  <tr>
209
210
  <td align="center"><a href="https://claude.com/contact-sales/claude-for-oss" target="_blank" rel="noopener" title="Claude for Open Source"><img src="https://cdn.simpleicons.org/claude" width="64" alt="Claude"/><br />Claude</a></td>
210
211
  <td align="center"><a href="https://pullfrog.com/for-oss" target="_blank" rel="noopener" title="Pullfrog for OSS"><img src="https://avatars.githubusercontent.com/in/1768019?s=128&amp;v=4" width="64" alt="Pullfrog"/><br />Pullfrog</a></td>
211
- <td align="center"><a href="https://macroscope.com/open-source" target="_blank" rel="noopener" title="Macroscope for Open Source"><img src="https://avatars.githubusercontent.com/in/900172?s=128&amp;v=4" width="64" alt="Macroscope"/><br />Macroscope</a></td>
212
212
  </tr>
213
213
  </table>
214
214
 
@@ -0,0 +1,37 @@
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.ts';
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
+ /**
11
+ * Creates a factory that builds Pinia Colada utils directly from a contract,
12
+ * using the given contract client factory. Useful for scaling large projects
13
+ * where each part only needs a slice of the router.
14
+ *
15
+ * @remarks
16
+ * **Note**: The contract must define a `path` meta matching its position in the root router contract.
17
+ *
18
+ * @see {@link https://orpc.dev/docs/contract/client-factory#pinia-colada-integration | Contract Client Factory - Pinia Colada Integration}
19
+ */
20
+ export declare function createContractUtilsFactory<TClientContext extends ClientContext>(clientFactory: ContractClientFactory<TClientContext>, options: ContractUtilsFactoryOptions<TClientContext>): ContractUtilsFactory<TClientContext>;
21
+ export interface ContractJsonifiedUtilsFactory<TClientContext extends ClientContext> {
22
+ <T extends RouterContract>(contract: T): RouterUtils<JsonifiedClient<RouterContractClient<T, TClientContext>>>;
23
+ }
24
+ export interface ContractJsonifiedUtilsFactoryOptions<TClientContext extends ClientContext> extends Omit<RouterUtilsOptions<JsonifiedClient<RouterContractClient<RouterContract, TClientContext>>>, 'path'> {
25
+ }
26
+ /**
27
+ * Like `createContractUtilsFactory`, but for clients whose types are wrapped in `JsonifiedClient`,
28
+ * such as clients using OpenAPI Link.
29
+ *
30
+ * @remarks
31
+ * Takes a client factory created by `createContractJsonifiedClientFactory` from `@orpc/openapi`.
32
+ *
33
+ * **Note**: The contract must define a `path` meta matching its position in the root router contract.
34
+ *
35
+ * @see {@link https://orpc.dev/docs/contract/client-factory#pinia-colada-integration | Contract Client Factory - Pinia Colada Integration}
36
+ */
37
+ export declare function createContractJsonifiedUtilsFactory<TClientContext extends ClientContext>(clientFactory: ContractJsonifiedClientFactory<TClientContext>, options: ContractJsonifiedUtilsFactoryOptions<TClientContext>): ContractJsonifiedUtilsFactory<TClientContext>;
@@ -0,0 +1,42 @@
1
+ import { resolveBasePathMeta } from '@orpc/contract';
2
+ import { get } from '@orpc/shared';
3
+ import { createRouterUtils } from './router-utils.js';
4
+ /**
5
+ * Creates a factory that builds Pinia Colada utils directly from a contract,
6
+ * using the given contract client factory. Useful for scaling large projects
7
+ * where each part only needs a slice of the router.
8
+ *
9
+ * @remarks
10
+ * **Note**: The contract must define a `path` meta matching its position in the root router contract.
11
+ *
12
+ * @see {@link https://orpc.dev/docs/contract/client-factory#pinia-colada-integration | Contract Client Factory - Pinia Colada Integration}
13
+ */
14
+ export function createContractUtilsFactory(clientFactory, options) {
15
+ const factory = (contract) => {
16
+ const client = clientFactory(contract);
17
+ const path = resolveBasePathMeta(contract);
18
+ if (path === undefined) {
19
+ throw new TypeError('ContractUtilsFactory: procedure contract must define `meta.path` that matches its path in the root router contract.');
20
+ }
21
+ return createRouterUtils(client, {
22
+ ...options,
23
+ path,
24
+ scoped: get(options.scoped, path),
25
+ });
26
+ };
27
+ return factory;
28
+ }
29
+ /**
30
+ * Like `createContractUtilsFactory`, but for clients whose types are wrapped in `JsonifiedClient`,
31
+ * such as clients using OpenAPI Link.
32
+ *
33
+ * @remarks
34
+ * Takes a client factory created by `createContractJsonifiedClientFactory` from `@orpc/openapi`.
35
+ *
36
+ * **Note**: The contract must define a `path` meta matching its position in the root router contract.
37
+ *
38
+ * @see {@link https://orpc.dev/docs/contract/client-factory#pinia-colada-integration | Contract Client Factory - Pinia Colada Integration}
39
+ */
40
+ export function createContractJsonifiedUtilsFactory(clientFactory, options) {
41
+ return createContractUtilsFactory(clientFactory, options);
42
+ }
@@ -0,0 +1,20 @@
1
+ export * from './contract-utils.ts';
2
+ export type { OperationKey, OperationKeyBaseOptions, OperationKeyOptions, OperationKeyPrefixOptions, } from './key.ts';
3
+ export * from './meta.ts';
4
+ export type { RouterUtilsPlugin } from './plugin.ts';
5
+ export { mergeProcedureUtilsOptions, ProcedureUtils } from './procedure-utils.ts';
6
+ export type { ProcedureUtilsInfiniteInterceptor, ProcedureUtilsInfiniteInterceptorOptions, ProcedureUtilsLiveInterceptor, ProcedureUtilsLiveInterceptorOptions, ProcedureUtilsModifier, ProcedureUtilsMutationInterceptor, ProcedureUtilsMutationInterceptorOptions, ProcedureUtilsOptions, ProcedureUtilsQueryInterceptor, ProcedureUtilsQueryInterceptorOptions, ProcedureUtilsStreamedInterceptor, ProcedureUtilsStreamedInterceptorOptions, } from './procedure-utils.ts';
7
+ export * from './router-utils.ts';
8
+ export {
9
+ /**
10
+ * @deprecated Use `createRouterUtils` instead.
11
+ */
12
+ createRouterUtils as createORPCVueColadaUtils, } from './router-utils.ts';
13
+ export { createRouterUtils as createPiniaColadaUtils } from './router-utils.ts';
14
+ export { SharedUtils } from './shared-utils.ts';
15
+ export * from './ssr.ts';
16
+ export type { SerializableStreamedQueryOptions, SettleOnFirstDataOptions } from './stream-query.ts';
17
+ export * from './types.ts';
18
+ export { OPERATION_CONTEXT_SYMBOL as PINIA_COLADA_OPERATION_CONTEXT_SYMBOL, type OperationContext as PiniaColadaOperationContext, } from './types.ts';
19
+ export type { AnyNestedClient } from '@orpc/client';
20
+ export type { Public } from '@orpc/shared';
package/dist/index.js ADDED
@@ -0,0 +1,14 @@
1
+ export * from './contract-utils.js';
2
+ export * from './meta.js';
3
+ export { mergeProcedureUtilsOptions, ProcedureUtils } from './procedure-utils.js';
4
+ export * from './router-utils.js';
5
+ export {
6
+ /**
7
+ * @deprecated Use `createRouterUtils` instead.
8
+ */
9
+ createRouterUtils as createORPCVueColadaUtils, } from './router-utils.js';
10
+ export { createRouterUtils as createPiniaColadaUtils } from './router-utils.js';
11
+ export { SharedUtils } from './shared-utils.js';
12
+ export * from './ssr.js';
13
+ export * from './types.js';
14
+ export { OPERATION_CONTEXT_SYMBOL as PINIA_COLADA_OPERATION_CONTEXT_SYMBOL, } from './types.js';
package/dist/key.d.ts ADDED
@@ -0,0 +1,45 @@
1
+ import { RPCJsonSerializer } from '@orpc/client';
2
+ import type { PartialDeep, Public } from '@orpc/shared';
3
+ import type { EntryKey } from '@pinia/colada';
4
+ import type { SerializableStreamedQueryOptions } from './stream-query.ts';
5
+ import type { OperationType } from './types.ts';
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<TType extends OperationType, TInput> = OperationKeyBaseOptions & {
23
+ type?: TType | undefined;
24
+ input?: PartialDeep<TInput> | undefined;
25
+ fnOptions?: (TType extends 'streamed' ? SerializableStreamedQueryOptions : never) | undefined;
26
+ };
27
+ type OperationKeyContent<TType extends OperationType, TInput> = Omit<OperationKeyOptions<TType, TInput>, keyof OperationKeyBaseOptions> & {
28
+ /**
29
+ * Serializer types of non-JSON values in `input`, keyed by their JSON-encoded path,
30
+ * so inputs with the same JSON form (like a `Date` and its ISO string) produce different keys.
31
+ * Keyed by path (not a list) so partial keys still match.
32
+ */
33
+ inputMeta?: Record<string, string[]> | undefined;
34
+ };
35
+ export type OperationKey<TType extends OperationType, TInput> = EntryKey & ([path: string[], options: OperationKeyContent<TType, TInput>] | [prefix: string, path: string[], options: OperationKeyContent<TType, TInput>]);
36
+ /**
37
+ * Generate a Pinia Colada entry key for a procedure.
38
+ *
39
+ * The input is serialized to JSON-compatible values because Pinia Colada
40
+ * requires entry keys to be serializable.
41
+ *
42
+ * @see {@link https://orpc.dev/docs/integrations/pinia-colada#querymutation-key | Pinia Colada Integration - Query/Mutation Key}
43
+ */
44
+ export declare function generateOperationKey<TType extends OperationType, TInput>(path: string[], options?: OperationKeyOptions<TType, TInput>): OperationKey<TType, TInput>;
45
+ export {};
package/dist/key.js ADDED
@@ -0,0 +1,47 @@
1
+ import { RPCJsonSerializer } from '@orpc/client';
2
+ import { stringifyJSON } from '@orpc/shared';
3
+ const defaultSerializer = /* @__PURE__ */ new RPCJsonSerializer();
4
+ /**
5
+ * Generate a Pinia Colada entry key for a procedure.
6
+ *
7
+ * The input is serialized to JSON-compatible values because Pinia Colada
8
+ * requires entry keys to be serializable.
9
+ *
10
+ * @see {@link https://orpc.dev/docs/integrations/pinia-colada#querymutation-key | Pinia Colada Integration - Query/Mutation Key}
11
+ */
12
+ export function generateOperationKey(path, options = {}) {
13
+ return [
14
+ ...(options.prefix !== undefined ? [options.prefix] : []),
15
+ path,
16
+ {
17
+ ...(options.input !== undefined
18
+ ? serializeInput(options.serializer ?? defaultSerializer, options.input)
19
+ : {}),
20
+ ...(options.type !== undefined ? { type: options.type } : {}),
21
+ ...streamedKeyOptions(options.fnOptions),
22
+ },
23
+ ];
24
+ }
25
+ function serializeInput(serializer, input) {
26
+ const { json, meta } = serializer.serializeJson(input);
27
+ if (!meta?.length) {
28
+ return { input: json };
29
+ }
30
+ const inputMeta = {};
31
+ for (const [type, ...segments] of meta) {
32
+ ;
33
+ (inputMeta[stringifyJSON(segments)] ??= []).push(type);
34
+ }
35
+ return { input: json, inputMeta };
36
+ }
37
+ /**
38
+ * Leaves out default streamed options, so passing a default gives the same key as omitting it.
39
+ */
40
+ function streamedKeyOptions(options) {
41
+ const { refetchMode, maxChunks } = options ?? {};
42
+ const fnOptions = {
43
+ ...(refetchMode !== undefined && refetchMode !== 'reset' ? { refetchMode } : {}),
44
+ ...(maxChunks !== undefined && maxChunks !== Number.POSITIVE_INFINITY ? { maxChunks } : {}),
45
+ };
46
+ return Object.keys(fnOptions).length > 0 ? { fnOptions } : {};
47
+ }
@@ -0,0 +1,8 @@
1
+ import type { Promisable } from '@orpc/shared';
2
+ import type { SettleOnFirstDataOptions } from './stream-query.ts';
3
+ import type { UseQueryFnContext } from './types.ts';
4
+ /**
5
+ * A Pinia Colada query function that publishes each streamed chunk to the
6
+ * cache entry as it arrives, replacing the previous value.
7
+ */
8
+ export declare function liveQuery<T>(queryFn: (context: UseQueryFnContext) => Promisable<AsyncIterable<T>>, { settleOnFirstData }?: SettleOnFirstDataOptions): (context: UseQueryFnContext) => Promise<T>;
@@ -0,0 +1,38 @@
1
+ import { stringifyJSON, throwIfAborted } from '@orpc/shared';
2
+ /**
3
+ * A Pinia Colada query function that publishes each streamed chunk to the
4
+ * cache entry as it arrives, replacing the previous value.
5
+ */
6
+ export function liveQuery(queryFn, { settleOnFirstData = false } = {}) {
7
+ return async (context) => {
8
+ const { entry, signal } = context;
9
+ // a fetch cut short (cancelled, superseded, or its last component left) reopens when used again
10
+ const markStale = () => {
11
+ entry.when = 0;
12
+ };
13
+ if (signal.aborted) {
14
+ markStale();
15
+ }
16
+ signal.addEventListener('abort', markStale, { once: true });
17
+ const stream = await queryFn(context);
18
+ if (signal.aborted) {
19
+ await stream[Symbol.asyncIterator]().return?.();
20
+ throw signal.reason;
21
+ }
22
+ let last;
23
+ for await (const chunk of stream) {
24
+ throwIfAborted(signal);
25
+ last = { chunk };
26
+ entry.state.value = { status: 'success', data: chunk, error: null };
27
+ if (settleOnFirstData) {
28
+ break;
29
+ }
30
+ }
31
+ // a stream that ends on abort must not be stored as fresh data
32
+ throwIfAborted(signal);
33
+ if (!last) {
34
+ 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.`);
35
+ }
36
+ return last.chunk;
37
+ };
38
+ }
package/dist/meta.d.ts ADDED
@@ -0,0 +1,42 @@
1
+ import type { AnyNestedClient, ClientContext, InferClientContext, InferClientError } from '@orpc/client';
2
+ import type { AnySchema, ErrorMap, InferSchemaInput, InferSchemaOutput, Meta, MetaPlugin, ORPCErrorFromErrorMap, RouterContract } from '@orpc/contract';
3
+ import type { ThrowableError } from '@orpc/shared';
4
+ import type { OperationKeyBaseOptions } from './key.ts';
5
+ import type { RouterUtilsPlugin } from './plugin.ts';
6
+ import type { ProcedureUtilsOptions } from './procedure-utils.ts';
7
+ export type PiniaColadaMetaOptions<TClientContext extends ClientContext, TInput, TOutput, TError> = Omit<ProcedureUtilsOptions<TClientContext, TInput, TOutput, TError>, keyof OperationKeyBaseOptions>;
8
+ export interface PiniaColadaMetaPlugin<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> extends MetaPlugin<TInputSchema, TOutputSchema, TErrorMap> {
9
+ name: '~pinia-colada';
10
+ }
11
+ /**
12
+ * Define base Pinia Colada options and interceptors on a procedure contract.
13
+ * Applied multiple times, later options are spread-merged with higher priority
14
+ * while interceptors are concatenated. A key explicitly set to `undefined`
15
+ * resets the value from earlier applications instead of merging.
16
+ *
17
+ * Apply them to router utils with {@link ContractOptionsUtilsPlugin}.
18
+ *
19
+ * @see {@link https://orpc.dev/docs/integrations/pinia-colada#contract-options-plugin | Pinia Colada Integration - Contract Options Plugin}
20
+ */
21
+ export 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>;
22
+ export declare function getPiniaColadaMeta(procedureOrLazy: {
23
+ '~orpc': {
24
+ meta: Meta;
25
+ };
26
+ }): PiniaColadaMetaOptions<ClientContext, unknown, unknown, ThrowableError> | undefined;
27
+ /**
28
+ * Router utils plugin that applies base options defined via {@link piniaColada}
29
+ * on the given router contract. Meta options act as the base layer: options defined
30
+ * on the utils override them, and utils interceptors run after meta interceptors.
31
+ *
32
+ * The contract shape must match the client the utils are created from,
33
+ * so pass the root router contract when utils paths start from the root.
34
+ *
35
+ * @see {@link https://orpc.dev/docs/integrations/pinia-colada#contract-options-plugin | Pinia Colada Integration - Contract Options Plugin}
36
+ */
37
+ export declare class ContractOptionsUtilsPlugin<T extends AnyNestedClient = AnyNestedClient> implements RouterUtilsPlugin<T> {
38
+ private readonly contract;
39
+ readonly name = "~contract-options";
40
+ constructor(contract: RouterContract);
41
+ initProcedureOptions(path: string[], options: ProcedureUtilsOptions<InferClientContext<T>, any, any, InferClientError<T>>): ProcedureUtilsOptions<InferClientContext<T>, any, any, InferClientError<T>>;
42
+ }
package/dist/meta.js ADDED
@@ -0,0 +1,55 @@
1
+ import { getRouterContract, ProcedureContract } from '@orpc/contract';
2
+ import { mergeProcedureUtilsOptions } from './procedure-utils.js';
3
+ /**
4
+ * Define base Pinia Colada options and interceptors on a procedure contract.
5
+ * Applied multiple times, later options are spread-merged with higher priority
6
+ * while interceptors are concatenated. A key explicitly set to `undefined`
7
+ * resets the value from earlier applications instead of merging.
8
+ *
9
+ * Apply them to router utils with {@link ContractOptionsUtilsPlugin}.
10
+ *
11
+ * @see {@link https://orpc.dev/docs/integrations/pinia-colada#contract-options-plugin | Pinia Colada Integration - Contract Options Plugin}
12
+ */
13
+ export function piniaColada(options) {
14
+ return {
15
+ name: '~pinia-colada',
16
+ init(meta) {
17
+ const current = meta['~pinia-colada'];
18
+ return {
19
+ ...meta,
20
+ '~pinia-colada': current ? mergeProcedureUtilsOptions(current, options) : options,
21
+ };
22
+ },
23
+ };
24
+ }
25
+ export function getPiniaColadaMeta(procedureOrLazy) {
26
+ return procedureOrLazy['~orpc'].meta['~pinia-colada'];
27
+ }
28
+ /**
29
+ * Router utils plugin that applies base options defined via {@link piniaColada}
30
+ * on the given router contract. Meta options act as the base layer: options defined
31
+ * on the utils override them, and utils interceptors run after meta interceptors.
32
+ *
33
+ * The contract shape must match the client the utils are created from,
34
+ * so pass the root router contract when utils paths start from the root.
35
+ *
36
+ * @see {@link https://orpc.dev/docs/integrations/pinia-colada#contract-options-plugin | Pinia Colada Integration - Contract Options Plugin}
37
+ */
38
+ export class ContractOptionsUtilsPlugin {
39
+ contract;
40
+ name = '~contract-options';
41
+ constructor(contract) {
42
+ this.contract = contract;
43
+ }
44
+ initProcedureOptions(path, options) {
45
+ const procedure = getRouterContract(this.contract, path);
46
+ if (!(procedure instanceof ProcedureContract)) {
47
+ return options;
48
+ }
49
+ const base = getPiniaColadaMeta(procedure);
50
+ if (!base) {
51
+ return options;
52
+ }
53
+ return mergeProcedureUtilsOptions(base, options);
54
+ }
55
+ }
@@ -0,0 +1,46 @@
1
+ import type { AnyNestedClient, InferClientContext, InferClientError } from '@orpc/client';
2
+ import type { OrderablePlugin } from '@orpc/shared';
3
+ import type { ProcedureUtilsOptions } from './procedure-utils.ts';
4
+ import type { RouterUtilsOptions } from './router-utils.ts';
5
+ export interface RouterUtilsPlugin<T extends AnyNestedClient> extends OrderablePlugin {
6
+ /**
7
+ * Initializes the router utils plugin and returns updated router utils options.
8
+ * Called once per plugin instance during composition.
9
+ *
10
+ * This method allows plugins to wrap, extend, or transform router utils options,
11
+ * such as interceptors or configuration.
12
+ *
13
+ * @param options - The current router utils options from previous plugins or base configuration
14
+ * @returns Transformed router utils options with this plugin's modifications applied
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * init(options) {
19
+ * return {
20
+ * ...options,
21
+ * mutationInterceptors: [...(options.mutationInterceptors ?? []), myInterceptor]
22
+ * }
23
+ * }
24
+ * ```
25
+ */
26
+ init?(options: RouterUtilsOptions<T>): RouterUtilsOptions<T>;
27
+ /**
28
+ * Initializes per-procedure router utils options and returns updated options.
29
+ * Called once per procedure utils instance during composition.
30
+ *
31
+ * This method allows plugins to customize merged procedure-specific defaults,
32
+ * such as query or mutation options, for the current path.
33
+ *
34
+ * @param path - The current procedure path
35
+ * @param options - The merged procedure utils options for the current procedure
36
+ * @returns Transformed procedure utils options with this plugin's modifications applied
37
+ */
38
+ initProcedureOptions?(path: string[], options: ProcedureUtilsOptions<InferClientContext<T>, any, any, InferClientError<T>>): ProcedureUtilsOptions<InferClientContext<T>, any, any, InferClientError<T>>;
39
+ }
40
+ export declare class CompositeRouterUtilsPlugin<T extends AnyNestedClient> implements RouterUtilsPlugin<T> {
41
+ protected readonly plugins: RouterUtilsPlugin<T>[];
42
+ readonly name = "~composite";
43
+ constructor(plugins?: RouterUtilsPlugin<T>[]);
44
+ init(options: RouterUtilsOptions<T>): RouterUtilsOptions<T>;
45
+ initProcedureOptions(path: string[], options: ProcedureUtilsOptions<InferClientContext<T>, any, any, InferClientError<T>>): ProcedureUtilsOptions<InferClientContext<T>, any, any, InferClientError<T>>;
46
+ }
package/dist/plugin.js ADDED
@@ -0,0 +1,25 @@
1
+ import { sortPlugins } from '@orpc/shared';
2
+ export class CompositeRouterUtilsPlugin {
3
+ plugins;
4
+ name = '~composite';
5
+ constructor(plugins = []) {
6
+ this.plugins = plugins;
7
+ this.plugins = sortPlugins(plugins);
8
+ }
9
+ init(options) {
10
+ for (const plugin of this.plugins) {
11
+ if (plugin.init) {
12
+ options = plugin.init(options);
13
+ }
14
+ }
15
+ return options;
16
+ }
17
+ initProcedureOptions(path, options) {
18
+ for (const plugin of this.plugins) {
19
+ if (plugin.initProcedureOptions) {
20
+ options = plugin.initProcedureOptions(path, options);
21
+ }
22
+ }
23
+ return options;
24
+ }
25
+ }