@lunora/d1 1.0.0-alpha.72 → 1.0.0-alpha.74

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.
@@ -29,6 +29,16 @@ type SqlAffinity = "BLOB" | "INTEGER" | "REAL" | "TEXT";
29
29
  * would coerce a numeric-looking string and corrupt the decode.
30
30
  */
31
31
  declare const sqlAffinityForKind: (kind: string | undefined) => SqlAffinity;
32
+ /**
33
+ * Most columns one D1 table may carry, framework columns included.
34
+ *
35
+ * D1 runs Workerd's SQLite build, which sets `SQLITE_LIMIT_COLUMN` to 100 where
36
+ * stock SQLite allows 2,000. Exported so the two producers of global-table DDL
37
+ * — the runtime auto-provisioner in `@lunora/sql-store` and the
38
+ * `lunora migrate generate` emitter — check the same number rather than each
39
+ * carrying its own copy.
40
+ */
41
+ declare const MAX_D1_TABLE_COLUMNS = 100;
32
42
  /** Framework columns every global table carries: the physical `id` (exposed as `_id`) and `_creationTime`. */
33
43
  declare const frameworkColumnDdl: () => ReadonlyArray<string>;
34
44
  /**
@@ -38,4 +48,4 @@ declare const frameworkColumnDdl: () => ReadonlyArray<string>;
38
48
  declare const columnRef: (field: string) => string;
39
49
  /** Physical index identifier — `<table>_<name>`, so two tables' like-named indexes don't collide in SQLite's flat index namespace. */
40
50
  declare const physicalIndexName: (tableName: string, indexName: string) => string;
41
- export { SqlAffinity, columnRef, frameworkColumnDdl, physicalIndexName, quoteIdentifier, sqlAffinityForKind };
51
+ export { MAX_D1_TABLE_COLUMNS, SqlAffinity, columnRef, frameworkColumnDdl, physicalIndexName, quoteIdentifier, sqlAffinityForKind };
package/dist/dialect.d.ts CHANGED
@@ -29,6 +29,16 @@ type SqlAffinity = "BLOB" | "INTEGER" | "REAL" | "TEXT";
29
29
  * would coerce a numeric-looking string and corrupt the decode.
30
30
  */
31
31
  declare const sqlAffinityForKind: (kind: string | undefined) => SqlAffinity;
32
+ /**
33
+ * Most columns one D1 table may carry, framework columns included.
34
+ *
35
+ * D1 runs Workerd's SQLite build, which sets `SQLITE_LIMIT_COLUMN` to 100 where
36
+ * stock SQLite allows 2,000. Exported so the two producers of global-table DDL
37
+ * — the runtime auto-provisioner in `@lunora/sql-store` and the
38
+ * `lunora migrate generate` emitter — check the same number rather than each
39
+ * carrying its own copy.
40
+ */
41
+ declare const MAX_D1_TABLE_COLUMNS = 100;
32
42
  /** Framework columns every global table carries: the physical `id` (exposed as `_id`) and `_creationTime`. */
33
43
  declare const frameworkColumnDdl: () => ReadonlyArray<string>;
34
44
  /**
@@ -38,4 +48,4 @@ declare const frameworkColumnDdl: () => ReadonlyArray<string>;
38
48
  declare const columnRef: (field: string) => string;
39
49
  /** Physical index identifier — `<table>_<name>`, so two tables' like-named indexes don't collide in SQLite's flat index namespace. */
40
50
  declare const physicalIndexName: (tableName: string, indexName: string) => string;
