@orpc/server 2.0.0-beta.4 → 2.0.0-beta.40
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/README.md +97 -94
- package/dist/adapters/aws-lambda/index.d.mts +50 -0
- package/dist/adapters/aws-lambda/index.d.ts +50 -0
- package/dist/adapters/aws-lambda/index.mjs +39 -0
- package/dist/adapters/crossws/index.d.mts +21 -12
- package/dist/adapters/crossws/index.d.ts +21 -12
- package/dist/adapters/crossws/index.mjs +14 -10
- package/dist/adapters/fastify/index.d.mts +42 -0
- package/dist/adapters/fastify/index.d.ts +42 -0
- package/dist/adapters/fastify/index.mjs +39 -0
- package/dist/adapters/fetch/index.d.mts +21 -114
- package/dist/adapters/fetch/index.d.ts +21 -114
- package/dist/adapters/fetch/index.mjs +20 -182
- package/dist/adapters/message-port/index.d.mts +23 -20
- package/dist/adapters/message-port/index.d.ts +23 -20
- package/dist/adapters/message-port/index.mjs +31 -34
- package/dist/adapters/node/index.d.mts +19 -96
- package/dist/adapters/node/index.d.ts +19 -96
- package/dist/adapters/node/index.mjs +19 -157
- package/dist/adapters/standard/index.d.mts +91 -17
- package/dist/adapters/standard/index.d.ts +91 -17
- package/dist/adapters/standard/index.mjs +4 -4
- package/dist/adapters/standard-peer/index.d.mts +6 -11
- package/dist/adapters/standard-peer/index.d.ts +6 -11
- package/dist/adapters/standard-peer/index.mjs +10 -2
- package/dist/adapters/websocket/index.d.mts +45 -29
- package/dist/adapters/websocket/index.d.ts +45 -29
- package/dist/adapters/websocket/index.mjs +37 -28
- package/dist/extensions/callable.d.mts +5 -5
- package/dist/extensions/callable.d.ts +5 -5
- package/dist/extensions/callable.mjs +2 -2
- package/dist/helpers/index.d.mts +23 -6
- package/dist/helpers/index.d.ts +23 -6
- package/dist/helpers/index.mjs +13 -5
- package/dist/index.d.mts +332 -37
- package/dist/index.d.ts +332 -37
- package/dist/index.mjs +131 -49
- package/dist/plugins/index.d.mts +243 -31
- package/dist/plugins/index.d.ts +243 -31
- package/dist/plugins/index.mjs +527 -30
- package/dist/shared/server.1ExWFMze.mjs +69 -0
- package/dist/shared/{server.CjOb6ItT.mjs → server.24nXyhbl.mjs} +1 -1
- package/dist/shared/{server.DBANIheG.d.ts → server.B5K1CViq.d.mts} +24 -13
- package/dist/shared/{server.BsNNjG5J.d.mts → server.BpmUhems.d.mts} +32 -20
- package/dist/shared/{server.BL22TloH.d.mts → server.BsujoJoF.d.mts} +38 -59
- package/dist/shared/{server.BL22TloH.d.ts → server.BsujoJoF.d.ts} +38 -59
- package/dist/shared/{server.BwHnWUuN.mjs → server.BynNaBBA.mjs} +24 -19
- package/dist/shared/{server.GDpX6Df8.mjs → server.C0lFtoHU.mjs} +162 -68
- package/dist/shared/server.C7xllBNN.d.mts +34 -0
- package/dist/shared/server.CFqSIFnT.d.mts +14 -0
- package/dist/shared/{server.Pa0F03f_.d.ts → server.CRwPbhLO.d.ts} +32 -20
- package/dist/shared/{server.DJIkub_t.d.mts → server.Cxranw-8.d.ts} +24 -13
- package/dist/shared/server.D0dr-F8u.d.ts +34 -0
- package/dist/shared/{server.CrlKQucM.mjs → server.Djb_ebJT.mjs} +25 -53
- package/dist/shared/server.RRVK1xTV.d.ts +14 -0
- package/package.json +47 -14
- package/dist/shared/server.CX4vUnDk.mjs +0 -11
- package/dist/shared/server.Cj5lgPuG.d.mts +0 -66
- package/dist/shared/server.D_QauotT.mjs +0 -30
- package/dist/shared/server.d_2NS3g5.d.ts +0 -66
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AnyORPCError } from '@orpc/client';
|
|
2
|
-
import { OrderablePlugin,
|
|
3
|
-
import { StandardLazyRequest, StandardResponse } from '@
|
|
4
|
-
import { C as Context, c as ProcedureClientInterceptor, A as AnyProcedure } from './server.
|
|
2
|
+
import { OrderablePlugin, Value, Promisable, Interceptor } from '@orpc/shared';
|
|
3
|
+
import { StandardLazyRequest, StandardResponse } from '@standard-server/core';
|
|
4
|
+
import { C as Context, c as ProcedureClientInterceptor, A as AnyProcedure } from './server.BsujoJoF.js';
|
|
5
5
|
import { Schema, ErrorMap } from '@orpc/contract';
|
|
6
6
|
|
|
7
7
|
interface StandardHandlerPlugin<T extends Context> extends OrderablePlugin {
|
|
@@ -36,6 +36,17 @@ declare class CompositeStandardHandlerPlugin<T extends Context> implements Stand
|
|
|
36
36
|
|
|
37
37
|
interface StandardHandlerHandleOptions<T extends Context> {
|
|
38
38
|
prefix?: `/${string}` | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* The initial context, or a function (sync or async) that receives the request and returns it.
|
|
41
|
+
* The function only runs once the request passes the prefix check.
|
|
42
|
+
*/
|
|
43
|
+
context: Value<Promisable<T>, [request: StandardLazyRequest]>;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* `StandardHandlerHandleOptions` after the context has been resolved,
|
|
47
|
+
* this is what interceptors and codecs receive.
|
|
48
|
+
*/
|
|
49
|
+
interface ResolvedStandardHandlerHandleOptions<T extends Context> extends Omit<StandardHandlerHandleOptions<T>, 'context'> {
|
|
39
50
|
context: T;
|
|
40
51
|
}
|
|
41
52
|
type StandardHandlerHandleResult = {
|
|
@@ -45,11 +56,11 @@ type StandardHandlerHandleResult = {
|
|
|
45
56
|
matched: false;
|
|
46
57
|
response?: undefined;
|
|
47
58
|
};
|
|
48
|
-
interface StandardHandlerInterceptorOptions<T extends Context> extends StandardHandlerCodecResolvedProcedure,
|
|
59
|
+
interface StandardHandlerInterceptorOptions<T extends Context> extends StandardHandlerCodecResolvedProcedure, ResolvedStandardHandlerHandleOptions<T> {
|
|
49
60
|
request: StandardLazyRequest;
|
|
50
61
|
}
|
|
51
62
|
type StandardHandlerInterceptor<T extends Context> = Interceptor<StandardHandlerInterceptorOptions<T>, Promise<StandardResponse>>;
|
|
52
|
-
interface StandardHandlerRoutingInterceptorOptions<T extends Context> extends
|
|
63
|
+
interface StandardHandlerRoutingInterceptorOptions<T extends Context> extends ResolvedStandardHandlerHandleOptions<T> {
|
|
53
64
|
request: StandardLazyRequest;
|
|
54
65
|
}
|
|
55
66
|
type StandardHandlerRoutingInterceptor<T extends Context> = Interceptor<StandardHandlerRoutingInterceptorOptions<T>, Promise<StandardHandlerHandleResult>>;
|
|
@@ -73,7 +84,7 @@ interface StandardHandlerOptions<TContext extends Context> {
|
|
|
73
84
|
* ClientInterceptor equivalent with createRouterClient.interceptors / createProcedure.interceptors
|
|
74
85
|
* useful for error handling, logging, metrics, etc. (not counting encoding/decoding)
|
|
75
86
|
*/
|
|
76
|
-
clientInterceptors?: ProcedureClientInterceptor<TContext, Schema<unknown>, ErrorMap
|
|
87
|
+
clientInterceptors?: ProcedureClientInterceptor<TContext, Schema<unknown>, ErrorMap>[];
|
|
77
88
|
plugins?: StandardHandlerPlugin<TContext>[];
|
|
78
89
|
}
|
|
79
90
|
declare class StandardHandler<T extends Context> {
|
|
@@ -82,9 +93,9 @@ declare class StandardHandler<T extends Context> {
|
|
|
82
93
|
private readonly interceptors;
|
|
83
94
|
private readonly clientInterceptors;
|
|
84
95
|
constructor(codec: StandardHandlerCodec<T>, options: StandardHandlerOptions<T>);
|
|
85
|
-
handle(request: StandardLazyRequest,
|
|
96
|
+
handle(request: StandardLazyRequest, options: StandardHandlerHandleOptions<T>): Promise<StandardHandlerHandleResult>;
|
|
86
97
|
}
|
|
87
|
-
declare class
|
|
98
|
+
declare class TracingHandlerPlugin implements StandardHandlerPlugin<any> {
|
|
88
99
|
name: string;
|
|
89
100
|
init(options: StandardHandlerOptions<any>): StandardHandlerOptions<any>;
|
|
90
101
|
}
|
|
@@ -95,10 +106,10 @@ interface StandardHandlerCodecResolvedProcedure {
|
|
|
95
106
|
decodeInput: () => Promise<unknown>;
|
|
96
107
|
}
|
|
97
108
|
interface StandardHandlerCodec<T extends Context> {
|
|
98
|
-
resolveProcedure(request: StandardLazyRequest, options:
|
|
99
|
-
encodeOutput(output: unknown, procedure: AnyProcedure, path: string[], options:
|
|
100
|
-
encodeError(error: AnyORPCError, procedure: AnyProcedure, path: string[], options:
|
|
109
|
+
resolveProcedure(request: StandardLazyRequest, options: ResolvedStandardHandlerHandleOptions<T>): Promisable<StandardHandlerCodecResolvedProcedure | undefined>;
|
|
110
|
+
encodeOutput(output: unknown, procedure: AnyProcedure, path: string[], options: ResolvedStandardHandlerHandleOptions<T>): Promisable<StandardResponse>;
|
|
111
|
+
encodeError(error: AnyORPCError, procedure: AnyProcedure, path: string[], options: ResolvedStandardHandlerHandleOptions<T>): Promisable<StandardResponse>;
|
|
101
112
|
}
|
|
102
113
|
|
|
103
|
-
export { CompositeStandardHandlerPlugin as C,
|
|
104
|
-
export type {
|
|
114
|
+
export { CompositeStandardHandlerPlugin as C, StandardHandler as S, TracingHandlerPlugin as T };
|
|
115
|
+
export type { ResolvedStandardHandlerHandleOptions as R, StandardHandlerHandleOptions as a, StandardHandlerPlugin as b, StandardHandlerOptions as c, StandardHandlerRoutingInterceptorOptions as d, StandardHandlerInterceptorOptions as e, StandardHandlerCodec as f, StandardHandlerCodecResolvedProcedure as g, StandardHandlerHandleResult as h, StandardHandlerInterceptor as i, StandardHandlerRoutingInterceptor as j };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { C as Context } from './server.BsujoJoF.js';
|
|
2
|
+
import { b as StandardHandlerPlugin, c as StandardHandlerOptions } from './server.Cxranw-8.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 };
|
|
@@ -1,32 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { reconcileORPCError, ValidationError, ProcedureContract } from '@orpc/contract';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
function createORPCErrorConstructorMap(errorMap) {
|
|
6
|
-
const proxy = new Proxy(errorMap, {
|
|
7
|
-
get(target, code) {
|
|
8
|
-
if (typeof code !== "string") {
|
|
9
|
-
return getOrBind(target, code);
|
|
10
|
-
}
|
|
11
|
-
const item = (...rest) => {
|
|
12
|
-
const options = resolveMaybeOptionalOptions(rest);
|
|
13
|
-
const config = errorMap[code];
|
|
14
|
-
const error = new ORPCError(code, {
|
|
15
|
-
message: options.message ?? config?.message,
|
|
16
|
-
data: options.data,
|
|
17
|
-
cause: options.cause
|
|
18
|
-
});
|
|
19
|
-
if (config) {
|
|
20
|
-
error.defined = true;
|
|
21
|
-
error.inferable = true;
|
|
22
|
-
}
|
|
23
|
-
return error;
|
|
24
|
-
};
|
|
25
|
-
return item;
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
return proxy;
|
|
29
|
-
}
|
|
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, isPlainObject, mergeTwoLevels } from '@orpc/shared';
|
|
30
4
|
|
|
31
5
|
class Lazy {
|
|
32
6
|
"~orpc";
|
|
@@ -34,7 +8,7 @@ class Lazy {
|
|
|
34
8
|
this["~orpc"] = def;
|
|
35
9
|
}
|
|
36
10
|
/**
|
|
37
|
-
* Checks if the given instance satisfies the {@
|
|
11
|
+
* Checks if the given instance satisfies the {@link Lazy} class/interface.
|
|
38
12
|
*/
|
|
39
13
|
static [Symbol.hasInstance](instance) {
|
|
40
14
|
if (this !== Lazy) {
|
|
@@ -84,12 +58,11 @@ function createProcedureClient(lazyableProcedure, ...rest) {
|
|
|
84
58
|
);
|
|
85
59
|
});
|
|
86
60
|
if (isAsyncIteratorObject(output)) {
|
|
87
|
-
return override(output,
|
|
88
|
-
traceAsyncIterator("
|
|
61
|
+
return override(output, wrapAsyncIteratorPreservingEventMeta(
|
|
62
|
+
getTracer() ? traceAsyncIterator("consume_async_iterator_object_output", output) : output,
|
|
89
63
|
{ mapError: reconcileError }
|
|
90
64
|
));
|
|
91
|
-
}
|
|
92
|
-
if (output instanceof ReadableStream) {
|
|
65
|
+
} else if (getTracer() && output instanceof ReadableStream) {
|
|
93
66
|
return override(output, traceReadableStream("consume_octet_stream_output", output));
|
|
94
67
|
}
|
|
95
68
|
return output;
|
|
@@ -149,10 +122,19 @@ async function executeProcedureInternal(procedure, options) {
|
|
|
149
122
|
const orderedMiddlewares = procedure["~orpc"].orderedMiddlewares;
|
|
150
123
|
const next = async (midIndex, context, input) => {
|
|
151
124
|
let currentInput = input;
|
|
125
|
+
let middlewareInput = input;
|
|
152
126
|
const startInputIndex = midIndex === 0 ? 0 : orderedMiddlewares[midIndex - 1].inputSchemasLengthAtUse ?? 0;
|
|
153
127
|
const endInputIndex = midIndex === orderedMiddlewares.length ? inputSchemas.length : orderedMiddlewares[midIndex].inputSchemasLengthAtUse ?? 0;
|
|
154
|
-
|
|
155
|
-
|
|
128
|
+
if (!procedure["~orpc"].disableInputValidation) {
|
|
129
|
+
for (let i = startInputIndex; i < endInputIndex; i++) {
|
|
130
|
+
const validated = await validateInput(
|
|
131
|
+
i,
|
|
132
|
+
inputSchemas[i],
|
|
133
|
+
inputSchemas.length > 1 && isPlainObject(currentInput) ? options.input : currentInput
|
|
134
|
+
);
|
|
135
|
+
currentInput = i !== 0 ? mergeTwoLevels(currentInput, validated) : validated;
|
|
136
|
+
}
|
|
137
|
+
middlewareInput = endInputIndex > 0 && endInputIndex < inputSchemas.length ? mergeTwoLevels(options.input, currentInput) : currentInput;
|
|
156
138
|
}
|
|
157
139
|
let currentOutput;
|
|
158
140
|
let currentContext = context;
|
|
@@ -175,7 +157,7 @@ async function executeProcedureInternal(procedure, options) {
|
|
|
175
157
|
},
|
|
176
158
|
lastEventId: options.lastEventId
|
|
177
159
|
},
|
|
178
|
-
|
|
160
|
+
middlewareInput,
|
|
179
161
|
middlewareDone
|
|
180
162
|
);
|
|
181
163
|
});
|
|
@@ -186,23 +168,13 @@ async function executeProcedureInternal(procedure, options) {
|
|
|
186
168
|
"handler",
|
|
187
169
|
() => procedure["~orpc"].handler({ ...options, context, input: currentInput }, currentInput)
|
|
188
170
|
);
|
|
189
|
-
if (currentOutput instanceof ORPCError) {
|
|
190
|
-
if (procedure["~orpc"].opaqueReturnedErrors) {
|
|
191
|
-
throw currentOutput;
|
|
192
|
-
}
|
|
193
|
-
if (currentOutput.inferable && !currentOutput.defined) {
|
|
194
|
-
throw currentOutput;
|
|
195
|
-
}
|
|
196
|
-
const error = cloneORPCError(currentOutput);
|
|
197
|
-
error.defined = false;
|
|
198
|
-
error.inferable = true;
|
|
199
|
-
throw error;
|
|
200
|
-
}
|
|
201
171
|
}
|
|
202
172
|
const startOutputIndex = midIndex === 0 ? 0 : orderedMiddlewares[midIndex - 1].outputSchemasLengthAtUse ?? 0;
|
|
203
173
|
const endOutputIndex = midIndex === orderedMiddlewares.length ? outputSchemas.length : orderedMiddlewares[midIndex].outputSchemasLengthAtUse ?? 0;
|
|
204
|
-
|
|
205
|
-
|
|
174
|
+
if (!procedure["~orpc"].disableOutputValidation) {
|
|
175
|
+
for (let i = endOutputIndex - 1; i >= startOutputIndex; i--) {
|
|
176
|
+
currentOutput = await validateOutput(i, outputSchemas[i], currentOutput);
|
|
177
|
+
}
|
|
206
178
|
}
|
|
207
179
|
return { output: currentOutput, context: currentContext };
|
|
208
180
|
};
|
|
@@ -216,7 +188,7 @@ class Procedure {
|
|
|
216
188
|
this["~orpc"] = def;
|
|
217
189
|
}
|
|
218
190
|
/**
|
|
219
|
-
* Checks if the given instance satisfies the {@
|
|
191
|
+
* Checks if the given instance satisfies the {@link Procedure} class/interface.
|
|
220
192
|
*/
|
|
221
193
|
static [Symbol.hasInstance](instance) {
|
|
222
194
|
if (this !== Procedure) {
|
|
@@ -230,4 +202,4 @@ class Procedure {
|
|
|
230
202
|
}
|
|
231
203
|
}
|
|
232
204
|
|
|
233
|
-
export { Lazy as L, Procedure as P,
|
|
205
|
+
export { Lazy as L, Procedure as P, createProcedureClient as c, unlazy as u };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Value, Promisable } from '@orpc/shared';
|
|
2
|
+
import { StandardLazyRequest } from '@standard-server/core';
|
|
3
|
+
import { C as Context } from './server.BsujoJoF.js';
|
|
4
|
+
import { a as StandardHandlerHandleOptions } from './server.Cxranw-8.js';
|
|
5
|
+
|
|
6
|
+
type FriendlyStandardHandlerHandleOptions<T extends Context> = Omit<StandardHandlerHandleOptions<T>, 'context'> & (object extends T ? {
|
|
7
|
+
context?: Value<Promisable<T>, [request: StandardLazyRequest]>;
|
|
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 };
|
package/package.json
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/server",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.0.0-beta.
|
|
4
|
+
"version": "2.0.0-beta.40",
|
|
5
|
+
"description": "Build typesafe APIs with oRPC: RPC and OpenAPI support, middleware, and adapters for Node.js, Bun, Deno, Fetch, Fastify, WebSocket, AWS Lambda, and more",
|
|
5
6
|
"license": "MIT",
|
|
7
|
+
"funding": [
|
|
8
|
+
"https://github.com/sponsors/dinwwwh",
|
|
9
|
+
"https://opencollective.com/middleapi"
|
|
10
|
+
],
|
|
6
11
|
"homepage": "https://orpc.dev",
|
|
7
12
|
"repository": {
|
|
8
13
|
"type": "git",
|
|
@@ -10,7 +15,20 @@
|
|
|
10
15
|
"directory": "packages/server"
|
|
11
16
|
},
|
|
12
17
|
"keywords": [
|
|
13
|
-
"orpc"
|
|
18
|
+
"orpc",
|
|
19
|
+
"rpc",
|
|
20
|
+
"api",
|
|
21
|
+
"typescript",
|
|
22
|
+
"typesafe",
|
|
23
|
+
"server",
|
|
24
|
+
"openapi",
|
|
25
|
+
"middleware",
|
|
26
|
+
"nodejs",
|
|
27
|
+
"bun",
|
|
28
|
+
"deno",
|
|
29
|
+
"fastify",
|
|
30
|
+
"websocket",
|
|
31
|
+
"aws-lambda"
|
|
14
32
|
],
|
|
15
33
|
"sideEffects": [
|
|
16
34
|
"./dist/extensions/callable.mjs"
|
|
@@ -52,6 +70,16 @@
|
|
|
52
70
|
"import": "./dist/adapters/node/index.mjs",
|
|
53
71
|
"default": "./dist/adapters/node/index.mjs"
|
|
54
72
|
},
|
|
73
|
+
"./aws-lambda": {
|
|
74
|
+
"types": "./dist/adapters/aws-lambda/index.d.mts",
|
|
75
|
+
"import": "./dist/adapters/aws-lambda/index.mjs",
|
|
76
|
+
"default": "./dist/adapters/aws-lambda/index.mjs"
|
|
77
|
+
},
|
|
78
|
+
"./fastify": {
|
|
79
|
+
"types": "./dist/adapters/fastify/index.d.mts",
|
|
80
|
+
"import": "./dist/adapters/fastify/index.mjs",
|
|
81
|
+
"default": "./dist/adapters/fastify/index.mjs"
|
|
82
|
+
},
|
|
55
83
|
"./websocket": {
|
|
56
84
|
"types": "./dist/adapters/websocket/index.d.mts",
|
|
57
85
|
"import": "./dist/adapters/websocket/index.mjs",
|
|
@@ -77,31 +105,36 @@
|
|
|
77
105
|
"dist"
|
|
78
106
|
],
|
|
79
107
|
"peerDependencies": {
|
|
80
|
-
"crossws": ">=0.3.4"
|
|
108
|
+
"crossws": ">=0.3.4",
|
|
109
|
+
"fastify": ">=5.6.1"
|
|
81
110
|
},
|
|
82
111
|
"peerDependenciesMeta": {
|
|
83
112
|
"crossws": {
|
|
84
113
|
"optional": true
|
|
114
|
+
},
|
|
115
|
+
"fastify": {
|
|
116
|
+
"optional": true
|
|
85
117
|
}
|
|
86
118
|
},
|
|
87
119
|
"dependencies": {
|
|
88
|
-
"@
|
|
89
|
-
"@
|
|
90
|
-
"@
|
|
91
|
-
"@
|
|
92
|
-
"
|
|
93
|
-
"@
|
|
94
|
-
"@
|
|
95
|
-
"@
|
|
96
|
-
"@
|
|
120
|
+
"@orpc/client": "2.0.0-beta.40",
|
|
121
|
+
"@orpc/contract": "2.0.0-beta.40",
|
|
122
|
+
"@orpc/shared": "2.0.0-beta.40",
|
|
123
|
+
"@standard-server/aws-lambda": "~0.9.2",
|
|
124
|
+
"@standard-server/core": "~0.9.2",
|
|
125
|
+
"@standard-server/fastify": "~0.9.2",
|
|
126
|
+
"@standard-server/fetch": "~0.9.2",
|
|
127
|
+
"@standard-server/node": "~0.9.2",
|
|
128
|
+
"@standard-server/peer": "~0.9.2",
|
|
129
|
+
"cookie": "^2.0.1"
|
|
97
130
|
},
|
|
98
131
|
"devDependencies": {
|
|
99
132
|
"crossws": "^0.4.6",
|
|
133
|
+
"fastify": "^5.12.1",
|
|
100
134
|
"supertest": "^7.2.2",
|
|
101
|
-
"zod": "^4.4
|
|
135
|
+
"zod": "^4.5.4"
|
|
102
136
|
},
|
|
103
137
|
"scripts": {
|
|
104
|
-
"build": "unbuild",
|
|
105
138
|
"type:check": "tsc -b"
|
|
106
139
|
}
|
|
107
140
|
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { value } from '@orpc/shared';
|
|
2
|
-
|
|
3
|
-
function createStandardPeerRequestHandler(handler, options) {
|
|
4
|
-
return async (request) => {
|
|
5
|
-
const context = await value(options.context ?? {}, request);
|
|
6
|
-
const { response } = await handler.handle(request, { ...options, context });
|
|
7
|
-
return response ?? { status: 404, headers: {}, body: "No procedure matched" };
|
|
8
|
-
};
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export { createStandardPeerRequestHandler as c };
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { RPCSerializer, AnyORPCError } from '@orpc/client';
|
|
2
|
-
import { Value, Promisable } from '@orpc/shared';
|
|
3
|
-
import { StandardMethod, StandardLazyRequest, StandardResponse } from '@standardserver/core';
|
|
4
|
-
import { A as AnyProcedure, C as Context } from './server.BL22TloH.mjs';
|
|
5
|
-
import { A as AnyRouter } from './server.BsNNjG5J.mjs';
|
|
6
|
-
import { AnyProcedureContract } from '@orpc/contract';
|
|
7
|
-
import { b as StandardHandlerHandleOptions, c as StandardHandlerCodec, d as StandardHandlerCodecResolvedProcedure } from './server.DJIkub_t.mjs';
|
|
8
|
-
|
|
9
|
-
interface RPCMatcherOptions {
|
|
10
|
-
/**
|
|
11
|
-
* Filter which procedures are exposed for matching. Return `false` to exclude.
|
|
12
|
-
*
|
|
13
|
-
* @default true
|
|
14
|
-
*/
|
|
15
|
-
filter?: Value<boolean, [procedure: AnyProcedureContract | AnyProcedure, path: string[]]>;
|
|
16
|
-
}
|
|
17
|
-
declare class RPCMatcher {
|
|
18
|
-
private readonly filter;
|
|
19
|
-
private readonly rootRouter;
|
|
20
|
-
private readonly tree;
|
|
21
|
-
private pendingLazyRouters;
|
|
22
|
-
constructor(router: AnyRouter, options?: RPCMatcherOptions);
|
|
23
|
-
private index;
|
|
24
|
-
match(_method: StandardMethod, pathname: `/${string}`, prefix: `/${string}` | undefined): Promise<{
|
|
25
|
-
path: string[];
|
|
26
|
-
procedure: AnyProcedure;
|
|
27
|
-
} | undefined>;
|
|
28
|
-
private matchPathname;
|
|
29
|
-
private resolvePendingLazyRouters;
|
|
30
|
-
private resolveProcedure;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
interface RPCHandlerCodecOptions<T extends Context> extends RPCMatcherOptions {
|
|
34
|
-
/**
|
|
35
|
-
* Override the default RPC serializer.
|
|
36
|
-
*/
|
|
37
|
-
serializer?: Pick<RPCSerializer, keyof RPCSerializer>;
|
|
38
|
-
/**
|
|
39
|
-
* Resolve HTTP status for encoded successful outputs.
|
|
40
|
-
*
|
|
41
|
-
* Value should be in range `200-299`
|
|
42
|
-
* Return `undefined` or `null` to fallback to default
|
|
43
|
-
*
|
|
44
|
-
* @default DEFAULT_ERROR_STATUS, DEFAULT_ERROR_STATUS
|
|
45
|
-
*/
|
|
46
|
-
outputStatus?: Value<number | undefined | null, [output: unknown, procedure: AnyProcedure, path: string[], options: StandardHandlerHandleOptions<T>]>;
|
|
47
|
-
/**
|
|
48
|
-
* Mapping ORPCError Code -> HTTP Status Code
|
|
49
|
-
*
|
|
50
|
-
* @default COMMON_ERROR_STATUS_MAP
|
|
51
|
-
*/
|
|
52
|
-
errorStatusMap?: Record<string, number> | undefined;
|
|
53
|
-
}
|
|
54
|
-
declare class RPCHandlerCodec<T extends Context> implements StandardHandlerCodec<T> {
|
|
55
|
-
private readonly matcher;
|
|
56
|
-
private readonly serializer;
|
|
57
|
-
private readonly errorStatusMap;
|
|
58
|
-
private readonly outputStatus;
|
|
59
|
-
constructor(router: AnyRouter, options?: RPCHandlerCodecOptions<T>);
|
|
60
|
-
resolveProcedure(request: StandardLazyRequest, options: StandardHandlerHandleOptions<T>): Promise<StandardHandlerCodecResolvedProcedure | undefined>;
|
|
61
|
-
encodeOutput(output: unknown, procedure: AnyProcedure, path: string[], options: StandardHandlerHandleOptions<T>): Promisable<StandardResponse>;
|
|
62
|
-
encodeError(error: AnyORPCError, _procedure: AnyProcedure, _path: string[], _options: StandardHandlerHandleOptions<T>): Promisable<StandardResponse>;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export { RPCHandlerCodec as a, RPCMatcher as b };
|
|
66
|
-
export type { RPCHandlerCodecOptions as R, RPCMatcherOptions as c };
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { ORPCError } from '@orpc/client';
|
|
2
|
-
import { toArray } from '@orpc/shared';
|
|
3
|
-
import { flattenStandardHeader } from '@standardserver/core';
|
|
4
|
-
|
|
5
|
-
class CSRFGuardHandlerPlugin {
|
|
6
|
-
name = "~csrf-guard";
|
|
7
|
-
init(options) {
|
|
8
|
-
const interceptor = async (interceptorOptions) => {
|
|
9
|
-
const mode = flattenStandardHeader(
|
|
10
|
-
interceptorOptions.request.headers["sec-fetch-mode"]
|
|
11
|
-
)?.toLowerCase();
|
|
12
|
-
if (mode === void 0) {
|
|
13
|
-
return interceptorOptions.next();
|
|
14
|
-
}
|
|
15
|
-
if (mode === "cors" || mode === "same-origin") {
|
|
16
|
-
return interceptorOptions.next();
|
|
17
|
-
}
|
|
18
|
-
throw new ORPCError("FORBIDDEN", {
|
|
19
|
-
message: "Request blocked by CSRF protection."
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
return {
|
|
23
|
-
...options,
|
|
24
|
-
// appended last so user's interceptors can catch ORPCError
|
|
25
|
-
interceptors: [...toArray(options.interceptors), interceptor]
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export { CSRFGuardHandlerPlugin as C };
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { RPCSerializer, AnyORPCError } from '@orpc/client';
|
|
2
|
-
import { Value, Promisable } from '@orpc/shared';
|
|
3
|
-
import { StandardMethod, StandardLazyRequest, StandardResponse } from '@standardserver/core';
|
|
4
|
-
import { A as AnyProcedure, C as Context } from './server.BL22TloH.js';
|
|
5
|
-
import { A as AnyRouter } from './server.Pa0F03f_.js';
|
|
6
|
-
import { AnyProcedureContract } from '@orpc/contract';
|
|
7
|
-
import { b as StandardHandlerHandleOptions, c as StandardHandlerCodec, d as StandardHandlerCodecResolvedProcedure } from './server.DBANIheG.js';
|
|
8
|
-
|
|
9
|
-
interface RPCMatcherOptions {
|
|
10
|
-
/**
|
|
11
|
-
* Filter which procedures are exposed for matching. Return `false` to exclude.
|
|
12
|
-
*
|
|
13
|
-
* @default true
|
|
14
|
-
*/
|
|
15
|
-
filter?: Value<boolean, [procedure: AnyProcedureContract | AnyProcedure, path: string[]]>;
|
|
16
|
-
}
|
|
17
|
-
declare class RPCMatcher {
|
|
18
|
-
private readonly filter;
|
|
19
|
-
private readonly rootRouter;
|
|
20
|
-
private readonly tree;
|
|
21
|
-
private pendingLazyRouters;
|
|
22
|
-
constructor(router: AnyRouter, options?: RPCMatcherOptions);
|
|
23
|
-
private index;
|
|
24
|
-
match(_method: StandardMethod, pathname: `/${string}`, prefix: `/${string}` | undefined): Promise<{
|
|
25
|
-
path: string[];
|
|
26
|
-
procedure: AnyProcedure;
|
|
27
|
-
} | undefined>;
|
|
28
|
-
private matchPathname;
|
|
29
|
-
private resolvePendingLazyRouters;
|
|
30
|
-
private resolveProcedure;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
interface RPCHandlerCodecOptions<T extends Context> extends RPCMatcherOptions {
|
|
34
|
-
/**
|
|
35
|
-
* Override the default RPC serializer.
|
|
36
|
-
*/
|
|
37
|
-
serializer?: Pick<RPCSerializer, keyof RPCSerializer>;
|
|
38
|
-
/**
|
|
39
|
-
* Resolve HTTP status for encoded successful outputs.
|
|
40
|
-
*
|
|
41
|
-
* Value should be in range `200-299`
|
|
42
|
-
* Return `undefined` or `null` to fallback to default
|
|
43
|
-
*
|
|
44
|
-
* @default DEFAULT_ERROR_STATUS, DEFAULT_ERROR_STATUS
|
|
45
|
-
*/
|
|
46
|
-
outputStatus?: Value<number | undefined | null, [output: unknown, procedure: AnyProcedure, path: string[], options: StandardHandlerHandleOptions<T>]>;
|
|
47
|
-
/**
|
|
48
|
-
* Mapping ORPCError Code -> HTTP Status Code
|
|
49
|
-
*
|
|
50
|
-
* @default COMMON_ERROR_STATUS_MAP
|
|
51
|
-
*/
|
|
52
|
-
errorStatusMap?: Record<string, number> | undefined;
|
|
53
|
-
}
|
|
54
|
-
declare class RPCHandlerCodec<T extends Context> implements StandardHandlerCodec<T> {
|
|
55
|
-
private readonly matcher;
|
|
56
|
-
private readonly serializer;
|
|
57
|
-
private readonly errorStatusMap;
|
|
58
|
-
private readonly outputStatus;
|
|
59
|
-
constructor(router: AnyRouter, options?: RPCHandlerCodecOptions<T>);
|
|
60
|
-
resolveProcedure(request: StandardLazyRequest, options: StandardHandlerHandleOptions<T>): Promise<StandardHandlerCodecResolvedProcedure | undefined>;
|
|
61
|
-
encodeOutput(output: unknown, procedure: AnyProcedure, path: string[], options: StandardHandlerHandleOptions<T>): Promisable<StandardResponse>;
|
|
62
|
-
encodeError(error: AnyORPCError, _procedure: AnyProcedure, _path: string[], _options: StandardHandlerHandleOptions<T>): Promisable<StandardResponse>;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export { RPCHandlerCodec as a, RPCMatcher as b };
|
|
66
|
-
export type { RPCHandlerCodecOptions as R, RPCMatcherOptions as c };
|