@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
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,121 @@
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
+ const vitest_1 = require("vitest");
7
+ const better_sqlite3_1 = __importDefault(require("better-sqlite3"));
8
+ const migrations_js_1 = require("./migrations.js");
9
+ const fs_1 = __importDefault(require("fs"));
10
+ (0, vitest_1.describe)('the v5->v6 migration', () => {
11
+ let dbFile;
12
+ let db;
13
+ (0, vitest_1.beforeAll)(() => {
14
+ dbFile = `v5-migration-test-${Math.random()}.sqlite`;
15
+ db = (0, better_sqlite3_1.default)(dbFile);
16
+ });
17
+ (0, vitest_1.afterAll)(() => {
18
+ db.close();
19
+ fs_1.default.rmSync(dbFile);
20
+ });
21
+ (0, vitest_1.it)('rewrites legacy oids in all ops and baselines', () => {
22
+ // manually migrate to v4 before starting and seed the database with some
23
+ // operations and baselines.
24
+ (0, migrations_js_1.migrations)(db, 5);
25
+ // manually insert some operations and baselines
26
+ db.transaction(() => {
27
+ [
28
+ {
29
+ libraryId: 'test-1',
30
+ replicaId: 'foo',
31
+ oid: 'weirds/b',
32
+ data: {
33
+ op: 'set',
34
+ value: { '@@type': 'ref', id: 'weirds/b.objectMap.one:ghi' },
35
+ },
36
+ timestamp: '1',
37
+ serverOrder: 1,
38
+ },
39
+ {
40
+ libraryId: 'test-1',
41
+ replicaId: 'foo',
42
+ oid: 'weirds/b.list:ghi',
43
+ data: {
44
+ op: 'list-push',
45
+ value: { '@@type': 'ref', id: 'weirds/b.list.#:abc' },
46
+ },
47
+ timestamp: '1',
48
+ serverOrder: 2,
49
+ },
50
+ {
51
+ libraryId: 'test-1',
52
+ replicaId: 'foo',
53
+ oid: 'weirds/b.list:ghi',
54
+ data: {
55
+ op: 'list-remove',
56
+ value: { '@@type': 'ref', id: 'weirds/b.list.#:abc' },
57
+ },
58
+ timestamp: '2',
59
+ serverOrder: 3,
60
+ },
61
+ {
62
+ libraryId: 'test-2',
63
+ replicaId: 'bar',
64
+ oid: 'weirds/b',
65
+ data: {
66
+ op: 'set',
67
+ value: { '@@type': 'ref', id: 'weirds/b.objectMap.one:ghi' },
68
+ },
69
+ timestamp: '1a',
70
+ serverOrder: 1,
71
+ },
72
+ ].forEach(({ libraryId, replicaId, oid, data, timestamp, serverOrder }) => {
73
+ db.prepare(
74
+ /* sql */ `
75
+ INSERT INTO OperationHistory (libraryId, replicaId, oid, data, timestamp, serverOrder)
76
+ VALUES (?, ?, ?, ?, ?, ?);
77
+ `).run(libraryId, replicaId, oid, JSON.stringify(data), timestamp, serverOrder);
78
+ });
79
+ [
80
+ {
81
+ libraryId: 'test-1',
82
+ oid: 'weirds/b.objectMap.one:ghi',
83
+ snapshot: { '@@type': 'ref', id: 'weirds/b.list.#:abc' },
84
+ timestamp: '1',
85
+ },
86
+ {
87
+ libraryId: 'test-2',
88
+ oid: 'weirds/b.objectMap.one:ghi',
89
+ snapshot: { '@@type': 'ref', id: 'weirds/b.list.#:abc' },
90
+ timestamp: '1a',
91
+ },
92
+ ].forEach(({ libraryId, oid, snapshot, timestamp }) => {
93
+ db.prepare(
94
+ /* sql */ `
95
+ INSERT INTO DocumentBaseline (libraryId, oid, snapshot, timestamp)
96
+ VALUES (?, ?, ?, ?);
97
+ `).run(libraryId, oid, JSON.stringify(snapshot), timestamp);
98
+ });
99
+ })();
100
+ (0, migrations_js_1.migrations)(db);
101
+ // check that the operations and baselines have been rewritten
102
+ db.transaction(() => {
103
+ const operations = db
104
+ .prepare(
105
+ /* sql */ `
106
+ SELECT * from OperationHistory;
107
+ `)
108
+ .all();
109
+ (0, vitest_1.expect)(operations).toMatchSnapshot();
110
+ const baselines = db
111
+ .prepare(
112
+ /* sql */ `
113
+ SELECT * from DocumentBaseline;
114
+ `)
115
+ .all();
116
+ (0, vitest_1.expect)(baselines).toMatchSnapshot();
117
+ })();
118
+ db.close();
119
+ });
120
+ });
121
+ //# sourceMappingURL=migrations.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrations.test.js","sourceRoot":"","sources":["../../src/migrations.test.ts"],"names":[],"mappings":"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"}
@@ -1,22 +1,22 @@
1
- import { DocumentBaseline, Operation, ReplicaInfo, ReplicaType } from '@verdant-web/common';
2
- export interface OperationSpec extends Operation {
3
- serverOrder: number;
4
- replicaId: string;
5
- }
6
- export interface DocumentBaselineSpec extends Omit<DocumentBaseline<any>, 'snapshot'> {
7
- snapshot: string;
8
- libraryId: string;
9
- }
10
- export interface ReplicaInfoSpec extends ReplicaInfo {
11
- libraryId: string;
12
- clientId: string;
13
- lastSeenWallClockTime: number | null;
14
- type: ReplicaType;
15
- ackedServerOrder: number;
16
- }
17
- declare global {
18
- interface File {
19
- readonly lastModified: number;
20
- readonly name: string;
21
- }
22
- }
1
+ import { DocumentBaseline, Operation, ReplicaInfo, ReplicaType } from '@verdant-web/common';
2
+ export interface OperationSpec extends Operation {
3
+ serverOrder: number;
4
+ replicaId: string;
5
+ }
6
+ export interface DocumentBaselineSpec extends Omit<DocumentBaseline<any>, 'snapshot'> {
7
+ snapshot: string;
8
+ libraryId: string;
9
+ }
10
+ export interface ReplicaInfoSpec extends ReplicaInfo {
11
+ libraryId: string;
12
+ clientId: string;
13
+ lastSeenWallClockTime: number | null;
14
+ type: ReplicaType;
15
+ ackedServerOrder: number;
16
+ }
17
+ declare global {
18
+ interface File {
19
+ readonly lastModified: number;
20
+ readonly name: string;
21
+ }
22
+ }
package/dist/cjs/types.js CHANGED
@@ -1,3 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  //# sourceMappingURL=types.js.map
@@ -1,15 +1,15 @@
1
- import { DocumentBaseline, Operation, Ref } from '@verdant-web/common';
2
- import { Database } from 'better-sqlite3';
3
- export declare class Baselines {
4
- private db;
5
- constructor(db: Database);
6
- get: (libraryId: string, oid: string) => DocumentBaseline<any> | null;
7
- getAllWithSubObjects: (libraryId: string, oid: string) => DocumentBaseline<any>[];
8
- set: (libraryId: string, baseline: DocumentBaseline) => import("better-sqlite3").RunResult;
9
- insertAll: (libraryId: string, baselines: DocumentBaseline[]) => void;
10
- private hydrateSnapshot;
11
- getAllAfter: (libraryId: string, timestamp: string | null) => DocumentBaseline<any>[];
12
- applyOperations: (libraryId: string, oid: string, operations: Operation[], deletedRefs?: Ref[]) => never[] | undefined;
13
- deleteAll: (libraryId: string) => void;
14
- getCount: (libraryId: string) => number;
15
- }
1
+ import { DocumentBaseline, Operation, Ref } from '@verdant-web/common';
2
+ import { Database } from 'better-sqlite3';
3
+ export declare class Baselines {
4
+ private db;
5
+ constructor(db: Database);
6
+ get: (libraryId: string, oid: string) => DocumentBaseline<any> | null;
7
+ getAllWithSubObjects: (libraryId: string, oid: string) => DocumentBaseline<any>[];
8
+ set: (libraryId: string, baseline: DocumentBaseline) => import("better-sqlite3").RunResult;
9
+ insertAll: (libraryId: string, baselines: DocumentBaseline[]) => void;
10
+ private hydrateSnapshot;
11
+ getAllAfter: (libraryId: string, timestamp: string | null) => DocumentBaseline<any>[];
12
+ applyOperations: (libraryId: string, oid: string, operations: Operation[], deletedRefs?: Ref[]) => never[] | undefined;
13
+ deleteAll: (libraryId: string) => void;
14
+ getCount: (libraryId: string) => number;
15
+ }
@@ -1,106 +1,106 @@
1
- import { applyPatch, } from '@verdant-web/common';
2
- export class Baselines {
3
- constructor(db) {
4
- this.db = db;
5
- this.get = (libraryId, oid) => {
6
- const row = this.db
1
+ import { applyPatch, } from '@verdant-web/common';
2
+ export class Baselines {
3
+ constructor(db) {
4
+ this.db = db;
5
+ this.get = (libraryId, oid) => {
6
+ const row = this.db
7
7
  .prepare(`
8
8
  SELECT * FROM DocumentBaseline
9
9
  WHERE libraryId = ? AND oid = ?
10
- `)
11
- .get(libraryId, oid);
12
- if (!row) {
13
- return null;
14
- }
15
- return this.hydrateSnapshot(row);
16
- };
17
- this.getAllWithSubObjects = (libraryId, oid) => {
18
- const rows = this.db
10
+ `)
11
+ .get(libraryId, oid);
12
+ if (!row) {
13
+ return null;
14
+ }
15
+ return this.hydrateSnapshot(row);
16
+ };
17
+ this.getAllWithSubObjects = (libraryId, oid) => {
18
+ const rows = this.db
19
19
  .prepare(`
20
20
  SELECT * FROM DocumentBaseline
21
21
  WHERE libraryId = ? AND oid LIKE ?
22
- `)
23
- .all(libraryId, `${oid}%`);
24
- return rows.map(this.hydrateSnapshot);
25
- };
26
- this.set = (libraryId, baseline) => {
27
- return this.db
22
+ `)
23
+ .all(libraryId, `${oid}%`);
24
+ return rows.map(this.hydrateSnapshot);
25
+ };
26
+ this.set = (libraryId, baseline) => {
27
+ return this.db
28
28
  .prepare(`
29
29
  INSERT OR REPLACE INTO DocumentBaseline (libraryId, oid, snapshot, timestamp)
30
30
  VALUES (?, ?, ?, ?)
31
- `)
32
- .run(libraryId, baseline.oid, JSON.stringify(baseline.snapshot), baseline.timestamp);
33
- };
34
- this.insertAll = (libraryId, baselines) => {
35
- const tx = this.db.transaction(() => {
36
- for (const baseline of baselines) {
37
- this.db
31
+ `)
32
+ .run(libraryId, baseline.oid, JSON.stringify(baseline.snapshot), baseline.timestamp);
33
+ };
34
+ this.insertAll = (libraryId, baselines) => {
35
+ const tx = this.db.transaction(() => {
36
+ for (const baseline of baselines) {
37
+ this.db
38
38
  .prepare(`
39
39
  INSERT OR REPLACE INTO DocumentBaseline (libraryId, oid, snapshot, timestamp)
40
40
  VALUES (?, ?, ?, ?)
41
- `)
42
- .run(libraryId, baseline.oid, JSON.stringify(baseline.snapshot), baseline.timestamp);
43
- }
44
- });
45
- tx();
46
- };
47
- this.hydrateSnapshot = (snapshot) => {
48
- return Object.assign(Object.assign({}, snapshot), { snapshot: JSON.parse(snapshot.snapshot) });
49
- };
50
- this.getAllAfter = (libraryId, timestamp) => {
51
- if (!timestamp) {
52
- return this.db
41
+ `)
42
+ .run(libraryId, baseline.oid, JSON.stringify(baseline.snapshot), baseline.timestamp);
43
+ }
44
+ });
45
+ tx();
46
+ };
47
+ this.hydrateSnapshot = (snapshot) => {
48
+ return Object.assign(Object.assign({}, snapshot), { snapshot: JSON.parse(snapshot.snapshot) });
49
+ };
50
+ this.getAllAfter = (libraryId, timestamp) => {
51
+ if (!timestamp) {
52
+ return this.db
53
53
  .prepare(`
54
54
  SELECT * FROM DocumentBaseline
55
55
  WHERE libraryId = ?
56
56
  ORDER BY timestamp ASC
57
- `)
58
- .all(libraryId)
59
- .map(this.hydrateSnapshot);
60
- }
61
- return this.db
57
+ `)
58
+ .all(libraryId)
59
+ .map(this.hydrateSnapshot);
60
+ }
61
+ return this.db
62
62
  .prepare(`
63
63
  SELECT * FROM DocumentBaseline
64
64
  WHERE libraryId = ? AND timestamp > ?
65
65
  ORDER BY timestamp ASC
66
- `)
67
- .all(libraryId, timestamp)
68
- .map(this.hydrateSnapshot);
69
- };
70
- this.applyOperations = (libraryId, oid, operations, deletedRefs) => {
71
- if (operations.length === 0)
72
- return [];
73
- let baseline = this.get(libraryId, oid);
74
- if (!baseline) {
75
- baseline = {
76
- oid,
77
- snapshot: {},
78
- timestamp: operations[0].timestamp,
79
- };
80
- }
81
- for (const operation of operations) {
82
- baseline.snapshot = applyPatch(baseline.snapshot, operation.data, deletedRefs);
83
- }
84
- baseline.timestamp = operations[operations.length - 1].timestamp;
85
- this.set(libraryId, baseline);
86
- };
87
- this.deleteAll = (libraryId) => {
88
- this.db
66
+ `)
67
+ .all(libraryId, timestamp)
68
+ .map(this.hydrateSnapshot);
69
+ };
70
+ this.applyOperations = (libraryId, oid, operations, deletedRefs) => {
71
+ if (operations.length === 0)
72
+ return [];
73
+ let baseline = this.get(libraryId, oid);
74
+ if (!baseline) {
75
+ baseline = {
76
+ oid,
77
+ snapshot: {},
78
+ timestamp: operations[0].timestamp,
79
+ };
80
+ }
81
+ for (const operation of operations) {
82
+ baseline.snapshot = applyPatch(baseline.snapshot, operation.data, deletedRefs);
83
+ }
84
+ baseline.timestamp = operations[operations.length - 1].timestamp;
85
+ this.set(libraryId, baseline);
86
+ };
87
+ this.deleteAll = (libraryId) => {
88
+ this.db
89
89
  .prepare(`
90
90
  DELETE FROM DocumentBaseline
91
91
  WHERE libraryId = ?
92
- `)
93
- .run(libraryId);
94
- };
95
- this.getCount = (libraryId) => {
96
- var _a, _b;
97
- return ((_b = (_a = this.db
92
+ `)
93
+ .run(libraryId);
94
+ };
95
+ this.getCount = (libraryId) => {
96
+ var _a, _b;
97
+ return ((_b = (_a = this.db
98
98
  .prepare(`
99
99
  SELECT COUNT(*) AS count FROM DocumentBaseline
100
100
  WHERE libraryId = ?
101
- `)
102
- .get(libraryId)) === null || _a === void 0 ? void 0 : _a.count) !== null && _b !== void 0 ? _b : 0);
103
- };
104
- }
105
- }
101
+ `)
102
+ .get(libraryId)) === null || _a === void 0 ? void 0 : _a.count) !== null && _b !== void 0 ? _b : 0);
103
+ };
104
+ }
105
+ }
106
106
  //# sourceMappingURL=Baselines.js.map
