@libsql/hrana-client
Advanced tools
Comparing version 0.1.4 to 0.2.0
@@ -20,8 +20,11 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Stream = exports.Client = exports.open = void 0; | ||
exports.Stream = exports.Client = exports.open = exports.Stmt = void 0; | ||
const isomorphic_ws_1 = __importDefault(require("isomorphic-ws")); | ||
const convert_js_1 = require("./convert.js"); | ||
const errors_js_1 = require("./errors.js"); | ||
const id_alloc_js_1 = __importDefault(require("./id_alloc.js")); | ||
const result_js_1 = require("./result.js"); | ||
const stmt_js_1 = require("./stmt.js"); | ||
__exportStar(require("./errors.js"), exports); | ||
var stmt_js_2 = require("./stmt.js"); | ||
Object.defineProperty(exports, "Stmt", { enumerable: true, get: function () { return stmt_js_2.Stmt; } }); | ||
/** Open a Hrana client connected to the given `url`. */ | ||
@@ -89,2 +92,6 @@ function open(url, jwt) { | ||
#sendRequest(request, callbacks) { | ||
if (this.#closed !== undefined) { | ||
callbacks.errorCallback(new errors_js_1.ClosedError("Client is closed", this.#closed)); | ||
return; | ||
} | ||
const requestId = this.#requestIdAlloc.alloc(); | ||
@@ -141,3 +148,3 @@ this.#responseMap.set(requestId, { ...callbacks, type: request.type }); | ||
if (msg["type"] === "hello_error") { | ||
throw (0, convert_js_1.errorFromProto)(msg["error"]); | ||
throw (0, result_js_1.errorFromProto)(msg["error"]); | ||
} | ||
@@ -174,3 +181,3 @@ return; | ||
} | ||
responseState.errorCallback((0, convert_js_1.errorFromProto)(msg["error"])); | ||
responseState.errorCallback((0, result_js_1.errorFromProto)(msg["error"])); | ||
} | ||
@@ -183,5 +190,2 @@ else { | ||
openStream() { | ||
if (this.#closed !== undefined) { | ||
throw new errors_js_1.ClosedError("Client is closed", this.#closed); | ||
} | ||
const streamId = this.#streamIdAlloc.alloc(); | ||
@@ -263,10 +267,8 @@ const streamState = { | ||
} | ||
/** Execute a statement that returns rows. */ | ||
/** Execute a statement and return rows. */ | ||
query(stmt) { | ||
return new Promise((rowsCallback, errorCallback) => { | ||
this.#client._execute(this.#state, { | ||
stmt: (0, convert_js_1.stmtToProto)(stmt, true), | ||
resultCallback(result) { | ||
rowsCallback((0, convert_js_1.rowArrayFromProto)(result)); | ||
}, | ||
stmt: (0, stmt_js_1.stmtToProto)(stmt, true), | ||
resultCallback(result) { rowsCallback((0, result_js_1.rowsResultFromProto)(result)); }, | ||
errorCallback, | ||
@@ -276,15 +278,8 @@ }); | ||
} | ||
/** Execute a statement that returns at most a single row. */ | ||
/** Execute a statement and return at most a single row. */ | ||
queryRow(stmt) { | ||
return new Promise((rowCallback, errorCallback) => { | ||
this.#client._execute(this.#state, { | ||
stmt: (0, convert_js_1.stmtToProto)(stmt, true), | ||
resultCallback(result) { | ||
if (result.rows.length >= 1) { | ||
rowCallback((0, convert_js_1.rowFromProto)(result, result.rows[0])); | ||
} | ||
else { | ||
rowCallback(undefined); | ||
} | ||
}, | ||
stmt: (0, stmt_js_1.stmtToProto)(stmt, true), | ||
resultCallback(result) { rowCallback((0, result_js_1.rowResultFromProto)(result)); }, | ||
errorCallback, | ||
@@ -294,15 +289,8 @@ }); | ||
} | ||
/** Execute a statement that returns at most a single value. */ | ||
/** Execute a statement and return at most a single value. */ | ||
queryValue(stmt) { | ||
return new Promise((valueCallback, errorCallback) => { | ||
this.#client._execute(this.#state, { | ||
stmt: (0, convert_js_1.stmtToProto)(stmt, true), | ||
resultCallback(result) { | ||
if (result.rows.length >= 1 && result.rows[0].length >= 1) { | ||
valueCallback((0, convert_js_1.valueFromProto)(result.rows[0][0])); | ||
} | ||
else { | ||
valueCallback(undefined); | ||
} | ||
}, | ||
stmt: (0, stmt_js_1.stmtToProto)(stmt, true), | ||
resultCallback(result) { valueCallback((0, result_js_1.valueResultFromProto)(result)); }, | ||
errorCallback, | ||
@@ -312,8 +300,8 @@ }); | ||
} | ||
/** Execute a statement that does not return rows. */ | ||
/** Execute a statement without returning rows. */ | ||
execute(stmt) { | ||
return new Promise((doneCallback, errorCallback) => { | ||
this.#client._execute(this.#state, { | ||
stmt: (0, convert_js_1.stmtToProto)(stmt, false), | ||
resultCallback(result) { doneCallback((0, convert_js_1.stmtResultFromProto)(result)); }, | ||
stmt: (0, stmt_js_1.stmtToProto)(stmt, false), | ||
resultCallback(result) { doneCallback((0, result_js_1.stmtResultFromProto)(result)); }, | ||
errorCallback, | ||
@@ -320,0 +308,0 @@ }); |
/// <reference types="ws" /> | ||
import WebSocket from "isomorphic-ws"; | ||
import type { Stmt, Value, StmtResult, RowArray, Row } from "./convert.js"; | ||
import type * as proto from "./proto.js"; | ||
export type { Stmt, StmtArgs, Value, StmtResult, RowArray, Row } from "./convert.js"; | ||
import type { StmtResult, RowsResult, RowResult, ValueResult } from "./result.js"; | ||
import type { InStmt } from "./stmt.js"; | ||
export * from "./errors.js"; | ||
export type { StmtResult, RowsResult, RowResult, ValueResult, Row } from "./result.js"; | ||
export type { InStmt, InStmtArgs } from "./stmt.js"; | ||
export { Stmt } from "./stmt.js"; | ||
export type { Value, InValue } from "./value.js"; | ||
export type { proto }; | ||
@@ -40,12 +44,12 @@ /** Open a Hrana client connected to the given `url`. */ | ||
executeRaw(stmt: proto.Stmt): Promise<proto.StmtResult>; | ||
/** Execute a statement that returns rows. */ | ||
query(stmt: Stmt): Promise<RowArray>; | ||
/** Execute a statement that returns at most a single row. */ | ||
queryRow(stmt: Stmt): Promise<Row | undefined>; | ||
/** Execute a statement that returns at most a single value. */ | ||
queryValue(stmt: Stmt): Promise<Value | undefined>; | ||
/** Execute a statement that does not return rows. */ | ||
execute(stmt: Stmt): Promise<StmtResult>; | ||
/** Execute a statement and return rows. */ | ||
query(stmt: InStmt): Promise<RowsResult>; | ||
/** Execute a statement and return at most a single row. */ | ||
queryRow(stmt: InStmt): Promise<RowResult>; | ||
/** Execute a statement and return at most a single value. */ | ||
queryValue(stmt: InStmt): Promise<ValueResult>; | ||
/** Execute a statement without returning rows. */ | ||
execute(stmt: InStmt): Promise<StmtResult>; | ||
/** Close the stream. */ | ||
close(): void; | ||
} |
import WebSocket from "isomorphic-ws"; | ||
import { stmtToProto, rowArrayFromProto, rowFromProto, stmtResultFromProto, valueFromProto, errorFromProto, } from "./convert.js"; | ||
import { ClientError, ProtoError, ClosedError } from "./errors.js"; | ||
import IdAlloc from "./id_alloc.js"; | ||
import { rowsResultFromProto, rowResultFromProto, valueResultFromProto, stmtResultFromProto, errorFromProto, } from "./result.js"; | ||
import { stmtToProto } from "./stmt.js"; | ||
export * from "./errors.js"; | ||
export { Stmt } from "./stmt.js"; | ||
/** Open a Hrana client connected to the given `url`. */ | ||
@@ -67,2 +69,6 @@ export function open(url, jwt) { | ||
#sendRequest(request, callbacks) { | ||
if (this.#closed !== undefined) { | ||
callbacks.errorCallback(new ClosedError("Client is closed", this.#closed)); | ||
return; | ||
} | ||
const requestId = this.#requestIdAlloc.alloc(); | ||
@@ -159,5 +165,2 @@ this.#responseMap.set(requestId, { ...callbacks, type: request.type }); | ||
openStream() { | ||
if (this.#closed !== undefined) { | ||
throw new ClosedError("Client is closed", this.#closed); | ||
} | ||
const streamId = this.#streamIdAlloc.alloc(); | ||
@@ -238,3 +241,3 @@ const streamState = { | ||
} | ||
/** Execute a statement that returns rows. */ | ||
/** Execute a statement and return rows. */ | ||
query(stmt) { | ||
@@ -244,5 +247,3 @@ return new Promise((rowsCallback, errorCallback) => { | ||
stmt: stmtToProto(stmt, true), | ||
resultCallback(result) { | ||
rowsCallback(rowArrayFromProto(result)); | ||
}, | ||
resultCallback(result) { rowsCallback(rowsResultFromProto(result)); }, | ||
errorCallback, | ||
@@ -252,3 +253,3 @@ }); | ||
} | ||
/** Execute a statement that returns at most a single row. */ | ||
/** Execute a statement and return at most a single row. */ | ||
queryRow(stmt) { | ||
@@ -258,10 +259,3 @@ return new Promise((rowCallback, errorCallback) => { | ||
stmt: stmtToProto(stmt, true), | ||
resultCallback(result) { | ||
if (result.rows.length >= 1) { | ||
rowCallback(rowFromProto(result, result.rows[0])); | ||
} | ||
else { | ||
rowCallback(undefined); | ||
} | ||
}, | ||
resultCallback(result) { rowCallback(rowResultFromProto(result)); }, | ||
errorCallback, | ||
@@ -271,3 +265,3 @@ }); | ||
} | ||
/** Execute a statement that returns at most a single value. */ | ||
/** Execute a statement and return at most a single value. */ | ||
queryValue(stmt) { | ||
@@ -277,10 +271,3 @@ return new Promise((valueCallback, errorCallback) => { | ||
stmt: stmtToProto(stmt, true), | ||
resultCallback(result) { | ||
if (result.rows.length >= 1 && result.rows[0].length >= 1) { | ||
valueCallback(valueFromProto(result.rows[0][0])); | ||
} | ||
else { | ||
valueCallback(undefined); | ||
} | ||
}, | ||
resultCallback(result) { valueCallback(valueResultFromProto(result)); }, | ||
errorCallback, | ||
@@ -290,3 +277,3 @@ }); | ||
} | ||
/** Execute a statement that does not return rows. */ | ||
/** Execute a statement without returning rows. */ | ||
execute(stmt) { | ||
@@ -293,0 +280,0 @@ return new Promise((doneCallback, errorCallback) => { |
@@ -72,2 +72,3 @@ export type int32 = number; | ||
"affected_row_count": number; | ||
"last_insert_rowid"?: string | null; | ||
}; | ||
@@ -74,0 +75,0 @@ export type Col = { |
{ | ||
"name": "@libsql/hrana-client", | ||
"version": "0.1.4", | ||
"version": "0.2.0", | ||
"keywords": [ | ||
@@ -5,0 +5,0 @@ "hrana", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
55850
25
1388