@lunora/bindings 1.0.0-alpha.36 → 1.0.0-alpha.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/packem_shared/{R2SqlError-D51drQVA.mjs → R2SqlError-CJ_zgztT.mjs} +1 -1
- package/dist/packem_shared/{SelectBuilder-C3dn71re.mjs → SelectBuilder-Dnqem9T0.mjs} +1 -1
- package/dist/packem_shared/{SetOperation-DwBivS9U.mjs → SetOperation-kiI5Wnlm.mjs} +1 -1
- package/dist/packem_shared/Sql-BfnxRway.mjs +1 -0
- package/dist/packem_shared/{WindowExpression-D2wkQ8zz.mjs → WindowExpression-VX7EEV3h.mjs} +1 -1
- package/dist/packem_shared/{WindowFunction-BAPoVyhc.mjs → WindowFunction-CL4jYy2l.mjs} +1 -1
- package/dist/packem_shared/{asc-DQLvku7R.mjs → asc-DP_WFiAE.mjs} +1 -1
- package/dist/r2sql/index.d.mts +1 -1
- package/dist/r2sql/index.d.ts +1 -1
- package/dist/r2sql/index.mjs +1 -1
- package/package.json +1 -1
- package/dist/packem_shared/Sql-CJr-IlfQ.mjs +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{LunoraError as b}from"@lunora/errors";import f from"./SelectBuilder-
|
|
1
|
+
import{LunoraError as b}from"@lunora/errors";import f from"./SelectBuilder-Dnqem9T0.mjs";import{ident as m,toText as h}from"./Sql-BfnxRway.mjs";const R="https://api.sql.cloudflarestorage.com/api/v1/accounts",T=6e4,$=e=>e[0]===void 0?[]:Object.keys(e[0]).map(s=>({name:s}));class c extends b{constructor(s,l){super("R2_SQL_ERROR",`R2 SQL query failed (${String(s)}): ${l}`,{name:"R2SqlError",status:s})}}const O=e=>{const s=e.fetch??globalThis.fetch,S=`${e.endpoint??R}/${encodeURIComponent(e.accountId)}/r2-sql/query/${encodeURIComponent(e.bucket)}`,w=`${e.accountId}_${e.bucket}`,u=e.timeoutMs??T,n=async t=>{const a=new AbortController,y=setTimeout(()=>{a.abort()},u);try{const r=await s(S,{body:JSON.stringify({query:t,warehouse:w}),headers:{Authorization:`Bearer ${e.apiToken}`,"Content-Type":"application/json"},method:"POST",signal:a.signal});if(!r.ok)throw new c(r.status,await r.text().catch(()=>"<error body unavailable: the request deadline fired before it was read>"));let d;try{d=await r.json()}catch(p){throw a.signal.aborted?p:new c(r.status,"R2 SQL returned a non-JSON body.")}const o=d;if(o.success===!1||o.errors!==void 0&&o.errors.length>0)throw new c(r.status,JSON.stringify(o.errors??o));const i=o.result?.rows??[];return{columns:o.result?.schema??$(i),rowCount:i.length,rows:i}}catch(r){throw a.signal.aborted&&!(r instanceof c)?new c(504,`query timed out after ${String(u)}ms (R2SqlConfig.timeoutMs)`):r}finally{clearTimeout(y)}};return{describe:async t=>n(`DESCRIBE ${m(t)}`),explain:async(t,a)=>n(`EXPLAIN ${a?.format==="json"?"FORMAT JSON ":""}${h(t)}`),from:t=>new f(n,t),query:async t=>n(h(t)),showDatabases:async()=>n("SHOW DATABASES"),showTables:async t=>n(`SHOW TABLES IN ${m(t)}`)}};export{c as R2SqlError,O as createR2Sql};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{renderOrderTerm as o}from"./asc-
|
|
1
|
+
import{renderOrderTerm as o}from"./asc-DP_WFiAE.mjs";import h from"./SetOperation-kiI5Wnlm.mjs";import{tableRef as s,toText as e,assertLimit as u,lit as l}from"./Sql-BfnxRway.mjs";const n={cross:"CROSS JOIN",full:"FULL OUTER JOIN",inner:"INNER JOIN",left:"LEFT JOIN",right:"RIGHT JOIN"};class I{exec;table;selectItems=[];distinctFlag=!1;distinctOnItems=[];joins=[];whereConditions=[];groupByItems=[];havingConditions=[];qualifyCondition;orderByItems=[];limitValue;constructor(t,i){this.exec=t,this.table=s(i)}select(...t){return this.selectItems.push(...t.map(i=>e(i))),this}distinct(){return this.distinctFlag=!0,this}distinctOn(...t){return this.distinctOnItems.push(...t.map(i=>e(i))),this}innerJoin(t,i){return this.addJoin("inner",t,i)}leftJoin(t,i){return this.addJoin("left",t,i)}rightJoin(t,i){return this.addJoin("right",t,i)}fullJoin(t,i){return this.addJoin("full",t,i)}crossJoin(t){return this.addJoin("cross",t)}where(...t){return this.whereConditions.push(...t.map(i=>e(i))),this}groupBy(...t){return this.groupByItems.push(...t.map(i=>e(i))),this}having(...t){return this.havingConditions.push(...t.map(i=>e(i))),this}qualify(t){return this.qualifyCondition=e(t),this}orderBy(...t){return this.orderByItems.push(...t.map(i=>o(i))),this}limit(t){return u(t),this.limitValue=t,this}returns(){return this}union(t){return this.setOperation("UNION",t)}unionAll(t){return this.setOperation("UNION ALL",t)}intersect(t){return this.setOperation("INTERSECT",t)}except(t){return this.setOperation("EXCEPT",t)}get needsWrapForSetOperation(){return this.orderByItems.length>0||this.limitValue!==void 0}toSQL(){const t=[`${this.renderHead()} ${this.selectItems.length>0?this.selectItems.join(", "):"*"}`,`FROM ${this.table}`];for(const i of this.joins)t.push(i.on===void 0?`${n[i.kind]} ${i.table}`:`${n[i.kind]} ${i.table} ON ${e(i.on)}`);return this.whereConditions.length>0&&t.push(`WHERE ${this.whereConditions.join(" AND ")}`),this.groupByItems.length>0&&t.push(`GROUP BY ${this.groupByItems.join(", ")}`),this.havingConditions.length>0&&t.push(`HAVING ${this.havingConditions.join(" AND ")}`),this.qualifyCondition!==void 0&&t.push(`QUALIFY ${this.qualifyCondition}`),this.orderByItems.length>0&&t.push(`ORDER BY ${this.orderByItems.join(", ")}`),this.limitValue!==void 0&&t.push(`LIMIT ${l(this.limitValue)}`),t.join(" ")}async run(){return this.exec(this.toSQL())}renderHead(){return this.distinctOnItems.length>0?`SELECT DISTINCT ON (${this.distinctOnItems.join(", ")})`:this.distinctFlag?"SELECT DISTINCT":"SELECT"}addJoin(t,i,r){return this.joins.push({kind:t,on:r,table:s(i)}),this}setOperation(t,i){return new h(this.exec,[{query:this},{operator:t,query:i}])}}export{I as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{renderOrderTerm as o}from"./asc-
|
|
1
|
+
import{renderOrderTerm as o}from"./asc-DP_WFiAE.mjs";import{assertLimit as u,lit as a}from"./Sql-BfnxRway.mjs";const h=s=>{const t=s.toSQL();return s.needsWrapForSetOperation===!0?`(${t})`:t};class p{needsWrapForSetOperation=!0;exec;members;orderByItems=[];limitValue;constructor(t,r){this.exec=t,this.members=r}union(t){return this.add("UNION",t)}unionAll(t){return this.add("UNION ALL",t)}intersect(t){return this.add("INTERSECT",t)}except(t){return this.add("EXCEPT",t)}orderBy(...t){return this.orderByItems.push(...t.map(r=>o(r))),this}limit(t){return u(t),this.limitValue=t,this}returns(){return this}toSQL(){const r=this.members.map(i=>{const n=h(i.query);return i.operator===void 0?n:`${i.operator} ${n}`}).join(" "),e=[];return this.orderByItems.length>0&&e.push(`ORDER BY ${this.orderByItems.join(", ")}`),this.limitValue!==void 0&&e.push(`LIMIT ${a(this.limitValue)}`),e.length>0?`${r} ${e.join(" ")}`:r}async run(){return this.exec(this.toSQL())}add(t,r){return this.members.push({operator:t,query:r}),this}}export{p as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const o=t=>`'${t.replaceAll("'","''")}'`,c=/^\w+(?:\.\w+)*$/,p=/^\w+(?:\.\w+)*(?:\s+(?:as\s+)?\w+)?$/i;class n{text;constructor(r){this.text=r}toString(){return this.text}}const s=t=>t instanceof n,l=t=>new n(t),w=t=>s(t)?t.text:t,y=t=>{if(typeof t!="string"||!c.test(t))throw new TypeError(`r2sql: invalid identifier ${JSON.stringify(t)} — expected dotted [A-Za-z0-9_] segments (e.g. "namespace.table").`);return t},g=t=>{if(typeof t!="string"||!p.test(t))throw new TypeError(`r2sql: invalid table reference ${JSON.stringify(t)} — expected "namespace.table" with an optional "[AS] alias".`);return t},a=t=>{if(t==null)return"NULL";if(typeof t=="boolean")return t?"true":"false";if(typeof t=="bigint")return t.toString();if(typeof t=="number"){if(!Number.isFinite(t))throw new TypeError(`r2sql: cannot inline a non-finite number (${String(t)}) as a SQL literal.`);return String(t)}if(typeof t=="string")return o(t);if(t instanceof Date){if(Number.isNaN(t.getTime()))throw new TypeError("r2sql: cannot inline an invalid Date — it has no RFC3339 form. Check the value parsed before building the query.");return o(t.toISOString())}if(Array.isArray(t)){if(t.length===0)throw new TypeError("r2sql: cannot inline an empty array — `IN ()` is not valid SQL. Guard the empty case before building the query.");return`(${t.map(r=>a(r)).join(", ")})`}throw new TypeError(`r2sql: cannot inline a value of type ${typeof t} as a SQL literal. Wrap trusted SQL with raw(), or pass a primitive/Date/array.`)},S=(t,...r)=>{let e=t[0]??"";for(const[f,i]of r.entries())e+=s(i)?i.text:a(i),e+=t[f+1]??"";return new n(e)},d=(t,r)=>new n(t.map(e=>w(e)).join(r)),h=t=>{if(!Number.isInteger(t)||t<1||t>1e4)throw new RangeError(`r2sql: limit must be an integer between 1 and ${String(1e4)} (got ${String(t)}).`)};export{n as Sql,h as assertLimit,y as ident,s as isSql,d as joinSql,a as lit,l as raw,S as sql,g as tableRef,w as toText};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Sql as r,lit as i}from"./Sql-
|
|
1
|
+
import{Sql as r,lit as i}from"./Sql-BfnxRway.mjs";const n=/^[A-Z_][\w$]*$/i,o=t=>{if(!n.test(t))throw new TypeError(`r2sql: invalid identifier ${JSON.stringify(t)} — expected a simple SQL name (letters, digits, underscore).`);return t};class p extends r{as(e){return new r(`${this.text} AS ${o(e)}`)}between(e,s){return new r(`${this.text} BETWEEN ${i(e)} AND ${i(s)}`)}eq(e){return this.compare("=",e)}gt(e){return this.compare(">",e)}gte(e){return this.compare(">=",e)}lt(e){return this.compare("<",e)}lte(e){return this.compare("<=",e)}compare(e,s){return new r(`${this.text} ${e} ${i(s)}`)}}export{p as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{renderOrderTerm as $}from"./asc-
|
|
1
|
+
import{renderOrderTerm as $}from"./asc-DP_WFiAE.mjs";import{toText as o,lit as s}from"./Sql-BfnxRway.mjs";import A from"./WindowExpression-VX7EEV3h.mjs";const u=r=>r===void 0?[]:Array.isArray(r)?r:[r],c=r=>{const t=[],i=u(r.partitionBy).map(a=>o(a));i.length>0&&t.push(`PARTITION BY ${i.join(", ")}`);const e=u(r.orderBy).map(a=>$(a));return e.length>0&&t.push(`ORDER BY ${e.join(", ")}`),r.frame!==void 0&&r.frame.length>0&&t.push(r.frame),`OVER (${t.join(" ")})`},m=(r,t,i)=>{const e=[o(r)];return t!==void 0&&e.push(s(t)),i!==void 0&&e.push(s(i)),e.join(", ")};class d{callText;constructor(t){this.callText=t}over(t={}){return new A(`${this.callText} ${c(t)}`)}}const n=r=>new d(r),l={avg:r=>n(`AVG(${o(r)})`),count:r=>n(`COUNT(${r===void 0?"*":o(r)})`),cumeDist:()=>n("CUME_DIST()"),denseRank:()=>n("DENSE_RANK()"),firstValue:r=>n(`FIRST_VALUE(${o(r)})`),lag:(r,t,i)=>n(`LAG(${m(r,t,i)})`),lastValue:r=>n(`LAST_VALUE(${o(r)})`),lead:(r,t,i)=>n(`LEAD(${m(r,t,i)})`),max:r=>n(`MAX(${o(r)})`),min:r=>n(`MIN(${o(r)})`),nthValue:(r,t)=>n(`NTH_VALUE(${o(r)}, ${s(t)})`),ntile:r=>n(`NTILE(${s(r)})`),percentRank:()=>n("PERCENT_RANK()"),rank:()=>n("RANK()"),rowNumber:()=>n("ROW_NUMBER()"),sum:r=>n(`SUM(${o(r)})`)};export{d as WindowFunction,l as fn};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Sql as e,toText as n}from"./Sql-
|
|
1
|
+
import{Sql as e,toText as n}from"./Sql-BfnxRway.mjs";const o=r=>({dir:"ASC",expr:r}),i=r=>({dir:"DESC",expr:r}),s=r=>typeof r=="string"||r instanceof e?n(r):`${n(r.expr)} ${r.dir}`;export{o as asc,i as desc,s as renderOrderTerm};
|
package/dist/r2sql/index.d.mts
CHANGED
|
@@ -24,7 +24,7 @@ declare const toText: (value: Sql | string) => string;
|
|
|
24
24
|
* - `null` / `undefined` → `NULL`
|
|
25
25
|
* - `boolean` → `true` / `false`
|
|
26
26
|
* - finite `number` / `bigint` → the numeric text (non-finite throws — `NaN`/`Infinity` have no SQL literal)
|
|
27
|
-
* - `Date` → an RFC3339 string literal (R2 SQL's `timestamp` form)
|
|
27
|
+
* - `Date` → an RFC3339 string literal (R2 SQL's `timestamp` form; an invalid `Date` throws)
|
|
28
28
|
* - `string` → a single-quoted, escaped literal
|
|
29
29
|
* - `Array` → a parenthesised, comma-separated list of literals (for `IN (...)`)
|
|
30
30
|
*
|
package/dist/r2sql/index.d.ts
CHANGED
|
@@ -24,7 +24,7 @@ declare const toText: (value: Sql | string) => string;
|
|
|
24
24
|
* - `null` / `undefined` → `NULL`
|
|
25
25
|
* - `boolean` → `true` / `false`
|
|
26
26
|
* - finite `number` / `bigint` → the numeric text (non-finite throws — `NaN`/`Infinity` have no SQL literal)
|
|
27
|
-
* - `Date` → an RFC3339 string literal (R2 SQL's `timestamp` form)
|
|
27
|
+
* - `Date` → an RFC3339 string literal (R2 SQL's `timestamp` form; an invalid `Date` throws)
|
|
28
28
|
* - `string` → a single-quoted, escaped literal
|
|
29
29
|
* - `Array` → a parenthesised, comma-separated list of literals (for `IN (...)`)
|
|
30
30
|
*
|
package/dist/r2sql/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{default as o}from"../packem_shared/SelectBuilder-
|
|
1
|
+
import{default as o}from"../packem_shared/SelectBuilder-Dnqem9T0.mjs";import{R2SqlError as l,createR2Sql as f}from"../packem_shared/R2SqlError-CJ_zgztT.mjs";import{asc as d,desc as i,renderOrderTerm as n}from"../packem_shared/asc-DP_WFiAE.mjs";import{default as s}from"../packem_shared/SetOperation-kiI5Wnlm.mjs";import{Sql as m,isSql as S,joinSql as q,lit as c,raw as u,sql as w,toText as E}from"../packem_shared/Sql-BfnxRway.mjs";import{WindowFunction as R,fn as T}from"../packem_shared/WindowFunction-CL4jYy2l.mjs";import{default as j}from"../packem_shared/WindowExpression-VX7EEV3h.mjs";export{l as R2SqlError,o as SelectBuilder,s as SetOperation,m as Sql,j as WindowExpression,R as WindowFunction,d as asc,f as createR2Sql,i as desc,T as fn,S as isSql,q as joinSql,c as lit,u as raw,n as renderOrderTerm,w as sql,E as toText};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lunora/bindings",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.37",
|
|
4
4
|
"description": "Lightweight Cloudflare binding helpers for Lunora — ctx.kv, ctx.images, ctx.analytics, ctx.pipelines, ctx.vectors, ctx.r2sql — one install, per-binding subpaths",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"analytics",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
const o=t=>`'${t.replaceAll("'","''")}'`,f=/^\w+(?:\.\w+)*$/,p=/^\w+(?:\.\w+)*(?:\s+(?:as\s+)?\w+)?$/i;class n{text;constructor(r){this.text=r}toString(){return this.text}}const s=t=>t instanceof n,l=t=>new n(t),w=t=>s(t)?t.text:t,y=t=>{if(typeof t!="string"||!f.test(t))throw new TypeError(`r2sql: invalid identifier ${JSON.stringify(t)} — expected dotted [A-Za-z0-9_] segments (e.g. "namespace.table").`);return t},g=t=>{if(typeof t!="string"||!p.test(t))throw new TypeError(`r2sql: invalid table reference ${JSON.stringify(t)} — expected "namespace.table" with an optional "[AS] alias".`);return t},a=t=>{if(t==null)return"NULL";if(typeof t=="boolean")return t?"true":"false";if(typeof t=="bigint")return t.toString();if(typeof t=="number"){if(!Number.isFinite(t))throw new TypeError(`r2sql: cannot inline a non-finite number (${String(t)}) as a SQL literal.`);return String(t)}if(typeof t=="string")return o(t);if(t instanceof Date)return o(t.toISOString());if(Array.isArray(t)){if(t.length===0)throw new TypeError("r2sql: cannot inline an empty array — `IN ()` is not valid SQL. Guard the empty case before building the query.");return`(${t.map(r=>a(r)).join(", ")})`}throw new TypeError(`r2sql: cannot inline a value of type ${typeof t} as a SQL literal. Wrap trusted SQL with raw(), or pass a primitive/Date/array.`)},S=(t,...r)=>{let e=t[0]??"";for(const[c,i]of r.entries())e+=s(i)?i.text:a(i),e+=t[c+1]??"";return new n(e)},d=(t,r)=>new n(t.map(e=>w(e)).join(r)),b=t=>{if(!Number.isInteger(t)||t<1||t>1e4)throw new RangeError(`r2sql: limit must be an integer between 1 and ${String(1e4)} (got ${String(t)}).`)};export{n as Sql,b as assertLimit,y as ident,s as isSql,d as joinSql,a as lit,l as raw,S as sql,g as tableRef,w as toText};
|