@temporary-name/server 1.9.3-alpha.a252b3ff8cb6bf7deaa6d41dc9ac8a8d50edd80e → 1.9.3-alpha.afa9ee885873ed8fa674c071639909426419e6f0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/dist/adapters/aws-lambda/index.d.mts +3 -4
  2. package/dist/adapters/aws-lambda/index.d.ts +3 -4
  3. package/dist/adapters/aws-lambda/index.mjs +4 -3
  4. package/dist/adapters/fetch/index.d.mts +3 -4
  5. package/dist/adapters/fetch/index.d.ts +3 -4
  6. package/dist/adapters/fetch/index.mjs +4 -3
  7. package/dist/adapters/node/index.d.mts +3 -4
  8. package/dist/adapters/node/index.d.ts +3 -4
  9. package/dist/adapters/node/index.mjs +4 -3
  10. package/dist/adapters/standard/index.d.mts +20 -32
  11. package/dist/adapters/standard/index.d.ts +20 -32
  12. package/dist/adapters/standard/index.mjs +4 -3
  13. package/dist/index.d.mts +56 -1047
  14. package/dist/index.d.ts +56 -1047
  15. package/dist/index.mjs +79 -1886
  16. package/dist/openapi/index.d.mts +1 -1
  17. package/dist/openapi/index.d.ts +1 -1
  18. package/dist/openapi/index.mjs +60 -77
  19. package/dist/plugins/index.d.mts +3 -4
  20. package/dist/plugins/index.d.ts +3 -4
  21. package/dist/shared/{server.BeuTpcmO.d.mts → server.7aL9gcoU.d.mts} +2 -2
  22. package/dist/shared/server.BL2R5jcp.d.mts +228 -0
  23. package/dist/shared/server.BL2R5jcp.d.ts +228 -0
  24. package/dist/shared/{server.CMTfy2UB.mjs → server.CVBLzkro.mjs} +57 -95
  25. package/dist/shared/server.ClhVCxfg.mjs +413 -0
  26. package/dist/shared/{server.CQyYNJ1H.d.ts → server.D6Qs_UcF.d.mts} +2 -4
  27. package/dist/shared/{server.SLLuK6_v.d.ts → server.DFptr1Nz.d.ts} +2 -2
  28. package/dist/shared/{server.C1fnTLq0.d.mts → server.DpoO_ER_.d.ts} +2 -4
  29. package/dist/shared/{server.BEHw7Eyx.mjs → server.JtIZ8YG7.mjs} +1 -11
  30. package/package.json +10 -9
  31. package/dist/shared/server.BKSOrA6h.d.mts +0 -192
  32. package/dist/shared/server.BKSOrA6h.d.ts +0 -192
  33. package/dist/shared/server.BZtKt8i8.mjs +0 -201