@@ -1,18 +1,18 @@
1
- import { ServerMessage } from '@verdant-web/common';
2
- import { IncomingMessage, ServerResponse } from 'http';
3
- import { WebSocket } from 'ws';
4
- import { TokenInfo } from './TokenVerifier.js';
5
- export declare class ClientConnectionManager {
6
- private readonly connections;
7
- private getLibraryConnections;
8
- addSocket: (libraryId: string, key: string, socket: WebSocket, info: TokenInfo) => void;
9
- addRequest: (libraryId: string, key: string, request: IncomingMessage, response: ServerResponse, info: TokenInfo) => () => void;
10
- remove: (libraryId: string, key: string) => void;
11
- respond: (libraryId: string, key: string, message: ServerMessage) => void;
12
- /**
13
- * Broadcasts a message to all live-connected clients in a library.
14
- * This does not reach push/pull clients.
15
- */
16
- broadcast: (libraryId: string, message: ServerMessage, omitKeys?: string[]) => void;
17
- disconnectAll: (libraryId: string) => void;
18
- }
1
+ import { ServerMessage } from '@verdant-web/common';
2
+ import { IncomingMessage, ServerResponse } from 'http';
3
+ import { WebSocket } from 'ws';
4
+ import { TokenInfo } from './TokenVerifier.js';
5
+ export declare class ClientConnectionManager {
6
+ private readonly connections;
7
+ private getLibraryConnections;
8
+ addSocket: (libraryId: string, key: string, socket: WebSocket, info: TokenInfo) => void;
9
+ addRequest: (libraryId: string, key: string, request: IncomingMessage, response: ServerResponse, info: TokenInfo) => () => void;
10
+ remove: (libraryId: string, key: string) => void;
11
+ respond: (libraryId: string, key: string, message: ServerMessage) => void;
12
+ /**
13
+ * Broadcasts a message to all live-connected clients in a library.
14
+ * This does not reach push/pull clients.
15
+ */
16
+ broadcast: (libraryId: string, message: ServerMessage, omitKeys?: string[]) => void;
17
+ disconnectAll: (libraryId: string) => void;
18
+ }
@@ -1,102 +1,102 @@
1
- class ClientConnection {
2
- constructor(key) {
3
- this.key = key;
4
- }
5
- }
6
- class RequestClientConnection extends ClientConnection {
7
- constructor(key, req, res, info) {
8
- super(key);
9
- this.req = req;
10
- this.res = res;
11
- this.info = info;
12
- this.type = 'request';
13
- this.responses = [];
14
- this.respond = (message) => {
15
- this.responses.push(message);
16
- };
17
- this.end = () => {
18
- this.res.writeHead(200, {
19
- 'Content-Type': 'application/json',
20
- });
21
- this.res.write(JSON.stringify({
22
- messages: this.responses,
23
- }));
24
- this.res.end();
25
- };
26
- }
27
- }
28
- class WebSocketClientConnection extends ClientConnection {
29
- constructor(key, ws, info) {
30
- super(key);
31
- this.ws = ws;
32
- this.info = info;
33
- this.type = 'websocket';
34
- this.respond = (message) => {
35
- this.ws.send(JSON.stringify(message));
36
- };
37
- }
38
- }
39
- export class ClientConnectionManager {
40
- constructor() {
41
- this.connections = {};
42
- this.getLibraryConnections = (libraryId) => {
43
- if (!this.connections[libraryId]) {
44
- this.connections[libraryId] = new Map();
45
- }
46
- return this.connections[libraryId];
47
- };
48
- this.addSocket = (libraryId, key, socket, info) => {
49
- const lib = this.getLibraryConnections(libraryId);
50
- const connection = new WebSocketClientConnection(key, socket, info);
51
- lib.set(key, connection);
52
- socket.on('close', () => {
53
- lib.delete(key);
54
- });
55
- };
56
- this.addRequest = (libraryId, key, request, response, info) => {
57
- const lib = this.getLibraryConnections(libraryId);
58
- const connection = new RequestClientConnection(key, request, response, info);
59
- lib.set(key, connection);
60
- return () => {
61
- connection.end();
62
- lib.delete(key);
63
- };
64
- };
65
- this.remove = (libraryId, key) => {
66
- const lib = this.getLibraryConnections(libraryId);
67
- lib.delete(key);
68
- };
69
- this.respond = (libraryId, key, message) => {
70
- const lib = this.getLibraryConnections(libraryId);
71
- const connection = lib.get(key);
72
- if (connection) {
73
- connection.respond(message);
74
- }
75
- else {
76
- throw new Error(`No connection found for library ${libraryId}, key ${key}`);
77
- }
78
- };
79
- /**
80
- * Broadcasts a message to all live-connected clients in a library.
81
- * This does not reach push/pull clients.
82
- */
83
- this.broadcast = (libraryId, message, omitKeys = []) => {
84
- const lib = this.getLibraryConnections(libraryId);
85
- for (const [key, connection] of lib) {
86
- if (!omitKeys.includes(key)) {
87
- connection.respond(message);
88
- }
89
- }
90
- };
91
- this.disconnectAll = (libraryId) => {
92
- const lib = this.getLibraryConnections(libraryId);
93
- for (const connection of lib.values()) {
94
- if (connection instanceof WebSocketClientConnection) {
95
- connection.ws.close();
96
- }
97
- }
98
- lib.clear();
99
- };
100
- }
101
- }
1
+ class ClientConnection {
2
+ constructor(key) {
3
+ this.key = key;
4
+ }
5
+ }
6
+ class RequestClientConnection extends ClientConnection {
7
+ constructor(key, req, res, info) {
8
+ super(key);
9
+ this.req = req;
10
+ this.res = res;
11
+ this.info = info;
12
+ this.type = 'request';
13
+ this.responses = [];
14
+ this.respond = (message) => {
15
+ this.responses.push(message);
16
+ };
17
+ this.end = () => {
18
+ this.res.writeHead(200, {
19
+ 'Content-Type': 'application/json',
20
+ });
21
+ this.res.write(JSON.stringify({
22
+ messages: this.responses,
23
+ }));
24
+ this.res.end();
25
+ };
26
+ }
27
+ }
28
+ class WebSocketClientConnection extends ClientConnection {
29
+ constructor(key, ws, info) {
30
+ super(key);
31
+ this.ws = ws;
32
+ this.info = info;
33
+ this.type = 'websocket';
34
+ this.respond = (message) => {
35
+ this.ws.send(JSON.stringify(message));
36
+ };
37
+ }
38
+ }
39
+ export class ClientConnectionManager {
40
+ constructor() {
41
+ this.connections = {};
42
+ this.getLibraryConnections = (libraryId) => {
43
+ if (!this.connections[libraryId]) {
44
+ this.connections[libraryId] = new Map();
45
+ }
46
+ return this.connections[libraryId];
47
+ };
48
+ this.addSocket = (libraryId, key, socket, info) => {
49
+ const lib = this.getLibraryConnections(libraryId);
50
+ const connection = new WebSocketClientConnection(key, socket, info);
51
+ lib.set(key, connection);
52
+ socket.on('close', () => {
53
+ lib.delete(key);
54
+ });
55
+ };
56
+ this.addRequest = (libraryId, key, request, response, info) => {
57
+ const lib = this.getLibraryConnections(libraryId);
58
+ const connection = new RequestClientConnection(key, request, response, info);
59
+ lib.set(key, connection);
60
+ return () => {
61
+ connection.end();
62
+ lib.delete(key);
63
+ };
64
+ };
65
+ this.remove = (libraryId, key) => {
66
+ const lib = this.getLibraryConnections(libraryId);
67
+ lib.delete(key);
68
+ };
69
+ this.respond = (libraryId, key, message) => {
70
+ const lib = this.getLibraryConnections(libraryId);
71
+ const connection = lib.get(key);
72
+ if (connection) {
73
+ connection.respond(message);
74
+ }
75
+ else {
76
+ throw new Error(`No connection found for library ${libraryId}, key ${key}`);
77
+ }
78
+ };
79
+ /**
80
+ * Broadcasts a message to all live-connected clients in a library.
81
+ * This does not reach push/pull clients.
82
+ */
83
+ this.broadcast = (libraryId, message, omitKeys = []) => {
84
+ const lib = this.getLibraryConnections(libraryId);
85
+ for (const [key, connection] of lib) {
86
+ if (!omitKeys.includes(key)) {
87
+ connection.respond(message);
88
+ }
89
+ }
90
+ };
91
+ this.disconnectAll = (libraryId) => {
92
+ const lib = this.getLibraryConnections(libraryId);
93
+ for (const connection of lib.values()) {
94
+ if (connection instanceof WebSocketClientConnection) {
95
+ connection.ws.close();
96
+ }
97
+ }
98
+ lib.clear();
99
+ };
100
+ }
101
+ }
102
102
  //# sourceMappingURL=ClientConnection.js.map
@@ -1,5 +1,5 @@
1
- import { ServerMessage } from '@verdant-web/common';
2
- export interface MessageSender {
3
- broadcast(libraryId: string, message: ServerMessage, omitKeys?: string[]): void;
4
- send(libraryId: string, clientKey: string, message: ServerMessage): void;
5
- }
1
+ import { ServerMessage } from '@verdant-web/common';
2
+ export interface MessageSender {
3
+ broadcast(libraryId: string, message: ServerMessage, omitKeys?: string[]): void;
4
+ send(libraryId: string, clientKey: string, message: ServerMessage): void;
5
+ }
@@ -1,2 +1,2 @@
1
- export {};
1
+ export {};
2
2
  //# sourceMappingURL=MessageSender.js.map