@powersync/service-core 0.1.1 → 0.1.2

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.
@@ -2,6 +2,7 @@ import { JSONBig } from '@powersync/service-jsonbig';
2
2
  import { EvaluatedParameters, EvaluatedRow } from '@powersync/service-sync-rules';
3
3
  import * as bson from 'bson';
4
4
  import * as mongo from 'mongodb';
5
+ import * as micro from '@journeyapps-platform/micro';
5
6
 
6
7
  import * as util from '@/util/util-index.js';
7
8
  import { SourceTable } from '../SourceTable.js';
@@ -42,6 +43,11 @@ export class PersistedBatch {
42
43
  bucketParameters: mongo.AnyBulkWriteOperation<BucketParameterDocument>[] = [];
43
44
  currentData: mongo.AnyBulkWriteOperation<CurrentDataDocument>[] = [];
44
45
 
46
+ /**
47
+ * For debug logging only.
48
+ */
49
+ debugLastOpId: bigint | null = null;
50
+
45
51
  /**
46
52
  * Very rough estimate of transaction size.
47
53
  */
@@ -75,13 +81,16 @@ export class PersistedBatch {
75
81
  const checksum = util.hashData(k.table, k.id, recordData);
76
82
  this.currentSize += recordData.length + 200;
77
83
 
84
+ const op_id = options.op_seq.next();
85
+ this.debugLastOpId = op_id;
86
+
78
87
  this.bucketData.push({
79
88
  insertOne: {
80
89
  document: {
81
90
  _id: {
82
91
  g: this.group_id,
83
92
  b: k.bucket,
84
- o: options.op_seq.next()
93
+ o: op_id
85
94
  },
86
95
  op: 'PUT',
87
96
  source_table: options.table.id,
@@ -97,13 +106,17 @@ export class PersistedBatch {
97
106
 
98
107
  for (let bd of remaining_buckets.values()) {
99
108
  // REMOVE
109
+
110
+ const op_id = options.op_seq.next();
111
+ this.debugLastOpId = op_id;
112
+
100
113
  this.bucketData.push({
101
114
  insertOne: {
102
115
  document: {
103
116
  _id: {
104
117
  g: this.group_id,
105
118
  b: bd.bucket,
106
- o: options.op_seq.next()
119
+ o: op_id
107
120
  },
108
121
  op: 'REMOVE',
109
122
  source_table: options.table.id,
@@ -145,7 +158,9 @@ export class PersistedBatch {
145
158
  const binLookup = serializeLookup(result.lookup);
146
159
  const hex = binLookup.toString('base64');
147
160
  remaining_lookups.delete(hex);
161
+
148
162
  const op_id = data.op_seq.next();
163
+ this.debugLastOpId = op_id;
149
164
  this.bucketParameters.push({
150
165
  insertOne: {
151
166
  document: {
@@ -167,6 +182,7 @@ export class PersistedBatch {
167
182
  // 2. "REMOVE" entries for any lookup not touched.
168
183
  for (let lookup of remaining_lookups.values()) {
169
184
  const op_id = data.op_seq.next();
185
+ this.debugLastOpId = op_id;
170
186
  this.bucketParameters.push({
171
187
  insertOne: {
172
188
  document: {
@@ -237,9 +253,16 @@ export class PersistedBatch {
237
253
  });
238
254
  }
239
255
 
256
+ micro.logger.info(
257
+ `powersync_${this.group_id} Flushed ${this.bucketData.length} + ${this.bucketParameters.length} + ${
258
+ this.currentData.length
259
+ } updates, ${Math.round(this.currentSize / 1024)}kb. Last op_id: ${this.debugLastOpId}`
260
+ );
261
+
240
262
  this.bucketData = [];
241
263
  this.bucketParameters = [];
242
264
  this.currentData = [];
243
265
  this.currentSize = 0;
266
+ this.debugLastOpId = null;
244
267
  }
245
268
  }
@@ -45,9 +45,6 @@ export class PowerSyncMongo {
45
45
  this.client = client;
46
46
 
47
47
  const db = client.db(options?.database, {
48
- // Note this issue with useBigInt64: https://jira.mongodb.org/browse/NODE-6165
49
- // Unfortunately there is no workaround if we want to continue using bigint.
50
- // We selectively disable this in individual queries where we don't need that.
51
48
  ...BSON_DESERIALIZE_OPTIONS
52
49
  });
53
50
  this.db = db;
@@ -83,6 +83,6 @@ export async function readSingleBatch<T>(cursor: mongo.FindCursor<T>): Promise<{
83
83
  }
84
84
 
85
85
  export const BSON_DESERIALIZE_OPTIONS: bson.DeserializeOptions = {
86
- // use bigint instead of long
86
+ // use bigint instead of Long
87
87
  useBigInt64: true
88
88
  };
@@ -121,7 +121,8 @@ export class CompoundConfigCollector {
121
121
  migrations: baseConfig.migrations,
122
122
  telemetry: {
123
123
  disable_telemetry_sharing: baseConfig.telemetry?.disable_telemetry_sharing ?? false,
124
- internal_service_endpoint: baseConfig.telemetry?.internal_service_endpoint ?? 'https://pulse.journeyapps.com/v1/metrics'
124
+ internal_service_endpoint:
125
+ baseConfig.telemetry?.internal_service_endpoint ?? 'https://pulse.journeyapps.com/v1/metrics'
125
126
  },
126
127
  slot_name_prefix: connections[0]?.slot_name_prefix ?? 'powersync_'
127
128
  };