@orpc/server 0.0.0-next.8b5a6d6 → 0.0.0-next.8b973a6

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 (83) hide show
  1. package/README.md +131 -0
  2. package/dist/adapters/aws-lambda/index.d.mts +46 -0
  3. package/dist/adapters/aws-lambda/index.d.ts +46 -0
  4. package/dist/adapters/aws-lambda/index.mjs +42 -0
  5. package/dist/adapters/bun-ws/index.d.mts +36 -0
  6. package/dist/adapters/bun-ws/index.d.ts +36 -0
  7. package/dist/adapters/bun-ws/index.mjs +47 -0
  8. package/dist/adapters/crossws/index.d.mts +33 -0
  9. package/dist/adapters/crossws/index.d.ts +33 -0
  10. package/dist/adapters/crossws/index.mjs +45 -0
  11. package/dist/adapters/fastify/index.d.mts +53 -0
  12. package/dist/adapters/fastify/index.d.ts +53 -0
  13. package/dist/adapters/fastify/index.mjs +54 -0
  14. package/dist/adapters/fetch/index.d.mts +124 -0
  15. package/dist/adapters/fetch/index.d.ts +124 -0
  16. package/dist/adapters/fetch/index.mjs +180 -0
  17. package/dist/adapters/message-port/index.d.mts +57 -0
  18. package/dist/adapters/message-port/index.d.ts +57 -0
  19. package/dist/adapters/message-port/index.mjs +55 -0
  20. package/dist/adapters/node/index.d.mts +99 -0
  21. package/dist/adapters/node/index.d.ts +99 -0
  22. package/dist/adapters/node/index.mjs +152 -0
  23. package/dist/adapters/standard/index.d.mts +21 -0
  24. package/dist/adapters/standard/index.d.ts +21 -0
  25. package/dist/adapters/standard/index.mjs +8 -0
  26. package/dist/adapters/standard-peer/index.d.mts +18 -0
  27. package/dist/adapters/standard-peer/index.d.ts +18 -0
  28. package/dist/adapters/standard-peer/index.mjs +7 -0
  29. package/dist/adapters/websocket/index.d.mts +56 -0
  30. package/dist/adapters/websocket/index.d.ts +56 -0
  31. package/dist/adapters/websocket/index.mjs +67 -0
  32. package/dist/adapters/ws/index.d.mts +31 -0
  33. package/dist/adapters/ws/index.d.ts +31 -0
  34. package/dist/adapters/ws/index.mjs +37 -0
  35. package/dist/helpers/index.d.mts +149 -0
  36. package/dist/helpers/index.d.ts +149 -0
  37. package/dist/helpers/index.mjs +198 -0
  38. package/dist/hibernation/index.d.mts +44 -0
  39. package/dist/hibernation/index.d.ts +44 -0
  40. package/dist/hibernation/index.mjs +65 -0
  41. package/dist/index.d.mts +803 -0
  42. package/dist/index.d.ts +803 -0
  43. package/dist/index.mjs +492 -0
  44. package/dist/plugins/index.d.mts +204 -0
  45. package/dist/plugins/index.d.ts +204 -0
  46. package/dist/plugins/index.mjs +328 -0
  47. package/dist/shared/server.7cEtMB30.d.ts +74 -0
  48. package/dist/shared/server.B8gYOD5g.d.mts +12 -0
  49. package/dist/shared/server.BqadksTP.d.mts +74 -0
  50. package/dist/shared/server.Bxx6tqNe.mjs +219 -0
  51. package/dist/shared/server.C8_sRzQB.d.mts +42 -0
  52. package/dist/shared/server.ChUyt5-i.d.mts +32 -0
  53. package/dist/shared/server.ChyoA9XY.d.ts +42 -0
  54. package/dist/shared/server.DZ5BIITo.mjs +9 -0
  55. package/dist/shared/server.Ds4HPpvH.mjs +409 -0
  56. package/dist/shared/server.EfTOZ2Q7.d.ts +12 -0
  57. package/dist/shared/server.TEVCLCFC.mjs +39 -0
  58. package/dist/shared/server.UVMTOWrk.mjs +26 -0
  59. package/dist/shared/server.qKsRrdxW.d.mts +193 -0
  60. package/dist/shared/server.qKsRrdxW.d.ts +193 -0
  61. package/dist/shared/server.yoEB3Fx4.d.ts +32 -0
  62. package/package.json +103 -21
  63. package/dist/chunk-3JMSDC5L.js +0 -274
  64. package/dist/fetch.js +0 -112
  65. package/dist/index.js +0 -467
  66. package/dist/src/builder.d.ts +0 -53
  67. package/dist/src/fetch/handle.d.ts +0 -7
  68. package/dist/src/fetch/handler.d.ts +0 -3
  69. package/dist/src/fetch/index.d.ts +0 -4
  70. package/dist/src/fetch/types.d.ts +0 -28
  71. package/dist/src/index.d.ts +0 -17
  72. package/dist/src/lazy.d.ts +0 -23
  73. package/dist/src/middleware.d.ts +0 -26
  74. package/dist/src/procedure-builder.d.ts +0 -31
  75. package/dist/src/procedure-caller.d.ts +0 -26
  76. package/dist/src/procedure-implementer.d.ts +0 -22
  77. package/dist/src/procedure.d.ts +0 -32
  78. package/dist/src/router-builder.d.ts +0 -27
  79. package/dist/src/router-caller.d.ts +0 -25
  80. package/dist/src/router-implementer.d.ts +0 -24
  81. package/dist/src/router.d.ts +0 -21
  82. package/dist/src/types.d.ts +0 -14
  83. package/dist/src/utils.d.ts +0 -3
@@ -0,0 +1,193 @@
1
+ import { ORPCErrorCode, ORPCErrorOptions, ORPCError, HTTPPath, ClientContext, Client } from '@orpc/client';
2
+ import { ErrorMap, ErrorMapItem, InferSchemaInput, AnySchema, Meta, ContractProcedureDef, InferSchemaOutput, ErrorFromErrorMap, AnyContractRouter, ContractProcedure } from '@orpc/contract';
3
+ import { MaybeOptionalOptions, Promisable, Interceptor, PromiseWithError, Value } from '@orpc/shared';
4
+
5
+ type Context = Record<PropertyKey, any>;
6
+ type MergedInitialContext<TInitial extends Context, TAdditional extends Context, TCurrent extends Context> = TInitial & Omit<TAdditional, keyof TCurrent>;
7
+ type MergedCurrentContext<T extends Context, U extends Context> = Omit<T, keyof U> & U;
8
+ declare function mergeCurrentContext<T extends Context, U extends Context>(context: T, other: U): MergedCurrentContext<T, U>;
9
+
10
+ type ORPCErrorConstructorMapItemOptions<TData> = Omit<ORPCErrorOptions<TData>, 'defined' | 'status'>;
11
+ type ORPCErrorConstructorMapItem<TCode extends ORPCErrorCode, TInData> = (...rest: MaybeOptionalOptions<ORPCErrorConstructorMapItemOptions<TInData>>) => ORPCError<TCode, TInData>;
12
+ type ORPCErrorConstructorMap<T extends ErrorMap> = {
13
+ [K in keyof T]: K extends ORPCErrorCode ? T[K] extends ErrorMapItem<infer UInputSchema> ? ORPCErrorConstructorMapItem<K, InferSchemaInput<UInputSchema>> : never : never;
14
+ };
15
+ declare function createORPCErrorConstructorMap<T extends ErrorMap>(errors: T): ORPCErrorConstructorMap<T>;
16
+
17
+ declare const LAZY_SYMBOL: unique symbol;
18
+ interface LazyMeta {
19
+ prefix?: HTTPPath;
20
+ }
21
+ interface Lazy<T> {
22
+ [LAZY_SYMBOL]: {
23
+ loader: () => Promise<{
24
+ default: T;
25
+ }>;
26
+ meta: LazyMeta;
27
+ };
28
+ }
29
+ type Lazyable<T> = T | Lazy<T>;
30
+ /**
31
+ * Creates a lazy-loaded item.
32
+ *
33
+ * @warning The `prefix` in `meta` only holds metadata and does not apply the prefix to the lazy router, use `os.prefix(...).lazy(...)` instead.
34
+ */
35
+ declare function lazy<T>(loader: () => Promise<{
36
+ default: T;
37
+ }>, meta?: LazyMeta): Lazy<T>;
38
+ declare function isLazy(item: unknown): item is Lazy<any>;
39
+ declare function getLazyMeta(lazied: Lazy<any>): LazyMeta;
40
+ declare function unlazy<T extends Lazyable<any>>(lazied: T): Promise<{
41
+ default: T extends Lazy<infer U> ? U : T;
42
+ }>;
43
+
44
+ interface ProcedureHandlerOptions<TCurrentContext extends Context, TInput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
45
+ context: TCurrentContext;
46
+ input: TInput;
47
+ path: readonly string[];
48
+ procedure: Procedure<Context, Context, AnySchema, AnySchema, ErrorMap, TMeta>;
49
+ signal?: AbortSignal;
50
+ lastEventId: string | undefined;
51
+ errors: TErrorConstructorMap;
52
+ }
53
+ interface ProcedureHandler<TCurrentContext extends Context, TInput, THandlerOutput, TErrorMap extends ErrorMap, TMeta extends Meta> {
54
+ (opt: ProcedureHandlerOptions<TCurrentContext, TInput, ORPCErrorConstructorMap<TErrorMap>, TMeta>): Promisable<THandlerOutput>;
55
+ }
56
+ 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> {
57
+ __initialContext?: (type: TInitialContext) => unknown;
58
+ middlewares: readonly AnyMiddleware[];
59
+ inputValidationIndex: number;
60
+ outputValidationIndex: number;
61
+ handler: ProcedureHandler<TCurrentContext, any, any, any, any>;
62
+ }
63
+ /**
64
+ * This class represents a procedure.
65
+ *
66
+ * @see {@link https://orpc.dev/docs/procedure Procedure Docs}
67
+ */
68
+ declare class Procedure<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
69
+ /**
70
+ * This property holds the defined options.
71
+ */
72
+ '~orpc': ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
73
+ constructor(def: ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>);
74
+ }
75
+ type AnyProcedure = Procedure<any, any, any, any, any, any>;
76
+ declare function isProcedure(item: unknown): item is AnyProcedure;
77
+
78
+ type MiddlewareResult<TOutContext extends Context, TOutput> = Promisable<{
79
+ output: TOutput;
80
+ context: TOutContext;
81
+ }>;
82
+ type MiddlewareNextFnOptions<TOutContext extends Context> = Record<never, never> extends TOutContext ? {
83
+ context?: TOutContext;
84
+ } : {
85
+ context: TOutContext;
86
+ };
87
+ interface MiddlewareNextFn<TOutput> {
88
+ <U extends Context = Record<never, never>>(...rest: MaybeOptionalOptions<MiddlewareNextFnOptions<U>>): MiddlewareResult<U, TOutput>;
89
+ }
90
+ interface MiddlewareOutputFn<TOutput> {
91
+ (output: TOutput): MiddlewareResult<Record<never, never>, TOutput>;
92
+ }
93
+ interface MiddlewareOptions<TInContext extends Context, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
94
+ context: TInContext;
95
+ path: readonly string[];
96
+ procedure: Procedure<Context, Context, AnySchema, AnySchema, ErrorMap, TMeta>;
97
+ signal?: AbortSignal;
98
+ lastEventId: string | undefined;
99
+ next: MiddlewareNextFn<TOutput>;
100
+ errors: TErrorConstructorMap;
101
+ }
102
+ /**
103
+ * A function that represents a middleware.
104
+ *
105
+ * @see {@link https://orpc.dev/docs/middleware Middleware Docs}
106
+ */
107
+ interface Middleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
108
+ (options: MiddlewareOptions<TInContext, TOutput, TErrorConstructorMap, TMeta>, input: TInput, output: MiddlewareOutputFn<TOutput>): Promisable<MiddlewareResult<TOutContext, TOutput>>;
109
+ }
110
+ type AnyMiddleware = Middleware<any, any, any, any, any, any>;
111
+ interface MapInputMiddleware<TInput, TMappedInput> {
112
+ (input: TInput): TMappedInput;
113
+ }
114
+ declare function middlewareOutputFn<TOutput>(output: TOutput): MiddlewareResult<Record<never, never>, TOutput>;
115
+
116
+ type ProcedureClient<TClientContext extends ClientContext, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> = Client<TClientContext, InferSchemaInput<TInputSchema>, InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>;
117
+ interface ProcedureClientInterceptorOptions<TInitialContext extends Context, TErrorMap extends ErrorMap, TMeta extends Meta> {
118
+ context: TInitialContext;
119
+ input: unknown;
120
+ errors: ORPCErrorConstructorMap<TErrorMap>;
121
+ path: readonly string[];
122
+ procedure: Procedure<Context, Context, AnySchema, AnySchema, ErrorMap, TMeta>;
123
+ signal?: AbortSignal;
124
+ lastEventId: string | undefined;
125
+ }
126
+ type CreateProcedureClientOptions<TInitialContext extends Context, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext> = {
127
+ /**
128
+ * This is helpful for logging and analytics.
129
+ */
130
+ path?: readonly string[];
131
+ interceptors?: Interceptor<ProcedureClientInterceptorOptions<TInitialContext, TErrorMap, TMeta>, PromiseWithError<InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>>[];
132
+ } & (Record<never, never> extends TInitialContext ? {
133
+ context?: Value<Promisable<TInitialContext>, [clientContext: TClientContext]>;
134
+ } : {
135
+ context: Value<Promisable<TInitialContext>, [clientContext: TClientContext]>;
136
+ });
137
+ /**
138
+ * Create Server-side client from a procedure.
139
+ *
140
+ * @see {@link https://orpc.dev/docs/client/server-side Server-side Client Docs}
141
+ */
142
+ 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>>, ...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TOutputSchema, TErrorMap, TMeta, TClientContext>>): ProcedureClient<TClientContext, TInputSchema, TOutputSchema, TErrorMap>;
143
+
144
+ /**
145
+ * Represents a router, which defines a hierarchical structure of procedures.
146
+ *
147
+ * @info A procedure is a router too.
148
+ * @see {@link https://orpc.dev/docs/contract-first/define-contract#contract-router Contract Router Docs}
149
+ */
150
+ 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> : {
151
+ [K in keyof T]: T[K] extends AnyContractRouter ? Lazyable<Router<T[K], TInitialContext>> : never;
152
+ };
153
+ type AnyRouter = Router<any, any>;
154
+ type InferRouterInitialContext<T extends AnyRouter> = T extends Router<any, infer UInitialContext> ? UInitialContext : never;
155
+ /**
156
+ * Infer all initial context of the router.
157
+ *
158
+ * @info A procedure is a router too.
159
+ * @see {@link https://orpc.dev/docs/router#utilities Router Utilities Docs}
160
+ */
161
+ type InferRouterInitialContexts<T extends AnyRouter> = T extends Procedure<infer UInitialContext, any, any, any, any, any> ? UInitialContext : {
162
+ [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInitialContexts<U> : never;
163
+ };
164
+ /**
165
+ * Infer all current context of the router.
166
+ *
167
+ * @info A procedure is a router too.
168
+ * @see {@link https://orpc.dev/docs/router#utilities Router Utilities Docs}
169
+ */
170
+ type InferRouterCurrentContexts<T extends AnyRouter> = T extends Procedure<any, infer UCurrentContext, any, any, any, any> ? UCurrentContext : {
171
+ [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterCurrentContexts<U> : never;
172
+ };
173
+ /**
174
+ * Infer all router inputs
175
+ *
176
+ * @info A procedure is a router too.
177
+ * @see {@link https://orpc.dev/docs/router#utilities Router Utilities Docs}
178
+ */
179
+ type InferRouterInputs<T extends AnyRouter> = T extends Procedure<any, any, infer UInputSchema, any, any, any> ? InferSchemaInput<UInputSchema> : {
180
+ [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInputs<U> : never;
181
+ };
182
+ /**
183
+ * Infer all router outputs
184
+ *
185
+ * @info A procedure is a router too.
186
+ * @see {@link https://orpc.dev/docs/router#utilities Router Utilities Docs}
187
+ */
188
+ type InferRouterOutputs<T extends AnyRouter> = T extends Procedure<any, any, any, infer UOutputSchema, any, any> ? InferSchemaOutput<UOutputSchema> : {
189
+ [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterOutputs<U> : never;
190
+ };
191
+
192
+ export { isProcedure as E, createProcedureClient as F, Procedure as P, mergeCurrentContext as m, createORPCErrorConstructorMap as n, LAZY_SYMBOL as o, lazy as q, isLazy as r, getLazyMeta as s, unlazy as u, middlewareOutputFn as z };
193
+ export type { AnyProcedure as A, ProcedureHandlerOptions as B, Context as C, ProcedureDef as D, InferRouterInitialContexts as G, InferRouterCurrentContexts as H, InferRouterInitialContext as I, InferRouterInputs as J, InferRouterOutputs as K, Lazyable as L, MergedInitialContext as M, ORPCErrorConstructorMap as O, Router as R, AnyMiddleware as a, AnyRouter as b, Lazy as c, ProcedureClientInterceptorOptions as d, Middleware as e, MergedCurrentContext as f, MapInputMiddleware as g, CreateProcedureClientOptions as h, ProcedureClient as i, ProcedureHandler as j, ORPCErrorConstructorMapItemOptions as k, ORPCErrorConstructorMapItem as l, LazyMeta as p, MiddlewareResult as t, MiddlewareNextFnOptions as v, MiddlewareNextFn as w, MiddlewareOutputFn as x, MiddlewareOptions as y };
@@ -0,0 +1,32 @@
1
+ import { StandardRPCJsonSerializerOptions } from '@orpc/client/standard';
2
+ import { b as AnyRouter, C as Context, R as Router } from './server.qKsRrdxW.js';
3
+ import { i as StandardMatcher, h as StandardMatchResult, e as StandardHandlerOptions, f as StandardHandler } from './server.7cEtMB30.js';
4
+ import { HTTPPath } from '@orpc/client';
5
+ import { Value } from '@orpc/shared';
6
+ import { T as TraverseContractProcedureCallbackOptions } from './server.ChyoA9XY.js';
7
+
8
+ interface StandardRPCMatcherOptions {
9
+ /**
10
+ * Filter procedures. Return `false` to exclude a procedure from matching.
11
+ *
12
+ * @default true
13
+ */
14
+ filter?: Value<boolean, [options: TraverseContractProcedureCallbackOptions]>;
15
+ }
16
+ declare class StandardRPCMatcher implements StandardMatcher {
17
+ private readonly filter;
18
+ private readonly tree;
19
+ private pendingRouters;
20
+ constructor(options?: StandardRPCMatcherOptions);
21
+ init(router: AnyRouter, path?: readonly string[]): void;
22
+ match(_method: string, pathname: HTTPPath): Promise<StandardMatchResult>;
23
+ }
24
+
25
+ interface StandardRPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, StandardRPCJsonSerializerOptions, StandardRPCMatcherOptions {
26
+ }
27
+ declare class StandardRPCHandler<T extends Context> extends StandardHandler<T> {
28
+ constructor(router: Router<any, T>, options?: StandardRPCHandlerOptions<T>);
29
+ }
30
+
31
+ export { StandardRPCHandler as a, StandardRPCMatcher as c };
32
+ export type { StandardRPCHandlerOptions as S, StandardRPCMatcherOptions as b };
package/package.json CHANGED
@@ -1,52 +1,134 @@
1
1
  {
2
2
  "name": "@orpc/server",
3
3
  "type": "module",
4
- "version": "0.0.0-next.8b5a6d6",
4
+ "version": "0.0.0-next.8b973a6",
5
5
  "license": "MIT",
6
- "homepage": "https://orpc.unnoq.com",
6
+ "homepage": "https://orpc.dev",
7
7
  "repository": {
8
8
  "type": "git",
9
- "url": "git+https://github.com/unnoq/orpc.git",
9
+ "url": "git+https://github.com/middleapi/orpc.git",
10
10
  "directory": "packages/server"
11
11
  },
12
12
  "keywords": [
13
- "unnoq",
14
13
  "orpc"
15
14
  ],
16
15
  "exports": {
17
16
  ".": {
18
- "types": "./dist/src/index.d.ts",
19
- "import": "./dist/index.js",
20
- "default": "./dist/index.js"
17
+ "types": "./dist/index.d.mts",
18
+ "import": "./dist/index.mjs",
19
+ "default": "./dist/index.mjs"
20
+ },
21
+ "./helpers": {
22
+ "types": "./dist/helpers/index.d.mts",
23
+ "import": "./dist/helpers/index.mjs",
24
+ "default": "./dist/helpers/index.mjs"
25
+ },
26
+ "./plugins": {
27
+ "types": "./dist/plugins/index.d.mts",
28
+ "import": "./dist/plugins/index.mjs",
29
+ "default": "./dist/plugins/index.mjs"
30
+ },
31
+ "./hibernation": {
32
+ "types": "./dist/hibernation/index.d.mts",
33
+ "import": "./dist/hibernation/index.mjs",
34
+ "default": "./dist/hibernation/index.mjs"
35
+ },
36
+ "./standard": {
37
+ "types": "./dist/adapters/standard/index.d.mts",
38
+ "import": "./dist/adapters/standard/index.mjs",
39
+ "default": "./dist/adapters/standard/index.mjs"
40
+ },
41
+ "./standard-peer": {
42
+ "types": "./dist/adapters/standard-peer/index.d.mts",
43
+ "import": "./dist/adapters/standard-peer/index.mjs",
44
+ "default": "./dist/adapters/standard-peer/index.mjs"
21
45
  },
22
46
  "./fetch": {
23
- "types": "./dist/src/fetch/index.d.ts",
24
- "import": "./dist/fetch.js",
25
- "default": "./dist/fetch.js"
47
+ "types": "./dist/adapters/fetch/index.d.mts",
48
+ "import": "./dist/adapters/fetch/index.mjs",
49
+ "default": "./dist/adapters/fetch/index.mjs"
50
+ },
51
+ "./node": {
52
+ "types": "./dist/adapters/node/index.d.mts",
53
+ "import": "./dist/adapters/node/index.mjs",
54
+ "default": "./dist/adapters/node/index.mjs"
55
+ },
56
+ "./fastify": {
57
+ "types": "./dist/adapters/fastify/index.d.mts",
58
+ "import": "./dist/adapters/fastify/index.mjs",
59
+ "default": "./dist/adapters/fastify/index.mjs"
60
+ },
61
+ "./aws-lambda": {
62
+ "types": "./dist/adapters/aws-lambda/index.d.mts",
63
+ "import": "./dist/adapters/aws-lambda/index.mjs",
64
+ "default": "./dist/adapters/aws-lambda/index.mjs"
26
65
  },
27
- "./🔒/*": {
28
- "types": "./dist/src/*.d.ts"
66
+ "./websocket": {
67
+ "types": "./dist/adapters/websocket/index.d.mts",
68
+ "import": "./dist/adapters/websocket/index.mjs",
69
+ "default": "./dist/adapters/websocket/index.mjs"
70
+ },
71
+ "./crossws": {
72
+ "types": "./dist/adapters/crossws/index.d.mts",
73
+ "import": "./dist/adapters/crossws/index.mjs",
74
+ "default": "./dist/adapters/crossws/index.mjs"
75
+ },
76
+ "./ws": {
77
+ "types": "./dist/adapters/ws/index.d.mts",
78
+ "import": "./dist/adapters/ws/index.mjs",
79
+ "default": "./dist/adapters/ws/index.mjs"
80
+ },
81
+ "./bun-ws": {
82
+ "types": "./dist/adapters/bun-ws/index.d.mts",
83
+ "import": "./dist/adapters/bun-ws/index.mjs",
84
+ "default": "./dist/adapters/bun-ws/index.mjs"
85
+ },
86
+ "./message-port": {
87
+ "types": "./dist/adapters/message-port/index.d.mts",
88
+ "import": "./dist/adapters/message-port/index.mjs",
89
+ "default": "./dist/adapters/message-port/index.mjs"
29
90
  }
30
91
  },
31
92
  "files": [
32
- "!**/*.map",
33
- "!**/*.tsbuildinfo",
34
93
  "dist"
35
94
  ],
36
95
  "peerDependencies": {
37
- "zod": ">=3.23.0",
38
- "@orpc/zod": "0.0.0-next.8b5a6d6"
96
+ "crossws": ">=0.3.4",
97
+ "ws": ">=8.18.1"
98
+ },
99
+ "peerDependenciesMeta": {
100
+ "crossws": {
101
+ "optional": true
102
+ },
103
+ "ws": {
104
+ "optional": true
105
+ }
39
106
  },
40
107
  "dependencies": {
41
- "@orpc/shared": "0.0.0-next.8b5a6d6",
42
- "@orpc/contract": "0.0.0-next.8b5a6d6",
43
- "@orpc/transformer": "0.0.0-next.8b5a6d6"
108
+ "cookie": "^1.1.1",
109
+ "@orpc/contract": "0.0.0-next.8b973a6",
110
+ "@orpc/interop": "0.0.0-next.8b973a6",
111
+ "@orpc/client": "0.0.0-next.8b973a6",
112
+ "@orpc/shared": "0.0.0-next.8b973a6",
113
+ "@orpc/standard-server-aws-lambda": "0.0.0-next.8b973a6",
114
+ "@orpc/standard-server-fastify": "0.0.0-next.8b973a6",
115
+ "@orpc/standard-server-fetch": "0.0.0-next.8b973a6",
116
+ "@orpc/standard-server": "0.0.0-next.8b973a6",
117
+ "@orpc/standard-server-node": "0.0.0-next.8b973a6",
118
+ "@orpc/standard-server-peer": "0.0.0-next.8b973a6"
44
119
  },
45
120
  "devDependencies": {
46
- "@orpc/openapi": "0.0.0-next.8b5a6d6"
121
+ "@tanstack/router-core": "^1.158.1",
122
+ "@types/ws": "^8.18.1",
123
+ "crossws": "^0.4.4",
124
+ "fastify": "^5.7.4",
125
+ "next": "^16.1.6",
126
+ "supertest": "^7.1.4",
127
+ "ws": "^8.18.3",
128
+ "zod": "^4.3.6"
47
129
  },
48
130
  "scripts": {
49
- "build": "tsup --clean --sourcemap --entry.index=src/index.ts --entry.fetch=src/fetch/index.ts --format=esm --onSuccess='tsc -b --noCheck'",
131
+ "build": "unbuild",
50
132
  "build:watch": "pnpm run build --watch",
51
133
  "type:check": "tsc -b"
52
134
  }
@@ -1,274 +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/middleware.ts
14
- var decoratedMiddlewareSymbol = Symbol("\u{1F512}decoratedMiddleware");
15
- function decorateMiddleware(middleware) {
16
- if (Reflect.get(middleware, decoratedMiddlewareSymbol)) {
17
- return middleware;
18
- }
19
- const concat = (concatMiddleware, mapInput2) => {
20
- const concatMiddleware_ = mapInput2 ? decorateMiddleware(concatMiddleware).mapInput(mapInput2) : concatMiddleware;
21
- return decorateMiddleware(async (input, context, meta, ...rest) => {
22
- const input_ = input;
23
- const context_ = context;
24
- const meta_ = meta;
25
- const next = async (options) => {
26
- return concatMiddleware_(input_, mergeContext(context_, options.context), meta_, ...rest);
27
- };
28
- const m1 = await middleware(input_, context_, {
29
- ...meta_,
30
- next
31
- }, ...rest);
32
- return m1;
33
- });
34
- };
35
- const mapInput = (map) => {
36
- return decorateMiddleware(
37
- (input, ...rest) => middleware(map(input), ...rest)
38
- );
39
- };
40
- return Object.assign(middleware, {
41
- [decoratedMiddlewareSymbol]: true,
42
- concat,
43
- mapInput
44
- });
45
- }
46
-
47
- // src/procedure-caller.ts
48
- import { executeWithHooks, trim, value } from "@orpc/shared";
49
- import { ORPCError } from "@orpc/shared/error";
50
-
51
- // src/procedure.ts
52
- import {
53
- DecoratedContractProcedure,
54
- isContractProcedure
55
- } from "@orpc/contract";
56
- var Procedure = class {
57
- constructor(zz$p) {
58
- this.zz$p = zz$p;
59
- }
60
- };
61
- var DECORATED_PROCEDURE_SYMBOL = Symbol("DECORATED_PROCEDURE");
62
- function decorateProcedure(procedure) {
63
- if (DECORATED_PROCEDURE_SYMBOL in procedure) {
64
- return procedure;
65
- }
66
- return Object.assign(createProcedureCaller({
67
- procedure,
68
- context: void 0
69
- }), {
70
- [DECORATED_PROCEDURE_SYMBOL]: true,
71
- zz$p: procedure.zz$p,
72
- prefix(prefix) {
73
- return decorateProcedure({
74
- zz$p: {
75
- ...procedure.zz$p,
76
- contract: DecoratedContractProcedure.decorate(
77
- procedure.zz$p.contract
78
- ).prefix(prefix)
79
- }
80
- });
81
- },
82
- route(opts) {
83
- return decorateProcedure({
84
- zz$p: {
85
- ...procedure.zz$p,
86
- contract: DecoratedContractProcedure.decorate(
87
- procedure.zz$p.contract
88
- ).route(opts)
89
- }
90
- });
91
- },
92
- use(middleware, mapInput) {
93
- const middleware_ = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
94
- return decorateProcedure({
95
- zz$p: {
96
- ...procedure.zz$p,
97
- middlewares: [middleware_, ...procedure.zz$p.middlewares ?? []]
98
- }
99
- });
100
- }
101
- });
102
- }
103
- function isProcedure(item) {
104
- if (item instanceof Procedure)
105
- return true;
106
- return (typeof item === "object" || typeof item === "function") && item !== null && "zz$p" in item && typeof item.zz$p === "object" && item.zz$p !== null && "contract" in item.zz$p && isContractProcedure(item.zz$p.contract) && "func" in item.zz$p && typeof item.zz$p.func === "function";
107
- }
108
-
109
- // src/procedure-caller.ts
110
- function createProcedureCaller(options) {
111
- const caller = async (...args) => {
112
- const [input, callerOptions] = args;
113
- const path = options.path ?? [];
114
- const procedure = await loadProcedure(options.procedure);
115
- const context = await value(options.context);
116
- const execute = async () => {
117
- const validInput = (() => {
118
- const schema = procedure.zz$p.contract.zz$cp.InputSchema;
119
- if (!schema) {
120
- return input;
121
- }
122
- try {
123
- return schema.parse(input);
124
- } catch (e) {
125
- throw new ORPCError({
126
- message: "Validation input failed",
127
- code: "BAD_REQUEST",
128
- cause: e
129
- });
130
- }
131
- })();
132
- const meta = {
133
- path,
134
- procedure,
135
- signal: callerOptions?.signal
136
- };
137
- const middlewares = procedure.zz$p.middlewares ?? [];
138
- let currentMidIndex = 0;
139
- let currentContext = context;
140
- const next = async (nextOptions) => {
141
- const mid = middlewares[currentMidIndex];
142
- currentMidIndex += 1;
143
- currentContext = mergeContext(currentContext, nextOptions.context);
144
- if (mid) {
145
- return await mid(validInput, currentContext, {
146
- ...meta,
147
- next,
148
- output: (output3) => ({ output: output3, context: void 0 })
149
- });
150
- } else {
151
- return {
152
- output: await await procedure.zz$p.func(validInput, currentContext, meta),
153
- context: currentContext
154
- };
155
- }
156
- };
157
- const output2 = (await next({})).output;
158
- const validOutput = await (async () => {
159
- const schema = procedure.zz$p.contract.zz$cp.OutputSchema;
160
- if (!schema) {
161
- return output2;
162
- }
163
- const result = await schema.safeParseAsync(output2);
164
- if (result.error) {
165
- throw new ORPCError({
166
- message: "Validation output failed",
167
- code: "INTERNAL_SERVER_ERROR",
168
- cause: result.error
169
- });
170
- }
171
- return result.data;
172
- })();
173
- return validOutput;
174
- };
175
- const output = await executeWithHooks({
176
- hooks: options,
177
- input,
178
- context,
179
- meta: {
180
- path,
181
- procedure
182
- },
183
- execute
184
- });
185
- return output;
186
- };
187
- return caller;
188
- }
189
- async function loadProcedure(procedure) {
190
- let loadedProcedure;
191
- if (isLazy(procedure)) {
192
- loadedProcedure = (await loadLazy(procedure)).default;
193
- } else {
194
- loadedProcedure = procedure;
195
- }
196
- if (!isProcedure(loadedProcedure)) {
197
- throw new ORPCError({
198
- code: "NOT_FOUND",
199
- message: "Not found",
200
- cause: new Error(trim(`
201
- This error should be caught by the typescript compiler.
202
- But if you still see this error, it means that you trying to call a lazy router (expected to be a lazy procedure).
203
- `))
204
- });
205
- }
206
- return loadedProcedure;
207
- }
208
-
209
- // src/lazy.ts
210
- var LAZY_LOADER_SYMBOL = Symbol("ORPC_LAZY_LOADER");
211
- function createLazy(loader) {
212
- return {
213
- [LAZY_LOADER_SYMBOL]: loader
214
- };
215
- }
216
- function loadLazy(lazy) {
217
- return lazy[LAZY_LOADER_SYMBOL]();
218
- }
219
- function isLazy(item) {
220
- return (typeof item === "object" || typeof item === "function") && item !== null && LAZY_LOADER_SYMBOL in item && typeof item[LAZY_LOADER_SYMBOL] === "function";
221
- }
222
- function createFlattenLazy(lazy) {
223
- const flattenLoader = async () => {
224
- let current = await loadLazy(lazy);
225
- while (true) {
226
- if (!isLazy(current.default)) {
227
- break;
228
- }
229
- current = await loadLazy(current.default);
230
- }
231
- return current;
232
- };
233
- const flattenLazy = {
234
- [LAZY_LOADER_SYMBOL]: flattenLoader
235
- };
236
- return flattenLazy;
237
- }
238
- function decorateLazy(lazy) {
239
- const flattenLazy = createFlattenLazy(lazy);
240
- const procedureCaller = createProcedureCaller({
241
- procedure: flattenLazy,
242
- context: void 0
243
- });
244
- Object.assign(procedureCaller, flattenLazy);
245
- const recursive = new Proxy(procedureCaller, {
246
- get(target, key) {
247
- if (typeof key !== "string") {
248
- return Reflect.get(target, key);
249
- }
250
- return decorateLazy(createLazy(async () => {
251
- const current = await loadLazy(flattenLazy);
252
- return { default: current.default[key] };
253
- }));
254
- }
255
- });
256
- return recursive;
257
- }
258
-
259
- export {
260
- mergeContext,
261
- decorateMiddleware,
262
- LAZY_LOADER_SYMBOL,
263
- createLazy,
264
- loadLazy,
265
- isLazy,
266
- createFlattenLazy,
267
- decorateLazy,
268
- createProcedureCaller,
269
- loadProcedure,
270
- Procedure,
271
- decorateProcedure,
272
- isProcedure
273
- };
274
- //# sourceMappingURL=chunk-3JMSDC5L.js.map