@temporary-name/server 1.9.3-alpha.e098b3d1c5bffbad2fadfda89ba01f6452db46b5 → 1.9.3-alpha.ec3bfb9dce56198911349c322c970208b21b50db
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/adapters/aws-lambda/index.d.mts +4 -5
- package/dist/adapters/aws-lambda/index.d.ts +4 -5
- package/dist/adapters/aws-lambda/index.mjs +4 -4
- package/dist/adapters/fetch/index.d.mts +8 -85
- package/dist/adapters/fetch/index.d.ts +8 -85
- package/dist/adapters/fetch/index.mjs +16 -155
- package/dist/adapters/node/index.d.mts +8 -62
- package/dist/adapters/node/index.d.ts +8 -62
- package/dist/adapters/node/index.mjs +14 -120
- package/dist/adapters/standard/index.d.mts +5 -6
- package/dist/adapters/standard/index.d.ts +5 -6
- package/dist/adapters/standard/index.mjs +4 -4
- package/dist/helpers/index.mjs +3 -29
- package/dist/index.d.mts +110 -199
- package/dist/index.d.ts +110 -199
- package/dist/index.mjs +140 -153
- package/dist/openapi/index.d.mts +11 -27
- package/dist/openapi/index.d.ts +11 -27
- package/dist/openapi/index.mjs +9 -79
- package/dist/shared/server.C1RJffw4.mjs +30 -0
- package/dist/shared/server.CQIFwyhc.mjs +40 -0
- package/dist/shared/server.CVhIyQ4x.d.mts +41 -0
- package/dist/shared/server.CYa9puL2.mjs +403 -0
- package/dist/shared/server.ChOv1yG3.mjs +319 -0
- package/dist/shared/server.Cj3_Lp61.d.mts +373 -0
- package/dist/shared/server.Cj3_Lp61.d.ts +373 -0
- package/dist/shared/server.Cza0RB3u.mjs +160 -0
- package/dist/shared/server.D8RAzJ_p.d.ts +41 -0
- package/dist/shared/server.YUvuxHty.mjs +48 -0
- package/package.json +10 -28
- package/dist/plugins/index.d.mts +0 -110
- package/dist/plugins/index.d.ts +0 -110
- package/dist/plugins/index.mjs +0 -175
- package/dist/shared/server.7aL9gcoU.d.mts +0 -23
- package/dist/shared/server.BL2R5jcp.d.mts +0 -228
- package/dist/shared/server.BL2R5jcp.d.ts +0 -228
- package/dist/shared/server.CVBLzkro.mjs +0 -255
- package/dist/shared/server.ClhVCxfg.mjs +0 -413
- package/dist/shared/server.D6Qs_UcF.d.mts +0 -55
- package/dist/shared/server.DFptr1Nz.d.ts +0 -23
- package/dist/shared/server.DpoO_ER_.d.ts +0 -55
- package/dist/shared/server.JtIZ8YG7.mjs +0 -237
package/dist/index.d.ts
CHANGED
|
@@ -1,48 +1,55 @@
|
|
|
1
|
-
import
|
|
2
|
-
export { ContractProcedure, ContractProcedureDef, ContractRouter, ErrorMap, ErrorMapItem, InferSchemaInput, InferSchemaOutput, MergedErrorMap, Meta, OutputStructure, Route, Schema, ValidationError, eventIterator, validateORPCError } from '@temporary-name/contract';
|
|
3
|
-
import { ClientContext, MaybeOptionalOptions, HTTPEndpoint, IntersectPick, HTTPPath, ClientOptions, ClientPromiseResult } from '@temporary-name/shared';
|
|
4
|
-
export { AsyncIteratorClass, ClientContext, EventPublisher, EventPublisherOptions, EventPublisherSubscribeIteratorOptions, HTTPMethod, HTTPPath, IntersectPick, ORPCError, Registry, ThrowableError, asyncIteratorToStream as eventIteratorToStream, isDefinedError, onError, onFinish, onStart, onSuccess, safe, streamToAsyncIteratorClass as streamToEventIterator } from '@temporary-name/shared';
|
|
1
|
+
import * as z from '@temporary-name/zod';
|
|
5
2
|
import { SchemaClass, core } from '@temporary-name/zod';
|
|
6
|
-
import
|
|
7
|
-
|
|
3
|
+
import * as zod_v4_core from 'zod/v4/core';
|
|
4
|
+
import { ClientContext, Value, Promisable, Client, MaybeOptionalOptions, HTTPEndpoint as HTTPEndpoint$1, IntersectPick, OptionalIfEmpty, HTTPPath, AsyncIteratorClass, ClientOptions, HTTPMethod } from '@temporary-name/shared';
|
|
5
|
+
export { AsyncIteratorClass, ClientContext, EventPublisher, EventPublisherOptions, EventPublisherSubscribeIteratorOptions, HTTPMethod, HTTPPath, IntersectPick, ORPCError, asyncIteratorToStream as eventIteratorToStream, isDefinedError, onError, onFinish, onStart, onSuccess, streamToAsyncIteratorClass as streamToEventIterator } from '@temporary-name/shared';
|
|
6
|
+
import { C as Context, S as Schemas, I as InferProcedureClientInputs, a as InferSchemaOutput, M as Meta, L as Lazyable, P as Procedure, b as Contract, A as AnyShape, c as MergedSchemas, W as WrapShape, U as UnionToIntersection, d as AnySchema, R as Route, e as Middleware, f as MergedCurrentContext, g as MergedInitialContext, h as AuthType, V as ValidatedAuthContext, i as AuthConfig, B as BuildContextWithAuth, j as ProcedureHandler, k as InferHandlerInputs, l as InferSchemaInput, E as EnhanceRouterOptions, m as Router, n as EnhancedRouter, o as MapInputMiddleware, p as ContractDef, q as SchemaIssue, r as Schema, s as AnyMiddleware, t as Lazy, u as AnyProcedure, v as AnyRouter, w as InferRouterInitialContext } from './shared/server.Cj3_Lp61.js';
|
|
7
|
+
export { a7 as AccessibleLazyRouter, _ as AnyContractDef, ac as ContractProcedureCallbackOptions, a1 as ContractRouter, Y as DefaultProcedureHandlerOptions, a3 as InferRouterCurrentContexts, a2 as InferRouterInitialContexts, a4 as InferRouterInputs, a5 as InferRouterOutputs, ak as InitialSchemas, y as LAZY_SYMBOL, z as LazyMeta, ad as LazyTraverseContractProceduresOptions, O as MiddlewareNextFn, T as MiddlewareOptions, Q as MiddlewareOutputFn, N as MiddlewareResult, $ as ProcedureDef, Z as ProcedureHandlerOptions, ab as TraverseContractProcedureCallbackOptions, aa as TraverseContractProceduresOptions, ai as TypeRest, ag as UnlaziedRouter, a8 as createAccessibleLazyRouter, a9 as enhanceRouter, H as getLazyMeta, a6 as getRouter, aj as initialSchemas, G as isLazy, a0 as isProcedure, F as lazy, D as lazyInternal, x as mergeCurrentContext, K as mergeMeta, X as middlewareOutputFn, af as resolveContractProcedures, ae as traverseContractProcedures, J as unlazy, ah as unlazyRouter } from './shared/server.Cj3_Lp61.js';
|
|
8
8
|
export { getEventMeta, withEventMeta } from '@temporary-name/standard-server';
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
type ProcedureClient<TClientContext extends ClientContext, TSchemas extends Schemas> = Client<TClientContext, InferProcedureClientInputs<TSchemas>, InferSchemaOutput<TSchemas['outputSchema']>>;
|
|
11
|
+
type CreateProcedureClientOptions<TInitialContext extends Context, TClientContext extends ClientContext> = {
|
|
12
|
+
/**
|
|
13
|
+
* This is helpful for logging and analytics.
|
|
14
|
+
*/
|
|
15
|
+
path?: readonly string[];
|
|
16
|
+
} & (object extends TInitialContext ? {
|
|
17
|
+
context?: Value<Promisable<TInitialContext>, [clientContext: TClientContext]>;
|
|
18
|
+
} : {
|
|
19
|
+
context: Value<Promisable<TInitialContext>, [clientContext: TClientContext]>;
|
|
20
|
+
});
|
|
21
|
+
/**
|
|
22
|
+
* Create Server-side client from a procedure.
|
|
23
|
+
*
|
|
24
|
+
* @see {@link https://orpc.unnoq.com/docs/client/server-side Server-side Client Docs}
|
|
25
|
+
*/
|
|
26
|
+
declare function createProcedureClient<TInitialContext extends Context, TSchemas extends Schemas, TMeta extends Meta, TClientContext extends ClientContext>(lazyableProcedure: Lazyable<Procedure<TInitialContext, any, TSchemas, TMeta>>, ...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TClientContext>>): ProcedureClient<TClientContext, TSchemas>;
|
|
27
|
+
|
|
28
|
+
declare class DecoratedProcedure<TInitialContext extends Context, TCurrentContext extends Context, TSchemas extends Schemas, TMeta extends Meta> extends Procedure<TInitialContext, TCurrentContext, TSchemas, TMeta> {
|
|
11
29
|
/**
|
|
12
30
|
* Make this procedure callable (works like a function while still being a procedure).
|
|
13
31
|
*
|
|
14
32
|
* @see {@link https://orpc.unnoq.com/docs/client/server-side Server-side Client Docs}
|
|
15
33
|
*/
|
|
16
|
-
callable<TClientContext extends ClientContext>(...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext,
|
|
34
|
+
callable<TClientContext extends ClientContext>(...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TClientContext>>): DecoratedProcedure<TInitialContext, TCurrentContext, TSchemas, TMeta> & ProcedureClient<TClientContext, TSchemas>;
|
|
17
35
|
}
|
|
18
36
|
|
|
19
|
-
declare class ProcedureBuilder<TInitialContext extends Context, TCurrentContext extends Context, TSchemas extends Schemas,
|
|
37
|
+
declare class ProcedureBuilder<TInitialContext extends Context, TCurrentContext extends Context, TSchemas extends Schemas, TMeta extends Meta, TGateName extends string> extends Contract<BuilderDef<TSchemas, TMeta>> {
|
|
20
38
|
z: SchemaClass<TGateName>;
|
|
21
|
-
|
|
22
|
-
* This property holds the defined options.
|
|
23
|
-
*/
|
|
24
|
-
'~orpc': BuilderDef<TSchemas, TErrorMap, TMeta>;
|
|
25
|
-
constructor(def: BuilderDef<TSchemas, TErrorMap, TMeta>);
|
|
26
|
-
/**
|
|
27
|
-
* Adds type-safe custom errors to the contract.
|
|
28
|
-
* The provided errors are spared-merged with any existing errors in the contract.
|
|
29
|
-
*
|
|
30
|
-
* @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
31
|
-
*/
|
|
32
|
-
errors<U extends ErrorMap>(errors: U): ProcedureBuilder<TInitialContext, TCurrentContext, TSchemas, MergedErrorMap<TErrorMap, U>, TMeta, TGateName>;
|
|
39
|
+
constructor(def: BuilderDef<TSchemas, TMeta>);
|
|
33
40
|
/**
|
|
34
41
|
* Sets or updates the metadata for the contract.
|
|
35
42
|
* The provided metadata is spared-merged with any existing metadata in the contract.
|
|
36
43
|
*
|
|
37
44
|
* @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
|
|
38
45
|
*/
|
|
39
|
-
meta(meta: TMeta): ProcedureBuilder<TInitialContext, TCurrentContext, TSchemas,
|
|
46
|
+
meta(meta: TMeta): ProcedureBuilder<TInitialContext, TCurrentContext, TSchemas, TMeta, TGateName>;
|
|
40
47
|
endpoint<U extends AnyShape[]>(strings: TemplateStringsArray, ...values: [...U]): ProcedureBuilder<TInitialContext, TCurrentContext, MergedSchemas<TSchemas, {
|
|
41
48
|
pathSchema: WrapShape<UnionToIntersection<U>>;
|
|
42
|
-
}>,
|
|
43
|
-
endpoint<U extends AnySchema | AnyShape = core.$ZodType<Record<string, never>, Record<string, never>>>(endpoint: HTTPEndpoint, schema?: U): ProcedureBuilder<TInitialContext, TCurrentContext, MergedSchemas<TSchemas, {
|
|
49
|
+
}>, TMeta, TGateName>;
|
|
50
|
+
endpoint<U extends AnySchema | AnyShape = core.$ZodType<Record<string, never>, Record<string, never>>>(endpoint: HTTPEndpoint$1, schema?: U): ProcedureBuilder<TInitialContext, TCurrentContext, MergedSchemas<TSchemas, {
|
|
44
51
|
pathSchema: WrapShape<U>;
|
|
45
|
-
}>,
|
|
52
|
+
}>, TMeta, TGateName>;
|
|
46
53
|
/**
|
|
47
54
|
* Sets or updates the route definition for the contract.
|
|
48
55
|
* The provided route is spared-merged with any existing route in the contract.
|
|
@@ -51,13 +58,13 @@ declare class ProcedureBuilder<TInitialContext extends Context, TCurrentContext
|
|
|
51
58
|
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
52
59
|
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
53
60
|
*/
|
|
54
|
-
endpointOpts(route: Route): ProcedureBuilder<TInitialContext, TCurrentContext, TSchemas,
|
|
61
|
+
endpointOpts(route: Route): ProcedureBuilder<TInitialContext, TCurrentContext, TSchemas, TMeta, TGateName>;
|
|
55
62
|
query<U extends AnySchema | AnyShape>(schema: U): ProcedureBuilder<TInitialContext, TCurrentContext, MergedSchemas<TSchemas, {
|
|
56
63
|
querySchema: WrapShape<U>;
|
|
57
|
-
}>,
|
|
64
|
+
}>, TMeta, TGateName>;
|
|
58
65
|
body<U extends AnySchema | AnyShape>(schema: U): ProcedureBuilder<TInitialContext, TCurrentContext, MergedSchemas<TSchemas, {
|
|
59
66
|
bodySchema: WrapShape<U>;
|
|
60
|
-
}>,
|
|
67
|
+
}>, TMeta, TGateName>;
|
|
61
68
|
/**
|
|
62
69
|
* Defines the output validation schema.
|
|
63
70
|
*
|
|
@@ -65,7 +72,7 @@ declare class ProcedureBuilder<TInitialContext extends Context, TCurrentContext
|
|
|
65
72
|
*/
|
|
66
73
|
output<U extends AnySchema | AnyShape>(schema: U): ProcedureBuilder<TInitialContext, TCurrentContext, MergedSchemas<TSchemas, {
|
|
67
74
|
outputSchema: WrapShape<U>;
|
|
68
|
-
}>,
|
|
75
|
+
}>, TMeta, TGateName>;
|
|
69
76
|
/**
|
|
70
77
|
* Uses a middleware to modify the context or improve the pipeline.
|
|
71
78
|
*
|
|
@@ -73,18 +80,20 @@ declare class ProcedureBuilder<TInitialContext extends Context, TCurrentContext
|
|
|
73
80
|
* @note The current context must be satisfy middleware dependent-context
|
|
74
81
|
* @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
|
|
75
82
|
*/
|
|
76
|
-
use<UOutContext extends IntersectPick<TCurrentContext, UOutContext
|
|
83
|
+
use<UOutContext extends IntersectPick<TCurrentContext, UOutContext>>(middleware: Middleware<TCurrentContext, UOutContext, unknown, unknown, TMeta>): ProcedureBuilder<TInitialContext, MergedCurrentContext<TCurrentContext, UOutContext>, TSchemas, TMeta, TGateName>;
|
|
84
|
+
use<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext, UOutContext, unknown, unknown, TMeta>): ProcedureBuilder<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TSchemas, TMeta, TGateName>;
|
|
85
|
+
useAuth<const TAuthType extends AuthType & {}, TAuthContext extends ValidatedAuthContext = false>(type: TAuthType, ...rest: OptionalIfEmpty<AuthConfig<TAuthType, TAuthContext>>): ProcedureBuilder<TInitialContext, BuildContextWithAuth<TCurrentContext, TAuthContext>, TSchemas, TMeta, TGateName>;
|
|
77
86
|
useGating<const TInferredGateName extends string>(gates: TInferredGateName[], isGateEnabled: (gate: TInferredGateName, ctx: TCurrentContext) => boolean): BuilderWithMiddlewares<MergedInitialContext<TInitialContext, Context, TCurrentContext>, MergedCurrentContext<TCurrentContext, {
|
|
78
87
|
isGateEnabled: typeof isGateEnabled;
|
|
79
|
-
}>, TSchemas,
|
|
88
|
+
}>, TSchemas, TMeta, TInferredGateName>;
|
|
80
89
|
/**
|
|
81
90
|
* Defines the handler of the procedure.
|
|
82
91
|
*
|
|
83
92
|
* @see {@link https://orpc.unnoq.com/docs/procedure Procedure Docs}
|
|
84
93
|
*/
|
|
85
|
-
handler(handler: ProcedureHandler<TCurrentContext, InferHandlerInputs<TSchemas>, InferSchemaInput<TSchemas['outputSchema']>,
|
|
94
|
+
handler(handler: ProcedureHandler<TCurrentContext, InferHandlerInputs<TSchemas>, InferSchemaInput<TSchemas['outputSchema']>, TMeta>): DecoratedProcedure<TInitialContext, TCurrentContext, TSchemas, TMeta>;
|
|
86
95
|
}
|
|
87
|
-
declare class BuilderWithMiddlewares<TInitialContext extends Context, TCurrentContext extends Context, TSchemas extends Schemas,
|
|
96
|
+
declare class BuilderWithMiddlewares<TInitialContext extends Context, TCurrentContext extends Context, TSchemas extends Schemas, TMeta extends Meta, TGateName extends string> extends ProcedureBuilder<TInitialContext, TCurrentContext, TSchemas, TMeta, TGateName> {
|
|
88
97
|
/**
|
|
89
98
|
* Prefixes all procedures in the router.
|
|
90
99
|
* The provided prefix is post-appended to any existing router prefix.
|
|
@@ -93,205 +102,90 @@ declare class BuilderWithMiddlewares<TInitialContext extends Context, TCurrentCo
|
|
|
93
102
|
*
|
|
94
103
|
* @see {@link https://orpc.unnoq.com/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
|
|
95
104
|
*/
|
|
96
|
-
prefix(prefix: HTTPPath): BuilderWithMiddlewares<TInitialContext, TCurrentContext, TSchemas,
|
|
105
|
+
prefix(prefix: HTTPPath): BuilderWithMiddlewares<TInitialContext, TCurrentContext, TSchemas, TMeta, TGateName>;
|
|
97
106
|
/**
|
|
98
107
|
* Adds tags to all procedures in the router.
|
|
99
108
|
* This helpful when you want to group procedures together in the OpenAPI specification.
|
|
100
109
|
*
|
|
101
110
|
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
|
102
111
|
*/
|
|
103
|
-
tag(...tags: string[]): RouterBuilder<TInitialContext, TCurrentContext,
|
|
112
|
+
tag(...tags: string[]): RouterBuilder<TInitialContext, TCurrentContext, TMeta>;
|
|
104
113
|
/**
|
|
105
114
|
* Applies all of the previously defined options to the specified router.
|
|
106
115
|
*
|
|
107
116
|
* @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
|
|
108
117
|
*/
|
|
109
|
-
router<U extends Router<
|
|
118
|
+
router<U extends Router<TCurrentContext>>(router: U): EnhancedRouter<U, TInitialContext, TCurrentContext>;
|
|
110
119
|
}
|
|
111
|
-
interface RouterBuilder<TInitialContext extends Context, TCurrentContext extends Context,
|
|
120
|
+
interface RouterBuilder<TInitialContext extends Context, TCurrentContext extends Context, TMeta extends Meta> extends Pick<BuilderWithMiddlewares<TInitialContext, TCurrentContext, any, TMeta, any>, 'prefix' | 'tag' | 'router'> {
|
|
112
121
|
/**
|
|
113
122
|
* This property holds the defined options.
|
|
114
123
|
*/
|
|
115
|
-
'~orpc': EnhanceRouterOptions
|
|
124
|
+
'~orpc': EnhanceRouterOptions;
|
|
116
125
|
}
|
|
117
126
|
|
|
118
|
-
interface DecoratedMiddleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput,
|
|
127
|
+
interface DecoratedMiddleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TMeta extends Meta> extends Middleware<TInContext, TOutContext, TInput, TOutput, TMeta> {
|
|
119
128
|
/**
|
|
120
129
|
* Change the expected input type by providing a map function.
|
|
121
130
|
*/
|
|
122
|
-
mapInput<UInput>(map: MapInputMiddleware<UInput, TInput>): DecoratedMiddleware<TInContext, TOutContext, UInput, TOutput,
|
|
123
|
-
/**
|
|
124
|
-
* Concatenates two middlewares.
|
|
125
|
-
*
|
|
126
|
-
* @info Pass second argument to map the input.
|
|
127
|
-
* @see {@link https://orpc.unnoq.com/docs/middleware#concatenation Middleware Concatenation Docs}
|
|
128
|
-
*/
|
|
129
|
-
concat<UOutContext extends IntersectPick<MergedCurrentContext<TInContext, TOutContext>, UOutContext>, UInput extends TInput, UInContext extends Context = MergedCurrentContext<TInContext, TOutContext>>(middleware: Middleware<UInContext | MergedCurrentContext<TInContext, TOutContext>, UOutContext, UInput, TOutput, TErrorConstructorMap, TMeta>): DecoratedMiddleware<MergedInitialContext<TInContext, UInContext, MergedCurrentContext<TInContext, TOutContext>>, MergedCurrentContext<TOutContext, UOutContext>, UInput, TOutput, TErrorConstructorMap, TMeta>;
|
|
130
|
-
/**
|
|
131
|
-
* Concatenates two middlewares.
|
|
132
|
-
*
|
|
133
|
-
* @info Pass second argument to map the input.
|
|
134
|
-
* @see {@link https://orpc.unnoq.com/docs/middleware#concatenation Middleware Concatenation Docs}
|
|
135
|
-
*/
|
|
136
|
-
concat<UOutContext extends IntersectPick<MergedCurrentContext<TInContext, TOutContext>, UOutContext>, UInput extends TInput, UMappedInput, UInContext extends Context = MergedCurrentContext<TInContext, TOutContext>>(middleware: Middleware<UInContext | MergedCurrentContext<TInContext, TOutContext>, UOutContext, UMappedInput, TOutput, TErrorConstructorMap, TMeta>, mapInput: MapInputMiddleware<UInput, UMappedInput>): DecoratedMiddleware<MergedInitialContext<TInContext, UInContext, MergedCurrentContext<TInContext, TOutContext>>, MergedCurrentContext<TOutContext, UOutContext>, UInput, TOutput, TErrorConstructorMap, TMeta>;
|
|
131
|
+
mapInput<UInput>(map: MapInputMiddleware<UInput, TInput>): DecoratedMiddleware<TInContext, TOutContext, UInput, TOutput, TMeta>;
|
|
137
132
|
}
|
|
138
|
-
declare function decorateMiddleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput,
|
|
133
|
+
declare function decorateMiddleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TMeta extends Meta>(middleware: Middleware<TInContext, TOutContext, TInput, TOutput, TMeta>): DecoratedMiddleware<TInContext, TOutContext, TInput, TOutput, TMeta>;
|
|
139
134
|
|
|
140
|
-
interface BuilderDef<TSchemas extends Schemas,
|
|
141
|
-
middlewares: readonly AnyMiddleware[];
|
|
142
|
-
inputValidationIndex: number;
|
|
143
|
-
outputValidationIndex: number;
|
|
135
|
+
interface BuilderDef<TSchemas extends Schemas, TMeta extends Meta> extends ContractDef<TSchemas, TMeta>, EnhanceRouterOptions {
|
|
144
136
|
}
|
|
145
|
-
declare class Builder<TInitialContext extends Context, TCurrentContext extends Context, TSchemas extends Schemas,
|
|
137
|
+
declare class Builder<TInitialContext extends Context, TCurrentContext extends Context, TSchemas extends Schemas, TMeta extends Meta, TGateName extends string> extends BuilderWithMiddlewares<TInitialContext, TCurrentContext, TSchemas, TMeta, TGateName> {
|
|
146
138
|
/**
|
|
147
139
|
* Set or override the initial context.
|
|
148
140
|
*
|
|
149
141
|
* @see {@link https://orpc.unnoq.com/docs/context Context Docs}
|
|
150
142
|
*/
|
|
151
|
-
$context<U extends Context>(): Builder<U, U, TSchemas,
|
|
143
|
+
$context<U extends Context>(): Builder<U, U, TSchemas, TMeta, TGateName>;
|
|
152
144
|
/**
|
|
153
145
|
* Creates a middleware.
|
|
154
146
|
*
|
|
155
147
|
* @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
|
|
156
148
|
*/
|
|
157
149
|
middleware<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, TInput, TOutput = any>(// = any here is important to make middleware can be used in any output by default
|
|
158
|
-
middleware: Middleware<TInitialContext, UOutContext, TInput, TOutput,
|
|
150
|
+
middleware: Middleware<TInitialContext, UOutContext, TInput, TOutput, TMeta>): DecoratedMiddleware<TInitialContext, UOutContext, TInput, TOutput, TMeta>;
|
|
159
151
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
|
|
152
|
+
declare const baseApi: Builder<{}, {}, {
|
|
153
|
+
pathSchema: z.KrustyObject<{}, zod_v4_core.$strict, z.KrustyInternals<string>>;
|
|
154
|
+
querySchema: z.KrustyObject<{}, zod_v4_core.$strict, z.KrustyInternals<string>>;
|
|
155
|
+
bodySchema: z.KrustyObject<{}, zod_v4_core.$strict, z.KrustyInternals<string>>;
|
|
156
|
+
outputSchema: z.KrustyUnknown<z.KrustyInternals<string>>;
|
|
157
|
+
}, Record<never, never>, never>;
|
|
166
158
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
interface ImplementedProcedure<TInitialContext extends Context, TCurrentContext extends Context, TSchemas extends Schemas, TErrorMap extends ErrorMap, TMeta extends Meta> extends Procedure<TInitialContext, TCurrentContext, TSchemas, TErrorMap, TMeta> {
|
|
171
|
-
/**
|
|
172
|
-
* Uses a middleware to modify the context or improve the pipeline.
|
|
173
|
-
*
|
|
174
|
-
* @info Supports both normal middleware and inline middleware implementations.
|
|
175
|
-
* @info Pass second argument to map the input.
|
|
176
|
-
* @note The current context must be satisfy middleware dependent-context
|
|
177
|
-
* @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
|
|
178
|
-
*/
|
|
179
|
-
use<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, InferHandlerInputs<TSchemas>, InferSchemaInput<TSchemas['outputSchema']>, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ImplementedProcedure<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TSchemas, TErrorMap, TMeta>;
|
|
159
|
+
interface ValidationErrorOptions extends ErrorOptions {
|
|
160
|
+
message: string;
|
|
161
|
+
issues: readonly SchemaIssue[];
|
|
180
162
|
/**
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
* @info Supports both normal middleware and inline middleware implementations.
|
|
184
|
-
* @info Pass second argument to map the input.
|
|
185
|
-
* @note The current context must be satisfy middleware dependent-context
|
|
186
|
-
* @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
|
|
163
|
+
* @todo require this field in v2
|
|
187
164
|
*/
|
|
188
|
-
|
|
189
|
-
/**
|
|
190
|
-
* Make this procedure callable (works like a function while still being a procedure).
|
|
191
|
-
*
|
|
192
|
-
* @see {@link https://orpc.unnoq.com/docs/client/server-side Server-side Client Docs}
|
|
193
|
-
*/
|
|
194
|
-
callable<TClientContext extends ClientContext>(...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TSchemas['outputSchema'], TErrorMap, TMeta, TClientContext>>): ImplementedProcedure<TInitialContext, TCurrentContext, TSchemas, TErrorMap, TMeta> & ProcedureClient<TClientContext, TSchemas, TErrorMap>;
|
|
165
|
+
data?: unknown;
|
|
195
166
|
}
|
|
196
167
|
/**
|
|
197
|
-
*
|
|
168
|
+
* This errors usually used for ORPCError.cause when the error is a validation error.
|
|
169
|
+
*
|
|
170
|
+
* @see {@link https://orpc.unnoq.com/docs/advanced/validation-errors Validation Errors Docs}
|
|
198
171
|
*/
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
*
|
|
204
|
-
* @info Supports both normal middleware and inline middleware implementations.
|
|
205
|
-
* @info Pass second argument to map the input.
|
|
206
|
-
* @note The current context must be satisfy middleware dependent-context
|
|
207
|
-
* @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
|
|
208
|
-
*/
|
|
209
|
-
'use'<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, InferHandlerInputs<TSchemas>, InferSchemaInput<TSchemas['outputSchema']>, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ProcedureImplementer<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TSchemas, TErrorMap, TMeta>;
|
|
210
|
-
/**
|
|
211
|
-
* Uses a middleware to modify the context or improve the pipeline.
|
|
212
|
-
*
|
|
213
|
-
* @info Supports both normal middleware and inline middleware implementations.
|
|
214
|
-
* @info Pass second argument to map the input.
|
|
215
|
-
* @note The current context must be satisfy middleware dependent-context
|
|
216
|
-
* @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
|
|
217
|
-
*/
|
|
218
|
-
'use'<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInput, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, UInput, InferSchemaInput<TSchemas['outputSchema']>, ORPCErrorConstructorMap<TErrorMap>, TMeta>, mapInput: MapInputMiddleware<InferHandlerInputs<TSchemas>, UInput>): ProcedureImplementer<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TSchemas, TErrorMap, TMeta>;
|
|
219
|
-
/**
|
|
220
|
-
* Defines the handler of the procedure.
|
|
221
|
-
*
|
|
222
|
-
* @see {@link https://orpc.unnoq.com/docs/procedure Procedure Docs}
|
|
223
|
-
*/
|
|
224
|
-
'handler'(handler: ProcedureHandler<TCurrentContext, InferHandlerInputs<TSchemas>, InferSchemaInput<TSchemas['outputSchema']>, TErrorMap, TMeta>): ImplementedProcedure<TInitialContext, TCurrentContext, TSchemas, TErrorMap, TMeta>;
|
|
172
|
+
declare class ValidationError extends Error {
|
|
173
|
+
readonly issues: readonly SchemaIssue[];
|
|
174
|
+
readonly data: unknown;
|
|
175
|
+
constructor(options: ValidationErrorOptions);
|
|
225
176
|
}
|
|
226
177
|
|
|
227
|
-
interface
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
*
|
|
231
|
-
* @info Supports both normal middleware and inline middleware implementations.
|
|
232
|
-
* @note The current context must be satisfy middleware dependent-context
|
|
233
|
-
* @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
|
|
234
|
-
*/
|
|
235
|
-
use<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, unknown, unknown, ORPCErrorConstructorMap<InferContractRouterErrorMap<T>>, InferContractRouterMeta<T>>): ImplementerInternalWithMiddlewares<T, MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>>;
|
|
236
|
-
/**
|
|
237
|
-
* Applies all of the previously defined options to the specified router.
|
|
238
|
-
* And enforces the router match the contract.
|
|
239
|
-
*
|
|
240
|
-
* @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
|
|
241
|
-
*/
|
|
242
|
-
router<U extends Router<T, TCurrentContext>>(router: U): EnhancedRouter<U, TInitialContext, TCurrentContext, Record<never, never>>;
|
|
178
|
+
interface EventIteratorSchemaDetails {
|
|
179
|
+
yields: AnySchema;
|
|
180
|
+
returns?: AnySchema;
|
|
243
181
|
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
*
|
|
252
|
-
* @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
|
|
253
|
-
*/
|
|
254
|
-
middleware<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, TInput, TOutput = any>(// = any here is important to make middleware can be used in any output by default
|
|
255
|
-
middleware: Middleware<TInitialContext, UOutContext, TInput, TOutput, ORPCErrorConstructorMap<InferContractRouterErrorMap<T>>, InferContractRouterMeta<T>>): DecoratedMiddleware<TInitialContext, UOutContext, TInput, TOutput, any, InferContractRouterMeta<T>>;
|
|
256
|
-
/**
|
|
257
|
-
* Uses a middleware to modify the context or improve the pipeline.
|
|
258
|
-
*
|
|
259
|
-
* @info Supports both normal middleware and inline middleware implementations.
|
|
260
|
-
* @note The current context must be satisfy middleware dependent-context
|
|
261
|
-
* @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
|
|
262
|
-
*/
|
|
263
|
-
use<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, unknown, unknown, ORPCErrorConstructorMap<InferContractRouterErrorMap<T>>, InferContractRouterMeta<T>>): ImplementerInternalWithMiddlewares<T, MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>>;
|
|
264
|
-
/**
|
|
265
|
-
* Applies all of the previously defined options to the specified router.
|
|
266
|
-
* And enforces the router match the contract.
|
|
267
|
-
*
|
|
268
|
-
* @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
|
|
269
|
-
*/
|
|
270
|
-
router<U extends Router<T, TCurrentContext>>(router: U): EnhancedRouter<U, TInitialContext, TCurrentContext, Record<never, never>>;
|
|
271
|
-
/**
|
|
272
|
-
* Create a lazy router
|
|
273
|
-
* And applies all of the previously defined options to the specified router.
|
|
274
|
-
* And enforces the router match the contract.
|
|
275
|
-
*
|
|
276
|
-
* @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
|
|
277
|
-
*/
|
|
278
|
-
lazyRoute<U extends Router<T, TCurrentContext>>(loader: () => Promise<{
|
|
279
|
-
default: U;
|
|
280
|
-
}>): EnhancedRouter<Lazy<U>, TInitialContext, TCurrentContext, Record<never, never>>;
|
|
281
|
-
}
|
|
282
|
-
type ImplementerInternal<TContract extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> = TContract extends ContractProcedure<infer USchemas, infer UErrorMap, infer UMeta> ? ProcedureImplementer<TInitialContext, TCurrentContext, USchemas, UErrorMap, UMeta> : RouterImplementer<TContract, TInitialContext, TCurrentContext> & {
|
|
283
|
-
[K in keyof TContract]: TContract[K] extends AnyContractRouter ? ImplementerInternal<TContract[K], TInitialContext, TCurrentContext> : never;
|
|
284
|
-
};
|
|
285
|
-
declare function implementerInternal<T extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context>(contract: T, middlewares: AnyMiddleware[]): ImplementerInternal<T, TInitialContext, TCurrentContext>;
|
|
286
|
-
type Implementer<TContract extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> = {
|
|
287
|
-
/**
|
|
288
|
-
* Set or override the initial context.
|
|
289
|
-
*
|
|
290
|
-
* @see {@link https://orpc.unnoq.com/docs/context Context Docs}
|
|
291
|
-
*/
|
|
292
|
-
$context<U extends Context>(): Implementer<TContract, U, U>;
|
|
293
|
-
} & ImplementerInternal<TContract, TInitialContext, TCurrentContext>;
|
|
294
|
-
declare function implement<T extends AnyContractRouter, TContext extends Context = Record<never, never>>(contract: T): Implementer<T, TContext, TContext>;
|
|
182
|
+
/**
|
|
183
|
+
* Define schema for an event iterator.
|
|
184
|
+
*
|
|
185
|
+
* @see {@link https://orpc.unnoq.com/docs/event-iterator#validate-event-iterator Validate Event Iterator Docs}
|
|
186
|
+
*/
|
|
187
|
+
declare function eventIterator<TYieldIn, TYieldOut, TReturnIn = unknown, TReturnOut = unknown>(yields: Schema<TYieldIn, TYieldOut>, returns?: Schema<TReturnIn, TReturnOut>): Schema<AsyncIteratorObject<TYieldIn, TReturnIn, void>, AsyncIteratorClass<TYieldOut, TReturnOut, void>>;
|
|
188
|
+
declare function getEventIteratorSchemaDetails(schema: AnySchema | undefined): undefined | EventIteratorSchemaDetails;
|
|
295
189
|
|
|
296
190
|
declare function isStartWithMiddlewares(middlewares: readonly AnyMiddleware[], compare: readonly AnyMiddleware[]): boolean;
|
|
297
191
|
declare function mergeMiddlewares(first: readonly AnyMiddleware[], second: readonly AnyMiddleware[], options: {
|
|
@@ -300,10 +194,6 @@ declare function mergeMiddlewares(first: readonly AnyMiddleware[], second: reado
|
|
|
300
194
|
declare function addMiddleware(middlewares: readonly AnyMiddleware[], addition: AnyMiddleware): AnyMiddleware[];
|
|
301
195
|
|
|
302
196
|
declare function createAssertedLazyProcedure(lazied: Lazy<any>): Lazy<AnyProcedure>;
|
|
303
|
-
/**
|
|
304
|
-
* Create a new procedure that ensure the contract is applied to the procedure.
|
|
305
|
-
*/
|
|
306
|
-
declare function createContractedProcedure(procedure: AnyProcedure, contract: AnyContractProcedure): AnyProcedure;
|
|
307
197
|
/**
|
|
308
198
|
* Directly call a procedure without creating a client.
|
|
309
199
|
*
|
|
@@ -314,9 +204,9 @@ declare function createContractedProcedure(procedure: AnyProcedure, contract: An
|
|
|
314
204
|
* ```
|
|
315
205
|
*
|
|
316
206
|
*/
|
|
317
|
-
declare function call<TInitialContext extends Context, TSchemas extends Schemas,
|
|
207
|
+
declare function call<TInitialContext extends Context, TSchemas extends Schemas, TMeta extends Meta>(procedure: Lazyable<Procedure<TInitialContext, any, TSchemas, TMeta>>, input: InferProcedureClientInputs<TSchemas>, ...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, {}> & Omit<ClientOptions<{}>, 'context'>>): Promise<InferSchemaOutput<TSchemas['outputSchema']>>;
|
|
318
208
|
|
|
319
|
-
type RouterClient<TRouter extends AnyRouter, TClientContext extends ClientContext =
|
|
209
|
+
type RouterClient<TRouter extends AnyRouter, TClientContext extends ClientContext = {}> = TRouter extends Procedure<any, any, infer USchemas, any> ? ProcedureClient<TClientContext, USchemas> : {
|
|
320
210
|
[K in keyof TRouter]: TRouter[K] extends Lazyable<infer U extends AnyRouter> ? RouterClient<U, TClientContext> : never;
|
|
321
211
|
};
|
|
322
212
|
/**
|
|
@@ -324,10 +214,31 @@ type RouterClient<TRouter extends AnyRouter, TClientContext extends ClientContex
|
|
|
324
214
|
*
|
|
325
215
|
* @see {@link https://orpc.unnoq.com/docs/client/server-side Server-side Client Docs}
|
|
326
216
|
*/
|
|
327
|
-
declare function createRouterClient<T extends AnyRouter, TClientContext extends ClientContext>(router: Lazyable<T | undefined>, ...rest: MaybeOptionalOptions<CreateProcedureClientOptions<InferRouterInitialContext<T>,
|
|
217
|
+
declare function createRouterClient<T extends AnyRouter, TClientContext extends ClientContext>(router: Lazyable<T | undefined>, ...rest: MaybeOptionalOptions<CreateProcedureClientOptions<InferRouterInitialContext<T>, TClientContext>>): RouterClient<T, TClientContext>;
|
|
218
|
+
|
|
219
|
+
declare function isSchemaIssue(issue: unknown): issue is SchemaIssue;
|
|
328
220
|
|
|
329
|
-
|
|
330
|
-
declare
|
|
221
|
+
type HTTPEndpoint = `${HTTPMethod} ${HTTPPath}`;
|
|
222
|
+
declare const endpointRegex: RegExp;
|
|
223
|
+
/**
|
|
224
|
+
* @internal
|
|
225
|
+
*/
|
|
226
|
+
declare function standardizeHTTPPath(path: HTTPPath): HTTPPath;
|
|
227
|
+
/**
|
|
228
|
+
* @internal
|
|
229
|
+
*/
|
|
230
|
+
declare function getDynamicParams(path: HTTPPath | undefined): {
|
|
231
|
+
raw: string;
|
|
232
|
+
name: string;
|
|
233
|
+
}[] | undefined;
|
|
234
|
+
/**
|
|
235
|
+
* @internal
|
|
236
|
+
*/
|
|
237
|
+
declare function parseEndpointDefinition(stringsOrEndpoint: TemplateStringsArray | HTTPEndpoint, values: AnyShape[] | [AnySchema | AnyShape] | []): {
|
|
238
|
+
method: HTTPMethod;
|
|
239
|
+
path: HTTPPath;
|
|
240
|
+
pathSchema: AnySchema;
|
|
241
|
+
};
|
|
331
242
|
|
|
332
|
-
export { AnyMiddleware, AnyProcedure, AnyRouter, Builder, BuilderWithMiddlewares, Context,
|
|
333
|
-
export type {
|
|
243
|
+
export { AnyMiddleware, AnyProcedure, AnyRouter, AnySchema, AnyShape, BuildContextWithAuth, Builder, BuilderWithMiddlewares, Context, Contract, ContractDef, DecoratedProcedure, EnhanceRouterOptions, EnhancedRouter, InferHandlerInputs, InferProcedureClientInputs, InferRouterInitialContext, InferSchemaInput, InferSchemaOutput, Lazy, Lazyable, MapInputMiddleware, MergedCurrentContext, MergedInitialContext, MergedSchemas, Meta, Middleware, Procedure, ProcedureBuilder, ProcedureHandler, Router, Schema, SchemaIssue, Schemas, UnionToIntersection, ValidationError, WrapShape, addMiddleware, baseApi, call, createAssertedLazyProcedure, createProcedureClient, createRouterClient, decorateMiddleware, endpointRegex, eventIterator, getDynamicParams, getEventIteratorSchemaDetails, isSchemaIssue, isStartWithMiddlewares, mergeMiddlewares, parseEndpointDefinition, standardizeHTTPPath };
|
|
244
|
+
export type { BuilderDef, CreateProcedureClientOptions, DecoratedMiddleware, EventIteratorSchemaDetails, HTTPEndpoint, ProcedureClient, RouterBuilder, RouterClient, ValidationErrorOptions };
|