@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,125 +1,125 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ReplicaInfos = void 0;
4
- class ReplicaInfos {
5
- constructor(db, replicaTruancyMinutes) {
6
- this.db = db;
7
- this.replicaTruancyMinutes = replicaTruancyMinutes;
8
- this.get = (libraryId, replicaId) => {
9
- const row = this.db
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ReplicaInfos = void 0;
4
+ class ReplicaInfos {
5
+ constructor(db, replicaTruancyMinutes) {
6
+ this.db = db;
7
+ this.replicaTruancyMinutes = replicaTruancyMinutes;
8
+ this.get = (libraryId, replicaId) => {
9
+ const row = this.db
10
10
  .prepare(`
11
11
  SELECT * FROM ReplicaInfo
12
12
  WHERE id = ? AND libraryId = ?
13
- `)
14
- .get(replicaId, libraryId);
15
- if (!row) {
16
- return null;
17
- }
18
- return {
19
- id: row.id,
20
- libraryId: row.libraryId,
21
- clientId: row.clientId,
22
- lastSeenWallClockTime: row.lastSeenWallClockTime,
23
- ackedLogicalTime: row.ackedLogicalTime,
24
- type: row.type,
25
- ackedServerOrder: row.ackedServerOrder,
26
- };
27
- };
28
- this.getOrCreate = (libraryId, replicaId, info) => {
29
- const replicaInfo = this.db
13
+ `)
14
+ .get(replicaId, libraryId);
15
+ if (!row) {
16
+ return null;
17
+ }
18
+ return {
19
+ id: row.id,
20
+ libraryId: row.libraryId,
21
+ clientId: row.clientId,
22
+ lastSeenWallClockTime: row.lastSeenWallClockTime,
23
+ ackedLogicalTime: row.ackedLogicalTime,
24
+ type: row.type,
25
+ ackedServerOrder: row.ackedServerOrder,
26
+ };
27
+ };
28
+ this.getOrCreate = (libraryId, replicaId, info) => {
29
+ const replicaInfo = this.db
30
30
  .prepare(`
31
31
  SELECT * FROM ReplicaInfo
32
32
  WHERE id = ? AND libraryId = ?
33
- `)
34
- .get(replicaId, libraryId);
35
- if (!replicaInfo) {
36
- this.db
33
+ `)
34
+ .get(replicaId, libraryId);
35
+ if (!replicaInfo) {
36
+ this.db
37
37
  .prepare(`
38
38
  INSERT INTO ReplicaInfo (id, clientId, libraryId, type)
39
39
  VALUES (?, ?, ?, ?)
40
- `)
41
- .run(replicaId, info.userId, libraryId, info.type);
42
- return {
43
- status: 'new',
44
- replicaInfo: {
45
- id: replicaId,
46
- clientId: info.userId,
47
- ackedLogicalTime: null,
48
- lastSeenWallClockTime: null,
49
- libraryId: libraryId,
50
- type: info.type,
51
- ackedServerOrder: 0,
52
- },
53
- };
54
- }
55
- if (replicaInfo.type !== info.type) {
56
- // type should be updated if a new token changes it
57
- this.db
40
+ `)
41
+ .run(replicaId, info.userId, libraryId, info.type);
42
+ return {
43
+ status: 'new',
44
+ replicaInfo: {
45
+ id: replicaId,
46
+ clientId: info.userId,
47
+ ackedLogicalTime: null,
48
+ lastSeenWallClockTime: null,
49
+ libraryId: libraryId,
50
+ type: info.type,
51
+ ackedServerOrder: 0,
52
+ },
53
+ };
54
+ }
55
+ if (replicaInfo.type !== info.type) {
56
+ // type should be updated if a new token changes it
57
+ this.db
58
58
  .prepare(`
59
59
  UPDATE ReplicaInfo
60
60
  SET type = ?
61
61
  WHERE id = ? AND libraryId = ?
62
- `)
63
- .run(info.type, replicaId, libraryId);
64
- }
65
- if (replicaInfo.clientId !== info.userId) {
66
- throw new Error(`Replica ${replicaId} already exists with a different user ID`);
67
- }
68
- if (replicaInfo.lastSeenWallClockTime &&
69
- replicaInfo.lastSeenWallClockTime < this.truantCutoff) {
70
- return {
71
- status: 'truant',
72
- replicaInfo,
73
- };
74
- }
75
- return {
76
- status: 'existing',
77
- replicaInfo,
78
- };
79
- };
80
- this.getAllNonTruant = (libraryId) => {
81
- return this.db
62
+ `)
63
+ .run(info.type, replicaId, libraryId);
64
+ }
65
+ if (replicaInfo.clientId !== info.userId) {
66
+ throw new Error(`Replica ${replicaId} already exists with a different user ID`);
67
+ }
68
+ if (replicaInfo.lastSeenWallClockTime &&
69
+ replicaInfo.lastSeenWallClockTime < this.truantCutoff) {
70
+ return {
71
+ status: 'truant',
72
+ replicaInfo,
73
+ };
74
+ }
75
+ return {
76
+ status: 'existing',
77
+ replicaInfo,
78
+ };
79
+ };
80
+ this.getAllNonTruant = (libraryId) => {
81
+ return this.db
82
82
  .prepare(`
83
83
  SELECT * FROM ReplicaInfo
84
84
  WHERE libraryId = ? AND lastSeenWallClockTime > ?
85
- `)
86
- .all(libraryId, this.truantCutoff);
87
- };
88
- this.updateLastSeen = (libraryId, replicaId) => {
89
- const clockTime = new Date().getTime();
90
- return this.db
85
+ `)
86
+ .all(libraryId, this.truantCutoff);
87
+ };
88
+ this.updateLastSeen = (libraryId, replicaId) => {
89
+ const clockTime = new Date().getTime();
90
+ return this.db
91
91
  .prepare(`
92
92
  UPDATE ReplicaInfo
93
93
  SET lastSeenWallClockTime = ?
94
94
  WHERE id = ? AND libraryId = ?
95
- `)
96
- .run(clockTime, replicaId, libraryId);
97
- };
98
- this.updateAcknowledged = (libraryId, replicaId, timestamp) => {
99
- this.db
95
+ `)
96
+ .run(clockTime, replicaId, libraryId);
97
+ };
98
+ this.updateAcknowledged = (libraryId, replicaId, timestamp) => {
99
+ this.db
100
100
  .prepare(`
101
101
  UPDATE ReplicaInfo
102
102
  SET ackedLogicalTime = ?
103
103
  WHERE id = ? AND libraryId = ?
104
- `)
105
- .run(timestamp, replicaId, libraryId);
106
- };
107
- this.updateServerOrder = (libraryId, replicaId, serverOrder) => {
108
- // only increment the server order, never set it to lower than before
109
- this.db
104
+ `)
105
+ .run(timestamp, replicaId, libraryId);
106
+ };
107
+ this.updateServerOrder = (libraryId, replicaId, serverOrder) => {
108
+ // only increment the server order, never set it to lower than before
109
+ this.db
110
110
  .prepare(`
111
111
  UPDATE ReplicaInfo
112
112
  SET ackedServerOrder = MAX(ackedServerOrder, ?)
113
113
  WHERE id = ? AND libraryId = ?
114
- `)
115
- .run(serverOrder, replicaId, libraryId);
116
- };
117
- this.acknowledgeOperation = (libraryId, replicaId, timestamp) => {
118
- if (!timestamp)
119
- return;
120
- // get the server order from the operation with the timestamp and update the replica's server order
121
- // to the max of the current server order and the server order of the operation
122
- this.db
114
+ `)
115
+ .run(serverOrder, replicaId, libraryId);
116
+ };
117
+ this.acknowledgeOperation = (libraryId, replicaId, timestamp) => {
118
+ if (!timestamp)
119
+ return;
120
+ // get the server order from the operation with the timestamp and update the replica's server order
121
+ // to the max of the current server order and the server order of the operation
122
+ this.db
123
123
  .prepare(`
124
124
  UPDATE ReplicaInfo
125
125
  SET ackedLogicalTime = ?, ackedServerOrder = MAX(ackedServerOrder, COALESCE((
@@ -127,48 +127,48 @@ class ReplicaInfos {
127
127
  WHERE libraryId = ? AND timestamp = ?
128
128
  ), 0))
129
129
  WHERE id = ? AND libraryId = ?
130
- `)
131
- .run(timestamp, libraryId, timestamp, replicaId, libraryId);
132
- };
133
- this.getGlobalAck = (libraryId, onlineReplicaIds) => {
134
- const nonTruant = this.getAllNonTruant(libraryId);
135
- const globalAckEligible = nonTruant.filter((replica) => replica.type < 2 || (onlineReplicaIds === null || onlineReplicaIds === void 0 ? void 0 : onlineReplicaIds.includes(replica.id)));
136
- // get the earliest acked time
137
- return globalAckEligible.reduce((acc, replica) => {
138
- if (!replica.ackedLogicalTime) {
139
- return acc;
140
- }
141
- if (acc === undefined) {
142
- return replica.ackedLogicalTime;
143
- }
144
- return acc < replica.ackedLogicalTime ? acc : replica.ackedLogicalTime;
145
- }, undefined);
146
- };
147
- this.delete = (libraryId, replicaId) => {
148
- return this.db
130
+ `)
131
+ .run(timestamp, libraryId, timestamp, replicaId, libraryId);
132
+ };
133
+ this.getGlobalAck = (libraryId, onlineReplicaIds) => {
134
+ const nonTruant = this.getAllNonTruant(libraryId);
135
+ const globalAckEligible = nonTruant.filter((replica) => replica.type < 2 || (onlineReplicaIds === null || onlineReplicaIds === void 0 ? void 0 : onlineReplicaIds.includes(replica.id)));
136
+ // get the earliest acked time
137
+ return globalAckEligible.reduce((acc, replica) => {
138
+ if (!replica.ackedLogicalTime) {
139
+ return acc;
140
+ }
141
+ if (acc === undefined) {
142
+ return replica.ackedLogicalTime;
143
+ }
144
+ return acc < replica.ackedLogicalTime ? acc : replica.ackedLogicalTime;
145
+ }, undefined);
146
+ };
147
+ this.delete = (libraryId, replicaId) => {
148
+ return this.db
149
149
  .prepare(`
150
150
  DELETE FROM ReplicaInfo
151
151
  WHERE id = ? AND libraryId = ?
152
- `)
153
- .run(replicaId, libraryId);
154
- };
155
- this.deleteAll = (libraryId) => {
156
- return this.db
152
+ `)
153
+ .run(replicaId, libraryId);
154
+ };
155
+ this.deleteAll = (libraryId) => {
156
+ return this.db
157
157
  .prepare(`
158
158
  DELETE FROM ReplicaInfo
159
159
  WHERE libraryId = ?
160
- `)
161
- .run(libraryId);
162
- };
163
- this.deleteAllForUser = (libraryId, userId) => {
164
- return this.db
165
- .prepare(`DELETE FROM ReplicaInfo WHERE libraryId = ? AND clientId = ?`)
166
- .run(libraryId, userId);
167
- };
168
- }
169
- get truantCutoff() {
170
- return Date.now() - this.replicaTruancyMinutes * 60 * 1000;
171
- }
172
- }
173
- exports.ReplicaInfos = ReplicaInfos;
160
+ `)
161
+ .run(libraryId);
162
+ };
163
+ this.deleteAllForUser = (libraryId, userId) => {
164
+ return this.db
165
+ .prepare(`DELETE FROM ReplicaInfo WHERE libraryId = ? AND clientId = ?`)
166
+ .run(libraryId, userId);
167
+ };
168
+ }
169
+ get truantCutoff() {
170
+ return Date.now() - this.replicaTruancyMinutes * 60 * 1000;
171
+ }
172
+ }
173
+ exports.ReplicaInfos = ReplicaInfos;
174
174
  //# sourceMappingURL=Replicas.js.map
@@ -1,121 +1,121 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
- /// <reference types="node" resolution-mode="require"/>
3
- import { DocumentBaseline, Operation, ServerMessage } from '@verdant-web/common';
4
- import EventEmitter from 'events';
5
- import { IncomingMessage, Server as HttpServer, ServerResponse } from 'http';
6
- import { UserProfiles } from './Profiles.js';
7
- import { MessageSender } from './MessageSender.js';
8
- import { TokenInfo } from './TokenVerifier.js';
9
- import { FileStorage } from './files/FileStorage.js';
10
- import { FileMetadataConfig } from './files/FileMetadata.js';
11
- export interface ServerOptions {
12
- /**
13
- * Attach to a pre-existing HTTP server. Provide this if you have another server,
14
- * like an Express server, that you want to add lofi to. If provided, you don't
15
- * need to call .listen()
16
- */
17
- httpServer?: HttpServer;
18
- /**
19
- * The secret value used to generate tokens from your authentication endpoint.
20
- * Used to verify and decode user identity and library access on connection.
21
- */
22
- tokenSecret: string;
23
- /**
24
- * The path to your SQLite database.
25
- */
26
- databaseFile: string;
27
- /**
28
- * Optionally provide an implementation of the UserProfiles interface to look up
29
- * static user profile data to use in persistence. This data is considered trusted
30
- * and can be used to identify users with information like name or profile image.
31
- */
32
- profiles?: UserProfiles<any>;
33
- /**
34
- * How many minutes of inactivity before a replica is considered truant and
35
- * removed from the library. Defaults to 30 days.
36
- */
37
- replicaTruancyMinutes?: number;
38
- /**
39
- * Supply a logging function to log debug messages.
40
- */
41
- log?: (...args: any[]) => void;
42
- /**
43
- * Disable history compaction. Storage usage will grow indefinitely. Not recommended.
44
- */
45
- disableRebasing?: boolean;
46
- /**
47
- * Provide a FileStorage backend to accept file uploads. Without a file backend,
48
- * users will not be able to synchronize files, and all files added on peer replicas
49
- * will be forever unavailable.
50
- *
51
- * A default, filesystem-backed FileStorage implementation is provided as an export
52
- * of this library.
53
- */
54
- fileStorage?: FileStorage;
55
- fileConfig?: FileMetadataConfig;
56
- }
57
- export interface ServerEvents {
58
- error: (err: any) => void;
59
- warning: (msg: string, ...args: any[]) => void;
60
- changes: (info: Omit<TokenInfo, 'token'>, operations: Operation[], baselines: DocumentBaseline[]) => void;
61
- request: (info: TokenInfo) => void;
62
- 'socket-close': (info: TokenInfo) => void;
63
- 'socket-connection': (info: TokenInfo) => void;
64
- }
65
- export declare interface Server {
66
- on<Event extends keyof ServerEvents>(ev: Event, cb: ServerEvents[Event]): this;
67
- off<Event extends keyof ServerEvents>(ev: Event, cb: ServerEvents[Event]): this;
68
- emit<Event extends keyof ServerEvents>(ev: Event, ...args: Parameters<ServerEvents[Event]>): boolean;
69
- }
70
- export declare class Server extends EventEmitter implements MessageSender {
71
- readonly httpServer: HttpServer;
72
- private wss;
73
- private fileStorage?;
74
- private fileMetadata;
75
- private library;
76
- private clientConnections;
77
- private keepalives;
78
- private tokenVerifier;
79
- private connectionToReplicaIdMap;
80
- private log;
81
- private __testMode;
82
- constructor(options: ServerOptions);
83
- private authorizeRequest;
84
- private getRequestToken;
85
- private internalServerHandleRequest;
86
- handleRequest: (req: IncomingMessage, res: ServerResponse) => Promise<void>;
87
- /**
88
- * Handles a multipart upload of a file from a verdant client. The upload
89
- * will include parameters for the file's ID, name, and type. The request
90
- * must be authenticated with a token to tie it to a library.
91
- */
92
- handleFileRequest: (req: IncomingMessage, res: ServerResponse) => Promise<void>;
93
- broadcast: (libraryId: string, message: ServerMessage, omitKeys?: string[]) => void;
94
- send: (libraryId: string, key: string, message: ServerMessage) => void;
95
- private handleMessage;
96
- private handleConnection;
97
- listen: (handle: any, listeningListener?: (() => void) | undefined) => void;
98
- close: () => Promise<void>;
99
- /**
100
- * Completely remove a library from the server.
101
- * This will remove all data associated with the library.
102
- * Use it very carefully! Data will still be stored on user
103
- * devices, so this is not as scary as it sounds - the next time
104
- * any replica connects, it will repopulate the library. But
105
- * you should still be careful.
106
- */
107
- evictLibrary: (libraryId: string) => void;
108
- getLibraryPresence: (libraryId: string) => Record<string, import("@verdant-web/common").UserInfo<any, any>>;
109
- /**
110
- * Removes all replicas associated with a User ID from
111
- * the server. Consistency algorithms will no longer wait on these
112
- * replicas before confirming and squashing changes.
113
- */
114
- evictUser: (libraryId: string, userId: string) => void;
115
- /**
116
- * Retrieves a snapshot of the full document contents at this time.
117
- * Useful for capturing the shape of data for static usage outside
118
- * of the live system.
119
- */
120
- getDocumentSnapshot: (libraryId: string, collection: string, documentId: string) => any;
121
- }
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ /// <reference types="node" resolution-mode="require"/>
3
+ import { DocumentBaseline, Operation, ServerMessage } from '@verdant-web/common';
4
+ import EventEmitter from 'events';
5
+ import { IncomingMessage, Server as HttpServer, ServerResponse } from 'http';
6
+ import { UserProfiles } from './Profiles.js';
7
+ import { MessageSender } from './MessageSender.js';
8
+ import { TokenInfo } from './TokenVerifier.js';
9
+ import { FileStorage } from './files/FileStorage.js';
10
+ import { FileMetadataConfig } from './files/FileMetadata.js';
11
+ export interface ServerOptions {
12
+ /**
13
+ * Attach to a pre-existing HTTP server. Provide this if you have another server,
14
+ * like an Express server, that you want to add lofi to. If provided, you don't
15
+ * need to call .listen()
16
+ */
17
+ httpServer?: HttpServer;
18
+ /**
19
+ * The secret value used to generate tokens from your authentication endpoint.
20
+ * Used to verify and decode user identity and library access on connection.
21
+ */
22
+ tokenSecret: string;
23
+ /**
24
+ * The path to your SQLite database.
25
+ */
26
+ databaseFile: string;
27
+ /**
28
+ * Optionally provide an implementation of the UserProfiles interface to look up
29
+ * static user profile data to use in persistence. This data is considered trusted
30
+ * and can be used to identify users with information like name or profile image.
31
+ */
32
+ profiles?: UserProfiles<any>;
33
+ /**
34
+ * How many minutes of inactivity before a replica is considered truant and
35
+ * removed from the library. Defaults to 30 days.
36
+ */
37
+ replicaTruancyMinutes?: number;
38
+ /**
39
+ * Supply a logging function to log debug messages.
40
+ */
41
+ log?: (...args: any[]) => void;
42
+ /**
43
+ * Disable history compaction. Storage usage will grow indefinitely. Not recommended.
44
+ */
45
+ disableRebasing?: boolean;
46
+ /**
47
+ * Provide a FileStorage backend to accept file uploads. Without a file backend,
48
+ * users will not be able to synchronize files, and all files added on peer replicas
49
+ * will be forever unavailable.
50
+ *
51
+ * A default, filesystem-backed FileStorage implementation is provided as an export
52
+ * of this library.
53
+ */
54
+ fileStorage?: FileStorage;
55
+ fileConfig?: FileMetadataConfig;
56
+ }
57
+ export interface ServerEvents {
58
+ error: (err: any) => void;
59
+ warning: (msg: string, ...args: any[]) => void;
60
+ changes: (info: Omit<TokenInfo, 'token'>, operations: Operation[], baselines: DocumentBaseline[]) => void;
61
+ request: (info: TokenInfo) => void;
62
+ 'socket-close': (info: TokenInfo) => void;
63
+ 'socket-connection': (info: TokenInfo) => void;
64
+ }
65
+ export declare interface Server {
66
+ on<Event extends keyof ServerEvents>(ev: Event, cb: ServerEvents[Event]): this;
67
+ off<Event extends keyof ServerEvents>(ev: Event, cb: ServerEvents[Event]): this;
68
+ emit<Event extends keyof ServerEvents>(ev: Event, ...args: Parameters<ServerEvents[Event]>): boolean;
69
+ }
70
+ export declare class Server extends EventEmitter implements MessageSender {
71
+ readonly httpServer: HttpServer;
72
+ private wss;
73
+ private fileStorage?;
74
+ private fileMetadata;
75
+ private library;
76
+ private clientConnections;
77
+ private keepalives;
78
+ private tokenVerifier;
79
+ private connectionToReplicaIdMap;
80
+ private log;
81
+ private __testMode;
82
+ constructor(options: ServerOptions);
83
+ private authorizeRequest;
84
+ private getRequestToken;
85
+ private internalServerHandleRequest;
86
+ handleRequest: (req: IncomingMessage, res: ServerResponse) => Promise<void>;
87
+ /**
88
+ * Handles a multipart upload of a file from a verdant client. The upload
89
+ * will include parameters for the file's ID, name, and type. The request
90
+ * must be authenticated with a token to tie it to a library.
91
+ */
92
+ handleFileRequest: (req: IncomingMessage, res: ServerResponse) => Promise<void>;
93
+ broadcast: (libraryId: string, message: ServerMessage, omitKeys?: string[]) => void;
94
+ send: (libraryId: string, key: string, message: ServerMessage) => void;
95
+ private handleMessage;
96
+ private handleConnection;
97
+ listen: (handle: any, listeningListener?: (() => void) | undefined) => void;
98
+ close: () => Promise<void>;
99
+ /**
100
+ * Completely remove a library from the server.
101
+ * This will remove all data associated with the library.
102
+ * Use it very carefully! Data will still be stored on user
103
+ * devices, so this is not as scary as it sounds - the next time
104
+ * any replica connects, it will repopulate the library. But
105
+ * you should still be careful.
106
+ */
107
+ evictLibrary: (libraryId: string) => void;
108
+ getLibraryPresence: (libraryId: string) => Record<string, import("@verdant-web/common").UserInfo<any, any>>;
109
+ /**
110
+ * Removes all replicas associated with a User ID from
111
+ * the server. Consistency algorithms will no longer wait on these
112
+ * replicas before confirming and squashing changes.
113
+ */
114
+ evictUser: (libraryId: string, userId: string) => void;
115
+ /**
116
+ * Retrieves a snapshot of the full document contents at this time.
117
+ * Useful for capturing the shape of data for static usage outside
118
+ * of the live system.
119
+ */
120
+ getDocumentSnapshot: (libraryId: string, collection: string, documentId: string) => any;
121
+ }