@powersync/service-core 0.0.0-dev-20260313100403 → 0.0.0-dev-20260511080634

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 (235) hide show
  1. package/CHANGELOG.md +70 -7
  2. package/dist/api/RouteAPI.d.ts +17 -3
  3. package/dist/api/api-index.d.ts +1 -1
  4. package/dist/api/api-index.js +1 -1
  5. package/dist/api/api-index.js.map +1 -1
  6. package/dist/api/api-metrics.js.map +1 -1
  7. package/dist/api/diagnostics.d.ts +1 -1
  8. package/dist/api/diagnostics.js +32 -14
  9. package/dist/api/diagnostics.js.map +1 -1
  10. package/dist/auth/CachedKeyCollector.js +1 -1
  11. package/dist/auth/CachedKeyCollector.js.map +1 -1
  12. package/dist/auth/CompoundKeyCollector.js.map +1 -1
  13. package/dist/auth/KeyStore.js.map +1 -1
  14. package/dist/auth/RemoteJWKSCollector.js.map +1 -1
  15. package/dist/auth/StaticKeyCollector.d.ts +1 -1
  16. package/dist/auth/StaticKeyCollector.js.map +1 -1
  17. package/dist/auth/StaticSupabaseKeyCollector.d.ts +1 -1
  18. package/dist/auth/StaticSupabaseKeyCollector.js.map +1 -1
  19. package/dist/entry/commands/compact-action.js +26 -5
  20. package/dist/entry/commands/compact-action.js.map +1 -1
  21. package/dist/entry/commands/teardown-action.js +2 -2
  22. package/dist/entry/commands/teardown-action.js.map +1 -1
  23. package/dist/entry/entry-index.d.ts +1 -1
  24. package/dist/entry/entry-index.js +1 -1
  25. package/dist/entry/entry-index.js.map +1 -1
  26. package/dist/events/EventsEngine.js +1 -1
  27. package/dist/events/EventsEngine.js.map +1 -1
  28. package/dist/index.d.ts +1 -0
  29. package/dist/index.js +1 -0
  30. package/dist/index.js.map +1 -1
  31. package/dist/metrics/MetricsEngine.d.ts +1 -1
  32. package/dist/metrics/RollingBucketMax.d.ts +28 -0
  33. package/dist/metrics/RollingBucketMax.js +80 -0
  34. package/dist/metrics/RollingBucketMax.js.map +1 -0
  35. package/dist/metrics/metrics-index.d.ts +3 -2
  36. package/dist/metrics/metrics-index.js +3 -2
  37. package/dist/metrics/metrics-index.js.map +1 -1
  38. package/dist/metrics/open-telemetry/util.js +1 -1
  39. package/dist/metrics/open-telemetry/util.js.map +1 -1
  40. package/dist/metrics/register-metrics.js +2 -2
  41. package/dist/metrics/register-metrics.js.map +1 -1
  42. package/dist/modules/AbstractModule.d.ts +2 -2
  43. package/dist/modules/AbstractModule.js.map +1 -1
  44. package/dist/modules/modules-index.d.ts +1 -1
  45. package/dist/modules/modules-index.js +1 -1
  46. package/dist/modules/modules-index.js.map +1 -1
  47. package/dist/replication/AbstractReplicationJob.d.ts +2 -2
  48. package/dist/replication/AbstractReplicationJob.js +1 -1
  49. package/dist/replication/AbstractReplicationJob.js.map +1 -1
  50. package/dist/replication/AbstractReplicator.d.ts +7 -7
  51. package/dist/replication/AbstractReplicator.js +31 -28
  52. package/dist/replication/AbstractReplicator.js.map +1 -1
  53. package/dist/replication/ReplicationLagTracker.d.ts +50 -0
  54. package/dist/replication/ReplicationLagTracker.js +78 -0
  55. package/dist/replication/ReplicationLagTracker.js.map +1 -0
  56. package/dist/replication/replication-index.d.ts +3 -2
  57. package/dist/replication/replication-index.js +3 -2
  58. package/dist/replication/replication-index.js.map +1 -1
  59. package/dist/replication/replication-metrics.js.map +1 -1
  60. package/dist/routes/configure-fastify.d.ts +59 -32
  61. package/dist/routes/endpoints/admin.d.ts +108 -54
  62. package/dist/routes/endpoints/admin.js +7 -3
  63. package/dist/routes/endpoints/admin.js.map +1 -1
  64. package/dist/routes/endpoints/checkpointing.js +1 -1
  65. package/dist/routes/endpoints/checkpointing.js.map +1 -1
  66. package/dist/routes/endpoints/socket-route.js +1 -1
  67. package/dist/routes/endpoints/socket-route.js.map +1 -1
  68. package/dist/routes/endpoints/sync-rules.js +10 -10
  69. package/dist/routes/endpoints/sync-rules.js.map +1 -1
  70. package/dist/routes/endpoints/sync-stream.d.ts +10 -10
  71. package/dist/routes/endpoints/sync-stream.js +2 -2
  72. package/dist/routes/endpoints/sync-stream.js.map +1 -1
  73. package/dist/routes/hooks.js +1 -1
  74. package/dist/routes/hooks.js.map +1 -1
  75. package/dist/routes/route-register.js.map +1 -1
  76. package/dist/runner/teardown.js +4 -4
  77. package/dist/runner/teardown.js.map +1 -1
  78. package/dist/storage/BucketStorage.d.ts +9 -9
  79. package/dist/storage/BucketStorage.js +9 -9
  80. package/dist/storage/BucketStorageBatch.d.ts +1 -1
  81. package/dist/storage/BucketStorageFactory.d.ts +27 -20
  82. package/dist/storage/BucketStorageFactory.js +19 -16
  83. package/dist/storage/BucketStorageFactory.js.map +1 -1
  84. package/dist/storage/ChecksumCache.js.map +1 -1
  85. package/dist/storage/PersistedSyncRulesContent.d.ts +3 -1
  86. package/dist/storage/PersistedSyncRulesContent.js +24 -5
  87. package/dist/storage/PersistedSyncRulesContent.js.map +1 -1
  88. package/dist/storage/ReplicationEventPayload.d.ts +1 -1
  89. package/dist/storage/ReportStorage.d.ts +3 -3
  90. package/dist/storage/SourceTable.d.ts +4 -4
  91. package/dist/storage/SourceTable.js +3 -3
  92. package/dist/storage/SourceTable.js.map +1 -1
  93. package/dist/storage/StorageVersionConfig.d.ts +1 -1
  94. package/dist/storage/StorageVersionConfig.js +1 -1
  95. package/dist/storage/SyncRulesBucketStorage.d.ts +37 -5
  96. package/dist/storage/SyncRulesBucketStorage.js +14 -0
  97. package/dist/storage/SyncRulesBucketStorage.js.map +1 -1
  98. package/dist/storage/WriteCheckpointAPI.d.ts +6 -6
  99. package/dist/storage/WriteCheckpointAPI.js +1 -1
  100. package/dist/storage/bson.d.ts +0 -1
  101. package/dist/storage/bson.js +0 -4
  102. package/dist/storage/bson.js.map +1 -1
  103. package/dist/storage/storage-index.d.ts +8 -8
  104. package/dist/storage/storage-index.js +8 -8
  105. package/dist/storage/storage-index.js.map +1 -1
  106. package/dist/storage/storage-metrics.js.map +1 -1
  107. package/dist/streams/streams-index.d.ts +2 -2
  108. package/dist/streams/streams-index.js +2 -2
  109. package/dist/streams/streams-index.js.map +1 -1
  110. package/dist/sync/BucketChecksumState.d.ts +2 -5
  111. package/dist/sync/BucketChecksumState.js +107 -75
  112. package/dist/sync/BucketChecksumState.js.map +1 -1
  113. package/dist/sync/RequestTracker.js +1 -1
  114. package/dist/sync/RequestTracker.js.map +1 -1
  115. package/dist/sync/sync-index.d.ts +2 -2
  116. package/dist/sync/sync-index.js +2 -2
  117. package/dist/sync/sync-index.js.map +1 -1
  118. package/dist/sync/sync.js.map +1 -1
  119. package/dist/sync/util.js.map +1 -1
  120. package/dist/system/ServiceContext.d.ts +1 -1
  121. package/dist/system/ServiceContext.js +1 -1
  122. package/dist/system/ServiceContext.js.map +1 -1
  123. package/dist/tracing/PerformanceTracer.d.ts +44 -0
  124. package/dist/tracing/PerformanceTracer.js +102 -0
  125. package/dist/tracing/PerformanceTracer.js.map +1 -0
  126. package/dist/tracing/TraceWriter.d.ts +22 -0
  127. package/dist/tracing/TraceWriter.js +63 -0
  128. package/dist/tracing/TraceWriter.js.map +1 -0
  129. package/dist/util/checkpointing.js +1 -1
  130. package/dist/util/config/collectors/impl/base64-config-collector.d.ts +1 -1
  131. package/dist/util/config/collectors/impl/base64-config-collector.js.map +1 -1
  132. package/dist/util/config/collectors/impl/filesystem-config-collector.d.ts +1 -1
  133. package/dist/util/config/collectors/impl/filesystem-config-collector.js +1 -1
  134. package/dist/util/config/collectors/impl/filesystem-config-collector.js.map +1 -1
  135. package/dist/util/config/compound-config-collector.d.ts +1 -1
  136. package/dist/util/config/compound-config-collector.js +2 -2
  137. package/dist/util/config/compound-config-collector.js.map +1 -1
  138. package/dist/util/config/sync-rules/impl/filesystem-sync-rules-collector.js +1 -1
  139. package/dist/util/config/sync-rules/impl/filesystem-sync-rules-collector.js.map +1 -1
  140. package/dist/util/config/sync-rules/sync-rules-provider.js.map +1 -1
  141. package/dist/util/config.js +1 -1
  142. package/dist/util/config.js.map +1 -1
  143. package/dist/util/env.js +1 -1
  144. package/dist/util/errors.d.ts +3 -0
  145. package/dist/util/errors.js +15 -0
  146. package/dist/util/errors.js.map +1 -0
  147. package/dist/util/protocol-types.d.ts +3 -3
  148. package/dist/util/protocol-types.js +1 -1
  149. package/dist/util/util-index.d.ts +1 -1
  150. package/dist/util/util-index.js +1 -1
  151. package/dist/util/util-index.js.map +1 -1
  152. package/dist/util/utils.d.ts +1 -1
  153. package/package.json +11 -11
  154. package/src/api/RouteAPI.ts +20 -3
  155. package/src/api/api-index.ts +1 -1
  156. package/src/api/api-metrics.ts +1 -1
  157. package/src/api/diagnostics.ts +42 -20
  158. package/src/auth/CachedKeyCollector.ts +2 -3
  159. package/src/auth/CompoundKeyCollector.ts +2 -3
  160. package/src/auth/KeyStore.ts +1 -1
  161. package/src/auth/RemoteJWKSCollector.ts +0 -1
  162. package/src/auth/StaticKeyCollector.ts +1 -1
  163. package/src/auth/StaticSupabaseKeyCollector.ts +1 -1
  164. package/src/entry/commands/compact-action.ts +29 -5
  165. package/src/entry/commands/teardown-action.ts +2 -2
  166. package/src/entry/entry-index.ts +1 -1
  167. package/src/events/EventsEngine.ts +1 -1
  168. package/src/index.ts +2 -0
  169. package/src/metrics/MetricsEngine.ts +1 -1
  170. package/src/metrics/RollingBucketMax.ts +109 -0
  171. package/src/metrics/metrics-index.ts +3 -2
  172. package/src/metrics/open-telemetry/util.ts +1 -1
  173. package/src/metrics/register-metrics.ts +3 -3
  174. package/src/modules/AbstractModule.ts +2 -2
  175. package/src/modules/modules-index.ts +1 -1
  176. package/src/replication/AbstractReplicationJob.ts +3 -3
  177. package/src/replication/AbstractReplicator.ts +32 -30
  178. package/src/replication/ReplicationLagTracker.ts +86 -0
  179. package/src/replication/replication-index.ts +3 -2
  180. package/src/replication/replication-metrics.ts +1 -1
  181. package/src/routes/endpoints/admin.ts +7 -3
  182. package/src/routes/endpoints/checkpointing.ts +1 -1
  183. package/src/routes/endpoints/socket-route.ts +1 -1
  184. package/src/routes/endpoints/sync-rules.ts +10 -12
  185. package/src/routes/endpoints/sync-stream.ts +2 -2
  186. package/src/routes/hooks.ts +2 -2
  187. package/src/routes/route-register.ts +2 -10
  188. package/src/runner/teardown.ts +4 -4
  189. package/src/storage/BucketStorage.ts +9 -9
  190. package/src/storage/BucketStorageBatch.ts +1 -1
  191. package/src/storage/BucketStorageFactory.ts +45 -34
  192. package/src/storage/ChecksumCache.ts +1 -1
  193. package/src/storage/PersistedSyncRulesContent.ts +30 -6
  194. package/src/storage/ReplicationEventPayload.ts +1 -1
  195. package/src/storage/ReportStorage.ts +3 -3
  196. package/src/storage/SourceTable.ts +4 -4
  197. package/src/storage/StorageVersionConfig.ts +1 -1
  198. package/src/storage/SyncRulesBucketStorage.ts +44 -5
  199. package/src/storage/WriteCheckpointAPI.ts +6 -6
  200. package/src/storage/bson.ts +0 -5
  201. package/src/storage/storage-index.ts +8 -8
  202. package/src/storage/storage-metrics.ts +2 -2
  203. package/src/streams/streams-index.ts +2 -2
  204. package/src/sync/BucketChecksumState.ts +127 -93
  205. package/src/sync/RequestTracker.ts +1 -1
  206. package/src/sync/sync-index.ts +2 -2
  207. package/src/sync/sync.ts +2 -8
  208. package/src/sync/util.ts +1 -1
  209. package/src/system/ServiceContext.ts +1 -1
  210. package/src/tracing/PerformanceTracer.ts +126 -0
  211. package/src/tracing/TraceWriter.ts +67 -0
  212. package/src/util/checkpointing.ts +1 -1
  213. package/src/util/config/collectors/impl/base64-config-collector.ts +1 -1
  214. package/src/util/config/collectors/impl/filesystem-config-collector.ts +2 -2
  215. package/src/util/config/compound-config-collector.ts +3 -3
  216. package/src/util/config/sync-rules/impl/filesystem-sync-rules-collector.ts +1 -1
  217. package/src/util/config/sync-rules/sync-rules-provider.ts +1 -1
  218. package/src/util/config.ts +1 -1
  219. package/src/util/env.ts +1 -1
  220. package/src/util/errors.ts +21 -0
  221. package/src/util/protocol-types.ts +1 -1
  222. package/src/util/util-index.ts +1 -1
  223. package/src/util/utils.ts +1 -1
  224. package/test/src/ReplicationLagTracker.test.ts +53 -0
  225. package/test/src/RollingBucketMax.test.ts +106 -0
  226. package/test/src/auth.test.ts +7 -7
  227. package/test/src/diagnostics.test.ts +151 -0
  228. package/test/src/module-loader.test.ts +1 -1
  229. package/test/src/routes/mocks.ts +1 -1
  230. package/test/src/routes/stream.test.ts +1 -2
  231. package/test/src/sync/BucketChecksumState.test.ts +157 -60
  232. package/test/src/util/protocol_types.test.ts +1 -1
  233. package/test/tsconfig.json +0 -1
  234. package/tsconfig.tsbuildinfo +1 -1
  235. package/vitest.config.ts +1 -1
