Socket
Socket
Sign inDemoInstall

libsql-stateless-easy

Package Overview
Dependencies
Maintainers
0
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

libsql-stateless-easy - npm Package Compare versions

Comparing version 1.7.4 to 1.7.5

9

dist/main.d.ts

@@ -233,3 +233,3 @@ import { libsqlFetchLike, libsqlSQLValue, libsqlSQLStatement, libsqlBatchReqStepExecCond, libsqlBatchReqStep, libsqlStatementResOkData, libsqlBatchStreamResOkData, libsqlStreamResErrData } from 'libsql-stateless';

*/
execute(stmt: rawSQL, args: rawSQLArgs, want_rows?: boolean): Promise<ResultSet>;
execute(stmt: rawSQL, args?: rawSQLArgs, want_rows?: boolean): Promise<ResultSet>;
execute(stmt: rawSQLStatement): Promise<ResultSet>;

@@ -320,2 +320,3 @@ /** Execute a batch of SQL statements in a transaction.

declare class ResponseError extends LibsqlError {
proto: libsqlStreamResErrData;
constructor(message: string, protoError: libsqlStreamResErrData);

@@ -325,8 +326,6 @@ }

declare class HttpServerError extends LibsqlError {
status: number;
constructor(message: string, status: number);
}
/** Error thrown when an internal client error happens. */
declare class InternalError extends LibsqlError {
constructor(message: string);
}
/** Error thrown when the API is misused. */

