@orpc/contract 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 (81) hide show
  1. package/README.md +4 -4
  2. package/dist/builder-variants.d.ts +103 -0
  3. package/dist/builder.d.ts +78 -0
  4. package/dist/builder.js +112 -0
  5. package/dist/client-factory.d.ts +24 -0
  6. package/dist/client-factory.js +38 -0
  7. package/dist/error-factory.d.ts +80 -0
  8. package/dist/error-factory.js +121 -0
  9. package/dist/error-utils.d.ts +5 -0
  10. package/dist/error-utils.js +40 -0
  11. package/dist/error.d.ts +45 -0
  12. package/dist/error.js +20 -0
  13. package/dist/index.d.ts +62 -0
  14. package/dist/index.js +31 -0
  15. package/dist/meta-built-in.d.ts +30 -0
  16. package/dist/meta-built-in.js +54 -0
  17. package/dist/meta-utils.d.ts +58 -0
  18. package/dist/meta-utils.js +76 -0
  19. package/dist/meta.d.ts +53 -0
  20. package/dist/meta.js +13 -0
  21. package/dist/plugins/index.d.ts +12 -0
  22. package/dist/plugins/index.js +12 -0
  23. package/dist/plugins/request-validation.d.ts +28 -0
  24. package/dist/plugins/request-validation.js +55 -0
  25. package/dist/plugins/response-validation.d.ts +15 -0
  26. package/dist/plugins/response-validation.js +72 -0
  27. package/dist/procedure-client.d.ts +5 -0
  28. package/dist/procedure.d.ts +28 -0
  29. package/dist/procedure.js +28 -0
  30. package/dist/router-client.d.ts +13 -0
  31. package/dist/router-utils.d.ts +30 -0
  32. package/dist/router-utils.js +79 -0
  33. package/dist/router.d.ts +52 -0
  34. package/dist/schema-built-in.d.ts +23 -0
  35. package/dist/schema-built-in.js +76 -0
  36. package/dist/schema-utils.d.ts +20 -0
  37. package/dist/schema-utils.js +44 -0
  38. package/dist/schema.d.ts +25 -0
  39. package/package.json +28 -30
  40. package/dist/builder-variants.d.mts +0 -113
  41. package/dist/builder.d.mts +0 -78
  42. package/dist/builder.mjs +0 -71
  43. package/dist/client-factory.d.mts +0 -24
  44. package/dist/client-factory.mjs +0 -34
  45. package/dist/error-factory.d.mts +0 -87
  46. package/dist/error-factory.mjs +0 -75
  47. package/dist/error-utils.d.mts +0 -11
  48. package/dist/error-utils.mjs +0 -43
  49. package/dist/error.d.mts +0 -41
  50. package/dist/error.mjs +0 -12
  51. package/dist/index.d.mts +0 -62
  52. package/dist/index.mjs +0 -25
  53. package/dist/meta-built-in.d.mts +0 -38
  54. package/dist/meta-built-in.mjs +0 -40
  55. package/dist/meta-utils.d.mts +0 -62
  56. package/dist/meta-utils.mjs +0 -33
  57. package/dist/meta.d.mts +0 -61
  58. package/dist/meta.mjs +0 -11
  59. package/dist/plugins/index.d.mts +0 -12
  60. package/dist/plugins/index.mjs +0 -8
  61. package/dist/plugins/request-validation.d.mts +0 -28
  62. package/dist/plugins/request-validation.mjs +0 -46
  63. package/dist/plugins/response-validation.d.mts +0 -15
  64. package/dist/plugins/response-validation.mjs +0 -53
  65. package/dist/procedure-client.d.mts +0 -10
  66. package/dist/procedure.d.mts +0 -36
  67. package/dist/procedure.mjs +0 -19
  68. package/dist/router-client.d.mts +0 -14
  69. package/dist/router-utils.d.mts +0 -34
  70. package/dist/router-utils.mjs +0 -67
  71. package/dist/router.d.mts +0 -42
  72. package/dist/schema-built-in.d.mts +0 -28
  73. package/dist/schema-built-in.mjs +0 -73
  74. package/dist/schema-utils.d.mts +0 -26
  75. package/dist/schema-utils.mjs +0 -29
  76. package/dist/schema.d.mts +0 -31
  77. /package/dist/{builder-variants.mjs → builder-variants.js} +0 -0
  78. /package/dist/{procedure-client.mjs → procedure-client.js} +0 -0
  79. /package/dist/{router-client.mjs → router-client.js} +0 -0
  80. /package/dist/{router.mjs → router.js} +0 -0
  81. /package/dist/{schema.mjs → schema.js} +0 -0
