@temporary-name/server 1.9.3-alpha.16e8a4f82a5b0af6e22263774a4af4e6f9afd8bc → 1.9.3-alpha.1a5ff4923d25c9d83e80d717687ebc859f5312f2

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 (31) hide show
  1. package/dist/adapters/aws-lambda/index.d.mts +3 -3
  2. package/dist/adapters/aws-lambda/index.d.ts +3 -3
  3. package/dist/adapters/aws-lambda/index.mjs +4 -6
  4. package/dist/adapters/fetch/index.d.mts +3 -3
  5. package/dist/adapters/fetch/index.d.ts +3 -3
  6. package/dist/adapters/fetch/index.mjs +4 -6
  7. package/dist/adapters/node/index.d.mts +3 -3
  8. package/dist/adapters/node/index.d.ts +3 -3
  9. package/dist/adapters/node/index.mjs +4 -6
  10. package/dist/adapters/standard/index.d.mts +20 -31
  11. package/dist/adapters/standard/index.d.ts +20 -31
  12. package/dist/adapters/standard/index.mjs +4 -6
  13. package/dist/index.d.mts +66 -339
  14. package/dist/index.d.ts +66 -339
  15. package/dist/index.mjs +126 -354
  16. package/dist/openapi/index.d.mts +1 -1
  17. package/dist/openapi/index.d.ts +1 -1
  18. package/dist/openapi/index.mjs +59 -76
  19. package/dist/plugins/index.d.mts +2 -2
  20. package/dist/plugins/index.d.ts +2 -2
  21. package/dist/shared/{server.DLsti1Pv.mjs → server.B--sAUhn.mjs} +55 -94
  22. package/dist/shared/{server.CQyYNJ1H.d.ts → server.BCcLYvdF.d.mts} +1 -2
  23. package/dist/shared/server.CHV9AQHl.mjs +412 -0
  24. package/dist/shared/{server.C1fnTLq0.d.mts → server.CdeqmULw.d.ts} +1 -2
  25. package/dist/shared/{server.BeuTpcmO.d.mts → server.DHezmW6C.d.mts} +2 -2
  26. package/dist/shared/{server.SLLuK6_v.d.ts → server.Da-qLzdU.d.ts} +2 -2
  27. package/dist/shared/{server.BKSOrA6h.d.mts → server.DecvGKtb.d.mts} +125 -75
  28. package/dist/shared/{server.BKSOrA6h.d.ts → server.DecvGKtb.d.ts} +125 -75
  29. package/dist/shared/{server.BEHw7Eyx.mjs → server.Kxw442A9.mjs} +1 -1
  30. package/package.json +10 -9
  31. package/dist/shared/server.BKh8I1Ny.mjs +0 -239
@@ -1,7 +1,7 @@
1
1
  import { isProcedure, resolveContractProcedures, ORPCError, createRouterClient } from '@temporary-name/server';
2
2
  import { fallbackContractConfig, getEventIteratorSchemaDetails } from '@temporary-name/contract';
