@orpc/server 0.0.0-next.bc9d3dd → 0.0.0-next.bec5773
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 +128 -0
- package/dist/adapters/bun-ws/index.d.mts +35 -0
- package/dist/adapters/bun-ws/index.d.ts +35 -0
- package/dist/adapters/bun-ws/index.mjs +51 -0
- package/dist/adapters/crossws/index.d.mts +30 -0
- package/dist/adapters/crossws/index.d.ts +30 -0
- package/dist/adapters/crossws/index.mjs +51 -0
- package/dist/adapters/fetch/index.d.mts +78 -0
- package/dist/adapters/fetch/index.d.ts +78 -0
- package/dist/adapters/fetch/index.mjs +110 -0
- package/dist/adapters/node/index.d.mts +77 -0
- package/dist/adapters/node/index.d.ts +77 -0
- package/dist/adapters/node/index.mjs +95 -0
- package/dist/adapters/standard/index.d.mts +26 -0
- package/dist/adapters/standard/index.d.ts +26 -0
- package/dist/adapters/standard/index.mjs +7 -0
- package/dist/adapters/websocket/index.d.mts +27 -0
- package/dist/adapters/websocket/index.d.ts +27 -0
- package/dist/adapters/websocket/index.mjs +38 -0
- package/dist/adapters/ws/index.d.mts +28 -0
- package/dist/adapters/ws/index.d.ts +28 -0
- package/dist/adapters/ws/index.mjs +38 -0
- package/dist/index.d.mts +829 -0
- package/dist/index.d.ts +829 -0
- package/dist/index.mjs +474 -0
- package/dist/plugins/index.d.mts +156 -0
- package/dist/plugins/index.d.ts +156 -0
- package/dist/plugins/index.mjs +251 -0
- package/dist/shared/server.4FnxLwwr.mjs +186 -0
- package/dist/shared/server.BRoxSiSC.d.mts +12 -0
- package/dist/shared/server.BVwwTHyO.mjs +9 -0
- package/dist/shared/server.BW-nUGgA.mjs +36 -0
- package/dist/shared/server.BjiJH9Vo.d.ts +10 -0
- package/dist/shared/server.Cy1vfSiG.d.ts +12 -0
- package/dist/shared/server.DG7Tamti.mjs +367 -0
- package/dist/shared/server.DPWk5pjW.d.mts +192 -0
- package/dist/shared/server.DPWk5pjW.d.ts +192 -0
- package/dist/shared/server.QUe9N8P4.d.mts +10 -0
- package/dist/shared/server.YZzrREz9.d.ts +74 -0
- package/dist/shared/server.eWLxY3lq.d.mts +74 -0
- package/package.json +57 -36
- package/dist/chunk-4IQKTPXM.js +0 -145
- package/dist/chunk-SD2T3J2Z.js +0 -319
- package/dist/chunk-SV6DBVXJ.js +0 -377
- package/dist/chunk-XFBAK67J.js +0 -128
- package/dist/fetch.js +0 -16
- package/dist/hono.js +0 -40
- package/dist/index.js +0 -404
- package/dist/next.js +0 -37
- package/dist/node.js +0 -170
- package/dist/plugins.js +0 -11
- package/dist/src/adapters/fetch/index.d.ts +0 -4
- package/dist/src/adapters/fetch/rpc-handler.d.ts +0 -10
- package/dist/src/adapters/fetch/types.d.ts +0 -13
- package/dist/src/adapters/fetch/utils.d.ts +0 -5
- package/dist/src/adapters/hono/index.d.ts +0 -3
- package/dist/src/adapters/hono/middleware.d.ts +0 -13
- package/dist/src/adapters/next/index.d.ts +0 -3
- package/dist/src/adapters/next/serve.d.ts +0 -20
- package/dist/src/adapters/node/index.d.ts +0 -4
- package/dist/src/adapters/node/rpc-handler.d.ts +0 -10
- package/dist/src/adapters/node/types.d.ts +0 -21
- package/dist/src/adapters/node/utils.d.ts +0 -5
- package/dist/src/adapters/standard/handler.d.ts +0 -51
- package/dist/src/adapters/standard/index.d.ts +0 -7
- package/dist/src/adapters/standard/rpc-codec.d.ts +0 -15
- package/dist/src/adapters/standard/rpc-handler.d.ts +0 -8
- package/dist/src/adapters/standard/rpc-matcher.d.ts +0 -10
- package/dist/src/adapters/standard/rpc-serializer.d.ts +0 -16
- package/dist/src/adapters/standard/types.d.ts +0 -44
- package/dist/src/builder-variants.d.ts +0 -74
- package/dist/src/builder.d.ts +0 -57
- package/dist/src/config.d.ts +0 -6
- package/dist/src/context.d.ts +0 -9
- package/dist/src/hidden.d.ts +0 -8
- package/dist/src/implementer-procedure.d.ts +0 -30
- package/dist/src/implementer-variants.d.ts +0 -17
- package/dist/src/implementer.d.ts +0 -28
- package/dist/src/index.d.ts +0 -23
- package/dist/src/lazy-utils.d.ts +0 -6
- package/dist/src/lazy.d.ts +0 -22
- package/dist/src/middleware-decorated.d.ts +0 -10
- package/dist/src/middleware-utils.d.ts +0 -5
- package/dist/src/middleware.d.ts +0 -37
- package/dist/src/plugins/base.d.ts +0 -13
- package/dist/src/plugins/cors.d.ts +0 -19
- package/dist/src/plugins/index.d.ts +0 -4
- package/dist/src/plugins/response-headers.d.ts +0 -10
- package/dist/src/procedure-client.d.ts +0 -31
- package/dist/src/procedure-decorated.d.ts +0 -21
- package/dist/src/procedure-utils.d.ts +0 -17
- package/dist/src/procedure.d.ts +0 -29
- package/dist/src/router-accessible-lazy.d.ts +0 -8
- package/dist/src/router-client.d.ts +0 -11
- package/dist/src/router.d.ts +0 -29
- package/dist/src/utils.d.ts +0 -24
- package/dist/standard.js +0 -17
package/dist/chunk-XFBAK67J.js
DELETED
@@ -1,128 +0,0 @@
|
|
1
|
-
// src/plugins/base.ts
|
2
|
-
var CompositePlugin = class {
|
3
|
-
constructor(plugins = []) {
|
4
|
-
this.plugins = plugins;
|
5
|
-
}
|
6
|
-
init(options) {
|
7
|
-
for (const plugin of this.plugins) {
|
8
|
-
plugin.init?.(options);
|
9
|
-
}
|
10
|
-
}
|
11
|
-
beforeCreateProcedureClient(clientOptions, interceptorOptions) {
|
12
|
-
for (const plugin of this.plugins) {
|
13
|
-
plugin.beforeCreateProcedureClient?.(clientOptions, interceptorOptions);
|
14
|
-
}
|
15
|
-
}
|
16
|
-
};
|
17
|
-
|
18
|
-
// src/plugins/cors.ts
|
19
|
-
import { value } from "@orpc/shared";
|
20
|
-
var CORSPlugin = class {
|
21
|
-
options;
|
22
|
-
constructor(options) {
|
23
|
-
const defaults = {
|
24
|
-
origin: "*",
|
25
|
-
allowMethods: ["GET", "HEAD", "PUT", "POST", "DELETE", "PATCH"]
|
26
|
-
};
|
27
|
-
if (options?.credentials) {
|
28
|
-
defaults.origin = (origin) => origin;
|
29
|
-
}
|
30
|
-
this.options = {
|
31
|
-
...defaults,
|
32
|
-
...options
|
33
|
-
};
|
34
|
-
}
|
35
|
-
init(options) {
|
36
|
-
options.interceptorsRoot ??= [];
|
37
|
-
options.interceptorsRoot.unshift(async (interceptorOptions) => {
|
38
|
-
if (interceptorOptions.request.method === "OPTIONS") {
|
39
|
-
const resHeaders = {};
|
40
|
-
if (this.options.maxAge !== void 0) {
|
41
|
-
resHeaders["access-control-max-age"] = this.options.maxAge.toString();
|
42
|
-
}
|
43
|
-
if (this.options.allowMethods?.length) {
|
44
|
-
resHeaders["access-control-allow-methods"] = this.options.allowMethods.join(",");
|
45
|
-
}
|
46
|
-
const allowHeaders = this.options.allowHeaders ?? interceptorOptions.request.headers["access-control-request-headers"];
|
47
|
-
if (Array.isArray(allowHeaders) && allowHeaders.length) {
|
48
|
-
resHeaders["access-control-allow-headers"] = allowHeaders.join(",");
|
49
|
-
} else if (typeof allowHeaders === "string") {
|
50
|
-
resHeaders["access-control-allow-headers"] = allowHeaders;
|
51
|
-
}
|
52
|
-
return {
|
53
|
-
matched: true,
|
54
|
-
response: {
|
55
|
-
status: 204,
|
56
|
-
headers: resHeaders,
|
57
|
-
body: void 0
|
58
|
-
}
|
59
|
-
};
|
60
|
-
}
|
61
|
-
return interceptorOptions.next();
|
62
|
-
});
|
63
|
-
options.interceptorsRoot.unshift(async (interceptorOptions) => {
|
64
|
-
const result = await interceptorOptions.next();
|
65
|
-
if (!result.matched) {
|
66
|
-
return result;
|
67
|
-
}
|
68
|
-
const origin = Array.isArray(interceptorOptions.request.headers.origin) ? interceptorOptions.request.headers.origin.join(",") : interceptorOptions.request.headers.origin || "";
|
69
|
-
const allowedOrigin = await value(this.options.origin, origin, interceptorOptions);
|
70
|
-
const allowedOriginArr = Array.isArray(allowedOrigin) ? allowedOrigin : [allowedOrigin];
|
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
|
-
}
|
77
|
-
result.response.headers.vary = interceptorOptions.request.headers.vary ?? "origin";
|
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
|
-
}
|
86
|
-
if (this.options.credentials) {
|
87
|
-
result.response.headers["access-control-allow-credentials"] = "true";
|
88
|
-
}
|
89
|
-
if (this.options.exposeHeaders?.length) {
|
90
|
-
result.response.headers["access-control-expose-headers"] = this.options.exposeHeaders.join(",");
|
91
|
-
}
|
92
|
-
return result;
|
93
|
-
});
|
94
|
-
}
|
95
|
-
};
|
96
|
-
|
97
|
-
// src/plugins/response-headers.ts
|
98
|
-
var ResponseHeadersPlugin = class {
|
99
|
-
init(options) {
|
100
|
-
options.interceptorsRoot ??= [];
|
101
|
-
options.interceptorsRoot.push(async (interceptorOptions) => {
|
102
|
-
const headers = new Headers();
|
103
|
-
interceptorOptions.context.resHeaders = headers;
|
104
|
-
const result = await interceptorOptions.next();
|
105
|
-
if (!result.matched) {
|
106
|
-
return result;
|
107
|
-
}
|
108
|
-
const responseHeaders = result.response.headers;
|
109
|
-
for (const [key, value2] of headers) {
|
110
|
-
if (Array.isArray(responseHeaders[key])) {
|
111
|
-
responseHeaders[key].push(value2);
|
112
|
-
} else if (responseHeaders[key] !== void 0) {
|
113
|
-
responseHeaders[key] = [responseHeaders[key], value2];
|
114
|
-
} else {
|
115
|
-
responseHeaders[key] = value2;
|
116
|
-
}
|
117
|
-
}
|
118
|
-
return result;
|
119
|
-
});
|
120
|
-
}
|
121
|
-
};
|
122
|
-
|
123
|
-
export {
|
124
|
-
CompositePlugin,
|
125
|
-
CORSPlugin,
|
126
|
-
ResponseHeadersPlugin
|
127
|
-
};
|
128
|
-
//# sourceMappingURL=chunk-XFBAK67J.js.map
|
package/dist/fetch.js
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
RPCHandler,
|
3
|
-
fetchReToStandardBody,
|
4
|
-
fetchRequestToStandardRequest,
|
5
|
-
standardResponseToFetchResponse
|
6
|
-
} from "./chunk-4IQKTPXM.js";
|
7
|
-
import "./chunk-SD2T3J2Z.js";
|
8
|
-
import "./chunk-SV6DBVXJ.js";
|
9
|
-
import "./chunk-XFBAK67J.js";
|
10
|
-
export {
|
11
|
-
RPCHandler,
|
12
|
-
fetchReToStandardBody,
|
13
|
-
fetchRequestToStandardRequest,
|
14
|
-
standardResponseToFetchResponse
|
15
|
-
};
|
16
|
-
//# sourceMappingURL=fetch.js.map
|
package/dist/hono.js
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
RPCHandler,
|
3
|
-
fetchReToStandardBody,
|
4
|
-
fetchRequestToStandardRequest,
|
5
|
-
standardResponseToFetchResponse
|
6
|
-
} from "./chunk-4IQKTPXM.js";
|
7
|
-
import "./chunk-SD2T3J2Z.js";
|
8
|
-
import "./chunk-SV6DBVXJ.js";
|
9
|
-
import "./chunk-XFBAK67J.js";
|
10
|
-
|
11
|
-
// src/adapters/hono/middleware.ts
|
12
|
-
import { value } from "@orpc/shared";
|
13
|
-
function createMiddleware(handler, ...[options]) {
|
14
|
-
return async (c, next) => {
|
15
|
-
const bodyProps = /* @__PURE__ */ new Set(["arrayBuffer", "blob", "formData", "json", "text"]);
|
16
|
-
const request = c.req.method === "GET" || c.req.method === "HEAD" ? c.req.raw : new Proxy(c.req.raw, {
|
17
|
-
// https://github.com/honojs/middleware/blob/main/packages/trpc-server/src/index.ts#L39
|
18
|
-
get(target, prop) {
|
19
|
-
if (bodyProps.has(prop)) {
|
20
|
-
return () => c.req[prop]();
|
21
|
-
}
|
22
|
-
return Reflect.get(target, prop, target);
|
23
|
-
}
|
24
|
-
});
|
25
|
-
const context = await value(options?.context ?? {}, c);
|
26
|
-
const { matched, response } = await handler.handle(request, { ...options, context });
|
27
|
-
if (matched) {
|
28
|
-
return c.newResponse(response.body, response);
|
29
|
-
}
|
30
|
-
await next();
|
31
|
-
};
|
32
|
-
}
|
33
|
-
export {
|
34
|
-
RPCHandler,
|
35
|
-
createMiddleware,
|
36
|
-
fetchReToStandardBody,
|
37
|
-
fetchRequestToStandardRequest,
|
38
|
-
standardResponseToFetchResponse
|
39
|
-
};
|
40
|
-
//# sourceMappingURL=hono.js.map
|
package/dist/index.js
DELETED
@@ -1,404 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
LAZY_LOADER_SYMBOL,
|
3
|
-
Procedure,
|
4
|
-
adaptRouter,
|
5
|
-
addMiddleware,
|
6
|
-
convertPathToHttpPath,
|
7
|
-
createAccessibleLazyRouter,
|
8
|
-
createContractedProcedure,
|
9
|
-
createLazyProcedureFormAnyLazy,
|
10
|
-
createProcedureClient,
|
11
|
-
deepSetLazyRouterPrefix,
|
12
|
-
eachAllContractProcedure,
|
13
|
-
eachContractProcedure,
|
14
|
-
flatLazy,
|
15
|
-
getLazyRouterPrefix,
|
16
|
-
getRouterChild,
|
17
|
-
getRouterContract,
|
18
|
-
isLazy,
|
19
|
-
isProcedure,
|
20
|
-
lazy,
|
21
|
-
middlewareOutputFn,
|
22
|
-
setRouterContract,
|
23
|
-
unlazy
|
24
|
-
} from "./chunk-SV6DBVXJ.js";
|
25
|
-
|
26
|
-
// src/builder.ts
|
27
|
-
import { mergeErrorMap as mergeErrorMap2, mergeMeta as mergeMeta2, mergePrefix, mergeRoute as mergeRoute2, mergeTags } from "@orpc/contract";
|
28
|
-
|
29
|
-
// src/config.ts
|
30
|
-
var DEFAULT_CONFIG = {
|
31
|
-
initialInputValidationIndex: 0,
|
32
|
-
initialOutputValidationIndex: 0
|
33
|
-
};
|
34
|
-
function fallbackConfig(key, value) {
|
35
|
-
if (value === void 0) {
|
36
|
-
return DEFAULT_CONFIG[key];
|
37
|
-
}
|
38
|
-
return value;
|
39
|
-
}
|
40
|
-
|
41
|
-
// src/middleware-decorated.ts
|
42
|
-
function decorateMiddleware(middleware) {
|
43
|
-
const decorated = middleware;
|
44
|
-
decorated.mapInput = (mapInput) => {
|
45
|
-
const mapped = decorateMiddleware(
|
46
|
-
(options, input, ...rest) => middleware(options, mapInput(input), ...rest)
|
47
|
-
);
|
48
|
-
return mapped;
|
49
|
-
};
|
50
|
-
decorated.concat = (concatMiddleware, mapInput) => {
|
51
|
-
const mapped = mapInput ? decorateMiddleware(concatMiddleware).mapInput(mapInput) : concatMiddleware;
|
52
|
-
const concatted = decorateMiddleware((options, input, output, ...rest) => {
|
53
|
-
const next = async (...[nextOptions]) => {
|
54
|
-
return mapped({ ...options, context: { ...nextOptions?.context, ...options.context } }, input, output, ...rest);
|
55
|
-
};
|
56
|
-
const merged = middleware({ ...options, next }, input, output, ...rest);
|
57
|
-
return merged;
|
58
|
-
});
|
59
|
-
return concatted;
|
60
|
-
};
|
61
|
-
return decorated;
|
62
|
-
}
|
63
|
-
|
64
|
-
// src/procedure-decorated.ts
|
65
|
-
import { mergeErrorMap, mergeMeta, mergeRoute } from "@orpc/contract";
|
66
|
-
var DecoratedProcedure = class _DecoratedProcedure extends Procedure {
|
67
|
-
errors(errors) {
|
68
|
-
return new _DecoratedProcedure({
|
69
|
-
...this["~orpc"],
|
70
|
-
errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
|
71
|
-
});
|
72
|
-
}
|
73
|
-
meta(meta) {
|
74
|
-
return new _DecoratedProcedure({
|
75
|
-
...this["~orpc"],
|
76
|
-
meta: mergeMeta(this["~orpc"].meta, meta)
|
77
|
-
});
|
78
|
-
}
|
79
|
-
route(route) {
|
80
|
-
return new _DecoratedProcedure({
|
81
|
-
...this["~orpc"],
|
82
|
-
route: mergeRoute(this["~orpc"].route, route)
|
83
|
-
});
|
84
|
-
}
|
85
|
-
use(middleware, mapInput) {
|
86
|
-
const mapped = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
|
87
|
-
return new _DecoratedProcedure({
|
88
|
-
...this["~orpc"],
|
89
|
-
middlewares: addMiddleware(this["~orpc"].middlewares, mapped)
|
90
|
-
});
|
91
|
-
}
|
92
|
-
/**
|
93
|
-
* Make this procedure callable (works like a function while still being a procedure).
|
94
|
-
*/
|
95
|
-
callable(...rest) {
|
96
|
-
return Object.assign(createProcedureClient(this, ...rest), {
|
97
|
-
"~type": "Procedure",
|
98
|
-
"~orpc": this["~orpc"]
|
99
|
-
});
|
100
|
-
}
|
101
|
-
/**
|
102
|
-
* Make this procedure compatible with server action (the same as .callable, but the type is compatible with server action).
|
103
|
-
*/
|
104
|
-
actionable(...rest) {
|
105
|
-
return this.callable(...rest);
|
106
|
-
}
|
107
|
-
};
|
108
|
-
|
109
|
-
// src/builder.ts
|
110
|
-
var Builder = class _Builder {
|
111
|
-
"~orpc";
|
112
|
-
constructor(def) {
|
113
|
-
this["~orpc"] = def;
|
114
|
-
}
|
115
|
-
/**
|
116
|
-
* Reset config
|
117
|
-
*/
|
118
|
-
$config(config) {
|
119
|
-
const inputValidationCount = this["~orpc"].inputValidationIndex - fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex);
|
120
|
-
const outputValidationCount = this["~orpc"].outputValidationIndex - fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex);
|
121
|
-
return new _Builder({
|
122
|
-
...this["~orpc"],
|
123
|
-
config,
|
124
|
-
inputValidationIndex: fallbackConfig("initialInputValidationIndex", config.initialInputValidationIndex) + inputValidationCount,
|
125
|
-
outputValidationIndex: fallbackConfig("initialOutputValidationIndex", config.initialOutputValidationIndex) + outputValidationCount
|
126
|
-
});
|
127
|
-
}
|
128
|
-
/**
|
129
|
-
* Reset initial context
|
130
|
-
*/
|
131
|
-
$context() {
|
132
|
-
return new _Builder({
|
133
|
-
...this["~orpc"],
|
134
|
-
middlewares: [],
|
135
|
-
inputValidationIndex: fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex),
|
136
|
-
outputValidationIndex: fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex)
|
137
|
-
});
|
138
|
-
}
|
139
|
-
/**
|
140
|
-
* Reset initial meta
|
141
|
-
*/
|
142
|
-
$meta(initialMeta) {
|
143
|
-
return new _Builder({
|
144
|
-
...this["~orpc"],
|
145
|
-
meta: initialMeta
|
146
|
-
});
|
147
|
-
}
|
148
|
-
/**
|
149
|
-
* Reset initial route
|
150
|
-
*/
|
151
|
-
$route(initialRoute) {
|
152
|
-
return new _Builder({
|
153
|
-
...this["~orpc"],
|
154
|
-
route: initialRoute
|
155
|
-
});
|
156
|
-
}
|
157
|
-
middleware(middleware) {
|
158
|
-
return decorateMiddleware(middleware);
|
159
|
-
}
|
160
|
-
errors(errors) {
|
161
|
-
return new _Builder({
|
162
|
-
...this["~orpc"],
|
163
|
-
errorMap: mergeErrorMap2(this["~orpc"].errorMap, errors)
|
164
|
-
});
|
165
|
-
}
|
166
|
-
use(middleware, mapInput) {
|
167
|
-
const mapped = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
|
168
|
-
return new _Builder({
|
169
|
-
...this["~orpc"],
|
170
|
-
middlewares: addMiddleware(this["~orpc"].middlewares, mapped)
|
171
|
-
});
|
172
|
-
}
|
173
|
-
meta(meta) {
|
174
|
-
return new _Builder({
|
175
|
-
...this["~orpc"],
|
176
|
-
meta: mergeMeta2(this["~orpc"].meta, meta)
|
177
|
-
});
|
178
|
-
}
|
179
|
-
route(route) {
|
180
|
-
return new _Builder({
|
181
|
-
...this["~orpc"],
|
182
|
-
route: mergeRoute2(this["~orpc"].route, route)
|
183
|
-
});
|
184
|
-
}
|
185
|
-
input(schema) {
|
186
|
-
return new _Builder({
|
187
|
-
...this["~orpc"],
|
188
|
-
inputSchema: schema,
|
189
|
-
inputValidationIndex: fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex) + this["~orpc"].middlewares.length
|
190
|
-
});
|
191
|
-
}
|
192
|
-
output(schema) {
|
193
|
-
return new _Builder({
|
194
|
-
...this["~orpc"],
|
195
|
-
outputSchema: schema,
|
196
|
-
outputValidationIndex: fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex) + this["~orpc"].middlewares.length
|
197
|
-
});
|
198
|
-
}
|
199
|
-
handler(handler) {
|
200
|
-
return new DecoratedProcedure({
|
201
|
-
...this["~orpc"],
|
202
|
-
handler
|
203
|
-
});
|
204
|
-
}
|
205
|
-
prefix(prefix) {
|
206
|
-
return new _Builder({
|
207
|
-
...this["~orpc"],
|
208
|
-
prefix: mergePrefix(this["~orpc"].prefix, prefix)
|
209
|
-
});
|
210
|
-
}
|
211
|
-
tag(...tags) {
|
212
|
-
return new _Builder({
|
213
|
-
...this["~orpc"],
|
214
|
-
tags: mergeTags(this["~orpc"].tags, tags)
|
215
|
-
});
|
216
|
-
}
|
217
|
-
router(router) {
|
218
|
-
return adaptRouter(router, this["~orpc"]);
|
219
|
-
}
|
220
|
-
lazy(loader) {
|
221
|
-
return adaptRouter(flatLazy(lazy(loader)), this["~orpc"]);
|
222
|
-
}
|
223
|
-
};
|
224
|
-
var os = new Builder({
|
225
|
-
config: {},
|
226
|
-
route: {},
|
227
|
-
meta: {},
|
228
|
-
errorMap: {},
|
229
|
-
inputSchema: void 0,
|
230
|
-
outputSchema: void 0,
|
231
|
-
inputValidationIndex: fallbackConfig("initialInputValidationIndex"),
|
232
|
-
outputValidationIndex: fallbackConfig("initialOutputValidationIndex"),
|
233
|
-
middlewares: []
|
234
|
-
});
|
235
|
-
|
236
|
-
// src/context.ts
|
237
|
-
function mergeContext(context, other) {
|
238
|
-
return { ...context, ...other };
|
239
|
-
}
|
240
|
-
|
241
|
-
// src/implementer.ts
|
242
|
-
import { isContractProcedure } from "@orpc/contract";
|
243
|
-
function implementerInternal(contract, config, middlewares) {
|
244
|
-
if (isContractProcedure(contract)) {
|
245
|
-
const impl2 = new Builder({
|
246
|
-
...contract["~orpc"],
|
247
|
-
config,
|
248
|
-
middlewares,
|
249
|
-
inputValidationIndex: fallbackConfig("initialInputValidationIndex", config?.initialInputValidationIndex) + middlewares.length,
|
250
|
-
outputValidationIndex: fallbackConfig("initialOutputValidationIndex", config?.initialOutputValidationIndex) + middlewares.length
|
251
|
-
});
|
252
|
-
return impl2;
|
253
|
-
}
|
254
|
-
const impl = new Proxy(contract, {
|
255
|
-
get: (target, key) => {
|
256
|
-
let method;
|
257
|
-
if (key === "middleware") {
|
258
|
-
method = (mid) => decorateMiddleware(mid);
|
259
|
-
} else if (key === "use") {
|
260
|
-
method = (mid) => {
|
261
|
-
return implementerInternal(
|
262
|
-
contract,
|
263
|
-
config,
|
264
|
-
addMiddleware(middlewares, mid)
|
265
|
-
);
|
266
|
-
};
|
267
|
-
} else if (key === "router") {
|
268
|
-
method = (router) => {
|
269
|
-
const adapted = adaptRouter(router, {
|
270
|
-
middlewares,
|
271
|
-
errorMap: {}
|
272
|
-
});
|
273
|
-
return setRouterContract(adapted, contract);
|
274
|
-
};
|
275
|
-
} else if (key === "lazy") {
|
276
|
-
method = (loader) => {
|
277
|
-
const adapted = adaptRouter(flatLazy(lazy(loader)), {
|
278
|
-
middlewares,
|
279
|
-
errorMap: {}
|
280
|
-
});
|
281
|
-
return setRouterContract(adapted, contract);
|
282
|
-
};
|
283
|
-
}
|
284
|
-
const next = Reflect.get(target, key);
|
285
|
-
if (!next || typeof next !== "function" && typeof next !== "object") {
|
286
|
-
return method ?? next;
|
287
|
-
}
|
288
|
-
const nextImpl = implementerInternal(next, config, middlewares);
|
289
|
-
if (method) {
|
290
|
-
return new Proxy(method, {
|
291
|
-
get(_, key2) {
|
292
|
-
return Reflect.get(nextImpl, key2);
|
293
|
-
}
|
294
|
-
});
|
295
|
-
}
|
296
|
-
return nextImpl;
|
297
|
-
}
|
298
|
-
});
|
299
|
-
return impl;
|
300
|
-
}
|
301
|
-
function implement(contract, config = {}) {
|
302
|
-
const implInternal = implementerInternal(contract, config, []);
|
303
|
-
const impl = new Proxy(implInternal, {
|
304
|
-
get: (target, key) => {
|
305
|
-
let method;
|
306
|
-
if (key === "$context") {
|
307
|
-
method = () => impl;
|
308
|
-
} else if (key === "$config") {
|
309
|
-
method = (config2) => implement(contract, config2);
|
310
|
-
}
|
311
|
-
const next = Reflect.get(target, key);
|
312
|
-
if (!next || typeof next !== "function" && typeof next !== "object") {
|
313
|
-
return method ?? next;
|
314
|
-
}
|
315
|
-
if (method) {
|
316
|
-
return new Proxy(method, {
|
317
|
-
get(_, key2) {
|
318
|
-
return Reflect.get(next, key2);
|
319
|
-
}
|
320
|
-
});
|
321
|
-
}
|
322
|
-
return next;
|
323
|
-
}
|
324
|
-
});
|
325
|
-
return impl;
|
326
|
-
}
|
327
|
-
|
328
|
-
// src/procedure-utils.ts
|
329
|
-
function call(procedure, input, ...rest) {
|
330
|
-
return createProcedureClient(procedure, ...rest)(input);
|
331
|
-
}
|
332
|
-
|
333
|
-
// src/router-client.ts
|
334
|
-
function createRouterClient(router, ...rest) {
|
335
|
-
if (isProcedure(router)) {
|
336
|
-
const caller = createProcedureClient(router, ...rest);
|
337
|
-
return caller;
|
338
|
-
}
|
339
|
-
const procedureCaller = isLazy(router) ? createProcedureClient(createLazyProcedureFormAnyLazy(router), ...rest) : {};
|
340
|
-
const recursive = new Proxy(procedureCaller, {
|
341
|
-
get(target, key) {
|
342
|
-
if (typeof key !== "string") {
|
343
|
-
return Reflect.get(target, key);
|
344
|
-
}
|
345
|
-
const next = getRouterChild(router, key);
|
346
|
-
if (!next) {
|
347
|
-
return Reflect.get(target, key);
|
348
|
-
}
|
349
|
-
const [options] = rest;
|
350
|
-
return createRouterClient(next, {
|
351
|
-
...options,
|
352
|
-
path: [...options?.path ?? [], key]
|
353
|
-
});
|
354
|
-
}
|
355
|
-
});
|
356
|
-
return recursive;
|
357
|
-
}
|
358
|
-
|
359
|
-
// src/index.ts
|
360
|
-
import { isDefinedError, ORPCError, safe, type, ValidationError } from "@orpc/contract";
|
361
|
-
import { onError, onFinish, onStart, onSuccess } from "@orpc/shared";
|
362
|
-
export {
|
363
|
-
Builder,
|
364
|
-
DecoratedProcedure,
|
365
|
-
LAZY_LOADER_SYMBOL,
|
366
|
-
ORPCError,
|
367
|
-
Procedure,
|
368
|
-
ValidationError,
|
369
|
-
adaptRouter,
|
370
|
-
call,
|
371
|
-
convertPathToHttpPath,
|
372
|
-
createAccessibleLazyRouter,
|
373
|
-
createContractedProcedure,
|
374
|
-
createLazyProcedureFormAnyLazy,
|
375
|
-
createProcedureClient,
|
376
|
-
createRouterClient,
|
377
|
-
decorateMiddleware,
|
378
|
-
deepSetLazyRouterPrefix,
|
379
|
-
eachAllContractProcedure,
|
380
|
-
eachContractProcedure,
|
381
|
-
fallbackConfig,
|
382
|
-
flatLazy,
|
383
|
-
getLazyRouterPrefix,
|
384
|
-
getRouterChild,
|
385
|
-
getRouterContract,
|
386
|
-
implement,
|
387
|
-
implementerInternal,
|
388
|
-
isDefinedError,
|
389
|
-
isLazy,
|
390
|
-
isProcedure,
|
391
|
-
lazy,
|
392
|
-
mergeContext,
|
393
|
-
middlewareOutputFn,
|
394
|
-
onError,
|
395
|
-
onFinish,
|
396
|
-
onStart,
|
397
|
-
onSuccess,
|
398
|
-
os,
|
399
|
-
safe,
|
400
|
-
setRouterContract,
|
401
|
-
type,
|
402
|
-
unlazy
|
403
|
-
};
|
404
|
-
//# sourceMappingURL=index.js.map
|
package/dist/next.js
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
RPCHandler,
|
3
|
-
fetchReToStandardBody,
|
4
|
-
fetchRequestToStandardRequest,
|
5
|
-
standardResponseToFetchResponse
|
6
|
-
} from "./chunk-4IQKTPXM.js";
|
7
|
-
import "./chunk-SD2T3J2Z.js";
|
8
|
-
import "./chunk-SV6DBVXJ.js";
|
9
|
-
import "./chunk-XFBAK67J.js";
|
10
|
-
|
11
|
-
// src/adapters/next/serve.ts
|
12
|
-
import { value } from "@orpc/shared";
|
13
|
-
function serve(handler, ...[options]) {
|
14
|
-
const main = async (req) => {
|
15
|
-
const context = await value(options?.context ?? {}, req);
|
16
|
-
const { matched, response } = await handler.handle(req, { ...options, context });
|
17
|
-
if (matched) {
|
18
|
-
return response;
|
19
|
-
}
|
20
|
-
return new Response(`Cannot find a matching procedure for ${req.url}`, { status: 404 });
|
21
|
-
};
|
22
|
-
return {
|
23
|
-
GET: main,
|
24
|
-
POST: main,
|
25
|
-
PUT: main,
|
26
|
-
PATCH: main,
|
27
|
-
DELETE: main
|
28
|
-
};
|
29
|
-
}
|
30
|
-
export {
|
31
|
-
RPCHandler,
|
32
|
-
fetchReToStandardBody,
|
33
|
-
fetchRequestToStandardRequest,
|
34
|
-
serve,
|
35
|
-
standardResponseToFetchResponse
|
36
|
-
};
|
37
|
-
//# sourceMappingURL=next.js.map
|