@croct/sdk 0.7.0 → 0.8.0

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 (64) hide show
  1. package/activeRecord.d.ts +1 -0
  2. package/activeRecord.js +9 -1
  3. package/cache/fallbackCache.js +1 -1
  4. package/cache/index.js +1 -1
  5. package/channel/beaconSocketChannel.js +5 -5
  6. package/channel/guaranteedChannel.js +6 -6
  7. package/channel/index.js +1 -1
  8. package/channel/queuedChannel.js +6 -6
  9. package/channel/retryChannel.js +5 -5
  10. package/channel/socketChannel.js +4 -4
  11. package/cid/cachedAssigner.js +2 -2
  12. package/cid/index.js +1 -1
  13. package/cid/remoteAssigner.js +3 -3
  14. package/constants.js +1 -1
  15. package/container.d.ts +1 -0
  16. package/container.js +15 -9
  17. package/context.js +1 -1
  18. package/evaluator.js +14 -14
  19. package/facade/evaluatorFacade.js +3 -3
  20. package/facade/sdkFacade.d.ts +1 -0
  21. package/facade/sdkFacade.js +8 -8
  22. package/facade/sessionPatch.js +1 -1
  23. package/facade/trackerFacade.js +5 -4
  24. package/facade/userPatch.js +1 -1
  25. package/logging/consoleLogger.js +1 -1
  26. package/logging/index.js +1 -1
  27. package/logging/namespacedLogger.js +1 -1
  28. package/namespacedStorage.js +2 -2
  29. package/package.json +12 -12
  30. package/patch.d.ts +5 -1
  31. package/queue/inMemoryQueue.js +1 -1
  32. package/queue/index.js +1 -1
  33. package/queue/monitoredQueue.js +1 -1
  34. package/retry/arbitraryPolicy.js +1 -1
  35. package/retry/index.js +1 -1
  36. package/schema/eventSchemas.d.ts +1 -0
  37. package/schema/eventSchemas.js +9 -1
  38. package/schema/index.js +10 -10
  39. package/schema/operationSchemas.d.ts +1 -0
  40. package/schema/operationSchemas.js +8 -1
  41. package/schema/sdkFacadeSchemas.js +1 -0
  42. package/schema/sdkSchemas.js +1 -0
  43. package/sdk.d.ts +1 -0
  44. package/sdk.js +16 -15
  45. package/sourceLocation.js +2 -2
  46. package/token/index.js +1 -1
  47. package/token/token.js +11 -11
  48. package/tracker.d.ts +1 -0
  49. package/tracker.js +30 -22
  50. package/trackingEvents.d.ts +9 -3
  51. package/trackingEvents.js +6 -5
  52. package/uuid.js +1 -1
  53. package/validation/arrayType.js +8 -8
  54. package/validation/booleanType.js +1 -1
  55. package/validation/functionType.js +1 -1
  56. package/validation/index.js +2 -2
  57. package/validation/jsonType.js +6 -6
  58. package/validation/nullType.js +1 -1
  59. package/validation/numberType.js +6 -6
  60. package/validation/objectType.js +16 -16
  61. package/validation/schema.js +1 -1
  62. package/validation/stringType.js +28 -16
  63. package/validation/unionType.js +7 -7
  64. package/validation/violation.js +1 -1
