@orpc/server 2.0.0-beta.47 → 2.0.0-beta.48

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 (169) hide show
  1. package/README.md +2 -3
  2. package/dist/adapters/aws-lambda/handler.d.mts +25 -0
  3. package/dist/adapters/aws-lambda/handler.mjs +21 -0
  4. package/dist/adapters/aws-lambda/index.d.mts +14 -49
  5. package/dist/adapters/aws-lambda/index.mjs +2 -39
  6. package/dist/adapters/aws-lambda/rpc-handler.d.mts +18 -0
  7. package/dist/adapters/aws-lambda/rpc-handler.mjs +10 -0
  8. package/dist/adapters/crossws/handler.d.mts +41 -0
  9. package/dist/adapters/crossws/handler.mjs +38 -0
  10. package/dist/adapters/crossws/index.d.mts +2 -63
  11. package/dist/adapters/crossws/index.mjs +2 -68
  12. package/dist/adapters/crossws/rpc-handler.d.mts +15 -0
  13. package/dist/adapters/crossws/rpc-handler.mjs +10 -0
  14. package/dist/adapters/fastify/handler.d.mts +21 -0
  15. package/dist/adapters/fastify/handler.mjs +20 -0
  16. package/dist/adapters/fastify/index.d.mts +2 -42
  17. package/dist/adapters/fastify/index.mjs +2 -39
  18. package/dist/adapters/fastify/rpc-handler.d.mts +14 -0
  19. package/dist/adapters/fastify/rpc-handler.mjs +10 -0
  20. package/dist/adapters/fetch/handler.d.mts +23 -0
  21. package/dist/adapters/fetch/handler.mjs +22 -0
  22. package/dist/adapters/fetch/index.d.mts +6 -46
  23. package/dist/adapters/fetch/index.mjs +4 -41
  24. package/dist/adapters/fetch/rpc-handler.d.mts +16 -0
  25. package/dist/adapters/fetch/rpc-handler.mjs +10 -0
  26. package/dist/adapters/message-port/handler.d.mts +57 -0
  27. package/dist/adapters/message-port/handler.mjs +62 -0
  28. package/dist/adapters/message-port/index.d.mts +2 -77
  29. package/dist/adapters/message-port/index.mjs +2 -87
  30. package/dist/adapters/message-port/rpc-handler.d.mts +15 -0
  31. package/dist/adapters/message-port/rpc-handler.mjs +10 -0
  32. package/dist/adapters/node/handler.d.mts +21 -0
  33. package/dist/adapters/node/handler.mjs +20 -0
  34. package/dist/adapters/node/index.d.mts +6 -43
  35. package/dist/adapters/node/index.mjs +4 -40
  36. package/dist/adapters/node/rpc-handler.d.mts +15 -0
  37. package/dist/adapters/node/rpc-handler.mjs +10 -0
  38. package/dist/adapters/standard/codec.d.mts +16 -0
  39. package/dist/adapters/standard/codec.mjs +1 -0
  40. package/dist/adapters/standard/handler.d.mts +68 -0
  41. package/dist/adapters/standard/handler.mjs +185 -0
  42. package/dist/adapters/standard/index.d.mts +6 -95
  43. package/dist/adapters/standard/index.mjs +5 -8
  44. package/dist/adapters/standard/plugin.d.mts +32 -0
  45. package/dist/adapters/standard/plugin.mjs +16 -0
  46. package/dist/adapters/standard/rpc-handler-codec.d.mts +42 -0
  47. package/dist/adapters/standard/rpc-handler-codec.mjs +51 -0
  48. package/dist/adapters/standard/rpc-matcher.d.mts +53 -0
  49. package/dist/adapters/standard/rpc-matcher.mjs +140 -0
  50. package/dist/adapters/standard/utils.d.mts +10 -0
  51. package/dist/adapters/standard/utils.mjs +6 -0
  52. package/dist/adapters/standard-peer/index.d.mts +1 -11
  53. package/dist/adapters/standard-peer/index.mjs +1 -10
  54. package/dist/adapters/standard-peer/utils.d.mts +4 -0
  55. package/dist/adapters/standard-peer/utils.mjs +11 -0
  56. package/dist/adapters/websocket/handler.d.mts +55 -0
  57. package/dist/adapters/websocket/handler.mjs +55 -0
  58. package/dist/adapters/websocket/index.d.mts +2 -77
  59. package/dist/adapters/websocket/index.mjs +2 -87
  60. package/dist/adapters/websocket/rpc-handler.d.mts +15 -0
  61. package/dist/adapters/websocket/rpc-handler.mjs +10 -0
  62. package/dist/builder-variants.d.mts +267 -0
  63. package/dist/builder-variants.mjs +1 -0
  64. package/dist/builder.d.mts +141 -0
  65. package/dist/builder.mjs +145 -0
  66. package/dist/constants.d.mts +2 -0
  67. package/dist/constants.mjs +2 -0
  68. package/dist/context.d.mts +13 -0
  69. package/dist/context.mjs +1 -0
  70. package/dist/extensions/callable.d.mts +16 -9
  71. package/dist/extensions/callable.mjs +5 -9
  72. package/dist/helpers/base64url.d.mts +31 -0
  73. package/dist/helpers/base64url.mjs +25 -0
  74. package/dist/helpers/cookie.d.mts +50 -0
  75. package/dist/helpers/cookie.mjs +35 -0
  76. package/dist/helpers/encryption.d.mts +28 -0
  77. package/dist/helpers/encryption.mjs +62 -0
  78. package/dist/helpers/index.d.mts +4 -167
  79. package/dist/helpers/index.mjs +4 -200
  80. package/dist/helpers/signing.d.mts +50 -0
  81. package/dist/helpers/signing.mjs +43 -0
  82. package/dist/implementer-procedure.d.mts +36 -0
  83. package/dist/implementer-procedure.mjs +38 -0
  84. package/dist/implementer-router.d.mts +78 -0
  85. package/dist/implementer-router.mjs +77 -0
  86. package/dist/implementer.d.mts +22 -0
  87. package/dist/implementer.mjs +30 -0
  88. package/dist/index.d.mts +57 -476
  89. package/dist/index.mjs +25 -458
  90. package/dist/lazy.d.mts +20 -0
  91. package/dist/lazy.mjs +22 -0
  92. package/dist/middleware-decorated.d.mts +27 -0
  93. package/dist/middleware-decorated.mjs +65 -0
  94. package/dist/middleware.d.mts +70 -0
  95. package/dist/middleware.mjs +1 -0
  96. package/dist/plugins/batch.d.mts +104 -0
  97. package/dist/plugins/batch.mjs +373 -0
  98. package/dist/plugins/cors.d.mts +67 -0
  99. package/dist/plugins/cors.mjs +134 -0
  100. package/dist/plugins/get-method-csrf-protection.d.mts +23 -0
  101. package/dist/plugins/get-method-csrf-protection.mjs +45 -0
  102. package/dist/plugins/head-method.d.mts +23 -0
  103. package/dist/plugins/head-method.mjs +95 -0
  104. package/dist/plugins/index.d.mts +39 -432
  105. package/dist/plugins/index.mjs +23 -965
  106. package/dist/plugins/method-override.d.mts +38 -0
  107. package/dist/plugins/method-override.mjs +50 -0
  108. package/dist/plugins/request-compression.d.mts +16 -0
  109. package/dist/plugins/request-compression.mjs +67 -0
  110. package/dist/plugins/request-headers.d.mts +22 -0
  111. package/dist/plugins/request-headers.mjs +21 -0
  112. package/dist/plugins/request-limit.d.mts +30 -0
  113. package/dist/plugins/request-limit.mjs +53 -0
  114. package/dist/plugins/response-compression.d.mts +59 -0
  115. package/dist/plugins/response-compression.mjs +172 -0
  116. package/dist/plugins/response-headers.d.mts +30 -0
  117. package/dist/plugins/response-headers.mjs +34 -0
  118. package/dist/plugins/rethrow.d.mts +33 -0
  119. package/dist/plugins/rethrow.mjs +46 -0
  120. package/dist/plugins/signal-sync.d.mts +13 -0
  121. package/dist/plugins/signal-sync.mjs +84 -0
  122. package/dist/plugins/timeout.d.mts +37 -0
  123. package/dist/plugins/timeout.mjs +56 -0
  124. package/dist/procedure-client.d.mts +41 -0
  125. package/dist/procedure-client.mjs +157 -0
  126. package/dist/procedure-decorated.d.mts +20 -0
  127. package/dist/procedure-decorated.mjs +41 -0
  128. package/dist/procedure-utils.d.mts +52 -0
  129. package/dist/procedure-utils.mjs +33 -0
  130. package/dist/procedure.d.mts +93 -0
  131. package/dist/procedure.mjs +20 -0
  132. package/dist/router-client.d.mts +27 -0
  133. package/dist/router-client.mjs +35 -0
  134. package/dist/router-hidden.d.mts +5 -0
  135. package/dist/router-hidden.mjs +12 -0
  136. package/dist/router-utils.d.mts +59 -0
  137. package/dist/router-utils.mjs +191 -0
  138. package/dist/router.d.mts +61 -0
  139. package/dist/router.mjs +1 -0
  140. package/package.json +11 -11
  141. package/dist/adapters/aws-lambda/index.d.ts +0 -51
  142. package/dist/adapters/crossws/index.d.ts +0 -63
  143. package/dist/adapters/fastify/index.d.ts +0 -42
  144. package/dist/adapters/fetch/index.d.ts +0 -47
  145. package/dist/adapters/message-port/index.d.ts +0 -77
  146. package/dist/adapters/node/index.d.ts +0 -44
  147. package/dist/adapters/standard/index.d.ts +0 -95
  148. package/dist/adapters/standard-peer/index.d.ts +0 -11
  149. package/dist/adapters/websocket/index.d.ts +0 -77
  150. package/dist/extensions/callable.d.ts +0 -10
  151. package/dist/helpers/index.d.ts +0 -167
  152. package/dist/index.d.ts +0 -476
  153. package/dist/plugins/index.d.ts +0 -432
  154. package/dist/shared/server.1ExWFMze.mjs +0 -69
  155. package/dist/shared/server.9B1jEm5a.d.mts +0 -105
  156. package/dist/shared/server.BB464y-6.mjs +0 -207
  157. package/dist/shared/server.BC5BIu02.d.mts +0 -73
  158. package/dist/shared/server.BSYGskId.d.ts +0 -14
  159. package/dist/shared/server.BvG3boBj.d.mts +0 -14
  160. package/dist/shared/server.CTV_mC2P.d.mts +0 -34
  161. package/dist/shared/server.CYbIpHbH.mjs +0 -239
  162. package/dist/shared/server.CgBF3Vj1.d.ts +0 -34
  163. package/dist/shared/server.Chq5FpXf.mjs +0 -353
  164. package/dist/shared/server.DFPxP2v3.d.mts +0 -166
  165. package/dist/shared/server.DFPxP2v3.d.ts +0 -166
  166. package/dist/shared/server.DOg7ke6y.d.ts +0 -105
  167. package/dist/shared/server.Dz7j9BEh.d.ts +0 -73
  168. package/dist/shared/server.W91HSRkE.mjs +0 -9
  169. package/dist/shared/server.sBQSgqK3.mjs +0 -41
