From 0768462410ff75d61fa2a35dcdc6c571e428f707 Mon Sep 17 00:00:00 2001 From: Jamie Barton Date: Fri, 5 Jul 2024 09:25:37 +0100 Subject: [PATCH 1/2] fix rebase --- packages/libsql-client-wasm/src/wasm.ts | 18 ++++++++++++-- packages/libsql-client/src/http.ts | 17 ++++++++++++- packages/libsql-client/src/sqlite3.ts | 33 +++++++++++++++++++++++-- packages/libsql-client/src/web.ts | 29 +++++++++++++--------- packages/libsql-client/src/ws.ts | 17 ++++++++++++- 5 files changed, 96 insertions(+), 18 deletions(-) diff --git a/packages/libsql-client-wasm/src/wasm.ts b/packages/libsql-client-wasm/src/wasm.ts index a64b1b2..bebfb0a 100644 --- a/packages/libsql-client-wasm/src/wasm.ts +++ b/packages/libsql-client-wasm/src/wasm.ts @@ -2,7 +2,6 @@ import sqlite3InitModule from "@libsql/libsql-wasm-experimental"; import type { Database, - InitOptions, SqlValue, Sqlite3Static, } from "@libsql/libsql-wasm-experimental"; @@ -18,6 +17,7 @@ import type { Value, InValue, InStatement, + InArgs } from "@libsql/core/api"; import { LibsqlError } from "@libsql/core/api"; import type { ExpandedConfig } from "@libsql/core/config"; @@ -122,7 +122,21 @@ export class Sqlite3Client implements Client { this.protocol = "file"; } - async execute(stmt: InStatement): Promise { + async execute(stmt: InStatement): Promise; + async execute(sql: string, args?: InArgs): Promise; + + async execute(stmtOrSql: InStatement | string, args?: InArgs): Promise { + let stmt: InStatement; + + if (typeof stmtOrSql === 'string') { + stmt = { + sql: stmtOrSql, + args: args || [] + }; + } else { + stmt = stmtOrSql; + } + this.#checkNotClosed(); return executeStmt(this.#getDb(), stmt, this.#intMode); } diff --git a/packages/libsql-client/src/http.ts b/packages/libsql-client/src/http.ts index c6cc908..526b811 100644 --- a/packages/libsql-client/src/http.ts +++ b/packages/libsql-client/src/http.ts @@ -6,6 +6,7 @@ import type { ResultSet, Transaction, IntMode, + InArgs } from "@libsql/core/api"; import { TransactionMode, LibsqlError } from "@libsql/core/api"; import type { ExpandedConfig } from "@libsql/core/config"; @@ -112,7 +113,21 @@ export class HttpClient implements Client { return this.#promiseLimitFunction(fn); } - async execute(stmt: InStatement): Promise { + async execute(stmt: InStatement): Promise; + async execute(sql: string, args?: InArgs): Promise; + + async execute(stmtOrSql: InStatement | string, args?: InArgs): Promise { + let stmt: InStatement; + + if (typeof stmtOrSql === 'string') { + stmt = { + sql: stmtOrSql, + args: args || [] + }; + } else { + stmt = stmtOrSql; + } + return this.limit(async () => { try { const isSchemaDatabasePromise = this.getIsSchemaDatabase(); diff --git a/packages/libsql-client/src/sqlite3.ts b/packages/libsql-client/src/sqlite3.ts index 90df5ce..34083a6 100644 --- a/packages/libsql-client/src/sqlite3.ts +++ b/packages/libsql-client/src/sqlite3.ts @@ -12,6 +12,7 @@ import type { Value, InValue, InStatement, + InArgs } from "@libsql/core/api"; import { LibsqlError } from "@libsql/core/api"; import type { ExpandedConfig } from "@libsql/core/config"; @@ -105,7 +106,21 @@ export class Sqlite3Client implements Client { this.protocol = "file"; } - async execute(stmt: InStatement): Promise { + async execute(stmt: InStatement): Promise; + async execute(sql: string, args?: InArgs): Promise; + + async execute(stmtOrSql: InStatement | string, args?: InArgs): Promise { + let stmt: InStatement; + + if (typeof stmtOrSql === 'string') { + stmt = { + sql: stmtOrSql, + args: args || [] + }; + } else { + stmt = stmtOrSql; + } + this.#checkNotClosed(); return executeStmt(this.#getDb(), stmt, this.#intMode); } @@ -192,7 +207,21 @@ export class Sqlite3Transaction implements Transaction { this.#intMode = intMode; } - async execute(stmt: InStatement): Promise { + async execute(stmt: InStatement): Promise; + async execute(sql: string, args?: InArgs): Promise; + + async execute(stmtOrSql: InStatement | string, args?: InArgs): Promise { + let stmt: InStatement; + + if (typeof stmtOrSql === 'string') { + stmt = { + sql: stmtOrSql, + args: args || [] + }; + } else { + stmt = stmtOrSql; + } + this.#checkNotClosed(); return executeStmt(this.#database, stmt, this.#intMode); } diff --git a/packages/libsql-client/src/web.ts b/packages/libsql-client/src/web.ts index 3e4d2c0..4659de7 100644 --- a/packages/libsql-client/src/web.ts +++ b/packages/libsql-client/src/web.ts @@ -10,20 +10,25 @@ import { _createClient as _createHttpClient } from "./http.js"; export * from "@libsql/core/api"; export function createClient(config: Config): Client { - return _createClient(expandConfig(config, true)); + return _createClient(expandConfig(config, true)); } /** @private */ export function _createClient(config: ExpandedConfig): Client { - if (config.scheme === "ws" || config.scheme === "wss") { - return _createWsClient(config); - } else if (config.scheme === "http" || config.scheme === "https") { - return _createHttpClient(config); - } else { - throw new LibsqlError( - 'The client that uses Web standard APIs supports only "libsql:", "wss:", "ws:", "https:" and "http:" URLs, ' + - `got ${JSON.stringify(config.scheme + ":")}. For more information, please read ${supportedUrlLink}`, - "URL_SCHEME_NOT_SUPPORTED", - ); - } + console.log("HELLO WORLD FROM WEB"); + console.log("HELLO WORLD FROM WEB"); + console.log("HELLO WORLD FROM WEB"); + console.log("HELLO WORLD FROM WEB"); + + if (config.scheme === "ws" || config.scheme === "wss") { + return _createWsClient(config); + } else if (config.scheme === "http" || config.scheme === "https") { + return _createHttpClient(config); + } else { + throw new LibsqlError( + 'The client that uses Web standard APIs supports only "libsql:", "wss:", "ws:", "https:" and "http:" URLs, ' + + `got ${JSON.stringify(config.scheme + ":")}. For more information, please read ${supportedUrlLink}`, + "URL_SCHEME_NOT_SUPPORTED", + ); + } } diff --git a/packages/libsql-client/src/ws.ts b/packages/libsql-client/src/ws.ts index 4d3c183..3b0f477 100644 --- a/packages/libsql-client/src/ws.ts +++ b/packages/libsql-client/src/ws.ts @@ -7,6 +7,7 @@ import type { Transaction, ResultSet, InStatement, + InArgs } from "@libsql/core/api"; import { TransactionMode, LibsqlError } from "@libsql/core/api"; import type { ExpandedConfig } from "@libsql/core/config"; @@ -167,7 +168,21 @@ export class WsClient implements Client { return this.#promiseLimitFunction(fn); } - async execute(stmt: InStatement): Promise { + async execute(stmt: InStatement): Promise; + async execute(sql: string, args?: InArgs): Promise; + + async execute(stmtOrSql: InStatement | string, args?: InArgs): Promise { + let stmt: InStatement; + + if (typeof stmtOrSql === 'string') { + stmt = { + sql: stmtOrSql, + args: args || [] + }; + } else { + stmt = stmtOrSql; + } + return this.limit(async () => { const streamState = await this.#openStream(); try { From c42fad7992823b744dd0aad9f039282276e4f62b Mon Sep 17 00:00:00 2001 From: Jamie Barton Date: Fri, 5 Jul 2024 09:26:44 +0100 Subject: [PATCH 2/2] eager commit --- packages/libsql-client/src/web.ts | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/packages/libsql-client/src/web.ts b/packages/libsql-client/src/web.ts index 4659de7..3e4d2c0 100644 --- a/packages/libsql-client/src/web.ts +++ b/packages/libsql-client/src/web.ts @@ -10,25 +10,20 @@ import { _createClient as _createHttpClient } from "./http.js"; export * from "@libsql/core/api"; export function createClient(config: Config): Client { - return _createClient(expandConfig(config, true)); + return _createClient(expandConfig(config, true)); } /** @private */ export function _createClient(config: ExpandedConfig): Client { - console.log("HELLO WORLD FROM WEB"); - console.log("HELLO WORLD FROM WEB"); - console.log("HELLO WORLD FROM WEB"); - console.log("HELLO WORLD FROM WEB"); - - if (config.scheme === "ws" || config.scheme === "wss") { - return _createWsClient(config); - } else if (config.scheme === "http" || config.scheme === "https") { - return _createHttpClient(config); - } else { - throw new LibsqlError( - 'The client that uses Web standard APIs supports only "libsql:", "wss:", "ws:", "https:" and "http:" URLs, ' + - `got ${JSON.stringify(config.scheme + ":")}. For more information, please read ${supportedUrlLink}`, - "URL_SCHEME_NOT_SUPPORTED", - ); - } + if (config.scheme === "ws" || config.scheme === "wss") { + return _createWsClient(config); + } else if (config.scheme === "http" || config.scheme === "https") { + return _createHttpClient(config); + } else { + throw new LibsqlError( + 'The client that uses Web standard APIs supports only "libsql:", "wss:", "ws:", "https:" and "http:" URLs, ' + + `got ${JSON.stringify(config.scheme + ":")}. For more information, please read ${supportedUrlLink}`, + "URL_SCHEME_NOT_SUPPORTED", + ); + } }