@lunora/bindings 1.0.0-alpha.35 → 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/images/index.mjs +1 -1
- 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/packem_shared/buildSignedImageUrl-C-LlaNdt.mjs +4 -0
- 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 +2 -2
- package/dist/packem_shared/Sql-CJr-IlfQ.mjs +0 -1
- package/dist/packem_shared/buildSignedImageUrl-DHlSjlqb.mjs +0 -4
package/dist/images/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createImages as m}from"../packem_shared/createImages-CHgMZP4g.mjs";import{buildImageDeliveryUrl as g}from"../packem_shared/buildImageDeliveryUrl-Brqs-dcZ.mjs";import{buildSignedImageUrl as o,parseSignedTransform as l,verifySignedImageUrl as d}from"../packem_shared/buildSignedImageUrl-
|
|
1
|
+
import{createImages as m}from"../packem_shared/createImages-CHgMZP4g.mjs";import{buildImageDeliveryUrl as g}from"../packem_shared/buildImageDeliveryUrl-Brqs-dcZ.mjs";import{buildSignedImageUrl as o,parseSignedTransform as l,verifySignedImageUrl as d}from"../packem_shared/buildSignedImageUrl-C-LlaNdt.mjs";export{g as buildImageDeliveryUrl,o as buildSignedImageUrl,m as createImages,l as parseSignedTransform,d as verifySignedImageUrl};
|
|
@@ -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};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
const v=(e,t)=>{if(e.size<t)return;const n=e.keys().next().value;n!==void 0&&e.delete(n)},E=(e,t,n,r)=>{const s=e.get(t);if(s!==void 0)return s;v(e,r);const o=n().catch(a=>{throw e.get(t)===o&&e.delete(t),a});return e.set(t,o),o},f=new TextEncoder,$=10080*60,R=/^[a-z][a-z0-9+\-.]*:\/\//i,_=Array.from({length:32},(e,t)=>t),C=new RegExp(`[${_.map(e=>String.fromCodePoint(e)).join("")}]`,"u"),x=e=>{const t=String.fromCodePoint(...e);return btoa(t).replaceAll("+","-").replaceAll("/","_").replaceAll("=","")},A=e=>{const t=e.replaceAll("-","+").replaceAll("_","/")+"===".slice((e.length+3)%4),n=atob(t),r=new Uint8Array(n.length);for(let s=0;s<n.length;s+=1)r[s]=n.codePointAt(s)??0;return r},N=64,T=new Map,g=async e=>E(T,e,async()=>crypto.subtle.importKey("raw",f.encode(e),{hash:"SHA-256",name:"HMAC"},!1,["sign","verify"]),N),h=e=>{try{return new URL(e).host}catch{return e.replace(R,"").split("/")[0]??""}},y=e=>{if(C.test(e))throw new TypeError("hmac-url: value must not contain control characters (including CR/LF)")},U=/^\/+$/u,O=e=>U.test(e),L=(e,t)=>{if(!Number.isFinite(e)||e<=0)return"expiresInSeconds must be a positive finite number";if(e>t){const n=` (${String(t/86400)} days)`;return`expiresInSeconds must not exceed ${String(t)} seconds${n}`}},I=async(e,t)=>{const n=await g(e),r=await crypto.subtle.sign("HMAC",n,f.encode(t));return x(new Uint8Array(r))},H=async(e,t,n)=>{const r=await g(e);return crypto.subtle.verify("HMAC",r,n,f.encode(t))},p=/^\//,K=e=>{let t=e.length;for(;t>0&&e[t-1]==="/";)t-=1;return e.slice(0,t)},P=e=>e===void 0?"":Object.entries(e).filter(([,t])=>t!==void 0).toSorted(([t],[n])=>(t>n?1:0)-(t<n?1:0)).map(([t,n])=>`${t}=${typeof n=="object"?JSON.stringify(n):String(n)}`).join("&"),M={background:"string",blur:"number",brightness:"number",contrast:"number",draw:"json",fit:"string",flip:"string",gamma:"number",gravity:"string-or-json",height:"number",rotate:"number",saturation:"number",segment:"string",sharpen:"number",upscale:"string",width:"number"},b=new Map(Object.entries(M)),j=e=>{const t=[];for(const n of e.split("&")){const r=n.indexOf("="),s=r!==-1&&b.has(n.slice(0,r)),o=t.at(-1);s||o===void 0?t.push(n):t[t.length-1]=`${o}&${n}`}return t},D=(e,t,n)=>{if(t==="string"||t==="string-or-json"&&!n.startsWith("{"))return n;if(t==="number"){const r=Number(n);if(n===""||!Number.isFinite(r))throw new TypeError(`@lunora/bindings/images: transform key "${e}" expects a number, got "${n}"`);return r}try{return JSON.parse(n)}catch{throw new TypeError(`@lunora/bindings/images: transform key "${e}" carries malformed JSON`)}},w=(e,t,n,r)=>`${e.toLowerCase()}
|
|
2
|
+
${t}
|
|
3
|
+
${String(n)}
|
|
4
|
+
${r}`,k=e=>e.split("/").map(t=>encodeURIComponent(t)).join("/"),z=e=>{if(e==="")return{};const t={};for(const n of j(e)){const r=n.indexOf("=");if(r===-1)throw new TypeError(`@lunora/bindings/images: malformed transform segment "${n}" — expected key=value`);const s=n.slice(0,r),o=b.get(s);if(o===void 0)throw new TypeError(`@lunora/bindings/images: unknown transform key "${s}" — the serialized transform does not match this version's TransformOptions`);t[s]=D(s,o,n.slice(r+1))}return t},F=async e=>{const t=e.expiresInSeconds??3600,n=L(t,$);if(n!==void 0)throw new TypeError(`@lunora/bindings/images: ${n}`);let r="";try{r=new URL(e.baseUrl).pathname}catch{}if(r!==""&&!O(r))throw new TypeError(`@lunora/bindings/images: baseUrl must not carry a path ("${r}") — the key is verified from the full URL pathname, so a subpath base would make every signed URL fail verification`);const s=Math.floor(Date.now()/1e3)+t,o=h(e.baseUrl),a=P(e.transform),i=e.key.replace(p,"");y(i);const c=await I(e.secret,w(o,i,s,a)),l=K(e.baseUrl),m=k(i),u=a===""?"":`&t=${encodeURIComponent(a)}`;return`${l}/${m}?exp=${String(s)}&sig=${c}${u}`},Y=async(e,t,n)=>{let r;try{r=e instanceof URL?e:new URL(e)}catch{return{reason:"malformed",valid:!1}}const s=r.searchParams.get("exp"),o=s===null?Number.NaN:Number(s),a=r.searchParams.get("sig"),i=r.searchParams.get("t")??"";if(!a||!Number.isInteger(o))return{reason:"malformed",valid:!1};if(o<Math.floor(Date.now()/1e3))return{reason:"expired",valid:!1};let c,l;try{c=r.pathname.replace(p,"").split("/").map(S=>decodeURIComponent(S)).join("/"),y(c),l=A(a)}catch{return{reason:"malformed",valid:!1}}const m=n?.expectedHost===void 0?r.host:h(n.expectedHost);if(!await H(t,w(m,c,o,i),l))return{reason:"bad_signature",valid:!1};if(i==="")return{key:c,valid:!0};let d;try{d=z(i)}catch{d=void 0}return{key:c,transform:i,transformOptions:d,valid:!0}};export{F as buildSignedImageUrl,z as parseSignedTransform,Y as verifySignedImageUrl};
|
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",
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
67
|
"@lunora/errors": "1.0.0-alpha.22",
|
|
68
|
-
"@lunora/platform": "1.0.0-alpha.
|
|
68
|
+
"@lunora/platform": "1.0.0-alpha.17"
|
|
69
69
|
},
|
|
70
70
|
"engines": {
|
|
71
71
|
"node": "^22.15.0 || >=24.11.0"
|
|
@@ -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};
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
const E=(e,t)=>{if(e.size<t)return;const n=e.keys().next().value;n!==void 0&&e.delete(n)},f=new TextEncoder,$=10080*60,R=/^[a-z][a-z0-9+\-.]*:\/\//i,_=Array.from({length:32},(e,t)=>t),C=new RegExp(`[${_.map(e=>String.fromCodePoint(e)).join("")}]`,"u"),x=e=>{const t=String.fromCodePoint(...e);return btoa(t).replaceAll("+","-").replaceAll("/","_").replaceAll("=","")},A=e=>{const t=e.replaceAll("-","+").replaceAll("_","/")+"===".slice((e.length+3)%4),n=atob(t),r=new Uint8Array(n.length);for(let s=0;s<n.length;s+=1)r[s]=n.codePointAt(s)??0;return r},N=64,u=new Map,y=async e=>{const t=u.get(e);if(t)return t;E(u,N);const n=crypto.subtle.importKey("raw",f.encode(e),{hash:"SHA-256",name:"HMAC"},!1,["sign","verify"]);return u.set(e,n),n},h=e=>{try{return new URL(e).host}catch{return e.replace(R,"").split("/")[0]??""}},p=e=>{if(C.test(e))throw new TypeError("hmac-url: value must not contain control characters (including CR/LF)")},T=/^\/+$/u,U=e=>T.test(e),O=(e,t)=>{if(!Number.isFinite(e)||e<=0)return"expiresInSeconds must be a positive finite number";if(e>t){const n=` (${String(t/86400)} days)`;return`expiresInSeconds must not exceed ${String(t)} seconds${n}`}},L=async(e,t)=>{const n=await y(e),r=await crypto.subtle.sign("HMAC",n,f.encode(t));return x(new Uint8Array(r))},I=async(e,t,n)=>{const r=await y(e);return crypto.subtle.verify("HMAC",r,n,f.encode(t))},b=/^\//,H=e=>{let t=e.length;for(;t>0&&e[t-1]==="/";)t-=1;return e.slice(0,t)},K=e=>e===void 0?"":Object.entries(e).filter(([,t])=>t!==void 0).toSorted(([t],[n])=>(t>n?1:0)-(t<n?1:0)).map(([t,n])=>`${t}=${typeof n=="object"?JSON.stringify(n):String(n)}`).join("&"),k={background:"string",blur:"number",brightness:"number",contrast:"number",draw:"json",fit:"string",flip:"string",gamma:"number",gravity:"string-or-json",height:"number",rotate:"number",saturation:"number",segment:"string",sharpen:"number",upscale:"string",width:"number"},S=new Map(Object.entries(k)),P=e=>{const t=[];for(const n of e.split("&")){const r=n.indexOf("="),s=r!==-1&&S.has(n.slice(0,r)),o=t.at(-1);s||o===void 0?t.push(n):t[t.length-1]=`${o}&${n}`}return t},M=(e,t,n)=>{if(t==="string"||t==="string-or-json"&&!n.startsWith("{"))return n;if(t==="number"){const r=Number(n);if(n===""||!Number.isFinite(r))throw new TypeError(`@lunora/bindings/images: transform key "${e}" expects a number, got "${n}"`);return r}try{return JSON.parse(n)}catch{throw new TypeError(`@lunora/bindings/images: transform key "${e}" carries malformed JSON`)}},w=(e,t,n,r)=>`${e.toLowerCase()}
|
|
2
|
-
${t}
|
|
3
|
-
${String(n)}
|
|
4
|
-
${r}`,j=e=>e.split("/").map(t=>encodeURIComponent(t)).join("/"),D=e=>{if(e==="")return{};const t={};for(const n of P(e)){const r=n.indexOf("=");if(r===-1)throw new TypeError(`@lunora/bindings/images: malformed transform segment "${n}" — expected key=value`);const s=n.slice(0,r),o=S.get(s);if(o===void 0)throw new TypeError(`@lunora/bindings/images: unknown transform key "${s}" — the serialized transform does not match this version's TransformOptions`);t[s]=M(s,o,n.slice(r+1))}return t},z=async e=>{const t=e.expiresInSeconds??3600,n=O(t,$);if(n!==void 0)throw new TypeError(`@lunora/bindings/images: ${n}`);let r="";try{r=new URL(e.baseUrl).pathname}catch{}if(r!==""&&!U(r))throw new TypeError(`@lunora/bindings/images: baseUrl must not carry a path ("${r}") — the key is verified from the full URL pathname, so a subpath base would make every signed URL fail verification`);const s=Math.floor(Date.now()/1e3)+t,o=h(e.baseUrl),c=K(e.transform),a=e.key.replace(b,"");p(a);const i=await L(e.secret,w(o,a,s,c)),l=H(e.baseUrl),m=j(a),g=c===""?"":`&t=${encodeURIComponent(c)}`;return`${l}/${m}?exp=${String(s)}&sig=${i}${g}`},F=async(e,t,n)=>{let r;try{r=e instanceof URL?e:new URL(e)}catch{return{reason:"malformed",valid:!1}}const s=r.searchParams.get("exp"),o=s===null?Number.NaN:Number(s),c=r.searchParams.get("sig"),a=r.searchParams.get("t")??"";if(!c||!Number.isInteger(o))return{reason:"malformed",valid:!1};if(o<Math.floor(Date.now()/1e3))return{reason:"expired",valid:!1};let i,l;try{i=r.pathname.replace(b,"").split("/").map(v=>decodeURIComponent(v)).join("/"),p(i),l=A(c)}catch{return{reason:"malformed",valid:!1}}const m=n?.expectedHost===void 0?r.host:h(n.expectedHost);if(!await I(t,w(m,i,o,a),l))return{reason:"bad_signature",valid:!1};if(a==="")return{key:i,valid:!0};let d;try{d=D(a)}catch{d=void 0}return{key:i,transform:a,transformOptions:d,valid:!0}};export{z as buildSignedImageUrl,D as parseSignedTransform,F as verifySignedImageUrl};
|