Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
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.1 to 1.7.2

4

dist/main.d.ts

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

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

@@ -44,3 +44,3 @@ type rawValue = null | bigint | number | string | ArrayBuffer;

/** Custom `fetch` function to use for the HTTP client.*/
fetch?: Function;
fetch?: libsqlFetchLike;
}

@@ -47,0 +47,0 @@ /** Row returned from an SQL statement.

import { libsqlExecute, libsqlBatch, libsqlServerCompatCheck } from 'libsql-stateless';
var nt=Object.defineProperty;var ot=(t,r,e)=>r in t?nt(t,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[r]=e;var l=(t,r,e)=>(ot(t,typeof r!="symbol"?r+"":r,e),e);var a=class extends Error{constructor(e,s,n){super(`${s}: ${e}`,{cause:n});l(this,"code");l(this,"rawCode");this.code=s,this.rawCode=void 0,this.name="LibsqlError";}},h=class extends a{constructor(r){super(r,"HRANA_PROTO_ERROR",new class extends Error{constructor(){super(r),this.name="ProtoError";}});}},u=class extends a{constructor(r,e){super(r,e.code??"UNKNOWN",new class extends Error{constructor(){super(r);l(this,"proto");this.name="ResponseError",this.proto=e,this.stack=void 0;}});}},q=class extends a{constructor(r,e){super(r,"SERVER_ERROR",new class extends Error{constructor(){super(r);l(this,"status");this.status=e,this.name="HttpServerError";}});}},p=class extends a{constructor(r){super(r,"INTERNAL_ERROR",new class extends Error{constructor(){super(r),this.name="InternalError";}});}},S=class extends a{constructor(r){super(r,"UNKNOWN",new class extends Error{constructor(){super(r),this.name="MisuseError";}});}};var f=class extends a{constructor(r,e){super(r,e,new class extends Error{constructor(){super(r),this.name="Base64Error";}});}};var b=typeof Buffer=="function",Q=typeof btoa=="function",O=typeof atob=="function",T=t=>atob(t),I=t=>btoa(t),U=t=>Buffer.from(t).toString("base64"),k=t=>Buffer.from(t,"binary").toString("base64"),M=t=>Buffer.from(t,"base64"),P=t=>Buffer.from(t,"base64").toString("binary");var at="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",m=Array.prototype.slice.call(at),y=(t=>{let r={};return t.forEach((e,s)=>r[e]=s),r})(m),it=/^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/,lt=t=>{let r,e,s,n,o="",i=t.length%3;for(let c=0;c<t.length;){if((e=t.charCodeAt(c++))>255||(s=t.charCodeAt(c++))>255||(n=t.charCodeAt(c++))>255)throw new f("Invalid character found while polyfilling btoa","BTOA_POLYFILL_INVALID_CHAR");r=e<<16|s<<8|n,o+=m[r>>18&63]+m[r>>12&63]+m[r>>6&63]+m[r&63];}return i?o.slice(0,i-3)+"===".substring(i):o},ct=Q?t=>I(t):b?t=>k(t):lt,w=String.fromCharCode.bind(String),v=b?t=>U(t):t=>{let e=[];for(let s=0,n=t.length;s<n;s+=4096){let o=[];t.subarray(s,s+4096).forEach(i=>o.push(i.valueOf())),e.push(w.apply(null,o));}return ct(e.join(""))},D=t=>t.replace(/[^A-Za-z0-9\+\/]/g,""),ut=t=>{if(t=t.replace(/\s+/g,""),!it.test(t))throw new f("Malformed base64 while polyfilling atob","ATOB_POLYFILL_INVALID_CHAR");t+="==".slice(2-(t.length&3));let r,e="",s,n;for(let o=0;o<t.length;)r=y[t.charAt(o++)]<<18|y[t.charAt(o++)]<<12|(s=y[t.charAt(o++)])<<6|(n=y[t.charAt(o++)]),e+=s===64?w(r>>16&255):n===64?w(r>>16&255,r>>8&255):w(r>>16&255,r>>8&255,r&255);return e},pt=O?t=>T(D(t)):b?t=>P(t):ut,N=typeof Uint8Array.from=="function"?Uint8Array.from.bind(Uint8Array):t=>new Uint8Array(Array.prototype.slice.call(t,0)),ft=b?t=>N(M(t)):t=>N(pt(t).split("").map(r=>r.charCodeAt(0))),bt=t=>D(t.replace(/[-_]/g,r=>r=="-"?"+":"/")),V=t=>ft(bt(t));function j(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:v(t)};throw new p("Invalid type of input. Cannot build request to server.")}function H(t){if(t===void 0)return {};if(Object.prototype.toString.call(t)==="[object Array]")return {args:t.map(r=>j(r))};{let r=[],e=t;for(let s in e)r.push({name:s,value:j(e[s])});return {named_args:r}}}function g(t,r,e){if(typeof t=="string"){let s=H(r);return {sql:t,args:s.args,named_args:s.named_args,want_rows:e}}else {let s=H(t.args);return {sql:t.sql,args:s.args,named_args:s.named_args,want_rows:t.want_rows}}}var _={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,r){return t.map((e,s)=>({stmt:g(e),condition:r[s]??void 0}))}function mt(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 dt(t){return [{stmt:{sql:"COMMIT"},condition:{type:"ok",step:t}},{stmt:{sql:"ROLLBACK"},condition:{type:"not",cond:{type:"ok",step:t+1}}}]}function W(t,r){let e=t.map((s,n)=>({stmt:g(s),condition:_.ok(n)}));return [mt(r)].concat(e).concat(dt(e.length))}function ht(t,r="number"){switch(r){case"number":return +t;case"string":return t;case"bigint":return BigInt(t);default:throw new S('Invalid value for "intMode".')}}function qt(t,r){switch(t.type){case"null":return null;case"integer":return ht(t.value,r);case"float":return Number(t.value);case"text":return t.value;case"blob":return V(t.base64);default:throw new h("Invalid data type from server. Cannot parse.")}}function B(t,r){let e=[];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=qt(t.rows[n][i],r);Object.defineProperty(o,i,{value:c});let x=t.cols[i].name;x!==void 0&&!Object.hasOwn(o,x)&&Object.defineProperty(o,x,{value:c,enumerable:!0,configurable:!0,writable:!0});}e.push(o);}let s={rows:e,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 A(t,r){return t.step_results.map((e,s)=>{var n;if(e)return B(e,r);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 z(t,r){let e=A(t,r);return e.slice(1,e.length-2).filter(s=>s!==null)}function d(t){return {db_url:t.url,authToken:t.authToken,fetch:t.fetch}}function R(t){return t.kind==="LIBSQL_SERVER_ERROR"?new q(t.server_message??"No error message from server.",t.http_status_code):new u(t.data.message,t.data)}async function K(t,r,e,s){let n=await libsqlExecute(d(t),g(r,e,s));if(n.isOk)return B(n.val,t.intMode);throw R(n.err)}async function Z(t,r,e){let s=await libsqlBatch(d(t),F(r,e));if(s.isOk)return A(s.val,t.intMode);throw R(s.err)}async function G(t){return (await libsqlServerCompatCheck(d(t))).isOk}async function Y(t,r,e="deferred"){let s=await libsqlBatch(d(t),W(r,e));if(s.isOk)return z(s.val,t.intMode);throw R(s.err)}async function J(t,r){let e=r.split(";").filter(n=>n.trim()!=="").map((n,o)=>({stmt:{sql:n},condition:_.ok(o-1)}));e[0].condition=void 0;let s=await libsqlBatch(d(t),e);if(!s.isOk)throw R(s.err)}var $=typeof console.error=="function",X=typeof URL=="function",tt=t=>console.error(t),rt=t=>new URL(t);function et(t){try{if(!G(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 L(t){$&&tt(t);}function st(t){if((()=>{if(X)try{let e=rt(t);return !(e.protocol==="https:"||e.protocol==="http:")}catch(e){throw new a(e.message,"ERR_INVALID_URL",e)}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.',"URL_SCHEME_NOT_SUPPORTED")}function tr(t){return new C(t)}var C=class{constructor(r){l(this,"conf");l(this,"closed");l(this,"protocol");r.disableCriticalChecks||(st(r.url),et(r)),this.conf=r,this.closed=!1,this.protocol="http";}async execute(r,e,s){return await K(this.conf,r,e,s)}async batch(r,e){return await Y(this.conf,r,e)}async batchWithoutTransaction(r,e){return await Z(this.conf,r,e)}async transaction(r){throw new p("'libsql-stateless' is stateless and does not support interactive transactions. Use this.batch() instead.")}async executeMultiple(r){return await J(this.conf,r)}async sync(){L("'libsql-stateless' is remote only so nothing to sync.");}close(){L("'libsql-stateless' is stateless therefore no connection to close.");}};
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 B={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:B.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 _(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 x(t,e){return t.step_results.map((r,s)=>{var n;if(r)return _(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=x(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 _(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 x(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:B.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.");}};
export { q as HttpServerError, p as InternalError, a as LibsqlError, S as MisuseError, h as ProtoError, u as ResponseError, tr as createClient, H as libsqlArgumentsBuilder, Z as libsqlBatch, _ as libsqlBatchReqStepExecCondBuilder, F as libsqlBatchReqStepsBuilder, A as libsqlBatchStreamResParser, Y as libsqlBatchTransaction, C as libsqlClient, K as libsqlExecute, J as libsqlExecuteMultiple, G as libsqlServerCompatCheck, g as libsqlStatementBuilder, B as libsqlStatementResParser, W as libsqlTransactionBatchReqStepsBuilder, z as libsqlTransactionBatchStreamResParser, mt as libsqlTransactionBeginStatement, dt as libsqlTransactionEndStatements, j as libsqlValueBuilder, qt as libsqlValueParser };
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, B as libsqlBatchReqStepExecCondBuilder, F as libsqlBatchReqStepsBuilder, x as libsqlBatchStreamResParser, G as libsqlBatchTransaction, L as libsqlClient, z as libsqlExecute, J as libsqlExecuteMultiple, Z as libsqlServerCompatCheck, w as libsqlStatementBuilder, _ as libsqlStatementResParser, H as libsqlTransactionBatchReqStepsBuilder, W as libsqlTransactionBatchStreamResParser, bt as libsqlTransactionBeginStatement, mt as libsqlTransactionEndStatements, V as libsqlValueBuilder, ht as libsqlValueParser };
{
"name": "libsql-stateless-easy",
"version": "1.7.1",
"version": "1.7.2",
"description": "thin libSQL stateless http driver for TypeScript and JavaScript but easy",

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

"dependencies": {
"libsql-stateless": "^2.8.6"
"libsql-stateless": "^2.9.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