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.
- package/README.md +16 -50
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -5
- package/dist/lib.d.ts +27 -27
- package/dist/lib.js +29 -67
- package/dist/routing/app.d.ts +2 -2
- package/dist/routing/app.js +33 -50
- package/dist/routing/endpoint.d.ts +5 -5
- package/dist/routing/endpoint.js +50 -65
- package/dist/routing/env.d.ts +2 -2
- package/dist/routing/env.js +3 -7
- package/dist/routing/errors.js +7 -17
- package/dist/routing/http.d.ts +1 -1
- package/dist/routing/http.js +34 -53
- package/dist/routing/listen.d.ts +1 -1
- package/dist/routing/listen.js +20 -36
- package/dist/routing/log.js +1 -5
- package/dist/routing/path.js +1 -5
- package/dist/routing/route.d.ts +8 -7
- package/dist/routing/route.js +58 -70
- package/dist/routing/test.d.ts +2 -2
- package/dist/routing/test.js +52 -64
- package/dist/validation/array.d.ts +3 -3
- package/dist/validation/array.js +12 -16
- package/dist/validation/body.js +1 -5
- package/dist/validation/boolean.d.ts +1 -1
- package/dist/validation/boolean.js +6 -10
- package/dist/validation/date.d.ts +1 -1
- package/dist/validation/date.js +8 -12
- package/dist/validation/doc.d.ts +1 -1
- package/dist/validation/doc.js +7 -7
- package/dist/validation/either.d.ts +1 -1
- package/dist/validation/either.js +7 -11
- package/dist/validation/enum.d.ts +1 -1
- package/dist/validation/enum.js +6 -10
- package/dist/validation/error.js +4 -9
- package/dist/validation/intersection.d.ts +2 -2
- package/dist/validation/intersection.js +8 -13
- package/dist/validation/modifiable.d.ts +2 -2
- package/dist/validation/modifiable.js +6 -10
- package/dist/validation/none.d.ts +1 -1
- package/dist/validation/none.js +3 -8
- package/dist/validation/number.d.ts +1 -1
- package/dist/validation/number.js +12 -16
- package/dist/validation/object.d.ts +3 -3
- package/dist/validation/object.js +14 -19
- package/dist/validation/raw.d.ts +1 -1
- package/dist/validation/raw.js +4 -8
- package/dist/validation/record.d.ts +3 -3
- package/dist/validation/record.js +8 -12
- package/dist/validation/schema.d.ts +1 -1
- package/dist/validation/schema.js +5 -9
- package/dist/validation/string.d.ts +1 -1
- package/dist/validation/string.js +11 -15
- package/dist/validation/undefined.d.ts +1 -1
- package/dist/validation/undefined.js +6 -11
- package/dist/validation/union.d.ts +2 -2
- package/dist/validation/union.js +6 -10
- package/dist/validation/unknown.d.ts +1 -1
- package/dist/validation/unknown.js +3 -7
- package/package.json +3 -2
package/dist/routing/test.js
CHANGED
|
@@ -1,75 +1,63 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.TestService = void 0;
|
|
13
|
-
const types_1 = require("node:util/types");
|
|
14
|
-
const app_1 = require("./app");
|
|
15
|
-
const http_1 = require("./http");
|
|
16
|
-
const log_1 = require("./log");
|
|
17
|
-
class TestService {
|
|
1
|
+
import { isUint8Array } from 'node:util/types';
|
|
2
|
+
import { App } from './app.js';
|
|
3
|
+
import { Http, HttpRequestError, HttpResponse } from './http.js';
|
|
4
|
+
import { Log } from './log.js';
|
|
5
|
+
export class TestService {
|
|
18
6
|
constructor(target, headers) {
|
|
19
7
|
this.target = target;
|
|
20
8
|
this.headers = headers;
|
|
21
|
-
const log = new
|
|
22
|
-
this.http = new
|
|
9
|
+
const log = new Log();
|
|
10
|
+
this.http = new Http(log);
|
|
23
11
|
}
|
|
24
|
-
get(path, headers) {
|
|
25
|
-
return
|
|
26
|
-
return yield this.request('GET', path, undefined, headers);
|
|
27
|
-
});
|
|
12
|
+
async get(path, headers) {
|
|
13
|
+
return await this.request('GET', path, undefined, headers);
|
|
28
14
|
}
|
|
29
|
-
post(path, body, headers) {
|
|
30
|
-
return
|
|
31
|
-
return yield this.request('POST', path, body, headers);
|
|
32
|
-
});
|
|
15
|
+
async post(path, body, headers) {
|
|
16
|
+
return await this.request('POST', path, body, headers);
|
|
33
17
|
}
|
|
34
|
-
request(method, path, body, headers) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
if (body) {
|
|
41
|
-
|
|
42
|
-
buffer = Buffer.from(body);
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
buffer = Buffer.from(JSON.stringify(body), 'utf-8');
|
|
46
|
-
contentHeader = { 'content-type': 'application/json' };
|
|
47
|
-
}
|
|
18
|
+
async request(method, path, body, headers) {
|
|
19
|
+
if (this.target instanceof App) {
|
|
20
|
+
// test local server
|
|
21
|
+
let buffer;
|
|
22
|
+
let contentHeader = {};
|
|
23
|
+
if (body) {
|
|
24
|
+
if (isUint8Array(body)) {
|
|
25
|
+
buffer = Buffer.from(body);
|
|
48
26
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
url: path,
|
|
53
|
-
query: {},
|
|
54
|
-
body: buffer !== null && buffer !== void 0 ? buffer : Buffer.from(''),
|
|
55
|
-
headers: Object.assign(Object.assign(Object.assign({}, headers), contentHeader), this.headers),
|
|
56
|
-
});
|
|
57
|
-
return new http_1.HttpResponse(response.status, response.headers, response.body);
|
|
58
|
-
}
|
|
59
|
-
// test remote server
|
|
60
|
-
try {
|
|
61
|
-
return yield this.http.request(method, this.target + path, body, Object.assign(Object.assign({}, this.headers), headers));
|
|
62
|
-
}
|
|
63
|
-
catch (error) {
|
|
64
|
-
if (error instanceof http_1.HttpRequestError && error.response) {
|
|
65
|
-
// return response even on errors
|
|
66
|
-
return error.response;
|
|
27
|
+
else {
|
|
28
|
+
buffer = Buffer.from(JSON.stringify(body), 'utf-8');
|
|
29
|
+
contentHeader = { 'content-type': 'application/json' };
|
|
67
30
|
}
|
|
68
|
-
// non-HTTP error, doesn't make sense to run other tests
|
|
69
|
-
console.error(`Could not connect to ${this.target}. Make sure the server is running and reachable.`);
|
|
70
|
-
process.exit(1);
|
|
71
31
|
}
|
|
72
|
-
|
|
32
|
+
// TODO: extract query parameters
|
|
33
|
+
const response = await this.target.handle({
|
|
34
|
+
method,
|
|
35
|
+
url: path,
|
|
36
|
+
query: {},
|
|
37
|
+
body: buffer ?? Buffer.from(''),
|
|
38
|
+
headers: {
|
|
39
|
+
...headers,
|
|
40
|
+
...contentHeader,
|
|
41
|
+
...this.headers,
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
return new HttpResponse(response.status, response.headers, response.body);
|
|
45
|
+
}
|
|
46
|
+
// test remote server
|
|
47
|
+
try {
|
|
48
|
+
return await this.http.request(method, this.target + path, body, {
|
|
49
|
+
...this.headers,
|
|
50
|
+
...headers,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
if (error instanceof HttpRequestError && error.response) {
|
|
55
|
+
// return response even on errors
|
|
56
|
+
return error.response;
|
|
57
|
+
}
|
|
58
|
+
// non-HTTP error, doesn't make sense to run other tests
|
|
59
|
+
console.error(`Could not connect to ${this.target}. Make sure the server is running and reachable.`);
|
|
60
|
+
process.exit(1);
|
|
61
|
+
}
|
|
73
62
|
}
|
|
74
63
|
}
|
|
75
|
-
exports.TestService = TestService;
|
|
@@ -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 ArraySchema<ItemSchema extends Schema<unknown>> extends ModifiableSchema<Typeof<ItemSchema>[]> {
|
|
5
5
|
private readonly itemSchema;
|
|
6
6
|
private readonly minItems?;
|
package/dist/validation/array.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const error_1 = require("./error");
|
|
5
|
-
const modifiable_1 = require("./modifiable");
|
|
6
|
-
class ArraySchema extends modifiable_1.ModifiableSchema {
|
|
1
|
+
import { Issue, ValidationError } from './error.js';
|
|
2
|
+
import { ModifiableSchema } from './modifiable.js';
|
|
3
|
+
class ArraySchema extends ModifiableSchema {
|
|
7
4
|
constructor(itemSchema, minItems, maxItems) {
|
|
8
5
|
super();
|
|
9
6
|
this.itemSchema = itemSchema;
|
|
@@ -34,18 +31,18 @@ class ArraySchema extends modifiable_1.ModifiableSchema {
|
|
|
34
31
|
}
|
|
35
32
|
parse(obj) {
|
|
36
33
|
if (!Array.isArray(obj)) {
|
|
37
|
-
throw new
|
|
38
|
-
new
|
|
34
|
+
throw new ValidationError([
|
|
35
|
+
new Issue('invalidType', [], 'array', typeof obj),
|
|
39
36
|
]);
|
|
40
37
|
}
|
|
41
38
|
if (this.minItems && obj.length < this.minItems) {
|
|
42
|
-
throw new
|
|
43
|
-
new
|
|
39
|
+
throw new ValidationError([
|
|
40
|
+
new Issue('tooShort', [], this.minItems.toString(), obj.length.toString()),
|
|
44
41
|
]);
|
|
45
42
|
}
|
|
46
43
|
if (this.maxItems && obj.length > this.maxItems) {
|
|
47
|
-
throw new
|
|
48
|
-
new
|
|
44
|
+
throw new ValidationError([
|
|
45
|
+
new Issue('tooLong', [], this.maxItems.toString(), obj.length.toString()),
|
|
49
46
|
]);
|
|
50
47
|
}
|
|
51
48
|
const elems = [];
|
|
@@ -55,7 +52,7 @@ class ArraySchema extends modifiable_1.ModifiableSchema {
|
|
|
55
52
|
elems.push(this.itemSchema.parse(obj[i]));
|
|
56
53
|
}
|
|
57
54
|
catch (error) {
|
|
58
|
-
if (error instanceof
|
|
55
|
+
if (error instanceof ValidationError) {
|
|
59
56
|
issues.push(...error.withPrefix(i.toString()));
|
|
60
57
|
}
|
|
61
58
|
else {
|
|
@@ -64,7 +61,7 @@ class ArraySchema extends modifiable_1.ModifiableSchema {
|
|
|
64
61
|
}
|
|
65
62
|
}
|
|
66
63
|
if (issues.length > 0) {
|
|
67
|
-
throw new
|
|
64
|
+
throw new ValidationError(issues);
|
|
68
65
|
}
|
|
69
66
|
return elems;
|
|
70
67
|
}
|
|
@@ -81,5 +78,4 @@ class ArraySchema extends modifiable_1.ModifiableSchema {
|
|
|
81
78
|
* A schema matching arrays of the provided item type.
|
|
82
79
|
* @param itemSchema - The schema for array items.
|
|
83
80
|
*/
|
|
84
|
-
const array = (itemSchema) => new ArraySchema(itemSchema);
|
|
85
|
-
exports.array = array;
|
|
81
|
+
export const array = (itemSchema) => new ArraySchema(itemSchema);
|
package/dist/validation/body.js
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BodyType = void 0;
|
|
4
1
|
/**
|
|
5
2
|
* The base class for all body types.
|
|
6
3
|
*/
|
|
7
|
-
class BodyType {
|
|
4
|
+
export class BodyType {
|
|
8
5
|
constructor() {
|
|
9
6
|
this._typeof = undefined;
|
|
10
7
|
}
|
|
11
8
|
}
|
|
12
|
-
exports.BodyType = BodyType;
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const error_1 = require("./error");
|
|
5
|
-
const modifiable_1 = require("./modifiable");
|
|
6
|
-
class BooleanSchema extends modifiable_1.ModifiableSchema {
|
|
1
|
+
import { Issue, ValidationError } from './error.js';
|
|
2
|
+
import { ModifiableSchema } from './modifiable.js';
|
|
3
|
+
class BooleanSchema extends ModifiableSchema {
|
|
7
4
|
parse(obj) {
|
|
8
5
|
if (typeof obj !== 'boolean') {
|
|
9
|
-
throw new
|
|
10
|
-
new
|
|
6
|
+
throw new ValidationError([
|
|
7
|
+
new Issue('invalidType', [], 'boolean', typeof obj),
|
|
11
8
|
]);
|
|
12
9
|
}
|
|
13
10
|
return obj;
|
|
@@ -21,5 +18,4 @@ class BooleanSchema extends modifiable_1.ModifiableSchema {
|
|
|
21
18
|
/**
|
|
22
19
|
* A schema matching any boolean.
|
|
23
20
|
*/
|
|
24
|
-
const boolean = () => new BooleanSchema();
|
|
25
|
-
exports.boolean = boolean;
|
|
21
|
+
export const boolean = () => new BooleanSchema();
|
package/dist/validation/date.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const error_1 = require("./error");
|
|
6
|
-
const modifiable_1 = require("./modifiable");
|
|
7
|
-
class DateSchema extends modifiable_1.ModifiableSchema {
|
|
1
|
+
import { isDate } from 'node:util/types';
|
|
2
|
+
import { Issue, ValidationError } from './error.js';
|
|
3
|
+
import { ModifiableSchema } from './modifiable.js';
|
|
4
|
+
class DateSchema extends ModifiableSchema {
|
|
8
5
|
parse(obj) {
|
|
9
|
-
if (
|
|
6
|
+
if (isDate(obj)) {
|
|
10
7
|
return obj;
|
|
11
8
|
}
|
|
12
9
|
if (typeof obj === 'string' || typeof obj === 'number') {
|
|
@@ -15,8 +12,8 @@ class DateSchema extends modifiable_1.ModifiableSchema {
|
|
|
15
12
|
return date;
|
|
16
13
|
}
|
|
17
14
|
}
|
|
18
|
-
throw new
|
|
19
|
-
new
|
|
15
|
+
throw new ValidationError([
|
|
16
|
+
new Issue('invalidType', [], 'date', typeof obj),
|
|
20
17
|
]);
|
|
21
18
|
}
|
|
22
19
|
documentation() {
|
|
@@ -30,5 +27,4 @@ class DateSchema extends modifiable_1.ModifiableSchema {
|
|
|
30
27
|
* A schema matching date objects, or strings and numbers that can be
|
|
31
28
|
* interpreted as dates.
|
|
32
29
|
*/
|
|
33
|
-
const date = () => new DateSchema();
|
|
34
|
-
exports.date = date;
|
|
30
|
+
export const date = () => new DateSchema();
|
package/dist/validation/doc.d.ts
CHANGED
package/dist/validation/doc.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.DocSchema = void 0;
|
|
4
|
-
const schema_1 = require("./schema");
|
|
5
|
-
class DocSchema extends schema_1.Schema {
|
|
1
|
+
import { Schema } from './schema.js';
|
|
2
|
+
export class DocSchema extends Schema {
|
|
6
3
|
constructor(schema, description, example) {
|
|
7
4
|
super();
|
|
8
5
|
this._schema = schema;
|
|
@@ -13,10 +10,13 @@ class DocSchema extends schema_1.Schema {
|
|
|
13
10
|
return this._schema.parse(obj);
|
|
14
11
|
}
|
|
15
12
|
documentation() {
|
|
16
|
-
return
|
|
13
|
+
return {
|
|
14
|
+
description: this._description,
|
|
15
|
+
example: this._example,
|
|
16
|
+
...this._schema.documentation(),
|
|
17
|
+
};
|
|
17
18
|
}
|
|
18
19
|
isOptional() {
|
|
19
20
|
return this._schema.isOptional();
|
|
20
21
|
}
|
|
21
22
|
}
|
|
22
|
-
exports.DocSchema = DocSchema;
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const body_1 = require("./body");
|
|
5
|
-
const error_1 = require("./error");
|
|
6
|
-
class EitherBody extends body_1.BodyType {
|
|
1
|
+
import { BodyType } from './body.js';
|
|
2
|
+
import { ValidationError } from './error.js';
|
|
3
|
+
class EitherBody extends BodyType {
|
|
7
4
|
constructor(options) {
|
|
8
5
|
super();
|
|
9
6
|
this.options = options;
|
|
@@ -15,7 +12,7 @@ class EitherBody extends body_1.BodyType {
|
|
|
15
12
|
return option.deserialize(buffer, contentType);
|
|
16
13
|
}
|
|
17
14
|
catch (error) {
|
|
18
|
-
if (error instanceof
|
|
15
|
+
if (error instanceof ValidationError) {
|
|
19
16
|
issues.push(...error.issues);
|
|
20
17
|
}
|
|
21
18
|
else {
|
|
@@ -23,12 +20,12 @@ class EitherBody extends body_1.BodyType {
|
|
|
23
20
|
}
|
|
24
21
|
}
|
|
25
22
|
}
|
|
26
|
-
throw new
|
|
23
|
+
throw new ValidationError(issues);
|
|
27
24
|
}
|
|
28
25
|
bodyDocs() {
|
|
29
26
|
let docs = {};
|
|
30
27
|
for (const option of this.options) {
|
|
31
|
-
docs =
|
|
28
|
+
docs = { ...docs, ...option.bodyDocs() };
|
|
32
29
|
}
|
|
33
30
|
return docs;
|
|
34
31
|
}
|
|
@@ -38,5 +35,4 @@ class EitherBody extends body_1.BodyType {
|
|
|
38
35
|
* @param options
|
|
39
36
|
* @returns
|
|
40
37
|
*/
|
|
41
|
-
const either = (...options) => new EitherBody(options);
|
|
42
|
-
exports.either = either;
|
|
38
|
+
export const either = (...options) => new EitherBody(options);
|
package/dist/validation/enum.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const error_1 = require("./error");
|
|
5
|
-
const modifiable_1 = require("./modifiable");
|
|
6
|
-
class EnumSchema extends modifiable_1.ModifiableSchema {
|
|
1
|
+
import { Issue, ValidationError } from './error.js';
|
|
2
|
+
import { ModifiableSchema } from './modifiable.js';
|
|
3
|
+
class EnumSchema extends ModifiableSchema {
|
|
7
4
|
constructor(options) {
|
|
8
5
|
super();
|
|
9
6
|
this.options = options;
|
|
@@ -12,9 +9,9 @@ class EnumSchema extends modifiable_1.ModifiableSchema {
|
|
|
12
9
|
if (!obj ||
|
|
13
10
|
(typeof obj !== 'string' && typeof obj !== 'number') ||
|
|
14
11
|
!this.options.includes(obj)) {
|
|
15
|
-
throw new
|
|
12
|
+
throw new ValidationError([
|
|
16
13
|
// TODO: better validation message
|
|
17
|
-
new
|
|
14
|
+
new Issue('invalidType', [], this.options.join(', '), typeof obj === 'string' || typeof obj === 'number'
|
|
18
15
|
? obj.toString()
|
|
19
16
|
: typeof obj),
|
|
20
17
|
]);
|
|
@@ -38,5 +35,4 @@ class EnumSchema extends modifiable_1.ModifiableSchema {
|
|
|
38
35
|
* type OptionsType = y.Typeof<typeof options>; // 3 | 4 | 'hello'
|
|
39
36
|
* ```
|
|
40
37
|
*/
|
|
41
|
-
const _enum = (...options) => new EnumSchema(options);
|
|
42
|
-
exports._enum = _enum;
|
|
38
|
+
export const _enum = (...options) => new EnumSchema(options);
|
package/dist/validation/error.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ValidationError = exports.Issue = void 0;
|
|
4
1
|
const issueMessages = {
|
|
5
2
|
invalidType: "Expected '${expected}' but got '${actual}'",
|
|
6
3
|
tooSmall: "Must be at least '${expected}' but was '${actual}'",
|
|
@@ -11,7 +8,7 @@ const issueMessages = {
|
|
|
11
8
|
missingProperty: 'Required',
|
|
12
9
|
invalidContentType: "Expected content type '${expected}' but got '${actual}'",
|
|
13
10
|
};
|
|
14
|
-
class Issue {
|
|
11
|
+
export class Issue {
|
|
15
12
|
constructor(code, path, expected, actual) {
|
|
16
13
|
this.code = code;
|
|
17
14
|
this.path = path;
|
|
@@ -19,13 +16,12 @@ class Issue {
|
|
|
19
16
|
this.actual = actual;
|
|
20
17
|
}
|
|
21
18
|
format(messages) {
|
|
22
|
-
return (messages
|
|
19
|
+
return (messages ?? issueMessages)[this.code]
|
|
23
20
|
.replace('${expected}', this.expected)
|
|
24
21
|
.replace('${actual}', this.actual);
|
|
25
22
|
}
|
|
26
23
|
}
|
|
27
|
-
|
|
28
|
-
class ValidationError extends Error {
|
|
24
|
+
export class ValidationError extends Error {
|
|
29
25
|
constructor(issues) {
|
|
30
26
|
super(ValidationError.formatIssues(issues));
|
|
31
27
|
this.issues = issues;
|
|
@@ -49,9 +45,8 @@ class ValidationError extends Error {
|
|
|
49
45
|
static formatIssues(issues, messages) {
|
|
50
46
|
const formattedIssues = [];
|
|
51
47
|
for (const issue of issues) {
|
|
52
|
-
formattedIssues.push(`Error at '${issue.path.join('.')}': ${issue.format(messages
|
|
48
|
+
formattedIssues.push(`Error at '${issue.path.join('.')}': ${issue.format(messages ?? issueMessages)}.`);
|
|
53
49
|
}
|
|
54
50
|
return formattedIssues.join(' ');
|
|
55
51
|
}
|
|
56
52
|
}
|
|
57
|
-
exports.ValidationError = ValidationError;
|
|
@@ -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
|
export declare class IntersectionSchema<T, U> extends ModifiableSchema<T & U> {
|
|
4
4
|
private left;
|
|
5
5
|
private right;
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const error_1 = require("./error");
|
|
5
|
-
const modifiable_1 = require("./modifiable");
|
|
6
|
-
class IntersectionSchema extends modifiable_1.ModifiableSchema {
|
|
1
|
+
import { ValidationError } from './error.js';
|
|
2
|
+
import { ModifiableSchema } from './modifiable.js';
|
|
3
|
+
export class IntersectionSchema extends ModifiableSchema {
|
|
7
4
|
constructor(left, right) {
|
|
8
5
|
super();
|
|
9
6
|
this.left = left;
|
|
@@ -17,7 +14,7 @@ class IntersectionSchema extends modifiable_1.ModifiableSchema {
|
|
|
17
14
|
left = this.left.parse(obj);
|
|
18
15
|
}
|
|
19
16
|
catch (error) {
|
|
20
|
-
if (error instanceof
|
|
17
|
+
if (error instanceof ValidationError) {
|
|
21
18
|
issues.push(...error.issues);
|
|
22
19
|
}
|
|
23
20
|
else {
|
|
@@ -28,7 +25,7 @@ class IntersectionSchema extends modifiable_1.ModifiableSchema {
|
|
|
28
25
|
right = this.right.parse(obj);
|
|
29
26
|
}
|
|
30
27
|
catch (error) {
|
|
31
|
-
if (error instanceof
|
|
28
|
+
if (error instanceof ValidationError) {
|
|
32
29
|
issues.push(...error.issues);
|
|
33
30
|
}
|
|
34
31
|
else {
|
|
@@ -36,9 +33,9 @@ class IntersectionSchema extends modifiable_1.ModifiableSchema {
|
|
|
36
33
|
}
|
|
37
34
|
}
|
|
38
35
|
if (!(left && right)) {
|
|
39
|
-
throw new
|
|
36
|
+
throw new ValidationError(issues);
|
|
40
37
|
}
|
|
41
|
-
return
|
|
38
|
+
return { ...left, ...right };
|
|
42
39
|
}
|
|
43
40
|
documentation() {
|
|
44
41
|
return {
|
|
@@ -46,11 +43,9 @@ class IntersectionSchema extends modifiable_1.ModifiableSchema {
|
|
|
46
43
|
};
|
|
47
44
|
}
|
|
48
45
|
}
|
|
49
|
-
exports.IntersectionSchema = IntersectionSchema;
|
|
50
46
|
/**
|
|
51
47
|
* A schema that only matches values that match both base schemas.
|
|
52
48
|
* @param schema0 - The first schema.
|
|
53
49
|
* @param schema1 - The second schema.
|
|
54
50
|
*/
|
|
55
|
-
const intersection = (schema0, schema1) => new IntersectionSchema(schema0, schema1);
|
|
56
|
-
exports.intersection = intersection;
|
|
51
|
+
export const intersection = (schema0, schema1) => new IntersectionSchema(schema0, schema1);
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const doc_1 = require("./doc");
|
|
5
|
-
const schema_1 = require("./schema");
|
|
6
|
-
class ModifiableSchema extends schema_1.Schema {
|
|
1
|
+
import { DocSchema } from './doc.js';
|
|
2
|
+
import { Schema } from './schema.js';
|
|
3
|
+
export class ModifiableSchema extends Schema {
|
|
7
4
|
/**
|
|
8
5
|
* Mark this schema as optional.
|
|
9
6
|
*/
|
|
@@ -15,11 +12,10 @@ class ModifiableSchema extends schema_1.Schema {
|
|
|
15
12
|
* @param doc - The documentation.
|
|
16
13
|
*/
|
|
17
14
|
doc(doc) {
|
|
18
|
-
return new
|
|
15
|
+
return new DocSchema(this, doc.description, doc.example);
|
|
19
16
|
}
|
|
20
17
|
}
|
|
21
|
-
|
|
22
|
-
class OptionalSchema extends schema_1.Schema {
|
|
18
|
+
class OptionalSchema extends Schema {
|
|
23
19
|
constructor(schema) {
|
|
24
20
|
super();
|
|
25
21
|
this.schema = schema;
|
|
@@ -29,7 +25,7 @@ class OptionalSchema extends schema_1.Schema {
|
|
|
29
25
|
* @param doc - The documentation.
|
|
30
26
|
*/
|
|
31
27
|
doc(doc) {
|
|
32
|
-
return new
|
|
28
|
+
return new DocSchema(this, doc.description, doc.example);
|
|
33
29
|
}
|
|
34
30
|
parse(obj) {
|
|
35
31
|
if (obj === undefined) {
|
package/dist/validation/none.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.none = exports.NoneBody = void 0;
|
|
4
|
-
const body_1 = require("./body");
|
|
5
|
-
class NoneBody extends body_1.BodyType {
|
|
1
|
+
import { BodyType } from './body.js';
|
|
2
|
+
export class NoneBody extends BodyType {
|
|
6
3
|
deserialize(buffer, contentType) {
|
|
7
4
|
return;
|
|
8
5
|
}
|
|
@@ -11,9 +8,7 @@ class NoneBody extends body_1.BodyType {
|
|
|
11
8
|
return {};
|
|
12
9
|
}
|
|
13
10
|
}
|
|
14
|
-
exports.NoneBody = NoneBody;
|
|
15
11
|
/**
|
|
16
12
|
* Accepts no input body.
|
|
17
13
|
*/
|
|
18
|
-
const none = () => new NoneBody();
|
|
19
|
-
exports.none = none;
|
|
14
|
+
export const none = () => new NoneBody();
|