@temporary-name/server 1.9.3-alpha.03f5d40e5b399f85012c2fb4e98167e26d551d36 → 1.9.3-alpha.0489b23089852dc674460c2b1311b592746e58e1

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 (42) hide show
  1. package/dist/adapters/aws-lambda/index.d.mts +4 -6
  2. package/dist/adapters/aws-lambda/index.d.ts +4 -6
  3. package/dist/adapters/aws-lambda/index.mjs +4 -4
  4. package/dist/adapters/fetch/index.d.mts +8 -86
  5. package/dist/adapters/fetch/index.d.ts +8 -86
  6. package/dist/adapters/fetch/index.mjs +16 -155
  7. package/dist/adapters/node/index.d.mts +8 -63
  8. package/dist/adapters/node/index.d.ts +8 -63
  9. package/dist/adapters/node/index.mjs +14 -120
  10. package/dist/adapters/standard/index.d.mts +10 -7
  11. package/dist/adapters/standard/index.d.ts +10 -7
  12. package/dist/adapters/standard/index.mjs +4 -4
  13. package/dist/helpers/index.mjs +3 -29
  14. package/dist/index.d.mts +121 -258
  15. package/dist/index.d.ts +121 -258
  16. package/dist/index.mjs +168 -359
  17. package/dist/openapi/index.d.mts +12 -28
  18. package/dist/openapi/index.d.ts +12 -28
  19. package/dist/openapi/index.mjs +134 -152
  20. package/dist/shared/server.B0LJ_wu-.d.ts +41 -0
  21. package/dist/shared/server.BQZMQrPe.d.mts +41 -0
  22. package/dist/shared/server.C1RJffw4.mjs +30 -0
  23. package/dist/shared/server.CQIFwyhc.mjs +40 -0
  24. package/dist/shared/server.CYa9puL2.mjs +403 -0
  25. package/dist/shared/server.ChOv1yG3.mjs +319 -0
  26. package/dist/shared/server.Cza0RB3u.mjs +160 -0
  27. package/dist/shared/server.DXPMDozZ.d.mts +388 -0
  28. package/dist/shared/server.DXPMDozZ.d.ts +388 -0
  29. package/dist/shared/server.YUvuxHty.mjs +48 -0
  30. package/package.json +10 -28
  31. package/dist/plugins/index.d.mts +0 -160
  32. package/dist/plugins/index.d.ts +0 -160
  33. package/dist/plugins/index.mjs +0 -288
  34. package/dist/shared/server.BEHw7Eyx.mjs +0 -247
  35. package/dist/shared/server.BVxcyR6X.mjs +0 -287
  36. package/dist/shared/server.Bk5r0-2R.d.ts +0 -56
  37. package/dist/shared/server.Bs6ka_UE.d.mts +0 -23
  38. package/dist/shared/server.CZNLCQBm.d.mts +0 -192
  39. package/dist/shared/server.CZNLCQBm.d.ts +0 -192
  40. package/dist/shared/server.CbLTWfgn.d.mts +0 -56
  41. package/dist/shared/server.D2UFMrxf.d.ts +0 -23
  42. package/dist/shared/server.DcfsPloY.mjs +0 -202
