@verdant-web/server 1.7.8 → 1.7.9

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 (97) hide show
  1. package/dist/cjs/Baselines.d.ts +14 -14
  2. package/dist/cjs/Baselines.js +77 -77
  3. package/dist/cjs/ClientConnection.d.ts +18 -18
  4. package/dist/cjs/ClientConnection.js +105 -105
  5. package/dist/cjs/MessageSender.d.ts +5 -5
  6. package/dist/cjs/MessageSender.js +2 -2
  7. package/dist/cjs/OperationHistory.d.ts +34 -34
  8. package/dist/cjs/OperationHistory.js +108 -108
  9. package/dist/cjs/Presence.d.ts +15 -15
  10. package/dist/cjs/Presence.js +59 -59
  11. package/dist/cjs/Profiles.d.ts +10 -10
  12. package/dist/cjs/Profiles.js +19 -19
  13. package/dist/cjs/ReplicaKeepaliveTimers.d.ts +17 -17
  14. package/dist/cjs/ReplicaKeepaliveTimers.js +30 -30
  15. package/dist/cjs/Replicas.d.ts +23 -23
  16. package/dist/cjs/Replicas.js +132 -132
  17. package/dist/cjs/Server.d.ts +121 -121
  18. package/dist/cjs/Server.js +377 -377
  19. package/dist/cjs/ServerLibrary.d.ts +63 -63
  20. package/dist/cjs/ServerLibrary.js +467 -467
  21. package/dist/cjs/TokenProvider.d.ts +16 -16
  22. package/dist/cjs/TokenProvider.js +26 -26
  23. package/dist/cjs/TokenVerifier.d.ts +16 -16
  24. package/dist/cjs/TokenVerifier.js +28 -28
  25. package/dist/cjs/files/FileMetadata.d.ts +28 -28
  26. package/dist/cjs/files/FileMetadata.js +46 -46
  27. package/dist/cjs/files/FileStorage.d.ts +35 -35
  28. package/dist/cjs/files/FileStorage.js +71 -71
  29. package/dist/cjs/index.d.ts +9 -9
  30. package/dist/cjs/index.js +11 -11
  31. package/dist/cjs/migrations/v0.sql.d.ts +2 -2
  32. package/dist/cjs/migrations/v0.sql.js +3 -3
  33. package/dist/cjs/migrations/v1.sql.d.ts +2 -2
  34. package/dist/cjs/migrations/v1.sql.js +3 -3
  35. package/dist/cjs/migrations/v2.sql.d.ts +2 -2
  36. package/dist/cjs/migrations/v2.sql.js +4 -4
  37. package/dist/cjs/migrations/v3.sql.d.ts +2 -2
  38. package/dist/cjs/migrations/v3.sql.js +4 -4
  39. package/dist/cjs/migrations/v4.sql.d.ts +2 -2
  40. package/dist/cjs/migrations/v4.sql.js +4 -4
  41. package/dist/cjs/migrations.d.ts +2 -2
  42. package/dist/cjs/migrations.js +32 -32
  43. package/dist/cjs/types.d.ts +22 -22
  44. package/dist/cjs/types.js +2 -2
  45. package/dist/esm/Baselines.d.ts +14 -14
  46. package/dist/esm/Baselines.js +73 -73
  47. package/dist/esm/ClientConnection.d.ts +18 -18
  48. package/dist/esm/ClientConnection.js +101 -101
  49. package/dist/esm/MessageSender.d.ts +5 -5
  50. package/dist/esm/MessageSender.js +1 -1
  51. package/dist/esm/OperationHistory.d.ts +34 -34
  52. package/dist/esm/OperationHistory.js +104 -104
  53. package/dist/esm/Presence.d.ts +15 -15
  54. package/dist/esm/Presence.js +52 -52
  55. package/dist/esm/Profiles.d.ts +10 -10
  56. package/dist/esm/Profiles.js +15 -15
  57. package/dist/esm/ReplicaKeepaliveTimers.d.ts +17 -17
  58. package/dist/esm/ReplicaKeepaliveTimers.js +26 -26
  59. package/dist/esm/Replicas.d.ts +23 -23
  60. package/dist/esm/Replicas.js +128 -128
  61. package/dist/esm/Server.d.ts +121 -121
  62. package/dist/esm/Server.js +370 -370
  63. package/dist/esm/ServerLibrary.d.ts +63 -63
  64. package/dist/esm/ServerLibrary.js +463 -463
  65. package/dist/esm/TokenProvider.d.ts +16 -16
  66. package/dist/esm/TokenProvider.js +19 -19
  67. package/dist/esm/TokenVerifier.d.ts +16 -16
  68. package/dist/esm/TokenVerifier.js +21 -21
  69. package/dist/esm/files/FileMetadata.d.ts +28 -28
  70. package/dist/esm/files/FileMetadata.js +42 -42
  71. package/dist/esm/files/FileStorage.d.ts +35 -35
  72. package/dist/esm/files/FileStorage.js +44 -44
  73. package/dist/esm/index.d.ts +9 -9
  74. package/dist/esm/index.js +4 -4
  75. package/dist/esm/migrations/v0.sql.d.ts +2 -2
  76. package/dist/esm/migrations/v0.sql.js +1 -1
  77. package/dist/esm/migrations/v1.sql.d.ts +2 -2
  78. package/dist/esm/migrations/v1.sql.js +1 -1
  79. package/dist/esm/migrations/v2.sql.d.ts +2 -2
  80. package/dist/esm/migrations/v2.sql.js +2 -2
  81. package/dist/esm/migrations/v3.sql.d.ts +2 -2
  82. package/dist/esm/migrations/v3.sql.js +2 -2
  83. package/dist/esm/migrations/v4.sql.d.ts +2 -2
  84. package/dist/esm/migrations/v4.sql.js +2 -2
  85. package/dist/esm/migrations.d.ts +2 -2
  86. package/dist/esm/migrations.js +25 -25
  87. package/dist/esm/types.d.ts +22 -22
  88. package/dist/esm/types.js +1 -1
  89. package/dist/tsconfig-cjs.tsbuildinfo +1 -1
  90. package/dist/tsconfig.tsbuildinfo +1 -1
  91. package/package.json +2 -2
  92. package/dist/cjs/ServerStorage.d.ts +0 -35
  93. package/dist/cjs/ServerStorage.js +0 -60
  94. package/dist/cjs/ServerStorage.js.map +0 -1
  95. package/dist/esm/ServerStorage.d.ts +0 -44
  96. package/dist/esm/ServerStorage.js +0 -58
  97. package/dist/esm/ServerStorage.js.map +0 -1
