@lunora/d1 1.0.0-alpha.206 → 1.0.0-alpha.207
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
CHANGED
|
@@ -94,6 +94,12 @@ interface ExportGlobalArgs {
|
|
|
94
94
|
*/
|
|
95
95
|
declare const exportGlobalRows: (exec: SqlCtxExec, schema: SchemaLike, args: ExportGlobalArgs) => AsyncGenerator<ExportRow, void, undefined>;
|
|
96
96
|
interface ImportGlobalArgs {
|
|
97
|
+
/**
|
|
98
|
+
* Check the rows and report their shape errors, writing nothing. The conflict
|
|
99
|
+
* probe and the insert are skipped, so an `_id` already in use and a foreign-key
|
|
100
|
+
* or unique failure are only found by a real import.
|
|
101
|
+
*/
|
|
102
|
+
dryRun?: boolean;
|
|
97
103
|
/**
|
|
98
104
|
* Optional direct exec handle to the same D1 database the writer targets.
|
|
99
105
|
* When supplied, the conflict pre-probe issues a single
|
package/dist/index.d.ts
CHANGED
|
@@ -94,6 +94,12 @@ interface ExportGlobalArgs {
|
|
|
94
94
|
*/
|
|
95
95
|
declare const exportGlobalRows: (exec: SqlCtxExec, schema: SchemaLike, args: ExportGlobalArgs) => AsyncGenerator<ExportRow, void, undefined>;
|
|
96
96
|
interface ImportGlobalArgs {
|
|
97
|
+
/**
|
|
98
|
+
* Check the rows and report their shape errors, writing nothing. The conflict
|
|
99
|
+
* probe and the insert are skipped, so an `_id` already in use and a foreign-key
|
|
100
|
+
* or unique failure are only found by a real import.
|
|
101
|
+
*/
|
|
102
|
+
dryRun?: boolean;
|
|
97
103
|
/**
|
|
98
104
|
* Optional direct exec handle to the same D1 database the writer targets.
|
|
99
105
|
* When supplied, the conflict pre-probe issues a single
|
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-CpdCm-Ki.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-B9B-UuDR.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};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{toErrorBody as p}from"@lunora/errors";import{needsWireEncoding as E,encodeWire as m,decodeWire as R}from"@lunora/wire";import{runD1GlobalTableMigrations as w}from"./backfillD1SearchIndexes-BHgn1SNb.mjs";import{quoteIdentifier as b}from"./quoteIdentifier-CObIFRhb.mjs";import{decodeGlobalRow as g}from"@lunora/sql-store";const k=200,O=(r,e)=>{const t=o=>r.tables[o]?.shardMode?.kind==="global";return e&&e.length>0?e.filter(o=>t(o)):Object.keys(r.tables).filter(o=>t(o))},h=(r,e,t)=>{const o=r.tables[e];return o?g(o,t):{_creationTime:t._creationTime,_id:t.id}},y=r=>E(r)?m(r):r,F=async function*(r,e,t){const o=O(e,t.tables),i=t.batchSize??k;await w(r,e);for(const s of o){const n=b(s);let c,l=!0;for(;l;){const a=c===void 0?await r.all(`SELECT * FROM ${n} ORDER BY "id" LIMIT ?`,[i]):await r.all(`SELECT * FROM ${n} WHERE "id" > ? ORDER BY "id" LIMIT ?`,[c,i]);for(const f of a)yield{doc:y(h(e,s,f)),table:s};const d=a.at(-1);d!==void 0&&(c=String(d.id)),l=a.length===i}}},u=r=>r?._meta?.column?.notNull===!1,I=(r,e)=>{const t=new Set;for(const[o,i]of Object.entries(r.shape)){if(e[o]!==null||i.kind!=="optional"||u(i))continue;const s=i._meta?.inner;u(s)||t.add(o)}return t.size===0?e:Object.fromEntries(Object.entries(e).filter(([o])=>!t.has(o)))},T=new Set(["_creationTime","_id"]),_=(r,e)=>Object.keys(e).find(t=>!T.has(t)&&!Object.hasOwn(r.shape,t)),S=(r,e,t)=>{const o=r.tables[e];if(!o)return`unknown table: ${e}`;const i=_(o,t);if(i!==void 0)return`unexpected field "${i}": not declared in table "${e}"`;for(const[s,n]of Object.entries(o.shape)){const c=t[s],l=n.kind==="optional";if(c===void 0&&l)continue;const a=n.parse;if(typeof a=="function")try{a(c)}catch(d){const f=d instanceof Error?d.message:String(d);return`field "${s}": ${f}`}}},v=async(r,e,t,o)=>{try{return e?(await e.all(`SELECT 1 AS hit FROM ${b(t)} WHERE "id" = ? LIMIT 1`,[o])).length>0:await r.get(o)!==null}catch{return!1}},A=async(r,e,t,o,i)=>{const{doc:s,table:n}=o;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 c;try{c=R(s)}catch(d){return{error:{code:"BAD_ROW",line:i,message:d instanceof Error?d.message:String(d),table:n},kind:"error"}}c=I(e.tables[n],c);const l=S(e,n,c);if(l!==void 0)return{error:{code:"VALIDATION_ERROR",line:i,message:l,table:n},kind:"error"};if(t.dryRun===!0)return{kind:"checked"};const a=typeof c._id=="string"?c._id:void 0;if(a!==void 0&&await v(r,t.exec,n,a))return{kind:"conflict"};try{return await r.insert(n,c,{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(r,e,t)=>{const o=[],i={};let s=0,n=(t.startLine??1)-1;for(const c of t.rows){n+=1;const l=c.line??n,a=await A(r,e,t,c,l);switch(a.kind){case"conflict":{s+=1;break}case"error":{o.push(a.error);break}case"inserted":{i[a.inserted]=(i[a.inserted]??0)+1;break}}}return{conflicts:s,errors:o,inserted:i}};export{F as exportGlobalRows,$ as importGlobalRows,O as selectGlobalTables};
|
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.207",
|
|
4
4
|
"description": "D1 adapter for Lunora .global() tables, wrapping the Sessions API for read-your-writes",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
@@ -52,8 +52,8 @@
|
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"@lunora/errors": ">=1.0.0-alpha.51 <2.0.0-0",
|
|
54
54
|
"@lunora/platform": "1.0.0-alpha.75",
|
|
55
|
-
"@lunora/shard-engine": "1.0.0-alpha.
|
|
56
|
-
"@lunora/sql-store": "1.0.0-alpha.
|
|
55
|
+
"@lunora/shard-engine": "1.0.0-alpha.159",
|
|
56
|
+
"@lunora/sql-store": "1.0.0-alpha.208",
|
|
57
57
|
"@lunora/wire": "1.0.0-alpha.2",
|
|
58
58
|
"drizzle-orm": "1.0.0-rc.5"
|
|
59
59
|
},
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{toErrorBody as p}from"@lunora/errors";import{needsWireEncoding as E,encodeWire as m,decodeWire as g}from"@lunora/wire";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,d=!0;for(;d;){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 l=c.at(-1);l!==void 0&&(a=String(l.id)),d=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],d=n.kind==="optional";if(a===void 0&&d)continue;const c=n.parse;if(typeof c=="function")try{c(a)}catch(l){const f=l instanceof Error?l.message:String(l);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(l){return{error:{code:"BAD_ROW",line:i,message:l instanceof Error?l.message:String(l),table:n},kind:"error"}}a=I(e.tables[n],a);const d=S(e,n,a);if(d!==void 0)return{error:{code:"VALIDATION_ERROR",line:i,message:d,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(l){const{body:f}=p(l,{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 d=a.line??n,c=await A(t,e,o,a,d);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};
|