@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,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
+ }