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.6 to 1.7.7

8

dist/main.d.ts

@@ -1,2 +0,2 @@

import { libsqlFetchLike, libsqlSQLValue, libsqlSQLStatement, libsqlBatchReqStepExecCond, libsqlBatchReqStep, libsqlStatementResOkData, libsqlBatchStreamResOkData, libsqlStreamResErrData } from 'libsql-stateless';
import { libsqlFetchLike, libsqlSQLValue, libsqlSQLStatement, libsqlBatchReqStepExecCond, libsqlBatchReqStep, libsqlStatementResOkData, libsqlBatchStreamResOkData } from 'libsql-stateless';
export { libsqlFetchLike } from 'libsql-stateless';

@@ -309,4 +309,2 @@

code: string;
/** Raw numeric error code */
rawCode?: number;
constructor(message: string, code: string, cause?: Error);

@@ -320,7 +318,7 @@ }

declare class ResponseError extends LibsqlError {
constructor(message: string, protoError: libsqlStreamResErrData);
constructor(message: string, code?: string | null);
}
/** Error thrown when the HTTP server returns an error response. */
declare class HttpServerError extends LibsqlError {
constructor(message: string, status: number);
constructor(status: number, message?: string | null);
}

@@ -327,0 +325,0 @@ /** Error thrown when an internal client error happens. */

