Skip to content

Commit 417cf5f

Browse files
authored
Merge pull request #84 from powersync-ja/update-tooling
Update tooling
2 parents 1f4ded8 + f433195 commit 417cf5f

30 files changed

+421
-1724
lines changed

.prettierignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
**/.git
2+
**/node_modules
3+
dist
4+
lib
5+
pnpm-lock.yaml

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ _[PowerSync](https://www.powersync.com) is a Postgres-SQLite sync engine, which
1111
The service can be started using the public Docker image. See the image [notes](./service/README.md)
1212

1313
# Monorepo Structure:
14+
1415
## Packages
1516

1617
- [packages/service-core](./packages/service-core/README.md)
@@ -52,13 +53,13 @@ Contains the PowerSync service code. This project is used to build the `journeya
5253

5354
- [docs](./docs/README.md)
5455

55-
Technical documentation regarding the implementation of PowerSync.
56+
Technical documentation regarding the implementation of PowerSync.
5657

5758
## Test Client
5859

5960
- [test-client](./test-client/README.md)
6061

61-
Contains a minimal client demonstrating direct usage of the HTTP stream sync API. This can be used to test sync rules in contexts such as automated testing.
62+
Contains a minimal client demonstrating direct usage of the HTTP stream sync API. This can be used to test sync rules in contexts such as automated testing.
6263

6364
# Developing
6465

libs/lib-services/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@
3333
"devDependencies": {
3434
"@types/lodash": "^4.17.5",
3535
"@types/uuid": "^9.0.4",
36-
"vitest": "^0.34.6"
36+
"vitest": "^2.1.1"
3737
}
3838
}

modules/module-postgres/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"build": "tsc -b",
1414
"build:tests": "tsc -b test/tsconfig.json",
1515
"clean": "rm -rf ./lib && tsc -b --clean",
16-
"test": "vitest --no-threads"
16+
"test": "vitest"
1717
},
1818
"exports": {
1919
".": {
@@ -42,8 +42,8 @@
4242
},
4343
"devDependencies": {
4444
"@types/uuid": "^9.0.4",
45-
"typescript": "^5.2.2",
46-
"vitest": "^0.34.6",
45+
"typescript": "^5.6.2",
46+
"vitest": "^2.1.1",
4747
"vite-tsconfig-paths": "^4.3.2"
4848
}
4949
}

modules/module-postgres/src/replication/PgManager.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ export class PgManager {
99

1010
private connectionPromises: Promise<pgwire.PgConnection>[] = [];
1111

12-
constructor(public options: NormalizedPostgresConnectionConfig, public poolOptions: pgwire.PgPoolOptions) {
12+
constructor(
13+
public options: NormalizedPostgresConnectionConfig,
14+
public poolOptions: pgwire.PgPoolOptions
15+
) {
1316
// The pool is lazy - no connections are opened until a query is performed.
1417
this.pool = pgwire.connectPgWirePool(this.options, poolOptions);
1518
}

modules/module-postgres/src/replication/PgRelation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export function getReplicaIdColumns(relation: PgoutputRelation): storage.ColumnD
99
} else {
1010
return relation.columns
1111
.filter((c) => (c.flags & 0b1) != 0)
12-
.map((c) => ({ name: c.name, typeId: c.typeOid } satisfies storage.ColumnDescriptor));
12+
.map((c) => ({ name: c.name, typeId: c.typeOid }) satisfies storage.ColumnDescriptor);
1313
}
1414
}
1515
export function getRelId(source: PgoutputRelation): number {

modules/module-postgres/src/utils/populate_test_data.ts

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import * as crypto from 'crypto';
2-
import { Worker, isMainThread, parentPort, workerData } from 'node:worker_threads';
1+
import { Worker } from 'node:worker_threads';
32

43
import * as pgwire from '@powersync/service-jpgwire';
54

@@ -12,49 +11,10 @@ export interface PopulateDataOptions {
1211
size: number;
1312
}
1413

15-
if (isMainThread || parentPort == null) {
16-
// Not a worker - ignore
17-
} else {
18-
try {
19-
const options = workerData as PopulateDataOptions;
20-
21-
const result = await populateDataInner(options);
22-
parentPort.postMessage(result);
23-
process.exit(0);
24-
} catch (e) {
25-
// This is a bug, not a connection issue
26-
console.error(e);
27-
// Only closes the Worker thread
28-
process.exit(2);
29-
}
30-
}
31-
32-
async function populateDataInner(options: PopulateDataOptions) {
33-
// Dedicated connection so we can release the memory easily
34-
const initialDb = await pgwire.connectPgWire(options.connection, { type: 'standard' });
35-
const largeDescription = crypto.randomBytes(options.size / 2).toString('hex');
36-
let operation_count = 0;
37-
for (let i = 0; i < options.num_transactions; i++) {
38-
const prefix = `test${i}K`;
39-
40-
await initialDb.query({
41-
statement: `INSERT INTO test_data(id, description, other) SELECT $1 || i, $2, 'foo' FROM generate_series(1, $3) i`,
42-
params: [
43-
{ type: 'varchar', value: prefix },
44-
{ type: 'varchar', value: largeDescription },
45-
{ type: 'int4', value: options.per_transaction }
46-
]
47-
});
48-
operation_count += options.per_transaction;
49-
}
50-
await initialDb.end();
51-
return operation_count;
52-
}
53-
5414
export async function populateData(options: PopulateDataOptions) {
5515
const WORKER_TIMEOUT = 30_000;
5616

57-
const worker = new Worker(new URL('./populate_test_data.js', import.meta.url), {
17+
const worker = new Worker(new URL('./populate_test_data_worker.js', import.meta.url), {
5818
workerData: options
5919
});
6020
const timeout = setTimeout(() => {
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import * as crypto from 'crypto';
2+
import { isMainThread, parentPort, workerData } from 'node:worker_threads';
3+
4+
import * as pgwire from '@powersync/service-jpgwire';
5+
import type { PopulateDataOptions } from './populate_test_data.js';
6+
7+
// This util is actually for tests only, but we need it compiled to JS for the service to work, so it's placed in the service.
8+
9+
if (isMainThread || parentPort == null) {
10+
// Must not be imported - only expected to run in a worker
11+
throw new Error('Do not import this file');
12+
} else {
13+
try {
14+
const options = workerData as PopulateDataOptions;
15+
if (options == null) {
16+
throw new Error('loaded worker without options');
17+
}
18+
19+
const result = await populateDataInner(options);
20+
parentPort.postMessage(result);
21+
process.exit(0);
22+
} catch (e) {
23+
// This is a bug, not a connection issue
24+
console.error(e);
25+
// Only closes the Worker thread
26+
process.exit(2);
27+
}
28+
}
29+
30+
async function populateDataInner(options: PopulateDataOptions) {
31+
// Dedicated connection so we can release the memory easily
32+
const initialDb = await pgwire.connectPgWire(options.connection, { type: 'standard' });
33+
const largeDescription = crypto.randomBytes(options.size / 2).toString('hex');
34+
let operation_count = 0;
35+
for (let i = 0; i < options.num_transactions; i++) {
36+
const prefix = `test${i}K`;
37+
38+
await initialDb.query({
39+
statement: `INSERT INTO test_data(id, description, other) SELECT $1 || i, $2, 'foo' FROM generate_series(1, $3) i`,
40+
params: [
41+
{ type: 'varchar', value: prefix },
42+
{ type: 'varchar', value: largeDescription },
43+
{ type: 'int4', value: options.per_transaction }
44+
]
45+
});
46+
operation_count += options.per_transaction;
47+
}
48+
await initialDb.end();
49+
return operation_count;
50+
}

modules/module-postgres/test/src/wal_stream_utils.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ export class WalStreamTestContext {
3636
public storage?: SyncRulesBucketStorage;
3737
private replicationConnection?: pgwire.PgConnection;
3838

39-
constructor(public factory: BucketStorageFactory, public connectionManager: PgManager) {}
39+
constructor(
40+
public factory: BucketStorageFactory,
41+
public connectionManager: PgManager
42+
) {}
4043

4144
async dispose() {
4245
this.abortController.abort();

modules/module-postgres/vitest.config.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ import tsconfigPaths from 'vite-tsconfig-paths';
44
export default defineConfig({
55
plugins: [tsconfigPaths()],
66
test: {
7-
setupFiles: './test/src/setup.ts'
7+
setupFiles: './test/src/setup.ts',
8+
poolOptions: {
9+
threads: {
10+
singleThread: true
11+
}
12+
},
13+
pool: 'threads'
814
}
915
});

0 commit comments

Comments
 (0)