@powersync/service-core 0.0.0-dev-20241128134723 → 0.0.0-dev-20241219091224

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 (188) hide show
  1. package/CHANGELOG.md +63 -4
  2. package/dist/auth/KeySpec.d.ts +1 -0
  3. package/dist/auth/KeySpec.js +10 -8
  4. package/dist/auth/KeySpec.js.map +1 -1
  5. package/dist/auth/RemoteJWKSCollector.js +2 -2
  6. package/dist/auth/RemoteJWKSCollector.js.map +1 -1
  7. package/dist/entry/commands/compact-action.js +15 -15
  8. package/dist/entry/commands/compact-action.js.map +1 -1
  9. package/dist/entry/commands/migrate-action.js +15 -4
  10. package/dist/entry/commands/migrate-action.js.map +1 -1
  11. package/dist/index.d.ts +1 -3
  12. package/dist/index.js +1 -3
  13. package/dist/index.js.map +1 -1
  14. package/dist/migrations/PowerSyncMigrationManager.d.ts +17 -0
  15. package/dist/migrations/PowerSyncMigrationManager.js +22 -0
  16. package/dist/migrations/PowerSyncMigrationManager.js.map +1 -0
  17. package/dist/migrations/ensure-automatic-migrations.d.ts +4 -0
  18. package/dist/migrations/ensure-automatic-migrations.js +14 -0
  19. package/dist/migrations/ensure-automatic-migrations.js.map +1 -0
  20. package/dist/migrations/migrations-index.d.ts +2 -3
  21. package/dist/migrations/migrations-index.js +2 -3
  22. package/dist/migrations/migrations-index.js.map +1 -1
  23. package/dist/routes/RouterEngine.js +2 -1
  24. package/dist/routes/RouterEngine.js.map +1 -1
  25. package/dist/routes/configure-fastify.d.ts +28 -28
  26. package/dist/routes/endpoints/admin.d.ts +24 -24
  27. package/dist/storage/BucketStorage.d.ts +41 -1
  28. package/dist/storage/BucketStorage.js +26 -0
  29. package/dist/storage/BucketStorage.js.map +1 -1
  30. package/dist/storage/storage-index.d.ts +2 -14
  31. package/dist/storage/storage-index.js +2 -14
  32. package/dist/storage/storage-index.js.map +1 -1
  33. package/dist/sync/sync.js +12 -3
  34. package/dist/sync/sync.js.map +1 -1
  35. package/dist/system/ServiceContext.d.ts +3 -0
  36. package/dist/system/ServiceContext.js +11 -3
  37. package/dist/system/ServiceContext.js.map +1 -1
  38. package/dist/util/config/types.d.ts +2 -2
  39. package/dist/util/utils.d.ts +14 -1
  40. package/dist/util/utils.js +56 -0
  41. package/dist/util/utils.js.map +1 -1
  42. package/package.json +6 -7
  43. package/src/auth/KeySpec.ts +12 -9
  44. package/src/auth/RemoteJWKSCollector.ts +2 -2
  45. package/src/entry/commands/compact-action.ts +20 -15
  46. package/src/entry/commands/migrate-action.ts +17 -4
  47. package/src/index.ts +1 -4
  48. package/src/migrations/PowerSyncMigrationManager.ts +43 -0
  49. package/src/migrations/ensure-automatic-migrations.ts +15 -0
  50. package/src/migrations/migrations-index.ts +2 -3
  51. package/src/routes/RouterEngine.ts +2 -1
  52. package/src/storage/BucketStorage.ts +44 -1
  53. package/src/storage/storage-index.ts +3 -15
  54. package/src/sync/sync.ts +12 -3
  55. package/src/system/ServiceContext.ts +17 -4
  56. package/src/util/config/types.ts +2 -2
  57. package/src/util/utils.ts +59 -1
  58. package/test/src/auth.test.ts +54 -21
  59. package/test/src/env.ts +0 -1
  60. package/tsconfig.tsbuildinfo +1 -1
  61. package/dist/db/db-index.d.ts +0 -1
  62. package/dist/db/db-index.js +0 -2
  63. package/dist/db/db-index.js.map +0 -1
  64. package/dist/db/mongo.d.ts +0 -35
  65. package/dist/db/mongo.js +0 -73
  66. package/dist/db/mongo.js.map +0 -1
  67. package/dist/locks/LockManager.d.ts +0 -10
  68. package/dist/locks/LockManager.js +0 -7
  69. package/dist/locks/LockManager.js.map +0 -1
  70. package/dist/locks/MongoLocks.d.ts +0 -36
  71. package/dist/locks/MongoLocks.js +0 -81
  72. package/dist/locks/MongoLocks.js.map +0 -1
  73. package/dist/locks/locks-index.d.ts +0 -2
  74. package/dist/locks/locks-index.js +0 -3
  75. package/dist/locks/locks-index.js.map +0 -1
  76. package/dist/migrations/db/migrations/1684951997326-init.d.ts +0 -3
  77. package/dist/migrations/db/migrations/1684951997326-init.js +0 -33
  78. package/dist/migrations/db/migrations/1684951997326-init.js.map +0 -1
  79. package/dist/migrations/db/migrations/1688556755264-initial-sync-rules.d.ts +0 -2
  80. package/dist/migrations/db/migrations/1688556755264-initial-sync-rules.js +0 -5
  81. package/dist/migrations/db/migrations/1688556755264-initial-sync-rules.js.map +0 -1
  82. package/dist/migrations/db/migrations/1702295701188-sync-rule-state.d.ts +0 -3
  83. package/dist/migrations/db/migrations/1702295701188-sync-rule-state.js +0 -56
  84. package/dist/migrations/db/migrations/1702295701188-sync-rule-state.js.map +0 -1
  85. package/dist/migrations/db/migrations/1711543888062-write-checkpoint-index.d.ts +0 -3
  86. package/dist/migrations/db/migrations/1711543888062-write-checkpoint-index.js +0 -29
  87. package/dist/migrations/db/migrations/1711543888062-write-checkpoint-index.js.map +0 -1
  88. package/dist/migrations/db/migrations/1727099539247-custom-write-checkpoint-index.d.ts +0 -3
  89. package/dist/migrations/db/migrations/1727099539247-custom-write-checkpoint-index.js +0 -31
  90. package/dist/migrations/db/migrations/1727099539247-custom-write-checkpoint-index.js.map +0 -1
  91. package/dist/migrations/definitions.d.ts +0 -18
  92. package/dist/migrations/definitions.js +0 -6
  93. package/dist/migrations/definitions.js.map +0 -1
  94. package/dist/migrations/executor.d.ts +0 -16
  95. package/dist/migrations/executor.js +0 -64
  96. package/dist/migrations/executor.js.map +0 -1
  97. package/dist/migrations/migrations.d.ts +0 -18
  98. package/dist/migrations/migrations.js +0 -110
  99. package/dist/migrations/migrations.js.map +0 -1
  100. package/dist/migrations/store/migration-store.d.ts +0 -11
  101. package/dist/migrations/store/migration-store.js +0 -46
  102. package/dist/migrations/store/migration-store.js.map +0 -1
  103. package/dist/storage/MongoBucketStorage.d.ts +0 -48
  104. package/dist/storage/MongoBucketStorage.js +0 -426
  105. package/dist/storage/MongoBucketStorage.js.map +0 -1
  106. package/dist/storage/mongo/MongoBucketBatch.d.ts +0 -67
  107. package/dist/storage/mongo/MongoBucketBatch.js +0 -643
  108. package/dist/storage/mongo/MongoBucketBatch.js.map +0 -1
  109. package/dist/storage/mongo/MongoCompactor.d.ts +0 -40
  110. package/dist/storage/mongo/MongoCompactor.js +0 -309
  111. package/dist/storage/mongo/MongoCompactor.js.map +0 -1
  112. package/dist/storage/mongo/MongoIdSequence.d.ts +0 -12
  113. package/dist/storage/mongo/MongoIdSequence.js +0 -21
  114. package/dist/storage/mongo/MongoIdSequence.js.map +0 -1
  115. package/dist/storage/mongo/MongoPersistedSyncRules.d.ts +0 -9
  116. package/dist/storage/mongo/MongoPersistedSyncRules.js +0 -9
  117. package/dist/storage/mongo/MongoPersistedSyncRules.js.map +0 -1
  118. package/dist/storage/mongo/MongoPersistedSyncRulesContent.d.ts +0 -20
  119. package/dist/storage/mongo/MongoPersistedSyncRulesContent.js +0 -26
  120. package/dist/storage/mongo/MongoPersistedSyncRulesContent.js.map +0 -1
  121. package/dist/storage/mongo/MongoStorageProvider.d.ts +0 -5
  122. package/dist/storage/mongo/MongoStorageProvider.js +0 -26
  123. package/dist/storage/mongo/MongoStorageProvider.js.map +0 -1
  124. package/dist/storage/mongo/MongoSyncBucketStorage.d.ts +0 -38
  125. package/dist/storage/mongo/MongoSyncBucketStorage.js +0 -531
  126. package/dist/storage/mongo/MongoSyncBucketStorage.js.map +0 -1
  127. package/dist/storage/mongo/MongoSyncRulesLock.d.ts +0 -16
  128. package/dist/storage/mongo/MongoSyncRulesLock.js +0 -65
  129. package/dist/storage/mongo/MongoSyncRulesLock.js.map +0 -1
  130. package/dist/storage/mongo/MongoWriteCheckpointAPI.d.ts +0 -20
  131. package/dist/storage/mongo/MongoWriteCheckpointAPI.js +0 -103
  132. package/dist/storage/mongo/MongoWriteCheckpointAPI.js.map +0 -1
  133. package/dist/storage/mongo/OperationBatch.d.ts +0 -35
  134. package/dist/storage/mongo/OperationBatch.js +0 -119
  135. package/dist/storage/mongo/OperationBatch.js.map +0 -1
  136. package/dist/storage/mongo/PersistedBatch.d.ts +0 -46
  137. package/dist/storage/mongo/PersistedBatch.js +0 -213
  138. package/dist/storage/mongo/PersistedBatch.js.map +0 -1
  139. package/dist/storage/mongo/config.d.ts +0 -19
  140. package/dist/storage/mongo/config.js +0 -26
  141. package/dist/storage/mongo/config.js.map +0 -1
  142. package/dist/storage/mongo/db.d.ts +0 -36
  143. package/dist/storage/mongo/db.js +0 -47
  144. package/dist/storage/mongo/db.js.map +0 -1
  145. package/dist/storage/mongo/models.d.ts +0 -156
  146. package/dist/storage/mongo/models.js +0 -27
  147. package/dist/storage/mongo/models.js.map +0 -1
  148. package/dist/storage/mongo/util.d.ts +0 -40
  149. package/dist/storage/mongo/util.js +0 -151
  150. package/dist/storage/mongo/util.js.map +0 -1
  151. package/src/db/db-index.ts +0 -1
  152. package/src/db/mongo.ts +0 -81
  153. package/src/locks/LockManager.ts +0 -16
  154. package/src/locks/MongoLocks.ts +0 -142
  155. package/src/locks/locks-index.ts +0 -2
  156. package/src/migrations/db/migrations/1684951997326-init.ts +0 -38
  157. package/src/migrations/db/migrations/1688556755264-initial-sync-rules.ts +0 -5
  158. package/src/migrations/db/migrations/1702295701188-sync-rule-state.ts +0 -102
  159. package/src/migrations/db/migrations/1711543888062-write-checkpoint-index.ts +0 -34
  160. package/src/migrations/db/migrations/1727099539247-custom-write-checkpoint-index.ts +0 -37
  161. package/src/migrations/definitions.ts +0 -21
  162. package/src/migrations/executor.ts +0 -87
  163. package/src/migrations/migrations.ts +0 -142
  164. package/src/migrations/store/migration-store.ts +0 -63
  165. package/src/storage/MongoBucketStorage.ts +0 -540
  166. package/src/storage/mongo/MongoBucketBatch.ts +0 -841
  167. package/src/storage/mongo/MongoCompactor.ts +0 -392
  168. package/src/storage/mongo/MongoIdSequence.ts +0 -24
  169. package/src/storage/mongo/MongoPersistedSyncRules.ts +0 -16
  170. package/src/storage/mongo/MongoPersistedSyncRulesContent.ts +0 -50
  171. package/src/storage/mongo/MongoStorageProvider.ts +0 -31
  172. package/src/storage/mongo/MongoSyncBucketStorage.ts +0 -636
  173. package/src/storage/mongo/MongoSyncRulesLock.ts +0 -85
  174. package/src/storage/mongo/MongoWriteCheckpointAPI.ts +0 -151
  175. package/src/storage/mongo/OperationBatch.ts +0 -131
  176. package/src/storage/mongo/PersistedBatch.ts +0 -272
  177. package/src/storage/mongo/config.ts +0 -40
  178. package/src/storage/mongo/db.ts +0 -88
  179. package/src/storage/mongo/models.ts +0 -179
  180. package/src/storage/mongo/util.ts +0 -158
  181. package/test/src/__snapshots__/sync.test.ts.snap +0 -332
  182. package/test/src/bucket_validation.test.ts +0 -142
  183. package/test/src/bucket_validation.ts +0 -116
  184. package/test/src/compacting.test.ts +0 -295
  185. package/test/src/data_storage.test.ts +0 -1499
  186. package/test/src/stream_utils.ts +0 -42
  187. package/test/src/sync.test.ts +0 -511
  188. package/test/src/util.ts +0 -148