import { libsqlExecute, libsqlBatch, libsqlServerCompatCheck } from 'libsql-stateless';
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 u=(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});u(this,"code");u(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(e,r){super(`${e}: ${r.message}`,r.code??"UNKNOWN"),this.name="ResponseError",this.stack=void 0;}},h=class extends a{constructor(e,r){super(`HTTP code ${r}: ${e}`,"SERVER_ERROR"),this.name="HttpServerError";}},l=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+/=",m=Array.prototype.slice.call(nt),q=(t=>{let e={};return t.forEach((r,s)=>e[r]=s),e})(m),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 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+=m[e>>18&63]+m[e>>12&63]+m[e>>6&63]+m[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 l("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 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:y(s),condition:R.ok(n)}));return [ft(e)].concat(r).concat(mt(r.length))}function bt(t,e="number"){switch(e){case"number":return +t;case"string":return t;case"bigint":return BigInt(t);default:throw new l('Invalid value for "intMode".')}}function dt(t,e){switch(t.type){case"null":return null;case"integer":return bt(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 c=dt(t.rows[n][i],e);Object.defineProperty(o,i,{value:c});let g=t.cols[i].name;g!==void 0&&!Object.hasOwn(o,g)&&Object.defineProperty(o,g,{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 p(((n=t.step_errors[s])==null?void 0:n.message)??"No error message supplied by server.",t.step_errors[s]);return null})}function F(t,e){let r=_(t,e);return r.slice(1,r.length-2).filter(s=>s!==null)}function b(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(b(t),y(e,r,s));if(n.isOk)return B(n.val,t.intMode);throw w(n.err)}async function $(t,e,r){let s=await libsqlBatch(b(t),j(e,r));if(s.isOk)return _(s.val,t.intMode);throw w(s.err)}async function z(t){return (await libsqlServerCompatCheck(b(t))).isOk}async function K(t,e,r="deferred"){let s=await libsqlBatch(b(t),H(e,r));if(s.isOk)return F(s.val,t.intMode);throw w(s.err)}async function Z(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(b(t),r);if(!s.isOk)throw w(s.err)}var G=typeof console.error=="function",J=typeof URL=="function",Y=t=>console.error(t),X=t=>new URL(t);function tt(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 A(t){G&&Y(t);}function et(t){if((()=>{if(J)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 Ft(t){return new E(t)}var E=class{constructor(e){u(this,"conf");u(this,"closed");u(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 K(this.conf,e,r)}async batchWithoutTransaction(e,r){return await $(this.conf,e,r)}async transaction(e){throw new l("'libsql-stateless' is stateless and does not support interactive transactions. Use this.batch() instead.")}async executeMultiple(e){return await Z(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.");}};
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 u=(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});u(this,"code");this.code=s,this.name="LibsqlError";}},d=class extends a{constructor(e){super(e,"HRANA_PROTO_ERROR"),this.name="ProtoError";}},p=class extends a{constructor(e,r){super(e,r??"UNKNOWN"),this.name="ResponseError",this.stack=void 0;}},h=class extends a{constructor(e,r){super(`HTTP code ${e}: ${r??"No error message from server."}`,"SERVER_ERROR"),this.name="HttpServerError";}},l=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 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},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 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:P(t)};throw new l("Invalid type of input. Cannot build request to server.")}function D(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 y(t,e,r){if(typeof t=="string"){let s=D(e);return {sql:t,args:s.args,named_args:s.named_args,want_rows:r}}else {let s=D(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 H(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 l('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 c=dt(t.rows[n][i],e);Object.defineProperty(o,i,{value:c});let g=t.cols[i].name;g!==void 0&&!Object.hasOwn(o,g)&&Object.defineProperty(o,g,{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,o;if(r)return B(r,e);if(t.step_errors[s])throw new p((n=t.step_errors[s])==null?void 0:n.message,(o=t.step_errors[s])==null?void 0:o.code);return null})}function F(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.http_status_code,t.server_message):new p(t.data.message,t.data.code)}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),H(e,r));if(s.isOk)return F(s.val,t.intMode);throw w(s.err)}async function $(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 G=typeof console.error=="function",J=typeof URL=="function",Y=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){G&&Y(t);}function et(t){if((()=>{if(J)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 Ft(t){return new E(t)}var E=class{constructor(e){u(this,"conf");u(this,"closed");u(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 l("'libsql-stateless' is stateless and does not support interactive transactions. Use this.batch() instead.")}async executeMultiple(e){return await $(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, a as LibsqlError, l as MisuseError, d as ProtoError, p as ResponseError, Ft as createClient, V as libsqlArgumentsBuilder, $ as libsqlBatch, R as libsqlBatchReqStepExecCondBuilder, j as libsqlBatchReqStepsBuilder, _ as libsqlBatchStreamResParser, K as libsqlBatchTransaction, E as libsqlClient, W as libsqlExecute, Z as libsqlExecuteMultiple, z as libsqlServerCompatCheck, y as libsqlStatementBuilder, B as libsqlStatementResParser, H as libsqlTransactionBatchReqStepsBuilder, F as libsqlTransactionBatchStreamResParser, ft as libsqlTransactionBeginStatement, mt as libsqlTransactionEndStatements, D as libsqlValueBuilder, dt as libsqlValueParser };
export { h as HttpServerError, a as LibsqlError, l as MisuseError, d as ProtoError, p as ResponseError, Ft as createClient, D as libsqlArgumentsBuilder, z as libsqlBatch, R as libsqlBatchReqStepExecCondBuilder, j as libsqlBatchReqStepsBuilder, _ as libsqlBatchStreamResParser, Z as libsqlBatchTransaction, E as libsqlClient, W as libsqlExecute, $ as libsqlExecuteMultiple, K as libsqlServerCompatCheck, y as libsqlStatementBuilder, B as libsqlStatementResParser, H as libsqlTransactionBatchReqStepsBuilder, F as libsqlTransactionBatchStreamResParser, ft as libsqlTransactionBeginStatement, bt as libsqlTransactionEndStatements, V as libsqlValueBuilder, dt as libsqlValueParser };
{
"name": "libsql-stateless-easy",
"version": "1.7.6",
"version": "1.7.7",
"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.39kB (unpacked)* / 3.6kB (gzipped)
- ✅ **Is extremely light:** 8.3kB (unpacked)* / 3.5kB (gzipped)
- ✅ **Is built for:** Quick stateless query execution. (Mainly for serverless and edge functions.)

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

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