@orpc/server 0.0.0-next.fd1db03 → 0.0.0-next.fd1ee2a

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 (86) hide show
  1. package/README.md +126 -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 +41 -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 +47 -0
  11. package/dist/adapters/fetch/index.d.mts +79 -0
  12. package/dist/adapters/fetch/index.d.ts +79 -0
  13. package/dist/adapters/fetch/index.mjs +110 -0
  14. package/dist/adapters/message-port/index.d.mts +31 -0
  15. package/dist/adapters/message-port/index.d.ts +31 -0
  16. package/dist/adapters/message-port/index.mjs +41 -0
  17. package/dist/adapters/node/index.d.mts +78 -0
  18. package/dist/adapters/node/index.d.ts +78 -0
  19. package/dist/adapters/node/index.mjs +95 -0
  20. package/dist/adapters/standard/index.d.mts +21 -0
  21. package/dist/adapters/standard/index.d.ts +21 -0
  22. package/dist/adapters/standard/index.mjs +8 -0
  23. package/dist/adapters/standard-peer/index.d.mts +14 -0
  24. package/dist/adapters/standard-peer/index.d.ts +14 -0
  25. package/dist/adapters/standard-peer/index.mjs +7 -0
  26. package/dist/adapters/websocket/index.d.mts +54 -0
  27. package/dist/adapters/websocket/index.d.ts +54 -0
  28. package/dist/adapters/websocket/index.mjs +69 -0
  29. package/dist/adapters/ws/index.d.mts +31 -0
  30. package/dist/adapters/ws/index.d.ts +31 -0
  31. package/dist/adapters/ws/index.mjs +39 -0
  32. package/dist/hibernation/index.d.mts +44 -0
  33. package/dist/hibernation/index.d.ts +44 -0
  34. package/dist/hibernation/index.mjs +65 -0
  35. package/dist/index.d.mts +803 -0
  36. package/dist/index.d.ts +803 -0
  37. package/dist/index.mjs +489 -0
  38. package/dist/plugins/index.d.mts +156 -0
  39. package/dist/plugins/index.d.ts +156 -0
  40. package/dist/plugins/index.mjs +259 -0
  41. package/dist/shared/server.BW-nUGgA.mjs +36 -0
  42. package/dist/shared/server.C6Q5sqYw.mjs +20 -0
  43. package/dist/shared/server.CC8z0B3U.d.mts +32 -0
  44. package/dist/shared/server.CIL9uKTN.mjs +194 -0
  45. package/dist/shared/server.CNZgPgce.d.ts +12 -0
  46. package/dist/shared/server.Cu-7se50.d.mts +12 -0
  47. package/dist/shared/server.Cwq7K86l.d.mts +42 -0
  48. package/dist/shared/server.DHgXKx3q.d.mts +74 -0
  49. package/dist/shared/server.DOwaI1le.d.ts +32 -0
  50. package/dist/shared/server.DVBSOxWU.d.ts +74 -0
  51. package/dist/shared/server.DZ5BIITo.mjs +9 -0
  52. package/dist/shared/server.NeumLVdS.mjs +370 -0
  53. package/dist/shared/server.a_VzWVCm.d.ts +42 -0
  54. package/dist/shared/server.wMv480px.d.mts +192 -0
  55. package/dist/shared/server.wMv480px.d.ts +192 -0
  56. package/package.json +87 -15
  57. package/dist/chunk-6A7XHEBH.js +0 -189
  58. package/dist/fetch.js +0 -324
  59. package/dist/index.js +0 -518
  60. package/dist/src/builder.d.ts +0 -35
  61. package/dist/src/fetch/composite-handler.d.ts +0 -8
  62. package/dist/src/fetch/index.d.ts +0 -7
  63. package/dist/src/fetch/orpc-handler.d.ts +0 -20
  64. package/dist/src/fetch/orpc-payload-codec.d.ts +0 -16
  65. package/dist/src/fetch/orpc-procedure-matcher.d.ts +0 -12
  66. package/dist/src/fetch/super-json.d.ts +0 -12
  67. package/dist/src/fetch/types.d.ts +0 -16
  68. package/dist/src/hidden.d.ts +0 -6
  69. package/dist/src/implementer-chainable.d.ts +0 -10
  70. package/dist/src/index.d.ts +0 -23
  71. package/dist/src/lazy-decorated.d.ts +0 -10
  72. package/dist/src/lazy-utils.d.ts +0 -4
  73. package/dist/src/lazy.d.ts +0 -18
  74. package/dist/src/middleware-decorated.d.ts +0 -8
  75. package/dist/src/middleware.d.ts +0 -23
  76. package/dist/src/procedure-builder.d.ts +0 -22
  77. package/dist/src/procedure-client.d.ts +0 -34
  78. package/dist/src/procedure-decorated.d.ts +0 -14
  79. package/dist/src/procedure-implementer.d.ts +0 -18
  80. package/dist/src/procedure.d.ts +0 -23
  81. package/dist/src/router-builder.d.ts +0 -29
  82. package/dist/src/router-client.d.ts +0 -25
  83. package/dist/src/router-implementer.d.ts +0 -21
  84. package/dist/src/router.d.ts +0 -16
  85. package/dist/src/types.d.ts +0 -12
  86. package/dist/src/utils.d.ts +0 -3
