@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.
Files changed (47) hide show
  1. package/README.md +4 -4
  2. package/dist/contract-utils.d.ts +35 -0
  3. package/dist/contract-utils.js +42 -0
  4. package/dist/index.d.ts +13 -0
  5. package/dist/index.js +7 -0
  6. package/dist/key.d.ts +36 -0
  7. package/dist/key.js +45 -0
  8. package/dist/live-query.js +34 -0
  9. package/dist/meta.d.ts +42 -0
  10. package/dist/meta.js +53 -0
  11. package/dist/plugin.d.ts +39 -0
  12. package/dist/plugin.js +19 -0
  13. package/dist/procedure-utils.d.ts +187 -0
  14. package/dist/procedure-utils.js +383 -0
  15. package/dist/router-utils.d.ts +62 -0
  16. package/dist/router-utils.js +54 -0
  17. package/dist/shared-utils.d.ts +13 -0
  18. package/dist/shared-utils.js +23 -0
  19. package/dist/ssr.d.ts +22 -0
  20. package/dist/ssr.js +22 -0
  21. package/dist/stream-query.d.ts +33 -0
  22. package/dist/stream-query.js +47 -0
  23. package/dist/types.d.ts +80 -0
  24. package/dist/types.js +9 -0
  25. package/package.json +31 -33
  26. package/dist/contract-utils.d.mts +0 -35
  27. package/dist/contract-utils.mjs +0 -23
  28. package/dist/index.d.mts +0 -19
  29. package/dist/index.mjs +0 -11
  30. package/dist/key.d.mts +0 -57
  31. package/dist/key.mjs +0 -29
  32. package/dist/live-query.d.mts +0 -7
  33. package/dist/live-query.mjs +0 -24
  34. package/dist/meta.d.mts +0 -55
  35. package/dist/meta.mjs +0 -37
  36. package/dist/plugin.d.mts +0 -46
  37. package/dist/plugin.mjs +0 -25
  38. package/dist/procedure-utils.d.mts +0 -245
  39. package/dist/procedure-utils.mjs +0 -394
  40. package/dist/router-utils.d.mts +0 -57
  41. package/dist/router-utils.mjs +0 -51
  42. package/dist/shared-utils.d.mts +0 -13
  43. package/dist/shared-utils.mjs +0 -17
  44. package/dist/stream-query.d.mts +0 -30
  45. package/dist/stream-query.mjs +0 -45
  46. package/dist/types.d.mts +0 -125
  47. package/dist/types.mjs +0 -2
