@temporary-name/server 1.9.3-alpha.26612c2cf6a7177d2b500d984d282309d8320ca3 → 1.9.3-alpha.2957dbc009ec31fa21575f028b83c96651cba827

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 (39) hide show
  1. package/dist/adapters/aws-lambda/index.d.mts +3 -5
  2. package/dist/adapters/aws-lambda/index.d.ts +3 -5
  3. package/dist/adapters/aws-lambda/index.mjs +3 -3
  4. package/dist/adapters/fetch/index.d.mts +7 -85
  5. package/dist/adapters/fetch/index.d.ts +7 -85
  6. package/dist/adapters/fetch/index.mjs +15 -154
  7. package/dist/adapters/node/index.d.mts +7 -62
  8. package/dist/adapters/node/index.d.ts +7 -62
  9. package/dist/adapters/node/index.mjs +13 -119
  10. package/dist/adapters/standard/index.d.mts +9 -6
  11. package/dist/adapters/standard/index.d.ts +9 -6
  12. package/dist/adapters/standard/index.mjs +4 -4
  13. package/dist/helpers/index.mjs +3 -29
  14. package/dist/index.d.mts +72 -195
  15. package/dist/index.d.ts +72 -195
  16. package/dist/index.mjs +131 -114
  17. package/dist/openapi/index.d.mts +10 -27
  18. package/dist/openapi/index.d.ts +10 -27
  19. package/dist/openapi/index.mjs +57 -108
  20. package/dist/shared/{server.CjkiSCui.mjs → server.B7tjiDal.mjs} +73 -115
  21. package/dist/shared/server.C1RJffw4.mjs +30 -0
  22. package/dist/shared/server.CQIFwyhc.mjs +40 -0
  23. package/dist/shared/server.CpS0m3at.mjs +403 -0
  24. package/dist/shared/server.DPD7R7h_.d.mts +226 -0
  25. package/dist/shared/server.DPD7R7h_.d.ts +226 -0
  26. package/dist/shared/server.DfUs5c4R.d.ts +41 -0
  27. package/dist/shared/server.L8lRAYBR.d.mts +41 -0
  28. package/package.json +10 -27
  29. package/dist/plugins/index.d.mts +0 -160
  30. package/dist/plugins/index.d.ts +0 -160
  31. package/dist/plugins/index.mjs +0 -288
  32. package/dist/shared/server.BYnDyuDL.d.mts +0 -23
  33. package/dist/shared/server.BlJrjUA9.d.mts +0 -56
  34. package/dist/shared/server.C-tNYmY_.d.ts +0 -56
  35. package/dist/shared/server.DdHBdcen.mjs +0 -262
  36. package/dist/shared/server.JI4dqTgD.d.ts +0 -23
  37. package/dist/shared/server.Kxw442A9.mjs +0 -247
  38. package/dist/shared/server.WsFQIubj.d.mts +0 -235
  39. package/dist/shared/server.WsFQIubj.d.ts +0 -235
@@ -1,7 +1,7 @@
1
- import { isProcedure, resolveContractProcedures, ORPCError, createRouterClient } from '@temporary-name/server';
2
- import { fallbackContractConfig, getEventIteratorSchemaDetails } from '@temporary-name/contract';
3
- import { isObject, stringifyJSON, findDeepMatches, toArray, clone, value, toHttpPath, isORPCErrorStatus, fallbackORPCErrorStatus, fallbackORPCErrorMessage, resolveMaybeOptionalOptions, createORPCErrorFromJson } from '@temporary-name/shared';
4
- import { a as standardizeHTTPPath, j as jsonSerialize, g as getDynamicParams, d as deserialize, s as serialize } from '../shared/server.Kxw442A9.mjs';
1
+ import { standardizeHTTPPath, fallbackContractConfig, getDynamicParams, getEventIteratorSchemaDetails } from '@temporary-name/contract';
2
+ import { resolveContractProcedures } from '@temporary-name/server';
3
+ import { isObject, stringifyJSON, findDeepMatches, toArray, clone, value, toHttpPath, isORPCErrorStatus } from '@temporary-name/shared';
4
+ import { j as jsonSerialize } from '../shared/server.CQIFwyhc.mjs';
5
5
  import '@temporary-name/standard-server';