@@ -1,147 +1,147 @@
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
- /**
92
- * Adds a new operation or replaces an existing one.
93
- * The server order will be set to the current max + 1
94
- */
95
- this.insert = (libraryId, replicaId, item) => {
96
- return this.db
87
+ `)
88
+ .all(libraryId, serverOrder);
89
+ return (result || []).map(this.hydratePatch);
90
+ };
91
+ /**
92
+ * Adds a new operation or replaces an existing one.
93
+ * The server order will be set to the current max + 1
94
+ */
95
+ this.insert = (libraryId, replicaId, item) => {
96
+ return this.db
97
97
  .prepare(`
98
98
  INSERT OR REPLACE INTO OperationHistory (libraryId, oid, data, timestamp, replicaId, serverOrder)
99
99
  VALUES (?, ?, ?, ?, ?, (SELECT COALESCE(MAX(serverOrder), 0) FROM OperationHistory WHERE libraryId = ?) + 1)
100
- `)
101
- .run(libraryId, item.oid, JSON.stringify(item.data), item.timestamp, replicaId);
102
- };
103
- /**
104
- * Inserts all operations and updates the server
105
- * order for this library
106
- */
107
- this.insertAll = async (libraryId, replicaId, items) => {
108
- const tx = this.db.transaction(() => {
109
- let orderResult = this.db
100
+ `)
101
+ .run(libraryId, item.oid, JSON.stringify(item.data), item.timestamp, replicaId);
102
+ };
103
+ /**
104
+ * Inserts all operations and updates the server
105
+ * order for this library
106
+ */
107
+ this.insertAll = async (libraryId, replicaId, items) => {
108
+ const tx = this.db.transaction(() => {
109
+ let orderResult = this.db
110
110
  .prepare(`
111
111
  SELECT COALESCE(MAX(serverOrder), 0) AS serverOrder FROM OperationHistory WHERE libraryId = ?
112
- `)
113
- .get(libraryId);
114
- let currentServerOrder = orderResult.serverOrder || 0;
112
+ `)
113
+ .get(libraryId);
114
+ let currentServerOrder = orderResult.serverOrder || 0;
115
115
  const insertStatement = this.db.prepare(`
116
116
  INSERT OR REPLACE INTO OperationHistory (libraryId, oid, data, timestamp, replicaId, serverOrder)
117
117
  VALUES (?, ?, ?, ?, ?, ?)
118
- `);
119
- for (const item of items) {
120
- insertStatement.run(libraryId, item.oid, JSON.stringify(item.data), item.timestamp, replicaId, ++currentServerOrder);
121
- }
122
- });
123
- tx();
124
- };
125
- this.dropAll = async (libraryId, items) => {
118
+ `);
119
+ for (const item of items) {
120
+ insertStatement.run(libraryId, item.oid, JSON.stringify(item.data), item.timestamp, replicaId, ++currentServerOrder);
121
+ }
122
+ });
123
+ tx();
124
+ };
125
+ this.dropAll = async (libraryId, items) => {
126
126
  const deleteStatement = this.db.prepare(`
127
127
  DELETE FROM OperationHistory
128
128
  WHERE libraryId = ? AND replicaId = ? AND oid = ? AND timestamp = ?
129
- `);
130
- this.db.transaction(() => {
131
- for (const item of items) {
132
- deleteStatement.run(libraryId, item.replicaId, item.oid, item.timestamp);
133
- }
134
- })();
135
- };
136
- this.deleteAll = (libraryId) => {
137
- this.db
129
+ `);
130
+ this.db.transaction(() => {
131
+ for (const item of items) {
132
+ deleteStatement.run(libraryId, item.replicaId, item.oid, item.timestamp);
133
+ }
134
+ })();
135
+ };
136
+ this.deleteAll = (libraryId) => {
137
+ this.db
138
138
  .prepare(`
139
139
  DELETE FROM OperationHistory
140
140
  WHERE libraryId = ?
141
- `)
142
- .run(libraryId);
143
- };
144
- }
145
- }
146
- exports.OperationHistory = OperationHistory;
141
+ `)
142
+ .run(libraryId);
143
+ };
144
+ }
145
+ }
146
+ exports.OperationHistory = OperationHistory;
147
147
  //# sourceMappingURL=OperationHistory.js.map