@@ -0,0 +1,80 @@
1
+ import { SerializableStreamedQueryOptions, SettleOnFirstDataOptions } from "./stream-query.js";
2
+ import { ClientContext } from "@orpc/client";
3
+ import { DefineInfiniteQueryOptions, DefineInfiniteQueryOptionsTagged, DefineMutationOptionsTagged, DefineQueryOptions, DefineQueryOptionsTagged, EntryKey, UseInfiniteQueryData, UseMutationOptions, UseMutationOptionsGlobal, UseQueryOptions } from "@pinia/colada";
4
+ export type InferStreamedQueryOutput<TOutput> = TOutput extends AsyncIterable<infer U> ? U[] : never;
5
+ export type InferLiveQueryOutput<TOutput> = TOutput extends AsyncIterable<infer U> ? U : never;
6
+ export type UseQueryFnContext = Parameters<UseQueryOptions<any>["query"]>[0];
7
+ /**
8
+ * The context passed to the mutation function, including the merged
9
+ * `UseMutationGlobalContext` values provided by a global `onMutate` hook.
10
+ */
11
+ export type UseMutationFnContext = Parameters<NonNullable<UseMutationOptionsGlobal["onSuccess"]>>[2];
12
+ /**
13
+ * The symbol under which Pinia Colada utils attach operation details
14
+ * (key and operation type) to the client context.
15
+ *
16
+ * @see {@link https://orpc.dev/docs/integrations/pinia-colada#client-context | Pinia Colada Integration - Client Context}
17
+ */
18
+ export declare const OPERATION_CONTEXT_SYMBOL: unique symbol;
19
+ export type OperationType = "query" | "streamed" | "live" | "infinite" | "mutation";
20
+ /**
21
+ * A client context automatically populated by Pinia Colada utils,
22
+ * exposing the operation key and type of the calling operation.
23
+ *
24
+ * @see {@link https://orpc.dev/docs/integrations/pinia-colada#client-context | Pinia Colada Integration - Client Context}
25
+ */
26
+ export interface OperationContext {
27
+ [OPERATION_CONTEXT_SYMBOL]?: {
28
+ key: EntryKey;
29
+ type: OperationType;
30
+ };
31
+ }
32
+ export type QueryKeyOptions<TInput> = (undefined extends TInput ? {
33
+ input?: TInput;
34
+ } : {
35
+ input: TInput;
36
+ }) | {
37
+ key: EntryKey;
38
+ };
39
+ export type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TInitialData extends TOutput | undefined> = (undefined extends TInput ? {
40
+ input?: TInput;
41
+ } : {
42
+ input: TInput;
43
+ }) & (object extends TClientContext ? {
44
+ context?: TClientContext | undefined;
45
+ } : {
46
+ context: TClientContext;
47
+ }) & Omit<DefineQueryOptions<TOutput, TError, TInitialData>, "key" | "query"> & Partial<Pick<DefineQueryOptions<TOutput, TError, TInitialData>, "key" | "query">>;
48
+ export type QueryOptionsOut<TOutput, TError, TInitialData extends TOutput | undefined> = DefineQueryOptionsTagged<TOutput, TError, TInitialData>;
49
+ export type StreamedKeyOptions<TInput> = ((undefined extends TInput ? {
50
+ input?: TInput;
51
+ } : {
52
+ input: TInput;
53
+ }) & {
54
+ fnOptions?: SerializableStreamedQueryOptions | undefined;
55
+ }) | {
56
+ key: EntryKey;
57
+ };
58
+ export type StreamedOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TInitialData extends TOutput | undefined> = QueryOptionsIn<TClientContext, TInput, TOutput, TError, TInitialData> & {
59
+ fnOptions?: SerializableStreamedQueryOptions | undefined;
60
+ } & SettleOnFirstDataOptions;
61
+ export type StreamedOptionsOut<TOutput, TError, TInitialData extends TOutput | undefined> = QueryOptionsOut<TOutput, TError, TInitialData>;
62
+ export type LiveOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TInitialData extends TOutput | undefined> = QueryOptionsIn<TClientContext, TInput, TOutput, TError, TInitialData> & SettleOnFirstDataOptions;
63
+ export type InfiniteKeyOptions<TInput, TPageParam> = Pick<InfiniteOptionsIn<any, TInput, any, any, TPageParam, any>, "input" | "initialPageParam"> | {
64
+ key: EntryKey;
65
+ };
66
+ export type InfiniteOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TPageParam, TInitialData extends UseInfiniteQueryData<TOutput, TPageParam> | undefined> = {
67
+ input: (pageParam: TPageParam) => TInput;
68
+ } & (object extends TClientContext ? {
69
+ context?: TClientContext | undefined;
70
+ } : {
71
+ context: TClientContext;
72
+ }) & Omit<DefineInfiniteQueryOptions<TOutput, TError, TPageParam, TInitialData>, "key" | "query"> & Partial<Pick<DefineInfiniteQueryOptions<TOutput, TError, TPageParam, TInitialData>, "key" | "query">>;
73
+ export type InfiniteOptionsOut<TOutput, TError, TPageParam, TInitialData extends UseInfiniteQueryData<TOutput, TPageParam> | undefined> = DefineInfiniteQueryOptionsTagged<TOutput, TError, TPageParam, TInitialData>;
74
+ export type MutationKeyOptions<TInput> = Pick<MutationOptionsIn<any, TInput, any, any, any>, "key">;
75
+ export type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TMutationContext extends Record<any, any>> = (object extends TClientContext ? {
76
+ context?: TClientContext | undefined;
77
+ } : {
78
+ context: TClientContext;
79
+ }) & Omit<UseMutationOptions<TOutput, TInput, TError, TMutationContext>, "mutation"> & Partial<Pick<UseMutationOptions<TOutput, TInput, TError, TMutationContext>, "mutation">>;
80
+ export type MutationOptionsOut<TInput, TOutput, TError, TMutationContext extends Record<any, any>> = DefineMutationOptionsTagged<TOutput, TInput, TError, TMutationContext>;
package/dist/types.js ADDED
@@ -0,0 +1,9 @@
1
+ // src/types.ts
2
+ /**
3
+ * The symbol under which Pinia Colada utils attach operation details
4
+ * (key and operation type) to the client context.
5
+ *
6
+ * @see {@link https://orpc.dev/docs/integrations/pinia-colada#client-context | Pinia Colada Integration - Client Context}
7
+ */
8
+ const OPERATION_CONTEXT_SYMBOL = /* @__PURE__ */ Symbol.for("ORPC_PINIA_COLADA_OPERATION_CONTEXT");
9
+ export { OPERATION_CONTEXT_SYMBOL };
package/package.json CHANGED
@@ -1,59 +1,57 @@
1
1
  {
2
2
  "name": "@orpc/pinia-colada",
3
- "type": "module",
4
- "version": "2.0.0-beta.48",
3
+ "version": "2.0.0-beta.50",
5
4
  "description": "Pinia Colada integration for oRPC: typesafe queries and mutations for Vue",
6
- "license": "MIT",
7
- "funding": [
8
- "https://github.com/sponsors/dinwwwh",
9
- "https://opencollective.com/middleapi"
5
+ "keywords": [
6
+ "mutation",
7
+ "orpc",
8
+ "pinia",
9
+ "pinia-colada",
10
+ "query",
11
+ "typesafe",
12
+ "typescript",
13
+ "vue"
10
14
  ],
11
15
  "homepage": "https://orpc.dev",
16
+ "license": "MIT",
12
17
  "repository": {
13
18
  "type": "git",
14
19
  "url": "git+https://github.com/middleapi/orpc.git",
15
20
  "directory": "packages/pinia-colada"
16
21
  },
17
- "keywords": [
18
- "orpc",
19
- "vue",
20
- "pinia",
21
- "pinia-colada",
22
- "query",
23
- "mutation",
24
- "typescript",
25
- "typesafe"
22
+ "funding": [
23
+ "https://github.com/sponsors/dinwwwh",
24
+ "https://opencollective.com/middleapi"
26
25
  ],
26
+ "files": [
27
+ "dist"
28
+ ],
29
+ "type": "module",
27
30
  "sideEffects": false,
28
31
  "exports": {
29
32
  "./package.json": "./package.json",
30
33
  ".": {
31
- "types": "./dist/index.d.mts",
32
- "import": "./dist/index.mjs",
33
- "default": "./dist/index.mjs"
34
+ "types": "./dist/index.d.ts",
35
+ "import": "./dist/index.js",
36
+ "default": "./dist/index.js"
34
37
  }
35
38
  },
36
- "files": [
37
- "dist"
38
- ],
39
- "peerDependencies": {
40
- "@pinia/colada": ">=1.2.0",
41
- "vue": ">=3.5.17"
42
- },
43
39
  "dependencies": {
44
- "@orpc/client": "2.0.0-beta.48",
45
- "@orpc/contract": "2.0.0-beta.48",
46
- "@orpc/openapi": "2.0.0-beta.48",
47
- "@orpc/shared": "2.0.0-beta.48"
40
+ "@orpc/client": "2.0.0-beta.50",
41
+ "@orpc/contract": "2.0.0-beta.50",
42
+ "@orpc/openapi": "2.0.0-beta.50",
43
+ "@orpc/shared": "2.0.0-beta.50"
48
44
  },
49
45
  "devDependencies": {
50
- "@pinia/colada": "^1.4.8",
46
+ "@pinia/colada": "^1.4.9",
51
47
  "@vue/test-utils": "^2.5.1",
52
48
  "pinia": "^4.1.0",
53
49
  "vue": "^3.5.44",
54
50
  "zod": "^4.6.7"
55
51
  },
56
- "scripts": {
57
- "type:check": "tsc -b"
58
- }
52
+ "peerDependencies": {
53
+ "@pinia/colada": ">=1.4.9",
54
+ "vue": ">=3.5.17"
55
+ },
56
+ "scripts": {}
59
57
  }
@@ -1,35 +0,0 @@
1
- import type { ClientContext } from "@orpc/client";
2
- import type { ContractClientFactory, RouterContract, RouterContractClient } from "@orpc/contract";
3
- import type { ContractJsonifiedClientFactory, JsonifiedClient } from "@orpc/openapi";
4
- import type { RouterUtils, RouterUtilsOptions } from "./router-utils.mjs";
5
- export interface ContractUtilsFactory<TClientContext extends ClientContext> {
6
- <T extends RouterContract>(contract: T): RouterUtils<RouterContractClient<T, TClientContext>>;
7
- }
8
- export interface ContractUtilsFactoryOptions<TClientContext extends ClientContext> extends Omit<RouterUtilsOptions<RouterContractClient<RouterContract, TClientContext>>, "path"> {}
9
- /**
10
- * Creates a factory that builds Pinia Colada utils directly from a contract,
11
- * using the given contract client factory. Useful for scaling large projects
12
- * where each part only needs a slice of the router.
13
- *
14
- * @remarks
15
- * **Note**: The contract must define a `path` meta matching its position in the root router contract.
16
- *
17
- * @see {@link https://orpc.dev/docs/contract/client-factory#pinia-colada-integration | Contract Client Factory - Pinia Colada Integration}
18
- */
19
- export declare function createContractUtilsFactory<TClientContext extends ClientContext>(clientFactory: ContractClientFactory<TClientContext>, options: ContractUtilsFactoryOptions<TClientContext>): ContractUtilsFactory<TClientContext>;
20
- export interface ContractJsonifiedUtilsFactory<TClientContext extends ClientContext> {
21
- <T extends RouterContract>(contract: T): RouterUtils<JsonifiedClient<RouterContractClient<T, TClientContext>>>;
22
- }
23
- export interface ContractJsonifiedUtilsFactoryOptions<TClientContext extends ClientContext> extends Omit<RouterUtilsOptions<JsonifiedClient<RouterContractClient<RouterContract, TClientContext>>>, "path"> {}
24
- /**
25
- * Like `createContractUtilsFactory`, but for clients whose types are wrapped in `JsonifiedClient`,
26
- * such as clients using OpenAPI Link.
27
- *
28
- * @remarks
29
- * Takes a client factory created by `createContractJsonifiedClientFactory` from `@orpc/openapi`.
30
- *
31
- * **Note**: The contract must define a `path` meta matching its position in the root router contract.
32
- *
33
- * @see {@link https://orpc.dev/docs/contract/client-factory#pinia-colada-integration | Contract Client Factory - Pinia Colada Integration}
34
- */
35
- export declare function createContractJsonifiedUtilsFactory<TClientContext extends ClientContext>(clientFactory: ContractJsonifiedClientFactory<TClientContext>, options: ContractJsonifiedUtilsFactoryOptions<TClientContext>): ContractJsonifiedUtilsFactory<TClientContext>;
@@ -1,23 +0,0 @@
1
- import { resolveBasePathMeta } from "@orpc/contract";
2
- import { get } from "@orpc/shared";
3
- import { createRouterUtils } from "./router-utils.mjs";
4
-
5
- export function createContractUtilsFactory(clientFactory, options) {
6
- const factory = (contract) => {
7
- const client = clientFactory(contract);
8
- const path = resolveBasePathMeta(contract);
9
- if (path === undefined) {
10
- throw new TypeError("ContractUtilsFactory: procedure contract must define `meta.path` that matches its path in the root router contract.");
11
- }
12
- return createRouterUtils(client, {
13
- ...options,
14
- path,
15
- scoped: get(options.scoped, path)
16
- });
17
- };
18
- return factory;
19
- }
20
-
21
- export function createContractJsonifiedUtilsFactory(clientFactory, options) {
22
- return createContractUtilsFactory(clientFactory, options);
23
- }
package/dist/index.d.mts DELETED
@@ -1,19 +0,0 @@
1
- export * from "./contract-utils.mjs";
2
- export type { OperationKey, OperationKeyBaseOptions, OperationKeyOptions, OperationKeyPrefixOptions } from "./key.mjs";
3
- export * from "./meta.mjs";
4
- export type { RouterUtilsPlugin } from "./plugin.mjs";
5
- export { mergeProcedureUtilsOptions, ProcedureUtils } from "./procedure-utils.mjs";
6
- export type { ProcedureUtilsInfiniteInterceptor, ProcedureUtilsInfiniteInterceptorOptions, ProcedureUtilsLiveInterceptor, ProcedureUtilsLiveInterceptorOptions, ProcedureUtilsModifier, ProcedureUtilsMutationInterceptor, ProcedureUtilsMutationInterceptorOptions, ProcedureUtilsOptions, ProcedureUtilsQueryInterceptor, ProcedureUtilsQueryInterceptorOptions, ProcedureUtilsStreamedInterceptor, ProcedureUtilsStreamedInterceptorOptions } from "./procedure-utils.mjs";
7
- export * from "./router-utils.mjs";
8
- export {
9
- /**
10
- * @deprecated Use `createRouterUtils` instead.
11
- */
12
- createRouterUtils as createORPCVueColadaUtils } from "./router-utils.mjs";
13
- export { createRouterUtils as createPiniaColadaUtils } from "./router-utils.mjs";
14
- export { SharedUtils } from "./shared-utils.mjs";
15
- export type { SerializableStreamedQueryOptions } from "./stream-query.mjs";
16
- export * from "./types.mjs";
17
- export { OPERATION_CONTEXT_SYMBOL as PINIA_COLADA_OPERATION_CONTEXT_SYMBOL, type OperationContext as PiniaColadaOperationContext } from "./types.mjs";
18
- export type { AnyNestedClient } from "@orpc/client";
19
- export type { Public } from "@orpc/shared";
package/dist/index.mjs DELETED
@@ -1,11 +0,0 @@
1
- export * from "./contract-utils.mjs";
2
- export * from "./meta.mjs";
3
- export { mergeProcedureUtilsOptions, ProcedureUtils } from "./procedure-utils.mjs";
4
- export * from "./router-utils.mjs";
5
- export {
6
-
7
- createRouterUtils as createORPCVueColadaUtils } from "./router-utils.mjs";
8
- export { createRouterUtils as createPiniaColadaUtils } from "./router-utils.mjs";
9
- export { SharedUtils } from "./shared-utils.mjs";
10
- export * from "./types.mjs";
11
- export { OPERATION_CONTEXT_SYMBOL as PINIA_COLADA_OPERATION_CONTEXT_SYMBOL } from "./types.mjs";
package/dist/key.d.mts DELETED
@@ -1,57 +0,0 @@
1
- import type { PartialDeep, Public } from "@orpc/shared";
2
- import type { EntryKey } from "@pinia/colada";
3
- import type { SerializableStreamedQueryOptions } from "./stream-query.mjs";
4
- import type { OperationType } from "./types.mjs";
5
- import { RPCJsonSerializer } from "@orpc/client";
6
- export interface OperationKeyPrefixOptions {
7
- /**
8
- * Prepended as the first element of the key when present.
9
- * Use this to avoid key conflicts when multiple router utils share the same client.
10
- */
11
- prefix?: string | undefined;
12
- }
13
- export interface OperationKeyBaseOptions extends OperationKeyPrefixOptions {
14
- /**
15
- * Serializes inputs into JSON-compatible values when building keys.
16
- * Pass the serializer your link uses so custom types produce consistent keys.
17
- *
18
- * @default new RPCJsonSerializer()
19
- */
20
- serializer?: Public<RPCJsonSerializer> | undefined;
21
- }
22
- export type OperationKeyOptions<
23
- TType extends OperationType,
24
- TInput
25
- > = OperationKeyBaseOptions & {
26
- type?: TType | undefined;
27
- input?: PartialDeep<TInput> | undefined;
28
- fnOptions?: (TType extends "streamed" ? SerializableStreamedQueryOptions : never) | undefined;
29
- };
30
- type OperationKeyContent<
31
- TType extends OperationType,
32
- TInput
33
- > = Omit<OperationKeyOptions<TType, TInput>, keyof OperationKeyBaseOptions> & {
34
- /**
35
- * Serializer types of non-JSON values in `input`, keyed by their JSON-encoded path,
36
- * so inputs with the same JSON form (like a `Date` and its ISO string) produce different keys.
37
- * Keyed by path (not a list) so partial keys still match.
38
- */
39
- inputMeta?: Record<string, string[]> | undefined;
40
- };
41
- export type OperationKey<
42
- TType extends OperationType,
43
- TInput
44
- > = EntryKey & ([path: string[], options: OperationKeyContent<TType, TInput>] | [prefix: string, path: string[], options: OperationKeyContent<TType, TInput>]);
45
- /**
46
- * Generate a Pinia Colada entry key for a procedure.
47
- *
48
- * The input is serialized to JSON-compatible values because Pinia Colada
49
- * requires entry keys to be serializable.
50
- *
51
- * @see {@link https://orpc.dev/docs/integrations/pinia-colada#querymutation-key | Pinia Colada Integration - Query/Mutation Key}
52
- */
53
- export declare function generateOperationKey<
54
- TType extends OperationType,
55
- TInput
56
- >(path: string[], options?: OperationKeyOptions<TType, TInput>): OperationKey<TType, TInput>;
57
- export {};
package/dist/key.mjs DELETED
@@ -1,29 +0,0 @@
1
- import { RPCJsonSerializer } from "@orpc/client";
2
- import { stringifyJSON } from "@orpc/shared";
3
- const defaultSerializer = /* @__PURE__ */ new RPCJsonSerializer();
4
-
5
- export function generateOperationKey(path, options = {}) {
6
- return [
7
- ...options.prefix !== undefined ? [options.prefix] : [],
8
- path,
9
- {
10
- ...options.input !== undefined ? serializeInput(options.serializer ?? defaultSerializer, options.input) : {},
11
- ...options.type !== undefined ? { type: options.type } : {},
12
- ...options.fnOptions !== undefined ? { fnOptions: options.fnOptions } : {}
13
- }
14
- ];
15
- }
16
- function serializeInput(serializer, input) {
17
- const { json, meta } = serializer.serializeJson(input);
18
- if (!meta?.length) {
19
- return { input: json };
20
- }
21
- const inputMeta = {};
22
- for (const [type, ...segments] of meta) {
23
- (inputMeta[stringifyJSON(segments)] ??= []).push(type);
24
- }
25
- return {
26
- input: json,
27
- inputMeta
28
- };
29
- }
@@ -1,7 +0,0 @@
1
- import type { Promisable } from "@orpc/shared";
2
- import type { UseQueryFnContext } from "./types.mjs";
3
- /**
4
- * A Pinia Colada query function that publishes each streamed chunk to the
5
- * cache entry as it arrives, replacing the previous value.
6
- */
7
- export declare function liveQuery<T>(queryFn: (context: UseQueryFnContext) => Promisable<AsyncIterable<T>>): (context: UseQueryFnContext) => Promise<T>;
@@ -1,24 +0,0 @@
1
- import { stringifyJSON } from "@orpc/shared";
2
-
3
- export function liveQuery(queryFn) {
4
- return async (context) => {
5
- const { entry, signal } = context;
6
- const stream = await queryFn(context);
7
- let last;
8
- for await (const chunk of stream) {
9
- if (signal.aborted) {
10
- throw signal.reason;
11
- }
12
- last = { chunk };
13
- entry.state.value = {
14
- status: "success",
15
- data: chunk,
16
- error: null
17
- };
18
- }
19
- if (!last) {
20
- throw new TypeError(`Live query for ${stringifyJSON(entry.key)} did not yield any data. Ensure the query function returns an AsyncIterable with at least one chunk.`);
21
- }
22
- return last.chunk;
23
- };
24
- }
package/dist/meta.d.mts DELETED
@@ -1,55 +0,0 @@
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.mjs";
5
- import type { RouterUtilsPlugin } from "./plugin.mjs";
6
- import type { ProcedureUtilsOptions } from "./procedure-utils.mjs";
7
- export type PiniaColadaMetaOptions<
8
- TClientContext extends ClientContext,
9
- TInput,
10
- TOutput,
11
- TError
12
- > = Omit<ProcedureUtilsOptions<TClientContext, TInput, TOutput, TError>, keyof OperationKeyBaseOptions>;
13
- export interface PiniaColadaMetaPlugin<
14
- TInputSchema extends AnySchema,
15
- TOutputSchema extends AnySchema,
16
- TErrorMap extends ErrorMap
17
- > extends MetaPlugin<TInputSchema, TOutputSchema, TErrorMap> {
18
- name: "~pinia-colada";
19
- }
20
- /**
21
- * Define base Pinia Colada options and interceptors on a procedure contract.
22
- * Applied multiple times, later options are spread-merged with higher priority
23
- * while interceptors are concatenated. A key explicitly set to `undefined`
24
- * resets the value from earlier applications instead of merging.
25
- *
26
- * Apply them to router utils with {@link ContractOptionsUtilsPlugin}.
27
- *
28
- * @see {@link https://orpc.dev/docs/integrations/pinia-colada#contract-options-plugin | Pinia Colada Integration - Contract Options Plugin}
29
- */
30
- export declare function piniaColada<
31
- TInputSchema extends AnySchema,
32
- TOutputSchema extends AnySchema,
33
- TErrorMap extends ErrorMap
34
- >(options: PiniaColadaMetaOptions<ClientContext, InferSchemaInput<TInputSchema>, InferSchemaOutput<TOutputSchema>, ORPCErrorFromErrorMap<TErrorMap> | ThrowableError>): PiniaColadaMetaPlugin<TInputSchema, TOutputSchema, TErrorMap>;
35
- export declare function getPiniaColadaMeta(procedureOrLazy: {
36
- "~orpc": {
37
- meta: Meta;
38
- };
39
- }): PiniaColadaMetaOptions<ClientContext, unknown, unknown, ThrowableError> | undefined;
40
- /**
41
- * Router utils plugin that applies base options defined via {@link piniaColada}
42
- * on the given router contract. Meta options act as the base layer: options defined
43
- * on the utils override them, and utils interceptors run after meta interceptors.
44
- *
45
- * The contract shape must match the client the utils are created from,
46
- * so pass the root router contract when utils paths start from the root.
47
- *
48
- * @see {@link https://orpc.dev/docs/integrations/pinia-colada#contract-options-plugin | Pinia Colada Integration - Contract Options Plugin}
49
- */
50
- export declare class ContractOptionsUtilsPlugin<T extends AnyNestedClient = AnyNestedClient> implements RouterUtilsPlugin<T> {
51
- private readonly contract;
52
- readonly name = "~contract-options";
53
- constructor(contract: RouterContract);
54
- initProcedureOptions(path: string[], options: ProcedureUtilsOptions<InferClientContext<T>, any, any, InferClientError<T>>): ProcedureUtilsOptions<InferClientContext<T>, any, any, InferClientError<T>>;
55
- }
package/dist/meta.mjs DELETED
@@ -1,37 +0,0 @@
1
- import { getRouterContract, ProcedureContract } from "@orpc/contract";
2
- import { mergeProcedureUtilsOptions } from "./procedure-utils.mjs";
3
-
4
- export function piniaColada(options) {
5
- return {
6
- name: "~pinia-colada",
7
- init(meta) {
8
- const current = meta["~pinia-colada"];
9
- return {
10
- ...meta,
11
- "~pinia-colada": current ? mergeProcedureUtilsOptions(current, options) : options
12
- };
13
- }
14
- };
15
- }
16
- export function getPiniaColadaMeta(procedureOrLazy) {
17
- return procedureOrLazy["~orpc"].meta["~pinia-colada"];
18
- }
19
-
20
- export class ContractOptionsUtilsPlugin {
21
- contract;
22
- name = "~contract-options";
23
- constructor(contract) {
24
- this.contract = contract;
25
- }
26
- initProcedureOptions(path, options) {
27
- const procedure = getRouterContract(this.contract, path);
28
- if (!(procedure instanceof ProcedureContract)) {
29
- return options;
30
- }
31
- const base = getPiniaColadaMeta(procedure);
32
- if (!base) {
33
- return options;
34
- }
35
- return mergeProcedureUtilsOptions(base, options);
36
- }
37
- }
package/dist/plugin.d.mts DELETED
@@ -1,46 +0,0 @@
1
- import type { AnyNestedClient, InferClientContext, InferClientError } from "@orpc/client";
2
- import type { OrderablePlugin } from "@orpc/shared";
3
- import type { ProcedureUtilsOptions } from "./procedure-utils.mjs";
4
- import type { RouterUtilsOptions } from "./router-utils.mjs";
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.mjs DELETED
@@ -1,25 +0,0 @@
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
- }