yedra 0.9.2 → 0.9.4

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 (61) hide show
  1. package/README.md +16 -50
  2. package/dist/index.d.ts +1 -1
  3. package/dist/index.js +2 -5
  4. package/dist/lib.d.ts +27 -27
  5. package/dist/lib.js +29 -67
  6. package/dist/routing/app.d.ts +2 -2
  7. package/dist/routing/app.js +33 -50
  8. package/dist/routing/endpoint.d.ts +5 -5
  9. package/dist/routing/endpoint.js +50 -65
  10. package/dist/routing/env.d.ts +2 -2
  11. package/dist/routing/env.js +3 -7
  12. package/dist/routing/errors.js +7 -17
  13. package/dist/routing/http.d.ts +1 -1
  14. package/dist/routing/http.js +34 -53
  15. package/dist/routing/listen.d.ts +1 -1
  16. package/dist/routing/listen.js +20 -36
  17. package/dist/routing/log.js +1 -5
  18. package/dist/routing/path.js +1 -5
  19. package/dist/routing/route.d.ts +8 -7
  20. package/dist/routing/route.js +58 -70
  21. package/dist/routing/test.d.ts +2 -2
  22. package/dist/routing/test.js +52 -64
  23. package/dist/validation/array.d.ts +3 -3
  24. package/dist/validation/array.js +12 -16
  25. package/dist/validation/body.js +1 -5
  26. package/dist/validation/boolean.d.ts +1 -1
  27. package/dist/validation/boolean.js +6 -10
  28. package/dist/validation/date.d.ts +1 -1
  29. package/dist/validation/date.js +8 -12
  30. package/dist/validation/doc.d.ts +1 -1
  31. package/dist/validation/doc.js +7 -7
  32. package/dist/validation/either.d.ts +1 -1
  33. package/dist/validation/either.js +7 -11
  34. package/dist/validation/enum.d.ts +1 -1
  35. package/dist/validation/enum.js +6 -10
  36. package/dist/validation/error.js +4 -9
  37. package/dist/validation/intersection.d.ts +2 -2
  38. package/dist/validation/intersection.js +8 -13
  39. package/dist/validation/modifiable.d.ts +2 -2
  40. package/dist/validation/modifiable.js +6 -10
  41. package/dist/validation/none.d.ts +1 -1
  42. package/dist/validation/none.js +3 -8
  43. package/dist/validation/number.d.ts +1 -1
  44. package/dist/validation/number.js +12 -16
  45. package/dist/validation/object.d.ts +3 -3
  46. package/dist/validation/object.js +14 -19
  47. package/dist/validation/raw.d.ts +1 -1
  48. package/dist/validation/raw.js +4 -8
  49. package/dist/validation/record.d.ts +3 -3
  50. package/dist/validation/record.js +8 -12
  51. package/dist/validation/schema.d.ts +1 -1
  52. package/dist/validation/schema.js +5 -9
  53. package/dist/validation/string.d.ts +1 -1
  54. package/dist/validation/string.js +11 -15
  55. package/dist/validation/undefined.d.ts +1 -1
  56. package/dist/validation/undefined.js +6 -11
  57. package/dist/validation/union.d.ts +2 -2
  58. package/dist/validation/union.js +6 -10
  59. package/dist/validation/unknown.d.ts +1 -1
  60. package/dist/validation/unknown.js +3 -7
  61. package/package.json +3 -2