package/dist/index.mjs CHANGED
@@ -1,50 +1,75 @@
1
- import { onError, resolveMaybeOptionalOptions } from '@temporary-name/shared';
2
- export { AsyncIteratorClass, EventPublisher, ORPCError, asyncIteratorToStream as eventIteratorToStream, isDefinedError, onError, onFinish, onStart, onSuccess, safe, streamToAsyncIteratorClass as streamToEventIterator } from '@temporary-name/shared';
3
- import { isContractProcedure, mergePrefix, mergeErrorMap, enhanceRoute, mergeTags, ContractProcedure, mergeMeta, mergeRoute, prefixRoute, getContractRouter } from '@temporary-name/contract';
4
- export { ValidationError, eventIterator, validateORPCError } from '@temporary-name/contract';
5
- import { SchemaClass, gatingContext } from '@temporary-name/zod';
6
- import { c as createProcedureClient, i as isLazy, g as getLazyMeta, l as lazy, u as unlazy } from './shared/server.DcfsPloY.mjs';
7
- export { L as LAZY_SYMBOL, a as createORPCErrorConstructorMap, m as mergeCurrentContext, b as middlewareOutputFn } from './shared/server.DcfsPloY.mjs';
1
+ import { assertNever, splitFirst, ORPCError, onError, resolveMaybeOptionalOptions, isTypescriptObject, isPropertyKey } from '@temporary-name/shared';
2
+ export { AsyncIteratorClass, EventPublisher, ORPCError, asyncIteratorToStream as eventIteratorToStream, isDefinedError, onError, onFinish, onStart, onSuccess, streamToAsyncIteratorClass as streamToEventIterator } from '@temporary-name/shared';
3
+ import * as z from '@temporary-name/zod';
4
+ import { SchemaClass, object, core, gatingContext } from '@temporary-name/zod';
5
+ import { g as getCookie } from './shared/server.C1RJffw4.mjs';
6
+ import { P as Procedure, m as mergePrefix, a as mergeTags, e as enhanceRouter, C as Contract, p as parseEndpointDefinition, b as mergeRoute, c as prefixRoute, d as addMiddleware, l as lazyInternal, f as getLazyMeta, u as unlazy, i as isProcedure, h as isLazy, j as getRouter } from './shared/server.ChOv1yG3.mjs';
7
+ export { L as LAZY_SYMBOL, V as ValidationError, q as createAccessibleLazyRouter, w as endpointRegex, g as getDynamicParams, n as isStartWithMiddlewares, k as lazy, o as mergeMiddlewares, r as resolveContractProcedures, s as standardizeHTTPPath, t as traverseContractProcedures, v as unlazyRouter } from './shared/server.ChOv1yG3.mjs';
8
+ import { c as createProcedureClient } from './shared/server.Cza0RB3u.mjs';
9
+ export { m as mergeCurrentContext, a as middlewareOutputFn } from './shared/server.Cza0RB3u.mjs';
10
+ export { e as eventIterator, g as getEventIteratorSchemaDetails } from './shared/server.YUvuxHty.mjs';
8
11
  export { getEventMeta, withEventMeta } from '@temporary-name/standard-server';
12
+ import 'cookie';
9
13
 
