@waku/sds 0.0.6-ced989a.0 → 0.0.6-e1212cc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/bundle/index.js +22879 -5883
  2. package/dist/.tsbuildinfo +1 -1
  3. package/dist/index.d.ts +1 -1
  4. package/dist/index.js.map +1 -1
  5. package/dist/message_channel/command_queue.d.ts +1 -1
  6. package/dist/message_channel/events.d.ts +3 -85
  7. package/dist/message_channel/events.js +1 -137
  8. package/dist/message_channel/events.js.map +1 -1
  9. package/dist/message_channel/index.d.ts +1 -0
  10. package/dist/message_channel/index.js +1 -0
  11. package/dist/message_channel/index.js.map +1 -1
  12. package/dist/message_channel/mem_local_history.d.ts +7 -7
  13. package/dist/message_channel/mem_local_history.js +18 -32
  14. package/dist/message_channel/mem_local_history.js.map +1 -1
  15. package/dist/message_channel/message.d.ts +83 -0
  16. package/dist/message_channel/message.js +139 -0
  17. package/dist/message_channel/message.js.map +1 -0
  18. package/dist/message_channel/message_channel.d.ts +4 -3
  19. package/dist/message_channel/message_channel.js +7 -7
  20. package/dist/message_channel/message_channel.js.map +1 -1
  21. package/package.json +1 -1
  22. package/src/index.ts +2 -1
  23. package/src/message_channel/command_queue.ts +1 -1
  24. package/src/message_channel/events.ts +3 -175
  25. package/src/message_channel/index.ts +13 -0
  26. package/src/message_channel/mem_local_history.ts +37 -43
  27. package/src/message_channel/message.ts +175 -0
  28. package/src/message_channel/message_channel.ts +13 -15
  29. package/dist/message_channel/sorted_array_base.d.ts +0 -50
  30. package/dist/message_channel/sorted_array_base.js +0 -199
  31. package/dist/message_channel/sorted_array_base.js.map +0 -1
  32. package/src/message_channel/sorted_array_base.ts +0 -306