3
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.BEHw7Eyx.mjs';
4
+ import { a as standardizeHTTPPath, j as jsonSerialize, g as getDynamicParams, d as deserialize, s as serialize } from '../shared/server.Kxw442A9.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';
@@ -530,94 +530,77 @@ ${errors.join("\n\n")}`
530
530
  }
531
531
  async #request(doc, ref, def, baseSchemaConvertOptions) {
532
532
  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
533
  const dynamicParams = getDynamicParams(def.route.path)?.map((v) => v.name);
545
- const inputStructure = fallbackContractConfig("defaultInputStructure", def.route.inputStructure);
546
- let [required, schema] = await this.converter.convert(def.inputSchema, {
534
+ const [_pathRequired, pathSchema] = await this.converter.convert(def.schemas.pathSchema, {
547
535
  ...baseSchemaConvertOptions,
548
536
  strategy: "input",
549
- minStructureDepthForRef: dynamicParams?.length || inputStructure === "detailed" ? 1 : 0
537
+ minStructureDepthForRef: 1
550
538
  });
551
- if (isAnySchema(schema) && !dynamicParams?.length) {
552
- return;
553
- }
554
- if (inputStructure === "compact") {
555
- if (dynamicParams?.length) {
556
- const error2 = new OpenAPIGeneratorError(
557
- 'When input structure is "compact", and path has dynamic params, input schema must be an object with all dynamic params as required.'
558
- );
559
- if (!isObjectSchema(schema)) {
560
- throw error2;
561
- }
562
- const [paramsSchema, rest] = separateObjectSchema(schema, dynamicParams);
563
- schema = rest;
564
- required = rest.required ? rest.required.length !== 0 : false;
565
- if (!checkParamsSchema(paramsSchema, dynamicParams)) {
566
- throw error2;
567
- }
568
- ref.parameters ??= [];
569
- ref.parameters.push(...toOpenAPIParameters(paramsSchema, "path"));
539
+ if (dynamicParams?.length) {
540
+ const error = new OpenAPIGeneratorError(
541
+ // TODO: fix this error
542
+ 'When input structure is "compact", and path has dynamic params, input schema must be an object with all dynamic params as required.'
543
+ );
544
+ if (!isObjectSchema(pathSchema)) {
545
+ throw error;
570
546
  }
571
- if (method === "GET") {
572
- const resolvedSchema = resolveOpenAPIJsonSchemaRef(doc, schema);
573
- if (!isObjectSchema(resolvedSchema)) {
574
- throw new OpenAPIGeneratorError(
575
- 'When method is "GET", input schema must satisfy: object | any | unknown'
576
- );
577
- }
578
- ref.parameters ??= [];
579
- ref.parameters.push(...toOpenAPIParameters(resolvedSchema, "query"));
580
- } else {
581
- ref.requestBody = {
582
- required,
583
- content: toOpenAPIContent(schema)
584
- };
547
+ if (!checkParamsSchema(pathSchema, dynamicParams)) {
548
+ throw error;
549
+ }
550
+ ref.parameters ??= [];
551
+ ref.parameters.push(...toOpenAPIParameters(pathSchema, "path"));
552
+ } else {
553
+ const error = new OpenAPIGeneratorError("Params set via path do not match those on the route");
554
+ if (!isObjectSchema(pathSchema)) {
555
+ console.log("FOO", pathSchema);
556
+ throw error;
557
+ }
558
+ if (!checkParamsSchema(pathSchema, [])) {
559
+ console.log("BAR", pathSchema);
560
+ throw error;
585
561
  }
586
- return;
587
- }
588
- const error = new OpenAPIGeneratorError(
589
- 'When input structure is "detailed", input schema must satisfy: { params?: Record<string, unknown>, query?: Record<string, unknown>, headers?: Record<string, unknown>, body?: unknown }'
590
- );
591
- if (!isObjectSchema(schema)) {
592
- throw error;
593
562
  }
594
- const resolvedParamSchema = schema.properties?.params !== void 0 ? resolveOpenAPIJsonSchemaRef(doc, schema.properties.params) : void 0;
595
- if (dynamicParams?.length && (resolvedParamSchema === void 0 || !isObjectSchema(resolvedParamSchema) || !checkParamsSchema(resolvedParamSchema, dynamicParams))) {
596
- throw new OpenAPIGeneratorError(
597
- 'When input structure is "detailed" and path has dynamic params, the "params" schema must be an object with all dynamic params as required.'
598
- );
563
+ const [_queryRequired, querySchema] = await this.converter.convert(def.schemas.querySchema, {
564
+ ...baseSchemaConvertOptions,
565
+ strategy: "input",
566
+ minStructureDepthForRef: 0
567
+ });
568
+ if (!isAnySchema(querySchema)) {
569
+ const resolvedSchema = resolveOpenAPIJsonSchemaRef(doc, querySchema);
570
+ if (!isObjectSchema(resolvedSchema)) {
571
+ throw new OpenAPIGeneratorError("Query param schema must satisfy: object | any | unknown");
572
+ }
573
+ ref.parameters ??= [];
574
+ ref.parameters.push(...toOpenAPIParameters(resolvedSchema, "query"));
599
575
  }
600
- for (const from of ["params", "query", "headers"]) {
601
- const fromSchema = schema.properties?.[from];
602
- if (fromSchema !== void 0) {
603
- const resolvedSchema = resolveOpenAPIJsonSchemaRef(doc, fromSchema);
604
- if (!isObjectSchema(resolvedSchema)) {
605
- throw error;
576
+ if (method !== "GET") {
577
+ const details = getEventIteratorSchemaDetails(def.schemas.bodySchema);
578
+ if (details) {
579
+ ref.requestBody = {
580
+ required: true,
581
+ content: toOpenAPIEventIteratorContent(
582
+ await this.converter.convert(details.yields, { ...baseSchemaConvertOptions, strategy: "input" }),
583
+ await this.converter.convert(details.returns, { ...baseSchemaConvertOptions, strategy: "input" })
584
+ )
585
+ };
586
+ } else {
587
+ const [bodyRequired, bodySchema] = await this.converter.convert(def.schemas.bodySchema, {
588
+ ...baseSchemaConvertOptions,
589
+ strategy: "input",
590
+ minStructureDepthForRef: 0
591
+ });
592
+ if (isAnySchema(bodySchema)) {
593
+ return;
606
594
  }
607
- const parameterIn = from === "params" ? "path" : from === "headers" ? "header" : "query";
608
- ref.parameters ??= [];
609
- ref.parameters.push(...toOpenAPIParameters(resolvedSchema, parameterIn));
595
+ ref.requestBody = {
596
+ required: bodyRequired,
597
+ content: toOpenAPIContent(bodySchema)
598
+ };
610
599
  }
611
600
  }
612
- if (schema.properties?.body !== void 0) {
613
- ref.requestBody = {
614
- required: schema.required?.includes("body"),
615
- content: toOpenAPIContent(schema.properties.body)
616
- };
617
- }
618
601
  }
619
602
  async #successResponse(doc, ref, def, baseSchemaConvertOptions) {
620
- const outputSchema = def.outputSchema;
603
+ const outputSchema = def.schemas.outputSchema;
621
604
  const status = fallbackContractConfig("defaultSuccessStatus", def.route.successStatus);
622
605
  const description = fallbackContractConfig("defaultSuccessDescription", def.route?.successDescription);
623
606
  const eventIteratorSchemaDetails = getEventIteratorSchemaDetails(outputSchema);
@@ -1,8 +1,8 @@
1
1
  import { Value, Promisable, ORPCError } from '@temporary-name/shared';
2
2
  import { StandardRequest, StandardHeaders } from '@temporary-name/standard-server';
3
3
  import { BatchResponseBodyItem } from '@temporary-name/standard-server/batch';
4
- import { S as StandardHandlerInterceptorOptions, a as StandardHandlerPlugin, b as StandardHandlerOptions } from '../shared/server.C1fnTLq0.mjs';
5
- import { C as Context, E as ProcedureClientInterceptorOptions } from '../shared/server.BKSOrA6h.mjs';
4
+ import { S as StandardHandlerInterceptorOptions, a as StandardHandlerPlugin, b as StandardHandlerOptions } from '../shared/server.BCcLYvdF.mjs';
5
+ import { C as Context, H as ProcedureClientInterceptorOptions } from '../shared/server.DecvGKtb.mjs';
6
6
  import { Meta } from '@temporary-name/contract';
7
7
 
8
8
  interface BatchHandlerOptions<T extends Context> {
@@ -1,8 +1,8 @@
1
1
  import { Value, Promisable, ORPCError } from '@temporary-name/shared';
2
2
  import { StandardRequest, StandardHeaders } from '@temporary-name/standard-server';
3
3
  import { BatchResponseBodyItem } from '@temporary-name/standard-server/batch';
4
- import { S as StandardHandlerInterceptorOptions, a as StandardHandlerPlugin, b as StandardHandlerOptions } from '../shared/server.CQyYNJ1H.js';
5
- import { C as Context, E as ProcedureClientInterceptorOptions } from '../shared/server.BKSOrA6h.js';
4
+ import { S as StandardHandlerInterceptorOptions, a as StandardHandlerPlugin, b as StandardHandlerOptions } from '../shared/server.CdeqmULw.js';
5
+ import { C as Context, H as ProcedureClientInterceptorOptions } from '../shared/server.DecvGKtb.js';
6
6
  import { Meta } from '@temporary-name/contract';
7
7
 
8
8
  interface BatchHandlerOptions<T extends Context> {
@@ -1,67 +1,37 @@
1
- import { isObject, stringifyJSON, isORPCErrorStatus, tryDecodeURIComponent, value, toHttpPath, toArray, intercept, runWithSpan, ORPC_NAME, isAsyncIteratorObject, asyncIteratorWithSpan, setSpanError, ORPCError, toORPCError } from '@temporary-name/shared';
1
+ import { stringifyJSON, isObject, isORPCErrorStatus, tryDecodeURIComponent, toHttpPath, toArray, intercept, runWithSpan, ORPC_NAME, isAsyncIteratorObject, asyncIteratorWithSpan, setSpanError, ORPCError, toORPCError } from '@temporary-name/shared';
2
2
  import { flattenHeader } from '@temporary-name/standard-server';
3
- import { c as createProcedureClient } from './server.BKh8I1Ny.mjs';
3
+ import { c as createProcedureClient } from './server.CHV9AQHl.mjs';
4
4
  import { fallbackContractConfig } from '@temporary-name/contract';
5
- import { d as deserialize, s as serialize, a as standardizeHTTPPath } from './server.BEHw7Eyx.mjs';
5
+ import { d as deserialize, b as bracketNotationDeserialize, s as serialize, a as standardizeHTTPPath } from './server.Kxw442A9.mjs';
6
6
  import { traverseContractProcedures, isProcedure, getLazyMeta, unlazy, getRouter, createContractedProcedure } from '@temporary-name/server';
7
7
  import { createRouter, addRoute, findRoute } from 'rou3';
8
8
 
9
- class StandardOpenAPICodec {
10
- constructor() {
11
- }
12
- async decode(request, params, procedure) {
13
- const inputStructure = fallbackContractConfig(
14
- "defaultInputStructure",
15
- procedure["~orpc"].route.inputStructure
16
- );
17
- if (inputStructure === "compact") {
18
- const data = request.method === "GET" ? deserialize(request.url.searchParams) : deserialize(await request.body());
19
- if (data === void 0) {
20
- return params;
21
- }
22
- if (isObject(data)) {
23
- return {
24
- ...params,
25
- ...data
26
- };
27
- }
28
- return data;
29
- }
30
- const deserializeSearchParams = () => {
31
- return deserialize(request.url.searchParams);
32
- };
9
+ async function decode(request, pathParams) {
10
+ return {
11
+ path: pathParams ?? {},
12
+ query: bracketNotationDeserialize(Array.from(request.url.searchParams.entries())),
13
+ headers: request.headers,
14
+ body: deserialize(await request.body()) ?? {}
15
+ };
16
+ }
17
+ function encode(output, procedure) {
18
+ const successStatus = fallbackContractConfig(
19
+ "defaultSuccessStatus",
20
+ procedure["~orpc"].route.successStatus
21
+ );
22
+ const outputStructure = fallbackContractConfig(
23
+ "defaultOutputStructure",
24
+ procedure["~orpc"].route.outputStructure
25
+ );
26
+ if (outputStructure === "compact") {
33
27
  return {
34
- params,
35
- get query() {
36
- const value = deserializeSearchParams();
37
- Object.defineProperty(this, "query", { value, writable: true });
38
- return value;
39
- },
40
- set query(value) {
41
- Object.defineProperty(this, "query", { value, writable: true });
42
- },
43
- headers: request.headers,
44
- body: deserialize(await request.body())
28
+ status: successStatus,
29
+ headers: {},
30
+ body: serialize(output)
45
31
  };
46
32
  }
47
- encode(output, procedure) {
48
- const successStatus = fallbackContractConfig(
49
- "defaultSuccessStatus",
50
- procedure["~orpc"].route.successStatus
51
- );
52
- const outputStructure = fallbackContractConfig(
53
- "defaultOutputStructure",
54
- procedure["~orpc"].route.outputStructure
55
- );
56
- if (outputStructure === "compact") {
57
- return {
58
- status: successStatus,
59
- headers: {},
60
- body: serialize(output)
61
- };
62
- }
63
- if (!this.#isDetailedOutput(output)) {
64
- throw new Error(`
33
+ if (!isDetailedOutput(output)) {
34
+ throw new Error(`
65
35
  Invalid "detailed" output structure:
66
36
  \u2022 Expected an object with optional properties:
67
37
  - status (number 200-399)
@@ -72,32 +42,31 @@ class StandardOpenAPICodec {
72
42
  Actual value:
73
43
  ${stringifyJSON(output)}
74
44
  `);
75
- }
76
- return {
77
- status: output.status ?? successStatus,
78
- headers: output.headers ?? {},
79
- body: serialize(output.body)
80
- };
81
45
  }