@@ -1,78 +0,0 @@
1
- import type { ProcedureContractBuilderWithInput, ProcedureContractBuilderWithOutput } from "./builder-variants.mjs";
2
- import type { ErrorMap } from "./error.mjs";
3
- import type { MergedErrorMap } from "./error-utils.mjs";
4
- import type { MetaPlugin } from "./meta.mjs";
5
- import type { RouterContract } from "./router.mjs";
6
- import type { AugmentedContractRouter } from "./router-utils.mjs";
7
- import type { AnySchema, Schema } from "./schema.mjs";
8
- import { ProcedureContract } from "./procedure.mjs";
9
- /**
10
- * The input schema type used before `.input` is called.
11
- * Input is `void` for better compatibility with third-party libraries,
12
- * such as TanStack Query, which allow calling mutations without input.
13
- */
14
- export type InitialInputSchema = Schema<void, unknown>;
15
- /**
16
- * The output schema type used before `.output` is called.
17
- */
18
- export type InitialOutputSchema = Schema<unknown>;
19
- /**
20
- * The contract builder behind `oc`. Chain its methods to define procedure
21
- * contracts — metadata, errors, and input/output schemas — without any
22
- * business logic.
23
- *
24
- * @see {@link https://orpc.dev/docs/contract/procedure | Procedure Contract}
25
- */
26
- export declare class ContractBuilder<TErrorMap extends ErrorMap> extends ProcedureContract<InitialInputSchema, InitialOutputSchema, TErrorMap> {
27
- /**
28
- * Private constructor to prevent direct instantiation.
29
- * Use the static `create` method to initialize a new instance with a safe initial definition.
30
- */
31
- private constructor();
32
- /**
33
- * Creates a fresh contract builder with an empty definition.
34
- * Prefer the exported `oc` instance over calling this directly.
35
- *
36
- * @see {@link https://orpc.dev/docs/contract/procedure | Procedure Contract}
37
- */
38
- static create(): ContractBuilder<Record<never, never>>;
39
- /**
40
- * Applies metadata plugins to contracts built from this builder.
41
- *
42
- * @see {@link https://orpc.dev/docs/contract/procedure#metadata | Procedure Contract - Metadata}
43
- */
44
- meta(...plugins: MetaPlugin<InitialInputSchema, InitialOutputSchema, TErrorMap>[]): ContractBuilder<TErrorMap>;
45
- /**
46
- * Defines typesafe errors that implementations of this contract can throw.
47
- *
48
- * @see {@link https://orpc.dev/docs/contract/procedure#typesafe-errors | Procedure Contract - Typesafe Errors}
49
- */
50
- errors<T extends ErrorMap>(errors: T): ContractBuilder<MergedErrorMap<TErrorMap, T>>;
51
- /**
52
- * Defines the input schema used to validate and type the procedure input.
53
- *
54
- * @see {@link https://orpc.dev/docs/contract/procedure#inputoutput-validation | Procedure Contract - Input/Output Validation}
55
- */
56
- input<T extends AnySchema>(schema: T): ProcedureContractBuilderWithInput<T, TErrorMap>;
57
- /**
58
- * Defines the output schema used to validate and type the procedure output.
59
- *
60
- * @see {@link https://orpc.dev/docs/contract/procedure#inputoutput-validation | Procedure Contract - Input/Output Validation}
61
- */
62
- output<T extends AnySchema>(schema: T): ProcedureContractBuilderWithOutput<T, TErrorMap>;
63
- /**
64
- * Applies the builder's errors and metadata to every procedure contract in
65
- * the given router contract.
66
- *
67
- * @see {@link https://orpc.dev/docs/contract/router#extending-router | Router Contract - Extending Router}
68
- */
69
- router<T extends RouterContract>(router: T): AugmentedContractRouter<T, TErrorMap>;
70
- }
71
- /**
72
- * The oRPC contract builder. Chain methods like `.input`, `.errors`, and
73
- * `.output` to define procedure contracts, then compose them into router
74
- * contracts.
75
- *
76
- * @see {@link https://orpc.dev/docs/contract/procedure | Procedure Contract}
77
- */
78
- export declare const oc: ContractBuilder<Record<never, never>>;
package/dist/builder.mjs DELETED
@@ -1,71 +0,0 @@
1
- import { toArray } from "@orpc/shared";
2
- import { mergeErrorMap } from "./error-utils.mjs";
3
- import { getHiddenMetaPlugins } from "./meta.mjs";
4
- import { resolveMetaPlugins } from "./meta-utils.mjs";
5
- import { ProcedureContract } from "./procedure.mjs";
6
- import { augmentContractRouter } from "./router-utils.mjs";
7
-
8
- export class ContractBuilder extends ProcedureContract {
9
-
10
- constructor(definition) {
11
- super(definition);
12
- }
13
-
14
- static create() {
15
- return new ContractBuilder({
16
- errorMap: {},
17
- meta: {}
18
- });
19
- }
20
-
21
- meta(...plugins) {
22
- const [meta, metaPlugins] = resolveMetaPlugins(this["~orpc"].meta, this["~orpc"].metaPlugins, plugins);
23
- return new ContractBuilder({
24
- ...this["~orpc"],
25
- meta,
26
- metaPlugins
27
- });
28
- }
29
-
30
- errors(errors) {
31
- let result = new ContractBuilder({
32
- ...this["~orpc"],
33
- errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
34
- });
35
- const plugins = getHiddenMetaPlugins(errors);
36
- if (plugins) {
37
- result = result.meta(...plugins);
38
- }
39
- return result;
40
- }
41
-
42
- input(schema) {
43
- let result = new ContractBuilder({
44
- ...this["~orpc"],
45
- inputSchemas: [...toArray(this["~orpc"].inputSchemas), schema]
46
- });
47
- const plugins = getHiddenMetaPlugins(schema);
48
- if (plugins) {
49
- result = result.meta(...plugins);
50
- }
51
- return result;
52
- }
53
-
54
- output(schema) {
55
- let result = new ContractBuilder({
56
- ...this["~orpc"],
57
- outputSchemas: [...toArray(this["~orpc"].outputSchemas), schema]
58
- });
59
- const plugins = getHiddenMetaPlugins(schema);
60
- if (plugins) {
61
- result = result.meta(...plugins);
62
- }
63
- return result;
64
- }
65
-
66
- router(router) {
67
- return augmentContractRouter(router, this["~orpc"]);
68
- }
69
- }
70
-
71
- export const oc = /* @__PURE__ */ ContractBuilder.create();
@@ -1,24 +0,0 @@
1
- import type { ClientContext, ClientLink, ORPCClientOptions } from "@orpc/client";
2
- import type { RouterContract } from "./router.mjs";
3
- import type { RouterContractClient } from "./router-client.mjs";
4
- export interface ContractClientFactory<TClientContext extends ClientContext> {
5
- <T extends RouterContract>(contract: T): RouterContractClient<T, TClientContext>;
6
- }
7
- export interface ContractClientFactoryOptions<TClientContext extends ClientContext> extends Pick<ORPCClientOptions<RouterContractClient<RouterContract, TClientContext>>, "interceptors" | "scoped"> {
8
- /**
9
- * An optional reference to the root router-contract.
10
- * When provided, the client factory will automatically register the passed contract
11
- * into the router at the path defined by `meta.path`.
12
- */
13
- contractRef?: RouterContract | undefined;
14
- }
15
- /**
16
- * Creates a client factory that builds a client from any procedure or router contract,
17
- * so large projects can import individual contracts instead of a single root client.
18
- *
19
- * @remarks
20
- * **Warning**: Every procedure contract passed to the factory must define `meta.path` matching its location in the root contract.
21
- *
22
- * @see {@link https://orpc.dev/docs/contract/client-factory | Contract Client Factory}
23
- */
24
- export declare function createContractClientFactory<TClientContext extends ClientContext>(link: ClientLink<TClientContext>, options?: ContractClientFactoryOptions<TClientContext>): ContractClientFactory<TClientContext>;
@@ -1,34 +0,0 @@
1
- import { createORPCClient } from "@orpc/client";
2
- import { get, isTypescriptObject, set } from "@orpc/shared";
3
- import { resolveBasePathMeta } from "./meta-built-in.mjs";
4
- import { ProcedureContract } from "./procedure.mjs";
5
-
6
- export function createContractClientFactory(link, options = {}) {
7
- const factory = (contract) => {
8
- const path = resolveBasePathMeta(contract);
9
- if (path === undefined) {
10
- throw new TypeError("ContractClientFactory: procedure contract must define `meta.path` that matches its path in the root router contract.");
11
- }
12
- const contractRef = options.contractRef;
13
- if (contractRef) {
14
- const register = (contract, path) => {
15
- if (contract instanceof ProcedureContract) {
16
- set(contractRef, [...path, "~orpc"], contract["~orpc"]);
17
- return;
18
- }
19
- if (isTypescriptObject(contract)) {
20
- for (const [key, value] of Object.entries(contract)) {
21
- register(value, [...path, key]);
22
- }
23
- }
24
- };
25
- register(contract, path);
26
- }
27
- return createORPCClient(link, {
28
- ...options,
29
- scoped: get(options.scoped, path),
30
- path
31
- });
32
- };
33
- return factory;
34
- }
@@ -1,87 +0,0 @@
1
- import type { ORPCErrorCode, ORPCErrorOptions } from "@orpc/client";
2
- import type { MaybeOptionalOptions } from "@orpc/shared";
3
- import type { ErrorMap, ErrorMapItem } from "./error.mjs";
4
- import type { AnySchema, InferSchemaInput, Schema } from "./schema.mjs";
5
- import { ORPCError } from "@orpc/client";
6
- export interface ORPCErrorFactoryOptions<TData> {
7
- /**
8
- * Optional schema used to type and validate the error data.
9
- * Must be a synchronous schema.
10
- */
11
- data?: Schema<TData> | undefined;
12
- /**
13
- * Optional default message, can be overridden when constructing an error.
14
- */
15
- message?: string | undefined;
16
- }
17
- export interface ORPCErrorFactory<
18
- TCode extends ORPCErrorCode,
19
- TData
20
- > extends ErrorMapItem {
21
- code: TCode;
22
- data: Schema<TData>;
23
- new (...rest: MaybeOptionalOptions<ORPCErrorOptions<TData>>): ORPCError<TCode, TData>;
24
- }
25
- /**
26
- * Creates a reusable error class ({@link ORPCErrorFactory}) for the given code,
27
- * default message, and data schema.
28
- *
29
- * @example
30
- * ```ts
31
- * const RateLimitedError = error('RATE_LIMITED', {
32
- * message: 'You are being rate limited',
33
- * data: z.object({ retryAfter: z.number() }),
34
- * })
35
- *
36
- * const procedure = os
37
- * .errors({ [RateLimitedError.code]: RateLimitedError })
38
- * .handler(() => {
39
- * throw new RateLimitedError({ data: { retryAfter: 60 } })
40
- * })
41
- *
42
- * try {
43
- * const output = call(procedure)
44
- * } catch (error) {
45
- * if (error instanceof RateLimitedError) {
46
- * console.log(error.data.retryAfter)
47
- * }
48
- * }
49
- * ```
50
- *
51
- * @see {@link https://orpc.dev/docs/error-handling#error-factory | Error Handling - Error Factory}
52
- */
53
- export declare function error<
54
- TCode extends ORPCErrorCode,
55
- TData = unknown
56
- >(code: TCode, { data: dataSchema, message }?: ORPCErrorFactoryOptions<TData>): ORPCErrorFactory<TCode, TData>;
57
- export type ORPCErrorConstructorMapItemOptions<TData> = Omit<ORPCErrorOptions<TData>, "status">;
58
- export interface ORPCErrorConstructorMapItem<
59
- TCode extends ORPCErrorCode,
60
- TInData
61
- > {
62
- (...rest: MaybeOptionalOptions<ORPCErrorConstructorMapItemOptions<TInData>>): ORPCError<TCode, TInData>;
63
- }
64
- export type ORPCErrorConstructorMap<T extends ErrorMap> = { [K in keyof T]: T[K] extends ErrorMapItem ? ORPCErrorConstructorMapItem<K & ORPCErrorCode, T[K]["data"] extends AnySchema ? InferSchemaInput<T[K]["data"]> : unknown> : never };
65
- /**
66
- * Creates a map of ORPC error constructors.
67
- *
68
- * The returned object is a `Proxy` that allows access to arbitrary error codes:
69
- * - If the code exists in the provided `errorMap`, the corresponding constructor
70
- * will create a **defined** `ORPCError`.
71
- * - If the code does not exist, a fallback `ORPCError` constructor is returned.
72
- *
73
- * The `in` operator can be used to check whether an error code is explicitly
74
- * defined in the map.
75
- *
76
- * @example
77
- * ```ts
78
- * const errorMap = createORPCErrorConstructorMap({
79
- * NOT_FOUND: {
80
- * message: 'Not Found',
81
- * },
82
- * })
83
- *
84
- * throw errorMap.NOT_FOUND()
85
- * ```
86
- */
87
- export declare function createORPCErrorConstructorMap<T extends ErrorMap>(errorMap: T): ORPCErrorConstructorMap<T>;
@@ -1,75 +0,0 @@
1
- import { ORPCError, RECURSIVE_CLIENT_UNWRAP_KEYS } from "@orpc/client";
2
- import { getOwn, resolveMaybeOptionalOptions } from "@orpc/shared";
3
- import { ValidationError } from "./error.mjs";
4
- import { type } from "./schema-utils.mjs";
5
-
6
- export function error(code, { data: dataSchema, message } = {}) {
7
- const validateData = (schema, value) => {
8
- const result = schema["~standard"].validate(value);
9
- if (result instanceof Promise) {
10
- throw new TypeError(`Error factory "${code}" does not support async data schemas.`);
11
- }
12
- return result;
13
- };
14
- return class extends ORPCError {
15
- static code = code;
16
- static data = dataSchema ?? type();
17
- static message = message;
18
- constructor(...rest) {
19
- const options = resolveMaybeOptionalOptions(rest);
20
- let data = options.data;
21
- if (dataSchema) {
22
- const result = validateData(dataSchema, options.data);
23
- if (result.issues) {
24
- throw new ValidationError({
25
- message: `Error factory "${code}" data validation failed`,
26
- issues: result.issues,
27
- invalidData: options.data
28
- });
29
- }
30
- data = result.value;
31
- }
32
- super(code, {
33
- ...options,
34
- message: options.message ?? message,
35
- data
36
- });
37
- }
38
- static [Symbol.hasInstance](instance) {
39
- if (!(instance instanceof ORPCError)) {
40
- return false;
41
- }
42
- if (instance.code !== code) {
43
- return false;
44
- }
45
- if (dataSchema && validateData(dataSchema, instance.data).issues) {
46
- return false;
47
- }
48
- return true;
49
- }
50
- };
51
- }
52
-
53
- export function createORPCErrorConstructorMap(errorMap) {
54
- const proxy = new Proxy(errorMap, { get(target, code) {
55
- if (typeof code !== "string" || RECURSIVE_CLIENT_UNWRAP_KEYS.has(code)) {
56
- return Reflect.get(target, code);
57
- }
58
- const item = (...rest) => {
59
- const options = resolveMaybeOptionalOptions(rest);
60
- const config = getOwn(errorMap, code);
61
- const error = new ORPCError(code, {
62
- message: options.message ?? config?.message,
63
- data: options.data,
64
- cause: options.cause
65
- });
66
- if (config) {
67
- ;
68
- error.defined = true;
69
- }
70
- return error;
71
- };
72
- return item;
73
- } });
74
- return proxy;
75
- }
@@ -1,11 +0,0 @@
1
- import type { AnyORPCError } from "@orpc/client";
2
- import type { ErrorMap } from "./error.mjs";
3
- export type MergedErrorMap<
4
- T1 extends ErrorMap,
5
- T2 extends ErrorMap
6
- > = keyof T1 extends never | keyof T2 ? T2 : Omit<T1, keyof T2> & T2;
7
- export declare function mergeErrorMap<
8
- T1 extends ErrorMap = object,
9
- T2 extends ErrorMap = object
10
- >(errorMap1: T1 | undefined, errorMap2: T2 | undefined): MergedErrorMap<T1, T2>;
11
- export declare function reconcileORPCError(map: ErrorMap, error: AnyORPCError): Promise<AnyORPCError>;
@@ -1,43 +0,0 @@
1
- import { cloneORPCError } from "@orpc/client";
2
- import { getOwn } from "@orpc/shared";
3
- export function mergeErrorMap(errorMap1, errorMap2) {
4
- return {
5
- ...errorMap1,
6
- ...errorMap2
7
- };
8
- }
9
- export async function reconcileORPCError(map, error) {
10
- const config = getOwn(map, error.code);
11
- if (!config) {
12
- if (!error.defined) {
13
- return error;
14
- }
15
- const cloned = cloneORPCError(error);
16
- cloned.defined = false;
17
- return cloned;
18
- }
19
- if (!config.data) {
20
- if (error.defined) {
21
- return error;
22
- }
23
- const cloned = cloneORPCError(error);
24
- cloned.defined = true;
25
- return cloned;
26
- }
27
- const validated = await config.data["~standard"].validate(error.data);
28
- if (validated.issues) {
29
- if (!error.defined) {
30
- return error;
31
- }
32
- const cloned = cloneORPCError(error);
33
- cloned.defined = false;
34
- return cloned;
35
- }
36
- if (error.data === validated.value && error.defined) {
37
- return error;
38
- }
39
- const cloned = cloneORPCError(error);
40
- cloned.data = validated.value;
41
- cloned.defined = true;
42
- return cloned;
43
- }
package/dist/error.d.mts DELETED
@@ -1,41 +0,0 @@
1
- import type { ORPCError, ORPCErrorCode } from "@orpc/client";
2
- import type { AnySchema, InferSchemaOutput, SchemaIssue } from "./schema.mjs";
3
- export interface ErrorMapItem {
4
- /**
5
- * Default message, can be overridden when constructing an error.
6
- */
7
- message?: string | undefined;
8
- /**
9
- * Schema used to type and validate the error data.
10
- */
11
- data?: AnySchema | undefined;
12
- }
13
- /**
14
- * Map of error codes to their definitions, as passed to `.errors(...)`.
15
- * Errors defined here remain properly typed on the client.
16
- *
17
- * @see {@link https://orpc.dev/docs/metadata | Metadata}
18
- */
19
- export type ErrorMap = { [key in ORPCErrorCode]?: ErrorMapItem };
20
- export type ORPCErrorFromErrorMap<TErrorMap extends ErrorMap> = { [K in keyof TErrorMap]: TErrorMap[K] extends ErrorMapItem ? ORPCError<K & ORPCErrorCode, TErrorMap[K]["data"] extends AnySchema ? InferSchemaOutput<TErrorMap[K]["data"]> : unknown> : never }[keyof TErrorMap];
21
- export interface ValidationErrorOptions extends ErrorOptions {
22
- message: string;
23
- issues: readonly SchemaIssue[];
24
- invalidData: unknown;
25
- }
26
- /**
27
- * Error thrown when input, output, or error data fails schema validation,
28
- * carrying the standard-schema `issues` and the invalid data.
29
- * Usually found as the `cause` of an `ORPCError`.
30
- *
31
- * @see {@link https://orpc.dev/docs/recipes/validation-customization | Validation Customization}
32
- */
33
- export declare class ValidationError extends Error {
34
- override name: string;
35
- /**
36
- * This array is readonly because the upstream Standard Schema returns readonly issues.
37
- */
38
- issues: readonly SchemaIssue[];
39
- invalidData: unknown;
40
- constructor(options: ValidationErrorOptions);
41
- }
package/dist/error.mjs DELETED
@@ -1,12 +0,0 @@
1
-
2
- export class ValidationError extends Error {
3
- name = "ValidationError";
4
-
5
- issues;
6
- invalidData;
7
- constructor(options) {
8
- super(options.message, options);
9
- this.issues = options.issues;
10
- this.invalidData = options.invalidData;
11
- }
12
- }
package/dist/index.d.mts DELETED
@@ -1,62 +0,0 @@
1
- export * from "./builder.mjs";
2
- export * from "./builder-variants.mjs";
3
- export * from "./client-factory.mjs";
4
- export * from "./error.mjs";
5
- export * from "./error-factory.mjs";
6
- export * from "./error-utils.mjs";
7
- export * from "./meta.mjs";
8
- export * from "./meta-built-in.mjs";
9
- export * from "./meta-utils.mjs";
10
- export * from "./procedure.mjs";
11
- export type {
12
- /**
13
- * @deprecated Use `AnyProcedureContract` instead.
14
- */
15
- AnyProcedureContract as AnyContractProcedure } from "./procedure.mjs";
16
- export * from "./procedure-client.mjs";
17
- export * from "./router.mjs";
18
- export type {
19
- /**
20
- * @deprecated Use `RouterContract` instead.
21
- */
22
- RouterContract as AnyContractRouter,
23
- /**
24
- * @deprecated Use `InferRouterContractErrorMap` instead.
25
- */
26
- InferRouterContractErrorMap as InferContractRouterErrorMap,
27
- /**
28
- * @deprecated Use `InferRouterContractInputs` instead.
29
- */
30
- InferRouterContractInputs as InferContractRouterInputs,
31
- /**
32
- * @deprecated Use `InferRouterContractOutputs` instead.
33
- */
34
- InferRouterContractOutputs as InferContractRouterOutputs } from "./router.mjs";
35
- export * from "./router-client.mjs";
36
- export type {
37
- /**
38
- * @deprecated Use `RouterContractClient` instead.
39
- */
40
- RouterContractClient as ContractRouterClient } from "./router-client.mjs";
41
- export { getProcedureContractOrThrow, getRouterContract, minifyRouterContract } from "./router-utils.mjs";
42
- export type { AugmentContractRouterOptions, AugmentedContractRouter } from "./router-utils.mjs";
43
- export {
44
- /**
45
- * @deprecated Use `getRouterContract` instead.
46
- */
47
- getRouterContract as getContractRouter,
48
- /**
49
- * @deprecated Use `minifyRouterContract` instead.
50
- */
51
- minifyRouterContract as minifyContractRouter } from "./router-utils.mjs";
52
- export * from "./schema.mjs";
53
- export { asyncIteratorObject, getAsyncIteratorObjectSchemasDetails } from "./schema-built-in.mjs";
54
- export type { AsyncIteratorObjectSchemasDetails } from "./schema-built-in.mjs";
55
- export {
56
- /**
57
- * @deprecated Use `asyncIteratorObject` instead.
58
- */
59
- asyncIteratorObject as eventIterator } from "./schema-built-in.mjs";
60
- export * from "./schema-utils.mjs";
61
- export type { Client, ClientContext, ClientOptions, ClientRest, FriendlyClientOptions } from "@orpc/client";
62
- export type { AsyncIteratorClass, PromiseWithError, Registry, ThrowableError } from "@orpc/shared";
package/dist/index.mjs DELETED
@@ -1,25 +0,0 @@
1
- export * from "./builder.mjs";
2
- export * from "./builder-variants.mjs";
3
- export * from "./client-factory.mjs";
4
- export * from "./error.mjs";
5
- export * from "./error-factory.mjs";
6
- export * from "./error-utils.mjs";
7
- export * from "./meta.mjs";
8
- export * from "./meta-built-in.mjs";
9
- export * from "./meta-utils.mjs";
10
- export * from "./procedure.mjs";
11
- export * from "./procedure-client.mjs";
12
- export * from "./router.mjs";
13
- export * from "./router-client.mjs";
14
- export { getProcedureContractOrThrow, getRouterContract, minifyRouterContract } from "./router-utils.mjs";
15
- export {
16
-
17
- getRouterContract as getContractRouter,
18
-
19
- minifyRouterContract as minifyContractRouter } from "./router-utils.mjs";
20
- export * from "./schema.mjs";
21
- export { asyncIteratorObject, getAsyncIteratorObjectSchemasDetails } from "./schema-built-in.mjs";
22
- export {
23
-
24
- asyncIteratorObject as eventIterator } from "./schema-built-in.mjs";
25
- export * from "./schema-utils.mjs";
@@ -1,38 +0,0 @@
1
- import type { ErrorMap } from "./error.mjs";
2
- import type { Meta, MetaPlugin } from "./meta.mjs";
3
- import type { RouterContract } from "./router.mjs";
4
- import type { AnySchema } from "./schema.mjs";
5
- export interface PathMetaPlugin<
6
- TInputSchema extends AnySchema,
7
- TOutputSchema extends AnySchema,
8
- TErrorMap extends ErrorMap
9
- > extends MetaPlugin<TInputSchema, TOutputSchema, TErrorMap> {
10
- name: "~path";
11
- }
12
- /**
13
- * Built-in metadata plugins.
14
- * `meta.path` records a procedure contract's path inside the root contract,
15
- * which is required for the contract client factory pattern.
16
- *
17
- * @see {@link https://orpc.dev/docs/contract/client-factory | Contract Client Factory}
18
- */
19
- export declare const meta: {
20
- path<
21
- TInputSchema extends AnySchema,
22
- TOutputSchema extends AnySchema,
23
- TErrorMap extends ErrorMap
24
- >(path: string[]): PathMetaPlugin<TInputSchema, TOutputSchema, TErrorMap>;
25
- };
26
- export declare function getPathMeta(procedureOrLazy: {
27
- "~orpc": {
28
- meta: Meta;
29
- };
30
- }): string[] | undefined;
31
- /**
32
- * Resolve the base path of a contract from the first procedure-contract
33
- * that defines `meta.path`: its `meta.path` minus its path inside the given contract.
34
- * For a procedure-contract, this is its `meta.path` itself.
35
- *
36
- * Returns `undefined` when no procedure-contract defines `meta.path`.
37
- */
38
- export declare function resolveBasePathMeta(contract: RouterContract, currentPath?: string[]): string[] | undefined;
@@ -1,40 +0,0 @@
1
- import { isTypescriptObject } from "@orpc/shared";
2
- import { ProcedureContract } from "./procedure.mjs";
3
-
4
- export const meta = { path(path) {
5
- return {
6
- name: "~path",
7
- init(meta) {
8
- return {
9
- ...meta,
10
- "~path": path
11
- };
12
- }
13
- };
14
- } };
15
- export function getPathMeta(procedureOrLazy) {
16
- return procedureOrLazy["~orpc"].meta["~path"];
17
- }
18
-
19
- export function resolveBasePathMeta(contract, currentPath = []) {
20
- if (contract instanceof ProcedureContract) {
21
- const path = getPathMeta(contract);
22
- if (!path) {
23
- return undefined;
24
- }
25
- const base = path.slice(0, Math.max(0, path.length - currentPath.length));
26
- if (currentPath.some((key, i) => path[base.length + i] !== key)) {
27
- throw new TypeError(`Procedure contract at "${currentPath.join(".")}" defines meta.path "${path.join(".")}" that does not match its path inside the given router contract.`);
28
- }
29
- return base;
30
- }
31
- if (isTypescriptObject(contract)) {
32
- for (const [key, child] of Object.entries(contract)) {
33
- const base = resolveBasePathMeta(child, [...currentPath, key]);
34
- if (base !== undefined) {
35
- return base;
36
- }
37
- }
38
- }
39
- return undefined;
40
- }