@@ -71,8 +71,8 @@ export declare const cartEventTypes: readonly ["cartModified", "cartViewed", "ch
71
71
  export declare const ecommerceEventTypes: readonly ["cartModified", "cartViewed", "checkoutStarted", "orderPlaced", "productViewed"];
72
72
  export declare const identifiedUserEventTypes: string[];
73
73
  export declare const userEventTypes: readonly [...string[], "userProfileChanged"];
74
- export declare const miscEventTypes: readonly ["nothingChanged", "sessionAttributesChanged", "goalCompleted", "interestShown", "postViewed", "eventOccurred"];
75
- export declare const eventTypes: readonly ["pageLoaded", "pageOpened", "cartModified", "cartViewed", "checkoutStarted", "orderPlaced", "productViewed", ...string[], "userProfileChanged", "nothingChanged", "sessionAttributesChanged", "goalCompleted", "interestShown", "postViewed", "eventOccurred"];
74
+ export declare const miscEventTypes: readonly ["nothingChanged", "sessionAttributesChanged", "goalCompleted", "interestShown", "postViewed", "eventOccurred", "linkOpened"];
75
+ export declare const eventTypes: readonly ["pageLoaded", "pageOpened", "cartModified", "cartViewed", "checkoutStarted", "orderPlaced", "productViewed", ...string[], "userProfileChanged", "nothingChanged", "sessionAttributesChanged", "goalCompleted", "interestShown", "postViewed", "eventOccurred", "linkOpened"];
76
76
  interface BaseEvent {
77
77
  type: string;
78
78
  }
@@ -235,7 +235,11 @@ export interface EventOccurred extends BaseEvent {
235
235
  [key: string]: string | number | boolean | null;
236
236
  };
237
237
  }
