@peerbit/pubsub-interface 1.0.4 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,31 +1,45 @@
1
1
  import { PublicSignKey } from "@peerbit/crypto";
2
- import { PubSubData, Subscription } from "./messages";
2
+ import { PubSubData, Subscription } from "./messages.js";
3
3
  import { Message, DataMessage, WaitForPeer, PeerEvents } from "@peerbit/stream-interface";
4
4
  import { EventHandler } from "@libp2p/interfaces/events";
5
5
  import { PeerId as Libp2pPeerId } from "@libp2p/interface-peer-id";
6
- interface From {
6
+ export declare class SubscriptionEvent {
7
7
  from: PublicSignKey;
8
- }
9
- export interface SubscriptionEvent extends From {
10
8
  subscriptions: Subscription[];
9
+ constructor(from: PublicSignKey, subscriptions: Subscription[]);
11
10
  }
12
- export interface UnsubcriptionEvent extends From {
11
+ export declare class UnsubcriptionEvent {
12
+ from: PublicSignKey;
13
13
  unsubscriptions: Subscription[];
14
+ constructor(from: PublicSignKey, unsubscriptions: Subscription[]);
15
+ }
16
+ export declare class DataEvent {
17
+ data: PubSubData;
18
+ message: DataMessage;
19
+ constructor(data: PubSubData, message: DataMessage);
20
+ }
21
+ export declare class SubscriptionData {
22
+ publicKey: PublicSignKey;
23
+ timestamp: bigint;
24
+ data?: Uint8Array;
25
+ constructor(properties: {
26
+ publicKey: PublicSignKey;
27
+ timestamp: bigint;
28
+ data?: Uint8Array;
29
+ });
14
30
  }
15
31
  export interface PubSubEvents extends PeerEvents {
16
- data: CustomEvent<{
17
- data: PubSubData;
18
- message: DataMessage;
19
- }>;
32
+ data: CustomEvent<DataEvent>;
20
33
  subscribe: CustomEvent<SubscriptionEvent>;
21
34
  unsubscribe: CustomEvent<UnsubcriptionEvent>;
22
35
  message: CustomEvent<Message>;
23
36
  }
24
37
  export interface IEventEmitter<EventMap extends Record<string, any>> {
25
- addEventListener<K extends keyof EventMap>(type: K, listener: EventHandler<EventMap[K]> | null, options?: boolean | AddEventListenerOptions): void;
26
- removeEventListener<K extends keyof EventMap>(type: K, listener?: EventHandler<EventMap[K]> | null, options?: boolean | EventListenerOptions): void;
27
- dispatchEvent(event: Event): boolean;
38
+ addEventListener<K extends keyof EventMap>(type: K, listener: EventHandler<EventMap[K]> | null, options?: boolean | AddEventListenerOptions): MaybePromise<void>;
39
+ removeEventListener<K extends keyof EventMap>(type: K, listener?: EventHandler<EventMap[K]> | null, options?: boolean | EventListenerOptions): MaybePromise<void>;
40
+ dispatchEvent(event: Event): MaybePromise<boolean>;
28
41
  }
42
+ type MaybePromise<T> = Promise<T> | T;
29
43
  export type PublishOptions = {
30
44
  topics?: string[];
31
45
  to?: (string | PublicSignKey | Libp2pPeerId)[];
@@ -36,17 +50,15 @@ export type PublishOptions = {
36
50
  strict: true;
37
51
  };
38
52
  export interface PubSub extends IEventEmitter<PubSubEvents>, WaitForPeer {
39
- getSubscribers(topic: string): Map<string, {
40
- timestamp: bigint;
41
- data?: Uint8Array;
42
- }> | undefined;
53
+ emitSelf: boolean;
54
+ getSubscribers(topic: string): MaybePromise<Map<string, SubscriptionData> | undefined>;
43
55
  requestSubscribers(topic: string, from?: PublicSignKey): Promise<void>;
44
56
  subscribe(topic: string, options?: {
45
57
  data?: Uint8Array;
46
58
  }): Promise<void>;
47
59
  unsubscribe(topic: string, options?: {
48
- force: boolean;
49
- data: Uint8Array;
60
+ force?: boolean;
61
+ data?: Uint8Array;
50
62
  }): Promise<boolean>;
51
63
  publish(data: Uint8Array, options?: PublishOptions): Promise<Uint8Array>;
52
64
  }
package/lib/esm/index.js CHANGED
@@ -1,2 +1,87 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { PublicSignKey } from "@peerbit/crypto";
11
+ import { PubSubData, Subscription } from "./messages.js";
12
+ import { DataMessage, } from "@peerbit/stream-interface";
13
+ import { field, option, vec } from "@dao-xyz/borsh";
14
+ export class SubscriptionEvent {
15
+ from;
16
+ subscriptions;
17
+ constructor(from, subscriptions) {
18
+ this.from = from;
19
+ this.subscriptions = subscriptions;
20
+ }
21
+ }
22
+ __decorate([
23
+ field({ type: PublicSignKey }),
24
+ __metadata("design:type", PublicSignKey)
25
+ ], SubscriptionEvent.prototype, "from", void 0);
26
+ __decorate([
27
+ field({ type: vec(Subscription) }),
28
+ __metadata("design:type", Array)
29
+ ], SubscriptionEvent.prototype, "subscriptions", void 0);
30
+ export class UnsubcriptionEvent {
31
+ from;
32
+ unsubscriptions;
33
+ constructor(from, unsubscriptions) {
34
+ this.from = from;
35
+ this.unsubscriptions = unsubscriptions;
36
+ }
37
+ }
38
+ __decorate([
39
+ field({ type: PublicSignKey }),
40
+ __metadata("design:type", PublicSignKey)
41
+ ], UnsubcriptionEvent.prototype, "from", void 0);
42
+ __decorate([
43
+ field({ type: vec(Subscription) }),
44
+ __metadata("design:type", Array)
45
+ ], UnsubcriptionEvent.prototype, "unsubscriptions", void 0);
46
+ export class DataEvent {
47
+ data;
48
+ message;
49
+ constructor(data, message) {
50
+ this.data = data;
51
+ this.message = message;
52
+ }
53
+ }
54
+ __decorate([
55
+ field({ type: PubSubData }),
56
+ __metadata("design:type", PubSubData)
57
+ ], DataEvent.prototype, "data", void 0);
58
+ __decorate([
59
+ field({ type: DataMessage }),
60
+ __metadata("design:type", DataMessage)
61
+ ], DataEvent.prototype, "message", void 0);
62
+ export class SubscriptionData {
63
+ publicKey;
64
+ timestamp;
65
+ data;
66
+ constructor(properties) {
67
+ this.publicKey = properties.publicKey;
68
+ this.timestamp = properties.timestamp;
69
+ this.data = properties.data;
70
+ }
71
+ }
72
+ __decorate([
73
+ field({ type: PublicSignKey }),
74
+ __metadata("design:type", PublicSignKey)
75
+ ], SubscriptionData.prototype, "publicKey", void 0);
76
+ __decorate([
77
+ field({ type: "u64" }),
78
+ __metadata("design:type", BigInt)
79
+ ], SubscriptionData.prototype, "timestamp", void 0);
80
+ __decorate([
81
+ field({
82
+ type: option(Uint8Array),
83
+ }),
84
+ __metadata("design:type", Uint8Array)
85
+ ], SubscriptionData.prototype, "data", void 0);
1
86
  export * from "./messages.js";
2
87
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAsFA,cAAc,eAAe,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,EAEN,WAAW,GAGX,MAAM,2BAA2B,CAAC;AAGnC,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAEpD,MAAM,OAAO,iBAAiB;IAE7B,IAAI,CAAgB;IAGpB,aAAa,CAAiB;IAE9B,YAAY,IAAmB,EAAE,aAA6B;QAC7D,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;IACpC,CAAC;CACD;AATA;IADC,KAAK,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,CAAC;8BACzB,aAAa;+CAAC;AAGpB;IADC,KAAK,CAAC,EAAE,IAAI,EAAE,GAAG,CAAC,YAAY,CAAC,EAAE,CAA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KACxB,CAAC;8BACK,UAAU;8CAAC;AAyEnB,cAAc,eAAe,CAAC"}
@@ -1,7 +1,7 @@
1
1
  import { Uint8ArrayList } from "uint8arraylist";
2
2
  export declare abstract class PubSubMessage {
3
- abstract serialize(): Uint8Array | Uint8ArrayList;
4
- static deserialize(bytes: Uint8Array): PubSubData | Subscribe | Unsubscribe | GetSubscribers;
3
+ abstract bytes(): Uint8Array | Uint8ArrayList;
4
+ static from(bytes: Uint8Array): PubSubData | Subscribe | Unsubscribe | GetSubscribers;
5
5
  }
6
6
  export declare const toUint8Array: (arr: Uint8ArrayList | Uint8Array) => Uint8Array;
7
7
  export declare class PubSubData extends PubSubMessage {
@@ -14,8 +14,8 @@ export declare class PubSubData extends PubSubMessage {
14
14
  strict?: boolean;
15
15
  });
16
16
  _serialized: Uint8ArrayList;
17
- serialize(): Uint8Array | Uint8ArrayList;
18
- static deserialize(bytes: Uint8Array | Uint8ArrayList): PubSubData;
17
+ bytes(): Uint8Array | Uint8ArrayList;
18
+ static from(bytes: Uint8Array | Uint8ArrayList): PubSubData;
19
19
  }
20
20
  export declare class Subscription {
21
21
  topic: string;
@@ -28,8 +28,8 @@ export declare class Subscribe extends PubSubMessage {
28
28
  subscriptions: Subscription[];
29
29
  });
30
30
  _serialized: Uint8ArrayList;
31
- serialize(): Uint8Array | Uint8ArrayList;
32
- static deserialize(bytes: Uint8Array | Uint8ArrayList): Subscribe;
31
+ bytes(): Uint8Array | Uint8ArrayList;
32
+ static from(bytes: Uint8Array | Uint8ArrayList): Subscribe;
33
33
  get topics(): string[];
34
34
  }
35
35
  export declare class Unsubscription {
@@ -42,8 +42,8 @@ export declare class Unsubscribe extends PubSubMessage {
42
42
  topics: string[];
43
43
  });
44
44
  _serialized: Uint8ArrayList;
45
- serialize(): Uint8Array | Uint8ArrayList;
46
- static deserialize(bytes: Uint8Array | Uint8ArrayList): Unsubscribe;
45
+ bytes(): Uint8Array | Uint8ArrayList;
46
+ static from(bytes: Uint8Array | Uint8ArrayList): Unsubscribe;
47
47
  get topics(): string[];
48
48
  }