82
- encodeError(error) {
83
- return {
84
- status: error.status,
85
- headers: {},
86
- body: serialize(error.toJSON(), { outputFormat: "plain" })
87
- };
46
+ return {
47
+ status: output.status ?? successStatus,
48
+ headers: output.headers ?? {},
49
+ body: serialize(output.body)
50
+ };
51
+ }
52
+ function encodeError(error) {
53
+ return {
54
+ status: error.status,
55
+ headers: {},
56
+ body: serialize(error.toJSON(), { outputFormat: "plain" })
57
+ };
58
+ }
59
+ function isDetailedOutput(output) {
60
+ if (!isObject(output)) {
61
+ return false;
88
62
  }
89
- #isDetailedOutput(output) {
90
- if (!isObject(output)) {
91
- return false;
92
- }
93
- if (output.headers && !isObject(output.headers)) {
94
- return false;
95
- }
96
- if (output.status !== void 0 && (typeof output.status !== "number" || !Number.isInteger(output.status) || isORPCErrorStatus(output.status))) {
97
- return false;
98
- }
99
- return true;
63
+ if (output.headers && !isObject(output.headers)) {
64
+ return false;
65
+ }
66
+ if (output.status !== void 0 && (typeof output.status !== "number" || !Number.isInteger(output.status) || isORPCErrorStatus(output.status))) {
67
+ return false;
100
68
  }
69
+ return true;
101
70
  }
