@verdant-web/server 1.8.13 → 1.8.14-next.1
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/cjs/Baselines.d.ts +15 -15
- package/dist/cjs/Baselines.js +83 -83
- package/dist/cjs/ClientConnection.d.ts +18 -18
- package/dist/cjs/ClientConnection.js +105 -105
- package/dist/cjs/MessageSender.d.ts +5 -5
- package/dist/cjs/MessageSender.js +2 -2
- package/dist/cjs/OperationHistory.d.ts +36 -36
- package/dist/cjs/OperationHistory.js +120 -120
- package/dist/cjs/Presence.d.ts +15 -15
- package/dist/cjs/Presence.js +59 -59
- package/dist/cjs/Profiles.d.ts +10 -10
- package/dist/cjs/Profiles.js +19 -19
- package/dist/cjs/ReplicaKeepaliveTimers.d.ts +17 -17
- package/dist/cjs/ReplicaKeepaliveTimers.js +30 -30
- package/dist/cjs/Replicas.d.ts +24 -24
- package/dist/cjs/Replicas.js +137 -137
- package/dist/cjs/Server.d.ts +143 -143
- package/dist/cjs/Server.js +396 -396
- package/dist/cjs/ServerLibrary.d.ts +77 -77
- package/dist/cjs/ServerLibrary.js +487 -487
- package/dist/cjs/ServerStorage.d.ts +35 -0
- package/dist/cjs/ServerStorage.js +60 -0
- package/dist/cjs/ServerStorage.js.map +1 -0
- package/dist/cjs/TokenProvider.d.ts +16 -16
- package/dist/cjs/TokenProvider.js +26 -26
- package/dist/cjs/TokenVerifier.d.ts +16 -16
- package/dist/cjs/TokenVerifier.js +28 -28
- package/dist/cjs/files/FileMetadata.d.ts +28 -28
- package/dist/cjs/files/FileMetadata.js +46 -46
- package/dist/cjs/files/FileStorage.d.ts +35 -35
- package/dist/cjs/files/FileStorage.js +71 -71
- package/dist/cjs/index.d.ts +9 -9
- package/dist/cjs/index.js +11 -11
- package/dist/cjs/migrations/v0.d.ts +1 -0
- package/dist/cjs/migrations/v0.js +30 -0
- package/dist/cjs/migrations/v0.js.map +1 -0
- package/dist/cjs/migrations/v0.sql.d.ts +2 -2
- package/dist/cjs/migrations/v0.sql.js +3 -3
- package/dist/cjs/migrations/v1.d.ts +1 -0
- package/dist/cjs/migrations/v1.js +32 -0
- package/dist/cjs/migrations/v1.js.map +1 -0
- package/dist/cjs/migrations/v1.sql.d.ts +2 -2
- package/dist/cjs/migrations/v1.sql.js +3 -3
- package/dist/cjs/migrations/v2.d.ts +1 -0
- package/dist/cjs/migrations/v2.js +29 -0
- package/dist/cjs/migrations/v2.js.map +1 -0
- package/dist/cjs/migrations/v2.sql.d.ts +2 -2
- package/dist/cjs/migrations/v2.sql.js +4 -4
- package/dist/cjs/migrations/v3.d.ts +1 -0
- package/dist/cjs/migrations/v3.js +15 -0
- package/dist/cjs/migrations/v3.js.map +1 -0
- package/dist/cjs/migrations/v3.sql.d.ts +2 -2
- package/dist/cjs/migrations/v3.sql.js +4 -4
- package/dist/cjs/migrations/v4.d.ts +1 -0
- package/dist/cjs/migrations/v4.js +9 -0
- package/dist/cjs/migrations/v4.js.map +1 -0
- package/dist/cjs/migrations/v4.sql.d.ts +2 -2
- package/dist/cjs/migrations/v4.sql.js +4 -4
- package/dist/cjs/migrations/v5.d.ts +2 -0
- package/dist/cjs/migrations/v5.js +37 -0
- package/dist/cjs/migrations/v5.js.map +1 -0
- package/dist/cjs/migrations.d.ts +6 -2
- package/dist/cjs/migrations.js +62 -32
- package/dist/cjs/migrations.js.map +1 -1
- package/dist/cjs/migrations.test.d.ts +1 -0
- package/dist/cjs/migrations.test.js +121 -0
- package/dist/cjs/migrations.test.js.map +1 -0
- package/dist/cjs/types.d.ts +22 -22
- package/dist/cjs/types.js +2 -2
- package/dist/esm/Baselines.d.ts +15 -15
- package/dist/esm/Baselines.js +79 -79
- package/dist/esm/ClientConnection.d.ts +18 -18
- package/dist/esm/ClientConnection.js +101 -101
- package/dist/esm/MessageSender.d.ts +5 -5
- package/dist/esm/MessageSender.js +1 -1
- package/dist/esm/OperationHistory.d.ts +36 -36
- package/dist/esm/OperationHistory.js +116 -116
- package/dist/esm/Presence.d.ts +15 -15
- package/dist/esm/Presence.js +52 -52
- package/dist/esm/Profiles.d.ts +10 -10
- package/dist/esm/Profiles.js +15 -15
- package/dist/esm/ReplicaKeepaliveTimers.d.ts +17 -17
- package/dist/esm/ReplicaKeepaliveTimers.js +26 -26
- package/dist/esm/Replicas.d.ts +24 -24
- package/dist/esm/Replicas.js +133 -133
- package/dist/esm/Server.d.ts +143 -143
- package/dist/esm/Server.js +389 -389
- package/dist/esm/ServerLibrary.d.ts +77 -77
- package/dist/esm/ServerLibrary.js +483 -483
- package/dist/esm/ServerStorage.d.ts +44 -0
- package/dist/esm/ServerStorage.js +58 -0
- package/dist/esm/ServerStorage.js.map +1 -0
- package/dist/esm/TokenProvider.d.ts +16 -16
- package/dist/esm/TokenProvider.js +19 -19
- package/dist/esm/TokenVerifier.d.ts +16 -16
- package/dist/esm/TokenVerifier.js +21 -21
- package/dist/esm/files/FileMetadata.d.ts +28 -28
- package/dist/esm/files/FileMetadata.js +42 -42
- package/dist/esm/files/FileStorage.d.ts +35 -35
- package/dist/esm/files/FileStorage.js +44 -44
- package/dist/esm/index.d.ts +9 -9
- package/dist/esm/index.js +4 -4
- package/dist/esm/migrations/v0.d.ts +1 -0
- package/dist/esm/migrations/v0.js +27 -0
- package/dist/esm/migrations/v0.js.map +1 -0
- package/dist/esm/migrations/v0.sql.d.ts +2 -2
- package/dist/esm/migrations/v0.sql.js +1 -1
- package/dist/esm/migrations/v1.d.ts +1 -0
- package/dist/esm/migrations/v1.js +29 -0
- package/dist/esm/migrations/v1.js.map +1 -0
- package/dist/esm/migrations/v1.sql.d.ts +2 -2
- package/dist/esm/migrations/v1.sql.js +1 -1
- package/dist/esm/migrations/v2.d.ts +1 -0
- package/dist/esm/migrations/v2.js +26 -0
- package/dist/esm/migrations/v2.js.map +1 -0
- package/dist/esm/migrations/v2.sql.d.ts +2 -2
- package/dist/esm/migrations/v2.sql.js +2 -2
- package/dist/esm/migrations/v3.d.ts +1 -0
- package/dist/esm/migrations/v3.js +12 -0
- package/dist/esm/migrations/v3.js.map +1 -0
- package/dist/esm/migrations/v3.sql.d.ts +2 -2
- package/dist/esm/migrations/v3.sql.js +2 -2
- package/dist/esm/migrations/v4.d.ts +1 -0
- package/dist/esm/migrations/v4.js +6 -0
- package/dist/esm/migrations/v4.js.map +1 -0
- package/dist/esm/migrations/v4.sql.d.ts +2 -2
- package/dist/esm/migrations/v4.sql.js +2 -2
- package/dist/esm/migrations/v5.d.ts +2 -0
- package/dist/esm/migrations/v5.js +33 -0
- package/dist/esm/migrations/v5.js.map +1 -0
- package/dist/esm/migrations.d.ts +6 -2
- package/dist/esm/migrations.js +35 -25
- package/dist/esm/migrations.js.map +1 -1
- package/dist/esm/migrations.test.d.ts +1 -0
- package/dist/esm/migrations.test.js +116 -0
- package/dist/esm/migrations.test.js.map +1 -0
- package/dist/esm/types.d.ts +22 -22
- package/dist/esm/types.js +1 -1
- package/dist/tsconfig-cjs.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +6 -4
- package/src/__snapshots__/migrations.test.ts.snap +55 -0
- package/src/migrations/{v0.sql.ts → v0.ts} +1 -1
- package/src/migrations/{v1.sql.ts → v1.ts} +1 -1
- package/src/migrations/{v2.sql.ts → v2.ts} +1 -1
- package/src/migrations/{v3.sql.ts → v3.ts} +1 -1
- package/src/migrations/{v4.sql.ts → v4.ts} +1 -1
- package/src/migrations/v5.ts +49 -0
- package/src/migrations.test.ts +133 -0
- package/src/migrations.ts +28 -19
|
@@ -1,165 +1,165 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
-
var t = {};
|
|
4
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
-
t[p] = s[p];
|
|
6
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
-
t[p[i]] = s[p[i]];
|
|
10
|
-
}
|
|
11
|
-
return t;
|
|
12
|
-
};
|
|
13
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.OperationHistory = void 0;
|
|
15
|
-
class OperationHistory {
|
|
16
|
-
constructor(db) {
|
|
17
|
-
this.db = db;
|
|
18
|
-
this.hydratePatch = (_a) => {
|
|
19
|
-
var { libraryId: _, data } = _a, rest = __rest(_a, ["libraryId", "data"]);
|
|
20
|
-
return Object.assign(Object.assign({}, rest), { data: JSON.parse(data) });
|
|
21
|
-
};
|
|
22
|
-
this.getAllFor = (libraryId, oid) => {
|
|
23
|
-
return this.db
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.OperationHistory = void 0;
|
|
15
|
+
class OperationHistory {
|
|
16
|
+
constructor(db) {
|
|
17
|
+
this.db = db;
|
|
18
|
+
this.hydratePatch = (_a) => {
|
|
19
|
+
var { libraryId: _, data } = _a, rest = __rest(_a, ["libraryId", "data"]);
|
|
20
|
+
return Object.assign(Object.assign({}, rest), { data: JSON.parse(data) });
|
|
21
|
+
};
|
|
22
|
+
this.getAllFor = (libraryId, oid) => {
|
|
23
|
+
return this.db
|
|
24
24
|
.prepare(`
|
|
25
25
|
SELECT * FROM OperationHistory
|
|
26
26
|
WHERE libraryId = ? AND oid = ?
|
|
27
27
|
ORDER BY timestamp ASC
|
|
28
|
-
`)
|
|
29
|
-
.all(libraryId, oid)
|
|
30
|
-
.map(this.hydratePatch);
|
|
31
|
-
};
|
|
32
|
-
this.getEarliest = (libraryId, count) => {
|
|
33
|
-
return this.db
|
|
28
|
+
`)
|
|
29
|
+
.all(libraryId, oid)
|
|
30
|
+
.map(this.hydratePatch);
|
|
31
|
+
};
|
|
32
|
+
this.getEarliest = (libraryId, count) => {
|
|
33
|
+
return this.db
|
|
34
34
|
.prepare(`
|
|
35
35
|
SELECT * FROM OperationHistory
|
|
36
36
|
WHERE libraryId = ?
|
|
37
37
|
ORDER BY timestamp ASC
|
|
38
38
|
LIMIT ?
|
|
39
|
-
`)
|
|
40
|
-
.all(libraryId, count)
|
|
41
|
-
.map(this.hydratePatch);
|
|
42
|
-
};
|
|
43
|
-
this.getAfter = (libraryId, timestamp = null) => {
|
|
44
|
-
if (timestamp === null) {
|
|
45
|
-
return this.db
|
|
39
|
+
`)
|
|
40
|
+
.all(libraryId, count)
|
|
41
|
+
.map(this.hydratePatch);
|
|
42
|
+
};
|
|
43
|
+
this.getAfter = (libraryId, timestamp = null) => {
|
|
44
|
+
if (timestamp === null) {
|
|
45
|
+
return this.db
|
|
46
46
|
.prepare(`
|
|
47
47
|
SELECT * FROM OperationHistory
|
|
48
48
|
WHERE libraryId = ?
|
|
49
49
|
ORDER BY timestamp ASC
|
|
50
|
-
`)
|
|
51
|
-
.all(libraryId)
|
|
52
|
-
.map(this.hydratePatch);
|
|
53
|
-
}
|
|
54
|
-
return this.db
|
|
50
|
+
`)
|
|
51
|
+
.all(libraryId)
|
|
52
|
+
.map(this.hydratePatch);
|
|
53
|
+
}
|
|
54
|
+
return this.db
|
|
55
55
|
.prepare(`
|
|
56
56
|
SELECT * FROM OperationHistory
|
|
57
57
|
WHERE libraryId = ? AND timestamp > ?
|
|
58
58
|
ORDER BY timestamp ASC
|
|
59
|
-
`)
|
|
60
|
-
.all(libraryId, timestamp)
|
|
61
|
-
.map(this.hydratePatch);
|
|
62
|
-
};
|
|
63
|
-
/**
|
|
64
|
-
* Returns all operations before the given timestamp
|
|
65
|
-
* in ascending chronological order
|
|
66
|
-
*/
|
|
67
|
-
this.getBefore = (libraryId, before) => {
|
|
68
|
-
return this.db
|
|
59
|
+
`)
|
|
60
|
+
.all(libraryId, timestamp)
|
|
61
|
+
.map(this.hydratePatch);
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Returns all operations before the given timestamp
|
|
65
|
+
* in ascending chronological order
|
|
66
|
+
*/
|
|
67
|
+
this.getBefore = (libraryId, before) => {
|
|
68
|
+
return this.db
|
|
69
69
|
.prepare(`
|
|
70
70
|
SELECT * FROM OperationHistory
|
|
71
71
|
WHERE libraryId = ? AND timestamp < ?
|
|
72
72
|
ORDER BY timestamp ASC
|
|
73
|
-
`)
|
|
74
|
-
.all(libraryId, before)
|
|
75
|
-
.map(this.hydratePatch);
|
|
76
|
-
};
|
|
77
|
-
/**
|
|
78
|
-
* Returns all operations after a given server order. Useful
|
|
79
|
-
* for retrieving operations that were created after a client
|
|
80
|
-
* last synced.
|
|
81
|
-
*/
|
|
82
|
-
this.getFromServerOrder = (libraryId, serverOrder) => {
|
|
83
|
-
const result = this.db
|
|
73
|
+
`)
|
|
74
|
+
.all(libraryId, before)
|
|
75
|
+
.map(this.hydratePatch);
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Returns all operations after a given server order. Useful
|
|
79
|
+
* for retrieving operations that were created after a client
|
|
80
|
+
* last synced.
|
|
81
|
+
*/
|
|
82
|
+
this.getFromServerOrder = (libraryId, serverOrder) => {
|
|
83
|
+
const result = this.db
|
|
84
84
|
.prepare(`
|
|
85
85
|
SELECT * FROM OperationHistory
|
|
86
86
|
WHERE libraryId = ? AND serverOrder > ?
|
|
87
|
-
`)
|
|
88
|
-
.all(libraryId, serverOrder);
|
|
89
|
-
return (result || []).map(this.hydratePatch);
|
|
90
|
-
};
|
|
91
|
-
this.getLatestServerOrder = (libraryId) => {
|
|
92
|
-
const result = this.db
|
|
87
|
+
`)
|
|
88
|
+
.all(libraryId, serverOrder);
|
|
89
|
+
return (result || []).map(this.hydratePatch);
|
|
90
|
+
};
|
|
91
|
+
this.getLatestServerOrder = (libraryId) => {
|
|
92
|
+
const result = this.db
|
|
93
93
|
.prepare(`
|
|
94
94
|
SELECT MAX(serverOrder) AS serverOrder FROM OperationHistory
|
|
95
95
|
WHERE libraryId = ?
|
|
96
|
-
`)
|
|
97
|
-
.get(libraryId);
|
|
98
|
-
return (result === null || result === void 0 ? void 0 : result.serverOrder) || 0;
|
|
99
|
-
};
|
|
100
|
-
this.getCount = (libraryId) => {
|
|
101
|
-
const result = this.db
|
|
96
|
+
`)
|
|
97
|
+
.get(libraryId);
|
|
98
|
+
return (result === null || result === void 0 ? void 0 : result.serverOrder) || 0;
|
|
99
|
+
};
|
|
100
|
+
this.getCount = (libraryId) => {
|
|
101
|
+
const result = this.db
|
|
102
102
|
.prepare(`
|
|
103
103
|
SELECT COUNT(*) AS count FROM OperationHistory
|
|
104
104
|
WHERE libraryId = ?
|
|
105
|
-
`)
|
|
106
|
-
.get(libraryId);
|
|
107
|
-
return (result === null || result === void 0 ? void 0 : result.count) || 0;
|
|
108
|
-
};
|
|
109
|
-
/**
|
|
110
|
-
* Adds a new operation or replaces an existing one.
|
|
111
|
-
* The server order will be set to the current max + 1
|
|
112
|
-
*/
|
|
113
|
-
this.insert = (libraryId, replicaId, item) => {
|
|
114
|
-
return this.db
|
|
105
|
+
`)
|
|
106
|
+
.get(libraryId);
|
|
107
|
+
return (result === null || result === void 0 ? void 0 : result.count) || 0;
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* Adds a new operation or replaces an existing one.
|
|
111
|
+
* The server order will be set to the current max + 1
|
|
112
|
+
*/
|
|
113
|
+
this.insert = (libraryId, replicaId, item) => {
|
|
114
|
+
return this.db
|
|
115
115
|
.prepare(`
|
|
116
116
|
INSERT OR REPLACE INTO OperationHistory (libraryId, oid, data, timestamp, replicaId, serverOrder)
|
|
117
117
|
VALUES (?, ?, ?, ?, ?, (SELECT COALESCE(MAX(serverOrder), 0) FROM OperationHistory WHERE libraryId = ?) + 1)
|
|
118
|
-
`)
|
|
119
|
-
.run(libraryId, item.oid, JSON.stringify(item.data), item.timestamp, replicaId);
|
|
120
|
-
};
|
|
121
|
-
/**
|
|
122
|
-
* Inserts all operations and updates the server
|
|
123
|
-
* order for this library
|
|
124
|
-
*/
|
|
125
|
-
this.insertAll = async (libraryId, replicaId, items) => {
|
|
126
|
-
const tx = this.db.transaction(() => {
|
|
127
|
-
let orderResult = this.db
|
|
118
|
+
`)
|
|
119
|
+
.run(libraryId, item.oid, JSON.stringify(item.data), item.timestamp, replicaId);
|
|
120
|
+
};
|
|
121
|
+
/**
|
|
122
|
+
* Inserts all operations and updates the server
|
|
123
|
+
* order for this library
|
|
124
|
+
*/
|
|
125
|
+
this.insertAll = async (libraryId, replicaId, items) => {
|
|
126
|
+
const tx = this.db.transaction(() => {
|
|
127
|
+
let orderResult = this.db
|
|
128
128
|
.prepare(`
|
|
129
129
|
SELECT COALESCE(MAX(serverOrder), 0) AS serverOrder FROM OperationHistory WHERE libraryId = ?
|
|
130
|
-
`)
|
|
131
|
-
.get(libraryId);
|
|
132
|
-
let currentServerOrder = orderResult.serverOrder || 0;
|
|
130
|
+
`)
|
|
131
|
+
.get(libraryId);
|
|
132
|
+
let currentServerOrder = orderResult.serverOrder || 0;
|
|
133
133
|
const insertStatement = this.db.prepare(`
|
|
134
134
|
INSERT OR REPLACE INTO OperationHistory (libraryId, oid, data, timestamp, replicaId, serverOrder)
|
|
135
135
|
VALUES (?, ?, ?, ?, ?, ?)
|
|
136
|
-
`);
|
|
137
|
-
for (const item of items) {
|
|
138
|
-
insertStatement.run(libraryId, item.oid, JSON.stringify(item.data), item.timestamp, replicaId, ++currentServerOrder);
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
tx();
|
|
142
|
-
};
|
|
143
|
-
this.dropAll = async (libraryId, items) => {
|
|
136
|
+
`);
|
|
137
|
+
for (const item of items) {
|
|
138
|
+
insertStatement.run(libraryId, item.oid, JSON.stringify(item.data), item.timestamp, replicaId, ++currentServerOrder);
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
tx();
|
|
142
|
+
};
|
|
143
|
+
this.dropAll = async (libraryId, items) => {
|
|
144
144
|
const deleteStatement = this.db.prepare(`
|
|
145
145
|
DELETE FROM OperationHistory
|
|
146
146
|
WHERE libraryId = ? AND replicaId = ? AND oid = ? AND timestamp = ?
|
|
147
|
-
`);
|
|
148
|
-
this.db.transaction(() => {
|
|
149
|
-
for (const item of items) {
|
|
150
|
-
deleteStatement.run(libraryId, item.replicaId, item.oid, item.timestamp);
|
|
151
|
-
}
|
|
152
|
-
})();
|
|
153
|
-
};
|
|
154
|
-
this.deleteAll = (libraryId) => {
|
|
155
|
-
this.db
|
|
147
|
+
`);
|
|
148
|
+
this.db.transaction(() => {
|
|
149
|
+
for (const item of items) {
|
|
150
|
+
deleteStatement.run(libraryId, item.replicaId, item.oid, item.timestamp);
|
|
151
|
+
}
|
|
152
|
+
})();
|
|
153
|
+
};
|
|
154
|
+
this.deleteAll = (libraryId) => {
|
|
155
|
+
this.db
|
|
156
156
|
.prepare(`
|
|
157
157
|
DELETE FROM OperationHistory
|
|
158
158
|
WHERE libraryId = ?
|
|
159
|
-
`)
|
|
160
|
-
.run(libraryId);
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
exports.OperationHistory = OperationHistory;
|
|
159
|
+
`)
|
|
160
|
+
.run(libraryId);
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
exports.OperationHistory = OperationHistory;
|
|
165
165
|
//# sourceMappingURL=OperationHistory.js.map
|
package/dist/cjs/Presence.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
-
import { UserInfo } from '@verdant-web/common';
|
|
3
|
-
import EventEmitter from 'events';
|
|
4
|
-
/**
|
|
5
|
-
* Stores client presence in-memory for connected
|
|
6
|
-
* clients
|
|
7
|
-
*/
|
|
8
|
-
export declare class Presence extends EventEmitter {
|
|
9
|
-
private presences;
|
|
10
|
-
private getLibrary;
|
|
11
|
-
set: (libraryId: string, userId: string, presence: UserInfo<any, any>) => void;
|
|
12
|
-
removeReplica: (libraryId: string, replicaId: string) => void;
|
|
13
|
-
all: (libraryId: string) => Record<string, UserInfo<any, any>>;
|
|
14
|
-
clear: (libraryId: string) => void;
|
|
15
|
-
}
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
import { UserInfo } from '@verdant-web/common';
|
|
3
|
+
import EventEmitter from 'events';
|
|
4
|
+
/**
|
|
5
|
+
* Stores client presence in-memory for connected
|
|
6
|
+
* clients
|
|
7
|
+
*/
|
|
8
|
+
export declare class Presence extends EventEmitter {
|
|
9
|
+
private presences;
|
|
10
|
+
private getLibrary;
|
|
11
|
+
set: (libraryId: string, userId: string, presence: UserInfo<any, any>) => void;
|
|
12
|
+
removeReplica: (libraryId: string, replicaId: string) => void;
|
|
13
|
+
all: (libraryId: string) => Record<string, UserInfo<any, any>>;
|
|
14
|
+
clear: (libraryId: string) => void;
|
|
15
|
+
}
|
package/dist/cjs/Presence.js
CHANGED
|
@@ -1,60 +1,60 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Presence = void 0;
|
|
7
|
-
const events_1 = __importDefault(require("events"));
|
|
8
|
-
/**
|
|
9
|
-
* Stores client presence in-memory for connected
|
|
10
|
-
* clients
|
|
11
|
-
*/
|
|
12
|
-
class Presence extends events_1.default {
|
|
13
|
-
constructor() {
|
|
14
|
-
super(...arguments);
|
|
15
|
-
this.presences = new Map();
|
|
16
|
-
this.getLibrary = (libraryId) => {
|
|
17
|
-
let map = this.presences.get(libraryId);
|
|
18
|
-
if (!map) {
|
|
19
|
-
map = {
|
|
20
|
-
presences: {},
|
|
21
|
-
replicaToUser: {},
|
|
22
|
-
userToReplica: {},
|
|
23
|
-
};
|
|
24
|
-
this.presences.set(libraryId, map);
|
|
25
|
-
}
|
|
26
|
-
return map;
|
|
27
|
-
};
|
|
28
|
-
this.set = (libraryId, userId, presence) => {
|
|
29
|
-
const lib = this.getLibrary(libraryId);
|
|
30
|
-
lib.presences[userId] = presence;
|
|
31
|
-
lib.replicaToUser[presence.replicaId] = userId;
|
|
32
|
-
lib.userToReplica[userId] = lib.userToReplica[userId] || new Set();
|
|
33
|
-
lib.userToReplica[userId].add(presence.replicaId);
|
|
34
|
-
};
|
|
35
|
-
this.removeReplica = (libraryId, replicaId) => {
|
|
36
|
-
const lib = this.getLibrary(libraryId);
|
|
37
|
-
const userId = lib.replicaToUser[replicaId];
|
|
38
|
-
if (!userId)
|
|
39
|
-
return;
|
|
40
|
-
lib.userToReplica[userId].delete(replicaId);
|
|
41
|
-
if (lib.userToReplica[userId].size === 0) {
|
|
42
|
-
delete lib.presences[userId];
|
|
43
|
-
this.emit('lost', libraryId, replicaId, userId);
|
|
44
|
-
// memory cleanup
|
|
45
|
-
if (Object.keys(lib.presences).length === 0) {
|
|
46
|
-
this.clear(libraryId);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
this.all = (libraryId) => {
|
|
51
|
-
var _a;
|
|
52
|
-
return ((_a = this.presences.get(libraryId)) === null || _a === void 0 ? void 0 : _a.presences) || {};
|
|
53
|
-
};
|
|
54
|
-
this.clear = (libraryId) => {
|
|
55
|
-
this.presences.delete(libraryId);
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
exports.Presence = Presence;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Presence = void 0;
|
|
7
|
+
const events_1 = __importDefault(require("events"));
|
|
8
|
+
/**
|
|
9
|
+
* Stores client presence in-memory for connected
|
|
10
|
+
* clients
|
|
11
|
+
*/
|
|
12
|
+
class Presence extends events_1.default {
|
|
13
|
+
constructor() {
|
|
14
|
+
super(...arguments);
|
|
15
|
+
this.presences = new Map();
|
|
16
|
+
this.getLibrary = (libraryId) => {
|
|
17
|
+
let map = this.presences.get(libraryId);
|
|
18
|
+
if (!map) {
|
|
19
|
+
map = {
|
|
20
|
+
presences: {},
|
|
21
|
+
replicaToUser: {},
|
|
22
|
+
userToReplica: {},
|
|
23
|
+
};
|
|
24
|
+
this.presences.set(libraryId, map);
|
|
25
|
+
}
|
|
26
|
+
return map;
|
|
27
|
+
};
|
|
28
|
+
this.set = (libraryId, userId, presence) => {
|
|
29
|
+
const lib = this.getLibrary(libraryId);
|
|
30
|
+
lib.presences[userId] = presence;
|
|
31
|
+
lib.replicaToUser[presence.replicaId] = userId;
|
|
32
|
+
lib.userToReplica[userId] = lib.userToReplica[userId] || new Set();
|
|
33
|
+
lib.userToReplica[userId].add(presence.replicaId);
|
|
34
|
+
};
|
|
35
|
+
this.removeReplica = (libraryId, replicaId) => {
|
|
36
|
+
const lib = this.getLibrary(libraryId);
|
|
37
|
+
const userId = lib.replicaToUser[replicaId];
|
|
38
|
+
if (!userId)
|
|
39
|
+
return;
|
|
40
|
+
lib.userToReplica[userId].delete(replicaId);
|
|
41
|
+
if (lib.userToReplica[userId].size === 0) {
|
|
42
|
+
delete lib.presences[userId];
|
|
43
|
+
this.emit('lost', libraryId, replicaId, userId);
|
|
44
|
+
// memory cleanup
|
|
45
|
+
if (Object.keys(lib.presences).length === 0) {
|
|
46
|
+
this.clear(libraryId);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
this.all = (libraryId) => {
|
|
51
|
+
var _a;
|
|
52
|
+
return ((_a = this.presences.get(libraryId)) === null || _a === void 0 ? void 0 : _a.presences) || {};
|
|
53
|
+
};
|
|
54
|
+
this.clear = (libraryId) => {
|
|
55
|
+
this.presences.delete(libraryId);
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.Presence = Presence;
|
|
60
60
|
//# sourceMappingURL=Presence.js.map
|
package/dist/cjs/Profiles.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export interface UserProfiles<Profile> {
|
|
2
|
-
get(userId: string): Promise<Profile>;
|
|
3
|
-
}
|
|
4
|
-
export declare class UserProfileLoader<Profile> {
|
|
5
|
-
private source;
|
|
6
|
-
private cache;
|
|
7
|
-
constructor(source: UserProfiles<Profile>);
|
|
8
|
-
get: (userId: string) => Promise<Profile>;
|
|
9
|
-
evict: (userId: string) => void;
|
|
10
|
-
}
|
|
1
|
+
export interface UserProfiles<Profile> {
|
|
2
|
+
get(userId: string): Promise<Profile>;
|
|
3
|
+
}
|
|
4
|
+
export declare class UserProfileLoader<Profile> {
|
|
5
|
+
private source;
|
|
6
|
+
private cache;
|
|
7
|
+
constructor(source: UserProfiles<Profile>);
|
|
8
|
+
get: (userId: string) => Promise<Profile>;
|
|
9
|
+
evict: (userId: string) => void;
|
|
10
|
+
}
|
package/dist/cjs/Profiles.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.UserProfileLoader = void 0;
|
|
4
|
-
class UserProfileLoader {
|
|
5
|
-
constructor(source) {
|
|
6
|
-
this.source = source;
|
|
7
|
-
this.cache = new Map();
|
|
8
|
-
this.get = async (userId) => {
|
|
9
|
-
if (!this.cache.has(userId)) {
|
|
10
|
-
this.cache.set(userId, this.source.get(userId));
|
|
11
|
-
}
|
|
12
|
-
return this.cache.get(userId);
|
|
13
|
-
};
|
|
14
|
-
this.evict = (userId) => {
|
|
15
|
-
this.cache.delete(userId);
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
exports.UserProfileLoader = UserProfileLoader;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UserProfileLoader = void 0;
|
|
4
|
+
class UserProfileLoader {
|
|
5
|
+
constructor(source) {
|
|
6
|
+
this.source = source;
|
|
7
|
+
this.cache = new Map();
|
|
8
|
+
this.get = async (userId) => {
|
|
9
|
+
if (!this.cache.has(userId)) {
|
|
10
|
+
this.cache.set(userId, this.source.get(userId));
|
|
11
|
+
}
|
|
12
|
+
return this.cache.get(userId);
|
|
13
|
+
};
|
|
14
|
+
this.evict = (userId) => {
|
|
15
|
+
this.cache.delete(userId);
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.UserProfileLoader = UserProfileLoader;
|
|
20
20
|
//# sourceMappingURL=Profiles.js.map
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { EventSubscriber } from '@verdant-web/common';
|
|
2
|
-
/**
|
|
3
|
-
* A set of timers per-replica which are
|
|
4
|
-
* refreshed whenever the replica sends
|
|
5
|
-
* a message to the server. If a timer expires,
|
|
6
|
-
* the replica is removed from presence. This
|
|
7
|
-
* is a failsafe for socket-based replicas but
|
|
8
|
-
* essential for pull-based replicas.
|
|
9
|
-
*/
|
|
10
|
-
export declare class ReplicaKeepaliveTimers extends EventSubscriber<{
|
|
11
|
-
lost: (libraryId: string, replicaId: string) => void;
|
|
12
|
-
}> {
|
|
13
|
-
private timeout;
|
|
14
|
-
private timers;
|
|
15
|
-
constructor(timeout?: number);
|
|
16
|
-
refresh: (libraryId: string, replicaId: string) => void;
|
|
17
|
-
}
|
|
1
|
+
import { EventSubscriber } from '@verdant-web/common';
|
|
2
|
+
/**
|
|
3
|
+
* A set of timers per-replica which are
|
|
4
|
+
* refreshed whenever the replica sends
|
|
5
|
+
* a message to the server. If a timer expires,
|
|
6
|
+
* the replica is removed from presence. This
|
|
7
|
+
* is a failsafe for socket-based replicas but
|
|
8
|
+
* essential for pull-based replicas.
|
|
9
|
+
*/
|
|
10
|
+
export declare class ReplicaKeepaliveTimers extends EventSubscriber<{
|
|
11
|
+
lost: (libraryId: string, replicaId: string) => void;
|
|
12
|
+
}> {
|
|
13
|
+
private timeout;
|
|
14
|
+
private timers;
|
|
15
|
+
constructor(timeout?: number);
|
|
16
|
+
refresh: (libraryId: string, replicaId: string) => void;
|
|
17
|
+
}
|
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ReplicaKeepaliveTimers = void 0;
|
|
4
|
-
const common_1 = require("@verdant-web/common");
|
|
5
|
-
/**
|
|
6
|
-
* A set of timers per-replica which are
|
|
7
|
-
* refreshed whenever the replica sends
|
|
8
|
-
* a message to the server. If a timer expires,
|
|
9
|
-
* the replica is removed from presence. This
|
|
10
|
-
* is a failsafe for socket-based replicas but
|
|
11
|
-
* essential for pull-based replicas.
|
|
12
|
-
*/
|
|
13
|
-
class ReplicaKeepaliveTimers extends common_1.EventSubscriber {
|
|
14
|
-
constructor(timeout = 30 * 1000) {
|
|
15
|
-
super();
|
|
16
|
-
this.timeout = timeout;
|
|
17
|
-
this.timers = new Map();
|
|
18
|
-
this.refresh = (libraryId, replicaId) => {
|
|
19
|
-
const existing = this.timers.get(replicaId);
|
|
20
|
-
if (existing) {
|
|
21
|
-
clearTimeout(existing);
|
|
22
|
-
}
|
|
23
|
-
this.timers.set(replicaId, setTimeout(() => {
|
|
24
|
-
this.emit('lost', libraryId, replicaId);
|
|
25
|
-
this.timers.delete(replicaId);
|
|
26
|
-
}, this.timeout));
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
exports.ReplicaKeepaliveTimers = ReplicaKeepaliveTimers;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ReplicaKeepaliveTimers = void 0;
|
|
4
|
+
const common_1 = require("@verdant-web/common");
|
|
5
|
+
/**
|
|
6
|
+
* A set of timers per-replica which are
|
|
7
|
+
* refreshed whenever the replica sends
|
|
8
|
+
* a message to the server. If a timer expires,
|
|
9
|
+
* the replica is removed from presence. This
|
|
10
|
+
* is a failsafe for socket-based replicas but
|
|
11
|
+
* essential for pull-based replicas.
|
|
12
|
+
*/
|
|
13
|
+
class ReplicaKeepaliveTimers extends common_1.EventSubscriber {
|
|
14
|
+
constructor(timeout = 30 * 1000) {
|
|
15
|
+
super();
|
|
16
|
+
this.timeout = timeout;
|
|
17
|
+
this.timers = new Map();
|
|
18
|
+
this.refresh = (libraryId, replicaId) => {
|
|
19
|
+
const existing = this.timers.get(replicaId);
|
|
20
|
+
if (existing) {
|
|
21
|
+
clearTimeout(existing);
|
|
22
|
+
}
|
|
23
|
+
this.timers.set(replicaId, setTimeout(() => {
|
|
24
|
+
this.emit('lost', libraryId, replicaId);
|
|
25
|
+
this.timers.delete(replicaId);
|
|
26
|
+
}, this.timeout));
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.ReplicaKeepaliveTimers = ReplicaKeepaliveTimers;
|
|
31
31
|
//# sourceMappingURL=ReplicaKeepaliveTimers.js.map
|
package/dist/cjs/Replicas.d.ts
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import { Database } from 'better-sqlite3';
|
|
2
|
-
import { TokenInfo } from './TokenVerifier.js';
|
|
3
|
-
import { ReplicaInfoSpec } from './types.js';
|
|
4
|
-
export declare class ReplicaInfos {
|
|
5
|
-
private db;
|
|
6
|
-
private readonly replicaTruancyMinutes;
|
|
7
|
-
constructor(db: Database, replicaTruancyMinutes: number);
|
|
8
|
-
get truantCutoff(): number;
|
|
9
|
-
get: (libraryId: string, replicaId: string) => ReplicaInfoSpec | null;
|
|
10
|
-
getOrCreate: (libraryId: string, replicaId: string, info: TokenInfo) => {
|
|
11
|
-
status: 'new' | 'existing' | 'truant';
|
|
12
|
-
replicaInfo: ReplicaInfoSpec;
|
|
13
|
-
};
|
|
14
|
-
getAllNonTruant: (libraryId: string) => ReplicaInfoSpec[];
|
|
15
|
-
getAll: (libraryId: string) => ReplicaInfoSpec[];
|
|
16
|
-
updateLastSeen: (libraryId: string, replicaId: string) => import("better-sqlite3").RunResult;
|
|
17
|
-
updateAcknowledged: (libraryId: string, replicaId: string, timestamp: string) => void;
|
|
18
|
-
updateServerOrder: (libraryId: string, replicaId: string, serverOrder: number) => void;
|
|
19
|
-
acknowledgeOperation: (libraryId: string, replicaId: string, timestamp: string) => void;
|
|
20
|
-
getGlobalAck: (libraryId: string, onlineReplicaIds?: string[]) => string | undefined;
|
|
21
|
-
delete: (libraryId: string, replicaId: string) => import("better-sqlite3").RunResult;
|
|
22
|
-
deleteAll: (libraryId: string) => import("better-sqlite3").RunResult;
|
|
23
|
-
deleteAllForUser: (libraryId: string, userId: string) => import("better-sqlite3").RunResult;
|
|
24
|
-
}
|
|
1
|
+
import { Database } from 'better-sqlite3';
|
|
2
|
+
import { TokenInfo } from './TokenVerifier.js';
|
|
3
|
+
import { ReplicaInfoSpec } from './types.js';
|
|
4
|
+
export declare class ReplicaInfos {
|
|
5
|
+
private db;
|
|
6
|
+
private readonly replicaTruancyMinutes;
|
|
7
|
+
constructor(db: Database, replicaTruancyMinutes: number);
|
|
8
|
+
get truantCutoff(): number;
|
|
9
|
+
get: (libraryId: string, replicaId: string) => ReplicaInfoSpec | null;
|
|
10
|
+
getOrCreate: (libraryId: string, replicaId: string, info: TokenInfo) => {
|
|
11
|
+
status: 'new' | 'existing' | 'truant';
|
|
12
|
+
replicaInfo: ReplicaInfoSpec;
|
|
13
|
+
};
|
|
14
|
+
getAllNonTruant: (libraryId: string) => ReplicaInfoSpec[];
|
|
15
|
+
getAll: (libraryId: string) => ReplicaInfoSpec[];
|
|
16
|
+
updateLastSeen: (libraryId: string, replicaId: string) => import("better-sqlite3").RunResult;
|
|
17
|
+
updateAcknowledged: (libraryId: string, replicaId: string, timestamp: string) => void;
|
|
18
|
+
updateServerOrder: (libraryId: string, replicaId: string, serverOrder: number) => void;
|
|
19
|
+
acknowledgeOperation: (libraryId: string, replicaId: string, timestamp: string) => void;
|
|
20
|
+
getGlobalAck: (libraryId: string, onlineReplicaIds?: string[]) => string | undefined;
|
|
21
|
+
delete: (libraryId: string, replicaId: string) => import("better-sqlite3").RunResult;
|
|
22
|
+
deleteAll: (libraryId: string) => import("better-sqlite3").RunResult;
|
|
23
|
+
deleteAllForUser: (libraryId: string, userId: string) => import("better-sqlite3").RunResult;
|
|
24
|
+
}
|