6
6
  import { TypeName } from '@temporary-name/interop/json-schema-typed/draft-2020-12';
7
7
  export { ContentEncoding as JSONSchemaContentEncoding, Format as JSONSchemaFormat, TypeName as JSONSchemaTypeName } from '@temporary-name/interop/json-schema-typed/draft-2020-12';
@@ -22,20 +22,12 @@ function getCustomOpenAPIOperation(o) {
22
22
  }
23
23
  function applyCustomOpenAPIOperation(operation, contract) {
24
24
  const operationCustoms = [];
25
- for (const errorItem of Object.values(contract["~orpc"].errorMap)) {
26
- const maybeExtender = errorItem ? getCustomOpenAPIOperation(errorItem) : void 0;
25
+ for (const middleware of contract["~orpc"].middlewares) {
26
+ const maybeExtender = getCustomOpenAPIOperation(middleware);
27
27
  if (maybeExtender) {
28
28
  operationCustoms.push(maybeExtender);
29
29
  }
30
30
  }
31
- if (isProcedure(contract)) {
32
- for (const middleware of contract["~orpc"].middlewares) {
33
- const maybeExtender = getCustomOpenAPIOperation(middleware);
34
- if (maybeExtender) {
35
- operationCustoms.push(maybeExtender);
36
- }
37
- }
38
- }
39
31
  let currentOperation = operation;
40
32
  for (const custom of operationCustoms) {
41
33
  if (typeof custom === "function") {
@@ -432,12 +424,6 @@ class OpenAPIGenerator {
432
424
  };
433
425
  await this.#request(doc, operationObjectRef, def, baseSchemaConvertOptions);
434
426
  await this.#successResponse(doc, operationObjectRef, def, baseSchemaConvertOptions);
435
- await this.#errorResponse(
436
- operationObjectRef,
437
- def,
438
- baseSchemaConvertOptions,
439
- undefinedErrorJsonSchema
440
- );
441
427
  }
442
428
  if (typeof def.route.spec === "function") {
443
429
  operationObjectRef = def.route.spec(operationObjectRef);
@@ -530,60 +516,77 @@ ${errors.join("\n\n")}`
530
516
  }
531
517
  async #request(doc, ref, def, baseSchemaConvertOptions) {
532
518
  const method = fallbackContractConfig("defaultMethod", def.route.method);
533
- const details = getEventIteratorSchemaDetails(def.inputSchema);
534
- if (details) {
535
- ref.requestBody = {
536
- required: true,
537
- content: toOpenAPIEventIteratorContent(
538
- await this.converter.convert(details.yields, { ...baseSchemaConvertOptions, strategy: "input" }),
539
- await this.converter.convert(details.returns, { ...baseSchemaConvertOptions, strategy: "input" })
540
- )
541
- };
542
- return;
543
- }
544
519
  const dynamicParams = getDynamicParams(def.route.path)?.map((v) => v.name);
545
- let [required, schema] = await this.converter.convert(def.inputSchema, {
520
+ const [_pathRequired, pathSchema] = await this.converter.convert(def.schemas.pathSchema, {
546
521
  ...baseSchemaConvertOptions,
547
522
  strategy: "input",
548
- minStructureDepthForRef: dynamicParams?.length ? 1 : 0
523
+ minStructureDepthForRef: 1
549
524
  });
550
- if (isAnySchema(schema) && !dynamicParams?.length) {
551
- return;
552
- }
553
525
  if (dynamicParams?.length) {
554
526
  const error = new OpenAPIGeneratorError(
527
+ // TODO: fix this error
555
528
  'When input structure is "compact", and path has dynamic params, input schema must be an object with all dynamic params as required.'
556
529
  );
557
- if (!isObjectSchema(schema)) {
530
+ if (!isObjectSchema(pathSchema)) {
558
531
  throw error;
559
532
  }
560
- const [paramsSchema, rest] = separateObjectSchema(schema, dynamicParams);
561
- schema = rest;
562
- required = rest.required ? rest.required.length !== 0 : false;
563
- if (!checkParamsSchema(paramsSchema, dynamicParams)) {
533
+ if (!checkParamsSchema(pathSchema, dynamicParams)) {
564
534
  throw error;
565
535
  }
566
536
  ref.parameters ??= [];
567
- ref.parameters.push(...toOpenAPIParameters(paramsSchema, "path"));
537
+ ref.parameters.push(...toOpenAPIParameters(pathSchema, "path"));
538
+ } else {
539
+ const error = new OpenAPIGeneratorError("Params set via path do not match those on the route");
540
+ if (!isObjectSchema(pathSchema)) {
541
+ console.log("FOO", pathSchema);
542
+ throw error;
543
+ }
544
+ if (!checkParamsSchema(pathSchema, [])) {
545
+ console.log("BAR", pathSchema);
546
+ throw error;
547
+ }
568
548
  }
569
- if (method === "GET") {
570
- const resolvedSchema = resolveOpenAPIJsonSchemaRef(doc, schema);
549
+ const [_queryRequired, querySchema] = await this.converter.convert(def.schemas.querySchema, {
550
+ ...baseSchemaConvertOptions,
551
+ strategy: "input",
552
+ minStructureDepthForRef: 0
553
+ });
554
+ if (!isAnySchema(querySchema)) {
555
+ const resolvedSchema = resolveOpenAPIJsonSchemaRef(doc, querySchema);
571
556
  if (!isObjectSchema(resolvedSchema)) {
572
- throw new OpenAPIGeneratorError(
573
- 'When method is "GET", input schema must satisfy: object | any | unknown'
574
- );
557
+ throw new OpenAPIGeneratorError("Query param schema must satisfy: object | any | unknown");
575
558
  }
576
559
  ref.parameters ??= [];
577
560
  ref.parameters.push(...toOpenAPIParameters(resolvedSchema, "query"));
578
- } else {
579
- ref.requestBody = {
580
- required,
581
- content: toOpenAPIContent(schema)
582
- };
561
+ }
562
+ if (method !== "GET") {
563
+ const details = getEventIteratorSchemaDetails(def.schemas.bodySchema);
564
+ if (details) {
565
+ ref.requestBody = {
566
+ required: true,
567
+ content: toOpenAPIEventIteratorContent(
568
+ await this.converter.convert(details.yields, { ...baseSchemaConvertOptions, strategy: "input" }),
569
+ await this.converter.convert(details.returns, { ...baseSchemaConvertOptions, strategy: "input" })
570
+ )
571
+ };
572
+ } else {
573
+ const [bodyRequired, bodySchema] = await this.converter.convert(def.schemas.bodySchema, {
574
+ ...baseSchemaConvertOptions,
575
+ strategy: "input",
576
+ minStructureDepthForRef: 0
577
+ });
578
+ if (isAnySchema(bodySchema)) {
579
+ return;
580
+ }
581
+ ref.requestBody = {
582
+ required: bodyRequired,
583
+ content: toOpenAPIContent(bodySchema)
584
+ };
585
+ }
583
586
  }
584
587
  }
585
588
  async #successResponse(doc, ref, def, baseSchemaConvertOptions) {
586
- const outputSchema = def.outputSchema;
589
+ const outputSchema = def.schemas.outputSchema;
587
590
  const status = fallbackContractConfig("defaultSuccessStatus", def.route.successStatus);
588
591
  const description = fallbackContractConfig("defaultSuccessDescription", def.route?.successDescription);
589
592
  const eventIteratorSchemaDetails = getEventIteratorSchemaDetails(outputSchema);
@@ -679,64 +682,10 @@ ${errors.join("\n\n")}`
679
682
  }
680
683
  }
681
684
  }
