@orpc/server 0.0.0-next.141bae5 → 0.0.0-next.14dd190

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 (98) 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 +84 -28
  57. package/dist/chunk-3BAPJGK6.js +0 -302
  58. package/dist/chunk-E7GUWVR4.js +0 -186
  59. package/dist/chunk-WUOGVGWG.js +0 -1
  60. package/dist/fetch.js +0 -15
  61. package/dist/hono.js +0 -30
  62. package/dist/index.js +0 -521
  63. package/dist/next.js +0 -36
  64. package/dist/node.js +0 -87
  65. package/dist/src/adapters/fetch/index.d.ts +0 -6
  66. package/dist/src/adapters/fetch/orpc-handler.d.ts +0 -20
  67. package/dist/src/adapters/fetch/orpc-payload-codec.d.ts +0 -16
  68. package/dist/src/adapters/fetch/orpc-procedure-matcher.d.ts +0 -12
  69. package/dist/src/adapters/fetch/super-json.d.ts +0 -12
  70. package/dist/src/adapters/fetch/types.d.ts +0 -21
  71. package/dist/src/adapters/hono/index.d.ts +0 -3
  72. package/dist/src/adapters/hono/middleware.d.ts +0 -12
  73. package/dist/src/adapters/next/index.d.ts +0 -3
  74. package/dist/src/adapters/next/serve.d.ts +0 -19
  75. package/dist/src/adapters/node/index.d.ts +0 -5
  76. package/dist/src/adapters/node/orpc-handler.d.ts +0 -12
  77. package/dist/src/adapters/node/request-listener.d.ts +0 -28
  78. package/dist/src/adapters/node/types.d.ts +0 -22
  79. package/dist/src/builder.d.ts +0 -35
  80. package/dist/src/hidden.d.ts +0 -6
  81. package/dist/src/implementer-chainable.d.ts +0 -10
  82. package/dist/src/index.d.ts +0 -24
  83. package/dist/src/lazy-decorated.d.ts +0 -10
  84. package/dist/src/lazy-utils.d.ts +0 -4
  85. package/dist/src/lazy.d.ts +0 -18
  86. package/dist/src/middleware-decorated.d.ts +0 -8
  87. package/dist/src/middleware.d.ts +0 -33
  88. package/dist/src/procedure-builder.d.ts +0 -22
  89. package/dist/src/procedure-client.d.ts +0 -34
  90. package/dist/src/procedure-decorated.d.ts +0 -14
  91. package/dist/src/procedure-implementer.d.ts +0 -18
  92. package/dist/src/procedure.d.ts +0 -30
  93. package/dist/src/router-builder.d.ts +0 -29
  94. package/dist/src/router-client.d.ts +0 -25
  95. package/dist/src/router-implementer.d.ts +0 -21
  96. package/dist/src/router.d.ts +0 -16
  97. package/dist/src/types.d.ts +0 -14
  98. 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.141bae5",
4
+ "version": "0.0.0-next.14dd190",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -15,49 +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
21
  },
22
- "./fetch": {
23
- "types": "./dist/src/adapters/fetch/index.d.ts",
24
- "import": "./dist/fetch.js",
25
- "default": "./dist/fetch.js"
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"
26
31
  },
27
- "./hono": {
28
- "types": "./dist/src/adapters/hono/index.d.ts",
29
- "import": "./dist/hono.js",
30
- "default": "./dist/hono.js"
32
+ "./standard": {
33
+ "types": "./dist/adapters/standard/index.d.mts",
34
+ "import": "./dist/adapters/standard/index.mjs",
35
+ "default": "./dist/adapters/standard/index.mjs"
31
36
  },
32
- "./next": {
33
- "types": "./dist/src/adapters/next/index.d.ts",
34
- "import": "./dist/next.js",
35
- "default": "./dist/next.js"
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"
41
+ },
42
+ "./fetch": {
43
+ "types": "./dist/adapters/fetch/index.d.mts",
44
+ "import": "./dist/adapters/fetch/index.mjs",
45
+ "default": "./dist/adapters/fetch/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"
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"
61
+ },
62
+ "./crossws": {
63
+ "types": "./dist/adapters/crossws/index.d.mts",
64
+ "import": "./dist/adapters/crossws/index.mjs",
65
+ "default": "./dist/adapters/crossws/index.mjs"
41
66
  },
42
- "./🔒/*": {
43
- "types": "./dist/src/*.d.ts"
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"
44
81
  }
45
82
  },
46
83
  "files": [
47
- "!**/*.map",
48
- "!**/*.tsbuildinfo",
49
84
  "dist"
50
85
  ],
51
86
  "peerDependencies": {
52
- "hono": ">=4.6.0",
53
- "next": ">=14.0.0"
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
+ }
54
97
  },
55
98
  "dependencies": {
56
- "@orpc/contract": "0.0.0-next.141bae5",
57
- "@orpc/shared": "0.0.0-next.141bae5"
99
+ "@orpc/client": "0.0.0-next.14dd190",
100
+ "@orpc/shared": "0.0.0-next.14dd190",
101
+ "@orpc/contract": "0.0.0-next.14dd190",
102
+ "@orpc/standard-server": "0.0.0-next.14dd190",
103
+ "@orpc/standard-server-aws-lambda": "0.0.0-next.14dd190",
104
+ "@orpc/standard-server-node": "0.0.0-next.14dd190",
105
+ "@orpc/standard-server-peer": "0.0.0-next.14dd190",
106
+ "@orpc/standard-server-fetch": "0.0.0-next.14dd190"
107
+ },
108
+ "devDependencies": {
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"
58
114
  },
59
115
  "scripts": {
60
- "build": "tsup --onSuccess='tsc -b --noCheck'",
116
+ "build": "unbuild",
61
117
  "build:watch": "pnpm run build --watch",
62
118
  "type:check": "tsc -b"
63
119
  }
@@ -1,302 +0,0 @@
1
- import {
2
- __export,
3
- createProcedureClient,
4
- getRouterChild,
5
- isProcedure,
6
- unlazy
7
- } from "./chunk-E7GUWVR4.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 { findDeepMatches, set } from "@orpc/shared";
134
- import { ORPCError } from "@orpc/shared/error";
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 { executeWithHooks, trim as trim2 } from "@orpc/shared";
240
- import { ORPCError as ORPCError2 } from "@orpc/shared/error";
241
- var ORPCHandler = 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({
260
- context,
261
- procedure: match.procedure,
262
- path: match.path
263
- });
264
- const output = await client(input, { signal: request.signal });
265
- const { body, headers } = this.payloadCodec.encode(output);
266
- const response = new Response(body, { headers });
267
- return { matched: true, response };
268
- };
269
- try {
270
- const result = await executeWithHooks({
271
- context,
272
- execute,
273
- input: request,
274
- hooks: this.options,
275
- meta: {
276
- signal: request.signal
277
- }
278
- });
279
- return result;
280
- } catch (e) {
281
- const error = e instanceof ORPCError2 ? e : new ORPCError2({
282
- code: "INTERNAL_SERVER_ERROR",
283
- message: "Internal server error",
284
- cause: e
285
- });
286
- const { body, headers } = this.payloadCodec.encode(error.toJSON());
287
- const response = new Response(body, {
288
- headers,
289
- status: error.status
290
- });
291
- return { matched: true, response };
292
- }
293
- }
294
- };
295
-
296
- export {
297
- super_json_exports,
298
- ORPCPayloadCodec,
299
- ORPCProcedureMatcher,
300
- ORPCHandler
301
- };
302
- //# sourceMappingURL=chunk-3BAPJGK6.js.map