@orpc/server 0.0.0-next.9914009 → 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.
Files changed (75) hide show
  1. package/README.md +118 -0
  2. package/dist/adapters/fetch/index.d.mts +26 -0
  3. package/dist/adapters/fetch/index.d.ts +26 -0
  4. package/dist/adapters/fetch/index.mjs +9 -0
  5. package/dist/adapters/hono/index.d.mts +19 -0
  6. package/dist/adapters/hono/index.d.ts +19 -0
  7. package/dist/adapters/hono/index.mjs +32 -0
  8. package/dist/adapters/next/index.d.mts +26 -0
  9. package/dist/adapters/next/index.d.ts +26 -0
  10. package/dist/adapters/next/index.mjs +29 -0
  11. package/dist/adapters/node/index.d.mts +34 -0
  12. package/dist/adapters/node/index.d.ts +34 -0
  13. package/dist/adapters/node/index.mjs +31 -0
  14. package/dist/adapters/standard/index.d.mts +25 -0
  15. package/dist/adapters/standard/index.d.ts +25 -0
  16. package/dist/adapters/standard/index.mjs +6 -0
  17. package/dist/index.d.mts +264 -0
  18. package/dist/index.d.ts +264 -0
  19. package/dist/index.mjs +333 -0
  20. package/dist/plugins/index.d.mts +31 -0
  21. package/dist/plugins/index.d.ts +31 -0
  22. package/dist/plugins/index.mjs +103 -0
  23. package/dist/shared/server.3cSam35R.mjs +158 -0
  24. package/dist/shared/server.BFBhsdJr.mjs +345 -0
  25. package/dist/shared/server.BZRSVRDu.d.ts +77 -0
  26. package/dist/shared/server.CPteJIPP.d.mts +143 -0
  27. package/dist/shared/server.CPteJIPP.d.ts +143 -0
  28. package/dist/shared/server.CjB_m7jG.mjs +28 -0
  29. package/dist/shared/server.Q6ZmnTgO.mjs +12 -0
  30. package/dist/shared/server.iM8li30u.d.mts +77 -0
  31. package/package.json +36 -24
  32. package/dist/chunk-3EVCPLVI.js +0 -301
  33. package/dist/chunk-OUPZ7QGV.js +0 -245
  34. package/dist/chunk-WUOGVGWG.js +0 -1
  35. package/dist/fetch.js +0 -15
  36. package/dist/hono.js +0 -30
  37. package/dist/index.js +0 -562
  38. package/dist/next.js +0 -36
  39. package/dist/node.js +0 -87
  40. package/dist/src/adapters/fetch/index.d.ts +0 -6
  41. package/dist/src/adapters/fetch/orpc-handler.d.ts +0 -20
  42. package/dist/src/adapters/fetch/orpc-payload-codec.d.ts +0 -16
  43. package/dist/src/adapters/fetch/orpc-procedure-matcher.d.ts +0 -12
  44. package/dist/src/adapters/fetch/super-json.d.ts +0 -12
  45. package/dist/src/adapters/fetch/types.d.ts +0 -21
  46. package/dist/src/adapters/hono/index.d.ts +0 -3
  47. package/dist/src/adapters/hono/middleware.d.ts +0 -12
  48. package/dist/src/adapters/next/index.d.ts +0 -3
  49. package/dist/src/adapters/next/serve.d.ts +0 -19
  50. package/dist/src/adapters/node/index.d.ts +0 -5
  51. package/dist/src/adapters/node/orpc-handler.d.ts +0 -12
  52. package/dist/src/adapters/node/request-listener.d.ts +0 -28
  53. package/dist/src/adapters/node/types.d.ts +0 -22
  54. package/dist/src/builder.d.ts +0 -36
  55. package/dist/src/error.d.ts +0 -10
  56. package/dist/src/hidden.d.ts +0 -6
  57. package/dist/src/implementer-chainable.d.ts +0 -10
  58. package/dist/src/index.d.ts +0 -25
  59. package/dist/src/lazy-decorated.d.ts +0 -7
  60. package/dist/src/lazy-utils.d.ts +0 -4
  61. package/dist/src/lazy.d.ts +0 -18
  62. package/dist/src/middleware-decorated.d.ts +0 -9
  63. package/dist/src/middleware.d.ts +0 -36
  64. package/dist/src/procedure-builder.d.ts +0 -24
  65. package/dist/src/procedure-client.d.ts +0 -22
  66. package/dist/src/procedure-decorated.d.ts +0 -26
  67. package/dist/src/procedure-implementer.d.ts +0 -20
  68. package/dist/src/procedure-utils.d.ts +0 -17
  69. package/dist/src/procedure.d.ts +0 -44
  70. package/dist/src/router-builder.d.ts +0 -29
  71. package/dist/src/router-client.d.ts +0 -26
  72. package/dist/src/router-implementer.d.ts +0 -21
  73. package/dist/src/router.d.ts +0 -16
  74. package/dist/src/types.d.ts +0 -14
  75. 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,12 @@
