@orpc/pinia-colada 2.0.0-beta.49 → 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.
@@ -1,12 +1,11 @@
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';
1
+ import { RouterUtils, RouterUtilsOptions } from "./router-utils.js";
2
+ import { ContractClientFactory, RouterContract, RouterContractClient } from "@orpc/contract";
3
+ import { ClientContext } from "@orpc/client";
4
+ import { ContractJsonifiedClientFactory, JsonifiedClient } from "@orpc/openapi";
5
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'> {
6
+ <T extends RouterContract>(contract: T): RouterUtils<RouterContractClient<T, TClientContext>>;
9
7
  }
8
+ export interface ContractUtilsFactoryOptions<TClientContext extends ClientContext> extends Omit<RouterUtilsOptions<RouterContractClient<RouterContract, TClientContext>>, "path"> {}
10
9
  /**
11
10
  * Creates a factory that builds Pinia Colada utils directly from a contract,
12
11
  * using the given contract client factory. Useful for scaling large projects
@@ -19,10 +18,9 @@ export interface ContractUtilsFactoryOptions<TClientContext extends ClientContex
19
18
  */
20
19
  export declare function createContractUtilsFactory<TClientContext extends ClientContext>(clientFactory: ContractClientFactory<TClientContext>, options: ContractUtilsFactoryOptions<TClientContext>): ContractUtilsFactory<TClientContext>;
21
20
  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'> {
21
+ <T extends RouterContract>(contract: T): RouterUtils<JsonifiedClient<RouterContractClient<T, TClientContext>>>;
25
22
  }
23
+ export interface ContractJsonifiedUtilsFactoryOptions<TClientContext extends ClientContext> extends Omit<RouterUtilsOptions<JsonifiedClient<RouterContractClient<RouterContract, TClientContext>>>, "path"> {}
26
24
  /**
27
25
  * Like `createContractUtilsFactory`, but for clients whose types are wrapped in `JsonifiedClient`,
28
26
  * such as clients using OpenAPI Link.
@@ -34,4 +32,4 @@ export interface ContractJsonifiedUtilsFactoryOptions<TClientContext extends Cli
34
32
  *
35
33
  * @see {@link https://orpc.dev/docs/contract/client-factory#pinia-colada-integration | Contract Client Factory - Pinia Colada Integration}
36
34
  */
37
- export declare function createContractJsonifiedUtilsFactory<TClientContext extends ClientContext>(clientFactory: ContractJsonifiedClientFactory<TClientContext>, options: ContractJsonifiedUtilsFactoryOptions<TClientContext>): ContractJsonifiedUtilsFactory<TClientContext>;
35
+ export declare function createContractJsonifiedUtilsFactory<TClientContext extends ClientContext>(clientFactory: ContractJsonifiedClientFactory<TClientContext>, options: ContractJsonifiedUtilsFactoryOptions<TClientContext>): ContractJsonifiedUtilsFactory<TClientContext>;
@@ -1,42 +1,42 @@
1
- import { resolveBasePathMeta } from '@orpc/contract';
2
- import { get } from '@orpc/shared';
3
- import { createRouterUtils } from './router-utils.js';
1
+ import { createRouterUtils } from "./router-utils.js";
2
+ import { resolveBasePathMeta } from "@orpc/contract";
3
+ import { get } from "@orpc/shared";
4
+ // src/contract-utils.ts
4
5
  /**
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;
6
+ * Creates a factory that builds Pinia Colada utils directly from a contract,
7
+ * using the given contract client factory. Useful for scaling large projects
8
+ * where each part only needs a slice of the router.
9
+ *
10
+ * @remarks
11
+ * **Note**: The contract must define a `path` meta matching its position in the root router contract.
12
+ *
13
+ * @see {@link https://orpc.dev/docs/contract/client-factory#pinia-colada-integration | Contract Client Factory - Pinia Colada Integration}
14
+ */
15
+ function createContractUtilsFactory(clientFactory, options) {
16
+ const factory = (contract) => {
17
+ const client = clientFactory(contract);
18
+ const path = resolveBasePathMeta(contract);
19
+ if (path === void 0) throw new TypeError("ContractUtilsFactory: procedure contract must define `meta.path` that matches its path in the root router contract.");
20
+ return createRouterUtils(client, {
21
+ ...options,
22
+ path,
23
+ scoped: get(options.scoped, path)
24
+ });
25
+ };
26
+ return factory;
28
27
  }