102
71
 
103
72
  function resolveFriendlyStandardHandleOptions(options) {
@@ -121,9 +90,6 @@ class StandardOpenAPIMatcher {
121
90
  pendingRouters = [];
122
91
  init(router, path = []) {
123
92
  const laziedOptions = traverseContractProcedures({ router, path }, (traverseOptions) => {
124
- if (!value(true, traverseOptions)) {
125
- return;
126
- }
127
93
  const { path: path2, contract } = traverseOptions;
128
94
  const method = fallbackContractConfig("defaultMethod", contract["~orpc"].route.method);
129
95
  const httpPath = toRou3Pattern(contract["~orpc"].route.path ?? toHttpPath(path2));
@@ -204,10 +170,8 @@ class StandardHandler {
204
170
  clientInterceptors;
205
171
  rootInterceptors;
206
172
  matcher;
207
- codec;
208
173
  constructor(router, options) {
209
174
  this.matcher = new StandardOpenAPIMatcher();
210
- this.codec = new StandardOpenAPICodec();
211
175
  const plugins = new CompositeStandardHandlerPlugin(options.plugins);
212
176
  plugins.init(options, router);
213
177
  this.interceptors = toArray(options.interceptors);
@@ -242,15 +206,12 @@ class StandardHandler {
242
206
  span?.setAttribute("rpc.system", ORPC_NAME);
243
207
  span?.setAttribute("rpc.method", match.path.join("."));
244
208
  step = "decode_input";
245
- let input = await runWithSpan(
246
- { name: "decode_input" },
247
- () => this.codec.decode(request2, match.params, match.procedure)
248
- );
209
+ const input = await runWithSpan({ name: "decode_input" }, () => decode(request2, match.params));
249
210
  step = void 0;
250
- if (isAsyncIteratorObject(input)) {
251
- input = asyncIteratorWithSpan(
211
+ if (isAsyncIteratorObject(input.body)) {
212
+ input.body = asyncIteratorWithSpan(
252
213
  { name: "consume_event_iterator_input", signal: request2.signal },
253
- input
214
+ input.body
254
215
  );
255
216
  }
256
217
  const client = createProcedureClient(match.procedure, {
@@ -264,7 +225,7 @@ class StandardHandler {
264
225
  lastEventId: flattenHeader(request2.headers["last-event-id"])
265
226
  });
266
227
  step = void 0;
267
- const response = this.codec.encode(output, match.procedure);
228
+ const response = encode(output, match.procedure);
268
229
  return {
269
230
  matched: true,
270
231
  response
@@ -279,7 +240,7 @@ class StandardHandler {
279
240
  message: `Malformed request. Ensure the request body is properly formatted and the 'Content-Type' header is set correctly.`,
280
241
  cause: e
281
242
  }) : toORPCError(e);
282
- const response = this.codec.encodeError(error);
243
+ const response = encodeError(error);
283
244
  return {
284
245
  matched: true,
285
246
  response
@@ -290,4 +251,4 @@ class StandardHandler {
290
251
  }
291
252
  }
292
253
 
293
- export { CompositeStandardHandlerPlugin as C, StandardHandler as S, StandardOpenAPICodec as a, StandardOpenAPIMatcher as b, decodeParams as d, resolveFriendlyStandardHandleOptions as r, toRou3Pattern as t };
254
+ export { CompositeStandardHandlerPlugin as C, StandardHandler as S, encodeError as a, StandardOpenAPIMatcher as b, decodeParams as c, decode as d, encode as e, resolveFriendlyStandardHandleOptions as r, toRou3Pattern as t };
@@ -1,7 +1,7 @@
1
1
  import { Meta } from '@temporary-name/contract';
2
2
  import { HTTPPath, Interceptor } from '@temporary-name/shared';
3
3
  import { StandardLazyRequest, StandardResponse } from '@temporary-name/standard-server';
4
- import { C as Context, R as Router, E as ProcedureClientInterceptorOptions } from './server.BKSOrA6h.js';
4
+ import { C as Context, R as Router, H as ProcedureClientInterceptorOptions } from './server.DecvGKtb.mjs';
5
5
 
6
6
  interface StandardHandlerPlugin<T extends Context> {
7
7
  order?: number;
@@ -48,7 +48,6 @@ declare class StandardHandler<T extends Context> {
48
48
  private readonly clientInterceptors;
49
49
  private readonly rootInterceptors;
50
50
  private readonly matcher;
51
- private readonly codec;
52
51
  constructor(router: Router<any, T>, options: NoInfer<StandardHandlerOptions<T>>);
53
52
  handle(request: StandardLazyRequest, options: StandardHandleOptions<T>): Promise<StandardHandleResult>;
54
53
  }