1
+ class CompositePlugin {
2
+ constructor(plugins = []) {
3
+ this.plugins = plugins;
4
+ }
5
+ init(options) {
6
+ for (const plugin of this.plugins) {
7
+ plugin.init?.(options);
8
+ }
9
+ }
10
+ }
11
+
12
+ export { CompositePlugin as C };
@@ -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.9914009",
4
+ "version": "0.0.0-next.9adcd05",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -15,37 +15,42 @@
15
15
  ],
16
16
  "exports": {
17
17
  ".": {
18
- "types": "./dist/src/index.d.ts",
19
- "import": "./dist/index.js",
20
- "default": "./dist/index.js"
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/src/adapters/fetch/index.d.ts",
24
- "import": "./dist/fetch.js",
25
- "default": "./dist/fetch.js"
33
+ "types": "./dist/adapters/fetch/index.d.mts",
34
+ "import": "./dist/adapters/fetch/index.mjs",
35
+ "default": "./dist/adapters/fetch/index.mjs"
26
36
  },
27
37
  "./hono": {
28
- "types": "./dist/src/adapters/hono/index.d.ts",
29
- "import": "./dist/hono.js",
30
- "default": "./dist/hono.js"
38
+ "types": "./dist/adapters/hono/index.d.mts",
39
+ "import": "./dist/adapters/hono/index.mjs",
40
+ "default": "./dist/adapters/hono/index.mjs"
31
41
  },
32
42
  "./next": {
33
- "types": "./dist/src/adapters/next/index.d.ts",
34
- "import": "./dist/next.js",
35
- "default": "./dist/next.js"
43
+ "types": "./dist/adapters/next/index.d.mts",
44
+ "import": "./dist/adapters/next/index.mjs",
45
+ "default": "./dist/adapters/next/index.mjs"
36
46
  },
37
47
  "./node": {
38
- "types": "./dist/src/adapters/node/index.d.ts",
39
- "import": "./dist/node.js",
40
- "default": "./dist/node.js"
41
- },
42
- "./🔒/*": {
43
- "types": "./dist/src/*.d.ts"
48
+ "types": "./dist/adapters/node/index.d.mts",
49
+ "import": "./dist/adapters/node/index.mjs",
50
+ "default": "./dist/adapters/node/index.mjs"
44
51
  }
45
52
  },
46
53
  "files": [
47
- "!**/*.map",
48
- "!**/*.tsbuildinfo",
49
54
  "dist"
50
55
  ],
51
56
  "peerDependencies": {
@@ -53,11 +58,18 @@
53
58
  "next": ">=14.0.0"
54
59
  },
55
60
  "dependencies": {
56
- "@orpc/shared": "0.0.0-next.9914009",
57
- "@orpc/contract": "0.0.0-next.9914009"
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"
67
+ },
68
+ "devDependencies": {
69
+ "light-my-request": "^6.5.1"
58
70
  },
59
71
  "scripts": {
60
- "build": "tsup --onSuccess='tsc -b --noCheck'",
72
+ "build": "unbuild",
61
73
  "build:watch": "pnpm run build --watch",
62
74
  "type:check": "tsc -b"
63
75
  }