29
28
  /**
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);
29
+ * Like `createContractUtilsFactory`, but for clients whose types are wrapped in `JsonifiedClient`,
30
+ * such as clients using OpenAPI Link.
31
+ *
32
+ * @remarks
33
+ * Takes a client factory created by `createContractJsonifiedClientFactory` from `@orpc/openapi`.
34
+ *
35
+ * **Note**: The contract must define a `path` meta matching its position in the root router contract.
36
+ *
37
+ * @see {@link https://orpc.dev/docs/contract/client-factory#pinia-colada-integration | Contract Client Factory - Pinia Colada Integration}
38
+ */
39
+ function createContractJsonifiedUtilsFactory(clientFactory, options) {
40
+ return createContractUtilsFactory(clientFactory, options);
42
41
  }
42
+ export { createContractJsonifiedUtilsFactory, createContractUtilsFactory };
package/dist/index.d.ts CHANGED
@@ -1,20 +1,13 @@
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';
1
+ import { ContractJsonifiedUtilsFactory, ContractJsonifiedUtilsFactoryOptions, ContractUtilsFactory, ContractUtilsFactoryOptions, createContractJsonifiedUtilsFactory, createContractUtilsFactory } from "./contract-utils.js";
2
+ import { OperationKey, OperationKeyBaseOptions, OperationKeyOptions, OperationKeyPrefixOptions } from "./key.js";
3
+ import { ContractOptionsUtilsPlugin, PiniaColadaMetaOptions, PiniaColadaMetaPlugin, getPiniaColadaMeta, piniaColada } from "./meta.js";
4
+ import { RouterUtilsPlugin } from "./plugin.js";
5
+ import { ProcedureUtils, ProcedureUtilsInfiniteInterceptor, ProcedureUtilsInfiniteInterceptorOptions, ProcedureUtilsLiveInterceptor, ProcedureUtilsLiveInterceptorOptions, ProcedureUtilsModifier, ProcedureUtilsMutationInterceptor, ProcedureUtilsMutationInterceptorOptions, ProcedureUtilsOptions, ProcedureUtilsQueryInterceptor, ProcedureUtilsQueryInterceptorOptions, ProcedureUtilsStreamedInterceptor, ProcedureUtilsStreamedInterceptorOptions, mergeProcedureUtilsOptions } from "./procedure-utils.js";
6
+ import { RouterUtils, RouterUtilsOptions, RouterUtilsScoped, createRouterUtils } from "./router-utils.js";
7
+ import { SharedUtils } from "./shared-utils.js";
8
+ import { StreamQuerySSRUtilsPlugin, StreamQuerySSRUtilsPluginOptions } from "./ssr.js";
9
+ import { SerializableStreamedQueryOptions, SettleOnFirstDataOptions } from "./stream-query.js";
10
+ import { InferLiveQueryOutput, InferStreamedQueryOutput, InfiniteKeyOptions, InfiniteOptionsIn, InfiniteOptionsOut, LiveOptionsIn, MutationKeyOptions, MutationOptionsIn, MutationOptionsOut, OPERATION_CONTEXT_SYMBOL, OperationContext, OperationType, QueryKeyOptions, QueryOptionsIn, QueryOptionsOut, StreamedKeyOptions, StreamedOptionsIn, StreamedOptionsOut, UseMutationFnContext, UseQueryFnContext } from "./types.js";
11
+ import { Public } from "@orpc/shared";
12
+ import { AnyNestedClient } from "@orpc/client";
13
+ export { type AnyNestedClient, ContractJsonifiedUtilsFactory, ContractJsonifiedUtilsFactoryOptions, ContractOptionsUtilsPlugin, ContractUtilsFactory, ContractUtilsFactoryOptions, InferLiveQueryOutput, InferStreamedQueryOutput, InfiniteKeyOptions, InfiniteOptionsIn, InfiniteOptionsOut, LiveOptionsIn, MutationKeyOptions, MutationOptionsIn, MutationOptionsOut, OPERATION_CONTEXT_SYMBOL, OperationContext, type OperationKey, type OperationKeyBaseOptions, type OperationKeyOptions, type OperationKeyPrefixOptions, OperationType, OPERATION_CONTEXT_SYMBOL as PINIA_COLADA_OPERATION_CONTEXT_SYMBOL, PiniaColadaMetaOptions, PiniaColadaMetaPlugin, type OperationContext as PiniaColadaOperationContext, ProcedureUtils, type ProcedureUtilsInfiniteInterceptor, type ProcedureUtilsInfiniteInterceptorOptions, type ProcedureUtilsLiveInterceptor, type ProcedureUtilsLiveInterceptorOptions, type ProcedureUtilsModifier, type ProcedureUtilsMutationInterceptor, type ProcedureUtilsMutationInterceptorOptions, type ProcedureUtilsOptions, type ProcedureUtilsQueryInterceptor, type ProcedureUtilsQueryInterceptorOptions, type ProcedureUtilsStreamedInterceptor, type ProcedureUtilsStreamedInterceptorOptions, type Public, QueryKeyOptions, QueryOptionsIn, QueryOptionsOut, RouterUtils, RouterUtilsOptions, type RouterUtilsPlugin, RouterUtilsScoped, type SerializableStreamedQueryOptions, type SettleOnFirstDataOptions, SharedUtils, StreamQuerySSRUtilsPlugin, StreamQuerySSRUtilsPluginOptions, StreamedKeyOptions, StreamedOptionsIn, StreamedOptionsOut, UseMutationFnContext, UseQueryFnContext, createContractJsonifiedUtilsFactory, createContractUtilsFactory, createRouterUtils as createORPCVueColadaUtils, createRouterUtils as createPiniaColadaUtils, createRouterUtils, getPiniaColadaMeta, mergeProcedureUtilsOptions, piniaColada };
package/dist/index.js CHANGED
@@ -1,14 +1,7 @@
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';
1
+ export { createContractJsonifiedUtilsFactory, createContractUtilsFactory } from "./contract-utils.js";
2
+ export { ContractOptionsUtilsPlugin, getPiniaColadaMeta, piniaColada } from "./meta.js";
3
+ export { ProcedureUtils, mergeProcedureUtilsOptions } from "./procedure-utils.js";
4
+ export { createRouterUtils as createORPCVueColadaUtils, createRouterUtils as createPiniaColadaUtils, createRouterUtils } from "./router-utils.js";
5
+ export { SharedUtils } from "./shared-utils.js";
6
+ export { StreamQuerySSRUtilsPlugin } from "./ssr.js";
7
+ export { OPERATION_CONTEXT_SYMBOL, OPERATION_CONTEXT_SYMBOL as PINIA_COLADA_OPERATION_CONTEXT_SYMBOL } from "./types.js";
package/dist/key.d.ts CHANGED
@@ -1,45 +1,36 @@
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';
1
+ import { SerializableStreamedQueryOptions } from "./stream-query.js";
2
+ import { OperationType } from "./types.js";
3
+ import { PartialDeep, Public } from "@orpc/shared";
4
+ import { RPCJsonSerializer } from "@orpc/client";
5
+ import { EntryKey } from "@pinia/colada";
6
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;
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
12
  }
