@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.
Files changed (122) hide show
  1. package/activeRecord.js +32 -36
  2. package/cache/fallbackCache.js +15 -32
  3. package/cache/inMemoryCache.js +9 -10
  4. package/cache/index.js +1 -1
  5. package/cache/localStorageCache.js +24 -25
  6. package/channel/beaconSocketChannel.d.ts +1 -1
  7. package/channel/beaconSocketChannel.js +49 -79
  8. package/channel/channel.d.ts +1 -1
  9. package/channel/encodedChannel.js +8 -10
  10. package/channel/guaranteedChannel.d.ts +4 -4
  11. package/channel/guaranteedChannel.js +41 -43
  12. package/channel/index.js +1 -1
  13. package/channel/queuedChannel.js +35 -64
  14. package/channel/retryChannel.d.ts +1 -1
  15. package/channel/retryChannel.js +44 -77
  16. package/channel/sandboxChannel.js +17 -18
  17. package/channel/socketChannel.d.ts +4 -4
  18. package/channel/socketChannel.js +77 -79
  19. package/cid/cachedAssigner.js +15 -27
  20. package/cid/fixedAssigner.js +5 -6
  21. package/cid/index.js +1 -1
  22. package/cid/remoteAssigner.js +23 -36
  23. package/constants.d.ts +3 -2
  24. package/constants.js +6 -5
  25. package/container.d.ts +13 -6
  26. package/container.js +152 -168
  27. package/contentFetcher.d.ts +59 -0
  28. package/contentFetcher.js +129 -0
  29. package/context.d.ts +3 -3
  30. package/context.js +36 -38
  31. package/error.js +2 -2
  32. package/evaluator.d.ts +33 -24
  33. package/evaluator.js +126 -117
  34. package/eventManager.d.ts +1 -1
  35. package/eventManager.js +14 -15
  36. package/facade/contentFetcherFacade.d.ts +27 -0
  37. package/facade/contentFetcherFacade.js +40 -0
  38. package/facade/evaluatorFacade.d.ts +13 -3
  39. package/facade/evaluatorFacade.js +57 -72
  40. package/facade/sdkFacade.d.ts +10 -3
  41. package/facade/sdkFacade.js +129 -141
  42. package/facade/sessionFacade.js +6 -7
  43. package/facade/sessionPatch.js +9 -13
  44. package/facade/trackerFacade.js +32 -38
  45. package/facade/userFacade.js +10 -11
  46. package/facade/userPatch.js +9 -13
  47. package/index.js +2 -2
  48. package/logging/consoleLogger.js +18 -35
  49. package/logging/index.js +1 -1
  50. package/logging/namespacedLogger.js +14 -15
  51. package/logging/nullLogger.js +10 -13
  52. package/namespacedStorage.js +30 -47
  53. package/package.json +13 -16
  54. package/patch.d.ts +1 -1
  55. package/queue/capacityRestrictedQueue.js +17 -18
  56. package/queue/inMemoryQueue.js +22 -28
  57. package/queue/index.js +1 -1
  58. package/queue/monitoredQueue.d.ts +2 -2
  59. package/queue/monitoredQueue.js +39 -40
  60. package/queue/persistentQueue.js +33 -38
  61. package/retry/arbitraryPolicy.js +8 -10
  62. package/retry/backoffPolicy.d.ts +1 -1
  63. package/retry/backoffPolicy.js +11 -13
  64. package/retry/index.js +1 -1
  65. package/retry/maxAttemptsPolicy.js +7 -8
  66. package/retry/neverPolicy.js +6 -9
  67. package/schema/attributeSchema.js +1 -1
  68. package/schema/contentFetcherSchemas.d.ts +2 -0
  69. package/schema/contentFetcherSchemas.js +22 -0
  70. package/schema/contentSchemas.js +1 -1
  71. package/schema/contextSchemas.js +1 -1
  72. package/schema/ecommerceSchemas.js +1 -1
  73. package/schema/evaluatorSchemas.d.ts +2 -0
  74. package/schema/{evaluationSchemas.js → evaluatorSchemas.js} +3 -3
  75. package/schema/eventSchemas.js +5 -7
  76. package/schema/index.d.ts +2 -1
  77. package/schema/index.js +3 -2
  78. package/schema/loggerSchema.js +1 -1
  79. package/schema/operationSchemas.js +8 -8
  80. package/schema/sdkFacadeSchemas.js +9 -6
  81. package/schema/sdkSchemas.js +8 -5
  82. package/schema/tokenSchema.js +5 -4
  83. package/schema/userSchema.js +2 -2
  84. package/sdk.d.ts +9 -3
  85. package/sdk.js +81 -127
  86. package/sdkEvents.d.ts +3 -3
  87. package/sourceLocation.d.ts +3 -3
  88. package/sourceLocation.js +13 -14
  89. package/tab.d.ts +5 -5
  90. package/tab.js +50 -80
  91. package/token/cachedTokenStore.js +9 -10
  92. package/token/inMemoryTokenStore.js +7 -8
  93. package/token/index.js +1 -1
  94. package/token/replicatedTokenStore.js +7 -8
  95. package/token/token.d.ts +9 -5
  96. package/token/token.js +63 -57
  97. package/tracker.d.ts +4 -4
  98. package/tracker.js +145 -122
  99. package/trackingEvents.d.ts +36 -36
  100. package/trackingEvents.js +12 -6
  101. package/transformer.js +1 -1
  102. package/utilityTypes.d.ts +2 -2
  103. package/uuid.js +9 -7
  104. package/validation/arrayType.d.ts +2 -2
  105. package/validation/arrayType.js +29 -27
  106. package/validation/booleanType.js +11 -15
  107. package/validation/functionType.js +11 -15
  108. package/validation/index.js +1 -1
  109. package/validation/jsonType.d.ts +2 -2
  110. package/validation/jsonType.js +61 -80
  111. package/validation/mixedSchema.js +4 -7
  112. package/validation/nullType.js +11 -15
  113. package/validation/numberType.d.ts +1 -1
  114. package/validation/numberType.js +23 -22
  115. package/validation/objectType.d.ts +1 -1
  116. package/validation/objectType.js +61 -72
  117. package/validation/schema.js +6 -10
  118. package/validation/stringType.d.ts +1 -1
  119. package/validation/stringType.js +36 -47
  120. package/validation/unionType.js +27 -77
  121. package/validation/violation.js +1 -2
  122. 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