682
- async #errorResponse(ref, def, baseSchemaConvertOptions, undefinedErrorSchema) {
683
- const errorMap = def.errorMap;
684
- const errors = {};
685
- for (const code in errorMap) {
686
- const config = errorMap[code];
687
- if (!config) {
688
- continue;
689
- }
690
- const status = fallbackORPCErrorStatus(code, config.status);
691
- const message = fallbackORPCErrorMessage(code, config.message);
692
- const [dataRequired, dataSchema] = await this.converter.convert(config.data, {
693
- ...baseSchemaConvertOptions,
694
- strategy: "output"
695
- });
696
- errors[status] ??= [];
697
- errors[status].push({
698
- type: "object",
699
- properties: {
700
- defined: { const: true },
701
- code: { const: code },
702
- status: { const: status },
703
- message: { type: "string", default: message },
704
- data: dataSchema
705
- },
706
- required: dataRequired ? ["defined", "code", "status", "message", "data"] : ["defined", "code", "status", "message"]
707
- });
708
- }
709
- ref.responses ??= {};
710
- for (const status in errors) {
711
- const schemas = errors[status];
712
- ref.responses[status] = {
713
- description: status,
714
- content: toOpenAPIContent({
715
- oneOf: [...schemas, undefinedErrorSchema]
716
- })
717
- };
718
- }
719
- }
720
- }
721
-
722
- function createJsonifiedRouterClient(router, ...rest) {
723
- const options = resolveMaybeOptionalOptions(rest);
724
- options.interceptors ??= [];
725
- options.interceptors.unshift(async (options2) => {
726
- try {
727
- return deserialize(serialize(await options2.next()));
728
- } catch (e) {
729
- if (e instanceof ORPCError) {
730
- throw createORPCErrorFromJson(deserialize(serialize(e.toJSON(), { outputFormat: "plain" })));
731
- }
732
- throw e;
733
- }
734
- });
735
- return createRouterClient(router, options);
736
685
  }