13
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;
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
21
  }
22
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;
23
+ type?: TType | undefined;
24
+ input?: PartialDeep<TInput> | undefined;
25
+ fnOptions?: (TType extends "streamed" ? SerializableStreamedQueryOptions : never) | undefined;
26
26
  };
27
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;
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
34
  };
35
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 {};
36
+ export {};
package/dist/key.js CHANGED
@@ -1,47 +1,45 @@
1
- import { RPCJsonSerializer } from '@orpc/client';
2
- import { stringifyJSON } from '@orpc/shared';
1
+ import { stringifyJSON } from "@orpc/shared";
2
+ import { RPCJsonSerializer } from "@orpc/client";
3
+ // src/key.ts
3
4
  const defaultSerializer = /* @__PURE__ */ new RPCJsonSerializer();
4
5
  /**
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
- ];
6
+ * Generate a Pinia Colada entry key for a procedure.
7
+ *
8
+ * The input is serialized to JSON-compatible values because Pinia Colada
9
+ * requires entry keys to be serializable.
10
+ *
11
+ * @see {@link https://orpc.dev/docs/integrations/pinia-colada#querymutation-key | Pinia Colada Integration - Query/Mutation Key}
12
+ */
13
+ function generateOperationKey(path, options = {}) {
14
+ return [
15
+ ...options.prefix !== void 0 ? [options.prefix] : [],
16
+ path,
17
+ {
18
+ ...options.input !== void 0 ? serializeInput(options.serializer ?? defaultSerializer, options.input) : {},
19
+ ...options.type !== void 0 ? { type: options.type } : {},
20
+ ...streamedKeyOptions(options.fnOptions)
21
+ }
22
+ ];
24
23
  }