10
- function isStartWithMiddlewares(middlewares, compare) {
11
- if (compare.length > middlewares.length) {
12
- return false;
14
+ function validateTokenPrefix(prefix, token) {
15
+ if (prefix && !token.startsWith(prefix)) {
16
+ throw new ORPCError("UNAUTHORIZED", { message: `Invalid auth token. It must start with "${prefix}"` });
13
17
  }
14
- for (let i = 0; i < middlewares.length; i++) {
15
- if (compare[i] === void 0) {
16
- return true;
18
+ }
19
+ function validateTokenAuth(config, token, options) {
20
+ const { tokenPrefix, validate } = config;
21
+ validateTokenPrefix(tokenPrefix, token);
22
+ return validate(token, options);
23
+ }
24
+ function runAuth(config, options) {
25
+ switch (config.type) {
26
+ case "header": {
27
+ const authHeader = options.request.headers.get(config.name);
28
+ return authHeader ? validateTokenAuth(config, authHeader, options) : void 0;
29
+ }
30
+ case "query": {
31
+ const { name, tokenPrefix, validate } = config;
32
+ const query = options.request.url.searchParams;
33
+ const token = query.get(name);
34
+ if (!token) return void 0;
35
+ validateTokenPrefix(tokenPrefix, token);
36
+ return validate(token, options);
37
+ }
38
+ case "cookie": {
39
+ const cookie = getCookie(options.request.headers, config.name);
40
+ return cookie ? validateTokenAuth(config, cookie, options) : void 0;
17
41
  }
18
- if (middlewares[i] !== compare[i]) {
42
+ case "bearer": {
43
+ const authHeader = options.request.headers.get("Authorization");
44
+ if (!authHeader) return void 0;
45
+ const [authType, bearer] = splitFirst(authHeader, " ");
46
+ return authType === "Bearer" ? validateTokenAuth(config, bearer, options) : void 0;
47
+ }
48
+ case "basic": {
49
+ const authHeader = options.request.headers.get("Authorization");
50
+ if (!authHeader) return void 0;
51
+ const [authType, encoded] = splitFirst(authHeader, " ");
52
+ if (authType !== "Basic") return void 0;
53
+ const decoded = Buffer.from(encoded, "base64").toString("utf-8");
54
+ const [username, password] = splitFirst(decoded, ":");
55
+ validateTokenPrefix(config.tokenPrefix, password);
56
+ return config.validate(username, password, options);
57
+ }
58
+ case "none": {
19
59
  return false;
20
60
  }
61
+ default: {
62
+ assertNever(config);
63
+ }
21
64
  }
22
- return true;
23
- }
24
- function mergeMiddlewares(first, second, options) {
25
- if (options.dedupeLeading && isStartWithMiddlewares(second, first)) {
26
- return second;
27
- }
28
- return [...first, ...second];
29
65
  }
30
- function addMiddleware(middlewares, addition) {
31
- return [...middlewares, addition];
66
+ function authDescription(config) {
67
+ const { type } = config;
68
+ return type === "basic" ? "a Basic Authentication header" : type === "bearer" ? "a Bearer Authentication header" : type === "header" ? `a header named "${config.name}"` : type === "query" ? `a query parameter named "${config.name}"` : type === "cookie" ? `a cookie named "${config.name}"` : type === "none" ? "no authentication" : assertNever(type);
32
69
  }
33
70
 
34
- class Procedure {
35
- /**
36
- * This property holds the defined options.
37
- */
38
- "~orpc";
39
- constructor(def) {
40
- this["~orpc"] = def;
41
- }
42
- }
43
- function isProcedure(item) {
44
- if (item instanceof Procedure) {
45
- return true;
46
- }
47
- return isContractProcedure(item) && "middlewares" in item["~orpc"] && "handler" in item["~orpc"];
71
+ function mergeMeta(meta1, meta2) {
72
+ return { ...meta1, ...meta2 };
48
73
  }
49
74
 
50
75
  class DecoratedProcedure extends Procedure {
@@ -66,170 +91,19 @@ class DecoratedProcedure extends Procedure {
66
91
  }
67
92
  }
68
93
 
69
- const HIDDEN_ROUTER_CONTRACT_SYMBOL = Symbol("ORPC_HIDDEN_ROUTER_CONTRACT");
70
- function setHiddenRouterContract(router, contract) {
71
- return new Proxy(router, {
72
- get(target, key) {
73
- if (key === HIDDEN_ROUTER_CONTRACT_SYMBOL) {
74
- return contract;
75
- }
76
- return Reflect.get(target, key);
77
- }
78
- });
79
- }
80
- function getHiddenRouterContract(router) {
81
- return router[HIDDEN_ROUTER_CONTRACT_SYMBOL];
82
- }
94
+ const initialSchemas = {
95
+ pathSchema: z.strictObject({}),
96
+ querySchema: z.strictObject({}),
97
+ bodySchema: z.strictObject({}),
98
+ outputSchema: z.unknown()
99
+ };
83
100
 
84
- function getRouter(router, path) {
85
- let current = router;
86
- for (let i = 0; i < path.length; i++) {
87
- const segment = path[i];
88
- if (!current) {
89
- return void 0;
90
- }
91
- if (isProcedure(current)) {
92
- return void 0;
93
- }
94
- if (!isLazy(current)) {
95
- current = current[segment];
96
- continue;
97
- }
98
- const lazied = current;
99
- const rest = path.slice(i);
100
- return lazy(async () => {
101
- const unwrapped = await unlazy(lazied);
102
- const next = getRouter(unwrapped.default, rest);
103
- return unlazy(next);
104
- }, getLazyMeta(lazied));
105
- }
106
- return current;
107
- }
108
- function createAccessibleLazyRouter(lazied) {
109
- const recursive = new Proxy(lazied, {
110
- get(target, key) {
111
- if (typeof key !== "string") {
112
- return Reflect.get(target, key);
113
- }
114
- const next = getRouter(lazied, [key]);
115
- return createAccessibleLazyRouter(next);
116
- }
117
- });
118
- return recursive;
119
- }
120
- function enhanceRouter(router, options) {
121
- if (isLazy(router)) {
122
- const laziedMeta = getLazyMeta(router);
123
- const enhancedPrefix = laziedMeta?.prefix ? mergePrefix(options.prefix, laziedMeta?.prefix) : options.prefix;
124
- const enhanced2 = lazy(
125
- async () => {
126
- const { default: unlaziedRouter } = await unlazy(router);
127
- const enhanced3 = enhanceRouter(unlaziedRouter, options);
128
- return unlazy(enhanced3);
129
- },
130
- {
131
- ...laziedMeta,
132
- prefix: enhancedPrefix
133
- }
134
- );
135
- const accessible = createAccessibleLazyRouter(enhanced2);
136
- return accessible;
137
- }
138
- if (isProcedure(router)) {
139
- const newMiddlewares = mergeMiddlewares(options.middlewares, router["~orpc"].middlewares, {
140
- dedupeLeading: options.dedupeLeadingMiddlewares
141
- });
142
- const newMiddlewareAdded = newMiddlewares.length - router["~orpc"].middlewares.length;
143
- const enhanced2 = new Procedure({
144
- ...router["~orpc"],
145
- route: enhanceRoute(router["~orpc"].route, options),
146
- errorMap: mergeErrorMap(options.errorMap, router["~orpc"].errorMap),
147
- middlewares: newMiddlewares,
148
- inputValidationIndex: router["~orpc"].inputValidationIndex + newMiddlewareAdded,
149
- outputValidationIndex: router["~orpc"].outputValidationIndex + newMiddlewareAdded
150
- });
151
- return enhanced2;
152
- }
153
- const enhanced = {};
154
- for (const key in router) {
155
- enhanced[key] = enhanceRouter(router[key], options);
156
- }
157
- return enhanced;
158
- }
159
- function traverseContractProcedures(options, callback, lazyOptions = []) {
160
- let currentRouter = options.router;
161
- const hiddenContract = getHiddenRouterContract(options.router);
162
- if (hiddenContract !== void 0) {
163
- currentRouter = hiddenContract;
164
- }
165
- if (isLazy(currentRouter)) {
166
- lazyOptions.push({
167
- router: currentRouter,
168
- path: options.path
169
- });
170
- } else if (isContractProcedure(currentRouter)) {
171
- callback({
172
- contract: currentRouter,
173
- path: options.path
174
- });
175
- } else {
176
- for (const key in currentRouter) {
177
- traverseContractProcedures(
178
- {
179
- router: currentRouter[key],
180
- path: [...options.path, key]
181
- },
182
- callback,
183
- lazyOptions
184
- );
185
- }
186
- }
187
- return lazyOptions;
188
- }
189
- async function resolveContractProcedures(options, callback) {
190
- const pending = [options];
191
- for (const options2 of pending) {
192
- const lazyOptions = traverseContractProcedures(options2, callback);
193
- for (const options3 of lazyOptions) {
194
- const { default: router } = await unlazy(options3.router);
195
- pending.push({
196
- router,
197
- path: options3.path
198
- });
199
- }
200
- }
201
- }
202
- async function unlazyRouter(router) {
203
- if (isProcedure(router)) {
204
- return router;
205
- }
206
- const unlazied = {};
207
- for (const key in router) {
208
- const item = router[key];
209
- const { default: unlaziedRouter } = await unlazy(item);
210
- unlazied[key] = await unlazyRouter(unlaziedRouter);
211
- }
212
- return unlazied;
213
- }
214
-
215
- class ProcedureBuilder extends ContractProcedure {
101
+ class ProcedureBuilder extends Contract {
216
102
  z;
217
103
  constructor(def) {
218
104
  super(def);
219
105
  this.z = new SchemaClass();
220
106
  }
221
- /**
222
- * Adds type-safe custom errors to the contract.
223
- * The provided errors are spared-merged with any existing errors in the contract.
224
- *
225
- * @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
226
- */
227
- errors(errors) {
228
- return new ProcedureBuilder({
229
- ...this["~orpc"],
230
- errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
231
- });
232
- }
233
107
  /**
234
108
  * Sets or updates the metadata for the contract.
235
109
  * The provided metadata is spared-merged with any existing metadata in the contract.
@@ -242,6 +116,19 @@ class ProcedureBuilder extends ContractProcedure {
242
116
  meta: mergeMeta(this["~orpc"].meta, meta)
243
117
  });
244
118
  }
119
+ endpoint(stringsOrEndpoint, ...values) {
120
+ const { method, path, pathSchema } = parseEndpointDefinition(stringsOrEndpoint, values);
121
+ const { prefix } = this["~orpc"];
122
+ const route = { method, path };
123
+ return new ProcedureBuilder({
124
+ ...this["~orpc"],
125
+ route: mergeRoute(this["~orpc"].route, prefix ? prefixRoute(route, prefix) : route),
126
+ schemas: {
127
+ ...this["~orpc"].schemas,
128
+ pathSchema
129
+ }
130
+ });
131
+ }
245
132
  /**
246
133
  * Sets or updates the route definition for the contract.
247
134
  * The provided route is spared-merged with any existing route in the contract.
@@ -250,22 +137,30 @@ class ProcedureBuilder extends ContractProcedure {
250
137
  * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
251
138
  * @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
252
139
  */
253
- route(route) {
140
+ endpointOpts(route) {
254
141
  const { prefix } = this["~orpc"];
255
142
  return new ProcedureBuilder({
256
143
  ...this["~orpc"],
257
144
  route: mergeRoute(this["~orpc"].route, prefix ? prefixRoute(route, prefix) : route)
258
145
  });
259
146
  }
260
- /**
261
- * Defines the input validation schema.
262
- *
263
- * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
264
- */
265
- input(schema) {
147
+ query(schema) {
266
148
  return new ProcedureBuilder({
267
149
  ...this["~orpc"],
268
- inputSchema: schema,
150
+ schemas: {
151
+ ...this["~orpc"].schemas,
152
+ querySchema: schema instanceof core.$ZodType ? schema : object(schema)
153
+ },
154
+ inputValidationIndex: this["~orpc"].middlewares.length
155
+ });
156
+ }
157
+ body(schema) {
158
+ return new ProcedureBuilder({
159
+ ...this["~orpc"],
160
+ schemas: {
161
+ ...this["~orpc"].schemas,
162
+ bodySchema: schema instanceof core.$ZodType ? schema : object(schema)
163
+ },
269
164
  inputValidationIndex: this["~orpc"].middlewares.length
270
165
  });
271
166
  }
@@ -277,23 +172,47 @@ class ProcedureBuilder extends ContractProcedure {
277
172
  output(schema) {
278
173
  return new ProcedureBuilder({
279
174
  ...this["~orpc"],
280
- outputSchema: schema,
175
+ schemas: {
176
+ ...this["~orpc"].schemas,
177
+ outputSchema: schema instanceof core.$ZodType ? schema : object(schema)
178
+ },
281
179
  outputValidationIndex: this["~orpc"].middlewares.length
282
180
  });
283
181
  }
284
- /**
285
- * Uses a middleware to modify the context or improve the pipeline.
286
- *
287
- * @info Supports both normal middleware and inline middleware implementations.
288
- * @note The current context must be satisfy middleware dependent-context
289
- * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
290
- */
291
182
  use(middleware) {
292
183
  return new this.constructor({
293
184
  ...this["~orpc"],
294
185
  middlewares: addMiddleware(this["~orpc"].middlewares, middleware)
295
186
  });
296
187
  }
188
+ // The default of false for ValidatedAuthContext is used when you pass in the type 'none'. We use false
189
+ // because we can't use null or undefined (see ValidatedAuthContext) but we still want it to be falsy.
190
+ useAuth(config) {
191
+ const middleware = baseApi.$context().middleware(async (options) => {
192
+ const { next, context } = options;
193
+ if (context.auth) return next();
194
+ const auth = await runAuth(config, options);
195
+ if (auth === void 0) {
196
+ const { authConfigs } = options.procedure["~orpc"];
197
+ if (context.auth !== false && config === authConfigs.at(-1)) {
198
+ let authDescriptions = authConfigs.map(authDescription).join(", ");
199
+ if (authConfigs.length > 1) {
200
+ authDescriptions = `one of: ${authDescriptions}`;
201
+ }
202
+ throw new ORPCError("UNAUTHORIZED", {
203
+ message: `Authentication required. You must provide ${authDescriptions}`
204
+ });
205
+ }
206
+ return next();
207
+ }
208
+ return next({ context: { auth } });
209
+ });
210
+ return new this.constructor({
211
+ ...this["~orpc"],
212
+ authConfigs: [...this["~orpc"].authConfigs, config],
213
+ middlewares: addMiddleware(this["~orpc"].middlewares, middleware)
214
+ });
215
+ }
297
216
  useGating(gates, isGateEnabled) {
298
217
  return this.use(({ next, context }) => {
299
218
  return gatingContext.run(
@@ -308,6 +227,9 @@ class ProcedureBuilder extends ContractProcedure {
308
227
  * @see {@link https://orpc.unnoq.com/docs/procedure Procedure Docs}
309
228
  */
310
229
  handler(handler) {
230
+ if (this["~orpc"].schemas.outputSchema === initialSchemas.outputSchema) {
231
+ throw new Error("You must call .output() before calling .handler()");
232
+ }
311
233
  return new DecoratedProcedure({
312
234
  ...this["~orpc"],
313
235
  handler
@@ -349,16 +271,6 @@ class BuilderWithMiddlewares extends ProcedureBuilder {
349
271
  router(router) {
350
272
  return enhanceRouter(router, this["~orpc"]);
351
273
  }
352
- /**
353
- * Create a lazy router
354
- * And applies all of the previously defined options to the specified router.
355
- *
356
- * @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
357
- */
358
- lazyRoute(loader) {
359
- const lazied = lazy(loader);
360
- return enhanceRouter(lazied, this["~orpc"]);
361
- }
362
274
  }
363
275
 
364
276
  function decorateMiddleware(middleware) {
@@ -369,31 +281,6 @@ function decorateMiddleware(middleware) {
369
281
  );
370
282
  return mapped;
371
283
  };
372
- decorated.concat = (concatMiddleware, mapInput) => {
373
- const mapped = mapInput ? decorateMiddleware(concatMiddleware).mapInput(mapInput) : concatMiddleware;
374
- const concatted = decorateMiddleware((options, input, output, ...rest) => {
375
- const merged = middleware(
376
- {
377
- ...options,
378
- next: (...[nextOptions1]) => mapped(
379
- {
380
- ...options,
381
- context: { ...options.context, ...nextOptions1?.context },
382
- next: (...[nextOptions2]) => options.next({ context: { ...nextOptions1?.context, ...nextOptions2?.context } })
383
- },
384
- input,
385
- output,
386
- ...rest
387
- )
388
- },
389
- input,
390
- output,
391
- ...rest
392
- );
393
- return merged;
394
- });
395
- return concatted;
396
- };
397
284
  return decorated;
398
285
  }
399
286
 
@@ -415,112 +302,25 @@ class Builder extends BuilderWithMiddlewares {
415
302
  return decorateMiddleware(middleware);
416
303
  }
417
304
  }
418
- function createApiBuilder(opts = {}) {
419
- return new Builder({
420
- route: {},
421
- meta: opts.meta ?? {},
422
- errorMap: {},
423
- inputValidationIndex: 0,
424
- outputValidationIndex: 0,
425
- middlewares: [
426
- onError((error, _options) => {
427
- console.dir(error, { depth: null });
428
- })
429
- ],
430
- // NB: this is a relic from orpc -- I'm not convinced there's a need for this (or if there is, that it's
431
- // the best solution). For now I've removed the interface to configure it externally.
432
- dedupeLeadingMiddlewares: true
433
- });
434
- }
435
- const os = createApiBuilder();
436
-
437
- function implementerInternal(contract, middlewares) {
438
- if (isContractProcedure(contract)) {
439
- const impl2 = new Builder({
440
- ...contract["~orpc"],
441
- middlewares,
442
- inputValidationIndex: middlewares.length,
443
- outputValidationIndex: middlewares.length,
444
- dedupeLeadingMiddlewares: true
445
- });
446
- return impl2;
447
- }
448
- const impl = new Proxy(contract, {
449
- get: (target, key) => {
450
- if (typeof key !== "string") {
451
- return Reflect.get(target, key);
452
- }
453
- let method;
454
- if (key === "middleware") {
455
- method = (mid) => decorateMiddleware(mid);
456
- } else if (key === "use") {
457
- method = (mid) => {
458
- return implementerInternal(contract, addMiddleware(middlewares, mid));
459
- };
460
- } else if (key === "router") {
461
- method = (router) => {
462
- const adapted = enhanceRouter(router, {
463
- middlewares,
464
- errorMap: {},
465
- prefix: void 0,
466
- tags: void 0,
467
- dedupeLeadingMiddlewares: true
468
- });
469
- return setHiddenRouterContract(adapted, contract);
470
- };
471
- } else if (key === "lazyRoute") {
472
- method = (loader) => {
473
- const adapted = enhanceRouter(lazy(loader), {
474
- middlewares,
475
- errorMap: {},
476
- prefix: void 0,
477
- tags: void 0,
478
- dedupeLeadingMiddlewares: true
479
- });
480
- return setHiddenRouterContract(adapted, contract);
481
- };
482
- }
483
- const next = getContractRouter(target, [key]);
484
- if (!next) {
485
- return method ?? next;
486
- }
487
- const nextImpl = implementerInternal(next, middlewares);
488
- if (method) {
489
- return new Proxy(method, {
490
- get(_, key2) {
491
- return Reflect.get(nextImpl, key2);
492
- }
493
- });
494
- }
495
- return nextImpl;
496
- }
497
- });
498
- return impl;
499
- }
500
- function implement(contract) {
501
- const implInternal = implementerInternal(contract, []);
502
- const impl = new Proxy(implInternal, {
503
- get: (target, key) => {
504
- let method;
505
- if (key === "$context") {
506
- method = () => impl;
507
- }
508
- const next = Reflect.get(target, key);
509
- if (!method || !next || typeof next !== "function" && typeof next !== "object") {
510
- return method || next;
511
- }
512
- return new Proxy(method, {
513
- get(_, key2) {
514
- return Reflect.get(next, key2);
515
- }
516
- });
517
- }
518
- });
519
- return impl;
520
- }
305
+ const baseApi = new Builder({
306
+ route: {},
307
+ meta: {},
308
+ inputValidationIndex: 0,
309
+ outputValidationIndex: 0,
310
+ middlewares: [
311
+ onError((error, _options) => {
312
+ console.dir(error, { depth: null });
313
+ })
314
+ ],
315
+ schemas: initialSchemas,
316
+ // NB: this is a relic from orpc -- I'm not convinced there's a need for this (or if there is, that it's
317
+ // the best solution). For now I've removed the interface to configure it externally.
318
+ dedupeLeadingMiddlewares: true,
319
+ authConfigs: []
320
+ });
521
321
 
522
322
  function createAssertedLazyProcedure(lazied) {
523
- const lazyProcedure = lazy(async () => {
323
+ const lazyProcedure = lazyInternal(async () => {
524
324
  const { default: maybeProcedure } = await unlazy(lazied);
525
325
  if (!isProcedure(maybeProcedure)) {
526
326
  throw new Error(`
@@ -533,14 +333,6 @@ function createAssertedLazyProcedure(lazied) {
533
333
  }, getLazyMeta(lazied));
534
334
  return lazyProcedure;
535
335
  }
536
- function createContractedProcedure(procedure, contract) {
537
- return new Procedure({
538
- ...procedure["~orpc"],
539
- errorMap: contract["~orpc"].errorMap,
540
- route: contract["~orpc"].route,
541
- meta: contract["~orpc"].meta
542
- });
543
- }
544
336
  function call(procedure, input, ...rest) {
545
337
  const options = resolveMaybeOptionalOptions(rest);
546
338
  return createProcedureClient(procedure, options)(input, options);
@@ -571,4 +363,21 @@ function createRouterClient(router, ...rest) {
571
363
  return recursive;
572
364
  }
573
365
 
574
- export { Builder, BuilderWithMiddlewares, DecoratedProcedure, Procedure, ProcedureBuilder, addMiddleware, call, createAccessibleLazyRouter, createApiBuilder, createAssertedLazyProcedure, createContractedProcedure, createProcedureClient, createRouterClient, decorateMiddleware, enhanceRouter, getHiddenRouterContract, getLazyMeta, getRouter, implement, implementerInternal, isLazy, isProcedure, isStartWithMiddlewares, lazy, mergeMiddlewares, os, resolveContractProcedures, setHiddenRouterContract, traverseContractProcedures, unlazy, unlazyRouter };
366
+ function isSchemaIssue(issue) {
367
+ if (!isTypescriptObject(issue) || typeof issue.message !== "string") {
368
+ return false;
369
+ }
370
+ if (issue.path !== void 0) {
371
+ if (!Array.isArray(issue.path)) {
372
+ return false;
373
+ }
374
+ if (!issue.path.every(
375
+ (segment) => isPropertyKey(segment) || isTypescriptObject(segment) && isPropertyKey(segment.key)
376
+ )) {
377
+ return false;
378
+ }
379
+ }
380
+ return true;
381
+ }
382
+
383
+ export { Builder, BuilderWithMiddlewares, Contract, DecoratedProcedure, Procedure, ProcedureBuilder, addMiddleware, baseApi, call, createAssertedLazyProcedure, createProcedureClient, createRouterClient, decorateMiddleware, enhanceRouter, getLazyMeta, getRouter, initialSchemas, isLazy, isProcedure, isSchemaIssue, lazyInternal, mergeMeta, parseEndpointDefinition, unlazy };