@orpc/server 2.0.0-beta.49 → 2.0.0-beta.50
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/adapters/aws-lambda/handler.d.ts +17 -15
- package/dist/adapters/aws-lambda/handler.js +23 -23
- package/dist/adapters/aws-lambda/index.d.ts +4 -16
- package/dist/adapters/aws-lambda/index.js +2 -2
- package/dist/adapters/aws-lambda/rpc-handler.d.ts +9 -9
- package/dist/adapters/aws-lambda/rpc-handler.js +20 -17
- package/dist/adapters/crossws/handler.d.ts +44 -42
- package/dist/adapters/crossws/handler.js +53 -60
- package/dist/adapters/crossws/index.d.ts +3 -2
- package/dist/adapters/crossws/index.js +2 -2
- package/dist/adapters/crossws/rpc-handler.d.ts +10 -10
- package/dist/adapters/crossws/rpc-handler.js +17 -14
- package/dist/adapters/fastify/handler.d.ts +17 -15
- package/dist/adapters/fastify/handler.js +20 -20
- package/dist/adapters/fastify/index.d.ts +3 -2
- package/dist/adapters/fastify/index.js +2 -2
- package/dist/adapters/fastify/rpc-handler.d.ts +9 -9
- package/dist/adapters/fastify/rpc-handler.js +16 -13
- package/dist/adapters/fetch/handler.d.ts +19 -17
- package/dist/adapters/fetch/handler.js +22 -22
- package/dist/adapters/fetch/index.d.ts +4 -7
- package/dist/adapters/fetch/index.js +3 -7
- package/dist/adapters/fetch/rpc-handler.d.ts +9 -9
- package/dist/adapters/fetch/rpc-handler.js +18 -15
- package/dist/adapters/message-port/handler.d.ts +58 -60
- package/dist/adapters/message-port/handler.js +72 -86
- package/dist/adapters/message-port/index.d.ts +3 -2
- package/dist/adapters/message-port/index.js +2 -2
- package/dist/adapters/message-port/rpc-handler.d.ts +9 -9
- package/dist/adapters/message-port/rpc-handler.js +17 -14
- package/dist/adapters/node/handler.d.ts +17 -15
- package/dist/adapters/node/handler.js +20 -20
- package/dist/adapters/node/index.d.ts +4 -7
- package/dist/adapters/node/index.js +3 -7
- package/dist/adapters/node/rpc-handler.d.ts +9 -9
- package/dist/adapters/node/rpc-handler.js +17 -14
- package/dist/adapters/standard/codec.d.ts +13 -13
- package/dist/adapters/standard/handler.d.ts +49 -49
- package/dist/adapters/standard/handler.js +205 -205
- package/dist/adapters/standard/index.d.ts +7 -6
- package/dist/adapters/standard/index.js +4 -5
- package/dist/adapters/standard/plugin.d.ts +25 -31
- package/dist/adapters/standard/plugin.js +14 -16
- package/dist/adapters/standard/rpc-handler-codec.d.ts +39 -43
- package/dist/adapters/standard/rpc-handler-codec.js +50 -51
- package/dist/adapters/standard/rpc-matcher.d.ts +40 -40
- package/dist/adapters/standard/rpc-matcher.js +103 -149
- package/dist/adapters/standard/utils.d.ts +8 -8
- package/dist/adapters/standard/utils.js +7 -5
- package/dist/adapters/standard-peer/index.d.ts +2 -1
- package/dist/adapters/standard-peer/index.js +1 -1
- package/dist/adapters/standard-peer/utils.d.ts +6 -4
- package/dist/adapters/standard-peer/utils.js +12 -6
- package/dist/adapters/websocket/handler.d.ts +52 -50
- package/dist/adapters/websocket/handler.js +75 -85
- package/dist/adapters/websocket/index.d.ts +3 -2
- package/dist/adapters/websocket/index.js +2 -2
- package/dist/adapters/websocket/rpc-handler.d.ts +9 -9
- package/dist/adapters/websocket/rpc-handler.js +17 -14
- package/dist/builder-variants.d.ts +195 -195
- package/dist/builder.d.ts +103 -104
- package/dist/builder.js +198 -224
- package/dist/constants.d.ts +1 -1
- package/dist/constants.js +4 -2
- package/dist/context.d.ts +3 -3
- package/dist/extensions/callable.d.ts +11 -11
- package/dist/extensions/callable.js +6 -5
- package/dist/helpers/base64url.d.ts +1 -1
- package/dist/helpers/base64url.js +44 -49
- package/dist/helpers/cookie.d.ts +10 -11
- package/dist/helpers/cookie.js +56 -63
- package/dist/helpers/encryption.d.ts +1 -1
- package/dist/helpers/encryption.js +80 -70
- package/dist/helpers/index.d.ts +5 -4
- package/dist/helpers/index.js +4 -4
- package/dist/helpers/signing.d.ts +1 -1
- package/dist/helpers/signing.js +72 -82
- package/dist/implementer-procedure.d.ts +12 -13
- package/dist/implementer-procedure.js +37 -44
- package/dist/implementer-router.d.ts +30 -36
- package/dist/implementer-router.js +92 -111
- package/dist/implementer.d.ts +8 -8
- package/dist/implementer.js +28 -35
- package/dist/index.d.ts +22 -61
- package/dist/index.js +16 -48
- package/dist/lazy.d.ts +14 -14
- package/dist/lazy.js +19 -30
- package/dist/middleware-decorated.d.ts +8 -9
- package/dist/middleware-decorated.js +66 -70
- package/dist/middleware.d.ts +34 -34
- package/dist/plugins/batch.d.ts +75 -75
- package/dist/plugins/batch.js +345 -379
- package/dist/plugins/cors.d.ts +60 -64
- package/dist/plugins/cors.js +118 -111
- package/dist/plugins/get-method-csrf-protection.d.ts +8 -6
- package/dist/plugins/get-method-csrf-protection.js +47 -63
- package/dist/plugins/head-method.d.ts +11 -9
- package/dist/plugins/head-method.js +97 -94
- package/dist/plugins/index.d.ts +15 -39
- package/dist/plugins/index.js +14 -29
- package/dist/plugins/method-override.d.ts +30 -28
- package/dist/plugins/method-override.js +53 -49
- package/dist/plugins/request-compression.d.ts +11 -9
- package/dist/plugins/request-compression.js +52 -79
- package/dist/plugins/request-headers.d.ts +10 -8
- package/dist/plugins/request-headers.js +27 -29
- package/dist/plugins/request-limit.d.ts +21 -19
- package/dist/plugins/request-limit.js +60 -67
- package/dist/plugins/response-compression.d.ts +42 -39
- package/dist/plugins/response-compression.js +150 -202
- package/dist/plugins/response-headers.d.ts +15 -13
- package/dist/plugins/response-headers.js +43 -46
- package/dist/plugins/rethrow.d.ts +25 -23
- package/dist/plugins/rethrow.js +46 -58
- package/dist/plugins/signal-sync.d.ts +7 -5
- package/dist/plugins/signal-sync.js +71 -86
- package/dist/plugins/timeout.d.ts +29 -27
- package/dist/plugins/timeout.js +61 -58
- package/dist/procedure-client.d.ts +14 -15
- package/dist/procedure-client.js +149 -166
- package/dist/procedure-decorated.d.ts +9 -9
- package/dist/procedure-decorated.js +36 -44
- package/dist/procedure-utils.d.ts +10 -30
- package/dist/procedure-utils.js +39 -40
- package/dist/procedure.d.ts +60 -60
- package/dist/procedure.js +18 -24
- package/dist/router-client.d.ts +9 -11
- package/dist/router-client.js +33 -41
- package/dist/router-hidden.js +10 -12
- package/dist/router-utils.d.ts +13 -30
- package/dist/router-utils.js +146 -191
- package/dist/router.d.ts +12 -26
- package/package.json +10 -10
- package/dist/adapters/standard/codec.js +0 -1
- package/dist/builder-variants.js +0 -1
- package/dist/context.js +0 -1
- package/dist/middleware.js +0 -1
- package/dist/router-hidden.d.ts +0 -5
- package/dist/router.js +0 -1
package/dist/builder.js
CHANGED
|
@@ -1,226 +1,200 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
1
|
+
import { Lazy } from "./lazy.js";
|
|
2
|
+
import { decorateMiddleware } from "./middleware-decorated.js";
|
|
3
|
+
import { DecoratedProcedure } from "./procedure-decorated.js";
|
|
4
|
+
import { augmentRouter } from "./router-utils.js";
|
|
5
|
+
import { getHiddenMetaPlugins, mergeErrorMap, resolveMetaPlugins } from "@orpc/contract";
|
|
6
|
+
import { toArray } from "@orpc/shared";
|
|
7
|
+
// src/builder.ts
|
|
7
8
|
/**
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
*
|
|
193
|
-
* @see {@link https://orpc.dev/docs/router#extending-router | Router - Extending Router}
|
|
194
|
-
*/
|
|
195
|
-
'router'(router) {
|
|
196
|
-
return augmentRouter(router, {
|
|
197
|
-
...this['~orpc'],
|
|
198
|
-
middlewares: this['~orpc'].orderedMiddlewares.map(({ middleware }) => middleware),
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
/**
|
|
202
|
-
* Like `.router`, but loads the router lazily on first access, which helps
|
|
203
|
-
* reduce startup time for large applications.
|
|
204
|
-
*
|
|
205
|
-
* @see {@link https://orpc.dev/docs/router#lazy-router | Router - Lazy Router}
|
|
206
|
-
*/
|
|
207
|
-
'lazy'(loader) {
|
|
208
|
-
return new Lazy({
|
|
209
|
-
loader: async () => {
|
|
210
|
-
const { default: router } = await loader();
|
|
211
|
-
return {
|
|
212
|
-
default: this.router(router),
|
|
213
|
-
};
|
|
214
|
-
},
|
|
215
|
-
meta: this['~orpc'].meta,
|
|
216
|
-
metaPlugins: this['~orpc'].metaPlugins,
|
|
217
|
-
});
|
|
218
|
-
}
|
|
219
|
-
}
|
|
9
|
+
* The procedure builder behind `os`. Chain its methods to gradually define
|
|
10
|
+
* context, middleware, errors, schemas, and finally a handler or router.
|
|
11
|
+
*
|
|
12
|
+
* @see {@link https://orpc.dev/docs/procedure | Procedure}
|
|
13
|
+
*/
|
|
14
|
+
var Builder = class Builder {
|
|
15
|
+
"~orpc";
|
|
16
|
+
/**
|
|
17
|
+
* Private constructor to prevent direct instantiation.
|
|
18
|
+
* Use the static `create` method to initialize a new instance with a safe initial definition.
|
|
19
|
+
*/
|
|
20
|
+
"constructor"(definition) {
|
|
21
|
+
this["~orpc"] = definition;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Creates a fresh builder with an empty definition.
|
|
25
|
+
* Prefer the exported `os` instance over calling this directly.
|
|
26
|
+
*
|
|
27
|
+
* @see {@link https://orpc.dev/docs/procedure | Procedure}
|
|
28
|
+
*/
|
|
29
|
+
static "create"() {
|
|
30
|
+
return new Builder({
|
|
31
|
+
errorMap: {},
|
|
32
|
+
meta: {},
|
|
33
|
+
orderedMiddlewares: []
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Declares the initial context type that must be provided when executing
|
|
38
|
+
* procedures built from this builder.
|
|
39
|
+
*
|
|
40
|
+
* @see {@link https://orpc.dev/docs/context#initial-context | Context - Initial Context}
|
|
41
|
+
*/
|
|
42
|
+
"$context"() {
|
|
43
|
+
return this;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Overrides the procedure configuration, such as disabling runtime
|
|
47
|
+
* input/output validation.
|
|
48
|
+
*
|
|
49
|
+
* @see {@link https://orpc.dev/docs/recipes/validation-customization | Validation Customization}
|
|
50
|
+
*/
|
|
51
|
+
"$config"(config) {
|
|
52
|
+
return new Builder({
|
|
53
|
+
...this["~orpc"],
|
|
54
|
+
...config
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Applies metadata plugins to procedures built from this builder.
|
|
59
|
+
*
|
|
60
|
+
* @see {@link https://orpc.dev/docs/metadata | Metadata}
|
|
61
|
+
*/
|
|
62
|
+
"meta"(...plugins) {
|
|
63
|
+
const [meta, metaPlugins] = resolveMetaPlugins(this["~orpc"].meta, this["~orpc"].metaPlugins, plugins);
|
|
64
|
+
return new Builder({
|
|
65
|
+
...this["~orpc"],
|
|
66
|
+
meta,
|
|
67
|
+
metaPlugins
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Defines typesafe errors that procedures built from this builder can throw
|
|
72
|
+
* via the `errors` utility in handlers and middleware.
|
|
73
|
+
*
|
|
74
|
+
* @see {@link https://orpc.dev/docs/error-handling#typesafe-errors | Error Handling - Typesafe Errors}
|
|
75
|
+
*/
|
|
76
|
+
"errors"(errors) {
|
|
77
|
+
let builder = new Builder({
|
|
78
|
+
...this["~orpc"],
|
|
79
|
+
errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
|
|
80
|
+
});
|
|
81
|
+
const plugins = getHiddenMetaPlugins(errors);
|
|
82
|
+
if (plugins) builder = builder.meta(...plugins);
|
|
83
|
+
return builder;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Applies a middleware that runs before the handler of every procedure
|
|
87
|
+
* built from this builder.
|
|
88
|
+
*
|
|
89
|
+
* @see {@link https://orpc.dev/docs/middleware | Middleware}
|
|
90
|
+
*/
|
|
91
|
+
"use"(middleware) {
|
|
92
|
+
let builder = new Builder({
|
|
93
|
+
...this["~orpc"],
|
|
94
|
+
errorMap: mergeErrorMap(middleware["~orpc"]?.errorMap ?? {}, this["~orpc"].errorMap),
|
|
95
|
+
orderedMiddlewares: [...this["~orpc"].orderedMiddlewares, {
|
|
96
|
+
middleware,
|
|
97
|
+
inputSchemasLengthAtUse: this["~orpc"].inputSchemas?.length,
|
|
98
|
+
outputSchemasLengthAtUse: this["~orpc"].outputSchemas?.length
|
|
99
|
+
}]
|
|
100
|
+
});
|
|
101
|
+
if (middleware["~orpc"]?.metaPlugins) builder = builder.meta(...middleware["~orpc"]?.metaPlugins);
|
|
102
|
+
return builder;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Creates a standalone middleware that can be composed and applied to any
|
|
106
|
+
* compatible builder or procedure with `.use`.
|
|
107
|
+
*
|
|
108
|
+
* @see {@link https://orpc.dev/docs/middleware | Middleware}
|
|
109
|
+
*/
|
|
110
|
+
"middleware"(middleware) {
|
|
111
|
+
const allMiddlewares = [...this["~orpc"].orderedMiddlewares.map(({ middleware }) => middleware), middleware];
|
|
112
|
+
let current = decorateMiddleware(allMiddlewares.shift());
|
|
113
|
+
for (const mid of allMiddlewares) current = current.use(mid);
|
|
114
|
+
current["~orpc"] = {
|
|
115
|
+
...current["~orpc"],
|
|
116
|
+
errorMap: this["~orpc"].errorMap,
|
|
117
|
+
metaPlugins: [...toArray(this["~orpc"].metaPlugins), ...toArray(middleware["~orpc"]?.metaPlugins)]
|
|
118
|
+
};
|
|
119
|
+
return current;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Defines the input schema used to validate and type the procedure input.
|
|
123
|
+
*
|
|
124
|
+
* @see {@link https://orpc.dev/docs/procedure#inputoutput-validation | Procedure - Input/Output Validation}
|
|
125
|
+
*/
|
|
126
|
+
"input"(schema) {
|
|
127
|
+
let builder = new Builder({
|
|
128
|
+
...this["~orpc"],
|
|
129
|
+
inputSchemas: [...toArray(this["~orpc"].inputSchemas), schema]
|
|
130
|
+
});
|
|
131
|
+
const plugins = getHiddenMetaPlugins(schema);
|
|
132
|
+
if (plugins) builder = builder.meta(...plugins);
|
|
133
|
+
return builder;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Defines the output schema used to validate and type the procedure output.
|
|
137
|
+
*
|
|
138
|
+
* @see {@link https://orpc.dev/docs/procedure#inputoutput-validation | Procedure - Input/Output Validation}
|
|
139
|
+
*/
|
|
140
|
+
"output"(schema) {
|
|
141
|
+
let builder = new Builder({
|
|
142
|
+
...this["~orpc"],
|
|
143
|
+
outputSchemas: [...toArray(this["~orpc"].outputSchemas), schema]
|
|
144
|
+
});
|
|
145
|
+
const plugins = getHiddenMetaPlugins(schema);
|
|
146
|
+
if (plugins) builder = builder.meta(...plugins);
|
|
147
|
+
return builder;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Defines the function that implements the procedure and completes the
|
|
151
|
+
* chain, returning a callable procedure.
|
|
152
|
+
*
|
|
153
|
+
* @see {@link https://orpc.dev/docs/procedure | Procedure}
|
|
154
|
+
*/
|
|
155
|
+
"handler"(handler) {
|
|
156
|
+
let procedure = new DecoratedProcedure({
|
|
157
|
+
...this["~orpc"],
|
|
158
|
+
handler
|
|
159
|
+
});
|
|
160
|
+
const plugins = getHiddenMetaPlugins(handler);
|
|
161
|
+
if (plugins) procedure = procedure.meta(...plugins);
|
|
162
|
+
return procedure;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Applies the builder's middleware, errors, and metadata to every procedure
|
|
166
|
+
* in the given router.
|
|
167
|
+
*
|
|
168
|
+
* @see {@link https://orpc.dev/docs/router#extending-router | Router - Extending Router}
|
|
169
|
+
*/
|
|
170
|
+
"router"(router) {
|
|
171
|
+
return augmentRouter(router, {
|
|
172
|
+
...this["~orpc"],
|
|
173
|
+
middlewares: this["~orpc"].orderedMiddlewares.map(({ middleware }) => middleware)
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Like `.router`, but loads the router lazily on first access, which helps
|
|
178
|
+
* reduce startup time for large applications.
|
|
179
|
+
*
|
|
180
|
+
* @see {@link https://orpc.dev/docs/router#lazy-router | Router - Lazy Router}
|
|
181
|
+
*/
|
|
182
|
+
"lazy"(loader) {
|
|
183
|
+
return new Lazy({
|
|
184
|
+
loader: async () => {
|
|
185
|
+
const { default: router } = await loader();
|
|
186
|
+
return { default: this.router(router) };
|
|
187
|
+
},
|
|
188
|
+
meta: this["~orpc"].meta,
|
|
189
|
+
metaPlugins: this["~orpc"].metaPlugins
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
};
|
|
220
193
|
/**
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
194
|
+
* The oRPC procedure builder. Chain methods like `.input`, `.use`, and `.handler`
|
|
195
|
+
* to define procedures, then compose them into routers.
|
|
196
|
+
*
|
|
197
|
+
* @see {@link https://orpc.dev/docs/procedure | Procedure}
|
|
198
|
+
*/
|
|
199
|
+
const os = /* @__PURE__ */ Builder.create();
|
|
200
|
+
export { Builder, os };
|
package/dist/constants.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export declare const DEFAULT_SUCCESS_STATUS = 200;
|
|
2
|
-
export declare const DEFAULT_ERROR_STATUS = 400;
|
|
2
|
+
export declare const DEFAULT_ERROR_STATUS = 400;
|
package/dist/constants.js
CHANGED
package/dist/context.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { DistributiveOmit } from "@orpc/shared";
|
|
2
2
|
export interface Context {
|
|
3
|
-
|
|
3
|
+
[key: PropertyKey]: any;
|
|
4
4
|
}
|
|
5
5
|
export type MergedInitialContext<TInitial extends Context, TOutContext extends Context, TInContext extends Context> = TInContext extends any ? Exclude<keyof TInContext, keyof TInitial | keyof TOutContext> extends never ? TInitial : TInitial & DistributiveOmit<TInContext, keyof TInitial | keyof TOutContext> : never;
|
|
6
|
-
export type MergedContext<TCurrent extends Context, TOutContext extends Context> = keyof TOutContext extends never ? TCurrent : DistributiveOmit<TCurrent, keyof TOutContext> & TOutContext;
|
|
6
|
+
export type MergedContext<TCurrent extends Context, TOutContext extends Context> = keyof TOutContext extends never ? TCurrent : DistributiveOmit<TCurrent, keyof TOutContext> & TOutContext;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
declare module
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
1
|
+
import { Context } from "../context.js";
|
|
2
|
+
import { Procedure } from "../procedure.js";
|
|
3
|
+
import { ProcedureClient, ProcedureClientOptions } from "../procedure-client.js";
|
|
4
|
+
import { AnySchema, ErrorMap } from "@orpc/contract";
|
|
5
|
+
import { MaybeOptionalOptions } from "@orpc/shared";
|
|
6
|
+
import { ClientContext } from "@orpc/client";
|
|
7
|
+
declare module "@orpc/server" {
|
|
8
|
+
interface DecoratedProcedure<TInitialContext extends Context, TInjectedContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> {
|
|
9
|
+
callable<TClientContext extends ClientContext>(...rest: MaybeOptionalOptions<ProcedureClientOptions<TInitialContext, TOutputSchema, TErrorMap, TClientContext>>): Procedure<TInitialContext, TInjectedContext, TInputSchema, TOutputSchema, TErrorMap> & ProcedureClient<TClientContext, TInputSchema, TOutputSchema, TErrorMap>;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { createProcedureClient } from
|
|
2
|
-
import { DecoratedProcedure } from
|
|
1
|
+
import { createProcedureClient } from "../procedure-client.js";
|
|
2
|
+
import { DecoratedProcedure } from "../procedure-decorated.js";
|
|
3
|
+
// src/extensions/callable.ts
|
|
3
4
|
DecoratedProcedure.prototype.callable = function callable(...rest) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
const callable = createProcedureClient(this, ...rest);
|
|
6
|
+
callable["~orpc"] = this["~orpc"];
|
|
7
|
+
return callable;
|
|
7
8
|
};
|
|
@@ -28,4 +28,4 @@ export declare function encodeBase64url(data: Uint8Array): string;
|
|
|
28
28
|
*
|
|
29
29
|
* @see {@link https://orpc.dev/docs/helpers/base64url | Base64Url Helpers}
|
|
30
30
|
*/
|
|
31
|
-
export declare function decodeBase64url(base64url: string | undefined | null): Uint8Array<ArrayBuffer> | undefined;
|
|
31
|
+
export declare function decodeBase64url(base64url: string | undefined | null): Uint8Array<ArrayBuffer> | undefined;
|
|
@@ -1,53 +1,48 @@
|
|
|
1
|
-
import { encodeBase64 } from
|
|
1
|
+
import { encodeBase64 } from "@orpc/shared";
|
|
2
|
+
// src/helpers/base64url.ts
|
|
2
3
|
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
4
|
+
* Encodes a Uint8Array to base64url format
|
|
5
|
+
* Base64url is URL-safe and doesn't use padding
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* const text = "Hello World"
|
|
10
|
+
* const encoded = encodeBase64url(new TextEncoder().encode(text))
|
|
11
|
+
* const decoded = decodeBase64url(encoded)
|
|
12
|
+
* expect(new TextDecoder().decode(decoded)).toEqual(text)
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* @see {@link https://orpc.dev/docs/helpers/base64url | Base64Url Helpers}
|
|
16
|
+
*/
|
|
17
|
+
function encodeBase64url(data) {
|
|
18
|
+
return encodeBase64(data).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
|
18
19
|
}
|
|
19
20
|
/**
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
bytes[i] = binaryString.charCodeAt(i);
|
|
47
|
-
}
|
|
48
|
-
return encodeBase64url(bytes) === base64url ? bytes : undefined;
|
|
49
|
-
}
|
|
50
|
-
catch {
|
|
51
|
-
return undefined;
|
|
52
|
-
}
|
|
21
|
+
* Decodes a base64url string to Uint8Array
|
|
22
|
+
* Only accepts canonical, unpadded base64url (the form produced by `encodeBase64url`),
|
|
23
|
+
* returns undefined for anything else, including padded or standard base64 input
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* const text = "Hello World"
|
|
28
|
+
* const encoded = encodeBase64url(new TextEncoder().encode(text))
|
|
29
|
+
* const decoded = decodeBase64url(encoded)
|
|
30
|
+
* expect(new TextDecoder().decode(decoded)).toEqual(text)
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @see {@link https://orpc.dev/docs/helpers/base64url | Base64Url Helpers}
|
|
34
|
+
*/
|
|
35
|
+
function decodeBase64url(base64url) {
|
|
36
|
+
try {
|
|
37
|
+
if (typeof base64url !== "string") return;
|
|
38
|
+
let base64 = base64url.replace(/-/g, "+").replace(/_/g, "/");
|
|
39
|
+
while (base64.length % 4) base64 += "=";
|
|
40
|
+
const binaryString = atob(base64);
|
|
41
|
+
const bytes = new Uint8Array(binaryString.length);
|
|
42
|
+
for (let i = 0; i < binaryString.length; i++) bytes[i] = binaryString.charCodeAt(i);
|
|
43
|
+
return encodeBase64url(bytes) === base64url ? bytes : void 0;
|
|
44
|
+
} catch {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
53
47
|
}
|
|
48
|
+
export { decodeBase64url, encodeBase64url };
|
package/dist/helpers/cookie.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
export interface SetCookieOptions extends Omit<SetCookie,
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { ParseOptions, SetCookie, StringifyOptions } from "cookie";
|
|
2
|
+
export interface SetCookieOptions extends Omit<SetCookie, "name" | "value">, StringifyOptions {
|
|
3
|
+
/**
|
|
4
|
+
* Specifies the value for the [`Path` `Set-Cookie` attribute](https://tools.ietf.org/html/rfc6265#section-5.2.4).
|
|
5
|
+
*
|
|
6
|
+
* @default '/'
|
|
7
|
+
*/
|
|
8
|
+
path?: string;
|
|
9
9
|
}
|
|
10
10
|
/**
|
|
11
11
|
* Sets a cookie in the response headers.
|
|
@@ -24,8 +24,7 @@ export interface SetCookieOptions extends Omit<SetCookie, 'name' | 'value'>, Str
|
|
|
24
24
|
* @see {@link https://orpc.dev/docs/helpers/cookie | Cookie Helpers}
|
|
25
25
|
*/
|
|
26
26
|
export declare function setCookie(headers: Headers | undefined, name: string, value: string, options?: SetCookieOptions): void;
|
|
27
|
-
export interface GetCookieOptions extends ParseOptions {
|
|
28
|
-
}
|
|
27
|
+
export interface GetCookieOptions extends ParseOptions {}
|
|
29
28
|
/**
|
|
30
29
|
* Gets a cookie value from request headers
|
|
31
30
|
*
|
|
@@ -48,4 +47,4 @@ export declare function getCookie(headers: Headers | undefined, name: string, op
|
|
|
48
47
|
*
|
|
49
48
|
* @see {@link https://orpc.dev/docs/helpers/cookie | Cookie Helpers}
|
|
50
49
|
*/
|
|
51
|
-
export declare function deleteCookie(headers: Headers | undefined, name: string, options?: Omit<SetCookieOptions,
|
|
50
|
+
export declare function deleteCookie(headers: Headers | undefined, name: string, options?: Omit<SetCookieOptions, "maxAge">): void;
|