@@ -7,6 +7,7 @@ import {
7
7
  ChecksumMap,
8
8
  InternalOpId,
9
9
  JwtPayload,
10
+ ParameterSetLimitExceededError,
10
11
  ReplicationCheckpoint,
11
12
  StreamingSyncRequest,
12
13
  SyncContext,
@@ -15,13 +16,12 @@ import {
15
16
  import { JSONBig } from '@powersync/service-jsonbig';
16
17
  import {
17
18
  ParameterIndexLookupCreator,
18
- RequestJwtPayload,
19
19
  ScopedParameterLookup,
20
+ SourceTableInterface,
20
21
  SqliteJsonRow,
21
22
  SqliteRow,
22
23
  SqlSyncRules,
23
24
  TablePattern,
24
- SourceTableInterface,
25
25
  versionedHydrationState
26
26
  } from '@powersync/service-sync-rules';
27
27
  import { ParameterLookupScope } from '@powersync/service-sync-rules/src/HydrationState.js';
@@ -901,19 +901,127 @@ config:
901
901
  expect(logData[0].parameter_query_results).toBe(3);
902
902
  });
903
903
 
904
- test('throws error with breakdown when parameter query limit is exceeded', async () => {
904
+ test('throws error with breakdown when too many parameters were fetched', async () => {
905
+ const syncRules = SqlSyncRules.fromYaml(
906
+ `
907
+ config:
908
+ edition: 3
909
+
910
+ streams:
911
+ a:
912
+ auto_subscribe: true
913
+ query: SELECT * FROM a WHERE id IN (SELECT id FROM magic_sequence WHERE count0 = auth.parameter('a'))
914
+ b:
915
+ auto_subscribe: true
916
+ query: SELECT * FROM a WHERE id IN (SELECT id FROM magic_sequence WHERE count1 = auth.parameter('b'))
917
+ c:
918
+ auto_subscribe: true
919
+ query: SELECT * FROM a WHERE id IN (SELECT id FROM magic_sequence WHERE count1 = auth.parameter('c'))
920
+ `,
921
+ { defaultSchema: 'public' }
922
+ ).config.hydrate({
923
+ hydrationState: versionedHydrationState(1)
924
+ });
925
+
926
+ const storage = new MockBucketChecksumStateStorage();
927
+
928
+ const errorMessages: string[] = [];
929
+ const errorData: any[] = [];
930
+ const mockLogger = {
931
+ info: () => {},
932
+ error: (message: string, data: any) => {
933
+ errorMessages.push(message);
934
+ errorData.push(data);
935
+ },
936
+ warn: () => {},
937
+ debug: () => {}
938
+ };
939
+
940
+ const smallContext = new SyncContext({
941
+ maxBuckets: 100,
942
+ maxParameterQueryResults: 55,
943
+ maxDataFetchConcurrency: 10
944
+ });
945
+
946
+ const state = new BucketChecksumState({
947
+ syncContext: smallContext,
948
+ tokenPayload: new JwtPayload({
949
+ sub: 'u1',
950
+ // Create 60 total results: 30 a + 20 b + 10 c
951
+ a: BigInt(30),
952
+ b: BigInt(20),
953
+ c: BigInt(10)
954
+ }),
955
+ syncRequest,
956
+ syncRules,
957
+ bucketStorage: storage,
958
+ logger: mockLogger as any
959
+ });
960
+
961
+ await expect(
962
+ state.buildNextCheckpointLine({
963
+ base: storage.makeCheckpoint(1n, (lookups, limit) => {
964
+ expect(lookups).toHaveLength(1);
965
+ const [{ values }] = lookups;
966
+ expect(values[0]).toStrictEqual('lookup');
967
+
968
+ const count = Number(values[2]); // The count parameter from streams
969
+ if (count > limit) {
970
+ throw new ParameterSetLimitExceededError(limit);
971
+ }
972
+ return Array.from({ length: count }, (_, i) => ({ '0': BigInt(i) }));
973
+ }),
974
+ writeCheckpoint: null,
975
+ update: CHECKPOINT_INVALIDATE_ALL
976
+ })
977
+ ).rejects.toThrow('Too many parameter query results (limit of 55)');
978
+
979
+ // Verify error log includes breakdown
980
+ expect(errorMessages[0]).toContain('Invoked parameter queries by definition:');
981
+ expect(errorMessages[0]).toContain('Stream a evaluating parameter on magic_sequence: 30 results.');
982
+ expect(errorMessages[0]).toContain('Stream b evaluating parameter on magic_sequence: 20 results.');
983
+ expect(errorMessages[0]).toContain(
984
+ 'Stream c evaluating parameter on magic_sequence exceeded the remaining limit of 5 available results.'
985
+ );
986
+
987
+ expect(errorData[0].checkpoint).toEqual(1n);
988
+ expect(errorData[0].parameterResults).toEqual([
989
+ {
990
+ definition: 'Stream a evaluating parameter on magic_sequence',
991
+ didExceedLimit: false,
992
+ resultsOrLimit: 30
993
+ },
994
+ {
995
+ definition: 'Stream b evaluating parameter on magic_sequence',
996
+ didExceedLimit: false,
997
+ resultsOrLimit: 20
998
+ },
999
+ {
1000
+ definition: 'Stream c evaluating parameter on magic_sequence',
1001
+ didExceedLimit: true,
1002
+ resultsOrLimit: 5
1003
+ }
1004
+ ]);
1005
+ });
1006
+
1007
+ test('throws error with breakdown when bucket limit is exceeded', async () => {
1008
+ // These streams are designed to return buckets without consuming too many parameters (as exceeding that limit is
1009
+ // a different error).
905
1010
  const SYNC_RULES_MULTI = SqlSyncRules.fromYaml(
906
1011
  `
907
- bucket_definitions:
1012
+ config:
1013
+ edition: 3
1014
+
1015
+ streams:
908
1016
  projects:
909
- parameters: select id from projects where user_id = request.user_id()
910
- data: []
1017
+ auto_subscribe: true
1018
+ query: SELECT id FROM projects WHERE p IN auth.parameter('a')
911
1019
  tasks:
912
- parameters: select id from tasks where user_id = request.user_id()
913
- data: []
1020
+ auto_subscribe: true
1021
+ query: SELECT id FROM tasks WHERE p IN auth.parameter('b')
914
1022
  comments:
915
- parameters: select id from comments where user_id = request.user_id()
916
- data: []
1023
+ auto_subscribe: true
1024
+ query: SELECT id FROM comments WHERE p IN auth.parameter('c')
917
1025
  `,
918
1026
  { defaultSchema: 'public' }
919
1027
  ).config.hydrate({ hydrationState: versionedHydrationState(4) });
@@ -933,74 +1041,66 @@ bucket_definitions:
933
1041
  };
934
1042
 
935
1043
  const smallContext = new SyncContext({
936
- maxBuckets: 100,
937
- maxParameterQueryResults: 50,
1044
+ maxBuckets: 50,
1045
+ maxParameterQueryResults: 10,
938
1046
  maxDataFetchConcurrency: 10
939
1047
  });
940
1048
 
941
1049
  const state = new BucketChecksumState({
942
1050
  syncContext: smallContext,
943
- tokenPayload: new JwtPayload({ sub: 'u1' }),
1051
+ tokenPayload: new JwtPayload({
1052
+ sub: 'u1',
1053
+ // Create 60 total results: 30 projects + 20 tasks + 10 comments
1054
+ a: Array.from({ length: 30 }, (_, i) => BigInt(i)),
1055
+ b: Array.from({ length: 20 }, (_, i) => BigInt(i)),
1056
+ c: Array.from({ length: 10 }, (_, i) => BigInt(i))
1057
+ }),
944
1058
  syncRequest,
945
1059
  syncRules: SYNC_RULES_MULTI,
946
1060
  bucketStorage: storage,
947
1061
  logger: mockLogger as any
948
1062
  });
949
1063
 
950
- // Create 60 total results: 30 projects + 20 tasks + 10 comments
951
- const projectIds = Array.from({ length: 30 }, (_, i) => ({ id: i + 1 }));
952
- const taskIds = Array.from({ length: 20 }, (_, i) => ({ id: i + 1 }));
953
- const commentIds = Array.from({ length: 10 }, (_, i) => ({ id: i + 1 }));
954
-
955
- for (let i = 1; i <= 30; i++) {
956
- storage.updateTestChecksum({ bucket: `projects[${i}]`, checksum: 1, count: 1 });
957
- }
958
- for (let i = 1; i <= 20; i++) {
959
- storage.updateTestChecksum({ bucket: `tasks[${i}]`, checksum: 1, count: 1 });
960
- }
961
- for (let i = 1; i <= 10; i++) {
962
- storage.updateTestChecksum({ bucket: `comments[${i}]`, checksum: 1, count: 1 });
963
- }
964
-
1064
+ let invokedParameterQueries = 0;
965
1065
  await expect(
966
1066
  state.buildNextCheckpointLine({
967
- base: storage.makeCheckpoint(1n, (lookups) => {
968
- const lookup = lookups[0];
969
- const lookupName = lookup.values[0];
970
- if (lookupName === 'projects') {
971
- return projectIds;
972
- } else if (lookupName === 'tasks') {
973
- return taskIds;
974
- } else {
975
- return commentIds;
976
- }
1067
+ base: storage.makeCheckpoint(1n, () => {
1068
+ invokedParameterQueries++;
1069
+ return [{ '0': 'user' }];
977
1070
  }),
978
1071
  writeCheckpoint: null,
979
1072
  update: CHECKPOINT_INVALIDATE_ALL
980
1073
  })
981
- ).rejects.toThrow('Too many parameter query results: 60 (limit of 50)');
1074
+ ).rejects.toThrow('Too many buckets: 60 (limit of 50');
1075
+ expect(invokedParameterQueries).toStrictEqual(0);
982
1076
 
983
1077
  // Verify error log includes breakdown
984
- expect(errorMessages[0]).toContain('Parameter query results by definition:');
1078
+ expect(errorMessages[0]).toContain('Buckets by definition:');
985
1079
  expect(errorMessages[0]).toContain('projects: 30');
986
1080
  expect(errorMessages[0]).toContain('tasks: 20');
987
1081
  expect(errorMessages[0]).toContain('comments: 10');
988
1082
 
989
- expect(errorData[0].parameter_query_results).toBe(60);
990
- expect(errorData[0].parameter_query_results_by_definition).toEqual({
1083
+ expect(errorData[0].checkpoint).toEqual(1n);
1084
+ expect(errorData[0].buckets).toBe(60);
1085
+ expect(errorData[0].buckets_by_definition).toEqual({
991
1086
  projects: 30,
992
1087
  tasks: 20,
993
1088
  comments: 10
994
1089
  });
995
1090
  });
996
1091
 
997
- test('limits breakdown to top 10 definitions', async () => {
998
- // Create sync rules with 15 different definitions with dynamic parameters
999
- let yamlDefinitions = 'bucket_definitions:\n';
1092
+ test('limits bucket breakdown to top 10 definitions', async () => {
1093
+ // Create sync streams with 15 different definitions with dynamic parameters
1094
+ let yamlDefinitions = `
1095
+ config:
1096
+ edition: 3
1097
+
1098
+ streams:
1099
+ `;
1000
1100
  for (let i = 1; i <= 15; i++) {
1001
1101
  yamlDefinitions += ` def${i}:\n`;
1002
- yamlDefinitions += ` parameters: select id from def${i}_table where user_id = request.user_id()\n`;
1003
- yamlDefinitions += ` data: []\n`;
1102
+ yamlDefinitions += ` auto_subscribe: true\n`;
1103
+ yamlDefinitions += ` query: SELECT * FROM tbl WHERE b = auth.parameter('${i}')\n`;
1004
1104
  }
1005
1105
 
1006
1106
  const SYNC_RULES_MANY = SqlSyncRules.fromYaml(yamlDefinitions, { defaultSchema: 'public' }).config.hydrate({
@@ -1020,35 +1120,32 @@ bucket_definitions:
1020
1120
  };
1021
1121
 
1022
1122
  const smallContext = new SyncContext({
1023
- maxBuckets: 100,
1123
+ maxBuckets: 10,
1024
1124
  maxParameterQueryResults: 10,
1025
1125
  maxDataFetchConcurrency: 10
1026
1126
  });
1027
1127
 
1028
1128
  const state = new BucketChecksumState({
1029
1129
  syncContext: smallContext,
1030
- tokenPayload: new JwtPayload({ sub: 'u1' }),
1130
+ tokenPayload: new JwtPayload({
1131
+ sub: 'u1',
1132
+ ...Object.fromEntries(Array.from({ length: 30 }, (_, i) => [i.toString(), BigInt(i)]))
1133
+ }),
1031
1134
  syncRequest,
1032
1135
  syncRules: SYNC_RULES_MANY,
1033
1136
  bucketStorage: storage,
1034
1137
  logger: mockLogger as any
1035
1138
  });
1036
1139
 
1037
- // Each definition creates one bucket, total 15 buckets
1038
- for (let i = 1; i <= 15; i++) {
1039
- storage.updateTestChecksum({ bucket: `def${i}[${i}]`, checksum: 1, count: 1 });
1040
- }
1041
-
1042
1140
  await expect(
1043
1141
  state.buildNextCheckpointLine({
1044
1142
  base: storage.makeCheckpoint(1n, (lookups) => {
1045
- // Return one result for each definition
1046
- return [{ id: 1 }];
1143
+ return [{ '0': 'user' }];
1047
1144
  }),
1048
1145
  writeCheckpoint: null,
1049
1146
  update: CHECKPOINT_INVALIDATE_ALL
1050
1147
  })
1051
- ).rejects.toThrow('Too many parameter query results: 15 (limit of 10)');
1148
+ ).rejects.toThrow('Too many buckets: 15 (limit of 10)');
1052
1149
 
1053
1150
  // Verify only top 10 are shown
1054
1151
  const errorMessage = errorMessages[0];
@@ -1094,16 +1191,16 @@ class MockBucketChecksumStateStorage implements BucketChecksumStateStorage {
1094
1191
 
1095
1192
  makeCheckpoint(
1096
1193
  opId: InternalOpId,
1097
- parameters?: (lookups: ScopedParameterLookup[]) => SqliteJsonRow[]
1194
+ parameters?: (lookups: ScopedParameterLookup[], limit: number) => SqliteJsonRow[]
1098
1195
  ): ReplicationCheckpoint {
1099
1196
  return {
1100
1197
  checkpoint: opId,
1101
1198
  lsn: String(opId),
1102
- getParameterSets: async (lookups: ScopedParameterLookup[]) => {
1199
+ getParameterSets: async (lookups: ScopedParameterLookup[], limit) => {
1103
1200
  if (parameters == null) {
1104
1201
  throw new Error(`getParametersSets not defined for checkpoint ${opId}`);
1105
1202
  }
1106
- return parameters(lookups);
1203
+ return parameters(lookups, limit);
1107
1204
  }
1108
1205
  };
1109
1206
  }
@@ -1,6 +1,6 @@
1
1
  import { StreamingSyncRequest } from '@/index.js';
2
2
  import { schema } from '@powersync/lib-services-framework';
3
- import { describe, test, expect, it } from 'vitest';
3
+ import { describe, expect, test } from 'vitest';
4
4
 
5
5
  describe('protocol types', () => {
6
6
  describe('StreamingSyncRequest', () => {
@@ -1,7 +1,6 @@
1
1
  {
2
2
  "extends": "../../../tsconfig.tests.json",
3
3
  "compilerOptions": {
4
- "baseUrl": "./",
5
4
  "outDir": "dist",
6
5
  "paths": {
7
6
  "@/*": ["../src/*"]