yedra 0.13.0 → 0.13.2

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.
@@ -1,5 +1,5 @@
1
1
  import { paramDocs } from '../util/docs.js';
2
- import { ValidationError } from '../validation/error.js';
2
+ import { Issue, ValidationError } from '../validation/error.js';
3
3
  import { NoneBody, none } from '../validation/none.js';
4
4
  import { object } from '../validation/object.js';
5
5
  import { BadRequestError } from './errors.js';
@@ -22,26 +22,67 @@ class ConcreteRestEndpoint extends RestEndpoint {
22
22
  let parsedParams;
23
23
  let parsedQuery;
24
24
  let parsedHeaders;
25
+ const issues = [];
25
26
  try {
26
27
  parsedBody = this.options.req.deserialize(typeof body === 'string' ? Buffer.from(body) : body, headers['content-type'] ?? 'application/octet-stream');
28
+ }
29
+ catch (error) {
30
+ if (error instanceof SyntaxError) {
31
+ issues.push(new Issue('invalidSyntax', ['body'], 'JSON', error.message));
32
+ }
33
+ else if (error instanceof ValidationError) {
34
+ issues.push(...error.withPrefix('body'));
35
+ }
36
+ else {
37
+ throw error;
38
+ }
39
+ }
40
+ try {
27
41
  parsedParams = this.paramsSchema.parse(params);
42
+ }
43
+ catch (error) {
44
+ if (error instanceof ValidationError) {
45
+ issues.push(...error.withPrefix('params'));
46
+ }
47
+ else {
48
+ throw error;
49
+ }
50
+ }
51
+ try {
28
52
  parsedQuery = this.querySchema.parse(query);
29
- parsedHeaders = this.headersSchema.parse(headers);
30
53
  }
31
54
  catch (error) {
32
- if (error instanceof SyntaxError) {
33
- throw new BadRequestError(error.message);
55
+ if (error instanceof ValidationError) {
56
+ issues.push(...error.withPrefix('query'));
57
+ }
58
+ else {
59
+ throw error;
34
60
  }
61
+ }
62
+ try {
63
+ parsedHeaders = this.headersSchema.parse(headers);
64
+ }
65
+ catch (error) {
35
66
  if (error instanceof ValidationError) {
36
- throw new BadRequestError(error.format());
67
+ issues.push(...error.withPrefix('headers'));
68
+ }
69
+ else {
70
+ throw error;
37
71
  }
38
- throw error;
72
+ }
73
+ if (issues.length > 0) {
74
+ const error = new ValidationError(issues);
75
+ throw new BadRequestError(error.format());
39
76
  }
40
77
  const response = await this.options.do({
41
78
  url,
79
+ // biome-ignore lint/style/noNonNullAssertion: this is required to convince TypeScript that this is initialized
42
80
  params: parsedParams,
81
+ // biome-ignore lint/style/noNonNullAssertion: this is required to convince TypeScript that this is initialized
43
82
  query: parsedQuery,
83
+ // biome-ignore lint/style/noNonNullAssertion: this is required to convince TypeScript that this is initialized
44
84
  headers: parsedHeaders,
85
+ // biome-ignore lint/style/noNonNullAssertion: this is required to convince TypeScript that this is initialized
45
86
  body: parsedBody,
46
87
  });
47
88
  if (response.body instanceof Uint8Array) {
@@ -1,4 +1,4 @@
1
- type IssueCode = 'invalidType' | 'tooSmall' | 'tooBig' | 'tooShort' | 'tooLong' | 'invalidPattern' | 'missingProperty' | 'invalidContentType';
1
+ type IssueCode = 'invalidSyntax' | 'invalidType' | 'tooSmall' | 'tooBig' | 'tooShort' | 'tooLong' | 'invalidPattern' | 'missingProperty' | 'invalidContentType';
2
2
  export declare class Issue {
3
3
  readonly code: IssueCode;
4
4
  readonly path: string[];
@@ -1,4 +1,5 @@
1
1
  const issueMessages = {
2
+ invalidSyntax: '${actual}',
2
3
  invalidType: "Expected '${expected}' but got '${actual}'",
3
4
  tooSmall: "Must be at least '${expected}' but was '${actual}'",
4
5
  tooBig: "Must be at most '${expected}' but was '${actual}'",
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "yedra",
3
- "version": "0.13.0",
3
+ "version": "0.13.2",
4
4
  "repository": "github:0codekit/yedra",
5
5
  "main": "dist/index.js",
6
6
  "devDependencies": {
7
7
  "@biomejs/biome": "^1.9.4",
8
- "@types/node": "^22.7.9",
8
+ "@types/node": "^22.8.2",
9
9
  "@types/uuid": "^10.0.0",
10
+ "@types/ws": "^8.5.12",
10
11
  "typescript": "^5.6.3"
11
12
  },
12
13
  "bugs": "https://github.com/0codekit/yedra/issues",
@@ -21,10 +22,8 @@
21
22
  "types": "dist/index.d.ts",
22
23
  "type": "module",
23
24
  "dependencies": {
24
- "@types/ws": "^8.5.12",
25
- "bufferutil": "^4.0.8",
26
25
  "mime": "^4.0.4",
27
- "uuid": "^10.0.0",
26
+ "uuid": "^11.0.2",
28
27
  "ws": "^8.18.0"
29
28
  }
30
29
  }