@@ -337,2 +336,2 @@ declare class MisuseError extends LibsqlError {

export { HttpServerError, InternalError, LibsqlError, MisuseError, ProtoError, ResponseError, type ResultSet, type Row, type TransactionMode, createClient, type intMode, libsqlArgumentsBuilder, libsqlBatch, libsqlBatchReqStepExecCondBuilder, libsqlBatchReqStepsBuilder, libsqlBatchStreamResParser, libsqlBatchTransaction, libsqlClient, type libsqlConfig, libsqlExecute, libsqlExecuteMultiple, libsqlServerCompatCheck, libsqlStatementBuilder, libsqlStatementResParser, libsqlTransactionBatchReqStepsBuilder, libsqlTransactionBatchStreamResParser, libsqlTransactionBeginStatement, libsqlTransactionEndStatements, libsqlValueBuilder, libsqlValueParser, type rawSQL, type rawSQLArgs, type rawSQLStatement, type rawValue };
export { HttpServerError, LibsqlError, MisuseError, ProtoError, ResponseError, type ResultSet, type Row, type TransactionMode, createClient, type intMode, libsqlArgumentsBuilder, libsqlBatch, libsqlBatchReqStepExecCondBuilder, libsqlBatchReqStepsBuilder, libsqlBatchStreamResParser, libsqlBatchTransaction, libsqlClient, type libsqlConfig, libsqlExecute, libsqlExecuteMultiple, libsqlServerCompatCheck, libsqlStatementBuilder, libsqlStatementResParser, libsqlTransactionBatchReqStepsBuilder, libsqlTransactionBatchStreamResParser, libsqlTransactionBeginStatement, libsqlTransactionEndStatements, libsqlValueBuilder, libsqlValueParser, type rawSQL, type rawSQLArgs, type rawSQLStatement, type rawValue };
import { libsqlExecute, libsqlBatch, libsqlServerCompatCheck } from 'libsql-stateless';
var st=Object.defineProperty;var nt=(t,e,r)=>e in t?st(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var l=(t,e,r)=>(nt(t,typeof e!="symbol"?e+"":e,r),r);var a=class extends Error{constructor(r,s,n){super(`${s}: ${r}`,{cause:n});l(this,"code");l(this,"rawCode");this.code=s,this.rawCode=void 0,this.name="LibsqlError";}},d=class extends a{constructor(e){super(e,"HRANA_PROTO_ERROR",new class extends Error{constructor(){super(e),this.name="ProtoError";}});}},u=class extends a{constructor(e,r){super(e,r.code??"UNKNOWN",new class extends Error{constructor(){super(e);l(this,"proto");this.name="ResponseError",this.proto=r,this.stack=void 0;}});}},h=class extends a{constructor(e,r){super(e,"SERVER_ERROR",new class extends Error{constructor(){super(e);l(this,"status");this.status=r,this.name="HttpServerError";}});}},p=class extends a{constructor(e){super(e,"INTERNAL_ERROR",new class extends Error{constructor(){super(e),this.name="InternalError";}});}},q=class extends a{constructor(e){super(e,"UNKNOWN",new class extends Error{constructor(){super(e),this.name="MisuseError";}});}};var f=typeof Buffer=="function",C=typeof btoa=="function",Q=typeof atob=="function",O=t=>atob(t),T=t=>btoa(t),U=t=>Buffer.from(t).toString("base64"),I=t=>Buffer.from(t,"binary").toString("base64"),M=t=>Buffer.from(t,"base64"),k=t=>Buffer.from(t,"base64").toString("binary");var ot="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",b=Array.prototype.slice.call(ot),S=(t=>{let e={};return t.forEach((r,s)=>e[r]=s),e})(b),at=/^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/,it=t=>{let e,r,s,n,o="",i=t.length%3;for(let c=0;c<t.length;){if((r=t.charCodeAt(c++))>255||(s=t.charCodeAt(c++))>255||(n=t.charCodeAt(c++))>255)throw new a("Invalid character found while polyfilling btoa","BTOA_POLYFILL_INVALID_CHAR");e=r<<16|s<<8|n,o+=b[e>>18&63]+b[e>>12&63]+b[e>>6&63]+b[e&63];}return i?o.slice(0,i-3)+"===".substring(i):o},lt=C?t=>T(t):f?t=>I(t):it,y=String.fromCharCode.bind(String),N=f?t=>U(t):t=>{let r=[];for(let s=0,n=t.length;s<n;s+=4096){let o=[];t.subarray(s,s+4096).forEach(i=>o.push(i.valueOf())),r.push(y.apply(null,o));}return lt(r.join(""))},v=t=>t.replace(/[^A-Za-z0-9\+\/]/g,""),ct=t=>{if(t=t.replace(/\s+/g,""),!at.test(t))throw new a("Malformed base64 while polyfilling atob","MALFORMED_BASE64_FOR_ATOB");t+="==".slice(2-(t.length&3));let e,r="",s,n;for(let o=0;o<t.length;)e=S[t.charAt(o++)]<<18|S[t.charAt(o++)]<<12|(s=S[t.charAt(o++)])<<6|(n=S[t.charAt(o++)]),r+=s===64?y(e>>16&255):n===64?y(e>>16&255,e>>8&255):y(e>>16&255,e>>8&255,e&255);return r},ut=Q?t=>O(v(t)):f?t=>k(t):ct,P=typeof Uint8Array.from=="function"?Uint8Array.from.bind(Uint8Array):t=>new Uint8Array(Array.prototype.slice.call(t,0)),pt=f?t=>P(M(t)):t=>P(ut(t).split("").map(e=>e.charCodeAt(0))),ft=t=>v(t.replace(/[-_]/g,e=>e=="-"?"+":"/")),D=t=>pt(ft(t));function V(t){if(t===null)return {type:"null"};if(typeof t=="bigint")return {type:"integer",value:""+t};if(typeof t=="number")return {type:"float",value:t};if(typeof t=="string")return {type:"text",value:t};if(t instanceof Uint8Array)return {type:"blob",base64:N(t)};throw new p("Invalid type of input. Cannot build request to server.")}function j(t){if(t===void 0)return {};if(Object.prototype.toString.call(t)==="[object Array]")return {args:t.map(e=>V(e))};{let e=[],r=t;for(let s in r)e.push({name:s,value:V(r[s])});return {named_args:e}}}function w(t,e,r){if(typeof t=="string"){let s=j(e);return {sql:t,args:s.args,named_args:s.named_args,want_rows:r}}else {let s=j(t.args);return {sql:t.sql,args:s.args,named_args:s.named_args,want_rows:t.want_rows}}}var x={ok:t=>({type:"ok",step:t}),error:t=>({type:"error",step:t}),not:t=>({type:"not",cond:t}),and:t=>({type:"and",conds:t}),or:t=>({type:"or",conds:t}),is_autocommit:()=>({type:"is_autocommit"})};function F(t,e){return t.map((r,s)=>({stmt:w(r),condition:e[s]??void 0}))}function bt(t){if(t==="write")return {stmt:{sql:"BEGIN IMMEDIATE"}};if(t==="read")return {stmt:{sql:"BEGIN TRANSACTION READONLY"}};if(t==="deferred")return {stmt:{sql:"BEGIN DEFERRED"}};throw RangeError('Unknown transaction mode, supported values are "write", "read" and "deferred"')}function mt(t){return [{stmt:{sql:"COMMIT"},condition:{type:"ok",step:t}},{stmt:{sql:"ROLLBACK"},condition:{type:"not",cond:{type:"ok",step:t+1}}}]}function H(t,e){let r=t.map((s,n)=>({stmt:w(s),condition:x.ok(n)}));return [bt(e)].concat(r).concat(mt(r.length))}function dt(t,e="number"){switch(e){case"number":return +t;case"string":return t;case"bigint":return BigInt(t);default:throw new q('Invalid value for "intMode".')}}function ht(t,e){switch(t.type){case"null":return null;case"integer":return dt(t.value,e);case"float":return Number(t.value);case"text":return t.value;case"blob":return D(t.base64);default:throw new d("Invalid data type from server. Cannot parse.")}}function B(t,e){let r=[];for(let n=0;n<t.rows.length;n++){let o={};Object.defineProperty(o,"length",{value:t.rows[n].length});for(let i=0;i<t.rows[n].length;i++){let c=ht(t.rows[n][i],e);Object.defineProperty(o,i,{value:c});let R=t.cols[i].name;R!==void 0&&!Object.hasOwn(o,R)&&Object.defineProperty(o,R,{value:c,enumerable:!0,configurable:!0,writable:!0});}r.push(o);}let s={rows:r,columns:t.cols.map(n=>n.name??""),columnTypes:t.cols.map(n=>n.decltype??""),rowsAffected:t.affected_row_count,lastInsertRowid:t.last_insert_rowid?BigInt(t.last_insert_rowid):void 0,rowsRead:t.rows_read,rowsWritten:t.rows_written,queryDurationMS:t.query_duration_ms};return {...s,toJSON:()=>s}}function _(t,e){return t.step_results.map((r,s)=>{var n;if(r)return B(r,e);if(t.step_errors[s])throw new u(((n=t.step_errors[s])==null?void 0:n.message)??"No error message supplied by server.",t.step_errors[s]);return null})}function W(t,e){let r=_(t,e);return r.slice(1,r.length-2).filter(s=>s!==null)}function m(t){return {db_url:t.url,authToken:t.authToken,fetch:t.fetch}}function g(t){return t.kind==="LIBSQL_SERVER_ERROR"?new h(t.server_message??"No error message from server.",t.http_status_code):new u(t.data.message,t.data)}async function z(t,e,r,s){let n=await libsqlExecute(m(t),w(e,r,s));if(n.isOk)return B(n.val,t.intMode);throw g(n.err)}async function K(t,e,r){let s=await libsqlBatch(m(t),F(e,r));if(s.isOk)return _(s.val,t.intMode);throw g(s.err)}async function Z(t){return (await libsqlServerCompatCheck(m(t))).isOk}async function G(t,e,r="deferred"){let s=await libsqlBatch(m(t),H(e,r));if(s.isOk)return W(s.val,t.intMode);throw g(s.err)}async function J(t,e){let r=e.split(";").filter(n=>n.trim()!=="").map((n,o)=>({stmt:{sql:n},condition:x.ok(o-1)}));r[0].condition=void 0;let s=await libsqlBatch(m(t),r);if(!s.isOk)throw g(s.err)}var Y=typeof console.error=="function",$=typeof URL=="function",X=t=>console.error(t),tt=t=>new URL(t);function et(t){try{if(!Z(t))throw new a("Server incompatible. Please upgrade your libSQL server.","OUT_OF_DATE_SERVER")}catch{throw new a("The fetch function is non functional.","FETCH_FUCKED")}}function E(t){Y&&X(t);}function rt(t){if((()=>{if($)try{let r=tt(t);return !(r.protocol==="https:"||r.protocol==="http:")}catch(r){throw new a(r.message,"ERR_INVALID_URL",r)}else if(t.startsWith("https://")||t.startsWith("http://"))return !1;return !0})())throw new a('This is a HTTP client and only supports "https:" and "http:" URLs. For modern libsql DBs simply changing "libsql://" to "https://" should resolve this.',"URL_SCHEME_NOT_SUPPORTED")}function Jt(t){return new L(t)}var L=class{constructor(e){l(this,"conf");l(this,"closed");l(this,"protocol");e.disableCriticalChecks||(rt(e.url),et(e)),this.conf=e,this.closed=!1,this.protocol="http";}async execute(e,r,s){return await z(this.conf,e,r,s)}async batch(e,r){return await G(this.conf,e,r)}async batchWithoutTransaction(e,r){return await K(this.conf,e,r)}async transaction(e){throw new p("'libsql-stateless' is stateless and does not support interactive transactions. Use this.batch() instead.")}async executeMultiple(e){return await J(this.conf,e)}async sync(){E("'libsql-stateless' is remote only so nothing to sync.");}close(){E("'libsql-stateless' is stateless therefore no connection to close.");}};
var rt=Object.defineProperty;var st=(t,e,r)=>e in t?rt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var l=(t,e,r)=>(st(t,typeof e!="symbol"?e+"":e,r),r);var a=class extends Error{constructor(r,s,n){super(`${s}: ${r}`,{cause:n});l(this,"code");l(this,"rawCode");this.code=s,this.rawCode=void 0,this.name="LibsqlError";}},d=class extends a{constructor(e){super(e,"HRANA_PROTO_ERROR"),this.name="ProtoError";}},p=class extends a{constructor(r,s){super(r,s.code??"UNKNOWN");l(this,"proto");this.name="ResponseError",this.proto=s,this.stack=void 0;}},h=class extends a{constructor(r,s){super(r,"SERVER_ERROR");l(this,"status");this.status=s,this.name="HttpServerError";}},c=class extends a{constructor(e){super(e,"UNKNOWN"),this.name="MisuseError";}};var f=typeof Buffer=="function",L=typeof btoa=="function",C=typeof atob=="function",Q=t=>atob(t),O=t=>btoa(t),T=t=>Buffer.from(t).toString("base64"),U=t=>Buffer.from(t,"binary").toString("base64"),M=t=>Buffer.from(t,"base64"),k=t=>Buffer.from(t,"base64").toString("binary");var nt="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",b=Array.prototype.slice.call(nt),q=(t=>{let e={};return t.forEach((r,s)=>e[r]=s),e})(b),ot=/^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/,at=t=>{let e,r,s,n,o="",i=t.length%3;for(let u=0;u<t.length;){if((r=t.charCodeAt(u++))>255||(s=t.charCodeAt(u++))>255||(n=t.charCodeAt(u++))>255)throw new a("Invalid character found while polyfilling btoa","BTOA_POLYFILL_INVALID_CHAR");e=r<<16|s<<8|n,o+=b[e>>18&63]+b[e>>12&63]+b[e>>6&63]+b[e&63];}return i?o.slice(0,i-3)+"===".substring(i):o},it=L?t=>O(t):f?t=>U(t):at,S=String.fromCharCode.bind(String),P=f?t=>T(t):t=>{let r=[];for(let s=0,n=t.length;s<n;s+=4096){let o=[];t.subarray(s,s+4096).forEach(i=>o.push(i.valueOf())),r.push(S.apply(null,o));}return it(r.join(""))},v=t=>t.replace(/[^A-Za-z0-9\+\/]/g,""),lt=t=>{if(t=t.replace(/\s+/g,""),!ot.test(t))throw new a("Malformed base64 while polyfilling atob","MALFORMED_BASE64_FOR_ATOB");t+="==".slice(2-(t.length&3));let e,r="",s,n;for(let o=0;o<t.length;)e=q[t.charAt(o++)]<<18|q[t.charAt(o++)]<<12|(s=q[t.charAt(o++)])<<6|(n=q[t.charAt(o++)]),r+=s===64?S(e>>16&255):n===64?S(e>>16&255,e>>8&255):S(e>>16&255,e>>8&255,e&255);return r},ct=C?t=>Q(v(t)):f?t=>k(t):lt,I=typeof Uint8Array.from=="function"?Uint8Array.from.bind(Uint8Array):t=>new Uint8Array(Array.prototype.slice.call(t,0)),ut=f?t=>I(M(t)):t=>I(ct(t).split("").map(e=>e.charCodeAt(0))),pt=t=>v(t.replace(/[-_]/g,e=>e=="-"?"+":"/")),N=t=>ut(pt(t));function D(t){if(t===null)return {type:"null"};if(typeof t=="bigint")return {type:"integer",value:""+t};if(typeof t=="number")return {type:"float",value:t};if(typeof t=="string")return {type:"text",value:t};if(t instanceof Uint8Array)return {type:"blob",base64:P(t)};throw new c("Invalid type of input. Cannot build request to server.")}function V(t){if(t===void 0)return {};if(Object.prototype.toString.call(t)==="[object Array]")return {args:t.map(e=>D(e))};{let e=[],r=t;for(let s in r)e.push({name:s,value:D(r[s])});return {named_args:e}}}function y(t,e,r){if(typeof t=="string"){let s=V(e);return {sql:t,args:s.args,named_args:s.named_args,want_rows:r}}else {let s=V(t.args);return {sql:t.sql,args:s.args,named_args:s.named_args,want_rows:t.want_rows}}}var R={ok:t=>({type:"ok",step:t}),error:t=>({type:"error",step:t}),not:t=>({type:"not",cond:t}),and:t=>({type:"and",conds:t}),or:t=>({type:"or",conds:t}),is_autocommit:()=>({type:"is_autocommit"})};function j(t,e){return t.map((r,s)=>({stmt:y(r),condition:e[s]??void 0}))}function ft(t){if(t==="write")return {stmt:{sql:"BEGIN IMMEDIATE"}};if(t==="read")return {stmt:{sql:"BEGIN TRANSACTION READONLY"}};if(t==="deferred")return {stmt:{sql:"BEGIN DEFERRED"}};throw RangeError('Unknown transaction mode, supported values are "write", "read" and "deferred"')}function bt(t){return [{stmt:{sql:"COMMIT"},condition:{type:"ok",step:t}},{stmt:{sql:"ROLLBACK"},condition:{type:"not",cond:{type:"ok",step:t+1}}}]}function F(t,e){let r=t.map((s,n)=>({stmt:y(s),condition:R.ok(n)}));return [ft(e)].concat(r).concat(bt(r.length))}function mt(t,e="number"){switch(e){case"number":return +t;case"string":return t;case"bigint":return BigInt(t);default:throw new c('Invalid value for "intMode".')}}function dt(t,e){switch(t.type){case"null":return null;case"integer":return mt(t.value,e);case"float":return Number(t.value);case"text":return t.value;case"blob":return N(t.base64);default:throw new d("Invalid data type from server. Cannot parse.")}}function B(t,e){let r=[];for(let n=0;n<t.rows.length;n++){let o={};Object.defineProperty(o,"length",{value:t.rows[n].length});for(let i=0;i<t.rows[n].length;i++){let u=dt(t.rows[n][i],e);Object.defineProperty(o,i,{value:u});let g=t.cols[i].name;g!==void 0&&!Object.hasOwn(o,g)&&Object.defineProperty(o,g,{value:u,enumerable:!0,configurable:!0,writable:!0});}r.push(o);}let s={rows:r,columns:t.cols.map(n=>n.name??""),columnTypes:t.cols.map(n=>n.decltype??""),rowsAffected:t.affected_row_count,lastInsertRowid:t.last_insert_rowid?BigInt(t.last_insert_rowid):void 0,rowsRead:t.rows_read,rowsWritten:t.rows_written,queryDurationMS:t.query_duration_ms};return {...s,toJSON:()=>s}}function _(t,e){return t.step_results.map((r,s)=>{var n;if(r)return B(r,e);if(t.step_errors[s])throw new p(((n=t.step_errors[s])==null?void 0:n.message)??"No error message supplied by server.",t.step_errors[s]);return null})}function H(t,e){let r=_(t,e);return r.slice(1,r.length-2).filter(s=>s!==null)}function m(t){return {db_url:t.url,authToken:t.authToken,fetch:t.fetch}}function w(t){return t.kind==="LIBSQL_SERVER_ERROR"?new h(t.server_message??"No error message from server.",t.http_status_code):new p(t.data.message,t.data)}async function W(t,e,r,s){let n=await libsqlExecute(m(t),y(e,r,s));if(n.isOk)return B(n.val,t.intMode);throw w(n.err)}async function z(t,e,r){let s=await libsqlBatch(m(t),j(e,r));if(s.isOk)return _(s.val,t.intMode);throw w(s.err)}async function K(t){return (await libsqlServerCompatCheck(m(t))).isOk}async function Z(t,e,r="deferred"){let s=await libsqlBatch(m(t),F(e,r));if(s.isOk)return H(s.val,t.intMode);throw w(s.err)}async function G(t,e){let r=e.split(";").filter(n=>n.trim()!=="").map((n,o)=>({stmt:{sql:n},condition:R.ok(o-1)}));r[0].condition=void 0;let s=await libsqlBatch(m(t),r);if(!s.isOk)throw w(s.err)}var J=typeof console.error=="function",Y=typeof URL=="function",$=t=>console.error(t),X=t=>new URL(t);function tt(t){try{if(!K(t))throw new a("Server incompatible. Please upgrade your libSQL server.","OUT_OF_DATE_SERVER")}catch{throw new a("The fetch function is non functional.","FETCH_FUCKED")}}function A(t){J&&$(t);}function et(t){if((()=>{if(Y)try{let r=X(t);return !(r.protocol==="https:"||r.protocol==="http:")}catch(r){throw new a(r.message,"ERR_INVALID_URL",r)}else if(t.startsWith("https://")||t.startsWith("http://"))return !1;return !0})())throw new a('This is a HTTP client and only supports "https:" and "http:" URLs. For modern libsql DBs simply changing "libsql://" to "https://" should resolve this.',"URL_SCHEME_NOT_SUPPORTED")}function Ht(t){return new E(t)}var E=class{constructor(e){l(this,"conf");l(this,"closed");l(this,"protocol");e.disableCriticalChecks||(et(e.url),tt(e)),this.conf=e,this.closed=!1,this.protocol="http";}async execute(e,r,s){return await W(this.conf,e,r,s)}async batch(e,r){return await Z(this.conf,e,r)}async batchWithoutTransaction(e,r){return await z(this.conf,e,r)}async transaction(e){throw new c("'libsql-stateless' is stateless and does not support interactive transactions. Use this.batch() instead.")}async executeMultiple(e){return await G(this.conf,e)}async sync(){A("'libsql-stateless' is remote only so nothing to sync.");}close(){A("'libsql-stateless' is stateless therefore no connection to close.");}};
export { h as HttpServerError, p as InternalError, a as LibsqlError, q as MisuseError, d as ProtoError, u as ResponseError, Jt as createClient, j as libsqlArgumentsBuilder, K as libsqlBatch, x as libsqlBatchReqStepExecCondBuilder, F as libsqlBatchReqStepsBuilder, _ as libsqlBatchStreamResParser, G as libsqlBatchTransaction, L as libsqlClient, z as libsqlExecute, J as libsqlExecuteMultiple, Z as libsqlServerCompatCheck, w as libsqlStatementBuilder, B as libsqlStatementResParser, H as libsqlTransactionBatchReqStepsBuilder, W as libsqlTransactionBatchStreamResParser, bt as libsqlTransactionBeginStatement, mt as libsqlTransactionEndStatements, V as libsqlValueBuilder, ht as libsqlValueParser };
export { h as HttpServerError, a as LibsqlError, c as MisuseError, d as ProtoError, p as ResponseError, Ht as createClient, V as libsqlArgumentsBuilder, z as libsqlBatch, R as libsqlBatchReqStepExecCondBuilder, j as libsqlBatchReqStepsBuilder, _ as libsqlBatchStreamResParser, Z as libsqlBatchTransaction, E as libsqlClient, W as libsqlExecute, G as libsqlExecuteMultiple, K as libsqlServerCompatCheck, y as libsqlStatementBuilder, B as libsqlStatementResParser, F as libsqlTransactionBatchReqStepsBuilder, H as libsqlTransactionBatchStreamResParser, ft as libsqlTransactionBeginStatement, bt as libsqlTransactionEndStatements, D as libsqlValueBuilder, dt as libsqlValueParser };
{
"name": "libsql-stateless-easy",
"version": "1.7.4",
"version": "1.7.5",
"description": "thin libSQL stateless http driver for TypeScript and JavaScript but easy",

@@ -5,0 +5,0 @@ "homepage": "https://github.com/DaBigBlob/libsql-stateless-easy#readme",

@@ -5,3 +5,3 @@ # libsql-stateless-easy

- ✅ **Supported runtime environments:** Web API (browser, serverless), Bun, Node.js (>=18)
- ✅ **Is extremely light:** 8.79kB (unpacked)* / 3.8kB (gzipped)
- ✅ **Is extremely light:** 8.39kB (unpacked)* / 3.6kB (gzipped)
- ✅ **Is built for:** Quick stateless query execution. (Mainly for serverless and edge functions.)

@@ -24,3 +24,3 @@ - ✅ Supports everything in `@libsql/client/web` **except `interactive transactions`.

# Client Usage
`libsql-stateless-easy`'s `client` has the exact same API as [`@libsql/client/web`](https://docs.turso.tech/libsql/client-access/javascript-typescript-sdk#create-a-database-client-object-for-local-and-remote-access)'s `client`.
`libsql-stateless-easy`'s `client` has the exact same API as [`@libsql/client/web`](https://docs.turso.tech/sdk/ts/reference)'s `client`.
```ts

@@ -58,2 +58,5 @@ import { createClient } from "libsql-stateless-easy";

console.log(res2);
const res3 = await client.execute("select first_name, last_name, email, contact_id from contacts where contact_id = 1;");
console.log(res3);
```

@@ -93,14 +96,82 @@

## Custom Fetch
Pass your own implementation of fetch or fetch-like function if you don't want libsql-stateless-easy to use the global fetch or if your global fetch does not exist.
```ts
import { createClient, libsqlFetchLike } from 'libsql-stateless-easy';
const client = createClient({
url: "https://da-fish-mandible.turso.io",
authToken: "fksdgfgksdgfksdg.javsdKDGKSBkgsdfg289374dg",
fetch: async (...args: Parameters<libsqlFetchLike>): ReturnType<libsqlFetchLike> => {
//implement your own fetch here (look at examples/custom_fetch/libsql_isomorphic_fetch.ts for concrete example)
/** NOTE:
* args[0] is the url string
* args[1] is the request init
*/
);
}
});
const res = await client.execute("select * from contacts;", []);
console.log(res);
```
## Modularity
`libsql-stateless-easy` is extremely modular. `execute`, `batch`, etc. can be used without initiating a `client`.
```ts
import { libsqlBatchTransaction, libsqlExecute } from "libsql-stateless-easy";
//or
const { libsqlBatchTransaction, libsqlExecute } = require("libsql-stateless-easy");
const config = {
url: "https://da-fish-mandible.turso.io",
authToken: "fksdgfgksdgfksdg.javsdKDGKSBkgsdfg289374dg"
};
const res = await libsqlBatchTransaction(
config,
[
{
sql: "select * from contacts where contact_id = ?;",
args: [3]
},
"select first_name, last_name, email from contacts where contact_id = 2",
{
sql: "insert into contacts (contact_id,first_name,last_name,email,phone) values (?,?,?,?,?);",
args: [6,"glomm","feru","moca@doro.co","001"]
},
{
sql: "delete from contacts where contact_id = :kkl",
args: {kkl: 6}
}
]
);
console.log(res);
const res2 = await libsqlExecute(
config,
{
sql: "select first_name, last_name, email, contact_id from contacts where contact_id = ?;",
args: [1]
}
);
console.log(res2);
const res3 = await libsqlExecute(config, "select first_name, last_name, email, contact_id from contacts where contact_id = 1;", []);
console.log(res3);
```
`libsql-stateless-easy`'s `client` just conveniently packages these individually executable functions to conform to the official sdk interface.
### List of other stuff in this library
Feel free to explore them (however you don't need to as they've been neatly packaged into the `client`)
```ts
import {
libsqlValueBuilder, libsqlArgumentsBuilder, libsqlStatementBuilder, libsqlBatchReqStepsBuilder, libsqlBatchReqStepExecCondBuilder, libsqlTransactionBeginStatement,
libsqlValueParser, libsqlStatementResParser, libsqlBatchStreamResParser, libsqlTransactionBatchStreamResParser,
libsqlExecute, //has easier API than `libsql-stateless`'s function of the same name
libsqlBatch, //has easier API than `libsql-stateless`'s function of the same name
libsqlServerCompatCheck, //has easier API than `libsql-stateless`'s function of the same name,
libsqlBatchTransaction, libsqlExecuteMultiple
createClient //used above
} from "libsql-stateless-easy";
import {
libsqlValueBuilder, libsqlArgumentsBuilder, libsqlStatementBuilder, libsqlBatchReqStepsBuilder, libsqlBatchReqStepExecCondBuilder, libsqlTransactionBeginStatement,
libsqlValueParser, libsqlStatementResParser, libsqlBatchStreamResParser, libsqlTransactionBatchStreamResParser,
libsqlExecute, //has easier API than `libsql-stateless`'s function of the same name
libsqlBatch, //has easier API than `libsql-stateless`'s function of the same name
libsqlServerCompatCheck, //has easier API than `libsql-stateless`'s function of the same name,
libsqlBatchTransaction, libsqlExecuteMultiple
createClient //used above
} from "libsql-stateless-easy";
```

@@ -107,0 +178,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc