@croct/sdk 0.6.1 → 0.9.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 (60) hide show
  1. package/activeRecord.d.ts +4 -3
  2. package/activeRecord.js +8 -0
  3. package/channel/beaconSocketChannel.js +1 -1
  4. package/channel/guaranteedChannel.js +4 -4
  5. package/channel/queuedChannel.js +3 -3
  6. package/channel/retryChannel.js +2 -2
  7. package/channel/socketChannel.js +2 -2
  8. package/cid/remoteAssigner.js +1 -1
  9. package/constants.js +1 -1
  10. package/container.d.ts +1 -0
  11. package/container.js +13 -7
  12. package/context.js +1 -1
  13. package/evaluator.d.ts +1 -1
  14. package/evaluator.js +6 -6
  15. package/facade/evaluatorFacade.d.ts +1 -1
  16. package/facade/evaluatorFacade.js +1 -1
  17. package/facade/sdkFacade.d.ts +1 -0
  18. package/facade/sdkFacade.js +8 -8
  19. package/facade/trackerFacade.js +5 -3
  20. package/logging/consoleLogger.js +1 -1
  21. package/logging/namespacedLogger.js +1 -1
  22. package/namespacedStorage.js +1 -1
  23. package/package.json +13 -12
  24. package/patch.d.ts +12 -8
  25. package/queue/inMemoryQueue.js +1 -1
  26. package/queue/monitoredQueue.js +1 -1
  27. package/retry/arbitraryPolicy.js +1 -1
  28. package/schema/attributeSchema.d.ts +2 -0
  29. package/schema/attributeSchema.js +8 -0
  30. package/schema/contentSchemas.d.ts +2 -0
  31. package/schema/contentSchemas.js +46 -0
  32. package/schema/eventSchemas.d.ts +3 -1
  33. package/schema/eventSchemas.js +29 -14
  34. package/schema/operationSchemas.d.ts +1 -0
  35. package/schema/operationSchemas.js +11 -1
  36. package/schema/sdkFacadeSchemas.js +1 -0
  37. package/schema/sdkSchemas.js +1 -0
  38. package/schema/userSchema.js +5 -16
  39. package/sdk.d.ts +1 -0
  40. package/sdk.js +11 -10
  41. package/sourceLocation.js +2 -2
  42. package/token/token.js +8 -8
  43. package/tracker.d.ts +1 -0
  44. package/tracker.js +15 -7
  45. package/trackingEvents.d.ts +31 -10
  46. package/trackingEvents.js +8 -6
  47. package/uuid.js +1 -1
  48. package/validation/arrayType.js +7 -7
  49. package/validation/booleanType.js +1 -1
  50. package/validation/functionType.js +1 -1
  51. package/validation/jsonType.d.ts +1 -0
  52. package/validation/jsonType.js +12 -6
  53. package/validation/nullType.js +1 -1
  54. package/validation/numberType.js +5 -5
  55. package/validation/objectType.js +10 -10
  56. package/validation/stringType.js +27 -15
  57. package/validation/unionType.js +3 -3
  58. package/validation/violation.js +1 -1
  59. package/json.d.ts +0 -11
  60. package/json.js +0 -2
@@ -35,15 +35,21 @@ 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
- if (this.definition.properties === undefined) {
40
+ if (this.definition.properties === undefined && this.definition.propertyNames === undefined) {
41
41
  return;
42
42
  }
43
43
  try {
44
44
  for (var _b = tslib_1.__values(Object.entries(value)), _c = _b.next(); !_c.done; _c = _b.next()) {
45
45
  var _d = tslib_1.__read(_c.value, 2), entryName = _d[0], entryValue = _d[1];
46
- this.definition.properties.validate(entryValue, path.concat([entryName]));
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
+ }
47
53
  }
48
54
  }
49
55
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
@@ -71,7 +77,7 @@ var JsonArrayType = /** @class */ (function () {
71
77
  JsonArrayType.prototype.validate = function (value, path) {
72
78
  if (path === void 0) { path = []; }
73
79
  if (!isJsonArray(value)) {
74
- 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' });
75
81
  }
76
82
  if (this.definition.items === undefined) {
77
83
  return;
@@ -95,7 +101,7 @@ var JsonPrimitiveType = /** @class */ (function () {
95
101
  JsonPrimitiveType.prototype.validate = function (value, path) {
96
102
  if (path === void 0) { path = []; }
97
103
  if (!this.isValidType(value)) {
98
- 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('|') });
99
105
  }
100
106
  };
101
107
  return JsonPrimitiveType;
@@ -113,7 +119,7 @@ var JsonType = /** @class */ (function () {
113
119
  JsonType.prototype.validate = function (value, path) {
114
120
  if (path === void 0) { path = []; }
115
121
  if (!isJsonValue(value)) {
116
- 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('|') });
117
123
  }
118
124
  };
119
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;
@@ -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;
@@ -29,27 +29,27 @@ var ObjectType = /** @class */ (function () {
29
29
  if (path === void 0) { path = []; }
30
30
  if (!this.isValidType(value)) {
31
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 });
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
47
  var additionalProperties = tslib_1.__assign({}, value);
48
48
  try {
49
49
  for (var _e = 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
  }
@@ -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
  }
@@ -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,6 +27,18 @@ 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) {
@@ -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,7 +10,7 @@ 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 = tslib_1.__spreadArray([first, second], tslib_1.__read(others), false);
14
14
  }
15
15
  UnionType.prototype.getTypes = function () {
16
16
  var e_1, _a, e_2, _b;
@@ -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;
package/json.d.ts DELETED
@@ -1,11 +0,0 @@
1
- export declare type JsonPrimitive = string | number | boolean | null;
2
- export declare type JsonObject = {
3
- [member: string]: JsonValue;
4
- };
5
- export declare type JsonArray = Array<JsonValue>;
6
- export declare type JsonValue = JsonPrimitive | JsonObject | JsonArray;
7
- export declare type LenientJsonObject = {
8
- [member: string]: LenientJsonValue | undefined;
9
- };
10
- export declare type LenientJsonArray = Array<JsonValue>;
11
- export declare type LenientJsonValue = JsonPrimitive | LenientJsonObject | LenientJsonArray;
package/json.js DELETED
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });