diff options
author | 2025-05-10 04:47:56 +0000 | |
---|---|---|
committer | 2025-05-10 04:47:56 +0000 | |
commit | 3348a5a41372129700dc1ca466a3211b9629e483 (patch) | |
tree | 847eddb115b41e526e5ab52428be33a2730f95df | |
parent | 83193d43cfb7fb28254f0ff3fb717a7bdd65977b (diff) | |
download | astro-3348a5a41372129700dc1ca466a3211b9629e483.tar.gz astro-3348a5a41372129700dc1ca466a3211b9629e483.tar.zst astro-3348a5a41372129700dc1ca466a3211b9629e483.zip |
[ci] format
-rw-r--r-- | packages/db/src/runtime/db-client.ts | 6 | ||||
-rw-r--r-- | packages/db/test/unit/db-client.test.js | 106 |
2 files changed, 58 insertions, 54 deletions
diff --git a/packages/db/src/runtime/db-client.ts b/packages/db/src/runtime/db-client.ts index 6a4e610e7..55288951d 100644 --- a/packages/db/src/runtime/db-client.ts +++ b/packages/db/src/runtime/db-client.ts @@ -62,13 +62,13 @@ export function createRemoteDatabaseClient(options: RemoteDbClientOptions) { // without this, there is runtime errors due to incorrect values export function parseOpts(config: Record<string, string>): Partial<LibSQLConfig> { return { - ... config, + ...config, ...(config.syncInterval ? { syncInterval: parseInt(config.syncInterval) } : {}), ...('readYourWrites' in config ? { readYourWrites: config.readYourWrites !== 'false' } : {}), ...('offline' in config ? { offline: config.offline !== 'false' } : {}), ...('tls' in config ? { tls: config.tls !== 'false' } : {}), ...(config.concurrency ? { concurrency: parseInt(config.concurrency) } : {}), - } + }; } function createRemoteLibSQLClient(appToken: string, remoteDbURL: URL, rawUrl: string) { @@ -96,7 +96,7 @@ function createRemoteLibSQLClient(appToken: string, remoteDbURL: URL, rawUrl: st url = 'file:' + remoteDbURL.pathname.substring(1); } - const client = createClient({ ...parseOpts(options), url, authToken: appToken, }); + const client = createClient({ ...parseOpts(options), url, authToken: appToken }); return drizzleLibsql(client); } diff --git a/packages/db/test/unit/db-client.test.js b/packages/db/test/unit/db-client.test.js index ac41aa07f..22df2610e 100644 --- a/packages/db/test/unit/db-client.test.js +++ b/packages/db/test/unit/db-client.test.js @@ -3,54 +3,58 @@ import test, { describe } from 'node:test'; import { parseOpts } from '../../dist/runtime/db-client.js'; describe('db client config', () => { - test('parse config options from URL (docs example url)', () => { - const remoteURLToParse = new URL('file://local-copy.db?encryptionKey=your-encryption-key&syncInterval=60&syncUrl=libsql%3A%2F%2Fyour.server.io'); - const options = Object.fromEntries(remoteURLToParse.searchParams.entries()); - - const config = parseOpts(options); - - assert.deepEqual(config, { - encryptionKey: "your-encryption-key", - syncInterval: 60, - syncUrl: "libsql://your.server.io", - }) - }); - - test('parse config options from URL (test booleans without value)', () => { - const remoteURLToParse = new URL('file://local-copy.db?readYourWrites&offline&tls'); - const options = Object.fromEntries(remoteURLToParse.searchParams.entries()); - - const config = parseOpts(options); - - assert.deepEqual(config, { - readYourWrites: true, - offline: true, - tls: true - }) - }) - - test('parse config options from URL (test booleans with value)', () => { - const remoteURLToParse = new URL('file://local-copy.db?readYourWrites=true&offline=true&tls=true'); - const options = Object.fromEntries(remoteURLToParse.searchParams.entries()); - - const config = parseOpts(options); - - assert.deepEqual(config, { - readYourWrites: true, - offline: true, - tls: true - }) - }) - - test('parse config options from URL (test numbers)', () => { - const remoteURLToParse = new URL('file://local-copy.db?syncInterval=60&concurrency=2'); - const options = Object.fromEntries(remoteURLToParse.searchParams.entries()); - - const config = parseOpts(options); - - assert.deepEqual(config, { - syncInterval: 60, - concurrency: 2 - }) - }) -})
\ No newline at end of file + test('parse config options from URL (docs example url)', () => { + const remoteURLToParse = new URL( + 'file://local-copy.db?encryptionKey=your-encryption-key&syncInterval=60&syncUrl=libsql%3A%2F%2Fyour.server.io', + ); + const options = Object.fromEntries(remoteURLToParse.searchParams.entries()); + + const config = parseOpts(options); + + assert.deepEqual(config, { + encryptionKey: 'your-encryption-key', + syncInterval: 60, + syncUrl: 'libsql://your.server.io', + }); + }); + + test('parse config options from URL (test booleans without value)', () => { + const remoteURLToParse = new URL('file://local-copy.db?readYourWrites&offline&tls'); + const options = Object.fromEntries(remoteURLToParse.searchParams.entries()); + + const config = parseOpts(options); + + assert.deepEqual(config, { + readYourWrites: true, + offline: true, + tls: true, + }); + }); + + test('parse config options from URL (test booleans with value)', () => { + const remoteURLToParse = new URL( + 'file://local-copy.db?readYourWrites=true&offline=true&tls=true', + ); + const options = Object.fromEntries(remoteURLToParse.searchParams.entries()); + + const config = parseOpts(options); + + assert.deepEqual(config, { + readYourWrites: true, + offline: true, + tls: true, + }); + }); + + test('parse config options from URL (test numbers)', () => { + const remoteURLToParse = new URL('file://local-copy.db?syncInterval=60&concurrency=2'); + const options = Object.fromEntries(remoteURLToParse.searchParams.entries()); + + const config = parseOpts(options); + + assert.deepEqual(config, { + syncInterval: 60, + concurrency: 2, + }); + }); +}); |