@powersync/service-module-mongodb-storage 0.0.0-dev-20260803144812 → 0.0.0-dev-20260929095716
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 +129 -7
- package/dist/storage/MongoBucketStorage.d.ts +42 -5
- package/dist/storage/MongoBucketStorage.js +404 -215
- package/dist/storage/MongoBucketStorage.js.map +1 -1
- package/dist/storage/implementation/MongoBucketBatch.d.ts +39 -14
- package/dist/storage/implementation/MongoBucketBatch.js +169 -98
- package/dist/storage/implementation/MongoBucketBatch.js.map +1 -1
- package/dist/storage/implementation/MongoCompactor.d.ts +21 -79
- package/dist/storage/implementation/MongoCompactor.js +27 -238
- package/dist/storage/implementation/MongoCompactor.js.map +1 -1
- package/dist/storage/implementation/MongoIdSequence.d.ts +10 -1
- package/dist/storage/implementation/MongoIdSequence.js +14 -1
- package/dist/storage/implementation/MongoIdSequence.js.map +1 -1
- package/dist/storage/implementation/MongoOpIdAllocator.d.ts +27 -0
- package/dist/storage/implementation/MongoOpIdAllocator.js +97 -0
- package/dist/storage/implementation/MongoOpIdAllocator.js.map +1 -0
- package/dist/storage/implementation/MongoParameterCompactor.d.ts +83 -10
- package/dist/storage/implementation/MongoParameterCompactor.js +309 -96
- package/dist/storage/implementation/MongoParameterCompactor.js.map +1 -1
- package/dist/storage/implementation/MongoParsedSyncConfigSet.d.ts +9 -1
- package/dist/storage/implementation/MongoParsedSyncConfigSet.js +35 -2
- package/dist/storage/implementation/MongoParsedSyncConfigSet.js.map +1 -1
- package/dist/storage/implementation/MongoPersistedReplicationStream.d.ts +2 -1
- package/dist/storage/implementation/MongoPersistedReplicationStream.js +7 -4
- package/dist/storage/implementation/MongoPersistedReplicationStream.js.map +1 -1
- package/dist/storage/implementation/MongoPersistedSyncConfigContent.d.ts +3 -3
- package/dist/storage/implementation/MongoPersistedSyncConfigContent.js +10 -8
- package/dist/storage/implementation/MongoPersistedSyncConfigContent.js.map +1 -1
- package/dist/storage/implementation/MongoStorageProvider.js +8 -4
- package/dist/storage/implementation/MongoStorageProvider.js.map +1 -1
- package/dist/storage/implementation/MongoSyncBucketStorage.d.ts +32 -11
- package/dist/storage/implementation/MongoSyncBucketStorage.js +95 -31
- package/dist/storage/implementation/MongoSyncBucketStorage.js.map +1 -1
- package/dist/storage/implementation/MongoSyncRulesLock.d.ts +26 -2
- package/dist/storage/implementation/MongoSyncRulesLock.js +59 -10
- package/dist/storage/implementation/MongoSyncRulesLock.js.map +1 -1
- package/dist/storage/implementation/MongoWriteBatch.d.ts +49 -0
- package/dist/storage/implementation/MongoWriteBatch.js +149 -0
- package/dist/storage/implementation/MongoWriteBatch.js.map +1 -0
- package/dist/storage/implementation/MongoWriteCheckpointAPI.d.ts +9 -7
- package/dist/storage/implementation/MongoWriteCheckpointAPI.js +9 -30
- package/dist/storage/implementation/MongoWriteCheckpointAPI.js.map +1 -1
- package/dist/storage/implementation/SyncRuleStateUpdate.d.ts +11 -5
- package/dist/storage/implementation/SyncRuleStateUpdate.js +14 -6
- package/dist/storage/implementation/SyncRuleStateUpdate.js.map +1 -1
- package/dist/storage/implementation/common/MongoSyncBucketStorageCheckpoint.d.ts +22 -2
- package/dist/storage/implementation/common/PersistedBatch.d.ts +32 -4
- package/dist/storage/implementation/common/PersistedBatch.js +57 -14
- package/dist/storage/implementation/common/PersistedBatch.js.map +1 -1
- package/dist/storage/implementation/common/VersionedPowerSyncMongoBase.d.ts +3 -0
- package/dist/storage/implementation/common/VersionedPowerSyncMongoBase.js +3 -0
- package/dist/storage/implementation/common/VersionedPowerSyncMongoBase.js.map +1 -1
- package/dist/storage/implementation/db.d.ts +9 -1
- package/dist/storage/implementation/db.js +28 -1
- package/dist/storage/implementation/db.js.map +1 -1
- package/dist/storage/implementation/models.d.ts +35 -0
- package/dist/storage/implementation/models.js.map +1 -1
- package/dist/storage/implementation/v1/MongoBucketBatchV1.d.ts +11 -0
- package/dist/storage/implementation/v1/MongoBucketBatchV1.js +227 -221
- package/dist/storage/implementation/v1/MongoBucketBatchV1.js.map +1 -1
- package/dist/storage/implementation/v1/MongoCompactorV1.d.ts +38 -6
- package/dist/storage/implementation/v1/MongoCompactorV1.js +247 -20
- package/dist/storage/implementation/v1/MongoCompactorV1.js.map +1 -1
- package/dist/storage/implementation/v1/MongoParameterCompactorV1.d.ts +16 -2
- package/dist/storage/implementation/v1/MongoParameterCompactorV1.js +20 -9
- package/dist/storage/implementation/v1/MongoParameterCompactorV1.js.map +1 -1
- package/dist/storage/implementation/v1/MongoSyncBucketStorageV1.d.ts +18 -11
- package/dist/storage/implementation/v1/MongoSyncBucketStorageV1.js +66 -17
- package/dist/storage/implementation/v1/MongoSyncBucketStorageV1.js.map +1 -1
- package/dist/storage/implementation/v1/PersistedBatchV1.d.ts +7 -5
- package/dist/storage/implementation/v1/PersistedBatchV1.js +22 -28
- package/dist/storage/implementation/v1/PersistedBatchV1.js.map +1 -1
- package/dist/storage/implementation/v1/models.js +1 -0
- package/dist/storage/implementation/v1/models.js.map +1 -1
- package/dist/storage/implementation/v3/CompactionLease.d.ts +50 -0
- package/dist/storage/implementation/v3/CompactionLease.js +131 -0
- package/dist/storage/implementation/v3/CompactionLease.js.map +1 -0
- package/dist/storage/implementation/v3/MongoBucketBatchV3.d.ts +14 -2
- package/dist/storage/implementation/v3/MongoBucketBatchV3.js +261 -194
- package/dist/storage/implementation/v3/MongoBucketBatchV3.js.map +1 -1
- package/dist/storage/implementation/v3/MongoCompactorV3.d.ts +83 -25
- package/dist/storage/implementation/v3/MongoCompactorV3.js +702 -159
- package/dist/storage/implementation/v3/MongoCompactorV3.js.map +1 -1
- package/dist/storage/implementation/v3/MongoParameterCompactorV3.d.ts +18 -0
- package/dist/storage/implementation/v3/MongoParameterCompactorV3.js +23 -0
- package/dist/storage/implementation/v3/MongoParameterCompactorV3.js.map +1 -0
- package/dist/storage/implementation/v3/MongoStoppedSyncConfigCleanup.d.ts +2 -15
- package/dist/storage/implementation/v3/MongoStoppedSyncConfigCleanup.js +60 -92
- package/dist/storage/implementation/v3/MongoStoppedSyncConfigCleanup.js.map +1 -1
- package/dist/storage/implementation/v3/MongoSyncBucketStorageV3.d.ts +19 -9
- package/dist/storage/implementation/v3/MongoSyncBucketStorageV3.js +92 -32
- package/dist/storage/implementation/v3/MongoSyncBucketStorageV3.js.map +1 -1
- package/dist/storage/implementation/v3/MongoWriteCheckpointAPIV3.d.ts +26 -0
- package/dist/storage/implementation/v3/MongoWriteCheckpointAPIV3.js +82 -0
- package/dist/storage/implementation/v3/MongoWriteCheckpointAPIV3.js.map +1 -0
- package/dist/storage/implementation/v3/PersistedBatchV3.d.ts +14 -8
- package/dist/storage/implementation/v3/PersistedBatchV3.js +77 -45
- package/dist/storage/implementation/v3/PersistedBatchV3.js.map +1 -1
- package/dist/storage/implementation/v3/VersionedPowerSyncMongoV3.d.ts +12 -2
- package/dist/storage/implementation/v3/VersionedPowerSyncMongoV3.js +42 -3
- package/dist/storage/implementation/v3/VersionedPowerSyncMongoV3.js.map +1 -1
- package/dist/storage/implementation/v3/bucket-format.js +2 -0
- package/dist/storage/implementation/v3/bucket-format.js.map +1 -1
- package/dist/storage/implementation/v3/compact-utils.d.ts +108 -0
- package/dist/storage/implementation/v3/compact-utils.js +223 -0
- package/dist/storage/implementation/v3/compact-utils.js.map +1 -0
- package/dist/storage/implementation/v3/compaction-constants.d.ts +5 -0
- package/dist/storage/implementation/v3/compaction-constants.js +6 -0
- package/dist/storage/implementation/v3/compaction-constants.js.map +1 -0
- package/dist/storage/implementation/v3/models.d.ts +90 -6
- package/dist/storage/implementation/v3/models.js.map +1 -1
- package/dist/storage/implementation/v3/object-storage/BucketDataObjectStorage.d.ts +7 -8
- package/dist/storage/implementation/v3/object-storage/BucketDataObjectStorage.js +16 -5
- package/dist/storage/implementation/v3/object-storage/BucketDataObjectStorage.js.map +1 -1
- package/dist/storage/implementation/v3/object-storage/ObjectStorage.d.ts +14 -11
- package/dist/storage/implementation/v3/object-storage/ObjectStorageLifecycle.d.ts +6 -8
- package/dist/storage/implementation/v3/object-storage/ObjectStorageLifecycle.js +17 -11
- package/dist/storage/implementation/v3/object-storage/ObjectStorageLifecycle.js.map +1 -1
- package/dist/storage/implementation/v3/object-storage/ObjectStorageUsage.d.ts +38 -0
- package/dist/storage/implementation/v3/object-storage/ObjectStorageUsage.js +164 -0
- package/dist/storage/implementation/v3/object-storage/ObjectStorageUsage.js.map +1 -0
- package/dist/storage/implementation/v3/object-storage/S3ObjectStorage.d.ts +37 -12
- package/dist/storage/implementation/v3/object-storage/S3ObjectStorage.js +197 -25
- package/dist/storage/implementation/v3/object-storage/S3ObjectStorage.js.map +1 -1
- package/dist/storage/implementation/v3/source-table-utils.d.ts +15 -7
- package/dist/storage/implementation/v3/source-table-utils.js +49 -57
- package/dist/storage/implementation/v3/source-table-utils.js.map +1 -1
- package/dist/storage/storage-index.d.ts +2 -1
- package/dist/storage/storage-index.js +1 -0
- package/dist/storage/storage-index.js.map +1 -1
- package/dist/types/types.d.ts +28 -1
- package/dist/types/types.js +28 -7
- package/dist/types/types.js.map +1 -1
- package/dist/utils/test-utils.d.ts +4 -2
- package/dist/utils/test-utils.js +7 -4
- package/dist/utils/test-utils.js.map +1 -1
- package/dist/utils/util.js +3 -1
- package/dist/utils/util.js.map +1 -1
- package/package.json +10 -9
- package/src/storage/MongoBucketStorage.ts +545 -277
- package/src/storage/implementation/MongoBucketBatch.ts +258 -124
- package/src/storage/implementation/MongoCompactor.ts +37 -346
- package/src/storage/implementation/MongoIdSequence.ts +21 -1
- package/src/storage/implementation/MongoOpIdAllocator.ts +105 -0
- package/src/storage/implementation/MongoParameterCompactor.ts +388 -102
- package/src/storage/implementation/MongoParsedSyncConfigSet.ts +46 -1
- package/src/storage/implementation/MongoPersistedReplicationStream.ts +12 -4
- package/src/storage/implementation/MongoPersistedSyncConfigContent.ts +48 -29
- package/src/storage/implementation/MongoStorageProvider.ts +16 -4
- package/src/storage/implementation/MongoSyncBucketStorage.ts +133 -40
- package/src/storage/implementation/MongoSyncRulesLock.ts +78 -12
- package/src/storage/implementation/MongoWriteBatch.ts +172 -0
- package/src/storage/implementation/MongoWriteCheckpointAPI.ts +16 -46
- package/src/storage/implementation/SyncRuleStateUpdate.ts +13 -6
- package/src/storage/implementation/common/MongoSyncBucketStorageCheckpoint.ts +24 -2
- package/src/storage/implementation/common/PersistedBatch.ts +76 -20
- package/src/storage/implementation/common/VersionedPowerSyncMongoBase.ts +4 -0
- package/src/storage/implementation/db.ts +36 -2
- package/src/storage/implementation/models.ts +39 -0
- package/src/storage/implementation/v1/MongoBucketBatchV1.ts +272 -254
- package/src/storage/implementation/v1/MongoCompactorV1.ts +327 -40
- package/src/storage/implementation/v1/MongoParameterCompactorV1.ts +25 -9
- package/src/storage/implementation/v1/MongoSyncBucketStorageV1.ts +88 -28
- package/src/storage/implementation/v1/PersistedBatchV1.ts +25 -30
- package/src/storage/implementation/v1/models.ts +1 -0
- package/src/storage/implementation/v3/CompactionLease.ts +152 -0
- package/src/storage/implementation/v3/MongoBucketBatchV3.ts +339 -247
- package/src/storage/implementation/v3/MongoCompactorV3.ts +955 -225
- package/src/storage/implementation/v3/MongoParameterCompactorV3.ts +34 -0
- package/src/storage/implementation/v3/MongoStoppedSyncConfigCleanup.ts +100 -109
- package/src/storage/implementation/v3/MongoSyncBucketStorageV3.ts +112 -42
- package/src/storage/implementation/v3/MongoWriteCheckpointAPIV3.ts +111 -0
- package/src/storage/implementation/v3/PersistedBatchV3.ts +94 -51
- package/src/storage/implementation/v3/VersionedPowerSyncMongoV3.ts +55 -4
- package/src/storage/implementation/v3/bucket-format.ts +2 -0
- package/src/storage/implementation/v3/compact-utils.ts +329 -0
- package/src/storage/implementation/v3/compaction-constants.ts +5 -0
- package/src/storage/implementation/v3/models.ts +97 -4
- package/src/storage/implementation/v3/object-storage/BucketDataObjectStorage.ts +24 -9
- package/src/storage/implementation/v3/object-storage/ObjectStorage.ts +20 -5
- package/src/storage/implementation/v3/object-storage/ObjectStorageLifecycle.ts +26 -14
- package/src/storage/implementation/v3/object-storage/ObjectStorageUsage.ts +229 -0
- package/src/storage/implementation/v3/object-storage/S3ObjectStorage.ts +279 -29
- package/src/storage/implementation/v3/source-table-utils.ts +82 -76
- package/src/storage/storage-index.ts +2 -0
- package/src/types/types.ts +42 -7
- package/src/utils/test-utils.ts +9 -5
- package/src/utils/util.ts +3 -1
- package/test/src/__snapshots__/storage.test.ts.snap +25 -0
- package/test/src/__snapshots__/storage_sync.test.ts.snap +794 -205
- package/test/src/chunk_compaction_config.test.ts +38 -0
- package/test/src/cleanup-stopped-sync-configs.test.ts +59 -26
- package/test/src/compact-utils.test.ts +251 -0
- package/test/src/concurrent_writers.test.ts +599 -0
- package/test/src/connection_config.test.ts +159 -0
- package/test/src/helpers/MemoryObjectStorage.ts +14 -6
- package/test/src/helpers/concurrentWriter.mjs +29 -0
- package/test/src/helpers/s3TestFactory.ts +12 -12
- package/test/src/object_storage_usage.test.ts +268 -0
- package/test/src/parameter_compacting_v1.test.ts +120 -0
- package/test/src/parameter_compacting_v3.test.ts +192 -0
- package/test/src/parameter_compaction_fence.test.ts +276 -0
- package/test/src/storage.test.ts +280 -24
- package/test/src/storage_compacting.test.ts +1097 -253
- package/test/src/storage_object_storage_inline_threshold.test.ts +3 -3
- package/test/src/storage_s3_checksums.test.ts +6 -7
- package/test/src/storage_s3_compaction_lifecycle.test.ts +143 -17
- package/test/src/storage_s3_reading.test.ts +294 -6
- package/test/src/storage_s3_writing.test.ts +4 -3
- package/test/src/storage_sync.test.ts +412 -80
- package/test/src/storeCurrentData.test.ts +5 -5
- package/test/src/util.ts +1 -1
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import { DeleteObjectsCommand, ListObjectsV2Command } from '@aws-sdk/client-s3';
|
|
2
2
|
import { storage, updateSyncRulesFromYaml } from '@powersync/service-core';
|
|
3
|
-
import { bucketRequest, test_utils } from '@powersync/service-core-tests';
|
|
3
|
+
import { bucketRequest, getTestStorage, test_utils } from '@powersync/service-core-tests';
|
|
4
4
|
import * as bson from 'bson';
|
|
5
|
-
import { describe, expect, test } from 'vitest';
|
|
5
|
+
import { describe, expect, test, vi } from 'vitest';
|
|
6
6
|
import { MongoSyncBucketStorage } from '../../src/storage/implementation/createMongoSyncBucketStorage.js';
|
|
7
7
|
import { VersionedPowerSyncMongoV3 } from '../../src/storage/implementation/v3/VersionedPowerSyncMongoV3.js';
|
|
8
8
|
import { hydrateBucketDataDocuments } from '../../src/storage/implementation/v3/object-storage/BucketDataObjectStorage.js';
|
|
9
9
|
import { ObjectStorageError } from '../../src/storage/implementation/v3/object-storage/ObjectStorage.js';
|
|
10
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
resolveTimeoutProfile,
|
|
12
|
+
S3ObjectStorage,
|
|
13
|
+
type S3TimeoutProfile
|
|
14
|
+
} from '../../src/storage/implementation/v3/object-storage/S3ObjectStorage.js';
|
|
11
15
|
import { env } from './env.js';
|
|
12
16
|
import { MemoryObjectStorage } from './helpers/MemoryObjectStorage.js';
|
|
13
17
|
import { createMemoryS3TestStorageSuite, createS3TestStorageSuite } from './helpers/s3TestFactory.js';
|
|
@@ -62,6 +66,234 @@ describe('S3 object storage reads', () => {
|
|
|
62
66
|
);
|
|
63
67
|
});
|
|
64
68
|
|
|
69
|
+
test('derives request timeouts from the AWS defaults mode', () => {
|
|
70
|
+
// legacy - the mode used when nothing is configured - defines no timeouts of its own,
|
|
71
|
+
// and uses the same baseline as standard.
|
|
72
|
+
expect(resolveTimeoutProfile('legacy')).toEqual({
|
|
73
|
+
connectionTimeoutMs: 3_100,
|
|
74
|
+
requestTimeoutMs: 15_500,
|
|
75
|
+
operationTimeoutMs: 31_000,
|
|
76
|
+
queueTimeoutMs: 124_000
|
|
77
|
+
});
|
|
78
|
+
expect(resolveTimeoutProfile('standard')).toEqual(resolveTimeoutProfile('legacy'));
|
|
79
|
+
expect(resolveTimeoutProfile('cross-region')).toEqual(resolveTimeoutProfile('legacy'));
|
|
80
|
+
expect(resolveTimeoutProfile('in-region')).toEqual({
|
|
81
|
+
connectionTimeoutMs: 1_100,
|
|
82
|
+
requestTimeoutMs: 5_500,
|
|
83
|
+
operationTimeoutMs: 11_000,
|
|
84
|
+
queueTimeoutMs: 44_000
|
|
85
|
+
});
|
|
86
|
+
expect(resolveTimeoutProfile('mobile')).toEqual({
|
|
87
|
+
connectionTimeoutMs: 30_000,
|
|
88
|
+
requestTimeoutMs: 150_000,
|
|
89
|
+
operationTimeoutMs: 300_000,
|
|
90
|
+
queueTimeoutMs: 1_200_000
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test('resolves explicit and environment defaults modes without waiting on configuration', async () => {
|
|
95
|
+
// The timeouts are resolved up front, so operations never wait on configuration. The client
|
|
96
|
+
// wraps the mode in a provider of its own, which resolves to the same value.
|
|
97
|
+
const modeOf = async (objectStorage: S3ObjectStorage) => {
|
|
98
|
+
const configured = objectStorage.client.config.defaultsMode;
|
|
99
|
+
return typeof configured === 'function' ? await configured() : configured;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const previousMode = process.env.AWS_DEFAULTS_MODE;
|
|
103
|
+
try {
|
|
104
|
+
process.env.AWS_DEFAULTS_MODE = 'cross-region';
|
|
105
|
+
await expect(modeOf(new S3ObjectStorage({ bucket: 'test', region: 'test' }))).resolves.toEqual('cross-region');
|
|
106
|
+
|
|
107
|
+
// The storage option takes precedence over the environment.
|
|
108
|
+
await expect(
|
|
109
|
+
modeOf(new S3ObjectStorage({ bucket: 'test', region: 'test', defaultsMode: 'in-region' }))
|
|
110
|
+
).resolves.toEqual('in-region');
|
|
111
|
+
|
|
112
|
+
// 'auto' would query the EC2 instance metadata service, and requires a resolvable region.
|
|
113
|
+
await expect(modeOf(new S3ObjectStorage({ bucket: 'test', defaultsMode: 'auto' }))).resolves.toEqual('standard');
|
|
114
|
+
|
|
115
|
+
delete process.env.AWS_DEFAULTS_MODE;
|
|
116
|
+
await expect(modeOf(new S3ObjectStorage({ bucket: 'test', region: 'test' }))).resolves.toEqual('legacy');
|
|
117
|
+
|
|
118
|
+
// An invalid mode fails on startup, rather than on every operation.
|
|
119
|
+
expect(
|
|
120
|
+
() => new S3ObjectStorage({ bucket: 'test', region: 'test', defaultsMode: 'nonsense' as any })
|
|
121
|
+
).toThrowError(/Invalid AWS defaults mode "nonsense"/);
|
|
122
|
+
} finally {
|
|
123
|
+
if (previousMode == null) {
|
|
124
|
+
delete process.env.AWS_DEFAULTS_MODE;
|
|
125
|
+
} else {
|
|
126
|
+
process.env.AWS_DEFAULTS_MODE = previousMode;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
test('cancels active uploads and deletes', async () => {
|
|
132
|
+
const operations = [
|
|
133
|
+
(objectStorage: S3ObjectStorage, signal: AbortSignal) =>
|
|
134
|
+
objectStorage.put(
|
|
135
|
+
'object',
|
|
136
|
+
new Uint8Array(),
|
|
137
|
+
{ contentType: 'application/bson', contentEncoding: null },
|
|
138
|
+
{ signal }
|
|
139
|
+
),
|
|
140
|
+
(objectStorage: S3ObjectStorage, signal: AbortSignal) => objectStorage.delete(['object'], { signal })
|
|
141
|
+
];
|
|
142
|
+
|
|
143
|
+
for (const startOperation of operations) {
|
|
144
|
+
const objectStorage = new S3ObjectStorage({ bucket: 'test', region: 'test' });
|
|
145
|
+
const controller = new AbortController();
|
|
146
|
+
let requestStarted!: () => void;
|
|
147
|
+
const started = new Promise<void>((resolve) => (requestStarted = resolve));
|
|
148
|
+
objectStorage.client.send = async (_command: any, options: any) => {
|
|
149
|
+
requestStarted();
|
|
150
|
+
await new Promise<void>((_resolve, reject) => {
|
|
151
|
+
const abort = () => reject(options.abortSignal.reason);
|
|
152
|
+
if (options.abortSignal.aborted) {
|
|
153
|
+
abort();
|
|
154
|
+
} else {
|
|
155
|
+
options.abortSignal.addEventListener('abort', abort, { once: true });
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
throw new Error('unreachable');
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
const running = startOperation(objectStorage, controller.signal);
|
|
162
|
+
const expectation = expect(running).rejects.toMatchObject({ name: 'AbortError' });
|
|
163
|
+
await started;
|
|
164
|
+
controller.abort();
|
|
165
|
+
await expectation;
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
test('reports why a streaming operation was cancelled', async () => {
|
|
170
|
+
// Aborting mid-stream destroys the socket, and the stream fails with a generic 'aborted'
|
|
171
|
+
// error. The operation reports the actual cause instead.
|
|
172
|
+
const stalledDownload = (objectStorage: S3ObjectStorage) => {
|
|
173
|
+
objectStorage.client.send = async (_command: any, options: any) => ({
|
|
174
|
+
ContentLength: 10,
|
|
175
|
+
ContentType: 'application/bson',
|
|
176
|
+
Body: (async function* () {
|
|
177
|
+
yield new Uint8Array([1, 2, 3]);
|
|
178
|
+
await new Promise<void>((_resolve, reject) => {
|
|
179
|
+
const abort = () => reject(new Error('stream aborted'));
|
|
180
|
+
if (options.abortSignal.aborted) {
|
|
181
|
+
abort();
|
|
182
|
+
} else {
|
|
183
|
+
options.abortSignal.addEventListener('abort', abort, { once: true });
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
})()
|
|
187
|
+
});
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
const timingOut = new S3ObjectStorage({ bucket: 'test', region: 'test' });
|
|
191
|
+
(timingOut as any).timeouts = {
|
|
192
|
+
...resolveTimeoutProfile('standard'),
|
|
193
|
+
operationTimeoutMs: 50
|
|
194
|
+
} satisfies S3TimeoutProfile;
|
|
195
|
+
stalledDownload(timingOut);
|
|
196
|
+
await expect(timingOut.get('stalled-object')).rejects.toMatchObject({
|
|
197
|
+
name: 'ObjectStorageError',
|
|
198
|
+
retryable: true,
|
|
199
|
+
message: expect.stringContaining('did not complete within 50 ms')
|
|
200
|
+
} satisfies Partial<ObjectStorageError>);
|
|
201
|
+
|
|
202
|
+
// A caller abort is a cancellation, not a retryable failure.
|
|
203
|
+
const cancelled = new S3ObjectStorage({ bucket: 'test', region: 'test' });
|
|
204
|
+
stalledDownload(cancelled);
|
|
205
|
+
const controller = new AbortController();
|
|
206
|
+
const reading = cancelled.get('stalled-object', { signal: controller.signal });
|
|
207
|
+
const expectation = expect(reading).rejects.toMatchObject({ name: 'AbortError' });
|
|
208
|
+
controller.abort();
|
|
209
|
+
await expectation;
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
test('reports the caller abort reason unchanged', async () => {
|
|
213
|
+
// Callers abort with the error that stopped them, and upstream error handling matches on that
|
|
214
|
+
// type. Replacing it with an ObjectStorageError would hide it - for MongoDB replication, that
|
|
215
|
+
// loses the invalidation error that triggers a replication restart.
|
|
216
|
+
class StreamInvalidatedError extends Error {}
|
|
217
|
+
|
|
218
|
+
const objectStorage = new S3ObjectStorage({ bucket: 'test', region: 'test' });
|
|
219
|
+
const reason = new StreamInvalidatedError('stream invalidated');
|
|
220
|
+
const controller = new AbortController();
|
|
221
|
+
objectStorage.client.send = async (_command: any, options: any) => {
|
|
222
|
+
controller.abort(reason);
|
|
223
|
+
throw options.abortSignal.reason;
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
await expect(objectStorage.get('object', { signal: controller.signal })).rejects.toBe(reason);
|
|
227
|
+
await expect(
|
|
228
|
+
objectStorage.put(
|
|
229
|
+
'object',
|
|
230
|
+
new Uint8Array(),
|
|
231
|
+
{ contentType: 'application/bson', contentEncoding: null },
|
|
232
|
+
{ signal: controller.signal }
|
|
233
|
+
)
|
|
234
|
+
).rejects.toBe(reason);
|
|
235
|
+
await expect(objectStorage.delete(['object'], { signal: controller.signal })).rejects.toBe(reason);
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
test('times out waiting for an operation slot', async () => {
|
|
239
|
+
const objectStorage = new S3ObjectStorage({ bucket: 'test', region: 'test', concurrencyLimit: 1 });
|
|
240
|
+
(objectStorage as any).timeouts = {
|
|
241
|
+
connectionTimeoutMs: 10,
|
|
242
|
+
requestTimeoutMs: 20,
|
|
243
|
+
operationTimeoutMs: 10_000,
|
|
244
|
+
queueTimeoutMs: 50
|
|
245
|
+
} satisfies S3TimeoutProfile;
|
|
246
|
+
let releaseBlocker!: () => void;
|
|
247
|
+
const blocked = new Promise<void>((resolve) => (releaseBlocker = resolve));
|
|
248
|
+
objectStorage.client.send = async () => {
|
|
249
|
+
await blocked;
|
|
250
|
+
return { ContentLength: 0, Body: (async function* () {})(), ContentType: 'application/bson' };
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
// The single slot is held by the first upload, which has no signal of its own.
|
|
254
|
+
const holding = objectStorage.put('held-object', new Uint8Array(), {
|
|
255
|
+
contentType: 'application/bson',
|
|
256
|
+
contentEncoding: null
|
|
257
|
+
});
|
|
258
|
+
await expect(objectStorage.get('queued-object')).rejects.toMatchObject({
|
|
259
|
+
name: 'ObjectStorageError',
|
|
260
|
+
retryable: true,
|
|
261
|
+
message: expect.stringContaining('waiting for a concurrency slot')
|
|
262
|
+
} satisfies Partial<ObjectStorageError>);
|
|
263
|
+
|
|
264
|
+
releaseBlocker();
|
|
265
|
+
await holding;
|
|
266
|
+
// The slot is usable again once the blocking operation completes.
|
|
267
|
+
await expect(objectStorage.get('later-object')).resolves.toMatchObject({ data: new Uint8Array(0) });
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
test('reports a caller abort while queued as a cancellation', async () => {
|
|
271
|
+
const objectStorage = new S3ObjectStorage({ bucket: 'test', region: 'test', concurrencyLimit: 1 });
|
|
272
|
+
const controller = new AbortController();
|
|
273
|
+
let holderStarted!: () => void;
|
|
274
|
+
const started = new Promise<void>((resolve) => (holderStarted = resolve));
|
|
275
|
+
let releaseHolder!: () => void;
|
|
276
|
+
const blocked = new Promise<void>((resolve) => (releaseHolder = resolve));
|
|
277
|
+
objectStorage.client.send = async () => {
|
|
278
|
+
holderStarted();
|
|
279
|
+
await blocked;
|
|
280
|
+
return {};
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
const holding = objectStorage.put('held-object', new Uint8Array(), {
|
|
284
|
+
contentType: 'application/bson',
|
|
285
|
+
contentEncoding: null
|
|
286
|
+
});
|
|
287
|
+
await started;
|
|
288
|
+
|
|
289
|
+
const queuedRead = objectStorage.get('queued-object', { signal: controller.signal });
|
|
290
|
+
const expectation = expect(queuedRead).rejects.toMatchObject({ name: 'AbortError' });
|
|
291
|
+
controller.abort();
|
|
292
|
+
await expectation;
|
|
293
|
+
releaseHolder();
|
|
294
|
+
await holding;
|
|
295
|
+
});
|
|
296
|
+
|
|
65
297
|
test('rejects complete S3 keys over the safe byte limit', async () => {
|
|
66
298
|
const objectStorage = new S3ObjectStorage({
|
|
67
299
|
bucket: 'test',
|
|
@@ -125,6 +357,16 @@ describe('S3 object storage reads', () => {
|
|
|
125
357
|
message: expect.stringContaining('S3 download failed for transient-object')
|
|
126
358
|
} satisfies Partial<ObjectStorageError>);
|
|
127
359
|
|
|
360
|
+
const timeoutCause = new DOMException('The operation was aborted due to timeout', 'TimeoutError');
|
|
361
|
+
objectStorage.client.send = async () => {
|
|
362
|
+
throw timeoutCause;
|
|
363
|
+
};
|
|
364
|
+
await expect(objectStorage.get('timed-out-object')).rejects.toMatchObject({
|
|
365
|
+
name: 'ObjectStorageError',
|
|
366
|
+
retryable: true,
|
|
367
|
+
cause: timeoutCause
|
|
368
|
+
} satisfies Partial<ObjectStorageError>);
|
|
369
|
+
|
|
128
370
|
const permanentCause = Object.assign(new Error('access denied'), {
|
|
129
371
|
name: 'AccessDenied',
|
|
130
372
|
$metadata: { httpStatusCode: 403 }
|
|
@@ -334,6 +576,52 @@ describe('S3 object storage reads', () => {
|
|
|
334
576
|
expect(maxActiveOperations).toBe(4);
|
|
335
577
|
});
|
|
336
578
|
|
|
579
|
+
test('drains sibling downloads before reporting a hydration failure', async () => {
|
|
580
|
+
const objectStorage = new MemoryObjectStorage();
|
|
581
|
+
const gate = Promise.withResolvers<void>();
|
|
582
|
+
const failure = new Error('download failed');
|
|
583
|
+
const documents = ['failed', 'pending'].map((path, index) => ({
|
|
584
|
+
_id: { b: 'bucket', o: BigInt(index + 1) },
|
|
585
|
+
min_op: BigInt(index + 1),
|
|
586
|
+
checksum: 0n,
|
|
587
|
+
count: 0,
|
|
588
|
+
size: 1,
|
|
589
|
+
storage_ref: { path, file_size: 1 }
|
|
590
|
+
}));
|
|
591
|
+
const get = vi.spyOn(objectStorage, 'get').mockImplementation(async (path) => {
|
|
592
|
+
if (path === 'failed') {
|
|
593
|
+
throw failure;
|
|
594
|
+
}
|
|
595
|
+
await gate.promise;
|
|
596
|
+
return {
|
|
597
|
+
data: bson.serialize({ ops: [] }),
|
|
598
|
+
metadata: { contentType: 'application/bson', contentEncoding: null }
|
|
599
|
+
};
|
|
600
|
+
});
|
|
601
|
+
let settled = false;
|
|
602
|
+
const result = hydrateBucketDataDocuments(documents, objectStorage, {}).then(
|
|
603
|
+
() => {
|
|
604
|
+
settled = true;
|
|
605
|
+
return undefined;
|
|
606
|
+
},
|
|
607
|
+
(error) => {
|
|
608
|
+
settled = true;
|
|
609
|
+
return error;
|
|
610
|
+
}
|
|
611
|
+
);
|
|
612
|
+
try {
|
|
613
|
+
await vi.waitFor(() => expect(get).toHaveBeenCalledTimes(2));
|
|
614
|
+
await new Promise<void>((resolve) => setImmediate(resolve));
|
|
615
|
+
expect(settled).toBe(false);
|
|
616
|
+
} finally {
|
|
617
|
+
gate.resolve();
|
|
618
|
+
await result;
|
|
619
|
+
get.mockRestore();
|
|
620
|
+
}
|
|
621
|
+
expect(await result).toBe(failure);
|
|
622
|
+
expect(documents[1]).toHaveProperty('ops', []);
|
|
623
|
+
});
|
|
624
|
+
|
|
337
625
|
test('aborts active object downloads', async () => {
|
|
338
626
|
const objectStorage = new MemoryObjectStorage();
|
|
339
627
|
const controller = new AbortController();
|
|
@@ -374,7 +662,7 @@ describe('S3 object storage reads', () => {
|
|
|
374
662
|
const { memoryStorage, factory: factoryGen } = memoryS3Factory();
|
|
375
663
|
await using factory = await factoryGen.factory();
|
|
376
664
|
const syncRules = await factory.updateSyncRules(updateSyncRulesFromYaml(SYNC_RULES_YAML, { storageVersion: 3 }));
|
|
377
|
-
const bucketStorage = factory
|
|
665
|
+
const bucketStorage = (await getTestStorage(factory, syncRules)) as MongoSyncBucketStorage;
|
|
378
666
|
|
|
379
667
|
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
380
668
|
const sourceTable = await test_utils.resolveTestTable(writer, 'items', ['id'], factoryGen, 1);
|
|
@@ -422,7 +710,7 @@ describe('S3 object storage reads', () => {
|
|
|
422
710
|
const { factory: factoryGen } = s3Factory();
|
|
423
711
|
await using factory = await factoryGen.factory();
|
|
424
712
|
const syncRules = await factory.updateSyncRules(updateSyncRulesFromYaml(SYNC_RULES_YAML, { storageVersion: 3 }));
|
|
425
|
-
const bucketStorage = factory
|
|
713
|
+
const bucketStorage = (await getTestStorage(factory, syncRules)) as MongoSyncBucketStorage;
|
|
426
714
|
|
|
427
715
|
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
428
716
|
const sourceTable = await test_utils.resolveTestTable(writer, 'items', ['id'], factoryGen, 1);
|
|
@@ -475,7 +763,7 @@ describe('S3 object storage reads', () => {
|
|
|
475
763
|
const { memoryStorage, factory: factoryGen } = memoryS3Factory({ inlineThresholdBytes: 1_000 });
|
|
476
764
|
await using factory = await factoryGen.factory();
|
|
477
765
|
const syncRules = await factory.updateSyncRules(updateSyncRulesFromYaml(SYNC_RULES_YAML, { storageVersion: 3 }));
|
|
478
|
-
const bucketStorage = factory
|
|
766
|
+
const bucketStorage = (await getTestStorage(factory, syncRules)) as MongoSyncBucketStorage;
|
|
479
767
|
|
|
480
768
|
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
481
769
|
const sourceTable = await test_utils.resolveTestTable(writer, 'items', ['id'], factoryGen, 1);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { storage, updateSyncRulesFromYaml } from '@powersync/service-core';
|
|
2
|
-
import { test_utils } from '@powersync/service-core-tests';
|
|
2
|
+
import { getTestStorage, test_utils } from '@powersync/service-core-tests';
|
|
3
3
|
import * as bson from 'bson';
|
|
4
4
|
import { describe, expect, test } from 'vitest';
|
|
5
5
|
import { MongoSyncBucketStorage } from '../../src/storage/implementation/createMongoSyncBucketStorage.js';
|
|
@@ -28,7 +28,7 @@ describe('S3 object storage writes', () => {
|
|
|
28
28
|
const { memoryStorage, factory: factoryGen } = memoryS3Factory();
|
|
29
29
|
await using factory = await factoryGen.factory();
|
|
30
30
|
const syncRules = await factory.updateSyncRules(updateSyncRulesFromYaml(SYNC_RULES_YAML, { storageVersion: 3 }));
|
|
31
|
-
const bucketStorage = factory
|
|
31
|
+
const bucketStorage = (await getTestStorage(factory, syncRules)) as MongoSyncBucketStorage;
|
|
32
32
|
|
|
33
33
|
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
34
34
|
const sourceTable = await test_utils.resolveTestTable(writer, 'items', ['id'], factoryGen, 1);
|
|
@@ -65,6 +65,7 @@ describe('S3 object storage writes', () => {
|
|
|
65
65
|
{ op: 'PUT', row_id: 'item2' }
|
|
66
66
|
]);
|
|
67
67
|
expect(ops.every((op) => op.data != null)).toBe(true);
|
|
68
|
+
expect(ops.every((op) => typeof op.subkey == 'string')).toBe(true);
|
|
68
69
|
|
|
69
70
|
// Verify the corresponding MongoDB metadata shell.
|
|
70
71
|
const db = bucketStorage.db as VersionedPowerSyncMongoV3;
|
|
@@ -94,7 +95,7 @@ describe('S3 object storage writes', () => {
|
|
|
94
95
|
const { memoryStorage, factory: factoryGen } = memoryS3Factory();
|
|
95
96
|
await using factory = await factoryGen.factory();
|
|
96
97
|
const syncRules = await factory.updateSyncRules(updateSyncRulesFromYaml(SYNC_RULES_YAML, { storageVersion: 3 }));
|
|
97
|
-
const bucketStorage = factory
|
|
98
|
+
const bucketStorage = (await getTestStorage(factory, syncRules)) as MongoSyncBucketStorage;
|
|
98
99
|
|
|
99
100
|
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
100
101
|
const sourceTable = await test_utils.resolveTestTable(writer, 'items', ['id'], factoryGen, 4);
|