@@ -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
+ }
@@ -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
@@ -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
+ }
@@ -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
@@ -1,23 +1,23 @@
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
- private get truantCutoff();
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
- updateLastSeen: (libraryId: string, replicaId: string) => import("better-sqlite3").RunResult;
16
- updateAcknowledged: (libraryId: string, replicaId: string, timestamp: string) => void;
17
- updateServerOrder: (libraryId: string, replicaId: string, serverOrder: number) => void;
18
- acknowledgeOperation: (libraryId: string, replicaId: string, timestamp: string) => void;
19
- getGlobalAck: (libraryId: string, onlineReplicaIds?: string[]) => string | undefined;
20
- delete: (libraryId: string, replicaId: string) => import("better-sqlite3").RunResult;
21
- deleteAll: (libraryId: string) => import("better-sqlite3").RunResult;
22
- deleteAllForUser: (libraryId: string, userId: string) => import("better-sqlite3").RunResult;
23
- }
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
+ private get truantCutoff();
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
+ updateLastSeen: (libraryId: string, replicaId: string) => import("better-sqlite3").RunResult;
16
+ updateAcknowledged: (libraryId: string, replicaId: string, timestamp: string) => void;
17
+ updateServerOrder: (libraryId: string, replicaId: string, serverOrder: number) => void;
18
+ acknowledgeOperation: (libraryId: string, replicaId: string, timestamp: string) => void;
19
+ getGlobalAck: (libraryId: string, onlineReplicaIds?: string[]) => string | undefined;
20
+ delete: (libraryId: string, replicaId: string) => import("better-sqlite3").RunResult;
21
+ deleteAll: (libraryId: string) => import("better-sqlite3").RunResult;
22
+ deleteAllForUser: (libraryId: string, userId: string) => import("better-sqlite3").RunResult;
23
+ }