@eleven-am/pondsocket 0.1.11 → 0.1.13
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/dist/client/channel.js +200 -0
- package/dist/client/index.d.ts +122 -0
- package/{pondClient/socket.js → dist/client/index.js} +30 -44
- package/dist/express/index.d.ts +36 -0
- package/dist/express/index.js +16 -0
- package/dist/index.d.ts +340 -0
- package/dist/index.js +4 -0
- package/dist/server/abstracts/abstractRequest.js +40 -0
- package/dist/server/abstracts/abstractRequest.test.js +41 -0
- package/dist/server/abstracts/abstractResponse.js +6 -0
- package/dist/server/abstracts/middleware.js +38 -0
- package/dist/server/abstracts/middleware.test.js +70 -0
- package/dist/server/channel/channelEngine.js +279 -0
- package/dist/server/channel/channelEngine.test.js +377 -0
- package/dist/server/channel/channelRequest.test.js +29 -0
- package/dist/server/channel/channelResponse.test.js +134 -0
- package/dist/server/channel/eventRequest.js +18 -0
- package/dist/server/channel/eventResponse.js +141 -0
- package/dist/server/endpoint/connectionResponse.js +50 -0
- package/dist/server/endpoint/endpoint.js +269 -0
- package/dist/server/endpoint/endpoint.test.js +406 -0
- package/dist/server/endpoint/endpointResponse.test.js +43 -0
- package/dist/server/pondChannel/joinRequest.js +29 -0
- package/dist/server/pondChannel/joinResponse.js +96 -0
- package/dist/server/pondChannel/pondChannel.js +161 -0
- package/dist/server/pondChannel/pondChannelResponse.test.js +108 -0
- package/dist/server/presence/presenceEngine.js +112 -0
- package/dist/server/presence/presenceEngine.test.js +104 -0
- package/dist/server/server/pondSocket.js +122 -0
- package/{pondSocket → dist/server/server}/server.test.js +7 -21
- package/{pondBase/baseClass.js → dist/server/utils/matchPattern.js} +33 -43
- package/{pondBase/baseClass.test.js → dist/server/utils/matchPattern.test.js} +16 -25
- package/dist/server/utils/subjectUtils.js +68 -0
- package/package.json +31 -12
- package/.eslintrc.js +0 -28
- package/base.d.ts +0 -1
- package/base.js +0 -17
- package/client.d.ts +0 -1
- package/client.js +0 -17
- package/index.d.ts +0 -1
- package/index.js +0 -17
- package/jest.config.js +0 -11
- package/pondBase/baseClass.d.ts +0 -55
- package/pondBase/enums.d.ts +0 -9
- package/pondBase/enums.js +0 -14
- package/pondBase/index.d.ts +0 -6
- package/pondBase/index.js +0 -22
- package/pondBase/pondBase.d.ts +0 -41
- package/pondBase/pondBase.js +0 -60
- package/pondBase/pondBase.test.js +0 -101
- package/pondBase/pubSub.d.ts +0 -82
- package/pondBase/pubSub.js +0 -158
- package/pondBase/pubSub.test.js +0 -332
- package/pondBase/simpleBase.d.ts +0 -126
- package/pondBase/simpleBase.js +0 -211
- package/pondBase/simpleBase.test.js +0 -153
- package/pondBase/types.d.ts +0 -2
- package/pondBase/types.js +0 -2
- package/pondClient/channel.d.ts +0 -77
- package/pondClient/channel.js +0 -167
- package/pondClient/index.d.ts +0 -2
- package/pondClient/index.js +0 -18
- package/pondClient/socket.d.ts +0 -41
- package/pondSocket/channel.d.ts +0 -129
- package/pondSocket/channel.js +0 -287
- package/pondSocket/channel.test.js +0 -377
- package/pondSocket/channelMiddleWare.d.ts +0 -28
- package/pondSocket/channelMiddleWare.js +0 -36
- package/pondSocket/endpoint.d.ts +0 -90
- package/pondSocket/endpoint.js +0 -320
- package/pondSocket/endpoint.test.js +0 -490
- package/pondSocket/enums.d.ts +0 -19
- package/pondSocket/enums.js +0 -25
- package/pondSocket/index.d.ts +0 -7
- package/pondSocket/index.js +0 -23
- package/pondSocket/pondChannel.d.ts +0 -79
- package/pondSocket/pondChannel.js +0 -211
- package/pondSocket/pondChannel.test.js +0 -430
- package/pondSocket/pondResponse.d.ts +0 -25
- package/pondSocket/pondResponse.js +0 -120
- package/pondSocket/pondSocket.d.ts +0 -47
- package/pondSocket/pondSocket.js +0 -94
- package/pondSocket/socketMiddleWare.d.ts +0 -6
- package/pondSocket/socketMiddleWare.js +0 -32
- package/pondSocket/types.d.ts +0 -74
- package/pondSocket/types.js +0 -2
- package/socket.d.ts +0 -1
- package/socket.js +0 -17
- package/tsconfig.eslint.json +0 -5
- package/tsconfig.json +0 -90
package/pondBase/simpleBase.d.ts
DELETED
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
export declare class PondDocument<T> {
|
|
2
|
-
constructor(id: string, removeDoc: () => void, updateDoc: (value: T) => PondDocument<T>, getDoc: () => T);
|
|
3
|
-
|
|
4
|
-
get id(): string;
|
|
5
|
-
|
|
6
|
-
get doc(): T;
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @desc Removes the document from the collection
|
|
10
|
-
*/
|
|
11
|
-
removeDoc(): T;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* @desc Updates the document in the collection
|
|
15
|
-
* @param value - the new value of the document
|
|
16
|
-
*/
|
|
17
|
-
updateDoc(value: T): this;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
declare type UpdateCallback<T> = (data: {
|
|
21
|
-
oldValue: T | null; currentValue: T | null;
|
|
22
|
-
}) => void;
|
|
23
|
-
|
|
24
|
-
export declare class SimpleBase<T> {
|
|
25
|
-
constructor(callbacks?: UpdateCallback<T>);
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* @desc Get the number of documents
|
|
29
|
-
*/
|
|
30
|
-
get size(): number;
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* @desc Get all the documents in the database
|
|
34
|
-
*/
|
|
35
|
-
get all(): PondDocument<T>[];
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* @desc Gets all the keys of the database
|
|
39
|
-
*/
|
|
40
|
-
get keys(): string[];
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* @desc Gets all the values of the database
|
|
44
|
-
*/
|
|
45
|
-
get values(): T[];
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* @desc Makes the database iterable
|
|
49
|
-
*/
|
|
50
|
-
[Symbol.iterator](): IterableIterator<PondDocument<T>>;
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* @desc Create a generator for the pond
|
|
54
|
-
*/
|
|
55
|
-
generator(): Generator<PondDocument<T>>;
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* @desc Get a document by key
|
|
59
|
-
* @param key - The key of the document
|
|
60
|
-
*/
|
|
61
|
-
get(key: string): PondDocument<T> | null;
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* @desc getOrCreate a document in the database
|
|
65
|
-
* @param key - The key of the document
|
|
66
|
-
* @param creator - The function to create the document
|
|
67
|
-
*/
|
|
68
|
-
getOrCreate(key: string, creator: (doc: Readonly<PondDocument<T>>) => T): PondDocument<T>;
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* @desc Upsert a document in the database
|
|
72
|
-
* @param key - The key of the document
|
|
73
|
-
* @param value - The value of the document
|
|
74
|
-
*/
|
|
75
|
-
upsert(key: string, value: T): PondDocument<T>;
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* @desc checks if a document exists
|
|
79
|
-
* @param key - The key of the document
|
|
80
|
-
*/
|
|
81
|
-
has(key: string): boolean;
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* @desc Set a document to the database
|
|
85
|
-
* @param key - The key of the document
|
|
86
|
-
* @param value - The value of the document
|
|
87
|
-
*/
|
|
88
|
-
set(key: string, value: T): PondDocument<T>;
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* @desc Find a document by a query function
|
|
92
|
-
* @param query - The query function
|
|
93
|
-
*/
|
|
94
|
-
find(query: (doc: T, id: string) => boolean): PondDocument<T> | null;
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* @desc Map the pond to a new array
|
|
98
|
-
* @param mapper - The mapper function
|
|
99
|
-
*/
|
|
100
|
-
map<U>(mapper: (doc: T, id: string) => U): U[];
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* @desc Filters the pond using a query function
|
|
104
|
-
* @param query - The query function
|
|
105
|
-
*/
|
|
106
|
-
filter(query: (doc: T, id: string) => boolean): PondDocument<T>[];
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* @desc Reduce the pond to a single value
|
|
110
|
-
* @param reducer - The reducer function
|
|
111
|
-
* @param initialValue - The initial value of the reducer
|
|
112
|
-
*/
|
|
113
|
-
reduce<U>(reducer: (accumulator: U, currentValue: T) => U, initialValue: U): U;
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* @desc Generate a generic pond document
|
|
117
|
-
* @param id - The id of the document
|
|
118
|
-
*/
|
|
119
|
-
createGenericDocument(id?: string): PondDocument<T>;
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* @desc Gets the raw database
|
|
123
|
-
* @protected
|
|
124
|
-
*/
|
|
125
|
-
protected _getDB(): Record<string, T>;
|
|
126
|
-
}
|
package/pondBase/simpleBase.js
DELETED
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SimpleBase = exports.PondDocument = void 0;
|
|
4
|
-
class PondDocument {
|
|
5
|
-
constructor(id, removeDoc, updateDoc, getDoc) {
|
|
6
|
-
this._removeDoc = removeDoc;
|
|
7
|
-
this._updateDoc = updateDoc;
|
|
8
|
-
this._getDoc = getDoc;
|
|
9
|
-
this._id = id;
|
|
10
|
-
}
|
|
11
|
-
get id() {
|
|
12
|
-
return this._id;
|
|
13
|
-
}
|
|
14
|
-
get doc() {
|
|
15
|
-
return this._getDoc();
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* @desc Removes the document from the collection
|
|
19
|
-
*/
|
|
20
|
-
removeDoc() {
|
|
21
|
-
const doc = this._getDoc();
|
|
22
|
-
this._removeDoc();
|
|
23
|
-
return doc;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* @desc Updates the document in the collection
|
|
27
|
-
* @param value - the new value of the document
|
|
28
|
-
*/
|
|
29
|
-
updateDoc(value) {
|
|
30
|
-
this._updateDoc(value);
|
|
31
|
-
return this;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
exports.PondDocument = PondDocument;
|
|
35
|
-
class SimpleBase {
|
|
36
|
-
constructor(callbacks) {
|
|
37
|
-
this._db = {};
|
|
38
|
-
this._update = callbacks || null;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* @desc Get the number of documents
|
|
42
|
-
*/
|
|
43
|
-
get size() {
|
|
44
|
-
return Object.keys(this._db).length;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* @desc Get all the documents in the database
|
|
48
|
-
*/
|
|
49
|
-
get all() {
|
|
50
|
-
return Object.keys(this._db).map(this._createPondDocument.bind(this));
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* @desc Makes the database iterable
|
|
54
|
-
*/
|
|
55
|
-
[Symbol.iterator]() {
|
|
56
|
-
return this.all[Symbol.iterator]();
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* @desc Create a generator for the pond
|
|
60
|
-
*/
|
|
61
|
-
*generator() {
|
|
62
|
-
for (const key in this._db) {
|
|
63
|
-
yield this._createPondDocument(key);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* @desc Get a document by key
|
|
68
|
-
* @param key - The key of the document
|
|
69
|
-
*/
|
|
70
|
-
get(key) {
|
|
71
|
-
const doc = this._db[key];
|
|
72
|
-
if (doc)
|
|
73
|
-
return this._createPondDocument(key);
|
|
74
|
-
return null;
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* @desc getOrCreate a document in the database
|
|
78
|
-
* @param key - The key of the document
|
|
79
|
-
* @param creator - The function to create the document
|
|
80
|
-
*/
|
|
81
|
-
getOrCreate(key, creator) {
|
|
82
|
-
const doc = this.get(key);
|
|
83
|
-
if (doc)
|
|
84
|
-
return doc;
|
|
85
|
-
return this.set(key, creator(this._createPondDocument(key)));
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* @desc Upsert a document in the database
|
|
89
|
-
* @param key - The key of the document
|
|
90
|
-
* @param value - The value of the document
|
|
91
|
-
*/
|
|
92
|
-
upsert(key, value) {
|
|
93
|
-
const doc = this.get(key);
|
|
94
|
-
if (doc)
|
|
95
|
-
return doc.updateDoc(value);
|
|
96
|
-
return this.set(key, value);
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* @desc checks if a document exists
|
|
100
|
-
* @param key - The key of the document
|
|
101
|
-
*/
|
|
102
|
-
has(key) {
|
|
103
|
-
return this._db[key] !== undefined;
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* @desc Set a document to the database
|
|
107
|
-
* @param key - The key of the document
|
|
108
|
-
* @param value - The value of the document
|
|
109
|
-
*/
|
|
110
|
-
set(key, value) {
|
|
111
|
-
var _a;
|
|
112
|
-
const oldValue = this._db[key] || null;
|
|
113
|
-
this._db[key] = value;
|
|
114
|
-
(_a = this._update) === null || _a === void 0 ? void 0 : _a.call(this, { oldValue, currentValue: value });
|
|
115
|
-
return this._createPondDocument(key);
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* @desc Find a document by a query function
|
|
119
|
-
* @param query - The query function
|
|
120
|
-
*/
|
|
121
|
-
find(query) {
|
|
122
|
-
for (const key in this._db) {
|
|
123
|
-
const doc = this._db[key];
|
|
124
|
-
if (query(doc, key))
|
|
125
|
-
return this._createPondDocument(key);
|
|
126
|
-
}
|
|
127
|
-
return null;
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* @desc Map the pond to a new array
|
|
131
|
-
* @param mapper - The mapper function
|
|
132
|
-
*/
|
|
133
|
-
map(mapper) {
|
|
134
|
-
return Object.keys(this._db).map(key => mapper(this._db[key], key));
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* @desc Filters the pond using a query function
|
|
138
|
-
* @param query - The query function
|
|
139
|
-
*/
|
|
140
|
-
filter(query) {
|
|
141
|
-
return Object.keys(this._db)
|
|
142
|
-
.filter(key => query(this._db[key], key))
|
|
143
|
-
.map(this._createPondDocument.bind(this));
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* @desc Reduce the pond to a single value
|
|
147
|
-
* @param reducer - The reducer function
|
|
148
|
-
* @param initialValue - The initial value of the reducer
|
|
149
|
-
*/
|
|
150
|
-
reduce(reducer, initialValue) {
|
|
151
|
-
return Object.values(this._db).reduce(reducer, initialValue);
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* @desc Gets all the keys of the database
|
|
155
|
-
*/
|
|
156
|
-
get keys() {
|
|
157
|
-
return Object.keys(this._db);
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* @desc Gets all the values of the database
|
|
161
|
-
*/
|
|
162
|
-
get values() {
|
|
163
|
-
return Object.values(this._db);
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* @desc Generate a generic pond document
|
|
167
|
-
* @param id - The id of the document
|
|
168
|
-
*/
|
|
169
|
-
createGenericDocument(id) {
|
|
170
|
-
const idValue = id || Math.random().toString(36).substr(2, 9);
|
|
171
|
-
return this._createPondDocument(idValue);
|
|
172
|
-
}
|
|
173
|
-
/**
|
|
174
|
-
* @desc Delete a document by key
|
|
175
|
-
*/
|
|
176
|
-
_delete(key) {
|
|
177
|
-
var _a;
|
|
178
|
-
const oldValue = this._db[key];
|
|
179
|
-
delete this._db[key];
|
|
180
|
-
(_a = this._update) === null || _a === void 0 ? void 0 : _a.call(this, { oldValue, currentValue: null });
|
|
181
|
-
}
|
|
182
|
-
/**
|
|
183
|
-
* @desc Retrieve a document from the database
|
|
184
|
-
* @param key - The key of the document
|
|
185
|
-
*/
|
|
186
|
-
_getDocument(key) {
|
|
187
|
-
const data = this._db[key];
|
|
188
|
-
if (!data)
|
|
189
|
-
return null;
|
|
190
|
-
return data;
|
|
191
|
-
}
|
|
192
|
-
/**
|
|
193
|
-
* @desc Create a pond document
|
|
194
|
-
* @param id - The id of the document
|
|
195
|
-
* @private
|
|
196
|
-
*/
|
|
197
|
-
_createPondDocument(id) {
|
|
198
|
-
const removeDoc = this._delete.bind(this, id);
|
|
199
|
-
const updateDoc = this.set.bind(this, id);
|
|
200
|
-
const getDoc = this._getDocument.bind(this, id);
|
|
201
|
-
return new PondDocument(id, removeDoc, updateDoc, getDoc);
|
|
202
|
-
}
|
|
203
|
-
/**
|
|
204
|
-
* @desc Gets the raw database
|
|
205
|
-
* @protected
|
|
206
|
-
*/
|
|
207
|
-
_getDB() {
|
|
208
|
-
return this._db;
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
exports.SimpleBase = SimpleBase;
|
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const simpleBase_1 = require("./simpleBase");
|
|
4
|
-
describe('SimpleBase', () => {
|
|
5
|
-
it('should ba instantiated', () => {
|
|
6
|
-
const base = new simpleBase_1.SimpleBase();
|
|
7
|
-
expect(base).toBeTruthy();
|
|
8
|
-
});
|
|
9
|
-
it('should set a value', () => {
|
|
10
|
-
const base = new simpleBase_1.SimpleBase();
|
|
11
|
-
base.set('test', { name: 'test' });
|
|
12
|
-
expect(base.size).toBe(1);
|
|
13
|
-
});
|
|
14
|
-
it('should get a value', () => {
|
|
15
|
-
var _a;
|
|
16
|
-
const base = new simpleBase_1.SimpleBase();
|
|
17
|
-
base.set('test', { name: 'test' });
|
|
18
|
-
expect((_a = base.get('test')) === null || _a === void 0 ? void 0 : _a.doc).toStrictEqual({ name: 'test' });
|
|
19
|
-
});
|
|
20
|
-
it('should upsert a value', () => {
|
|
21
|
-
var _a, _b;
|
|
22
|
-
const base = new simpleBase_1.SimpleBase();
|
|
23
|
-
expect((_a = base.get('test')) === null || _a === void 0 ? void 0 : _a.doc).toBeUndefined();
|
|
24
|
-
expect(base.size).toBe(0);
|
|
25
|
-
base.getOrCreate('test', () => ({ name: 'test' }));
|
|
26
|
-
expect(base.size).toBe(1);
|
|
27
|
-
expect((_b = base.get('test')) === null || _b === void 0 ? void 0 : _b.doc).toStrictEqual({ name: 'test' });
|
|
28
|
-
});
|
|
29
|
-
it('should tell if a document exists', () => {
|
|
30
|
-
const base = new simpleBase_1.SimpleBase();
|
|
31
|
-
expect(base.has('test')).toBe(false);
|
|
32
|
-
base.set('test', { name: 'test' });
|
|
33
|
-
expect(base.has('test')).toBe(true);
|
|
34
|
-
});
|
|
35
|
-
it('should return an array of filtered documents', () => {
|
|
36
|
-
const base = new simpleBase_1.SimpleBase();
|
|
37
|
-
base.set('test', { name: 'test' });
|
|
38
|
-
base.set('test2', { name: 'test2' });
|
|
39
|
-
base.set('test3', { name: 'test3' });
|
|
40
|
-
expect(base.filter(doc => doc.name === 'test').map(doc => doc.doc.name)).toEqual(['test']);
|
|
41
|
-
});
|
|
42
|
-
it('should return an array of mapped documents', () => {
|
|
43
|
-
const base = new simpleBase_1.SimpleBase();
|
|
44
|
-
base.set('test', { name: 'test' });
|
|
45
|
-
base.set('test2', { name: 'test2' });
|
|
46
|
-
base.set('test3', { name: 'test3' });
|
|
47
|
-
expect(base.map(doc => doc.name)).toEqual(['test', 'test2', 'test3']);
|
|
48
|
-
});
|
|
49
|
-
it('should return an empty array of documents', () => {
|
|
50
|
-
const base = new simpleBase_1.SimpleBase();
|
|
51
|
-
expect(base.map(doc => doc.name)).toEqual([]);
|
|
52
|
-
expect(base.filter(doc => doc.name === 'test').map(doc => doc.doc.name)).toEqual([]);
|
|
53
|
-
});
|
|
54
|
-
it('should return a document by a query function', () => {
|
|
55
|
-
var _a;
|
|
56
|
-
const base = new simpleBase_1.SimpleBase();
|
|
57
|
-
base.set('test', { name: 'test' });
|
|
58
|
-
base.set('test2', { name: 'test2' });
|
|
59
|
-
base.set('test3', { name: 'test3' });
|
|
60
|
-
expect((_a = base.find(doc => doc.name === 'test2')) === null || _a === void 0 ? void 0 : _a.doc.name).toBe('test2');
|
|
61
|
-
});
|
|
62
|
-
it('should return null if no document is found by a query function', () => {
|
|
63
|
-
const base = new simpleBase_1.SimpleBase();
|
|
64
|
-
base.set('test', { name: 'test' });
|
|
65
|
-
base.set('test2', { name: 'test2' });
|
|
66
|
-
base.set('test3', { name: 'test3' });
|
|
67
|
-
expect(base.find(doc => doc.name === 'test4')).toBeNull();
|
|
68
|
-
});
|
|
69
|
-
it('should reduce the pond to a single value', () => {
|
|
70
|
-
const base = new simpleBase_1.SimpleBase();
|
|
71
|
-
base.set('test', { name: 'test' });
|
|
72
|
-
base.set('test2', { name: 'test2' });
|
|
73
|
-
base.set('test3', { name: 'test3' });
|
|
74
|
-
expect(base.reduce((acc, doc) => acc + doc.name, '')).toBe('testtest2test3');
|
|
75
|
-
});
|
|
76
|
-
it('should return the size of the pond', () => {
|
|
77
|
-
const base = new simpleBase_1.SimpleBase();
|
|
78
|
-
base.set('test', { name: 'test' });
|
|
79
|
-
base.set('test2', { name: 'test2' });
|
|
80
|
-
base.set('test3', { name: 'test3' });
|
|
81
|
-
expect(base.size).toBe(3);
|
|
82
|
-
});
|
|
83
|
-
it('should provide an empty document', () => {
|
|
84
|
-
const base = new simpleBase_1.SimpleBase();
|
|
85
|
-
const test = base.createGenericDocument();
|
|
86
|
-
expect(test).toBeInstanceOf(simpleBase_1.PondDocument);
|
|
87
|
-
expect(test.doc).toBeNull();
|
|
88
|
-
});
|
|
89
|
-
it('should provide a document with a value', () => {
|
|
90
|
-
const base = new simpleBase_1.SimpleBase();
|
|
91
|
-
const test = base.createGenericDocument('test');
|
|
92
|
-
expect(base.size).toBe(0);
|
|
93
|
-
expect(test).toBeInstanceOf(simpleBase_1.PondDocument);
|
|
94
|
-
expect(test.id).toBe('test');
|
|
95
|
-
});
|
|
96
|
-
it('should be iterable', () => {
|
|
97
|
-
const base = new simpleBase_1.SimpleBase();
|
|
98
|
-
base.set('test', { name: 'test' });
|
|
99
|
-
base.set('test2', { name: 'test2' });
|
|
100
|
-
base.set('test3', { name: 'test3' });
|
|
101
|
-
expect([...base].map(doc => doc.doc.name)).toEqual(['test', 'test2', 'test3']);
|
|
102
|
-
});
|
|
103
|
-
it('should be iterable with a for of loop', () => {
|
|
104
|
-
const base = new simpleBase_1.SimpleBase();
|
|
105
|
-
base.set('test', { name: 'test' });
|
|
106
|
-
base.set('test2', { name: 'test2' });
|
|
107
|
-
base.set('test3', { name: 'test3' });
|
|
108
|
-
const docs = [];
|
|
109
|
-
for (const doc of base) {
|
|
110
|
-
docs.push(doc.doc.name);
|
|
111
|
-
}
|
|
112
|
-
expect(docs).toEqual(['test', 'test2', 'test3']);
|
|
113
|
-
});
|
|
114
|
-
it('should be have a generator', () => {
|
|
115
|
-
const base = new simpleBase_1.SimpleBase();
|
|
116
|
-
base.set('test', { name: 'test' });
|
|
117
|
-
base.set('test2', { name: 'test2' });
|
|
118
|
-
base.set('test3', { name: 'test3' });
|
|
119
|
-
const docs = [];
|
|
120
|
-
for (const doc of base.generator()) {
|
|
121
|
-
docs.push(doc.doc.name);
|
|
122
|
-
}
|
|
123
|
-
expect(docs).toEqual(['test', 'test2', 'test3']);
|
|
124
|
-
});
|
|
125
|
-
});
|
|
126
|
-
describe('PondDocument', () => {
|
|
127
|
-
it('should be able to set a value', () => {
|
|
128
|
-
var _a;
|
|
129
|
-
const base = new simpleBase_1.SimpleBase();
|
|
130
|
-
const test = base.createGenericDocument('test');
|
|
131
|
-
test.updateDoc({ name: 'test' });
|
|
132
|
-
expect((_a = base.get('test')) === null || _a === void 0 ? void 0 : _a.doc).toStrictEqual({ name: 'test' });
|
|
133
|
-
});
|
|
134
|
-
it('should be able to get a value', () => {
|
|
135
|
-
const base = new simpleBase_1.SimpleBase();
|
|
136
|
-
const test = base.createGenericDocument('test');
|
|
137
|
-
test.updateDoc({ name: 'test' });
|
|
138
|
-
expect(test.doc).toStrictEqual({ name: 'test' });
|
|
139
|
-
});
|
|
140
|
-
it('should be able to delete a value', () => {
|
|
141
|
-
const base = new simpleBase_1.SimpleBase();
|
|
142
|
-
const test = base.createGenericDocument('test');
|
|
143
|
-
test.updateDoc({ name: 'test' });
|
|
144
|
-
expect(base.size).toBe(1);
|
|
145
|
-
test.removeDoc();
|
|
146
|
-
expect(base.size).toBe(0);
|
|
147
|
-
});
|
|
148
|
-
it('should be able to get the id', () => {
|
|
149
|
-
const base = new simpleBase_1.SimpleBase();
|
|
150
|
-
const test = base.createGenericDocument('test');
|
|
151
|
-
expect(test.id).toBe('test');
|
|
152
|
-
});
|
|
153
|
-
});
|
package/pondBase/types.d.ts
DELETED
package/pondBase/types.js
DELETED
package/pondClient/channel.d.ts
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import {ClientMessage, PondAssigns, PondMessage, PondPresence, ServerMessage} from "../pondSocket";
|
|
2
|
-
import {Broadcast, Subscription} from "../pondBase";
|
|
3
|
-
|
|
4
|
-
export declare type ChannelParams = PondAssigns;
|
|
5
|
-
|
|
6
|
-
export declare class Channel {
|
|
7
|
-
|
|
8
|
-
constructor(name: string, receiver: Broadcast<ServerMessage, void>, broadcaster: Broadcast<ClientMessage, void>, params?: ChannelParams);
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* @desc Gets the current presence state of the channel.
|
|
12
|
-
*/
|
|
13
|
-
get presence(): PondPresence[];
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* @desc Connects to the channel.
|
|
17
|
-
*/
|
|
18
|
-
join(): void;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* @desc Disconnects from the channel.
|
|
22
|
-
*/
|
|
23
|
-
leave(): void;
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* @desc Monitors the channel for messages.
|
|
27
|
-
* @param event - The event to monitor.
|
|
28
|
-
* @param callback - The callback to call when a message is received.
|
|
29
|
-
*/
|
|
30
|
-
onMessage(event: string, callback: (message: PondMessage) => void): Subscription;
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* @desc Broadcasts a message to the channel, including yourself.
|
|
34
|
-
* @param event - The event to send.
|
|
35
|
-
* @param payload - The message to send.
|
|
36
|
-
*/
|
|
37
|
-
broadcast(event: string, payload: PondMessage): void;
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* @desc Broadcasts a message to every other client in the channel except yourself.
|
|
41
|
-
* @param event - The event to send.
|
|
42
|
-
* @param payload - The message to send.
|
|
43
|
-
*/
|
|
44
|
-
broadcastFrom(event: string, payload: PondMessage): void;
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* @desc Sends a message to specific clients in the channel.
|
|
48
|
-
* @param event - The event to send.
|
|
49
|
-
* @param payload - The message to send.
|
|
50
|
-
* @param recipient - The clients to send the message to.
|
|
51
|
-
*/
|
|
52
|
-
sendMessage(event: string, payload: PondMessage, recipient: string[]): void;
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* @desc Updates the presence state of the current client in the channel.
|
|
56
|
-
* @param presence - The presence state to update.
|
|
57
|
-
*/
|
|
58
|
-
updatePresence(presence: PondPresence): void;
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* @desc Detects when clients join the channel.
|
|
62
|
-
* @param callback - The callback to call when a client joins the channel.
|
|
63
|
-
*/
|
|
64
|
-
onJoin(callback: (presence: PondPresence) => void): Subscription;
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* @desc Detects when clients leave the channel.
|
|
68
|
-
* @param callback - The callback to call when a client leaves the channel.
|
|
69
|
-
*/
|
|
70
|
-
onLeave(callback: (presence: PondPresence) => void): Subscription;
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* @desc Monitors the connection state of the channel.
|
|
74
|
-
* @param callback - The callback to call when the connection state changes.
|
|
75
|
-
*/
|
|
76
|
-
onConnectionChange(callback: (connected: boolean) => void): Subscription;
|
|
77
|
-
}
|