@@ -0,0 +1,192 @@
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
+ declare function validateORPCError(map: ErrorMap, error: ORPCError<any, any>): Promise<ORPCError<string, unknown>>;
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
+ /**
32
+ * Create a lazy thing.
33
+ */
34
+ declare function lazy<T>(loader: () => Promise<{
35
+ default: T;
36
+ }>, meta?: LazyMeta): Lazy<T>;
37
+ declare function isLazy(item: unknown): item is Lazy<any>;
38
+ declare function getLazyMeta(lazied: Lazy<any>): LazyMeta;
39
+ declare function unlazy<T extends Lazyable<any>>(lazied: T): Promise<{
40
+ default: T extends Lazy<infer U> ? U : T;
41
+ }>;
42
+
43
+ interface ProcedureHandlerOptions<TCurrentContext extends Context, TInput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
44
+ context: TCurrentContext;
45
+ input: TInput;
46
+ path: readonly string[];
47
+ procedure: Procedure<Context, Context, AnySchema, AnySchema, ErrorMap, TMeta>;
48
+ signal?: AbortSignal;
49
+ lastEventId: string | undefined;
50
+ errors: TErrorConstructorMap;
51
+ }
52
+ interface ProcedureHandler<TCurrentContext extends Context, TInput, THandlerOutput, TErrorMap extends ErrorMap, TMeta extends Meta> {
53
+ (opt: ProcedureHandlerOptions<TCurrentContext, TInput, ORPCErrorConstructorMap<TErrorMap>, TMeta>): Promisable<THandlerOutput>;
54
+ }
55
+ 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> {
56
+ __initialContext?: (type: TInitialContext) => unknown;
57
+ middlewares: readonly AnyMiddleware[];
58
+ inputValidationIndex: number;
59
+ outputValidationIndex: number;
60
+ handler: ProcedureHandler<TCurrentContext, any, any, any, any>;
61
+ }
62
+ /**
63
+ * This class represents a procedure.
64
+ *
65
+ * @see {@link https://orpc.unnoq.com/docs/procedure Procedure Docs}
66
+ */
67
+ declare class Procedure<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
68
+ /**
69
+ * This property holds the defined options.
70
+ */
71
+ '~orpc': ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
72
+ constructor(def: ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>);
73
+ }
74
+ type AnyProcedure = Procedure<any, any, any, any, any, any>;
75
+ declare function isProcedure(item: unknown): item is AnyProcedure;
76
+
77
+ type MiddlewareResult<TOutContext extends Context, TOutput> = Promisable<{
78
+ output: TOutput;
79
+ context: TOutContext;
80
+ }>;
81
+ type MiddlewareNextFnOptions<TOutContext extends Context> = Record<never, never> extends TOutContext ? {
82
+ context?: TOutContext;
83
+ } : {
84
+ context: TOutContext;
85
+ };
86
+ interface MiddlewareNextFn<TOutput> {
87
+ <U extends Context = Record<never, never>>(...rest: MaybeOptionalOptions<MiddlewareNextFnOptions<U>>): MiddlewareResult<U, TOutput>;
88
+ }
89
+ interface MiddlewareOutputFn<TOutput> {
90
+ (output: TOutput): MiddlewareResult<Record<never, never>, TOutput>;
91
+ }
92
+ interface MiddlewareOptions<TInContext extends Context, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
93
+ context: TInContext;
94
+ path: readonly string[];
95
+ procedure: Procedure<Context, Context, AnySchema, AnySchema, ErrorMap, TMeta>;
96
+ signal?: AbortSignal;
97
+ lastEventId: string | undefined;
98
+ next: MiddlewareNextFn<TOutput>;
99
+ errors: TErrorConstructorMap;
100
+ }
101
+ /**
102
+ * A function that represents a middleware.
103
+ *
104
+ * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
105
+ */
106
+ interface Middleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
107
+ (options: MiddlewareOptions<TInContext, TOutput, TErrorConstructorMap, TMeta>, input: TInput, output: MiddlewareOutputFn<TOutput>): Promisable<MiddlewareResult<TOutContext, TOutput>>;
108
+ }
109
+ type AnyMiddleware = Middleware<any, any, any, any, any, any>;
110
+ interface MapInputMiddleware<TInput, TMappedInput> {
111
+ (input: TInput): TMappedInput;
112
+ }
113
+ declare function middlewareOutputFn<TOutput>(output: TOutput): MiddlewareResult<Record<never, never>, TOutput>;
114
+
115
+ type ProcedureClient<TClientContext extends ClientContext, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> = Client<TClientContext, InferSchemaInput<TInputSchema>, InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>;
116
+ interface ProcedureClientInterceptorOptions<TInitialContext extends Context, TErrorMap extends ErrorMap, TMeta extends Meta> {
117
+ context: TInitialContext;
118
+ input: unknown;
119
+ errors: ORPCErrorConstructorMap<TErrorMap>;
120
+ path: readonly string[];
121
+ procedure: Procedure<Context, Context, AnySchema, AnySchema, ErrorMap, TMeta>;
122
+ signal?: AbortSignal;
123
+ lastEventId: string | undefined;
124
+ }
125
+ type CreateProcedureClientOptions<TInitialContext extends Context, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext> = {
126
+ /**
127
+ * This is helpful for logging and analytics.
128
+ */
129
+ path?: readonly string[];
130
+ interceptors?: Interceptor<ProcedureClientInterceptorOptions<TInitialContext, TErrorMap, TMeta>, PromiseWithError<InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>>[];
131
+ } & (Record<never, never> extends TInitialContext ? {
132
+ context?: Value<Promisable<TInitialContext>, [clientContext: TClientContext]>;
133
+ } : {
134
+ context: Value<Promisable<TInitialContext>, [clientContext: TClientContext]>;
135
+ });
136
+ /**
137
+ * Create Server-side client from a procedure.
138
+ *
139
+ * @see {@link https://orpc.unnoq.com/docs/client/server-side Server-side Client Docs}
140
+ */
141
+ 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>;
142
+
143
+ /**
144
+ * Represents a router, which defines a hierarchical structure of procedures.
145
+ *
146
+ * @info A procedure is a router too.
147
+ * @see {@link https://orpc.unnoq.com/docs/contract-first/define-contract#contract-router Contract Router Docs}
148
+ */
149
+ 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> : {
150
+ [K in keyof T]: T[K] extends AnyContractRouter ? Lazyable<Router<T[K], TInitialContext>> : never;
151
+ };
152
+ type AnyRouter = Router<any, any>;
153
+ type InferRouterInitialContext<T extends AnyRouter> = T extends Router<any, infer UInitialContext> ? UInitialContext : never;
154
+ /**
155
+ * Infer all initial context of the router.
156
+ *
157
+ * @info A procedure is a router too.
158
+ * @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
159
+ */
160
+ type InferRouterInitialContexts<T extends AnyRouter> = T extends Procedure<infer UInitialContext, any, any, any, any, any> ? UInitialContext : {
161
+ [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInitialContexts<U> : never;
162
+ };
163
+ /**
164
+ * Infer all current context of the router.
165
+ *
166
+ * @info A procedure is a router too.
167
+ * @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
168
+ */
169
+ type InferRouterCurrentContexts<T extends AnyRouter> = T extends Procedure<any, infer UCurrentContext, any, any, any, any> ? UCurrentContext : {
170
+ [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterCurrentContexts<U> : never;
171
+ };
172
+ /**
173
+ * Infer all router inputs
174
+ *
175
+ * @info A procedure is a router too.
176
+ * @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
177
+ */
178
+ type InferRouterInputs<T extends AnyRouter> = T extends Procedure<any, any, infer UInputSchema, any, any, any> ? InferSchemaInput<UInputSchema> : {
179
+ [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInputs<U> : never;
180
+ };
181
+ /**
182
+ * Infer all router outputs
183
+ *
184
+ * @info A procedure is a router too.
185
+ * @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
186
+ */
187
+ type InferRouterOutputs<T extends AnyRouter> = T extends Procedure<any, any, any, infer UOutputSchema, any, any> ? InferSchemaOutput<UOutputSchema> : {
188
+ [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterOutputs<U> : never;
189
+ };
190
+
191
+ export { middlewareOutputFn as B, isProcedure as F, createProcedureClient as G, 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, validateORPCError as v };
192
+ export type { AnyProcedure as A, Context as C, ProcedureHandlerOptions as D, ProcedureDef as E, InferRouterInitialContexts as H, InferRouterInitialContext as I, InferRouterCurrentContexts as J, InferRouterInputs as K, Lazyable as L, MergedInitialContext as M, InferRouterOutputs as N, 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 w, MiddlewareNextFn as x, MiddlewareOutputFn as y, MiddlewareOptions as z };
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.fd1db03",
4
+ "version": "0.0.0-next.fd1ee2a",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -15,33 +15,105 @@
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
+ "./hibernation": {
28
+ "types": "./dist/hibernation/index.d.mts",
29
+ "import": "./dist/hibernation/index.mjs",
30
+ "default": "./dist/hibernation/index.mjs"
31
+ },
32
+ "./standard": {
33
+ "types": "./dist/adapters/standard/index.d.mts",
34
+ "import": "./dist/adapters/standard/index.mjs",
35
+ "default": "./dist/adapters/standard/index.mjs"
36
+ },
37
+ "./standard-peer": {
38
+ "types": "./dist/adapters/standard-peer/index.d.mts",
39
+ "import": "./dist/adapters/standard-peer/index.mjs",
40
+ "default": "./dist/adapters/standard-peer/index.mjs"
21
41
  },
22
42
  "./fetch": {
23
- "types": "./dist/src/fetch/index.d.ts",
24
- "import": "./dist/fetch.js",
25
- "default": "./dist/fetch.js"
43
+ "types": "./dist/adapters/fetch/index.d.mts",
44
+ "import": "./dist/adapters/fetch/index.mjs",
45
+ "default": "./dist/adapters/fetch/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"
51
+ },
52
+ "./aws-lambda": {
53
+ "types": "./dist/adapters/aws-lambda/index.d.mts",
54
+ "import": "./dist/adapters/aws-lambda/index.mjs",
55
+ "default": "./dist/adapters/aws-lambda/index.mjs"
56
+ },
57
+ "./websocket": {
58
+ "types": "./dist/adapters/websocket/index.d.mts",
59
+ "import": "./dist/adapters/websocket/index.mjs",
60
+ "default": "./dist/adapters/websocket/index.mjs"
26
61
  },
27
- "./🔒/*": {
28
- "types": "./dist/src/*.d.ts"
62
+ "./crossws": {
63
+ "types": "./dist/adapters/crossws/index.d.mts",
64
+ "import": "./dist/adapters/crossws/index.mjs",
65
+ "default": "./dist/adapters/crossws/index.mjs"
66
+ },
67
+ "./ws": {
68
+ "types": "./dist/adapters/ws/index.d.mts",
69
+ "import": "./dist/adapters/ws/index.mjs",
70
+ "default": "./dist/adapters/ws/index.mjs"
71
+ },
72
+ "./bun-ws": {
73
+ "types": "./dist/adapters/bun-ws/index.d.mts",
74
+ "import": "./dist/adapters/bun-ws/index.mjs",
75
+ "default": "./dist/adapters/bun-ws/index.mjs"
76
+ },
77
+ "./message-port": {
78
+ "types": "./dist/adapters/message-port/index.d.mts",
79
+ "import": "./dist/adapters/message-port/index.mjs",
80
+ "default": "./dist/adapters/message-port/index.mjs"
29
81
  }
30
82
  },
31
83
  "files": [
32
- "!**/*.map",
33
- "!**/*.tsbuildinfo",
34
84
  "dist"
35
85
  ],
86
+ "peerDependencies": {
87
+ "crossws": ">=0.3.4",
88
+ "ws": ">=8.18.1"
89
+ },
90
+ "peerDependenciesMeta": {
91
+ "crossws": {
92
+ "optional": true
93
+ },
94
+ "ws": {
95
+ "optional": true
96
+ }
97
+ },
36
98
  "dependencies": {
37
- "@orpc/contract": "0.0.0-next.fd1db03",
38
- "@orpc/shared": "0.0.0-next.fd1db03"
99
+ "@orpc/contract": "0.0.0-next.fd1ee2a",
100
+ "@orpc/client": "0.0.0-next.fd1ee2a",
101
+ "@orpc/shared": "0.0.0-next.fd1ee2a",
102
+ "@orpc/standard-server": "0.0.0-next.fd1ee2a",
103
+ "@orpc/standard-server-aws-lambda": "0.0.0-next.fd1ee2a",
104
+ "@orpc/standard-server-fetch": "0.0.0-next.fd1ee2a",
105
+ "@orpc/standard-server-peer": "0.0.0-next.fd1ee2a",
106
+ "@orpc/standard-server-node": "0.0.0-next.fd1ee2a"
39
107
  },
40
108
  "devDependencies": {
41
- "zod": "^3.24.1"
109
+ "@types/ws": "^8.18.1",
110
+ "crossws": "^0.4.1",
111
+ "next": "^15.4.1",
112
+ "supertest": "^7.1.3",
113
+ "ws": "^8.18.3"
42
114
  },
43
115
  "scripts": {
44
- "build": "tsup --clean --sourcemap --entry.index=src/index.ts --entry.fetch=src/fetch/index.ts --format=esm --onSuccess='tsc -b --noCheck'",
116
+ "build": "unbuild",
45
117
  "build:watch": "pnpm run build --watch",
46
118
  "type:check": "tsc -b"
47
119
  }
@@ -1,189 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __export = (target, all) => {
3
- for (var name in all)
4
- __defProp(target, name, { get: all[name], enumerable: true });
5
- };
6
-
7
- // src/utils.ts
8
- function mergeContext(a, b) {
9
- if (!a)
10
- return b;
11
- if (!b)
12
- return a;
13
- return {
14
- ...a,
15
- ...b
16
- };
17
- }
18
-
19
- // src/procedure.ts
20
- import { isContractProcedure } from "@orpc/contract";
21
- var Procedure = class {
22
- "~type" = "Procedure";
23
- "~orpc";
24
- constructor(def) {
25
- this["~orpc"] = def;
26
- }
27
- };
28
- function isProcedure(item) {
29
- if (item instanceof Procedure) {
30
- return true;
31
- }
32
- 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";
33
- }
34
-
35
- // src/lazy.ts
36
- var LAZY_LOADER_SYMBOL = Symbol("ORPC_LAZY_LOADER");
37
- function lazy(loader) {
38
- return {
39
- [LAZY_LOADER_SYMBOL]: loader
40
- };
41
- }
42
- function isLazy(item) {
43
- return (typeof item === "object" || typeof item === "function") && item !== null && LAZY_LOADER_SYMBOL in item && typeof item[LAZY_LOADER_SYMBOL] === "function";
44
- }
45
- function unlazy(lazied) {
46
- return isLazy(lazied) ? lazied[LAZY_LOADER_SYMBOL]() : Promise.resolve({ default: lazied });
47
- }
48
- function flatLazy(lazied) {
49
- const flattenLoader = async () => {
50
- let current = await unlazy(lazied);
51
- while (true) {
52
- if (!isLazy(current.default)) {
53
- break;
54
- }
55
- current = await unlazy(current.default);
56
- }
57
- return current;
58
- };
59
- return lazy(flattenLoader);
60
- }
61
-
62
- // src/procedure-client.ts
63
- import { executeWithHooks, value } from "@orpc/shared";
64
- import { ORPCError } from "@orpc/shared/error";
65
- function createProcedureClient(options) {
66
- return async (...[input, callerOptions]) => {
67
- const path = options.path ?? [];
68
- const { default: procedure } = await unlazy(options.procedure);
69
- const context = await value(options.context);
70
- const meta = {
71
- path,
72
- procedure,
73
- signal: callerOptions?.signal
74
- };
75
- const executeWithValidation = async () => {
76
- const validInput = await validateInput(procedure, input);
77
- const output = await executeMiddlewareChain(
78
- procedure,
79
- validInput,
80
- context,
81
- meta
82
- );
83
- return validateOutput(procedure, output);
84
- };
85
- return executeWithHooks({
86
- hooks: options,
87
- input,
88
- context,
89
- meta,
90
- execute: executeWithValidation
91
- });
92
- };
93
- }
94
- async function validateInput(procedure, input) {
95
- const schema = procedure["~orpc"].contract["~orpc"].InputSchema;
96
- if (!schema)
97
- return input;
98
- const result = await schema["~standard"].validate(input);
99
- if (result.issues) {
100
- throw new ORPCError({
101
- message: "Input validation failed",
102
- code: "BAD_REQUEST",
103
- issues: result.issues
104
- });
105
- }
106
- return result.value;
107
- }
108
- async function validateOutput(procedure, output) {
109
- const schema = procedure["~orpc"].contract["~orpc"].OutputSchema;
110
- if (!schema)
111
- return output;
112
- const result = await schema["~standard"].validate(output);
113
- if (result.issues) {
114
- throw new ORPCError({
115
- message: "Output validation failed",
116
- code: "INTERNAL_SERVER_ERROR",
117
- issues: result.issues
118
- });
119
- }
120
- return result.value;
121
- }
122
- async function executeMiddlewareChain(procedure, input, context, meta) {
123
- const middlewares = procedure["~orpc"].middlewares ?? [];
124
- let currentMidIndex = 0;
125
- let currentContext = context;
126
- const next = async (nextOptions) => {
127
- const mid = middlewares[currentMidIndex];
128
- currentMidIndex += 1;
129
- currentContext = mergeContext(currentContext, nextOptions.context);
130
- if (mid) {
131
- return await mid(input, currentContext, {
132
- ...meta,
133
- next,
134
- output: (output) => ({ output, context: void 0 })
135
- });
136
- }
137
- const result = {
138
- output: await procedure["~orpc"].handler(input, currentContext, meta),
139
- context: currentContext
140
- };
141
- return result;
142
- };
143
- return (await next({})).output;
144
- }
145
-
146
- // src/router.ts
147
- function getRouterChild(router, ...path) {
148
- let current = router;
149
- for (let i = 0; i < path.length; i++) {
150
- const segment = path[i];
151
- if (!current) {
152
- return void 0;
153
- }
154
- if (isProcedure(current)) {
155
- return void 0;
156
- }
157
- if (!isLazy(current)) {
158
- current = current[segment];
159
- continue;
160
- }
161
- const lazied = current;
162
- const rest = path.slice(i);
163
- const newLazy = lazy(async () => {
164
- const unwrapped = await unlazy(lazied);
165
- if (!unwrapped.default) {
166
- return unwrapped;
167
- }
168
- const next = getRouterChild(unwrapped.default, ...rest);
169
- return { default: next };
170
- });
171
- return flatLazy(newLazy);
172
- }
173
- return current;
174
- }
175
-
176
- export {
177
- __export,
178
- mergeContext,
179
- Procedure,
180
- isProcedure,
181
- LAZY_LOADER_SYMBOL,
182
- lazy,
183
- isLazy,
184
- unlazy,
185
- flatLazy,
186
- createProcedureClient,
187
- getRouterChild
188
- };
189
- //# sourceMappingURL=chunk-6A7XHEBH.js.map