@croct/sdk 0.9.1 → 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 +8 -9
  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 -73
  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,10 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TrackerFacade = void 0;
4
- var tslib_1 = require("tslib");
5
- var error_1 = require("../error");
6
- var schema_1 = require("../schema");
7
- var eventSchemas = {
4
+ const error_1 = require("../error");
5
+ const schema_1 = require("../schema");
6
+ const eventSchemas = {
8
7
  cartViewed: schema_1.cartViewed,
9
8
  cartModified: schema_1.cartModified,
10
9
  checkoutStarted: schema_1.checkoutStarted,
@@ -17,6 +16,18 @@ var eventSchemas = {
17
16
  goalCompleted: schema_1.goalCompleted,
18
17
  linkOpened: schema_1.linkOpened,
19
18
  };
19
+ function validateEvent(event) {
20
+ const { type, ...payload } = event;
21
+ if (!(type in eventSchemas)) {
22
+ throw new Error(`Unknown event type '${type}'.`);
23
+ }
24
+ try {
25
+ eventSchemas[type].validate(payload);
26
+ }
27
+ catch (violation) {
28
+ throw new Error(`Invalid event payload: ${(0, error_1.formatCause)(violation)}`);
29
+ }
30
+ }
20
31
  function createEvent(type, payload) {
21
32
  if (typeof type !== 'string') {
22
33
  throw new Error('The event type must of type string.');
@@ -24,48 +35,31 @@ function createEvent(type, payload) {
24
35
  if (typeof payload !== 'object' || payload == null) {
25
36
  throw new Error('The event payload must of type object.');
26
37
  }
27
- var event = tslib_1.__assign({ type: type }, payload);
38
+ const event = { type: type, ...payload };
28
39
  validateEvent(event);
29
40
  return event;
30
41
  }
31
- function validateEvent(event) {
32
- var type = event.type, payload = tslib_1.__rest(event, ["type"]);
33
- if (!(type in eventSchemas)) {
34
- throw new Error("Unknown event type '".concat(type, "'."));
35
- }
36
- try {
37
- eventSchemas[type].validate(payload);
38
- }
39
- catch (violation) {
40
- throw new Error("Invalid event payload: ".concat((0, error_1.formatCause)(violation)));
41
- }
42
- }
43
- var TrackerFacade = /** @class */ (function () {
44
- function TrackerFacade(tracker) {
42
+ class TrackerFacade {
43
+ constructor(tracker) {
45
44
  this.tracker = tracker;
46
45
  }
47
- Object.defineProperty(TrackerFacade.prototype, "flushed", {
48
- get: function () {
49
- return this.tracker.flushed;
50
- },
51
- enumerable: false,
52
- configurable: true
53
- });
54
- TrackerFacade.prototype.enable = function () {
46
+ get flushed() {
47
+ return this.tracker.flushed;
48
+ }
49
+ enable() {
55
50
  this.tracker.enable();
56
- };
57
- TrackerFacade.prototype.disable = function () {
51
+ }
52
+ disable() {
58
53
  this.tracker.disable();
59
- };
60
- TrackerFacade.prototype.addListener = function (listener) {
54
+ }
55
+ addListener(listener) {
61
56
  this.tracker.addListener(listener);
62
- };
63
- TrackerFacade.prototype.removeListener = function (listener) {
57
+ }
58
+ removeListener(listener) {
64
59
  this.tracker.removeListener(listener);
65
- };
66
- TrackerFacade.prototype.track = function (type, payload) {
60
+ }
61
+ track(type, payload) {
67
62
  return this.tracker.track(createEvent(type, payload));
68
- };
69
- return TrackerFacade;
70
- }());
63
+ }
64
+ }
71
65
  exports.TrackerFacade = TrackerFacade;
@@ -1,21 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.UserFacade = void 0;
4
- var userPatch_1 = require("./userPatch");
5
- var UserFacade = /** @class */ (function () {
6
- function UserFacade(context, tracker) {
4
+ const userPatch_1 = require("./userPatch");
5
+ class UserFacade {
6
+ constructor(context, tracker) {
7
7
  this.context = context;
8
8
  this.tracker = tracker;
9
9
  }
10
- UserFacade.prototype.isIdentified = function () {
10
+ isIdentified() {
11
11
  return !this.isAnonymous();
12
- };
13
- UserFacade.prototype.isAnonymous = function () {
12
+ }
13
+ isAnonymous() {
14
14
  return this.context.isAnonymous();
15
- };
16
- UserFacade.prototype.edit = function () {
15
+ }
16
+ edit() {
17
17
  return new userPatch_1.UserPatch(this.tracker);
18
- };
19
- return UserFacade;
20
- }());
18
+ }
19
+ }
21
20
  exports.UserFacade = UserFacade;
@@ -1,16 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.UserPatch = void 0;
4
- var tslib_1 = require("tslib");
5
- var activeRecord_1 = require("../activeRecord");
6
- var UserPatch = /** @class */ (function (_super) {
7
- tslib_1.__extends(UserPatch, _super);
8
- function UserPatch(tracker) {
9
- var _this = _super.call(this) || this;
10
- _this.tracker = tracker;
11
- return _this;
4
+ const activeRecord_1 = require("../activeRecord");
5
+ class UserPatch extends activeRecord_1.ActiveRecord {
6
+ constructor(tracker) {
7
+ super();
8
+ this.tracker = tracker;
12
9
  }
13
- UserPatch.prototype.save = function () {
10
+ save() {
14
11
  if (!this.isDirty()) {
15
12
  // Empty patch
16
13
  return Promise.resolve({
@@ -18,13 +15,12 @@ var UserPatch = /** @class */ (function (_super) {
18
15
  patch: { operations: [] },
19
16
  });
20
17
  }
21
- var promise = this.tracker.track({
18
+ const promise = this.tracker.track({
22
19
  type: 'userProfileChanged',
23
20
  patch: this.buildPatch(),
24
21
  });
25
22
  this.reset();
26
23
  return promise;
27
- };
28
- return UserPatch;
29
- }(activeRecord_1.ActiveRecord));
24
+ }
25
+ }
30
26
  exports.UserPatch = UserPatch;
package/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = exports.Sdk = void 0;
4
- var constants_1 = require("./constants");
4
+ const constants_1 = require("./constants");
5
5
  Object.defineProperty(exports, "VERSION", { enumerable: true, get: function () { return constants_1.VERSION; } });
6
- var sdk_1 = require("./sdk");
6
+ const sdk_1 = require("./sdk");
7
7
  Object.defineProperty(exports, "Sdk", { enumerable: true, get: function () { return sdk_1.Sdk; } });
@@ -1,44 +1,27 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ConsoleLogger = void 0;
4
- var ConsoleLogger = /** @class */ (function () {
5
- function ConsoleLogger(namespace) {
4
+ class ConsoleLogger {
5
+ constructor(namespace) {
6
6
  this.namespace = namespace;
7
7
  }
8
- Object.defineProperty(ConsoleLogger.prototype, "debug", {
9
- get: function () {
10
- return this.bind(window.console.debug);
11
- },
12
- enumerable: false,
13
- configurable: true
14
- });
15
- Object.defineProperty(ConsoleLogger.prototype, "info", {
16
- get: function () {
17
- return this.bind(window.console.info);
18
- },
19
- enumerable: false,
20
- configurable: true
21
- });
22
- Object.defineProperty(ConsoleLogger.prototype, "warn", {
23
- get: function () {
24
- return this.bind(window.console.warn);
25
- },
26
- enumerable: false,
27
- configurable: true
28
- });
29
- Object.defineProperty(ConsoleLogger.prototype, "error", {
30
- get: function () {
31
- return this.bind(window.console.error);
32
- },
33
- enumerable: false,
34
- configurable: true
35
- });
36
- ConsoleLogger.prototype.bind = function (method) {
8
+ get debug() {
9
+ return this.bind(window.console.debug);
10
+ }
11
+ get info() {
12
+ return this.bind(window.console.info);
13
+ }
14
+ get warn() {
15
+ return this.bind(window.console.warn);
16
+ }
17
+ get error() {
18
+ return this.bind(window.console.error);
19
+ }
20
+ bind(method) {
37
21
  if (this.namespace !== undefined) {
38
- return method.bind(window.console, "[".concat(this.namespace, "]"));
22
+ return method.bind(window.console, `[${this.namespace}]`);
39
23
  }
40
24
  return method.bind(window.console);
41
- };
42
- return ConsoleLogger;
43
- }());
25
+ }
26
+ }
44
27
  exports.ConsoleLogger = ConsoleLogger;
package/logging/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.NullLogger = exports.NamespacedLogger = exports.ConsoleLogger = void 0;
4
- var tslib_1 = require("tslib");
4
+ const tslib_1 = require("tslib");
5
5
  tslib_1.__exportStar(require("./logger"), exports);
6
6
  var consoleLogger_1 = require("./consoleLogger");
7
7
  Object.defineProperty(exports, "ConsoleLogger", { enumerable: true, get: function () { return consoleLogger_1.ConsoleLogger; } });
@@ -1,26 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.NamespacedLogger = void 0;
4
- var NamespacedLogger = /** @class */ (function () {
5
- function NamespacedLogger(logger, namespace) {
4
+ class NamespacedLogger {
5
+ constructor(logger, namespace) {
6
6
  this.logger = logger;
7
7
  this.namespace = namespace;
8
8
  }
9
- NamespacedLogger.prototype.debug = function (message) {
9
+ debug(message) {
10
10
  this.logger.debug(this.format(message));
11
- };
12
- NamespacedLogger.prototype.info = function (message) {
11
+ }
12
+ info(message) {
13
13
  this.logger.info(this.format(message));
14
- };
15
- NamespacedLogger.prototype.warn = function (message) {
14
+ }
15
+ warn(message) {
16
16
  this.logger.warn(this.format(message));
17
- };
18
- NamespacedLogger.prototype.error = function (message) {
17
+ }
18
+ error(message) {
19
19
  this.logger.error(this.format(message));
20
- };
21
- NamespacedLogger.prototype.format = function (message) {
22
- return "[".concat(this.namespace, "] ").concat(message);
23
- };
24
- return NamespacedLogger;
25
- }());
20
+ }
21
+ format(message) {
22
+ return `[${this.namespace}] ${message}`;
23
+ }
24
+ }
26
25
  exports.NamespacedLogger = NamespacedLogger;
@@ -1,21 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.NullLogger = void 0;
4
- var NullLogger = /** @class */ (function () {
5
- function NullLogger() {
6
- }
7
- NullLogger.prototype.debug = function () {
4
+ class NullLogger {
5
+ debug() {
8
6
  // suppress debug logs
9
- };
10
- NullLogger.prototype.info = function () {
7
+ }
8
+ info() {
11
9
  // suppress info logs
12
- };
13
- NullLogger.prototype.warn = function () {
10
+ }
11
+ warn() {
14
12
  // suppress warning logs
15
- };
16
- NullLogger.prototype.error = function () {
13
+ }
14
+ error() {
17
15
  // suppress error logs
18
- };
19
- return NullLogger;
20
- }());
16
+ }
17
+ }
21
18
  exports.NullLogger = NullLogger;
@@ -1,71 +1,54 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.NamespacedStorage = void 0;
4
- var tslib_1 = require("tslib");
5
- var NamespacedStorage = /** @class */ (function () {
6
- function NamespacedStorage(storage, namespace) {
4
+ class NamespacedStorage {
5
+ constructor(storage, namespace) {
7
6
  if (namespace === '') {
8
7
  throw new Error('The namespace cannot be empty.');
9
8
  }
10
9
  this.storage = storage;
11
10
  this.namespace = namespace;
12
11
  }
13
- Object.defineProperty(NamespacedStorage.prototype, "length", {
14
- get: function () {
15
- return this.getKeys().length;
16
- },
17
- enumerable: false,
18
- configurable: true
19
- });
20
- NamespacedStorage.prototype.clear = function () {
21
- var e_1, _a;
22
- try {
23
- for (var _b = tslib_1.__values(this.getKeys()), _c = _b.next(); !_c.done; _c = _b.next()) {
24
- var key = _c.value;
25
- this.storage.removeItem(key);
26
- }
27
- }
28
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
29
- finally {
30
- try {
31
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
32
- }
33
- finally { if (e_1) throw e_1.error; }
12
+ get length() {
13
+ return this.getKeys().length;
14
+ }
15
+ clear() {
16
+ for (const key of this.getKeys()) {
17
+ this.storage.removeItem(key);
34
18
  }
35
- };
36
- NamespacedStorage.prototype.getItem = function (key) {
19
+ }
20
+ getItem(key) {
37
21
  return this.storage.getItem(this.getPrefixedKey(key));
38
- };
39
- NamespacedStorage.prototype.key = function (index) {
40
- var keys = this.getKeys();
22
+ }
23
+ key(index) {
24
+ const keys = this.getKeys();
41
25
  if (index >= keys.length) {
42
26
  return null;
43
27
  }
44
28
  return keys[index].substring(this.namespace.length + 1);
45
- };
46
- NamespacedStorage.prototype.removeItem = function (key) {
29
+ }
30
+ removeItem(key) {
47
31
  this.storage.removeItem(this.getPrefixedKey(key));
48
- };
49
- NamespacedStorage.prototype.setItem = function (key, value) {
32
+ }
33
+ setItem(key, value) {
50
34
  this.storage.setItem(this.getPrefixedKey(key), value);
51
- };
52
- NamespacedStorage.prototype.getKeys = function () {
53
- var keys = [];
54
- var prefix = this.getPrefix();
55
- for (var index = 0; index < this.storage.length; index++) {
56
- var key = this.storage.key(index);
35
+ }
36
+ getKeys() {
37
+ const keys = [];
38
+ const prefix = this.getPrefix();
39
+ for (let index = 0; index < this.storage.length; index++) {
40
+ const key = this.storage.key(index);
57
41
  if (key !== null && key.indexOf(prefix) === 0) {
58
42
  keys.push(key);
59
43
  }
60
44
  }
61
45
  return keys;
62
- };
63
- NamespacedStorage.prototype.getPrefixedKey = function (key) {
46
+ }
47
+ getPrefixedKey(key) {
64
48
  return this.getPrefix() + key;
65
- };
66
- NamespacedStorage.prototype.getPrefix = function () {
67
- return "".concat(this.namespace, ".");
68
- };
69
- return NamespacedStorage;
70
- }());
49
+ }
50
+ getPrefix() {
51
+ return `${this.namespace}.`;
52
+ }
53
+ }
71
54
  exports.NamespacedStorage = NamespacedStorage;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@croct/sdk",
3
- "version": "0.9.1",
3
+ "version": "0.11.0-alpha",
4
4
  "description": "Croct SDK for JavaScript.",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -25,28 +25,25 @@
25
25
  "lint": "eslint 'src/**/*.ts' 'test/**/*.ts'",
26
26
  "test": "jest -c jest.config.js --coverage",
27
27
  "validate": "tsc --noEmit",
28
- "build": "tsc"
28
+ "build": "tsc -p tsconfig.build.json"
29
29
  },
30
30
  "dependencies": {
31
31
  "@croct/json": "^1.0",
32
- "tslib": "^2.3.1"
32
+ "tslib": "^2.4.1"
33
33
  },
34
34
  "devDependencies": {
35
- "@types/jest": "^26.0.24",
36
- "@typescript-eslint/eslint-plugin": "^4.33.0",
37
- "@typescript-eslint/parser": "^4.33.0",
38
- "eslint": "^7.32.0",
39
- "eslint-config-airbnb-base": "^14.2.1",
40
- "eslint-plugin-import": "^2.25.4",
41
- "eslint-plugin-jest": "^24.7.0",
35
+ "@croct/eslint-plugin": "^0.6.3",
36
+ "@types/jest": "^29.2.3",
37
+ "eslint": "^8.27.0",
42
38
  "fetch-mock": "^9.11.0",
43
- "jest": "^26.6.3",
44
- "jest-websocket-mock": "^2.3.0",
45
- "mock-socket": "^9.1.0",
39
+ "jest": "^29.3.1",
40
+ "jest-environment-jsdom": "^29.3.1",
41
+ "jest-extended": "^3.1.0",
42
+ "jest-websocket-mock": "^2.4.0",
43
+ "mock-socket": "^9.1.5",
46
44
  "node-fetch": "^2.6.7",
47
- "temp-dir": "^2.0.0",
48
- "ts-jest": "^26.5.6",
49
- "typescript": "^4.5.4"
45
+ "ts-jest": "^29.0.3",
46
+ "typescript": "^4.8.0"
50
47
  },
51
48
  "files": [
52
49
  "**/*.js",
package/patch.d.ts CHANGED
@@ -37,7 +37,7 @@ interface removeOperation extends AbstractOperation {
37
37
  type: 'remove';
38
38
  value: JsonValue;
39
39
  }
40
- export declare type Operation = UnsetOperation | ClearOperation | AddOperation | SetOperation | CombineOperation | MergeOperation | IncrementOperation | DecrementOperation | removeOperation;
40
+ export type Operation = UnsetOperation | ClearOperation | AddOperation | SetOperation | CombineOperation | MergeOperation | IncrementOperation | DecrementOperation | removeOperation;
41
41
  export interface Patch {
42
42
  operations: Operation[];
43
43
  }
@@ -1,35 +1,34 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CapacityRestrictedQueue = void 0;
4
- var CapacityRestrictedQueue = /** @class */ (function () {
5
- function CapacityRestrictedQueue(queue, capacity) {
4
+ class CapacityRestrictedQueue {
5
+ constructor(queue, capacity) {
6
6
  this.queue = queue;
7
7
  this.capacity = capacity;
8
8
  }
9
- CapacityRestrictedQueue.prototype.all = function () {
9
+ all() {
10
10
  return this.queue.all();
11
- };
12
- CapacityRestrictedQueue.prototype.getCapacity = function () {
11
+ }
12
+ getCapacity() {
13
13
  return this.capacity;
14
- };
15
- CapacityRestrictedQueue.prototype.isEmpty = function () {
14
+ }
15
+ isEmpty() {
16
16
  return this.queue.isEmpty();
17
- };
18
- CapacityRestrictedQueue.prototype.length = function () {
17
+ }
18
+ length() {
19
19
  return Math.min(this.capacity, this.queue.length());
20
- };
21
- CapacityRestrictedQueue.prototype.peek = function () {
20
+ }
21
+ peek() {
22
22
  return this.queue.peek();
23
- };
24
- CapacityRestrictedQueue.prototype.push = function (value) {
23
+ }
24
+ push(value) {
25
25
  if (this.queue.length() >= this.capacity) {
26
26
  throw new Error('Maximum queue capacity reached.');
27
27
  }
28
28
  this.queue.push(value);
29
- };
30
- CapacityRestrictedQueue.prototype.shift = function () {
29
+ }
30
+ shift() {
31
31
  return this.queue.shift();
32
- };
33
- return CapacityRestrictedQueue;
34
- }());
32
+ }
33
+ }
35
34
  exports.CapacityRestrictedQueue = CapacityRestrictedQueue;
@@ -1,42 +1,36 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.InMemoryQueue = void 0;
4
- var tslib_1 = require("tslib");
5
- var InMemoryQueue = /** @class */ (function () {
6
- function InMemoryQueue() {
7
- var _a;
8
- var values = [];
9
- for (var _i = 0; _i < arguments.length; _i++) {
10
- values[_i] = arguments[_i];
11
- }
4
+ class InMemoryQueue {
5
+ constructor(...values) {
12
6
  this.queue = [];
13
- (_a = this.queue).unshift.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(values), false));
7
+ this.queue.unshift(...values);
14
8
  }
15
- InMemoryQueue.prototype.all = function () {
9
+ all() {
16
10
  return this.queue.slice();
17
- };
18
- InMemoryQueue.prototype.getCapacity = function () {
11
+ }
12
+ getCapacity() {
19
13
  return Infinity;
20
- };
21
- InMemoryQueue.prototype.isEmpty = function () {
14
+ }
15
+ isEmpty() {
22
16
  return this.queue.length === 0;
23
- };
24
- InMemoryQueue.prototype.push = function (value) {
17
+ }
18
+ push(value) {
25
19
  this.queue.push(value);
26
- };
27
- InMemoryQueue.prototype.peek = function () {
28
- return this.queue[0] || null;
29
- };
30
- InMemoryQueue.prototype.shift = function () {
31
- var value = this.queue.shift();
32
- if (!value) {
20
+ }
21
+ peek() {
22
+ var _a;
23
+ return (_a = this.queue[0]) !== null && _a !== void 0 ? _a : null;
24
+ }
25
+ shift() {
26
+ const value = this.queue.shift();
27
+ if (value === undefined) {
33
28
  throw new Error('The queue is empty.');
34
29
  }
35
30
  return value;
36
- };
37
- InMemoryQueue.prototype.length = function () {
31
+ }
32
+ length() {
38
33
  return this.queue.length;
39
- };
40
- return InMemoryQueue;
41
- }());
34
+ }
35
+ }
42
36
  exports.InMemoryQueue = InMemoryQueue;
package/queue/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PersistentQueue = exports.MonitoredQueue = exports.InMemoryQueue = exports.CapacityRestrictedQueue = void 0;
4
- var tslib_1 = require("tslib");
4
+ const tslib_1 = require("tslib");
5
5
  tslib_1.__exportStar(require("./queue"), exports);
6
6
  var capacityRestrictedQueue_1 = require("./capacityRestrictedQueue");
7
7
  Object.defineProperty(exports, "CapacityRestrictedQueue", { enumerable: true, get: function () { return capacityRestrictedQueue_1.CapacityRestrictedQueue; } });
@@ -1,7 +1,7 @@
1
1
  import { Queue } from './queue';
2
2
  import { Logger } from '../logging';
3
- export declare type QueueStatus = 'halfEmpty' | 'almostEmpty' | 'empty' | 'halfFull' | 'almostFull' | 'full';
4
- export declare type QueueCallback<T> = {
3
+ export type QueueStatus = 'halfEmpty' | 'almostEmpty' | 'empty' | 'halfFull' | 'almostFull' | 'full';
4
+ export type QueueCallback<T> = {
5
5
  (queue: Queue<T>): void;
6
6
  };
7
7
  export declare class MonitoredQueue<T> implements Queue<T> {