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