41
- export { SqlAffinity, columnRef, frameworkColumnDdl, physicalIndexName, quoteIdentifier, sqlAffinityForKind };
51
+ export { MAX_D1_TABLE_COLUMNS, SqlAffinity, columnRef, frameworkColumnDdl, physicalIndexName, quoteIdentifier, sqlAffinityForKind };
package/dist/dialect.mjs CHANGED
@@ -1 +1 @@
1
- import{quoteIdentifier as i}from"./packem_shared/quoteIdentifier-CObIFRhb.mjs";const t=e=>{switch(e){case"boolean":return"INTEGER";case"bytes":return"BLOB";case"date":case"number":case"timestamp":return"REAL";default:return"TEXT"}},a=()=>[`${i("id")} TEXT PRIMARY KEY`,`${i("_creationTime")} REAL NOT NULL`],o=e=>e==="_id"||e==="id"?i("id"):e==="_creationTime"?i("_creationTime"):i(e),c=(e,r)=>i(`${e}_${r}`);export{o as columnRef,a as frameworkColumnDdl,c as physicalIndexName,i as quoteIdentifier,t as sqlAffinityForKind};
1
+ import{quoteIdentifier as i}from"./packem_shared/quoteIdentifier-CObIFRhb.mjs";const t=e=>{switch(e){case"boolean":return"INTEGER";case"bytes":return"BLOB";case"date":case"number":case"timestamp":return"REAL";default:return"TEXT"}},a=100,o=()=>[`${i("id")} TEXT PRIMARY KEY`,`${i("_creationTime")} REAL NOT NULL`],c=e=>e==="_id"||e==="id"?i("id"):e==="_creationTime"?i("_creationTime"):i(e),m=(e,r)=>i(`${e}_${r}`);export{a as MAX_D1_TABLE_COLUMNS,c as columnRef,o as frameworkColumnDdl,m as physicalIndexName,i as quoteIdentifier,t as sqlAffinityForKind};
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{exportGlobalRows as a,importGlobalRows as o,selectGlobalTables as l}from"./packem_shared/exportGlobalRows-B_2skT0r.mjs";import{D1Client as i,D1Session as n}from"./packem_shared/D1Client-DeccGO7F.mjs";import{backfillD1SearchIndexes as b,createD1CtxDb as D,readD1CdcChanges as g,runD1AggregateMigrations as c,runD1CdcMigration as x,runD1GlobalTableMigrations as f,runD1RankMigrations as m,runD1SearchMigrations as p,trimD1CdcChanges as C}from"./packem_shared/backfillD1SearchIndexes-CQyY3tKe.mjs";import{facetGlobalColumn as d,listGlobalTables as G,readGlobalTablePage as M}from"./packem_shared/facetGlobalColumn-BZWWCWZb.mjs";import{MigrationRunner as R}from"./packem_shared/MigrationRunner-CNH8wlIl.mjs";import{default as T}from"./packem_shared/sqliteDialect-D4zjIaj6.mjs";import{createSqlCtxDb as q}from"@lunora/sql-store";export{i as D1Client,n as D1Session,R as MigrationRunner,b as backfillD1SearchIndexes,D as createD1CtxDb,q as createSqlCtxDb,a as exportGlobalRows,d as facetGlobalColumn,o as importGlobalRows,G as listGlobalTables,g as readD1CdcChanges,M as readGlobalTablePage,c as runD1AggregateMigrations,x as runD1CdcMigration,f as runD1GlobalTableMigrations,m as runD1RankMigrations,p as runD1SearchMigrations,l as selectGlobalTables,T as sqliteDialect,C as trimD1CdcChanges};
1
+ import{exportGlobalRows as a,importGlobalRows as o,selectGlobalTables as l}from"./packem_shared/exportGlobalRows-_yXk_oxX.mjs";import{D1Client as i,D1Session as n}from"./packem_shared/D1Client-DeccGO7F.mjs";import{backfillD1SearchIndexes as b,createD1CtxDb as D,readD1CdcChanges as g,runD1AggregateMigrations as c,runD1CdcMigration as x,runD1GlobalTableMigrations as f,runD1RankMigrations as m,runD1SearchMigrations as p,trimD1CdcChanges as C}from"./packem_shared/backfillD1SearchIndexes-KCnA1HXB.mjs";import{facetGlobalColumn as d,listGlobalTables as G,readGlobalTablePage as M}from"./packem_shared/facetGlobalColumn-CVjP-5p6.mjs";import{MigrationRunner as R}from"./packem_shared/MigrationRunner-CNH8wlIl.mjs";import{default as T}from"./packem_shared/sqliteDialect-BKmeSU04.mjs";import{createSqlCtxDb as q}from"@lunora/sql-store";export{i as D1Client,n as D1Session,R as MigrationRunner,b as backfillD1SearchIndexes,D as createD1CtxDb,q as createSqlCtxDb,a as exportGlobalRows,d as facetGlobalColumn,o as importGlobalRows,G as listGlobalTables,g as readD1CdcChanges,M as readGlobalTablePage,c as runD1AggregateMigrations,x as runD1CdcMigration,f as runD1GlobalTableMigrations,m as runD1RankMigrations,p as runD1SearchMigrations,l as selectGlobalTables,T as sqliteDialect,C as trimD1CdcChanges};
@@ -1 +1 @@
1
- import{backfillSqlSearchIndexes as n,createSqlCtxDb as i,readSqlCdcChanges as t,runSqlAggregateMigrations as s,runSqlCdcMigration as l,runSqlGlobalTableMigrations as o,runSqlRankMigrations as g,runSqlSearchMigrations as c,trimSqlCdcChanges as d}from"@lunora/sql-store";import{createSqlCtxDb as G,decodeGlobalRow as R}from"@lunora/sql-store";import e from"./sqliteDialect-D4zjIaj6.mjs";const D=a=>i({...a,dialect:e}),b=(a,r)=>o(a,r,e),q=(a,r)=>s(a,r,e),u=(a,r)=>g(a,r,e),M=(a,r)=>c(a,r,e),h=(a,r)=>n(a,r,e),m=a=>l(a,e),x=(a,r={})=>t(a,r,e),f=(a,r)=>d(a,r,e);export{h as backfillD1SearchIndexes,D as createD1CtxDb,G as createSqlCtxDb,R as decodeGlobalRow,x as readD1CdcChanges,q as runD1AggregateMigrations,m as runD1CdcMigration,b as runD1GlobalTableMigrations,u as runD1RankMigrations,M as runD1SearchMigrations,f as trimD1CdcChanges};
1
+ import{backfillSqlSearchIndexes as n,createSqlCtxDb as i,readSqlCdcChanges as t,runSqlAggregateMigrations as s,runSqlCdcMigration as l,runSqlGlobalTableMigrations as o,runSqlRankMigrations as g,runSqlSearchMigrations as c,trimSqlCdcChanges as d}from"@lunora/sql-store";import{createSqlCtxDb as G,decodeGlobalRow as R}from"@lunora/sql-store";import e from"./sqliteDialect-BKmeSU04.mjs";const D=a=>i({...a,dialect:e}),b=(a,r)=>o(a,r,e),q=(a,r)=>s(a,r,e),u=(a,r)=>g(a,r,e),M=(a,r)=>c(a,r,e),h=(a,r)=>n(a,r,e),m=a=>l(a,e),x=(a,r={})=>t(a,r,e),f=(a,r)=>d(a,r,e);export{h as backfillD1SearchIndexes,D as createD1CtxDb,G as createSqlCtxDb,R as decodeGlobalRow,x as readD1CdcChanges,q as runD1AggregateMigrations,m as runD1CdcMigration,b as runD1GlobalTableMigrations,u as runD1RankMigrations,M as runD1SearchMigrations,f as trimD1CdcChanges};
@@ -1 +1 @@
1
- import{toErrorBody as u}from"@lunora/errors";import{runD1GlobalTableMigrations as m}from"./backfillD1SearchIndexes-CQyY3tKe.mjs";import{quoteIdentifier as f}from"./quoteIdentifier-CObIFRhb.mjs";import{decodeGlobalRow as E}from"@lunora/sql-store";const k=200,R=(o,t)=>{const r=e=>o.tables[e]?.shardMode?.kind==="global";return t&&t.length>0?t.filter(e=>r(e)):Object.keys(o.tables).filter(e=>r(e))},w=(o,t,r)=>{const e=o.tables[t];return e?E(e,r):{_creationTime:r._creationTime,_id:r.id}},O=async function*(o,t,r){const e=R(t,r.tables),a=r.batchSize??k;await m(o,t);for(const i of e){const n=f(i);let c,l=!0;for(;l;){const s=c===void 0?await o.all(`SELECT * FROM ${n} ORDER BY "id" LIMIT ?`,[a]):await o.all(`SELECT * FROM ${n} WHERE "id" > ? ORDER BY "id" LIMIT ?`,[c,a]);for(const b of s)yield{doc:w(t,i,b),table:i};const d=s.at(-1);d!==void 0&&(c=String(d.id)),l=s.length===a}}},y=(o,t,r)=>{const e=o.tables[t];if(!e)return`unknown table: ${t}`;for(const[a,i]of Object.entries(e.shape)){const n=r[a],c=i.kind==="optional";if(n===void 0&&c)continue;const l=i.parse;if(typeof l=="function")try{l(n)}catch(s){const d=s instanceof Error?s.message:String(s);return`field "${a}": ${d}`}}},g=async(o,t,r,e)=>{try{return t?(await t.all(`SELECT 1 AS hit FROM ${f(r)} WHERE "id" = ? LIMIT 1`,[e])).length>0:await o.get(e)!==null}catch{return!1}},p=async(o,t,r,e,a)=>{const{doc:i,table:n}=e;if(t.tables[n]?.shardMode?.kind!=="global")return{kind:"skip"};if(!i||typeof i!="object"||Array.isArray(i))return{error:{code:"BAD_ROW",line:a,message:"row is missing or malformed `doc`",table:n},kind:"error"};const c=y(t,n,i);if(c!==void 0)return{error:{code:"VALIDATION_ERROR",line:a,message:c,table:n},kind:"error"};const l=typeof i._id=="string"?i._id:void 0;if(l!==void 0&&await g(o,r.exec,n,l))return{kind:"conflict"};try{return await o.insert(n,i,{allowExplicitId:!0}),{inserted:n,kind:"inserted"}}catch(s){const{body:d}=u(s,{fallbackCode:"INSERT_FAILED"});return{error:{code:d.code,line:a,message:d.message,table:n},kind:"error"}}},M=async(o,t,r)=>{const e=[],a={};let i=0,n=(r.startLine??1)-1;for(const c of r.rows){n+=1;const l=c.line??n,s=await p(o,t,r,c,l);switch(s.kind){case"conflict":{i+=1;break}case"error":{e.push(s.error);break}case"inserted":{a[s.inserted]=(a[s.inserted]??0)+1;break}}}return{conflicts:i,errors:e,inserted:a}};export{O as exportGlobalRows,M as importGlobalRows,R as selectGlobalTables};
1
+ import{toErrorBody as u}from"@lunora/errors";import{runD1GlobalTableMigrations as m}from"./backfillD1SearchIndexes-KCnA1HXB.mjs";import{quoteIdentifier as f}from"./quoteIdentifier-CObIFRhb.mjs";import{decodeGlobalRow as E}from"@lunora/sql-store";const k=200,R=(o,t)=>{const r=e=>o.tables[e]?.shardMode?.kind==="global";return t&&t.length>0?t.filter(e=>r(e)):Object.keys(o.tables).filter(e=>r(e))},w=(o,t,r)=>{const e=o.tables[t];return e?E(e,r):{_creationTime:r._creationTime,_id:r.id}},O=async function*(o,t,r){const e=R(t,r.tables),a=r.batchSize??k;await m(o,t);for(const i of e){const n=f(i);let c,l=!0;for(;l;){const s=c===void 0?await o.all(`SELECT * FROM ${n} ORDER BY "id" LIMIT ?`,[a]):await o.all(`SELECT * FROM ${n} WHERE "id" > ? ORDER BY "id" LIMIT ?`,[c,a]);for(const b of s)yield{doc:w(t,i,b),table:i};const d=s.at(-1);d!==void 0&&(c=String(d.id)),l=s.length===a}}},y=(o,t,r)=>{const e=o.tables[t];if(!e)return`unknown table: ${t}`;for(const[a,i]of Object.entries(e.shape)){const n=r[a],c=i.kind==="optional";if(n===void 0&&c)continue;const l=i.parse;if(typeof l=="function")try{l(n)}catch(s){const d=s instanceof Error?s.message:String(s);return`field "${a}": ${d}`}}},g=async(o,t,r,e)=>{try{return t?(await t.all(`SELECT 1 AS hit FROM ${f(r)} WHERE "id" = ? LIMIT 1`,[e])).length>0:await o.get(e)!==null}catch{return!1}},p=async(o,t,r,e,a)=>{const{doc:i,table:n}=e;if(t.tables[n]?.shardMode?.kind!=="global")return{kind:"skip"};if(!i||typeof i!="object"||Array.isArray(i))return{error:{code:"BAD_ROW",line:a,message:"row is missing or malformed `doc`",table:n},kind:"error"};const c=y(t,n,i);if(c!==void 0)return{error:{code:"VALIDATION_ERROR",line:a,message:c,table:n},kind:"error"};const l=typeof i._id=="string"?i._id:void 0;if(l!==void 0&&await g(o,r.exec,n,l))return{kind:"conflict"};try{return await o.insert(n,i,{allowExplicitId:!0}),{inserted:n,kind:"inserted"}}catch(s){const{body:d}=u(s,{fallbackCode:"INSERT_FAILED"});return{error:{code:d.code,line:a,message:d.message,table:n},kind:"error"}}},M=async(o,t,r)=>{const e=[],a={};let i=0,n=(r.startLine??1)-1;for(const c of r.rows){n+=1;const l=c.line??n,s=await p(o,t,r,c,l);switch(s.kind){case"conflict":{i+=1;break}case"error":{e.push(s.error);break}case"inserted":{a[s.inserted]=(a[s.inserted]??0)+1;break}}}return{conflicts:i,errors:e,inserted:a}};export{O as exportGlobalRows,M as importGlobalRows,R as selectGlobalTables};
@@ -1 +1 @@
1
- import{LunoraError as _}from"@lunora/errors";import{runD1GlobalTableMigrations as E}from"./backfillD1SearchIndexes-CQyY3tKe.mjs";import{quoteIdentifier as i}from"./quoteIdentifier-CObIFRhb.mjs";import{decodeGlobalRow as T}from"@lunora/sql-store";const v=50,y=500,L=30,g=200,N=(a,t,n)=>Math.min(Math.max(a,t),n),C=/^sqlite_|^_cf_|^d1_|^__cdc|__agg_|__rank_|__fts_/u,A=a=>C.test(a),h=/password|secret|token|hash|salt|credential/iu,O=async a=>(await a.all("SELECT name FROM sqlite_master WHERE type = 'table' ORDER BY name",[])).map(t=>String(t.name)).filter(t=>!A(t)),M=async(a,t,n)=>{if(await E(a,t),!(await O(a)).includes(n))throw new _("UNKNOWN_TABLE",`unknown table: ${n}`,{status:404})},p=async(a,t,n="",o=[])=>{const s=await a.all(`SELECT COUNT(*) AS c FROM ${t}${n}`,o);return Number(s[0]?.c??0)},$=(a,t,n)=>a.tables[t]!==void 0&&n==="_id"?"id":n,R=(a,t,n,o)=>{const s=[],l=[];for(const e of o??[]){if(!n.includes(e.column))throw new _("UNKNOWN_COLUMN",`unknown column: ${e.column}`,{status:404});if(a.tables[t]===void 0&&h.test(e.column))throw new _("FORBIDDEN",`cannot filter on a redacted column: ${e.column}`,{status:403});const r=i($(a,t,e.column));e.value===null||e.value===void 0?s.push(`${r} IS NULL`):(s.push(`${r} = ?`),l.push(e.value))}return{params:l,where:s.length>0?` WHERE ${s.join(" AND ")}`:""}},G=(a,t,n)=>{const o=a.tables[t];if(o)return T(o,n);const s={};for(const[l,e]of Object.entries(n))s[l]=e!=null&&h.test(l)?"•••":e;return s},S=async(a,t,n)=>{const o=t.tables[n];return o?["_id","_creationTime",...Object.keys(o.shape)]:(await a.all(`PRAGMA table_info(${i(n)})`,[])).map(s=>String(s.name))},U=async(a,t,n)=>{if(t.tables[n])return;const o=await a.all(`PRAGMA foreign_key_list(${i(n)})`,[]);if(o.length===0)return;const s={};for(const l of o){const e=String(l.from),r=String(l.table);s[e]??=r}return s},P=async(a,t)=>{await E(a,t);const n=await O(a);return Promise.all(n.map(async o=>({name:o,rowCount:await p(a,i(o))})))},B=async(a,t,n)=>{const{table:o}=n;await M(a,t,o);const s=N(Math.trunc(n.limit??v),1,y),l=Math.max(0,Math.trunc(n.offset??0)),e=i(o),r=await S(a,t,o),{params:m,where:c}=R(t,o,r,n.filters),w=await p(a,e,c,m),u=(await a.all(`SELECT * FROM ${e}${c} LIMIT ? OFFSET ?`,[...m,s,l])).map(d=>G(t,o,d)),f=await U(a,t,o);return f===void 0?{columns:r,rows:u,total:w}:{columns:r,refs:f,rows:u,total:w}},W=async(a,t,n)=>{const{column:o,table:s}=n;await M(a,t,s);const l=await S(a,t,s);if(!l.includes(o))throw new _("UNKNOWN_COLUMN",`unknown column: ${o}`,{status:404});const e=i(s),{params:r,where:m}=R(t,s,l,n.filters);if(t.tables[s]===void 0&&h.test(o)){const b=await p(a,e,m,r);return{truncated:!1,values:b===0?[]:[{count:b,value:"•••"}]}}const c=N(Math.trunc(n.limit??L),1,g),w=i($(t,s,o)),u=await a.all(`SELECT ${w} AS value, COUNT(*) AS count FROM ${e}${m} GROUP BY ${w} ORDER BY count DESC LIMIT ?`,[...r,c+1]),f=u.length>c,d=f?u.slice(0,c):u;return{truncated:f,values:d.map(b=>({count:Number(b.count),value:b.value}))}};export{W as facetGlobalColumn,P as listGlobalTables,B as readGlobalTablePage};
1
+ import{LunoraError as _}from"@lunora/errors";import{runD1GlobalTableMigrations as E}from"./backfillD1SearchIndexes-KCnA1HXB.mjs";import{quoteIdentifier as i}from"./quoteIdentifier-CObIFRhb.mjs";import{decodeGlobalRow as T}from"@lunora/sql-store";const v=50,y=500,L=30,g=200,N=(a,t,n)=>Math.min(Math.max(a,t),n),C=/^sqlite_|^_cf_|^d1_|^__cdc|__agg_|__rank_|__fts_/u,A=a=>C.test(a),h=/password|secret|token|hash|salt|credential/iu,O=async a=>(await a.all("SELECT name FROM sqlite_master WHERE type = 'table' ORDER BY name",[])).map(t=>String(t.name)).filter(t=>!A(t)),M=async(a,t,n)=>{if(await E(a,t),!(await O(a)).includes(n))throw new _("UNKNOWN_TABLE",`unknown table: ${n}`,{status:404})},p=async(a,t,n="",o=[])=>{const s=await a.all(`SELECT COUNT(*) AS c FROM ${t}${n}`,o);return Number(s[0]?.c??0)},$=(a,t,n)=>a.tables[t]!==void 0&&n==="_id"?"id":n,R=(a,t,n,o)=>{const s=[],l=[];for(const e of o??[]){if(!n.includes(e.column))throw new _("UNKNOWN_COLUMN",`unknown column: ${e.column}`,{status:404});if(a.tables[t]===void 0&&h.test(e.column))throw new _("FORBIDDEN",`cannot filter on a redacted column: ${e.column}`,{status:403});const r=i($(a,t,e.column));e.value===null||e.value===void 0?s.push(`${r} IS NULL`):(s.push(`${r} = ?`),l.push(e.value))}return{params:l,where:s.length>0?` WHERE ${s.join(" AND ")}`:""}},G=(a,t,n)=>{const o=a.tables[t];if(o)return T(o,n);const s={};for(const[l,e]of Object.entries(n))s[l]=e!=null&&h.test(l)?"•••":e;return s},S=async(a,t,n)=>{const o=t.tables[n];return o?["_id","_creationTime",...Object.keys(o.shape)]:(await a.all(`PRAGMA table_info(${i(n)})`,[])).map(s=>String(s.name))},U=async(a,t,n)=>{if(t.tables[n])return;const o=await a.all(`PRAGMA foreign_key_list(${i(n)})`,[]);if(o.length===0)return;const s={};for(const l of o){const e=String(l.from),r=String(l.table);s[e]??=r}return s},P=async(a,t)=>{await E(a,t);const n=await O(a);return Promise.all(n.map(async o=>({name:o,rowCount:await p(a,i(o))})))},B=async(a,t,n)=>{const{table:o}=n;await M(a,t,o);const s=N(Math.trunc(n.limit??v),1,y),l=Math.max(0,Math.trunc(n.offset??0)),e=i(o),r=await S(a,t,o),{params:m,where:c}=R(t,o,r,n.filters),w=await p(a,e,c,m),u=(await a.all(`SELECT * FROM ${e}${c} LIMIT ? OFFSET ?`,[...m,s,l])).map(d=>G(t,o,d)),f=await U(a,t,o);return f===void 0?{columns:r,rows:u,total:w}:{columns:r,refs:f,rows:u,total:w}},W=async(a,t,n)=>{const{column:o,table:s}=n;await M(a,t,s);const l=await S(a,t,s);if(!l.includes(o))throw new _("UNKNOWN_COLUMN",`unknown column: ${o}`,{status:404});const e=i(s),{params:r,where:m}=R(t,s,l,n.filters);if(t.tables[s]===void 0&&h.test(o)){const b=await p(a,e,m,r);return{truncated:!1,values:b===0?[]:[{count:b,value:"•••"}]}}const c=N(Math.trunc(n.limit??L),1,g),w=i($(t,s,o)),u=await a.all(`SELECT ${w} AS value, COUNT(*) AS count FROM ${e}${m} GROUP BY ${w} ORDER BY count DESC LIMIT ?`,[...r,c+1]),f=u.length>c,d=f?u.slice(0,c):u;return{truncated:f,values:d.map(b=>({count:Number(b.count),value:b.value}))}};export{W as facetGlobalColumn,P as listGlobalTables,B as readGlobalTablePage};
@@ -0,0 +1 @@
1
+ import{sqliteEncode as t,sqliteDecode as i}from"@lunora/sql-store";import{sql as n}from"drizzle-orm";import{MAX_D1_TABLE_COLUMNS as o,sqlAffinityForKind as r}from"../dialect.mjs";const s=/unique constraint failed/iu,T={companionTypes:{autoincrementPrimaryKey:"INTEGER PRIMARY KEY AUTOINCREMENT",integer:"INTEGER",key:"TEXT",real:"REAL",text:"TEXT"},columnType:r,decode:i,encode:t,frameworkColumns:()=>[{name:"id",type:"TEXT PRIMARY KEY"},{name:"_creationTime",type:"REAL NOT NULL"}],isUniqueViolation:e=>e instanceof Error&&s.test(e.message),maxTableColumns:o,name:"sqlite",supportsFts5:!0,supportsReturning:!0,tableExists:e=>n`SELECT name FROM sqlite_master WHERE type = 'table' AND name = ${e}`};export{T as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/d1",
3
- "version": "1.0.0-alpha.72",
3
+ "version": "1.0.0-alpha.74",
4
4
  "description": "D1 adapter for Lunora .global() tables, wrapping the Sessions API for read-your-writes",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -50,10 +50,10 @@
50
50
  "access": "public"
51
51
  },
