@temporary-name/server 1.9.3-alpha.0d2fa3247b6b23bbc2e3097a95f631b86740e4d8

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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Stainless
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,31 @@
1
+ > [!NOTE]
2
+ > In the spirit of writing the press release first, drafting some content here as we go.
3
+
4
+ # Crusty [name WIP]
5
+
6
+ Crusty is an API framework that does the right thing by default.
7
+
8
+ > Everything should be possible, but correct things should be easy
9
+
10
+ Have you ever accidentally left out a single line of code and ended up with an unauthenticated API endpoint? Accidentally rendered an incoherent error format (or worse, returned HTML when you 500)?
11
+
12
+ Crusty takes the lessons from shipping massive production APIs (we built Stripe's API abstractions) and makes them available to everyone.
13
+
14
+ ## What is an API framework?
15
+
16
+ The frameworks you're probably thinking of are more like HTTP frameworks: they offer routing, middleware, and maybe some helpers around authentication and parameter validation.
17
+
18
+ This is great, but there's a layer on top of them that's missing, and every company ends up building themselves:
19
+
20
+ - Authentication & authorization
21
+ - Gating (expose certain request/response params to certain customers)
22
+ - Versioning (this one's gnarly!)
23
+ - Logging
24
+ - Error handling/rendering
25
+ - Rate limiting
26
+ - Idempotency
27
+ - Documentation/spec generation
28
+
29
+ Middleware is powerful for much of this, but in many ways it's lowest-common-denominator and you still need to build a lot of custom code to make these happen.
30
+
31
+ Crusty is a layer on top of your HTTP framework that adds best-in-class primitives for all of these.
@@ -0,0 +1,24 @@
1
+ import { MaybeOptionalOptions } from '@temporary-name/shared';
2
+ import { SendStandardResponseOptions, APIGatewayProxyEventV2, ResponseStream } from '@temporary-name/standard-server-aws-lambda';
3
+ import { C as Context } from '../../shared/server.C1YnHvvf.mjs';
4
+ import { S as StandardHandler } from '../../shared/server.Bo94xDTv.mjs';
5
+ import { FriendlyStandardHandleOptions } from '../standard/index.mjs';
6
+ import '@temporary-name/contract';
7
+ import '@temporary-name/standard-server';
8
+
9
+ interface AwsLambdaHandlerOptions extends SendStandardResponseOptions {
10
+ }
11
+ type AwsLambdaHandleResult = {
12
+ matched: true;
13
+ } | {
14
+ matched: false;
15
+ };
16
+ declare class AwsLambdaHandler<T extends Context> {
17
+ private readonly standardHandler;
18
+ private readonly sendStandardResponseOptions;
19
+ constructor(standardHandler: StandardHandler<T>, options?: AwsLambdaHandlerOptions);
20
+ handle(event: APIGatewayProxyEventV2, responseStream: ResponseStream, ...rest: MaybeOptionalOptions<FriendlyStandardHandleOptions<T>>): Promise<AwsLambdaHandleResult>;
21
+ }
22
+
23
+ export { AwsLambdaHandler };
24
+ export type { AwsLambdaHandleResult, AwsLambdaHandlerOptions };
@@ -0,0 +1,24 @@
1
+ import { MaybeOptionalOptions } from '@temporary-name/shared';
2
+ import { SendStandardResponseOptions, APIGatewayProxyEventV2, ResponseStream } from '@temporary-name/standard-server-aws-lambda';
3
+ import { C as Context } from '../../shared/server.C1YnHvvf.js';
4
+ import { S as StandardHandler } from '../../shared/server.Btxrgkj5.js';
5
+ import { FriendlyStandardHandleOptions } from '../standard/index.js';
6
+ import '@temporary-name/contract';
7
+ import '@temporary-name/standard-server';
8
+
9
+ interface AwsLambdaHandlerOptions extends SendStandardResponseOptions {
10
+ }
11
+ type AwsLambdaHandleResult = {
12
+ matched: true;
13
+ } | {
14
+ matched: false;
15
+ };
16
+ declare class AwsLambdaHandler<T extends Context> {
17
+ private readonly standardHandler;
18
+ private readonly sendStandardResponseOptions;
19
+ constructor(standardHandler: StandardHandler<T>, options?: AwsLambdaHandlerOptions);
20
+ handle(event: APIGatewayProxyEventV2, responseStream: ResponseStream, ...rest: MaybeOptionalOptions<FriendlyStandardHandleOptions<T>>): Promise<AwsLambdaHandleResult>;
21
+ }
22
+
23
+ export { AwsLambdaHandler };
24
+ export type { AwsLambdaHandleResult, AwsLambdaHandlerOptions };
@@ -0,0 +1,23 @@
1
+ import { resolveMaybeOptionalOptions } from '@temporary-name/shared';
2
+ import { toStandardLazyRequest, sendStandardResponse } from '@temporary-name/standard-server-aws-lambda';
3
+ import { r as resolveFriendlyStandardHandleOptions } from '../../shared/server.DZ5BIITo.mjs';
4
+
5
+ class AwsLambdaHandler {
6
+ constructor(standardHandler, options = {}) {
7
+ this.standardHandler = standardHandler;
8
+ this.sendStandardResponseOptions = options;
9
+ }
10
+ sendStandardResponseOptions;
11
+ async handle(event, responseStream, ...rest) {
12
+ const standardRequest = toStandardLazyRequest(event, responseStream);
13
+ const options = resolveFriendlyStandardHandleOptions(resolveMaybeOptionalOptions(rest));
14
+ const result = await this.standardHandler.handle(standardRequest, options);
15
+ if (!result.matched) {
16
+ return { matched: false };
17
+ }
18
+ await sendStandardResponse(responseStream, result.response, this.sendStandardResponseOptions);
19
+ return { matched: true };
20
+ }
21
+ }
22
+
23
+ export { AwsLambdaHandler };
@@ -0,0 +1,102 @@
1
+ import { C as Context } from '../../shared/server.C1YnHvvf.mjs';
2
+ import { Interceptor, MaybeOptionalOptions } from '@temporary-name/shared';
3
+ import { ToFetchResponseOptions } from '@temporary-name/standard-server-fetch';
4
+ import { a as StandardHandlerPlugin, C as CompositeStandardHandlerPlugin, b as StandardHandleOptions, S as StandardHandler } from '../../shared/server.Bo94xDTv.mjs';
5
+ import { FriendlyStandardHandleOptions } from '../standard/index.mjs';
6
+ import '@temporary-name/contract';
7
+ import '@temporary-name/standard-server';
8
+
9
+ interface FetchHandlerPlugin<T extends Context> extends StandardHandlerPlugin<T> {
10
+ initRuntimeAdapter?(options: FetchHandlerOptions<T>): void;
11
+ }
12
+ declare class CompositeFetchHandlerPlugin<T extends Context, TPlugin extends FetchHandlerPlugin<T>> extends CompositeStandardHandlerPlugin<T, TPlugin> implements FetchHandlerPlugin<T> {
13
+ initRuntimeAdapter(options: FetchHandlerOptions<T>): void;
14
+ }
15
+
16
+ type FetchHandleResult = {
17
+ matched: true;
18
+ response: Response;
19
+ } | {
20
+ matched: false;
21
+ response: undefined;
22
+ };
23
+ interface FetchHandlerInterceptorOptions<T extends Context> extends StandardHandleOptions<T> {
24
+ request: Request;
25
+ toFetchResponseOptions: ToFetchResponseOptions;
26
+ }
27
+ interface FetchHandlerOptions<T extends Context> extends ToFetchResponseOptions {
28
+ adapterInterceptors?: Interceptor<FetchHandlerInterceptorOptions<T>, Promise<FetchHandleResult>>[];
29
+ plugins?: FetchHandlerPlugin<T>[];
30
+ }
31
+ declare class FetchHandler<T extends Context> {
32
+ private readonly standardHandler;
33
+ private readonly toFetchResponseOptions;
34
+ private readonly adapterInterceptors;
35
+ constructor(standardHandler: StandardHandler<T>, options?: NoInfer<FetchHandlerOptions<T>>);
36
+ handle(request: Request, ...rest: MaybeOptionalOptions<FriendlyStandardHandleOptions<T>>): Promise<FetchHandleResult>;
37
+ }
38
+
39
+ interface BodyLimitPluginOptions {
40
+ /**
41
+ * The maximum size of the body in bytes.
42
+ */
43
+ maxBodySize: number;
44
+ }
45
+ /**
46
+ * The Body Limit Plugin restricts the size of the request body for the Fetch Server.
47
+ *
48
+ * @see {@link https://orpc.unnoq.com/docs/plugins/body-limit Body Limit Plugin Docs}
49
+ */
50
+ declare class BodyLimitPlugin<T extends Context> implements FetchHandlerPlugin<T> {
51
+ private readonly maxBodySize;
52
+ constructor(options: BodyLimitPluginOptions);
53
+ initRuntimeAdapter(options: FetchHandlerOptions<T>): void;
54
+ }
55
+
56
+ /**
57
+ * This plugin is heavily inspired by the [Hono Compression Plugin](https://github.com/honojs/hono/blob/main/src/middleware/compress/index.ts)
58
+ */
59
+
60
+ declare const ORDERED_SUPPORTED_ENCODINGS: readonly ["gzip", "deflate"];
61
+ interface CompressionPluginOptions {
62
+ /**
63
+ * The compression schemes to use for response compression.
64
+ * Schemes are prioritized by their order in this array and
65
+ * only applied if the client supports them.
66
+ *
67
+ * @default ['gzip', 'deflate']
68
+ */
69
+ encodings?: readonly (typeof ORDERED_SUPPORTED_ENCODINGS)[number][];
70
+ /**
71
+ * The minimum response size in bytes required to trigger compression.
72
+ * Responses smaller than this threshold will not be compressed to avoid overhead.
73
+ * If the response size cannot be determined, compression will still be applied.
74
+ *
75
+ * @default 1024 (1KB)
76
+ */
77
+ threshold?: number;
78
+ /**
79
+ * Override the default content-type filter used to determine which responses should be compressed.
80
+ *
81
+ * @warning [Event Iterator](https://orpc.unnoq.com/docs/event-iterator) responses are never compressed, regardless of this filter's return value.
82
+ * @default only responses with compressible content types are compressed.
83
+ */
84
+ filter?: (request: Request, response: Response) => boolean;
85
+ }
86
+ /**
87
+ * The Compression Plugin adds response compression to the Fetch Server.
88
+ * Build on top of [CompressionStream](https://developer.mozilla.org/en-US/docs/Web/API/CompressionStream)
89
+ * You might need to polyfill it if your environment does not support it.
90
+ *
91
+ * @see {@link https://orpc.unnoq.com/docs/plugins/compression Compression Plugin Docs}
92
+ */
93
+ declare class CompressionPlugin<T extends Context> implements FetchHandlerPlugin<T> {
94
+ private readonly encodings;
95
+ private readonly threshold;
96
+ private readonly filter;
97
+ constructor(options?: CompressionPluginOptions);
98
+ initRuntimeAdapter(options: FetchHandlerOptions<T>): void;
99
+ }
100
+
101
+ export { BodyLimitPlugin, CompositeFetchHandlerPlugin, CompressionPlugin, FetchHandler };
102
+ export type { BodyLimitPluginOptions, CompressionPluginOptions, FetchHandleResult, FetchHandlerInterceptorOptions, FetchHandlerOptions, FetchHandlerPlugin };
@@ -0,0 +1,102 @@
1
+ import { C as Context } from '../../shared/server.C1YnHvvf.js';
2
+ import { Interceptor, MaybeOptionalOptions } from '@temporary-name/shared';
3
+ import { ToFetchResponseOptions } from '@temporary-name/standard-server-fetch';
4
+ import { a as StandardHandlerPlugin, C as CompositeStandardHandlerPlugin, b as StandardHandleOptions, S as StandardHandler } from '../../shared/server.Btxrgkj5.js';
5
+ import { FriendlyStandardHandleOptions } from '../standard/index.js';
6
+ import '@temporary-name/contract';
7
+ import '@temporary-name/standard-server';
8
+
9
+ interface FetchHandlerPlugin<T extends Context> extends StandardHandlerPlugin<T> {
10
+ initRuntimeAdapter?(options: FetchHandlerOptions<T>): void;
11
+ }
12
+ declare class CompositeFetchHandlerPlugin<T extends Context, TPlugin extends FetchHandlerPlugin<T>> extends CompositeStandardHandlerPlugin<T, TPlugin> implements FetchHandlerPlugin<T> {
13
+ initRuntimeAdapter(options: FetchHandlerOptions<T>): void;
14
+ }
15
+
16
+ type FetchHandleResult = {
17
+ matched: true;
18
+ response: Response;
19
+ } | {
20
+ matched: false;
21
+ response: undefined;
22
+ };
23
+ interface FetchHandlerInterceptorOptions<T extends Context> extends StandardHandleOptions<T> {
24
+ request: Request;
25
+ toFetchResponseOptions: ToFetchResponseOptions;
26
+ }
27
+ interface FetchHandlerOptions<T extends Context> extends ToFetchResponseOptions {
28
+ adapterInterceptors?: Interceptor<FetchHandlerInterceptorOptions<T>, Promise<FetchHandleResult>>[];
29
+ plugins?: FetchHandlerPlugin<T>[];
30
+ }
31
+ declare class FetchHandler<T extends Context> {
32
+ private readonly standardHandler;
33
+ private readonly toFetchResponseOptions;
34
+ private readonly adapterInterceptors;
35
+ constructor(standardHandler: StandardHandler<T>, options?: NoInfer<FetchHandlerOptions<T>>);
36
+ handle(request: Request, ...rest: MaybeOptionalOptions<FriendlyStandardHandleOptions<T>>): Promise<FetchHandleResult>;
37
+ }
38
+
39
+ interface BodyLimitPluginOptions {
40
+ /**
41
+ * The maximum size of the body in bytes.
42
+ */
43
+ maxBodySize: number;
44
+ }
45
+ /**
46
+ * The Body Limit Plugin restricts the size of the request body for the Fetch Server.
47
+ *
48
+ * @see {@link https://orpc.unnoq.com/docs/plugins/body-limit Body Limit Plugin Docs}
49
+ */
50
+ declare class BodyLimitPlugin<T extends Context> implements FetchHandlerPlugin<T> {
51
+ private readonly maxBodySize;
52
+ constructor(options: BodyLimitPluginOptions);
53
+ initRuntimeAdapter(options: FetchHandlerOptions<T>): void;
54
+ }
55
+
56
+ /**
57
+ * This plugin is heavily inspired by the [Hono Compression Plugin](https://github.com/honojs/hono/blob/main/src/middleware/compress/index.ts)
58
+ */
59
+
60
+ declare const ORDERED_SUPPORTED_ENCODINGS: readonly ["gzip", "deflate"];
61
+ interface CompressionPluginOptions {
62
+ /**
63
+ * The compression schemes to use for response compression.
64
+ * Schemes are prioritized by their order in this array and
65
+ * only applied if the client supports them.
66
+ *
67
+ * @default ['gzip', 'deflate']
68
+ */
69
+ encodings?: readonly (typeof ORDERED_SUPPORTED_ENCODINGS)[number][];
70
+ /**
71
+ * The minimum response size in bytes required to trigger compression.
72
+ * Responses smaller than this threshold will not be compressed to avoid overhead.
73
+ * If the response size cannot be determined, compression will still be applied.
74
+ *
75
+ * @default 1024 (1KB)
76
+ */
77
+ threshold?: number;
78
+ /**
79
+ * Override the default content-type filter used to determine which responses should be compressed.
80
+ *
81
+ * @warning [Event Iterator](https://orpc.unnoq.com/docs/event-iterator) responses are never compressed, regardless of this filter's return value.
82
+ * @default only responses with compressible content types are compressed.
83
+ */
84
+ filter?: (request: Request, response: Response) => boolean;
85
+ }
86
+ /**
87
+ * The Compression Plugin adds response compression to the Fetch Server.
88
+ * Build on top of [CompressionStream](https://developer.mozilla.org/en-US/docs/Web/API/CompressionStream)
89
+ * You might need to polyfill it if your environment does not support it.
90
+ *
91
+ * @see {@link https://orpc.unnoq.com/docs/plugins/compression Compression Plugin Docs}
92
+ */
93
+ declare class CompressionPlugin<T extends Context> implements FetchHandlerPlugin<T> {
94
+ private readonly encodings;
95
+ private readonly threshold;
96
+ private readonly filter;
97
+ constructor(options?: CompressionPluginOptions);
98
+ initRuntimeAdapter(options: FetchHandlerOptions<T>): void;
99
+ }
100
+
101
+ export { BodyLimitPlugin, CompositeFetchHandlerPlugin, CompressionPlugin, FetchHandler };
102
+ export type { BodyLimitPluginOptions, CompressionPluginOptions, FetchHandleResult, FetchHandlerInterceptorOptions, FetchHandlerOptions, FetchHandlerPlugin };
@@ -0,0 +1,171 @@
1
+ import { ORPCError, toArray, intercept, resolveMaybeOptionalOptions } from '@temporary-name/shared';
2
+ import { toStandardLazyRequest, toFetchResponse } from '@temporary-name/standard-server-fetch';
3
+ import { r as resolveFriendlyStandardHandleOptions } from '../../shared/server.DZ5BIITo.mjs';
4
+ import '@temporary-name/standard-server';
5
+ import '@temporary-name/contract';
6
+ import '../../shared/server.D6K9uoPI.mjs';
7
+ import { C as CompositeStandardHandlerPlugin } from '../../shared/server.X0YaZxSJ.mjs';
8
+ import 'node:async_hooks';
9
+ import 'zod';
10
+ import 'zod/v4/core';
11
+
12
+ class BodyLimitPlugin {
13
+ maxBodySize;
14
+ constructor(options) {
15
+ this.maxBodySize = options.maxBodySize;
16
+ }
17
+ initRuntimeAdapter(options) {
18
+ options.adapterInterceptors ??= [];
19
+ options.adapterInterceptors.push(async (options2) => {
20
+ if (!options2.request.body) {
21
+ return options2.next();
22
+ }
23
+ let currentBodySize = 0;
24
+ const rawReader = options2.request.body.getReader();
25
+ const reader = new ReadableStream({
26
+ start: async (controller) => {
27
+ try {
28
+ if (Number(options2.request.headers.get("content-length")) > this.maxBodySize) {
29
+ controller.error(new ORPCError("PAYLOAD_TOO_LARGE"));
30
+ return;
31
+ }
32
+ while (true) {
33
+ const { done, value } = await rawReader.read();
34
+ if (done) {
35
+ break;
36
+ }
37
+ currentBodySize += value.length;
38
+ if (currentBodySize > this.maxBodySize) {
39
+ controller.error(new ORPCError("PAYLOAD_TOO_LARGE"));
40
+ break;
41
+ }
42
+ controller.enqueue(value);
43
+ }
44
+ } finally {
45
+ controller.close();
46
+ }
47
+ }
48
+ });
49
+ const requestInit = { body: reader, duplex: "half" };
50
+ return options2.next({
51
+ ...options2,
52
+ request: new Request(options2.request, requestInit)
53
+ });
54
+ });
55
+ }
56
+ }
57
+
58
+ const ORDERED_SUPPORTED_ENCODINGS = ["gzip", "deflate"];
59
+ class CompressionPlugin {
60
+ encodings;
61
+ threshold;
62
+ filter;
63
+ constructor(options = {}) {
64
+ this.encodings = options.encodings ?? ORDERED_SUPPORTED_ENCODINGS;
65
+ this.threshold = options.threshold ?? 1024;
66
+ this.filter = (request, response) => {
67
+ const hasContentDisposition = response.headers.has("content-disposition");
68
+ const contentType = response.headers.get("content-type");
69
+ if (!hasContentDisposition && contentType?.startsWith("text/event-stream")) {
70
+ return false;
71
+ }
72
+ return options.filter ? options.filter(request, response) : isCompressibleContentType(contentType);
73
+ };
74
+ }
75
+ initRuntimeAdapter(options) {
76
+ options.adapterInterceptors ??= [];
77
+ options.adapterInterceptors.unshift(async (options2) => {
78
+ const result = await options2.next();
79
+ if (!result.matched) {
80
+ return result;
81
+ }
82
+ const response = result.response;
83
+ if (response.headers.has("content-encoding") || // already encoded
84
+ response.headers.has("transfer-encoding") || // already encoded or chunked
85
+ isNoTransformCacheControl(response.headers.get("cache-control"))) {
86
+ return result;
87
+ }
88
+ const contentLength = response.headers.get("content-length");
89
+ if (contentLength && Number(contentLength) < this.threshold) {
90
+ return result;
91
+ }
92
+ const acceptEncoding = options2.request.headers.get("accept-encoding")?.split(",").map((enc) => enc.trim().split(";")[0]);
93
+ const encoding = this.encodings.find((enc) => acceptEncoding?.includes(enc));
94
+ if (!response.body || encoding === void 0) {
95
+ return result;
96
+ }
97
+ if (!this.filter(options2.request, response)) {
98
+ return result;
99
+ }
100
+ const compressedBody = response.body.pipeThrough(new CompressionStream(encoding));
101
+ const compressedHeaders = new Headers(response.headers);
102
+ compressedHeaders.delete("content-length");
103
+ compressedHeaders.set("content-encoding", encoding);
104
+ return {
105
+ ...result,
106
+ response: new Response(compressedBody, {
107
+ status: response.status,
108
+ statusText: response.statusText,
109
+ headers: compressedHeaders
110
+ })
111
+ };
112
+ });
113
+ }
114
+ }
115
+ const COMPRESSIBLE_CONTENT_TYPE_REGEX = /^\s*(?:text\/(?!event-stream(?:[;\s]|$))[^;\s]+|application\/(?:javascript|json|xml|xml-dtd|ecmascript|dart|postscript|rtf|tar|toml|vnd\.dart|vnd\.ms-fontobject|vnd\.ms-opentype|wasm|x-httpd-php|x-javascript|x-ns-proxy-autoconfig|x-sh|x-tar|x-virtualbox-hdd|x-virtualbox-ova|x-virtualbox-ovf|x-virtualbox-vbox|x-virtualbox-vdi|x-virtualbox-vhd|x-virtualbox-vmdk|x-www-form-urlencoded)|font\/(?:otf|ttf)|image\/(?:bmp|vnd\.adobe\.photoshop|vnd\.microsoft\.icon|vnd\.ms-dds|x-icon|x-ms-bmp)|message\/rfc822|model\/gltf-binary|x-shader\/x-fragment|x-shader\/x-vertex|[^;\s]+?\+(?:json|text|xml|yaml))(?:[;\s]|$)/i;
116
+ function isCompressibleContentType(contentType) {
117
+ if (contentType === null) {
118
+ return false;
119
+ }
120
+ return COMPRESSIBLE_CONTENT_TYPE_REGEX.test(contentType);
121
+ }
122
+ const CACHE_CONTROL_NO_TRANSFORM_REGEX = /(?:^|,)\s*no-transform\s*(?:,|$)/i;
123
+ function isNoTransformCacheControl(cacheControl) {
124
+ if (cacheControl === null) {
125
+ return false;
126
+ }
127
+ return CACHE_CONTROL_NO_TRANSFORM_REGEX.test(cacheControl);
128
+ }
129
+
130
+ class CompositeFetchHandlerPlugin extends CompositeStandardHandlerPlugin {
131
+ initRuntimeAdapter(options) {
132
+ for (const plugin of this.plugins) {
133
+ plugin.initRuntimeAdapter?.(options);
134
+ }
135
+ }
136
+ }
137
+
138
+ class FetchHandler {
139
+ constructor(standardHandler, options = {}) {
140
+ this.standardHandler = standardHandler;
141
+ const plugin = new CompositeFetchHandlerPlugin(options.plugins);
142
+ plugin.initRuntimeAdapter(options);
143
+ this.adapterInterceptors = toArray(options.adapterInterceptors);
144
+ this.toFetchResponseOptions = options;
145
+ }
146
+ toFetchResponseOptions;
147
+ adapterInterceptors;
148
+ async handle(request, ...rest) {
149
+ return intercept(
150
+ this.adapterInterceptors,
151
+ {
152
+ ...resolveFriendlyStandardHandleOptions(resolveMaybeOptionalOptions(rest)),
153
+ request,
154
+ toFetchResponseOptions: this.toFetchResponseOptions
155
+ },
156
+ async ({ request: request2, toFetchResponseOptions, ...options }) => {
157
+ const standardRequest = toStandardLazyRequest(request2);
158
+ const result = await this.standardHandler.handle(standardRequest, options);
159
+ if (!result.matched) {
160
+ return result;
161
+ }
162
+ return {
163
+ matched: true,
164
+ response: toFetchResponse(result.response, toFetchResponseOptions)
165
+ };
166
+ }
167
+ );
168
+ }
169
+ }
170
+
171
+ export { BodyLimitPlugin, CompositeFetchHandlerPlugin, CompressionPlugin, FetchHandler };
@@ -0,0 +1,77 @@
1
+ import { C as Context } from '../../shared/server.C1YnHvvf.mjs';
2
+ import { Interceptor, MaybeOptionalOptions } from '@temporary-name/shared';
3
+ import { SendStandardResponseOptions, NodeHttpRequest, NodeHttpResponse } from '@temporary-name/standard-server-node';
4
+ import { a as StandardHandlerPlugin, C as CompositeStandardHandlerPlugin, b as StandardHandleOptions, S as StandardHandler } from '../../shared/server.Bo94xDTv.mjs';
5
+ import { FriendlyStandardHandleOptions } from '../standard/index.mjs';
6
+ import compression from '@temporary-name/interop/compression';
7
+ import '@temporary-name/contract';
8
+ import '@temporary-name/standard-server';
9
+
10
+ interface NodeHttpHandlerPlugin<T extends Context> extends StandardHandlerPlugin<T> {
11
+ initRuntimeAdapter?(options: NodeHttpHandlerOptions<T>): void;
12
+ }
13
+ declare class CompositeNodeHttpHandlerPlugin<T extends Context, TPlugin extends NodeHttpHandlerPlugin<T>> extends CompositeStandardHandlerPlugin<T, TPlugin> implements NodeHttpHandlerPlugin<T> {
14
+ initRuntimeAdapter(options: NodeHttpHandlerOptions<T>): void;
15
+ }
16
+
17
+ type NodeHttpHandleResult = {
18
+ matched: true;
19
+ } | {
20
+ matched: false;
21
+ };
22
+ interface NodeHttpHandlerInterceptorOptions<T extends Context> extends StandardHandleOptions<T> {
23
+ request: NodeHttpRequest;
24
+ response: NodeHttpResponse;
25
+ sendStandardResponseOptions: SendStandardResponseOptions;
26
+ }
27
+ interface NodeHttpHandlerOptions<T extends Context> extends SendStandardResponseOptions {
28
+ adapterInterceptors?: Interceptor<NodeHttpHandlerInterceptorOptions<T>, Promise<NodeHttpHandleResult>>[];
29
+ plugins?: NodeHttpHandlerPlugin<T>[];
30
+ }
31
+ declare class NodeHttpHandler<T extends Context> implements NodeHttpHandler<T> {
32
+ private readonly standardHandler;
33
+ private readonly sendStandardResponseOptions;
34
+ private readonly adapterInterceptors;
35
+ constructor(standardHandler: StandardHandler<T>, options?: NoInfer<NodeHttpHandlerOptions<T>>);
36
+ handle(request: NodeHttpRequest, response: NodeHttpResponse, ...rest: MaybeOptionalOptions<FriendlyStandardHandleOptions<T>>): Promise<NodeHttpHandleResult>;
37
+ }
38
+
39
+ interface BodyLimitPluginOptions {
40
+ /**
41
+ * The maximum size of the body in bytes.
42
+ */
43
+ maxBodySize: number;
44
+ }
45
+ /**
46
+ * The Body Limit Plugin restricts the size of the request body for the Node.js HTTP Server.
47
+ *
48
+ * @see {@link https://orpc.unnoq.com/docs/plugins/body-limit Body Limit Plugin Docs}
49
+ */
50
+ declare class BodyLimitPlugin<T extends Context> implements NodeHttpHandlerPlugin<T> {
51
+ private readonly maxBodySize;
52
+ constructor(options: BodyLimitPluginOptions);
53
+ initRuntimeAdapter(options: NodeHttpHandlerOptions<T>): void;
54
+ }
55
+
56
+ interface CompressionPluginOptions extends compression.CompressionOptions {
57
+ /**
58
+ * Override the default content-type filter used to determine which responses should be compressed.
59
+ *
60
+ * @warning [Event Iterator](https://orpc.unnoq.com/docs/event-iterator) responses are never compressed, regardless of this filter's return value.
61
+ * @default only responses with compressible content types are compressed.
62
+ */
63
+ filter?: (req: NodeHttpRequest, res: NodeHttpResponse) => boolean;
64
+ }
65
+ /**
66
+ * The Compression Plugin adds response compression to the Node.js HTTP Server.
67
+ *
68
+ * @see {@link https://orpc.unnoq.com/docs/plugins/compression Compression Plugin Docs}
69
+ */
70
+ declare class CompressionPlugin<T extends Context> implements NodeHttpHandlerPlugin<T> {
71
+ private readonly compressionHandler;
72
+ constructor(options?: CompressionPluginOptions);
73
+ initRuntimeAdapter(options: NodeHttpHandlerOptions<T>): void;
74
+ }
75
+
76
+ export { BodyLimitPlugin, CompositeNodeHttpHandlerPlugin, CompressionPlugin, NodeHttpHandler };
77
+ export type { BodyLimitPluginOptions, CompressionPluginOptions, NodeHttpHandleResult, NodeHttpHandlerInterceptorOptions, NodeHttpHandlerOptions, NodeHttpHandlerPlugin };
@@ -0,0 +1,77 @@
1
+ import { C as Context } from '../../shared/server.C1YnHvvf.js';
2
+ import { Interceptor, MaybeOptionalOptions } from '@temporary-name/shared';
3
+ import { SendStandardResponseOptions, NodeHttpRequest, NodeHttpResponse } from '@temporary-name/standard-server-node';
4
+ import { a as StandardHandlerPlugin, C as CompositeStandardHandlerPlugin, b as StandardHandleOptions, S as StandardHandler } from '../../shared/server.Btxrgkj5.js';
5
+ import { FriendlyStandardHandleOptions } from '../standard/index.js';
6
+ import compression from '@temporary-name/interop/compression';
7
+ import '@temporary-name/contract';
8
+ import '@temporary-name/standard-server';
9
+
10
+ interface NodeHttpHandlerPlugin<T extends Context> extends StandardHandlerPlugin<T> {
11
+ initRuntimeAdapter?(options: NodeHttpHandlerOptions<T>): void;
12
+ }
13
+ declare class CompositeNodeHttpHandlerPlugin<T extends Context, TPlugin extends NodeHttpHandlerPlugin<T>> extends CompositeStandardHandlerPlugin<T, TPlugin> implements NodeHttpHandlerPlugin<T> {
14
+ initRuntimeAdapter(options: NodeHttpHandlerOptions<T>): void;
15
+ }
16
+
17
+ type NodeHttpHandleResult = {
18
+ matched: true;
19
+ } | {
20
+ matched: false;
21
+ };
22
+ interface NodeHttpHandlerInterceptorOptions<T extends Context> extends StandardHandleOptions<T> {
23
+ request: NodeHttpRequest;
24
+ response: NodeHttpResponse;
25
+ sendStandardResponseOptions: SendStandardResponseOptions;
26
+ }
27
+ interface NodeHttpHandlerOptions<T extends Context> extends SendStandardResponseOptions {
28
+ adapterInterceptors?: Interceptor<NodeHttpHandlerInterceptorOptions<T>, Promise<NodeHttpHandleResult>>[];
29
+ plugins?: NodeHttpHandlerPlugin<T>[];
30
+ }
31
+ declare class NodeHttpHandler<T extends Context> implements NodeHttpHandler<T> {
32
+ private readonly standardHandler;
33
+ private readonly sendStandardResponseOptions;
34
+ private readonly adapterInterceptors;
35
+ constructor(standardHandler: StandardHandler<T>, options?: NoInfer<NodeHttpHandlerOptions<T>>);
36
+ handle(request: NodeHttpRequest, response: NodeHttpResponse, ...rest: MaybeOptionalOptions<FriendlyStandardHandleOptions<T>>): Promise<NodeHttpHandleResult>;
37
+ }
38
+
39
+ interface BodyLimitPluginOptions {
40
+ /**
41
+ * The maximum size of the body in bytes.
42
+ */
43
+ maxBodySize: number;
44
+ }
45
+ /**
46
+ * The Body Limit Plugin restricts the size of the request body for the Node.js HTTP Server.
47
+ *
48
+ * @see {@link https://orpc.unnoq.com/docs/plugins/body-limit Body Limit Plugin Docs}
49
+ */
50
+ declare class BodyLimitPlugin<T extends Context> implements NodeHttpHandlerPlugin<T> {
51
+ private readonly maxBodySize;
52
+ constructor(options: BodyLimitPluginOptions);
53
+ initRuntimeAdapter(options: NodeHttpHandlerOptions<T>): void;
54
+ }
55
+
56
+ interface CompressionPluginOptions extends compression.CompressionOptions {
57
+ /**
58
+ * Override the default content-type filter used to determine which responses should be compressed.
59
+ *
60
+ * @warning [Event Iterator](https://orpc.unnoq.com/docs/event-iterator) responses are never compressed, regardless of this filter's return value.
61
+ * @default only responses with compressible content types are compressed.
62
+ */
63
+ filter?: (req: NodeHttpRequest, res: NodeHttpResponse) => boolean;
64
+ }
65
+ /**
66
+ * The Compression Plugin adds response compression to the Node.js HTTP Server.
67
+ *
68
+ * @see {@link https://orpc.unnoq.com/docs/plugins/compression Compression Plugin Docs}
69
+ */
70
+ declare class CompressionPlugin<T extends Context> implements NodeHttpHandlerPlugin<T> {
71
+ private readonly compressionHandler;
72
+ constructor(options?: CompressionPluginOptions);
73
+ initRuntimeAdapter(options: NodeHttpHandlerOptions<T>): void;
74
+ }
75
+
76
+ export { BodyLimitPlugin, CompositeNodeHttpHandlerPlugin, CompressionPlugin, NodeHttpHandler };
77
+ export type { BodyLimitPluginOptions, CompressionPluginOptions, NodeHttpHandleResult, NodeHttpHandlerInterceptorOptions, NodeHttpHandlerOptions, NodeHttpHandlerPlugin };