238
- export declare type MiscEvent = NothingChanged | SessionAttributesChanged | EventOccurred | GoalCompleted | InterestShown | PostViewed;
238
+ export interface LinkOpened extends BaseEvent {
239
+ type: 'linkOpened';
240
+ link: string;
241
+ }
242
+ export declare type MiscEvent = NothingChanged | SessionAttributesChanged | EventOccurred | GoalCompleted | InterestShown | PostViewed | LinkOpened;
239
243
  declare type EventMap = {
240
244
  tabVisibilityChanged: TabVisibilityChanged;
241
245
  tabUrlChanged: TabUrlChanged;
@@ -257,6 +261,7 @@ declare type EventMap = {
257
261
  interestShown: InterestShown;
258
262
  postViewed: PostViewed;
259
263
  eventOccurred: EventOccurred;
264
+ linkOpened: LinkOpened;
260
265
  };
261
266
  export declare type TrackingEventType = keyof EventMap;
262
267
  export declare type TrackingEvent<T extends TrackingEventType = TrackingEventType> = T extends TrackingEventType ? EventMap[T] : EventMap[TrackingEventType];
@@ -278,6 +283,7 @@ declare type ExternalEventMap = {
278
283
  goalCompleted: GoalCompleted;
279
284
  interestShown: InterestShown;
280
285
  postViewed: PostViewed;
286
+ linkOpened: LinkOpened;
281
287
  eventOccurred: EventOccurred;
282
288
  };
283
289
  export declare type ExternalTrackingEventType = keyof ExternalEventMap;
package/trackingEvents.js CHANGED
@@ -19,18 +19,18 @@ exports.cartEventTypes = [
19
19
  'cartViewed',
20
20
  'checkoutStarted',
21
21
  ];
22
- exports.ecommerceEventTypes = tslib_1.__spreadArray(tslib_1.__spreadArray([], tslib_1.__read(exports.cartEventTypes)), [
22
+ exports.ecommerceEventTypes = (0, tslib_1.__spreadArray)((0, tslib_1.__spreadArray)([], (0, tslib_1.__read)(exports.cartEventTypes), false), [
23
23
  'orderPlaced',
24
24
  'productViewed',
25
- ]);
25
+ ], false);
26
26
  exports.identifiedUserEventTypes = [
27
27
  'userSignedIn',
28
28
  'userSignedOut',
29
29
  'userSignedUp',
30
30
  ];
31
- exports.userEventTypes = tslib_1.__spreadArray(tslib_1.__spreadArray([], tslib_1.__read(exports.identifiedUserEventTypes)), [
31
+ exports.userEventTypes = (0, tslib_1.__spreadArray)((0, tslib_1.__spreadArray)([], (0, tslib_1.__read)(exports.identifiedUserEventTypes), false), [
32
32
  'userProfileChanged',
33
- ]);
33
+ ], false);
34
34
  exports.miscEventTypes = [
35
35
  'nothingChanged',
36
36
  'sessionAttributesChanged',
@@ -38,8 +38,9 @@ exports.miscEventTypes = [
38
38
  'interestShown',
39
39
  'postViewed',
40
40
  'eventOccurred',
41
+ 'linkOpened',
41
42
  ];
42
- exports.eventTypes = tslib_1.__spreadArray(tslib_1.__spreadArray(tslib_1.__spreadArray(tslib_1.__spreadArray([], tslib_1.__read(exports.pageEventTypes)), tslib_1.__read(exports.ecommerceEventTypes)), tslib_1.__read(exports.userEventTypes)), tslib_1.__read(exports.miscEventTypes));
43
+ exports.eventTypes = (0, tslib_1.__spreadArray)((0, tslib_1.__spreadArray)((0, tslib_1.__spreadArray)((0, tslib_1.__spreadArray)([], (0, tslib_1.__read)(exports.pageEventTypes), false), (0, tslib_1.__read)(exports.ecommerceEventTypes), false), (0, tslib_1.__read)(exports.userEventTypes), false), (0, tslib_1.__read)(exports.miscEventTypes), false);
43
44
  /*
44
45
  * Type guards
45
46
  */
package/uuid.js CHANGED
@@ -6,7 +6,7 @@ function uuid4(sortable) {
6
6
  var uuid = '';
7
7
  if (sortable) {
8
8
  var prefix = Date.now().toString(16).padStart(12, '0').substring(0, 12);
9
- uuid = prefix.substring(0, 8) + "-" + prefix.substring(8, 12);
9
+ uuid = "".concat(prefix.substring(0, 8), "-").concat(prefix.substring(8, 12));
10
10
  }
11
11
  for (var index = uuid.length; index < 36; index++) {
12
12
  switch (index) {
@@ -8,7 +8,7 @@ var ArrayType = /** @class */ (function () {
8
8
  function ArrayType(definition) {
9
9
  if (definition === void 0) { definition = {}; }
10
10
  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 });
11
+ this.definition = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, definition), { minItems: (_a = definition.minItems) !== null && _a !== void 0 ? _a : -1, maxItems: (_b = definition.maxItems) !== null && _b !== void 0 ? _b : -1 });
12
12
  }
13
13
  ArrayType.prototype.getTypes = function () {
14
14
  return ['array'];
@@ -19,19 +19,19 @@ var ArrayType = /** @class */ (function () {
19
19
  ArrayType.prototype.validate = function (value, path) {
20
20
  if (path === void 0) { path = []; }
21
21
  if (!this.isValidType(value)) {
22
- throw new schema_1.Violation("Expected value of type array at path '" + violation_1.formatPath(path) + "', actual " + violation_1.describe(value) + ".", path, { type: 'string' });
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
23
  }
24
24
  var _a = this.definition, minItems = _a.minItems, maxItems = _a.maxItems;
25
25
  var length = value.length;
26
26
  if (minItems >= 0 && minItems > length) {
27
- throw new schema_1.Violation("Expected " + (minItems === maxItems ? 'exactly' : 'at least') + " "
28
- + (minItems + " " + (minItems === 1 ? 'item' : 'items') + " ")
29
- + ("at path '" + violation_1.formatPath(path) + "', actual " + length + "."), path, { limit: minItems });
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 });
30
30
  }
31
31
  if (maxItems >= 0 && maxItems < length) {
32
- throw new schema_1.Violation("Expected " + (minItems === maxItems ? 'exactly' : 'at most') + " "
33
- + (maxItems + " " + (maxItems === 1 ? 'item' : 'items') + " ")
34
- + ("at path '" + violation_1.formatPath(path) + "', actual " + length + "."), path, { limit: maxItems });
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 });
35
35
  }
36
36
  if (this.definition.items === undefined) {
37
37
  return;
@@ -15,7 +15,7 @@ var BooleanType = /** @class */ (function () {
15
15
  BooleanType.prototype.validate = function (value, path) {
16
16
  if (path === void 0) { path = []; }
17
17
  if (!this.isValidType(value)) {
18
- throw new schema_1.Violation("Expected value of type boolean at path '" + violation_1.formatPath(path) + "', actual " + violation_1.describe(value) + ".", path, { type: 'boolean' });
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' });
19
19
  }
20
20
  };
21
21
  return BooleanType;
@@ -15,7 +15,7 @@ var FunctionType = /** @class */ (function () {
15
15
  FunctionType.prototype.validate = function (value, path) {
16
16
  if (path === void 0) { path = []; }
17
17
  if (!this.isValidType(value)) {
18
- throw new schema_1.Violation("Expected value of type function at path '" + violation_1.formatPath(path) + "', actual " + violation_1.describe(value) + ".", path, { type: 'function' });
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' });
19
19
  }
20
20
  };
21
21
  return FunctionType;
@@ -2,8 +2,8 @@
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
  var tslib_1 = require("tslib");
5
- tslib_1.__exportStar(require("./schema"), exports);
6
- tslib_1.__exportStar(require("./violation"), exports);
5
+ (0, tslib_1.__exportStar)(require("./schema"), exports);
6
+ (0, tslib_1.__exportStar)(require("./violation"), exports);
7
7
  var arrayType_1 = require("./arrayType");
8
8
  Object.defineProperty(exports, "ArrayType", { enumerable: true, get: function () { return arrayType_1.ArrayType; } });
9
9
  var booleanType_1 = require("./booleanType");
@@ -35,14 +35,14 @@ var JsonObjectType = /** @class */ (function () {
35
35
  var e_1, _a;
36
36
  if (path === void 0) { path = []; }
37
37
  if (!isJsonObject(value)) {
38
- throw new schema_1.Violation("Expected a JSON object at path '" + violation_1.formatPath(path) + "', actual " + violation_1.describe(value) + ".", path, { type: 'object' });
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' });
39
39
  }
40
40
  if (this.definition.properties === undefined && this.definition.propertyNames === undefined) {
41
41
  return;
42
42
  }
43
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];
44
+ for (var _b = (0, tslib_1.__values)(Object.entries(value)), _c = _b.next(); !_c.done; _c = _b.next()) {
45
+ var _d = (0, tslib_1.__read)(_c.value, 2), entryName = _d[0], entryValue = _d[1];
46
46
  var propertyPath = path.concat([entryName]);
47
47
  if (this.definition.propertyNames !== undefined) {
48
48
  this.definition.propertyNames.validate(entryName, propertyPath);
@@ -77,7 +77,7 @@ var JsonArrayType = /** @class */ (function () {
77
77
  JsonArrayType.prototype.validate = function (value, path) {
78
78
  if (path === void 0) { path = []; }
79
79
  if (!isJsonArray(value)) {
80
- throw new schema_1.Violation("Expected a JSON array at path '" + violation_1.formatPath(path) + "', actual " + violation_1.describe(value) + ".", path, { type: 'array' });
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' });
81
81
  }
82
82
  if (this.definition.items === undefined) {
83
83
  return;
@@ -101,7 +101,7 @@ var JsonPrimitiveType = /** @class */ (function () {
101
101
  JsonPrimitiveType.prototype.validate = function (value, path) {
102
102
  if (path === void 0) { path = []; }
103
103
  if (!this.isValidType(value)) {
104
- throw new schema_1.Violation("Expected a JSON primitive at path '" + violation_1.formatPath(path) + "', actual " + violation_1.describe(value) + ".", path, { type: this.getTypes().join('|') });
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('|') });
105
105
  }
106
106
  };
107
107
  return JsonPrimitiveType;
@@ -119,7 +119,7 @@ var JsonType = /** @class */ (function () {
119
119
  JsonType.prototype.validate = function (value, path) {
120
120
  if (path === void 0) { path = []; }
121
121
  if (!isJsonValue(value)) {
122
- throw new schema_1.Violation("Expected a JSON value at path '" + violation_1.formatPath(path) + "', actual " + violation_1.describe(value) + ".", path, { type: this.getTypes().join('|') });
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('|') });
123
123
  }
124
124
  };
125
125
  return JsonType;
@@ -15,7 +15,7 @@ var NullType = /** @class */ (function () {
15
15
  NullType.prototype.validate = function (value, path) {
16
16
  if (path === void 0) { path = []; }
17
17
  if (!this.isValidType(value)) {
18
- throw new schema_1.Violation("Expected value of type null at path '" + violation_1.formatPath(path) + "', actual " + violation_1.describe(value) + ".", path, { type: 'null' });
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' });
19
19
  }
20
20
  };
21
21
  return NullType;
@@ -8,7 +8,7 @@ var NumberType = /** @class */ (function () {
8
8
  function NumberType(definition) {
9
9
  if (definition === void 0) { definition = {}; }
10
10
  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 });
11
+ this.definition = (0, tslib_1.__assign)((0, 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 });
12
12
  }
13
13
  NumberType.prototype.getTypes = function () {
14
14
  return [this.definition.integer ? 'integer' : 'number'];
@@ -20,15 +20,15 @@ var NumberType = /** @class */ (function () {
20
20
  if (path === void 0) { path = []; }
21
21
  if (!this.isValidType(value)) {
22
22
  var type = this.getTypes()[0];
23
- throw new schema_1.Violation("Expected value of type " + type + " at path '" + violation_1.formatPath(path) + "', actual " + violation_1.describe(value) + ".", path, { type: type });
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
24
  }
25
25
  if (value < this.definition.minimum) {
26
- throw new schema_1.Violation("Expected a value greater than or equal to " + this.definition.minimum + " "
27
- + ("at path '" + violation_1.formatPath(path) + "', actual " + value + "."), path, { limit: 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
28
  }
29
29
  if (value > this.definition.maximum) {
30
- throw new schema_1.Violation("Expected a value less than or equal to " + this.definition.maximum + " "
31
- + ("at path '" + violation_1.formatPath(path) + "', actual " + value + "."), path, { limit: 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
32
  }
33
33
  };
34
34
  return NumberType;
@@ -9,7 +9,7 @@ var ObjectType = /** @class */ (function () {
9
9
  function ObjectType(schema) {
10
10
  if (schema === void 0) { schema = {}; }
11
11
  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 });
12
+ this.definition = (0, tslib_1.__assign)((0, 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 });
13
13
  }
14
14
  ObjectType.prototype.getTypes = function () {
15
15
  if (this.definition.type !== undefined) {
@@ -28,28 +28,28 @@ var ObjectType = /** @class */ (function () {
28
28
  var e_1, _a, e_2, _b;
29
29
  if (path === void 0) { path = []; }
30
30
  if (!this.isValidType(value)) {
31
- var _c = tslib_1.__read(this.getTypes(), 1), type = _c[0];
32
- throw new schema_1.Violation("Expected value of type " + type + " at path '" + violation_1.formatPath(path) + "', "
33
- + ("actual " + violation_1.describe(value) + "."), path, { type: type });
31
+ var _c = (0, tslib_1.__read)(this.getTypes(), 1), type = _c[0];
32
+ throw new schema_1.Violation("Expected value of type ".concat(type, " at path '").concat((0, violation_1.formatPath)(path), "', ")
33
+ + "actual ".concat((0, violation_1.describe)(value), "."), path, { type: type });
34
34
  }
35
35
  var entries = Object.entries(value);
36
36
  var _d = this.definition, minProperties = _d.minProperties, maxProperties = _d.maxProperties;
37
37
  if (minProperties >= 0 && minProperties > entries.length) {
38
- throw new schema_1.Violation("Expected " + (minProperties === maxProperties ? 'exactly' : 'at least') + " "
39
- + (minProperties + " " + (minProperties === 1 ? 'entry' : 'entries') + " ")
40
- + ("at path '" + violation_1.formatPath(path) + "', actual " + entries.length + "."), path, { limit: minProperties });
38
+ throw new schema_1.Violation("Expected ".concat(minProperties === maxProperties ? 'exactly' : 'at least', " ")
39
+ + "".concat(minProperties, " ").concat(minProperties === 1 ? 'entry' : 'entries', " ")
40
+ + "at path '".concat((0, violation_1.formatPath)(path), "', actual ").concat(entries.length, "."), path, { limit: minProperties });
41
41
  }
42
42
  if (maxProperties >= 0 && maxProperties < entries.length) {
43
- throw new schema_1.Violation("Expected " + (minProperties === maxProperties ? 'exactly' : 'at most') + " "
44
- + (maxProperties + " " + (maxProperties === 1 ? 'entry' : 'entries') + " ")
45
- + ("at path '" + violation_1.formatPath(path) + "', actual " + entries.length + "."), path, { limit: maxProperties });
43
+ throw new schema_1.Violation("Expected ".concat(minProperties === maxProperties ? 'exactly' : 'at most', " ")
44
+ + "".concat(maxProperties, " ").concat(maxProperties === 1 ? 'entry' : 'entries', " ")
45
+ + "at path '".concat((0, violation_1.formatPath)(path), "', actual ").concat(entries.length, "."), path, { limit: maxProperties });
46
46
  }
47
- var additionalProperties = tslib_1.__assign({}, value);
47
+ var additionalProperties = (0, tslib_1.__assign)({}, value);
48
48
  try {
49
- for (var _e = tslib_1.__values(this.definition.required), _f = _e.next(); !_f.done; _f = _e.next()) {
49
+ for (var _e = (0, tslib_1.__values)(this.definition.required), _f = _e.next(); !_f.done; _f = _e.next()) {
50
50
  var property = _f.value;
51
51
  if (!(property in value)) {
52
- throw new schema_1.Violation("Missing property '" + violation_1.formatPath(path.concat([property])) + "'.", path, {
52
+ throw new schema_1.Violation("Missing property '".concat((0, violation_1.formatPath)(path.concat([property])), "'."), path, {
53
53
  required: property,
54
54
  });
55
55
  }
@@ -63,8 +63,8 @@ var ObjectType = /** @class */ (function () {
63
63
  finally { if (e_1) throw e_1.error; }
64
64
  }
65
65
  try {
66
- for (var entries_1 = tslib_1.__values(entries), entries_1_1 = entries_1.next(); !entries_1_1.done; entries_1_1 = entries_1.next()) {
67
- var _g = tslib_1.__read(entries_1_1.value, 2), entryName = _g[0], entryValue = _g[1];
66
+ for (var entries_1 = (0, tslib_1.__values)(entries), entries_1_1 = entries_1.next(); !entries_1_1.done; entries_1_1 = entries_1.next()) {
67
+ var _g = (0, tslib_1.__read)(entries_1_1.value, 2), entryName = _g[0], entryValue = _g[1];
68
68
  var propertyPath = path.concat([entryName]);
69
69
  this.definition.propertyNames.validate(entryName, propertyPath);
70
70
  var propertyRule = this.definition.properties[entryName];
@@ -74,7 +74,7 @@ var ObjectType = /** @class */ (function () {
74
74
  continue;
75
75
  }
76
76
  if (this.definition.additionalProperties === false) {
77
- throw new schema_1.Violation("Unknown property '" + violation_1.formatPath(propertyPath) + "'.", propertyPath, {
77
+ throw new schema_1.Violation("Unknown property '".concat((0, violation_1.formatPath)(propertyPath), "'."), propertyPath, {
78
78
  additionalProperty: entryName,
79
79
  });
80
80
  }
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Violation = void 0;
4
4
  var tslib_1 = require("tslib");
5
5
  var Violation = /** @class */ (function (_super) {
6
- tslib_1.__extends(Violation, _super);
6
+ (0, tslib_1.__extends)(Violation, _super);
7
7
  function Violation(message, path, params) {
8
8
  var _this = _super.call(this, message) || this;
9
9
  _this.path = path;
@@ -5,7 +5,7 @@ var tslib_1 = require("tslib");
5
5
  var schema_1 = require("./schema");
6
6
  var violation_1 = require("./violation");
7
7
  var FORMAT = {
8
- pointer: function identifier(value) {
8
+ pointer: function pointer(value) {
9
9
  return /^(\.|([a-zA-Z_][a-zA-Z0-9_]*|\[[0-9]+])(\.[a-zA-Z_][a-zA-Z0-9_]*|\[[0-9]+])*)$/.test(value);
10
10
  },
11
11
  identifier: function identifier(value) {
@@ -17,7 +17,7 @@ var FORMAT = {
17
17
  date: function date(value) {
18
18
  return /^(\d\d\d\d)-(\d\d)-(\d\d)$/.test(value);
19
19
  },
20
- url: function date(value) {
20
+ url: function url(value) {
21
21
  try {
22
22
  // eslint-disable-next-line no-new
23
23
  new URL(value);
@@ -27,12 +27,24 @@ var FORMAT = {
27
27
  }
28
28
  return true;
29
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) {
38
+ return false;
39
+ }
40
+ return true;
41
+ },
30
42
  };
31
43
  var StringType = /** @class */ (function () {
32
44
  function StringType(definition) {
33
45
  if (definition === void 0) { definition = {}; }
34
46
  var _a, _b, _c;
35
- 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 : [] });
47
+ this.definition = (0, tslib_1.__assign)((0, 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 : [] });
36
48
  }
37
49
  StringType.prototype.getTypes = function () {
38
50
  return ['string'];
@@ -43,33 +55,33 @@ var StringType = /** @class */ (function () {
43
55
  StringType.prototype.validate = function (value, path) {
44
56
  if (path === void 0) { path = []; }
45
57
  if (!this.isValidType(value)) {
46
- throw new schema_1.Violation("Expected value of type string at path '" + violation_1.formatPath(path) + "', actual " + violation_1.describe(value) + ".", path, { type: 'string' });
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' });
47
59
  }
48
60
  var _a = this.definition, minLength = _a.minLength, maxLength = _a.maxLength;
49
61
  if (minLength >= 0 && minLength > value.length) {
50
- throw new schema_1.Violation("Expected " + (minLength === maxLength ? 'exactly' : 'at least') + " "
51
- + (minLength + " " + (minLength === 1 ? 'character' : 'characters') + " ")
52
- + ("at path '" + violation_1.formatPath(path) + "', actual " + value.length + "."), path, { limit: minLength });
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 });
53
65
  }
54
66
  if (maxLength >= 0 && maxLength < value.length) {
55
- throw new schema_1.Violation("Expected " + (minLength === maxLength ? 'exactly' : 'at most') + " "
56
- + (maxLength + " " + (maxLength === 1 ? 'character' : 'characters') + " ")
57
- + ("at path '" + violation_1.formatPath(path) + "', actual " + value.length + "."), path, { limit: maxLength });
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 });
58
70
  }
59
71
  var enumeration = this.definition.enumeration;
60
72
  if (enumeration.length > 0 && enumeration.indexOf(value) < 0) {
61
- throw new schema_1.Violation("Unexpected value at path '" + violation_1.formatPath(path) + "', expecting "
62
- + ("'" + (enumeration.length === 1
73
+ throw new schema_1.Violation("Unexpected value at path '".concat((0, violation_1.formatPath)(path), "', expecting ")
74
+ + "'".concat(enumeration.length === 1
63
75
  ? enumeration[0]
64
- : enumeration.slice(0, -1).join('\', \'') + "' or '" + enumeration.slice(-1)) + "', ")
65
- + ("found '" + value + "'."), path, { enumeration: enumeration });
76
+ : "".concat(enumeration.slice(0, -1).join('\', \''), "' or '").concat(enumeration.slice(-1)), "', ")
77
+ + "found '".concat(value, "'."), path, { enumeration: enumeration });
66
78
  }
67
79
  var _b = this.definition, format = _b.format, pattern = _b.pattern;
68
80
  if (format !== undefined && !FORMAT[format](value)) {
69
- throw new schema_1.Violation("Invalid " + format + " format at path '" + violation_1.formatPath(path) + "'.", path, { format: format });
81
+ throw new schema_1.Violation("Invalid ".concat(format, " format at path '").concat((0, violation_1.formatPath)(path), "'."), path, { format: format });
70
82
  }
71
83
  if (pattern !== undefined && !pattern.test(value)) {
72
- throw new schema_1.Violation("Invalid format at path '" + violation_1.formatPath(path) + "'.", path, { pattern: pattern });
84
+ throw new schema_1.Violation("Invalid format at path '".concat((0, violation_1.formatPath)(path), "'."), path, { pattern: pattern });
73
85
  }
74
86
  };
75
87
  return StringType;
@@ -10,16 +10,16 @@ var UnionType = /** @class */ (function () {
10
10
  for (var _i = 2; _i < arguments.length; _i++) {
11
11
  others[_i - 2] = arguments[_i];
12
12
  }
13
- this.schemas = tslib_1.__spreadArray([first, second], tslib_1.__read(others));
13
+ this.schemas = (0, tslib_1.__spreadArray)([first, second], (0, tslib_1.__read)(others), false);
14
14
  }
15
15
  UnionType.prototype.getTypes = function () {
16
16
  var e_1, _a, e_2, _b;
17
17
  var types = [];
18
18
  try {
19
- for (var _c = tslib_1.__values(this.schemas), _d = _c.next(); !_d.done; _d = _c.next()) {
19
+ for (var _c = (0, tslib_1.__values)(this.schemas), _d = _c.next(); !_d.done; _d = _c.next()) {
20
20
  var schema = _d.value;
21
21
  try {
22
- for (var _e = (e_2 = void 0, tslib_1.__values(schema.getTypes())), _f = _e.next(); !_f.done; _f = _e.next()) {
22
+ for (var _e = (e_2 = void 0, (0, tslib_1.__values)(schema.getTypes())), _f = _e.next(); !_f.done; _f = _e.next()) {
23
23
  var type = _f.value;
24
24
  if (types.indexOf(type) < 0) {
25
25
  types.push(type);
@@ -47,7 +47,7 @@ var UnionType = /** @class */ (function () {
47
47
  UnionType.prototype.isValidType = function (value) {
48
48
  var e_3, _a;
49
49
  try {
50
- for (var _b = tslib_1.__values(this.schemas), _c = _b.next(); !_c.done; _c = _b.next()) {
50
+ for (var _b = (0, tslib_1.__values)(this.schemas), _c = _b.next(); !_c.done; _c = _b.next()) {
51
51
  var schema = _c.value;
52
52
  if (schema.isValidType(value)) {
53
53
  return true;
@@ -67,7 +67,7 @@ var UnionType = /** @class */ (function () {
67
67
  var e_4, _a;
68
68
  if (path === void 0) { path = []; }
69
69
  try {
70
- for (var _b = tslib_1.__values(this.schemas), _c = _b.next(); !_c.done; _c = _b.next()) {
70
+ for (var _b = (0, tslib_1.__values)(this.schemas), _c = _b.next(); !_c.done; _c = _b.next()) {
71
71
  var schema = _c.value;
72
72
  if (schema.isValidType(value)) {
73
73
  schema.validate(value, path);
@@ -83,8 +83,8 @@ var UnionType = /** @class */ (function () {
83
83
  finally { if (e_4) throw e_4.error; }
84
84
  }
85
85
  var types = this.getTypes();
86
- throw new schema_1.Violation("Expected value of type " + types.slice(0, -1).join(', ') + " or " + types[types.length - 1] + " "
87
- + ("at path '" + violation_1.formatPath(path) + "', actual " + violation_1.describe(value) + "."), path, { type: types.join('|') });
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
88
  };
89
89
  return UnionType;
90
90
  }());
@@ -19,6 +19,6 @@ function describe(value) {
19
19
  }
20
20
  exports.describe = describe;
21
21
  function formatPath(path) {
22
- return "/" + path.join('/');
22
+ return "/".concat(path.join('/'));
23
23
  }
24
24
  exports.formatPath = formatPath;