52
52
  "dependencies": {
53
- "@lunora/errors": "1.0.0-alpha.18",
54
- "@lunora/platform": "1.0.0-alpha.8",
55
- "@lunora/shard-engine": "1.0.0-alpha.20",
56
- "@lunora/sql-store": "1.0.0-alpha.74",
53
+ "@lunora/errors": "1.0.0-alpha.20",
54
+ "@lunora/platform": "1.0.0-alpha.9",
55
+ "@lunora/shard-engine": "1.0.0-alpha.24",
56
+ "@lunora/sql-store": "1.0.0-alpha.76",
57
57
  "drizzle-orm": "^0.45.2"
58
58
  },
59
59
  "engines": {
@@ -1 +0,0 @@
1
- import{sqliteEncode as t,sqliteDecode as i}from"@lunora/sql-store";import{sql as n}from"drizzle-orm";import{sqlAffinityForKind as o}from"../dialect.mjs";const r=/unique constraint failed/iu,E={companionTypes:{autoincrementPrimaryKey:"INTEGER PRIMARY KEY AUTOINCREMENT",integer:"INTEGER",key:"TEXT",real:"REAL",text:"TEXT"},columnType:o,decode:i,encode:t,frameworkColumns:()=>[{name:"id",type:"TEXT PRIMARY KEY"},{name:"_creationTime",type:"REAL NOT NULL"}],isUniqueViolation:e=>e instanceof Error&&r.test(e.message),name:"sqlite",supportsFts5:!0,supportsReturning:!0,tableExists:e=>n`SELECT name FROM sqlite_master WHERE type = 'table' AND name = ${e}`};export{E as default};