@orpc/server 0.0.0-next.9ada823 → 0.0.0-next.9adcd05
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 +118 -0
- package/dist/adapters/fetch/index.d.mts +26 -0
- package/dist/adapters/fetch/index.d.ts +26 -0
- package/dist/adapters/fetch/index.mjs +9 -0
- package/dist/adapters/hono/index.d.mts +19 -0
- package/dist/adapters/hono/index.d.ts +19 -0
- package/dist/adapters/hono/index.mjs +32 -0
- package/dist/adapters/next/index.d.mts +26 -0
- package/dist/adapters/next/index.d.ts +26 -0
- package/dist/adapters/next/index.mjs +29 -0
- package/dist/adapters/node/index.d.mts +34 -0
- package/dist/adapters/node/index.d.ts +34 -0
- package/dist/adapters/node/index.mjs +31 -0
- package/dist/adapters/standard/index.d.mts +25 -0
- package/dist/adapters/standard/index.d.ts +25 -0
- package/dist/adapters/standard/index.mjs +6 -0
- package/dist/index.d.mts +264 -0
- package/dist/index.d.ts +264 -0
- package/dist/index.mjs +333 -0
- package/dist/plugins/index.d.mts +31 -0
- package/dist/plugins/index.d.ts +31 -0
- package/dist/plugins/index.mjs +103 -0
- package/dist/shared/server.3cSam35R.mjs +158 -0
- package/dist/shared/server.BFBhsdJr.mjs +345 -0
- package/dist/shared/server.BZRSVRDu.d.ts +77 -0
- package/dist/shared/server.CPteJIPP.d.mts +143 -0
- package/dist/shared/server.CPteJIPP.d.ts +143 -0
- package/dist/shared/server.CjB_m7jG.mjs +28 -0
- package/dist/shared/server.Q6ZmnTgO.mjs +12 -0
- package/dist/shared/server.iM8li30u.d.mts +77 -0
- package/package.json +43 -15
- package/dist/chunk-37HIYNDO.js +0 -182
- package/dist/fetch.js +0 -303
- package/dist/index.js +0 -518
- package/dist/src/builder.d.ts +0 -35
- package/dist/src/fetch/composite-handler.d.ts +0 -8
- package/dist/src/fetch/index.d.ts +0 -6
- package/dist/src/fetch/orpc-handler.d.ts +0 -20
- package/dist/src/fetch/orpc-payload-codec.d.ts +0 -11
- package/dist/src/fetch/orpc-procedure-matcher.d.ts +0 -12
- package/dist/src/fetch/super-json.d.ts +0 -12
- package/dist/src/fetch/types.d.ts +0 -16
- package/dist/src/hidden.d.ts +0 -6
- package/dist/src/implementer-chainable.d.ts +0 -10
- package/dist/src/index.d.ts +0 -23
- package/dist/src/lazy-decorated.d.ts +0 -10
- package/dist/src/lazy-utils.d.ts +0 -4
- package/dist/src/lazy.d.ts +0 -18
- package/dist/src/middleware-decorated.d.ts +0 -8
- package/dist/src/middleware.d.ts +0 -23
- package/dist/src/procedure-builder.d.ts +0 -22
- package/dist/src/procedure-client.d.ts +0 -34
- package/dist/src/procedure-decorated.d.ts +0 -14
- package/dist/src/procedure-implementer.d.ts +0 -18
- package/dist/src/procedure.d.ts +0 -23
- package/dist/src/router-builder.d.ts +0 -29
- package/dist/src/router-client.d.ts +0 -25
- package/dist/src/router-implementer.d.ts +0 -21
- package/dist/src/router.d.ts +0 -16
- package/dist/src/types.d.ts +0 -12
- package/dist/src/utils.d.ts +0 -3
@@ -0,0 +1,143 @@
|
|
1
|
+
import { ORPCErrorCode, ORPCErrorOptions, ORPCError, ClientContext, Client } from '@orpc/client';
|
2
|
+
import { IsNever, MaybeOptionalOptions, Promisable, Interceptor, Value } from '@orpc/shared';
|
3
|
+
import { ErrorMap, ErrorMapItem, InferSchemaInput, HTTPPath, AnySchema, Meta, ContractProcedureDef, InferSchemaOutput, ErrorFromErrorMap, AnyContractRouter, ContractProcedure } from '@orpc/contract';
|
4
|
+
|
5
|
+
type Context = Record<string, any>;
|
6
|
+
type MergedContext<T extends Context, U extends Context> = T & U;
|
7
|
+
declare function mergeContext<T extends Context, U extends Context>(context: T, other: U): MergedContext<T, U>;
|
8
|
+
type ConflictContextGuard<T extends Context> = true extends IsNever<T> | {
|
9
|
+
[K in keyof T]: IsNever<T[K]>;
|
10
|
+
}[keyof T] ? never : unknown;
|
11
|
+
|
12
|
+
type ORPCErrorConstructorMapItemOptions<TData> = Omit<ORPCErrorOptions<TData>, 'defined' | 'status'>;
|
13
|
+
type ORPCErrorConstructorMapItem<TCode extends ORPCErrorCode, TInData> = (...rest: MaybeOptionalOptions<ORPCErrorConstructorMapItemOptions<TInData>>) => ORPCError<TCode, TInData>;
|
14
|
+
type ORPCErrorConstructorMap<T extends ErrorMap> = {
|
15
|
+
[K in keyof T]: K extends ORPCErrorCode ? T[K] extends ErrorMapItem<infer UInputSchema> ? ORPCErrorConstructorMapItem<K, InferSchemaInput<UInputSchema>> : never : never;
|
16
|
+
};
|
17
|
+
|
18
|
+
declare const LAZY_SYMBOL: unique symbol;
|
19
|
+
interface LazyMeta {
|
20
|
+
prefix?: HTTPPath;
|
21
|
+
}
|
22
|
+
interface Lazy<T> {
|
23
|
+
[LAZY_SYMBOL]: {
|
24
|
+
loader: () => Promise<{
|
25
|
+
default: T;
|
26
|
+
}>;
|
27
|
+
meta: LazyMeta;
|
28
|
+
};
|
29
|
+
}
|
30
|
+
type Lazyable<T> = T | Lazy<T>;
|
31
|
+
declare function lazy<T>(loader: () => Promise<{
|
32
|
+
default: T;
|
33
|
+
}>, meta?: LazyMeta): Lazy<T>;
|
34
|
+
declare function isLazy(item: unknown): item is Lazy<any>;
|
35
|
+
declare function getLazyMeta(lazied: Lazy<any>): LazyMeta;
|
36
|
+
declare function unlazy<T extends Lazyable<any>>(lazied: T): Promise<{
|
37
|
+
default: T extends Lazy<infer U> ? U : T;
|
38
|
+
}>;
|
39
|
+
|
40
|
+
interface ProcedureHandlerOptions<TCurrentContext extends Context, TInput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
|
41
|
+
context: TCurrentContext;
|
42
|
+
input: TInput;
|
43
|
+
path: readonly string[];
|
44
|
+
procedure: Procedure<Context, Context, AnySchema, AnySchema, ErrorMap, TMeta>;
|
45
|
+
signal?: AbortSignal;
|
46
|
+
lastEventId: string | undefined;
|
47
|
+
errors: TErrorConstructorMap;
|
48
|
+
}
|
49
|
+
interface ProcedureHandler<TCurrentContext extends Context, TInput, THandlerOutput, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
50
|
+
(opt: ProcedureHandlerOptions<TCurrentContext, TInput, ORPCErrorConstructorMap<TErrorMap>, TMeta>): Promisable<THandlerOutput>;
|
51
|
+
}
|
52
|
+
interface ProcedureDef<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
53
|
+
__initialContext?: (type: TInitialContext) => unknown;
|
54
|
+
middlewares: AnyMiddleware[];
|
55
|
+
inputValidationIndex: number;
|
56
|
+
outputValidationIndex: number;
|
57
|
+
handler: ProcedureHandler<TCurrentContext, any, any, any, any>;
|
58
|
+
}
|
59
|
+
declare class Procedure<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
60
|
+
'~orpc': ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
61
|
+
constructor(def: ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>);
|
62
|
+
}
|
63
|
+
type AnyProcedure = Procedure<any, any, any, any, any, any>;
|
64
|
+
declare function isProcedure(item: unknown): item is AnyProcedure;
|
65
|
+
|
66
|
+
type MiddlewareResult<TOutContext extends Context, TOutput> = Promisable<{
|
67
|
+
output: TOutput;
|
68
|
+
context: TOutContext;
|
69
|
+
}>;
|
70
|
+
type MiddlewareNextFnOptions<TOutContext extends Context> = Record<never, never> extends TOutContext ? {
|
71
|
+
context?: TOutContext;
|
72
|
+
} : {
|
73
|
+
context: TOutContext;
|
74
|
+
};
|
75
|
+
interface MiddlewareNextFn<TInContext extends Context, TOutput> {
|
76
|
+
<U extends Context & Partial<TInContext> = Record<never, never>>(...rest: MaybeOptionalOptions<MiddlewareNextFnOptions<U>>): MiddlewareResult<U, TOutput>;
|
77
|
+
}
|
78
|
+
interface MiddlewareOutputFn<TOutput> {
|
79
|
+
(output: TOutput): MiddlewareResult<Record<never, never>, TOutput>;
|
80
|
+
}
|
81
|
+
interface MiddlewareOptions<TInContext extends Context, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
|
82
|
+
context: TInContext;
|
83
|
+
path: readonly string[];
|
84
|
+
procedure: Procedure<Context, Context, AnySchema, AnySchema, ErrorMap, TMeta>;
|
85
|
+
signal?: AbortSignal;
|
86
|
+
lastEventId: string | undefined;
|
87
|
+
next: MiddlewareNextFn<TInContext, TOutput>;
|
88
|
+
errors: TErrorConstructorMap;
|
89
|
+
}
|
90
|
+
interface Middleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
|
91
|
+
(options: MiddlewareOptions<TInContext, TOutput, TErrorConstructorMap, TMeta>, input: TInput, output: MiddlewareOutputFn<TOutput>): Promisable<MiddlewareResult<TOutContext, TOutput>>;
|
92
|
+
}
|
93
|
+
type AnyMiddleware = Middleware<any, any, any, any, any, any>;
|
94
|
+
interface MapInputMiddleware<TInput, TMappedInput> {
|
95
|
+
(input: TInput): TMappedInput;
|
96
|
+
}
|
97
|
+
declare function middlewareOutputFn<TOutput>(output: TOutput): MiddlewareResult<Record<never, never>, TOutput>;
|
98
|
+
|
99
|
+
type ProcedureClient<TClientContext extends ClientContext, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> = Client<TClientContext, InferSchemaInput<TInputSchema>, InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>;
|
100
|
+
interface ProcedureClientInterceptorOptions<TInitialContext extends Context, TInputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
101
|
+
context: TInitialContext;
|
102
|
+
input: InferSchemaInput<TInputSchema>;
|
103
|
+
errors: ORPCErrorConstructorMap<TErrorMap>;
|
104
|
+
path: readonly string[];
|
105
|
+
procedure: Procedure<Context, Context, AnySchema, AnySchema, ErrorMap, TMeta>;
|
106
|
+
signal?: AbortSignal;
|
107
|
+
lastEventId: string | undefined;
|
108
|
+
}
|
109
|
+
/**
|
110
|
+
* Options for creating a procedure caller with comprehensive type safety
|
111
|
+
*/
|
112
|
+
type CreateProcedureClientOptions<TInitialContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext> = {
|
113
|
+
/**
|
114
|
+
* This is helpful for logging and analytics.
|
115
|
+
*/
|
116
|
+
path?: readonly string[];
|
117
|
+
interceptors?: Interceptor<ProcedureClientInterceptorOptions<TInitialContext, TInputSchema, TErrorMap, TMeta>, InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>[];
|
118
|
+
} & (Record<never, never> extends TInitialContext ? {
|
119
|
+
context?: Value<TInitialContext, [clientContext: TClientContext]>;
|
120
|
+
} : {
|
121
|
+
context: Value<TInitialContext, [clientContext: TClientContext]>;
|
122
|
+
});
|
123
|
+
declare function createProcedureClient<TInitialContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext>(lazyableProcedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, TErrorMap, TMeta>>, ...[options]: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TInputSchema, TOutputSchema, TErrorMap, TMeta, TClientContext>>): ProcedureClient<TClientContext, TInputSchema, TOutputSchema, TErrorMap>;
|
124
|
+
|
125
|
+
type Router<T extends AnyContractRouter, TInitialContext extends Context> = T extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap, infer UMeta> ? Procedure<TInitialContext, any, UInputSchema, UOutputSchema, UErrorMap, UMeta> : {
|
126
|
+
[K in keyof T]: T[K] extends AnyContractRouter ? Lazyable<Router<T[K], TInitialContext>> : never;
|
127
|
+
};
|
128
|
+
type AnyRouter = Router<any, any>;
|
129
|
+
type InferRouterInitialContext<T extends AnyRouter> = T extends Router<any, infer UInitialContext> ? UInitialContext : never;
|
130
|
+
type InferRouterInitialContexts<T extends AnyRouter> = T extends Procedure<infer UInitialContext, any, any, any, any, any> ? UInitialContext : {
|
131
|
+
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInitialContexts<U> : never;
|
132
|
+
};
|
133
|
+
type InferRouterCurrentContexts<T extends AnyRouter> = T extends Procedure<any, infer UCurrentContext, any, any, any, any> ? UCurrentContext : {
|
134
|
+
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterCurrentContexts<U> : never;
|
135
|
+
};
|
136
|
+
type InferRouterInputs<T extends AnyRouter> = T extends Procedure<any, any, infer UInputSchema, any, any, any> ? InferSchemaInput<UInputSchema> : {
|
137
|
+
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInputs<U> : never;
|
138
|
+
};
|
139
|
+
type InferRouterOutputs<T extends AnyRouter> = T extends Procedure<any, any, any, infer UOutputSchema, any, any> ? InferSchemaOutput<UOutputSchema> : {
|
140
|
+
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterOutputs<U> : never;
|
141
|
+
};
|
142
|
+
|
143
|
+
export { type AnyProcedure as A, createProcedureClient as B, type Context as C, type InferRouterInitialContexts as D, type InferRouterCurrentContexts as E, type InferRouterInputs as F, type InferRouterOutputs as G, type InferRouterInitialContext as I, type Lazyable as L, type Middleware as M, type ORPCErrorConstructorMap as O, type ProcedureClientInterceptorOptions as P, type Router as R, type AnyRouter as a, Procedure as b, type ConflictContextGuard as c, type MergedContext as d, type MapInputMiddleware as e, type CreateProcedureClientOptions as f, type ProcedureClient as g, type AnyMiddleware as h, type Lazy as i, type ProcedureHandler as j, LAZY_SYMBOL as k, type LazyMeta as l, mergeContext as m, lazy as n, isLazy as o, getLazyMeta as p, type MiddlewareResult as q, type MiddlewareNextFnOptions as r, type MiddlewareNextFn as s, type MiddlewareOutputFn as t, unlazy as u, type MiddlewareOptions as v, middlewareOutputFn as w, type ProcedureHandlerOptions as x, type ProcedureDef as y, isProcedure as z };
|
@@ -0,0 +1,28 @@
|
|
1
|
+
import { RPCSerializer } from '@orpc/client/standard';
|
2
|
+
import { toStandardLazyRequest, toFetchResponse } from '@orpc/standard-server-fetch';
|
3
|
+
import { S as StandardHandler, a as RPCMatcher, R as RPCCodec } from './server.3cSam35R.mjs';
|
4
|
+
|
5
|
+
class RPCHandler {
|
6
|
+
standardHandler;
|
7
|
+
constructor(router, options = {}) {
|
8
|
+
const serializer = new RPCSerializer();
|
9
|
+
const matcher = new RPCMatcher();
|
10
|
+
const codec = new RPCCodec(serializer);
|
11
|
+
this.standardHandler = new StandardHandler(router, matcher, codec, options);
|
12
|
+
}
|
13
|
+
async handle(request, ...[
|
14
|
+
options = {}
|
15
|
+
]) {
|
16
|
+
const standardRequest = toStandardLazyRequest(request);
|
17
|
+
const result = await this.standardHandler.handle(standardRequest, options);
|
18
|
+
if (!result.matched) {
|
19
|
+
return result;
|
20
|
+
}
|
21
|
+
return {
|
22
|
+
matched: true,
|
23
|
+
response: toFetchResponse(result.response, options)
|
24
|
+
};
|
25
|
+
}
|
26
|
+
}
|
27
|
+
|
28
|
+
export { RPCHandler as R };
|
@@ -0,0 +1,77 @@
|
|
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.CPteJIPP.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 WellStandardHandleOptions<T extends Context> = StandardHandleOptions<T> & {
|
31
|
+
context: T;
|
32
|
+
};
|
33
|
+
type StandardHandleResult = {
|
34
|
+
matched: true;
|
35
|
+
response: StandardResponse;
|
36
|
+
} | {
|
37
|
+
matched: false;
|
38
|
+
response: undefined;
|
39
|
+
};
|
40
|
+
type StandardHandlerInterceptorOptions<TContext extends Context> = WellStandardHandleOptions<TContext> & {
|
41
|
+
request: StandardLazyRequest;
|
42
|
+
};
|
43
|
+
interface StandardHandlerOptions<TContext extends Context> {
|
44
|
+
plugins?: HandlerPlugin<TContext>[];
|
45
|
+
/**
|
46
|
+
* Interceptors at the request level, helpful when you want catch errors
|
47
|
+
*/
|
48
|
+
interceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, unknown>[];
|
49
|
+
/**
|
50
|
+
* Interceptors at the root level, helpful when you want override the request/response
|
51
|
+
*/
|
52
|
+
rootInterceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, unknown>[];
|
53
|
+
/**
|
54
|
+
*
|
55
|
+
* Interceptors for procedure client.
|
56
|
+
*/
|
57
|
+
clientInterceptors?: Interceptor<ProcedureClientInterceptorOptions<TContext, AnySchema, Record<never, never>, Meta>, InferSchemaOutput<AnySchema>, ErrorFromErrorMap<Record<never, never>>>[];
|
58
|
+
}
|
59
|
+
declare class StandardHandler<T extends Context> {
|
60
|
+
private readonly matcher;
|
61
|
+
private readonly codec;
|
62
|
+
private readonly options;
|
63
|
+
private readonly plugin;
|
64
|
+
constructor(router: Router<any, T>, matcher: StandardMatcher, codec: StandardCodec, options: NoInfer<StandardHandlerOptions<T>>);
|
65
|
+
handle(request: StandardLazyRequest, ...[options]: MaybeOptionalOptions<StandardHandleOptions<T>>): Promise<StandardHandleResult>;
|
66
|
+
}
|
67
|
+
|
68
|
+
interface HandlerPlugin<TContext extends Context> {
|
69
|
+
init?(options: StandardHandlerOptions<TContext>): void;
|
70
|
+
}
|
71
|
+
declare class CompositePlugin<TContext extends Context> implements HandlerPlugin<TContext> {
|
72
|
+
private readonly plugins;
|
73
|
+
constructor(plugins?: HandlerPlugin<TContext>[]);
|
74
|
+
init(options: StandardHandlerOptions<TContext>): void;
|
75
|
+
}
|
76
|
+
|
77
|
+
export { CompositePlugin as C, type HandlerPlugin as H, type StandardHandleOptions as S, type WellStandardHandleOptions as W, type StandardHandlerInterceptorOptions as a, type StandardHandlerOptions 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 };
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@orpc/server",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.0.0-next.
|
4
|
+
"version": "0.0.0-next.9adcd05",
|
5
5
|
"license": "MIT",
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
7
7
|
"repository": {
|
@@ -15,33 +15,61 @@
|
|
15
15
|
],
|
16
16
|
"exports": {
|
17
17
|
".": {
|
18
|
-
"types": "./dist/
|
19
|
-
"import": "./dist/index.
|
20
|
-
"default": "./dist/index.
|
18
|
+
"types": "./dist/index.d.mts",
|
19
|
+
"import": "./dist/index.mjs",
|
20
|
+
"default": "./dist/index.mjs"
|
21
|
+
},
|
22
|
+
"./plugins": {
|
23
|
+
"types": "./dist/plugins/index.d.mts",
|
24
|
+
"import": "./dist/plugins/index.mjs",
|
25
|
+
"default": "./dist/plugins/index.mjs"
|
26
|
+
},
|
27
|
+
"./standard": {
|
28
|
+
"types": "./dist/adapters/standard/index.d.mts",
|
29
|
+
"import": "./dist/adapters/standard/index.mjs",
|
30
|
+
"default": "./dist/adapters/standard/index.mjs"
|
21
31
|
},
|
22
32
|
"./fetch": {
|
23
|
-
"types": "./dist/
|
24
|
-
"import": "./dist/fetch.
|
25
|
-
"default": "./dist/fetch.
|
33
|
+
"types": "./dist/adapters/fetch/index.d.mts",
|
34
|
+
"import": "./dist/adapters/fetch/index.mjs",
|
35
|
+
"default": "./dist/adapters/fetch/index.mjs"
|
36
|
+
},
|
37
|
+
"./hono": {
|
38
|
+
"types": "./dist/adapters/hono/index.d.mts",
|
39
|
+
"import": "./dist/adapters/hono/index.mjs",
|
40
|
+
"default": "./dist/adapters/hono/index.mjs"
|
26
41
|
},
|
27
|
-
"
|
28
|
-
"types": "./dist/
|
42
|
+
"./next": {
|
43
|
+
"types": "./dist/adapters/next/index.d.mts",
|
44
|
+
"import": "./dist/adapters/next/index.mjs",
|
45
|
+
"default": "./dist/adapters/next/index.mjs"
|
46
|
+
},
|
47
|
+
"./node": {
|
48
|
+
"types": "./dist/adapters/node/index.d.mts",
|
49
|
+
"import": "./dist/adapters/node/index.mjs",
|
50
|
+
"default": "./dist/adapters/node/index.mjs"
|
29
51
|
}
|
30
52
|
},
|
31
53
|
"files": [
|
32
|
-
"!**/*.map",
|
33
|
-
"!**/*.tsbuildinfo",
|
34
54
|
"dist"
|
35
55
|
],
|
56
|
+
"peerDependencies": {
|
57
|
+
"hono": ">=4.6.0",
|
58
|
+
"next": ">=14.0.0"
|
59
|
+
},
|
36
60
|
"dependencies": {
|
37
|
-
"@orpc/
|
38
|
-
"@orpc/
|
61
|
+
"@orpc/client": "0.0.0-next.9adcd05",
|
62
|
+
"@orpc/contract": "0.0.0-next.9adcd05",
|
63
|
+
"@orpc/standard-server": "0.0.0-next.9adcd05",
|
64
|
+
"@orpc/shared": "0.0.0-next.9adcd05",
|
65
|
+
"@orpc/standard-server-fetch": "0.0.0-next.9adcd05",
|
66
|
+
"@orpc/standard-server-node": "0.0.0-next.9adcd05"
|
39
67
|
},
|
40
68
|
"devDependencies": {
|
41
|
-
"
|
69
|
+
"light-my-request": "^6.5.1"
|
42
70
|
},
|
43
71
|
"scripts": {
|
44
|
-
"build": "
|
72
|
+
"build": "unbuild",
|
45
73
|
"build:watch": "pnpm run build --watch",
|
46
74
|
"type:check": "tsc -b"
|
47
75
|
}
|
package/dist/chunk-37HIYNDO.js
DELETED
@@ -1,182 +0,0 @@
|
|
1
|
-
// src/utils.ts
|
2
|
-
function mergeContext(a, b) {
|
3
|
-
if (!a)
|
4
|
-
return b;
|
5
|
-
if (!b)
|
6
|
-
return a;
|
7
|
-
return {
|
8
|
-
...a,
|
9
|
-
...b
|
10
|
-
};
|
11
|
-
}
|
12
|
-
|
13
|
-
// src/procedure.ts
|
14
|
-
import { isContractProcedure } from "@orpc/contract";
|
15
|
-
var Procedure = class {
|
16
|
-
"~type" = "Procedure";
|
17
|
-
"~orpc";
|
18
|
-
constructor(def) {
|
19
|
-
this["~orpc"] = def;
|
20
|
-
}
|
21
|
-
};
|
22
|
-
function isProcedure(item) {
|
23
|
-
if (item instanceof Procedure) {
|
24
|
-
return true;
|
25
|
-
}
|
26
|
-
return (typeof item === "object" || typeof item === "function") && item !== null && "~type" in item && item["~type"] === "Procedure" && "~orpc" in item && typeof item["~orpc"] === "object" && item["~orpc"] !== null && "contract" in item["~orpc"] && isContractProcedure(item["~orpc"].contract) && "handler" in item["~orpc"] && typeof item["~orpc"].handler === "function";
|
27
|
-
}
|
28
|
-
|
29
|
-
// src/lazy.ts
|
30
|
-
var LAZY_LOADER_SYMBOL = Symbol("ORPC_LAZY_LOADER");
|
31
|
-
function lazy(loader) {
|
32
|
-
return {
|
33
|
-
[LAZY_LOADER_SYMBOL]: loader
|
34
|
-
};
|
35
|
-
}
|
36
|
-
function isLazy(item) {
|
37
|
-
return (typeof item === "object" || typeof item === "function") && item !== null && LAZY_LOADER_SYMBOL in item && typeof item[LAZY_LOADER_SYMBOL] === "function";
|
38
|
-
}
|
39
|
-
function unlazy(lazied) {
|
40
|
-
return isLazy(lazied) ? lazied[LAZY_LOADER_SYMBOL]() : Promise.resolve({ default: lazied });
|
41
|
-
}
|
42
|
-
function flatLazy(lazied) {
|
43
|
-
const flattenLoader = async () => {
|
44
|
-
let current = await unlazy(lazied);
|
45
|
-
while (true) {
|
46
|
-
if (!isLazy(current.default)) {
|
47
|
-
break;
|
48
|
-
}
|
49
|
-
current = await unlazy(current.default);
|
50
|
-
}
|
51
|
-
return current;
|
52
|
-
};
|
53
|
-
return lazy(flattenLoader);
|
54
|
-
}
|
55
|
-
|
56
|
-
// src/procedure-client.ts
|
57
|
-
import { executeWithHooks, value } from "@orpc/shared";
|
58
|
-
import { ORPCError } from "@orpc/shared/error";
|
59
|
-
function createProcedureClient(options) {
|
60
|
-
return async (...[input, callerOptions]) => {
|
61
|
-
const path = options.path ?? [];
|
62
|
-
const { default: procedure } = await unlazy(options.procedure);
|
63
|
-
const context = await value(options.context);
|
64
|
-
const meta = {
|
65
|
-
path,
|
66
|
-
procedure,
|
67
|
-
signal: callerOptions?.signal
|
68
|
-
};
|
69
|
-
const executeWithValidation = async () => {
|
70
|
-
const validInput = await validateInput(procedure, input);
|
71
|
-
const output = await executeMiddlewareChain(
|
72
|
-
procedure,
|
73
|
-
validInput,
|
74
|
-
context,
|
75
|
-
meta
|
76
|
-
);
|
77
|
-
return validateOutput(procedure, output);
|
78
|
-
};
|
79
|
-
return executeWithHooks({
|
80
|
-
hooks: options,
|
81
|
-
input,
|
82
|
-
context,
|
83
|
-
meta,
|
84
|
-
execute: executeWithValidation
|
85
|
-
});
|
86
|
-
};
|
87
|
-
}
|
88
|
-
async function validateInput(procedure, input) {
|
89
|
-
const schema = procedure["~orpc"].contract["~orpc"].InputSchema;
|
90
|
-
if (!schema)
|
91
|
-
return input;
|
92
|
-
const result = await schema["~standard"].validate(input);
|
93
|
-
if (result.issues) {
|
94
|
-
throw new ORPCError({
|
95
|
-
message: "Input validation failed",
|
96
|
-
code: "BAD_REQUEST",
|
97
|
-
issues: result.issues
|
98
|
-
});
|
99
|
-
}
|
100
|
-
return result.value;
|
101
|
-
}
|
102
|
-
async function validateOutput(procedure, output) {
|
103
|
-
const schema = procedure["~orpc"].contract["~orpc"].OutputSchema;
|
104
|
-
if (!schema)
|
105
|
-
return output;
|
106
|
-
const result = await schema["~standard"].validate(output);
|
107
|
-
if (result.issues) {
|
108
|
-
throw new ORPCError({
|
109
|
-
message: "Output validation failed",
|
110
|
-
code: "INTERNAL_SERVER_ERROR",
|
111
|
-
issues: result.issues
|
112
|
-
});
|
113
|
-
}
|
114
|
-
return result.value;
|
115
|
-
}
|
116
|
-
async function executeMiddlewareChain(procedure, input, context, meta) {
|
117
|
-
const middlewares = procedure["~orpc"].middlewares ?? [];
|
118
|
-
let currentMidIndex = 0;
|
119
|
-
let currentContext = context;
|
120
|
-
const next = async (nextOptions) => {
|
121
|
-
const mid = middlewares[currentMidIndex];
|
122
|
-
currentMidIndex += 1;
|
123
|
-
currentContext = mergeContext(currentContext, nextOptions.context);
|
124
|
-
if (mid) {
|
125
|
-
return await mid(input, currentContext, {
|
126
|
-
...meta,
|
127
|
-
next,
|
128
|
-
output: (output) => ({ output, context: void 0 })
|
129
|
-
});
|
130
|
-
}
|
131
|
-
const result = {
|
132
|
-
output: await procedure["~orpc"].handler(input, currentContext, meta),
|
133
|
-
context: currentContext
|
134
|
-
};
|
135
|
-
return result;
|
136
|
-
};
|
137
|
-
return (await next({})).output;
|
138
|
-
}
|
139
|
-
|
140
|
-
// src/router.ts
|
141
|
-
function getRouterChild(router, ...path) {
|
142
|
-
let current = router;
|
143
|
-
for (let i = 0; i < path.length; i++) {
|
144
|
-
const segment = path[i];
|
145
|
-
if (!current) {
|
146
|
-
return void 0;
|
147
|
-
}
|
148
|
-
if (isProcedure(current)) {
|
149
|
-
return void 0;
|
150
|
-
}
|
151
|
-
if (!isLazy(current)) {
|
152
|
-
current = current[segment];
|
153
|
-
continue;
|
154
|
-
}
|
155
|
-
const lazied = current;
|
156
|
-
const rest = path.slice(i);
|
157
|
-
const newLazy = lazy(async () => {
|
158
|
-
const unwrapped = await unlazy(lazied);
|
159
|
-
if (!unwrapped.default) {
|
160
|
-
return unwrapped;
|
161
|
-
}
|
162
|
-
const next = getRouterChild(unwrapped.default, ...rest);
|
163
|
-
return { default: next };
|
164
|
-
});
|
165
|
-
return flatLazy(newLazy);
|
166
|
-
}
|
167
|
-
return current;
|
168
|
-
}
|
169
|
-
|
170
|
-
export {
|
171
|
-
mergeContext,
|
172
|
-
Procedure,
|
173
|
-
isProcedure,
|
174
|
-
LAZY_LOADER_SYMBOL,
|
175
|
-
lazy,
|
176
|
-
isLazy,
|
177
|
-
unlazy,
|
178
|
-
flatLazy,
|
179
|
-
createProcedureClient,
|
180
|
-
getRouterChild
|
181
|
-
};
|
182
|
-
//# sourceMappingURL=chunk-37HIYNDO.js.map
|