@artstesh/postboy 1.1.0 → 1.1.2
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/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/mocks/message-history-item-mock.d.ts +10 -0
- package/lib/mocks/message-history-item-mock.d.ts.map +1 -0
- package/lib/mocks/message-history-item-mock.js +26 -0
- package/lib/mocks/message-history-item-mock.js.map +1 -0
- package/lib/mocks/message-history-mock.d.ts +9 -0
- package/lib/mocks/message-history-mock.d.ts.map +1 -0
- package/lib/mocks/message-history-mock.js +24 -0
- package/lib/mocks/message-history-mock.js.map +1 -0
- package/lib/mocks/postboy-service-mock.d.ts +6 -5
- package/lib/mocks/postboy-service-mock.d.ts.map +1 -1
- package/lib/mocks/postboy-service-mock.js +12 -14
- package/lib/mocks/postboy-service-mock.js.map +1 -1
- package/lib/models/message-queue.model.d.ts +44 -0
- package/lib/models/message-queue.model.d.ts.map +1 -0
- package/lib/models/message-queue.model.js +66 -0
- package/lib/models/message-queue.model.js.map +1 -0
- package/lib/postboy-abstract.registrator.d.ts +65 -6
- package/lib/postboy-abstract.registrator.d.ts.map +1 -1
- package/lib/postboy-abstract.registrator.js +63 -3
- package/lib/postboy-abstract.registrator.js.map +1 -1
- package/lib/postboy.service.d.ts +60 -4
- package/lib/postboy.service.d.ts.map +1 -1
- package/lib/postboy.service.js +59 -3
- package/lib/postboy.service.js.map +1 -1
- package/package.json +5 -2
package/lib/index.d.ts
CHANGED
|
@@ -6,4 +6,5 @@ export * from './models/postboy-generic-message';
|
|
|
6
6
|
export * from './models/postboy-callback.message';
|
|
7
7
|
export * from './models/postboy.locker';
|
|
8
8
|
export * from './models/postboy-executor';
|
|
9
|
+
export * from './models/message-queue.model';
|
|
9
10
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,mBAAmB,CAAC;AAClC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,kCAAkC,CAAC;AACjD,cAAc,mCAAmC,CAAC;AAClD,cAAc,yBAAyB,CAAC;AACxC,cAAc,2BAA2B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,mBAAmB,CAAC;AAClC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,kCAAkC,CAAC;AACjD,cAAc,mCAAmC,CAAC;AAClD,cAAc,yBAAyB,CAAC;AACxC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,8BAA8B,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -25,4 +25,5 @@ __exportStar(require("./models/postboy-generic-message"), exports);
|
|
|
25
25
|
__exportStar(require("./models/postboy-callback.message"), exports);
|
|
26
26
|
__exportStar(require("./models/postboy.locker"), exports);
|
|
27
27
|
__exportStar(require("./models/postboy-executor"), exports);
|
|
28
|
+
__exportStar(require("./models/message-queue.model"), exports);
|
|
28
29
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;AAEH,oDAAkC;AAClC,+DAA6C;AAC7C,gEAA8C;AAC9C,iEAA+C;AAC/C,mEAAiD;AACjD,oEAAkD;AAClD,0DAAwC;AACxC,4DAA0C"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;AAEH,oDAAkC;AAClC,+DAA6C;AAC7C,gEAA8C;AAC9C,iEAA+C;AAC/C,mEAAiD;AACjD,oEAAkD;AAClD,0DAAwC;AACxC,4DAA0C;AAC1C,+DAA6C"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { PostboyGenericMessage } from '../models/postboy-generic-message';
|
|
2
|
+
export declare class MessageHistoryItemMock<T extends PostboyGenericMessage> {
|
|
3
|
+
private list;
|
|
4
|
+
add(message: T): this;
|
|
5
|
+
clear(): void;
|
|
6
|
+
get length(): number;
|
|
7
|
+
get last(): T;
|
|
8
|
+
get all(): T[];
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=message-history-item-mock.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message-history-item-mock.d.ts","sourceRoot":"","sources":["../../src/mocks/message-history-item-mock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAE1E,qBAAa,sBAAsB,CAAC,CAAC,SAAS,qBAAqB;IACjE,OAAO,CAAC,IAAI,CAAW;IAEvB,GAAG,CAAC,OAAO,EAAE,CAAC;IAKd,KAAK;IAIL,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED,IAAI,IAAI,IAAI,CAAC,CAEZ;IAED,IAAI,GAAG,IAAI,CAAC,EAAE,CAEb;CACF"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MessageHistoryItemMock = void 0;
|
|
4
|
+
class MessageHistoryItemMock {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.list = [];
|
|
7
|
+
}
|
|
8
|
+
add(message) {
|
|
9
|
+
this.list.push(message);
|
|
10
|
+
return this;
|
|
11
|
+
}
|
|
12
|
+
clear() {
|
|
13
|
+
this.list = [];
|
|
14
|
+
}
|
|
15
|
+
get length() {
|
|
16
|
+
return this.list.length;
|
|
17
|
+
}
|
|
18
|
+
get last() {
|
|
19
|
+
return this.list[this.list.length - 1];
|
|
20
|
+
}
|
|
21
|
+
get all() {
|
|
22
|
+
return [...this.list];
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.MessageHistoryItemMock = MessageHistoryItemMock;
|
|
26
|
+
//# sourceMappingURL=message-history-item-mock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message-history-item-mock.js","sourceRoot":"","sources":["../../src/mocks/message-history-item-mock.ts"],"names":[],"mappings":";;;AAEA,MAAa,sBAAsB;IAAnC;QACU,SAAI,GAAQ,EAAE,CAAC;IAsBzB,CAAC;IApBC,GAAG,CAAC,OAAU;QACZ,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACxB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK;QACH,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC;IACjB,CAAC;IAED,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC;IAC1B,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACzC,CAAC;IAED,IAAI,GAAG;QACL,OAAO,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC;IACxB,CAAC;CACF;AAvBD,wDAuBC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { PostboyGenericMessage } from '../models/postboy-generic-message';
|
|
2
|
+
import { MessageHistoryItemMock } from './message-history-item-mock';
|
|
3
|
+
export declare class MessageHistoryMock {
|
|
4
|
+
private _items;
|
|
5
|
+
get<T extends PostboyGenericMessage>(id: string): MessageHistoryItemMock<T>;
|
|
6
|
+
add(message: PostboyGenericMessage): void;
|
|
7
|
+
reset(): void;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=message-history-mock.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message-history-mock.d.ts","sourceRoot":"","sources":["../../src/mocks/message-history-mock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAGrE,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,MAAM,CAAiD;IAE/D,GAAG,CAAC,CAAC,SAAS,qBAAqB,EAAE,EAAE,EAAE,MAAM,GAAG,sBAAsB,CAAC,CAAC,CAAC;IAI3E,GAAG,CAAC,OAAO,EAAE,qBAAqB,GAAG,IAAI;IAKzC,KAAK,IAAI,IAAI;CAGd"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MessageHistoryMock = void 0;
|
|
4
|
+
const message_history_item_mock_1 = require("./message-history-item-mock");
|
|
5
|
+
const collections_1 = require("@artstesh/collections");
|
|
6
|
+
class MessageHistoryMock {
|
|
7
|
+
constructor() {
|
|
8
|
+
this._items = new collections_1.Dictionary();
|
|
9
|
+
}
|
|
10
|
+
get(id) {
|
|
11
|
+
var _a;
|
|
12
|
+
return (_a = this._items.take(id)) !== null && _a !== void 0 ? _a : new message_history_item_mock_1.MessageHistoryItemMock();
|
|
13
|
+
}
|
|
14
|
+
add(message) {
|
|
15
|
+
var _a;
|
|
16
|
+
if (!((_a = this._items.take(message.id)) === null || _a === void 0 ? void 0 : _a.add(message)))
|
|
17
|
+
this._items.put(message.id, new message_history_item_mock_1.MessageHistoryItemMock().add(message));
|
|
18
|
+
}
|
|
19
|
+
reset() {
|
|
20
|
+
this._items.forEach((i) => i.clear());
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.MessageHistoryMock = MessageHistoryMock;
|
|
24
|
+
//# sourceMappingURL=message-history-mock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message-history-mock.js","sourceRoot":"","sources":["../../src/mocks/message-history-mock.ts"],"names":[],"mappings":";;;AACA,2EAAqE;AACrE,uDAAmD;AAEnD,MAAa,kBAAkB;IAA/B;QACU,WAAM,GAAG,IAAI,wBAAU,EAA+B,CAAC;IAcjE,CAAC;IAZC,GAAG,CAAkC,EAAU;;QAC7C,OAAO,MAAA,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,mCAAI,IAAI,kDAAsB,EAAE,CAAC;IAC9D,CAAC;IAED,GAAG,CAAC,OAA8B;;QAChC,IAAI,CAAC,CAAA,MAAA,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,0CAAE,GAAG,CAAC,OAAO,CAAC,CAAA;YAC7C,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,EAAE,IAAI,kDAAsB,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC;IAC3E,CAAC;IAED,KAAK;QACH,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC;IACxC,CAAC;CACF;AAfD,gDAeC"}
|
|
@@ -3,19 +3,20 @@ import { Observable } from 'rxjs';
|
|
|
3
3
|
import { PostboyExecutor } from '../models/postboy-executor';
|
|
4
4
|
import { PostboyGenericMessage } from '../models/postboy-generic-message';
|
|
5
5
|
import { PostboyCallbackMessage } from '../models/postboy-callback.message';
|
|
6
|
+
import { MessageHistoryItemMock } from './message-history-item-mock';
|
|
7
|
+
import { MessageType } from '../postboy-abstract.registrator';
|
|
6
8
|
export declare class PostboyServiceMock extends PostboyService {
|
|
7
|
-
private executions;
|
|
8
9
|
private subscriptions;
|
|
9
|
-
private
|
|
10
|
+
private _history;
|
|
10
11
|
reset(): void;
|
|
11
12
|
fired(id: string, times?: number): boolean;
|
|
12
|
-
executed(id: string, times?: number): boolean;
|
|
13
13
|
subscribed(id: string, times?: number): boolean;
|
|
14
14
|
private count;
|
|
15
15
|
exec<E extends PostboyExecutor<T>, T>(executor: E): T;
|
|
16
16
|
subscribe<T>(id: string): Observable<T>;
|
|
17
|
-
sub<T extends PostboyGenericMessage>(type:
|
|
17
|
+
sub<T extends PostboyGenericMessage>(type: MessageType<T>): Observable<T>;
|
|
18
18
|
fire<T extends PostboyGenericMessage>(message: T): void;
|
|
19
|
-
fireCallback<T>(message: PostboyCallbackMessage<T>, action
|
|
19
|
+
fireCallback<T>(message: PostboyCallbackMessage<T>, action?: (e: T) => void): Observable<T>;
|
|
20
|
+
history<T extends PostboyGenericMessage>(type: MessageType<T>): MessageHistoryItemMock<T>;
|
|
20
21
|
}
|
|
21
22
|
//# sourceMappingURL=postboy-service-mock.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postboy-service-mock.d.ts","sourceRoot":"","sources":["../../src/mocks/postboy-service-mock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAClC,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAW,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AACnF,OAAO,EAAE,sBAAsB,EAAE,MAAM,oCAAoC,CAAC;AAE5E,
|
|
1
|
+
{"version":3,"file":"postboy-service-mock.d.ts","sourceRoot":"","sources":["../../src/mocks/postboy-service-mock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAClC,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAW,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AACnF,OAAO,EAAE,sBAAsB,EAAE,MAAM,oCAAoC,CAAC;AAE5E,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAE9D,qBAAa,kBAAmB,SAAQ,cAAc;IACpD,OAAO,CAAC,aAAa,CAAgB;IACrC,OAAO,CAAC,QAAQ,CAA4B;IAE5C,KAAK,IAAI,IAAI;IAKb,KAAK,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,GAAE,MAAU,GAAG,OAAO;IAI7C,UAAU,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,GAAE,MAAU,GAAG,OAAO;IAKlD,OAAO,CAAC,KAAK,CAAmF;IAEhG,IAAI,CAAC,CAAC,SAAS,eAAe,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,GAAG,CAAC;IAKrD,SAAS,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,GAAG,UAAU,CAAC,CAAC,CAAC;IAKhC,GAAG,CAAC,CAAC,SAAS,qBAAqB,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC;IAKhF,IAAI,CAAC,CAAC,SAAS,qBAAqB,EAAE,OAAO,EAAE,CAAC;IAKhD,YAAY,CAAC,CAAC,EAAE,OAAO,EAAE,sBAAsB,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,IAAI,GAAG,UAAU,CAAC,CAAC,CAAC;IAK3F,OAAO,CAAC,CAAC,SAAS,qBAAqB,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,sBAAsB,CAAC,CAAC,CAAC;CAG1F"}
|
|
@@ -3,33 +3,28 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.PostboyServiceMock = void 0;
|
|
4
4
|
const postboy_service_1 = require("../postboy.service");
|
|
5
5
|
const postboy_generic_message_1 = require("../models/postboy-generic-message");
|
|
6
|
+
const message_history_mock_1 = require("./message-history-mock");
|
|
6
7
|
class PostboyServiceMock extends postboy_service_1.PostboyService {
|
|
7
8
|
constructor() {
|
|
8
9
|
super(...arguments);
|
|
9
|
-
this.executions = [];
|
|
10
10
|
this.subscriptions = [];
|
|
11
|
-
this.
|
|
11
|
+
this._history = new message_history_mock_1.MessageHistoryMock();
|
|
12
12
|
this.count = (collection, el) => collection.filter((e) => e === el).length;
|
|
13
13
|
}
|
|
14
14
|
reset() {
|
|
15
|
-
this.executions = [];
|
|
16
15
|
this.subscriptions = [];
|
|
17
|
-
this.
|
|
16
|
+
this._history.reset();
|
|
18
17
|
}
|
|
19
18
|
fired(id, times = 0) {
|
|
20
|
-
|
|
21
|
-
return
|
|
22
|
-
}
|
|
23
|
-
executed(id, times = 0) {
|
|
24
|
-
const count = this.count(this.executions, id);
|
|
25
|
-
return !!count && (!times || count === times);
|
|
19
|
+
var _a;
|
|
20
|
+
return ((_a = this._history.get(id)) === null || _a === void 0 ? void 0 : _a.length) === times;
|
|
26
21
|
}
|
|
27
22
|
subscribed(id, times = 0) {
|
|
28
23
|
const count = this.count(this.subscriptions, id);
|
|
29
24
|
return !!count && (!times || count === times);
|
|
30
25
|
}
|
|
31
26
|
exec(executor) {
|
|
32
|
-
this.
|
|
27
|
+
this._history.add(executor);
|
|
33
28
|
return super.exec(executor);
|
|
34
29
|
}
|
|
35
30
|
subscribe(id) {
|
|
@@ -41,12 +36,15 @@ class PostboyServiceMock extends postboy_service_1.PostboyService {
|
|
|
41
36
|
return super.subscribe((0, postboy_generic_message_1.checkId)(type));
|
|
42
37
|
}
|
|
43
38
|
fire(message) {
|
|
44
|
-
this.
|
|
39
|
+
this._history.add(message);
|
|
45
40
|
super.fire(message);
|
|
46
41
|
}
|
|
47
42
|
fireCallback(message, action) {
|
|
48
|
-
this.
|
|
49
|
-
super.fireCallback(message, action);
|
|
43
|
+
this._history.add(message);
|
|
44
|
+
return super.fireCallback(message, action);
|
|
45
|
+
}
|
|
46
|
+
history(type) {
|
|
47
|
+
return this._history.get((0, postboy_generic_message_1.checkId)(type));
|
|
50
48
|
}
|
|
51
49
|
}
|
|
52
50
|
exports.PostboyServiceMock = PostboyServiceMock;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postboy-service-mock.js","sourceRoot":"","sources":["../../src/mocks/postboy-service-mock.ts"],"names":[],"mappings":";;;AAAA,wDAAoD;AAGpD,+EAAmF;
|
|
1
|
+
{"version":3,"file":"postboy-service-mock.js","sourceRoot":"","sources":["../../src/mocks/postboy-service-mock.ts"],"names":[],"mappings":";;;AAAA,wDAAoD;AAGpD,+EAAmF;AAEnF,iEAA4D;AAI5D,MAAa,kBAAmB,SAAQ,gCAAc;IAAtD;;QACU,kBAAa,GAAa,EAAE,CAAC;QAC7B,aAAQ,GAAG,IAAI,yCAAkB,EAAE,CAAC;QAgBpC,UAAK,GAAG,CAAC,UAAoB,EAAE,EAAU,EAAE,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC;IA8BlG,CAAC;IA5CC,KAAK;QACH,IAAI,CAAC,aAAa,GAAG,EAAE,CAAC;QACxB,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;IACxB,CAAC;IAED,KAAK,CAAC,EAAU,EAAE,QAAgB,CAAC;;QACjC,OAAO,CAAA,MAAA,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,0CAAE,MAAM,MAAK,KAAK,CAAC;IACjD,CAAC;IAED,UAAU,CAAC,EAAU,EAAE,QAAgB,CAAC;QACtC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC;QACjD,OAAO,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,KAAK,IAAI,KAAK,KAAK,KAAK,CAAC,CAAC;IAChD,CAAC;IAID,IAAI,CAAkC,QAAW;QAC/C,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC5B,OAAO,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC9B,CAAC;IAED,SAAS,CAAI,EAAU;QACrB,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC5B,OAAO,KAAK,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;IAC7B,CAAC;IAEM,GAAG,CAAkC,IAAoB;QAC9D,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,IAAA,iCAAO,EAAC,IAAI,CAAC,CAAC,CAAC;QACvC,OAAO,KAAK,CAAC,SAAS,CAAC,IAAA,iCAAO,EAAC,IAAI,CAAC,CAAC,CAAC;IACxC,CAAC;IAED,IAAI,CAAkC,OAAU;QAC9C,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAC3B,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACtB,CAAC;IAED,YAAY,CAAI,OAAkC,EAAE,MAAuB;QACzE,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAC3B,OAAO,KAAK,CAAC,YAAY,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAC7C,CAAC;IAED,OAAO,CAAkC,IAAoB;QAC3D,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAA,iCAAO,EAAC,IAAI,CAAC,CAAC,CAAC;IAC1C,CAAC;CACF;AAhDD,gDAgDC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { PostboyCallbackMessage } from './postboy-callback.message';
|
|
2
|
+
export declare class MessageQueue<D> {
|
|
3
|
+
private cache;
|
|
4
|
+
/**
|
|
5
|
+
* Gets the current data stored in the instance.
|
|
6
|
+
*
|
|
7
|
+
* @return {D | null} The current data or null if no data is set.
|
|
8
|
+
*/
|
|
9
|
+
get data(): D | null;
|
|
10
|
+
private queries;
|
|
11
|
+
private _requestInProgress;
|
|
12
|
+
private _data;
|
|
13
|
+
constructor(cache?: boolean);
|
|
14
|
+
/**
|
|
15
|
+
* Resets the state of the instance by clearing stored data.
|
|
16
|
+
* This method sets the internal data to null, effectively resetting the object.
|
|
17
|
+
*
|
|
18
|
+
* @return {void} Does not return a value.
|
|
19
|
+
*/
|
|
20
|
+
reset(): MessageQueue<D>;
|
|
21
|
+
/**
|
|
22
|
+
* Attempts to finalize the provided query. It either queues the query for later processing
|
|
23
|
+
* if a request is in progress or data is missing, or completes the query immediately.
|
|
24
|
+
*
|
|
25
|
+
* @param {PostboyCallbackMessage<D>} query - The callback message to be finalized.
|
|
26
|
+
* @return {boolean} - Returns true if the query was successfully finalized, otherwise false.
|
|
27
|
+
*/
|
|
28
|
+
tryFinish(query: PostboyCallbackMessage<D>): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Adds a new query to the query queue.
|
|
31
|
+
*
|
|
32
|
+
* @param {PostboyCallbackMessage<D>} query - The query to be added to the queue.
|
|
33
|
+
* @return {MessageQueue<D>} The updated QueryQueue instance.
|
|
34
|
+
*/
|
|
35
|
+
add(query: PostboyCallbackMessage<D>): MessageQueue<D>;
|
|
36
|
+
/**
|
|
37
|
+
* Marks the operation as finished by updating the internal state and handling each query.
|
|
38
|
+
*
|
|
39
|
+
* @param {D} data - The data to be set for the current operation.
|
|
40
|
+
* @return {void} This method does not return a value.
|
|
41
|
+
*/
|
|
42
|
+
finish(data: D): void;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=message-queue.model.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message-queue.model.d.ts","sourceRoot":"","sources":["../../src/models/message-queue.model.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAGpE,qBAAa,YAAY,CAAC,CAAC;IAcb,OAAO,CAAC,KAAK;IAbzB;;;;OAIG;IACH,IAAI,IAAI,IAAI,CAAC,GAAG,IAAI,CAEnB;IAED,OAAO,CAAC,OAAO,CAA4E;IAC3F,OAAO,CAAC,kBAAkB,CAAiB;IAC3C,OAAO,CAAC,KAAK,CAAkB;gBAEX,KAAK,GAAE,OAAc;IAEzC;;;;;OAKG;IACI,KAAK,IAAI,YAAY,CAAC,CAAC,CAAC;IAK/B;;;;;;OAMG;IACI,SAAS,CAAC,KAAK,EAAE,sBAAsB,CAAC,CAAC,CAAC,GAAG,OAAO;IAM3D;;;;;OAKG;IACI,GAAG,CAAC,KAAK,EAAE,sBAAsB,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC;IAI7D;;;;;OAKG;IACI,MAAM,CAAC,IAAI,EAAE,CAAC,GAAG,IAAI;CAK7B"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MessageQueue = void 0;
|
|
4
|
+
const collections_1 = require("@artstesh/collections");
|
|
5
|
+
class MessageQueue {
|
|
6
|
+
/**
|
|
7
|
+
* Gets the current data stored in the instance.
|
|
8
|
+
*
|
|
9
|
+
* @return {D | null} The current data or null if no data is set.
|
|
10
|
+
*/
|
|
11
|
+
get data() {
|
|
12
|
+
return this._data;
|
|
13
|
+
}
|
|
14
|
+
constructor(cache = true) {
|
|
15
|
+
this.cache = cache;
|
|
16
|
+
this.queries = new collections_1.Queue();
|
|
17
|
+
this._requestInProgress = true;
|
|
18
|
+
this._data = null;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Resets the state of the instance by clearing stored data.
|
|
22
|
+
* This method sets the internal data to null, effectively resetting the object.
|
|
23
|
+
*
|
|
24
|
+
* @return {void} Does not return a value.
|
|
25
|
+
*/
|
|
26
|
+
reset() {
|
|
27
|
+
this._data = null;
|
|
28
|
+
return this;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Attempts to finalize the provided query. It either queues the query for later processing
|
|
32
|
+
* if a request is in progress or data is missing, or completes the query immediately.
|
|
33
|
+
*
|
|
34
|
+
* @param {PostboyCallbackMessage<D>} query - The callback message to be finalized.
|
|
35
|
+
* @return {boolean} - Returns true if the query was successfully finalized, otherwise false.
|
|
36
|
+
*/
|
|
37
|
+
tryFinish(query) {
|
|
38
|
+
if (this._requestInProgress || this._data === null)
|
|
39
|
+
return this.queries.put(query) && false;
|
|
40
|
+
query.finish(this._data);
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Adds a new query to the query queue.
|
|
45
|
+
*
|
|
46
|
+
* @param {PostboyCallbackMessage<D>} query - The query to be added to the queue.
|
|
47
|
+
* @return {MessageQueue<D>} The updated QueryQueue instance.
|
|
48
|
+
*/
|
|
49
|
+
add(query) {
|
|
50
|
+
return this.queries.put(query) && this;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Marks the operation as finished by updating the internal state and handling each query.
|
|
54
|
+
*
|
|
55
|
+
* @param {D} data - The data to be set for the current operation.
|
|
56
|
+
* @return {void} This method does not return a value.
|
|
57
|
+
*/
|
|
58
|
+
finish(data) {
|
|
59
|
+
if (this.cache)
|
|
60
|
+
this._data = data;
|
|
61
|
+
this._requestInProgress = false;
|
|
62
|
+
this.queries.each((q) => q.finish(data));
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.MessageQueue = MessageQueue;
|
|
66
|
+
//# sourceMappingURL=message-queue.model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message-queue.model.js","sourceRoot":"","sources":["../../src/models/message-queue.model.ts"],"names":[],"mappings":";;;AACA,uDAA8C;AAE9C,MAAa,YAAY;IACvB;;;;OAIG;IACH,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAMD,YAAoB,QAAiB,IAAI;QAArB,UAAK,GAAL,KAAK,CAAgB;QAJjC,YAAO,GAAqC,IAAI,mBAAK,EAA6B,CAAC;QACnF,uBAAkB,GAAY,IAAI,CAAC;QACnC,UAAK,GAAa,IAAI,CAAC;IAEa,CAAC;IAE7C;;;;;OAKG;IACI,KAAK;QACV,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;;OAMG;IACI,SAAS,CAAC,KAAgC;QAC/C,IAAI,IAAI,CAAC,kBAAkB,IAAI,IAAI,CAAC,KAAK,KAAK,IAAI;YAAE,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC;QAC5F,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACzB,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;OAKG;IACI,GAAG,CAAC,KAAgC;QACzC,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC;IACzC,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,IAAO;QACnB,IAAI,IAAI,CAAC,KAAK;YAAE,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClC,IAAI,CAAC,kBAAkB,GAAG,KAAK,CAAC;QAChC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;IAC3C,CAAC;CACF;AA7DD,oCA6DC"}
|
|
@@ -3,11 +3,18 @@ import { Observable, Subject } from 'rxjs';
|
|
|
3
3
|
import { IPostboyDependingService } from './i-postboy-depending.service';
|
|
4
4
|
import { PostboyExecutor } from './models/postboy-executor';
|
|
5
5
|
import { PostboyGenericMessage } from './models/postboy-generic-message';
|
|
6
|
+
export type MessageType<T extends PostboyGenericMessage> = new (...args: any[]) => T;
|
|
6
7
|
export declare abstract class PostboyAbstractRegistrator {
|
|
7
8
|
protected postboy: PostboyService;
|
|
8
9
|
private ids;
|
|
9
10
|
private services;
|
|
10
11
|
constructor(postboy: PostboyService);
|
|
12
|
+
/**
|
|
13
|
+
* Registers a list of services to be used by the application.
|
|
14
|
+
*
|
|
15
|
+
* @param {IPostboyDependingService[]} services - An array of services to register.
|
|
16
|
+
* @return {void} This method does not return a value.
|
|
17
|
+
*/
|
|
11
18
|
registerServices(services: IPostboyDependingService[]): void;
|
|
12
19
|
up(): void;
|
|
13
20
|
protected abstract _up(): void;
|
|
@@ -15,7 +22,6 @@ export declare abstract class PostboyAbstractRegistrator {
|
|
|
15
22
|
* @deprecated The method should be replaced with recordExecutor<T>
|
|
16
23
|
*/
|
|
17
24
|
registerExecutor<E extends PostboyExecutor<T>, T>(id: string, exec: (e: E) => T): void;
|
|
18
|
-
recordExecutor<E extends PostboyExecutor<T>, T>(type: new (...args: any[]) => E, exec: (e: E) => T): void;
|
|
19
25
|
/**
|
|
20
26
|
* @deprecated The method should be replaced with record<T>
|
|
21
27
|
*/
|
|
@@ -37,10 +43,63 @@ export declare abstract class PostboyAbstractRegistrator {
|
|
|
37
43
|
*/
|
|
38
44
|
registerSubject: <T>(id: string) => void;
|
|
39
45
|
down(): void;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
46
|
+
/**
|
|
47
|
+
* Records a type and its corresponding Subject<T> into the Postboy system and updates the internal identifiers.
|
|
48
|
+
*
|
|
49
|
+
* @param {MessageType<T>} type - A constructor for the generic message type T.
|
|
50
|
+
* @param {Subject<T>} sub - The subject associated with the generic message type.
|
|
51
|
+
* @return {this} Returns the current instance for method chaining.
|
|
52
|
+
*/
|
|
53
|
+
record<T extends PostboyGenericMessage>(type: MessageType<T>, sub: Subject<T>): this;
|
|
54
|
+
/**
|
|
55
|
+
* Records a message type with a specific subject and applies a transformation pipe to the subject.
|
|
56
|
+
*
|
|
57
|
+
* @param {MessageType<T>} type - The constructor of the message type to record, which extends PostboyGenericMessage.
|
|
58
|
+
* @param {Subject<T>} sub - The Subject instance to associate with the message type.
|
|
59
|
+
* @param {(s: Subject<T>) => Observable<T>} pipe - A function that takes the subject as input and returns an Observable with transformations applied.
|
|
60
|
+
* @return {this} The current instance of the class for chaining.
|
|
61
|
+
*/
|
|
62
|
+
recordWithPipe<T extends PostboyGenericMessage>(type: MessageType<T>, sub: Subject<T>, pipe: (s: Subject<T>) => Observable<T>): this;
|
|
63
|
+
/**
|
|
64
|
+
* Records an executor associated with a specific type and execution logic.
|
|
65
|
+
*
|
|
66
|
+
* @param type The class constructor of the executor type to be recorded, which extends PostboyExecutor.
|
|
67
|
+
* @param exec A callback function that executes the logic using an instance of the specified executor type.
|
|
68
|
+
* @return void
|
|
69
|
+
*/
|
|
70
|
+
recordExecutor<E extends PostboyExecutor<T>, T>(type: new (...args: any[]) => E, exec: (e: E) => T): void;
|
|
71
|
+
/**
|
|
72
|
+
* A utility function that facilitates the recording and replaying of messages
|
|
73
|
+
* using a ReplaySubject. This function is designed to handle messages of a
|
|
74
|
+
* specific type and allows specifying a buffer size to determine how many
|
|
75
|
+
* of the most recent messages should be replayed.
|
|
76
|
+
*
|
|
77
|
+
* @template T Extends the PostboyGenericMessage type, representing the type of message
|
|
78
|
+
* to be recorded and replayed.
|
|
79
|
+
* @param {MessageType<T>} type The constructor of the message type to be recorded and replayed.
|
|
80
|
+
* @param {number} [bufferSize=1] The number of recent messages to retain in the ReplaySubject's buffer.
|
|
81
|
+
* Defaults to 1 if not specified.
|
|
82
|
+
* @returns The result of invoking the `record` method with the given message type and configured ReplaySubject.
|
|
83
|
+
*/
|
|
84
|
+
recordReplay: <T extends PostboyGenericMessage>(type: MessageType<T>, bufferSize?: number) => this;
|
|
85
|
+
/**
|
|
86
|
+
* Represents a method that records a specific behavior associated with a message type.
|
|
87
|
+
* It creates a `BehaviorSubject` initialized with the provided initial message
|
|
88
|
+
* and associates it with the given message type using the `record` method.
|
|
89
|
+
*
|
|
90
|
+
* @template T - A type parameter extending `PostboyGenericMessage` that defines the message structure.
|
|
91
|
+
* @param {MessageType<T>} type - The constructor function of the message type to be recorded.
|
|
92
|
+
* @param {T} initial - The initial value of the message that will be set in the `BehaviorSubject`.
|
|
93
|
+
* @returns {void} - This function does not return a value; instead, it modifies the internal state.
|
|
94
|
+
*/
|
|
95
|
+
recordBehavior: <T extends PostboyGenericMessage>(type: MessageType<T>, initial: T) => this;
|
|
96
|
+
/**
|
|
97
|
+
* A function that creates and returns a new generic message recorder for a specific message type.
|
|
98
|
+
*
|
|
99
|
+
* @template T - A type parameter extending from `PostboyGenericMessage`.
|
|
100
|
+
* @param {MessageType<T>} type - The constructor for the message type being recorded.
|
|
101
|
+
* @returns {Subject<T>} A new instance of `Subject<T>` bound to the specified message type.
|
|
102
|
+
*/
|
|
103
|
+
recordSubject: <T extends PostboyGenericMessage>(type: MessageType<T>) => this;
|
|
45
104
|
}
|
|
46
105
|
//# sourceMappingURL=postboy-abstract.registrator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postboy-abstract.registrator.d.ts","sourceRoot":"","sources":["../src/postboy-abstract.registrator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAmB,UAAU,EAAiB,OAAO,EAAE,MAAM,MAAM,CAAC;AAC3E,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AACzE,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAW,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AAElF,8BAAsB,0BAA0B;IAIlC,SAAS,CAAC,OAAO,EAAE,cAAc;IAH7C,OAAO,CAAC,GAAG,CAAgB;IAC3B,OAAO,CAAC,QAAQ,CAAkC;gBAE5B,OAAO,EAAE,cAAc;
|
|
1
|
+
{"version":3,"file":"postboy-abstract.registrator.d.ts","sourceRoot":"","sources":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AEG;IACI,cAAc,UAAW,MAAM,+BAAyE;IAE/G;;OAEG;IACI,gBAAgB,UAAW,MAAM,sBAAoE;IAE5G;;OAEG;IACI,eAAe,UAAW,MAAM,UAAyC;IAEzE,IAAI,IAAI,IAAI;IAOnB;;;;;;OAMG;IACI,MAAM,CAAC,CAAC,SAAS,qBAAqB,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI;IAM3F;;;;;;;OAOG;IACI,cAAc,CAAC,CAAC,SAAS,qBAAqB,EACnD,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC,EACpB,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC,EACf,IAAI,EAAE,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,UAAU,CAAC,CAAC,CAAC,GACrC,IAAI;IAMP;;;;;;OAMG;IACI,cAAc,CAAC,CAAC,SAAS,eAAe,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,IAAI;IAIhH;;;;;;;;;;;;OAYG;IACI,YAAY,uFACmC;IAEtD;;;;;;;;;OASG;IACI,cAAc,8EACgC;IAErD;;;;;;OAMG;IACI,aAAa,kEAAkG;CACvH"}
|
|
@@ -20,10 +20,46 @@ class PostboyAbstractRegistrator {
|
|
|
20
20
|
* @deprecated The method should be replaced with recordSubject<T>
|
|
21
21
|
*/
|
|
22
22
|
this.registerSubject = (id) => this.register(id, new rxjs_1.Subject());
|
|
23
|
+
/**
|
|
24
|
+
* A utility function that facilitates the recording and replaying of messages
|
|
25
|
+
* using a ReplaySubject. This function is designed to handle messages of a
|
|
26
|
+
* specific type and allows specifying a buffer size to determine how many
|
|
27
|
+
* of the most recent messages should be replayed.
|
|
28
|
+
*
|
|
29
|
+
* @template T Extends the PostboyGenericMessage type, representing the type of message
|
|
30
|
+
* to be recorded and replayed.
|
|
31
|
+
* @param {MessageType<T>} type The constructor of the message type to be recorded and replayed.
|
|
32
|
+
* @param {number} [bufferSize=1] The number of recent messages to retain in the ReplaySubject's buffer.
|
|
33
|
+
* Defaults to 1 if not specified.
|
|
34
|
+
* @returns The result of invoking the `record` method with the given message type and configured ReplaySubject.
|
|
35
|
+
*/
|
|
23
36
|
this.recordReplay = (type, bufferSize = 1) => this.record(type, new rxjs_1.ReplaySubject(bufferSize));
|
|
37
|
+
/**
|
|
38
|
+
* Represents a method that records a specific behavior associated with a message type.
|
|
39
|
+
* It creates a `BehaviorSubject` initialized with the provided initial message
|
|
40
|
+
* and associates it with the given message type using the `record` method.
|
|
41
|
+
*
|
|
42
|
+
* @template T - A type parameter extending `PostboyGenericMessage` that defines the message structure.
|
|
43
|
+
* @param {MessageType<T>} type - The constructor function of the message type to be recorded.
|
|
44
|
+
* @param {T} initial - The initial value of the message that will be set in the `BehaviorSubject`.
|
|
45
|
+
* @returns {void} - This function does not return a value; instead, it modifies the internal state.
|
|
46
|
+
*/
|
|
24
47
|
this.recordBehavior = (type, initial) => this.record(type, new rxjs_1.BehaviorSubject(initial));
|
|
48
|
+
/**
|
|
49
|
+
* A function that creates and returns a new generic message recorder for a specific message type.
|
|
50
|
+
*
|
|
51
|
+
* @template T - A type parameter extending from `PostboyGenericMessage`.
|
|
52
|
+
* @param {MessageType<T>} type - The constructor for the message type being recorded.
|
|
53
|
+
* @returns {Subject<T>} A new instance of `Subject<T>` bound to the specified message type.
|
|
54
|
+
*/
|
|
25
55
|
this.recordSubject = (type) => this.record(type, new rxjs_1.Subject());
|
|
26
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* Registers a list of services to be used by the application.
|
|
59
|
+
*
|
|
60
|
+
* @param {IPostboyDependingService[]} services - An array of services to register.
|
|
61
|
+
* @return {void} This method does not return a value.
|
|
62
|
+
*/
|
|
27
63
|
registerServices(services) {
|
|
28
64
|
this.services = services;
|
|
29
65
|
}
|
|
@@ -37,9 +73,6 @@ class PostboyAbstractRegistrator {
|
|
|
37
73
|
registerExecutor(id, exec) {
|
|
38
74
|
this.postboy.registerExecutor(id, exec);
|
|
39
75
|
}
|
|
40
|
-
recordExecutor(type, exec) {
|
|
41
|
-
this.postboy.recordExecutor(type, exec);
|
|
42
|
-
}
|
|
43
76
|
/**
|
|
44
77
|
* @deprecated The method should be replaced with record<T>
|
|
45
78
|
*/
|
|
@@ -59,13 +92,40 @@ class PostboyAbstractRegistrator {
|
|
|
59
92
|
this.ids.forEach((id) => this.postboy.unregister(id));
|
|
60
93
|
}
|
|
61
94
|
// future
|
|
95
|
+
/**
|
|
96
|
+
* Records a type and its corresponding Subject<T> into the Postboy system and updates the internal identifiers.
|
|
97
|
+
*
|
|
98
|
+
* @param {MessageType<T>} type - A constructor for the generic message type T.
|
|
99
|
+
* @param {Subject<T>} sub - The subject associated with the generic message type.
|
|
100
|
+
* @return {this} Returns the current instance for method chaining.
|
|
101
|
+
*/
|
|
62
102
|
record(type, sub) {
|
|
63
103
|
this.ids.push((0, postboy_generic_message_1.checkId)(type));
|
|
64
104
|
this.postboy.record(type, sub);
|
|
105
|
+
return this;
|
|
65
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* Records a message type with a specific subject and applies a transformation pipe to the subject.
|
|
109
|
+
*
|
|
110
|
+
* @param {MessageType<T>} type - The constructor of the message type to record, which extends PostboyGenericMessage.
|
|
111
|
+
* @param {Subject<T>} sub - The Subject instance to associate with the message type.
|
|
112
|
+
* @param {(s: Subject<T>) => Observable<T>} pipe - A function that takes the subject as input and returns an Observable with transformations applied.
|
|
113
|
+
* @return {this} The current instance of the class for chaining.
|
|
114
|
+
*/
|
|
66
115
|
recordWithPipe(type, sub, pipe) {
|
|
67
116
|
this.ids.push((0, postboy_generic_message_1.checkId)(type));
|
|
68
117
|
this.postboy.recordWithPipe(type, sub, pipe);
|
|
118
|
+
return this;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Records an executor associated with a specific type and execution logic.
|
|
122
|
+
*
|
|
123
|
+
* @param type The class constructor of the executor type to be recorded, which extends PostboyExecutor.
|
|
124
|
+
* @param exec A callback function that executes the logic using an instance of the specified executor type.
|
|
125
|
+
* @return void
|
|
126
|
+
*/
|
|
127
|
+
recordExecutor(type, exec) {
|
|
128
|
+
this.postboy.recordExecutor(type, exec);
|
|
69
129
|
}
|
|
70
130
|
}
|
|
71
131
|
exports.PostboyAbstractRegistrator = PostboyAbstractRegistrator;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postboy-abstract.registrator.js","sourceRoot":"","sources":["../src/postboy-abstract.registrator.ts"],"names":[],"mappings":";;;AACA,+BAA2E;AAG3E,8EAAkF;
|
|
1
|
+
{"version":3,"file":"postboy-abstract.registrator.js","sourceRoot":"","sources":["../src/postboy-abstract.registrator.ts"],"names":[],"mappings":";;;AACA,+BAA2E;AAG3E,8EAAkF;AAIlF,MAAsB,0BAA0B;IAI9C,YAAsB,OAAuB;QAAvB,YAAO,GAAP,OAAO,CAAgB;QAHrC,QAAG,GAAa,EAAE,CAAC;QACnB,aAAQ,GAA+B,EAAE,CAAC;QA4ClD;;WAEG;QACI,mBAAc,GAAG,CAAI,EAAU,EAAE,UAAU,GAAG,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,IAAI,oBAAa,CAAI,UAAU,CAAC,CAAC,CAAC;QAE/G;;WAEG;QACI,qBAAgB,GAAG,CAAI,EAAU,EAAE,OAAU,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,IAAI,sBAAe,CAAI,OAAO,CAAC,CAAC,CAAC;QAE5G;;WAEG;QACI,oBAAe,GAAG,CAAI,EAAU,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,IAAI,cAAO,EAAK,CAAC,CAAC;QAmDhF;;;;;;;;;;;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AC,gBAAgB,CAAC,EAAE,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;IAC/C,CAAC;IAiBM,IAAI;QACT,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;QACnB,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC;IACxD,CAAC;IAED,SAAS;IAET;;;;;;OAMG;IACI,MAAM,CAAkC,IAAoB,EAAE,GAAe;QAClF,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAA,iCAAO,EAAC,IAAI,CAAC,CAAC,CAAC;QAC7B,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;QAC/B,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;;;OAOG;IACI,cAAc,CACnB,IAAoB,EACpB,GAAe,EACf,IAAsC;QAEtC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAA,iCAAO,EAAC,IAAI,CAAC,CAAC,CAAC;QAC7B,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;QAC7C,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;;OAMG;IACI,cAAc,CAAkC,IAA+B,EAAE,IAAiB;QACvG,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC1C,CAAC;CAuCF;AAnJD,gEAmJC"}
|
package/lib/postboy.service.d.ts
CHANGED
|
@@ -3,10 +3,17 @@ import { PostboyGenericMessage } from './models/postboy-generic-message';
|
|
|
3
3
|
import { PostboyLocker } from './models/postboy.locker';
|
|
4
4
|
import { PostboyExecutor } from './models/postboy-executor';
|
|
5
5
|
import { PostboyCallbackMessage } from './models/postboy-callback.message';
|
|
6
|
+
import { MessageType } from './postboy-abstract.registrator';
|
|
6
7
|
export declare class PostboyService {
|
|
7
8
|
private applications;
|
|
8
9
|
private locker;
|
|
9
10
|
private executors;
|
|
11
|
+
/**
|
|
12
|
+
* Adds a locker to the current list of lockers.
|
|
13
|
+
*
|
|
14
|
+
* @param {PostboyLocker} locker - The locker object to be added.
|
|
15
|
+
* @return {void} This method does not return a value.
|
|
16
|
+
*/
|
|
10
17
|
addLocker(locker: PostboyLocker): void;
|
|
11
18
|
/**
|
|
12
19
|
* @deprecated The method should be replaced with recordExecutor<T>
|
|
@@ -29,12 +36,61 @@ export declare class PostboyService {
|
|
|
29
36
|
* @deprecated The method should be replaced with sub<T>
|
|
30
37
|
*/
|
|
31
38
|
subscribe<T>(id: string): Observable<T>;
|
|
39
|
+
/**
|
|
40
|
+
* Fires a registered event and passes the message to its subscribers.
|
|
41
|
+
*
|
|
42
|
+
* @param {PostboyGenericMessage} message - The message object containing the event data.
|
|
43
|
+
* @return {void} This method does not return a value.
|
|
44
|
+
* @throws {Error} Throws an error if no registered event is found for the provided message ID.
|
|
45
|
+
*/
|
|
32
46
|
fire(message: PostboyGenericMessage): void;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
47
|
+
/**
|
|
48
|
+
* Fires a callback for a given message, optionally taking an action to apply to the message's result.
|
|
49
|
+
*
|
|
50
|
+
* @param {PostboyCallbackMessage<T>} message The message object that contains the callback information.
|
|
51
|
+
* @param {(e: T) => void} [action] An optional action function to execute with the emitted result of the message.
|
|
52
|
+
* @return {Observable<T>} An observable representing the result of the message's callback.
|
|
53
|
+
*/
|
|
54
|
+
fireCallback<T>(message: PostboyCallbackMessage<T>, action?: (e: T) => void): Observable<T>;
|
|
55
|
+
/**
|
|
56
|
+
* Subscribes to a specific message type and returns an observable of that type.
|
|
57
|
+
*
|
|
58
|
+
* @param type The constructor function of the type that extends PostboyGenericMessage.
|
|
59
|
+
* @return An Observable of the specified generic message type.
|
|
60
|
+
*/
|
|
61
|
+
sub<T extends PostboyGenericMessage>(type: MessageType<T>): Observable<T>;
|
|
62
|
+
/**
|
|
63
|
+
* Registers a given message type and its associated subject subscription with the system.
|
|
64
|
+
*
|
|
65
|
+
* @param type The constructor function of the message type that extends the PostboyGenericMessage.
|
|
66
|
+
* @param sub The Subject instance for the provided message type, used for managing subscriptions.
|
|
67
|
+
* @return {void} No return value.
|
|
68
|
+
*/
|
|
69
|
+
record<T extends PostboyGenericMessage>(type: MessageType<T>, sub: Subject<T>): void;
|
|
70
|
+
/**
|
|
71
|
+
* Registers a generic message type with a Subject and a transformation pipe.
|
|
72
|
+
*
|
|
73
|
+
* @param {MessageType<T>} type - The constructor of the message type being registered.
|
|
74
|
+
* @param {Subject<T>} sub - The Subject instance used to handle incoming messages of the specified type.
|
|
75
|
+
* @param {(s: Subject<T>) => Observable<T>} pipe - A function that applies a transformation or processing logic to the Subject and returns an Observable.
|
|
76
|
+
* @return {void} No return value.
|
|
77
|
+
*/
|
|
78
|
+
recordWithPipe<T extends PostboyGenericMessage>(type: MessageType<T>, sub: Subject<T>, pipe: (s: Subject<T>) => Observable<T>): void;
|
|
79
|
+
/**
|
|
80
|
+
* Records an executor instance and its corresponding execution function.
|
|
81
|
+
*
|
|
82
|
+
* @param {new (...args: any[]) => E} type - The constructor type of the executor.
|
|
83
|
+
* @param {(e: E) => T} exec - The function to execute with the provided executor instance.
|
|
84
|
+
* @return {void} No return value.
|
|
85
|
+
*/
|
|
37
86
|
recordExecutor<E extends PostboyExecutor<T>, T>(type: new (...args: any[]) => E, exec: (e: E) => T): void;
|
|
87
|
+
/**
|
|
88
|
+
* Executes the provided executor function and returns its result.
|
|
89
|
+
*
|
|
90
|
+
* @param {PostboyExecutor<T>} executor The executor to be executed, which includes its identifier and logic.
|
|
91
|
+
* @return {T} The resulting output from the executed executor function.
|
|
92
|
+
* @throws {Error} If the specified executor is not registered.
|
|
93
|
+
*/
|
|
38
94
|
exec<T>(executor: PostboyExecutor<T>): T;
|
|
39
95
|
}
|
|
40
96
|
//# sourceMappingURL=postboy.service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postboy.service.d.ts","sourceRoot":"","sources":["../src/postboy.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAW,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AAElF,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"postboy.service.d.ts","sourceRoot":"","sources":["../src/postboy.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAW,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AAElF,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAExD,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAE3E,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAE7D,qBAAa,cAAc;IACzB,OAAO,CAAC,YAAY,CAA8C;IAClE,OAAO,CAAC,MAAM,CAAqB;IACnC,OAAO,CAAC,SAAS,CAAsD;IAEvE;;;;;OAKG;IACI,SAAS,CAAC,MAAM,EAAE,aAAa,GAAG,IAAI;IAI7C;;OAEG;IACI,gBAAgB,CAAC,CAAC,SAAS,eAAe,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,IAAI;IAI7F;;OAEG;IACI,OAAO,CAAC,CAAC,SAAS,eAAe,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,GAAG,CAAC;IAM/D;;OAEG;IACI,QAAQ,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,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AAC,EAAE,IAAI,EAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,IAAI;IAIhH;;;;;;OAMG;IACI,IAAI,CAAC,CAAC,EAAE,QAAQ,EAAE,eAAe,CAAC,CAAC,CAAC,GAAG,CAAC;CAIhD"}
|
package/lib/postboy.service.js
CHANGED
|
@@ -4,13 +4,19 @@ exports.PostboyService = void 0;
|
|
|
4
4
|
const postboy_generic_message_1 = require("./models/postboy-generic-message");
|
|
5
5
|
const locker_store_1 = require("./locker.store");
|
|
6
6
|
const postboy_subscription_1 = require("./models/postboy-subscription");
|
|
7
|
-
const
|
|
7
|
+
const collections_1 = require("@artstesh/collections");
|
|
8
8
|
class PostboyService {
|
|
9
9
|
constructor() {
|
|
10
|
-
this.applications = new
|
|
10
|
+
this.applications = new collections_1.Dictionary();
|
|
11
11
|
this.locker = new locker_store_1.LockerStore();
|
|
12
|
-
this.executors = new
|
|
12
|
+
this.executors = new collections_1.Dictionary();
|
|
13
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* Adds a locker to the current list of lockers.
|
|
16
|
+
*
|
|
17
|
+
* @param {PostboyLocker} locker - The locker object to be added.
|
|
18
|
+
* @return {void} This method does not return a value.
|
|
19
|
+
*/
|
|
14
20
|
addLocker(locker) {
|
|
15
21
|
this.locker.addLocker(locker);
|
|
16
22
|
}
|
|
@@ -54,6 +60,13 @@ class PostboyService {
|
|
|
54
60
|
throw new Error(`There is no event with id ${id}`);
|
|
55
61
|
return application.pipe(application.sub);
|
|
56
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* Fires a registered event and passes the message to its subscribers.
|
|
65
|
+
*
|
|
66
|
+
* @param {PostboyGenericMessage} message - The message object containing the event data.
|
|
67
|
+
* @return {void} This method does not return a value.
|
|
68
|
+
* @throws {Error} Throws an error if no registered event is found for the provided message ID.
|
|
69
|
+
*/
|
|
57
70
|
fire(message) {
|
|
58
71
|
var _a, _b;
|
|
59
72
|
if (!((_a = this.applications.take(message.id)) === null || _a === void 0 ? void 0 : _a.sub))
|
|
@@ -61,6 +74,13 @@ class PostboyService {
|
|
|
61
74
|
if (this.locker.check(message.id))
|
|
62
75
|
(_b = this.applications.take(message.id)) === null || _b === void 0 ? void 0 : _b.sub.next(message);
|
|
63
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* Fires a callback for a given message, optionally taking an action to apply to the message's result.
|
|
79
|
+
*
|
|
80
|
+
* @param {PostboyCallbackMessage<T>} message The message object that contains the callback information.
|
|
81
|
+
* @param {(e: T) => void} [action] An optional action function to execute with the emitted result of the message.
|
|
82
|
+
* @return {Observable<T>} An observable representing the result of the message's callback.
|
|
83
|
+
*/
|
|
64
84
|
fireCallback(message, action) {
|
|
65
85
|
var _a, _b;
|
|
66
86
|
if (!((_a = this.applications.take(message.id)) === null || _a === void 0 ? void 0 : _a.sub))
|
|
@@ -68,23 +88,59 @@ class PostboyService {
|
|
|
68
88
|
message.result.subscribe(action);
|
|
69
89
|
if (this.locker.check(message.id))
|
|
70
90
|
(_b = this.applications.take(message.id)) === null || _b === void 0 ? void 0 : _b.sub.next(message);
|
|
91
|
+
return message.result;
|
|
71
92
|
}
|
|
72
93
|
// future
|
|
94
|
+
/**
|
|
95
|
+
* Subscribes to a specific message type and returns an observable of that type.
|
|
96
|
+
*
|
|
97
|
+
* @param type The constructor function of the type that extends PostboyGenericMessage.
|
|
98
|
+
* @return An Observable of the specified generic message type.
|
|
99
|
+
*/
|
|
73
100
|
sub(type) {
|
|
74
101
|
const application = this.applications.take((0, postboy_generic_message_1.checkId)(type));
|
|
75
102
|
if (!application)
|
|
76
103
|
throw new Error(`There is no registered event ${type.constructor.name}`);
|
|
77
104
|
return application.pipe(application.sub);
|
|
78
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* Registers a given message type and its associated subject subscription with the system.
|
|
108
|
+
*
|
|
109
|
+
* @param type The constructor function of the message type that extends the PostboyGenericMessage.
|
|
110
|
+
* @param sub The Subject instance for the provided message type, used for managing subscriptions.
|
|
111
|
+
* @return {void} No return value.
|
|
112
|
+
*/
|
|
79
113
|
record(type, sub) {
|
|
80
114
|
this.applications.put((0, postboy_generic_message_1.checkId)(type), new postboy_subscription_1.PostboySubscription(sub, (s) => s.asObservable()));
|
|
81
115
|
}
|
|
116
|
+
/**
|
|
117
|
+
* Registers a generic message type with a Subject and a transformation pipe.
|
|
118
|
+
*
|
|
119
|
+
* @param {MessageType<T>} type - The constructor of the message type being registered.
|
|
120
|
+
* @param {Subject<T>} sub - The Subject instance used to handle incoming messages of the specified type.
|
|
121
|
+
* @param {(s: Subject<T>) => Observable<T>} pipe - A function that applies a transformation or processing logic to the Subject and returns an Observable.
|
|
122
|
+
* @return {void} No return value.
|
|
123
|
+
*/
|
|
82
124
|
recordWithPipe(type, sub, pipe) {
|
|
83
125
|
this.applications.put((0, postboy_generic_message_1.checkId)(type), new postboy_subscription_1.PostboySubscription(sub, pipe));
|
|
84
126
|
}
|
|
127
|
+
/**
|
|
128
|
+
* Records an executor instance and its corresponding execution function.
|
|
129
|
+
*
|
|
130
|
+
* @param {new (...args: any[]) => E} type - The constructor type of the executor.
|
|
131
|
+
* @param {(e: E) => T} exec - The function to execute with the provided executor instance.
|
|
132
|
+
* @return {void} No return value.
|
|
133
|
+
*/
|
|
85
134
|
recordExecutor(type, exec) {
|
|
86
135
|
this.executors.put((0, postboy_generic_message_1.checkId)(type), exec);
|
|
87
136
|
}
|
|
137
|
+
/**
|
|
138
|
+
* Executes the provided executor function and returns its result.
|
|
139
|
+
*
|
|
140
|
+
* @param {PostboyExecutor<T>} executor The executor to be executed, which includes its identifier and logic.
|
|
141
|
+
* @return {T} The resulting output from the executed executor function.
|
|
142
|
+
* @throws {Error} If the specified executor is not registered.
|
|
143
|
+
*/
|
|
88
144
|
exec(executor) {
|
|
89
145
|
if (!this.executors.has(executor.id))
|
|
90
146
|
throw new Error(`There is no registered executor ${executor.id}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postboy.service.js","sourceRoot":"","sources":["../src/postboy.service.ts"],"names":[],"mappings":";;;AACA,8EAAkF;AAClF,iDAA6C;AAE7C,wEAAoE;
|
|
1
|
+
{"version":3,"file":"postboy.service.js","sourceRoot":"","sources":["../src/postboy.service.ts"],"names":[],"mappings":";;;AACA,8EAAkF;AAClF,iDAA6C;AAE7C,wEAAoE;AAGpE,uDAAmD;AAGnD,MAAa,cAAc;IAA3B;QACU,iBAAY,GAAG,IAAI,wBAAU,EAA4B,CAAC;QAC1D,WAAM,GAAG,IAAI,0BAAW,EAAE,CAAC;QAC3B,cAAS,GAAG,IAAI,wBAAU,EAAoC,CAAC;IAmJzE,CAAC;IAjJC;;;;;OAKG;IACI,SAAS,CAAC,MAAqB;QACpC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IAChC,CAAC;IAED;;OAEG;IACI,gBAAgB,CAAkC,EAAU,EAAE,IAAiB;QACpF,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,EAAE,IAAW,CAAC,CAAC;IACtC,CAAC;IAED;;OAEG;IACI,OAAO,CAAkC,QAAW;QACzD,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;YAClC,MAAM,IAAI,KAAK,CAAC,mCAAmC,QAAQ,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC,CAAC;QAClF,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAE,CAAC,QAAQ,CAAC,CAAC;IACrD,CAAC;IAED;;OAEG;IACI,QAAQ,CAAI,EAAU,EAAE,GAAe;QAC5C,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,0CAAmB,CAAI,GAAG,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,YAAY,EAAE,CAAC,CAAC,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AAG,EAAE,IAAI,CAAC,CAAC,CAAC;IAC9E,CAAC;IAED;;;;;;OAMG;IACI,cAAc,CAAkC,IAA+B,EAAE,IAAiB;QACvG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAA,iCAAO,EAAC,IAAI,CAAC,EAAE,IAAW,CAAC,CAAC;IACjD,CAAC;IAED;;;;;;OAMG;IACI,IAAI,CAAI,QAA4B;QACzC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,mCAAmC,QAAQ,CAAC,EAAE,EAAE,CAAC,CAAC;QACxG,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAE,CAAC,QAAQ,CAAC,CAAC;IACrD,CAAC;CACF;AAtJD,wCAsJC"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@artstesh/postboy",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"author": "artstesh",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
7
7
|
"license": "MIT",
|
|
8
|
+
"description": "Let's send a message ;)",
|
|
9
|
+
"homepage": "https://postboy.artstesh.ru",
|
|
8
10
|
"scripts": {
|
|
9
11
|
"prepare": "npm run build",
|
|
10
12
|
"prepublishOnly": "npm test && npm run lint",
|
|
@@ -27,7 +29,8 @@
|
|
|
27
29
|
},
|
|
28
30
|
"peerDependencies": {
|
|
29
31
|
"rxjs": ">6.0.0",
|
|
30
|
-
"typescript": "^4.0.0"
|
|
32
|
+
"typescript": "^4.0.0",
|
|
33
|
+
"@artstesh/collections": "^1.0.4"
|
|
31
34
|
},
|
|
32
35
|
"dependencies": {
|
|
33
36
|
"rxjs": "^6.0.0",
|