737
686
 
738
687
  const oo = {
739
688
  spec: customOpenAPIOperation
740
689
  };
741
690
 
742
- export { CompositeSchemaConverter, LOGIC_KEYWORDS, OpenAPIGenerator, applyCustomOpenAPIOperation, applySchemaOptionality, checkParamsSchema, createJsonifiedRouterClient, customOpenAPIOperation, expandArrayableSchema, expandUnionSchema, filterSchemaBranches, getCustomOpenAPIOperation, isAnySchema, isFileSchema, isObjectSchema, isPrimitiveSchema, oo, resolveOpenAPIJsonSchemaRef, separateObjectSchema, toOpenAPIContent, toOpenAPIEventIteratorContent, toOpenAPIMethod, toOpenAPIParameters, toOpenAPIPath, toOpenAPISchema };
691
+ export { CompositeSchemaConverter, LOGIC_KEYWORDS, OpenAPIGenerator, applyCustomOpenAPIOperation, applySchemaOptionality, checkParamsSchema, customOpenAPIOperation, expandArrayableSchema, expandUnionSchema, filterSchemaBranches, getCustomOpenAPIOperation, isAnySchema, isFileSchema, isObjectSchema, isPrimitiveSchema, oo, resolveOpenAPIJsonSchemaRef, separateObjectSchema, toOpenAPIContent, toOpenAPIEventIteratorContent, toOpenAPIMethod, toOpenAPIParameters, toOpenAPIPath, toOpenAPISchema };
@@ -1,7 +1,7 @@
1
- import { isContractProcedure, mergePrefix, mergeErrorMap, enhanceRoute, validateORPCError, ValidationError } from '@temporary-name/contract';
2
- import { resolveMaybeOptionalOptions, ORPCError, toArray, value, runWithSpan, intercept, isAsyncIteratorObject, overlayProxy, asyncIteratorWithSpan } from '@temporary-name/shared';
1
+ import { mergePrefix, enhanceRoute, ValidationError } from '@temporary-name/contract';
2
+ import { resolveMaybeOptionalOptions, toArray, value, runWithSpan, isAsyncIteratorObject, overlayProxy, asyncIteratorWithSpan, ORPCError } from '@temporary-name/shared';
3
3
  import { HibernationEventIterator, mapEventIterator } from '@temporary-name/standard-server';
4
- import { safeParseAsync } from '@temporary-name/zod';
4
+ import { safeDecodeAsync, safeEncodeAsync } from '@temporary-name/zod';
5
5
 
