@croct/sdk 0.10.0 → 0.11.0-alpha
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/activeRecord.js +32 -36
- package/cache/fallbackCache.js +15 -32
- package/cache/inMemoryCache.js +9 -10
- package/cache/index.js +1 -1
- package/cache/localStorageCache.js +24 -25
- package/channel/beaconSocketChannel.d.ts +1 -1
- package/channel/beaconSocketChannel.js +49 -79
- package/channel/channel.d.ts +1 -1
- package/channel/encodedChannel.js +8 -10
- package/channel/guaranteedChannel.d.ts +4 -4
- package/channel/guaranteedChannel.js +41 -43
- package/channel/index.js +1 -1
- package/channel/queuedChannel.js +35 -64
- package/channel/retryChannel.d.ts +1 -1
- package/channel/retryChannel.js +44 -77
- package/channel/sandboxChannel.js +17 -18
- package/channel/socketChannel.d.ts +4 -4
- package/channel/socketChannel.js +77 -79
- package/cid/cachedAssigner.js +15 -27
- package/cid/fixedAssigner.js +5 -6
- package/cid/index.js +1 -1
- package/cid/remoteAssigner.js +23 -36
- package/constants.d.ts +3 -2
- package/constants.js +6 -5
- package/container.d.ts +13 -6
- package/container.js +152 -168
- package/contentFetcher.d.ts +59 -0
- package/contentFetcher.js +129 -0
- package/context.d.ts +3 -3
- package/context.js +36 -38
- package/error.js +2 -2
- package/evaluator.d.ts +33 -24
- package/evaluator.js +126 -117
- package/eventManager.d.ts +1 -1
- package/eventManager.js +14 -15
- package/facade/contentFetcherFacade.d.ts +27 -0
- package/facade/contentFetcherFacade.js +40 -0
- package/facade/evaluatorFacade.d.ts +13 -3
- package/facade/evaluatorFacade.js +57 -72
- package/facade/sdkFacade.d.ts +10 -3
- package/facade/sdkFacade.js +129 -141
- package/facade/sessionFacade.js +6 -7
- package/facade/sessionPatch.js +9 -13
- package/facade/trackerFacade.js +32 -38
- package/facade/userFacade.js +10 -11
- package/facade/userPatch.js +9 -13
- package/index.js +2 -2
- package/logging/consoleLogger.js +18 -35
- package/logging/index.js +1 -1
- package/logging/namespacedLogger.js +14 -15
- package/logging/nullLogger.js +10 -13
- package/namespacedStorage.js +30 -47
- package/package.json +13 -16
- package/patch.d.ts +1 -1
- package/queue/capacityRestrictedQueue.js +17 -18
- package/queue/inMemoryQueue.js +22 -28
- package/queue/index.js +1 -1
- package/queue/monitoredQueue.d.ts +2 -2
- package/queue/monitoredQueue.js +39 -40
- package/queue/persistentQueue.js +33 -38
- package/retry/arbitraryPolicy.js +8 -10
- package/retry/backoffPolicy.d.ts +1 -1
- package/retry/backoffPolicy.js +11 -13
- package/retry/index.js +1 -1
- package/retry/maxAttemptsPolicy.js +7 -8
- package/retry/neverPolicy.js +6 -9
- package/schema/attributeSchema.js +1 -1
- package/schema/contentFetcherSchemas.d.ts +2 -0
- package/schema/contentFetcherSchemas.js +22 -0
- package/schema/contentSchemas.js +1 -1
- package/schema/contextSchemas.js +1 -1
- package/schema/ecommerceSchemas.js +1 -1
- package/schema/evaluatorSchemas.d.ts +2 -0
- package/schema/{evaluationSchemas.js → evaluatorSchemas.js} +3 -3
- package/schema/eventSchemas.js +5 -7
- package/schema/index.d.ts +2 -1
- package/schema/index.js +3 -2
- package/schema/loggerSchema.js +1 -1
- package/schema/operationSchemas.js +8 -8
- package/schema/sdkFacadeSchemas.js +9 -6
- package/schema/sdkSchemas.js +8 -5
- package/schema/tokenSchema.js +5 -4
- package/schema/userSchema.js +2 -2
- package/sdk.d.ts +9 -3
- package/sdk.js +81 -127
- package/sdkEvents.d.ts +3 -3
- package/sourceLocation.d.ts +3 -3
- package/sourceLocation.js +13 -14
- package/tab.d.ts +5 -5
- package/tab.js +50 -80
- package/token/cachedTokenStore.js +9 -10
- package/token/inMemoryTokenStore.js +7 -8
- package/token/index.js +1 -1
- package/token/replicatedTokenStore.js +7 -8
- package/token/token.d.ts +9 -5
- package/token/token.js +63 -57
- package/tracker.d.ts +4 -4
- package/tracker.js +145 -122
- package/trackingEvents.d.ts +36 -36
- package/trackingEvents.js +12 -6
- package/transformer.js +1 -1
- package/utilityTypes.d.ts +2 -2
- package/uuid.js +9 -7
- package/validation/arrayType.d.ts +2 -2
- package/validation/arrayType.js +29 -27
- package/validation/booleanType.js +11 -15
- package/validation/functionType.js +11 -15
- package/validation/index.js +1 -1
- package/validation/jsonType.d.ts +2 -2
- package/validation/jsonType.js +61 -80
- package/validation/mixedSchema.js +4 -7
- package/validation/nullType.js +11 -15
- package/validation/numberType.d.ts +1 -1
- package/validation/numberType.js +23 -22
- package/validation/objectType.d.ts +1 -1
- package/validation/objectType.js +61 -72
- package/validation/schema.js +6 -10
- package/validation/stringType.d.ts +1 -1
- package/validation/stringType.js +36 -47
- package/validation/unionType.js +27 -77
- package/validation/violation.js +1 -2
- package/schema/evaluationSchemas.d.ts +0 -2
package/validation/objectType.js
CHANGED
|
@@ -1,102 +1,91 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ObjectType = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
function ObjectType(schema) {
|
|
10
|
-
if (schema === void 0) { schema = {}; }
|
|
4
|
+
const schema_1 = require("./schema");
|
|
5
|
+
const mixedSchema_1 = require("./mixedSchema");
|
|
6
|
+
const violation_1 = require("./violation");
|
|
7
|
+
class ObjectType {
|
|
8
|
+
constructor(schema = {}) {
|
|
11
9
|
var _a, _b, _c, _d, _e, _f;
|
|
12
|
-
this.definition =
|
|
10
|
+
this.definition = {
|
|
11
|
+
...schema,
|
|
12
|
+
properties: (_a = schema.properties) !== null && _a !== void 0 ? _a : {},
|
|
13
|
+
required: (_b = schema.required) !== null && _b !== void 0 ? _b : [],
|
|
14
|
+
additionalProperties: (_c = schema.additionalProperties) !== null && _c !== void 0 ? _c : false,
|
|
15
|
+
propertyNames: (_d = schema.propertyNames) !== null && _d !== void 0 ? _d : new mixedSchema_1.MixedSchema(),
|
|
16
|
+
minProperties: (_e = schema.minProperties) !== null && _e !== void 0 ? _e : -1,
|
|
17
|
+
maxProperties: (_f = schema.maxProperties) !== null && _f !== void 0 ? _f : -1,
|
|
18
|
+
};
|
|
13
19
|
}
|
|
14
|
-
|
|
20
|
+
getTypes() {
|
|
15
21
|
if (this.definition.type !== undefined) {
|
|
16
22
|
return [this.definition.type.name];
|
|
17
23
|
}
|
|
18
24
|
return ['object'];
|
|
19
|
-
}
|
|
20
|
-
|
|
25
|
+
}
|
|
26
|
+
isValidType(value) {
|
|
21
27
|
if (this.definition.type !== undefined) {
|
|
22
28
|
return value instanceof this.definition.type;
|
|
23
29
|
}
|
|
24
|
-
return Object.prototype
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
30
|
+
return Object.prototype
|
|
31
|
+
.toString
|
|
32
|
+
.call(value) === '[object Object]';
|
|
33
|
+
}
|
|
34
|
+
validate(value, path = []) {
|
|
29
35
|
if (!this.isValidType(value)) {
|
|
30
|
-
|
|
31
|
-
throw new schema_1.Violation(
|
|
32
|
-
+
|
|
36
|
+
const [type] = this.getTypes();
|
|
37
|
+
throw new schema_1.Violation(`Expected value of type ${type} at path '${(0, violation_1.formatPath)(path)}', `
|
|
38
|
+
+ `actual ${(0, violation_1.describe)(value)}.`, path, { type: type });
|
|
33
39
|
}
|
|
34
|
-
|
|
35
|
-
|
|
40
|
+
const entries = Object.entries(value);
|
|
41
|
+
const { minProperties, maxProperties } = this.definition;
|
|
36
42
|
if (minProperties >= 0 && minProperties > entries.length) {
|
|
37
|
-
throw new schema_1.Violation(
|
|
38
|
-
+
|
|
39
|
-
+
|
|
43
|
+
throw new schema_1.Violation(`Expected ${minProperties === maxProperties ? 'exactly' : 'at least'} `
|
|
44
|
+
+ `${minProperties} ${minProperties === 1 ? 'entry' : 'entries'} `
|
|
45
|
+
+ `at path '${(0, violation_1.formatPath)(path)}', actual ${entries.length}.`, path, { limit: minProperties });
|
|
40
46
|
}
|
|
41
47
|
if (maxProperties >= 0 && maxProperties < entries.length) {
|
|
42
|
-
throw new schema_1.Violation(
|
|
43
|
-
+
|
|
44
|
-
+
|
|
48
|
+
throw new schema_1.Violation(`Expected ${minProperties === maxProperties ? 'exactly' : 'at most'} `
|
|
49
|
+
+ `${maxProperties} ${maxProperties === 1 ? 'entry' : 'entries'} `
|
|
50
|
+
+ `at path '${(0, violation_1.formatPath)(path)}', actual ${entries.length}.`, path, { limit: maxProperties });
|
|
45
51
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
required: property,
|
|
53
|
-
});
|
|
54
|
-
}
|
|
52
|
+
const additionalProperties = { ...value };
|
|
53
|
+
for (const property of this.definition.required) {
|
|
54
|
+
if (!(property in value)) {
|
|
55
|
+
throw new schema_1.Violation(`Missing property '${(0, violation_1.formatPath)(path.concat([property]))}'.`, path, {
|
|
56
|
+
required: property,
|
|
57
|
+
});
|
|
55
58
|
}
|
|
56
59
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
60
|
+
for (const [entryName, entryValue] of entries) {
|
|
61
|
+
const propertyPath = path.concat([entryName]);
|
|
62
|
+
this.definition
|
|
63
|
+
.propertyNames
|
|
64
|
+
.validate(entryName, propertyPath);
|
|
65
|
+
const propertyRule = this.definition.properties[entryName];
|
|
66
|
+
if (propertyRule !== undefined) {
|
|
67
|
+
propertyRule.validate(entryValue, propertyPath);
|
|
68
|
+
delete additionalProperties[entryName];
|
|
69
|
+
continue;
|
|
61
70
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
var _g = tslib_1.__read(entries_1_1.value, 2), entryName = _g[0], entryValue = _g[1];
|
|
67
|
-
var propertyPath = path.concat([entryName]);
|
|
68
|
-
this.definition.propertyNames.validate(entryName, propertyPath);
|
|
69
|
-
var propertyRule = this.definition.properties[entryName];
|
|
70
|
-
if (propertyRule !== undefined) {
|
|
71
|
-
propertyRule.validate(entryValue, propertyPath);
|
|
72
|
-
delete additionalProperties[entryName];
|
|
73
|
-
continue;
|
|
74
|
-
}
|
|
75
|
-
if (this.definition.additionalProperties === false) {
|
|
76
|
-
throw new schema_1.Violation("Unknown property '".concat((0, violation_1.formatPath)(propertyPath), "'."), propertyPath, {
|
|
77
|
-
additionalProperty: entryName,
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
if (this.definition.additionalProperties !== true) {
|
|
81
|
-
this.definition.additionalProperties.validate(entryValue, propertyPath);
|
|
82
|
-
}
|
|
71
|
+
if (this.definition.additionalProperties === false) {
|
|
72
|
+
throw new schema_1.Violation(`Unknown property '${(0, violation_1.formatPath)(propertyPath)}'.`, propertyPath, {
|
|
73
|
+
additionalProperty: entryName,
|
|
74
|
+
});
|
|
83
75
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
if (entries_1_1 && !entries_1_1.done && (_b = entries_1.return)) _b.call(entries_1);
|
|
76
|
+
if (this.definition.additionalProperties !== true) {
|
|
77
|
+
this.definition
|
|
78
|
+
.additionalProperties
|
|
79
|
+
.validate(entryValue, propertyPath);
|
|
89
80
|
}
|
|
90
|
-
finally { if (e_2) throw e_2.error; }
|
|
91
81
|
}
|
|
92
|
-
|
|
82
|
+
const { subtypes } = this.definition;
|
|
93
83
|
if (subtypes !== undefined) {
|
|
94
|
-
|
|
84
|
+
const type = value[subtypes.discriminator];
|
|
95
85
|
if (type !== undefined && subtypes.schemas[type] !== undefined) {
|
|
96
86
|
subtypes.schemas[type].validate(additionalProperties, path);
|
|
97
87
|
}
|
|
98
88
|
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
}());
|
|
89
|
+
}
|
|
90
|
+
}
|
|
102
91
|
exports.ObjectType = ObjectType;
|
package/validation/schema.js
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Violation = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
_this.path = path;
|
|
10
|
-
_this.params = params;
|
|
11
|
-
return _this;
|
|
4
|
+
class Violation extends Error {
|
|
5
|
+
constructor(message, path, params) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.path = path;
|
|
8
|
+
this.params = params;
|
|
12
9
|
}
|
|
13
|
-
|
|
14
|
-
}(Error));
|
|
10
|
+
}
|
|
15
11
|
exports.Violation = Violation;
|
package/validation/stringType.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.StringType = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var FORMAT = {
|
|
4
|
+
const schema_1 = require("./schema");
|
|
5
|
+
const violation_1 = require("./violation");
|
|
6
|
+
const FORMAT = {
|
|
8
7
|
pointer: function pointer(value) {
|
|
9
8
|
return /^(\.|([a-zA-Z_][a-zA-Z0-9_]*|\[[0-9]+])(\.[a-zA-Z_][a-zA-Z0-9_]*|\[[0-9]+])*)$/.test(value);
|
|
10
9
|
},
|
|
@@ -19,71 +18,61 @@ var FORMAT = {
|
|
|
19
18
|
},
|
|
20
19
|
url: function url(value) {
|
|
21
20
|
try {
|
|
22
|
-
// eslint-disable-next-line no-new
|
|
21
|
+
// eslint-disable-next-line no-new -- Easier way to validate a URL
|
|
23
22
|
new URL(value);
|
|
24
23
|
}
|
|
25
|
-
catch
|
|
26
|
-
return false;
|
|
27
|
-
}
|
|
28
|
-
return true;
|
|
29
|
-
},
|
|
30
|
-
'uri-reference': function uriReference(value) {
|
|
31
|
-
try {
|
|
32
|
-
// This simplistic approach covers the most common cases
|
|
33
|
-
// without inflating the library with an RFC 3986-compliant parser.
|
|
34
|
-
// eslint-disable-next-line no-new
|
|
35
|
-
new URL(value, 'http://any.thing');
|
|
36
|
-
}
|
|
37
|
-
catch (_a) {
|
|
24
|
+
catch {
|
|
38
25
|
return false;
|
|
39
26
|
}
|
|
40
27
|
return true;
|
|
41
28
|
},
|
|
42
29
|
};
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if (definition === void 0) { definition = {}; }
|
|
30
|
+
class StringType {
|
|
31
|
+
constructor(definition = {}) {
|
|
46
32
|
var _a, _b, _c;
|
|
47
|
-
this.definition =
|
|
33
|
+
this.definition = {
|
|
34
|
+
...definition,
|
|
35
|
+
minLength: (_a = definition.minLength) !== null && _a !== void 0 ? _a : -1,
|
|
36
|
+
maxLength: (_b = definition.maxLength) !== null && _b !== void 0 ? _b : -1,
|
|
37
|
+
enumeration: (_c = definition.enumeration) !== null && _c !== void 0 ? _c : [],
|
|
38
|
+
};
|
|
48
39
|
}
|
|
49
|
-
|
|
40
|
+
getTypes() {
|
|
50
41
|
return ['string'];
|
|
51
|
-
}
|
|
52
|
-
|
|
42
|
+
}
|
|
43
|
+
isValidType(value) {
|
|
53
44
|
return typeof value === 'string';
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (path === void 0) { path = []; }
|
|
45
|
+
}
|
|
46
|
+
validate(value, path = []) {
|
|
57
47
|
if (!this.isValidType(value)) {
|
|
58
|
-
throw new schema_1.Violation(
|
|
48
|
+
throw new schema_1.Violation(`Expected value of type string at path '${(0, violation_1.formatPath)(path)}', actual ${(0, violation_1.describe)(value)}.`, path, { type: 'string' });
|
|
59
49
|
}
|
|
60
|
-
|
|
50
|
+
const { minLength, maxLength } = this.definition;
|
|
61
51
|
if (minLength >= 0 && minLength > value.length) {
|
|
62
|
-
throw new schema_1.Violation(
|
|
63
|
-
+
|
|
64
|
-
+
|
|
52
|
+
throw new schema_1.Violation(`Expected ${minLength === maxLength ? 'exactly' : 'at least'} `
|
|
53
|
+
+ `${minLength} ${minLength === 1 ? 'character' : 'characters'} `
|
|
54
|
+
+ `at path '${(0, violation_1.formatPath)(path)}', actual ${value.length}.`, path, { limit: minLength });
|
|
65
55
|
}
|
|
66
56
|
if (maxLength >= 0 && maxLength < value.length) {
|
|
67
|
-
throw new schema_1.Violation(
|
|
68
|
-
+
|
|
69
|
-
+
|
|
57
|
+
throw new schema_1.Violation(`Expected ${minLength === maxLength ? 'exactly' : 'at most'} `
|
|
58
|
+
+ `${maxLength} ${maxLength === 1 ? 'character' : 'characters'} `
|
|
59
|
+
+ `at path '${(0, violation_1.formatPath)(path)}', actual ${value.length}.`, path, { limit: maxLength });
|
|
70
60
|
}
|
|
71
|
-
|
|
61
|
+
const { enumeration } = this.definition;
|
|
72
62
|
if (enumeration.length > 0 && enumeration.indexOf(value) < 0) {
|
|
73
|
-
throw new schema_1.Violation(
|
|
74
|
-
+
|
|
63
|
+
throw new schema_1.Violation(`Unexpected value at path '${(0, violation_1.formatPath)(path)}', expecting `
|
|
64
|
+
+ `'${enumeration.length === 1
|
|
75
65
|
? enumeration[0]
|
|
76
|
-
:
|
|
77
|
-
+
|
|
66
|
+
: `${enumeration.slice(0, -1).join('\', \'')}' or '${enumeration.slice(-1)}`}', `
|
|
67
|
+
+ `found '${value}'.`, path, { enumeration: enumeration });
|
|
78
68
|
}
|
|
79
|
-
|
|
69
|
+
const { format, pattern } = this.definition;
|
|
80
70
|
if (format !== undefined && !FORMAT[format](value)) {
|
|
81
|
-
throw new schema_1.Violation(
|
|
71
|
+
throw new schema_1.Violation(`Invalid ${format} format at path '${(0, violation_1.formatPath)(path)}'.`, path, { format: format });
|
|
82
72
|
}
|
|
83
73
|
if (pattern !== undefined && !pattern.test(value)) {
|
|
84
|
-
throw new schema_1.Violation(
|
|
74
|
+
throw new schema_1.Violation(`Invalid format at path '${(0, violation_1.formatPath)(path)}'.`, path, { pattern: pattern });
|
|
85
75
|
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
}());
|
|
76
|
+
}
|
|
77
|
+
}
|
|
89
78
|
exports.StringType = StringType;
|
package/validation/unionType.js
CHANGED
|
@@ -1,91 +1,41 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.UnionType = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
var others = [];
|
|
10
|
-
for (var _i = 2; _i < arguments.length; _i++) {
|
|
11
|
-
others[_i - 2] = arguments[_i];
|
|
12
|
-
}
|
|
13
|
-
this.schemas = tslib_1.__spreadArray([first, second], tslib_1.__read(others), false);
|
|
4
|
+
const schema_1 = require("./schema");
|
|
5
|
+
const violation_1 = require("./violation");
|
|
6
|
+
class UnionType {
|
|
7
|
+
constructor(first, second, ...others) {
|
|
8
|
+
this.schemas = [first, second, ...others];
|
|
14
9
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
try {
|
|
22
|
-
for (var _e = (e_2 = void 0, tslib_1.__values(schema.getTypes())), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
23
|
-
var type = _f.value;
|
|
24
|
-
if (types.indexOf(type) < 0) {
|
|
25
|
-
types.push(type);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
30
|
-
finally {
|
|
31
|
-
try {
|
|
32
|
-
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
|
|
33
|
-
}
|
|
34
|
-
finally { if (e_2) throw e_2.error; }
|
|
10
|
+
getTypes() {
|
|
11
|
+
const types = [];
|
|
12
|
+
for (const schema of this.schemas) {
|
|
13
|
+
for (const type of schema.getTypes()) {
|
|
14
|
+
if (types.indexOf(type) < 0) {
|
|
15
|
+
types.push(type);
|
|
35
16
|
}
|
|
36
17
|
}
|
|
37
18
|
}
|
|
38
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
39
|
-
finally {
|
|
40
|
-
try {
|
|
41
|
-
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
42
|
-
}
|
|
43
|
-
finally { if (e_1) throw e_1.error; }
|
|
44
|
-
}
|
|
45
19
|
return types;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
var schema = _c.value;
|
|
52
|
-
if (schema.isValidType(value)) {
|
|
53
|
-
return true;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
58
|
-
finally {
|
|
59
|
-
try {
|
|
60
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
20
|
+
}
|
|
21
|
+
isValidType(value) {
|
|
22
|
+
for (const schema of this.schemas) {
|
|
23
|
+
if (schema.isValidType(value)) {
|
|
24
|
+
return true;
|
|
61
25
|
}
|
|
62
|
-
finally { if (e_3) throw e_3.error; }
|
|
63
26
|
}
|
|
64
27
|
return false;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
var schema = _c.value;
|
|
72
|
-
if (schema.isValidType(value)) {
|
|
73
|
-
schema.validate(value, path);
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
79
|
-
finally {
|
|
80
|
-
try {
|
|
81
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
28
|
+
}
|
|
29
|
+
validate(value, path = []) {
|
|
30
|
+
for (const schema of this.schemas) {
|
|
31
|
+
if (schema.isValidType(value)) {
|
|
32
|
+
schema.validate(value, path);
|
|
33
|
+
return;
|
|
82
34
|
}
|
|
83
|
-
finally { if (e_4) throw e_4.error; }
|
|
84
35
|
}
|
|
85
|
-
|
|
86
|
-
throw new schema_1.Violation(
|
|
87
|
-
+
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
}());
|
|
36
|
+
const types = this.getTypes();
|
|
37
|
+
throw new schema_1.Violation(`Expected value of type ${types.slice(0, -1).join(', ')} or ${types[types.length - 1]} `
|
|
38
|
+
+ `at path '${(0, violation_1.formatPath)(path)}', actual ${(0, violation_1.describe)(value)}.`, path, { type: types.join('|') });
|
|
39
|
+
}
|
|
40
|
+
}
|
|
91
41
|
exports.UnionType = UnionType;
|
package/validation/violation.js
CHANGED
|
@@ -12,13 +12,12 @@ function describe(value) {
|
|
|
12
12
|
return Number.isInteger(value) ? 'integer' : 'number';
|
|
13
13
|
}
|
|
14
14
|
if (typeof value === 'object') {
|
|
15
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
16
15
|
return value.constructor.name;
|
|
17
16
|
}
|
|
18
17
|
return typeof value;
|
|
19
18
|
}
|
|
20
19
|
exports.describe = describe;
|
|
21
20
|
function formatPath(path) {
|
|
22
|
-
return
|
|
21
|
+
return `/${path.join('/')}`;
|
|
23
22
|
}
|
|
24
23
|
exports.formatPath = formatPath;
|