@orpc/server 0.35.1 → 0.36.1
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/dist/{chunk-SUGWQSMQ.js → chunk-F75AQ6KO.js} +22 -17
- package/dist/{chunk-JBPBLCBJ.js → chunk-GQ4376GR.js} +7 -7
- package/dist/{chunk-NOA3GBJQ.js → chunk-SV6DBVXJ.js} +15 -18
- package/dist/{chunk-OWMUECGT.js → chunk-XFBAK67J.js} +22 -5
- package/dist/fetch.js +4 -4
- package/dist/hono.js +5 -5
- package/dist/index.js +1 -1
- package/dist/next.js +4 -4
- package/dist/node.js +8 -8
- package/dist/plugins.js +1 -1
- package/dist/src/adapters/standard/handler.d.ts +5 -1
- package/dist/src/implementer-procedure.d.ts +2 -2
- package/dist/src/plugins/base.d.ts +3 -1
- package/dist/src/plugins/cors.d.ts +2 -1
- package/dist/src/procedure-client.d.ts +18 -7
- package/dist/src/procedure-decorated.d.ts +2 -2
- package/dist/src/procedure-utils.d.ts +2 -2
- package/dist/src/router-client.d.ts +3 -14
- package/dist/standard.js +3 -3
- package/package.json +4 -4
@@ -6,10 +6,10 @@ import {
|
|
6
6
|
getRouterChild,
|
7
7
|
isProcedure,
|
8
8
|
unlazy
|
9
|
-
} from "./chunk-
|
9
|
+
} from "./chunk-SV6DBVXJ.js";
|
10
10
|
import {
|
11
11
|
CompositePlugin
|
12
|
-
} from "./chunk-
|
12
|
+
} from "./chunk-XFBAK67J.js";
|
13
13
|
|
14
14
|
// src/adapters/standard/handler.ts
|
15
15
|
import { toORPCError } from "@orpc/contract";
|
@@ -25,30 +25,35 @@ var StandardHandler = class {
|
|
25
25
|
}
|
26
26
|
plugin;
|
27
27
|
handle(request, ...[options]) {
|
28
|
-
const handleOptions = options ?? {};
|
29
|
-
handleOptions.context ??= {};
|
30
28
|
return intercept(
|
31
29
|
this.options.interceptorsRoot ?? [],
|
32
|
-
{
|
33
|
-
|
30
|
+
{
|
31
|
+
request,
|
32
|
+
...options,
|
33
|
+
context: options?.context ?? {}
|
34
|
+
// context is optional only when all fields are optional so we can safely force it to have a context
|
35
|
+
},
|
36
|
+
async (interceptorOptions) => {
|
34
37
|
try {
|
35
38
|
return await intercept(
|
36
39
|
this.options.interceptors ?? [],
|
37
|
-
|
38
|
-
async (
|
39
|
-
const method =
|
40
|
-
const url =
|
41
|
-
const pathname = `/${trim(url.pathname.replace(
|
40
|
+
interceptorOptions,
|
41
|
+
async (interceptorOptions2) => {
|
42
|
+
const method = interceptorOptions2.request.method;
|
43
|
+
const url = interceptorOptions2.request.url;
|
44
|
+
const pathname = `/${trim(url.pathname.replace(interceptorOptions2.prefix ?? "", ""), "/")}`;
|
42
45
|
const match = await this.matcher.match(method, pathname);
|
43
46
|
if (!match) {
|
44
47
|
return { matched: false, response: void 0 };
|
45
48
|
}
|
46
|
-
const
|
47
|
-
context,
|
49
|
+
const clientOptions = {
|
50
|
+
context: interceptorOptions2.context,
|
48
51
|
path: match.path
|
49
|
-
}
|
50
|
-
|
51
|
-
const
|
52
|
+
};
|
53
|
+
this.plugin.beforeCreateProcedureClient(clientOptions, interceptorOptions2);
|
54
|
+
const client = createProcedureClient(match.procedure, clientOptions);
|
55
|
+
const input = await this.codec.decode(request, match.params, match.procedure);
|
56
|
+
const output = await client(input, { signal: request.signal });
|
52
57
|
const response = this.codec.encode(output, match.procedure);
|
53
58
|
return {
|
54
59
|
matched: true,
|
@@ -305,4 +310,4 @@ export {
|
|
305
310
|
RPCCodec,
|
306
311
|
RPCMatcher
|
307
312
|
};
|
308
|
-
//# sourceMappingURL=chunk-
|
313
|
+
//# sourceMappingURL=chunk-F75AQ6KO.js.map
|
@@ -2,11 +2,11 @@ import {
|
|
2
2
|
RPCCodec,
|
3
3
|
RPCMatcher,
|
4
4
|
StandardHandler
|
5
|
-
} from "./chunk-
|
5
|
+
} from "./chunk-F75AQ6KO.js";
|
6
6
|
|
7
7
|
// src/adapters/fetch/utils.ts
|
8
8
|
import { once } from "@orpc/shared";
|
9
|
-
import
|
9
|
+
import { contentDisposition, parse as parseContentDisposition } from "@tinyhttp/content-disposition";
|
10
10
|
function fetchHeadersToStandardHeaders(headers) {
|
11
11
|
const standardHeaders = {};
|
12
12
|
for (const [key, value] of headers) {
|
@@ -24,9 +24,9 @@ async function fetchReToStandardBody(re) {
|
|
24
24
|
if (!re.body) {
|
25
25
|
return void 0;
|
26
26
|
}
|
27
|
-
const
|
28
|
-
const fileName =
|
29
|
-
if (fileName) {
|
27
|
+
const contentDisposition2 = re.headers.get("content-disposition");
|
28
|
+
const fileName = contentDisposition2 ? parseContentDisposition(contentDisposition2).parameters.filename : void 0;
|
29
|
+
if (typeof fileName === "string") {
|
30
30
|
const blob2 = await re.blob();
|
31
31
|
return new File([blob2], fileName, {
|
32
32
|
type: blob2.type
|
@@ -86,7 +86,7 @@ function standardResponseToFetchHeaders(response) {
|
|
86
86
|
}
|
87
87
|
}
|
88
88
|
if (response.body instanceof Blob && !fetchHeaders.has("content-disposition")) {
|
89
|
-
fetchHeaders.set("content-disposition",
|
89
|
+
fetchHeaders.set("content-disposition", contentDisposition(response.body instanceof File ? response.body.name : "blob"));
|
90
90
|
} else if (!(response.body instanceof Blob) && !(response.body instanceof URLSearchParams) && !(response.body instanceof FormData) && response.body !== void 0 && !fetchHeaders.has("content-type")) {
|
91
91
|
fetchHeaders.set("content-type", "application/json");
|
92
92
|
}
|
@@ -133,4 +133,4 @@ export {
|
|
133
133
|
standardResponseToFetchResponse,
|
134
134
|
RPCHandler
|
135
135
|
};
|
136
|
-
//# sourceMappingURL=chunk-
|
136
|
+
//# sourceMappingURL=chunk-GQ4376GR.js.map
|
@@ -63,30 +63,27 @@ function middlewareOutputFn(output) {
|
|
63
63
|
|
64
64
|
// src/procedure-client.ts
|
65
65
|
import { createORPCErrorConstructorMap, ORPCError, validateORPCError, ValidationError } from "@orpc/contract";
|
66
|
-
import {
|
66
|
+
import { intercept, toError, value } from "@orpc/shared";
|
67
67
|
function createProcedureClient(lazyableProcedure, ...[options]) {
|
68
68
|
return async (...[input, callerOptions]) => {
|
69
69
|
const path = options?.path ?? [];
|
70
70
|
const { default: procedure } = await unlazy(lazyableProcedure);
|
71
71
|
const context = await value(options?.context ?? {}, callerOptions?.context);
|
72
72
|
const errors = createORPCErrorConstructorMap(procedure["~orpc"].errorMap);
|
73
|
-
const executeOptions = {
|
74
|
-
input,
|
75
|
-
context,
|
76
|
-
errors,
|
77
|
-
path,
|
78
|
-
procedure,
|
79
|
-
signal: callerOptions?.signal
|
80
|
-
};
|
81
73
|
try {
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
74
|
+
return await intercept(
|
75
|
+
options?.interceptors ?? [],
|
76
|
+
{
|
77
|
+
context,
|
78
|
+
input,
|
79
|
+
// input only optional when it undefinable so we can safely cast it
|
80
|
+
errors,
|
81
|
+
path,
|
82
|
+
procedure,
|
83
|
+
signal: callerOptions?.signal
|
84
|
+
},
|
85
|
+
(interceptorOptions) => executeProcedureInternal(interceptorOptions.procedure, interceptorOptions)
|
86
|
+
);
|
90
87
|
} catch (e) {
|
91
88
|
if (!(e instanceof ORPCError)) {
|
92
89
|
throw toError(e);
|
@@ -377,4 +374,4 @@ export {
|
|
377
374
|
convertPathToHttpPath,
|
378
375
|
createContractedProcedure
|
379
376
|
};
|
380
|
-
//# sourceMappingURL=chunk-
|
377
|
+
//# sourceMappingURL=chunk-SV6DBVXJ.js.map
|
@@ -8,6 +8,11 @@ var CompositePlugin = class {
|
|
8
8
|
plugin.init?.(options);
|
9
9
|
}
|
10
10
|
}
|
11
|
+
beforeCreateProcedureClient(clientOptions, interceptorOptions) {
|
12
|
+
for (const plugin of this.plugins) {
|
13
|
+
plugin.beforeCreateProcedureClient?.(clientOptions, interceptorOptions);
|
14
|
+
}
|
15
|
+
}
|
11
16
|
};
|
12
17
|
|
13
18
|
// src/plugins/cors.ts
|
@@ -19,6 +24,9 @@ var CORSPlugin = class {
|
|
19
24
|
origin: "*",
|
20
25
|
allowMethods: ["GET", "HEAD", "PUT", "POST", "DELETE", "PATCH"]
|
21
26
|
};
|
27
|
+
if (options?.credentials) {
|
28
|
+
defaults.origin = (origin) => origin;
|
29
|
+
}
|
22
30
|
this.options = {
|
23
31
|
...defaults,
|
24
32
|
...options
|
@@ -60,12 +68,21 @@ var CORSPlugin = class {
|
|
60
68
|
const origin = Array.isArray(interceptorOptions.request.headers.origin) ? interceptorOptions.request.headers.origin.join(",") : interceptorOptions.request.headers.origin || "";
|
61
69
|
const allowedOrigin = await value(this.options.origin, origin, interceptorOptions);
|
62
70
|
const allowedOriginArr = Array.isArray(allowedOrigin) ? allowedOrigin : [allowedOrigin];
|
63
|
-
if (allowedOriginArr.includes(
|
64
|
-
result.response.headers["access-control-allow-origin"] =
|
65
|
-
}
|
66
|
-
|
71
|
+
if (allowedOriginArr.includes("*")) {
|
72
|
+
result.response.headers["access-control-allow-origin"] = "*";
|
73
|
+
} else {
|
74
|
+
if (allowedOriginArr.includes(origin)) {
|
75
|
+
result.response.headers["access-control-allow-origin"] = origin;
|
76
|
+
}
|
67
77
|
result.response.headers.vary = interceptorOptions.request.headers.vary ?? "origin";
|
68
78
|
}
|
79
|
+
const allowedTimingOrigin = await value(this.options.timingOrigin, origin, interceptorOptions);
|
80
|
+
const allowedTimingOriginArr = Array.isArray(allowedTimingOrigin) ? allowedTimingOrigin : [allowedTimingOrigin];
|
81
|
+
if (allowedTimingOriginArr.includes("*")) {
|
82
|
+
result.response.headers["timing-allow-origin"] = "*";
|
83
|
+
} else if (allowedTimingOriginArr.includes(origin)) {
|
84
|
+
result.response.headers["timing-allow-origin"] = origin;
|
85
|
+
}
|
69
86
|
if (this.options.credentials) {
|
70
87
|
result.response.headers["access-control-allow-credentials"] = "true";
|
71
88
|
}
|
@@ -108,4 +125,4 @@ export {
|
|
108
125
|
CORSPlugin,
|
109
126
|
ResponseHeadersPlugin
|
110
127
|
};
|
111
|
-
//# sourceMappingURL=chunk-
|
128
|
+
//# sourceMappingURL=chunk-XFBAK67J.js.map
|
package/dist/fetch.js
CHANGED
@@ -4,10 +4,10 @@ import {
|
|
4
4
|
fetchRequestToStandardRequest,
|
5
5
|
standardBodyToFetchBody,
|
6
6
|
standardResponseToFetchResponse
|
7
|
-
} from "./chunk-
|
8
|
-
import "./chunk-
|
9
|
-
import "./chunk-
|
10
|
-
import "./chunk-
|
7
|
+
} from "./chunk-GQ4376GR.js";
|
8
|
+
import "./chunk-F75AQ6KO.js";
|
9
|
+
import "./chunk-SV6DBVXJ.js";
|
10
|
+
import "./chunk-XFBAK67J.js";
|
11
11
|
export {
|
12
12
|
RPCHandler,
|
13
13
|
fetchReToStandardBody,
|
package/dist/hono.js
CHANGED
@@ -4,10 +4,10 @@ import {
|
|
4
4
|
fetchRequestToStandardRequest,
|
5
5
|
standardBodyToFetchBody,
|
6
6
|
standardResponseToFetchResponse
|
7
|
-
} from "./chunk-
|
8
|
-
import "./chunk-
|
9
|
-
import "./chunk-
|
10
|
-
import "./chunk-
|
7
|
+
} from "./chunk-GQ4376GR.js";
|
8
|
+
import "./chunk-F75AQ6KO.js";
|
9
|
+
import "./chunk-SV6DBVXJ.js";
|
10
|
+
import "./chunk-XFBAK67J.js";
|
11
11
|
|
12
12
|
// src/adapters/hono/middleware.ts
|
13
13
|
import { value } from "@orpc/shared";
|
@@ -26,7 +26,7 @@ function createMiddleware(handler, ...[options]) {
|
|
26
26
|
const context = await value(options?.context ?? {}, c);
|
27
27
|
const { matched, response } = await handler.handle(request, { ...options, context });
|
28
28
|
if (matched) {
|
29
|
-
return c.
|
29
|
+
return c.newResponse(response.body, response);
|
30
30
|
}
|
31
31
|
await next();
|
32
32
|
};
|
package/dist/index.js
CHANGED
@@ -21,7 +21,7 @@ import {
|
|
21
21
|
middlewareOutputFn,
|
22
22
|
setRouterContract,
|
23
23
|
unlazy
|
24
|
-
} from "./chunk-
|
24
|
+
} from "./chunk-SV6DBVXJ.js";
|
25
25
|
|
26
26
|
// src/builder.ts
|
27
27
|
import { mergeErrorMap as mergeErrorMap2, mergeMeta as mergeMeta2, mergePrefix, mergeRoute as mergeRoute2, mergeTags } from "@orpc/contract";
|
package/dist/next.js
CHANGED
@@ -4,10 +4,10 @@ import {
|
|
4
4
|
fetchRequestToStandardRequest,
|
5
5
|
standardBodyToFetchBody,
|
6
6
|
standardResponseToFetchResponse
|
7
|
-
} from "./chunk-
|
8
|
-
import "./chunk-
|
9
|
-
import "./chunk-
|
10
|
-
import "./chunk-
|
7
|
+
} from "./chunk-GQ4376GR.js";
|
8
|
+
import "./chunk-F75AQ6KO.js";
|
9
|
+
import "./chunk-SV6DBVXJ.js";
|
10
|
+
import "./chunk-XFBAK67J.js";
|
11
11
|
|
12
12
|
// src/adapters/next/serve.ts
|
13
13
|
import { value } from "@orpc/shared";
|
package/dist/node.js
CHANGED
@@ -2,15 +2,15 @@ import {
|
|
2
2
|
RPCCodec,
|
3
3
|
RPCMatcher,
|
4
4
|
StandardHandler
|
5
|
-
} from "./chunk-
|
6
|
-
import "./chunk-
|
7
|
-
import "./chunk-
|
5
|
+
} from "./chunk-F75AQ6KO.js";
|
6
|
+
import "./chunk-SV6DBVXJ.js";
|
7
|
+
import "./chunk-XFBAK67J.js";
|
8
8
|
|
9
9
|
// src/adapters/node/utils.ts
|
10
10
|
import { Buffer, File } from "node:buffer";
|
11
11
|
import { Readable } from "node:stream";
|
12
12
|
import { once } from "@orpc/shared";
|
13
|
-
import
|
13
|
+
import { contentDisposition, parse as parseContentDisposition } from "@tinyhttp/content-disposition";
|
14
14
|
function nodeHttpToStandardRequest(req, res) {
|
15
15
|
const method = req.method ?? "GET";
|
16
16
|
const protocol = "encrypted" in req.socket && req.socket.encrypted ? "https:" : "http:";
|
@@ -50,7 +50,7 @@ function nodeHttpResponseSendStandardResponse(res, standardResponse) {
|
|
50
50
|
"content-length": standardResponse.body.size.toString()
|
51
51
|
};
|
52
52
|
if (!standardResponse.headers["content-disposition"] && standardResponse.body instanceof Blob) {
|
53
|
-
resHeaders["content-disposition"] =
|
53
|
+
resHeaders["content-disposition"] = contentDisposition(standardResponse.body instanceof File ? standardResponse.body.name : "blob");
|
54
54
|
}
|
55
55
|
res.writeHead(standardResponse.status, resHeaders);
|
56
56
|
Readable.fromWeb(
|
@@ -93,10 +93,10 @@ async function nodeHttpRequestToStandardBody(req) {
|
|
93
93
|
if (method === "GET" || method === "HEAD") {
|
94
94
|
return void 0;
|
95
95
|
}
|
96
|
-
const
|
97
|
-
const fileName =
|
96
|
+
const contentDisposition2 = req.headers["content-disposition"];
|
97
|
+
const fileName = contentDisposition2 ? parseContentDisposition(contentDisposition2).parameters.filename : void 0;
|
98
98
|
const contentType = req.headers["content-type"];
|
99
|
-
if (fileName) {
|
99
|
+
if (typeof fileName === "string") {
|
100
100
|
return await streamToFile(req, fileName, contentType || "application/octet-stream");
|
101
101
|
}
|
102
102
|
if (!contentType || contentType.startsWith("application/json")) {
|
package/dist/plugins.js
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
-
import type { HTTPPath } from '@orpc/contract';
|
1
|
+
import type { ErrorMap, HTTPPath, Meta, Schema } from '@orpc/contract';
|
2
2
|
import type { Interceptor } from '@orpc/shared';
|
3
3
|
import type { Context } from '../../context';
|
4
4
|
import type { Plugin } from '../../plugins';
|
5
|
+
import type { CreateProcedureClientOptions } from '../../procedure-client';
|
5
6
|
import type { Router } from '../../router';
|
6
7
|
import type { StandardCodec, StandardMatcher, StandardRequest, StandardResponse } from './types';
|
7
8
|
export type StandardHandleOptions<T extends Context> = {
|
@@ -25,6 +26,9 @@ export type StandardHandleResult = {
|
|
25
26
|
export type StandardHandlerInterceptorOptions<TContext extends Context> = WellStandardHandleOptions<TContext> & {
|
26
27
|
request: StandardRequest;
|
27
28
|
};
|
29
|
+
export type WellCreateProcedureClientOptions<TContext extends Context> = CreateProcedureClientOptions<TContext, Schema, Schema, unknown, ErrorMap, Meta, unknown> & {
|
30
|
+
context: TContext;
|
31
|
+
};
|
28
32
|
export interface StandardHandlerOptions<TContext extends Context> {
|
29
33
|
plugins?: Plugin<TContext>[];
|
30
34
|
/**
|
@@ -13,11 +13,11 @@ export interface ImplementedProcedure<TInitialContext extends Context, TCurrentC
|
|
13
13
|
/**
|
14
14
|
* Make this procedure callable (works like a function while still being a procedure).
|
15
15
|
*/
|
16
|
-
callable<TClientContext>(...rest: CreateProcedureClientRest<TInitialContext, TOutputSchema, THandlerOutput, TClientContext>): Procedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta> & ProcedureClient<TClientContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
|
16
|
+
callable<TClientContext>(...rest: CreateProcedureClientRest<TInitialContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta, TClientContext>): Procedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta> & ProcedureClient<TClientContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
|
17
17
|
/**
|
18
18
|
* Make this procedure compatible with server action (the same as .callable, but the type is compatible with server action).
|
19
19
|
*/
|
20
|
-
actionable<TClientContext>(...rest: CreateProcedureClientRest<TInitialContext, TOutputSchema, THandlerOutput, TClientContext>): Procedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta> & ((...rest: ClientRest<TClientContext, SchemaInput<TInputSchema>>) => Promise<SchemaOutput<TOutputSchema, THandlerOutput>>);
|
20
|
+
actionable<TClientContext>(...rest: CreateProcedureClientRest<TInitialContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta, TClientContext>): Procedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta> & ((...rest: ClientRest<TClientContext, SchemaInput<TInputSchema>>) => Promise<SchemaOutput<TOutputSchema, THandlerOutput>>);
|
21
21
|
}
|
22
22
|
/**
|
23
23
|
* Like `ProcedureBuilderWithoutHandler`, but removed all method that can change the contract.
|
@@ -1,11 +1,13 @@
|
|
1
|
-
import type { StandardHandlerOptions } from '../adapters/standard';
|
1
|
+
import type { StandardHandlerInterceptorOptions, StandardHandlerOptions, WellCreateProcedureClientOptions } from '../adapters/standard';
|
2
2
|
import type { Context } from '../context';
|
3
3
|
export interface Plugin<TContext extends Context> {
|
4
4
|
init?(options: StandardHandlerOptions<TContext>): void;
|
5
|
+
beforeCreateProcedureClient?(clientOptions: WellCreateProcedureClientOptions<TContext>, interceptorOptions: StandardHandlerInterceptorOptions<TContext>): void;
|
5
6
|
}
|
6
7
|
export declare class CompositePlugin<TContext extends Context> implements Plugin<TContext> {
|
7
8
|
private readonly plugins;
|
8
9
|
constructor(plugins?: Plugin<TContext>[]);
|
9
10
|
init(options: StandardHandlerOptions<TContext>): void;
|
11
|
+
beforeCreateProcedureClient(clientOptions: WellCreateProcedureClientOptions<TContext>, interceptorOptions: StandardHandlerInterceptorOptions<TContext>): void;
|
10
12
|
}
|
11
13
|
//# sourceMappingURL=base.d.ts.map
|
@@ -3,7 +3,8 @@ import type { Context } from '../context';
|
|
3
3
|
import type { Plugin } from './base';
|
4
4
|
import { type Value } from '@orpc/shared';
|
5
5
|
export interface CORSOptions<TContext extends Context> {
|
6
|
-
origin
|
6
|
+
origin?: Value<string | string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<TContext>]>;
|
7
|
+
timingOrigin?: Value<string | string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<TContext>]>;
|
7
8
|
allowMethods?: string[];
|
8
9
|
allowHeaders?: string[];
|
9
10
|
maxAge?: number;
|
@@ -1,20 +1,31 @@
|
|
1
|
-
import type { Client, ErrorFromErrorMap, ErrorMap, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
-
import type {
|
1
|
+
import type { Client, ErrorFromErrorMap, ErrorMap, Meta, ORPCErrorConstructorMap, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
+
import type { Interceptor, Value } from '@orpc/shared';
|
3
3
|
import type { Context } from './context';
|
4
4
|
import type { Lazyable } from './lazy';
|
5
5
|
import type { Procedure } from './procedure';
|
6
6
|
export type ProcedureClient<TClientContext, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap> = Client<TClientContext, SchemaInput<TInputSchema>, SchemaOutput<TOutputSchema, THandlerOutput>, ErrorFromErrorMap<TErrorMap>>;
|
7
|
+
export interface ProcedureClientInterceptorOptions<TInitialContext extends Context, TInputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
8
|
+
context: TInitialContext;
|
9
|
+
input: SchemaInput<TInputSchema>;
|
10
|
+
errors: ORPCErrorConstructorMap<TErrorMap>;
|
11
|
+
path: string[];
|
12
|
+
procedure: Procedure<Context, Context, Schema, Schema, unknown, ErrorMap, TMeta>;
|
13
|
+
signal?: AbortSignal;
|
14
|
+
}
|
7
15
|
/**
|
8
16
|
* Options for creating a procedure caller with comprehensive type safety
|
9
17
|
*/
|
10
|
-
export type CreateProcedureClientOptions<TInitialContext extends Context,
|
18
|
+
export type CreateProcedureClientOptions<TInitialContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext> = {
|
11
19
|
/**
|
12
20
|
* This is helpful for logging and analytics.
|
13
21
|
*/
|
14
22
|
path?: string[];
|
15
|
-
|
23
|
+
interceptors?: Interceptor<ProcedureClientInterceptorOptions<TInitialContext, TInputSchema, TErrorMap, TMeta>, SchemaOutput<TOutputSchema, THandlerOutput>, ErrorFromErrorMap<TErrorMap>>[];
|
24
|
+
} & (Record<never, never> extends TInitialContext ? {
|
25
|
+
context?: Value<TInitialContext, [clientContext: TClientContext]>;
|
26
|
+
} : {
|
16
27
|
context: Value<TInitialContext, [clientContext: TClientContext]>;
|
17
|
-
}
|
18
|
-
export type CreateProcedureClientRest<TInitialContext extends Context, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TClientContext> = [options: CreateProcedureClientOptions<TInitialContext, TOutputSchema, THandlerOutput, TClientContext>] | (Record<never, never> extends TInitialContext ? [] : never);
|
19
|
-
export declare function createProcedureClient<TInitialContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap, TClientContext>(lazyableProcedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap,
|
28
|
+
});
|
29
|
+
export type CreateProcedureClientRest<TInitialContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext> = [options: CreateProcedureClientOptions<TInitialContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta, TClientContext>] | (Record<never, never> extends TInitialContext ? [] : never);
|
30
|
+
export declare function createProcedureClient<TInitialContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext>(lazyableProcedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta>>, ...[options]: CreateProcedureClientRest<TInitialContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta, TClientContext>): ProcedureClient<TClientContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
|
20
31
|
//# sourceMappingURL=procedure-client.d.ts.map
|
@@ -12,10 +12,10 @@ export declare class DecoratedProcedure<TInitialContext extends Context, TCurren
|
|
12
12
|
/**
|
13
13
|
* Make this procedure callable (works like a function while still being a procedure).
|
14
14
|
*/
|
15
|
-
callable<TClientContext>(...rest: CreateProcedureClientRest<TInitialContext, TOutputSchema, THandlerOutput, TClientContext>): Procedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta> & ProcedureClient<TClientContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
|
15
|
+
callable<TClientContext>(...rest: CreateProcedureClientRest<TInitialContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta, TClientContext>): Procedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta> & ProcedureClient<TClientContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
|
16
16
|
/**
|
17
17
|
* Make this procedure compatible with server action (the same as .callable, but the type is compatible with server action).
|
18
18
|
*/
|
19
|
-
actionable<TClientContext>(...rest: CreateProcedureClientRest<TInitialContext, TOutputSchema, THandlerOutput, TClientContext>): Procedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta> & ((...rest: ClientRest<TClientContext, SchemaInput<TInputSchema>>) => Promise<SchemaOutput<TOutputSchema, THandlerOutput>>);
|
19
|
+
actionable<TClientContext>(...rest: CreateProcedureClientRest<TInitialContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta, TClientContext>): Procedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta> & ((...rest: ClientRest<TClientContext, SchemaInput<TInputSchema>>) => Promise<SchemaOutput<TOutputSchema, THandlerOutput>>);
|
20
20
|
}
|
21
21
|
//# sourceMappingURL=procedure-decorated.d.ts.map
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import type { ClientPromiseResult, ErrorFromErrorMap, ErrorMap, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
1
|
+
import type { ClientPromiseResult, ErrorFromErrorMap, ErrorMap, Meta, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
2
|
import type { Context } from './context';
|
3
3
|
import type { Lazyable } from './lazy';
|
4
4
|
import type { Procedure } from './procedure';
|
@@ -13,5 +13,5 @@ import { type CreateProcedureClientRest } from './procedure-client';
|
|
13
13
|
* ```
|
14
14
|
*
|
15
15
|
*/
|
16
|
-
export declare function call<TInitialContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap>(procedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap,
|
16
|
+
export declare function call<TInitialContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap, TMeta extends Meta>(procedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta>>, input: SchemaInput<TInputSchema>, ...rest: CreateProcedureClientRest<TInitialContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta, unknown>): ClientPromiseResult<SchemaOutput<TOutputSchema, THandlerOutput>, ErrorFromErrorMap<TErrorMap>>;
|
17
17
|
//# sourceMappingURL=procedure-utils.d.ts.map
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import type {
|
1
|
+
import type { ErrorMap, Meta } from '@orpc/contract';
|
2
2
|
import type { Lazy } from './lazy';
|
3
3
|
import type { Procedure } from './procedure';
|
4
4
|
import type { CreateProcedureClientRest, ProcedureClient } from './procedure-client';
|
@@ -6,17 +6,6 @@ import type { AnyRouter, Router } from './router';
|
|
6
6
|
export type RouterClient<TRouter extends AnyRouter, TClientContext> = TRouter extends Lazy<infer U extends AnyRouter> ? RouterClient<U, TClientContext> : TRouter extends Procedure<any, any, infer UInputSchema, infer UOutputSchema, infer UFuncOutput, infer UErrorMap, any> ? ProcedureClient<TClientContext, UInputSchema, UOutputSchema, UFuncOutput, UErrorMap> : {
|
7
7
|
[K in keyof TRouter]: TRouter[K] extends AnyRouter ? RouterClient<TRouter[K], TClientContext> : never;
|
8
8
|
};
|
9
|
-
export type
|
10
|
-
|
11
|
-
* This is helpful for logging and analytics.
|
12
|
-
*
|
13
|
-
* @internal
|
14
|
-
*/
|
15
|
-
path?: string[];
|
16
|
-
} & (TRouter extends Router<infer UContext, any> ? undefined extends UContext ? {
|
17
|
-
context?: Value<UContext>;
|
18
|
-
} : {
|
19
|
-
context: Value<UContext>;
|
20
|
-
} : never) & Hooks<unknown, unknown, TRouter extends Router<infer UContext, any> ? UContext : never, any>;
|
21
|
-
export declare function createRouterClient<TRouter extends AnyRouter, TClientContext>(router: TRouter | Lazy<undefined>, ...rest: CreateProcedureClientRest<TRouter extends Router<infer UContext, any> ? UContext : never, undefined, unknown, TClientContext>): RouterClient<TRouter, TClientContext>;
|
9
|
+
export type CreateRouterClientRest<TRouter extends AnyRouter, TClientContext> = CreateProcedureClientRest<TRouter extends Router<infer UContext, any> ? UContext : never, undefined, undefined, unknown, ErrorMap, Meta, TClientContext>;
|
10
|
+
export declare function createRouterClient<TRouter extends AnyRouter, TClientContext>(router: TRouter | Lazy<undefined>, ...rest: CreateRouterClientRest<TRouter, TClientContext>): RouterClient<TRouter, TClientContext>;
|
22
11
|
//# sourceMappingURL=router-client.d.ts.map
|
package/dist/standard.js
CHANGED
@@ -4,9 +4,9 @@ import {
|
|
4
4
|
RPCSerializer,
|
5
5
|
StandardHandler,
|
6
6
|
serializeRPCJson
|
7
|
-
} from "./chunk-
|
8
|
-
import "./chunk-
|
9
|
-
import "./chunk-
|
7
|
+
} from "./chunk-F75AQ6KO.js";
|
8
|
+
import "./chunk-SV6DBVXJ.js";
|
9
|
+
import "./chunk-XFBAK67J.js";
|
10
10
|
export {
|
11
11
|
RPCCodec,
|
12
12
|
RPCMatcher,
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@orpc/server",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.
|
4
|
+
"version": "0.36.1",
|
5
5
|
"license": "MIT",
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
7
7
|
"repository": {
|
@@ -63,9 +63,9 @@
|
|
63
63
|
"next": ">=14.0.0"
|
64
64
|
},
|
65
65
|
"dependencies": {
|
66
|
-
"content-disposition": "^
|
67
|
-
"@orpc/contract": "0.
|
68
|
-
"@orpc/shared": "0.
|
66
|
+
"@tinyhttp/content-disposition": "^2.2.2",
|
67
|
+
"@orpc/contract": "0.36.1",
|
68
|
+
"@orpc/shared": "0.36.1"
|
69
69
|
},
|
70
70
|
"devDependencies": {
|
71
71
|
"light-my-request": "^6.5.1"
|