@lunora/d1 1.0.0-alpha.177 → 1.0.0-alpha.179

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/index.mjs CHANGED
@@ -1 +1 @@
1
- import{exportGlobalRows as o,importGlobalRows as t,selectGlobalTables as a}from"./packem_shared/exportGlobalRows-BKsFpREf.mjs";import{D1Client as i,D1Session as n}from"./packem_shared/D1Client-CzS0Qfa6.mjs";import{backfillD1SearchIndexes as D,createD1CtxDb as p,readD1CdcChanges as x,runD1AggregateMigrations as b,runD1CdcMigration as g,runD1GlobalTableMigrations as m,runD1RankMigrations as c,runD1SearchMigrations as f,sweepD1CdcRetention as u}from"./packem_shared/backfillD1SearchIndexes-Dcv_bQOk.mjs";import{facetGlobalColumn as d,listGlobalTables as G,readGlobalTablePage as T}from"./packem_shared/facetGlobalColumn-5qWO1Uix.mjs";import{MigrationRunner as M}from"./packem_shared/MigrationRunner-DADTo9Q8.mjs";import{d1QueryTag as h,emitD1QueryCost as w,readD1QueryCost as S}from"./packem_shared/d1QueryTag-BcEGW4q1.mjs";import{D1TimeoutError as Q,isTransientD1Error as k,retryingExec as q,withD1Retry as A}from"./packem_shared/D1TimeoutError-D4YUqZPk.mjs";import{default as P}from"./packem_shared/sqliteDialect-Bjdkna-G.mjs";import{applyCdcChanges as v}from"@lunora/shard-engine";import{createSqlCtxDb as B}from"@lunora/sql-store";export{i as D1Client,n as D1Session,Q as D1TimeoutError,M as MigrationRunner,v as applyCdcChanges,D as backfillD1SearchIndexes,p as createD1CtxDb,B as createSqlCtxDb,h as d1QueryTag,w as emitD1QueryCost,o as exportGlobalRows,d as facetGlobalColumn,t as importGlobalRows,k as isTransientD1Error,G as listGlobalTables,x as readD1CdcChanges,S as readD1QueryCost,T as readGlobalTablePage,q as retryingExec,b as runD1AggregateMigrations,g as runD1CdcMigration,m as runD1GlobalTableMigrations,c as runD1RankMigrations,f as runD1SearchMigrations,a as selectGlobalTables,P as sqliteDialect,u as sweepD1CdcRetention,A as withD1Retry};
1
+ import{exportGlobalRows as o,importGlobalRows as t,selectGlobalTables as a}from"./packem_shared/exportGlobalRows-gh5TUaVm.mjs";import{D1Client as i,D1Session as n}from"./packem_shared/D1Client-CzS0Qfa6.mjs";import{backfillD1SearchIndexes as D,createD1CtxDb as p,readD1CdcChanges as x,runD1AggregateMigrations as b,runD1CdcMigration as g,runD1GlobalTableMigrations as m,runD1RankMigrations as c,runD1SearchMigrations as f,sweepD1CdcRetention as u}from"./packem_shared/backfillD1SearchIndexes-BHgn1SNb.mjs";import{facetGlobalColumn as d,listGlobalTables as G,readGlobalTablePage as T}from"./packem_shared/facetGlobalColumn-DcNoIRME.mjs";import{MigrationRunner as M}from"./packem_shared/MigrationRunner-DADTo9Q8.mjs";import{d1QueryTag as h,emitD1QueryCost as w,readD1QueryCost as S}from"./packem_shared/d1QueryTag-BcEGW4q1.mjs";import{D1TimeoutError as Q,isTransientD1Error as k,retryingExec as q,withD1Retry as A}from"./packem_shared/D1TimeoutError-D4YUqZPk.mjs";import{default as P}from"./packem_shared/sqliteDialect-B_3JNtdq.mjs";import{applyCdcChanges as v}from"@lunora/shard-engine";import{createSqlCtxDb as B}from"@lunora/sql-store";export{i as D1Client,n as D1Session,Q as D1TimeoutError,M as MigrationRunner,v as applyCdcChanges,D as backfillD1SearchIndexes,p as createD1CtxDb,B as createSqlCtxDb,h as d1QueryTag,w as emitD1QueryCost,o as exportGlobalRows,d as facetGlobalColumn,t as importGlobalRows,k as isTransientD1Error,G as listGlobalTables,x as readD1CdcChanges,S as readD1QueryCost,T as readGlobalTablePage,q as retryingExec,b as runD1AggregateMigrations,g as runD1CdcMigration,m as runD1GlobalTableMigrations,c as runD1RankMigrations,f as runD1SearchMigrations,a as selectGlobalTables,P as sqliteDialect,u as sweepD1CdcRetention,A as withD1Retry};
@@ -1 +1 @@
1
- import{backfillSqlSearchIndexes as r,createSqlCtxDb as o,readSqlCdcChanges as i,runSqlAggregateMigrations as c,runSqlCdcMigration as s,runSqlGlobalTableMigrations as l,runSqlRankMigrations as g,runSqlSearchMigrations as D,sweepSqlCdcRetention as S}from"@lunora/sql-store";import{createSqlCtxDb as w,decodeGlobalRow as G}from"@lunora/sql-store";import n from"./sqliteDialect-Bjdkna-G.mjs";const b=e=>o({...e,dialect:n}),q=(e,t)=>l(e,t,n),u=(e,t)=>c(e,t,n),M=(e,t)=>g(e,t,n),x=(e,t)=>D(e,t,n),h=(e,t)=>r(e,t,n),p=e=>s(e,n),f=(e,t={})=>i(e,t,n),m=(e,t,a)=>S(e,n,t,a);export{h as backfillD1SearchIndexes,b as createD1CtxDb,w as createSqlCtxDb,G as decodeGlobalRow,f as readD1CdcChanges,u as runD1AggregateMigrations,p as runD1CdcMigration,q as runD1GlobalTableMigrations,M as runD1RankMigrations,x as runD1SearchMigrations,m as sweepD1CdcRetention};
1
+ import{backfillSqlSearchIndexes as r,createSqlCtxDb as o,readSqlCdcChanges as i,runSqlAggregateMigrations as c,runSqlCdcMigration as s,runSqlGlobalTableMigrations as l,runSqlRankMigrations as g,runSqlSearchMigrations as D,sweepSqlCdcRetention as S}from"@lunora/sql-store";import{createSqlCtxDb as w,decodeGlobalRow as G}from"@lunora/sql-store";import n from"./sqliteDialect-B_3JNtdq.mjs";const b=e=>o({...e,dialect:n}),q=(e,t)=>l(e,t,n),u=(e,t)=>c(e,t,n),M=(e,t)=>g(e,t,n),x=(e,t)=>D(e,t,n),h=(e,t)=>r(e,t,n),p=e=>s(e,n),f=(e,t={})=>i(e,t,n),m=(e,t,a)=>S(e,n,t,a);export{h as backfillD1SearchIndexes,b as createD1CtxDb,w as createSqlCtxDb,G as decodeGlobalRow,f as readD1CdcChanges,u as runD1AggregateMigrations,p as runD1CdcMigration,q as runD1GlobalTableMigrations,M as runD1RankMigrations,x as runD1SearchMigrations,m as sweepD1CdcRetention};
@@ -1 +1 @@
1
- import{toErrorBody as p}from"@lunora/errors";import{n as E,e as m,d as g}from"./wire-codec-9PgXH_2y.mjs";import{runD1GlobalTableMigrations as w}from"./backfillD1SearchIndexes-Dcv_bQOk.mjs";import{quoteIdentifier as u}from"./quoteIdentifier-CObIFRhb.mjs";import{decodeGlobalRow as R}from"@lunora/sql-store";const O=200,k=(t,e)=>{const o=r=>t.tables[r]?.shardMode?.kind==="global";return e&&e.length>0?e.filter(r=>o(r)):Object.keys(t.tables).filter(r=>o(r))},h=(t,e,o)=>{const r=t.tables[e];return r?R(r,o):{_creationTime:o._creationTime,_id:o.id}},y=t=>E(t)?m(t):t,F=async function*(t,e,o){const r=k(e,o.tables),i=o.batchSize??O;await w(t,e);for(const s of r){const n=u(s);let a,l=!0;for(;l;){const c=a===void 0?await t.all(`SELECT * FROM ${n} ORDER BY "id" LIMIT ?`,[i]):await t.all(`SELECT * FROM ${n} WHERE "id" > ? ORDER BY "id" LIMIT ?`,[a,i]);for(const f of c)yield{doc:y(h(e,s,f)),table:s};const d=c.at(-1);d!==void 0&&(a=String(d.id)),l=c.length===i}}},b=t=>t?._meta?.column?.notNull===!1,I=(t,e)=>{const o=new Set;for(const[r,i]of Object.entries(t.shape)){if(e[r]!==null||i.kind!=="optional"||b(i))continue;const s=i._meta?.inner;b(s)||o.add(r)}return o.size===0?e:Object.fromEntries(Object.entries(e).filter(([r])=>!o.has(r)))},T=new Set(["_creationTime","_id"]),_=(t,e)=>Object.keys(e).find(o=>!T.has(o)&&!Object.hasOwn(t.shape,o)),S=(t,e,o)=>{const r=t.tables[e];if(!r)return`unknown table: ${e}`;const i=_(r,o);if(i!==void 0)return`unexpected field "${i}": not declared in table "${e}"`;for(const[s,n]of Object.entries(r.shape)){const a=o[s],l=n.kind==="optional";if(a===void 0&&l)continue;const c=n.parse;if(typeof c=="function")try{c(a)}catch(d){const f=d instanceof Error?d.message:String(d);return`field "${s}": ${f}`}}},v=async(t,e,o,r)=>{try{return e?(await e.all(`SELECT 1 AS hit FROM ${u(o)} WHERE "id" = ? LIMIT 1`,[r])).length>0:await t.get(r)!==null}catch{return!1}},A=async(t,e,o,r,i)=>{const{doc:s,table:n}=r;if(typeof n!="string"||n.length===0)return{error:{code:"BAD_ROW",line:i,message:"row is missing `table`",table:n},kind:"error"};if(e.tables[n]?.shardMode?.kind!=="global")return{kind:"skip"};if(!s||typeof s!="object"||Array.isArray(s))return{error:{code:"BAD_ROW",line:i,message:"row is missing or malformed `doc`",table:n},kind:"error"};let a;try{a=g(s)}catch(d){return{error:{code:"BAD_ROW",line:i,message:d instanceof Error?d.message:String(d),table:n},kind:"error"}}a=I(e.tables[n],a);const l=S(e,n,a);if(l!==void 0)return{error:{code:"VALIDATION_ERROR",line:i,message:l,table:n},kind:"error"};const c=typeof a._id=="string"?a._id:void 0;if(c!==void 0&&await v(t,o.exec,n,c))return{kind:"conflict"};try{return await t.insert(n,a,{allowExplicitId:!0}),{inserted:n,kind:"inserted"}}catch(d){const{body:f}=p(d,{fallbackCode:"INSERT_FAILED"});return{error:{code:f.code,line:i,message:f.message,table:n},kind:"error"}}},$=async(t,e,o)=>{const r=[],i={};let s=0,n=(o.startLine??1)-1;for(const a of o.rows){n+=1;const l=a.line??n,c=await A(t,e,o,a,l);switch(c.kind){case"conflict":{s+=1;break}case"error":{r.push(c.error);break}case"inserted":{i[c.inserted]=(i[c.inserted]??0)+1;break}}}return{conflicts:s,errors:r,inserted:i}};export{F as exportGlobalRows,$ as importGlobalRows,k as selectGlobalTables};
1
+ import{toErrorBody as p}from"@lunora/errors";import{n as E,e as m,d as g}from"./wire-codec-9PgXH_2y.mjs";import{runD1GlobalTableMigrations as w}from"./backfillD1SearchIndexes-BHgn1SNb.mjs";import{quoteIdentifier as u}from"./quoteIdentifier-CObIFRhb.mjs";import{decodeGlobalRow as R}from"@lunora/sql-store";const O=200,k=(t,e)=>{const o=r=>t.tables[r]?.shardMode?.kind==="global";return e&&e.length>0?e.filter(r=>o(r)):Object.keys(t.tables).filter(r=>o(r))},h=(t,e,o)=>{const r=t.tables[e];return r?R(r,o):{_creationTime:o._creationTime,_id:o.id}},y=t=>E(t)?m(t):t,F=async function*(t,e,o){const r=k(e,o.tables),i=o.batchSize??O;await w(t,e);for(const s of r){const n=u(s);let a,l=!0;for(;l;){const c=a===void 0?await t.all(`SELECT * FROM ${n} ORDER BY "id" LIMIT ?`,[i]):await t.all(`SELECT * FROM ${n} WHERE "id" > ? ORDER BY "id" LIMIT ?`,[a,i]);for(const f of c)yield{doc:y(h(e,s,f)),table:s};const d=c.at(-1);d!==void 0&&(a=String(d.id)),l=c.length===i}}},b=t=>t?._meta?.column?.notNull===!1,I=(t,e)=>{const o=new Set;for(const[r,i]of Object.entries(t.shape)){if(e[r]!==null||i.kind!=="optional"||b(i))continue;const s=i._meta?.inner;b(s)||o.add(r)}return o.size===0?e:Object.fromEntries(Object.entries(e).filter(([r])=>!o.has(r)))},T=new Set(["_creationTime","_id"]),_=(t,e)=>Object.keys(e).find(o=>!T.has(o)&&!Object.hasOwn(t.shape,o)),S=(t,e,o)=>{const r=t.tables[e];if(!r)return`unknown table: ${e}`;const i=_(r,o);if(i!==void 0)return`unexpected field "${i}": not declared in table "${e}"`;for(const[s,n]of Object.entries(r.shape)){const a=o[s],l=n.kind==="optional";if(a===void 0&&l)continue;const c=n.parse;if(typeof c=="function")try{c(a)}catch(d){const f=d instanceof Error?d.message:String(d);return`field "${s}": ${f}`}}},v=async(t,e,o,r)=>{try{return e?(await e.all(`SELECT 1 AS hit FROM ${u(o)} WHERE "id" = ? LIMIT 1`,[r])).length>0:await t.get(r)!==null}catch{return!1}},A=async(t,e,o,r,i)=>{const{doc:s,table:n}=r;if(typeof n!="string"||n.length===0)return{error:{code:"BAD_ROW",line:i,message:"row is missing `table`",table:n},kind:"error"};if(e.tables[n]?.shardMode?.kind!=="global")return{kind:"skip"};if(!s||typeof s!="object"||Array.isArray(s))return{error:{code:"BAD_ROW",line:i,message:"row is missing or malformed `doc`",table:n},kind:"error"};let a;try{a=g(s)}catch(d){return{error:{code:"BAD_ROW",line:i,message:d instanceof Error?d.message:String(d),table:n},kind:"error"}}a=I(e.tables[n],a);const l=S(e,n,a);if(l!==void 0)return{error:{code:"VALIDATION_ERROR",line:i,message:l,table:n},kind:"error"};const c=typeof a._id=="string"?a._id:void 0;if(c!==void 0&&await v(t,o.exec,n,c))return{kind:"conflict"};try{return await t.insert(n,a,{allowExplicitId:!0}),{inserted:n,kind:"inserted"}}catch(d){const{body:f}=p(d,{fallbackCode:"INSERT_FAILED"});return{error:{code:f.code,line:i,message:f.message,table:n},kind:"error"}}},$=async(t,e,o)=>{const r=[],i={};let s=0,n=(o.startLine??1)-1;for(const a of o.rows){n+=1;const l=a.line??n,c=await A(t,e,o,a,l);switch(c.kind){case"conflict":{s+=1;break}case"error":{r.push(c.error);break}case"inserted":{i[c.inserted]=(i[c.inserted]??0)+1;break}}}return{conflicts:s,errors:r,inserted:i}};export{F as exportGlobalRows,$ as importGlobalRows,k as selectGlobalTables};
@@ -1 +1 @@
1
- import{LunoraError as N}from"@lunora/errors";import{isInternalTableName as L}from"@lunora/shard-engine";import{sqliteDecode as G,effectiveColumnKind as D,decodeGlobalRow as F,sqliteEncode as M}from"@lunora/sql-store";import{n as _,e as A}from"./wire-codec-9PgXH_2y.mjs";import{runD1GlobalTableMigrations as R}from"./backfillD1SearchIndexes-Dcv_bQOk.mjs";import{TRACKING_TABLE_NAME as U}from"./MigrationRunner-DADTo9Q8.mjs";import{quoteIdentifier as l}from"./quoteIdentifier-CObIFRhb.mjs";const P=50,q=500,B=30,k=200,S=(t,o,n)=>Math.min(Math.max(t,o),n),K=t=>L(t)||t.startsWith("d1_")||t===U,v=/password|secret|token|hash|salt|credential/iu,u=(t,o)=>{const n=t.tables[o];return n?.shardMode?.kind==="global"?n:void 0},O=async t=>(await t.all("SELECT name FROM sqlite_master WHERE type = 'table' ORDER BY name",[])).map(n=>String(n.name)).filter(n=>!K(n)),$=async(t,o,n)=>{if(await R(t,o),!(await O(t)).includes(n))throw new N("UNKNOWN_TABLE",`unknown table: ${n}`,{status:404})},g=async(t,o,n="",e=[])=>{const r=await t.all(`SELECT COUNT(*) AS c FROM ${o}${n}`,e);return Number(r[0]?.c??0)},h=(t,o,n)=>u(t,o)!==void 0&&n==="_id"?"id":n,y=(t,o,n)=>{const e=u(t,o)?.shape[n];return e===void 0?void 0:D(e)},W=/^-?\d+$/u,Y=(t,o)=>{if(o!=="bigint")return M(t);const n=typeof t=="number"||typeof t=="string"?String(t).trim():void 0;return M(n!==void 0&&W.test(n)?BigInt(n):t,o)},C=(t,o,n,e)=>{const r=[],a=[];for(const s of e??[]){if(!n.includes(s.column))throw new N("UNKNOWN_COLUMN",`unknown column: ${s.column}`,{status:404});if(u(t,o)===void 0&&v.test(s.column))throw new N("FORBIDDEN",`cannot filter on a redacted column: ${s.column}`,{status:403});const i=l(h(t,o,s.column));s.value===null||s.value===void 0?r.push(`${i} IS NULL`):(r.push(`${i} = ?`),a.push(Y(s.value,y(t,o,s.column))))}return{params:a,where:r.length>0?` WHERE ${r.join(" AND ")}`:""}},j=(t,o,n)=>{const e=u(t,o);if(e)return F(e,n);const r={};for(const[a,s]of Object.entries(n))r[a]=s!=null&&v.test(a)?"•••":s;return r},I=async(t,o,n)=>{const e=u(o,n);return e?["_id","_creationTime",...Object.keys(e.shape)]:(await t.all(`PRAGMA table_info(${l(n)})`,[])).map(a=>String(a.name))},X=async(t,o,n)=>{if(u(o,n))return;const e=await t.all(`PRAGMA foreign_key_list(${l(n)})`,[]);if(e.length===0)return;const r={};for(const a of e){const s=String(a.from),i=String(a.table);r[s]??=i}return r},nt=async(t,o)=>{await R(t,o);const n=await O(t);return Promise.all(n.map(async e=>({name:e,rowCount:await g(t,l(e))})))},H=async(t,o,n,e)=>{if(u(o,n)!==void 0)return l("id");const a=(await t.all(`PRAGMA table_info(${l(n)})`,[])).filter(s=>Number(s.pk??0)>0);return a.length===1?l(String(a[0]?.name)):e.includes("id")?l("id"):"rowid"},ot=async(t,o,n)=>{const{table:e}=n;await $(t,o,e);const r=S(Math.trunc(n.limit??P),1,q),a=Math.max(0,Math.trunc(n.offset??0)),s=l(e),i=await I(t,o,e),{params:m,where:d}=C(o,e,i,n.filters),f=await g(t,s,d,m),w=await H(t,o,e,i),b=(await t.all(`SELECT * FROM ${s}${d} ORDER BY ${w} LIMIT ? OFFSET ?`,[...m,r,a])).map(E=>{const c=j(o,e,E);return _(c)?A(c):c}),T=await X(t,o,e);return T===void 0?{columns:i,rows:b,total:f}:{columns:i,refs:T,rows:b,total:f}},et=async(t,o,n)=>{const{column:e,table:r}=n;await $(t,o,r);const a=await I(t,o,r);if(!a.includes(e))throw new N("UNKNOWN_COLUMN",`unknown column: ${e}`,{status:404});const s=l(r),{params:i,where:m}=C(o,r,a,n.filters);if(u(o,r)===void 0&&v.test(e)){const c=await g(t,s,m,i);return{truncated:!1,values:c===0?[]:[{count:c,value:"•••"}]}}const d=S(Math.trunc(n.limit??B),1,k),f=l(h(o,r,e)),w=await t.all(`SELECT ${f} AS value, COUNT(*) AS count FROM ${s}${m} GROUP BY ${f} ORDER BY count DESC, ${f} ASC LIMIT ?`,[...i,d+1]),p=w.length>d,b=p?w.slice(0,d):w,T=y(o,r,e)==="bigint",E=b.map(c=>({count:Number(c.count),value:T?G(c.value,"bigint"):c.value}));return{truncated:p,values:_(E)?A(E):E}};export{et as facetGlobalColumn,nt as listGlobalTables,ot as readGlobalTablePage};
1
+ import{LunoraError as N}from"@lunora/errors";import{isInternalTableName as L}from"@lunora/shard-engine";import{sqliteDecode as G,effectiveColumnKind as D,decodeGlobalRow as F,sqliteEncode as M}from"@lunora/sql-store";import{n as _,e as A}from"./wire-codec-9PgXH_2y.mjs";import{runD1GlobalTableMigrations as R}from"./backfillD1SearchIndexes-BHgn1SNb.mjs";import{TRACKING_TABLE_NAME as U}from"./MigrationRunner-DADTo9Q8.mjs";import{quoteIdentifier as l}from"./quoteIdentifier-CObIFRhb.mjs";const P=50,q=500,B=30,k=200,S=(t,o,n)=>Math.min(Math.max(t,o),n),K=t=>L(t)||t.startsWith("d1_")||t===U,v=/password|secret|token|hash|salt|credential/iu,u=(t,o)=>{const n=t.tables[o];return n?.shardMode?.kind==="global"?n:void 0},O=async t=>(await t.all("SELECT name FROM sqlite_master WHERE type = 'table' ORDER BY name",[])).map(n=>String(n.name)).filter(n=>!K(n)),$=async(t,o,n)=>{if(await R(t,o),!(await O(t)).includes(n))throw new N("UNKNOWN_TABLE",`unknown table: ${n}`,{status:404})},g=async(t,o,n="",e=[])=>{const r=await t.all(`SELECT COUNT(*) AS c FROM ${o}${n}`,e);return Number(r[0]?.c??0)},h=(t,o,n)=>u(t,o)!==void 0&&n==="_id"?"id":n,y=(t,o,n)=>{const e=u(t,o)?.shape[n];return e===void 0?void 0:D(e)},W=/^-?\d+$/u,Y=(t,o)=>{if(o!=="bigint")return M(t);const n=typeof t=="number"||typeof t=="string"?String(t).trim():void 0;return M(n!==void 0&&W.test(n)?BigInt(n):t,o)},C=(t,o,n,e)=>{const r=[],a=[];for(const s of e??[]){if(!n.includes(s.column))throw new N("UNKNOWN_COLUMN",`unknown column: ${s.column}`,{status:404});if(u(t,o)===void 0&&v.test(s.column))throw new N("FORBIDDEN",`cannot filter on a redacted column: ${s.column}`,{status:403});const i=l(h(t,o,s.column));s.value===null||s.value===void 0?r.push(`${i} IS NULL`):(r.push(`${i} = ?`),a.push(Y(s.value,y(t,o,s.column))))}return{params:a,where:r.length>0?` WHERE ${r.join(" AND ")}`:""}},j=(t,o,n)=>{const e=u(t,o);if(e)return F(e,n);const r={};for(const[a,s]of Object.entries(n))r[a]=s!=null&&v.test(a)?"•••":s;return r},I=async(t,o,n)=>{const e=u(o,n);return e?["_id","_creationTime",...Object.keys(e.shape)]:(await t.all(`PRAGMA table_info(${l(n)})`,[])).map(a=>String(a.name))},X=async(t,o,n)=>{if(u(o,n))return;const e=await t.all(`PRAGMA foreign_key_list(${l(n)})`,[]);if(e.length===0)return;const r={};for(const a of e){const s=String(a.from),i=String(a.table);r[s]??=i}return r},nt=async(t,o)=>{await R(t,o);const n=await O(t);return Promise.all(n.map(async e=>({name:e,rowCount:await g(t,l(e))})))},H=async(t,o,n,e)=>{if(u(o,n)!==void 0)return l("id");const a=(await t.all(`PRAGMA table_info(${l(n)})`,[])).filter(s=>Number(s.pk??0)>0);return a.length===1?l(String(a[0]?.name)):e.includes("id")?l("id"):"rowid"},ot=async(t,o,n)=>{const{table:e}=n;await $(t,o,e);const r=S(Math.trunc(n.limit??P),1,q),a=Math.max(0,Math.trunc(n.offset??0)),s=l(e),i=await I(t,o,e),{params:m,where:d}=C(o,e,i,n.filters),f=await g(t,s,d,m),w=await H(t,o,e,i),b=(await t.all(`SELECT * FROM ${s}${d} ORDER BY ${w} LIMIT ? OFFSET ?`,[...m,r,a])).map(E=>{const c=j(o,e,E);return _(c)?A(c):c}),T=await X(t,o,e);return T===void 0?{columns:i,rows:b,total:f}:{columns:i,refs:T,rows:b,total:f}},et=async(t,o,n)=>{const{column:e,table:r}=n;await $(t,o,r);const a=await I(t,o,r);if(!a.includes(e))throw new N("UNKNOWN_COLUMN",`unknown column: ${e}`,{status:404});const s=l(r),{params:i,where:m}=C(o,r,a,n.filters);if(u(o,r)===void 0&&v.test(e)){const c=await g(t,s,m,i);return{truncated:!1,values:c===0?[]:[{count:c,value:"•••"}]}}const d=S(Math.trunc(n.limit??B),1,k),f=l(h(o,r,e)),w=await t.all(`SELECT ${f} AS value, COUNT(*) AS count FROM ${s}${m} GROUP BY ${f} ORDER BY count DESC, ${f} ASC LIMIT ?`,[...i,d+1]),p=w.length>d,b=p?w.slice(0,d):w,T=y(o,r,e)==="bigint",E=b.map(c=>({count:Number(c.count),value:T?G(c.value,"bigint"):c.value}));return{truncated:p,values:_(E)?A(E):E}};export{et as facetGlobalColumn,nt as listGlobalTables,ot as readGlobalTablePage};
@@ -0,0 +1 @@
1
+ import{renderSql as t}from"@lunora/shard-engine";import{sql as i}from"drizzle-orm";import{MAX_D1_TABLE_COLUMNS as a,sqlAffinityForKind as n}from"../dialect.mjs";const s=/unique constraint failed/iu,m={companionTypes:{autoincrementPrimaryKey:"INTEGER PRIMARY KEY AUTOINCREMENT",integer:"INTEGER",key:"TEXT",real:"REAL",text:"TEXT"},columnType:n,frameworkColumns:()=>[{name:"id",type:"TEXT PRIMARY KEY"},{name:"_creationTime",type:"REAL NOT NULL"}],isUniqueViolation:e=>e instanceof Error&&s.test(e.message),maxTableColumns:a,name:"sqlite",render:e=>t("sqlite",e),searchBackfillHint:"call backfillD1SearchIndexes with the store's exec from a host-side admin path",supportsFts5:!0,supportsReturning:!0,tableExists:e=>i`SELECT name FROM sqlite_master WHERE type = 'table' AND name = ${e}`};export{m as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/d1",
3
- "version": "1.0.0-alpha.177",
3
+ "version": "1.0.0-alpha.179",
4
4
  "description": "D1 adapter for Lunora .global() tables, wrapping the Sessions API for read-your-writes",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -51,9 +51,9 @@
51
51
  },
