Socket
Socket
Sign inDemoInstall

libsql-stateless-easy

Package Overview
Dependencies
1
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.6.2-alpha.1 to 1.6.2-alpha.2

4

dist/main.js
import { libsqlExecute, libsqlBatch, libsqlServerCompatCheck } from 'libsql-stateless';
var tt=Object.defineProperty;var et=(t,e,r)=>e in t?tt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var l=(t,e,r)=>(et(t,typeof e!="symbol"?e+"":e,r),r);var d=typeof Buffer=="function",A=typeof btoa=="function",C=typeof atob=="function",L=t=>atob(t),O=t=>btoa(t),T=t=>Buffer.from(t).toString("base64"),U=t=>Buffer.from(t,"binary").toString("base64"),k=t=>Buffer.from(t,"base64"),M=t=>Buffer.from(t,"base64").toString("binary");var rt="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",m=Array.prototype.slice.call(rt),b=(t=>{let e={};return t.forEach((r,s)=>e[r]=s),e})(m),st=/^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/,nt=t=>{let e,r,s,n,o="",a=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 TypeError("invalid character found");e=r<<16|s<<8|n,o+=m[e>>18&63]+m[e>>12&63]+m[e>>6&63]+m[e&63];}return a?o.slice(0,a-3)+"===".substring(a):o},ot=A?t=>O(t):d?t=>U(t):nt,at=t=>t.replace(/=/g,"").replace(/[+\/]/g,e=>e=="+"?"-":"_"),v=d?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(a=>o.push(a.valueOf())),r.push(h.apply(null,o));}return ot(r.join(""))},h=String.fromCharCode.bind(String),N=(t,e=!1)=>e?at(v(t)):v(t),P=t=>t.replace(/[^A-Za-z0-9\+\/]/g,""),it=t=>{if(t=t.replace(/\s+/g,""),!st.test(t))throw new TypeError("malformed base64.");t+="==".slice(2-(t.length&3));let e,r="",s,n;for(let o=0;o<t.length;)e=b[t.charAt(o++)]<<18|b[t.charAt(o++)]<<12|(s=b[t.charAt(o++)])<<6|(n=b[t.charAt(o++)]),r+=s===64?h(e>>16&255):n===64?h(e>>16&255,e>>8&255):h(e>>16&255,e>>8&255,e&255);return r},lt=C?t=>L(P(t)):d?t=>M(t):it,I=typeof Uint8Array.from=="function"?Uint8Array.from.bind(Uint8Array):t=>new Uint8Array(Array.prototype.slice.call(t,0)),ct=d?t=>I(k(t)):t=>I(lt(t).split("").map(e=>e.charCodeAt(0))),ut=t=>P(t.replace(/[-_]/g,e=>e=="-"?"+":"/")),Q=t=>ct(ut(t));var i=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";}},q=class extends i{constructor(e){super(e,"HRANA_PROTO_ERROR",new class extends Error{constructor(){super(e),this.name="ProtoError";}});}},c=class extends i{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;}});}},p=class extends i{constructor(e,r){super(e,"SERVER_ERROR",new class extends Error{constructor(){super(e);l(this,"status");this.status=r,this.name="HttpServerError";}});}},f=class extends i{constructor(e){super(e,"INTERNAL_ERROR",new class extends Error{constructor(){super(e),this.name="InternalError";}});}},y=class extends i{constructor(e){super(e,"UNKNOWN",new class extends Error{constructor(){super(e),this.name="MisuseError";}});}};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 f("Invalid type of input. Cannot build request to server.")}function S(t){if(typeof t!="string"){if(Object.prototype.toString.call(t.args)==="[object Array]")return {sql:t.sql,args:t.args.map(e=>V(e)),want_rows:t.want_rows};{let e=[],r=t.args;for(let s in r)e.push({name:s,value:V(r[s])});return {sql:t.sql,named_args:e,want_rows:t.want_rows}}}return {sql:t}}var w={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 D(t,e){return t.map((r,s)=>({stmt:S(r),condition:e[s]||void 0}))}function pt(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 ft(t){return [{stmt:{sql:"COMMIT"},condition:{type:"ok",step:t}},{stmt:{sql:"ROLLBACK"},condition:{type:"not",cond:{type:"ok",step:t+1}}}]}function j(t,e){let r=t.map((s,n)=>({stmt:S(s),condition:w.ok(n)}));return [pt(e)].concat(r).concat(ft(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 y('Invalid value for "intMode".')}}function mt(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 Q(t.base64);default:throw new q("Invalid data type from server. Cannot parse.")}}function g(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 a=0;a<t.rows[n].length;a++){let u=mt(t.rows[n][a],e);Object.defineProperty(o,a,{value:u});let R=t.cols[a].name;R!==void 0&&!Object.hasOwn(o,R)&&Object.defineProperty(o,R,{value:u,enumerable:!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 g(r,e);if(t.step_errors[s])throw new c(((n=t.step_errors[s])==null?void 0:n.message)||"",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)}async function F(t,e){let r=await libsqlExecute(t,S(e));if(r.isOk)return g(r.val,t.intMode);throw r.err.kind==="LIBSQL_SERVER_ERROR"?new p(r.err.server_message||"Server encountered error.",r.err.http_status_code):new c(r.err.data.message,r.err.data)}async function Pt(t,e,r){let s=await libsqlBatch(t,D(e,r));if(s.isOk)return _(s.val,t.intMode);throw s.err.kind==="LIBSQL_SERVER_ERROR"?new p(s.err.server_message||"Server encountered error.",s.err.http_status_code):new c(s.err.data.message,s.err.data)}async function G(t){return !!(await libsqlServerCompatCheck(t)).isOk}async function W(t,e,r="deferred"){let s=await libsqlBatch(t,j(e,r));if(s.isOk)return H(s.val,t.intMode);throw s.err.kind==="LIBSQL_SERVER_ERROR"?new p(s.err.server_message||"Server encountered error.",s.err.http_status_code):new c(s.err.data.message,s.err.data)}async function z(t,e){let r=e.split(";").filter(n=>n.trim()!=="").map((n,o)=>({stmt:{sql:n},condition:w.ok(o-1)}));r[0].condition=void 0;let s=await libsqlBatch(t,r);if(!s.isOk)throw s.err.kind==="LIBSQL_SERVER_ERROR"?new p(s.err.server_message||"Server encountered error.",s.err.http_status_code):new c(s.err.data.message,s.err.data)}var Z=typeof fetch=="function";var K=typeof URL=="function",J=t=>console.error(t),$=t=>new URL(t);function Y(t){if(!Z){if(t){globalThis.fetch=t;return}throw new i("No global fetch. Please provide one.","NO_GLOBAL_FETCH")}}function B(t){return J(t)}function X(t){if((()=>{if(K)try{return !!$(t)}catch(r){throw new i(r.message,"ERR_INVALID_URL",r)}else return !!(t.startsWith("https://")||t.startsWith("http://"))})())throw new i('This is a HTTP client and only supports "https:" and "http:" URLs.',"URL_SCHEME_NOT_SUPPORTED")}var E=class{constructor(e){l(this,"conf");l(this,"closed");l(this,"protocol");X(e.db_url),Y(e.fetch),this.conf=e,this.closed=!1,this.protocol="http";}async execute(e){return await F(this.conf,e)}async batch(e,r){return await W(this.conf,e,r)}async transaction(e){throw new f("'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(){B("'libsql-stateless' is remote only so nothing to sync.");}close(){B("'libsql-stateless' is stateless therefore no connection to close.");}async serverOk(){return await G(this.conf)}};function zt(t){return new E({db_url:t.url,authToken:t.authToken,intMode:t.intMode})}
var tt=Object.defineProperty;var et=(t,e,r)=>e in t?tt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var l=(t,e,r)=>(et(t,typeof e!="symbol"?e+"":e,r),r);var d=typeof Buffer=="function",A=typeof btoa=="function",C=typeof atob=="function",L=t=>atob(t),O=t=>btoa(t),T=t=>Buffer.from(t).toString("base64"),U=t=>Buffer.from(t,"binary").toString("base64"),k=t=>Buffer.from(t,"base64"),M=t=>Buffer.from(t,"base64").toString("binary");var rt="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",m=Array.prototype.slice.call(rt),b=(t=>{let e={};return t.forEach((r,s)=>e[r]=s),e})(m),st=/^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/,nt=t=>{let e,r,s,n,o="",a=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 TypeError("invalid character found");e=r<<16|s<<8|n,o+=m[e>>18&63]+m[e>>12&63]+m[e>>6&63]+m[e&63];}return a?o.slice(0,a-3)+"===".substring(a):o},ot=A?t=>O(t):d?t=>U(t):nt,at=t=>t.replace(/=/g,"").replace(/[+\/]/g,e=>e=="+"?"-":"_"),v=d?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(a=>o.push(a.valueOf())),r.push(h.apply(null,o));}return ot(r.join(""))},h=String.fromCharCode.bind(String),N=(t,e=!1)=>e?at(v(t)):v(t),P=t=>t.replace(/[^A-Za-z0-9\+\/]/g,""),it=t=>{if(t=t.replace(/\s+/g,""),!st.test(t))throw new TypeError("malformed base64.");t+="==".slice(2-(t.length&3));let e,r="",s,n;for(let o=0;o<t.length;)e=b[t.charAt(o++)]<<18|b[t.charAt(o++)]<<12|(s=b[t.charAt(o++)])<<6|(n=b[t.charAt(o++)]),r+=s===64?h(e>>16&255):n===64?h(e>>16&255,e>>8&255):h(e>>16&255,e>>8&255,e&255);return r},lt=C?t=>L(P(t)):d?t=>M(t):it,I=typeof Uint8Array.from=="function"?Uint8Array.from.bind(Uint8Array):t=>new Uint8Array(Array.prototype.slice.call(t,0)),ct=d?t=>I(k(t)):t=>I(lt(t).split("").map(e=>e.charCodeAt(0))),ut=t=>P(t.replace(/[-_]/g,e=>e=="-"?"+":"/")),Q=t=>ct(ut(t));var i=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";}},q=class extends i{constructor(e){super(e,"HRANA_PROTO_ERROR",new class extends Error{constructor(){super(e),this.name="ProtoError";}});}},c=class extends i{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;}});}},p=class extends i{constructor(e,r){super(e,"SERVER_ERROR",new class extends Error{constructor(){super(e);l(this,"status");this.status=r,this.name="HttpServerError";}});}},f=class extends i{constructor(e){super(e,"INTERNAL_ERROR",new class extends Error{constructor(){super(e),this.name="InternalError";}});}},y=class extends i{constructor(e){super(e,"UNKNOWN",new class extends Error{constructor(){super(e),this.name="MisuseError";}});}};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 f("Invalid type of input. Cannot build request to server.")}function S(t){if(typeof t!="string"){if(Object.prototype.toString.call(t.args)==="[object Array]")return {sql:t.sql,args:t.args.map(e=>V(e)),want_rows:t.want_rows};{let e=[],r=t.args;for(let s in r)e.push({name:s,value:V(r[s])});return {sql:t.sql,named_args:e,want_rows:t.want_rows}}}return {sql:t}}var w={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 D(t,e){return t.map((r,s)=>({stmt:S(r),condition:e[s]||void 0}))}function pt(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 ft(t){return [{stmt:{sql:"COMMIT"},condition:{type:"ok",step:t}},{stmt:{sql:"ROLLBACK"},condition:{type:"not",cond:{type:"ok",step:t+1}}}]}function j(t,e){let r=t.map((s,n)=>({stmt:S(s),condition:w.ok(n)}));return [pt(e)].concat(r).concat(ft(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 y('Invalid value for "intMode".')}}function mt(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 Q(t.base64);default:throw new q("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 a=0;a<t.rows[n].length;a++){let u=mt(t.rows[n][a],e);Object.defineProperty(o,a,{value:u});let R=t.cols[a].name;R!==void 0&&!Object.hasOwn(o,R)&&Object.defineProperty(o,R,{value:u,enumerable:!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 g(t,e){return t.step_results.map((r,s)=>{var n;if(r)return _(r,e);if(t.step_errors[s])throw new c(((n=t.step_errors[s])==null?void 0:n.message)||"",t.step_errors[s]);return null})}function H(t,e){let r=g(t,e);return r.slice(1,r.length-2).filter(s=>s!==null)}async function F(t,e){let r=await libsqlExecute(t,S(e));if(r.isOk)return _(r.val,t.intMode);throw r.err.kind==="LIBSQL_SERVER_ERROR"?new p(r.err.server_message||"Server encountered error.",r.err.http_status_code):new c(r.err.data.message,r.err.data)}async function Pt(t,e,r){let s=await libsqlBatch(t,D(e,r));if(s.isOk)return g(s.val,t.intMode);throw s.err.kind==="LIBSQL_SERVER_ERROR"?new p(s.err.server_message||"Server encountered error.",s.err.http_status_code):new c(s.err.data.message,s.err.data)}async function G(t){return !!(await libsqlServerCompatCheck(t)).isOk}async function W(t,e,r="deferred"){let s=await libsqlBatch(t,j(e,r));if(s.isOk)return H(s.val,t.intMode);throw s.err.kind==="LIBSQL_SERVER_ERROR"?new p(s.err.server_message||"Server encountered error.",s.err.http_status_code):new c(s.err.data.message,s.err.data)}async function z(t,e){let r=e.split(";").filter(n=>n.trim()!=="").map((n,o)=>({stmt:{sql:n},condition:w.ok(o-1)}));r[0].condition=void 0;let s=await libsqlBatch(t,r);if(!s.isOk)throw s.err.kind==="LIBSQL_SERVER_ERROR"?new p(s.err.server_message||"Server encountered error.",s.err.http_status_code):new c(s.err.data.message,s.err.data)}var Z=typeof fetch=="function";var K=typeof URL=="function",J=t=>console.error(t),$=t=>new URL(t);function Y(t){if(!Z){if(t){globalThis.fetch=t;return}throw new i("No global fetch. Please provide one.","NO_GLOBAL_FETCH")}}function B(t){return J(t)}function X(t){if((()=>{if(K)try{return !$(t)}catch(r){throw new i(r.message,"ERR_INVALID_URL",r)}else return !(t.startsWith("https://")||t.startsWith("http://"))})())throw new i('This is a HTTP client and only supports "https:" and "http:" URLs.',"URL_SCHEME_NOT_SUPPORTED")}var E=class{constructor(e){l(this,"conf");l(this,"closed");l(this,"protocol");X(e.db_url),Y(e.fetch),this.conf=e,this.closed=!1,this.protocol="http";}async execute(e){return await F(this.conf,e)}async batch(e,r){return await W(this.conf,e,r)}async transaction(e){throw new f("'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(){B("'libsql-stateless' is remote only so nothing to sync.");}close(){B("'libsql-stateless' is stateless therefore no connection to close.");}async serverOk(){return await G(this.conf)}};function zt(t){return new E({db_url:t.url,authToken:t.authToken,intMode:t.intMode})}
export { p as HttpServerError, f as InternalError, i as LibsqlError, y as MisuseError, q as ProtoError, c as ResponseError, zt as createClient, Pt as libsqlBatch, w as libsqlBatchReqStepExecCondBuilder, D as libsqlBatchReqStepsBuilder, _ as libsqlBatchStreamResParser, W as libsqlBatchTransaction, F as libsqlExecute, z as libsqlExecuteMultiple, G as libsqlServerCompatCheck, S as libsqlStatementBuilder, g as libsqlStatementResParser, j as libsqlTransactionBatchReqStepsBuilder, H as libsqlTransactionBatchStreamResParser, pt as libsqlTransactionBeginStatement, ft as libsqlTransactionEndStatements, V as libsqlValueBuilder, mt as libsqlValueParser };
export { p as HttpServerError, f as InternalError, i as LibsqlError, y as MisuseError, q as ProtoError, c as ResponseError, zt as createClient, Pt as libsqlBatch, w as libsqlBatchReqStepExecCondBuilder, D as libsqlBatchReqStepsBuilder, g as libsqlBatchStreamResParser, W as libsqlBatchTransaction, F as libsqlExecute, z as libsqlExecuteMultiple, G as libsqlServerCompatCheck, S as libsqlStatementBuilder, _ as libsqlStatementResParser, j as libsqlTransactionBatchReqStepsBuilder, H as libsqlTransactionBatchStreamResParser, pt as libsqlTransactionBeginStatement, ft as libsqlTransactionEndStatements, V as libsqlValueBuilder, mt as libsqlValueParser };
{
"name": "libsql-stateless-easy",
"version": "1.6.2-alpha.1",
"version": "1.6.2-alpha.2",
"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",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc