@lunora/bindings 1.0.0-alpha.28 → 1.0.0-alpha.29
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/analytics/index.mjs +1 -1
- package/dist/images/index.mjs +1 -1
- package/dist/kv/index.mjs +1 -1
- package/dist/packem_shared/{AnalyticsSqlError-B-JcsUhX.mjs → AnalyticsSqlError-cZQ6kiae.mjs} +1 -1
- package/dist/packem_shared/R2SqlError-Ba9yHVqU.mjs +1 -0
- package/dist/packem_shared/{SelectBuilder-WMBQ2b4q.mjs → SelectBuilder-C3dn71re.mjs} +1 -1
- package/dist/packem_shared/SetOperation-DwBivS9U.mjs +1 -0
- package/dist/packem_shared/Sql-CJr-IlfQ.mjs +1 -0
- package/dist/packem_shared/WindowExpression-D2wkQ8zz.mjs +1 -0
- package/dist/packem_shared/WindowFunction-BAPoVyhc.mjs +1 -0
- package/dist/packem_shared/asc-DQLvku7R.mjs +1 -0
- package/dist/packem_shared/buildImageDeliveryUrl-Brqs-dcZ.mjs +1 -0
- package/dist/packem_shared/buildSignedImageUrl-fucJNAbd.mjs +4 -0
- package/dist/packem_shared/concurrent-vRmSvRpF.mjs +1 -0
- package/dist/packem_shared/createAnalytics-BXTNc57d.mjs +1 -0
- package/dist/packem_shared/createContextVectors-Bk6ZVCqQ.mjs +6 -0
- package/dist/packem_shared/createImages-CHgMZP4g.mjs +1 -0
- package/dist/packem_shared/createKv-B0RfMMal.mjs +1 -0
- package/dist/packem_shared/createKvIntrospector-DT1k8mCG.mjs +1 -0
- package/dist/packem_shared/createPipelines-CIvqrc7E.mjs +1 -0
- package/dist/packem_shared/createVectorAdminIntrospector-DrsigTJs.mjs +1 -0
- package/dist/packem_shared/createVectors-DtLG5-xX.mjs +1 -0
- package/dist/pipelines/index.mjs +1 -1
- package/dist/r2sql/index.d.mts +16 -1
- package/dist/r2sql/index.d.ts +16 -1
- package/dist/r2sql/index.mjs +1 -1
- package/dist/vectors/index.mjs +1 -1
- package/package.json +3 -3
- package/dist/packem_shared/R2SqlError-Uaz0RJTR.mjs +0 -1
- package/dist/packem_shared/SetOperation-BrzMB1Tb.mjs +0 -1
- package/dist/packem_shared/Sql-CwhZl1Q5.mjs +0 -1
- package/dist/packem_shared/WindowExpression-CxCuEy8V.mjs +0 -1
- package/dist/packem_shared/WindowFunction-rzl4CzYE.mjs +0 -1
- package/dist/packem_shared/asc-BsbdtIQU.mjs +0 -1
- package/dist/packem_shared/buildImageDeliveryUrl-CMUkVJfB.mjs +0 -1
- package/dist/packem_shared/buildSignedImageUrl-BzgCHIu6.mjs +0 -4
- package/dist/packem_shared/concurrent-DMFQCILU.mjs +0 -1
- package/dist/packem_shared/createAnalytics-HRPCzT1M.mjs +0 -1
- package/dist/packem_shared/createContextVectors-D-ae1wWO.mjs +0 -6
- package/dist/packem_shared/createImages-TW6ircG2.mjs +0 -1
- package/dist/packem_shared/createKv-C05fokXt.mjs +0 -1
- package/dist/packem_shared/createKvIntrospector-Bz0nqUjD.mjs +0 -1
- package/dist/packem_shared/createPipelines-n0Bf_p8Y.mjs +0 -1
- package/dist/packem_shared/createVectorAdminIntrospector-B9Yt09yj.mjs +0 -1
- package/dist/packem_shared/createVectors-jb8fAY6R.mjs +0 -1
package/dist/analytics/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createAnalytics as e}from"../packem_shared/createAnalytics-
|
|
1
|
+
import{createAnalytics as e}from"../packem_shared/createAnalytics-BXTNc57d.mjs";import{AnalyticsSqlError as a,createAnalyticsSqlClient as c}from"../packem_shared/AnalyticsSqlError-cZQ6kiae.mjs";export{a as AnalyticsSqlError,e as createAnalytics,c as createAnalyticsSqlClient};
|
package/dist/images/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createImages as m}from"../packem_shared/createImages-
|
|
1
|
+
import{createImages as m}from"../packem_shared/createImages-CHgMZP4g.mjs";import{buildImageDeliveryUrl as i}from"../packem_shared/buildImageDeliveryUrl-Brqs-dcZ.mjs";import{buildSignedImageUrl as o,verifySignedImageUrl as a}from"../packem_shared/buildSignedImageUrl-fucJNAbd.mjs";export{i as buildImageDeliveryUrl,o as buildSignedImageUrl,m as createImages,a as verifySignedImageUrl};
|
package/dist/kv/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createKv as o,scopeKey as t}from"../packem_shared/createKv-
|
|
1
|
+
import{createKv as o,scopeKey as t}from"../packem_shared/createKv-B0RfMMal.mjs";import{createKvIntrospector as p,createKvIntrospectorFromEnv as v}from"../packem_shared/createKvIntrospector-DT1k8mCG.mjs";export{o as createKv,p as createKvIntrospector,v as createKvIntrospectorFromEnv,t as scopeKey};
|
package/dist/packem_shared/{AnalyticsSqlError-B-JcsUhX.mjs → AnalyticsSqlError-cZQ6kiae.mjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{LunoraError as l}from"@lunora/errors";const u="https://api.cloudflare.com/client/v4/accounts";class c extends l{constructor(e,o){super("ANALYTICS_SQL_ERROR",`Analytics Engine SQL API returned ${String(e)}: ${o}`,{name:"AnalyticsSqlError",status:e})}}const
|
|
1
|
+
import{LunoraError as l}from"@lunora/errors";const u="https://api.cloudflare.com/client/v4/accounts";class c extends l{constructor(e,o){super("ANALYTICS_SQL_ERROR",`Analytics Engine SQL API returned ${String(e)}: ${o}`,{name:"AnalyticsSqlError",status:e})}}const h=n=>{const e=n.fetch??globalThis.fetch,o=`${u}/${encodeURIComponent(n.accountId)}/analytics_engine/sql`;return{query:async i=>{const t=await e(o,{body:i,headers:{Authorization:`Bearer ${n.apiToken}`,"Content-Type":"text/plain"},method:"POST"});if(!t.ok)throw new c(t.status,await t.text());let a;try{a=await t.json()}catch{throw new c(t.status,"Analytics Engine SQL API returned a non-JSON body.")}const r=a,s=r.data??[];return{columns:r.meta??[],rowCount:r.rows??s.length,rows:s}}}};export{c as AnalyticsSqlError,h as createAnalyticsSqlClient};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{LunoraError as h}from"@lunora/errors";import m from"./SelectBuilder-C3dn71re.mjs";import{ident as l,toText as d}from"./Sql-CJr-IlfQ.mjs";const y="https://api.sql.cloudflarestorage.com/api/v1/accounts",w=e=>e[0]===void 0?[]:Object.keys(e[0]).map(s=>({name:s}));class c extends h{constructor(s,u){super("R2_SQL_ERROR",`R2 SQL query failed (${String(s)}): ${u}`,{name:"R2SqlError",status:s})}}const f=e=>{const s=e.fetch??globalThis.fetch,p=`${e.endpoint??y}/${encodeURIComponent(e.accountId)}/r2-sql/query/${encodeURIComponent(e.bucket)}`,S=`${e.accountId}_${e.bucket}`,n=async t=>{const r=await s(p,{body:JSON.stringify({query:t,warehouse:S}),headers:{Authorization:`Bearer ${e.apiToken}`,"Content-Type":"application/json"},method:"POST"});if(!r.ok)throw new c(r.status,await r.text());let i;try{i=await r.json()}catch{throw new c(r.status,"R2 SQL returned a non-JSON body.")}const o=i;if(o.success===!1||o.errors!==void 0&&o.errors.length>0)throw new c(r.status,JSON.stringify(o.errors??o));const a=o.result?.rows??[];return{columns:o.result?.schema??w(a),rowCount:a.length,rows:a}};return{describe:async t=>n(`DESCRIBE ${l(t)}`),explain:async(t,r)=>n(`EXPLAIN ${r?.format==="json"?"FORMAT JSON ":""}${d(t)}`),from:t=>new m(n,t),query:async t=>n(d(t)),showDatabases:async()=>n("SHOW DATABASES"),showTables:async t=>n(`SHOW TABLES IN ${l(t)}`)}};export{c as R2SqlError,f as createR2Sql};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{renderOrderTerm as o}from"./asc-
|
|
1
|
+
import{renderOrderTerm as o}from"./asc-DQLvku7R.mjs";import h from"./SetOperation-DwBivS9U.mjs";import{tableRef as s,toText as e,assertLimit as u,lit as l}from"./Sql-CJr-IlfQ.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};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{renderOrderTerm as o}from"./asc-DQLvku7R.mjs";import{assertLimit as u,lit as a}from"./Sql-CJr-IlfQ.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("'","''")}'`,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};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Sql as r,lit as i}from"./Sql-CJr-IlfQ.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};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{renderOrderTerm as $}from"./asc-DQLvku7R.mjs";import{toText as o,lit as s}from"./Sql-CJr-IlfQ.mjs";import A from"./WindowExpression-D2wkQ8zz.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};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Sql as e,toText as n}from"./Sql-CJr-IlfQ.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 @@
|
|
|
1
|
+
import{LunoraError as a}from"@lunora/errors";const s=/^[a-z][a-z\d+\-.]*:\/\//i,c=[",","=","#","?","/"],d=e=>e.endsWith("/")?e.slice(0,-1):e,g=e=>e.startsWith("/")?e.slice(1):e,m=e=>Object.entries(e).filter(([,r])=>r!==void 0&&(typeof r=="string"||typeof r=="number")).map(([r,i])=>{const n=String(i),t=c.find(o=>n.includes(o));if(t!==void 0)throw new a("INTERNAL",`@lunora/bindings/images: transform option \`${r}\` value \`${n}\` contains a \`${t}\`, which the /cdn-cgi/image/ option path cannot represent (\`,\`/\`=\` are the option/key-value separators; \`#\`/\`?\`/\`/\` are URL-structural). Percent-encode the value — for colors use \`%23RRGGBB\`, not \`#RRGGBB\` or \`rgb(r,g,b)\`.`);return`${r}=${n}`}).join(","),l=e=>e.split("/").map(r=>encodeURIComponent(r)).join("/"),h=e=>{const r=d(e.baseUrl);if(e.imageId!==void 0){const o=e.variant??"public";return`${r}/${encodeURIComponent(e.imageId)}/${encodeURIComponent(o)}`}if(e.key===void 0)throw new a("INTERNAL","@lunora/bindings/images: buildImageDeliveryUrl requires either `imageId` or `key`");const i=e.transform===void 0?"":m(e.transform),n=s.test(e.key)?e.key:l(g(e.key)),t=i===""?"/cdn-cgi/image":`/cdn-cgi/image/${i}`;return`${r}${t}/${n}`};export{h as buildImageDeliveryUrl};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
const S=(e,t)=>{if(e.size<t)return;const n=e.keys().next().value;n!==void 0&&e.delete(n)},y=new TextEncoder,f=10080*60,C=/^[a-z][a-z0-9+\-.]*:\/\//i,v=Array.from({length:32},(e,t)=>t),U=new RegExp(`[${v.map(e=>String.fromCodePoint(e)).join("")}]`,"u"),R=e=>{const t=String.fromCodePoint(...e);return btoa(t).replaceAll("+","-").replaceAll("/","_").replaceAll("=","")},x=e=>{const t=e.replaceAll("-","+").replaceAll("_","/")+"===".slice((e.length+3)%4),n=atob(t),r=new Uint8Array(n.length);for(let a=0;a<n.length;a+=1)r[a]=n.codePointAt(a)??0;return r},A=64,m=new Map,u=async e=>{const t=m.get(e);if(t)return t;S(m,A);const n=crypto.subtle.importKey("raw",y.encode(e),{hash:"SHA-256",name:"HMAC"},!1,["sign","verify"]);return m.set(e,n),n},g=e=>{try{return new URL(e).host}catch{return e.replace(C,"").split("/")[0]??""}},h=e=>{if(U.test(e))throw new TypeError("hmac-url: value must not contain control characters (including CR/LF)")},E=async(e,t)=>{const n=await u(e),r=await crypto.subtle.sign("HMAC",n,y.encode(t));return R(new Uint8Array(r))},_=async(e,t,n)=>{const r=await u(e);return crypto.subtle.verify("HMAC",r,n,y.encode(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("&"),b=(e,t,n,r)=>`${e.toLowerCase()}
|
|
2
|
+
${t}
|
|
3
|
+
${String(n)}
|
|
4
|
+
${r}`,L=e=>e.split("/").map(t=>encodeURIComponent(t)).join("/"),I=async e=>{const t=e.expiresInSeconds??3600;if(!Number.isFinite(t)||t<=0)throw new TypeError("@lunora/bindings/images: expiresInSeconds must be a positive finite number");if(t>f)throw new TypeError(`@lunora/bindings/images: expiresInSeconds must not exceed ${String(f)} (7 days)`);let n="";try{n=new URL(e.baseUrl).pathname}catch{}if(n!==""&&n!=="/")throw new TypeError(`@lunora/bindings/images: baseUrl must not carry a path ("${n}") — the key is verified from the full URL pathname, so a subpath base would make every signed URL fail verification`);const r=Math.floor(Date.now()/1e3)+t,a=g(e.baseUrl),s=$(e.transform),o=e.key.replace(p,"");h(o);const i=await E(e.secret,b(a,o,r,s)),c=e.baseUrl.endsWith("/")?e.baseUrl.slice(0,-1):e.baseUrl,l=L(o),d=s===""?"":`&t=${encodeURIComponent(s)}`;return`${c}/${l}?exp=${String(r)}&sig=${i}${d}`},N=async(e,t,n)=>{let r;try{r=e instanceof URL?e:new URL(e)}catch{return{reason:"malformed",valid:!1}}const a=r.searchParams.get("exp"),s=a===null?Number.NaN:Number(a),o=r.searchParams.get("sig"),i=r.searchParams.get("t")??"";if(!o||!Number.isInteger(s))return{reason:"malformed",valid:!1};if(s<Math.floor(Date.now()/1e3))return{reason:"expired",valid:!1};let c,l;try{c=r.pathname.replace(p,"").split("/").map(w=>decodeURIComponent(w)).join("/"),h(c),l=x(o)}catch{return{reason:"malformed",valid:!1}}const d=n?.expectedHost===void 0?r.host:g(n.expectedHost);return await _(t,b(d,c,s,i),l)?{key:c,transform:i===""?void 0:i,valid:!0}:{reason:"bad_signature",valid:!1}};export{I as buildSignedImageUrl,N as verifySignedImageUrl};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const h=8,u=async(r,c,l)=>{if(r.length===0)return[];const f=Math.max(1,Math.min(c,r.length)),n=Array.from({length:r.length});let a=0,t=!1,o;const s=Array.from({length:f},async()=>{for(;;){if(t)return;const e=a;if(a+=1,e>=r.length)return;try{n[e]=await l(r[e],e)}catch(i){t||(t=!0,o=i);return}}});if(await Promise.all(s),t)throw o;return n};export{h as U,u as c};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const _=new TextEncoder,l=n=>n===null?0:typeof n=="string"?_.encode(n).length:n.byteLength,a=(n,o,r)=>{if(o>r)throw new RangeError(`@lunora/bindings/analytics: a data point may carry at most ${String(r)} ${n} (got ${String(o)}).`)},b=(n,o,r)=>{if(o>r)throw new RangeError(`@lunora/bindings/analytics: a data point's ${n} may total at most ${String(r)} bytes (got ${String(o)}).`)},m=n=>{const o=t=>{a("blobs",t.blobs?.length??0,20),a("doubles",t.doubles?.length??0,20),a("indexes",t.indexes?.length??0,1);const s=(t.blobs??[]).reduce((e,c)=>e+l(c),0);b("blobs",s,16384);for(const e of t.indexes??[])b("index",l(e),96);n.writeDataPoint(t)};return{track:(t,s={})=>{const e=Object.entries(s.dimensions??{}),c=Object.entries(s.metrics??{}),E=[t,...e.map(([,i])=>i)],g=c.map(([,i])=>i),u=s.index===void 0?[]:[s.index];o({blobs:E,doubles:g,indexes:u});const B=e.map(([i],d)=>({column:`blob${String(d+2)}`,field:i})),S=c.map(([i],d)=>({column:`double${String(d+1)}`,field:i})),X=s.index===void 0?null:{column:"index1",field:"index"};return{dimensions:B,index:X,metrics:S,name:t}},writeDataPoint:o}};export{m as createAnalytics};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import{c as b,U as g}from"./concurrent-vRmSvRpF.mjs";const x=(s,c)=>{if(!c.includes("."))return s[c];let n=s;for(const d of c.split(".")){if(n===null||typeof n!="object"||Array.isArray(n))return;n=n[d]}return n},S=(s,c)=>{const n=c?.namespace,d=new Set(c?.shardedIndexNames),l=(t,a)=>{if(a!==void 0)return a;if(d.has(t)){if(n!==void 0)return n;throw new Error(`@lunora/bindings/vectors: index "${t}" belongs to a sharded table, but this DO instance has no shard key (it is the root/default DO) and no explicit namespace was given. A namespace-less operation here would reach every tenant's vectors — Vectorize indexes are account-global. Pass an explicit namespace, or issue this call from the sharded DO instance that owns the tenant.`)}},o=async(t,a)=>{await s.upsert(t,{embed:a.embed,id:a.id,input:a.input,metadata:a.metadata,namespace:l(t,a.namespace)})},h=async(t,a,i)=>{const r=await s.getByIds(t,a);return i===void 0?r:r.filter(m=>m.namespace===i)};return{deleteByIds:async(t,a,i)=>{const r=l(t,i);if(r===void 0){await s.deleteByIds(t,a);return}const m=await h(t,a,r);m.length!==0&&await s.deleteByIds(t,m.map(u=>u.id))},getByIds:async(t,a,i)=>{const r=l(t,i);return(await h(t,a,r)).map(u=>({id:u.id,metadata:u.metadata,namespace:u.namespace,values:u.values}))},query:async(t,a)=>{const i=await s.query(t,{embed:a.embed,filter:a.filter,input:a.input,namespace:l(t,a.namespace),returnMetadata:a.returnMetadata??"indexed",topK:a.topK,vector:a.vector});return{count:i.count,matches:i.matches.map(r=>({id:r.id,metadata:r.metadata,score:r.score}))}},upsert:o,upsertNow:o}},f=new Set,v=s=>{f.has(s)||(f.add(s),console.warn(`[@lunora/bindings/vectors] index "${s}" syncs vectors without a namespace — in a
|
|
2
|
+
multi-tenant/sharded app this exposes one tenant's vectors (and any captured
|
|
3
|
+
metadata) to every other tenant, since Vectorize indexes are account-global.
|
|
4
|
+
Pass \`namespace\` (the shard/tenant key) on both write and query — query-side
|
|
5
|
+
namespace filtering is mandatory for multi-tenant apps. Single-tenant apps that
|
|
6
|
+
legitimately have no tenant key suppress this via { allowSharedNamespace: true }.`))},I=(s,c)=>{const n={};for(const d of c)d in s&&(n[d]=s[d]);return n},D=s=>{const{allowSharedNamespace:c,namespace:n,schema:d,vectors:l}=s;return async o=>{const t=d.tables[o.table]?.vectorIndexes??[],a=Object.entries(d.vectorIndexes).filter(([,e])=>e.table===o.table);if(t.length===0&&a.length===0)return;const i=[...t.map(e=>e.name),...a.map(([e])=>e)];if(o.op==="delete"){await Promise.all(i.map(e=>l.deleteByIds(e,[o.id])));return}const r=o.doc;if(!r)return;const m=t.map(e=>({index:e,value:x(r,e.field)})),u=m.filter(e=>e.value!==void 0&&e.value!==null),y=m.filter(e=>e.value===void 0||e.value===null);for(const{index:e,value:p}of u)if(typeof p!="string")throw new TypeError(`@lunora/bindings/vectors: inline index "${e.name}" expects a string source at "${e.field}" on table "${o.table}" (got ${typeof p}); use a standalone defineVectorIndex with a select() to derive text from non-string columns`);const w=[...y.map(e=>async()=>{await l.deleteByIds(e.index.name,[o.id])}),...u.map(e=>async()=>{!c&&n===void 0&&v(e.index.name),await l.upsert(e.index.name,{embed:e.index.embed,id:o.id,input:e.value,metadata:e.index.metadata?I(r,e.index.metadata):void 0,namespace:n})}),...a.map(([e,p])=>async()=>{!c&&n===void 0&&v(e),await l.upsert(e,{embed:p.embed,id:o.id,input:p.select(r),metadata:p.metadata?.(r),namespace:n})})];try{await b(w,g,async e=>e())}catch(e){throw await Promise.allSettled(i.map(p=>l.deleteByIds(p,[o.id]))),e}}};export{S as createContextVectors,D as createVectorSyncHook};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{LunoraError as d}from"@lunora/errors";const m=new Set(["image/avif","image/gif","image/jpeg","image/png","image/webp"]),T=1e4,A="image/webp",O=e=>typeof e!="object"?!1:"body"in e&&!(e instanceof ArrayBuffer)&&!(e instanceof Uint8Array),i=e=>{if(e instanceof ReadableStream)return e;if(O(e)){if(e.body===null)throw new d("INTERNAL","@lunora/bindings/images: R2 object body is null (object missing or already consumed)");return e.body}if(e instanceof Blob)return e.stream();const t=e instanceof Uint8Array?e:new Uint8Array(e);return new ReadableStream({start(n){n.enqueue(t),n.close()}})},f=(e,t)=>{if(e===void 0)return{};const n=r=>{if(!Number.isFinite(r)||r<=0)throw new TypeError("@lunora/bindings/images: width/height must be a positive finite number");return Math.min(Math.floor(r),t)},o={...e};return delete o.draw,{...o,...e.width===void 0?{}:{width:n(e.width)},...e.height===void 0?{}:{height:n(e.height)}}},v=e=>{const{image:t,transform:n,...o}=e;return{drawOptions:o,image:t,transform:n}},U=e=>{const t=e?.format??A;if(!m.has(t))throw new d("INTERNAL",`@lunora/bindings/images: unsupported output format "${t}" (allowed: ${[...m].join(", ")})`);return{...e,format:t}},p=e=>{const{binding:t}=e,n=e.maxDimension??T;return{info:async o=>t.info(i(o)),transform:async(o,r,g,b)=>{const u=f(r,n),l=U(g);let a=t.input(i(o)).transform(u);for(const w of b??[]){const{drawOptions:y,image:s,transform:c}=v(w),h=c===void 0?i(s):t.input(i(s)).transform(f(c,n));a=a.draw(h,y)}return a.output(l)}}};export{p as createImages};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{LunoraError as c}from"@lunora/errors";const d=512,T=1e3,v=1024,f=new TextEncoder,m=t=>f.encode(t).length,h=(t,i)=>{if(m(t)>d)throw new c("INTERNAL",`@lunora/bindings/kv: ${i} exceeds ${String(d)}-byte limit`);if(t.includes("\0"))throw new c("INTERNAL",`@lunora/bindings/kv: ${i} contains NUL byte`);for(const a of t.split("/"))if(a==="."||a==="..")throw new c("INTERNAL",`@lunora/bindings/kv: ${i} contains a \`.\`/\`..\` path component`)},u=t=>{if(typeof t!="string"||t.length===0)throw new TypeError("@lunora/bindings/kv: key must be a non-empty string");h(t,"key")},g=t=>{t.length>0&&h(t,"prefix")},b=(t,i)=>{u(t),u(i);const o=`${t.endsWith("/")?t.slice(0,-1):t}/${i}`;if(m(o)>d)throw new c("INTERNAL",`@lunora/bindings/kv: scoped key exceeds ${String(d)}-byte limit`);return o},x=t=>{const i={};if(t.expiration!==void 0&&t.expirationTtl!==void 0)throw new c("INTERNAL","@lunora/bindings/kv: `expiration` and `expirationTtl` are mutually exclusive");if(t.expiration!==void 0&&(i.expiration=t.expiration),t.expirationTtl!==void 0&&(i.expirationTtl=t.expirationTtl),t.metadata!==void 0){let a;try{a=JSON.stringify(t.metadata)}catch{throw new c("INTERNAL","@lunora/bindings/kv: metadata is not JSON-serializable (cyclic value, bigint, or similar)")}if(m(a)>v)throw new c("INTERNAL",`@lunora/bindings/kv: metadata exceeds ${String(v)}-byte limit`);i.metadata=t.metadata}return Object.keys(i).length>0?i:void 0},k=t=>{if(!t.namespace)throw new TypeError("@lunora/bindings/kv: `namespace` is required");const{keyPrefix:i,namespace:a}=t;i!==void 0&&u(i);const o=e=>i===void 0?(u(e),e):b(i,e),y=e=>{if(i===void 0)return e;const n=i.endsWith("/")?i:`${i}/`;return e.startsWith(n)?e.slice(n.length):e};return{delete:async e=>{await a.delete(o(e))},get:async(e,n={})=>await a.get(o(e),{cacheTtl:n.cacheTtl,type:"json"})??null,getRaw:async(e,n={})=>await a.get(o(e),{cacheTtl:n.cacheTtl,type:n.type??"text"})??null,getWithMetadata:async(e,n={})=>{const r=await a.getWithMetadata(o(e),{cacheTtl:n.cacheTtl,type:"json"});return{metadata:r.metadata??null,value:r.value??null}},list:async(e={})=>{if(e.limit!==void 0&&(!Number.isInteger(e.limit)||e.limit<=0))throw new TypeError("@lunora/bindings/kv: `limit` must be a positive integer");let{prefix:n}=e;if(n!==void 0&&g(n),i!==void 0){const l=i.endsWith("/")?i:`${i}/`;n=e.prefix===void 0?l:`${l}${e.prefix}`,g(n)}const r=e.limit===void 0?void 0:Math.min(e.limit,T),s=await a.list({cursor:e.cursor,limit:r,prefix:n}),w=s.keys.map(l=>({...l,name:y(l.name)}));return{cursor:s.list_complete?void 0:s.cursor,keys:w,listComplete:s.list_complete}},put:async(e,n,r={})=>{const s=r.raw?n:JSON.stringify(n);await a.put(o(e),s,x(r))}}};export{k as createKv,b as scopeKey};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{LunoraError as l}from"@lunora/errors";const u=a=>{const{namespaces:t}=a,s=e=>{const r=t[e];if(!Object.hasOwn(t,e)||r===void 0)throw new l("BAD_REQUEST",`@lunora/bindings/kv: no namespace registered under binding "${e}"`);return r};return{deleteKey:async e=>{await s(e.namespace).delete(e.key)},getValue:async e=>{const n=await s(e.namespace).getWithMetadata(e.key,"text");return{metadata:n.metadata??null,value:n.value??null}},listKeys:async e=>{const n=await s(e.namespace).list({cursor:e.cursor,limit:e.limit,prefix:e.prefix}),i=n.keys.map(o=>({expiration:o.expiration,metadata:o.metadata,name:o.name}));return{cursor:n.list_complete?void 0:n.cursor,keys:i,listComplete:n.list_complete}},listNamespaces:()=>Promise.resolve(Object.keys(t).map(e=>({binding:e}))),putValue:async e=>{await s(e.namespace).put(e.key,e.value,{expiration:e.expiration,expirationTtl:e.expirationTtl,metadata:e.metadata})}}},m=a=>{if(typeof a!="object"||a===null)return!1;const t=a;return typeof t.getWithMetadata=="function"&&typeof t.list=="function"&&typeof t.put=="function"&&typeof t.delete=="function"},v=a=>{const t={};if(typeof a=="object"&&a!==null)for(const[s,c]of Object.entries(a))m(c)&&(t[s]=c);return u({namespaces:t})};export{u as createKvIntrospector,v as createKvIntrospectorFromEnv};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const i=a=>{const{binding:e}=a;return{send:async n=>{await e.send(Array.isArray(n)?n:[n])}}};export{i as createPipelines};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{LunoraError as a}from"@lunora/errors";const m=20,p=10,f=u=>{const{embedders:r,indexes:n,registry:b}=u,i=async()=>Promise.all(b.map(async e=>{const s=n[e.name];if(s?.describe===void 0)return{...e};try{const t=await s.describe();return{...e,dimensions:e.dimensions??t.dimensions,processedUpToMutation:t.processedUpToMutation,vectorsCount:t.vectorsCount}}catch{return{...e}}}));return r!==void 0&&Object.keys(r).length>0?{listIndexes:i,queryIndex:async({name:e,text:s,topK:t})=>{const d=n[e];if(!Object.hasOwn(n,e)||d===void 0)throw new a("INTERNAL",`@lunora/bindings/vectors: no Vectorize binding registered for index "${e}"`);const c=r[e];if(!Object.hasOwn(r,e)||c===void 0)throw new a("INTERNAL",`@lunora/bindings/vectors: no embedder registered for index "${e}" — it lists read-only`);const l=await c(s);return{matches:(await d.query(l,{returnMetadata:"all",topK:Math.min(t??p,m)})).matches.map(o=>({id:o.id,metadata:o.metadata,score:o.score}))}}}:{listIndexes:i}};export{f as createVectorAdminIntrospector};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{LunoraError as y}from"@lunora/errors";import{c as w,U as v}from"./concurrent-vRmSvRpF.mjs";const a=(r,s)=>{const d=r[s];if(!Object.hasOwn(r,s)||d===void 0)throw new y("INTERNAL",`@lunora/bindings/vectors: no index registered for "${s}". Known indexes: ${Object.keys(r).join(", ")||"(none)"}`);return d},g=async r=>{const s=await r.embed(r.input);return{id:r.id,metadata:r.metadata,namespace:r.namespace,values:s}},h=100,m=20,c=1e3,u=1e3,_=r=>{if(Object.keys(r.indexes).length===0)throw new TypeError("@lunora/bindings/vectors: at least one index binding is required");return{deleteByIds:async(t,e)=>{const n=a(r.indexes,t);if(e.length>c)throw new RangeError(`@lunora/bindings/vectors: deleteByIds accepts at most ${String(c)} ids (got ${String(e.length)})`);return n.deleteByIds(e)},describe:async t=>{const e=a(r.indexes,t);if(!e.describe)throw new y("INTERNAL",`@lunora/bindings/vectors: binding for "${t}" does not implement describe()`);return e.describe()},getByIds:async(t,e)=>{const n=a(r.indexes,t);if(e.length>c)throw new RangeError(`@lunora/bindings/vectors: getByIds accepts at most ${String(c)} ids (got ${String(e.length)})`);return n.getByIds(e)},query:async(t,e)=>{const n=a(r.indexes,t),o=e.returnValues===!0||e.returnMetadata==="all",l=o?m:h;if(e.topK!==void 0&&(!Number.isInteger(e.topK)||e.topK<1||e.topK>l)){const b=o?' (lowered to 20 because returnValues/returnMetadata:"all" is set)':"";throw new RangeError(`@lunora/bindings/vectors: topK must be an integer in [1, ${String(l)}]${b} (got ${String(e.topK)})`)}let i;if(e.vector&&e.vector.length>0)i=e.vector;else{if(!e.embed||e.input===void 0)throw new TypeError("@lunora/bindings/vectors: query requires either `vector` or both `input` and `embed`");i=await e.embed(e.input)}return n.query(i,{filter:e.filter,namespace:e.namespace,returnMetadata:e.returnMetadata,returnValues:e.returnValues,topK:e.topK})},upsert:async(t,e)=>{const n=a(r.indexes,t),o=await g(e);return n.upsert([o])},upsertMany:async(t,e)=>{const n=a(r.indexes,t);if(e.length>u)throw new RangeError(`@lunora/bindings/vectors: upsertMany batch exceeds ${String(u)} (got ${String(e.length)}) — split across calls`);const o=await w(e,v,g);return n.upsert(o)}}};export{_ as default};
|
package/dist/pipelines/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createPipelines as i}from"../packem_shared/createPipelines-
|
|
1
|
+
import{createPipelines as i}from"../packem_shared/createPipelines-CIvqrc7E.mjs";export{i as createPipelines};
|
package/dist/r2sql/index.d.mts
CHANGED
|
@@ -380,4 +380,19 @@ declare const fn: {
|
|
|
380
380
|
/** `SUM(column) OVER (...)`. */
|
|
381
381
|
sum: (column: Sql | string) => WindowFunction;
|
|
382
382
|
};
|
|
383
|
-
export { type Condition, type OrderTerm, type OverSpec, type QueryExecutor, type Queryable, type R2SqlClient, type R2SqlColumn, type R2SqlConfig, R2SqlError, type R2SqlExplainOptions, type R2SqlResult,
|
|
383
|
+
export { type Condition, type OrderTerm, type OverSpec, type QueryExecutor, type Queryable, type R2SqlClient, type R2SqlColumn, type R2SqlConfig, R2SqlError, type R2SqlExplainOptions, type R2SqlResult,
|
|
384
|
+
/**
|
|
385
|
+
* `@lunora/bindings/r2sql` — typed, chainable R2 SQL for Lunora.
|
|
386
|
+
*
|
|
387
|
+
* Query Cloudflare [R2 SQL](https://developers.cloudflare.com/r2-sql/) — the
|
|
388
|
+
* serverless engine over Apache Iceberg tables in R2 Data Catalog — from a
|
|
389
|
+
* Lunora **action** via `ctx.r2sql`. First-class support for the 2026-06-21
|
|
390
|
+
* features: window functions (`fn.rowNumber().over(...)`), `DISTINCT` /
|
|
391
|
+
* `DISTINCT ON`, `QUALIFY`, and set operations (`.union()/.intersect()/.except()`).
|
|
392
|
+
*
|
|
393
|
+
* R2 SQL is non-deterministic external I/O with no Workers binding, so — like
|
|
394
|
+
* `ctx.sql` (Hyperdrive) — it is wired onto `ActionCtx` only and its reads are
|
|
395
|
+
* not tracked by Lunora live queries (see the `r2sql_outside_action` advisor
|
|
396
|
+
* lint). See the README and `createR2Sql` JSDoc.
|
|
397
|
+
*/
|
|
398
|
+
SelectBuilder, SetOperation, Sql, WindowExpression, WindowFunction, asc, createR2Sql, desc, fn, isSql, joinSql, lit, raw, renderOrderTerm, sql, toText };
|
package/dist/r2sql/index.d.ts
CHANGED
|
@@ -380,4 +380,19 @@ declare const fn: {
|
|
|
380
380
|
/** `SUM(column) OVER (...)`. */
|
|
381
381
|
sum: (column: Sql | string) => WindowFunction;
|
|
382
382
|
};
|
|
383
|
-
export { type Condition, type OrderTerm, type OverSpec, type QueryExecutor, type Queryable, type R2SqlClient, type R2SqlColumn, type R2SqlConfig, R2SqlError, type R2SqlExplainOptions, type R2SqlResult,
|
|
383
|
+
export { type Condition, type OrderTerm, type OverSpec, type QueryExecutor, type Queryable, type R2SqlClient, type R2SqlColumn, type R2SqlConfig, R2SqlError, type R2SqlExplainOptions, type R2SqlResult,
|
|
384
|
+
/**
|
|
385
|
+
* `@lunora/bindings/r2sql` — typed, chainable R2 SQL for Lunora.
|
|
386
|
+
*
|
|
387
|
+
* Query Cloudflare [R2 SQL](https://developers.cloudflare.com/r2-sql/) — the
|
|
388
|
+
* serverless engine over Apache Iceberg tables in R2 Data Catalog — from a
|
|
389
|
+
* Lunora **action** via `ctx.r2sql`. First-class support for the 2026-06-21
|
|
390
|
+
* features: window functions (`fn.rowNumber().over(...)`), `DISTINCT` /
|
|
391
|
+
* `DISTINCT ON`, `QUALIFY`, and set operations (`.union()/.intersect()/.except()`).
|
|
392
|
+
*
|
|
393
|
+
* R2 SQL is non-deterministic external I/O with no Workers binding, so — like
|
|
394
|
+
* `ctx.sql` (Hyperdrive) — it is wired onto `ActionCtx` only and its reads are
|
|
395
|
+
* not tracked by Lunora live queries (see the `r2sql_outside_action` advisor
|
|
396
|
+
* lint). See the README and `createR2Sql` JSDoc.
|
|
397
|
+
*/
|
|
398
|
+
SelectBuilder, SetOperation, Sql, WindowExpression, WindowFunction, asc, createR2Sql, desc, fn, isSql, joinSql, lit, raw, renderOrderTerm, sql, toText };
|
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-C3dn71re.mjs";import{R2SqlError as l,createR2Sql as f}from"../packem_shared/R2SqlError-Ba9yHVqU.mjs";import{asc as d,desc as i,renderOrderTerm as n}from"../packem_shared/asc-DQLvku7R.mjs";import{default as s}from"../packem_shared/SetOperation-DwBivS9U.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-CJr-IlfQ.mjs";import{WindowFunction as R,fn as T}from"../packem_shared/WindowFunction-BAPoVyhc.mjs";import{default as j}from"../packem_shared/WindowExpression-D2wkQ8zz.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/dist/vectors/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createContextVectors as t,createVectorSyncHook as o}from"../packem_shared/createContextVectors-
|
|
1
|
+
import{createContextVectors as t,createVectorSyncHook as o}from"../packem_shared/createContextVectors-Bk6ZVCqQ.mjs";import{createVectorAdminIntrospector as a}from"../packem_shared/createVectorAdminIntrospector-DrsigTJs.mjs";import{default as m}from"../packem_shared/createVectors-DtLG5-xX.mjs";export{t as createContextVectors,a as createVectorAdminIntrospector,o as createVectorSyncHook,m as createVectors};
|
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.29",
|
|
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",
|
|
@@ -64,8 +64,8 @@
|
|
|
64
64
|
"access": "public"
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
|
-
"@lunora/errors": "1.0.0-alpha.
|
|
68
|
-
"@lunora/platform": "1.0.0-alpha.
|
|
67
|
+
"@lunora/errors": "1.0.0-alpha.22",
|
|
68
|
+
"@lunora/platform": "1.0.0-alpha.11"
|
|
69
69
|
},
|
|
70
70
|
"engines": {
|
|
71
71
|
"node": "^22.15.0 || >=24.11.0"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{LunoraError as h}from"@lunora/errors";import m from"./SelectBuilder-WMBQ2b4q.mjs";import{ident as l,toText as S}from"./Sql-CwhZl1Q5.mjs";const p="https://api.sql.cloudflarestorage.com/api/v1/accounts",w=t=>t[0]===void 0?[]:Object.keys(t[0]).map(e=>({name:e}));class i extends h{constructor(e,a){super("R2_SQL_ERROR",`R2 SQL query failed (${String(e)}): ${a}`,{name:"R2SqlError",status:e})}}const $=t=>{const e=t.fetch??globalThis.fetch,a=`${t.endpoint??p}/${encodeURIComponent(t.accountId)}/r2-sql/query/${encodeURIComponent(t.bucket)}`,d=`${t.accountId}_${t.bucket}`,n=async o=>{const r=await e(a,{body:JSON.stringify({query:o,warehouse:d}),headers:{Authorization:`Bearer ${t.apiToken}`,"Content-Type":"application/json"},method:"POST"});if(!r.ok)throw new i(r.status,await r.text());let u;try{u=await r.json()}catch{throw new i(r.status,"R2 SQL returned a non-JSON body.")}const s=u;if(s.success===!1||s.errors!==void 0&&s.errors.length>0)throw new i(r.status,JSON.stringify(s.errors??s));const c=s.result?.rows??[];return{columns:s.result?.schema??w(c),rowCount:c.length,rows:c}};return{describe:async o=>n(`DESCRIBE ${l(o)}`),explain:async(o,r)=>n(`EXPLAIN ${r?.format==="json"?"FORMAT JSON ":""}${S(o)}`),from:o=>new m(n,o),query:async o=>n(S(o)),showDatabases:async()=>n("SHOW DATABASES"),showTables:async o=>n(`SHOW TABLES IN ${l(o)}`)}};export{i as R2SqlError,$ as createR2Sql};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{renderOrderTerm as o}from"./asc-BsbdtIQU.mjs";import{assertLimit as n,lit as u}from"./Sql-CwhZl1Q5.mjs";const h=e=>{const t=e.toSQL();return e.needsWrapForSetOperation===!0?`(${t})`:t};class d{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 n(t),this.limitValue=t,this}returns(){return this}toSQL(){const t=this.members.map(s=>{const i=h(s.query);return s.operator===void 0?i:`${s.operator} ${i}`}).join(" "),r=[];return this.orderByItems.length>0&&r.push(`ORDER BY ${this.orderByItems.join(", ")}`),this.limitValue!==void 0&&r.push(`LIMIT ${u(this.limitValue)}`),r.length>0?`${t} ${r.join(" ")}`:t}async run(){return this.exec(this.toSQL())}add(t,r){return this.members.push({operator:t,query:r}),this}}export{d as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
const a=e=>`'${e.replaceAll("'","''")}'`,f=/^\w+(?:\.\w+)*$/,p=/^\w+(?:\.\w+)*(?:\s+(?:as\s+)?\w+)?$/i;class t{text;constructor(r){this.text=r}toString(){return this.text}}const o=e=>e instanceof t,u=e=>new t(e),w=e=>o(e)?e.text:e,y=e=>{if(typeof e!="string"||!f.test(e))throw new TypeError(`r2sql: invalid identifier ${JSON.stringify(e)} — expected dotted [A-Za-z0-9_] segments (e.g. "namespace.table").`);return e},g=e=>{if(typeof e!="string"||!p.test(e))throw new TypeError(`r2sql: invalid table reference ${JSON.stringify(e)} — expected "namespace.table" with an optional "[AS] alias".`);return e},s=e=>{if(e==null)return"NULL";if(typeof e=="boolean")return e?"true":"false";if(typeof e=="bigint")return e.toString();if(typeof e=="number"){if(!Number.isFinite(e))throw new TypeError(`r2sql: cannot inline a non-finite number (${String(e)}) as a SQL literal.`);return String(e)}if(typeof e=="string")return a(e);if(e instanceof Date)return a(e.toISOString());if(Array.isArray(e)){if(e.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`(${e.map(r=>s(r)).join(", ")})`}throw new TypeError(`r2sql: cannot inline a value of type ${typeof e} as a SQL literal. Wrap trusted SQL with raw(), or pass a primitive/Date/array.`)},c=(e,...r)=>{let n=e[0]??"";for(const[l,i]of r.entries())n+=o(i)?i.text:s(i),n+=e[l+1]??"";return new t(n)},S=(e,r)=>new t(e.map(n=>w(n)).join(r)),m=e=>{if(!Number.isInteger(e)||e<1||e>1e4)throw new RangeError(`r2sql: limit must be an integer between 1 and ${String(1e4)} (got ${String(e)}).`)};export{t as Sql,m as assertLimit,y as ident,o as isSql,S as joinSql,s as lit,u as raw,c as sql,g as tableRef,w as toText};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{Sql as r,lit as s}from"./Sql-CwhZl1Q5.mjs";const n=/^[A-Z_][\w$]*$/i,a=t=>{if(!n.test(t))throw new TypeError(`r2sql: invalid identifier ${JSON.stringify(t)} — expected a simple SQL name (letters, digits, underscore).`);return t};let o=class extends r{as(e){return new r(`${this.text} AS ${a(e)}`)}between(e,i){return new r(`${this.text} BETWEEN ${s(e)} AND ${s(i)}`)}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,i){return new r(`${this.text} ${e} ${s(i)}`)}};export{o as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{renderOrderTerm as m}from"./asc-BsbdtIQU.mjs";import{lit as n,toText as o}from"./Sql-CwhZl1Q5.mjs";import u from"./WindowExpression-CxCuEy8V.mjs";const l=r=>r===void 0?[]:Array.isArray(r)?r:[r],c=r=>{const e=[],a=l(r.partitionBy).map(s=>o(s));a.length>0&&e.push(`PARTITION BY ${a.join(", ")}`);const i=l(r.orderBy).map(s=>m(s));return i.length>0&&e.push(`ORDER BY ${i.join(", ")}`),r.frame!==void 0&&r.frame.length>0&&e.push(r.frame),`OVER (${e.join(" ")})`},$=(r,e,a)=>{const i=[o(r)];return e!==void 0&&i.push(n(e)),a!==void 0&&i.push(n(a)),i.join(", ")};class p{callText;constructor(e){this.callText=e}over(e={}){return new u(`${this.callText} ${c(e)}`)}}const t=r=>new p(r),R={avg:r=>t(`AVG(${o(r)})`),count:r=>t(`COUNT(${r===void 0?"*":o(r)})`),cumeDist:()=>t("CUME_DIST()"),denseRank:()=>t("DENSE_RANK()"),firstValue:r=>t(`FIRST_VALUE(${o(r)})`),lag:(r,e,a)=>t(`LAG(${$(r,e,a)})`),lastValue:r=>t(`LAST_VALUE(${o(r)})`),lead:(r,e,a)=>t(`LEAD(${$(r,e,a)})`),max:r=>t(`MAX(${o(r)})`),min:r=>t(`MIN(${o(r)})`),nthValue:(r,e)=>t(`NTH_VALUE(${o(r)}, ${n(e)})`),ntile:r=>t(`NTILE(${n(r)})`),percentRank:()=>t("PERCENT_RANK()"),rank:()=>t("RANK()"),rowNumber:()=>t("ROW_NUMBER()"),sum:r=>t(`SUM(${o(r)})`)};export{p as WindowFunction,R as fn};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{Sql as t,toText as r}from"./Sql-CwhZl1Q5.mjs";const d=e=>({dir:"ASC",expr:e}),i=e=>({dir:"DESC",expr:e}),p=e=>typeof e=="string"||e instanceof t?r(e):`${r(e.expr)} ${e.dir}`;export{d as asc,i as desc,p as renderOrderTerm};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{LunoraError as a}from"@lunora/errors";const s=/^[a-z][a-z\d+\-.]*:\/\//i,c=[",","=","#","?","/"],d=e=>e.endsWith("/")?e.slice(0,-1):e,m=e=>e.startsWith("/")?e.slice(1):e,g=e=>Object.entries(e).filter(([,r])=>r!==void 0&&(typeof r=="string"||typeof r=="number")).map(([r,n])=>{const i=String(n),o=c.find(t=>i.includes(t));if(o!==void 0)throw new a("INTERNAL",`@lunora/bindings/images: transform option \`${r}\` value \`${i}\` contains a \`${o}\`, which the /cdn-cgi/image/ option path cannot represent (\`,\`/\`=\` are the option/key-value separators; \`#\`/\`?\`/\`/\` are URL-structural). Percent-encode the value — for colors use \`%23RRGGBB\`, not \`#RRGGBB\` or \`rgb(r,g,b)\`.`);return`${r}=${i}`}).join(","),l=e=>e.split("/").map(r=>encodeURIComponent(r)).join("/"),p=e=>{const r=d(e.baseUrl);if(e.imageId!==void 0){const t=e.variant??"public";return`${r}/${encodeURIComponent(e.imageId)}/${encodeURIComponent(t)}`}if(e.key===void 0)throw new a("INTERNAL","@lunora/bindings/images: buildImageDeliveryUrl requires either `imageId` or `key`");const n=e.transform===void 0?"":g(e.transform),i=s.test(e.key)?e.key:l(m(e.key)),o=n===""?"/cdn-cgi/image":`/cdn-cgi/image/${n}`;return`${r}${o}/${i}`};export{p as buildImageDeliveryUrl};
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
const v=(e,r)=>{if(e.size<r)return;const t=e.keys().next().value;t!==void 0&&e.delete(t)},p=new TextEncoder,u=10080*60,U=/^[a-z][a-z0-9+\-.]*:\/\//i,$=Array.from({length:32},(e,r)=>r),S=new RegExp(`[${$.map(e=>String.fromCodePoint(e)).join("")}]`,"u"),x=e=>{const r=String.fromCodePoint(...e);return btoa(r).replaceAll("+","-").replaceAll("/","_").replaceAll("=","")},A=e=>{const r=e.replaceAll("-","+").replaceAll("_","/")+"===".slice((e.length+3)%4),t=atob(r),n=new Uint8Array(t.length);for(let a=0;a<t.length;a+=1)n[a]=t.codePointAt(a)??0;return n},C=64,m=new Map,f=async e=>{const r=m.get(e);if(r)return r;v(m,C);const t=crypto.subtle.importKey("raw",p.encode(e),{hash:"SHA-256",name:"HMAC"},!1,["sign","verify"]);return m.set(e,t),t},g=e=>{try{return new URL(e).host}catch{return e.replace(U,"").split("/")[0]??""}},y=e=>{if(S.test(e))throw new TypeError("hmac-url: value must not contain control characters (including CR/LF)")},R=async(e,r)=>{const t=await f(e),n=await crypto.subtle.sign("HMAC",t,p.encode(r));return x(new Uint8Array(n))},I=async(e,r,t)=>{const n=await f(e);return crypto.subtle.verify("HMAC",n,t,p.encode(r))},h=/^\//,L=e=>e===void 0?"":Object.entries(e).filter(([,r])=>r!==void 0).toSorted(([r],[t])=>(r>t?1:0)-(r<t?1:0)).map(([r,t])=>`${r}=${typeof t=="object"?JSON.stringify(t):String(t)}`).join("&"),b=(e,r,t,n)=>`${e.toLowerCase()}
|
|
2
|
-
${r}
|
|
3
|
-
${String(t)}
|
|
4
|
-
${n}`,E=e=>e.split("/").map(r=>encodeURIComponent(r)).join("/"),N=async e=>{const r=e.expiresInSeconds??3600;if(!Number.isFinite(r)||r<=0)throw new TypeError("@lunora/bindings/images: expiresInSeconds must be a positive finite number");if(r>u)throw new TypeError(`@lunora/bindings/images: expiresInSeconds must not exceed ${String(u)} (7 days)`);let t="";try{t=new URL(e.baseUrl).pathname}catch{}if(t!==""&&t!=="/")throw new TypeError(`@lunora/bindings/images: baseUrl must not carry a path ("${t}") — the key is verified from the full URL pathname, so a subpath base would make every signed URL fail verification`);const n=Math.floor(Date.now()/1e3)+r,a=g(e.baseUrl),o=L(e.transform),s=e.key.replace(h,"");y(s);const l=await R(e.secret,b(a,s,n,o)),i=e.baseUrl.endsWith("/")?e.baseUrl.slice(0,-1):e.baseUrl,c=E(s),d=o===""?"":`&t=${encodeURIComponent(o)}`;return`${i}/${c}?exp=${String(n)}&sig=${l}${d}`},j=async(e,r,t)=>{let n;try{n=e instanceof URL?e:new URL(e)}catch{return{reason:"malformed",valid:!1}}const a=n.searchParams.get("exp"),o=a===null?Number.NaN:Number(a),s=n.searchParams.get("sig"),l=n.searchParams.get("t")??"";if(!s||!Number.isInteger(o))return{reason:"malformed",valid:!1};if(o<Math.floor(Date.now()/1e3))return{reason:"expired",valid:!1};let i,c;try{i=n.pathname.replace(h,"").split("/").map(w=>decodeURIComponent(w)).join("/"),y(i),c=A(s)}catch{return{reason:"malformed",valid:!1}}const d=t?.expectedHost===void 0?n.host:g(t.expectedHost);return await I(r,b(d,i,o,l),c)?{key:i,transform:l===""?void 0:l,valid:!0}:{reason:"bad_signature",valid:!1}};export{N as buildSignedImageUrl,j as verifySignedImageUrl};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
const i=8,u=async(t,o,s)=>{if(t.length===0)return[];const h=Math.max(1,Math.min(o,t.length)),a=Array.from({length:t.length});let e=0,n=!1,c;const l=Array.from({length:h},async()=>{for(;;){if(n)return;const r=e;if(e+=1,r>=t.length)return;try{a[r]=await s(t[r],r)}catch(f){n||(n=!0,c=f);return}}});if(await Promise.all(l),n)throw c;return a};export{i as U,u as c};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
const f=new TextEncoder,d=e=>e===null?0:typeof e=="string"?f.encode(e).length:e.byteLength,l=(e,t,n)=>{if(t>n)throw new RangeError(`@lunora/bindings/analytics: a data point may carry at most ${String(n)} ${e} (got ${String(t)}).`)},c=(e,t,n)=>{if(t>n)throw new RangeError(`@lunora/bindings/analytics: a data point's ${e} may total at most ${String(n)} bytes (got ${String(t)}).`)},p=e=>{const t=n=>{l("blobs",n.blobs?.length??0,20),l("doubles",n.doubles?.length??0,20),l("indexes",n.indexes?.length??0,1);const o=(n.blobs??[]).reduce((r,s)=>r+d(s),0);c("blobs",o,16384);for(const r of n.indexes??[])c("index",d(r),96);e.writeDataPoint(n)};return{track:(n,o={})=>{const r=Object.entries(o.dimensions??{}),s=Object.entries(o.metrics??{}),b=[n,...r.map(([,i])=>i)],g=s.map(([,i])=>i),m=o.index===void 0?[]:[o.index];t({blobs:b,doubles:g,indexes:m});const u=r.map(([i],a)=>({column:`blob${String(a+2)}`,field:i})),x=s.map(([i],a)=>({column:`double${String(a+1)}`,field:i})),y=o.index===void 0?null:{column:"index1",field:"index"};return{dimensions:u,index:y,metrics:x,name:n}},writeDataPoint:t}};export{p as createAnalytics};
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import{c as w,U as b}from"./concurrent-DMFQCILU.mjs";const x=(n,c)=>{if(!c.includes("."))return n[c];let s=n;for(const l of c.split(".")){if(s===null||typeof s!="object"||Array.isArray(s))return;s=s[l]}return s},B=(n,c)=>{const s=c?.namespace,l=new Set(c?.shardedIndexNames),m=(t,a)=>{if(a!==void 0)return a;if(l.has(t)){if(s!==void 0)return s;throw new Error(`@lunora/bindings/vectors: index "${t}" belongs to a sharded table, but this DO instance has no shard key (it is the root/default DO) and no explicit namespace was given. A namespace-less operation here would reach every tenant's vectors — Vectorize indexes are account-global. Pass an explicit namespace, or issue this call from the sharded DO instance that owns the tenant.`)}},i=async(t,a)=>{await n.upsert(t,{embed:a.embed,id:a.id,input:a.input,metadata:a.metadata,namespace:m(t,a.namespace)})},u=async(t,a,r)=>{const o=await n.getByIds(t,a);return r===void 0?o:o.filter(d=>d.namespace===r)};return{deleteByIds:async(t,a,r)=>{const o=m(t,r);if(o===void 0){await n.deleteByIds(t,a);return}const d=await u(t,a,o);d.length!==0&&await n.deleteByIds(t,d.map(h=>h.id))},getByIds:async(t,a,r)=>{const o=m(t,r);return(await u(t,a,o)).map(d=>({id:d.id,metadata:d.metadata,namespace:d.namespace,values:d.values}))},query:async(t,a)=>{const r=await n.query(t,{embed:a.embed,filter:a.filter,input:a.input,namespace:m(t,a.namespace),returnMetadata:a.returnMetadata??"indexed",topK:a.topK,vector:a.vector});return{count:r.count,matches:r.matches.map(o=>({id:o.id,metadata:o.metadata,score:o.score}))}},upsert:i,upsertNow:i}},y=new Set,v=n=>{y.has(n)||(y.add(n),console.warn(`[@lunora/bindings/vectors] index "${n}" syncs vectors without a namespace — in a
|
|
2
|
-
multi-tenant/sharded app this exposes one tenant's vectors (and any captured
|
|
3
|
-
metadata) to every other tenant, since Vectorize indexes are account-global.
|
|
4
|
-
Pass \`namespace\` (the shard/tenant key) on both write and query — query-side
|
|
5
|
-
namespace filtering is mandatory for multi-tenant apps. Single-tenant apps that
|
|
6
|
-
legitimately have no tenant key suppress this via { allowSharedNamespace: true }.`))},g=(n,c)=>{const s={};for(const l of c)l in n&&(s[l]=n[l]);return s},S=n=>{const{allowSharedNamespace:c,namespace:s,schema:l,vectors:m}=n;return async i=>{const u=l.tables[i.table]?.vectorIndexes??[],t=Object.entries(l.vectorIndexes).filter(([,e])=>e.table===i.table);if(u.length===0&&t.length===0)return;const a=[...u.map(e=>e.name),...t.map(([e])=>e)];if(i.op==="delete"){await Promise.all(a.map(e=>m.deleteByIds(e,[i.id])));return}const r=i.doc;if(!r)return;const o=u.map(e=>({index:e,value:x(r,e.field)})),d=o.filter(e=>e.value!==void 0&&e.value!==null),h=o.filter(e=>e.value===void 0||e.value===null);for(const{index:e,value:p}of d)if(typeof p!="string")throw new TypeError(`@lunora/bindings/vectors: inline index "${e.name}" expects a string source at "${e.field}" on table "${i.table}" (got ${typeof p}); use a standalone defineVectorIndex with a select() to derive text from non-string columns`);const f=[...h.map(e=>async()=>{await m.deleteByIds(e.index.name,[i.id])}),...d.map(e=>async()=>{!c&&s===void 0&&v(e.index.name),await m.upsert(e.index.name,{embed:e.index.embed,id:i.id,input:e.value,metadata:e.index.metadata?g(r,e.index.metadata):void 0,namespace:s})}),...t.map(([e,p])=>async()=>{!c&&s===void 0&&v(e),await m.upsert(e,{embed:p.embed,id:i.id,input:p.select(r),metadata:p.metadata?.(r),namespace:s})})];try{await w(f,b,async e=>e())}catch(e){throw await Promise.allSettled(a.map(p=>m.deleteByIds(p,[i.id]))),e}}};export{B as createContextVectors,S as createVectorSyncHook};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{LunoraError as d}from"@lunora/errors";const f=new Set(["image/avif","image/gif","image/jpeg","image/png","image/webp"]),y=1e4,v="image/webp",A=n=>typeof n!="object"?!1:"body"in n&&!(n instanceof ArrayBuffer)&&!(n instanceof Uint8Array),e=n=>{if(n instanceof ReadableStream)return n;if(A(n)){if(n.body===null)throw new d("INTERNAL","@lunora/bindings/images: R2 object body is null (object missing or already consumed)");return n.body}if(n instanceof Blob)return n.stream();const t=n instanceof Uint8Array?n:new Uint8Array(n);return new ReadableStream({start(r){r.enqueue(t),r.close()}})},u=(n,t)=>{if(n===void 0)return{};const r=o=>{if(!Number.isFinite(o)||o<=0)throw new TypeError("@lunora/bindings/images: width/height must be a positive finite number");return Math.min(Math.floor(o),t)},i={...n};return delete i.draw,{...i,...n.width===void 0?{}:{width:r(n.width)},...n.height===void 0?{}:{height:r(n.height)}}},j=n=>{const{image:t,transform:r,...i}=n;return{drawOptions:i,image:t,transform:r}},N=n=>{const t=n?.format??v;if(!f.has(t))throw new d("INTERNAL",`@lunora/bindings/images: unsupported output format "${t}" (allowed: ${[...f].join(", ")})`);return{...n,format:t}},E=n=>{const{binding:t}=n,r=n.maxDimension??y;return{info:async i=>t.info(e(i)),transform:async(i,o,g,c)=>{const w=u(o,r),b=N(g);let a=t.input(e(i)).transform(w);for(const h of c??[]){const{drawOptions:l,image:s,transform:m}=j(h),p=m===void 0?e(s):t.input(e(s)).transform(u(m,r));a=a.draw(p,l)}return a.output(b)}}};export{E as createImages};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{LunoraError as o}from"@lunora/errors";const d=512,w=1e3,m=1024,f=new TextEncoder,u=t=>f.encode(t).length,y=(t,e)=>{if(u(t)>d)throw new o("INTERNAL",`@lunora/bindings/kv: ${e} exceeds ${String(d)}-byte limit`);if(t.includes("\0"))throw new o("INTERNAL",`@lunora/bindings/kv: ${e} contains NUL byte`);for(const a of t.split("/"))if(a==="."||a==="..")throw new o("INTERNAL",`@lunora/bindings/kv: ${e} contains a \`.\`/\`..\` path component`)},p=t=>{if(typeof t!="string"||t.length===0)throw new TypeError("@lunora/bindings/kv: key must be a non-empty string");y(t,"key")},v=t=>{t.length>0&&y(t,"prefix")},x=(t,e)=>{p(t),p(e);const a=`${t.endsWith("/")?t.slice(0,-1):t}/${e}`;if(u(a)>d)throw new o("INTERNAL",`@lunora/bindings/kv: scoped key exceeds ${String(d)}-byte limit`);return a},T=t=>{const e={};if(t.expiration!==void 0&&t.expirationTtl!==void 0)throw new o("INTERNAL","@lunora/bindings/kv: `expiration` and `expirationTtl` are mutually exclusive");if(t.expiration!==void 0&&(e.expiration=t.expiration),t.expirationTtl!==void 0&&(e.expirationTtl=t.expirationTtl),t.metadata!==void 0){let a;try{a=JSON.stringify(t.metadata)}catch{throw new o("INTERNAL","@lunora/bindings/kv: metadata is not JSON-serializable (cyclic value, bigint, or similar)")}if(u(a)>m)throw new o("INTERNAL",`@lunora/bindings/kv: metadata exceeds ${String(m)}-byte limit`);e.metadata=t.metadata}return Object.keys(e).length>0?e:void 0},N=t=>{if(!t.namespace)throw new TypeError("@lunora/bindings/kv: `namespace` is required");const{keyPrefix:e,namespace:a}=t;e!==void 0&&p(e);const l=i=>e===void 0?(p(i),i):x(e,i),g=i=>{if(e===void 0)return i;const n=e.endsWith("/")?e:`${e}/`;return i.startsWith(n)?i.slice(n.length):i};return{delete:async i=>{await a.delete(l(i))},get:async(i,n={})=>await a.get(l(i),{cacheTtl:n.cacheTtl,type:"json"})??null,getRaw:async(i,n={})=>await a.get(l(i),{cacheTtl:n.cacheTtl,type:n.type??"text"})??null,getWithMetadata:async(i,n={})=>{const r=await a.getWithMetadata(l(i),{cacheTtl:n.cacheTtl,type:"json"});return{metadata:r.metadata??null,value:r.value??null}},list:async(i={})=>{if(i.limit!==void 0&&(!Number.isInteger(i.limit)||i.limit<=0))throw new TypeError("@lunora/bindings/kv: `limit` must be a positive integer");let{prefix:n}=i;if(n!==void 0&&v(n),e!==void 0){const c=e.endsWith("/")?e:`${e}/`;n=i.prefix===void 0?c:`${c}${i.prefix}`,v(n)}const r=i.limit===void 0?void 0:Math.min(i.limit,w),s=await a.list({cursor:i.cursor,limit:r,prefix:n}),h=s.keys.map(c=>({...c,name:g(c.name)}));return{cursor:s.list_complete?void 0:s.cursor,keys:h,listComplete:s.list_complete}},put:async(i,n,r={})=>{const s=r.raw?n:JSON.stringify(n);await a.put(l(i),s,T(r))}}};export{N as createKv,x as scopeKey};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{LunoraError as o}from"@lunora/errors";const c=n=>{const{namespaces:e}=n,r=t=>{const a=e[t];if(!Object.hasOwn(e,t)||a===void 0)throw new o("BAD_REQUEST",`@lunora/bindings/kv: no namespace registered under binding "${t}"`);return a};return{deleteKey:async t=>{await r(t.namespace).delete(t.key)},getValue:async t=>{const a=await r(t.namespace).getWithMetadata(t.key,"text");return{metadata:a.metadata??null,value:a.value??null}},listKeys:async t=>{const a=await r(t.namespace).list({cursor:t.cursor,limit:t.limit,prefix:t.prefix}),s=a.keys.map(i=>({expiration:i.expiration,metadata:i.metadata,name:i.name}));return{cursor:a.list_complete?void 0:a.cursor,keys:s,listComplete:a.list_complete}},listNamespaces:()=>Promise.resolve(Object.keys(e).map(t=>({binding:t}))),putValue:async t=>{await r(t.namespace).put(t.key,t.value,{expiration:t.expiration,expirationTtl:t.expirationTtl,metadata:t.metadata})}}},p=n=>{if(typeof n!="object"||n===null)return!1;const e=n;return typeof e.getWithMetadata=="function"&&typeof e.list=="function"&&typeof e.put=="function"&&typeof e.delete=="function"},u=n=>{const e={};if(typeof n=="object"&&n!==null)for(const[r,t]of Object.entries(n))p(t)&&(e[r]=t);return c({namespaces:e})};export{c as createKvIntrospector,u as createKvIntrospectorFromEnv};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
const s=e=>{const{binding:r}=e;return{send:async n=>{await r.send(Array.isArray(n)?n:[n])}}};export{s as createPipelines};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{LunoraError as c}from"@lunora/errors";const l=20,b=10,h=m=>{const{embedders:n,indexes:o,registry:u}=m,i=async()=>Promise.all(u.map(async t=>{const r=o[t.name];if(r?.describe===void 0)return{...t};try{const e=await r.describe();return{...t,dimensions:t.dimensions??e.dimensions,processedUpToMutation:e.processedUpToMutation,vectorsCount:e.vectorsCount}}catch{return{...t}}}));return n!==void 0&&Object.keys(n).length>0?{listIndexes:i,queryIndex:async({name:t,text:r,topK:e})=>{const a=o[t];if(!Object.hasOwn(o,t)||a===void 0)throw new c("INTERNAL",`@lunora/bindings/vectors: no Vectorize binding registered for index "${t}"`);const d=n[t];if(!Object.hasOwn(n,t)||d===void 0)throw new c("INTERNAL",`@lunora/bindings/vectors: no embedder registered for index "${t}" — it lists read-only`);const p=await d(r);return{matches:(await a.query(p,{returnMetadata:"all",topK:Math.min(e??b,l)})).matches.map(s=>({id:s.id,metadata:s.metadata,score:s.score}))}}}:{listIndexes:i}};export{h as createVectorAdminIntrospector};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{LunoraError as g}from"@lunora/errors";import{c as p,U as b}from"./concurrent-DMFQCILU.mjs";const i=(r,n)=>{const e=r[n];if(!Object.hasOwn(r,n)||e===void 0)throw new g("INTERNAL",`@lunora/bindings/vectors: no index registered for "${n}". Known indexes: ${Object.keys(r).join(", ")||"(none)"}`);return e},c=async r=>{const n=await r.embed(r.input);return{id:r.id,metadata:r.metadata,namespace:r.namespace,values:n}},w=100,y=20,o=1e3,u=1e3,f=r=>{if(Object.keys(r.indexes).length===0)throw new TypeError("@lunora/bindings/vectors: at least one index binding is required");return{deleteByIds:async(n,e)=>{const t=i(r.indexes,n);if(e.length>o)throw new RangeError(`@lunora/bindings/vectors: deleteByIds accepts at most ${String(o)} ids (got ${String(e.length)})`);return t.deleteByIds(e)},describe:async n=>{const e=i(r.indexes,n);if(!e.describe)throw new g("INTERNAL",`@lunora/bindings/vectors: binding for "${n}" does not implement describe()`);return e.describe()},getByIds:async(n,e)=>{const t=i(r.indexes,n);if(e.length>o)throw new RangeError(`@lunora/bindings/vectors: getByIds accepts at most ${String(o)} ids (got ${String(e.length)})`);return t.getByIds(e)},query:async(n,e)=>{const t=i(r.indexes,n),s=e.returnValues===!0||e.returnMetadata==="all",d=s?y:w;if(e.topK!==void 0&&(!Number.isInteger(e.topK)||e.topK<1||e.topK>d)){const l=s?' (lowered to 20 because returnValues/returnMetadata:"all" is set)':"";throw new RangeError(`@lunora/bindings/vectors: topK must be an integer in [1, ${String(d)}]${l} (got ${String(e.topK)})`)}let a;if(e.vector&&e.vector.length>0)a=e.vector;else{if(!e.embed||e.input===void 0)throw new TypeError("@lunora/bindings/vectors: query requires either `vector` or both `input` and `embed`");a=await e.embed(e.input)}return t.query(a,{filter:e.filter,namespace:e.namespace,returnMetadata:e.returnMetadata,returnValues:e.returnValues,topK:e.topK})},upsert:async(n,e)=>{const t=i(r.indexes,n),s=await c(e);return t.upsert([s])},upsertMany:async(n,e)=>{const t=i(r.indexes,n);if(e.length>u)throw new RangeError(`@lunora/bindings/vectors: upsertMany batch exceeds ${String(u)} (got ${String(e.length)}) — split across calls`);const s=await p(e,b,c);return t.upsert(s)}}};export{f as default};
|