@@ -0,0 +1,228 @@
1
+ import { ErrorMap, ErrorMapItem, InferSchemaInput, Meta, Schemas, ContractProcedureDef, AnyContractRouter, ContractProcedure, InferProcedureClientInputs, InferSchemaOutput, EnhanceRouteOptions, MergedErrorMap, AnyContractProcedure, ContractRouter, AnySchema, ErrorFromErrorMap } from '@temporary-name/contract';
2
+ import { ORPCErrorCode, MaybeOptionalOptions, ORPCErrorOptions, ORPCError, Promisable, StandardLazyRequest, HTTPPath, ClientContext, Interceptor, PromiseWithError, Value, Client } from '@temporary-name/shared';
3
+
4
+ type Context = Record<PropertyKey, any>;
5
+ type MergedInitialContext<TInitial extends Context, TAdditional extends Context, TCurrent extends Context> = TInitial & Omit<TAdditional, keyof TCurrent>;
6
+ type MergedCurrentContext<T extends Context, U extends Context> = Omit<T, keyof U> & U;
7
+ declare function mergeCurrentContext<T extends Context, U extends Context>(context: T, other: U): MergedCurrentContext<T, U>;
8
+
9
+ type ORPCErrorConstructorMapItemOptions<TData> = Omit<ORPCErrorOptions<TData>, 'defined' | 'status'>;
10
+ type ORPCErrorConstructorMapItem<TCode extends ORPCErrorCode, TInData> = (...rest: MaybeOptionalOptions<ORPCErrorConstructorMapItemOptions<TInData>>) => ORPCError<TCode, TInData>;
11
+ type ORPCErrorConstructorMap<T extends ErrorMap> = {
12
+ [K in keyof T]: K extends ORPCErrorCode ? T[K] extends ErrorMapItem<infer UInputSchema> ? ORPCErrorConstructorMapItem<K, InferSchemaInput<UInputSchema>> : never : never;
13
+ };
14
+ declare function createORPCErrorConstructorMap<T extends ErrorMap>(errors: T): ORPCErrorConstructorMap<T>;
15
+
16
+ interface ProcedureHandlerOptions<TCurrentContext extends Context, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
17
+ context: TCurrentContext;
18
+ path: readonly string[];
19
+ procedure: Procedure<Context, Context, Schemas, ErrorMap, TMeta>;
20
+ signal?: AbortSignal;
21
+ request?: StandardLazyRequest;
22
+ lastEventId: string | undefined;
23
+ errors: TErrorConstructorMap;
24
+ }
25
+ interface ProcedureHandler<TCurrentContext extends Context, TInput extends {
26
+ path: any;
27
+ query: any;
28
+ body: any;
29
+ }, THandlerOutput, TErrorMap extends ErrorMap, TMeta extends Meta> {
30
+ (input: TInput, opt: ProcedureHandlerOptions<TCurrentContext, ORPCErrorConstructorMap<TErrorMap>, TMeta>): Promisable<THandlerOutput>;
31
+ }
32
+ interface ProcedureDef<TInitialContext extends Context, TCurrentContext extends Context, TSchemas extends Schemas, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedureDef<TSchemas, TErrorMap, TMeta> {
33
+ __initialContext?: (type: TInitialContext) => unknown;
34
+ middlewares: readonly AnyMiddleware[];
35
+ inputValidationIndex: number;
36
+ outputValidationIndex: number;
37
+ handler: ProcedureHandler<TCurrentContext, any, any, any, any>;
38
+ }
39
+ /**
40
+ * This class represents a procedure.
41
+ *
42
+ * @see {@link https://orpc.unnoq.com/docs/procedure Procedure Docs}
43
+ */
44
+ declare class Procedure<TInitialContext extends Context, TCurrentContext extends Context, TSchemas extends Schemas, TErrorMap extends ErrorMap, TMeta extends Meta> {
45
+ /**
46
+ * This property holds the defined options.
47
+ */
48
+ '~orpc': ProcedureDef<TInitialContext, TCurrentContext, TSchemas, TErrorMap, TMeta>;
49
+ constructor(def: ProcedureDef<TInitialContext, TCurrentContext, TSchemas, TErrorMap, TMeta>);
50
+ }
51
+ type AnyProcedure = Procedure<any, any, Schemas, any, any>;
52
+ declare function isProcedure(item: unknown): item is AnyProcedure;
53
+
54
+ type MiddlewareResult<TOutContext extends Context, TOutput> = Promisable<{
55
+ output: TOutput;
56
+ context: TOutContext;
57
+ }>;
58
+ interface MiddlewareNextFn<TOutput> {
59
+ <U extends Context = {}>(options?: {
60
+ context?: U;
61
+ }): MiddlewareResult<U, TOutput>;
62
+ }
63
+ interface MiddlewareOutputFn<TOutput> {
64
+ (output: TOutput): MiddlewareResult<Record<never, never>, TOutput>;
65
+ }
66
+ interface MiddlewareOptions<TInContext extends Context, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> extends ProcedureHandlerOptions<TInContext, TErrorConstructorMap, TMeta> {
67
+ next: MiddlewareNextFn<TOutput>;
68
+ }
69
+ /**
70
+ * A function that represents a middleware.
71
+ *
72
+ * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
73
+ */
74
+ interface Middleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
75
+ (options: MiddlewareOptions<TInContext, TOutput, TErrorConstructorMap, TMeta>, input: TInput, output: MiddlewareOutputFn<TOutput>): Promisable<MiddlewareResult<TOutContext, TOutput>>;
76
+ }
77
+ type AnyMiddleware = Middleware<any, any, any, any, any, any>;
78
+ interface MapInputMiddleware<TInput, TMappedInput> {
79
+ (input: TInput): TMappedInput;
80
+ }
81
+ declare function middlewareOutputFn<TOutput>(output: TOutput): MiddlewareResult<Record<never, never>, TOutput>;
82
+
83
+ /**
84
+ * Represents a router, which defines a hierarchical structure of procedures.
85
+ *
86
+ * @info A procedure is a router too.
87
+ * @see {@link https://orpc.unnoq.com/docs/contract-first/define-contract#contract-router Contract Router Docs}
88
+ */
89
+ type Router<T extends AnyContractRouter, TInitialContext extends Context> = T extends ContractProcedure<infer USchemas, infer UErrorMap, infer UMeta> ? Procedure<TInitialContext, any, USchemas, UErrorMap, UMeta> : {
90
+ [K in keyof T]: T[K] extends AnyContractRouter ? Lazyable<Router<T[K], TInitialContext>> : never;
91
+ };
92
+ type AnyRouter = Router<any, any>;
93
+ type InferRouterInitialContext<T extends AnyRouter> = T extends Router<any, infer UInitialContext> ? UInitialContext : never;
94
+ /**
95
+ * Infer all initial context of the router.
96
+ *
97
+ * @info A procedure is a router too.
98
+ * @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
99
+ */
100
+ type InferRouterInitialContexts<T extends AnyRouter> = T extends Procedure<infer UInitialContext, any, any, any, any> ? UInitialContext : {
101
+ [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInitialContexts<U> : never;
102
+ };
103
+ /**
104
+ * Infer all current context of the router.
105
+ *
106
+ * @info A procedure is a router too.
107
+ * @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
108
+ */
109
+ type InferRouterCurrentContexts<T extends AnyRouter> = T extends Procedure<any, infer UCurrentContext, any, any, any> ? UCurrentContext : {
110
+ [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterCurrentContexts<U> : never;
111
+ };
112
+ /**
113
+ * Infer all router inputs
114
+ *
115
+ * @info A procedure is a router too.
116
+ * @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
117
+ */
118
+ type InferRouterInputs<T extends AnyRouter> = T extends Procedure<any, any, infer USchemas, any, any> ? InferProcedureClientInputs<USchemas> : {
119
+ [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInputs<U> : never;
120
+ };
121
+ /**
122
+ * Infer all router outputs
123
+ *
124
+ * @info A procedure is a router too.
125
+ * @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
126
+ */
127
+ type InferRouterOutputs<T extends AnyRouter> = T extends Procedure<any, any, infer USchemas, any, any> ? InferSchemaOutput<USchemas['outputSchema']> : {
128
+ [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterOutputs<U> : never;
129
+ };
130
+
131
+ declare function getRouter<T extends Lazyable<AnyRouter | undefined>>(router: T, path: readonly string[]): T extends Lazy<any> ? Lazy<AnyRouter | undefined> : Lazyable<AnyRouter | undefined>;
132
+ type AccessibleLazyRouter<T extends Lazyable<AnyRouter | undefined>> = T extends Lazy<infer U extends AnyRouter | undefined | Lazy<AnyRouter | undefined>> ? AccessibleLazyRouter<U> : T extends AnyProcedure | undefined ? Lazy<T> : Lazy<T> & {
133
+ [K in keyof T]: T[K] extends Lazyable<AnyRouter> ? AccessibleLazyRouter<T[K]> : never;
134
+ };
135
+ declare function createAccessibleLazyRouter<T extends Lazy<AnyRouter | undefined>>(lazied: T): AccessibleLazyRouter<T>;
136
+ type EnhancedRouter<T extends Lazyable<AnyRouter>, TInitialContext extends Context, TCurrentContext extends Context, TErrorMap extends ErrorMap> = T extends Lazy<infer U extends AnyRouter> ? AccessibleLazyRouter<EnhancedRouter<U, TInitialContext, TCurrentContext, TErrorMap>> : T extends (Procedure<infer UInitialContext, infer UCurrentContext, infer USchemas, infer UErrorMap, infer UMeta>) ? Procedure<MergedInitialContext<TInitialContext, UInitialContext, TCurrentContext>, UCurrentContext, USchemas, MergedErrorMap<TErrorMap, UErrorMap>, UMeta> : {
137
+ [K in keyof T]: T[K] extends Lazyable<AnyRouter> ? EnhancedRouter<T[K], TInitialContext, TCurrentContext, TErrorMap> : never;
138
+ };
139
+ interface EnhanceRouterOptions<TErrorMap extends ErrorMap> extends EnhanceRouteOptions {
140
+ middlewares: readonly AnyMiddleware[];
141
+ errorMap: TErrorMap;
142
+ dedupeLeadingMiddlewares: boolean;
143
+ }
144
+ declare function enhanceRouter<T extends Lazyable<AnyRouter>, TInitialContext extends Context, TCurrentContext extends Context, TErrorMap extends ErrorMap>(router: T, options: EnhanceRouterOptions<TErrorMap>): EnhancedRouter<T, TInitialContext, TCurrentContext, TErrorMap>;
145
+ interface TraverseContractProceduresOptions {
146
+ router: AnyContractRouter | AnyRouter;
147
+ path: readonly string[];
148
+ }
149
+ interface TraverseContractProcedureCallbackOptions {
150
+ contract: AnyContractProcedure | AnyProcedure;
151
+ path: readonly string[];
152
+ }
153
+ /**
154
+ * @deprecated Use `TraverseContractProcedureCallbackOptions` instead.
155
+ */
156
+ type ContractProcedureCallbackOptions = TraverseContractProcedureCallbackOptions;
157
+ interface LazyTraverseContractProceduresOptions {
158
+ router: Lazy<AnyRouter>;
159
+ path: readonly string[];
160
+ }
161
+ declare function traverseContractProcedures(options: TraverseContractProceduresOptions, callback: (options: TraverseContractProcedureCallbackOptions) => void, lazyOptions?: LazyTraverseContractProceduresOptions[]): LazyTraverseContractProceduresOptions[];
162
+ declare function resolveContractProcedures(options: TraverseContractProceduresOptions, callback: (options: TraverseContractProcedureCallbackOptions) => void): Promise<void>;
163
+ type UnlaziedRouter<T extends AnyRouter> = T extends AnyProcedure ? T : {
164
+ [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? UnlaziedRouter<U> : never;
165
+ };
166
+ declare function unlazyRouter<T extends AnyRouter>(router: T): Promise<UnlaziedRouter<T>>;
167
+
168
+ declare const LAZY_SYMBOL: unique symbol;
169
+ interface LazyMeta {
170
+ prefix?: HTTPPath;
171
+ }
172
+ interface Lazy<T> {
173
+ [LAZY_SYMBOL]: {
174
+ loader: () => Promise<{
175
+ default: T;
176
+ }>;
177
+ meta: LazyMeta;
178
+ };
179
+ }
180
+ type Lazyable<T> = T | Lazy<T>;
181
+ /**
182
+ * @internal
183
+ */
184
+ declare function lazyInternal<T>(loader: () => Promise<{
185
+ default: T;
186
+ }>, meta?: LazyMeta): Lazy<T>;
187
+ /**
188
+ * Creates a lazy-loaded item.
189
+ *
190
+ * @warning The `prefix` in `meta` only holds metadata and does not apply the prefix to the lazy router, use `os.prefix(...).lazyRoute(...)` instead.
191
+ */
192
+ declare function lazy<T extends Router<ContractRouter<{}>, any>>(prefix: HTTPPath, loader: () => Promise<{
193
+ default: T;
194
+ }>): EnhancedRouter<Lazy<T>, {}, {}, {}>;
195
+ declare function isLazy(item: unknown): item is Lazy<any>;
196
+ declare function getLazyMeta(lazied: Lazy<any>): LazyMeta;
197
+ declare function unlazy<T extends Lazyable<any>>(lazied: T): Promise<{
198
+ default: T extends Lazy<infer U> ? U : T;
199
+ }>;
200
+
201
+ type ProcedureClient<TClientContext extends ClientContext, TSchemas extends Schemas, TErrorMap extends ErrorMap> = Client<TClientContext, InferProcedureClientInputs<TSchemas>, InferSchemaOutput<TSchemas['outputSchema']>, ErrorFromErrorMap<TErrorMap>>;
202
+ interface ProcedureClientInterceptorOptions<TInitialContext extends Context, TErrorMap extends ErrorMap, TMeta extends Meta> extends ProcedureHandlerOptions<TInitialContext, ORPCErrorConstructorMap<TErrorMap>, TMeta> {
203
+ input: {
204
+ path: unknown;
205
+ query: unknown;
206
+ body: unknown;
207
+ };
208
+ }
209
+ type CreateProcedureClientOptions<TInitialContext extends Context, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext> = {
210
+ /**
211
+ * This is helpful for logging and analytics.
212
+ */
213
+ path?: readonly string[];
214
+ interceptors?: Interceptor<ProcedureClientInterceptorOptions<TInitialContext, TErrorMap, TMeta>, PromiseWithError<InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>>[];
215
+ } & (Record<never, never> extends TInitialContext ? {
216
+ context?: Value<Promisable<TInitialContext>, [clientContext: TClientContext]>;
217
+ } : {
218
+ context: Value<Promisable<TInitialContext>, [clientContext: TClientContext]>;
219
+ });
220
+ /**
221
+ * Create Server-side client from a procedure.
222
+ *
223
+ * @see {@link https://orpc.unnoq.com/docs/client/server-side Server-side Client Docs}
224
+ */
225
+ declare function createProcedureClient<TInitialContext extends Context, TSchemas extends Schemas, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext>(lazyableProcedure: Lazyable<Procedure<TInitialContext, any, TSchemas, TErrorMap, TMeta>>, ...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TSchemas['outputSchema'], TErrorMap, TMeta, TClientContext>>): ProcedureClient<TClientContext, TSchemas, TErrorMap>;
226
+
227
+ export { resolveContractProcedures as $, isProcedure as F, createProcedureClient as H, Procedure as P, getRouter as S, createAccessibleLazyRouter as U, enhanceRouter as V, traverseContractProcedures as _, unlazyRouter as a1, mergeCurrentContext as m, createORPCErrorConstructorMap as n, LAZY_SYMBOL as o, lazyInternal as q, lazy as r, isLazy as s, getLazyMeta as t, unlazy as u, middlewareOutputFn as z };
228
+ export type { AnyMiddleware as A, ProcedureHandlerOptions as B, Context as C, ProcedureDef as D, EnhanceRouterOptions as E, ProcedureClientInterceptorOptions as G, InferRouterInitialContext as I, InferRouterInitialContexts as J, InferRouterCurrentContexts as K, Lazy as L, Middleware as M, InferRouterInputs as N, ORPCErrorConstructorMap as O, InferRouterOutputs as Q, Router as R, AccessibleLazyRouter as T, TraverseContractProceduresOptions as W, TraverseContractProcedureCallbackOptions as X, ContractProcedureCallbackOptions as Y, LazyTraverseContractProceduresOptions as Z, CreateProcedureClientOptions as a, UnlaziedRouter as a0, ProcedureClient as b, MergedInitialContext as c, MergedCurrentContext as d, ProcedureHandler as e, EnhancedRouter as f, MapInputMiddleware as g, AnyProcedure as h, Lazyable as i, AnyRouter as j, ORPCErrorConstructorMapItemOptions as k, ORPCErrorConstructorMapItem as l, LazyMeta as p, MiddlewareResult as v, MiddlewareNextFn as w, MiddlewareOutputFn as x, MiddlewareOptions as y };
@@ -1,67 +1,37 @@
1
- import { isObject, stringifyJSON, isORPCErrorStatus, tryDecodeURIComponent, value, toHttpPath, toArray, intercept, runWithSpan, ORPC_NAME, isAsyncIteratorObject, asyncIteratorWithSpan, setSpanError, ORPCError, toORPCError } from '@temporary-name/shared';
1
+ import { stringifyJSON, isObject, isORPCErrorStatus, tryDecodeURIComponent, toHttpPath, toArray, intercept, runWithSpan, ORPC_NAME, isAsyncIteratorObject, asyncIteratorWithSpan, setSpanError, ORPCError, toORPCError } from '@temporary-name/shared';
2
2
  import { flattenHeader } from '@temporary-name/standard-server';
3
- import { c as createProcedureClient } from './server.BZtKt8i8.mjs';
4
- import { fallbackContractConfig } from '@temporary-name/contract';
5
- import { d as deserialize, s as serialize, a as standardizeHTTPPath } from './server.BEHw7Eyx.mjs';
3
+ import { c as createProcedureClient } from './server.ClhVCxfg.mjs';
4
+ import { fallbackContractConfig, standardizeHTTPPath } from '@temporary-name/contract';
5
+ import { d as deserialize, b as bracketNotationDeserialize, s as serialize } from './server.JtIZ8YG7.mjs';
6
6
  import { traverseContractProcedures, isProcedure, getLazyMeta, unlazy, getRouter, createContractedProcedure } from '@temporary-name/server';
7
7
  import { createRouter, addRoute, findRoute } from 'rou3';
8
8
 
9
- class StandardOpenAPICodec {
10
- constructor() {
11
- }
12
- async decode(request, params, procedure) {
13
- const inputStructure = fallbackContractConfig(
14
- "defaultInputStructure",
15
- procedure["~orpc"].route.inputStructure
16
- );
17
- if (inputStructure === "compact") {
18
- const data = request.method === "GET" ? deserialize(request.url.searchParams) : deserialize(await request.body());
19
- if (data === void 0) {
20
- return params;
21
- }
22
- if (isObject(data)) {
23
- return {
24
- ...params,
25
- ...data
26
- };
27
- }
28
- return data;
29
- }
30
- const deserializeSearchParams = () => {
31
- return deserialize(request.url.searchParams);
32
- };
9
+ async function decode(request, pathParams) {
10
+ return {
11
+ path: pathParams ?? {},
12
+ query: bracketNotationDeserialize(Array.from(request.url.searchParams.entries())),
13
+ headers: request.headers,
14
+ body: deserialize(await request.body()) ?? {}
15
+ };
16
+ }
17
+ function encode(output, procedure) {
18
+ const successStatus = fallbackContractConfig(
19
+ "defaultSuccessStatus",
20
+ procedure["~orpc"].route.successStatus
21
+ );
22
+ const outputStructure = fallbackContractConfig(
23
+ "defaultOutputStructure",
24
+ procedure["~orpc"].route.outputStructure
25
+ );
26
+ if (outputStructure === "compact") {
33
27
  return {
34
- params,
35
- get query() {
36
- const value = deserializeSearchParams();
37
- Object.defineProperty(this, "query", { value, writable: true });
38
- return value;
39
- },
40
- set query(value) {
41
- Object.defineProperty(this, "query", { value, writable: true });
42
- },
43
- headers: request.headers,
44
- body: deserialize(await request.body())
28
+ status: successStatus,
29
+ headers: {},
30
+ body: serialize(output)
45
31
  };
46
32
  }
47
- encode(output, procedure) {
48
- const successStatus = fallbackContractConfig(
49
- "defaultSuccessStatus",
50
- procedure["~orpc"].route.successStatus
51
- );
52
- const outputStructure = fallbackContractConfig(
53
- "defaultOutputStructure",
54
- procedure["~orpc"].route.outputStructure
55
- );
56
- if (outputStructure === "compact") {
57
- return {
58
- status: successStatus,
59
- headers: {},
60
- body: serialize(output)
61
- };
62
- }
63
- if (!this.#isDetailedOutput(output)) {
64
- throw new Error(`
33
+ if (!isDetailedOutput(output)) {
34
+ throw new Error(`
65
35
  Invalid "detailed" output structure:
66
36
  \u2022 Expected an object with optional properties:
67
37
  - status (number 200-399)
@@ -72,32 +42,31 @@ class StandardOpenAPICodec {
72
42
  Actual value:
73
43
  ${stringifyJSON(output)}
74
44
  `);
75
- }
76
- return {
77
- status: output.status ?? successStatus,
78
- headers: output.headers ?? {},
79
- body: serialize(output.body)
80
- };
81
45
  }
82
- encodeError(error) {
83
- return {
84
- status: error.status,
85
- headers: {},
86
- body: serialize(error.toJSON(), { outputFormat: "plain" })
87
- };
46
+ return {
47
+ status: output.status ?? successStatus,
48
+ headers: output.headers ?? {},
49
+ body: serialize(output.body)
50
+ };
51
+ }
52
+ function encodeError(error) {
53
+ return {
54
+ status: error.status,
55
+ headers: {},
56
+ body: serialize(error.toJSON(), { outputFormat: "plain" })
57
+ };
58
+ }
59
+ function isDetailedOutput(output) {
60
+ if (!isObject(output)) {
61
+ return false;
88
62
  }
89
- #isDetailedOutput(output) {
90
- if (!isObject(output)) {
91
- return false;
92
- }
93
- if (output.headers && !isObject(output.headers)) {
94
- return false;
95
- }
96
- if (output.status !== void 0 && (typeof output.status !== "number" || !Number.isInteger(output.status) || isORPCErrorStatus(output.status))) {
97
- return false;
98
- }
99
- return true;
63
+ if (output.headers && !isObject(output.headers)) {
64
+ return false;
65
+ }
66
+ if (output.status !== void 0 && (typeof output.status !== "number" || !Number.isInteger(output.status) || isORPCErrorStatus(output.status))) {
67
+ return false;
100
68
  }
69
+ return true;
101
70
  }
102
71
 
103
72
  function resolveFriendlyStandardHandleOptions(options) {
@@ -121,9 +90,6 @@ class StandardOpenAPIMatcher {
121
90
  pendingRouters = [];
122
91
  init(router, path = []) {
123
92
  const laziedOptions = traverseContractProcedures({ router, path }, (traverseOptions) => {
124
- if (!value(true, traverseOptions)) {
125
- return;
126
- }
127
93
  const { path: path2, contract } = traverseOptions;
128
94
  const method = fallbackContractConfig("defaultMethod", contract["~orpc"].route.method);
129
95
  const httpPath = toRou3Pattern(contract["~orpc"].route.path ?? toHttpPath(path2));
@@ -204,10 +170,8 @@ class StandardHandler {
204
170
  clientInterceptors;
205
171
  rootInterceptors;
206
172
  matcher;
207
- codec;
208
173
  constructor(router, options) {
209
174
  this.matcher = new StandardOpenAPIMatcher();
210
- this.codec = new StandardOpenAPICodec();
211
175
  const plugins = new CompositeStandardHandlerPlugin(options.plugins);
212
176
  plugins.init(options, router);
213
177
  this.interceptors = toArray(options.interceptors);
@@ -242,15 +206,12 @@ class StandardHandler {
242
206
  span?.setAttribute("rpc.system", ORPC_NAME);
243
207
  span?.setAttribute("rpc.method", match.path.join("."));
244
208
  step = "decode_input";
245
- let input = await runWithSpan(
246
- { name: "decode_input" },
247
- () => this.codec.decode(request2, match.params, match.procedure)
248
- );
209
+ const input = await runWithSpan({ name: "decode_input" }, () => decode(request2, match.params));
249
210
  step = void 0;
250
- if (isAsyncIteratorObject(input)) {
251
- input = asyncIteratorWithSpan(
211
+ if (isAsyncIteratorObject(input.body)) {
212
+ input.body = asyncIteratorWithSpan(
252
213
  { name: "consume_event_iterator_input", signal: request2.signal },
253
- input
214
+ input.body
254
215
  );
255
216
  }
256
217
  const client = createProcedureClient(match.procedure, {
@@ -260,11 +221,12 @@ class StandardHandler {
260
221
  });
261
222
  step = "call_procedure";
262
223
  const output = await client(input, {
224
+ request: request2,
263
225
  signal: request2.signal,
264
226
  lastEventId: flattenHeader(request2.headers["last-event-id"])
265
227
  });
266
228
  step = void 0;
267
- const response = this.codec.encode(output, match.procedure);
229
+ const response = encode(output, match.procedure);
268
230
  return {
269
231
  matched: true,
270
232
  response
@@ -279,7 +241,7 @@ class StandardHandler {
279
241
  message: `Malformed request. Ensure the request body is properly formatted and the 'Content-Type' header is set correctly.`,
280
242
  cause: e
281
243
  }) : toORPCError(e);
282
- const response = this.codec.encodeError(error);
244
+ const response = encodeError(error);
283
245
  return {
284
246
  matched: true,
285
247
  response
@@ -290,4 +252,4 @@ class StandardHandler {
290
252
  }
291
253
  }
292
254
 
293
- export { CompositeStandardHandlerPlugin as C, StandardHandler as S, StandardOpenAPICodec as a, StandardOpenAPIMatcher as b, decodeParams as d, resolveFriendlyStandardHandleOptions as r, toRou3Pattern as t };
255
+ export { CompositeStandardHandlerPlugin as C, StandardHandler as S, encodeError as a, StandardOpenAPIMatcher as b, decodeParams as c, decode as d, encode as e, resolveFriendlyStandardHandleOptions as r, toRou3Pattern as t };