52
52
  "dependencies": {
53
53
  "@lunora/errors": ">=1.0.0-alpha.51 <2.0.0-0",
54
- "@lunora/platform": "1.0.0-alpha.63",
55
- "@lunora/shard-engine": "1.0.0-alpha.126",
56
- "@lunora/sql-store": "1.0.0-alpha.178",
54
+ "@lunora/platform": "1.0.0-alpha.64",
55
+ "@lunora/shard-engine": "1.0.0-alpha.128",
56
+ "@lunora/sql-store": "1.0.0-alpha.180",
57
57
  "drizzle-orm": "^0.45.3"
58
58
  },
59
59
  "engines": {
@@ -1 +0,0 @@
1
- import{sql as t}from"drizzle-orm";import{MAX_D1_TABLE_COLUMNS as i,sqlAffinityForKind as a}from"../dialect.mjs";const s=/unique constraint failed/iu,r={companionTypes:{autoincrementPrimaryKey:"INTEGER PRIMARY KEY AUTOINCREMENT",integer:"INTEGER",key:"TEXT",real:"REAL",text:"TEXT"},columnType:a,frameworkColumns:()=>[{name:"id",type:"TEXT PRIMARY KEY"},{name:"_creationTime",type:"REAL NOT NULL"}],isUniqueViolation:e=>e instanceof Error&&s.test(e.message),maxTableColumns:i,name:"sqlite",searchBackfillHint:"call backfillD1SearchIndexes with the store's exec from a host-side admin path",supportsFts5:!0,supportsReturning:!0,tableExists:e=>t`SELECT name FROM sqlite_master WHERE type = 'table' AND name = ${e}`};export{r as default};