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