@orpc/contract 1.14.11 → 1.14.12
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/README.md +81 -52
- package/dist/index.d.mts +301 -161
- package/dist/index.d.ts +301 -161
- package/dist/index.mjs +283 -136
- package/dist/plugins/index.d.mts +29 -24
- package/dist/plugins/index.d.ts +29 -24
- package/dist/plugins/index.mjs +63 -72
- package/dist/shared/contract.D_dZrO__.mjs +53 -0
- package/dist/shared/contract.TuRtB1Ca.d.mts +254 -0
- package/dist/shared/contract.TuRtB1Ca.d.ts +254 -0
- package/package.json +8 -7
- package/dist/shared/contract.CW-2wl1i.mjs +0 -180
- package/dist/shared/contract.Do92aRJ4.d.mts +0 -126
- package/dist/shared/contract.Do92aRJ4.d.ts +0 -126
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import { ThrowableError } from '@orpc/shared';
|
|
2
|
-
import { ORPCErrorCode, ORPCError } from '@orpc/client';
|
|
3
|
-
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* TOutput default = TInput for better readability (shorter) in-case both TInput, TOutput is equal
|
|
7
|
-
*/
|
|
8
|
-
type Schema<TInput, TOutput = TInput> = StandardSchemaV1<TInput, TOutput>;
|
|
9
|
-
type AnySchema = Schema<any>;
|
|
10
|
-
type SchemaIssue = StandardSchemaV1.Issue;
|
|
11
|
-
type InferSchemaInput<T extends AnySchema> = T extends StandardSchemaV1<infer UInput, any> ? UInput : never;
|
|
12
|
-
type InferSchemaOutput<T extends AnySchema> = T extends StandardSchemaV1<any, infer UOutput> ? UOutput : never;
|
|
13
|
-
type MergedSchema<T extends AnySchema, U extends AnySchema> = T extends Schema<infer TInput, infer TOutput> ? U extends Schema<infer UInput, infer UOutput> ? Schema<TInput & UInput, TOutput & UOutput> : never : never;
|
|
14
|
-
|
|
15
|
-
interface ErrorMapItem<TDataSchema extends AnySchema> {
|
|
16
|
-
message?: string;
|
|
17
|
-
data?: TDataSchema;
|
|
18
|
-
}
|
|
19
|
-
type ErrorMap = {
|
|
20
|
-
[key in ORPCErrorCode]?: ErrorMapItem<AnySchema>;
|
|
21
|
-
};
|
|
22
|
-
type ORPCErrorFromErrorMap<TErrorMap extends ErrorMap> = {
|
|
23
|
-
[K in keyof TErrorMap]: K extends string ? TErrorMap[K] extends ErrorMapItem<infer TDataSchema extends Schema<unknown>> ? ORPCError<K, InferSchemaOutput<TDataSchema>> : never : never;
|
|
24
|
-
}[keyof TErrorMap];
|
|
25
|
-
interface ValidationErrorOptions extends ErrorOptions {
|
|
26
|
-
message: string;
|
|
27
|
-
issues: readonly SchemaIssue[];
|
|
28
|
-
invalidData: unknown;
|
|
29
|
-
}
|
|
30
|
-
declare class ValidationError extends Error {
|
|
31
|
-
/**
|
|
32
|
-
* This array is readonly because the upstream Standard Schema returns readonly issues.
|
|
33
|
-
*/
|
|
34
|
-
issues: readonly SchemaIssue[];
|
|
35
|
-
invalidData: unknown;
|
|
36
|
-
constructor(options: ValidationErrorOptions);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
interface Meta {
|
|
40
|
-
[key: PropertyKey]: unknown;
|
|
41
|
-
}
|
|
42
|
-
interface MetaPluginDefinition<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> {
|
|
43
|
-
__TInputSchema?: {
|
|
44
|
-
type: TInputSchema;
|
|
45
|
-
};
|
|
46
|
-
__TOutputSchema?: {
|
|
47
|
-
type: TOutputSchema;
|
|
48
|
-
};
|
|
49
|
-
__TErrorMap?: {
|
|
50
|
-
type: TErrorMap;
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
interface MetaPlugin<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> {
|
|
54
|
-
/** This only for types, so it should be optional */
|
|
55
|
-
'~orpc'?: MetaPluginDefinition<TInputSchema, TOutputSchema, TErrorMap> | undefined;
|
|
56
|
-
/** Unique name of the plugin, used for identification. */
|
|
57
|
-
'name': string;
|
|
58
|
-
/**
|
|
59
|
-
* Runs once when this plugin is first added to the builder.
|
|
60
|
-
* Use this to set up initial metadata values.
|
|
61
|
-
*/
|
|
62
|
-
'init'?: (meta: Meta) => Meta;
|
|
63
|
-
/**
|
|
64
|
-
* Runs every time metadata is updated.
|
|
65
|
-
* This is called for all plugins in the chain whenever a new plugin is added.
|
|
66
|
-
*/
|
|
67
|
-
'apply'?: (meta: Meta) => Meta;
|
|
68
|
-
}
|
|
69
|
-
type AnyMetaPlugin = MetaPlugin<any, any, any>;
|
|
70
|
-
declare const HIDDEN_META_PLUGINS_SYMBOL: unique symbol;
|
|
71
|
-
declare function getHiddenMetaPlugins(container: unknown): AnyMetaPlugin[] | undefined;
|
|
72
|
-
declare function setHiddenMetaPlugins<T extends object>(container: T, metaPlugins: AnyMetaPlugin[]): void;
|
|
73
|
-
|
|
74
|
-
interface ProcedureContractDefinition<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> {
|
|
75
|
-
__TInputSchema?: {
|
|
76
|
-
type: TInputSchema;
|
|
77
|
-
};
|
|
78
|
-
__TOutputSchema?: {
|
|
79
|
-
type: TOutputSchema;
|
|
80
|
-
};
|
|
81
|
-
/**
|
|
82
|
-
* Non-serializable should be optional
|
|
83
|
-
*/
|
|
84
|
-
inputSchemas?: AnySchema[] | undefined;
|
|
85
|
-
outputSchemas?: AnySchema[] | undefined;
|
|
86
|
-
metaPlugins?: AnyMetaPlugin[] | undefined;
|
|
87
|
-
errorMap: TErrorMap;
|
|
88
|
-
meta: Meta;
|
|
89
|
-
}
|
|
90
|
-
declare class ProcedureContract<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> {
|
|
91
|
-
'~orpc': ProcedureContractDefinition<TInputSchema, TOutputSchema, TErrorMap>;
|
|
92
|
-
constructor(def: ProcedureContractDefinition<TInputSchema, TOutputSchema, TErrorMap>);
|
|
93
|
-
/**
|
|
94
|
-
* Checks if the given instance satisfies the {@see ProcedureContract} class/interface.
|
|
95
|
-
*/
|
|
96
|
-
static [Symbol.hasInstance](instance: unknown): boolean;
|
|
97
|
-
}
|
|
98
|
-
type AnyProcedureContract = ProcedureContract<any, any, any>;
|
|
99
|
-
|
|
100
|
-
type RouterContract = AnyProcedureContract | {
|
|
101
|
-
[k: string]: RouterContract;
|
|
102
|
-
};
|
|
103
|
-
type InferRouterContractInputs<T extends RouterContract> = T extends ProcedureContract<infer UInputSchema, any, any> ? InferSchemaInput<UInputSchema> : {
|
|
104
|
-
[K in keyof T]: T[K] extends RouterContract ? InferRouterContractInputs<T[K]> : never;
|
|
105
|
-
};
|
|
106
|
-
type InferRouterContractOutputs<T extends RouterContract> = T extends ProcedureContract<any, infer UOutputSchema, any> ? InferSchemaOutput<UOutputSchema> : {
|
|
107
|
-
[K in keyof T]: T[K] extends RouterContract ? InferRouterContractOutputs<T[K]> : never;
|
|
108
|
-
};
|
|
109
|
-
type InferRouterContractErrorMap<T extends RouterContract> = T extends ProcedureContract<any, any, infer UErrorMap> ? UErrorMap : {
|
|
110
|
-
[K in keyof T]: T[K] extends RouterContract ? InferRouterContractErrorMap<T[K]> : never;
|
|
111
|
-
}[keyof T];
|
|
112
|
-
/**
|
|
113
|
-
* Infer the union of throwable errors for entire router-contract.
|
|
114
|
-
*/
|
|
115
|
-
type InferRouterContractError<T extends RouterContract> = T extends ProcedureContract<any, any, infer UErrorMap> ? ORPCErrorFromErrorMap<UErrorMap> | ThrowableError : {
|
|
116
|
-
[K in keyof T]: T[K] extends RouterContract ? InferRouterContractError<T[K]> : never;
|
|
117
|
-
}[keyof T];
|
|
118
|
-
/**
|
|
119
|
-
* Infer throwable errors for each procedure-contract, preserving the router-contract shape.
|
|
120
|
-
*/
|
|
121
|
-
type InferRouterContractErrors<T extends RouterContract> = T extends ProcedureContract<any, any, infer UErrorMap> ? ORPCErrorFromErrorMap<UErrorMap> | ThrowableError : {
|
|
122
|
-
[K in keyof T]: T[K] extends RouterContract ? InferRouterContractErrors<T[K]> : never;
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
export { HIDDEN_META_PLUGINS_SYMBOL as H, ProcedureContract as P, ValidationError as V, getHiddenMetaPlugins as p, setHiddenMetaPlugins as s };
|
|
126
|
-
export type { AnySchema as A, ErrorMap as E, InferSchemaInput as I, MetaPlugin as M, ORPCErrorFromErrorMap as O, RouterContract as R, Schema as S, MergedSchema as a, Meta as b, AnyMetaPlugin as c, AnyProcedureContract as d, InferSchemaOutput as e, SchemaIssue as f, ErrorMapItem as g, InferRouterContractError as h, InferRouterContractErrorMap as i, InferRouterContractErrors as j, InferRouterContractInputs as k, InferRouterContractOutputs as l, MetaPluginDefinition as m, ProcedureContractDefinition as n, ValidationErrorOptions as o };
|