@lunora/d1 1.0.0-alpha.108 → 1.0.0-alpha.109
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/dialect.d.mts +5 -3
- package/dist/dialect.d.ts +5 -3
- package/dist/index.mjs +1 -1
- package/dist/packem_shared/MigrationRunner-BGcgKW27.mjs +2 -0
- package/dist/packem_shared/facetGlobalColumn-C6miqecw.mjs +1 -0
- package/package.json +4 -4
- package/dist/packem_shared/MigrationRunner-BcrG_upP.mjs +0 -2
- package/dist/packem_shared/facetGlobalColumn-x5_cK28F.mjs +0 -1
package/dist/dialect.d.mts
CHANGED
|
@@ -51,9 +51,11 @@ type SqlAffinity = "BLOB" | "INTEGER" | "REAL" | "TEXT";
|
|
|
51
51
|
* - `boolean` → INTEGER (stored as 1/0)
|
|
52
52
|
* - `number`/`timestamp`/`date` → REAL (numeric, never coerced to text)
|
|
53
53
|
* - `bytes` → BLOB
|
|
54
|
-
* - everything else → TEXT — string/id/literal, `bigint` (
|
|
55
|
-
*
|
|
56
|
-
*
|
|
54
|
+
* - everything else → TEXT — string/id/literal, `bigint` (the order-preserving
|
|
55
|
+
* 40-character key `bigintSqlKey` builds: a sign character plus 39 digits, so
|
|
56
|
+
* text comparison agrees with numeric comparison and an index range scan is
|
|
57
|
+
* correct), and object/array/record/union/any (JSON). A numeric affinity would
|
|
58
|
+
* coerce a numeric-looking string and corrupt the decode.
|
|
57
59
|
*/
|
|
58
60
|
declare const sqlAffinityForKind: (kind: string | undefined) => SqlAffinity;
|
|
59
61
|
/**
|
package/dist/dialect.d.ts
CHANGED
|
@@ -51,9 +51,11 @@ type SqlAffinity = "BLOB" | "INTEGER" | "REAL" | "TEXT";
|
|
|
51
51
|
* - `boolean` → INTEGER (stored as 1/0)
|
|
52
52
|
* - `number`/`timestamp`/`date` → REAL (numeric, never coerced to text)
|
|
53
53
|
* - `bytes` → BLOB
|
|
54
|
-
* - everything else → TEXT — string/id/literal, `bigint` (
|
|
55
|
-
*
|
|
56
|
-
*
|
|
54
|
+
* - everything else → TEXT — string/id/literal, `bigint` (the order-preserving
|
|
55
|
+
* 40-character key `bigintSqlKey` builds: a sign character plus 39 digits, so
|
|
56
|
+
* text comparison agrees with numeric comparison and an index range scan is
|
|
57
|
+
* correct), and object/array/record/union/any (JSON). A numeric affinity would
|
|
58
|
+
* coerce a numeric-looking string and corrupt the decode.
|
|
57
59
|
*/
|
|
58
60
|
declare const sqlAffinityForKind: (kind: string | undefined) => SqlAffinity;
|
|
59
61
|
/**
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{exportGlobalRows as o,importGlobalRows as t,selectGlobalTables as a}from"./packem_shared/exportGlobalRows-Ce_8Iuja.mjs";import{D1Client as i,D1Session as n}from"./packem_shared/D1Client-CzS0Qfa6.mjs";import{backfillD1SearchIndexes as D,createD1CtxDb as b,readD1CdcChanges as p,runD1AggregateMigrations as x,runD1CdcMigration as c,runD1GlobalTableMigrations as g,runD1RankMigrations as f,runD1SearchMigrations as m,sweepD1CdcRetention as C}from"./packem_shared/backfillD1SearchIndexes-V-i_kEvG.mjs";import{facetGlobalColumn as d,listGlobalTables as G,readGlobalTablePage as M}from"./packem_shared/facetGlobalColumn-
|
|
1
|
+
import{exportGlobalRows as o,importGlobalRows as t,selectGlobalTables as a}from"./packem_shared/exportGlobalRows-Ce_8Iuja.mjs";import{D1Client as i,D1Session as n}from"./packem_shared/D1Client-CzS0Qfa6.mjs";import{backfillD1SearchIndexes as D,createD1CtxDb as b,readD1CdcChanges as p,runD1AggregateMigrations as x,runD1CdcMigration as c,runD1GlobalTableMigrations as g,runD1RankMigrations as f,runD1SearchMigrations as m,sweepD1CdcRetention as C}from"./packem_shared/backfillD1SearchIndexes-V-i_kEvG.mjs";import{facetGlobalColumn as d,listGlobalTables as G,readGlobalTablePage as M}from"./packem_shared/facetGlobalColumn-C6miqecw.mjs";import{MigrationRunner as T}from"./packem_shared/MigrationRunner-BGcgKW27.mjs";import{D1TimeoutError as w,isTransientD1Error as S,retryingExec as y,withD1Retry as E}from"./packem_shared/D1TimeoutError-D4YUqZPk.mjs";import{default as q}from"./packem_shared/sqliteDialect-J6_WTDHg.mjs";import{applyCdcChanges as I}from"@lunora/shard-engine";import{createSqlCtxDb as j}from"@lunora/sql-store";export{i as D1Client,n as D1Session,w as D1TimeoutError,T as MigrationRunner,I as applyCdcChanges,D as backfillD1SearchIndexes,b as createD1CtxDb,j as createSqlCtxDb,o as exportGlobalRows,d as facetGlobalColumn,t as importGlobalRows,S as isTransientD1Error,G as listGlobalTables,p as readD1CdcChanges,M as readGlobalTablePage,y as retryingExec,x as runD1AggregateMigrations,c as runD1CdcMigration,g as runD1GlobalTableMigrations,f as runD1RankMigrations,m as runD1SearchMigrations,a as selectGlobalTables,q as sqliteDialect,C as sweepD1CdcRetention,E as withD1Retry};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{LunoraError as d}from"@lunora/errors";import{sql as m}from"drizzle-orm";import{D1Client as T}from"./D1Client-CzS0Qfa6.mjs";const p="__drizzle_migrations",I=`CREATE TABLE IF NOT EXISTS ${p} (id INTEGER PRIMARY KEY AUTOINCREMENT, hash TEXT NOT NULL UNIQUE, created_at NUMERIC)`,A=/\s/u,N=/[$\w]/u,g=String.raw`(?:\s|--[^\n]*\n|\/\*[\s\S]*?\*\/)`,v=/^(?:\s|--[^\n]*(?:\n|$)|\/\*[\s\S]*?\*\/)*/u,_=new RegExp(String.raw`^CREATE${g}+(?:TEMP${g}+|TEMPORARY${g}+)?TRIGGER\b`,"iu"),L=/^[0-9a-f]{64}$/u,$=new RegExp(String.raw`UNIQUE constraint failed:\s*${p}\.hash`,"iu"),C=l=>{const e=l.sql,t=_.test(e.slice(v.exec(e)?.[0].length??0));let i=!1,o=!1,c=!1,r=!1,s=!1,f=!1,h,R="",S=!1,E=!1;for(let a=0;a<e.length;a+=1){const n=e[a],u=e[a+1];if(s){n===`
|
|
2
|
+
`&&(s=!1);continue}if(f){n==="*"&&u==="/"&&(f=!1,a+=1);continue}if(i){n==="'"&&(u==="'"?a+=1:i=!1);continue}if(o){n==='"'&&(u==='"'?a+=1:o=!1);continue}if(c){n==="]"&&(c=!1);continue}if(r){n==="`"&&(u==="`"?a+=1:r=!1);continue}if(n==="-"&&u==="-"){s=!0,a+=1;continue}if(n==="/"&&u==="*"){f=!0,a+=1;continue}if(h!==void 0){if(n!==void 0&&!A.test(n))throw new d("INTERNAL",`Migration "${l.name}" (v${String(l.version)}) contains more than one SQL statement. Split it into separate migrations — batch() runs them atomically.`);continue}if(t&&n!==void 0){if(N.test(n)){R+=n;continue}const w=R.toUpperCase();R="",w!==""?(S=E&&w==="END",E=!1):n!==";"&&!A.test(n)&&(S=!1,E=!1)}if(n==="'"){i=!0;continue}if(n==='"'){o=!0;continue}if(n==="["){c=!0;continue}if(n==="`"){r=!0;continue}if(n===";"){if(t&&!S){E=!0;continue}h=a}}return h},U=async l=>{const e=new TextEncoder().encode(l),t=await crypto.subtle.digest("SHA-256",e);return[...new Uint8Array(t)].map(i=>i.toString(16).padStart(2,"0")).join("")};class M{client;migrations;constructor(e,t){this.client=e instanceof T?e:new T(e),this.migrations=[...t].toSorted((i,o)=>i.version-o.version),this.assertUniqueVersions(),this.assertUniqueSql()}async run(){await this.client.drizzle.run(m.raw(I));const e=await this.client.drizzle.all(m.raw(`SELECT hash FROM ${p}`)),t=new Set(e.map(r=>r.hash)),i=[],o=[],c=await Promise.all(this.migrations.map(async r=>U(r.sql)));for(const[r,s]of this.migrations.entries()){const f=c[r];if(t.has(f)){o.push({name:s.name,version:s.version});continue}await this.applyOne(s,f)?i.push({name:s.name,version:s.version}):o.push({name:s.name,version:s.version})}return{applied:i,skipped:o}}async applyOne(e,t){const i=C(e),o=(i===void 0?e.sql:e.sql.slice(0,i)).trim();if(!L.test(t))throw new d("INTERNAL",`migration "${e.name}" produced a non-hex hash; refusing to inline into SQL`);const c=`INSERT INTO ${p} (hash, created_at) VALUES ('${t}', ${String(Date.now())})`,r=[this.client.drizzle.run(m.raw(o)),this.client.drizzle.run(m.raw(c))];try{await this.client.batch(r)}catch(s){if($.test(s instanceof Error?s.message:String(s)))return!1;throw s}return!0}assertUniqueVersions(){const e=new Set;for(const t of this.migrations){if(e.has(t.version))throw new d("INTERNAL",`Duplicate migration version ${String(t.version)}`);e.add(t.version)}}assertUniqueSql(){const e=new Map;for(const t of this.migrations){const i=e.get(t.sql);if(i!==void 0)throw new d("INTERNAL",`Migrations ${String(i)} and ${String(t.version)} have identical SQL — bump the content, not just the version.`);e.set(t.sql,t.version)}}}export{M as MigrationRunner,p as TRACKING_TABLE_NAME};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{LunoraError as E}from"@lunora/errors";import{sqliteEncode as y,decodeGlobalRow as C}from"@lunora/sql-store";import{n as p,e as R}from"./wire-codec-DSSeKXyE.mjs";import{runD1GlobalTableMigrations as v}from"./backfillD1SearchIndexes-V-i_kEvG.mjs";import{TRACKING_TABLE_NAME as I}from"./MigrationRunner-BGcgKW27.mjs";import{quoteIdentifier as l}from"./quoteIdentifier-CObIFRhb.mjs";const k=50,G=500,U=30,D=200,S=(t,o,n)=>Math.min(Math.max(t,o),n),F=new RegExp(`^sqlite_|^_cf_|^d1_|^__cdc|^__lunora_|^${I}$|__agg_|__rank_|__fts_`,"u"),P=t=>F.test(t),A=/password|secret|token|hash|salt|credential/iu,u=(t,o)=>{const n=t.tables[o];return n?.shardMode?.kind==="global"?n:void 0},$=async t=>(await t.all("SELECT name FROM sqlite_master WHERE type = 'table' ORDER BY name",[])).map(n=>String(n.name)).filter(n=>!P(n)),O=async(t,o,n)=>{if(await v(t,o),!(await $(t)).includes(n))throw new E("UNKNOWN_TABLE",`unknown table: ${n}`,{status:404})},M=async(t,o,n="",e=[])=>{const a=await t.all(`SELECT COUNT(*) AS c FROM ${o}${n}`,e);return Number(a[0]?.c??0)},g=(t,o,n)=>u(t,o)!==void 0&&n==="_id"?"id":n,h=(t,o,n,e)=>{const a=[],s=[];for(const r of e??[]){if(!n.includes(r.column))throw new E("UNKNOWN_COLUMN",`unknown column: ${r.column}`,{status:404});if(u(t,o)===void 0&&A.test(r.column))throw new E("FORBIDDEN",`cannot filter on a redacted column: ${r.column}`,{status:403});const i=l(g(t,o,r.column));r.value===null||r.value===void 0?a.push(`${i} IS NULL`):(a.push(`${i} = ?`),s.push(y(r.value)))}return{params:s,where:a.length>0?` WHERE ${a.join(" AND ")}`:""}},q=(t,o,n)=>{const e=u(t,o);if(e)return C(e,n);const a={};for(const[s,r]of Object.entries(n))a[s]=r!=null&&A.test(s)?"•••":r;return a},L=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(s=>String(s.name))},B=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 a={};for(const s of e){const r=String(s.from),i=String(s.table);a[r]??=i}return a},V=async(t,o)=>{await v(t,o);const n=await $(t);return Promise.all(n.map(async e=>({name:e,rowCount:await M(t,l(e))})))},W=async(t,o,n,e)=>{if(u(o,n)!==void 0)return l("id");const s=(await t.all(`PRAGMA table_info(${l(n)})`,[])).filter(r=>Number(r.pk??0)>0);return s.length===1?l(String(s[0]?.name)):e.includes("id")?l("id"):"rowid"},z=async(t,o,n)=>{const{table:e}=n;await O(t,o,e);const a=S(Math.trunc(n.limit??k),1,G),s=Math.max(0,Math.trunc(n.offset??0)),r=l(e),i=await L(t,o,e),{params:m,where:d}=h(o,e,i,n.filters),f=await M(t,r,d,m),_=await W(t,o,e,i),T=(await t.all(`SELECT * FROM ${r}${d} ORDER BY ${_} LIMIT ? OFFSET ?`,[...m,a,s])).map(c=>{const b=q(o,e,c);return p(b)?R(b):b}),w=await B(t,o,e);return w===void 0?{columns:i,rows:T,total:f}:{columns:i,refs:w,rows:T,total:f}},J=async(t,o,n)=>{const{column:e,table:a}=n;await O(t,o,a);const s=await L(t,o,a);if(!s.includes(e))throw new E("UNKNOWN_COLUMN",`unknown column: ${e}`,{status:404});const r=l(a),{params:i,where:m}=h(o,a,s,n.filters);if(u(o,a)===void 0&&A.test(e)){const c=await M(t,r,m,i);return{truncated:!1,values:c===0?[]:[{count:c,value:"•••"}]}}const d=S(Math.trunc(n.limit??U),1,D),f=l(g(o,a,e)),_=await t.all(`SELECT ${f} AS value, COUNT(*) AS count FROM ${r}${m} GROUP BY ${f} ORDER BY count DESC, ${f} ASC LIMIT ?`,[...i,d+1]),N=_.length>d,w=(N?_.slice(0,d):_).map(c=>({count:Number(c.count),value:c.value}));return{truncated:N,values:p(w)?R(w):w}};export{J as facetGlobalColumn,V as listGlobalTables,z as readGlobalTablePage};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lunora/d1",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.109",
|
|
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.
|
|
53
|
+
"@lunora/errors": "1.0.0-alpha.32",
|
|
54
54
|
"@lunora/platform": "1.0.0-alpha.26",
|
|
55
|
-
"@lunora/shard-engine": "1.0.0-alpha.
|
|
56
|
-
"@lunora/sql-store": "1.0.0-alpha.
|
|
55
|
+
"@lunora/shard-engine": "1.0.0-alpha.56",
|
|
56
|
+
"@lunora/sql-store": "1.0.0-alpha.109",
|
|
57
57
|
"drizzle-orm": "^0.45.2"
|
|
58
58
|
},
|
|
59
59
|
"engines": {
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{LunoraError as d}from"@lunora/errors";import{sql as m}from"drizzle-orm";import{D1Client as g}from"./D1Client-CzS0Qfa6.mjs";const p="__drizzle_migrations",T=`CREATE TABLE IF NOT EXISTS ${p} (id INTEGER PRIMARY KEY AUTOINCREMENT, hash TEXT NOT NULL UNIQUE, created_at NUMERIC)`,w=/\s/u,A=/[$\w]/u,R=String.raw`(?:\s|--[^\n]*\n|\/\*[\s\S]*?\*\/)`,I=/^(?:\s|--[^\n]*(?:\n|$)|\/\*[\s\S]*?\*\/)*/u,N=new RegExp(String.raw`^CREATE${R}+(?:TEMP${R}+|TEMPORARY${R}+)?TRIGGER\b`,"iu"),v=/^[0-9a-f]{64}$/u,_=new RegExp(String.raw`UNIQUE constraint failed:\s*${p}\.hash`,"iu"),L=l=>{const t=l.sql,e=N.test(t.slice(I.exec(t)?.[0].length??0));let n=!1,o=!1,c=!1,r=!1,i,f="",u=!1,E=!1;for(let a=0;a<t.length;a+=1){const s=t[a],h=t[a+1];if(c){s===`
|
|
2
|
-
`&&(c=!1);continue}if(r){s==="*"&&h==="/"&&(r=!1,a+=1);continue}if(n){s==="'"&&(h==="'"?a+=1:n=!1);continue}if(o){s==='"'&&(h==='"'?a+=1:o=!1);continue}if(s==="-"&&h==="-"){c=!0,a+=1;continue}if(s==="/"&&h==="*"){r=!0,a+=1;continue}if(i!==void 0){if(s!==void 0&&!w.test(s))throw new d("INTERNAL",`Migration "${l.name}" (v${String(l.version)}) contains more than one SQL statement. Split it into separate migrations — batch() runs them atomically.`);continue}if(e&&s!==void 0){if(A.test(s)){f+=s;continue}const S=f.toUpperCase();f="",S!==""?(u=E&&S==="END",E=!1):s!==";"&&!w.test(s)&&(u=!1,E=!1)}if(s==="'"){n=!0;continue}if(s==='"'){o=!0;continue}if(s===";"){if(e&&!u){E=!0;continue}i=a}}return i},$=async l=>{const t=new TextEncoder().encode(l),e=await crypto.subtle.digest("SHA-256",t);return[...new Uint8Array(e)].map(n=>n.toString(16).padStart(2,"0")).join("")};class q{client;migrations;constructor(t,e){this.client=t instanceof g?t:new g(t),this.migrations=[...e].toSorted((n,o)=>n.version-o.version),this.assertUniqueVersions(),this.assertUniqueSql()}async run(){await this.client.drizzle.run(m.raw(T));const t=await this.client.drizzle.all(m.raw(`SELECT hash FROM ${p}`)),e=new Set(t.map(r=>r.hash)),n=[],o=[],c=await Promise.all(this.migrations.map(async r=>$(r.sql)));for(const[r,i]of this.migrations.entries()){const f=c[r];if(e.has(f)){o.push({name:i.name,version:i.version});continue}await this.applyOne(i,f)?n.push({name:i.name,version:i.version}):o.push({name:i.name,version:i.version})}return{applied:n,skipped:o}}async applyOne(t,e){const n=L(t),o=(n===void 0?t.sql:t.sql.slice(0,n)).trim();if(!v.test(e))throw new d("INTERNAL",`migration "${t.name}" produced a non-hex hash; refusing to inline into SQL`);const c=`INSERT INTO ${p} (hash, created_at) VALUES ('${e}', ${String(Date.now())})`,r=[this.client.drizzle.run(m.raw(o)),this.client.drizzle.run(m.raw(c))];try{await this.client.batch(r)}catch(i){if(_.test(i instanceof Error?i.message:String(i)))return!1;throw i}return!0}assertUniqueVersions(){const t=new Set;for(const e of this.migrations){if(t.has(e.version))throw new d("INTERNAL",`Duplicate migration version ${String(e.version)}`);t.add(e.version)}}assertUniqueSql(){const t=new Map;for(const e of this.migrations){const n=t.get(e.sql);if(n!==void 0)throw new d("INTERNAL",`Migrations ${String(n)} and ${String(e.version)} have identical SQL — bump the content, not just the version.`);t.set(e.sql,e.version)}}}export{q as MigrationRunner,p as TRACKING_TABLE_NAME};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{LunoraError as E}from"@lunora/errors";import{sqliteEncode as $,decodeGlobalRow as I}from"@lunora/sql-store";import{n as M,e as A}from"./wire-codec-DSSeKXyE.mjs";import{runD1GlobalTableMigrations as p}from"./backfillD1SearchIndexes-V-i_kEvG.mjs";import{TRACKING_TABLE_NAME as C}from"./MigrationRunner-BcrG_upP.mjs";import{quoteIdentifier as i}from"./quoteIdentifier-CObIFRhb.mjs";const g=50,y=500,U=30,F=200,v=(t,o,n)=>Math.min(Math.max(t,o),n),G=new RegExp(`^sqlite_|^_cf_|^d1_|^__cdc|^__lunora_|^${C}$|__agg_|__rank_|__fts_`,"u"),k=t=>G.test(t),T=/password|secret|token|hash|salt|credential/iu,R=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)),L=async(t,o,n)=>{if(await p(t,o),!(await R(t)).includes(n))throw new E("UNKNOWN_TABLE",`unknown table: ${n}`,{status:404})},b=async(t,o,n="",a=[])=>{const e=await t.all(`SELECT COUNT(*) AS c FROM ${o}${n}`,a);return Number(e[0]?.c??0)},S=(t,o,n)=>t.tables[o]!==void 0&&n==="_id"?"id":n,h=(t,o,n,a)=>{const e=[],r=[];for(const s of a??[]){if(!n.includes(s.column))throw new E("UNKNOWN_COLUMN",`unknown column: ${s.column}`,{status:404});if(t.tables[o]===void 0&&T.test(s.column))throw new E("FORBIDDEN",`cannot filter on a redacted column: ${s.column}`,{status:403});const l=i(S(t,o,s.column));s.value===null||s.value===void 0?e.push(`${l} IS NULL`):(e.push(`${l} = ?`),r.push($(s.value)))}return{params:r,where:e.length>0?` WHERE ${e.join(" AND ")}`:""}},q=(t,o,n)=>{const a=t.tables[o];if(a)return I(a,n);const e={};for(const[r,s]of Object.entries(n))e[r]=s!=null&&T.test(r)?"•••":s;return e},O=async(t,o,n)=>{const a=o.tables[n];return a?["_id","_creationTime",...Object.keys(a.shape)]:(await t.all(`PRAGMA table_info(${i(n)})`,[])).map(r=>String(r.name))},P=async(t,o,n)=>{if(o.tables[n])return;const a=await t.all(`PRAGMA foreign_key_list(${i(n)})`,[]);if(a.length===0)return;const e={};for(const r of a){const s=String(r.from),l=String(r.table);e[s]??=l}return e},H=async(t,o)=>{await p(t,o);const n=await R(t);return Promise.all(n.map(async a=>({name:a,rowCount:await b(t,i(a))})))},X=async(t,o,n)=>{const{table:a}=n;await L(t,o,a);const e=v(Math.trunc(n.limit??g),1,y),r=Math.max(0,Math.trunc(n.offset??0)),s=i(a),l=await O(t,o,a),{params:w,where:u}=h(o,a,l,n.filters),m=await b(t,s,u,w),f=(await t.all(`SELECT * FROM ${s}${u} LIMIT ? OFFSET ?`,[...w,e,r])).map(d=>{const c=q(o,a,d);return M(c)?A(c):c}),N=await P(t,o,a);return N===void 0?{columns:l,rows:f,total:m}:{columns:l,refs:N,rows:f,total:m}},Z=async(t,o,n)=>{const{column:a,table:e}=n;await L(t,o,e);const r=await O(t,o,e);if(!r.includes(a))throw new E("UNKNOWN_COLUMN",`unknown column: ${a}`,{status:404});const s=i(e),{params:l,where:w}=h(o,e,r,n.filters);if(o.tables[e]===void 0&&T.test(a)){const c=await b(t,s,w,l);return{truncated:!1,values:c===0?[]:[{count:c,value:"•••"}]}}const u=v(Math.trunc(n.limit??U),1,F),m=i(S(o,e,a)),_=await t.all(`SELECT ${m} AS value, COUNT(*) AS count FROM ${s}${w} GROUP BY ${m} ORDER BY count DESC LIMIT ?`,[...l,u+1]),f=_.length>u,d=(f?_.slice(0,u):_).map(c=>({count:Number(c.count),value:c.value}));return{truncated:f,values:M(d)?A(d):d}};export{Z as facetGlobalColumn,H as listGlobalTables,X as readGlobalTablePage};
|