@croct/sdk 0.5.0 → 0.7.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 (187) hide show
  1. package/activeRecord.d.ts +1 -1
  2. package/activeRecord.js +15 -12
  3. package/base64Url.js +7 -2
  4. package/cache/cache.d.ts +12 -0
  5. package/cache/cache.js +2 -0
  6. package/cache/fallbackCache.d.ts +2 -2
  7. package/cache/fallbackCache.js +6 -3
  8. package/cache/inMemoryCache.d.ts +2 -2
  9. package/cache/inMemoryCache.js +5 -2
  10. package/cache/index.d.ts +4 -12
  11. package/cache/index.js +11 -0
  12. package/cache/localStorageCache.d.ts +2 -2
  13. package/cache/localStorageCache.js +4 -1
  14. package/channel/beaconSocketChannel.d.ts +3 -3
  15. package/channel/beaconSocketChannel.js +12 -9
  16. package/channel/channel.d.ts +15 -0
  17. package/channel/channel.js +2 -0
  18. package/channel/encodedChannel.d.ts +2 -2
  19. package/channel/encodedChannel.js +4 -1
  20. package/channel/guaranteedChannel.d.ts +1 -1
  21. package/channel/guaranteedChannel.js +10 -7
  22. package/channel/index.d.ts +8 -15
  23. package/channel/index.js +19 -0
  24. package/channel/queuedChannel.d.ts +2 -2
  25. package/channel/queuedChannel.js +10 -7
  26. package/channel/retryChannel.d.ts +3 -3
  27. package/channel/retryChannel.js +18 -15
  28. package/channel/sandboxChannel.d.ts +2 -2
  29. package/channel/sandboxChannel.js +4 -1
  30. package/channel/socketChannel.d.ts +1 -1
  31. package/channel/socketChannel.js +12 -9
  32. package/cid/assigner.d.ts +3 -0
  33. package/cid/assigner.js +2 -0
  34. package/cid/cachedAssigner.d.ts +5 -5
  35. package/cid/cachedAssigner.js +9 -6
  36. package/cid/fixedAssigner.d.ts +6 -0
  37. package/cid/fixedAssigner.js +13 -0
  38. package/cid/index.d.ts +4 -3
  39. package/cid/index.js +11 -0
  40. package/cid/remoteAssigner.d.ts +3 -3
  41. package/cid/remoteAssigner.js +11 -8
  42. package/constants.js +8 -5
  43. package/container.d.ts +5 -5
  44. package/container.js +49 -55
  45. package/context.d.ts +4 -4
  46. package/context.js +14 -13
  47. package/error.d.ts +1 -1
  48. package/error.js +7 -2
  49. package/evaluator.d.ts +2 -2
  50. package/evaluator.js +26 -23
  51. package/eventManager.d.ts +1 -1
  52. package/eventManager.js +5 -2
  53. package/facade/evaluatorFacade.d.ts +3 -3
  54. package/facade/evaluatorFacade.js +13 -10
  55. package/facade/index.d.ts +7 -0
  56. package/facade/index.js +19 -0
  57. package/facade/sdkFacade.d.ts +9 -9
  58. package/facade/sdkFacade.js +35 -32
  59. package/facade/sessionFacade.d.ts +3 -3
  60. package/facade/sessionFacade.js +6 -3
  61. package/facade/sessionPatch.d.ts +3 -3
  62. package/facade/sessionPatch.js +8 -5
  63. package/facade/trackerFacade.d.ts +2 -2
  64. package/facade/trackerFacade.js +21 -17
  65. package/facade/userFacade.d.ts +4 -4
  66. package/facade/userFacade.js +6 -3
  67. package/facade/userPatch.d.ts +3 -3
  68. package/facade/userPatch.js +8 -5
  69. package/index.d.ts +2 -2
  70. package/index.js +7 -3
  71. package/json.js +2 -0
  72. package/logging/consoleLogger.d.ts +2 -2
  73. package/logging/consoleLogger.js +8 -5
  74. package/logging/index.d.ts +4 -9
  75. package/logging/index.js +11 -0
  76. package/logging/logger.d.ts +9 -0
  77. package/logging/logger.js +2 -0
  78. package/logging/namespacedLogger.d.ts +2 -2
  79. package/logging/namespacedLogger.js +4 -1
  80. package/logging/nullLogger.d.ts +2 -2
  81. package/logging/nullLogger.js +4 -1
  82. package/namespacedStorage.d.ts +1 -1
  83. package/namespacedStorage.js +7 -4
  84. package/package.json +21 -18
  85. package/patch.js +2 -0
  86. package/queue/capacityRestrictedQueue.d.ts +2 -2
  87. package/queue/capacityRestrictedQueue.js +4 -1
  88. package/queue/inMemoryQueue.d.ts +2 -2
  89. package/queue/inMemoryQueue.js +6 -3
  90. package/queue/index.d.ts +5 -9
  91. package/queue/index.js +13 -0
  92. package/queue/monitoredQueue.d.ts +6 -6
  93. package/queue/monitoredQueue.js +6 -3
  94. package/queue/persistentQueue.d.ts +2 -2
  95. package/queue/persistentQueue.js +5 -2
  96. package/queue/queue.d.ts +9 -0
  97. package/queue/queue.js +2 -0
  98. package/retry/arbitraryPolicy.d.ts +2 -2
  99. package/retry/arbitraryPolicy.js +6 -3
  100. package/retry/backoffPolicy.d.ts +2 -2
  101. package/retry/backoffPolicy.js +4 -1
  102. package/retry/index.d.ts +5 -4
  103. package/retry/index.js +13 -0
  104. package/retry/maxAttemptsPolicy.d.ts +2 -2
  105. package/retry/maxAttemptsPolicy.js +4 -1
  106. package/retry/neverPolicy.d.ts +2 -2
  107. package/retry/neverPolicy.js +4 -1
  108. package/retry/policy.d.ts +4 -0
  109. package/retry/policy.js +2 -0
  110. package/schema/attributeSchema.d.ts +2 -0
  111. package/schema/attributeSchema.js +8 -0
  112. package/schema/contentSchemas.d.ts +2 -0
  113. package/schema/contentSchemas.js +46 -0
  114. package/schema/contextSchemas.d.ts +1 -1
  115. package/schema/contextSchemas.js +5 -2
  116. package/schema/ecommerceSchemas.d.ts +1 -1
  117. package/schema/ecommerceSchemas.js +60 -60
  118. package/schema/evaluationSchemas.d.ts +1 -1
  119. package/schema/evaluationSchemas.js +7 -6
  120. package/schema/eventSchemas.d.ts +3 -2
  121. package/schema/eventSchemas.js +53 -48
  122. package/schema/index.d.ts +10 -0
  123. package/schema/index.js +13 -0
  124. package/schema/loggerSchema.d.ts +1 -1
  125. package/schema/loggerSchema.js +9 -7
  126. package/schema/operationSchemas.d.ts +1 -1
  127. package/schema/operationSchemas.js +26 -24
  128. package/schema/sdkFacadeSchemas.d.ts +2 -2
  129. package/schema/sdkFacadeSchemas.js +22 -24
  130. package/schema/sdkSchemas.d.ts +2 -2
  131. package/schema/sdkSchemas.js +21 -22
  132. package/schema/tokenSchema.d.ts +2 -3
  133. package/schema/tokenSchema.js +18 -17
  134. package/schema/userSchema.d.ts +1 -1
  135. package/schema/userSchema.js +47 -61
  136. package/sdk.d.ts +5 -5
  137. package/sdk.js +27 -24
  138. package/sdkEvents.d.ts +2 -2
  139. package/sdkEvents.js +2 -0
  140. package/sourceLocation.js +12 -6
  141. package/tab.d.ts +2 -2
  142. package/tab.js +12 -9
  143. package/token/cachedTokenStore.d.ts +3 -3
  144. package/token/cachedTokenStore.js +6 -3
  145. package/token/inMemoryTokenStore.d.ts +2 -2
  146. package/token/inMemoryTokenStore.js +4 -1
  147. package/token/index.d.ts +4 -41
  148. package/token/index.js +11 -96
  149. package/token/replicatedTokenStore.d.ts +2 -2
  150. package/token/replicatedTokenStore.js +4 -1
  151. package/token/token.d.ts +41 -0
  152. package/token/token.js +99 -0
  153. package/tracker.d.ts +3 -3
  154. package/tracker.js +29 -26
  155. package/trackingEvents.d.ts +29 -14
  156. package/trackingEvents.js +20 -14
  157. package/transformer.js +5 -1
  158. package/utilityTypes.js +2 -0
  159. package/uuid.js +5 -1
  160. package/validation/arrayType.d.ts +2 -2
  161. package/validation/arrayType.js +13 -9
  162. package/validation/booleanType.d.ts +2 -2
  163. package/validation/booleanType.js +7 -3
  164. package/validation/functionType.d.ts +2 -2
  165. package/validation/functionType.js +7 -3
  166. package/validation/index.d.ts +12 -18
  167. package/validation/index.js +29 -30
  168. package/validation/jsonType.d.ts +2 -1
  169. package/validation/jsonType.js +25 -14
  170. package/validation/mixedSchema.d.ts +2 -2
  171. package/validation/mixedSchema.js +4 -1
  172. package/validation/nullType.d.ts +2 -2
  173. package/validation/nullType.js +7 -3
  174. package/validation/numberType.d.ts +2 -2
  175. package/validation/numberType.js +13 -9
  176. package/validation/objectType.d.ts +2 -2
  177. package/validation/objectType.js +23 -18
  178. package/validation/schema.d.ts +16 -0
  179. package/validation/schema.js +15 -0
  180. package/validation/stringType.d.ts +2 -2
  181. package/validation/stringType.js +16 -12
  182. package/validation/unionType.d.ts +2 -2
  183. package/validation/unionType.js +14 -10
  184. package/validation/violation.d.ts +2 -0
  185. package/validation/violation.js +24 -0
  186. package/cid/fixedCidAssigner.d.ts +0 -6
  187. package/cid/fixedCidAssigner.js +0 -10
