@libsql/client
Advanced tools
Comparing version 0.0.7 to 0.0.8
@@ -9,10 +9,26 @@ "use strict"; | ||
authHeader; | ||
constructor(url) { | ||
constructor(url, authToken) { | ||
for (const [key, value] of url.searchParams.entries()) { | ||
if (key === "jwt") { | ||
if (authToken) { | ||
throw new TypeError(`Cannot specify both auth token in config and URL query argument`); | ||
} | ||
authToken = value; | ||
} | ||
else { | ||
throw new TypeError(`Unknown URL query argument ${JSON.stringify(key)}`); | ||
} | ||
} | ||
if (authToken) { | ||
this.authHeader = `Bearer ${authToken}`; | ||
} | ||
var protocol = url.protocol; | ||
if (protocol == "libsql:") { | ||
protocol = "https:"; | ||
} | ||
if (url.username !== "" || url.password !== "") { | ||
const encodedCreds = js_base64_1.Base64.encode(`${url.username}:${url.password}`); | ||
this.authHeader = `Basic ${encodedCreds}`; | ||
url.username = ""; | ||
url.password = ""; | ||
} | ||
this.url = url; | ||
this.url = new URL(`${protocol}//${url.host}${url.pathname}`); | ||
} | ||
@@ -19,0 +35,0 @@ async execute(stmt, params) { |
@@ -24,4 +24,4 @@ "use strict"; | ||
const url = new URL(rawUrl); | ||
if (url.protocol == "http:" || url.protocol == "https:") { | ||
return new shared_types_js_1.Client(new http_driver_js_1.HttpDriver(url)); | ||
if (url.protocol == "libsql:" || url.protocol == "http:" || url.protocol == "https:") { | ||
return new shared_types_js_1.Client(new http_driver_js_1.HttpDriver(url, config.authToken)); | ||
} | ||
@@ -28,0 +28,0 @@ else { |
@@ -6,5 +6,5 @@ import { ResultSet, BoundStatement, Params } from "../shared-types.js"; | ||
private authHeader; | ||
constructor(url: URL); | ||
constructor(url: URL, authToken?: string); | ||
execute(stmt: string, params?: Params): Promise<ResultSet>; | ||
transaction(stmts: (string | BoundStatement)[]): Promise<ResultSet[]>; | ||
} |
@@ -6,10 +6,26 @@ import { fetch as crossFetch } from "cross-fetch"; | ||
authHeader; | ||
constructor(url) { | ||
constructor(url, authToken) { | ||
for (const [key, value] of url.searchParams.entries()) { | ||
if (key === "jwt") { | ||
if (authToken) { | ||
throw new TypeError(`Cannot specify both auth token in config and URL query argument`); | ||
} | ||
authToken = value; | ||
} | ||
else { | ||
throw new TypeError(`Unknown URL query argument ${JSON.stringify(key)}`); | ||
} | ||
} | ||
if (authToken) { | ||
this.authHeader = `Bearer ${authToken}`; | ||
} | ||
var protocol = url.protocol; | ||
if (protocol == "libsql:") { | ||
protocol = "https:"; | ||
} | ||
if (url.username !== "" || url.password !== "") { | ||
const encodedCreds = Base64.encode(`${url.username}:${url.password}`); | ||
this.authHeader = `Basic ${encodedCreds}`; | ||
url.username = ""; | ||
url.password = ""; | ||
} | ||
this.url = url; | ||
this.url = new URL(`${protocol}//${url.host}${url.pathname}`); | ||
} | ||
@@ -16,0 +32,0 @@ async execute(stmt, params) { |
@@ -7,4 +7,4 @@ import { Client } from "./shared-types.js"; | ||
const url = new URL(rawUrl); | ||
if (url.protocol == "http:" || url.protocol == "https:") { | ||
return new Client(new HttpDriver(url)); | ||
if (url.protocol == "libsql:" || url.protocol == "http:" || url.protocol == "https:") { | ||
return new Client(new HttpDriver(url, config.authToken)); | ||
} | ||
@@ -11,0 +11,0 @@ else { |
import { Driver } from "./driver.js"; | ||
export type Config = { | ||
url: string; | ||
authToken?: string; | ||
}; | ||
@@ -5,0 +6,0 @@ /** |
{ | ||
"name": "@libsql/client", | ||
"version": "0.0.7", | ||
"version": "0.0.8", | ||
"keywords": [ | ||
@@ -5,0 +5,0 @@ "libsql", |
@@ -1,3 +0,6 @@ | ||
# libSQL driver for TypeScript and JavaScript | ||
# libSQL client API for TypeScript and JavaScript | ||
[![Node.js CI](https://github.com/libsql/libsql-client-ts/actions/workflows/node-ci.yaml/badge.svg)](https://github.com/libsql/libsql-client-ts/actions/workflows/node-ci.yaml) | ||
[![License](https://img.shields.io/badge/license-MIT-blue)](https://github.com/libsql/libsql-client-ts/blob/main/LICENSE) | ||
## Getting Started | ||
@@ -36,6 +39,1 @@ | ||
* SQL over HTTP with `fetch()` | ||
## Roadmap | ||
* Read replica mode | ||
* Cloudflare D1 API compatibility? |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
29326
727
4
39