@powersync/service-core-tests 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.
- package/CHANGELOG.md +15 -0
- package/LICENSE +67 -0
- package/README.md +5 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/test-utils/bucket-validation.d.ts +42 -0
- package/dist/test-utils/bucket-validation.js +115 -0
- package/dist/test-utils/bucket-validation.js.map +1 -0
- package/dist/test-utils/general-utils.d.ts +31 -0
- package/dist/test-utils/general-utils.js +81 -0
- package/dist/test-utils/general-utils.js.map +1 -0
- package/dist/test-utils/stream_utils.d.ts +6 -0
- package/dist/test-utils/stream_utils.js +37 -0
- package/dist/test-utils/stream_utils.js.map +1 -0
- package/dist/test-utils/test-utils-index.d.ts +3 -0
- package/dist/test-utils/test-utils-index.js +4 -0
- package/dist/test-utils/test-utils-index.js.map +1 -0
- package/dist/tests/register-bucket-validation-tests.d.ts +10 -0
- package/dist/tests/register-bucket-validation-tests.js +139 -0
- package/dist/tests/register-bucket-validation-tests.js.map +1 -0
- package/dist/tests/register-compacting-tests.d.ts +14 -0
- package/dist/tests/register-compacting-tests.js +343 -0
- package/dist/tests/register-compacting-tests.js.map +1 -0
- package/dist/tests/register-data-storage-tests.d.ts +14 -0
- package/dist/tests/register-data-storage-tests.js +1571 -0
- package/dist/tests/register-data-storage-tests.js.map +1 -0
- package/dist/tests/register-sync-tests.d.ts +11 -0
- package/dist/tests/register-sync-tests.js +538 -0
- package/dist/tests/register-sync-tests.js.map +1 -0
- package/dist/tests/tests-index.d.ts +4 -0
- package/dist/tests/tests-index.js +5 -0
- package/dist/tests/tests-index.js.map +1 -0
- package/package.json +28 -0
- package/src/index.ts +5 -0
- package/src/test-utils/bucket-validation.ts +120 -0
- package/src/test-utils/general-utils.ts +113 -0
- package/src/test-utils/stream_utils.ts +42 -0
- package/src/test-utils/test-utils-index.ts +4 -0
- package/src/tests/register-bucket-validation-tests.ts +148 -0
- package/src/tests/register-compacting-tests.ts +297 -0
- package/src/tests/register-data-storage-tests.ts +1552 -0
- package/src/tests/register-sync-tests.ts +521 -0
- package/src/tests/tests-index.ts +4 -0
- package/tsconfig.json +34 -0
- package/tsconfig.tsbuildinfo +1 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# @powersync/service-core-tests
|
|
2
|
+
|
|
3
|
+
## 0.0.0-dev-20241219091224
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 697d44b: Initial release of shared tests for different sync bucket storage providers
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [697d44b]
|
|
12
|
+
- Updated dependencies [697d44b]
|
|
13
|
+
- Updated dependencies [a66be3b]
|
|
14
|
+
- @powersync/service-core@0.0.0-dev-20241219091224
|
|
15
|
+
- @powersync/service-sync-rules@0.0.0-dev-20241219091224
|
package/LICENSE
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# Functional Source License, Version 1.1, Apache 2.0 Future License
|
|
2
|
+
|
|
3
|
+
## Abbreviation
|
|
4
|
+
|
|
5
|
+
FSL-1.1-Apache-2.0
|
|
6
|
+
|
|
7
|
+
## Notice
|
|
8
|
+
|
|
9
|
+
Copyright 2023-2024 Journey Mobile, Inc.
|
|
10
|
+
|
|
11
|
+
## Terms and Conditions
|
|
12
|
+
|
|
13
|
+
### Licensor ("We")
|
|
14
|
+
|
|
15
|
+
The party offering the Software under these Terms and Conditions.
|
|
16
|
+
|
|
17
|
+
### The Software
|
|
18
|
+
|
|
19
|
+
The "Software" is each version of the software that we make available under these Terms and Conditions, as indicated by our inclusion of these Terms and Conditions with the Software.
|
|
20
|
+
|
|
21
|
+
### License Grant
|
|
22
|
+
|
|
23
|
+
Subject to your compliance with this License Grant and the Patents, Redistribution and Trademark clauses below, we hereby grant you the right to use, copy, modify, create derivative works, publicly perform, publicly display and redistribute the Software for any Permitted Purpose identified below.
|
|
24
|
+
|
|
25
|
+
### Permitted Purpose
|
|
26
|
+
|
|
27
|
+
A Permitted Purpose is any purpose other than a Competing Use. A Competing Use means making the Software available to others in a commercial product or service that:
|
|
28
|
+
|
|
29
|
+
1. substitutes for the Software;
|
|
30
|
+
2. substitutes for any other product or service we offer using the Software that exists as of the date we make the Software available; or
|
|
31
|
+
3. offers the same or substantially similar functionality as the Software.
|
|
32
|
+
|
|
33
|
+
Permitted Purposes specifically include using the Software:
|
|
34
|
+
|
|
35
|
+
1. for your internal use and access;
|
|
36
|
+
2. for non-commercial education;
|
|
37
|
+
3. for non-commercial research; and
|
|
38
|
+
4. in connection with professional services that you provide to a licensee using the Software in accordance with these Terms and Conditions.
|
|
39
|
+
|
|
40
|
+
### Patents
|
|
41
|
+
|
|
42
|
+
To the extent your use for a Permitted Purpose would necessarily infringe our patents, the license grant above includes a license under our patents. If you make a claim against any party that the Software infringes or contributes to the infringement of any patent, then your patent license to the Software ends immediately.
|
|
43
|
+
|
|
44
|
+
### Redistribution
|
|
45
|
+
|
|
46
|
+
The Terms and Conditions apply to all copies, modifications and derivatives of the Software.
|
|
47
|
+
If you redistribute any copies, modifications or derivatives of the Software, you must include a copy of or a link to these Terms and Conditions and not remove any copyright notices provided in or with the Software.
|
|
48
|
+
|
|
49
|
+
### Disclaimer
|
|
50
|
+
|
|
51
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
|
|
52
|
+
IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES, EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
|
|
53
|
+
|
|
54
|
+
### Trademarks
|
|
55
|
+
|
|
56
|
+
Except for displaying the License Details and identifying us as the origin of the Software, you have no right under these Terms and Conditions to use our trademarks, trade names, service marks or product names.
|
|
57
|
+
|
|
58
|
+
## Grant of Future License
|
|
59
|
+
|
|
60
|
+
We hereby irrevocably grant you an additional license to use the Software under the Apache License, Version 2.0 that is effective on the second anniversary of the date we make the Software available. On or after that date, you may use the Software under the Apache License, Version 2.0, in which case the following will apply:
|
|
61
|
+
|
|
62
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
|
|
63
|
+
You may obtain a copy of the License at
|
|
64
|
+
|
|
65
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
66
|
+
|
|
67
|
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
package/README.md
ADDED
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kCAAkC,CAAC;AACjD,OAAO,KAAK,UAAU,MAAM,kCAAkC,CAAC;AAE/D,cAAc,wBAAwB,CAAC;AACvC,OAAO,KAAK,QAAQ,MAAM,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { utils } from '@powersync/service-core';
|
|
2
|
+
/**
|
|
3
|
+
* Reduce a bucket to the final state as stored on the client.
|
|
4
|
+
*
|
|
5
|
+
* This keeps the final state for each row as a PUT operation.
|
|
6
|
+
*
|
|
7
|
+
* All other operations are replaced with a single CLEAR operation,
|
|
8
|
+
* summing their checksums, and using a 0 as an op_id.
|
|
9
|
+
*
|
|
10
|
+
* This is the function $r(B)$, as described in /docs/bucket-properties.md.
|
|
11
|
+
*/
|
|
12
|
+
export declare function reduceBucket(operations: utils.OplogEntry[]): utils.OplogEntry[];
|
|
13
|
+
/**
|
|
14
|
+
import { OplogEntry } from '@/util/protocol-types.js';
|
|
15
|
+
import { reduceBucket } from '@/util/utils.js';
|
|
16
|
+
import { expect } from 'vitest';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Validate this property, as described in /docs/bucket-properties.md:
|
|
20
|
+
*
|
|
21
|
+
* $r(B_{[..id_n]}) = r(r(B_{[..id_i]}) \cup B_{[id_{i+1}..id_n]}) \;\forall\; i \in [1..n]$
|
|
22
|
+
*
|
|
23
|
+
* We test that a client syncing the entire bucket in one go (left side of the equation),
|
|
24
|
+
* ends up with the same result as another client syncing up to operation id_i, then sync
|
|
25
|
+
* the rest.
|
|
26
|
+
*/
|
|
27
|
+
export declare function validateBucket(bucket: utils.OplogEntry[]): void;
|
|
28
|
+
/**
|
|
29
|
+
* Validate these properties for a bucket $B$ and its compacted version $B'$,:
|
|
30
|
+
* as described in /docs/bucket-properties.md:
|
|
31
|
+
*
|
|
32
|
+
* 1. $r(B) = r(B')$
|
|
33
|
+
* 2. $r(B_{[..c]}) = r(r(B_{[..c_i]}) \cup B'_{[c_i+1..c]}) \;\forall\; c_i \in B$
|
|
34
|
+
*
|
|
35
|
+
* The first one is that the result of syncing the original bucket is the same as
|
|
36
|
+
* syncing the compacted bucket.
|
|
37
|
+
*
|
|
38
|
+
* The second property is that result of syncing the entire original bucket, is the same
|
|
39
|
+
* as syncing any partial version of that (up to op $c_i$), and then continue syncing
|
|
40
|
+
* using the compacted bucket.
|
|
41
|
+
*/
|
|
42
|
+
export declare function validateCompactedBucket(bucket: utils.OplogEntry[], compacted: utils.OplogEntry[]): void;
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { utils } from '@powersync/service-core';
|
|
2
|
+
import { expect } from 'vitest';
|
|
3
|
+
/**
|
|
4
|
+
* Reduce a bucket to the final state as stored on the client.
|
|
5
|
+
*
|
|
6
|
+
* This keeps the final state for each row as a PUT operation.
|
|
7
|
+
*
|
|
8
|
+
* All other operations are replaced with a single CLEAR operation,
|
|
9
|
+
* summing their checksums, and using a 0 as an op_id.
|
|
10
|
+
*
|
|
11
|
+
* This is the function $r(B)$, as described in /docs/bucket-properties.md.
|
|
12
|
+
*/
|
|
13
|
+
export function reduceBucket(operations) {
|
|
14
|
+
let rowState = new Map();
|
|
15
|
+
let otherChecksum = 0;
|
|
16
|
+
for (let op of operations) {
|
|
17
|
+
const key = rowKey(op);
|
|
18
|
+
if (op.op == 'PUT') {
|
|
19
|
+
const existing = rowState.get(key);
|
|
20
|
+
if (existing) {
|
|
21
|
+
otherChecksum = utils.addChecksums(otherChecksum, existing.checksum);
|
|
22
|
+
}
|
|
23
|
+
rowState.set(key, op);
|
|
24
|
+
}
|
|
25
|
+
else if (op.op == 'REMOVE') {
|
|
26
|
+
const existing = rowState.get(key);
|
|
27
|
+
if (existing) {
|
|
28
|
+
otherChecksum = utils.addChecksums(otherChecksum, existing.checksum);
|
|
29
|
+
}
|
|
30
|
+
rowState.delete(key);
|
|
31
|
+
otherChecksum = utils.addChecksums(otherChecksum, op.checksum);
|
|
32
|
+
}
|
|
33
|
+
else if (op.op == 'CLEAR') {
|
|
34
|
+
rowState.clear();
|
|
35
|
+
otherChecksum = op.checksum;
|
|
36
|
+
}
|
|
37
|
+
else if (op.op == 'MOVE') {
|
|
38
|
+
otherChecksum = utils.addChecksums(otherChecksum, op.checksum);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
throw new Error(`Unknown operation ${op.op}`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const puts = [...rowState.values()].sort((a, b) => {
|
|
45
|
+
return Number(BigInt(a.op_id) - BigInt(b.op_id));
|
|
46
|
+
});
|
|
47
|
+
let finalState = [
|
|
48
|
+
// Special operation to indiciate the checksum remainder
|
|
49
|
+
{ op_id: '0', op: 'CLEAR', checksum: otherChecksum },
|
|
50
|
+
...puts
|
|
51
|
+
];
|
|
52
|
+
return finalState;
|
|
53
|
+
}
|
|
54
|
+
function rowKey(entry) {
|
|
55
|
+
return `${entry.object_type}/${entry.object_id}/${entry.subkey}`;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
import { OplogEntry } from '@/util/protocol-types.js';
|
|
59
|
+
import { reduceBucket } from '@/util/utils.js';
|
|
60
|
+
import { expect } from 'vitest';
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Validate this property, as described in /docs/bucket-properties.md:
|
|
64
|
+
*
|
|
65
|
+
* $r(B_{[..id_n]}) = r(r(B_{[..id_i]}) \cup B_{[id_{i+1}..id_n]}) \;\forall\; i \in [1..n]$
|
|
66
|
+
*
|
|
67
|
+
* We test that a client syncing the entire bucket in one go (left side of the equation),
|
|
68
|
+
* ends up with the same result as another client syncing up to operation id_i, then sync
|
|
69
|
+
* the rest.
|
|
70
|
+
*/
|
|
71
|
+
export function validateBucket(bucket) {
|
|
72
|
+
const r1 = reduceBucket(bucket);
|
|
73
|
+
for (let i = 0; i <= bucket.length; i++) {
|
|
74
|
+
const r2 = reduceBucket(bucket.slice(0, i + 1));
|
|
75
|
+
const b3 = bucket.slice(i + 1);
|
|
76
|
+
const r3 = r2.concat(b3);
|
|
77
|
+
const r4 = reduceBucket(r3);
|
|
78
|
+
expect(r4).toEqual(r1);
|
|
79
|
+
}
|
|
80
|
+
// This is the same check, just implemented differently
|
|
81
|
+
validateCompactedBucket(bucket, bucket);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Validate these properties for a bucket $B$ and its compacted version $B'$,:
|
|
85
|
+
* as described in /docs/bucket-properties.md:
|
|
86
|
+
*
|
|
87
|
+
* 1. $r(B) = r(B')$
|
|
88
|
+
* 2. $r(B_{[..c]}) = r(r(B_{[..c_i]}) \cup B'_{[c_i+1..c]}) \;\forall\; c_i \in B$
|
|
89
|
+
*
|
|
90
|
+
* The first one is that the result of syncing the original bucket is the same as
|
|
91
|
+
* syncing the compacted bucket.
|
|
92
|
+
*
|
|
93
|
+
* The second property is that result of syncing the entire original bucket, is the same
|
|
94
|
+
* as syncing any partial version of that (up to op $c_i$), and then continue syncing
|
|
95
|
+
* using the compacted bucket.
|
|
96
|
+
*/
|
|
97
|
+
export function validateCompactedBucket(bucket, compacted) {
|
|
98
|
+
// r(B_{[..c]})
|
|
99
|
+
const r1 = reduceBucket(bucket);
|
|
100
|
+
// r(B) = r(B')
|
|
101
|
+
expect(reduceBucket(compacted)).toEqual(r1);
|
|
102
|
+
for (let i = 0; i < bucket.length; i++) {
|
|
103
|
+
// r(B_{[..c_i]})
|
|
104
|
+
const r2 = reduceBucket(bucket.slice(0, i + 1));
|
|
105
|
+
const c_i = BigInt(bucket[i].op_id);
|
|
106
|
+
// B'_{[c_i+1..c]}
|
|
107
|
+
const b3 = compacted.filter((op) => BigInt(op.op_id) > c_i);
|
|
108
|
+
// r(B_{[..c_i]}) \cup B'_{[c_i+1..c]}
|
|
109
|
+
const r3 = r2.concat(b3);
|
|
110
|
+
// r(r(B_{[..c_i]}) \cup B'_{[c_i+1..c]})
|
|
111
|
+
const r4 = reduceBucket(r3);
|
|
112
|
+
expect(r4).toEqual(r1);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=bucket-validation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bucket-validation.js","sourceRoot":"","sources":["../../src/test-utils/bucket-validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC;;;;;;;;;GASG;AACH,MAAM,UAAU,YAAY,CAAC,UAA8B;IACzD,IAAI,QAAQ,GAAG,IAAI,GAAG,EAA4B,CAAC;IACnD,IAAI,aAAa,GAAG,CAAC,CAAC;IAEtB,KAAK,IAAI,EAAE,IAAI,UAAU,EAAE,CAAC;QAC1B,MAAM,GAAG,G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G;AACH,MAAM,UAAU,uBAAuB,CAAC,MAA0B,EAAE,SAA6B;IAC/F,eAAe;IACf,MAAM,EAAE,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC;IAChC,eAAe;IACf,MAAM,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IAE5C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACvC,iBAAiB;QACjB,MAAM,EAAE,GAAG,YAAY,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAChD,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;QACpC,kBAAkB;QAClB,MAAM,EAAE,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC;QAC5D,sCAAsC;QACtC,MAAM,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QACzB,yCAAyC;QACzC,MAAM,EAAE,GAAG,YAAY,CAAC,EAAE,CAAC,CAAC;QAC5B,MAAM,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IACzB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { storage, utils } from '@powersync/service-core';
|
|
2
|
+
import * as bson from 'bson';
|
|
3
|
+
export interface StorageOptions {
|
|
4
|
+
/**
|
|
5
|
+
* By default, collections are only cleared/
|
|
6
|
+
* Setting this to true will drop the collections completely.
|
|
7
|
+
*/
|
|
8
|
+
dropAll?: boolean;
|
|
9
|
+
doNotClear?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export type StorageFactory = (options?: StorageOptions) => Promise<storage.BucketStorageFactory>;
|
|
12
|
+
export declare const ZERO_LSN = "0/0";
|
|
13
|
+
export declare const PARSE_OPTIONS: storage.ParseSyncRulesOptions;
|
|
14
|
+
export declare const BATCH_OPTIONS: storage.StartBatchOptions;
|
|
15
|
+
export declare function testRules(content: string): storage.PersistedSyncRulesContent;
|
|
16
|
+
export declare function makeTestTable(name: string, columns?: string[] | undefined): storage.SourceTable;
|
|
17
|
+
export declare function getBatchData(batch: utils.SyncBucketData[] | storage.SyncBucketDataBatch[] | storage.SyncBucketDataBatch): {
|
|
18
|
+
op_id: string;
|
|
19
|
+
op: "PUT" | "REMOVE" | "MOVE" | "CLEAR";
|
|
20
|
+
object_id: string | undefined;
|
|
21
|
+
checksum: number | bigint;
|
|
22
|
+
}[];
|
|
23
|
+
export declare function getBatchMeta(batch: utils.SyncBucketData[] | storage.SyncBucketDataBatch[] | storage.SyncBucketDataBatch): {
|
|
24
|
+
has_more: boolean;
|
|
25
|
+
after: string;
|
|
26
|
+
next_after: string;
|
|
27
|
+
} | null;
|
|
28
|
+
/**
|
|
29
|
+
* Replica id in the old Postgres format, for backwards-compatible tests.
|
|
30
|
+
*/
|
|
31
|
+
export declare function rid(id: string): bson.UUID;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { storage, utils } from '@powersync/service-core';
|
|
2
|
+
import { SqlSyncRules } from '@powersync/service-sync-rules';
|
|
3
|
+
import * as bson from 'bson';
|
|
4
|
+
export const ZERO_LSN = '0/0';
|
|
5
|
+
export const PARSE_OPTIONS = {
|
|
6
|
+
defaultSchema: 'public'
|
|
7
|
+
};
|
|
8
|
+
export const BATCH_OPTIONS = {
|
|
9
|
+
...PARSE_OPTIONS,
|
|
10
|
+
zeroLSN: ZERO_LSN,
|
|
11
|
+
storeCurrentData: true
|
|
12
|
+
};
|
|
13
|
+
export function testRules(content) {
|
|
14
|
+
return {
|
|
15
|
+
id: 1,
|
|
16
|
+
sync_rules_content: content,
|
|
17
|
+
slot_name: 'test',
|
|
18
|
+
parsed(options) {
|
|
19
|
+
return {
|
|
20
|
+
id: 1,
|
|
21
|
+
sync_rules: SqlSyncRules.fromYaml(content, options),
|
|
22
|
+
slot_name: 'test'
|
|
23
|
+
};
|
|
24
|
+
},
|
|
25
|
+
lock() {
|
|
26
|
+
throw new Error('Not implemented');
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export function makeTestTable(name, columns) {
|
|
31
|
+
const relId = utils.hashData('table', name, (columns ?? ['id']).join(','));
|
|
32
|
+
const id = new bson.ObjectId('6544e3899293153fa7b38331');
|
|
33
|
+
return new storage.SourceTable(id, storage.SourceTable.DEFAULT_TAG, relId, 'public', name, (columns ?? ['id']).map((column) => ({ name: column, type: 'VARCHAR', typeId: 25 })), true);
|
|
34
|
+
}
|
|
35
|
+
export function getBatchData(batch) {
|
|
36
|
+
const first = getFirst(batch);
|
|
37
|
+
if (first == null) {
|
|
38
|
+
return [];
|
|
39
|
+
}
|
|
40
|
+
return first.data.map((d) => {
|
|
41
|
+
return {
|
|
42
|
+
op_id: d.op_id,
|
|
43
|
+
op: d.op,
|
|
44
|
+
object_id: d.object_id,
|
|
45
|
+
checksum: d.checksum
|
|
46
|
+
};
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
export function getBatchMeta(batch) {
|
|
50
|
+
const first = getFirst(batch);
|
|
51
|
+
if (first == null) {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
has_more: first.has_more,
|
|
56
|
+
after: first.after,
|
|
57
|
+
next_after: first.next_after
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function getFirst(batch) {
|
|
61
|
+
if (!Array.isArray(batch)) {
|
|
62
|
+
return batch.batch;
|
|
63
|
+
}
|
|
64
|
+
if (batch.length == 0) {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
let first = batch[0];
|
|
68
|
+
if (first.batch != null) {
|
|
69
|
+
return first.batch;
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
return first;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Replica id in the old Postgres format, for backwards-compatible tests.
|
|
77
|
+
*/
|
|
78
|
+
export function rid(id) {
|
|
79
|
+
return utils.getUuidReplicaIdentityBson({ id: id }, [{ name: 'id', type: 'VARCHAR', typeId: 25 }]);
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=general-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"general-utils.js","sourceRoot":"","sources":["../../src/test-utils/general-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAC7D,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAa7B,MAAM,CAAC,MAAM,QAAQ,GAAG,KAAK,CAAC;AAE9B,MAAM,CAAC,MAAM,aAAa,GAAkC;IAC1D,aAAa,EAAE,QAAQ;CACxB,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAA8B;IACtD,GAAG,aAAa;IAChB,OAAO,EAAE,QAAQ;IACjB,gBAAgB,EAAE,IAAI;CACvB,CAAC;AAEF,MAAM,UAAU,SAAS,CAAC,OAAe;IACvC,OAAO;QACL,EAAE,EAAE,CAAC;QACL,kBAAkB,EAAE,OAAO;QAC3B,SAAS,EAAE,MAAM;QACjB,MAAM,CAAC,OAAO;YACZ,OAAO;gBACL,EAAE,EAAE,CAAC;gBACL,UAAU,EAAE,YAAY,CAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;gBACnD,SAAS,EAAE,MAAM;aAClB,CAAC;QACJ,CAAC;QACD,IAAI;YACF,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;QACrC,CAAC;KACF,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,aAAa,CA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AO;QACL,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,UAAU,EAAE,KAAK,CAAC,UAAU;KAC7B,CAAC;AACJ,CAAC;AAED,SAAS,QAAQ,CACf,KAA2F;IAE3F,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAC1B,OAAO,KAAK,CAAC,KAAK,CAAC;IACrB,CAAC;IACD,IAAI,KAAK,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC;QACtB,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;IACrB,IAAK,KAAqC,CAAC,KAAK,IAAI,IAAI,EAAE,CAAC;QACzD,OAAQ,KAAqC,CAAC,KAAK,CAAC;IACtD,CAAC;SAAM,CAAC;QACN,OAAO,KAA6B,CAAC;IACvC,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,GAAG,CAAC,EAAU;IAC5B,OAAO,KAAK,CAAC,0BAA0B,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;AACrG,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { utils } from '@powersync/service-core';
|
|
2
|
+
export declare function putOp(table: string, data: Record<string, any>): Partial<utils.OplogEntry>;
|
|
3
|
+
export declare function removeOp(table: string, id: string): Partial<utils.OplogEntry>;
|
|
4
|
+
export declare function compareIds(a: utils.OplogEntry, b: utils.OplogEntry): number;
|
|
5
|
+
export declare function oneFromAsync<T>(source: Iterable<T> | AsyncIterable<T>): Promise<T>;
|
|
6
|
+
export declare function fromAsync<T>(source: Iterable<T> | AsyncIterable<T>): Promise<T[]>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { JSONBig } from '@powersync/service-jsonbig';
|
|
2
|
+
export function putOp(table, data) {
|
|
3
|
+
return {
|
|
4
|
+
op: 'PUT',
|
|
5
|
+
object_type: table,
|
|
6
|
+
object_id: data.id,
|
|
7
|
+
data: JSONBig.stringify(data)
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
export function removeOp(table, id) {
|
|
11
|
+
return {
|
|
12
|
+
op: 'REMOVE',
|
|
13
|
+
object_type: table,
|
|
14
|
+
object_id: id
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export function compareIds(a, b) {
|
|
18
|
+
return a.object_id.localeCompare(b.object_id);
|
|
19
|
+
}
|
|
20
|
+
export async function oneFromAsync(source) {
|
|
21
|
+
const items = [];
|
|
22
|
+
for await (const item of source) {
|
|
23
|
+
items.push(item);
|
|
24
|
+
}
|
|
25
|
+
if (items.length != 1) {
|
|
26
|
+
throw new Error(`One item expected, got: ${items.length}`);
|
|
27
|
+
}
|
|
28
|
+
return items[0];
|
|
29
|
+
}
|
|
30
|
+
export async function fromAsync(source) {
|
|
31
|
+
const items = [];
|
|
32
|
+
for await (const item of source) {
|
|
33
|
+
items.push(item);
|
|
34
|
+
}
|
|
35
|
+
return items;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=stream_utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream_utils.js","sourceRoot":"","sources":["../../src/test-utils/stream_utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAErD,MAAM,UAAU,KAAK,CAAC,KAAa,EAAE,IAAyB;IAC5D,OAAO;QACL,EAAE,EAAE,KAAK;QACT,WAAW,EAAE,KAAK;QAClB,SAAS,EAAE,IAAI,CAAC,EAAE;QAClB,IAAI,EAAE,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC;KAC9B,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,KAAa,EAAE,EAAU;IAChD,OAAO;QACL,EAAE,EAAE,QAAQ;QACZ,WAAW,EAAE,KAAK;QAClB,SAAS,EAAE,EAAE;KACd,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,CAAmB,EAAE,CAAmB;IACjE,OAAO,CAAC,CAAC,SAAU,CAAC,aAAa,CAAC,CAAC,CAAC,SAAU,CAAC,CAAC;AAClD,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,YAAY,CAAI,MAAsC;IAC1E,MAAM,KAAK,GAAQ,EAAE,CAAC;IACtB,IAAI,KAAK,EAAE,MAAM,IAAI,IAAI,MAAM,EAAE,CAAC;QAChC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACnB,CAAC;IACD,IAAI,KAAK,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC;QACtB,MAAM,IAAI,KAAK,CAAC,2BAA2B,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC;IAC7D,CAAC;IACD,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,SAAS,CAAI,MAAsC;IACvE,MAAM,KAAK,GAAQ,EAAE,CAAC;IACtB,IAAI,KAAK,EAAE,MAAM,IAAI,IAAI,MAAM,EAAE,CAAC;QAChC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACnB,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-utils-index.js","sourceRoot":"","sources":["../../src/test-utils/test-utils-index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This tests the reduceBucket function.
|
|
3
|
+
* While this function is not used directly in the service implementation,
|
|
4
|
+
* it is an important part of validating consistency in other tests.
|
|
5
|
+
* @example
|
|
6
|
+
* ```TypeScript
|
|
7
|
+
* describe('bucket validation', registerBucketValidationTests);
|
|
8
|
+
* ```
|
|
9
|
+
*/
|
|
10
|
+
export declare function registerBucketValidationTests(): void;
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { expect, test } from 'vitest';
|
|
2
|
+
import * as test_utils from '../test-utils/test-utils-index.js';
|
|
3
|
+
/**
|
|
4
|
+
* This tests the reduceBucket function.
|
|
5
|
+
* While this function is not used directly in the service implementation,
|
|
6
|
+
* it is an important part of validating consistency in other tests.
|
|
7
|
+
* @example
|
|
8
|
+
* ```TypeScript
|
|
9
|
+
* describe('bucket validation', registerBucketValidationTests);
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export function registerBucketValidationTests() {
|
|
13
|
+
const ops1 = [
|
|
14
|
+
{
|
|
15
|
+
op_id: '1',
|
|
16
|
+
op: 'PUT',
|
|
17
|
+
object_type: 'test',
|
|
18
|
+
object_id: 't1',
|
|
19
|
+
checksum: 2634521662,
|
|
20
|
+
subkey: '6544e3899293153fa7b38331/117ab485-4b42-58a2-ab32-0053a22c3423',
|
|
21
|
+
data: '{"id":"t1"}'
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
op_id: '2',
|
|
25
|
+
op: 'PUT',
|
|
26
|
+
object_type: 'test',
|
|
27
|
+
object_id: 't2',
|
|
28
|
+
checksum: 4243212114,
|
|
29
|
+
subkey: '6544e3899293153fa7b38331/ec27c691-b47a-5d92-927a-9944feb89eee',
|
|
30
|
+
data: '{"id":"t2"}'
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
op_id: '3',
|
|
34
|
+
op: 'REMOVE',
|
|
35
|
+
object_type: 'test',
|
|
36
|
+
object_id: 't1',
|
|
37
|
+
checksum: 4228978084,
|
|
38
|
+
subkey: '6544e3899293153fa7b38331/117ab485-4b42-58a2-ab32-0053a22c3423',
|
|
39
|
+
data: null
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
op_id: '4',
|
|
43
|
+
op: 'PUT',
|
|
44
|
+
object_type: 'test',
|
|
45
|
+
object_id: 't2',
|
|
46
|
+
checksum: 4243212114,
|
|
47
|
+
subkey: '6544e3899293153fa7b38331/ec27c691-b47a-5d92-927a-9944feb89eee',
|
|
48
|
+
data: '{"id":"t2"}'
|
|
49
|
+
}
|
|
50
|
+
];
|
|
51
|
+
test('reduce 1', () => {
|
|
52
|
+
expect(test_utils.reduceBucket(ops1)).toEqual([
|
|
53
|
+
{
|
|
54
|
+
checksum: -1778190028,
|
|
55
|
+
op: 'CLEAR',
|
|
56
|
+
op_id: '0'
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
checksum: 4243212114,
|
|
60
|
+
data: '{"id":"t2"}',
|
|
61
|
+
object_id: 't2',
|
|
62
|
+
object_type: 'test',
|
|
63
|
+
op: 'PUT',
|
|
64
|
+
op_id: '4',
|
|
65
|
+
subkey: '6544e3899293153fa7b38331/ec27c691-b47a-5d92-927a-9944feb89eee'
|
|
66
|
+
}
|
|
67
|
+
]);
|
|
68
|
+
expect(test_utils.reduceBucket(test_utils.reduceBucket(ops1))).toEqual([
|
|
69
|
+
{
|
|
70
|
+
checksum: -1778190028,
|
|
71
|
+
op: 'CLEAR',
|
|
72
|
+
op_id: '0'
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
checksum: 4243212114,
|
|
76
|
+
data: '{"id":"t2"}',
|
|
77
|
+
object_id: 't2',
|
|
78
|
+
object_type: 'test',
|
|
79
|
+
op: 'PUT',
|
|
80
|
+
op_id: '4',
|
|
81
|
+
subkey: '6544e3899293153fa7b38331/ec27c691-b47a-5d92-927a-9944feb89eee'
|
|
82
|
+
}
|
|
83
|
+
]);
|
|
84
|
+
test_utils.validateBucket(ops1);
|
|
85
|
+
});
|
|
86
|
+
test('reduce 2', () => {
|
|
87
|
+
const bucket = [
|
|
88
|
+
...ops1,
|
|
89
|
+
{
|
|
90
|
+
checksum: 93784613,
|
|
91
|
+
op: 'CLEAR',
|
|
92
|
+
op_id: '5'
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
checksum: 5133378,
|
|
96
|
+
data: '{"id":"t3"}',
|
|
97
|
+
object_id: 't3',
|
|
98
|
+
object_type: 'test',
|
|
99
|
+
op: 'PUT',
|
|
100
|
+
op_id: '11',
|
|
101
|
+
subkey: '6544e3899293153fa7b38333/ec27c691-b47a-5d92-927a-9944feb89eee'
|
|
102
|
+
}
|
|
103
|
+
];
|
|
104
|
+
expect(test_utils.reduceBucket(bucket)).toEqual([
|
|
105
|
+
{
|
|
106
|
+
checksum: 93784613,
|
|
107
|
+
op: 'CLEAR',
|
|
108
|
+
op_id: '0'
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
checksum: 5133378,
|
|
112
|
+
data: '{"id":"t3"}',
|
|
113
|
+
object_id: 't3',
|
|
114
|
+
object_type: 'test',
|
|
115
|
+
op: 'PUT',
|
|
116
|
+
op_id: '11',
|
|
117
|
+
subkey: '6544e3899293153fa7b38333/ec27c691-b47a-5d92-927a-9944feb89eee'
|
|
118
|
+
}
|
|
119
|
+
]);
|
|
120
|
+
expect(test_utils.reduceBucket(test_utils.reduceBucket(bucket))).toEqual([
|
|
121
|
+
{
|
|
122
|
+
checksum: 93784613,
|
|
123
|
+
op: 'CLEAR',
|
|
124
|
+
op_id: '0'
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
checksum: 5133378,
|
|
128
|
+
data: '{"id":"t3"}',
|
|
129
|
+
object_id: 't3',
|
|
130
|
+
object_type: 'test',
|
|
131
|
+
op: 'PUT',
|
|
132
|
+
op_id: '11',
|
|
133
|
+
subkey: '6544e3899293153fa7b38333/ec27c691-b47a-5d92-927a-9944feb89eee'
|
|
134
|
+
}
|
|
135
|
+
]);
|
|
136
|
+
test_utils.validateBucket(bucket);
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=register-bucket-validation-tests.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register-bucket-validation-tests.js","sourceRoot":"","sources":["../../src/tests/register-bucket-validation-tests.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,KAAK,UAAU,MAAM,mCAAmC,CAAC;AAEhE;;;;;;;;GAQG;AACH,MAAM,UAAU,6BAA6B;IAC3C,MAAM,IAAI,GAAiB;QACzB;YACE,KAAK,EAAE,GAAG;YACV,EAAE,EAAE,KAAK;YACT,WAAW,EAAE,MAAM;YACnB,SAAS,EAAE,IAAI;YACf,QAAQ,EAAE,UAAU;YACpB,MAAM,EAAE,+DAA+D;YACvE,IAAI,EAAE,aAAa;SACpB;QACD;YACE,KAAK,EAAE,GAAG;YACV,EAAE,EAAE,KAAK;YACT,WAAW,EAAE,MAAM;YACnB,SAAS,EAAE,IAAI;YACf,QAAQ,EAAE,UAAU;YACpB,MAAM,EAAE,+DAA+D;YACvE,IAAI,EAAE,aAAa;SACpB;QACD;YACE,KAAK,EAAE,GAAG;YACV,EAAE,EAAE,QAAQ;YACZ,WAAW,EAAE,MAAM;YACnB,SAAS,EAAE,IAAI;YACf,QAAQ,EAAE,UAAU;YACpB,MAAM,EAAE,+DAA+D;YACvE,IAAI,EAAE,IAAI;SACX;QACD;YACE,KAAK,EAAE,GAAG;YACV,EAAE,EAAE,KAAK;YACT,WAAW,EAAE,MAAM;YACnB,SAAS,EAAE,IAAI;YACf,QAAQ,EAAE,UAAU;YACpB,MAAM,EAAE,+DAA+D;YACvE,IAAI,EAAE,aAAa;SACpB;KACF,CAAC;IAEF,IAAI,CAAC,UAAU,EAAE,GAAG,EAAE;QACpB,MAAM,CAAC,UAAU,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC;YAC5C;gBACE,QAAQ,EAAE,CAAC,UAAU;gBACrB,EAAE,EAAE,OAAO;gBACX,KAAK,EAAE,GAAG;aACX;YACD;gBAC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AAO;gBACjB,IAAI,EAAE,aAAa;gBACnB,SAAS,EAAE,IAAI;gBACf,WAAW,EAAE,MAAM;gBACnB,EAAE,EAAE,KAAK;gBACT,KAAK,EAAE,IAAI;gBACX,MAAM,EAAE,+DAA+D;aACxE;SACF,CAAC,CAAC;QAEH,MAAM,CAAC,UAAU,CAAC,YAAY,CAAC,UAAU,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;YACvE;gBACE,QAAQ,EAAE,QAAQ;gBAClB,EAAE,EAAE,OAAO;gBACX,KAAK,EAAE,GAAG;aACX;YACD;gBACE,QAAQ,EAAE,OAAO;gBACjB,IAAI,EAAE,aAAa;gBACnB,SAAS,EAAE,IAAI;gBACf,WAAW,EAAE,MAAM;gBACnB,EAAE,EAAE,KAAK;gBACT,KAAK,EAAE,IAAI;gBACX,MAAM,EAAE,+DAA+D;aACxE;SACF,CAAC,CAAC;QAEH,UAAU,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;IACpC,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { storage } from '@powersync/service-core';
|
|
2
|
+
import * as test_utils from '../test-utils/test-utils-index.js';
|
|
3
|
+
/**
|
|
4
|
+
* @example
|
|
5
|
+
* ```TypeScript
|
|
6
|
+
* // Test with the default options - large batch sizes
|
|
7
|
+
* describe('compacting buckets - default options', () => registerCompactTests(() => new MongoStorageFactory(), {}));
|
|
8
|
+
*
|
|
9
|
+
* // Also test with the miniumum batch sizes, forcing usage of multiple batches internally
|
|
10
|
+
* describe('compacting buckets - batched', () =>
|
|
11
|
+
* compactTests(() => new MongoStorageFactory(), { clearBatchLimit: 2, moveBatchLimit: 1, moveBatchQueryLimit: 1 }));
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export declare function registerCompactTests<CompactOptions extends storage.CompactOptions = storage.CompactOptions>(generateStorageFactory: test_utils.StorageFactory, compactOptions: CompactOptions): void;
|