25
24
  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 };
25
+ const { json, meta } = serializer.serializeJson(input);
26
+ if (!meta?.length) return { input: json };
27
+ const inputMeta = {};
28
+ for (const [type, ...segments] of meta) (inputMeta[stringifyJSON(segments)] ??= []).push(type);
29
+ return {
30
+ input: json,
31
+ inputMeta
32
+ };
36
33
  }
37
34
  /**
38
- * Leaves out default streamed options, so passing a default gives the same key as omitting it.
39
- */
35
+ * Leaves out default streamed options, so passing a default gives the same key as omitting it.
36
+ */
40
37
  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 } : {};
38
+ const { refetchMode, maxChunks } = options ?? {};
39
+ const fnOptions = {
40
+ ...refetchMode !== void 0 && refetchMode !== "reset" ? { refetchMode } : {},
41
+ ...maxChunks !== void 0 && maxChunks !== Number.POSITIVE_INFINITY ? { maxChunks } : {}
42
+ };
43
+ return Object.keys(fnOptions).length > 0 ? { fnOptions } : {};
47
44
  }
45
+ export { generateOperationKey };
@@ -1,38 +1,34 @@
1
- import { stringifyJSON, throwIfAborted } from '@orpc/shared';
1
+ import { listenAbort, stringifyJSON, throwIfAborted } from "@orpc/shared";
2
+ // src/live-query.ts
2
3
  /**
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
- };
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
+ function liveQuery(queryFn, { settleOnFirstData = false } = {}) {
8
+ return async (context) => {
9
+ const { entry, signal } = context;
10
+ listenAbort(signal, () => {
11
+ entry.when = 0;
12
+ });
13
+ const stream = await queryFn(context);
14
+ if (signal.aborted) {
15
+ await stream[Symbol.asyncIterator]().return?.();
16
+ throw signal.reason;
17
+ }
18
+ let last;
19
+ for await (const chunk of stream) {
20
+ throwIfAborted(signal);
21
+ last = { chunk };
22
+ entry.state.value = {
23
+ status: "success",
24
+ data: chunk,
25
+ error: null
26
+ };
27
+ if (settleOnFirstData) break;
28
+ }
29
+ throwIfAborted(signal);
30
+ if (!last) 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.`);
31
+ return last.chunk;
32
+ };
38
33
  }
34
+ export { liveQuery };
package/dist/meta.d.ts CHANGED
@@ -1,12 +1,12 @@
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';
1
+ import { OperationKeyBaseOptions } from "./key.js";
2
+ import { RouterUtilsPlugin } from "./plugin.js";
3
+ import { ProcedureUtilsOptions } from "./procedure-utils.js";
4
+ import { AnySchema, ErrorMap, InferSchemaInput, InferSchemaOutput, Meta, MetaPlugin, ORPCErrorFromErrorMap, RouterContract } from "@orpc/contract";
5
+ import { ThrowableError } from "@orpc/shared";
6
+ import { AnyNestedClient, ClientContext, InferClientContext, InferClientError } from "@orpc/client";
7
7
  export type PiniaColadaMetaOptions<TClientContext extends ClientContext, TInput, TOutput, TError> = Omit<ProcedureUtilsOptions<TClientContext, TInput, TOutput, TError>, keyof OperationKeyBaseOptions>;
8
8
  export interface PiniaColadaMetaPlugin<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> extends MetaPlugin<TInputSchema, TOutputSchema, TErrorMap> {
9
- name: '~pinia-colada';
9
+ name: "~pinia-colada";
10
10
  }
11
11
  /**
12
12
  * Define base Pinia Colada options and interceptors on a procedure contract.
@@ -20,9 +20,9 @@ export interface PiniaColadaMetaPlugin<TInputSchema extends AnySchema, TOutputSc
20
20
  */
21
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
22
  export declare function getPiniaColadaMeta(procedureOrLazy: {
23
- '~orpc': {
24
- meta: Meta;
25
- };
23
+ "~orpc": {
24
+ meta: Meta;
25
+ };
26
26
  }): PiniaColadaMetaOptions<ClientContext, unknown, unknown, ThrowableError> | undefined;
27
27
  /**
28
28
  * Router utils plugin that applies base options defined via {@link piniaColada}
@@ -35,8 +35,8 @@ export declare function getPiniaColadaMeta(procedureOrLazy: {
35
35
  * @see {@link https://orpc.dev/docs/integrations/pinia-colada#contract-options-plugin | Pinia Colada Integration - Contract Options Plugin}
36
36
  */
37
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
- }
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 CHANGED
@@ -1,55 +1,53 @@
1
- import { getRouterContract, ProcedureContract } from '@orpc/contract';
2
- import { mergeProcedureUtilsOptions } from './procedure-utils.js';
1
+ import { mergeProcedureUtilsOptions } from "./procedure-utils.js";
2
+ import { ProcedureContract, getRouterContract } from "@orpc/contract";
3
+ // src/meta.ts
3
4
  /**
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
- };
5
+ * Define base Pinia Colada options and interceptors on a procedure contract.
6
+ * Applied multiple times, later options are spread-merged with higher priority
7
+ * while interceptors are concatenated. A key explicitly set to `undefined`
8
+ * resets the value from earlier applications instead of merging.
9
+ *
10
+ * Apply them to router utils with {@link ContractOptionsUtilsPlugin}.
11
+ *
12
+ * @see {@link https://orpc.dev/docs/integrations/pinia-colada#contract-options-plugin | Pinia Colada Integration - Contract Options Plugin}
13
+ */
14
+ function piniaColada(options) {
15
+ return {
16
+ name: "~pinia-colada",
17
+ init(meta) {
18
+ const current = meta["~pinia-colada"];
19
+ return {
20
+ ...meta,
21
+ "~pinia-colada": current ? mergeProcedureUtilsOptions(current, options) : options
22
+ };
23
+ }
24
+ };
24
25
  }
25
- export function getPiniaColadaMeta(procedureOrLazy) {
26
- return procedureOrLazy['~orpc'].meta['~pinia-colada'];
26
+ function getPiniaColadaMeta(procedureOrLazy) {
27
+ return procedureOrLazy["~orpc"].meta["~pinia-colada"];
27
28
  }
28
29
  /**
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
- }
30
+ * Router utils plugin that applies base options defined via {@link piniaColada}
31
+ * on the given router contract. Meta options act as the base layer: options defined
32
+ * on the utils override them, and utils interceptors run after meta interceptors.
33
+ *
34
+ * The contract shape must match the client the utils are created from,
35
+ * so pass the root router contract when utils paths start from the root.
36
+ *
37
+ * @see {@link https://orpc.dev/docs/integrations/pinia-colada#contract-options-plugin | Pinia Colada Integration - Contract Options Plugin}
38
+ */
39
+ var ContractOptionsUtilsPlugin = class {
40
+ contract;
41
+ name = "~contract-options";
42
+ constructor(contract) {
43
+ this.contract = contract;
44
+ }
45
+ initProcedureOptions(path, options) {
46
+ const procedure = getRouterContract(this.contract, path);
47
+ if (!(procedure instanceof ProcedureContract)) return options;
48
+ const base = getPiniaColadaMeta(procedure);
49
+ if (!base) return options;
50
+ return mergeProcedureUtilsOptions(base, options);
51
+ }
52
+ };
53
+ export { ContractOptionsUtilsPlugin, getPiniaColadaMeta, piniaColada };