@@ -1,50 +0,0 @@
1
- type SortedArrayInterface<T> = Omit<Array<T>, "reverse" | "sort">;
2
- /**
3
- * Base class that implements a sorted array interface.
4
- * Automatically maintains sort order after any mutating operation.
5
- */
6
- export declare abstract class SortedArrayBase<T> implements SortedArrayInterface<T> {
7
- protected readonly items: Array<T>;
8
- private previousLength;
9
- constructor();
10
- [n: number]: T;
11
- get length(): number;
12
- private updateIndexedProperties;
13
- toString(): string;
14
- toLocaleString(): string;
15
- pop(): T | undefined;
16
- push(...items: T[]): number;
17
- concat(...items: ConcatArray<T>[]): T[];
18
- concat(...items: (T | ConcatArray<T>)[]): T[];
19
- join(separator?: string): string;
20
- shift(): T | undefined;
21
- slice(start?: number, end?: number): T[];
22
- splice(start: number, deleteCount?: number, ...items: T[]): T[];
23
- unshift(...items: T[]): number;
24
- indexOf(searchElement: T, fromIndex?: number): number;
25
- lastIndexOf(searchElement: T, fromIndex?: number): number;
26
- every<S extends T>(predicate: (value: T, index: number, array: T[]) => value is S, thisArg?: any): this is S[];
27
- some(predicate: (value: T, index: number, array: T[]) => unknown, thisArg?: any): boolean;
28
- forEach(callbackfn: (value: T, index: number, array: T[]) => void, thisArg?: any): void;
29
- map<U>(callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any): U[];
30
- filter<S extends T>(predicate: (value: T, index: number, array: T[]) => value is S, thisArg?: any): S[];
31
- reduce<U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue?: U): U;
32
- reduceRight<U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue?: U): U;
33
- find<S extends T>(predicate: (this: void, value: T, index: number, obj: T[]) => value is S, thisArg?: any): S | undefined;
34
- findIndex(predicate: (value: T, index: number, obj: T[]) => unknown, thisArg?: any): number;
35
- fill(value: T, start?: number, end?: number): T[];
36
- copyWithin(target: number, start: number, end?: number): T[];
37
- entries(): ArrayIterator<[number, T]>;
38
- keys(): ArrayIterator<number>;
39
- values(): ArrayIterator<T>;
40
- includes(searchElement: T, fromIndex?: number): boolean;
41
- flatMap<U, This = undefined>(callback: (this: This, value: T, index: number, array: T[]) => U | readonly U[], thisArg?: This | undefined): U[];
42
- flat<A, D extends number = 1>(this: A, depth?: D | undefined): FlatArray<A, D>[];
43
- at(index: number): T | undefined;
44
- [Symbol.iterator](): ArrayIterator<T>;
45
- readonly [Symbol.unscopables]: any;
46
- protected abstract getCompareFn(): (a: T, b: T) => number;
47
- protected sort(): void;
48
- protected sortArray(array: T[]): T[];
49
- }
50
- export {};
@@ -1,199 +0,0 @@
1
- /**
2
- * Base class that implements a sorted array interface.
3
- * Automatically maintains sort order after any mutating operation.
4
- */
5
- export class SortedArrayBase {
6
- items;
7
- previousLength = 0;
8
- constructor() {
9
- this.items = [];
10
- this.updateIndexedProperties();
11
- }
12
- get length() {
13
- return this.items.length;
14
- }
15
- updateIndexedProperties() {
16
- // Remove old properties
17
- for (let i = this.items.length; i < this.previousLength; i++) {
18
- delete this[i];
19
- }
20
- // Add/update current properties
21
- for (let i = 0; i < this.items.length; i++) {
22
- this[i] = this.items[i];
23
- }
24
- this.previousLength = this.items.length;
25
- }
26
- toString() {
27
- return this.items.toString();
28
- }
29
- toLocaleString() {
30
- return this.items.toLocaleString();
31
- }
32
- pop() {
33
- const result = this.items.pop();
34
- this.updateIndexedProperties();
35
- return result;
36
- }
37
- push(...items) {
38
- // Filter out duplicates both from existing items and within the new items
39
- const uniqueItems = [];
40
- for (const item of items) {
41
- if (!this.items.includes(item) && !uniqueItems.includes(item)) {
42
- uniqueItems.push(item);
43
- }
44
- }
45
- this.items.push(...uniqueItems);
46
- this.sort();
47
- this.updateIndexedProperties();
48
- return this.items.length;
49
- }
50
- concat(...items) {
51
- const result = this.items.concat(...items);
52
- return this.sortArray(result);
53
- }
54
- join(separator) {
55
- return this.items.join(separator);
56
- }
57
- shift() {
58
- const result = this.items.shift();
59
- this.updateIndexedProperties();
60
- return result;
61
- }
62
- slice(start, end) {
63
- return this.items.slice(start, end);
64
- }
65
- splice(start, deleteCount, ...items) {
66
- // First perform the deletion
67
- const result = this.items.splice(start, deleteCount || 0);
68
- // Then add unique items
69
- const uniqueItems = [];
70
- for (const item of items) {
71
- if (!this.items.includes(item) && !uniqueItems.includes(item)) {
72
- uniqueItems.push(item);
73
- }
74
- }
75
- this.items.push(...uniqueItems);
76
- this.sort();
77
- this.updateIndexedProperties();
78
- return result;
79
- }
80
- unshift(...items) {
81
- // Filter out duplicates both from existing items and within the new items
82
- const uniqueItems = [];
83
- for (const item of items) {
84
- if (!this.items.includes(item) && !uniqueItems.includes(item)) {
85
- uniqueItems.push(item);
86
- }
87
- }
88
- this.items.unshift(...uniqueItems);
89
- this.sort();
90
- this.updateIndexedProperties();
91
- return this.items.length;
92
- }
93
- indexOf(searchElement, fromIndex) {
94
- if (fromIndex === undefined) {
95
- return this.items.indexOf(searchElement);
96
- }
97
- return this.items.indexOf(searchElement, fromIndex);
98
- }
99
- lastIndexOf(searchElement, fromIndex) {
100
- if (fromIndex === undefined) {
101
- return this.items.lastIndexOf(searchElement);
102
- }
103
- return this.items.lastIndexOf(searchElement, fromIndex);
104
- }
105
- every(predicate, thisArg) {
106
- return this.items.every(predicate, thisArg);
107
- }
108
- some(predicate, thisArg) {
109
- return this.items.some(predicate, thisArg);
110
- }
111
- forEach(callbackfn, thisArg) {
112
- this.items.forEach(callbackfn, thisArg);
113
- }
114
- map(callbackfn, thisArg) {
115
- return this.items.map(callbackfn, thisArg);
116
- }
117
- filter(predicate, thisArg) {
118
- return this.items.filter(predicate, thisArg);
119
- }
120
- reduce(callbackfn, initialValue) {
121
- if (arguments.length >= 2) {
122
- return this.items.reduce(callbackfn, initialValue);
123
- }
124
- else {
125
- return this.items.reduce(callbackfn);
126
- }
127
- }
128
- reduceRight(callbackfn, initialValue) {
129
- if (arguments.length >= 2) {
130
- return this.items.reduceRight(callbackfn, initialValue);
131
- }
132
- else {
133
- return this.items.reduceRight(callbackfn);
134
- }
135
- }
136
- find(predicate, thisArg) {
137
- return this.items.find(predicate, thisArg);
138
- }
139
- findIndex(predicate, thisArg) {
140
- return this.items.findIndex(predicate, thisArg);
141
- }
142
- fill(value, start, end) {
143
- // Perform the fill operation first
144
- this.items.fill(value, start, end);
145
- // Then remove duplicates by creating a unique set
146
- const uniqueItems = [...new Set(this.items)];
147
- this.items.length = 0;
148
- this.items.push(...uniqueItems);
149
- this.sort();
150
- this.updateIndexedProperties();
151
- return this.items;
152
- }
153
- copyWithin(target, start, end) {
154
- this.items.copyWithin(target, start, end);
155
- this.sort();
156
- this.updateIndexedProperties();
157
- return this.items;
158
- }
159
- entries() {
160
- return this.items.entries();
161
- }
162
- keys() {
163
- return this.items.keys();
164
- }
165
- values() {
166
- return this.items.values();
167
- }
168
- includes(searchElement, fromIndex) {
169
- return this.items.includes(searchElement, fromIndex);
170
- }
171
- flatMap(callback, thisArg) {
172
- return this.items.flatMap(callback, thisArg);
173
- }
174
- flat(depth) {
175
- return this.items.flat(depth);
176
- }
177
- at(index) {
178
- return this.items.at(index);
179
- }
180
- [Symbol.iterator]() {
181
- return this.items[Symbol.iterator]();
182
- }
183
- [Symbol.unscopables] = {
184
- copyWithin: true,
185
- entries: true,
186
- fill: true,
187
- find: true,
188
- findIndex: true,
189
- keys: true,
190
- values: true
191
- };
192
- sort() {
193
- this.items.sort(this.getCompareFn());
194
- }
195
- sortArray(array) {
196
- return array.sort(this.getCompareFn());
197
- }
198
- }
199
- //# sourceMappingURL=sorted_array_base.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"sorted_array_base.js","sourceRoot":"","sources":["../../src/message_channel/sorted_array_base.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,OAAgB,eAAe;IAChB,KAAK,CAAW;IAC3B,cAAc,GAAG,CAAC,CAAC;IAE3B;QACE,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;QAChB,IAAI,CAAC,uBAAuB,EAAE,CAAC;IACjC,CAAC;IAID,IAAW,MAAM;QACf,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;IAC3B,CAAC;IAEO,uBAAuB;QAC7B,wBAAwB;QACxB,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,GAAG,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CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC/C,CAAC;IAEM,IAAI,CAET,KAAqB;QAErB,OAAS,IAAY,CAAC,KAAa,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAClD,CAAC;IAEM,EAAE,CAAC,KAAa;QACrB,OAAO,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC;IAC9B,CAAC;IAEM,CAAC,MAAM,CAAC,QAAQ,CAAC;QACtB,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;IACvC,CAAC;IAEe,CAAC,MAAM,CAAC,WAAW,CAAC,GAAQ;QAC1C,UAAU,EAAE,IAAI;QAChB,OAAO,EAAE,IAAI;QACb,IAAI,EAAE,IAAI;QACV,IAAI,EAAE,IAAI;QACV,SAAS,EAAE,IAAI;QACf,IAAI,EAAE,IAAI;QACV,MAAM,EAAE,IAAI;KACb,CAAC;IAIQ,IAAI;QACZ,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC,CAAC;IACvC,CAAC;IAES,SAAS,CAAC,KAAU;QAC5B,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC,CAAC;IACzC,CAAC;CACF"}
@@ -1,306 +0,0 @@
1
- type SortedArrayInterface<T> = Omit<Array<T>, "reverse" | "sort">;
2
-
3
- /**
4
- * Base class that implements a sorted array interface.
5
- * Automatically maintains sort order after any mutating operation.
6
- */
7
- export abstract class SortedArrayBase<T> implements SortedArrayInterface<T> {
8
- protected readonly items: Array<T>;
9
- private previousLength = 0;
10
-
11
- public constructor() {
12
- this.items = [];
13
- this.updateIndexedProperties();
14
- }
15
-
16
- [n: number]: T;
17
-
18
- public get length(): number {
19
- return this.items.length;
20
- }
21
-
22
- private updateIndexedProperties(): void {
23
- // Remove old properties
24
- for (let i = this.items.length; i < this.previousLength; i++) {
25
- delete (this as any)[i];
26
- }
27
-
28
- // Add/update current properties
29
- for (let i = 0; i < this.items.length; i++) {
30
- (this as any)[i] = this.items[i];
31
- }
32
-
33
- this.previousLength = this.items.length;
34
- }
35
-
36
- public toString(): string {
37
- return this.items.toString();
38
- }
39
-
40
- public toLocaleString(): string {
41
- return this.items.toLocaleString();
42
- }
43
-
44
- public pop(): T | undefined {
45
- const result = this.items.pop();
46
- this.updateIndexedProperties();
47
- return result;
48
- }
49
-
50
- public push(...items: T[]): number {
51
- // Filter out duplicates both from existing items and within the new items
52
- const uniqueItems: T[] = [];
53
- for (const item of items) {
54
- if (!this.items.includes(item) && !uniqueItems.includes(item)) {
55
- uniqueItems.push(item);
56
- }
57
- }
58
- this.items.push(...uniqueItems);
59
- this.sort();
60
- this.updateIndexedProperties();
61
- return this.items.length;
62
- }
63
-
64
- public concat(...items: ConcatArray<T>[]): T[];
65
- public concat(...items: (T | ConcatArray<T>)[]): T[];
66
- public concat(...items: (T | ConcatArray<T>)[]): T[] {
67
- const result = this.items.concat(...items);
68
- return this.sortArray(result);
69
- }
70
-
71
- public join(separator?: string): string {
72
- return this.items.join(separator);
73
- }
74
-
75
- public shift(): T | undefined {
76
- const result = this.items.shift();
77
- this.updateIndexedProperties();
78
- return result;
79
- }
80
-
81
- public slice(start?: number, end?: number): T[] {
82
- return this.items.slice(start, end);
83
- }
84
-
85
- public splice(start: number, deleteCount?: number, ...items: T[]): T[] {
86
- // First perform the deletion
87
- const result = this.items.splice(start, deleteCount || 0);
88
-
89
- // Then add unique items
90
- const uniqueItems: T[] = [];
91
- for (const item of items) {
92
- if (!this.items.includes(item) && !uniqueItems.includes(item)) {
93
- uniqueItems.push(item);
94
- }
95
- }
96
- this.items.push(...uniqueItems);
97
- this.sort();
98
- this.updateIndexedProperties();
99
- return result;
100
- }
101
-
102
- public unshift(...items: T[]): number {
103
- // Filter out duplicates both from existing items and within the new items
104
- const uniqueItems: T[] = [];
105
- for (const item of items) {
106
- if (!this.items.includes(item) && !uniqueItems.includes(item)) {
107
- uniqueItems.push(item);
108
- }
109
- }
110
- this.items.unshift(...uniqueItems);
111
- this.sort();
112
- this.updateIndexedProperties();
113
- return this.items.length;
114
- }
115
-
116
- public indexOf(searchElement: T, fromIndex?: number): number {
117
- if (fromIndex === undefined) {
118
- return this.items.indexOf(searchElement);
119
- }
120
- return this.items.indexOf(searchElement, fromIndex);
121
- }
122
-
123
- public lastIndexOf(searchElement: T, fromIndex?: number): number {
124
- if (fromIndex === undefined) {
125
- return this.items.lastIndexOf(searchElement);
126
- }
127
- return this.items.lastIndexOf(searchElement, fromIndex);
128
- }
129
-
130
- public every<S extends T>(
131
- predicate: (value: T, index: number, array: T[]) => value is S,
132
- thisArg?: any
133
- ): this is S[];
134
- public every(
135
- predicate: (value: T, index: number, array: T[]) => unknown,
136
- thisArg?: any
137
- ): boolean {
138
- return this.items.every(predicate, thisArg);
139
- }
140
-
141
- public some(
142
- predicate: (value: T, index: number, array: T[]) => unknown,
143
- thisArg?: any
144
- ): boolean {
145
- return this.items.some(predicate, thisArg);
146
- }
147
-
148
- public forEach(
149
- callbackfn: (value: T, index: number, array: T[]) => void,
150
- thisArg?: any
151
- ): void {
152
- this.items.forEach(callbackfn, thisArg);
153
- }
154
-
155
- public map<U>(
156
- callbackfn: (value: T, index: number, array: T[]) => U,
157
- thisArg?: any
158
- ): U[] {
159
- return this.items.map(callbackfn, thisArg);
160
- }
161
-
162
- public filter<S extends T>(
163
- predicate: (value: T, index: number, array: T[]) => value is S,
164
- thisArg?: any
165
- ): S[];
166
- public filter(
167
- predicate: (value: T, index: number, array: T[]) => unknown,
168
- thisArg?: any
169
- ): T[] {
170
- return this.items.filter(predicate, thisArg);
171
- }
172
-
173
- public reduce<U>(
174
- callbackfn: (
175
- previousValue: U,
176
- currentValue: T,
177
- currentIndex: number,
178
- array: T[]
179
- ) => U,
180
- initialValue?: U
181
- ): U {
182
- if (arguments.length >= 2) {
183
- return this.items.reduce(callbackfn, initialValue!);
184
- } else {
185
- return this.items.reduce(callbackfn as any) as unknown as U;
186
- }
187
- }
188
-
189
- public reduceRight<U>(
190
- callbackfn: (
191
- previousValue: U,
192
- currentValue: T,
193
- currentIndex: number,
194
- array: T[]
195
- ) => U,
196
- initialValue?: U
197
- ): U {
198
- if (arguments.length >= 2) {
199
- return this.items.reduceRight(callbackfn, initialValue!);
200
- } else {
201
- return this.items.reduceRight(callbackfn as any) as unknown as U;
202
- }
203
- }
204
-
205
- public find<S extends T>(
206
- predicate: (this: void, value: T, index: number, obj: T[]) => value is S,
207
- thisArg?: any
208
- ): S | undefined;
209
- public find(
210
- predicate: (value: T, index: number, obj: T[]) => unknown,
211
- thisArg?: any
212
- ): T | undefined {
213
- return this.items.find(predicate, thisArg);
214
- }
215
-
216
- public findIndex(
217
- predicate: (value: T, index: number, obj: T[]) => unknown,
218
- thisArg?: any
219
- ): number {
220
- return this.items.findIndex(predicate, thisArg);
221
- }
222
-
223
- public fill(value: T, start?: number, end?: number): T[] {
224
- // Perform the fill operation first
225
- this.items.fill(value, start, end);
226
-
227
- // Then remove duplicates by creating a unique set
228
- const uniqueItems = [...new Set(this.items)];
229
- this.items.length = 0;
230
- this.items.push(...uniqueItems);
231
-
232
- this.sort();
233
- this.updateIndexedProperties();
234
- return this.items;
235
- }
236
-
237
- public copyWithin(target: number, start: number, end?: number): T[] {
238
- this.items.copyWithin(target, start, end);
239
- this.sort();
240
- this.updateIndexedProperties();
241
- return this.items;
242
- }
243
-
244
- public entries(): ArrayIterator<[number, T]> {
245
- return this.items.entries();
246
- }
247
-
248
- public keys(): ArrayIterator<number> {
249
- return this.items.keys();
250
- }
251
-
252
- public values(): ArrayIterator<T> {
253
- return this.items.values();
254
- }
255
-
256
- public includes(searchElement: T, fromIndex?: number): boolean {
257
- return this.items.includes(searchElement, fromIndex);
258
- }
259
-
260
- public flatMap<U, This = undefined>(
261
- callback: (
262
- this: This,
263
- value: T,
264
- index: number,
265
- array: T[]
266
- ) => U | readonly U[],
267
- thisArg?: This | undefined
268
- ): U[] {
269
- return this.items.flatMap(callback, thisArg);
270
- }
271
-
272
- public flat<A, D extends number = 1>(
273
- this: A,
274
- depth?: D | undefined
275
- ): FlatArray<A, D>[] {
276
- return ((this as any).items as any).flat(depth);
277
- }
278
-
279
- public at(index: number): T | undefined {
280
- return this.items.at(index);
281
- }
282
-
283
- public [Symbol.iterator](): ArrayIterator<T> {
284
- return this.items[Symbol.iterator]();
285
- }
286
-
287
- public readonly [Symbol.unscopables]: any = {
288
- copyWithin: true,
289
- entries: true,
290
- fill: true,
291
- find: true,
292
- findIndex: true,
293
- keys: true,
294
- values: true
295
- };
296
-
297
- protected abstract getCompareFn(): (a: T, b: T) => number;
298
-
299
- protected sort(): void {
300
- this.items.sort(this.getCompareFn());
301
- }
302
-
303
- protected sortArray(array: T[]): T[] {
304
- return array.sort(this.getCompareFn());
305
- }
306
- }