49
49
  export declare class GetSubscribers extends PubSubMessage {
@@ -52,6 +52,6 @@ export declare class GetSubscribers extends PubSubMessage {
52
52
  topics: string[];
53
53
  });
54
54
  _serialized: Uint8ArrayList;
55
- serialize(): Uint8Array | Uint8ArrayList;
56
- static deserialize(bytes: Uint8Array | Uint8ArrayList): GetSubscribers;
55
+ bytes(): Uint8Array | Uint8ArrayList;
56
+ static from(bytes: Uint8Array | Uint8ArrayList): GetSubscribers;
57
57
  }
@@ -11,19 +11,19 @@ var PubSubData_1, Subscribe_1, Unsubscribe_1, GetSubscribers_1;
11
11
  import { Uint8ArrayList } from "uint8arraylist";
12
12
  import { field, vec, variant, serialize, deserialize, option, } from "@dao-xyz/borsh";
13
13
  export class PubSubMessage {
14
- static deserialize(bytes) {
14
+ static from(bytes) {
15
15
  const first = bytes[0];
16
16
  if (first === 0) {
17
- return PubSubData.deserialize(bytes);
17
+ return PubSubData.from(bytes);
18
18
  }
19
19
  if (first === 1) {
20
- return Subscribe.deserialize(bytes);
20
+ return Subscribe.from(bytes);
21
21
  }
22
22
  if (first === 2) {
23
- return Unsubscribe.deserialize(bytes);
23
+ return Unsubscribe.from(bytes);
24
24
  }
25
25
  if (first === 3) {
26
- return GetSubscribers.deserialize(bytes);
26
+ return GetSubscribers.from(bytes);
27
27
  }
28
28
  throw new Error("Unsupported");
29
29
  }
@@ -31,7 +31,7 @@ export class PubSubMessage {
31
31
  export const toUint8Array = (arr) => arr instanceof Uint8ArrayList ? arr.subarray() : arr;
32
32
  export let PubSubData = PubSubData_1 = class PubSubData extends PubSubMessage {
33
33
  topics;
34
- strict; // only deliver message to initial to recievers
34
+ strict; // only deliver message to initial to receivers
35
35
  data;
36
36
  constructor(options) {
37
37
  super();
@@ -43,13 +43,13 @@ export let PubSubData = PubSubData_1 = class PubSubData extends PubSubMessage {
43
43
  this.strict = options.strict ?? false;
44
44
  }
45
45
  _serialized;
46
- serialize() {
46
+ bytes() {
47
47
  if (this._serialized) {
48
48
  return this._serialized;
49
49
  }
50
50
  return serialize(this);
51
51
  }
52
- static deserialize(bytes) {
52
+ static from(bytes) {
53
53
  const ret = deserialize(bytes instanceof Uint8Array ? bytes : bytes.subarray(), PubSubData_1);
54
54
  if (bytes instanceof Uint8ArrayList) {
55
55
  ret._serialized = bytes;
@@ -100,13 +100,13 @@ export let Subscribe = Subscribe_1 = class Subscribe extends PubSubMessage {
100
100
  this.subscriptions = options.subscriptions;
101
101
  }
102
102
  _serialized;
103
- serialize() {
103
+ bytes() {
104
104
  if (this._serialized) {
105
105
  return this._serialized;
106
106
  }
107
107
  return serialize(this);
108
108
  }
109
- static deserialize(bytes) {
109
+ static from(bytes) {
110
110
  const ret = deserialize(bytes instanceof Uint8Array ? bytes : bytes.subarray(), Subscribe_1);
111
111
  if (bytes instanceof Uint8ArrayList) {
112
112
  ret._serialized = bytes;
@@ -146,13 +146,13 @@ export let Unsubscribe = Unsubscribe_1 = class Unsubscribe extends PubSubMessage
146
146
  this.unsubscriptions = options.topics.map((x) => new Unsubscription(x));
147
147
  }
148
148
  _serialized;
149
- serialize() {
149
+ bytes() {
150
150
  if (this._serialized) {
151
151
  return this._serialized;
152
152
  }
153
153
  return serialize(this);
154
154
  }
155
- static deserialize(bytes) {
155
+ static from(bytes) {
156
156
  const ret = deserialize(bytes instanceof Uint8Array ? bytes : bytes.subarray(), Unsubscribe_1);
157
157
  if (bytes instanceof Uint8ArrayList) {
158
158
  ret._serialized = bytes;
@@ -179,13 +179,13 @@ export let GetSubscribers = GetSubscribers_1 = class GetSubscribers extends PubS
179
179
  this.topics = options.topics;
180
180
  }
181
181
  _serialized;
182
- serialize() {
182
+ bytes() {
183
183
  if (this._serialized) {
184
184
  return this._serialized;
185
185
  }
186
186
  return serialize(this);
187
187
  }
188
- static deserialize(bytes) {
188
+ static from(bytes) {
189
189
  const ret = deserialize(bytes instanceof Uint8Array ? bytes : bytes.subarray(), GetSubscribers_1);
190
190
  if (bytes instanceof Uint8ArrayList) {
191
191
  ret._serialized = bytes;
@@ -1 +1 @@
1
- {"version":3,"file":"messages.js","sourceRoot":"","sources":["../../src/messages.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EACN,KAAK,EACL,GAAG,EACH,OAAO,EACP,SAAS,EACT,WAAW,EACX,MAAM,GACN,MAAM,gBAAgB,CAAC;AACxB,MAAM,OAAgB,aAAa;IAElC,MAAM,CAAC,WAAW,CAAC,KAAiB;QACnC,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QACvB,IAAI,KAAK,KAAK,CAAC,EAAE;YAChB,OAAO,UAAU,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;SACrC;QACD,IAAI,KAAK,KAAK,CAAC,EAAE;YAChB,OAAO,SAAS,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;SACpC;QACD,IAAI,KAAK,KAAK,CAAC,EAAE;YAChB,OAAO,WAAW,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;SACtC;QAED,IAAI,KAAK,KAAK,CAAC,EAAE;YAChB,OAAO,cAAc,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;SACzC;QACD,MAAM,IAAI,KAAK,CAAC,aAAa,CAAC,CAAC;IAChC,CAAC;CACD;AAED,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,GAAgC,EAAE,EAAE,CAChE,GAAG,YAAY,cAAc,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC;AAG/C,WAAM,UAAU,kBAAhB,MAAM,UAAW,SAAQ,aAAa;IAE5C,MAAM,CAAW;IAGjB,MAAM,CAAU,CAAC,+CAA+C;IAGhE,IAAI,CAAa;IAEjB,YAAY,OAIX;QACA,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,IAAI;YACR,OAAO,CAAC,IAAI,YAAY,UAAU;gBACjC,C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,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,EAAE,EACtD,gBAAc,CACd,CAAC;QACF,IAAI,KAAK,YAAY,cAAc,EAAE;YACpC,GAAG,CAAC,WAAW,GAAG,KAAK,CAAC;SACxB;QACD,OAAO,GAAG,CAAC;IACZ,CAAC;CACD,CAAA;AA5BA;IADC,KAAK,CAAC,EAAE,IAAI,EAAE,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;;8CACd;AAFL,cAAc;IAD1B,OAAO,CAAC,CAAC,CAAC;;GACE,cAAc,CA8B1B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peerbit/pubsub-interface",
3
- "version": "1.0.4",
3
+ "version": "1.1.0",
4
4
  "description": "Block store streaming",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -50,8 +50,8 @@
50
50
  ],
51
51
  "dependencies": {
52
52
  "@dao-xyz/borsh": "^5.1.5",
53
- "@peerbit/crypto": "1.0.3",
54
- "@peerbit/stream-interface": "^1.0.4"
53
+ "@peerbit/crypto": "1.0.5",
54
+ "@peerbit/stream-interface": "^1.0.6"
55
55
  },
56
- "gitHead": "99e30817f094e45ffcd60f4babd90a717bd26a22"
56
+ "gitHead": "464e807d679e24b897b7811ac99d6f85fbd756f9"
57
57
  }
package/src/index.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { PublicSignKey } from "@peerbit/crypto";
2
- import { PubSubData, Subscription } from "./messages";
2
+ import { PubSubData, Subscription } from "./messages.js";
3
3
  import {
4
4
  Message,
5
5
  DataMessage,
@@ -8,21 +8,71 @@ import {
8
8
  } from "@peerbit/stream-interface";
9
9
  import { EventHandler } from "@libp2p/interfaces/events";
10
10
  import { PeerId as Libp2pPeerId } from "@libp2p/interface-peer-id";
11
+ import { field, option, vec } from "@dao-xyz/borsh";
11
12
 
12
- interface From {
13
+ export class SubscriptionEvent {
14
+ @field({ type: PublicSignKey })
13
15
  from: PublicSignKey;
14
- }
15
16
 
16
- export interface SubscriptionEvent extends From {
17
+ @field({ type: vec(Subscription) })
17
18
  subscriptions: Subscription[];
19
+
20
+ constructor(from: PublicSignKey, subscriptions: Subscription[]) {
21
+ this.from = from;
22
+ this.subscriptions = subscriptions;
23
+ }
18
24
  }
19
25
 
20
- export interface UnsubcriptionEvent extends From {
26
+ export class UnsubcriptionEvent {
27
+ @field({ type: PublicSignKey })
28
+ from: PublicSignKey;
29
+
30
+ @field({ type: vec(Subscription) })
21
31
  unsubscriptions: Subscription[];
32
+
33
+ constructor(from: PublicSignKey, unsubscriptions: Subscription[]) {
34
+ this.from = from;
35
+ this.unsubscriptions = unsubscriptions;
36
+ }
37
+ }
38
+
39
+ export class DataEvent {
40
+ @field({ type: PubSubData })
41
+ data: PubSubData;
42
+
43
+ @field({ type: DataMessage })
44
+ message: DataMessage;
45
+ constructor(data: PubSubData, message: DataMessage) {
46
+ this.data = data;
47
+ this.message = message;
48
+ }
49
+ }
50
+
51
+ export class SubscriptionData {
52
+ @field({ type: PublicSignKey })
53
+ publicKey: PublicSignKey;
54
+
55
+ @field({ type: "u64" })
56
+ timestamp: bigint;
57
+
58
+ @field({
59
+ type: option(Uint8Array),
60
+ })
61
+ data?: Uint8Array;
62
+
63
+ constructor(properties: {
64
+ publicKey: PublicSignKey;
65
+ timestamp: bigint;
66
+ data?: Uint8Array;
67
+ }) {
68
+ this.publicKey = properties.publicKey;
69
+ this.timestamp = properties.timestamp;
70
+ this.data = properties.data;
71
+ }
22
72
  }
23
73
 
24
74
  export interface PubSubEvents extends PeerEvents {
25
- data: CustomEvent<{ data: PubSubData; message: DataMessage }>;
75
+ data: CustomEvent<DataEvent>;
26
76
  subscribe: CustomEvent<SubscriptionEvent>;
27
77
  unsubscribe: CustomEvent<UnsubcriptionEvent>;
28
78
  message: CustomEvent<Message>;
@@ -32,15 +82,16 @@ export interface IEventEmitter<EventMap extends Record<string, any>> {
32
82
  type: K,
33
83
  listener: EventHandler<EventMap[K]> | null,
34
84
  options?: boolean | AddEventListenerOptions
35
- ): void;
85
+ ): MaybePromise<void>;
36
86
  removeEventListener<K extends keyof EventMap>(
37
87
  type: K,
38
88
  listener?: EventHandler<EventMap[K]> | null,
39
89
  options?: boolean | EventListenerOptions
40
- ): void;
41
- dispatchEvent(event: Event): boolean;
90
+ ): MaybePromise<void>;
91
+ dispatchEvent(event: Event): MaybePromise<boolean>;
42
92
  }
43
93
 
94
+ type MaybePromise<T> = Promise<T> | T;
44
95
  export type PublishOptions =
45
96
  | {
46
97
  topics?: string[];
@@ -54,15 +105,11 @@ export type PublishOptions =
54
105
  };
55
106
 
56
107
  export interface PubSub extends IEventEmitter<PubSubEvents>, WaitForPeer {
57
- getSubscribers(topic: string):
58
- | Map<
59
- string,
60
- {
61
- timestamp: bigint;
62
- data?: Uint8Array;
63
- }
64
- >
65
- | undefined;
108
+ emitSelf: boolean;
109
+
110
+ getSubscribers(
111
+ topic: string
112
+ ): MaybePromise<Map<string, SubscriptionData> | undefined>;
66
113
 
67
114
  requestSubscribers(topic: string, from?: PublicSignKey): Promise<void>;
68
115
 
@@ -76,8 +123,8 @@ export interface PubSub extends IEventEmitter<PubSubEvents>, WaitForPeer {
76
123
  unsubscribe(
77
124
  topic: string,
78
125
  options?: {
79
- force: boolean;
80
- data: Uint8Array;
126
+ force?: boolean;
127
+ data?: Uint8Array;
81
128
  }
82
129
  ): Promise<boolean>;
83
130
 
package/src/messages.ts CHANGED
@@ -8,21 +8,21 @@ import {
8
8
  option,
9
9
  } from "@dao-xyz/borsh";
10
10
  export abstract class PubSubMessage {
11
- abstract serialize(): Uint8Array | Uint8ArrayList;
12
- static deserialize(bytes: Uint8Array) {
11
+ abstract bytes(): Uint8Array | Uint8ArrayList;
12
+ static from(bytes: Uint8Array) {
13
13
  const first = bytes[0];
14
14
  if (first === 0) {
15
- return PubSubData.deserialize(bytes);
15
+ return PubSubData.from(bytes);
16
16
  }
17
17
  if (first === 1) {
18
- return Subscribe.deserialize(bytes);
18
+ return Subscribe.from(bytes);
19
19
  }
20
20
  if (first === 2) {
21
- return Unsubscribe.deserialize(bytes);
21
+ return Unsubscribe.from(bytes);
22
22
  }
23
23
 
24
24
  if (first === 3) {
25
- return GetSubscribers.deserialize(bytes);
25
+ return GetSubscribers.from(bytes);
26
26
  }
27
27
  throw new Error("Unsupported");
28
28
  }
@@ -37,7 +37,7 @@ export class PubSubData extends PubSubMessage {
37
37
  topics: string[];
38
38
 
39
39
  @field({ type: "bool" })
40
- strict: boolean; // only deliver message to initial to recievers
40
+ strict: boolean; // only deliver message to initial to receivers
41
41
 
42
42
  @field({ type: Uint8Array })
43
43
  data: Uint8Array;
@@ -58,14 +58,14 @@ export class PubSubData extends PubSubMessage {
58
58
 
59
59
  _serialized: Uint8ArrayList;
60
60
 
61
- serialize() {
61
+ bytes() {
62
62
  if (this._serialized) {
63
63
  return this._serialized;
64
64
  }
65
65
 
66
66
  return serialize(this);
67
67
  }
68
- static deserialize(bytes: Uint8Array | Uint8ArrayList): PubSubData {
68
+ static from(bytes: Uint8Array | Uint8ArrayList): PubSubData {
69
69
  const ret = deserialize(
70
70
  bytes instanceof Uint8Array ? bytes : bytes.subarray(),
71
71
  PubSubData
@@ -103,13 +103,13 @@ export class Subscribe extends PubSubMessage {
103
103
 
104
104
  _serialized: Uint8ArrayList;
105
105
 
106
- serialize() {
106
+ bytes() {
107
107
  if (this._serialized) {
108
108
  return this._serialized;
109
109
  }
110
110
  return serialize(this);
111
111
  }
112
- static deserialize(bytes: Uint8Array | Uint8ArrayList): Subscribe {
112
+ static from(bytes: Uint8Array | Uint8ArrayList): Subscribe {
113
113
  const ret = deserialize(
114
114
  bytes instanceof Uint8Array ? bytes : bytes.subarray(),
115
115
  Subscribe
@@ -146,14 +146,14 @@ export class Unsubscribe extends PubSubMessage {
146
146
 
147
147
  _serialized: Uint8ArrayList;
148
148
 
149
- serialize() {
149
+ bytes() {
150
150
  if (this._serialized) {
151
151
  return this._serialized;
152
152
  }
153
153
  return serialize(this);
154
154
  }
155
155
 
156
- static deserialize(bytes: Uint8Array | Uint8ArrayList): Unsubscribe {
156
+ static from(bytes: Uint8Array | Uint8ArrayList): Unsubscribe {
157
157
  const ret = deserialize(
158
158
  bytes instanceof Uint8Array ? bytes : bytes.subarray(),
159
159
  Unsubscribe
@@ -163,6 +163,7 @@ export class Unsubscribe extends PubSubMessage {
163
163
  }
164
164
  return ret;
165
165
  }
166
+
166
167
  get topics() {
167
168
  return this.unsubscriptions.map((x) => x.topic);
168
169
  }
@@ -182,14 +183,14 @@ export class GetSubscribers extends PubSubMessage {
182
183
 
183
184
  _serialized: Uint8ArrayList;
184
185
 
185
- serialize() {
186
+ bytes() {
186
187
  if (this._serialized) {
187
188
  return this._serialized;
188
189
  }
189
190
  return serialize(this);
190
191
  }
191
192
 
192
- static deserialize(bytes: Uint8Array | Uint8ArrayList): GetSubscribers {
193
+ static from(bytes: Uint8Array | Uint8ArrayList): GetSubscribers {
193
194
  const ret = deserialize(
194
195
  bytes instanceof Uint8Array ? bytes : bytes.subarray(),
195
196
  GetSubscribers