@orpc/server 0.0.0-next.8900489 → 0.0.0-next.890a8ab
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +28 -23
- package/dist/adapters/aws-lambda/index.d.mts +46 -0
- package/dist/adapters/aws-lambda/index.d.ts +46 -0
- package/dist/adapters/aws-lambda/index.mjs +42 -0
- package/dist/adapters/bun-ws/index.d.mts +36 -0
- package/dist/adapters/bun-ws/index.d.ts +36 -0
- package/dist/adapters/bun-ws/index.mjs +47 -0
- package/dist/adapters/crossws/index.d.mts +33 -0
- package/dist/adapters/crossws/index.d.ts +33 -0
- package/dist/adapters/crossws/index.mjs +45 -0
- package/dist/adapters/fetch/index.d.mts +62 -11
- package/dist/adapters/fetch/index.d.ts +62 -11
- package/dist/adapters/fetch/index.mjs +109 -8
- package/dist/adapters/message-port/index.d.mts +31 -0
- package/dist/adapters/message-port/index.d.ts +31 -0
- package/dist/adapters/message-port/index.mjs +39 -0
- package/dist/adapters/node/index.d.mts +64 -22
- package/dist/adapters/node/index.d.ts +64 -22
- package/dist/adapters/node/index.mjs +88 -24
- package/dist/adapters/standard/index.d.mts +8 -13
- package/dist/adapters/standard/index.d.ts +8 -13
- package/dist/adapters/standard/index.mjs +5 -3
- package/dist/adapters/standard-peer/index.d.mts +18 -0
- package/dist/adapters/standard-peer/index.d.ts +18 -0
- package/dist/adapters/standard-peer/index.mjs +7 -0
- package/dist/adapters/websocket/index.d.mts +54 -0
- package/dist/adapters/websocket/index.d.ts +54 -0
- package/dist/adapters/websocket/index.mjs +67 -0
- package/dist/adapters/ws/index.d.mts +31 -0
- package/dist/adapters/ws/index.d.ts +31 -0
- package/dist/adapters/ws/index.mjs +37 -0
- package/dist/helpers/index.d.mts +134 -0
- package/dist/helpers/index.d.ts +134 -0
- package/dist/helpers/index.mjs +188 -0
- package/dist/hibernation/index.d.mts +44 -0
- package/dist/hibernation/index.d.ts +44 -0
- package/dist/hibernation/index.mjs +65 -0
- package/dist/index.d.mts +609 -84
- package/dist/index.d.ts +609 -84
- package/dist/index.mjs +162 -15
- package/dist/plugins/index.d.mts +154 -16
- package/dist/plugins/index.d.ts +154 -16
- package/dist/plugins/index.mjs +198 -16
- package/dist/shared/server.B7b2w3_i.d.ts +12 -0
- package/dist/shared/server.BEFBl-Cb.d.mts +12 -0
- package/dist/shared/server.BU4WI18A.d.mts +32 -0
- package/dist/shared/server.BW-nUGgA.mjs +36 -0
- package/dist/shared/server.Bmh5xd4n.d.ts +74 -0
- package/dist/shared/server.BohymmQ6.mjs +219 -0
- package/dist/shared/{server.BtxZnWJ9.mjs → server.CQr6WNc2.mjs} +103 -69
- package/dist/shared/{server.BYTulgUc.d.mts → server.CYNGeoCm.d.mts} +66 -16
- package/dist/shared/{server.BYTulgUc.d.ts → server.CYNGeoCm.d.ts} +66 -16
- package/dist/shared/server.D0H-iaY3.d.ts +32 -0
- package/dist/shared/server.DZ5BIITo.mjs +9 -0
- package/dist/shared/server.DhJj-1X9.d.mts +42 -0
- package/dist/shared/server.UVMTOWrk.mjs +26 -0
- package/dist/shared/server.gqRxT-yN.d.mts +74 -0
- package/dist/shared/server.jMTkVNIb.d.ts +42 -0
- package/package.json +70 -20
- package/dist/adapters/hono/index.d.mts +0 -21
- package/dist/adapters/hono/index.d.ts +0 -21
- package/dist/adapters/hono/index.mjs +0 -32
- package/dist/adapters/next/index.d.mts +0 -28
- package/dist/adapters/next/index.d.ts +0 -28
- package/dist/adapters/next/index.mjs +0 -29
- package/dist/shared/server.B3Tm0IXY.d.ts +0 -75
- package/dist/shared/server.BeJithK4.d.mts +0 -75
- package/dist/shared/server.Bz_xNBjz.d.mts +0 -8
- package/dist/shared/server.DoP20NVH.mjs +0 -29
- package/dist/shared/server.EhgR_5_I.d.ts +0 -8
- package/dist/shared/server.Q6ZmnTgO.mjs +0 -12
- package/dist/shared/server.jG7ZuX3S.mjs +0 -158
@@ -1,28 +0,0 @@
|
|
1
|
-
import { FetchHandler } from '../fetch/index.js';
|
2
|
-
export { FetchHandleResult, RPCHandler } from '../fetch/index.js';
|
3
|
-
import { Value, MaybeOptionalOptions } from '@orpc/shared';
|
4
|
-
import { NextRequest } from 'next/server';
|
5
|
-
import { C as Context } from '../../shared/server.BYTulgUc.js';
|
6
|
-
import { S as StandardHandleOptions } from '../../shared/server.B3Tm0IXY.js';
|
7
|
-
import '@orpc/standard-server-fetch';
|
8
|
-
import '../../shared/server.EhgR_5_I.js';
|
9
|
-
import '@orpc/client/standard';
|
10
|
-
import '@orpc/client';
|
11
|
-
import '@orpc/contract';
|
12
|
-
import '@orpc/standard-server';
|
13
|
-
|
14
|
-
type ServeOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
|
15
|
-
context?: Value<T, [NextRequest]>;
|
16
|
-
} : {
|
17
|
-
context: Value<T, [NextRequest]>;
|
18
|
-
});
|
19
|
-
interface ServeResult {
|
20
|
-
GET(req: NextRequest): Promise<Response>;
|
21
|
-
POST(req: NextRequest): Promise<Response>;
|
22
|
-
PUT(req: NextRequest): Promise<Response>;
|
23
|
-
PATCH(req: NextRequest): Promise<Response>;
|
24
|
-
DELETE(req: NextRequest): Promise<Response>;
|
25
|
-
}
|
26
|
-
declare function serve<T extends Context>(handler: FetchHandler<T>, ...[options]: MaybeOptionalOptions<ServeOptions<T>>): ServeResult;
|
27
|
-
|
28
|
-
export { FetchHandler, type ServeOptions, type ServeResult, serve };
|
@@ -1,29 +0,0 @@
|
|
1
|
-
export { R as RPCHandler } from '../../shared/server.DoP20NVH.mjs';
|
2
|
-
import { value } from '@orpc/shared';
|
3
|
-
import '@orpc/client/standard';
|
4
|
-
import '@orpc/standard-server-fetch';
|
5
|
-
import '../../shared/server.jG7ZuX3S.mjs';
|
6
|
-
import '@orpc/client';
|
7
|
-
import '../../shared/server.Q6ZmnTgO.mjs';
|
8
|
-
import '../../shared/server.BtxZnWJ9.mjs';
|
9
|
-
import '@orpc/contract';
|
10
|
-
|
11
|
-
function serve(handler, ...[options]) {
|
12
|
-
const main = async (req) => {
|
13
|
-
const context = await value(options?.context ?? {}, req);
|
14
|
-
const { matched, response } = await handler.handle(req, { ...options, context });
|
15
|
-
if (matched) {
|
16
|
-
return response;
|
17
|
-
}
|
18
|
-
return new Response(`Cannot find a matching procedure for ${req.url}`, { status: 404 });
|
19
|
-
};
|
20
|
-
return {
|
21
|
-
GET: main,
|
22
|
-
POST: main,
|
23
|
-
PUT: main,
|
24
|
-
PATCH: main,
|
25
|
-
DELETE: main
|
26
|
-
};
|
27
|
-
}
|
28
|
-
|
29
|
-
export { serve };
|
@@ -1,75 +0,0 @@
|
|
1
|
-
import { HTTPPath, AnySchema, Meta, InferSchemaOutput, ErrorFromErrorMap } from '@orpc/contract';
|
2
|
-
import { Interceptor, MaybeOptionalOptions } from '@orpc/shared';
|
3
|
-
import { StandardResponse, StandardLazyRequest } from '@orpc/standard-server';
|
4
|
-
import { a as AnyRouter, A as AnyProcedure, C as Context, P as ProcedureClientInterceptorOptions, R as Router } from './server.BYTulgUc.js';
|
5
|
-
import { ORPCError } from '@orpc/client';
|
6
|
-
|
7
|
-
type StandardParams = Record<string, string>;
|
8
|
-
type StandardMatchResult = {
|
9
|
-
path: readonly string[];
|
10
|
-
procedure: AnyProcedure;
|
11
|
-
params?: StandardParams;
|
12
|
-
} | undefined;
|
13
|
-
interface StandardMatcher {
|
14
|
-
init(router: AnyRouter): void;
|
15
|
-
match(method: string, pathname: HTTPPath): Promise<StandardMatchResult>;
|
16
|
-
}
|
17
|
-
interface StandardCodec {
|
18
|
-
encode(output: unknown, procedure: AnyProcedure): StandardResponse;
|
19
|
-
encodeError(error: ORPCError<any, any>): StandardResponse;
|
20
|
-
decode(request: StandardLazyRequest, params: StandardParams | undefined, procedure: AnyProcedure): Promise<unknown>;
|
21
|
-
}
|
22
|
-
|
23
|
-
type StandardHandleOptions<T extends Context> = {
|
24
|
-
prefix?: HTTPPath;
|
25
|
-
} & (Record<never, never> extends T ? {
|
26
|
-
context?: T;
|
27
|
-
} : {
|
28
|
-
context: T;
|
29
|
-
});
|
30
|
-
type StandardHandleResult = {
|
31
|
-
matched: true;
|
32
|
-
response: StandardResponse;
|
33
|
-
} | {
|
34
|
-
matched: false;
|
35
|
-
response: undefined;
|
36
|
-
};
|
37
|
-
type StandardHandlerInterceptorOptions<T extends Context> = StandardHandleOptions<T> & {
|
38
|
-
context: T;
|
39
|
-
request: StandardLazyRequest;
|
40
|
-
};
|
41
|
-
interface StandardHandlerOptions<TContext extends Context> {
|
42
|
-
plugins?: HandlerPlugin<TContext>[];
|
43
|
-
/**
|
44
|
-
* Interceptors at the request level, helpful when you want catch errors
|
45
|
-
*/
|
46
|
-
interceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, unknown>[];
|
47
|
-
/**
|
48
|
-
* Interceptors at the root level, helpful when you want override the request/response
|
49
|
-
*/
|
50
|
-
rootInterceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, unknown>[];
|
51
|
-
/**
|
52
|
-
*
|
53
|
-
* Interceptors for procedure client.
|
54
|
-
*/
|
55
|
-
clientInterceptors?: Interceptor<ProcedureClientInterceptorOptions<TContext, AnySchema, Record<never, never>, Meta>, InferSchemaOutput<AnySchema>, ErrorFromErrorMap<Record<never, never>>>[];
|
56
|
-
}
|
57
|
-
declare class StandardHandler<T extends Context> {
|
58
|
-
private readonly matcher;
|
59
|
-
private readonly codec;
|
60
|
-
private readonly options;
|
61
|
-
private readonly plugin;
|
62
|
-
constructor(router: Router<any, T>, matcher: StandardMatcher, codec: StandardCodec, options: NoInfer<StandardHandlerOptions<T>>);
|
63
|
-
handle(request: StandardLazyRequest, ...[options]: MaybeOptionalOptions<StandardHandleOptions<T>>): Promise<StandardHandleResult>;
|
64
|
-
}
|
65
|
-
|
66
|
-
interface HandlerPlugin<TContext extends Context> {
|
67
|
-
init?(options: StandardHandlerOptions<TContext>): void;
|
68
|
-
}
|
69
|
-
declare class CompositePlugin<TContext extends Context> implements HandlerPlugin<TContext> {
|
70
|
-
private readonly plugins;
|
71
|
-
constructor(plugins?: HandlerPlugin<TContext>[]);
|
72
|
-
init(options: StandardHandlerOptions<TContext>): void;
|
73
|
-
}
|
74
|
-
|
75
|
-
export { CompositePlugin as C, type HandlerPlugin as H, type StandardHandleOptions as S, type StandardHandlerOptions as a, type StandardHandlerInterceptorOptions as b, type StandardCodec as c, type StandardParams as d, type StandardMatcher as e, type StandardMatchResult as f, type StandardHandleResult as g, StandardHandler as h };
|
@@ -1,75 +0,0 @@
|
|
1
|
-
import { HTTPPath, AnySchema, Meta, InferSchemaOutput, ErrorFromErrorMap } from '@orpc/contract';
|
2
|
-
import { Interceptor, MaybeOptionalOptions } from '@orpc/shared';
|
3
|
-
import { StandardResponse, StandardLazyRequest } from '@orpc/standard-server';
|
4
|
-
import { a as AnyRouter, A as AnyProcedure, C as Context, P as ProcedureClientInterceptorOptions, R as Router } from './server.BYTulgUc.mjs';
|
5
|
-
import { ORPCError } from '@orpc/client';
|
6
|
-
|
7
|
-
type StandardParams = Record<string, string>;
|
8
|
-
type StandardMatchResult = {
|
9
|
-
path: readonly string[];
|
10
|
-
procedure: AnyProcedure;
|
11
|
-
params?: StandardParams;
|
12
|
-
} | undefined;
|
13
|
-
interface StandardMatcher {
|
14
|
-
init(router: AnyRouter): void;
|
15
|
-
match(method: string, pathname: HTTPPath): Promise<StandardMatchResult>;
|
16
|
-
}
|
17
|
-
interface StandardCodec {
|
18
|
-
encode(output: unknown, procedure: AnyProcedure): StandardResponse;
|
19
|
-
encodeError(error: ORPCError<any, any>): StandardResponse;
|
20
|
-
decode(request: StandardLazyRequest, params: StandardParams | undefined, procedure: AnyProcedure): Promise<unknown>;
|
21
|
-
}
|
22
|
-
|
23
|
-
type StandardHandleOptions<T extends Context> = {
|
24
|
-
prefix?: HTTPPath;
|
25
|
-
} & (Record<never, never> extends T ? {
|
26
|
-
context?: T;
|
27
|
-
} : {
|
28
|
-
context: T;
|
29
|
-
});
|
30
|
-
type StandardHandleResult = {
|
31
|
-
matched: true;
|
32
|
-
response: StandardResponse;
|
33
|
-
} | {
|
34
|
-
matched: false;
|
35
|
-
response: undefined;
|
36
|
-
};
|
37
|
-
type StandardHandlerInterceptorOptions<T extends Context> = StandardHandleOptions<T> & {
|
38
|
-
context: T;
|
39
|
-
request: StandardLazyRequest;
|
40
|
-
};
|
41
|
-
interface StandardHandlerOptions<TContext extends Context> {
|
42
|
-
plugins?: HandlerPlugin<TContext>[];
|
43
|
-
/**
|
44
|
-
* Interceptors at the request level, helpful when you want catch errors
|
45
|
-
*/
|
46
|
-
interceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, unknown>[];
|
47
|
-
/**
|
48
|
-
* Interceptors at the root level, helpful when you want override the request/response
|
49
|
-
*/
|
50
|
-
rootInterceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, unknown>[];
|
51
|
-
/**
|
52
|
-
*
|
53
|
-
* Interceptors for procedure client.
|
54
|
-
*/
|
55
|
-
clientInterceptors?: Interceptor<ProcedureClientInterceptorOptions<TContext, AnySchema, Record<never, never>, Meta>, InferSchemaOutput<AnySchema>, ErrorFromErrorMap<Record<never, never>>>[];
|
56
|
-
}
|
57
|
-
declare class StandardHandler<T extends Context> {
|
58
|
-
private readonly matcher;
|
59
|
-
private readonly codec;
|
60
|
-
private readonly options;
|
61
|
-
private readonly plugin;
|
62
|
-
constructor(router: Router<any, T>, matcher: StandardMatcher, codec: StandardCodec, options: NoInfer<StandardHandlerOptions<T>>);
|
63
|
-
handle(request: StandardLazyRequest, ...[options]: MaybeOptionalOptions<StandardHandleOptions<T>>): Promise<StandardHandleResult>;
|
64
|
-
}
|
65
|
-
|
66
|
-
interface HandlerPlugin<TContext extends Context> {
|
67
|
-
init?(options: StandardHandlerOptions<TContext>): void;
|
68
|
-
}
|
69
|
-
declare class CompositePlugin<TContext extends Context> implements HandlerPlugin<TContext> {
|
70
|
-
private readonly plugins;
|
71
|
-
constructor(plugins?: HandlerPlugin<TContext>[]);
|
72
|
-
init(options: StandardHandlerOptions<TContext>): void;
|
73
|
-
}
|
74
|
-
|
75
|
-
export { CompositePlugin as C, type HandlerPlugin as H, type StandardHandleOptions as S, type StandardHandlerOptions as a, type StandardHandlerInterceptorOptions as b, type StandardCodec as c, type StandardParams as d, type StandardMatcher as e, type StandardMatchResult as f, type StandardHandleResult as g, StandardHandler as h };
|
@@ -1,8 +0,0 @@
|
|
1
|
-
import { StandardRPCJsonSerializerOptions } from '@orpc/client/standard';
|
2
|
-
import { C as Context } from './server.BYTulgUc.mjs';
|
3
|
-
import { a as StandardHandlerOptions } from './server.BeJithK4.mjs';
|
4
|
-
|
5
|
-
interface StandardRPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, StandardRPCJsonSerializerOptions {
|
6
|
-
}
|
7
|
-
|
8
|
-
export type { StandardRPCHandlerOptions as S };
|
@@ -1,29 +0,0 @@
|
|
1
|
-
import { StandardRPCJsonSerializer, StandardRPCSerializer } from '@orpc/client/standard';
|
2
|
-
import { toStandardLazyRequest, toFetchResponse } from '@orpc/standard-server-fetch';
|
3
|
-
import { S as StandardHandler, b as StandardRPCMatcher, a as StandardRPCCodec } from './server.jG7ZuX3S.mjs';
|
4
|
-
|
5
|
-
class RPCHandler {
|
6
|
-
standardHandler;
|
7
|
-
constructor(router, options = {}) {
|
8
|
-
const jsonSerializer = new StandardRPCJsonSerializer(options);
|
9
|
-
const serializer = new StandardRPCSerializer(jsonSerializer);
|
10
|
-
const matcher = new StandardRPCMatcher();
|
11
|
-
const codec = new StandardRPCCodec(serializer);
|
12
|
-
this.standardHandler = new StandardHandler(router, matcher, codec, options);
|
13
|
-
}
|
14
|
-
async handle(request, ...[
|
15
|
-
options = {}
|
16
|
-
]) {
|
17
|
-
const standardRequest = toStandardLazyRequest(request);
|
18
|
-
const result = await this.standardHandler.handle(standardRequest, options);
|
19
|
-
if (!result.matched) {
|
20
|
-
return result;
|
21
|
-
}
|
22
|
-
return {
|
23
|
-
matched: true,
|
24
|
-
response: toFetchResponse(result.response, options)
|
25
|
-
};
|
26
|
-
}
|
27
|
-
}
|
28
|
-
|
29
|
-
export { RPCHandler as R };
|
@@ -1,8 +0,0 @@
|
|
1
|
-
import { StandardRPCJsonSerializerOptions } from '@orpc/client/standard';
|
2
|
-
import { C as Context } from './server.BYTulgUc.js';
|
3
|
-
import { a as StandardHandlerOptions } from './server.B3Tm0IXY.js';
|
4
|
-
|
5
|
-
interface StandardRPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, StandardRPCJsonSerializerOptions {
|
6
|
-
}
|
7
|
-
|
8
|
-
export type { StandardRPCHandlerOptions as S };
|
@@ -1,158 +0,0 @@
|
|
1
|
-
import { ORPCError, toORPCError } from '@orpc/client';
|
2
|
-
import { intercept, trim, parseEmptyableJSON } from '@orpc/shared';
|
3
|
-
import { C as CompositePlugin } from './server.Q6ZmnTgO.mjs';
|
4
|
-
import { c as createProcedureClient, t as traverseContractProcedures, a as toHttpPath, i as isProcedure, u as unlazy, g as getRouter, b as createContractedProcedure } from './server.BtxZnWJ9.mjs';
|
5
|
-
|
6
|
-
class StandardHandler {
|
7
|
-
constructor(router, matcher, codec, options) {
|
8
|
-
this.matcher = matcher;
|
9
|
-
this.codec = codec;
|
10
|
-
this.options = options;
|
11
|
-
this.plugin = new CompositePlugin(options.plugins);
|
12
|
-
this.plugin.init(this.options);
|
13
|
-
this.matcher.init(router);
|
14
|
-
}
|
15
|
-
plugin;
|
16
|
-
handle(request, ...[options]) {
|
17
|
-
return intercept(
|
18
|
-
this.options.rootInterceptors ?? [],
|
19
|
-
{
|
20
|
-
request,
|
21
|
-
...options,
|
22
|
-
context: options?.context ?? {}
|
23
|
-
// context is optional only when all fields are optional so we can safely force it to have a context
|
24
|
-
},
|
25
|
-
async (interceptorOptions) => {
|
26
|
-
let isDecoding = false;
|
27
|
-
try {
|
28
|
-
return await intercept(
|
29
|
-
this.options.interceptors ?? [],
|
30
|
-
interceptorOptions,
|
31
|
-
async (interceptorOptions2) => {
|
32
|
-
const method = interceptorOptions2.request.method;
|
33
|
-
const url = interceptorOptions2.request.url;
|
34
|
-
const pathname = `/${trim(url.pathname.replace(interceptorOptions2.prefix ?? "", ""), "/")}`;
|
35
|
-
const match = await this.matcher.match(method, pathname);
|
36
|
-
if (!match) {
|
37
|
-
return { matched: false, response: void 0 };
|
38
|
-
}
|
39
|
-
const client = createProcedureClient(match.procedure, {
|
40
|
-
context: interceptorOptions2.context,
|
41
|
-
path: match.path,
|
42
|
-
interceptors: this.options.clientInterceptors
|
43
|
-
});
|
44
|
-
isDecoding = true;
|
45
|
-
const input = await this.codec.decode(request, match.params, match.procedure);
|
46
|
-
isDecoding = false;
|
47
|
-
const lastEventId = Array.isArray(request.headers["last-event-id"]) ? request.headers["last-event-id"].at(-1) : request.headers["last-event-id"];
|
48
|
-
const output = await client(input, { signal: request.signal, lastEventId });
|
49
|
-
const response = this.codec.encode(output, match.procedure);
|
50
|
-
return {
|
51
|
-
matched: true,
|
52
|
-
response
|
53
|
-
};
|
54
|
-
}
|
55
|
-
);
|
56
|
-
} catch (e) {
|
57
|
-
const error = isDecoding ? new ORPCError("BAD_REQUEST", {
|
58
|
-
message: `Malformed request. Ensure the request body is properly formatted and the 'Content-Type' header is set correctly.`,
|
59
|
-
cause: e
|
60
|
-
}) : toORPCError(e);
|
61
|
-
const response = this.codec.encodeError(error);
|
62
|
-
return {
|
63
|
-
matched: true,
|
64
|
-
response
|
65
|
-
};
|
66
|
-
}
|
67
|
-
}
|
68
|
-
);
|
69
|
-
}
|
70
|
-
}
|
71
|
-
|
72
|
-
class StandardRPCCodec {
|
73
|
-
constructor(serializer) {
|
74
|
-
this.serializer = serializer;
|
75
|
-
}
|
76
|
-
async decode(request, _params, _procedure) {
|
77
|
-
const serialized = request.method === "GET" ? parseEmptyableJSON(request.url.searchParams.getAll("data").at(-1)) : await request.body();
|
78
|
-
return this.serializer.deserialize(serialized);
|
79
|
-
}
|
80
|
-
encode(output, _procedure) {
|
81
|
-
return {
|
82
|
-
status: 200,
|
83
|
-
headers: {},
|
84
|
-
body: this.serializer.serialize(output)
|
85
|
-
};
|
86
|
-
}
|
87
|
-
encodeError(error) {
|
88
|
-
return {
|
89
|
-
status: error.status,
|
90
|
-
headers: {},
|
91
|
-
body: this.serializer.serialize(error.toJSON())
|
92
|
-
};
|
93
|
-
}
|
94
|
-
}
|
95
|
-
|
96
|
-
class StandardRPCMatcher {
|
97
|
-
tree = {};
|
98
|
-
pendingRouters = [];
|
99
|
-
init(router, path = []) {
|
100
|
-
const laziedOptions = traverseContractProcedures({ router, path }, ({ path: path2, contract }) => {
|
101
|
-
const httpPath = toHttpPath(path2);
|
102
|
-
if (isProcedure(contract)) {
|
103
|
-
this.tree[httpPath] = {
|
104
|
-
path: path2,
|
105
|
-
contract,
|
106
|
-
procedure: contract,
|
107
|
-
// this mean dev not used contract-first so we can used contract as procedure directly
|
108
|
-
router
|
109
|
-
};
|
110
|
-
} else {
|
111
|
-
this.tree[httpPath] = {
|
112
|
-
path: path2,
|
113
|
-
contract,
|
114
|
-
procedure: void 0,
|
115
|
-
router
|
116
|
-
};
|
117
|
-
}
|
118
|
-
});
|
119
|
-
this.pendingRouters.push(...laziedOptions.map((option) => ({
|
120
|
-
...option,
|
121
|
-
httpPathPrefix: toHttpPath(option.path)
|
122
|
-
})));
|
123
|
-
}
|
124
|
-
async match(_method, pathname) {
|
125
|
-
if (this.pendingRouters.length) {
|
126
|
-
const newPendingRouters = [];
|
127
|
-
for (const pendingRouter of this.pendingRouters) {
|
128
|
-
if (pathname.startsWith(pendingRouter.httpPathPrefix)) {
|
129
|
-
const { default: router } = await unlazy(pendingRouter.router);
|
130
|
-
this.init(router, pendingRouter.path);
|
131
|
-
} else {
|
132
|
-
newPendingRouters.push(pendingRouter);
|
133
|
-
}
|
134
|
-
}
|
135
|
-
this.pendingRouters = newPendingRouters;
|
136
|
-
}
|
137
|
-
const match = this.tree[pathname];
|
138
|
-
if (!match) {
|
139
|
-
return void 0;
|
140
|
-
}
|
141
|
-
if (!match.procedure) {
|
142
|
-
const { default: maybeProcedure } = await unlazy(getRouter(match.router, match.path));
|
143
|
-
if (!isProcedure(maybeProcedure)) {
|
144
|
-
throw new Error(`
|
145
|
-
[Contract-First] Missing or invalid implementation for procedure at path: ${toHttpPath(match.path)}.
|
146
|
-
Ensure that the procedure is correctly defined and matches the expected contract.
|
147
|
-
`);
|
148
|
-
}
|
149
|
-
match.procedure = createContractedProcedure(maybeProcedure, match.contract);
|
150
|
-
}
|
151
|
-
return {
|
152
|
-
path: match.path,
|
153
|
-
procedure: match.procedure
|
154
|
-
};
|
155
|
-
}
|
156
|
-
}
|
157
|
-
|
158
|
-
export { StandardHandler as S, StandardRPCCodec as a, StandardRPCMatcher as b };
|