@@ -1,9 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.number = void 0;
4
- const error_1 = require("./error");
5
- const modifiable_1 = require("./modifiable");
6
- class NumberSchema extends modifiable_1.ModifiableSchema {
1
+ import { Issue, ValidationError } from './error.js';
2
+ import { ModifiableSchema } from './modifiable.js';
3
+ class NumberSchema extends ModifiableSchema {
7
4
  constructor(min, max) {
8
5
  super();
9
6
  this.minValue = min;
@@ -25,24 +22,24 @@ class NumberSchema extends modifiable_1.ModifiableSchema {
25
22
  }
26
23
  parse(obj) {
27
24
  if (typeof obj !== 'number' && typeof obj !== 'string') {
28
- throw new error_1.ValidationError([
29
- new error_1.Issue('invalidType', [], 'number', typeof obj),
25
+ throw new ValidationError([
26
+ new Issue('invalidType', [], 'number', typeof obj),
30
27
  ]);
31
28
  }
32
29
  const num = typeof obj === 'number' ? obj : Number.parseFloat(obj);
33
30
  if (Number.isNaN(num)) {
34
- throw new error_1.ValidationError([
35
- new error_1.Issue('invalidType', [], 'number', typeof obj),
31
+ throw new ValidationError([
32
+ new Issue('invalidType', [], 'number', typeof obj),
36
33
  ]);
37
34
  }
38
35
  if (this.minValue !== undefined && num < this.minValue) {
39
- throw new error_1.ValidationError([
40
- new error_1.Issue('tooSmall', [], this.minValue.toString(), num.toString()),
36
+ throw new ValidationError([
37
+ new Issue('tooSmall', [], this.minValue.toString(), num.toString()),
41
38
  ]);
42
39
  }
43
40
  if (this.maxValue !== undefined && num > this.maxValue) {
44
- throw new error_1.ValidationError([
45
- new error_1.Issue('tooBig', [], this.maxValue.toString(), num.toString()),
41
+ throw new ValidationError([
42
+ new Issue('tooBig', [], this.maxValue.toString(), num.toString()),
46
43
  ]);
47
44
  }
48
45
  return num;
@@ -58,5 +55,4 @@ class NumberSchema extends modifiable_1.ModifiableSchema {
58
55
  /**
59
56
  * A schema that matches a number.
60
57
  */
61
- const number = () => new NumberSchema();
62
- exports.number = number;
58
+ export const number = () => new NumberSchema();
@@ -1,6 +1,6 @@
1
- import type { Typeof } from './body';
2
- import { ModifiableSchema } from './modifiable';
3
- import { Schema } from './schema';
1
+ import type { Typeof } from './body.js';
2
+ import { ModifiableSchema } from './modifiable.js';
3
+ import { Schema } from './schema.js';
4
4
  /**
5
5
  * Make a union of all keys that are not extended by undefined
6
6
  * (i.e. have undefined as a variant) of the specified type.
@@ -1,39 +1,36 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.object = exports.ObjectSchema = void 0;
4
- const error_1 = require("./error");
5
- const modifiable_1 = require("./modifiable");
6
- const schema_1 = require("./schema");
7
- class ObjectSchema extends modifiable_1.ModifiableSchema {
1
+ import { Issue, ValidationError } from './error.js';
2
+ import { ModifiableSchema } from './modifiable.js';
3
+ import { Schema } from './schema.js';
4
+ export class ObjectSchema extends ModifiableSchema {
8
5
  constructor(shape) {
9
6
  super();
10
7
  this.shape = shape;
11
8
  }
12
9
  parse(obj) {
13
10
  if (typeof obj !== 'object') {
14
- throw new error_1.ValidationError([
15
- new error_1.Issue('invalidType', [], 'object', typeof obj),
11
+ throw new ValidationError([
12
+ new Issue('invalidType', [], 'object', typeof obj),
16
13
  ]);
17
14
  }
18
15
  if (obj == null) {
19
- throw new error_1.ValidationError([
20
- new error_1.Issue('invalidType', [], 'object', 'null'),
16
+ throw new ValidationError([
17
+ new Issue('invalidType', [], 'object', 'null'),
21
18
  ]);
22
19
  }
23
20
  const result = {};
24
21
  const issues = [];
25
22
  for (const prop in this.shape) {
26
23
  const propSchema = this.shape[prop];
27
- if (propSchema instanceof schema_1.Schema) {
24
+ if (propSchema instanceof Schema) {
28
25
  if (!(prop in obj || propSchema.isOptional())) {
29
- issues.push(new error_1.Issue('missingProperty', [prop], prop, ''));
26
+ issues.push(new Issue('missingProperty', [prop], prop, ''));
30
27
  continue;
31
28
  }
32
29
  try {
33
30
  result[prop] = propSchema.parse(obj[prop]);
34
31
  }
35
32
  catch (error) {
36
- if (error instanceof error_1.ValidationError) {
33
+ if (error instanceof ValidationError) {
37
34
  issues.push(...error.withPrefix(prop));
38
35
  }
39
36
  else {
@@ -43,7 +40,7 @@ class ObjectSchema extends modifiable_1.ModifiableSchema {
43
40
  }
44
41
  }
45
42
  if (issues.length > 0) {
46
- throw new error_1.ValidationError(issues);
43
+ throw new ValidationError(issues);
47
44
  }
48
45
  return result;
49
46
  }
@@ -52,7 +49,7 @@ class ObjectSchema extends modifiable_1.ModifiableSchema {
52
49
  const required = [];
53
50
  for (const prop in this.shape) {
54
51
  const propSchema = this.shape[prop];
55
- if (propSchema instanceof schema_1.Schema) {
52
+ if (propSchema instanceof Schema) {
56
53
  if (!propSchema.isOptional()) {
57
54
  required.push(prop);
58
55
  }
@@ -66,7 +63,6 @@ class ObjectSchema extends modifiable_1.ModifiableSchema {
66
63
  };
67
64
  }
68
65
  }
69
- exports.ObjectSchema = ObjectSchema;
70
66
  /**
71
67
  * A schema matching a JavaScript object of the specified shape. Fields which
72
68
  * can be undefined are automatically marked as optional.
@@ -77,5 +73,4 @@ exports.ObjectSchema = ObjectSchema;
77
73
  * type SchemaType = y.Typeof<typeof schema>; // { num: number, str?: string }
78
74
  * ```
79
75
  */
80
- const object = (shape) => new ObjectSchema(shape);
81
- exports.object = object;
76
+ export const object = (shape) => new ObjectSchema(shape);
@@ -1,4 +1,4 @@
1
- import { BodyType } from './body';
1
+ import { BodyType } from './body.js';
2
2
  declare class RawBody extends BodyType<Uint8Array> {
3
3
  private contentType;
4
4
  constructor(contentType: string | undefined);
@@ -1,11 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.raw = void 0;
4
- const body_1 = require("./body");
5
- class RawBody extends body_1.BodyType {
1
+ import { BodyType } from './body.js';
2
+ class RawBody extends BodyType {
6
3
  constructor(contentType) {
7
4
  super();
8
- this.contentType = contentType !== null && contentType !== void 0 ? contentType : 'application/octet-stream';
5
+ this.contentType = contentType ?? 'application/octet-stream';
9
6
  }
10
7
  deserialize(buffer, contentType) {
11
8
  return buffer;
@@ -19,5 +16,4 @@ class RawBody extends body_1.BodyType {
19
16
  /**
20
17
  * Accepts a raw buffer of the specified content type.
21
18
  */
22
- const raw = (contentType) => new RawBody(contentType);
23
- exports.raw = raw;
19
+ export const raw = (contentType) => new RawBody(contentType);
@@ -1,6 +1,6 @@
1
- import type { Typeof } from './body';
2
- import { ModifiableSchema } from './modifiable';
3
- import type { Schema } from './schema';
1
+ import type { Typeof } from './body.js';
2
+ import { ModifiableSchema } from './modifiable.js';
3
+ import type { Schema } from './schema.js';
4
4
  declare class RecordSchema<ValueSchema extends Schema<unknown>> extends ModifiableSchema<Record<string, Typeof<ValueSchema> | undefined>> {
5
5
  private readonly valueSchema;
6
6
  constructor(valueSchema: ValueSchema);
@@ -1,17 +1,14 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.record = void 0;
4
- const error_1 = require("./error");
5
- const modifiable_1 = require("./modifiable");
6
- class RecordSchema extends modifiable_1.ModifiableSchema {
1
+ import { Issue, ValidationError } from './error.js';
2
+ import { ModifiableSchema } from './modifiable.js';
3
+ class RecordSchema extends ModifiableSchema {
7
4
  constructor(valueSchema) {
8
5
  super();
9
6
  this.valueSchema = valueSchema;
10
7
  }
11
8
  parse(obj) {
12
9
  if (!obj || typeof obj !== 'object') {
13
- throw new error_1.ValidationError([
14
- new error_1.Issue('invalidType', [], 'object', typeof obj),
10
+ throw new ValidationError([
11
+ new Issue('invalidType', [], 'object', typeof obj),
15
12
  ]);
16
13
  }
17
14
  const result = {};
@@ -21,7 +18,7 @@ class RecordSchema extends modifiable_1.ModifiableSchema {
21
18
  result[key] = this.valueSchema.parse(obj[key]);
22
19
  }
23
20
  catch (error) {
24
- if (error instanceof error_1.ValidationError) {
21
+ if (error instanceof ValidationError) {
25
22
  issues.push(...error.withPrefix(key));
26
23
  }
27
24
  else {
@@ -30,7 +27,7 @@ class RecordSchema extends modifiable_1.ModifiableSchema {
30
27
  }
31
28
  }
32
29
  if (issues.length > 0) {
33
- throw new error_1.ValidationError(issues);
30
+ throw new ValidationError(issues);
34
31
  }
35
32
  return result;
36
33
  }
@@ -46,5 +43,4 @@ class RecordSchema extends modifiable_1.ModifiableSchema {
46
43
  * to match the specified value schema.
47
44
  * @param valueSchema - The schema for the record values.
48
45
  */
49
- const record = (valueSchema) => new RecordSchema(valueSchema);
50
- exports.record = record;
46
+ export const record = (valueSchema) => new RecordSchema(valueSchema);
@@ -1,4 +1,4 @@
1
- import { BodyType } from './body';
1
+ import { BodyType } from './body.js';
2
2
  /**
3
3
  * The base class for all schemas.
4
4
  */
@@ -1,16 +1,13 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Schema = void 0;
4
- const body_1 = require("./body");
5
- const error_1 = require("./error");
1
+ import { BodyType } from './body.js';
2
+ import { Issue, ValidationError } from './error.js';
6
3
  /**
7
4
  * The base class for all schemas.
8
5
  */
9
- class Schema extends body_1.BodyType {
6
+ export class Schema extends BodyType {
10
7
  deserialize(buffer, contentType) {
11
8
  if (contentType !== 'application/json' && buffer.length > 0) {
12
- throw new error_1.ValidationError([
13
- new error_1.Issue('invalidContentType', [], 'application/json', contentType),
9
+ throw new ValidationError([
10
+ new Issue('invalidContentType', [], 'application/json', contentType),
14
11
  ]);
15
12
  }
16
13
  const data = buffer.length > 0 ? JSON.parse(Buffer.from(buffer).toString('utf8')) : {};
@@ -30,4 +27,3 @@ class Schema extends body_1.BodyType {
30
27
  return false;
31
28
  }
32
29
  }
33
- exports.Schema = Schema;
@@ -1,4 +1,4 @@
1
- import { ModifiableSchema } from './modifiable';
1
+ import { ModifiableSchema } from './modifiable.js';
2
2
  declare class StringSchema extends ModifiableSchema<string> {
3
3
  /**
4
4
  * Require the string to match the specified pattern.
@@ -1,9 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.string = void 0;
4
- const error_1 = require("./error");
5
- const modifiable_1 = require("./modifiable");
6
- class StringSchema extends modifiable_1.ModifiableSchema {
1
+ import { Issue, ValidationError } from './error.js';
2
+ import { ModifiableSchema } from './modifiable.js';
3
+ class StringSchema extends ModifiableSchema {
7
4
  /**
8
5
  * Require the string to match the specified pattern.
9
6
  * @param pattern - A regular expression.
@@ -13,8 +10,8 @@ class StringSchema extends modifiable_1.ModifiableSchema {
13
10
  }
14
11
  parse(obj) {
15
12
  if (typeof obj !== 'string') {
16
- throw new error_1.ValidationError([
17
- new error_1.Issue('invalidType', [], 'string', typeof obj),
13
+ throw new ValidationError([
14
+ new Issue('invalidType', [], 'string', typeof obj),
18
15
  ]);
19
16
  }
20
17
  return obj;
@@ -25,20 +22,20 @@ class StringSchema extends modifiable_1.ModifiableSchema {
25
22
  };
26
23
  }
27
24
  }
28
- class PatternStringSchema extends modifiable_1.ModifiableSchema {
25
+ class PatternStringSchema extends ModifiableSchema {
29
26
  constructor(pattern) {
30
27
  super();
31
28
  this.pattern = pattern;
32
29
  }
33
30
  parse(obj) {
34
31
  if (typeof obj !== 'string') {
35
- throw new error_1.ValidationError([
36
- new error_1.Issue('invalidType', [], 'string', typeof obj),
32
+ throw new ValidationError([
33
+ new Issue('invalidType', [], 'string', typeof obj),
37
34
  ]);
38
35
  }
39
36
  if (!obj.match(this.pattern)) {
40
- throw new error_1.ValidationError([
41
- new error_1.Issue('invalidPattern', [], this.pattern.source, obj),
37
+ throw new ValidationError([
38
+ new Issue('invalidPattern', [], this.pattern.source, obj),
42
39
  ]);
43
40
  }
44
41
  return obj;
@@ -53,5 +50,4 @@ class PatternStringSchema extends modifiable_1.ModifiableSchema {
53
50
  /**
54
51
  * A schema matching a string.
55
52
  */
56
- const string = () => new StringSchema();
57
- exports.string = string;
53
+ export const string = () => new StringSchema();
@@ -1,4 +1,4 @@
1
- import { Schema } from './schema';
1
+ import { Schema } from './schema.js';
2
2
  export declare class UndefinedSchema extends Schema<undefined> {
3
3
  parse(obj: unknown): undefined;
4
4
  documentation(): object;
@@ -1,15 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports._undefined = exports.UndefinedSchema = void 0;
4
- const error_1 = require("./error");
5
- const schema_1 = require("./schema");
6
- class UndefinedSchema extends schema_1.Schema {
1
+ import { Issue, ValidationError } from './error.js';
2
+ import { Schema } from './schema.js';
3
+ export class UndefinedSchema extends Schema {
7
4
  parse(obj) {
8
5
  if (obj === undefined) {
9
6
  return undefined;
10
7
  }
11
- throw new error_1.ValidationError([
12
- new error_1.Issue('invalidType', [], 'undefined', typeof obj),
8
+ throw new ValidationError([
9
+ new Issue('invalidType', [], 'undefined', typeof obj),
13
10
  ]);
14
11
  }
15
12
  documentation() {
@@ -18,9 +15,7 @@ class UndefinedSchema extends schema_1.Schema {
18
15
  };
19
16
  }
20
17
  }
21
- exports.UndefinedSchema = UndefinedSchema;
22
18
  /**
23
19
  * A schema that matches only undefined.
24
20
  */
25
- const _undefined = () => new UndefinedSchema();
26
- exports._undefined = _undefined;
21
+ export const _undefined = () => new UndefinedSchema();
@@ -1,5 +1,5 @@
1
- import { ModifiableSchema } from './modifiable';
2
- import type { Schema } from './schema';
1
+ import { ModifiableSchema } from './modifiable.js';
2
+ import type { Schema } from './schema.js';
3
3
  declare class UnionSchema<T extends [...Schema<unknown>[]]> extends ModifiableSchema<T[number]['_typeof']> {
4
4
  private readonly options;
5
5
  constructor(options: T);
@@ -1,9 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.union = void 0;
4
- const error_1 = require("./error");
5
- const modifiable_1 = require("./modifiable");
6
- class UnionSchema extends modifiable_1.ModifiableSchema {
1
+ import { ValidationError } from './error.js';
2
+ import { ModifiableSchema } from './modifiable.js';
3
+ class UnionSchema extends ModifiableSchema {
7
4
  constructor(options) {
8
5
  super();
9
6
  this.options = options;
@@ -15,7 +12,7 @@ class UnionSchema extends modifiable_1.ModifiableSchema {
15
12
  return option.parse(obj);
16
13
  }
17
14
  catch (error) {
18
- if (error instanceof error_1.ValidationError) {
15
+ if (error instanceof ValidationError) {
19
16
  issues.push(...error.issues);
20
17
  }
21
18
  else {
@@ -23,7 +20,7 @@ class UnionSchema extends modifiable_1.ModifiableSchema {
23
20
  }
24
21
  }
25
22
  }
26
- throw new error_1.ValidationError(issues);
23
+ throw new ValidationError(issues);
27
24
  }
28
25
  documentation() {
29
26
  return {
@@ -36,5 +33,4 @@ class UnionSchema extends modifiable_1.ModifiableSchema {
36
33
  * expect that this requires real schemas instead of just strings or numbers.
37
34
  * @param options - The different possible schemas.
38
35
  */
39
- const union = (...options) => new UnionSchema(options);
40
- exports.union = union;
36
+ export const union = (...options) => new UnionSchema(options);
@@ -1,4 +1,4 @@
1
- import { ModifiableSchema } from './modifiable';
1
+ import { ModifiableSchema } from './modifiable.js';
2
2
  declare class UnknownSchema extends ModifiableSchema<unknown> {
3
3
  parse(obj: unknown): unknown;
4
4
  documentation(): object;
@@ -1,8 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.unknown = void 0;
4
- const modifiable_1 = require("./modifiable");
5
- class UnknownSchema extends modifiable_1.ModifiableSchema {
1
+ import { ModifiableSchema } from './modifiable.js';
2
+ class UnknownSchema extends ModifiableSchema {
6
3
  parse(obj) {
7
4
  return obj;
8
5
  }
@@ -15,5 +12,4 @@ class UnknownSchema extends modifiable_1.ModifiableSchema {
15
12
  /**
16
13
  * A schema matching anything.
17
14
  */
18
- const unknown = () => new UnknownSchema();
19
- exports.unknown = unknown;
15
+ export const unknown = () => new UnknownSchema();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yedra",
3
- "version": "0.9.2",
3
+ "version": "0.9.4",
4
4
  "repository": "github:0codekit/yedra",
5
5
  "main": "dist/index.js",
6
6
  "devDependencies": {
@@ -19,7 +19,8 @@
19
19
  "check": "biome check src/*"
20
20
  },
21
21
  "types": "dist/index.d.ts",
22
+ "type": "module",
22
23
  "dependencies": {
23
- "glob": "^10.4.5"
24
+ "glob": "^11.0.0"
24
25
  }
25
26
  }