@@ -1,207 +0,0 @@
1
- import { wrapAsyncIteratorPreservingEventMeta, ORPCError } from '@orpc/client';
2
- import { createORPCErrorConstructorMap, reconcileORPCError, ValidationError, ProcedureContract } from '@orpc/contract';
3
- import { getConstructor, isTypescriptObject, resolveMaybeOptionalOptions, toArray, value, runWithSpan, intercept, isAsyncIteratorObject, override, getTracer, traceAsyncIterator, traceReadableStream, mergeTwoLevels } from '@orpc/shared';
4
-
5
- class Lazy {
6
- "~orpc";
7
- constructor(def) {
8
- this["~orpc"] = def;
9
- }
10
- /**
11
- * Checks if the given instance satisfies the {@link Lazy} class/interface.
12
- */
13
- static [Symbol.hasInstance](instance) {
14
- if (this !== Lazy) {
15
- return Function.prototype[Symbol.hasInstance].call(this, instance);
16
- }
17
- const constructor = getConstructor(instance);
18
- if (constructor === Lazy) {
19
- return true;
20
- }
21
- return isTypescriptObject(instance) && isTypescriptObject(instance["~orpc"]) && isTypescriptObject(instance["~orpc"].meta) && (instance["~orpc"].metaPlugins === void 0 || Array.isArray(instance["~orpc"].metaPlugins)) && typeof instance["~orpc"].loader === "function";
22
- }
23
- }
24
- function unlazy(maybeLazy) {
25
- return maybeLazy instanceof Lazy ? maybeLazy["~orpc"].loader() : Promise.resolve({ default: maybeLazy });
26
- }
27
-
28
- function createProcedureClient(lazyableProcedure, ...rest) {
29
- const options = resolveMaybeOptionalOptions(rest);
30
- return async (...[input, callerOptions]) => {
31
- const path = toArray(options.path);
32
- const { default: procedure } = await unlazy(lazyableProcedure);
33
- const clientContext = callerOptions?.context ?? {};
34
- const context = await value(options.context, clientContext) ?? {};
35
- const errors = createORPCErrorConstructorMap(procedure["~orpc"].errorMap);
36
- const reconcileError = async (e) => {
37
- if (e instanceof ORPCError) {
38
- return await reconcileORPCError(procedure["~orpc"].errorMap, e);
39
- }
40
- return e;
41
- };
42
- try {
43
- const output = await runWithSpan("call_procedure", (span) => {
44
- span?.setAttribute("procedure.path", path);
45
- return intercept(
46
- options.interceptors,
47
- {
48
- context,
49
- // input can be optional if it is undefinable
50
- input,
51
- errors,
52
- path,
53
- procedure,
54
- signal: callerOptions?.signal,
55
- lastEventId: callerOptions?.lastEventId
56
- },
57
- (interceptorOptions) => executeProcedureInternal(interceptorOptions.procedure, interceptorOptions)
58
- );
59
- });
60
- if (isAsyncIteratorObject(output)) {
61
- return override(output, wrapAsyncIteratorPreservingEventMeta(
62
- getTracer() ? traceAsyncIterator("consume_async_iterator_object_output", output) : output,
63
- { mapError: reconcileError }
64
- ));
65
- } else if (getTracer() && output instanceof ReadableStream) {
66
- return override(output, traceReadableStream("consume_octet_stream_output", output));
67
- }
68
- return output;
69
- } catch (e) {
70
- throw await reconcileError(e);
71
- }
72
- };
73
- }
74
- async function validateInput(i, schema, input) {
75
- return runWithSpan(`validate_input.${i}`, async (span) => {
76
- span?.setAttribute("input_schema.index", i);
77
- const result = await schema["~standard"].validate(input);
78
- if (result.issues) {
79
- throw new ORPCError("BAD_REQUEST", {
80
- message: "Input validation failed",
81
- data: {
82
- issues: result.issues
83
- },
84
- cause: new ValidationError({
85
- message: "Input validation failed",
86
- issues: result.issues,
87
- invalidData: input
88
- })
89
- });
90
- }
91
- return result.value;
92
- });
93
- }
94
- async function validateOutput(i, schema, output) {
95
- return runWithSpan(`validate_output.${i}`, async (span) => {
96
- span?.setAttribute("output_schema.index", i);
97
- const result = await schema["~standard"].validate(output);
98
- if (result.issues) {
99
- throw new ORPCError("INTERNAL_SERVER_ERROR", {
100
- message: "Output validation failed",
101
- cause: new ValidationError({
102
- message: "Output validation failed",
103
- issues: result.issues,
104
- invalidData: output
105
- })
106
- });
107
- }
108
- return result.value;
109
- });
110
- }
111
- const middlewareDone = (...rest) => {
112
- const options = resolveMaybeOptionalOptions(rest);
113
- return {
114
- output: options.output,
115
- // context can be undefined when all field is optional
116
- context: options.context ?? {}
117
- };
118
- };
119
- async function executeProcedureInternal(procedure, options) {
120
- const inputSchemas = toArray(procedure["~orpc"].inputSchemas);
121
- const outputSchemas = toArray(procedure["~orpc"].outputSchemas);
122
- const orderedMiddlewares = procedure["~orpc"].orderedMiddlewares;
123
- const next = async (midIndex, context, input, signal) => {
124
- let currentInput = input;
125
- let middlewareInput = input;
126
- const startInputIndex = midIndex === 0 ? 0 : orderedMiddlewares[midIndex - 1].inputSchemasLengthAtUse ?? 0;
127
- const endInputIndex = midIndex === orderedMiddlewares.length ? inputSchemas.length : orderedMiddlewares[midIndex].inputSchemasLengthAtUse ?? 0;
128
- if (!procedure["~orpc"].disableInputValidation) {
129
- for (let i = startInputIndex; i < endInputIndex; i++) {
130
- const validated = await validateInput(
131
- i,
132
- inputSchemas[i],
133
- i !== 0 ? mergeTwoLevels(options.input, currentInput) : currentInput
134
- );
135
- currentInput = i !== 0 ? mergeTwoLevels(currentInput, validated) : validated;
136
- }
137
- middlewareInput = endInputIndex > 0 && endInputIndex < inputSchemas.length ? mergeTwoLevels(options.input, currentInput) : currentInput;
138
- }
139
- let currentOutput;
140
- let currentContext = context;
141
- if (midIndex < orderedMiddlewares.length) {
142
- const { middleware } = orderedMiddlewares[midIndex];
143
- const result = await runWithSpan(`middleware.${middleware.name}`, async (span) => {
144
- span?.setAttribute("middleware.index", midIndex);
145
- return await middleware(
146
- {
147
- ...options,
148
- context,
149
- signal,
150
- next: (...rest) => {
151
- const nextOptions = resolveMaybeOptionalOptions(rest);
152
- const nextContext = nextOptions.context ?? {};
153
- return next(
154
- midIndex + 1,
155
- { ...context, ...nextContext },
156
- currentInput,
157
- nextOptions.signal ?? signal
158
- );
159
- },
160
- lastEventId: options.lastEventId
161
- },
162
- middlewareInput,
163
- middlewareDone
164
- );
165
- });
166
- currentOutput = result.output;
167
- currentContext = { ...context, ...result.context };
168
- } else {
169
- currentOutput = await runWithSpan(
170
- "handler",
171
- () => procedure["~orpc"].handler({ ...options, context, input: currentInput, signal }, currentInput)
172
- );
173
- }
174
- const startOutputIndex = midIndex === 0 ? 0 : orderedMiddlewares[midIndex - 1].outputSchemasLengthAtUse ?? 0;
175
- const endOutputIndex = midIndex === orderedMiddlewares.length ? outputSchemas.length : orderedMiddlewares[midIndex].outputSchemasLengthAtUse ?? 0;
176
- if (!procedure["~orpc"].disableOutputValidation) {
177
- for (let i = endOutputIndex - 1; i >= startOutputIndex; i--) {
178
- currentOutput = await validateOutput(i, outputSchemas[i], currentOutput);
179
- }
180
- }
181
- return { output: currentOutput, context: currentContext };
182
- };
183
- const { output } = await next(0, options.context, options.input, options.signal);
184
- return output;
185
- }
186
-
187
- class Procedure {
188
- "~orpc";
189
- constructor(def) {
190
- this["~orpc"] = def;
191
- }
192
- /**
193
- * Checks if the given instance satisfies the {@link Procedure} class/interface.
194
- */
195
- static [Symbol.hasInstance](instance) {
196
- if (this !== Procedure) {
197
- return Function.prototype[Symbol.hasInstance].call(this, instance);
198
- }
199
- const constructor = getConstructor(instance);
200
- if (constructor === Procedure) {
201
- return true;
202
- }
203
- return instance instanceof ProcedureContract && Array.isArray(instance["~orpc"].orderedMiddlewares) && typeof instance["~orpc"].handler === "function";
204
- }
205
- }
206
-
207
- export { Lazy as L, Procedure as P, createProcedureClient as c, unlazy as u };
@@ -1,73 +0,0 @@
1
- import { RouterContract, ProcedureContract, ORPCErrorFromErrorMap, ThrowableError, InferSchemaInput, InferSchemaOutput } from '@orpc/contract';
2
- import { C as Context, a as Procedure, L as Lazyable, M as MergedContext } from './server.DFPxP2v3.mjs';
3
-
4
- type Router<TInitialContext extends Context> = Procedure<TInitialContext, any, any, any, any> | {
5
- [k: string]: Lazyable<Router<TInitialContext>>;
6
- };
7
- type ContractedRouter<T extends RouterContract, TInitialContext extends Context> = T extends ProcedureContract<infer $InputSchema, infer $OutputSchema, infer $ErrorMap> ? Procedure<TInitialContext, any, $InputSchema, $OutputSchema, $ErrorMap> : {
8
- [K in keyof T]: T[K] extends RouterContract ? Lazyable<ContractedRouter<T[K], TInitialContext>> : never;
9
- };
10
- type AnyRouter = Router<any>;
11
- type InferRouterInitialContext<T extends AnyRouter> = T extends Router<infer $> ? $ : never;
12
- /**
13
- * Infer all initial context of the router.
14
- *
15
- * @remarks
16
- * **Note**: A procedure is a router too.
17
- *
18
- * @see {@link https://orpc.dev/docs/router#infer-router-initial-contexts | Router - Infer Router Initial Contexts}
19
- */
20
- type InferRouterInitialContexts<T extends AnyRouter> = T extends Procedure<infer UInitialContext, any, any, any, any> ? UInitialContext : {
21
- [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInitialContexts<U> : never;
22
- };
23
- /**
24
- * Infer all current context of the router.
25
- *
26
- * @remarks
27
- * **Note**: A procedure is a router too.
28
- *
29
- * @see {@link https://orpc.dev/docs/router#infer-router-final-contexts | Router - Infer Router Final Contexts}
30
- */
31
- type InferRouterFinalContexts<T extends AnyRouter> = T extends Procedure<infer UInitialContext, infer UInjectedContext, any, any, any> ? MergedContext<UInitialContext, UInjectedContext> : {
32
- [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterFinalContexts<U> : never;
33
- };
34
- /**
35
- * Infer all router inputs.
36
- *
37
- * @remarks
38
- * **Note**: A procedure is a router too.
39
- *
40
- * @see {@link https://orpc.dev/docs/router#infer-router-inputs | Router - Infer Router Inputs}
41
- */
42
- type InferRouterInputs<T extends AnyRouter> = T extends Procedure<any, any, infer UInputSchema, any, any> ? InferSchemaInput<UInputSchema> : {
43
- [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInputs<U> : never;
44
- };
45
- /**
46
- * Infer all router outputs.
47
- *
48
- * @remarks
49
- * **Note**: A procedure is a router too.
50
- *
51
- * @see {@link https://orpc.dev/docs/router#infer-router-outputs | Router - Infer Router Outputs}
52
- */
53
- type InferRouterOutputs<T extends AnyRouter> = T extends Procedure<any, any, any, infer UOutputSchema, any> ? InferSchemaOutput<UOutputSchema> : {
54
- [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterOutputs<U> : never;
55
- };
56
- /**
57
- * Infer the union of throwable errors for entire router.
58
- *
59
- * @see {@link https://orpc.dev/docs/router#infer-router-error | Router - Infer Router Error}
60
- */
61
- type InferRouterError<T extends AnyRouter> = T extends Procedure<any, any, any, any, infer UErrorMap> ? ORPCErrorFromErrorMap<UErrorMap> | ThrowableError : {
62
- [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterError<U> : never;
63
- }[keyof T];
64
- /**
65
- * Infer throwable errors for each procedure, preserving the router shape.
66
- *
67
- * @see {@link https://orpc.dev/docs/router#infer-router-errors | Router - Infer Router Errors}
68
- */
69
- type InferRouterErrors<T extends AnyRouter> = T extends Procedure<any, any, any, any, infer UErrorMap> ? ORPCErrorFromErrorMap<UErrorMap> | ThrowableError : {
70
- [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterErrors<U> : never;
71
- };
72
-
73
- export type { AnyRouter as A, ContractedRouter as C, InferRouterInitialContext as I, Router as R, InferRouterFinalContexts as a, InferRouterError as b, InferRouterErrors as c, InferRouterInitialContexts as d, InferRouterInputs as e, InferRouterOutputs as f };
@@ -1,14 +0,0 @@
1
- import { Value, Promisable } from '@orpc/shared';
2
- import { StandardLazyRequest } from '@standard-server/core';
3
- import { C as Context } from './server.DFPxP2v3.js';
4
- import { a as StandardHandlerHandleOptions } from './server.DOg7ke6y.js';
5
-
6
- type FriendlyStandardHandlerHandleOptions<T extends Context> = Omit<StandardHandlerHandleOptions<T>, 'context'> & (object extends T ? {
7
- context?: Value<Promisable<T>, [request: StandardLazyRequest]> | undefined;
8
- } : {
9
- context: Value<Promisable<T>, [request: StandardLazyRequest]>;
10
- });
11
- declare function resolveFriendlyStandardHandlerHandleOptions<T extends Context>(options: FriendlyStandardHandlerHandleOptions<T>): StandardHandlerHandleOptions<T>;
12
-
13
- export { resolveFriendlyStandardHandlerHandleOptions as r };
14
- export type { FriendlyStandardHandlerHandleOptions as F };
@@ -1,14 +0,0 @@
1
- import { Value, Promisable } from '@orpc/shared';
2
- import { StandardLazyRequest } from '@standard-server/core';
3
- import { C as Context } from './server.DFPxP2v3.mjs';
4
- import { a as StandardHandlerHandleOptions } from './server.9B1jEm5a.mjs';
5
-
6
- type FriendlyStandardHandlerHandleOptions<T extends Context> = Omit<StandardHandlerHandleOptions<T>, 'context'> & (object extends T ? {
7
- context?: Value<Promisable<T>, [request: StandardLazyRequest]> | undefined;
8
- } : {
9
- context: Value<Promisable<T>, [request: StandardLazyRequest]>;
10
- });
11
- declare function resolveFriendlyStandardHandlerHandleOptions<T extends Context>(options: FriendlyStandardHandlerHandleOptions<T>): StandardHandlerHandleOptions<T>;
12
-
13
- export { resolveFriendlyStandardHandlerHandleOptions as r };
14
- export type { FriendlyStandardHandlerHandleOptions as F };
@@ -1,34 +0,0 @@
1
- import { C as Context } from './server.DFPxP2v3.mjs';
2
- import { b as StandardHandlerPlugin, c as StandardHandlerOptions } from './server.9B1jEm5a.mjs';
3
-
4
- interface RequestLimitHandlerPluginOptions {
5
- /**
6
- * The maximum allowed request body size in bytes.
7
- */
8
- maxBodySize: number;
9
- }
10
- /**
11
- * Rejects requests whose body exceeds `maxBodySize`.
12
- *
13
- * When used with the request compression plugin, the limit applies to the
14
- * decompressed payload rather than the compressed wire size.
15
- *
16
- * @see {@link https://orpc.dev/docs/plugins/request-limit | Request Limit Plugin}
17
- */
18
- declare class RequestLimitHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
19
- name: string;
20
- /**
21
- * Should limit the original batch request body instead of sub-requests.
22
- */
23
- after: string[];
24
- /**
25
- * Should limit the final body size instead of the compressed one.
26
- */
27
- before: string[];
28
- private readonly maxBodySize;
29
- constructor(options: RequestLimitHandlerPluginOptions);
30
- init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
31
- }
32
-
33
- export { RequestLimitHandlerPlugin as R };
34
- export type { RequestLimitHandlerPluginOptions as a };
@@ -1,239 +0,0 @@
1
- import { ProcedureContract, resolveMetaPlugins, mergeErrorMap } from '@orpc/contract';
2
- import { isTypescriptObject, getOwn, omit } from '@orpc/shared';
3
- import { c as createProcedureClient, L as Lazy, u as unlazy, P as Procedure } from './server.BB464y-6.mjs';
4
-
5
- const DEFAULT_SUCCESS_STATUS = 200;
6
- const DEFAULT_ERROR_STATUS = 400;
7
-
8
- function createGuardedProcedureLazy(lazy) {
9
- const guarded = new Lazy({
10
- ...lazy["~orpc"],
11
- async loader() {
12
- const { default: maybeProcedure } = await unlazy(lazy);
13
- if (!(maybeProcedure instanceof Procedure)) {
14
- throw new TypeError(`
15
- Expected a lazy<procedure> but got lazy<unknown>.
16
- This should be caught by TypeScript compilation.
17
- Please report this issue if you think this is a bug.
18
- `);
19
- }
20
- return { default: maybeProcedure };
21
- }
22
- });
23
- return guarded;
24
- }
25
- function createContractProcedure(procedure, contract) {
26
- return new Procedure({
27
- ...procedure["~orpc"],
28
- errorMap: contract["~orpc"].errorMap,
29
- meta: contract["~orpc"].meta,
30
- metaPlugins: contract["~orpc"].metaPlugins
31
- });
32
- }
33
- function call(lazyableProcedure, ...[
34
- input = void 0,
35
- options = {}
36
- ]) {
37
- return createProcedureClient(lazyableProcedure, options)(input, options);
38
- }
39
-
40
- const HIDDEN_ROUTER_CONTRACT_SYMBOL = Symbol.for("ORPC_HIDDEN_ROUTER_CONTRACT");
41
- function withHiddenRouterContract(router, contract) {
42
- return new Proxy(router, {
43
- get(target, key) {
44
- if (key === HIDDEN_ROUTER_CONTRACT_SYMBOL) {
45
- return contract;
46
- }
47
- return Reflect.get(target, key);
48
- }
49
- });
50
- }
51
- function getHiddenRouterContract(router) {
52
- return router[HIDDEN_ROUTER_CONTRACT_SYMBOL];
53
- }
54
-
55
- function augmentRouter(router, options) {
56
- if (router instanceof Lazy) {
57
- const [meta, metaPlugins] = resolveMetaPlugins(
58
- options.meta,
59
- options.metaPlugins,
60
- router["~orpc"].metaPlugins
61
- );
62
- const enhanced2 = new Lazy({
63
- meta,
64
- metaPlugins,
65
- async loader() {
66
- const { default: unlaziedRouter } = await unlazy(router);
67
- const enhanced3 = augmentRouter(unlaziedRouter, options);
68
- return unlazy(enhanced3);
69
- }
70
- });
71
- return enhanced2;
72
- }
73
- if (router instanceof Procedure) {
74
- const [meta, metaPlugins] = resolveMetaPlugins(
75
- options.meta,
76
- options.metaPlugins,
77
- router["~orpc"].metaPlugins
78
- );
79
- const enhanced2 = new Procedure({
80
- ...omit(options, ["middlewares", "errorMap", "meta", "metaPlugins"]),
81
- ...router["~orpc"],
82
- meta,
83
- metaPlugins,
84
- errorMap: mergeErrorMap(options.errorMap, router["~orpc"].errorMap),
85
- orderedMiddlewares: [
86
- ...options.middlewares.map((middleware) => ({ middleware, inputSchemasLengthAtUse: 0, outputSchemasLengthAtUse: 0 })),
87
- ...router["~orpc"].orderedMiddlewares
88
- ]
89
- });
90
- return enhanced2;
91
- }
92
- if (!isTypescriptObject(router)) {
93
- return router;
94
- }
95
- const enhanced = {};
96
- for (const [key, child] of Object.entries(router)) {
97
- enhanced[key] = augmentRouter(child, options);
98
- }
99
- return enhanced;
100
- }
101
- function augmentImplementedRouter(router, options) {
102
- if (router instanceof Lazy) {
103
- const enhanced2 = new Lazy({
104
- ...router["~orpc"],
105
- async loader() {
106
- const { default: unlaziedRouter } = await unlazy(router);
107
- const enhanced3 = augmentImplementedRouter(unlaziedRouter, options);
108
- return unlazy(enhanced3);
109
- }
110
- });
111
- return enhanced2;
112
- }
113
- if (router instanceof Procedure) {
114
- const enhanced2 = new Procedure({
115
- ...omit(options, ["middlewares"]),
116
- ...router["~orpc"],
117
- orderedMiddlewares: [
118
- ...options.middlewares.map((middleware) => ({ middleware, inputSchemasLengthAtUse: 0, outputSchemasLengthAtUse: 0 })),
119
- ...router["~orpc"].orderedMiddlewares
120
- ]
121
- });
122
- return enhanced2;
123
- }
124
- if (!isTypescriptObject(router)) {
125
- return router;
126
- }
127
- const enhanced = {};
128
- for (const [key, child] of Object.entries(router)) {
129
- enhanced[key] = augmentImplementedRouter(child, options);
130
- }
131
- return enhanced;
132
- }
133
- async function resolveContractProcedure(router, contract, path) {
134
- if (contract instanceof Procedure) {
135
- return contract;
136
- }
137
- const { default: maybeProcedure } = await unlazy(getRouter(router, path));
138
- if (!(maybeProcedure instanceof Procedure)) {
139
- throw new TypeError(
140
- `[Contract-First] Missing or invalid implementation for procedure at path: "${path.join(".")}". Ensure the procedure is correctly implemented and matches its contract.`
141
- );
142
- }
143
- return createContractProcedure(maybeProcedure, contract);
144
- }
145
- function getRouter(router, path) {
146
- let current = router;
147
- for (let i = 0; i < path.length; i++) {
148
- const segment = path[i];
149
- if (!isTypescriptObject(current)) {
150
- return void 0;
151
- }
152
- if (current instanceof Procedure) {
153
- return void 0;
154
- }
155
- if (!(current instanceof Lazy)) {
156
- current = getOwn(current, segment);
157
- continue;
158
- }
159
- const lazied = current;
160
- const rest = path.slice(i);
161
- return new Lazy({
162
- ...lazied["~orpc"],
163
- async loader() {
164
- const unwrapped = await unlazy(lazied);
165
- const next = getRouter(unwrapped.default, rest);
166
- return await unlazy(next);
167
- }
168
- });
169
- }
170
- if (!isTypescriptObject(current)) {
171
- return void 0;
172
- }
173
- return current;
174
- }
175
- function walkProcedureContractsSync(router, callback, path = []) {
176
- const lazyResults = [];
177
- walkProcedureContractsSyncInternal(router, callback, path.slice(), lazyResults);
178
- return lazyResults;
179
- }
180
- function walkProcedureContractsSyncInternal(router, callback, path, lazyResults) {
181
- const hiddenContract = getHiddenRouterContract(router);
182
- if (hiddenContract !== void 0) {
183
- router = hiddenContract;
184
- }
185
- if (router instanceof ProcedureContract) {
186
- callback(router, path.slice());
187
- return;
188
- }
189
- if (!isTypescriptObject(router)) {
190
- return;
191
- }
192
- for (const [key, value] of Object.entries(router)) {
193
- path.push(key);
194
- if (value instanceof Lazy) {
195
- lazyResults.push({ router: value, path: path.slice() });
196
- } else {
197
- walkProcedureContractsSyncInternal(value, callback, path, lazyResults);
198
- }
199
- path.pop();
200
- }
201
- }
202
- async function walkProcedureContractsAsync(router, callback, path = []) {
203
- const hiddenContract = getHiddenRouterContract(router);
204
- if (hiddenContract !== void 0) {
205
- router = hiddenContract;
206
- }
207
- if (router instanceof ProcedureContract) {
208
- await callback(router, path);
209
- return;
210
- }
211
- if (!isTypescriptObject(router)) {
212
- return;
213
- }
214
- for (const [key, value] of Object.entries(router)) {
215
- if (value instanceof Lazy) {
216
- const { default: router2 } = await unlazy(value);
217
- await walkProcedureContractsAsync(router2, callback, [...path, key]);
218
- } else {
219
- await walkProcedureContractsAsync(value, callback, [...path, key]);
220
- }
221
- }
222
- }
223
- async function unlazyRouter(router) {
224
- if (router instanceof Procedure) {
225
- return router;
226
- }
227
- if (!isTypescriptObject(router)) {
228
- return router;
229
- }
230
- const unlazied = {};
231
- for (const key of Object.keys(router)) {
232
- const item = router[key];
233
- const { default: unlaziedRouter } = await unlazy(item);
234
- unlazied[key] = await unlazyRouter(unlaziedRouter);
235
- }
236
- return unlazied;
237
- }
238
-
239
- export { DEFAULT_SUCCESS_STATUS as D, DEFAULT_ERROR_STATUS as a, augmentRouter as b, augmentImplementedRouter as c, withHiddenRouterContract as d, createGuardedProcedureLazy as e, call as f, getRouter as g, walkProcedureContractsAsync as h, resolveContractProcedure as r, unlazyRouter as u, walkProcedureContractsSync as w };
@@ -1,34 +0,0 @@
1
- import { C as Context } from './server.DFPxP2v3.js';
2
- import { b as StandardHandlerPlugin, c as StandardHandlerOptions } from './server.DOg7ke6y.js';
3
-
4
- interface RequestLimitHandlerPluginOptions {
5
- /**
6
- * The maximum allowed request body size in bytes.
7
- */
8
- maxBodySize: number;
9
- }
10
- /**
11
- * Rejects requests whose body exceeds `maxBodySize`.
12
- *
13
- * When used with the request compression plugin, the limit applies to the
14
- * decompressed payload rather than the compressed wire size.
15
- *
16
- * @see {@link https://orpc.dev/docs/plugins/request-limit | Request Limit Plugin}
17
- */
18
- declare class RequestLimitHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
19
- name: string;
20
- /**
21
- * Should limit the original batch request body instead of sub-requests.
22
- */
23
- after: string[];
24
- /**
25
- * Should limit the final body size instead of the compressed one.
26
- */
27
- before: string[];
28
- private readonly maxBodySize;
29
- constructor(options: RequestLimitHandlerPluginOptions);
30
- init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
31
- }
32
-
33
- export { RequestLimitHandlerPlugin as R };
34
- export type { RequestLimitHandlerPluginOptions as a };