@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.
- package/dist/contract-utils.d.ts +9 -11
- package/dist/contract-utils.js +38 -38
- package/dist/index.d.ts +13 -20
- package/dist/index.js +7 -14
- package/dist/key.d.ts +27 -36
- package/dist/key.js +37 -39
- package/dist/live-query.js +32 -36
- package/dist/meta.d.ts +15 -15
- package/dist/meta.js +49 -51
- package/dist/plugin.d.ts +38 -45
- package/dist/plugin.js +19 -25
- package/dist/procedure-utils.d.ts +160 -163
- package/dist/procedure-utils.js +374 -390
- package/dist/router-utils.d.ts +45 -50
- package/dist/router-utils.js +50 -65
- package/dist/shared-utils.d.ts +12 -12
- package/dist/shared-utils.js +23 -21
- package/dist/ssr.d.ts +13 -13
- package/dist/ssr.js +21 -23
- package/dist/stream-query.d.ts +30 -39
- package/dist/stream-query.js +45 -57
- package/dist/types.d.ts +34 -34
- package/dist/types.js +8 -6
- package/package.json +5 -5
- package/dist/live-query.d.ts +0 -8
package/dist/contract-utils.d.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
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
|
-
|
|
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
|
-
|
|
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>;
|
package/dist/contract-utils.js
CHANGED
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
export { createRouterUtils as createPiniaColadaUtils
|
|
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
|
|
2
|
-
export
|
|
3
|
-
export {
|
|
4
|
-
export
|
|
5
|
-
export {
|
|
6
|
-
|
|
7
|
-
|
|
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 {
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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 {
|
|
2
|
-
import {
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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 };
|
package/dist/live-query.js
CHANGED
|
@@ -1,38 +1,34 @@
|
|
|
1
|
-
import { stringifyJSON, throwIfAborted } from
|
|
1
|
+
import { listenAbort, stringifyJSON, throwIfAborted } from "@orpc/shared";
|
|
2
|
+
// src/live-query.ts
|
|
2
3
|
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
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
|
-
|
|
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
|
-
|
|
24
|
-
|
|
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
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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 {
|
|
2
|
-
import {
|
|
1
|
+
import { mergeProcedureUtilsOptions } from "./procedure-utils.js";
|
|
2
|
+
import { ProcedureContract, getRouterContract } from "@orpc/contract";
|
|
3
|
+
// src/meta.ts
|
|
3
4
|
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
-
|
|
26
|
-
|
|
26
|
+
function getPiniaColadaMeta(procedureOrLazy) {
|
|
27
|
+
return procedureOrLazy["~orpc"].meta["~pinia-colada"];
|
|
27
28
|
}
|
|
28
29
|
/**
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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 };
|