@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.
- package/CHANGELOG.md +70 -7
- package/dist/api/RouteAPI.d.ts +17 -3
- package/dist/api/api-index.d.ts +1 -1
- package/dist/api/api-index.js +1 -1
- package/dist/api/api-index.js.map +1 -1
- package/dist/api/api-metrics.js.map +1 -1
- package/dist/api/diagnostics.d.ts +1 -1
- package/dist/api/diagnostics.js +32 -14
- package/dist/api/diagnostics.js.map +1 -1
- package/dist/auth/CachedKeyCollector.js +1 -1
- package/dist/auth/CachedKeyCollector.js.map +1 -1
- package/dist/auth/CompoundKeyCollector.js.map +1 -1
- package/dist/auth/KeyStore.js.map +1 -1
- package/dist/auth/RemoteJWKSCollector.js.map +1 -1
- package/dist/auth/StaticKeyCollector.d.ts +1 -1
- package/dist/auth/StaticKeyCollector.js.map +1 -1
- package/dist/auth/StaticSupabaseKeyCollector.d.ts +1 -1
- package/dist/auth/StaticSupabaseKeyCollector.js.map +1 -1
- package/dist/entry/commands/compact-action.js +26 -5
- package/dist/entry/commands/compact-action.js.map +1 -1
- package/dist/entry/commands/teardown-action.js +2 -2
- package/dist/entry/commands/teardown-action.js.map +1 -1
- package/dist/entry/entry-index.d.ts +1 -1
- package/dist/entry/entry-index.js +1 -1
- package/dist/entry/entry-index.js.map +1 -1
- package/dist/events/EventsEngine.js +1 -1
- package/dist/events/EventsEngine.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/metrics/MetricsEngine.d.ts +1 -1
- package/dist/metrics/RollingBucketMax.d.ts +28 -0
- package/dist/metrics/RollingBucketMax.js +80 -0
- package/dist/metrics/RollingBucketMax.js.map +1 -0
- package/dist/metrics/metrics-index.d.ts +3 -2
- package/dist/metrics/metrics-index.js +3 -2
- package/dist/metrics/metrics-index.js.map +1 -1
- package/dist/metrics/open-telemetry/util.js +1 -1
- package/dist/metrics/open-telemetry/util.js.map +1 -1
- package/dist/metrics/register-metrics.js +2 -2
- package/dist/metrics/register-metrics.js.map +1 -1
- package/dist/modules/AbstractModule.d.ts +2 -2
- package/dist/modules/AbstractModule.js.map +1 -1
- package/dist/modules/modules-index.d.ts +1 -1
- package/dist/modules/modules-index.js +1 -1
- package/dist/modules/modules-index.js.map +1 -1
- package/dist/replication/AbstractReplicationJob.d.ts +2 -2
- package/dist/replication/AbstractReplicationJob.js +1 -1
- package/dist/replication/AbstractReplicationJob.js.map +1 -1
- package/dist/replication/AbstractReplicator.d.ts +7 -7
- package/dist/replication/AbstractReplicator.js +31 -28
- package/dist/replication/AbstractReplicator.js.map +1 -1
- package/dist/replication/ReplicationLagTracker.d.ts +50 -0
- package/dist/replication/ReplicationLagTracker.js +78 -0
- package/dist/replication/ReplicationLagTracker.js.map +1 -0
- package/dist/replication/replication-index.d.ts +3 -2
- package/dist/replication/replication-index.js +3 -2
- package/dist/replication/replication-index.js.map +1 -1
- package/dist/replication/replication-metrics.js.map +1 -1
- package/dist/routes/configure-fastify.d.ts +59 -32
- package/dist/routes/endpoints/admin.d.ts +108 -54
- package/dist/routes/endpoints/admin.js +7 -3
- package/dist/routes/endpoints/admin.js.map +1 -1
- package/dist/routes/endpoints/checkpointing.js +1 -1
- package/dist/routes/endpoints/checkpointing.js.map +1 -1
- package/dist/routes/endpoints/socket-route.js +1 -1
- package/dist/routes/endpoints/socket-route.js.map +1 -1
- package/dist/routes/endpoints/sync-rules.js +10 -10
- package/dist/routes/endpoints/sync-rules.js.map +1 -1
- package/dist/routes/endpoints/sync-stream.d.ts +10 -10
- package/dist/routes/endpoints/sync-stream.js +2 -2
- package/dist/routes/endpoints/sync-stream.js.map +1 -1
- package/dist/routes/hooks.js +1 -1
- package/dist/routes/hooks.js.map +1 -1
- package/dist/routes/route-register.js.map +1 -1
- package/dist/runner/teardown.js +4 -4
- package/dist/runner/teardown.js.map +1 -1
- package/dist/storage/BucketStorage.d.ts +9 -9
- package/dist/storage/BucketStorage.js +9 -9
- package/dist/storage/BucketStorageBatch.d.ts +1 -1
- package/dist/storage/BucketStorageFactory.d.ts +27 -20
- package/dist/storage/BucketStorageFactory.js +19 -16
- package/dist/storage/BucketStorageFactory.js.map +1 -1
- package/dist/storage/ChecksumCache.js.map +1 -1
- package/dist/storage/PersistedSyncRulesContent.d.ts +3 -1
- package/dist/storage/PersistedSyncRulesContent.js +24 -5
- package/dist/storage/PersistedSyncRulesContent.js.map +1 -1
- package/dist/storage/ReplicationEventPayload.d.ts +1 -1
- package/dist/storage/ReportStorage.d.ts +3 -3
- package/dist/storage/SourceTable.d.ts +4 -4
- package/dist/storage/SourceTable.js +3 -3
- package/dist/storage/SourceTable.js.map +1 -1
- package/dist/storage/StorageVersionConfig.d.ts +1 -1
- package/dist/storage/StorageVersionConfig.js +1 -1
- package/dist/storage/SyncRulesBucketStorage.d.ts +37 -5
- package/dist/storage/SyncRulesBucketStorage.js +14 -0
- package/dist/storage/SyncRulesBucketStorage.js.map +1 -1
- package/dist/storage/WriteCheckpointAPI.d.ts +6 -6
- package/dist/storage/WriteCheckpointAPI.js +1 -1
- package/dist/storage/bson.d.ts +0 -1
- package/dist/storage/bson.js +0 -4
- package/dist/storage/bson.js.map +1 -1
- package/dist/storage/storage-index.d.ts +8 -8
- package/dist/storage/storage-index.js +8 -8
- package/dist/storage/storage-index.js.map +1 -1
- package/dist/storage/storage-metrics.js.map +1 -1
- package/dist/streams/streams-index.d.ts +2 -2
- package/dist/streams/streams-index.js +2 -2
- package/dist/streams/streams-index.js.map +1 -1
- package/dist/sync/BucketChecksumState.d.ts +2 -5
- package/dist/sync/BucketChecksumState.js +107 -75
- package/dist/sync/BucketChecksumState.js.map +1 -1
- package/dist/sync/RequestTracker.js +1 -1
- package/dist/sync/RequestTracker.js.map +1 -1
- package/dist/sync/sync-index.d.ts +2 -2
- package/dist/sync/sync-index.js +2 -2
- package/dist/sync/sync-index.js.map +1 -1
- package/dist/sync/sync.js.map +1 -1
- package/dist/sync/util.js.map +1 -1
- package/dist/system/ServiceContext.d.ts +1 -1
- package/dist/system/ServiceContext.js +1 -1
- package/dist/system/ServiceContext.js.map +1 -1
- package/dist/tracing/PerformanceTracer.d.ts +44 -0
- package/dist/tracing/PerformanceTracer.js +102 -0
- package/dist/tracing/PerformanceTracer.js.map +1 -0
- package/dist/tracing/TraceWriter.d.ts +22 -0
- package/dist/tracing/TraceWriter.js +63 -0
- package/dist/tracing/TraceWriter.js.map +1 -0
- package/dist/util/checkpointing.js +1 -1
- package/dist/util/config/collectors/impl/base64-config-collector.d.ts +1 -1
- package/dist/util/config/collectors/impl/base64-config-collector.js.map +1 -1
- package/dist/util/config/collectors/impl/filesystem-config-collector.d.ts +1 -1
- package/dist/util/config/collectors/impl/filesystem-config-collector.js +1 -1
- package/dist/util/config/collectors/impl/filesystem-config-collector.js.map +1 -1
- package/dist/util/config/compound-config-collector.d.ts +1 -1
- package/dist/util/config/compound-config-collector.js +2 -2
- package/dist/util/config/compound-config-collector.js.map +1 -1
- package/dist/util/config/sync-rules/impl/filesystem-sync-rules-collector.js +1 -1
- package/dist/util/config/sync-rules/impl/filesystem-sync-rules-collector.js.map +1 -1
- package/dist/util/config/sync-rules/sync-rules-provider.js.map +1 -1
- package/dist/util/config.js +1 -1
- package/dist/util/config.js.map +1 -1
- package/dist/util/env.js +1 -1
- package/dist/util/errors.d.ts +3 -0
- package/dist/util/errors.js +15 -0
- package/dist/util/errors.js.map +1 -0
- package/dist/util/protocol-types.d.ts +3 -3
- package/dist/util/protocol-types.js +1 -1
- package/dist/util/util-index.d.ts +1 -1
- package/dist/util/util-index.js +1 -1
- package/dist/util/util-index.js.map +1 -1
- package/dist/util/utils.d.ts +1 -1
- package/package.json +11 -11
- package/src/api/RouteAPI.ts +20 -3
- package/src/api/api-index.ts +1 -1
- package/src/api/api-metrics.ts +1 -1
- package/src/api/diagnostics.ts +42 -20
- package/src/auth/CachedKeyCollector.ts +2 -3
- package/src/auth/CompoundKeyCollector.ts +2 -3
- package/src/auth/KeyStore.ts +1 -1
- package/src/auth/RemoteJWKSCollector.ts +0 -1
- package/src/auth/StaticKeyCollector.ts +1 -1
- package/src/auth/StaticSupabaseKeyCollector.ts +1 -1
- package/src/entry/commands/compact-action.ts +29 -5
- package/src/entry/commands/teardown-action.ts +2 -2
- package/src/entry/entry-index.ts +1 -1
- package/src/events/EventsEngine.ts +1 -1
- package/src/index.ts +2 -0
- package/src/metrics/MetricsEngine.ts +1 -1
- package/src/metrics/RollingBucketMax.ts +109 -0
- package/src/metrics/metrics-index.ts +3 -2
- package/src/metrics/open-telemetry/util.ts +1 -1
- package/src/metrics/register-metrics.ts +3 -3
- package/src/modules/AbstractModule.ts +2 -2
- package/src/modules/modules-index.ts +1 -1
- package/src/replication/AbstractReplicationJob.ts +3 -3
- package/src/replication/AbstractReplicator.ts +32 -30
- package/src/replication/ReplicationLagTracker.ts +86 -0
- package/src/replication/replication-index.ts +3 -2
- package/src/replication/replication-metrics.ts +1 -1
- package/src/routes/endpoints/admin.ts +7 -3
- package/src/routes/endpoints/checkpointing.ts +1 -1
- package/src/routes/endpoints/socket-route.ts +1 -1
- package/src/routes/endpoints/sync-rules.ts +10 -12
- package/src/routes/endpoints/sync-stream.ts +2 -2
- package/src/routes/hooks.ts +2 -2
- package/src/routes/route-register.ts +2 -10
- package/src/runner/teardown.ts +4 -4
- package/src/storage/BucketStorage.ts +9 -9
- package/src/storage/BucketStorageBatch.ts +1 -1
- package/src/storage/BucketStorageFactory.ts +45 -34
- package/src/storage/ChecksumCache.ts +1 -1
- package/src/storage/PersistedSyncRulesContent.ts +30 -6
- package/src/storage/ReplicationEventPayload.ts +1 -1
- package/src/storage/ReportStorage.ts +3 -3
- package/src/storage/SourceTable.ts +4 -4
- package/src/storage/StorageVersionConfig.ts +1 -1
- package/src/storage/SyncRulesBucketStorage.ts +44 -5
- package/src/storage/WriteCheckpointAPI.ts +6 -6
- package/src/storage/bson.ts +0 -5
- package/src/storage/storage-index.ts +8 -8
- package/src/storage/storage-metrics.ts +2 -2
- package/src/streams/streams-index.ts +2 -2
- package/src/sync/BucketChecksumState.ts +127 -93
- package/src/sync/RequestTracker.ts +1 -1
- package/src/sync/sync-index.ts +2 -2
- package/src/sync/sync.ts +2 -8
- package/src/sync/util.ts +1 -1
- package/src/system/ServiceContext.ts +1 -1
- package/src/tracing/PerformanceTracer.ts +126 -0
- package/src/tracing/TraceWriter.ts +67 -0
- package/src/util/checkpointing.ts +1 -1
- package/src/util/config/collectors/impl/base64-config-collector.ts +1 -1
- package/src/util/config/collectors/impl/filesystem-config-collector.ts +2 -2
- package/src/util/config/compound-config-collector.ts +3 -3
- package/src/util/config/sync-rules/impl/filesystem-sync-rules-collector.ts +1 -1
- package/src/util/config/sync-rules/sync-rules-provider.ts +1 -1
- package/src/util/config.ts +1 -1
- package/src/util/env.ts +1 -1
- package/src/util/errors.ts +21 -0
- package/src/util/protocol-types.ts +1 -1
- package/src/util/util-index.ts +1 -1
- package/src/util/utils.ts +1 -1
- package/test/src/ReplicationLagTracker.test.ts +53 -0
- package/test/src/RollingBucketMax.test.ts +106 -0
- package/test/src/auth.test.ts +7 -7
- package/test/src/diagnostics.test.ts +151 -0
- package/test/src/module-loader.test.ts +1 -1
- package/test/src/routes/mocks.ts +1 -1
- package/test/src/routes/stream.test.ts +1 -2
- package/test/src/sync/BucketChecksumState.test.ts +157 -60
- package/test/src/util/protocol_types.test.ts +1 -1
- package/test/tsconfig.json +0 -1
- package/tsconfig.tsbuildinfo +1 -1
- 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
|
|
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
|
-
|
|
1012
|
+
config:
|
|
1013
|
+
edition: 3
|
|
1014
|
+
|
|
1015
|
+
streams:
|
|
908
1016
|
projects:
|
|
909
|
-
|
|
910
|
-
|
|
1017
|
+
auto_subscribe: true
|
|
1018
|
+
query: SELECT id FROM projects WHERE p IN auth.parameter('a')
|
|
911
1019
|
tasks:
|
|
912
|
-
|
|
913
|
-
|
|
1020
|
+
auto_subscribe: true
|
|
1021
|
+
query: SELECT id FROM tasks WHERE p IN auth.parameter('b')
|
|
914
1022
|
comments:
|
|
915
|
-
|
|
916
|
-
|
|
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:
|
|
937
|
-
maxParameterQueryResults:
|
|
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({
|
|
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
|
-
|
|
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, (
|
|
968
|
-
|
|
969
|
-
|
|
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
|
|
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('
|
|
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].
|
|
990
|
-
expect(errorData[0].
|
|
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
|
|
999
|
-
let yamlDefinitions =
|
|
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 += `
|
|
1003
|
-
yamlDefinitions += `
|
|
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:
|
|
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({
|
|
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
|
-
|
|
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
|
|
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,
|
|
3
|
+
import { describe, expect, test } from 'vitest';
|
|
4
4
|
|
|
5
5
|
describe('protocol types', () => {
|
|
6
6
|
describe('StreamingSyncRequest', () => {
|