@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.
- package/activeRecord.js +32 -36
- package/cache/fallbackCache.js +15 -32
- package/cache/inMemoryCache.js +9 -10
- package/cache/index.js +1 -1
- package/cache/localStorageCache.js +24 -25
- package/channel/beaconSocketChannel.d.ts +1 -1
- package/channel/beaconSocketChannel.js +49 -79
- package/channel/channel.d.ts +1 -1
- package/channel/encodedChannel.js +8 -10
- package/channel/guaranteedChannel.d.ts +4 -4
- package/channel/guaranteedChannel.js +41 -43
- package/channel/index.js +1 -1
- package/channel/queuedChannel.js +35 -64
- package/channel/retryChannel.d.ts +1 -1
- package/channel/retryChannel.js +44 -77
- package/channel/sandboxChannel.js +17 -18
- package/channel/socketChannel.d.ts +4 -4
- package/channel/socketChannel.js +77 -79
- package/cid/cachedAssigner.js +15 -27
- package/cid/fixedAssigner.js +5 -6
- package/cid/index.js +1 -1
- package/cid/remoteAssigner.js +23 -36
- package/constants.d.ts +3 -2
- package/constants.js +6 -5
- package/container.d.ts +13 -6
- package/container.js +152 -168
- package/contentFetcher.d.ts +59 -0
- package/contentFetcher.js +129 -0
- package/context.d.ts +3 -3
- package/context.js +36 -38
- package/error.js +2 -2
- package/evaluator.d.ts +33 -24
- package/evaluator.js +126 -117
- package/eventManager.d.ts +1 -1
- package/eventManager.js +14 -15
- package/facade/contentFetcherFacade.d.ts +27 -0
- package/facade/contentFetcherFacade.js +40 -0
- package/facade/evaluatorFacade.d.ts +13 -3
- package/facade/evaluatorFacade.js +57 -72
- package/facade/sdkFacade.d.ts +10 -3
- package/facade/sdkFacade.js +129 -141
- package/facade/sessionFacade.js +6 -7
- package/facade/sessionPatch.js +9 -13
- package/facade/trackerFacade.js +32 -38
- package/facade/userFacade.js +10 -11
- package/facade/userPatch.js +9 -13
- package/index.js +2 -2
- package/logging/consoleLogger.js +18 -35
- package/logging/index.js +1 -1
- package/logging/namespacedLogger.js +14 -15
- package/logging/nullLogger.js +10 -13
- package/namespacedStorage.js +30 -47
- package/package.json +13 -16
- package/patch.d.ts +1 -1
- package/queue/capacityRestrictedQueue.js +17 -18
- package/queue/inMemoryQueue.js +22 -28
- package/queue/index.js +1 -1
- package/queue/monitoredQueue.d.ts +2 -2
- package/queue/monitoredQueue.js +39 -40
- package/queue/persistentQueue.js +33 -38
- package/retry/arbitraryPolicy.js +8 -10
- package/retry/backoffPolicy.d.ts +1 -1
- package/retry/backoffPolicy.js +11 -13
- package/retry/index.js +1 -1
- package/retry/maxAttemptsPolicy.js +7 -8
- package/retry/neverPolicy.js +6 -9
- package/schema/attributeSchema.js +1 -1
- package/schema/contentFetcherSchemas.d.ts +2 -0
- package/schema/contentFetcherSchemas.js +22 -0
- package/schema/contentSchemas.js +1 -1
- package/schema/contextSchemas.js +1 -1
- package/schema/ecommerceSchemas.js +1 -1
- package/schema/evaluatorSchemas.d.ts +2 -0
- package/schema/{evaluationSchemas.js → evaluatorSchemas.js} +3 -3
- package/schema/eventSchemas.js +8 -9
- package/schema/index.d.ts +2 -1
- package/schema/index.js +3 -2
- package/schema/loggerSchema.js +1 -1
- package/schema/operationSchemas.js +8 -8
- package/schema/sdkFacadeSchemas.js +9 -6
- package/schema/sdkSchemas.js +8 -5
- package/schema/tokenSchema.js +5 -4
- package/schema/userSchema.js +2 -2
- package/sdk.d.ts +9 -3
- package/sdk.js +81 -127
- package/sdkEvents.d.ts +3 -3
- package/sourceLocation.d.ts +3 -3
- package/sourceLocation.js +13 -14
- package/tab.d.ts +5 -5
- package/tab.js +50 -80
- package/token/cachedTokenStore.js +9 -10
- package/token/inMemoryTokenStore.js +7 -8
- package/token/index.js +1 -1
- package/token/replicatedTokenStore.js +7 -8
- package/token/token.d.ts +9 -5
- package/token/token.js +63 -57
- package/tracker.d.ts +4 -4
- package/tracker.js +145 -122
- package/trackingEvents.d.ts +36 -36
- package/trackingEvents.js +12 -6
- package/transformer.js +1 -1
- package/utilityTypes.d.ts +2 -2
- package/uuid.js +9 -7
- package/validation/arrayType.d.ts +2 -2
- package/validation/arrayType.js +29 -27
- package/validation/booleanType.js +11 -15
- package/validation/functionType.js +11 -15
- package/validation/index.js +1 -1
- package/validation/jsonType.d.ts +2 -2
- package/validation/jsonType.js +61 -80
- package/validation/mixedSchema.js +4 -7
- package/validation/nullType.js +11 -15
- package/validation/numberType.d.ts +1 -1
- package/validation/numberType.js +23 -22
- package/validation/objectType.d.ts +1 -1
- package/validation/objectType.js +61 -73
- package/validation/schema.js +6 -10
- package/validation/stringType.d.ts +1 -1
- package/validation/stringType.js +36 -47
- package/validation/unionType.js +27 -77
- package/validation/violation.js +1 -2
- package/schema/evaluationSchemas.d.ts +0 -2
package/facade/trackerFacade.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TrackerFacade = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
38
|
+
const event = { type: type, ...payload };
|
|
28
39
|
validateEvent(event);
|
|
29
40
|
return event;
|
|
30
41
|
}
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
|
|
51
|
+
}
|
|
52
|
+
disable() {
|
|
58
53
|
this.tracker.disable();
|
|
59
|
-
}
|
|
60
|
-
|
|
54
|
+
}
|
|
55
|
+
addListener(listener) {
|
|
61
56
|
this.tracker.addListener(listener);
|
|
62
|
-
}
|
|
63
|
-
|
|
57
|
+
}
|
|
58
|
+
removeListener(listener) {
|
|
64
59
|
this.tracker.removeListener(listener);
|
|
65
|
-
}
|
|
66
|
-
|
|
60
|
+
}
|
|
61
|
+
track(type, payload) {
|
|
67
62
|
return this.tracker.track(createEvent(type, payload));
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
}());
|
|
63
|
+
}
|
|
64
|
+
}
|
|
71
65
|
exports.TrackerFacade = TrackerFacade;
|
package/facade/userFacade.js
CHANGED
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.UserFacade = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
10
|
+
isIdentified() {
|
|
11
11
|
return !this.isAnonymous();
|
|
12
|
-
}
|
|
13
|
-
|
|
12
|
+
}
|
|
13
|
+
isAnonymous() {
|
|
14
14
|
return this.context.isAnonymous();
|
|
15
|
-
}
|
|
16
|
-
|
|
15
|
+
}
|
|
16
|
+
edit() {
|
|
17
17
|
return new userPatch_1.UserPatch(this.tracker);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
}());
|
|
18
|
+
}
|
|
19
|
+
}
|
|
21
20
|
exports.UserFacade = UserFacade;
|
package/facade/userPatch.js
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.UserPatch = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
4
|
+
const constants_1 = require("./constants");
|
|
5
5
|
Object.defineProperty(exports, "VERSION", { enumerable: true, get: function () { return constants_1.VERSION; } });
|
|
6
|
-
|
|
6
|
+
const sdk_1 = require("./sdk");
|
|
7
7
|
Object.defineProperty(exports, "Sdk", { enumerable: true, get: function () { return sdk_1.Sdk; } });
|
package/logging/consoleLogger.js
CHANGED
|
@@ -1,44 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ConsoleLogger = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
class ConsoleLogger {
|
|
5
|
+
constructor(namespace) {
|
|
6
6
|
this.namespace = namespace;
|
|
7
7
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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,
|
|
22
|
+
return method.bind(window.console, `[${this.namespace}]`);
|
|
39
23
|
}
|
|
40
24
|
return method.bind(window.console);
|
|
41
|
-
}
|
|
42
|
-
|
|
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
|
-
|
|
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
|
-
|
|
5
|
-
|
|
4
|
+
class NamespacedLogger {
|
|
5
|
+
constructor(logger, namespace) {
|
|
6
6
|
this.logger = logger;
|
|
7
7
|
this.namespace = namespace;
|
|
8
8
|
}
|
|
9
|
-
|
|
9
|
+
debug(message) {
|
|
10
10
|
this.logger.debug(this.format(message));
|
|
11
|
-
}
|
|
12
|
-
|
|
11
|
+
}
|
|
12
|
+
info(message) {
|
|
13
13
|
this.logger.info(this.format(message));
|
|
14
|
-
}
|
|
15
|
-
|
|
14
|
+
}
|
|
15
|
+
warn(message) {
|
|
16
16
|
this.logger.warn(this.format(message));
|
|
17
|
-
}
|
|
18
|
-
|
|
17
|
+
}
|
|
18
|
+
error(message) {
|
|
19
19
|
this.logger.error(this.format(message));
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
}());
|
|
20
|
+
}
|
|
21
|
+
format(message) {
|
|
22
|
+
return `[${this.namespace}] ${message}`;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
26
25
|
exports.NamespacedLogger = NamespacedLogger;
|
package/logging/nullLogger.js
CHANGED
|
@@ -1,21 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.NullLogger = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
NullLogger.prototype.debug = function () {
|
|
4
|
+
class NullLogger {
|
|
5
|
+
debug() {
|
|
8
6
|
// suppress debug logs
|
|
9
|
-
}
|
|
10
|
-
|
|
7
|
+
}
|
|
8
|
+
info() {
|
|
11
9
|
// suppress info logs
|
|
12
|
-
}
|
|
13
|
-
|
|
10
|
+
}
|
|
11
|
+
warn() {
|
|
14
12
|
// suppress warning logs
|
|
15
|
-
}
|
|
16
|
-
|
|
13
|
+
}
|
|
14
|
+
error() {
|
|
17
15
|
// suppress error logs
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
}());
|
|
16
|
+
}
|
|
17
|
+
}
|
|
21
18
|
exports.NullLogger = NullLogger;
|
package/namespacedStorage.js
CHANGED
|
@@ -1,71 +1,54 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.NamespacedStorage = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
|
|
19
|
+
}
|
|
20
|
+
getItem(key) {
|
|
37
21
|
return this.storage.getItem(this.getPrefixedKey(key));
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
|
|
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
|
-
|
|
29
|
+
}
|
|
30
|
+
removeItem(key) {
|
|
47
31
|
this.storage.removeItem(this.getPrefixedKey(key));
|
|
48
|
-
}
|
|
49
|
-
|
|
32
|
+
}
|
|
33
|
+
setItem(key, value) {
|
|
50
34
|
this.storage.setItem(this.getPrefixedKey(key), value);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
for (
|
|
56
|
-
|
|
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
|
-
|
|
46
|
+
}
|
|
47
|
+
getPrefixedKey(key) {
|
|
64
48
|
return this.getPrefix() + key;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return
|
|
68
|
-
}
|
|
69
|
-
|
|
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.
|
|
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.
|
|
32
|
+
"tslib": "^2.4.1"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@
|
|
36
|
-
"@
|
|
37
|
-
"
|
|
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": "^
|
|
44
|
-
"jest-
|
|
45
|
-
"
|
|
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
|
-
"
|
|
48
|
-
"
|
|
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
|
|
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
|
-
|
|
5
|
-
|
|
4
|
+
class CapacityRestrictedQueue {
|
|
5
|
+
constructor(queue, capacity) {
|
|
6
6
|
this.queue = queue;
|
|
7
7
|
this.capacity = capacity;
|
|
8
8
|
}
|
|
9
|
-
|
|
9
|
+
all() {
|
|
10
10
|
return this.queue.all();
|
|
11
|
-
}
|
|
12
|
-
|
|
11
|
+
}
|
|
12
|
+
getCapacity() {
|
|
13
13
|
return this.capacity;
|
|
14
|
-
}
|
|
15
|
-
|
|
14
|
+
}
|
|
15
|
+
isEmpty() {
|
|
16
16
|
return this.queue.isEmpty();
|
|
17
|
-
}
|
|
18
|
-
|
|
17
|
+
}
|
|
18
|
+
length() {
|
|
19
19
|
return Math.min(this.capacity, this.queue.length());
|
|
20
|
-
}
|
|
21
|
-
|
|
20
|
+
}
|
|
21
|
+
peek() {
|
|
22
22
|
return this.queue.peek();
|
|
23
|
-
}
|
|
24
|
-
|
|
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
|
-
|
|
29
|
+
}
|
|
30
|
+
shift() {
|
|
31
31
|
return this.queue.shift();
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
}());
|
|
32
|
+
}
|
|
33
|
+
}
|
|
35
34
|
exports.CapacityRestrictedQueue = CapacityRestrictedQueue;
|
package/queue/inMemoryQueue.js
CHANGED
|
@@ -1,42 +1,36 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.InMemoryQueue = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
7
|
+
this.queue.unshift(...values);
|
|
14
8
|
}
|
|
15
|
-
|
|
9
|
+
all() {
|
|
16
10
|
return this.queue.slice();
|
|
17
|
-
}
|
|
18
|
-
|
|
11
|
+
}
|
|
12
|
+
getCapacity() {
|
|
19
13
|
return Infinity;
|
|
20
|
-
}
|
|
21
|
-
|
|
14
|
+
}
|
|
15
|
+
isEmpty() {
|
|
22
16
|
return this.queue.length === 0;
|
|
23
|
-
}
|
|
24
|
-
|
|
17
|
+
}
|
|
18
|
+
push(value) {
|
|
25
19
|
this.queue.push(value);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
|
|
31
|
+
}
|
|
32
|
+
length() {
|
|
38
33
|
return this.queue.length;
|
|
39
|
-
}
|
|
40
|
-
|
|
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
|
-
|
|
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
|
|
4
|
-
export
|
|
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> {
|