Skip to content

Commit 54c30c4

Browse files
Add metadata to example node.js demo
1 parent 2cd3c43 commit 54c30c4

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

demos/example-node/src/main.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { once } from 'node:events';
2+
import { readFileSync } from 'node:fs';
3+
import { dirname, join } from 'node:path';
24
import repl_factory from 'node:repl';
5+
import { fileURLToPath } from 'node:url';
36
import { Worker } from 'node:worker_threads';
47

58
import {
@@ -10,10 +13,9 @@ import {
1013
SyncStreamConnectionMethod
1114
} from '@powersync/node';
1215
import { exit } from 'node:process';
16+
import { WorkerOpener } from 'node_modules/@powersync/node/src/db/options.js';
1317
import { AppSchema, DemoConnector } from './powersync.js';
1418
import { enableUncidiDiagnostics } from './UndiciDiagnostics.js';
15-
import { WorkerOpener } from 'node_modules/@powersync/node/src/db/options.js';
16-
import { LockContext } from 'node_modules/@powersync/node/dist/bundle.cjs';
1719

1820
const main = async () => {
1921
const baseLogger = createBaseLogger();
@@ -60,9 +62,19 @@ const main = async () => {
6062
});
6163
console.log(await db.get('SELECT powersync_rs_version();'));
6264

65+
// Read package version for metadata
66+
const __filename = fileURLToPath(import.meta.url);
67+
const __dirname = dirname(__filename);
68+
const packageJsonPath = join(__dirname, '..', 'package.json');
69+
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));
70+
const packageVersion = packageJson.version;
71+
6372
await db.connect(new DemoConnector(), {
6473
connectionMethod: SyncStreamConnectionMethod.WEB_SOCKET,
65-
clientImplementation: SyncClientImplementation.RUST
74+
clientImplementation: SyncClientImplementation.RUST,
75+
appMetadata: {
76+
package_version: packageVersion
77+
}
6678
});
6779
// Example using a proxy agent for more control over the connection:
6880
// const proxyAgent = new (await import('undici')).ProxyAgent({

0 commit comments

Comments
 (0)