@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
@@ -1,102 +1,91 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ObjectType = void 0;
4
- var tslib_1 = require("tslib");
5
- var schema_1 = require("./schema");
6
- var mixedSchema_1 = require("./mixedSchema");
7
- var violation_1 = require("./violation");
8
- var ObjectType = /** @class */ (function () {
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 = tslib_1.__assign(tslib_1.__assign({}, schema), { properties: (_a = schema.properties) !== null && _a !== void 0 ? _a : {}, required: (_b = schema.required) !== null && _b !== void 0 ? _b : [], additionalProperties: (_c = schema.additionalProperties) !== null && _c !== void 0 ? _c : false, propertyNames: (_d = schema.propertyNames) !== null && _d !== void 0 ? _d : new mixedSchema_1.MixedSchema(), minProperties: (_e = schema.minProperties) !== null && _e !== void 0 ? _e : -1, maxProperties: (_f = schema.maxProperties) !== null && _f !== void 0 ? _f : -1 });
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
- ObjectType.prototype.getTypes = function () {
20
+ getTypes() {
15
21
  if (this.definition.type !== undefined) {
16
22
  return [this.definition.type.name];
17
23
  }
18
24
  return ['object'];
19
- };
20
- ObjectType.prototype.isValidType = function (value) {
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.toString.call(value) === '[object Object]';
25
- };
26
- ObjectType.prototype.validate = function (value, path) {
27
- var e_1, _a, e_2, _b;
28
- if (path === void 0) { path = []; }
30
+ return Object.prototype
31
+ .toString
32
+ .call(value) === '[object Object]';
33
+ }
34
+ validate(value, path = []) {
29
35
  if (!this.isValidType(value)) {
30
- var _c = tslib_1.__read(this.getTypes(), 1), type = _c[0];
31
- throw new schema_1.Violation("Expected value of type ".concat(type, " at path '").concat((0, violation_1.formatPath)(path), "', ")
32
- + "actual ".concat((0, violation_1.describe)(value), "."), path, { type: type });
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
- var entries = Object.entries(value);
35
- var _d = this.definition, minProperties = _d.minProperties, maxProperties = _d.maxProperties;
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("Expected ".concat(minProperties === maxProperties ? 'exactly' : 'at least', " ")
38
- + "".concat(minProperties, " ").concat(minProperties === 1 ? 'entry' : 'entries', " ")
39
- + "at path '".concat((0, violation_1.formatPath)(path), "', actual ").concat(entries.length, "."), path, { limit: minProperties });
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("Expected ".concat(minProperties === maxProperties ? 'exactly' : 'at most', " ")
43
- + "".concat(maxProperties, " ").concat(maxProperties === 1 ? 'entry' : 'entries', " ")
44
- + "at path '".concat((0, violation_1.formatPath)(path), "', actual ").concat(entries.length, "."), path, { limit: maxProperties });
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
- var additionalProperties = tslib_1.__assign({}, value);
47
- try {
48
- for (var _e = tslib_1.__values(this.definition.required), _f = _e.next(); !_f.done; _f = _e.next()) {
49
- var property = _f.value;
50
- if (!(property in value)) {
51
- throw new schema_1.Violation("Missing property '".concat((0, violation_1.formatPath)(path.concat([property])), "'."), path, {
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
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
58
- finally {
59
- try {
60
- if (_f && !_f.done && (_a = _e.return)) _a.call(_e);
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
- finally { if (e_1) throw e_1.error; }
63
- }
64
- try {
65
- for (var entries_1 = tslib_1.__values(entries), entries_1_1 = entries_1.next(); !entries_1_1.done; entries_1_1 = entries_1.next()) {
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
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
86
- finally {
87
- try {
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
- var subtypes = this.definition.subtypes;
82
+ const { subtypes } = this.definition;
93
83
  if (subtypes !== undefined) {
94
- var type = value[subtypes.discriminator];
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
- return ObjectType;
101
- }());
89
+ }
90
+ }
102
91
  exports.ObjectType = ObjectType;
@@ -1,15 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Violation = void 0;
4
- var tslib_1 = require("tslib");
5
- var Violation = /** @class */ (function (_super) {
6
- tslib_1.__extends(Violation, _super);
7
- function Violation(message, path, params) {
8
- var _this = _super.call(this, message) || this;
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
- return Violation;
14
- }(Error));
10
+ }
15
11
  exports.Violation = Violation;
@@ -5,7 +5,7 @@ interface Format {
5
5
  declare const FORMAT: {
6
6
  [key: string]: Format;
7
7
  };
8
- declare type StringDefinition = {
8
+ type StringDefinition = {
9
9
  minLength: number;
10
10
  maxLength: number;
11
11
  enumeration: string[];
@@ -1,10 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.StringType = void 0;
4
- var tslib_1 = require("tslib");
5
- var schema_1 = require("./schema");
6
- var violation_1 = require("./violation");
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 (_a) {
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
- var StringType = /** @class */ (function () {
44
- function StringType(definition) {
45
- if (definition === void 0) { definition = {}; }
30
+ class StringType {
31
+ constructor(definition = {}) {
46
32
  var _a, _b, _c;
47
- this.definition = tslib_1.__assign(tslib_1.__assign({}, definition), { minLength: (_a = definition.minLength) !== null && _a !== void 0 ? _a : -1, maxLength: (_b = definition.maxLength) !== null && _b !== void 0 ? _b : -1, enumeration: (_c = definition.enumeration) !== null && _c !== void 0 ? _c : [] });
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
- StringType.prototype.getTypes = function () {
40
+ getTypes() {
50
41
  return ['string'];
51
- };
52
- StringType.prototype.isValidType = function (value) {
42
+ }
43
+ isValidType(value) {
53
44
  return typeof value === 'string';
54
- };
55
- StringType.prototype.validate = function (value, path) {
56
- if (path === void 0) { path = []; }
45
+ }
46
+ validate(value, path = []) {
57
47
  if (!this.isValidType(value)) {
58
- throw new schema_1.Violation("Expected value of type string at path '".concat((0, violation_1.formatPath)(path), "', actual ").concat((0, violation_1.describe)(value), "."), path, { type: 'string' });
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
- var _a = this.definition, minLength = _a.minLength, maxLength = _a.maxLength;
50
+ const { minLength, maxLength } = this.definition;
61
51
  if (minLength >= 0 && minLength > value.length) {
62
- throw new schema_1.Violation("Expected ".concat(minLength === maxLength ? 'exactly' : 'at least', " ")
63
- + "".concat(minLength, " ").concat(minLength === 1 ? 'character' : 'characters', " ")
64
- + "at path '".concat((0, violation_1.formatPath)(path), "', actual ").concat(value.length, "."), path, { limit: minLength });
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("Expected ".concat(minLength === maxLength ? 'exactly' : 'at most', " ")
68
- + "".concat(maxLength, " ").concat(maxLength === 1 ? 'character' : 'characters', " ")
69
- + "at path '".concat((0, violation_1.formatPath)(path), "', actual ").concat(value.length, "."), path, { limit: maxLength });
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
- var enumeration = this.definition.enumeration;
61
+ const { enumeration } = this.definition;
72
62
  if (enumeration.length > 0 && enumeration.indexOf(value) < 0) {
73
- throw new schema_1.Violation("Unexpected value at path '".concat((0, violation_1.formatPath)(path), "', expecting ")
74
- + "'".concat(enumeration.length === 1
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
- : "".concat(enumeration.slice(0, -1).join('\', \''), "' or '").concat(enumeration.slice(-1)), "', ")
77
- + "found '".concat(value, "'."), path, { enumeration: enumeration });
66
+ : `${enumeration.slice(0, -1).join('\', \'')}' or '${enumeration.slice(-1)}`}', `
67
+ + `found '${value}'.`, path, { enumeration: enumeration });
78
68
  }
79
- var _b = this.definition, format = _b.format, pattern = _b.pattern;
69
+ const { format, pattern } = this.definition;
80
70
  if (format !== undefined && !FORMAT[format](value)) {
81
- throw new schema_1.Violation("Invalid ".concat(format, " format at path '").concat((0, violation_1.formatPath)(path), "'."), path, { format: format });
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("Invalid format at path '".concat((0, violation_1.formatPath)(path), "'."), path, { pattern: pattern });
74
+ throw new schema_1.Violation(`Invalid format at path '${(0, violation_1.formatPath)(path)}'.`, path, { pattern: pattern });
85
75
  }
86
- };
87
- return StringType;
88
- }());
76
+ }
77
+ }
89
78
  exports.StringType = StringType;
@@ -1,91 +1,41 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.UnionType = void 0;
4
- var tslib_1 = require("tslib");
5
- var schema_1 = require("./schema");
6
- var violation_1 = require("./violation");
7
- var UnionType = /** @class */ (function () {
8
- function UnionType(first, second) {
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
- UnionType.prototype.getTypes = function () {
16
- var e_1, _a, e_2, _b;
17
- var types = [];
18
- try {
19
- for (var _c = tslib_1.__values(this.schemas), _d = _c.next(); !_d.done; _d = _c.next()) {
20
- var schema = _d.value;
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
- UnionType.prototype.isValidType = function (value) {
48
- var e_3, _a;
49
- try {
50
- for (var _b = tslib_1.__values(this.schemas), _c = _b.next(); !_c.done; _c = _b.next()) {
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
- UnionType.prototype.validate = function (value, path) {
67
- var e_4, _a;
68
- if (path === void 0) { path = []; }
69
- try {
70
- for (var _b = tslib_1.__values(this.schemas), _c = _b.next(); !_c.done; _c = _b.next()) {
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
- var types = this.getTypes();
86
- throw new schema_1.Violation("Expected value of type ".concat(types.slice(0, -1).join(', '), " or ").concat(types[types.length - 1], " ")
87
- + "at path '".concat((0, violation_1.formatPath)(path), "', actual ").concat((0, violation_1.describe)(value), "."), path, { type: types.join('|') });
88
- };
89
- return UnionType;
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;
@@ -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 "/".concat(path.join('/'));
21
+ return `/${path.join('/')}`;
23
22
  }
24
23
  exports.formatPath = formatPath;
@@ -1,2 +0,0 @@
1
- import { ObjectType } from '../validation';
2
- export declare const optionsSchema: ObjectType;