6
6
  function isStartWithMiddlewares(middlewares, compare) {
7
7
  if (compare.length > middlewares.length) {
@@ -27,7 +27,7 @@ function addMiddleware(middlewares, addition) {
27
27
  return [...middlewares, addition];
28
28
  }
29
29
 
30
- class Procedure {
30
+ class Contract {
31
31
  /**
32
32
  * This property holds the defined options.
33
33
  */
@@ -36,55 +36,17 @@ class Procedure {
36
36
  this["~orpc"] = def;
37
37
  }
38
38
  }
39
+ class Procedure extends Contract {
40
+ }
39
41
  function isProcedure(item) {
40
- if (item instanceof Procedure) {
41
- return true;
42
- }
43
- return isContractProcedure(item) && "middlewares" in item["~orpc"] && "handler" in item["~orpc"];
42
+ return item instanceof Procedure || // This is so we'll return true for Proxy-wrapped Procedures e.g. as returned by `callable`
43
+ (typeof item === "object" || typeof item === "function") && item !== null && "~orpc" in item && typeof item["~orpc"] === "object" && item["~orpc"] !== null && "route" in item["~orpc"] && "meta" in item["~orpc"] && "middlewares" in item["~orpc"] && "inputValidationIndex" in item["~orpc"] && "outputValidationIndex" in item["~orpc"] && "handler" in item["~orpc"];
44
44
  }
45
45
 
46
46
  function mergeCurrentContext(context, other) {
47
47
  return { ...context, ...other };
48
48
  }
49
49
 
50
- function createORPCErrorConstructorMap(errors) {
51
- const proxy = new Proxy(errors, {
52
- get(target, code) {
53
- if (typeof code !== "string") {
54
- return Reflect.get(target, code);
55
- }
56
- const item = (...rest) => {
57
- const options = resolveMaybeOptionalOptions(rest);
58
- const config = errors[code];
59
- return new ORPCError(code, {
60
- defined: Boolean(config),
61
- status: config?.status,
62
- message: options.message ?? config?.message,
63
- data: options.data,
64
- cause: options.cause
65
- });
66
- };
67
- return item;
68
- }
69
- });
70
- return proxy;
71
- }
72
-
73
- const HIDDEN_ROUTER_CONTRACT_SYMBOL = Symbol("ORPC_HIDDEN_ROUTER_CONTRACT");
74
- function setHiddenRouterContract(router, contract) {
75
- return new Proxy(router, {
76
- get(target, key) {
77
- if (key === HIDDEN_ROUTER_CONTRACT_SYMBOL) {
78
- return contract;
79
- }
80
- return Reflect.get(target, key);
81
- }
82
- });
83
- }
84
- function getHiddenRouterContract(router) {
85
- return router[HIDDEN_ROUTER_CONTRACT_SYMBOL];
86
- }
87
-
88
50
  function getRouter(router, path) {
89
51
  let current = router;
90
52
  for (let i = 0; i < path.length; i++) {
@@ -147,7 +109,6 @@ function enhanceRouter(router, options) {
147
109
  const enhanced2 = new Procedure({
148
110
  ...router["~orpc"],
149
111
  route: enhanceRoute(router["~orpc"].route, options),
150
- errorMap: mergeErrorMap(options.errorMap, router["~orpc"].errorMap),
151
112
  middlewares: newMiddlewares,
152
113
  inputValidationIndex: router["~orpc"].inputValidationIndex + newMiddlewareAdded,
153
114
  outputValidationIndex: router["~orpc"].outputValidationIndex + newMiddlewareAdded
@@ -161,21 +122,19 @@ function enhanceRouter(router, options) {
161
122
  return enhanced;
162
123
  }
163
124
  function traverseContractProcedures(options, callback, lazyOptions = []) {
164
- let currentRouter = options.router;
165
- const hiddenContract = getHiddenRouterContract(options.router);
166
- if (hiddenContract !== void 0) {
167
- currentRouter = hiddenContract;
168
- }
125
+ const currentRouter = options.router;
169
126
  if (isLazy(currentRouter)) {
170
127
  lazyOptions.push({
171
128
  router: currentRouter,
172
129
  path: options.path
173
130
  });
174
- } else if (isContractProcedure(currentRouter)) {
131
+ } else if (currentRouter instanceof Contract) {
175
132
  callback({
176
133
  contract: currentRouter,
177
134
  path: options.path
178
135
  });
136
+ } else if (typeof currentRouter === "string") {
137
+ throw new Error("Unexpected: got string instead of router");
179
138
  } else {
180
139
  for (const key in currentRouter) {
181
140
  traverseContractProcedures(
@@ -228,7 +187,6 @@ function lazyInternal(loader, meta = {}) {
228
187
  function lazy(prefix, loader) {
229
188
  return enhanceRouter(lazyInternal(loader), {
230
189
  middlewares: [],
231
- errorMap: {},
232
190
  dedupeLeadingMiddlewares: true,
233
191
  prefix
234
192
  });
@@ -254,85 +212,82 @@ function createProcedureClient(lazyableProcedure, ...rest) {
254
212
  const { default: procedure } = await unlazy(lazyableProcedure);
255
213
  const clientContext = callerOptions?.context ?? {};
256
214
  const context = await value(options.context ?? {}, clientContext);
257
- const errors = createORPCErrorConstructorMap(procedure["~orpc"].errorMap);
258
- const validateError = async (e) => {
259
- if (e instanceof ORPCError) {
260
- return await validateORPCError(procedure["~orpc"].errorMap, e);
261
- }
262
- return e;
263
- };
264
- try {
265
- const output = await runWithSpan({ name: "call_procedure", signal: callerOptions?.signal }, (span) => {
266
- span?.setAttribute("procedure.path", [...path]);
267
- return intercept(
268
- toArray(options.interceptors),
269
- {
270
- context,
271
- input,
272
- // input only optional when it undefinable so we can safely cast it
273
- errors,
274
- path,
275
- procedure,
276
- signal: callerOptions?.signal,
277
- lastEventId: callerOptions?.lastEventId
278
- },
279
- (interceptorOptions) => executeProcedureInternal(interceptorOptions.procedure, interceptorOptions)
280
- );
215
+ const output = await runWithSpan({ name: "call_procedure", signal: callerOptions?.signal }, (span) => {
216
+ span?.setAttribute("procedure.path", [...path]);
217
+ return executeProcedureInternal(procedure, input, {
218
+ context,
219
+ path,
220
+ procedure,
221
+ request: callerOptions?.request,
222
+ signal: callerOptions?.signal,
223
+ lastEventId: callerOptions?.lastEventId
281
224
  });
282
- if (isAsyncIteratorObject(output)) {
283
- if (output instanceof HibernationEventIterator) {
284
- return output;
285
- }
286
- return overlayProxy(
287
- output,
288
- mapEventIterator(
289
- asyncIteratorWithSpan(
290
- { name: "consume_event_iterator_output", signal: callerOptions?.signal },
291
- output
292
- ),
293
- {
294
- value: (v) => v,
295
- error: (e) => validateError(e)
296
- }
297
- )
298
- );
225
+ });
226
+ if (isAsyncIteratorObject(output)) {
227
+ if (output instanceof HibernationEventIterator) {
228
+ return output;
299
229
  }
300
- return output;
301
- } catch (e) {
302
- throw await validateError(e);
230
+ return overlayProxy(
231
+ output,
232
+ mapEventIterator(
233
+ asyncIteratorWithSpan(
234
+ { name: "consume_event_iterator_output", signal: callerOptions?.signal },
235
+ output
236
+ ),
237
+ {
238
+ value: (v) => v,
239
+ error: async (e) => e
240
+ }
241
+ )
242
+ );
303
243
  }
244
+ return output;
304
245
  };
305
246
  }
306
247
  async function validateInput(procedure, input) {
307
- const schema = procedure["~orpc"].inputSchema;
308
- if (!schema) {
309
- return input;
310
- }
248
+ const schemas = procedure["~orpc"].schemas;
311
249
  return runWithSpan({ name: "validate_input" }, async () => {
312
- const result = await safeParseAsync(schema, input);
313
- if (!result.success) {
250
+ const resultBody = await safeDecodeAsync(schemas.bodySchema, input.body, { parseType: "body" });
251
+ const resultPath = await safeDecodeAsync(schemas.pathSchema, input.path, { parseType: "path" });
252
+ const resultQuery = await safeDecodeAsync(schemas.querySchema, input.query, { parseType: "query" });
253
+ const issues = [];
254
+ if (!resultBody.success) {
255
+ issues.push(...resultBody.error.issues.map((i) => ({ ...i, path: ["body", ...i.path] })));
256
+ }
257
+ if (!resultPath.success) {
258
+ issues.push(...resultPath.error.issues.map((i) => ({ ...i, path: ["path", ...i.path] })));
259
+ }
260
+ if (!resultQuery.success) {
261
+ issues.push(...resultQuery.error.issues.map((i) => ({ ...i, path: ["query", ...i.path] })));
262
+ }
263
+ if (issues.length > 0) {
314
264
  throw new ORPCError("BAD_REQUEST", {
315
265
  message: "Input validation failed",
316
266
  data: {
317
- issues: result.error.issues
267
+ issues
318
268
  },
319
269
  cause: new ValidationError({
320
270
  message: "Input validation failed",
321
- issues: result.error.issues,
271
+ issues,
322
272
  data: input
323
273
  })
324
274
  });
325
275
  }
326
- return result.data;
276
+ const results = {
277
+ body: resultBody.data,
278
+ path: resultPath.data,
279
+ query: resultQuery.data
280
+ };
281
+ return results;
327
282
  });
328
283
  }
329
284
  async function validateOutput(procedure, output) {
330
- const schema = procedure["~orpc"].outputSchema;
285
+ const schema = procedure["~orpc"].schemas.outputSchema;
331
286
  if (!schema) {
332
287
  return output;
333
288
  }
334
289
  return runWithSpan({ name: "validate_output" }, async () => {
335
- const result = await safeParseAsync(schema, output);
290
+ const result = await safeEncodeAsync(schema, output, { parseType: "output" });
336
291
  if (!result.success) {
337
292
  throw new ORPCError("INTERNAL_SERVER_ERROR", {
338
293
  message: "Output validation failed",
@@ -346,7 +301,7 @@ async function validateOutput(procedure, output) {
346
301
  return result.data;
347
302
  });
348
303
  }
349
- async function executeProcedureInternal(procedure, options) {
304
+ async function executeProcedureInternal(procedure, input, options) {
350
305
  const middlewares = procedure["~orpc"].middlewares;
351
306
  const inputValidationIndex = Math.min(
352
307
  Math.max(0, procedure["~orpc"].inputValidationIndex),
@@ -356,8 +311,8 @@ async function executeProcedureInternal(procedure, options) {
356
311
  Math.max(0, procedure["~orpc"].outputValidationIndex),
357
312
  middlewares.length
358
313
  );
359
- const next = async (index, context, input) => {
360
- let currentInput = input;
314
+ const next = async (index, context, input2) => {
315
+ let currentInput = input2;
361
316
  if (index === inputValidationIndex) {
362
317
  currentInput = await validateInput(procedure, currentInput);
363
318
  }
@@ -373,6 +328,9 @@ async function executeProcedureInternal(procedure, options) {
373
328
  const nextContext = nextOptions?.context ?? {};
374
329
  return {
375
330
  output: await next(index + 1, mergeCurrentContext(context, nextContext), currentInput),
331
+ // NB: Pretty sure this isn't used (or meant to be used) at runtime, it's just there
332
+ // to get type inference in the builder (via the caller returning the output of next() in
333
+ // the middleware function)
376
334
  context: nextContext
377
335
  };
378
336
  }
@@ -383,14 +341,14 @@ async function executeProcedureInternal(procedure, options) {
383
341
  return result.output;
384
342
  }) : await runWithSpan(
385
343
  { name: "handler", signal: options.signal },
386
- () => procedure["~orpc"].handler({ ...options, context, input: currentInput })
344
+ () => procedure["~orpc"].handler(currentInput, { ...options, context })
387
345
  );
388
346
  if (index === outputValidationIndex) {
389
347
  return await validateOutput(procedure, output);
390
348
  }
391
349
  return output;
392
350
  };
393
- return next(0, options.context, options.input);
351
+ return next(0, options.context, input);
394
352
  }
395
353
 
396
- export { LAZY_SYMBOL as L, Procedure as P, addMiddleware as a, isLazy as b, createProcedureClient as c, getRouter as d, enhanceRouter as e, createORPCErrorConstructorMap as f, getLazyMeta as g, lazy as h, isProcedure as i, middlewareOutputFn as j, isStartWithMiddlewares as k, lazyInternal as l, mergeCurrentContext as m, mergeMiddlewares as n, getHiddenRouterContract as o, createAccessibleLazyRouter as p, unlazyRouter as q, resolveContractProcedures as r, setHiddenRouterContract as s, traverseContractProcedures as t, unlazy as u };
354
+ export { Contract as C, LAZY_SYMBOL as L, Procedure as P, addMiddleware as a, isLazy as b, createProcedureClient as c, getRouter as d, enhanceRouter as e, lazy as f, getLazyMeta as g, middlewareOutputFn as h, isProcedure as i, isStartWithMiddlewares as j, mergeMiddlewares as k, lazyInternal as l, mergeCurrentContext as m, createAccessibleLazyRouter as n, unlazyRouter as o, resolveContractProcedures as r, traverseContractProcedures as t, unlazy as u };
@@ -0,0 +1,30 @@
1
+ import { parse, serialize } from 'cookie';
2
+
3
+ function setCookie(headers, name, value, options = {}) {
4
+ if (headers === void 0) {
5
+ return;
6
+ }
7
+ const cookieString = serialize(name, value, {
8
+ path: "/",
9
+ ...options
10
+ });
11
+ headers.append("Set-Cookie", cookieString);
12
+ }
13
+ function getCookie(headers, name, options = {}) {
14
+ if (headers === void 0) {
15
+ return void 0;
16
+ }
17
+ const cookieHeader = headers.get("cookie");
18
+ if (cookieHeader === null) {
19
+ return void 0;
20
+ }
21
+ return parse(cookieHeader, options)[name];
22
+ }
23
+ function deleteCookie(headers, name, options = {}) {
24
+ return setCookie(headers, name, "", {
25
+ ...options,
26
+ maxAge: 0
27
+ });
28
+ }
29
+
30
+ export { deleteCookie as d, getCookie as g, setCookie as s };
@@ -0,0 +1,40 @@
1
+ import { isObject } from '@temporary-name/shared';
2
+
3
+ function jsonSerialize(data, hasBlobRef = { value: false }) {
4
+ if (data instanceof Blob) {
5
+ hasBlobRef.value = true;
6
+ return [data, hasBlobRef.value];
7
+ }
8
+ if (data instanceof Set) {
9
+ return jsonSerialize(Array.from(data), hasBlobRef);
10
+ }
11
+ if (data instanceof Map) {
12
+ return jsonSerialize(Array.from(data.entries()), hasBlobRef);
13
+ }
14
+ if (Array.isArray(data)) {
15
+ const json = data.map((v) => v === void 0 ? null : jsonSerialize(v, hasBlobRef)[0]);
16
+ return [json, hasBlobRef.value];
17
+ }
18
+ if (isObject(data)) {
19
+ const json = {};
20
+ for (const k in data) {
21
+ if (k === "toJSON" && typeof data[k] === "function") {
22
+ continue;
23
+ }
24
+ json[k] = jsonSerialize(data[k], hasBlobRef)[0];
25
+ }
26
+ return [json, hasBlobRef.value];
27
+ }
28
+ if (typeof data === "bigint" || data instanceof RegExp || data instanceof URL) {
29
+ return [data.toString(), hasBlobRef.value];
30
+ }
31
+ if (data instanceof Date) {
32
+ return [Number.isNaN(data.getTime()) ? null : data.toISOString(), hasBlobRef.value];
33
+ }
34
+ if (Number.isNaN(data)) {
35
+ return [null, hasBlobRef.value];
36
+ }
37
+ return [data, hasBlobRef.value];
38
+ }
39
+
40
+ export { jsonSerialize as j };