@temporary-name/server 1.9.3-alpha.592ae1e02e18c5274906b132313b083116248636 → 1.9.3-alpha.65222302f1b71807a849530b3fe0fa0326d3c1a2
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/index.d.mts +27 -230
- package/dist/index.d.ts +27 -230
- package/dist/index.mjs +67 -104
- package/package.json +8 -8
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AnySchema, ErrorMap, Meta, MergedErrorMap, Route, InferSchemaOutput, InferSchemaInput, EnhanceRouteOptions, AnyContractRouter, AnyContractProcedure, Schema, ContractRouter, ContractProcedureDef, ContractProcedure, InferContractRouterErrorMap, InferContractRouterMeta, ErrorFromErrorMap } from '@temporary-name/contract';
|
|
1
|
+
import { AnySchema, ErrorMap, Meta, MergedErrorMap, Route, InferSchemaOutput, InferSchemaInput, EnhanceRouteOptions, AnyContractRouter, AnyContractProcedure, ContractProcedureBuilder, Schema, ContractRouter, ContractProcedureDef, ContractProcedure, InferContractRouterErrorMap, InferContractRouterMeta, ErrorFromErrorMap } from '@temporary-name/contract';
|
|
2
2
|
export { ContractProcedure, ContractProcedureDef, ContractRouter, ErrorMap, ErrorMapItem, InferSchemaInput, InferSchemaOutput, InputStructure, MergedErrorMap, Meta, OutputStructure, Route, Schema, ValidationError, eventIterator, type, validateORPCError } from '@temporary-name/contract';
|
|
3
3
|
import { IntersectPick, ClientContext, MaybeOptionalOptions, HTTPPath, ClientOptions, ClientPromiseResult } from '@temporary-name/shared';
|
|
4
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';
|
|
@@ -93,104 +93,27 @@ type UnlaziedRouter<T extends AnyRouter> = T extends AnyProcedure ? T : {
|
|
|
93
93
|
};
|
|
94
94
|
declare function unlazyRouter<T extends AnyRouter>(router: T): Promise<UnlaziedRouter<T>>;
|
|
95
95
|
|
|
96
|
-
|
|
96
|
+
declare class ProcedureBuilder<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TGateName extends string> extends ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
|
97
97
|
/**
|
|
98
98
|
* This property holds the defined options.
|
|
99
99
|
*/
|
|
100
100
|
'~orpc': BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
* @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
106
|
-
*/
|
|
107
|
-
'errors'<U extends ErrorMap>(errors: U): BuilderWithMiddlewares<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta, TGateName>;
|
|
108
|
-
/**
|
|
109
|
-
* Uses a middleware to modify the context or improve the pipeline.
|
|
110
|
-
*
|
|
111
|
-
* @info Supports both normal middleware and inline middleware implementations.
|
|
112
|
-
* @note The current context must be satisfy middleware dependent-context
|
|
113
|
-
* @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
|
|
114
|
-
*/
|
|
115
|
-
'use'<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>): BuilderWithMiddlewares<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
|
|
116
|
-
/**
|
|
117
|
-
* Sets or updates the metadata.
|
|
118
|
-
* The provided metadata is spared-merged with any existing metadata.
|
|
119
|
-
*
|
|
120
|
-
* @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
|
|
121
|
-
*/
|
|
122
|
-
'meta'(meta: TMeta): BuilderWithMiddlewares<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
|
|
123
|
-
/**
|
|
124
|
-
* Sets or updates the route definition.
|
|
125
|
-
* The provided route is spared-merged with any existing route.
|
|
126
|
-
* This option is typically relevant when integrating with OpenAPI.
|
|
127
|
-
*
|
|
128
|
-
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
129
|
-
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
130
|
-
*/
|
|
131
|
-
'route'(route: Route): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
|
|
101
|
+
constructor(def: BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>);
|
|
102
|
+
errors: <U extends ErrorMap>(errors: U) => ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta, TGateName>;
|
|
103
|
+
meta: (meta: TMeta) => ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
|
|
104
|
+
route: (route: Route) => ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
|
|
132
105
|
/**
|
|
133
106
|
* Defines the input validation schema.
|
|
134
107
|
*
|
|
135
108
|
* @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
|
|
136
109
|
*/
|
|
137
|
-
|
|
110
|
+
input<USchema extends AnySchema>(schema: USchema): ProcedureBuilder<TInitialContext, TCurrentContext, USchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
|
|
138
111
|
/**
|
|
139
112
|
* Defines the output validation schema.
|
|
140
113
|
*
|
|
141
114
|
* @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
|
|
142
115
|
*/
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Defines the handler of the procedure.
|
|
146
|
-
*
|
|
147
|
-
* @see {@link https://orpc.unnoq.com/docs/procedure Procedure Docs}
|
|
148
|
-
*/
|
|
149
|
-
'handler'<UFuncOutput>(handler: ProcedureHandler<TCurrentContext, InferSchemaOutput<TInputSchema>, UFuncOutput, TErrorMap, TMeta>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, Schema<UFuncOutput, UFuncOutput>, TErrorMap, TMeta>;
|
|
150
|
-
/**
|
|
151
|
-
* Prefixes all procedures in the router.
|
|
152
|
-
* The provided prefix is post-appended to any existing router prefix.
|
|
153
|
-
*
|
|
154
|
-
* @note This option does not affect procedures that do not define a path in their route definition.
|
|
155
|
-
*
|
|
156
|
-
* @see {@link https://orpc.unnoq.com/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
|
|
157
|
-
*/
|
|
158
|
-
'prefix'(prefix: HTTPPath): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
|
|
159
|
-
/**
|
|
160
|
-
* Adds tags to all procedures in the router.
|
|
161
|
-
* This helpful when you want to group procedures together in the OpenAPI specification.
|
|
162
|
-
*
|
|
163
|
-
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
|
164
|
-
*/
|
|
165
|
-
'tag'(...tags: string[]): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
|
|
166
|
-
/**
|
|
167
|
-
* Applies all of the previously defined options to the specified router.
|
|
168
|
-
*
|
|
169
|
-
* @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
|
|
170
|
-
*/
|
|
171
|
-
'router'<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(router: U): EnhancedRouter<U, TInitialContext, TCurrentContext, TErrorMap>;
|
|
172
|
-
/**
|
|
173
|
-
* Create a lazy router
|
|
174
|
-
* And applies all of the previously defined options to the specified router.
|
|
175
|
-
*
|
|
176
|
-
* @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
|
|
177
|
-
*/
|
|
178
|
-
'lazyRoute'<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(loader: () => Promise<{
|
|
179
|
-
default: U;
|
|
180
|
-
}>): EnhancedRouter<Lazy<U>, TInitialContext, TCurrentContext, TErrorMap>;
|
|
181
|
-
}
|
|
182
|
-
interface ProcedureBuilder<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TGateName extends string> {
|
|
183
|
-
/**
|
|
184
|
-
* This property holds the defined options.
|
|
185
|
-
*/
|
|
186
|
-
'~orpc': BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
|
|
187
|
-
/**
|
|
188
|
-
* Adds type-safe custom errors.
|
|
189
|
-
* The provided errors are spared-merged with any existing errors.
|
|
190
|
-
*
|
|
191
|
-
* @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
192
|
-
*/
|
|
193
|
-
'errors'<U extends ErrorMap>(errors: U): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta, TGateName>;
|
|
116
|
+
output<USchema extends AnySchema>(schema: USchema): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, USchema, TErrorMap, TMeta, TGateName>;
|
|
194
117
|
/**
|
|
195
118
|
* Uses a middleware to modify the context or improve the pipeline.
|
|
196
119
|
*
|
|
@@ -198,62 +121,18 @@ interface ProcedureBuilder<TInitialContext extends Context, TCurrentContext exte
|
|
|
198
121
|
* @note The current context must be satisfy middleware dependent-context
|
|
199
122
|
* @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
|
|
200
123
|
*/
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
*
|
|
206
|
-
* @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
|
|
207
|
-
*/
|
|
208
|
-
'meta'(meta: TMeta): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
|
|
209
|
-
/**
|
|
210
|
-
* Sets or updates the route definition.
|
|
211
|
-
* The provided route is spared-merged with any existing route.
|
|
212
|
-
* This option is typically relevant when integrating with OpenAPI.
|
|
213
|
-
*
|
|
214
|
-
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
215
|
-
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
216
|
-
*/
|
|
217
|
-
'route'(route: Route): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
|
|
218
|
-
/**
|
|
219
|
-
* Defines the input validation schema.
|
|
220
|
-
*
|
|
221
|
-
* @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
|
|
222
|
-
*/
|
|
223
|
-
'input'<USchema extends AnySchema>(schema: USchema): ProcedureBuilder<TInitialContext, TCurrentContext, USchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
|
|
224
|
-
/**
|
|
225
|
-
* Defines the output validation schema.
|
|
226
|
-
*
|
|
227
|
-
* @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
|
|
228
|
-
*/
|
|
229
|
-
'output'<USchema extends AnySchema>(schema: USchema): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, USchema, TErrorMap, TMeta, TGateName>;
|
|
124
|
+
use<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ProcedureBuilder<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
|
|
125
|
+
useGating<const TInferredGateName extends string>(gates: TInferredGateName[], isGateEnabled: (gate: TInferredGateName, ctx: TCurrentContext) => boolean): BuilderWithMiddlewares<MergedInitialContext<TInitialContext, Context, TCurrentContext>, MergedCurrentContext<TCurrentContext, {
|
|
126
|
+
isGateEnabled: typeof isGateEnabled;
|
|
127
|
+
}>, TInputSchema, TOutputSchema, TErrorMap, TMeta, TInferredGateName>;
|
|
230
128
|
/**
|
|
231
129
|
* Defines the handler of the procedure.
|
|
232
130
|
*
|
|
233
131
|
* @see {@link https://orpc.unnoq.com/docs/procedure Procedure Docs}
|
|
234
132
|
*/
|
|
235
|
-
|
|
133
|
+
handler<UFuncOutput>(handler: ProcedureHandler<TCurrentContext, InferSchemaOutput<TInputSchema>, UFuncOutput, TErrorMap, TMeta>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, Schema<UFuncOutput, UFuncOutput>, TErrorMap, TMeta>;
|
|
236
134
|
}
|
|
237
|
-
|
|
238
|
-
/**
|
|
239
|
-
* This property holds the defined options.
|
|
240
|
-
*/
|
|
241
|
-
'~orpc': EnhanceRouterOptions<TErrorMap>;
|
|
242
|
-
/**
|
|
243
|
-
* Adds type-safe custom errors.
|
|
244
|
-
* The provided errors are spared-merged with any existing errors.
|
|
245
|
-
*
|
|
246
|
-
* @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
247
|
-
*/
|
|
248
|
-
'errors'<U extends ErrorMap>(errors: U): RouterBuilder<TInitialContext, TCurrentContext, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
249
|
-
/**
|
|
250
|
-
* Uses a middleware to modify the context or improve the pipeline.
|
|
251
|
-
*
|
|
252
|
-
* @info Supports both normal middleware and inline middleware implementations.
|
|
253
|
-
* @note The current context must be satisfy middleware dependent-context
|
|
254
|
-
* @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
|
|
255
|
-
*/
|
|
256
|
-
'use'<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>): RouterBuilder<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TErrorMap, TMeta>;
|
|
135
|
+
declare class BuilderWithMiddlewares<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TGateName extends string> extends ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName> {
|
|
257
136
|
/**
|
|
258
137
|
* Prefixes all procedures in the router.
|
|
259
138
|
* The provided prefix is post-appended to any existing router prefix.
|
|
@@ -262,30 +141,36 @@ interface RouterBuilder<TInitialContext extends Context, TCurrentContext extends
|
|
|
262
141
|
*
|
|
263
142
|
* @see {@link https://orpc.unnoq.com/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
|
|
264
143
|
*/
|
|
265
|
-
|
|
144
|
+
prefix(prefix: HTTPPath): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
|
|
266
145
|
/**
|
|
267
146
|
* Adds tags to all procedures in the router.
|
|
268
147
|
* This helpful when you want to group procedures together in the OpenAPI specification.
|
|
269
148
|
*
|
|
270
149
|
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
|
271
150
|
*/
|
|
272
|
-
|
|
151
|
+
tag(...tags: string[]): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
|
|
273
152
|
/**
|
|
274
153
|
* Applies all of the previously defined options to the specified router.
|
|
275
154
|
*
|
|
276
155
|
* @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
|
|
277
156
|
*/
|
|
278
|
-
|
|
157
|
+
router<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(router: U): EnhancedRouter<U, TInitialContext, TCurrentContext, TErrorMap>;
|
|
279
158
|
/**
|
|
280
159
|
* Create a lazy router
|
|
281
160
|
* And applies all of the previously defined options to the specified router.
|
|
282
161
|
*
|
|
283
162
|
* @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
|
|
284
163
|
*/
|
|
285
|
-
|
|
164
|
+
lazyRoute<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(loader: () => Promise<{
|
|
286
165
|
default: U;
|
|
287
166
|
}>): EnhancedRouter<Lazy<U>, TInitialContext, TCurrentContext, TErrorMap>;
|
|
288
167
|
}
|
|
168
|
+
interface RouterBuilder<TInitialContext extends Context, TCurrentContext extends Context, TErrorMap extends ErrorMap, TMeta extends Meta> extends Pick<BuilderWithMiddlewares<TInitialContext, TCurrentContext, any, any, TErrorMap, TMeta, any>, 'prefix' | 'tag' | 'router' | 'lazyRoute'> {
|
|
169
|
+
/**
|
|
170
|
+
* This property holds the defined options.
|
|
171
|
+
*/
|
|
172
|
+
'~orpc': EnhanceRouterOptions<TErrorMap>;
|
|
173
|
+
}
|
|
289
174
|
|
|
290
175
|
interface DecoratedMiddleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> extends Middleware<TInContext, TOutContext, TInput, TOutput, TErrorConstructorMap, TMeta> {
|
|
291
176
|
/**
|
|
@@ -314,12 +199,7 @@ interface BuilderDef<TInputSchema extends AnySchema, TOutputSchema extends AnySc
|
|
|
314
199
|
inputValidationIndex: number;
|
|
315
200
|
outputValidationIndex: number;
|
|
316
201
|
}
|
|
317
|
-
declare class Builder<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TGateName extends string> {
|
|
318
|
-
/**
|
|
319
|
-
* This property holds the defined options.
|
|
320
|
-
*/
|
|
321
|
-
'~orpc': BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
|
|
322
|
-
constructor(def: BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>);
|
|
202
|
+
declare class Builder<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TGateName extends string> extends BuilderWithMiddlewares<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName> {
|
|
323
203
|
/**
|
|
324
204
|
* Set or override the initial context.
|
|
325
205
|
*
|
|
@@ -333,89 +213,6 @@ declare class Builder<TInitialContext extends Context, TCurrentContext extends C
|
|
|
333
213
|
*/
|
|
334
214
|
middleware<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, TInput, TOutput = any>(// = any here is important to make middleware can be used in any output by default
|
|
335
215
|
middleware: Middleware<TInitialContext, UOutContext, TInput, TOutput, ORPCErrorConstructorMap<TErrorMap>, TMeta>): DecoratedMiddleware<TInitialContext, UOutContext, TInput, TOutput, any, TMeta>;
|
|
336
|
-
/**
|
|
337
|
-
* Adds type-safe custom errors.
|
|
338
|
-
* The provided errors are spared-merged with any existing errors.
|
|
339
|
-
*
|
|
340
|
-
* @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
341
|
-
*/
|
|
342
|
-
errors<U extends ErrorMap>(errors: U): Builder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta, TGateName>;
|
|
343
|
-
/**
|
|
344
|
-
* Uses a middleware to modify the context or improve the pipeline.
|
|
345
|
-
*
|
|
346
|
-
* @info Supports both normal middleware and inline middleware implementations.
|
|
347
|
-
* @note The current context must be satisfy middleware dependent-context
|
|
348
|
-
* @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
|
|
349
|
-
*/
|
|
350
|
-
use<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>): BuilderWithMiddlewares<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
|
|
351
|
-
useGating<const TInferredGateName extends string>(gates: TInferredGateName[], isGateEnabled: (gate: TInferredGateName, ctx: TCurrentContext) => boolean): BuilderWithMiddlewares<MergedInitialContext<TInitialContext, Context, TCurrentContext>, MergedCurrentContext<TCurrentContext, {
|
|
352
|
-
isGateEnabled: typeof isGateEnabled;
|
|
353
|
-
}>, TInputSchema, TOutputSchema, TErrorMap, TMeta, TInferredGateName>;
|
|
354
|
-
/**
|
|
355
|
-
* Sets or updates the metadata.
|
|
356
|
-
* The provided metadata is spared-merged with any existing metadata.
|
|
357
|
-
*
|
|
358
|
-
* @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
|
|
359
|
-
*/
|
|
360
|
-
meta(meta: TMeta): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
|
|
361
|
-
/**
|
|
362
|
-
* Sets or updates the route definition.
|
|
363
|
-
* The provided route is spared-merged with any existing route.
|
|
364
|
-
* This option is typically relevant when integrating with OpenAPI.
|
|
365
|
-
*
|
|
366
|
-
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
367
|
-
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
368
|
-
*/
|
|
369
|
-
route(route: Route): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
|
|
370
|
-
/**
|
|
371
|
-
* Defines the input validation schema.
|
|
372
|
-
*
|
|
373
|
-
* @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
|
|
374
|
-
*/
|
|
375
|
-
input<USchema extends AnySchema>(schema: USchema): ProcedureBuilder<TInitialContext, TCurrentContext, USchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
|
|
376
|
-
/**
|
|
377
|
-
* Defines the output validation schema.
|
|
378
|
-
*
|
|
379
|
-
* @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
|
|
380
|
-
*/
|
|
381
|
-
output<USchema extends AnySchema>(schema: USchema): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, USchema, TErrorMap, TMeta, TGateName>;
|
|
382
|
-
/**
|
|
383
|
-
* Defines the handler of the procedure.
|
|
384
|
-
*
|
|
385
|
-
* @see {@link https://orpc.unnoq.com/docs/procedure Procedure Docs}
|
|
386
|
-
*/
|
|
387
|
-
handler<UFuncOutput>(handler: ProcedureHandler<TCurrentContext, InferSchemaOutput<TInputSchema>, UFuncOutput, TErrorMap, TMeta>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, Schema<UFuncOutput, UFuncOutput>, TErrorMap, TMeta>;
|
|
388
|
-
/**
|
|
389
|
-
* Prefixes all procedures in the router.
|
|
390
|
-
* The provided prefix is post-appended to any existing router prefix.
|
|
391
|
-
*
|
|
392
|
-
* @note This option does not affect procedures that do not define a path in their route definition.
|
|
393
|
-
*
|
|
394
|
-
* @see {@link https://orpc.unnoq.com/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
|
|
395
|
-
*/
|
|
396
|
-
prefix(prefix: HTTPPath): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
|
|
397
|
-
/**
|
|
398
|
-
* Adds tags to all procedures in the router.
|
|
399
|
-
* This helpful when you want to group procedures together in the OpenAPI specification.
|
|
400
|
-
*
|
|
401
|
-
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
|
402
|
-
*/
|
|
403
|
-
tag(...tags: string[]): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
|
|
404
|
-
/**
|
|
405
|
-
* Applies all of the previously defined options to the specified router.
|
|
406
|
-
*
|
|
407
|
-
* @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
|
|
408
|
-
*/
|
|
409
|
-
router<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(router: U): EnhancedRouter<U, TInitialContext, TCurrentContext, TErrorMap>;
|
|
410
|
-
/**
|
|
411
|
-
* Create a lazy router
|
|
412
|
-
* And applies all of the previously defined options to the specified router.
|
|
413
|
-
*
|
|
414
|
-
* @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
|
|
415
|
-
*/
|
|
416
|
-
lazyRoute<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(loader: () => Promise<{
|
|
417
|
-
default: U;
|
|
418
|
-
}>): EnhancedRouter<Lazy<U>, TInitialContext, TCurrentContext, TErrorMap>;
|
|
419
216
|
}
|
|
420
217
|
type ApiBuilder<TMeta extends Meta> = Builder<Record<never, never>, Record<never, never>, Schema<unknown, unknown>, Schema<unknown, unknown>, Record<never, never>, TMeta, never>;
|
|
421
218
|
interface ApiBuilderOpts<TMeta extends Meta> {
|
|
@@ -599,5 +396,5 @@ declare function createRouterClient<T extends AnyRouter, TClientContext extends
|
|
|
599
396
|
declare function setHiddenRouterContract<T extends Lazyable<AnyRouter>>(router: T, contract: AnyContractRouter): T;
|
|
600
397
|
declare function getHiddenRouterContract(router: Lazyable<AnyRouter | AnyContractRouter>): AnyContractRouter | undefined;
|
|
601
398
|
|
|
602
|
-
export { AnyMiddleware, AnyProcedure, AnyRouter, Builder, Context, CreateProcedureClientOptions, DecoratedProcedure, InferRouterInitialContext, Lazy, Lazyable, MapInputMiddleware, MergedCurrentContext, MergedInitialContext, Middleware, ORPCErrorConstructorMap, Procedure, ProcedureClient, ProcedureHandler, Router, addMiddleware, call, createAccessibleLazyRouter, createApiBuilder, createAssertedLazyProcedure, createContractedProcedure, createRouterClient, decorateMiddleware, enhanceRouter, getHiddenRouterContract, getRouter, implement, implementerInternal, isStartWithMiddlewares, mergeMiddlewares, os, resolveContractProcedures, setHiddenRouterContract, traverseContractProcedures, unlazyRouter };
|
|
603
|
-
export type { AccessibleLazyRouter, ApiBuilder, BuilderDef,
|
|
399
|
+
export { AnyMiddleware, AnyProcedure, AnyRouter, Builder, BuilderWithMiddlewares, Context, CreateProcedureClientOptions, DecoratedProcedure, InferRouterInitialContext, Lazy, Lazyable, MapInputMiddleware, MergedCurrentContext, MergedInitialContext, Middleware, ORPCErrorConstructorMap, Procedure, ProcedureBuilder, ProcedureClient, ProcedureHandler, Router, addMiddleware, call, createAccessibleLazyRouter, createApiBuilder, createAssertedLazyProcedure, createContractedProcedure, createRouterClient, decorateMiddleware, enhanceRouter, getHiddenRouterContract, getRouter, implement, implementerInternal, isStartWithMiddlewares, mergeMiddlewares, os, resolveContractProcedures, setHiddenRouterContract, traverseContractProcedures, unlazyRouter };
|
|
400
|
+
export type { AccessibleLazyRouter, ApiBuilder, BuilderDef, ContractProcedureCallbackOptions, DecoratedMiddleware, EnhanceRouterOptions, EnhancedRouter, ImplementedProcedure, Implementer, ImplementerInternal, ImplementerInternalWithMiddlewares, LazyTraverseContractProceduresOptions, ProcedureImplementer, RouterBuilder, RouterClient, RouterImplementer, RouterImplementerWithMiddlewares, TraverseContractProcedureCallbackOptions, TraverseContractProceduresOptions, UnlaziedRouter };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AnySchema, ErrorMap, Meta, MergedErrorMap, Route, InferSchemaOutput, InferSchemaInput, EnhanceRouteOptions, AnyContractRouter, AnyContractProcedure, Schema, ContractRouter, ContractProcedureDef, ContractProcedure, InferContractRouterErrorMap, InferContractRouterMeta, ErrorFromErrorMap } from '@temporary-name/contract';
|
|
1
|
+
import { AnySchema, ErrorMap, Meta, MergedErrorMap, Route, InferSchemaOutput, InferSchemaInput, EnhanceRouteOptions, AnyContractRouter, AnyContractProcedure, ContractProcedureBuilder, Schema, ContractRouter, ContractProcedureDef, ContractProcedure, InferContractRouterErrorMap, InferContractRouterMeta, ErrorFromErrorMap } from '@temporary-name/contract';
|
|
2
2
|
export { ContractProcedure, ContractProcedureDef, ContractRouter, ErrorMap, ErrorMapItem, InferSchemaInput, InferSchemaOutput, InputStructure, MergedErrorMap, Meta, OutputStructure, Route, Schema, ValidationError, eventIterator, type, validateORPCError } from '@temporary-name/contract';
|
|
3
3
|
import { IntersectPick, ClientContext, MaybeOptionalOptions, HTTPPath, ClientOptions, ClientPromiseResult } from '@temporary-name/shared';
|
|
4
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';
|
|
@@ -93,104 +93,27 @@ type UnlaziedRouter<T extends AnyRouter> = T extends AnyProcedure ? T : {
|
|
|
93
93
|
};
|
|
94
94
|
declare function unlazyRouter<T extends AnyRouter>(router: T): Promise<UnlaziedRouter<T>>;
|
|
95
95
|
|
|
96
|
-
|
|
96
|
+
declare class ProcedureBuilder<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TGateName extends string> extends ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
|
97
97
|
/**
|
|
98
98
|
* This property holds the defined options.
|
|
99
99
|
*/
|
|
100
100
|
'~orpc': BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
* @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
106
|
-
*/
|
|
107
|
-
'errors'<U extends ErrorMap>(errors: U): BuilderWithMiddlewares<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta, TGateName>;
|
|
108
|
-
/**
|
|
109
|
-
* Uses a middleware to modify the context or improve the pipeline.
|
|
110
|
-
*
|
|
111
|
-
* @info Supports both normal middleware and inline middleware implementations.
|
|
112
|
-
* @note The current context must be satisfy middleware dependent-context
|
|
113
|
-
* @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
|
|
114
|
-
*/
|
|
115
|
-
'use'<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>): BuilderWithMiddlewares<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
|
|
116
|
-
/**
|
|
117
|
-
* Sets or updates the metadata.
|
|
118
|
-
* The provided metadata is spared-merged with any existing metadata.
|
|
119
|
-
*
|
|
120
|
-
* @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
|
|
121
|
-
*/
|
|
122
|
-
'meta'(meta: TMeta): BuilderWithMiddlewares<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
|
|
123
|
-
/**
|
|
124
|
-
* Sets or updates the route definition.
|
|
125
|
-
* The provided route is spared-merged with any existing route.
|
|
126
|
-
* This option is typically relevant when integrating with OpenAPI.
|
|
127
|
-
*
|
|
128
|
-
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
129
|
-
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
130
|
-
*/
|
|
131
|
-
'route'(route: Route): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
|
|
101
|
+
constructor(def: BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>);
|
|
102
|
+
errors: <U extends ErrorMap>(errors: U) => ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta, TGateName>;
|
|
103
|
+
meta: (meta: TMeta) => ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
|
|
104
|
+
route: (route: Route) => ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
|
|
132
105
|
/**
|
|
133
106
|
* Defines the input validation schema.
|
|
134
107
|
*
|
|
135
108
|
* @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
|
|
136
109
|
*/
|
|
137
|
-
|
|
110
|
+
input<USchema extends AnySchema>(schema: USchema): ProcedureBuilder<TInitialContext, TCurrentContext, USchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
|
|
138
111
|
/**
|
|
139
112
|
* Defines the output validation schema.
|
|
140
113
|
*
|
|
141
114
|
* @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
|
|
142
115
|
*/
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Defines the handler of the procedure.
|
|
146
|
-
*
|
|
147
|
-
* @see {@link https://orpc.unnoq.com/docs/procedure Procedure Docs}
|
|
148
|
-
*/
|
|
149
|
-
'handler'<UFuncOutput>(handler: ProcedureHandler<TCurrentContext, InferSchemaOutput<TInputSchema>, UFuncOutput, TErrorMap, TMeta>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, Schema<UFuncOutput, UFuncOutput>, TErrorMap, TMeta>;
|
|
150
|
-
/**
|
|
151
|
-
* Prefixes all procedures in the router.
|
|
152
|
-
* The provided prefix is post-appended to any existing router prefix.
|
|
153
|
-
*
|
|
154
|
-
* @note This option does not affect procedures that do not define a path in their route definition.
|
|
155
|
-
*
|
|
156
|
-
* @see {@link https://orpc.unnoq.com/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
|
|
157
|
-
*/
|
|
158
|
-
'prefix'(prefix: HTTPPath): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
|
|
159
|
-
/**
|
|
160
|
-
* Adds tags to all procedures in the router.
|
|
161
|
-
* This helpful when you want to group procedures together in the OpenAPI specification.
|
|
162
|
-
*
|
|
163
|
-
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
|
164
|
-
*/
|
|
165
|
-
'tag'(...tags: string[]): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
|
|
166
|
-
/**
|
|
167
|
-
* Applies all of the previously defined options to the specified router.
|
|
168
|
-
*
|
|
169
|
-
* @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
|
|
170
|
-
*/
|
|
171
|
-
'router'<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(router: U): EnhancedRouter<U, TInitialContext, TCurrentContext, TErrorMap>;
|
|
172
|
-
/**
|
|
173
|
-
* Create a lazy router
|
|
174
|
-
* And applies all of the previously defined options to the specified router.
|
|
175
|
-
*
|
|
176
|
-
* @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
|
|
177
|
-
*/
|
|
178
|
-
'lazyRoute'<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(loader: () => Promise<{
|
|
179
|
-
default: U;
|
|
180
|
-
}>): EnhancedRouter<Lazy<U>, TInitialContext, TCurrentContext, TErrorMap>;
|
|
181
|
-
}
|
|
182
|
-
interface ProcedureBuilder<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TGateName extends string> {
|
|
183
|
-
/**
|
|
184
|
-
* This property holds the defined options.
|
|
185
|
-
*/
|
|
186
|
-
'~orpc': BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
|
|
187
|
-
/**
|
|
188
|
-
* Adds type-safe custom errors.
|
|
189
|
-
* The provided errors are spared-merged with any existing errors.
|
|
190
|
-
*
|
|
191
|
-
* @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
192
|
-
*/
|
|
193
|
-
'errors'<U extends ErrorMap>(errors: U): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta, TGateName>;
|
|
116
|
+
output<USchema extends AnySchema>(schema: USchema): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, USchema, TErrorMap, TMeta, TGateName>;
|
|
194
117
|
/**
|
|
195
118
|
* Uses a middleware to modify the context or improve the pipeline.
|
|
196
119
|
*
|
|
@@ -198,62 +121,18 @@ interface ProcedureBuilder<TInitialContext extends Context, TCurrentContext exte
|
|
|
198
121
|
* @note The current context must be satisfy middleware dependent-context
|
|
199
122
|
* @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
|
|
200
123
|
*/
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
*
|
|
206
|
-
* @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
|
|
207
|
-
*/
|
|
208
|
-
'meta'(meta: TMeta): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
|
|
209
|
-
/**
|
|
210
|
-
* Sets or updates the route definition.
|
|
211
|
-
* The provided route is spared-merged with any existing route.
|
|
212
|
-
* This option is typically relevant when integrating with OpenAPI.
|
|
213
|
-
*
|
|
214
|
-
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
215
|
-
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
216
|
-
*/
|
|
217
|
-
'route'(route: Route): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
|
|
218
|
-
/**
|
|
219
|
-
* Defines the input validation schema.
|
|
220
|
-
*
|
|
221
|
-
* @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
|
|
222
|
-
*/
|
|
223
|
-
'input'<USchema extends AnySchema>(schema: USchema): ProcedureBuilder<TInitialContext, TCurrentContext, USchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
|
|
224
|
-
/**
|
|
225
|
-
* Defines the output validation schema.
|
|
226
|
-
*
|
|
227
|
-
* @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
|
|
228
|
-
*/
|
|
229
|
-
'output'<USchema extends AnySchema>(schema: USchema): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, USchema, TErrorMap, TMeta, TGateName>;
|
|
124
|
+
use<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ProcedureBuilder<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
|
|
125
|
+
useGating<const TInferredGateName extends string>(gates: TInferredGateName[], isGateEnabled: (gate: TInferredGateName, ctx: TCurrentContext) => boolean): BuilderWithMiddlewares<MergedInitialContext<TInitialContext, Context, TCurrentContext>, MergedCurrentContext<TCurrentContext, {
|
|
126
|
+
isGateEnabled: typeof isGateEnabled;
|
|
127
|
+
}>, TInputSchema, TOutputSchema, TErrorMap, TMeta, TInferredGateName>;
|
|
230
128
|
/**
|
|
231
129
|
* Defines the handler of the procedure.
|
|
232
130
|
*
|
|
233
131
|
* @see {@link https://orpc.unnoq.com/docs/procedure Procedure Docs}
|
|
234
132
|
*/
|
|
235
|
-
|
|
133
|
+
handler<UFuncOutput>(handler: ProcedureHandler<TCurrentContext, InferSchemaOutput<TInputSchema>, UFuncOutput, TErrorMap, TMeta>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, Schema<UFuncOutput, UFuncOutput>, TErrorMap, TMeta>;
|
|
236
134
|
}
|
|
237
|
-
|
|
238
|
-
/**
|
|
239
|
-
* This property holds the defined options.
|
|
240
|
-
*/
|
|
241
|
-
'~orpc': EnhanceRouterOptions<TErrorMap>;
|
|
242
|
-
/**
|
|
243
|
-
* Adds type-safe custom errors.
|
|
244
|
-
* The provided errors are spared-merged with any existing errors.
|
|
245
|
-
*
|
|
246
|
-
* @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
247
|
-
*/
|
|
248
|
-
'errors'<U extends ErrorMap>(errors: U): RouterBuilder<TInitialContext, TCurrentContext, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
249
|
-
/**
|
|
250
|
-
* Uses a middleware to modify the context or improve the pipeline.
|
|
251
|
-
*
|
|
252
|
-
* @info Supports both normal middleware and inline middleware implementations.
|
|
253
|
-
* @note The current context must be satisfy middleware dependent-context
|
|
254
|
-
* @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
|
|
255
|
-
*/
|
|
256
|
-
'use'<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>): RouterBuilder<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TErrorMap, TMeta>;
|
|
135
|
+
declare class BuilderWithMiddlewares<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TGateName extends string> extends ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName> {
|
|
257
136
|
/**
|
|
258
137
|
* Prefixes all procedures in the router.
|
|
259
138
|
* The provided prefix is post-appended to any existing router prefix.
|
|
@@ -262,30 +141,36 @@ interface RouterBuilder<TInitialContext extends Context, TCurrentContext extends
|
|
|
262
141
|
*
|
|
263
142
|
* @see {@link https://orpc.unnoq.com/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
|
|
264
143
|
*/
|
|
265
|
-
|
|
144
|
+
prefix(prefix: HTTPPath): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
|
|
266
145
|
/**
|
|
267
146
|
* Adds tags to all procedures in the router.
|
|
268
147
|
* This helpful when you want to group procedures together in the OpenAPI specification.
|
|
269
148
|
*
|
|
270
149
|
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
|
271
150
|
*/
|
|
272
|
-
|
|
151
|
+
tag(...tags: string[]): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
|
|
273
152
|
/**
|
|
274
153
|
* Applies all of the previously defined options to the specified router.
|
|
275
154
|
*
|
|
276
155
|
* @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
|
|
277
156
|
*/
|
|
278
|
-
|
|
157
|
+
router<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(router: U): EnhancedRouter<U, TInitialContext, TCurrentContext, TErrorMap>;
|
|
279
158
|
/**
|
|
280
159
|
* Create a lazy router
|
|
281
160
|
* And applies all of the previously defined options to the specified router.
|
|
282
161
|
*
|
|
283
162
|
* @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
|
|
284
163
|
*/
|
|
285
|
-
|
|
164
|
+
lazyRoute<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(loader: () => Promise<{
|
|
286
165
|
default: U;
|
|
287
166
|
}>): EnhancedRouter<Lazy<U>, TInitialContext, TCurrentContext, TErrorMap>;
|
|
288
167
|
}
|
|
168
|
+
interface RouterBuilder<TInitialContext extends Context, TCurrentContext extends Context, TErrorMap extends ErrorMap, TMeta extends Meta> extends Pick<BuilderWithMiddlewares<TInitialContext, TCurrentContext, any, any, TErrorMap, TMeta, any>, 'prefix' | 'tag' | 'router' | 'lazyRoute'> {
|
|
169
|
+
/**
|
|
170
|
+
* This property holds the defined options.
|
|
171
|
+
*/
|
|
172
|
+
'~orpc': EnhanceRouterOptions<TErrorMap>;
|
|
173
|
+
}
|
|
289
174
|
|
|
290
175
|
interface DecoratedMiddleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> extends Middleware<TInContext, TOutContext, TInput, TOutput, TErrorConstructorMap, TMeta> {
|
|
291
176
|
/**
|
|
@@ -314,12 +199,7 @@ interface BuilderDef<TInputSchema extends AnySchema, TOutputSchema extends AnySc
|
|
|
314
199
|
inputValidationIndex: number;
|
|
315
200
|
outputValidationIndex: number;
|
|
316
201
|
}
|
|
317
|
-
declare class Builder<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TGateName extends string> {
|
|
318
|
-
/**
|
|
319
|
-
* This property holds the defined options.
|
|
320
|
-
*/
|
|
321
|
-
'~orpc': BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
|
|
322
|
-
constructor(def: BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>);
|
|
202
|
+
declare class Builder<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TGateName extends string> extends BuilderWithMiddlewares<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName> {
|
|
323
203
|
/**
|
|
324
204
|
* Set or override the initial context.
|
|
325
205
|
*
|
|
@@ -333,89 +213,6 @@ declare class Builder<TInitialContext extends Context, TCurrentContext extends C
|
|
|
333
213
|
*/
|
|
334
214
|
middleware<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, TInput, TOutput = any>(// = any here is important to make middleware can be used in any output by default
|
|
335
215
|
middleware: Middleware<TInitialContext, UOutContext, TInput, TOutput, ORPCErrorConstructorMap<TErrorMap>, TMeta>): DecoratedMiddleware<TInitialContext, UOutContext, TInput, TOutput, any, TMeta>;
|
|
336
|
-
/**
|
|
337
|
-
* Adds type-safe custom errors.
|
|
338
|
-
* The provided errors are spared-merged with any existing errors.
|
|
339
|
-
*
|
|
340
|
-
* @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
341
|
-
*/
|
|
342
|
-
errors<U extends ErrorMap>(errors: U): Builder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta, TGateName>;
|
|
343
|
-
/**
|
|
344
|
-
* Uses a middleware to modify the context or improve the pipeline.
|
|
345
|
-
*
|
|
346
|
-
* @info Supports both normal middleware and inline middleware implementations.
|
|
347
|
-
* @note The current context must be satisfy middleware dependent-context
|
|
348
|
-
* @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
|
|
349
|
-
*/
|
|
350
|
-
use<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>): BuilderWithMiddlewares<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
|
|
351
|
-
useGating<const TInferredGateName extends string>(gates: TInferredGateName[], isGateEnabled: (gate: TInferredGateName, ctx: TCurrentContext) => boolean): BuilderWithMiddlewares<MergedInitialContext<TInitialContext, Context, TCurrentContext>, MergedCurrentContext<TCurrentContext, {
|
|
352
|
-
isGateEnabled: typeof isGateEnabled;
|
|
353
|
-
}>, TInputSchema, TOutputSchema, TErrorMap, TMeta, TInferredGateName>;
|
|
354
|
-
/**
|
|
355
|
-
* Sets or updates the metadata.
|
|
356
|
-
* The provided metadata is spared-merged with any existing metadata.
|
|
357
|
-
*
|
|
358
|
-
* @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
|
|
359
|
-
*/
|
|
360
|
-
meta(meta: TMeta): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
|
|
361
|
-
/**
|
|
362
|
-
* Sets or updates the route definition.
|
|
363
|
-
* The provided route is spared-merged with any existing route.
|
|
364
|
-
* This option is typically relevant when integrating with OpenAPI.
|
|
365
|
-
*
|
|
366
|
-
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
367
|
-
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
368
|
-
*/
|
|
369
|
-
route(route: Route): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
|
|
370
|
-
/**
|
|
371
|
-
* Defines the input validation schema.
|
|
372
|
-
*
|
|
373
|
-
* @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
|
|
374
|
-
*/
|
|
375
|
-
input<USchema extends AnySchema>(schema: USchema): ProcedureBuilder<TInitialContext, TCurrentContext, USchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
|
|
376
|
-
/**
|
|
377
|
-
* Defines the output validation schema.
|
|
378
|
-
*
|
|
379
|
-
* @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
|
|
380
|
-
*/
|
|
381
|
-
output<USchema extends AnySchema>(schema: USchema): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, USchema, TErrorMap, TMeta, TGateName>;
|
|
382
|
-
/**
|
|
383
|
-
* Defines the handler of the procedure.
|
|
384
|
-
*
|
|
385
|
-
* @see {@link https://orpc.unnoq.com/docs/procedure Procedure Docs}
|
|
386
|
-
*/
|
|
387
|
-
handler<UFuncOutput>(handler: ProcedureHandler<TCurrentContext, InferSchemaOutput<TInputSchema>, UFuncOutput, TErrorMap, TMeta>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, Schema<UFuncOutput, UFuncOutput>, TErrorMap, TMeta>;
|
|
388
|
-
/**
|
|
389
|
-
* Prefixes all procedures in the router.
|
|
390
|
-
* The provided prefix is post-appended to any existing router prefix.
|
|
391
|
-
*
|
|
392
|
-
* @note This option does not affect procedures that do not define a path in their route definition.
|
|
393
|
-
*
|
|
394
|
-
* @see {@link https://orpc.unnoq.com/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
|
|
395
|
-
*/
|
|
396
|
-
prefix(prefix: HTTPPath): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
|
|
397
|
-
/**
|
|
398
|
-
* Adds tags to all procedures in the router.
|
|
399
|
-
* This helpful when you want to group procedures together in the OpenAPI specification.
|
|
400
|
-
*
|
|
401
|
-
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
|
402
|
-
*/
|
|
403
|
-
tag(...tags: string[]): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
|
|
404
|
-
/**
|
|
405
|
-
* Applies all of the previously defined options to the specified router.
|
|
406
|
-
*
|
|
407
|
-
* @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
|
|
408
|
-
*/
|
|
409
|
-
router<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(router: U): EnhancedRouter<U, TInitialContext, TCurrentContext, TErrorMap>;
|
|
410
|
-
/**
|
|
411
|
-
* Create a lazy router
|
|
412
|
-
* And applies all of the previously defined options to the specified router.
|
|
413
|
-
*
|
|
414
|
-
* @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
|
|
415
|
-
*/
|
|
416
|
-
lazyRoute<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(loader: () => Promise<{
|
|
417
|
-
default: U;
|
|
418
|
-
}>): EnhancedRouter<Lazy<U>, TInitialContext, TCurrentContext, TErrorMap>;
|
|
419
216
|
}
|
|
420
217
|
type ApiBuilder<TMeta extends Meta> = Builder<Record<never, never>, Record<never, never>, Schema<unknown, unknown>, Schema<unknown, unknown>, Record<never, never>, TMeta, never>;
|
|
421
218
|
interface ApiBuilderOpts<TMeta extends Meta> {
|
|
@@ -599,5 +396,5 @@ declare function createRouterClient<T extends AnyRouter, TClientContext extends
|
|
|
599
396
|
declare function setHiddenRouterContract<T extends Lazyable<AnyRouter>>(router: T, contract: AnyContractRouter): T;
|
|
600
397
|
declare function getHiddenRouterContract(router: Lazyable<AnyRouter | AnyContractRouter>): AnyContractRouter | undefined;
|
|
601
398
|
|
|
602
|
-
export { AnyMiddleware, AnyProcedure, AnyRouter, Builder, Context, CreateProcedureClientOptions, DecoratedProcedure, InferRouterInitialContext, Lazy, Lazyable, MapInputMiddleware, MergedCurrentContext, MergedInitialContext, Middleware, ORPCErrorConstructorMap, Procedure, ProcedureClient, ProcedureHandler, Router, addMiddleware, call, createAccessibleLazyRouter, createApiBuilder, createAssertedLazyProcedure, createContractedProcedure, createRouterClient, decorateMiddleware, enhanceRouter, getHiddenRouterContract, getRouter, implement, implementerInternal, isStartWithMiddlewares, mergeMiddlewares, os, resolveContractProcedures, setHiddenRouterContract, traverseContractProcedures, unlazyRouter };
|
|
603
|
-
export type { AccessibleLazyRouter, ApiBuilder, BuilderDef,
|
|
399
|
+
export { AnyMiddleware, AnyProcedure, AnyRouter, Builder, BuilderWithMiddlewares, Context, CreateProcedureClientOptions, DecoratedProcedure, InferRouterInitialContext, Lazy, Lazyable, MapInputMiddleware, MergedCurrentContext, MergedInitialContext, Middleware, ORPCErrorConstructorMap, Procedure, ProcedureBuilder, ProcedureClient, ProcedureHandler, Router, addMiddleware, call, createAccessibleLazyRouter, createApiBuilder, createAssertedLazyProcedure, createContractedProcedure, createRouterClient, decorateMiddleware, enhanceRouter, getHiddenRouterContract, getRouter, implement, implementerInternal, isStartWithMiddlewares, mergeMiddlewares, os, resolveContractProcedures, setHiddenRouterContract, traverseContractProcedures, unlazyRouter };
|
|
400
|
+
export type { AccessibleLazyRouter, ApiBuilder, BuilderDef, ContractProcedureCallbackOptions, DecoratedMiddleware, EnhanceRouterOptions, EnhancedRouter, ImplementedProcedure, Implementer, ImplementerInternal, ImplementerInternalWithMiddlewares, LazyTraverseContractProceduresOptions, ProcedureImplementer, RouterBuilder, RouterClient, RouterImplementer, RouterImplementerWithMiddlewares, TraverseContractProcedureCallbackOptions, TraverseContractProceduresOptions, UnlaziedRouter };
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { isContractProcedure, mergeErrorMap, mergeMeta, mergeRoute, mergePrefix, enhanceRoute, mergeTags, getContractRouter } from '@temporary-name/contract';
|
|
2
|
-
export { ValidationError, eventIterator, type, validateORPCError } from '@temporary-name/contract';
|
|
3
1
|
import { onError, resolveMaybeOptionalOptions } from '@temporary-name/shared';
|
|
4
2
|
export { AsyncIteratorClass, EventPublisher, ORPCError, asyncIteratorToStream as eventIteratorToStream, isDefinedError, onError, onFinish, onStart, onSuccess, safe, streamToAsyncIteratorClass as streamToEventIterator } from '@temporary-name/shared';
|
|
3
|
+
import { isContractProcedure, mergeErrorMap, mergeMeta, mergeRoute, mergePrefix, enhanceRoute, mergeTags, ContractProcedureBuilder, getContractRouter } from '@temporary-name/contract';
|
|
4
|
+
export { ValidationError, eventIterator, type, validateORPCError } from '@temporary-name/contract';
|
|
5
5
|
import { c as createProcedureClient, i as isLazy, g as getLazyMeta, l as lazy, u as unlazy, a as gatingContext } from './shared/server.BKh8I1Ny.mjs';
|
|
6
6
|
export { L as LAZY_SYMBOL, b as createORPCErrorConstructorMap, m as mergeCurrentContext, d as middlewareOutputFn } from './shared/server.BKh8I1Ny.mjs';
|
|
7
7
|
export { getEventMeta, withEventMeta } from '@temporary-name/standard-server';
|
|
@@ -9,6 +9,30 @@ import 'node:async_hooks';
|
|
|
9
9
|
import 'zod';
|
|
10
10
|
import 'zod/v4/core';
|
|
11
11
|
|
|
12
|
+
function isStartWithMiddlewares(middlewares, compare) {
|
|
13
|
+
if (compare.length > middlewares.length) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
for (let i = 0; i < middlewares.length; i++) {
|
|
17
|
+
if (compare[i] === void 0) {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
if (middlewares[i] !== compare[i]) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
function mergeMiddlewares(first, second, options) {
|
|
27
|
+
if (options.dedupeLeading && isStartWithMiddlewares(second, first)) {
|
|
28
|
+
return second;
|
|
29
|
+
}
|
|
30
|
+
return [...first, ...second];
|
|
31
|
+
}
|
|
32
|
+
function addMiddleware(middlewares, addition) {
|
|
33
|
+
return [...middlewares, addition];
|
|
34
|
+
}
|
|
35
|
+
|
|
12
36
|
function decorateMiddleware(middleware) {
|
|
13
37
|
const decorated = ((...args) => middleware(...args));
|
|
14
38
|
decorated.mapInput = (mapInput) => {
|
|
@@ -45,30 +69,6 @@ function decorateMiddleware(middleware) {
|
|
|
45
69
|
return decorated;
|
|
46
70
|
}
|
|
47
71
|
|
|
48
|
-
function isStartWithMiddlewares(middlewares, compare) {
|
|
49
|
-
if (compare.length > middlewares.length) {
|
|
50
|
-
return false;
|
|
51
|
-
}
|
|
52
|
-
for (let i = 0; i < middlewares.length; i++) {
|
|
53
|
-
if (compare[i] === void 0) {
|
|
54
|
-
return true;
|
|
55
|
-
}
|
|
56
|
-
if (middlewares[i] !== compare[i]) {
|
|
57
|
-
return false;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return true;
|
|
61
|
-
}
|
|
62
|
-
function mergeMiddlewares(first, second, options) {
|
|
63
|
-
if (options.dedupeLeading && isStartWithMiddlewares(second, first)) {
|
|
64
|
-
return second;
|
|
65
|
-
}
|
|
66
|
-
return [...first, ...second];
|
|
67
|
-
}
|
|
68
|
-
function addMiddleware(middlewares, addition) {
|
|
69
|
-
return [...middlewares, addition];
|
|
70
|
-
}
|
|
71
|
-
|
|
72
72
|
class Procedure {
|
|
73
73
|
/**
|
|
74
74
|
* This property holds the defined options.
|
|
@@ -295,40 +295,32 @@ async function unlazyRouter(router) {
|
|
|
295
295
|
return unlazied;
|
|
296
296
|
}
|
|
297
297
|
|
|
298
|
-
class
|
|
299
|
-
/**
|
|
300
|
-
* This property holds the defined options.
|
|
301
|
-
*/
|
|
302
|
-
"~orpc";
|
|
298
|
+
class ProcedureBuilder extends ContractProcedureBuilder {
|
|
303
299
|
constructor(def) {
|
|
304
|
-
|
|
300
|
+
super(def);
|
|
305
301
|
}
|
|
306
302
|
/**
|
|
307
|
-
*
|
|
308
|
-
*
|
|
309
|
-
* @see {@link https://orpc.unnoq.com/docs/context Context Docs}
|
|
310
|
-
*/
|
|
311
|
-
$context() {
|
|
312
|
-
return this;
|
|
313
|
-
}
|
|
314
|
-
/**
|
|
315
|
-
* Creates a middleware.
|
|
303
|
+
* Defines the input validation schema.
|
|
316
304
|
*
|
|
317
|
-
* @see {@link https://orpc.unnoq.com/docs/
|
|
305
|
+
* @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
|
|
318
306
|
*/
|
|
319
|
-
|
|
320
|
-
return
|
|
307
|
+
input(schema) {
|
|
308
|
+
return new ProcedureBuilder({
|
|
309
|
+
...this["~orpc"],
|
|
310
|
+
inputSchema: schema,
|
|
311
|
+
inputValidationIndex: this["~orpc"].middlewares.length
|
|
312
|
+
});
|
|
321
313
|
}
|
|
322
314
|
/**
|
|
323
|
-
*
|
|
324
|
-
* The provided errors are spared-merged with any existing errors.
|
|
315
|
+
* Defines the output validation schema.
|
|
325
316
|
*
|
|
326
|
-
* @see {@link https://orpc.unnoq.com/docs/
|
|
317
|
+
* @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
|
|
327
318
|
*/
|
|
328
|
-
|
|
329
|
-
return new
|
|
319
|
+
output(schema) {
|
|
320
|
+
return new ProcedureBuilder({
|
|
330
321
|
...this["~orpc"],
|
|
331
|
-
|
|
322
|
+
outputSchema: schema,
|
|
323
|
+
outputValidationIndex: this["~orpc"].middlewares.length
|
|
332
324
|
});
|
|
333
325
|
}
|
|
334
326
|
/**
|
|
@@ -339,7 +331,7 @@ class Builder {
|
|
|
339
331
|
* @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
|
|
340
332
|
*/
|
|
341
333
|
use(middleware) {
|
|
342
|
-
return new
|
|
334
|
+
return new this.constructor({
|
|
343
335
|
...this["~orpc"],
|
|
344
336
|
middlewares: addMiddleware(this["~orpc"].middlewares, middleware)
|
|
345
337
|
});
|
|
@@ -352,56 +344,6 @@ class Builder {
|
|
|
352
344
|
);
|
|
353
345
|
});
|
|
354
346
|
}
|
|
355
|
-
/**
|
|
356
|
-
* Sets or updates the metadata.
|
|
357
|
-
* The provided metadata is spared-merged with any existing metadata.
|
|
358
|
-
*
|
|
359
|
-
* @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
|
|
360
|
-
*/
|
|
361
|
-
meta(meta) {
|
|
362
|
-
return new Builder({
|
|
363
|
-
...this["~orpc"],
|
|
364
|
-
meta: mergeMeta(this["~orpc"].meta, meta)
|
|
365
|
-
});
|
|
366
|
-
}
|
|
367
|
-
/**
|
|
368
|
-
* Sets or updates the route definition.
|
|
369
|
-
* The provided route is spared-merged with any existing route.
|
|
370
|
-
* This option is typically relevant when integrating with OpenAPI.
|
|
371
|
-
*
|
|
372
|
-
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
373
|
-
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
374
|
-
*/
|
|
375
|
-
route(route) {
|
|
376
|
-
return new Builder({
|
|
377
|
-
...this["~orpc"],
|
|
378
|
-
route: mergeRoute(this["~orpc"].route, route)
|
|
379
|
-
});
|
|
380
|
-
}
|
|
381
|
-
/**
|
|
382
|
-
* Defines the input validation schema.
|
|
383
|
-
*
|
|
384
|
-
* @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
|
|
385
|
-
*/
|
|
386
|
-
input(schema) {
|
|
387
|
-
return new Builder({
|
|
388
|
-
...this["~orpc"],
|
|
389
|
-
inputSchema: schema,
|
|
390
|
-
inputValidationIndex: this["~orpc"].middlewares.length
|
|
391
|
-
});
|
|
392
|
-
}
|
|
393
|
-
/**
|
|
394
|
-
* Defines the output validation schema.
|
|
395
|
-
*
|
|
396
|
-
* @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
|
|
397
|
-
*/
|
|
398
|
-
output(schema) {
|
|
399
|
-
return new Builder({
|
|
400
|
-
...this["~orpc"],
|
|
401
|
-
outputSchema: schema,
|
|
402
|
-
outputValidationIndex: this["~orpc"].middlewares.length
|
|
403
|
-
});
|
|
404
|
-
}
|
|
405
347
|
/**
|
|
406
348
|
* Defines the handler of the procedure.
|
|
407
349
|
*
|
|
@@ -413,6 +355,8 @@ class Builder {
|
|
|
413
355
|
handler
|
|
414
356
|
});
|
|
415
357
|
}
|
|
358
|
+
}
|
|
359
|
+
class BuilderWithMiddlewares extends ProcedureBuilder {
|
|
416
360
|
/**
|
|
417
361
|
* Prefixes all procedures in the router.
|
|
418
362
|
* The provided prefix is post-appended to any existing router prefix.
|
|
@@ -422,7 +366,7 @@ class Builder {
|
|
|
422
366
|
* @see {@link https://orpc.unnoq.com/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
|
|
423
367
|
*/
|
|
424
368
|
prefix(prefix) {
|
|
425
|
-
return new
|
|
369
|
+
return new this.constructor({
|
|
426
370
|
...this["~orpc"],
|
|
427
371
|
prefix: mergePrefix(this["~orpc"].prefix, prefix)
|
|
428
372
|
});
|
|
@@ -434,7 +378,7 @@ class Builder {
|
|
|
434
378
|
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
|
435
379
|
*/
|
|
436
380
|
tag(...tags) {
|
|
437
|
-
return new
|
|
381
|
+
return new this.constructor({
|
|
438
382
|
...this["~orpc"],
|
|
439
383
|
tags: mergeTags(this["~orpc"].tags, tags)
|
|
440
384
|
});
|
|
@@ -457,6 +401,25 @@ class Builder {
|
|
|
457
401
|
return enhanceRouter(lazy(loader), this["~orpc"]);
|
|
458
402
|
}
|
|
459
403
|
}
|
|
404
|
+
|
|
405
|
+
class Builder extends BuilderWithMiddlewares {
|
|
406
|
+
/**
|
|
407
|
+
* Set or override the initial context.
|
|
408
|
+
*
|
|
409
|
+
* @see {@link https://orpc.unnoq.com/docs/context Context Docs}
|
|
410
|
+
*/
|
|
411
|
+
$context() {
|
|
412
|
+
return this;
|
|
413
|
+
}
|
|
414
|
+
/**
|
|
415
|
+
* Creates a middleware.
|
|
416
|
+
*
|
|
417
|
+
* @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
|
|
418
|
+
*/
|
|
419
|
+
middleware(middleware) {
|
|
420
|
+
return decorateMiddleware(middleware);
|
|
421
|
+
}
|
|
422
|
+
}
|
|
460
423
|
function createApiBuilder(opts = {}) {
|
|
461
424
|
const base = new Builder({
|
|
462
425
|
route: {},
|
|
@@ -614,4 +577,4 @@ function createRouterClient(router, ...rest) {
|
|
|
614
577
|
return recursive;
|
|
615
578
|
}
|
|
616
579
|
|
|
617
|
-
export { Builder, DecoratedProcedure, Procedure, addMiddleware, call, createAccessibleLazyRouter, createApiBuilder, createAssertedLazyProcedure, createContractedProcedure, createProcedureClient, createRouterClient, decorateMiddleware, enhanceRouter, getHiddenRouterContract, getLazyMeta, getRouter, implement, implementerInternal, isLazy, isProcedure, isStartWithMiddlewares, lazy, mergeMiddlewares, os, resolveContractProcedures, setHiddenRouterContract, traverseContractProcedures, unlazy, unlazyRouter };
|
|
580
|
+
export { Builder, BuilderWithMiddlewares, DecoratedProcedure, Procedure, ProcedureBuilder, addMiddleware, call, createAccessibleLazyRouter, createApiBuilder, createAssertedLazyProcedure, createContractedProcedure, createProcedureClient, createRouterClient, decorateMiddleware, enhanceRouter, getHiddenRouterContract, getLazyMeta, getRouter, implement, implementerInternal, isLazy, isProcedure, isStartWithMiddlewares, lazy, mergeMiddlewares, os, resolveContractProcedures, setHiddenRouterContract, traverseContractProcedures, unlazy, unlazyRouter };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@temporary-name/server",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.9.3-alpha.
|
|
4
|
+
"version": "1.9.3-alpha.65222302f1b71807a849530b3fe0fa0326d3c1a2",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://www.stainless.com/",
|
|
7
7
|
"repository": {
|
|
@@ -74,13 +74,13 @@
|
|
|
74
74
|
"@standard-schema/spec": "^1.0.0",
|
|
75
75
|
"rou3": "^0.7.7",
|
|
76
76
|
"zod": "^4.1.12",
|
|
77
|
-
"@temporary-name/interop": "1.9.3-alpha.
|
|
78
|
-
"@temporary-name/
|
|
79
|
-
"@temporary-name/shared": "1.9.3-alpha.
|
|
80
|
-
"@temporary-name/
|
|
81
|
-
"@temporary-name/standard-server-
|
|
82
|
-
"@temporary-name/standard-server-
|
|
83
|
-
"@temporary-name/standard-server-
|
|
77
|
+
"@temporary-name/interop": "1.9.3-alpha.65222302f1b71807a849530b3fe0fa0326d3c1a2",
|
|
78
|
+
"@temporary-name/contract": "1.9.3-alpha.65222302f1b71807a849530b3fe0fa0326d3c1a2",
|
|
79
|
+
"@temporary-name/shared": "1.9.3-alpha.65222302f1b71807a849530b3fe0fa0326d3c1a2",
|
|
80
|
+
"@temporary-name/standard-server": "1.9.3-alpha.65222302f1b71807a849530b3fe0fa0326d3c1a2",
|
|
81
|
+
"@temporary-name/standard-server-fetch": "1.9.3-alpha.65222302f1b71807a849530b3fe0fa0326d3c1a2",
|
|
82
|
+
"@temporary-name/standard-server-node": "1.9.3-alpha.65222302f1b71807a849530b3fe0fa0326d3c1a2",
|
|
83
|
+
"@temporary-name/standard-server-aws-lambda": "1.9.3-alpha.65222302f1b71807a849530b3fe0fa0326d3c1a2"
|
|
84
84
|
},
|
|
85
85
|
"devDependencies": {
|
|
86
86
|
"@types/supertest": "^6.0.3",
|