- if (sortable === void 0) { sortable = false; }
6
- var uuid = '';
4
+ function uuid4(sortable = false) {
5
+ let uuid = '';
7
6
  if (sortable) {
8
- var prefix = Date.now().toString(16).padStart(12, '0').substring(0, 12);
9
- uuid = "".concat(prefix.substring(0, 8), "-").concat(prefix.substring(8, 12));
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 (var index = uuid.length; index < 36; index++) {
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
- var random = (Math.random() * 16) | 0;
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
- declare type ArrayDefinition = {
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 Array<unknown>;
11
+ isValidType(value: unknown): value is unknown[];
12
12
  validate(value: unknown, path?: string[]): void;
13
13
  }
14
14
  export {};
@@ -1,45 +1,47 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ArrayType = void 0;
4
- var tslib_1 = require("tslib");
5
- var schema_1 = require("./schema");
6
- var violation_1 = require("./violation");
7
- var ArrayType = /** @class */ (function () {
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 = tslib_1.__assign(tslib_1.__assign({}, definition), { minItems: (_a = definition.minItems) !== null && _a !== void 0 ? _a : -1, maxItems: (_b = definition.maxItems) !== null && _b !== void 0 ? _b : -1 });
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
- ArrayType.prototype.getTypes = function () {
15
+ getTypes() {
14
16
  return ['array'];
15
- };
16
- ArrayType.prototype.isValidType = function (value) {
17
+ }
18
+ isValidType(value) {
17
19
  return Array.isArray(value);
18
- };
19
- ArrayType.prototype.validate = function (value, path) {
20
- if (path === void 0) { path = []; }
20
+ }
21
+ validate(value, path = []) {
21
22
  if (!this.isValidType(value)) {
22
- throw new schema_1.Violation("Expected value of type array at path '".concat((0, violation_1.formatPath)(path), "', actual ").concat((0, violation_1.describe)(value), "."), path, { type: 'string' });
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
- var _a = this.definition, minItems = _a.minItems, maxItems = _a.maxItems;
25
- var length = value.length;
25
+ const { minItems, maxItems } = this.definition;
26
+ const { length } = value;
26
27
  if (minItems >= 0 && minItems > length) {
27
- throw new schema_1.Violation("Expected ".concat(minItems === maxItems ? 'exactly' : 'at least', " ")
28
- + "".concat(minItems, " ").concat(minItems === 1 ? 'item' : 'items', " ")
29
- + "at path '".concat((0, violation_1.formatPath)(path), "', actual ").concat(length, "."), path, { limit: minItems });
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("Expected ".concat(minItems === maxItems ? 'exactly' : 'at most', " ")
33
- + "".concat(maxItems, " ").concat(maxItems === 1 ? 'item' : 'items', " ")
34
- + "at path '".concat((0, violation_1.formatPath)(path), "', actual ").concat(length, "."), path, { limit: maxItems });
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 (var index = 0; index < length; index++) {
40
- this.definition.items.validate(value[index], path.concat([index.toString()]));
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
- return ArrayType;
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
- var schema_1 = require("./schema");
5
- var violation_1 = require("./violation");
6
- var BooleanType = /** @class */ (function () {
7
- function BooleanType() {
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
- BooleanType.prototype.isValidType = function (value) {
9
+ }
10
+ isValidType(value) {
13
11
  return typeof value === 'boolean';
14
- };
15
- BooleanType.prototype.validate = function (value, path) {
16
- if (path === void 0) { path = []; }
12
+ }
13
+ validate(value, path = []) {
17
14
  if (!this.isValidType(value)) {
18
- throw new schema_1.Violation("Expected value of type boolean at path '".concat((0, violation_1.formatPath)(path), "', actual ").concat((0, violation_1.describe)(value), "."), path, { type: 'boolean' });
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
- return BooleanType;
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
- var schema_1 = require("./schema");
5
- var violation_1 = require("./violation");
6
- var FunctionType = /** @class */ (function () {
7
- function FunctionType() {
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
- FunctionType.prototype.isValidType = function (value) {
9
+ }
10
+ isValidType(value) {
13
11
  return typeof value === 'function';
14
- };
15
- FunctionType.prototype.validate = function (value, path) {
16
- if (path === void 0) { path = []; }
12
+ }
13
+ validate(value, path = []) {
17
14
  if (!this.isValidType(value)) {
18
- throw new schema_1.Violation("Expected value of type function at path '".concat((0, violation_1.formatPath)(path), "', actual ").concat((0, violation_1.describe)(value), "."), path, { type: 'function' });
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
- return FunctionType;
22
- }());
17
+ }
18
+ }
23
19
  exports.FunctionType = FunctionType;
@@ -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
- var tslib_1 = require("tslib");
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");
@@ -1,5 +1,5 @@
1
1
  import { Schema, TypeSchema } from './schema';
2
- declare type JsonObjectDefinition = {
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
- declare type JsonArrayDefinition = {
13
+ type JsonArrayDefinition = {
14
14
  items?: Schema;
15
15
  };
16
16
  export declare class JsonArrayType implements TypeSchema {
@@ -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
- var tslib_1 = require("tslib");
5
- var schema_1 = require("./schema");
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
- // eslint-disable-next-line @typescript-eslint/ban-types
20
- function isPlainObject(value) {
21
- return Object.prototype.toString.call(value) === '[object Object]';
20
+ function isJsonValue(value) {
21
+ return isJsonPrimitive(value) || isJsonArray(value) || isJsonObject(value);
22
22
  }
23
- var JsonObjectType = /** @class */ (function () {
24
- function JsonObjectType(definition) {
25
- if (definition === void 0) { definition = {}; }
23
+ class JsonObjectType {
24
+ constructor(definition = {}) {
26
25
  this.definition = definition;
27
26
  }
28
- JsonObjectType.prototype.getTypes = function () {
27
+ getTypes() {
29
28
  return ['object'];
30
- };
31
- JsonObjectType.prototype.isValidType = function (value) {
29
+ }
30
+ isValidType(value) {
32
31
  return isPlainObject(value);
33
- };
34
- JsonObjectType.prototype.validate = function (value, path) {
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("Expected a JSON object at path '".concat((0, violation_1.formatPath)(path), "', actual ").concat((0, violation_1.describe)(value), "."), path, { type: 'object' });
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
- try {
44
- for (var _b = tslib_1.__values(Object.entries(value)), _c = _b.next(); !_c.done; _c = _b.next()) {
45
- var _d = tslib_1.__read(_c.value, 2), entryName = _d[0], entryValue = _d[1];
46
- var propertyPath = path.concat([entryName]);
47
- if (this.definition.propertyNames !== undefined) {
48
- this.definition.propertyNames.validate(entryName, propertyPath);
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
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
56
- finally {
57
- try {
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
- return JsonObjectType;
64
- }());
53
+ }
54
+ }
65
55
  exports.JsonObjectType = JsonObjectType;
66
- var JsonArrayType = /** @class */ (function () {
67
- function JsonArrayType(definition) {
68
- if (definition === void 0) { definition = {}; }
56
+ class JsonArrayType {
57
+ constructor(definition = {}) {
69
58
  this.definition = definition;
70
59
  }
71
- JsonArrayType.prototype.getTypes = function () {
60
+ getTypes() {
72
61
  return ['array'];
73
- };
74
- JsonArrayType.prototype.isValidType = function (value) {
62
+ }
63
+ isValidType(value) {
75
64
  return Array.isArray(value);
76
- };
77
- JsonArrayType.prototype.validate = function (value, path) {
78
- if (path === void 0) { path = []; }
65
+ }
66
+ validate(value, path = []) {
79
67
  if (!isJsonArray(value)) {
80
- throw new schema_1.Violation("Expected a JSON array at path '".concat((0, violation_1.formatPath)(path), "', actual ").concat((0, violation_1.describe)(value), "."), path, { type: 'array' });
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 (var index = 0; index < value.length; index++) {
86
- this.definition.items.validate(value[index], path.concat([index.toString()]));
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
- JsonPrimitiveType.prototype.getTypes = function () {
79
+ }
80
+ exports.JsonArrayType = JsonArrayType;
81
+ class JsonPrimitiveType {
82
+ getTypes() {
96
83
  return ['null', 'number', 'string', 'boolean'];
97
- };
98
- JsonPrimitiveType.prototype.isValidType = function (value) {
84
+ }
85
+ isValidType(value) {
99
86
  return isJsonPrimitive(value);
100
- };
101
- JsonPrimitiveType.prototype.validate = function (value, path) {
102
- if (path === void 0) { path = []; }
87
+ }
88
+ validate(value, path = []) {
103
89
  if (!this.isValidType(value)) {
104
- throw new schema_1.Violation("Expected a JSON primitive at path '".concat((0, violation_1.formatPath)(path), "', actual ").concat((0, violation_1.describe)(value), "."), path, { type: this.getTypes().join('|') });
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
- JsonType.prototype.getTypes = function () {
93
+ }
94
+ exports.JsonPrimitiveType = JsonPrimitiveType;
95
+ class JsonType {
96
+ getTypes() {
114
97
  return ['null', 'number', 'string', 'boolean', 'array', 'object'];
115
- };
116
- JsonType.prototype.isValidType = function (value) {
98
+ }
99
+ isValidType(value) {
117
100
  return isJsonPrimitive(value) || Array.isArray(value) || isPlainObject(value);
118
- };
119
- JsonType.prototype.validate = function (value, path) {
120
- if (path === void 0) { path = []; }
101
+ }
102
+ validate(value, path = []) {
121
103
  if (!isJsonValue(value)) {
122
- throw new schema_1.Violation("Expected a JSON value at path '".concat((0, violation_1.formatPath)(path), "', actual ").concat((0, violation_1.describe)(value), "."), path, { type: this.getTypes().join('|') });
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
- return JsonType;
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
- var MixedSchema = /** @class */ (function () {
5
- function MixedSchema() {
6
- }
7
- MixedSchema.prototype.validate = function () {
4
+ class MixedSchema {
5
+ validate() {
8
6
  // always valid
9
- };
10
- return MixedSchema;
11
- }());
7
+ }
8
+ }
12
9
  exports.MixedSchema = MixedSchema;
@@ -1,23 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.NullType = void 0;
4
- var schema_1 = require("./schema");
5
- var violation_1 = require("./violation");
6
- var NullType = /** @class */ (function () {
7
- function NullType() {
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
- NullType.prototype.isValidType = function (value) {
9
+ }
10
+ isValidType(value) {
13
11
  return value === null;
14
- };
15
- NullType.prototype.validate = function (value, path) {
16
- if (path === void 0) { path = []; }
12
+ }
13
+ validate(value, path = []) {
17
14
  if (!this.isValidType(value)) {
18
- throw new schema_1.Violation("Expected value of type null at path '".concat((0, violation_1.formatPath)(path), "', actual ").concat((0, violation_1.describe)(value), "."), path, { type: 'null' });
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
- return NullType;
22
- }());
17
+ }
18
+ }
23
19
  exports.NullType = NullType;
@@ -1,5 +1,5 @@
1
1
  import { TypeSchema } from './schema';
2
- declare type NumberDefinition = {
2
+ type NumberDefinition = {
3
3
  integer: boolean;
4
4
  minimum: number;
5
5
  maximum: number;
@@ -1,36 +1,37 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.NumberType = void 0;
4
- var tslib_1 = require("tslib");
5
- var schema_1 = require("./schema");
6
- var violation_1 = require("./violation");
7
- var NumberType = /** @class */ (function () {
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 = tslib_1.__assign(tslib_1.__assign({}, definition), { integer: (_a = definition.integer) !== null && _a !== void 0 ? _a : false, minimum: (_b = definition.minimum) !== null && _b !== void 0 ? _b : Number.NEGATIVE_INFINITY, maximum: (_c = definition.maximum) !== null && _c !== void 0 ? _c : Number.POSITIVE_INFINITY });
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
- NumberType.prototype.getTypes = function () {
16
+ getTypes() {
14
17
  return [this.definition.integer ? 'integer' : 'number'];
15
- };
16
- NumberType.prototype.isValidType = function (value) {
18
+ }
19
+ isValidType(value) {
17
20
  return typeof value === 'number' && (!this.definition.integer || Number.isInteger(value));
18
- };
19
- NumberType.prototype.validate = function (value, path) {
20
- if (path === void 0) { path = []; }
21
+ }
22
+ validate(value, path = []) {
21
23
  if (!this.isValidType(value)) {
22
- var type = this.getTypes()[0];
23
- throw new schema_1.Violation("Expected value of type ".concat(type, " at path '").concat((0, violation_1.formatPath)(path), "', actual ").concat((0, violation_1.describe)(value), "."), path, { type: type });
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("Expected a value greater than or equal to ".concat(this.definition.minimum, " ")
27
- + "at path '".concat((0, violation_1.formatPath)(path), "', actual ").concat(value, "."), path, { limit: this.definition.minimum });
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("Expected a value less than or equal to ".concat(this.definition.maximum, " ")
31
- + "at path '".concat((0, violation_1.formatPath)(path), "', actual ").concat(value, "."), path, { limit: this.definition.maximum });
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
- return NumberType;
35
- }());
35
+ }
36
+ }
36
37
  exports.NumberType = NumberType;
@@ -1,5 +1,5 @@
1
1
  import { Schema, TypeSchema } from './schema';
2
- declare type ObjectDefinition = {
2
+ type ObjectDefinition = {
3
3
  type?: {
4
4
  new (...args: any): any;
5
5
  };