Home / File/ libsql-node.ts — astro Source File

libsql-node.ts — astro Source File

Architecture documentation for libsql-node.ts, a typescript file in the astro codebase. 3 imports, 0 dependents.

File typescript CoreAstro CoreMiddleware 3 imports 1 functions

Entity Profile

Dependency Diagram

graph LR
  49db0359_d45e_d5a2_8e02_73df031d0a9e["libsql-node.ts"]
  18405672_85cf_603b_7e5d_ab7ea1416038["./utils.js"]
  49db0359_d45e_d5a2_8e02_73df031d0a9e --> 18405672_85cf_603b_7e5d_ab7ea1416038
  91decf0f_8a76_7391_4c56_d2f49dbb7487["client"]
  49db0359_d45e_d5a2_8e02_73df031d0a9e --> 91decf0f_8a76_7391_4c56_d2f49dbb7487
  512bd4d0_25e3_774d_1dff_0825d694fa9f["libsql"]
  49db0359_d45e_d5a2_8e02_73df031d0a9e --> 512bd4d0_25e3_774d_1dff_0825d694fa9f
  style 49db0359_d45e_d5a2_8e02_73df031d0a9e fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { createClient as createLibsqlClient } from '@libsql/client';
import { drizzle as drizzleLibsql } from 'drizzle-orm/libsql';
import { parseLibSQLConfig } from './utils.js';

type RemoteDbClientOptions = {
	token: string;
	url: string;
};

export function createClient(opts: RemoteDbClientOptions) {
	const { token, url: rawUrl } = opts;

	let parsedUrl = new URL(rawUrl);

	const options: Record<string, string> = Object.fromEntries(parsedUrl.searchParams.entries());
	parsedUrl.search = '';

	let url = parsedUrl.toString();
	if (parsedUrl.protocol === 'memory:') {
		// libSQL expects a special string in place of a URL
		// for in-memory DBs.
		url = ':memory:';
	} else if (
		parsedUrl.protocol === 'file:' &&
		parsedUrl.pathname.startsWith('/') &&
		!rawUrl.startsWith('file:/')
	) {
		// libSQL accepts relative and absolute file URLs
		// for local DBs. This doesn't match the URL specification.
		// Parsing `file:some.db` and `file:/some.db` should yield
		// the same result, but libSQL interprets the former as
		// a relative path, and the latter as an absolute path.
		// This detects when such a conversion happened during parsing
		// and undoes it so that the URL given to libSQL is the
		// same as given by the user.
		url = 'file:' + parsedUrl.pathname.substring(1);
	}

	const libSQLOptions = parseLibSQLConfig(options);

	const client = createLibsqlClient({ ...libSQLOptions, url, authToken: token });
	return drizzleLibsql(client);
}

Domain

Subdomains

Functions

Dependencies

  • ./utils.js
  • client
  • libsql

Frequently Asked Questions

What does libsql-node.ts do?
libsql-node.ts is a source file in the astro codebase, written in typescript. It belongs to the CoreAstro domain, CoreMiddleware subdomain.
What functions are defined in libsql-node.ts?
libsql-node.ts defines 1 function(s): createClient.
What does libsql-node.ts depend on?
libsql-node.ts imports 3 module(s): ./utils.js, client, libsql.
Where is libsql-node.ts in the architecture?
libsql-node.ts is located at packages/db/src/core/db-client/libsql-node.ts (domain: CoreAstro, subdomain: CoreMiddleware, directory: packages/db/src/core/db-client).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free