@lunora/d1 1.0.0-alpha.97 → 1.0.0-alpha.99
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.d.mts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.mjs +1 -1
- package/dist/packem_shared/{backfillD1SearchIndexes-Cmdl902w.mjs → backfillD1SearchIndexes-V-i_kEvG.mjs} +1 -1
- package/dist/packem_shared/exportGlobalRows-HXokzq27.mjs +1 -0
- package/dist/packem_shared/facetGlobalColumn-DffEmxwO.mjs +1 -0
- package/dist/packem_shared/sqliteDialect-J6_WTDHg.mjs +1 -0
- package/dist/packem_shared/wire-codec-CPB7SbIW.mjs +1 -0
- package/package.json +5 -5
- package/dist/packem_shared/exportGlobalRows-DfPc1vS0.mjs +0 -1
- package/dist/packem_shared/facetGlobalColumn-BPToW_z0.mjs +0 -1
- package/dist/packem_shared/sqliteDialect-DZoYJOa-.mjs +0 -1
package/dist/index.d.mts
CHANGED
|
@@ -451,9 +451,10 @@ declare const withD1Retry: <T>(operation: () => Promise<T>, options?: D1RetryOpt
|
|
|
451
451
|
*/
|
|
452
452
|
declare const retryingExec: (exec: SqlCtxExec, options?: D1RetryOptions) => SqlCtxExec;
|
|
453
453
|
/**
|
|
454
|
-
* The canonical SQLite dialect: column affinities,
|
|
455
|
-
*
|
|
456
|
-
*
|
|
454
|
+
* The canonical SQLite dialect: column affinities, `RETURNING` support (both D1
|
|
455
|
+
* and `node:sqlite`), and `sqlite_master` table probing. The rest of the
|
|
456
|
+
* per-statement shaping is drizzle's. The value codec is NOT a dialect member —
|
|
457
|
+
* the store core runs `sqliteEncode`/`sqliteDecode` on every engine.
|
|
457
458
|
*/
|
|
458
459
|
declare const sqliteDialect: SqlDialect;
|
|
459
460
|
export { D1Client, type D1ContextDatabaseOptions as D1CtxDbOptions, type D1RetryOptions, D1Session, D1TimeoutError, type ExportGlobalArgs, type FacetGlobalColumnOptions, type ExportRow as GlobalExportRow, type GlobalFacetResult, type GlobalFacetValue, type GlobalFilterClause, type ImportError as GlobalImportError, type ImportResult as GlobalImportResult, type GlobalTableInfo, type GlobalTablePage, type ImportGlobalArgs, type Migration, MigrationRunner, type MigrationRunnerResult, type ReadGlobalTablePageOptions, backfillD1SearchIndexes, createD1ContextDatabase as createD1CtxDb, exportGlobalRows, facetGlobalColumn, importGlobalRows, isTransientD1Error, listGlobalTables, readD1CdcChanges, readGlobalTablePage, retryingExec, runD1AggregateMigrations, runD1CdcMigration, runD1GlobalTableMigrations, runD1RankMigrations, runD1SearchMigrations, selectGlobalTables, sqliteDialect, sweepD1CdcRetention, withD1Retry };
|
package/dist/index.d.ts
CHANGED
|
@@ -451,9 +451,10 @@ declare const withD1Retry: <T>(operation: () => Promise<T>, options?: D1RetryOpt
|
|
|
451
451
|
*/
|
|
452
452
|
declare const retryingExec: (exec: SqlCtxExec, options?: D1RetryOptions) => SqlCtxExec;
|
|
453
453
|
/**
|
|
454
|
-
* The canonical SQLite dialect: column affinities,
|
|
455
|
-
*
|
|
456
|
-
*
|
|
454
|
+
* The canonical SQLite dialect: column affinities, `RETURNING` support (both D1
|
|
455
|
+
* and `node:sqlite`), and `sqlite_master` table probing. The rest of the
|
|
456
|
+
* per-statement shaping is drizzle's. The value codec is NOT a dialect member —
|
|
457
|
+
* the store core runs `sqliteEncode`/`sqliteDecode` on every engine.
|
|
457
458
|
*/
|
|
458
459
|
declare const sqliteDialect: SqlDialect;
|
|
459
460
|
export { D1Client, type D1ContextDatabaseOptions as D1CtxDbOptions, type D1RetryOptions, D1Session, D1TimeoutError, type ExportGlobalArgs, type FacetGlobalColumnOptions, type ExportRow as GlobalExportRow, type GlobalFacetResult, type GlobalFacetValue, type GlobalFilterClause, type ImportError as GlobalImportError, type ImportResult as GlobalImportResult, type GlobalTableInfo, type GlobalTablePage, type ImportGlobalArgs, type Migration, MigrationRunner, type MigrationRunnerResult, type ReadGlobalTablePageOptions, backfillD1SearchIndexes, createD1ContextDatabase as createD1CtxDb, exportGlobalRows, facetGlobalColumn, importGlobalRows, isTransientD1Error, listGlobalTables, readD1CdcChanges, readGlobalTablePage, retryingExec, runD1AggregateMigrations, runD1CdcMigration, runD1GlobalTableMigrations, runD1RankMigrations, runD1SearchMigrations, selectGlobalTables, sqliteDialect, sweepD1CdcRetention, withD1Retry };
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{exportGlobalRows as o,importGlobalRows as t,selectGlobalTables as a}from"./packem_shared/exportGlobalRows-
|
|
1
|
+
import{exportGlobalRows as o,importGlobalRows as t,selectGlobalTables as a}from"./packem_shared/exportGlobalRows-HXokzq27.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-DffEmxwO.mjs";import{MigrationRunner as T}from"./packem_shared/MigrationRunner-SadkIbU5.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};
|
|
@@ -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-
|
|
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-J6_WTDHg.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};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{toErrorBody as u}from"@lunora/errors";import{n as p,e as g,d as m}from"./wire-codec-CPB7SbIW.mjs";import{runD1GlobalTableMigrations as E}from"./backfillD1SearchIndexes-V-i_kEvG.mjs";import{quoteIdentifier as b}from"./quoteIdentifier-CObIFRhb.mjs";import{decodeGlobalRow as R}from"@lunora/sql-store";const w=200,k=(e,o)=>{const i=r=>e.tables[r]?.shardMode?.kind==="global";return o&&o.length>0?o.filter(r=>i(r)):Object.keys(e.tables).filter(r=>i(r))},y=(e,o,i)=>{const r=e.tables[o];return r?R(r,i):{_creationTime:i._creationTime,_id:i.id}},I=e=>p(e)?g(e):e,M=async function*(e,o,i){const r=k(o,i.tables),n=i.batchSize??w;await E(e,o);for(const s of r){const t=b(s);let c,d=!0;for(;d;){const a=c===void 0?await e.all(`SELECT * FROM ${t} ORDER BY "id" LIMIT ?`,[n]):await e.all(`SELECT * FROM ${t} WHERE "id" > ? ORDER BY "id" LIMIT ?`,[c,n]);for(const f of a)yield{doc:I(y(o,s,f)),table:s};const l=a.at(-1);l!==void 0&&(c=String(l.id)),d=a.length===n}}},h=(e,o,i)=>{const r=e.tables[o];if(!r)return`unknown table: ${o}`;for(const[n,s]of Object.entries(r.shape)){const t=i[n],c=s.kind==="optional";if(t===void 0&&c)continue;const d=s.parse;if(typeof d=="function")try{d(t)}catch(a){const l=a instanceof Error?a.message:String(a);return`field "${n}": ${l}`}}},T=async(e,o,i,r)=>{try{return o?(await o.all(`SELECT 1 AS hit FROM ${b(i)} WHERE "id" = ? LIMIT 1`,[r])).length>0:await e.get(r)!==null}catch{return!1}},O=async(e,o,i,r,n)=>{const{doc:s,table:t}=r;if(typeof t!="string"||t.length===0)return{error:{code:"BAD_ROW",line:n,message:"row is missing `table`",table:t},kind:"error"};if(o.tables[t]?.shardMode?.kind!=="global")return{kind:"skip"};if(!s||typeof s!="object"||Array.isArray(s))return{error:{code:"BAD_ROW",line:n,message:"row is missing or malformed `doc`",table:t},kind:"error"};let c;try{c=m(s)}catch(l){return{error:{code:"BAD_ROW",line:n,message:l instanceof Error?l.message:String(l),table:t},kind:"error"}}const d=h(o,t,c);if(d!==void 0)return{error:{code:"VALIDATION_ERROR",line:n,message:d,table:t},kind:"error"};const a=typeof c._id=="string"?c._id:void 0;if(a!==void 0&&await T(e,i.exec,t,a))return{kind:"conflict"};try{return await e.insert(t,c,{allowExplicitId:!0}),{inserted:t,kind:"inserted"}}catch(l){const{body:f}=u(l,{fallbackCode:"INSERT_FAILED"});return{error:{code:f.code,line:n,message:f.message,table:t},kind:"error"}}},_=async(e,o,i)=>{const r=[],n={};let s=0,t=(i.startLine??1)-1;for(const c of i.rows){t+=1;const d=c.line??t,a=await O(e,o,i,c,d);switch(a.kind){case"conflict":{s+=1;break}case"error":{r.push(a.error);break}case"inserted":{n[a.inserted]=(n[a.inserted]??0)+1;break}}}return{conflicts:s,errors:r,inserted:n}};export{M as exportGlobalRows,_ as importGlobalRows,k as selectGlobalTables};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{LunoraError as E}from"@lunora/errors";import{n as R,e as p}from"./wire-codec-CPB7SbIW.mjs";import{runD1GlobalTableMigrations as M}from"./backfillD1SearchIndexes-V-i_kEvG.mjs";import{quoteIdentifier as i}from"./quoteIdentifier-CObIFRhb.mjs";import{decodeGlobalRow as I}from"@lunora/sql-store";const $=50,C=500,g=30,y=200,v=(t,o,n)=>Math.min(Math.max(t,o),n),U=/^sqlite_|^_cf_|^d1_|^__cdc|__agg_|__rank_|__fts_/u,F=t=>U.test(t),N=/password|secret|token|hash|salt|credential/iu,S=async t=>(await t.all("SELECT name FROM sqlite_master WHERE type = 'table' ORDER BY name",[])).map(n=>String(n.name)).filter(n=>!F(n)),h=async(t,o,n)=>{if(await M(t,o),!(await S(t)).includes(n))throw new E("UNKNOWN_TABLE",`unknown table: ${n}`,{status:404})},T=async(t,o,n="",a=[])=>{const e=await t.all(`SELECT COUNT(*) AS c FROM ${o}${n}`,a);return Number(e[0]?.c??0)},A=(t,o,n)=>t.tables[o]!==void 0&&n==="_id"?"id":n,L=(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&&N.test(s.column))throw new E("FORBIDDEN",`cannot filter on a redacted column: ${s.column}`,{status:403});const l=i(A(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 ")}`:""}},G=(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&&N.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},j=async(t,o)=>{await M(t,o);const n=await S(t);return Promise.all(n.map(async a=>({name:a,rowCount:await T(t,i(a))})))},K=async(t,o,n)=>{const{table:a}=n;await h(t,o,a);const e=v(Math.trunc(n.limit??$),1,C),r=Math.max(0,Math.trunc(n.offset??0)),s=i(a),l=await O(t,o,a),{params:w,where:u}=L(o,a,l,n.filters),f=await T(t,s,u,w),m=(await t.all(`SELECT * FROM ${s}${u} LIMIT ? OFFSET ?`,[...w,e,r])).map(c=>{const b=G(o,a,c);return R(b)?p(b):b}),_=await P(t,o,a);return _===void 0?{columns:l,rows:m,total:f}:{columns:l,refs:_,rows:m,total:f}},Y=async(t,o,n)=>{const{column:a,table:e}=n;await h(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}=L(o,e,r,n.filters);if(o.tables[e]===void 0&&N.test(a)){const c=await T(t,s,w,l);return{truncated:!1,values:c===0?[]:[{count:c,value:"•••"}]}}const u=v(Math.trunc(n.limit??g),1,y),f=i(A(o,e,a)),d=await t.all(`SELECT ${f} AS value, COUNT(*) AS count FROM ${s}${w} GROUP BY ${f} ORDER BY count DESC LIMIT ?`,[...l,u+1]),m=d.length>u,_=m?d.slice(0,u):d;return{truncated:m,values:_.map(c=>({count:Number(c.count),value:c.value}))}};export{Y as facetGlobalColumn,j as listGlobalTables,K as readGlobalTablePage};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{sql as t}from"drizzle-orm";import{MAX_D1_TABLE_COLUMNS as i,sqlAffinityForKind as n}from"../dialect.mjs";const s=/unique constraint failed/iu,E={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:i,name:"sqlite",supportsFts5:!0,supportsReturning:!0,tableExists:e=>t`SELECT name FROM sqlite_master WHERE type = 'table' AND name = ${e}`};export{E as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const d=r=>{let n="";for(let t=0;t<r.length;t+=32768)n+=String.fromCharCode(...r.subarray(t,t+32768));return btoa(n)},p=r=>{const n=atob(r),s=new Uint8Array(n.length);for(let t=0;t<n.length;t+=1)s[t]=n.codePointAt(t)??0;return s},i="$lunora.wire$";const g="__proto__",m={BigInt64Array,BigUint64Array,Float32Array,Float64Array,Int8Array,Int16Array,Int32Array,Uint8Array,Uint8ClampedArray,Uint16Array,Uint32Array},w={Error,EvalError,RangeError,ReferenceError,SyntaxError,TypeError,URIError},O=r=>{if(r===null||typeof r!="object")return!1;const n=Object.getPrototypeOf(r);return n===null||n===Object.prototype},E=(r,n=0)=>{if(n>64)return!0;if(r===null)return!1;const s=typeof r;if(s==="string"||s==="boolean")return!1;if(s==="number")return!Number.isFinite(r);if(s!=="object")return!0;if(Array.isArray(r))return r.length>0&&r[0]===i?!0:r.some(t=>t===void 0||E(t,n+1));if(!O(r)||Object.hasOwn(r,g))return!0;for(const t of Object.keys(r)){const c=r[t];if(c!==void 0&&E(c,n+1))return!0}return!1},y=(r,n=0)=>{if(n>64)throw new RangeError("wire-codec: value nesting exceeds the 64-level limit");if(r===void 0)return[i,"undefined"];if(r===null)return null;const s=typeof r;if(s==="bigint")return[i,"bigint",r.toString()];if(s==="number"){const e=r;return Number.isNaN(e)?[i,"nan"]:e===1/0?[i,"inf"]:e===-1/0?[i,"-inf"]:e}if(s!=="object")return r;if(r instanceof Date)return[i,"date",y(r.getTime(),n+1)];if(r instanceof Error){const e=r,o={};for(const a of Object.keys(e))e[a]!==void 0&&(o[a]=y(e[a],n+1));const f=[i,"error",e.name,e.message,o];return e.cause!==void 0&&f.push(y(e.cause,n+1)),f}if(r instanceof URL)return[i,"url",r.href];if(r instanceof Map)return[i,"map",[...r.entries()].map(([e,o])=>[y(e,n+1),y(o,n+1)])];if(r instanceof Set)return[i,"set",[...r].map(e=>y(e,n+1))];if(r instanceof ArrayBuffer)return[i,"bytes",d(new Uint8Array(r)),"ArrayBuffer"];if(ArrayBuffer.isView(r)){const e=r,o=e.constructor.name,f=new Uint8Array(e.buffer,e.byteOffset,e.byteLength);return o==="Uint8Array"?[i,"bytes",d(f)]:[i,"bytes",d(f),o]}if(Array.isArray(r)){const e=r.map(o=>y(o,n+1));return e.length>0&&e[0]===i?[i,"arr",e]:e}if(!O(r)){const e=r.constructor?.name??"value";throw new TypeError(`wire-codec: cannot encode a ${e} over the Lunora wire — only plain objects, arrays, and the supported built-ins (Date, Error, URL, Map, Set, ArrayBuffer/typed arrays, bigint) round-trip`)}const t=r,c={};for(const e of Object.keys(t)){const o=t[e];if(o===void 0)continue;const f=y(o,n+1);e===g?Object.defineProperty(c,e,{configurable:!0,enumerable:!0,value:f,writable:!0}):c[e]=f}return c},u=(r,n=0)=>{if(n>64)throw new RangeError("wire-codec: value nesting exceeds the 64-level limit");if(r===null||typeof r!="object")return r;if(Array.isArray(r)){if(r[0]===i)switch(r[1]){case"-inf":return-1/0;case"arr":return r[2].map(e=>u(e,n+1));case"bigint":{const e=r[2];if(typeof e!="string"||e.length>1024||!/^-?\d+$/.test(e))throw new RangeError("wire-codec: invalid or over-long bigint (max 1024 digits)");return BigInt(e)}case"date":return new Date(u(r[2],n+1));case"map":return new Map(r[2].map(([e,o])=>[u(e,n+1),u(o,n+1)]));case"set":return new Set(r[2].map(e=>u(e,n+1)));case"url":return new URL(r[2]);case"error":{const e=r[2],o=r[3],f=(Object.hasOwn(w,e)?w[e]:void 0)??Error,a=new f(o);a.name!==e&&Object.defineProperty(a,"name",{configurable:!0,value:e,writable:!0});const A=u(r[4],n+1);for(const b of Object.keys(A))b===g?Object.defineProperty(a,b,{configurable:!0,enumerable:!0,value:A[b],writable:!0}):a[b]=A[b];return r.length>5&&Object.defineProperty(a,"cause",{configurable:!0,value:u(r[5],n+1),writable:!0}),a}case"bytes":{const e=p(r[2]),o=r[3]??"Uint8Array";if(o==="ArrayBuffer")return e.buffer.byteLength===e.byteLength?e.buffer:e.slice().buffer;const f=Object.hasOwn(m,o)?m[o]:void 0;return f?new f(e.slice().buffer):e}case"inf":return 1/0;case"nan":return Number.NaN;case"undefined":return;default:return r.map(e=>u(e,n+1))}return r.map(c=>u(c,n+1))}const s=r,t={};for(const c of Object.keys(s)){const e=u(s[c],n+1);c===g?Object.defineProperty(t,c,{configurable:!0,enumerable:!0,value:e,writable:!0}):t[c]=e}return t};export{u as d,y as e,E as n};
|
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.99",
|
|
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.
|
|
54
|
-
"@lunora/platform": "1.0.0-alpha.
|
|
55
|
-
"@lunora/shard-engine": "1.0.0-alpha.
|
|
56
|
-
"@lunora/sql-store": "1.0.0-alpha.
|
|
53
|
+
"@lunora/errors": "1.0.0-alpha.26",
|
|
54
|
+
"@lunora/platform": "1.0.0-alpha.22",
|
|
55
|
+
"@lunora/shard-engine": "1.0.0-alpha.48",
|
|
56
|
+
"@lunora/sql-store": "1.0.0-alpha.101",
|
|
57
57
|
"drizzle-orm": "^0.45.2"
|
|
58
58
|
},
|
|
59
59
|
"engines": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{toErrorBody as u}from"@lunora/errors";import{runD1GlobalTableMigrations as p}from"./backfillD1SearchIndexes-Cmdl902w.mjs";import{quoteIdentifier as f}from"./quoteIdentifier-CObIFRhb.mjs";import{decodeGlobalRow as w}from"@lunora/sql-store";const R=200,g=(n,o)=>{const r=t=>n.tables[t]?.shardMode?.kind==="global";return o&&o.length>0?o.filter(t=>r(t)):Object.keys(n.tables).filter(t=>r(t))},m=(n,o,r)=>{const t=n.tables[o];return t?w(t,r):{_creationTime:r._creationTime,_id:r.id}},L=async function*(n,o,r){const t=g(o,r.tables),s=r.batchSize??R;await p(n,o);for(const i of t){const e=f(i);let c,l=!0;for(;l;){const a=c===void 0?await n.all(`SELECT * FROM ${e} ORDER BY "id" LIMIT ?`,[s]):await n.all(`SELECT * FROM ${e} WHERE "id" > ? ORDER BY "id" LIMIT ?`,[c,s]);for(const b of a)yield{doc:m(o,i,b),table:i};const d=a.at(-1);d!==void 0&&(c=String(d.id)),l=a.length===s}}},E=(n,o,r)=>{const t=n.tables[o];if(!t)return`unknown table: ${o}`;for(const[s,i]of Object.entries(t.shape)){const e=r[s],c=i.kind==="optional";if(e===void 0&&c)continue;const l=i.parse;if(typeof l=="function")try{l(e)}catch(a){const d=a instanceof Error?a.message:String(a);return`field "${s}": ${d}`}}},k=async(n,o,r,t)=>{try{return o?(await o.all(`SELECT 1 AS hit FROM ${f(r)} WHERE "id" = ? LIMIT 1`,[t])).length>0:await n.get(t)!==null}catch{return!1}},y=async(n,o,r,t,s)=>{const{doc:i,table:e}=t;if(typeof e!="string"||e.length===0)return{error:{code:"BAD_ROW",line:s,message:"row is missing `table`",table:e},kind:"error"};if(o.tables[e]?.shardMode?.kind!=="global")return{kind:"skip"};if(!i||typeof i!="object"||Array.isArray(i))return{error:{code:"BAD_ROW",line:s,message:"row is missing or malformed `doc`",table:e},kind:"error"};const c=E(o,e,i);if(c!==void 0)return{error:{code:"VALIDATION_ERROR",line:s,message:c,table:e},kind:"error"};const l=typeof i._id=="string"?i._id:void 0;if(l!==void 0&&await k(n,r.exec,e,l))return{kind:"conflict"};try{return await n.insert(e,i,{allowExplicitId:!0}),{inserted:e,kind:"inserted"}}catch(a){const{body:d}=u(a,{fallbackCode:"INSERT_FAILED"});return{error:{code:d.code,line:s,message:d.message,table:e},kind:"error"}}},_=async(n,o,r)=>{const t=[],s={};let i=0,e=(r.startLine??1)-1;for(const c of r.rows){e+=1;const l=c.line??e,a=await y(n,o,r,c,l);switch(a.kind){case"conflict":{i+=1;break}case"error":{t.push(a.error);break}case"inserted":{s[a.inserted]=(s[a.inserted]??0)+1;break}}}return{conflicts:i,errors:t,inserted:s}};export{L as exportGlobalRows,_ as importGlobalRows,g as selectGlobalTables};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{LunoraError as E}from"@lunora/errors";import{runD1GlobalTableMigrations as T}from"./backfillD1SearchIndexes-Cmdl902w.mjs";import{quoteIdentifier as i}from"./quoteIdentifier-CObIFRhb.mjs";import{decodeGlobalRow as O}from"@lunora/sql-store";const R=50,p=500,I=30,$=200,M=(t,a,n)=>Math.min(Math.max(t,a),n),C=/^sqlite_|^_cf_|^d1_|^__cdc|__agg_|__rank_|__fts_/u,y=t=>C.test(t),b=/password|secret|token|hash|salt|credential/iu,v=async t=>(await t.all("SELECT name FROM sqlite_master WHERE type = 'table' ORDER BY name",[])).map(n=>String(n.name)).filter(n=>!y(n)),S=async(t,a,n)=>{if(await T(t,a),!(await v(t)).includes(n))throw new E("UNKNOWN_TABLE",`unknown table: ${n}`,{status:404})},N=async(t,a,n="",o=[])=>{const s=await t.all(`SELECT COUNT(*) AS c FROM ${a}${n}`,o);return Number(s[0]?.c??0)},h=(t,a,n)=>t.tables[a]!==void 0&&n==="_id"?"id":n,A=(t,a,n,o)=>{const s=[],r=[];for(const e of o??[]){if(!n.includes(e.column))throw new E("UNKNOWN_COLUMN",`unknown column: ${e.column}`,{status:404});if(t.tables[a]===void 0&&b.test(e.column))throw new E("FORBIDDEN",`cannot filter on a redacted column: ${e.column}`,{status:403});const l=i(h(t,a,e.column));e.value===null||e.value===void 0?s.push(`${l} IS NULL`):(s.push(`${l} = ?`),r.push(e.value))}return{params:r,where:s.length>0?` WHERE ${s.join(" AND ")}`:""}},g=(t,a,n)=>{const o=t.tables[a];if(o)return O(o,n);const s={};for(const[r,e]of Object.entries(n))s[r]=e!=null&&b.test(r)?"•••":e;return s},L=async(t,a,n)=>{const o=a.tables[n];return o?["_id","_creationTime",...Object.keys(o.shape)]:(await t.all(`PRAGMA table_info(${i(n)})`,[])).map(r=>String(r.name))},U=async(t,a,n)=>{if(a.tables[n])return;const o=await t.all(`PRAGMA foreign_key_list(${i(n)})`,[]);if(o.length===0)return;const s={};for(const r of o){const e=String(r.from),l=String(r.table);s[e]??=l}return s},q=async(t,a)=>{await T(t,a);const n=await v(t);return Promise.all(n.map(async o=>({name:o,rowCount:await N(t,i(o))})))},D=async(t,a,n)=>{const{table:o}=n;await S(t,a,o);const s=M(Math.trunc(n.limit??R),1,p),r=Math.max(0,Math.trunc(n.offset??0)),e=i(o),l=await L(t,a,o),{params:w,where:u}=A(a,o,l,n.filters),f=await N(t,e,u,w),m=(await t.all(`SELECT * FROM ${e}${u} LIMIT ? OFFSET ?`,[...w,s,r])).map(c=>g(a,o,c)),_=await U(t,a,o);return _===void 0?{columns:l,rows:m,total:f}:{columns:l,refs:_,rows:m,total:f}},B=async(t,a,n)=>{const{column:o,table:s}=n;await S(t,a,s);const r=await L(t,a,s);if(!r.includes(o))throw new E("UNKNOWN_COLUMN",`unknown column: ${o}`,{status:404});const e=i(s),{params:l,where:w}=A(a,s,r,n.filters);if(a.tables[s]===void 0&&b.test(o)){const c=await N(t,e,w,l);return{truncated:!1,values:c===0?[]:[{count:c,value:"•••"}]}}const u=M(Math.trunc(n.limit??I),1,$),f=i(h(a,s,o)),d=await t.all(`SELECT ${f} AS value, COUNT(*) AS count FROM ${e}${w} GROUP BY ${f} ORDER BY count DESC LIMIT ?`,[...l,u+1]),m=d.length>u,_=m?d.slice(0,u):d;return{truncated:m,values:_.map(c=>({count:Number(c.count),value:c.value}))}};export{B as facetGlobalColumn,q as listGlobalTables,D as readGlobalTablePage};
|
|
@@ -1 +0,0 @@
|
|
|
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 s}from"../dialect.mjs";const a=/unique constraint failed/iu,l={companionTypes:{autoincrementPrimaryKey:"INTEGER PRIMARY KEY AUTOINCREMENT",integer:"INTEGER",key:"TEXT",real:"REAL",text:"TEXT"},columnType:s,decode:i,encode:t,frameworkColumns:()=>[{name:"id",type:"TEXT PRIMARY KEY"},{name:"_creationTime",type:"REAL NOT NULL"}],isUniqueViolation:e=>e instanceof Error&&a.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{l as default};
|