@@ -1,179 +0,0 @@
1
- import { SqliteJsonValue } from '@powersync/service-sync-rules';
2
- import * as bson from 'bson';
3
-
4
- /**
5
- * Replica id uniquely identifying a row on the source database.
6
- *
7
- * Can be any value serializable to BSON.
8
- *
9
- * If the value is an entire document, the data serialized to a v5 UUID may be a good choice here.
10
- */
11
- export type ReplicaId = bson.UUID | bson.Document | any;
12
-
13
- export interface SourceKey {
14
- /** group_id */
15
- g: number;
16
- /** source table id */
17
- t: bson.ObjectId;
18
- /** source key */
19
- k: ReplicaId;
20
- }
21
-
22
- export interface BucketDataKey {
23
- /** group_id */
24
- g: number;
25
- /** bucket name */
26
- b: string;
27
- /** op_id */
28
- o: bigint;
29
- }
30
-
31
- export interface CurrentDataDocument {
32
- _id: SourceKey;
33
- data: bson.Binary;
34
- buckets: CurrentBucket[];
35
- lookups: bson.Binary[];
36
- }
37
-
38
- export interface CurrentBucket {
39
- bucket: string;
40
- table: string;
41
- id: string;
42
- }
43
-
44
- export interface BucketParameterDocument {
45
- _id: bigint;
46
- key: SourceKey;
47
- lookup: bson.Binary;
48
- bucket_parameters: Record<string, SqliteJsonValue>[];
49
- }
50
-
51
- export interface BucketDataDocument {
52
- _id: BucketDataKey;
53
- op: OpType;
54
- source_table?: bson.ObjectId;
55
- source_key?: ReplicaId;
56
- table?: string;
57
- row_id?: string;
58
- checksum: number;
59
- data: string | null;
60
- target_op?: bigint | null;
61
- }
62
-
63
- export type OpType = 'PUT' | 'REMOVE' | 'MOVE' | 'CLEAR';
64
-
65
- export interface SourceTableDocument {
66
- _id: bson.ObjectId;
67
- group_id: number;
68
- connection_id: number;
69
- relation_id: number | string | undefined;
70
- schema_name: string;
71
- table_name: string;
72
- replica_id_columns: string[] | null;
73
- replica_id_columns2: { name: string; type_oid?: number; type?: string }[] | undefined;
74
- snapshot_done: boolean | undefined;
75
- }
76
-
77
- export interface IdSequenceDocument {
78
- _id: string;
79
- op_id: bigint;
80
- }
81
-
82
- export enum SyncRuleState {
83
- /**
84
- * New sync rules - needs to be processed (initial replication).
85
- *
86
- * While multiple sets of sync rules _can_ be in PROCESSING,
87
- * it's generally pointless, so we only keep one in that state.
88
- */
89
- PROCESSING = 'PROCESSING',
90
-
91
- /**
92
- * Sync rule processing is done, and can be used for sync.
93
- *
94
- * Only one set of sync rules should be in ACTIVE state.
95
- */
96
- ACTIVE = 'ACTIVE',
97
- /**
98
- * This state is used when the sync rules has been replaced,
99
- * and replication is or should be stopped.
100
- */
101
- STOP = 'STOP',
102
- /**
103
- * After sync rules have been stopped, the data needs to be
104
- * deleted. Once deleted, the state is TERMINATED.
105
- */
106
- TERMINATED = 'TERMINATED'
107
- }
108
-
109
- export interface SyncRuleDocument {
110
- _id: number;
111
-
112
- state: SyncRuleState;
113
-
114
- /**
115
- * True if initial snapshot has been replicated.
116
- *
117
- * Can only be false if state == PROCESSING.
118
- */
119
- snapshot_done: boolean;
120
-
121
- /**
122
- * The last consistent checkpoint.
123
- *
124
- * There may be higher OpIds used in the database if we're in the middle of replicating a large transaction.
125
- */
126
- last_checkpoint: bigint | null;
127
-
128
- /**
129
- * The LSN associated with the last consistent checkpoint.
130
- */
131
- last_checkpoint_lsn: string | null;
132
-
133
- /**
134
- * If set, no new checkpoints may be created < this value.
135
- */
136
- no_checkpoint_before: string | null;
137
-
138
- slot_name: string | null;
139
-
140
- /**
141
- * Last time we persisted a checkpoint.
142
- *
143
- * This may be old if no data is incoming.
144
- */
145
- last_checkpoint_ts: Date | null;
146
-
147
- /**
148
- * Last time we persisted a checkpoint or keepalive.
149
- *
150
- * This should stay fairly current while replicating.
151
- */
152
- last_keepalive_ts: Date | null;
153
-
154
- /**
155
- * If an error is stopping replication, it will be stored here.
156
- */
157
- last_fatal_error: string | null;
158
-
159
- content: string;
160
- }
161
-
162
- export interface CustomWriteCheckpointDocument {
163
- _id: bson.ObjectId;
164
- user_id: string;
165
- checkpoint: bigint;
166
- sync_rules_id: number;
167
- }
168
-
169
- export interface WriteCheckpointDocument {
170
- _id: bson.ObjectId;
171
- user_id: string;
172
- lsns: Record<string, string>;
173
- client_id: bigint;
174
- }
175
-
176
- export interface InstanceDocument {
177
- // The instance UUID
178
- _id: string;
179
- }
@@ -1,158 +0,0 @@
1
- import { SqliteJsonValue } from '@powersync/service-sync-rules';
2
- import * as bson from 'bson';
3
- import * as crypto from 'crypto';
4
- import * as mongo from 'mongodb';
5
- import * as uuid from 'uuid';
6
- import { OplogEntry } from '../../util/protocol-types.js';
7
- import { ID_NAMESPACE, timestampToOpId } from '../../util/utils.js';
8
- import { BucketDataDocument, ReplicaId } from './models.js';
9
-
10
- /**
11
- * Lookup serialization must be number-agnostic. I.e. normalize numbers, instead of preserving numbers.
12
- * @param lookup
13
- */
14
-
15
- export function serializeLookup(lookup: SqliteJsonValue[]) {
16
- const normalized = lookup.map((value) => {
17
- if (typeof value == 'number' && Number.isInteger(value)) {
18
- return BigInt(value);
19
- } else {
20
- return value;
21
- }
22
- });
23
- return new bson.Binary(bson.serialize({ l: normalized }));
24
- }
25
-
26
- export function idPrefixFilter<T>(prefix: Partial<T>, rest: (keyof T)[]): mongo.Condition<T> {
27
- let filter = {
28
- $gte: {
29
- ...prefix
30
- } as any,
31
- $lt: {
32
- ...prefix
33
- } as any
34
- };
35
-
36
- for (let key of rest) {
37
- filter.$gte[key] = new bson.MinKey();
38
- filter.$lt[key] = new bson.MaxKey();
39
- }
40
-
41
- return filter;
42
- }
43
-
44
- export function generateSlotName(prefix: string, sync_rules_id: number) {
45
- const slot_suffix = crypto.randomBytes(2).toString('hex');
46
- return `${prefix}${sync_rules_id}_${slot_suffix}`;
47
- }
48
-
49
- /**
50
- * Read a single batch of data from a cursor, then close it.
51
- *
52
- * We do our best to avoid MongoDB fetching any more data than this single batch.
53
- *
54
- * This is similar to using `singleBatch: true` in find options.
55
- * However, that makes `has_more` detection very difficult, since the cursor is always closed
56
- * after the first batch. Instead, we do a workaround to only fetch a single batch below.
57
- *
58
- * For this to be effective, set batchSize = limit in the find command.
59
- */
60
- export async function readSingleBatch<T>(cursor: mongo.FindCursor<T>): Promise<{ data: T[]; hasMore: boolean }> {
61
- try {
62
- let data: T[];
63
- let hasMore = true;
64
- // Let MongoDB load the first batch of data
65
- const hasAny = await cursor.hasNext();
66
- // Now it's in memory, and we can read it
67
- data = cursor.readBufferedDocuments();
68
- if (!hasAny || cursor.id?.isZero()) {
69
- // A zero id means the cursor is exhaused.
70
- // No results (hasAny == false) means even this batch doesn't have data.
71
- // This should similar results as `await cursor.hasNext()`, but without
72
- // actually fetching the next batch.
73
- //
74
- // Note that it is safe (but slightly inefficient) to return `hasMore: true`
75
- // without there being more data, as long as the next batch
76
- // will return `hasMore: false`.
77
- hasMore = false;
78
- }
79
- return { data, hasMore };
80
- } finally {
81
- // Match the from the cursor iterator logic here:
82
- // https://github.com/mongodb/node-mongodb-native/blob/e02534e7d1c627bf50b85ca39f5995dbf165ad44/src/cursor/abstract_cursor.ts#L327-L331
83
- if (!cursor.closed) {
84
- await cursor.close();
85
- }
86
- }
87
- }
88
-
89
- export const BSON_DESERIALIZE_OPTIONS: bson.DeserializeOptions = {
90
- // use bigint instead of Long
91
- useBigInt64: true
92
- };
93
-
94
- export function mapOpEntry(row: BucketDataDocument): OplogEntry {
95
- if (row.op == 'PUT' || row.op == 'REMOVE') {
96
- return {
97
- op_id: timestampToOpId(row._id.o),
98
- op: row.op,
99
- object_type: row.table,
100
- object_id: row.row_id,
101
- checksum: Number(row.checksum),
102
- subkey: replicaIdToSubkey(row.source_table!, row.source_key!),
103
- data: row.data
104
- };
105
- } else {
106
- // MOVE, CLEAR
107
-
108
- return {
109
- op_id: timestampToOpId(row._id.o),
110
- op: row.op,
111
- checksum: Number(row.checksum)
112
- };
113
- }
114
- }
115
-
116
- /**
117
- * Returns true if two ReplicaId values are the same (serializes to the same BSON value).
118
- */
119
- export function replicaIdEquals(a: ReplicaId, b: ReplicaId) {
120
- if (a === b) {
121
- return true;
122
- } else if (typeof a == 'string' && typeof b == 'string') {
123
- return a == b;
124
- } else if (isUUID(a) && isUUID(b)) {
125
- return a.equals(b);
126
- } else if (a == null && b == null) {
127
- return true;
128
- } else if (a != null || b != null) {
129
- return false;
130
- } else {
131
- // There are many possible primitive values, this covers them all
132
- return (bson.serialize({ id: a }) as Buffer).equals(bson.serialize({ id: b }));
133
- }
134
- }
135
-
136
- export function replicaIdToSubkey(table: bson.ObjectId, id: ReplicaId): string {
137
- if (isUUID(id)) {
138
- // Special case for UUID for backwards-compatiblity
139
- return `${table.toHexString()}/${id.toHexString()}`;
140
- } else {
141
- // Hashed UUID from the table and id
142
- const repr = bson.serialize({ table, id });
143
- return uuid.v5(repr, ID_NAMESPACE);
144
- }
145
- }
146
-
147
- /**
148
- * True if this is a bson.UUID.
149
- *
150
- * Works even with multiple copies of the bson package.
151
- */
152
- export function isUUID(value: any): value is bson.UUID {
153
- if (value == null || typeof value != 'object') {
154
- return false;
155
- }
156
- const uuid = value as bson.UUID;
157
- return uuid._bsontype == 'Binary' && uuid.sub_type == bson.Binary.SUBTYPE_UUID;
158
- }
@@ -1,332 +0,0 @@
1
- // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
-
3
- exports[`sync - mongodb > compacting data - invalidate checkpoint 1`] = `
4
- [
5
- {
6
- "checkpoint": {
7
- "buckets": [
8
- {
9
- "bucket": "mybucket[]",
10
- "checksum": -93886621,
11
- "count": 2,
12
- },
13
- ],
14
- "last_op_id": "2",
15
- "write_checkpoint": undefined,
16
- },
17
- },
18
- ]
19
- `;
20
-
21
- exports[`sync - mongodb > compacting data - invalidate checkpoint 2`] = `
22
- [
23
- {
24
- "data": {
25
- "after": "0",
26
- "bucket": "mybucket[]",
27
- "data": [
28
- {
29
- "checksum": -93886621n,
30
- "op": "CLEAR",
31
- "op_id": "2",
32
- },
33
- ],
34
- "has_more": false,
35
- "next_after": "2",
36
- },
37
- },
38
- {
39
- "checkpoint_diff": {
40
- "last_op_id": "4",
41
- "removed_buckets": [],
42
- "updated_buckets": [
43
- {
44
- "bucket": "mybucket[]",
45
- "checksum": 499012468,
46
- "count": 4,
47
- },
48
- ],
49
- "write_checkpoint": undefined,
50
- },
51
- },
52
- {
53
- "data": {
54
- "after": "2",
55
- "bucket": "mybucket[]",
56
- "data": [
57
- {
58
- "checksum": 1859363232n,
59
- "data": "{"id":"t1","description":"Test 1b"}",
60
- "object_id": "t1",
61
- "object_type": "test",
62
- "op": "PUT",
63
- "op_id": "3",
64
- "subkey": "e5aa2ddc-1328-58fa-a000-0b5ed31eaf1a",
65
- },
66
- {
67
- "checksum": 3028503153n,
68
- "data": "{"id":"t2","description":"Test 2b"}",
69
- "object_id": "t2",
70
- "object_type": "test",
71
- "op": "PUT",
72
- "op_id": "4",
73
- "subkey": "13423353-9f27-59b4-baf0-64a5e09f1769",
74
- },
75
- ],
76
- "has_more": false,
77
- "next_after": "4",
78
- },
79
- },
80
- {
81
- "checkpoint_complete": {
82
- "last_op_id": "4",
83
- },
84
- },
85
- ]
86
- `;
87
-
88
- exports[`sync - mongodb > expired token 1`] = `
89
- [
90
- {
91
- "token_expires_in": 0,
92
- },
93
- ]
94
- `;
95
-
96
- exports[`sync - mongodb > expiring token 1`] = `
97
- [
98
- {
99
- "checkpoint": {
100
- "buckets": [
101
- {
102
- "bucket": "mybucket[]",
103
- "checksum": 0,
104
- "count": 0,
105
- },
106
- ],
107
- "last_op_id": "0",
108
- "write_checkpoint": undefined,
109
- },
110
- },
111
- {
112
- "checkpoint_complete": {
113
- "last_op_id": "0",
114
- },
115
- },
116
- ]
117
- `;
118
-
119
- exports[`sync - mongodb > expiring token 2`] = `
120
- [
121
- {
122
- "token_expires_in": 0,
123
- },
124
- ]
125
- `;
126
-
127
- exports[`sync - mongodb > sync global data 1`] = `
128
- [
129
- {
130
- "checkpoint": {
131
- "buckets": [
132
- {
133
- "bucket": "mybucket[]",
134
- "checksum": -93886621,
135
- "count": 2,
136
- },
137
- ],
138
- "last_op_id": "2",
139
- "write_checkpoint": undefined,
140
- },
141
- },
142
- {
143
- "data": {
144
- "after": "0",
145
- "bucket": "mybucket[]",
146
- "data": [
147
- {
148
- "checksum": 920318466n,
149
- "data": "{"id":"t1","description":"Test 1"}",
150
- "object_id": "t1",
151
- "object_type": "test",
152
- "op": "PUT",
153
- "op_id": "1",
154
- "subkey": "e5aa2ddc-1328-58fa-a000-0b5ed31eaf1a",
155
- },
156
- {
157
- "checksum": 3280762209n,
158
- "data": "{"id":"t2","description":"Test 2"}",
159
- "object_id": "t2",
160
- "object_type": "test",
161
- "op": "PUT",
162
- "op_id": "2",
163
- "subkey": "13423353-9f27-59b4-baf0-64a5e09f1769",
164
- },
165
- ],
166
- "has_more": false,
167
- "next_after": "2",
168
- },
169
- },
170
- {
171
- "checkpoint_complete": {
172
- "last_op_id": "2",
173
- },
174
- },
175
- ]
176
- `;
177
-
178
- exports[`sync - mongodb > sync legacy non-raw data 1`] = `
179
- [
180
- {
181
- "checkpoint": {
182
- "buckets": [
183
- {
184
- "bucket": "mybucket[]",
185
- "checksum": -852817836,
186
- "count": 1,
187
- },
188
- ],
189
- "last_op_id": "1",
190
- "write_checkpoint": undefined,
191
- },
192
- },
193
- {
194
- "data": {
195
- "after": "0",
196
- "bucket": "mybucket[]",
197
- "data": [
198
- {
199
- "checksum": 3442149460n,
200
- "data": {
201
- "description": "Test
202
- "string"",
203
- "id": "t1",
204
- "large_num": 12345678901234567890n,
205
- },
206
- "object_id": "t1",
207
- "object_type": "test",
208
- "op": "PUT",
209
- "op_id": "1",
210
- "subkey": "e5aa2ddc-1328-58fa-a000-0b5ed31eaf1a",
211
- },
212
- ],
213
- "has_more": false,
214
- "next_after": "1",
215
- },
216
- },
217
- {
218
- "checkpoint_complete": {
219
- "last_op_id": "1",
220
- },
221
- },
222
- ]
223
- `;
224
-
225
- exports[`sync - mongodb > sync updates to global data 1`] = `
226
- [
227
- {
228
- "checkpoint": {
229
- "buckets": [
230
- {
231
- "bucket": "mybucket[]",
232
- "checksum": 0,
233
- "count": 0,
234
- },
235
- ],
236
- "last_op_id": "0",
237
- "write_checkpoint": undefined,
238
- },
239
- },
240
- {
241
- "checkpoint_complete": {
242
- "last_op_id": "0",
243
- },
244
- },
245
- ]
246
- `;
247
-
248
- exports[`sync - mongodb > sync updates to global data 2`] = `
249
- [
250
- {
251
- "checkpoint_diff": {
252
- "last_op_id": "1",
253
- "removed_buckets": [],
254
- "updated_buckets": [
255
- {
256
- "bucket": "mybucket[]",
257
- "checksum": 920318466,
258
- "count": 1,
259
- },
260
- ],
261
- "write_checkpoint": undefined,
262
- },
263
- },
264
- {
265
- "data": {
266
- "after": "0",
267
- "bucket": "mybucket[]",
268
- "data": [
269
- {
270
- "checksum": 920318466n,
271
- "data": "{"id":"t1","description":"Test 1"}",
272
- "object_id": "t1",
273
- "object_type": "test",
274
- "op": "PUT",
275
- "op_id": "1",
276
- "subkey": "e5aa2ddc-1328-58fa-a000-0b5ed31eaf1a",
277
- },
278
- ],
279
- "has_more": false,
280
- "next_after": "1",
281
- },
282
- },
283
- {
284
- "checkpoint_complete": {
285
- "last_op_id": "1",
286
- },
287
- },
288
- ]
289
- `;
290
-
291
- exports[`sync - mongodb > sync updates to global data 3`] = `
292
- [
293
- {
294
- "checkpoint_diff": {
295
- "last_op_id": "2",
296
- "removed_buckets": [],
297
- "updated_buckets": [
298
- {
299
- "bucket": "mybucket[]",
300
- "checksum": -93886621,
301
- "count": 2,
302
- },
303
- ],
304
- "write_checkpoint": undefined,
305
- },
306
- },
307
- {
308
- "data": {
309
- "after": "1",
310
- "bucket": "mybucket[]",
311
- "data": [
312
- {
313
- "checksum": 3280762209n,
314
- "data": "{"id":"t2","description":"Test 2"}",
315
- "object_id": "t2",
316
- "object_type": "test",
317
- "op": "PUT",
318
- "op_id": "2",
319
- "subkey": "13423353-9f27-59b4-baf0-64a5e09f1769",
320
- },
321
- ],
322
- "has_more": false,
323
- "next_after": "2",
324
- },
325
- },
326
- {
327
- "checkpoint_complete": {
328
- "last_op_id": "2",
329
- },
330
- },
331
- ]
332
- `;