@@ -1,301 +0,0 @@
1
- import {
2
- __export,
3
- createProcedureClient,
4
- getRouterChild,
5
- isProcedure,
6
- unlazy
7
- } from "./chunk-OUPZ7QGV.js";
8
-
9
- // src/adapters/fetch/super-json.ts
10
- var super_json_exports = {};
11
- __export(super_json_exports, {
12
- deserialize: () => deserialize,
13
- serialize: () => serialize
14
- });
15
-
16
- // ../../node_modules/.pnpm/is-what@5.0.2/node_modules/is-what/dist/getType.js
17
- function getType(payload) {
18
- return Object.prototype.toString.call(payload).slice(8, -1);
19
- }
20
-
21
- // ../../node_modules/.pnpm/is-what@5.0.2/node_modules/is-what/dist/isPlainObject.js
22
- function isPlainObject(payload) {
23
- if (getType(payload) !== "Object")
24
- return false;
25
- const prototype = Object.getPrototypeOf(payload);
26
- return !!prototype && prototype.constructor === Object && prototype === Object.prototype;
27
- }
28
-
29
- // src/adapters/fetch/super-json.ts
30
- function serialize(value, segments = [], meta = []) {
31
- if (typeof value === "bigint") {
32
- meta.push(["bigint", segments]);
33
- return { data: value.toString(), meta };
34
- }
35
- if (value instanceof Date) {
36
- meta.push(["date", segments]);
37
- const data = Number.isNaN(value.getTime()) ? "Invalid Date" : value.toISOString();
38
- return { data, meta };
39
- }
40
- if (Number.isNaN(value)) {
41
- meta.push(["nan", segments]);
42
- return { data: "NaN", meta };
43
- }
44
- if (value instanceof RegExp) {
45
- meta.push(["regexp", segments]);
46
- return { data: value.toString(), meta };
47
- }
48
- if (value instanceof URL) {
49
- meta.push(["url", segments]);
50
- return { data: value.toString(), meta };
51
- }
52
- if (isPlainObject(value)) {
53
- const data = {};
54
- for (const k in value) {
55
- data[k] = serialize(value[k], [...segments, k], meta).data;
56
- }
57
- return { data, meta };
58
- }
59
- if (Array.isArray(value)) {
60
- const data = value.map((v, i) => {
61
- if (v === void 0) {
62
- meta.push(["undefined", [...segments, i]]);
63
- return null;
64
- }
65
- return serialize(v, [...segments, i], meta).data;
66
- });
67
- return { data, meta };
68
- }
69
- if (value instanceof Set) {
70
- const result = serialize(Array.from(value), segments, meta);
71
- meta.push(["set", segments]);
72
- return result;
73
- }
74
- if (value instanceof Map) {
75
- const result = serialize(Array.from(value.entries()), segments, meta);
76
- meta.push(["map", segments]);
77
- return result;
78
- }
79
- return { data: value, meta };
80
- }
81
- function deserialize({
82
- data,
83
- meta
84
- }) {
85
- if (meta.length === 0) {
86
- return data;
87
- }
88
- const ref = { data };
89
- for (const [type, segments] of meta) {
90
- let currentRef = ref;
91
- let preSegment = "data";
92
- for (let i = 0; i < segments.length; i++) {
93
- currentRef = currentRef[preSegment];
94
- preSegment = segments[i];
95
- }
96
- switch (type) {
97
- case "nan":
98
- currentRef[preSegment] = Number.NaN;
99
- break;
100
- case "bigint":
101
- currentRef[preSegment] = BigInt(currentRef[preSegment]);
102
- break;
103
- case "date":
104
- currentRef[preSegment] = new Date(currentRef[preSegment]);
105
- break;
106
- case "regexp": {
107
- const [, pattern, flags] = currentRef[preSegment].match(/^\/(.*)\/([a-z]*)$/);
108
- currentRef[preSegment] = new RegExp(pattern, flags);
109
- break;
110
- }
111
- case "url":
112
- currentRef[preSegment] = new URL(currentRef[preSegment]);
113
- break;
114
- case "undefined":
115
- currentRef[preSegment] = void 0;
116
- break;
117
- case "map":
118
- currentRef[preSegment] = new Map(currentRef[preSegment]);
119
- break;
120
- case "set":
121
- currentRef[preSegment] = new Set(currentRef[preSegment]);
122
- break;
123
- /* v8 ignore next 3 */
124
- default: {
125
- const _expected = type;
126
- }
127
- }
128
- }
129
- return ref.data;
130
- }
131
-
132
- // src/adapters/fetch/orpc-payload-codec.ts
133
- import { ORPCError } from "@orpc/contract";
134
- import { findDeepMatches, set } from "@orpc/shared";
135
- var ORPCPayloadCodec = class {
136
- /**
137
- * If method is GET, the payload will be encoded as query string.
138
- * If method is GET and payload contain file, the method will be fallback to fallbackMethod. (fallbackMethod = GET will force to use GET method)
139
- */
140
- encode(payload, method = "POST", fallbackMethod = "POST") {
141
- const { data, meta } = serialize(payload);
142
- const { maps, values } = findDeepMatches((v) => v instanceof Blob, data);
143
- if (method === "GET" && (values.length === 0 || fallbackMethod === "GET")) {
144
- const query = new URLSearchParams({
145
- data: JSON.stringify(data),
146
- meta: JSON.stringify(meta)
147
- });
148
- return {
149
- query,
150
- method: "GET"
151
- };
152
- }
153
- const nonGETMethod = method === "GET" ? fallbackMethod : method;
154
- if (values.length > 0) {
155
- const form = new FormData();
156
- if (data !== void 0) {
157
- form.append("data", JSON.stringify(data));
158
- }
159
- form.append("meta", JSON.stringify(meta));
160
- form.append("maps", JSON.stringify(maps));
161
- for (const i in values) {
162
- const value = values[i];
163
- form.append(i, value);
164
- }
165
- return {
166
- body: form,
167
- method: nonGETMethod
168
- };
169
- }
170
- return {
171
- body: JSON.stringify({ data, meta }),
172
- headers: new Headers({
173
- "content-type": "application/json"
174
- }),
175
- method: nonGETMethod
176
- };
177
- }
178
- async decode(re) {
179
- try {
180
- if ("method" in re && re.method === "GET") {
181
- const url = new URL(re.url);
182
- const query = url.searchParams;
183
- const data = JSON.parse(query.getAll("data").at(-1));
184
- const meta = JSON.parse(query.getAll("meta").at(-1));
185
- return deserialize({
186
- data,
187
- meta
188
- });
189
- }
190
- if (re.headers.get("content-type")?.startsWith("multipart/form-data")) {
191
- const form = await re.formData();
192
- const rawData = form.get("data");
193
- const rawMeta = form.get("meta");
194
- const rawMaps = form.get("maps");
195
- let data = JSON.parse(rawData);
196
- const meta = JSON.parse(rawMeta);
197
- const maps = JSON.parse(rawMaps);
198
- for (const i in maps) {
199
- data = set(data, maps[i], form.get(i));
200
- }
201
- return deserialize({
202
- data,
203
- meta
204
- });
205
- }
206
- const json = await re.json();
207
- return deserialize(json);
208
- } catch (e) {
209
- throw new ORPCError({
210
- code: "BAD_REQUEST",
211
- message: "Cannot parse request/response. Please check the request/response body and Content-Type header.",
212
- cause: e
213
- });
214
- }
215
- }
216
- };
217
-
218
- // src/adapters/fetch/orpc-procedure-matcher.ts
219
- import { trim } from "@orpc/shared";
220
- var ORPCProcedureMatcher = class {
221
- constructor(router) {
222
- this.router = router;
223
- }
224
- async match(pathname) {
225
- const path = trim(pathname, "/").split("/").map(decodeURIComponent);
226
- const match = getRouterChild(this.router, ...path);
227
- const { default: maybeProcedure } = await unlazy(match);
228
- if (!isProcedure(maybeProcedure)) {
229
- return void 0;
230
- }
231
- return {
232
- procedure: maybeProcedure,
233
- path
234
- };
235
- }
236
- };
237
-
238
- // src/adapters/fetch/orpc-handler.ts
239
- import { ORPCError as ORPCError2 } from "@orpc/contract";
240
- import { executeWithHooks, trim as trim2 } from "@orpc/shared";
241
- var RPCHandler = class {
242
- constructor(router, options) {
243
- this.options = options;
244
- this.procedureMatcher = options?.procedureMatcher ?? new ORPCProcedureMatcher(router);
245
- this.payloadCodec = options?.payloadCodec ?? new ORPCPayloadCodec();
246
- }
247
- procedureMatcher;
248
- payloadCodec;
249
- async handle(request, ...[options]) {
250
- const context = options?.context;
251
- const execute = async () => {
252
- const url = new URL(request.url);
253
- const pathname = `/${trim2(url.pathname.replace(options?.prefix ?? "", ""), "/")}`;
254
- const match = await this.procedureMatcher.match(pathname);
255
- if (!match) {
256
- return { matched: false, response: void 0 };
257
- }
258
- const input = await this.payloadCodec.decode(request);
259
- const client = createProcedureClient(match.procedure, {
260
- context,
261
- path: match.path
262
- });
263
- const output = await client(input, { signal: request.signal });
264
- const { body, headers } = this.payloadCodec.encode(output);
265
- const response = new Response(body, { headers });
266
- return { matched: true, response };
267
- };
268
- try {
269
- const result = await executeWithHooks({
270
- context,
271
- execute,
272
- input: request,
273
- hooks: this.options,
274
- meta: {
275
- signal: request.signal
276
- }
277
- });
278
- return result;
279
- } catch (e) {
280
- const error = e instanceof ORPCError2 ? e : new ORPCError2({
281
- code: "INTERNAL_SERVER_ERROR",
282
- message: "Internal server error",
283
- cause: e
284
- });
285
- const { body, headers } = this.payloadCodec.encode(error.toJSON());
286
- const response = new Response(body, {
287
- headers,
288
- status: error.status
289
- });
290
- return { matched: true, response };
291
- }
292
- }
293
- };
294
-
295
- export {
296
- super_json_exports,
297
- ORPCPayloadCodec,
298
- ORPCProcedureMatcher,
299
- RPCHandler
300
- };
301
- //# sourceMappingURL=chunk-3EVCPLVI.js.map