@croct/sdk 0.9.1 → 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 +8 -9
- 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 -73
- 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/uuid.js
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.uuid4 = void 0;
|
|
4
|
-
function uuid4(sortable) {
|
|
5
|
-
|
|
6
|
-
var uuid = '';
|
|
4
|
+
function uuid4(sortable = false) {
|
|
5
|
+
let uuid = '';
|
|
7
6
|
if (sortable) {
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
const prefix = Date.now()
|
|
8
|
+
.toString(16)
|
|
9
|
+
.padStart(12, '0')
|
|
10
|
+
.substring(0, 12);
|
|
11
|
+
uuid = `${prefix.substring(0, 8)}-${prefix.substring(8, 12)}`;
|
|
10
12
|
}
|
|
11
|
-
for (
|
|
13
|
+
for (let index = uuid.length; index < 36; index++) {
|
|
12
14
|
switch (index) {
|
|
13
15
|
case 8:
|
|
14
16
|
case 13:
|
|
@@ -21,7 +23,7 @@ function uuid4(sortable) {
|
|
|
21
23
|
uuid += '4';
|
|
22
24
|
break;
|
|
23
25
|
default: {
|
|
24
|
-
|
|
26
|
+
let random = (Math.random() * 16) | 0;
|
|
25
27
|
if (index === 19) {
|
|
26
28
|
// bits 6-7 of the clock_seq_hi_and_reserved to 01
|
|
27
29
|
random = (random & 3) | 8;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Schema, TypeSchema } from './schema';
|
|
2
|
-
|
|
2
|
+
type ArrayDefinition = {
|
|
3
3
|
minItems: number;
|
|
4
4
|
maxItems: number;
|
|
5
5
|
items?: Schema;
|
|
@@ -8,7 +8,7 @@ export declare class ArrayType implements TypeSchema {
|
|
|
8
8
|
private readonly definition;
|
|
9
9
|
constructor(definition?: Partial<ArrayDefinition>);
|
|
10
10
|
getTypes(): string[];
|
|
11
|
-
isValidType(value: unknown): value is
|
|
11
|
+
isValidType(value: unknown): value is unknown[];
|
|
12
12
|
validate(value: unknown, path?: string[]): void;
|
|
13
13
|
}
|
|
14
14
|
export {};
|
package/validation/arrayType.js
CHANGED
|
@@ -1,45 +1,47 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ArrayType = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
function ArrayType(definition) {
|
|
9
|
-
if (definition === void 0) { definition = {}; }
|
|
4
|
+
const schema_1 = require("./schema");
|
|
5
|
+
const violation_1 = require("./violation");
|
|
6
|
+
class ArrayType {
|
|
7
|
+
constructor(definition = {}) {
|
|
10
8
|
var _a, _b;
|
|
11
|
-
this.definition =
|
|
9
|
+
this.definition = {
|
|
10
|
+
...definition,
|
|
11
|
+
minItems: (_a = definition.minItems) !== null && _a !== void 0 ? _a : -1,
|
|
12
|
+
maxItems: (_b = definition.maxItems) !== null && _b !== void 0 ? _b : -1,
|
|
13
|
+
};
|
|
12
14
|
}
|
|
13
|
-
|
|
15
|
+
getTypes() {
|
|
14
16
|
return ['array'];
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
+
}
|
|
18
|
+
isValidType(value) {
|
|
17
19
|
return Array.isArray(value);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
if (path === void 0) { path = []; }
|
|
20
|
+
}
|
|
21
|
+
validate(value, path = []) {
|
|
21
22
|
if (!this.isValidType(value)) {
|
|
22
|
-
throw new schema_1.Violation(
|
|
23
|
+
throw new schema_1.Violation(`Expected value of type array at path '${(0, violation_1.formatPath)(path)}', actual ${(0, violation_1.describe)(value)}.`, path, { type: 'string' });
|
|
23
24
|
}
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
const { minItems, maxItems } = this.definition;
|
|
26
|
+
const { length } = value;
|
|
26
27
|
if (minItems >= 0 && minItems > length) {
|
|
27
|
-
throw new schema_1.Violation(
|
|
28
|
-
+
|
|
29
|
-
+
|
|
28
|
+
throw new schema_1.Violation(`Expected ${minItems === maxItems ? 'exactly' : 'at least'} `
|
|
29
|
+
+ `${minItems} ${minItems === 1 ? 'item' : 'items'} `
|
|
30
|
+
+ `at path '${(0, violation_1.formatPath)(path)}', actual ${length}.`, path, { limit: minItems });
|
|
30
31
|
}
|
|
31
32
|
if (maxItems >= 0 && maxItems < length) {
|
|
32
|
-
throw new schema_1.Violation(
|
|
33
|
-
+
|
|
34
|
-
+
|
|
33
|
+
throw new schema_1.Violation(`Expected ${minItems === maxItems ? 'exactly' : 'at most'} `
|
|
34
|
+
+ `${maxItems} ${maxItems === 1 ? 'item' : 'items'} `
|
|
35
|
+
+ `at path '${(0, violation_1.formatPath)(path)}', actual ${length}.`, path, { limit: maxItems });
|
|
35
36
|
}
|
|
36
37
|
if (this.definition.items === undefined) {
|
|
37
38
|
return;
|
|
38
39
|
}
|
|
39
|
-
for (
|
|
40
|
-
this.definition
|
|
40
|
+
for (let index = 0; index < length; index++) {
|
|
41
|
+
this.definition
|
|
42
|
+
.items
|
|
43
|
+
.validate(value[index], path.concat([index.toString()]));
|
|
41
44
|
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
}());
|
|
45
|
+
}
|
|
46
|
+
}
|
|
45
47
|
exports.ArrayType = ArrayType;
|
|
@@ -1,23 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BooleanType = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
BooleanType.prototype.getTypes = function () {
|
|
4
|
+
const schema_1 = require("./schema");
|
|
5
|
+
const violation_1 = require("./violation");
|
|
6
|
+
class BooleanType {
|
|
7
|
+
getTypes() {
|
|
10
8
|
return ['boolean'];
|
|
11
|
-
}
|
|
12
|
-
|
|
9
|
+
}
|
|
10
|
+
isValidType(value) {
|
|
13
11
|
return typeof value === 'boolean';
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
if (path === void 0) { path = []; }
|
|
12
|
+
}
|
|
13
|
+
validate(value, path = []) {
|
|
17
14
|
if (!this.isValidType(value)) {
|
|
18
|
-
throw new schema_1.Violation(
|
|
15
|
+
throw new schema_1.Violation(`Expected value of type boolean at path '${(0, violation_1.formatPath)(path)}', actual ${(0, violation_1.describe)(value)}.`, path, { type: 'boolean' });
|
|
19
16
|
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
}());
|
|
17
|
+
}
|
|
18
|
+
}
|
|
23
19
|
exports.BooleanType = BooleanType;
|
|
@@ -1,23 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.FunctionType = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
FunctionType.prototype.getTypes = function () {
|
|
4
|
+
const schema_1 = require("./schema");
|
|
5
|
+
const violation_1 = require("./violation");
|
|
6
|
+
class FunctionType {
|
|
7
|
+
getTypes() {
|
|
10
8
|
return ['function'];
|
|
11
|
-
}
|
|
12
|
-
|
|
9
|
+
}
|
|
10
|
+
isValidType(value) {
|
|
13
11
|
return typeof value === 'function';
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
if (path === void 0) { path = []; }
|
|
12
|
+
}
|
|
13
|
+
validate(value, path = []) {
|
|
17
14
|
if (!this.isValidType(value)) {
|
|
18
|
-
throw new schema_1.Violation(
|
|
15
|
+
throw new schema_1.Violation(`Expected value of type function at path '${(0, violation_1.formatPath)(path)}', actual ${(0, violation_1.describe)(value)}.`, path, { type: 'function' });
|
|
19
16
|
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
}());
|
|
17
|
+
}
|
|
18
|
+
}
|
|
23
19
|
exports.FunctionType = FunctionType;
|
package/validation/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.UnionType = exports.StringType = exports.ObjectType = exports.NumberType = exports.NullType = exports.MixedSchema = exports.JsonPrimitiveType = exports.JsonObjectType = exports.JsonArrayType = exports.JsonType = exports.FunctionType = exports.BooleanType = exports.ArrayType = void 0;
|
|
4
|
-
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
5
|
tslib_1.__exportStar(require("./schema"), exports);
|
|
6
6
|
tslib_1.__exportStar(require("./violation"), exports);
|
|
7
7
|
var arrayType_1 = require("./arrayType");
|
package/validation/jsonType.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Schema, TypeSchema } from './schema';
|
|
2
|
-
|
|
2
|
+
type JsonObjectDefinition = {
|
|
3
3
|
properties?: Schema;
|
|
4
4
|
propertyNames?: Schema;
|
|
5
5
|
};
|
|
@@ -10,7 +10,7 @@ export declare class JsonObjectType implements TypeSchema {
|
|
|
10
10
|
isValidType(value: unknown): boolean;
|
|
11
11
|
validate(value: unknown, path?: string[]): void;
|
|
12
12
|
}
|
|
13
|
-
|
|
13
|
+
type JsonArrayDefinition = {
|
|
14
14
|
items?: Schema;
|
|
15
15
|
};
|
|
16
16
|
export declare class JsonArrayType implements TypeSchema {
|
package/validation/jsonType.js
CHANGED
|
@@ -1,127 +1,108 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.JsonType = exports.JsonPrimitiveType = exports.JsonArrayType = exports.JsonObjectType = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var violation_1 = require("./violation");
|
|
4
|
+
const schema_1 = require("./schema");
|
|
5
|
+
const violation_1 = require("./violation");
|
|
7
6
|
function isJsonPrimitive(value) {
|
|
8
7
|
return value === null || typeof value === 'string' || typeof value === 'boolean' || typeof value === 'number';
|
|
9
8
|
}
|
|
9
|
+
function isPlainObject(value) {
|
|
10
|
+
return Object.prototype
|
|
11
|
+
.toString
|
|
12
|
+
.call(value) === '[object Object]';
|
|
13
|
+
}
|
|
10
14
|
function isJsonArray(value) {
|
|
11
15
|
return Array.isArray(value) && value.every(isJsonValue);
|
|
12
16
|
}
|
|
13
|
-
function isJsonValue(value) {
|
|
14
|
-
return isJsonPrimitive(value) || isJsonArray(value) || isJsonObject(value);
|
|
15
|
-
}
|
|
16
17
|
function isJsonObject(value) {
|
|
17
18
|
return isPlainObject(value) && Object.values(value).every(isJsonValue);
|
|
18
19
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
return Object.prototype.toString.call(value) === '[object Object]';
|
|
20
|
+
function isJsonValue(value) {
|
|
21
|
+
return isJsonPrimitive(value) || isJsonArray(value) || isJsonObject(value);
|
|
22
22
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
if (definition === void 0) { definition = {}; }
|
|
23
|
+
class JsonObjectType {
|
|
24
|
+
constructor(definition = {}) {
|
|
26
25
|
this.definition = definition;
|
|
27
26
|
}
|
|
28
|
-
|
|
27
|
+
getTypes() {
|
|
29
28
|
return ['object'];
|
|
30
|
-
}
|
|
31
|
-
|
|
29
|
+
}
|
|
30
|
+
isValidType(value) {
|
|
32
31
|
return isPlainObject(value);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
var e_1, _a;
|
|
36
|
-
if (path === void 0) { path = []; }
|
|
32
|
+
}
|
|
33
|
+
validate(value, path = []) {
|
|
37
34
|
if (!isJsonObject(value)) {
|
|
38
|
-
throw new schema_1.Violation(
|
|
35
|
+
throw new schema_1.Violation(`Expected a JSON object at path '${(0, violation_1.formatPath)(path)}', actual ${(0, violation_1.describe)(value)}.`, path, { type: 'object' });
|
|
39
36
|
}
|
|
40
37
|
if (this.definition.properties === undefined && this.definition.propertyNames === undefined) {
|
|
41
38
|
return;
|
|
42
39
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
if (this.definition.properties !== undefined) {
|
|
51
|
-
this.definition.properties.validate(entryValue, path.concat([entryName]));
|
|
52
|
-
}
|
|
40
|
+
for (const [entryName, entryValue] of Object.entries(value)) {
|
|
41
|
+
const propertyPath = path.concat([entryName]);
|
|
42
|
+
if (this.definition.propertyNames !== undefined) {
|
|
43
|
+
this.definition
|
|
44
|
+
.propertyNames
|
|
45
|
+
.validate(entryName, propertyPath);
|
|
53
46
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
47
|
+
if (this.definition.properties !== undefined) {
|
|
48
|
+
this.definition
|
|
49
|
+
.properties
|
|
50
|
+
.validate(entryValue, path.concat([entryName]));
|
|
59
51
|
}
|
|
60
|
-
finally { if (e_1) throw e_1.error; }
|
|
61
52
|
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
}());
|
|
53
|
+
}
|
|
54
|
+
}
|
|
65
55
|
exports.JsonObjectType = JsonObjectType;
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
if (definition === void 0) { definition = {}; }
|
|
56
|
+
class JsonArrayType {
|
|
57
|
+
constructor(definition = {}) {
|
|
69
58
|
this.definition = definition;
|
|
70
59
|
}
|
|
71
|
-
|
|
60
|
+
getTypes() {
|
|
72
61
|
return ['array'];
|
|
73
|
-
}
|
|
74
|
-
|
|
62
|
+
}
|
|
63
|
+
isValidType(value) {
|
|
75
64
|
return Array.isArray(value);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
if (path === void 0) { path = []; }
|
|
65
|
+
}
|
|
66
|
+
validate(value, path = []) {
|
|
79
67
|
if (!isJsonArray(value)) {
|
|
80
|
-
throw new schema_1.Violation(
|
|
68
|
+
throw new schema_1.Violation(`Expected a JSON array at path '${(0, violation_1.formatPath)(path)}', actual ${(0, violation_1.describe)(value)}.`, path, { type: 'array' });
|
|
81
69
|
}
|
|
82
70
|
if (this.definition.items === undefined) {
|
|
83
71
|
return;
|
|
84
72
|
}
|
|
85
|
-
for (
|
|
86
|
-
this.definition
|
|
73
|
+
for (let index = 0; index < value.length; index++) {
|
|
74
|
+
this.definition
|
|
75
|
+
.items
|
|
76
|
+
.validate(value[index], path.concat([index.toString()]));
|
|
87
77
|
}
|
|
88
|
-
};
|
|
89
|
-
return JsonArrayType;
|
|
90
|
-
}());
|
|
91
|
-
exports.JsonArrayType = JsonArrayType;
|
|
92
|
-
var JsonPrimitiveType = /** @class */ (function () {
|
|
93
|
-
function JsonPrimitiveType() {
|
|
94
78
|
}
|
|
95
|
-
|
|
79
|
+
}
|
|
80
|
+
exports.JsonArrayType = JsonArrayType;
|
|
81
|
+
class JsonPrimitiveType {
|
|
82
|
+
getTypes() {
|
|
96
83
|
return ['null', 'number', 'string', 'boolean'];
|
|
97
|
-
}
|
|
98
|
-
|
|
84
|
+
}
|
|
85
|
+
isValidType(value) {
|
|
99
86
|
return isJsonPrimitive(value);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
if (path === void 0) { path = []; }
|
|
87
|
+
}
|
|
88
|
+
validate(value, path = []) {
|
|
103
89
|
if (!this.isValidType(value)) {
|
|
104
|
-
throw new schema_1.Violation(
|
|
90
|
+
throw new schema_1.Violation(`Expected a JSON primitive at path '${(0, violation_1.formatPath)(path)}', actual ${(0, violation_1.describe)(value)}.`, path, { type: this.getTypes().join('|') });
|
|
105
91
|
}
|
|
106
|
-
};
|
|
107
|
-
return JsonPrimitiveType;
|
|
108
|
-
}());
|
|
109
|
-
exports.JsonPrimitiveType = JsonPrimitiveType;
|
|
110
|
-
var JsonType = /** @class */ (function () {
|
|
111
|
-
function JsonType() {
|
|
112
92
|
}
|
|
113
|
-
|
|
93
|
+
}
|
|
94
|
+
exports.JsonPrimitiveType = JsonPrimitiveType;
|
|
95
|
+
class JsonType {
|
|
96
|
+
getTypes() {
|
|
114
97
|
return ['null', 'number', 'string', 'boolean', 'array', 'object'];
|
|
115
|
-
}
|
|
116
|
-
|
|
98
|
+
}
|
|
99
|
+
isValidType(value) {
|
|
117
100
|
return isJsonPrimitive(value) || Array.isArray(value) || isPlainObject(value);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
if (path === void 0) { path = []; }
|
|
101
|
+
}
|
|
102
|
+
validate(value, path = []) {
|
|
121
103
|
if (!isJsonValue(value)) {
|
|
122
|
-
throw new schema_1.Violation(
|
|
104
|
+
throw new schema_1.Violation(`Expected a JSON value at path '${(0, violation_1.formatPath)(path)}', actual ${(0, violation_1.describe)(value)}.`, path, { type: this.getTypes().join('|') });
|
|
123
105
|
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
}());
|
|
106
|
+
}
|
|
107
|
+
}
|
|
127
108
|
exports.JsonType = JsonType;
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MixedSchema = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
MixedSchema.prototype.validate = function () {
|
|
4
|
+
class MixedSchema {
|
|
5
|
+
validate() {
|
|
8
6
|
// always valid
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
}());
|
|
7
|
+
}
|
|
8
|
+
}
|
|
12
9
|
exports.MixedSchema = MixedSchema;
|
package/validation/nullType.js
CHANGED
|
@@ -1,23 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.NullType = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
NullType.prototype.getTypes = function () {
|
|
4
|
+
const schema_1 = require("./schema");
|
|
5
|
+
const violation_1 = require("./violation");
|
|
6
|
+
class NullType {
|
|
7
|
+
getTypes() {
|
|
10
8
|
return ['null'];
|
|
11
|
-
}
|
|
12
|
-
|
|
9
|
+
}
|
|
10
|
+
isValidType(value) {
|
|
13
11
|
return value === null;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
if (path === void 0) { path = []; }
|
|
12
|
+
}
|
|
13
|
+
validate(value, path = []) {
|
|
17
14
|
if (!this.isValidType(value)) {
|
|
18
|
-
throw new schema_1.Violation(
|
|
15
|
+
throw new schema_1.Violation(`Expected value of type null at path '${(0, violation_1.formatPath)(path)}', actual ${(0, violation_1.describe)(value)}.`, path, { type: 'null' });
|
|
19
16
|
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
}());
|
|
17
|
+
}
|
|
18
|
+
}
|
|
23
19
|
exports.NullType = NullType;
|
package/validation/numberType.js
CHANGED
|
@@ -1,36 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.NumberType = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
function NumberType(definition) {
|
|
9
|
-
if (definition === void 0) { definition = {}; }
|
|
4
|
+
const schema_1 = require("./schema");
|
|
5
|
+
const violation_1 = require("./violation");
|
|
6
|
+
class NumberType {
|
|
7
|
+
constructor(definition = {}) {
|
|
10
8
|
var _a, _b, _c;
|
|
11
|
-
this.definition =
|
|
9
|
+
this.definition = {
|
|
10
|
+
...definition,
|
|
11
|
+
integer: (_a = definition.integer) !== null && _a !== void 0 ? _a : false,
|
|
12
|
+
minimum: (_b = definition.minimum) !== null && _b !== void 0 ? _b : Number.NEGATIVE_INFINITY,
|
|
13
|
+
maximum: (_c = definition.maximum) !== null && _c !== void 0 ? _c : Number.POSITIVE_INFINITY,
|
|
14
|
+
};
|
|
12
15
|
}
|
|
13
|
-
|
|
16
|
+
getTypes() {
|
|
14
17
|
return [this.definition.integer ? 'integer' : 'number'];
|
|
15
|
-
}
|
|
16
|
-
|
|
18
|
+
}
|
|
19
|
+
isValidType(value) {
|
|
17
20
|
return typeof value === 'number' && (!this.definition.integer || Number.isInteger(value));
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
if (path === void 0) { path = []; }
|
|
21
|
+
}
|
|
22
|
+
validate(value, path = []) {
|
|
21
23
|
if (!this.isValidType(value)) {
|
|
22
|
-
|
|
23
|
-
throw new schema_1.Violation(
|
|
24
|
+
const type = this.getTypes()[0];
|
|
25
|
+
throw new schema_1.Violation(`Expected value of type ${type} at path '${(0, violation_1.formatPath)(path)}', actual ${(0, violation_1.describe)(value)}.`, path, { type: type });
|
|
24
26
|
}
|
|
25
27
|
if (value < this.definition.minimum) {
|
|
26
|
-
throw new schema_1.Violation(
|
|
27
|
-
+
|
|
28
|
+
throw new schema_1.Violation(`Expected a value greater than or equal to ${this.definition.minimum} `
|
|
29
|
+
+ `at path '${(0, violation_1.formatPath)(path)}', actual ${value}.`, path, { limit: this.definition.minimum });
|
|
28
30
|
}
|
|
29
31
|
if (value > this.definition.maximum) {
|
|
30
|
-
throw new schema_1.Violation(
|
|
31
|
-
+
|
|
32
|
+
throw new schema_1.Violation(`Expected a value less than or equal to ${this.definition.maximum} `
|
|
33
|
+
+ `at path '${(0, violation_1.formatPath)(path)}', actual ${value}.`, path, { limit: this.definition.maximum });
|
|
32
34
|
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
}());
|
|
35
|
+
}
|
|
36
|
+
}
|
|
36
37
|
exports.NumberType = NumberType;
|