@@ -1,5 +1,9 @@
1
- import { __read, __values } from "tslib";
2
- import { describe, formatPath, Violation } from './index';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
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");
3
7
  function isJsonPrimitive(value) {
4
8
  return value === null || typeof value === 'string' || typeof value === 'boolean' || typeof value === 'number';
5
9
  }
@@ -12,6 +16,7 @@ function isJsonValue(value) {
12
16
  function isJsonObject(value) {
13
17
  return isPlainObject(value) && Object.values(value).every(isJsonValue);
14
18
  }
19
+ // eslint-disable-next-line @typescript-eslint/ban-types
15
20
  function isPlainObject(value) {
16
21
  return Object.prototype.toString.call(value) === '[object Object]';
17
22
  }
@@ -30,15 +35,21 @@ var JsonObjectType = /** @class */ (function () {
30
35
  var e_1, _a;
31
36
  if (path === void 0) { path = []; }
32
37
  if (!isJsonObject(value)) {
33
- throw new Violation("Expected a JSON object at path '" + formatPath(path) + "', actual " + describe(value) + ".", path, { type: 'object' });
38
+ throw new schema_1.Violation("Expected a JSON object at path '" + violation_1.formatPath(path) + "', actual " + violation_1.describe(value) + ".", path, { type: 'object' });
34
39
  }
35
- if (this.definition.properties === undefined) {
40
+ if (this.definition.properties === undefined && this.definition.propertyNames === undefined) {
36
41
  return;
37
42
  }
38
43
  try {
39
- for (var _b = __values(Object.entries(value)), _c = _b.next(); !_c.done; _c = _b.next()) {
40
- var _d = __read(_c.value, 2), entryName = _d[0], entryValue = _d[1];
41
- this.definition.properties.validate(entryValue, path.concat([entryName]));
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
+ }
42
53
  }
43
54
  }
44
55
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
@@ -51,7 +62,7 @@ var JsonObjectType = /** @class */ (function () {
51
62
  };
52
63
  return JsonObjectType;
53
64
  }());
54
- export { JsonObjectType };
65
+ exports.JsonObjectType = JsonObjectType;
55
66
  var JsonArrayType = /** @class */ (function () {
56
67
  function JsonArrayType(definition) {
57
68
  if (definition === void 0) { definition = {}; }
@@ -66,7 +77,7 @@ var JsonArrayType = /** @class */ (function () {
66
77
  JsonArrayType.prototype.validate = function (value, path) {
67
78
  if (path === void 0) { path = []; }
68
79
  if (!isJsonArray(value)) {
69
- throw new Violation("Expected a JSON array at path '" + formatPath(path) + "', actual " + describe(value) + ".", path, { type: 'array' });
80
+ throw new schema_1.Violation("Expected a JSON array at path '" + violation_1.formatPath(path) + "', actual " + violation_1.describe(value) + ".", path, { type: 'array' });
70
81
  }
71
82
  if (this.definition.items === undefined) {
72
83
  return;
@@ -77,7 +88,7 @@ var JsonArrayType = /** @class */ (function () {
77
88
  };
78
89
  return JsonArrayType;
79
90
  }());
80
- export { JsonArrayType };
91
+ exports.JsonArrayType = JsonArrayType;
81
92
  var JsonPrimitiveType = /** @class */ (function () {
82
93
  function JsonPrimitiveType() {
83
94
  }
@@ -90,12 +101,12 @@ var JsonPrimitiveType = /** @class */ (function () {
90
101
  JsonPrimitiveType.prototype.validate = function (value, path) {
91
102
  if (path === void 0) { path = []; }
92
103
  if (!this.isValidType(value)) {
93
- throw new Violation("Expected a JSON primitive at path '" + formatPath(path) + "', actual " + describe(value) + ".", path, { type: this.getTypes().join('|') });
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('|') });
94
105
  }
95
106
  };
96
107
  return JsonPrimitiveType;
97
108
  }());
98
- export { JsonPrimitiveType };
109
+ exports.JsonPrimitiveType = JsonPrimitiveType;
99
110
  var JsonType = /** @class */ (function () {
100
111
  function JsonType() {
101
112
  }
@@ -108,9 +119,9 @@ var JsonType = /** @class */ (function () {
108
119
  JsonType.prototype.validate = function (value, path) {
109
120
  if (path === void 0) { path = []; }
110
121
  if (!isJsonValue(value)) {
111
- throw new Violation("Expected a JSON value at path '" + formatPath(path) + "', actual " + describe(value) + ".", path, { type: this.getTypes().join('|') });
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('|') });
112
123
  }
113
124
  };
114
125
  return JsonType;
115
126
  }());
116
- export { JsonType };
127
+ exports.JsonType = JsonType;
@@ -1,4 +1,4 @@
1
- import { Schema } from './index';
2
- export default class MixedSchema implements Schema {
1
+ import { Schema } from './schema';
2
+ export declare class MixedSchema implements Schema {
3
3
  validate(): void;
4
4
  }
@@ -1,3 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MixedSchema = void 0;
1
4
  var MixedSchema = /** @class */ (function () {
2
5
  function MixedSchema() {
3
6
  }
@@ -6,4 +9,4 @@ var MixedSchema = /** @class */ (function () {
6
9
  };
7
10
  return MixedSchema;
8
11
  }());
9
- export default MixedSchema;
12
+ exports.MixedSchema = MixedSchema;
@@ -1,5 +1,5 @@
1
- import { TypeSchema } from './index';
2
- export default class NullType implements TypeSchema {
1
+ import { TypeSchema } from './schema';
2
+ export declare class NullType implements TypeSchema {
3
3
  getTypes(): string[];
4
4
  isValidType(value: unknown): value is null;
5
5
  validate(value: unknown, path?: string[]): void;
@@ -1,4 +1,8 @@
1
- import { describe, formatPath, Violation } from './index';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NullType = void 0;
4
+ var schema_1 = require("./schema");
5
+ var violation_1 = require("./violation");
2
6
  var NullType = /** @class */ (function () {
3
7
  function NullType() {
4
8
  }
@@ -11,9 +15,9 @@ var NullType = /** @class */ (function () {
11
15
  NullType.prototype.validate = function (value, path) {
12
16
  if (path === void 0) { path = []; }
13
17
  if (!this.isValidType(value)) {
14
- throw new Violation("Expected value of type null at path '" + formatPath(path) + "', actual " + describe(value) + ".", path, { type: 'null' });
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' });
15
19
  }
16
20
  };
17
21
  return NullType;
18
22
  }());
19
- export default NullType;
23
+ exports.NullType = NullType;
@@ -1,10 +1,10 @@
1
- import { TypeSchema } from './index';
1
+ import { TypeSchema } from './schema';
2
2
  declare type NumberDefinition = {
3
3
  integer: boolean;
4
4
  minimum: number;
5
5
  maximum: number;
6
6
  };
7
- export default class NumberType implements TypeSchema {
7
+ export declare class NumberType implements TypeSchema {
8
8
  private readonly definition;
9
9
  constructor(definition?: Partial<NumberDefinition>);
10
10
  getTypes(): string[];
@@ -1,10 +1,14 @@
1
- import { __assign } from "tslib";
2
- import { describe, formatPath, Violation } from './index';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NumberType = void 0;
4
+ var tslib_1 = require("tslib");
5
+ var schema_1 = require("./schema");
6
+ var violation_1 = require("./violation");
3
7
  var NumberType = /** @class */ (function () {
4
8
  function NumberType(definition) {
5
9
  if (definition === void 0) { definition = {}; }
6
10
  var _a, _b, _c;
7
- this.definition = __assign(__assign({}, definition), { integer: (_a = definition.integer, (_a !== null && _a !== void 0 ? _a : false)), minimum: (_b = definition.minimum, (_b !== null && _b !== void 0 ? _b : Number.NEGATIVE_INFINITY)), maximum: (_c = definition.maximum, (_c !== null && _c !== void 0 ? _c : Number.POSITIVE_INFINITY)) });
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 });
8
12
  }
9
13
  NumberType.prototype.getTypes = function () {
10
14
  return [this.definition.integer ? 'integer' : 'number'];
@@ -16,17 +20,17 @@ var NumberType = /** @class */ (function () {
16
20
  if (path === void 0) { path = []; }
17
21
  if (!this.isValidType(value)) {
18
22
  var type = this.getTypes()[0];
19
- throw new Violation("Expected value of type " + type + " at path '" + formatPath(path) + "', actual " + describe(value) + ".", path, { type: type });
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 });
20
24
  }
21
25
  if (value < this.definition.minimum) {
22
- throw new Violation("Expected a value greater than or equal to " + this.definition.minimum + " "
23
- + ("at path '" + formatPath(path) + "', actual " + value + "."), path, { limit: 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 });
24
28
  }
25
29
  if (value > this.definition.maximum) {
26
- throw new Violation("Expected a value less than or equal to " + this.definition.maximum + " "
27
- + ("at path '" + formatPath(path) + "', actual " + value + "."), path, { limit: 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 });
28
32
  }
29
33
  };
30
34
  return NumberType;
31
35
  }());
32
- export default NumberType;
36
+ exports.NumberType = NumberType;
@@ -1,4 +1,4 @@
1
- import { Schema, TypeSchema } from './index';
1
+ import { Schema, TypeSchema } from './schema';
2
2
  declare type ObjectDefinition = {
3
3
  type?: {
4
4
  new (...args: any): any;
@@ -18,7 +18,7 @@ declare type ObjectDefinition = {
18
18
  minProperties: number;
19
19
  maxProperties: number;
20
20
  };
21
- export default class ObjectType implements TypeSchema {
21
+ export declare class ObjectType implements TypeSchema {
22
22
  private readonly definition;
23
23
  constructor(schema?: Partial<ObjectDefinition>);
24
24
  getTypes(): string[];
@@ -1,11 +1,15 @@
1
- import { __assign, __read, __values } from "tslib";
2
- import { describe, formatPath, Violation } from './index';
3
- import MixedSchema from './mixedSchema';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
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");
4
8
  var ObjectType = /** @class */ (function () {
5
9
  function ObjectType(schema) {
6
10
  if (schema === void 0) { schema = {}; }
7
11
  var _a, _b, _c, _d, _e, _f;
8
- this.definition = __assign(__assign({}, schema), { properties: (_a = schema.properties, (_a !== null && _a !== void 0 ? _a : {})), required: (_b = schema.required, (_b !== null && _b !== void 0 ? _b : [])), additionalProperties: (_c = schema.additionalProperties, (_c !== null && _c !== void 0 ? _c : false)), propertyNames: (_d = schema.propertyNames, (_d !== null && _d !== void 0 ? _d : new MixedSchema())), minProperties: (_e = schema.minProperties, (_e !== null && _e !== void 0 ? _e : -1)), maxProperties: (_f = schema.maxProperties, (_f !== null && _f !== void 0 ? _f : -1)) });
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 });
9
13
  }
10
14
  ObjectType.prototype.getTypes = function () {
11
15
  if (this.definition.type !== undefined) {
@@ -13,6 +17,7 @@ var ObjectType = /** @class */ (function () {
13
17
  }
14
18
  return ['object'];
15
19
  };
20
+ // eslint-disable-next-line @typescript-eslint/ban-types
16
21
  ObjectType.prototype.isValidType = function (value) {
17
22
  if (this.definition.type !== undefined) {
18
23
  return value instanceof this.definition.type;
@@ -23,28 +28,28 @@ var ObjectType = /** @class */ (function () {
23
28
  var e_1, _a, e_2, _b;
24
29
  if (path === void 0) { path = []; }
25
30
  if (!this.isValidType(value)) {
26
- var _c = __read(this.getTypes(), 1), type = _c[0];
27
- throw new Violation("Expected value of type " + type + " at path '" + formatPath(path) + "', "
28
- + ("actual " + describe(value) + "."), path, { type: type });
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 });
29
34
  }
30
35
  var entries = Object.entries(value);
31
36
  var _d = this.definition, minProperties = _d.minProperties, maxProperties = _d.maxProperties;
32
37
  if (minProperties >= 0 && minProperties > entries.length) {
33
- throw new Violation("Expected " + (minProperties === maxProperties ? 'exactly' : 'at least') + " "
38
+ throw new schema_1.Violation("Expected " + (minProperties === maxProperties ? 'exactly' : 'at least') + " "
34
39
  + (minProperties + " " + (minProperties === 1 ? 'entry' : 'entries') + " ")
35
- + ("at path '" + formatPath(path) + "', actual " + entries.length + "."), path, { limit: minProperties });
40
+ + ("at path '" + violation_1.formatPath(path) + "', actual " + entries.length + "."), path, { limit: minProperties });
36
41
  }
37
42
  if (maxProperties >= 0 && maxProperties < entries.length) {
38
- throw new Violation("Expected " + (minProperties === maxProperties ? 'exactly' : 'at most') + " "
43
+ throw new schema_1.Violation("Expected " + (minProperties === maxProperties ? 'exactly' : 'at most') + " "
39
44
  + (maxProperties + " " + (maxProperties === 1 ? 'entry' : 'entries') + " ")
40
- + ("at path '" + formatPath(path) + "', actual " + entries.length + "."), path, { limit: maxProperties });
45
+ + ("at path '" + violation_1.formatPath(path) + "', actual " + entries.length + "."), path, { limit: maxProperties });
41
46
  }
42
- var additionalProperties = __assign({}, value);
47
+ var additionalProperties = tslib_1.__assign({}, value);
43
48
  try {
44
- for (var _e = __values(this.definition.required), _f = _e.next(); !_f.done; _f = _e.next()) {
49
+ for (var _e = tslib_1.__values(this.definition.required), _f = _e.next(); !_f.done; _f = _e.next()) {
45
50
  var property = _f.value;
46
51
  if (!(property in value)) {
47
- throw new Violation("Missing property '" + formatPath(path.concat([property])) + "'.", path, {
52
+ throw new schema_1.Violation("Missing property '" + violation_1.formatPath(path.concat([property])) + "'.", path, {
48
53
  required: property,
49
54
  });
50
55
  }
@@ -58,8 +63,8 @@ var ObjectType = /** @class */ (function () {
58
63
  finally { if (e_1) throw e_1.error; }
59
64
  }
60
65
  try {
61
- for (var entries_1 = __values(entries), entries_1_1 = entries_1.next(); !entries_1_1.done; entries_1_1 = entries_1.next()) {
62
- var _g = __read(entries_1_1.value, 2), entryName = _g[0], entryValue = _g[1];
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];
63
68
  var propertyPath = path.concat([entryName]);
64
69
  this.definition.propertyNames.validate(entryName, propertyPath);
65
70
  var propertyRule = this.definition.properties[entryName];
@@ -69,7 +74,7 @@ var ObjectType = /** @class */ (function () {
69
74
  continue;
70
75
  }
71
76
  if (this.definition.additionalProperties === false) {
72
- throw new Violation("Unknown property '" + formatPath(propertyPath) + "'.", propertyPath, {
77
+ throw new schema_1.Violation("Unknown property '" + violation_1.formatPath(propertyPath) + "'.", propertyPath, {
73
78
  additionalProperty: entryName,
74
79
  });
75
80
  }
@@ -95,4 +100,4 @@ var ObjectType = /** @class */ (function () {
95
100
  };
96
101
  return ObjectType;
97
102
  }());
98
- export default ObjectType;
103
+ exports.ObjectType = ObjectType;
@@ -0,0 +1,16 @@
1
+ export interface Schema {
2
+ validate(value: unknown, path?: string[]): void;
3
+ }
4
+ export interface TypeSchema extends Schema {
5
+ getTypes(): string[];
6
+ isValidType(value: unknown): boolean;
7
+ }
8
+ export declare class Violation extends Error {
9
+ readonly path: string[];
10
+ readonly params: {
11
+ [key: string]: unknown;
12
+ };
13
+ constructor(message: string, path: string[], params: {
14
+ [p: string]: unknown;
15
+ });
16
+ }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
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;
12
+ }
13
+ return Violation;
14
+ }(Error));
15
+ exports.Violation = Violation;
@@ -1,4 +1,4 @@
1
- import { TypeSchema } from './index';
1
+ import { TypeSchema } from './schema';
2
2
  interface Format {
3
3
  (value: string): boolean;
4
4
  }
@@ -12,7 +12,7 @@ declare type StringDefinition = {
12
12
  pattern?: RegExp;
13
13
  format?: keyof typeof FORMAT;
14
14
  };
15
- export default class StringType implements TypeSchema {
15
+ export declare class StringType implements TypeSchema {
16
16
  private readonly definition;
17
17
  constructor(definition?: Partial<StringDefinition>);
18
18
  getTypes(): string[];
@@ -1,5 +1,9 @@
1
- import { __assign } from "tslib";
2
- import { describe, formatPath, Violation } from './index';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StringType = void 0;
4
+ var tslib_1 = require("tslib");
5
+ var schema_1 = require("./schema");
6
+ var violation_1 = require("./violation");
3
7
  var FORMAT = {
4
8
  pointer: function identifier(value) {
5
9
  return /^(\.|([a-zA-Z_][a-zA-Z0-9_]*|\[[0-9]+])(\.[a-zA-Z_][a-zA-Z0-9_]*|\[[0-9]+])*)$/.test(value);
@@ -28,7 +32,7 @@ var StringType = /** @class */ (function () {
28
32
  function StringType(definition) {
29
33
  if (definition === void 0) { definition = {}; }
30
34
  var _a, _b, _c;
31
- this.definition = __assign(__assign({}, definition), { minLength: (_a = definition.minLength, (_a !== null && _a !== void 0 ? _a : -1)), maxLength: (_b = definition.maxLength, (_b !== null && _b !== void 0 ? _b : -1)), enumeration: (_c = definition.enumeration, (_c !== null && _c !== void 0 ? _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 : [] });
32
36
  }
33
37
  StringType.prototype.getTypes = function () {
34
38
  return ['string'];
@@ -39,22 +43,22 @@ var StringType = /** @class */ (function () {
39
43
  StringType.prototype.validate = function (value, path) {
40
44
  if (path === void 0) { path = []; }
41
45
  if (!this.isValidType(value)) {
42
- throw new Violation("Expected value of type string at path '" + formatPath(path) + "', actual " + describe(value) + ".", path, { type: 'string' });
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' });
43
47
  }
44
48
  var _a = this.definition, minLength = _a.minLength, maxLength = _a.maxLength;
45
49
  if (minLength >= 0 && minLength > value.length) {
46
- throw new Violation("Expected " + (minLength === maxLength ? 'exactly' : 'at least') + " "
50
+ throw new schema_1.Violation("Expected " + (minLength === maxLength ? 'exactly' : 'at least') + " "
47
51
  + (minLength + " " + (minLength === 1 ? 'character' : 'characters') + " ")
48
- + ("at path '" + formatPath(path) + "', actual " + value.length + "."), path, { limit: minLength });
52
+ + ("at path '" + violation_1.formatPath(path) + "', actual " + value.length + "."), path, { limit: minLength });
49
53
  }
50
54
  if (maxLength >= 0 && maxLength < value.length) {
51
- throw new Violation("Expected " + (minLength === maxLength ? 'exactly' : 'at most') + " "
55
+ throw new schema_1.Violation("Expected " + (minLength === maxLength ? 'exactly' : 'at most') + " "
52
56
  + (maxLength + " " + (maxLength === 1 ? 'character' : 'characters') + " ")
53
- + ("at path '" + formatPath(path) + "', actual " + value.length + "."), path, { limit: maxLength });
57
+ + ("at path '" + violation_1.formatPath(path) + "', actual " + value.length + "."), path, { limit: maxLength });
54
58
  }
55
59
  var enumeration = this.definition.enumeration;
56
60
  if (enumeration.length > 0 && enumeration.indexOf(value) < 0) {
57
- throw new Violation("Unexpected value at path '" + formatPath(path) + "', expecting "
61
+ throw new schema_1.Violation("Unexpected value at path '" + violation_1.formatPath(path) + "', expecting "
58
62
  + ("'" + (enumeration.length === 1
59
63
  ? enumeration[0]
60
64
  : enumeration.slice(0, -1).join('\', \'') + "' or '" + enumeration.slice(-1)) + "', ")
@@ -62,12 +66,12 @@ var StringType = /** @class */ (function () {
62
66
  }
63
67
  var _b = this.definition, format = _b.format, pattern = _b.pattern;
64
68
  if (format !== undefined && !FORMAT[format](value)) {
65
- throw new Violation("Invalid " + format + " format at path '" + formatPath(path) + "'.", path, { format: format });
69
+ throw new schema_1.Violation("Invalid " + format + " format at path '" + violation_1.formatPath(path) + "'.", path, { format: format });
66
70
  }
67
71
  if (pattern !== undefined && !pattern.test(value)) {
68
- throw new Violation("Invalid format at path '" + formatPath(path) + "'.", path, { pattern: pattern });
72
+ throw new schema_1.Violation("Invalid format at path '" + violation_1.formatPath(path) + "'.", path, { pattern: pattern });
69
73
  }
70
74
  };
71
75
  return StringType;
72
76
  }());
73
- export default StringType;
77
+ exports.StringType = StringType;
@@ -1,5 +1,5 @@
1
- import { TypeSchema } from './index';
2
- export default class UnionType implements TypeSchema {
1
+ import { TypeSchema } from './schema';
2
+ export declare class UnionType implements TypeSchema {
3
3
  private readonly schemas;
4
4
  constructor(first: TypeSchema, second: TypeSchema, ...others: TypeSchema[]);
5
5
  getTypes(): string[];
@@ -1,21 +1,25 @@
1
- import { __read, __spread, __values } from "tslib";
2
- import { describe, formatPath, Violation } from './index';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UnionType = void 0;
4
+ var tslib_1 = require("tslib");
5
+ var schema_1 = require("./schema");
6
+ var violation_1 = require("./violation");
3
7
  var UnionType = /** @class */ (function () {
4
8
  function UnionType(first, second) {
5
9
  var others = [];
6
10
  for (var _i = 2; _i < arguments.length; _i++) {
7
11
  others[_i - 2] = arguments[_i];
8
12
  }
9
- this.schemas = __spread([first, second], others);
13
+ this.schemas = tslib_1.__spreadArray([first, second], tslib_1.__read(others));
10
14
  }
11
15
  UnionType.prototype.getTypes = function () {
12
16
  var e_1, _a, e_2, _b;
13
17
  var types = [];
14
18
  try {
15
- for (var _c = __values(this.schemas), _d = _c.next(); !_d.done; _d = _c.next()) {
19
+ for (var _c = tslib_1.__values(this.schemas), _d = _c.next(); !_d.done; _d = _c.next()) {
16
20
  var schema = _d.value;
17
21
  try {
18
- for (var _e = (e_2 = void 0, __values(schema.getTypes())), _f = _e.next(); !_f.done; _f = _e.next()) {
22
+ for (var _e = (e_2 = void 0, tslib_1.__values(schema.getTypes())), _f = _e.next(); !_f.done; _f = _e.next()) {
19
23
  var type = _f.value;
20
24
  if (types.indexOf(type) < 0) {
21
25
  types.push(type);
@@ -43,7 +47,7 @@ var UnionType = /** @class */ (function () {
43
47
  UnionType.prototype.isValidType = function (value) {
44
48
  var e_3, _a;
45
49
  try {
46
- for (var _b = __values(this.schemas), _c = _b.next(); !_c.done; _c = _b.next()) {
50
+ for (var _b = tslib_1.__values(this.schemas), _c = _b.next(); !_c.done; _c = _b.next()) {
47
51
  var schema = _c.value;
48
52
  if (schema.isValidType(value)) {
49
53
  return true;
@@ -63,7 +67,7 @@ var UnionType = /** @class */ (function () {
63
67
  var e_4, _a;
64
68
  if (path === void 0) { path = []; }
65
69
  try {
66
- for (var _b = __values(this.schemas), _c = _b.next(); !_c.done; _c = _b.next()) {
70
+ for (var _b = tslib_1.__values(this.schemas), _c = _b.next(); !_c.done; _c = _b.next()) {
67
71
  var schema = _c.value;
68
72
  if (schema.isValidType(value)) {
69
73
  schema.validate(value, path);
@@ -79,9 +83,9 @@ var UnionType = /** @class */ (function () {
79
83
  finally { if (e_4) throw e_4.error; }
80
84
  }
81
85
  var types = this.getTypes();
82
- throw new Violation("Expected value of type " + types.slice(0, -1).join(', ') + " or " + types[types.length - 1] + " "
83
- + ("at path '" + formatPath(path) + "', actual " + describe(value) + "."), path, { type: types.join('|') });
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('|') });
84
88
  };
85
89
  return UnionType;
86
90
  }());
87
- export default UnionType;
91
+ exports.UnionType = UnionType;
@@ -0,0 +1,2 @@
1
+ export declare function describe(value: unknown): string;
2
+ export declare function formatPath(path: string[]): string;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatPath = exports.describe = void 0;
4
+ function describe(value) {
5
+ if (value === null) {
6
+ return 'null';
7
+ }
8
+ if (Array.isArray(value)) {
9
+ return 'array';
10
+ }
11
+ if (typeof value === 'number') {
12
+ return Number.isInteger(value) ? 'integer' : 'number';
13
+ }
14
+ if (typeof value === 'object') {
15
+ // eslint-disable-next-line @typescript-eslint/ban-types
16
+ return value.constructor.name;
17
+ }
18
+ return typeof value;
19
+ }
20
+ exports.describe = describe;
21
+ function formatPath(path) {
22
+ return "/" + path.join('/');
23
+ }
24
+ exports.formatPath = formatPath;
@@ -1,6 +0,0 @@
1
- import CidAssigner from './index';
2
- export default class FixedCidAssigner implements CidAssigner {
3
- private readonly cid;
4
- constructor(cid: string);
5
- assignCid(): Promise<string>;
6
- }
@@ -1,10 +0,0 @@
1
- var FixedCidAssigner = /** @class */ (function () {
2
- function FixedCidAssigner(cid) {
3
- this.cid = cid;
4
- }
5
- FixedCidAssigner.prototype.assignCid = function () {
6
- return Promise.resolve(this.cid);
7
- };
8
- return FixedCidAssigner;
9
- }());
10
- export default FixedCidAssigner;