@lunora/shard-engine 1.0.0-alpha.26 → 1.0.0-alpha.28
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/conformance/index.mjs +1 -1
- package/dist/index.d.mts +7 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.mjs +1 -1
- package/dist/packem_shared/ADMIN_FUNCTIONS-Ddr79XHG.mjs +1 -0
- package/dist/packem_shared/AGGREGATE_SQL_FUNCTION-m1iUU1rv.mjs +1 -0
- package/dist/packem_shared/AGG_COUNT-DOlqqroz.mjs +1 -0
- package/dist/packem_shared/AUDIT_LOG_TABLE-uNVU9O1W.mjs +8 -0
- package/dist/packem_shared/CDC_LOG_TABLE-B58N8NQO.mjs +8 -0
- package/dist/packem_shared/CLIENT_WATERMARK_TABLE-BoS1HEqz.mjs +7 -0
- package/dist/packem_shared/CountRlsUnsupportedError-Bdfupt3g.mjs +1 -0
- package/dist/packem_shared/DATA_MIGRATION_STATE_TABLE-4l6aU1Vc.mjs +31 -0
- package/dist/packem_shared/DEFAULT_MAX_RELATION_KEYS-BAWGIEvC.mjs +1 -0
- package/dist/packem_shared/DEFAULT_MAX_RELAYS-DeVcEXBh.mjs +1 -0
- package/dist/packem_shared/DEFAULT_PROMOTION_THRESHOLDS-DVTD9iu0.mjs +1 -0
- package/dist/packem_shared/DEFAULT_TRANSACTION_LIMITS-Bcoi7Bvf.mjs +1 -0
- package/dist/packem_shared/DurableStreamRunner-Bm6KDMBU.mjs +1 -0
- package/dist/packem_shared/GEO_DEFAULT_PRECISION-CqpQZ-J_.mjs +1 -0
- package/dist/packem_shared/GLOBAL_SHAPE_SNAPSHOT_TABLE-NWaL77m5.mjs +7 -0
- package/dist/packem_shared/IDEMPOTENCY_TABLE-DKVe2Ohf.mjs +7 -0
- package/dist/packem_shared/MAIL_RETENTION-Cig9Dmc8.mjs +18 -0
- package/dist/packem_shared/MAX_SQL_ROWS-DnDyeZph.mjs +2 -0
- package/dist/packem_shared/NotUniqueError-BixDiv4O.mjs +1 -0
- package/dist/packem_shared/QUEUE_TABLE-zj9Tt6tk.mjs +17 -0
- package/dist/packem_shared/RANK_TIEBREAK-ci3MaM65.mjs +1 -0
- package/dist/packem_shared/RELATION_EXISTS_KEY-CFUhnZSZ.mjs +1 -0
- package/dist/packem_shared/REPROJECTION_MIGRATION_PREFIX-Czcb6_mO.mjs +1 -0
- package/dist/packem_shared/RLS_UNWRAP_SYMBOL-BWloGsd3.mjs +1 -0
- package/dist/packem_shared/ReactiveCache-DfyeaJOA.mjs +1 -0
- package/dist/packem_shared/SCAN_DEP-D7qE3iUe.mjs +1 -0
- package/dist/packem_shared/SCHEMA_HISTORY_MAX_VERSIONS-DsycDXWm.mjs +6 -0
- package/dist/packem_shared/SEARCH_STATE_TABLE-Dju8ebbU.mjs +1 -0
- package/dist/packem_shared/SHAPE_POKE_CURSOR_TABLE-Dh4HfSdC.mjs +7 -0
- package/dist/packem_shared/ShardRunner-C9p5DVOx.mjs +1 -0
- package/dist/packem_shared/aggregateTableName-Cy5e03oz.mjs +1 -0
- package/dist/packem_shared/appendStreamChunk-CH4e4nJn.mjs +19 -0
- package/dist/packem_shared/applyOnDelete-BlcwKjuO.mjs +1 -0
- package/dist/packem_shared/applySelect-BQbHyo-W.mjs +1 -0
- package/dist/packem_shared/{armRestore-BNzdvQ_o.mjs → armRestore-Bu1_8SUa.mjs} +1 -1
- package/dist/packem_shared/awaitWsDrain-kSGvAfw1.mjs +1 -0
- package/dist/packem_shared/backfillAggregateIndexes-DVQ2sVuV.mjs +1 -0
- package/dist/packem_shared/base64-DfpzS4o_.mjs +1 -0
- package/dist/packem_shared/buildIndexRange-CBKQmHSS.mjs +1 -0
- package/dist/packem_shared/buildPokeFrames-BXejpiII.mjs +1 -0
- package/dist/packem_shared/buildReprojectionMigration-8nVn8Qwb.mjs +1 -0
- package/dist/packem_shared/buildSettings-B4igo4rJ.mjs +1 -0
- package/dist/packem_shared/compileWhereSql-JBpSfQm9.mjs +1 -0
- package/dist/packem_shared/computeRankPage-Bby1Npkd.mjs +1 -0
- package/dist/packem_shared/createCompanionSync-zCwaB6wj.mjs +1 -0
- package/dist/packem_shared/createReadFootprint-MRH1If3F.mjs +1 -0
- package/dist/packem_shared/createReplicaLink-C1JuP_DN.mjs +7 -0
- package/dist/packem_shared/createSystemReader-BtYeSMDb.mjs +1 -0
- package/dist/packem_shared/ctx-db-companions-lTt-rvKG.mjs +1 -0
- package/dist/packem_shared/defineEngineContractSuite-0XtjRA7F.mjs +1 -0
- package/dist/packem_shared/diffExternalSource-pozJ4UdZ.mjs +1 -0
- package/dist/packem_shared/do-sql-Dk_DJxn4.mjs +1 -0
- package/dist/packem_shared/estimate-bytes-CzG5x1f8.mjs +1 -0
- package/dist/packem_shared/exportShardRows-Cgt3ITwH.mjs +1 -0
- package/dist/packem_shared/hasTrigger-CjlwI4le.mjs +1 -0
- package/dist/packem_shared/isSoftDeleted-DcGB0pov.mjs +9 -0
- package/dist/packem_shared/liftSourceId-CA3ENhXj.mjs +1 -0
- package/dist/packem_shared/materializeExternalRows-Drn0FGdb.mjs +1 -0
- package/dist/packem_shared/mergeChangedKeys-D1T-TPUb.mjs +1 -0
- package/dist/packem_shared/param-Ib8WHnrF.mjs +1 -0
- package/dist/packem_shared/runDrizzle-it6rL9bR.mjs +1 -0
- package/dist/packem_shared/runShardMigrations-Crppyq1f.mjs +5 -0
- package/dist/packem_shared/runSocketPool-CZJ2X9cF.mjs +1 -0
- package/dist/packem_shared/selectExpiredIds-_5514W_v.mjs +1 -0
- package/dist/packem_shared/selectShapeMemberIds-B-pQJHAu.mjs +1 -0
- package/dist/packem_shared/serializeSqlValue-DbI1VQYM.mjs +1 -0
- package/dist/packem_shared/sibling-channel-BRZpLiDA.mjs +1 -0
- package/dist/packem_shared/sql-projection-BqmxFxQU.mjs +1 -0
- package/dist/packem_shared/stableStringify-CujpENIO.mjs +1 -0
- package/dist/packem_shared/stableWireKey-BYB5GQJa.mjs +1 -0
- package/dist/packem_shared/wire-codec-BU9T2xJ7.mjs +1 -0
- package/package.json +3 -3
- package/dist/packem_shared/ADMIN_FUNCTIONS-Cj1pJjVg.mjs +0 -1
- package/dist/packem_shared/AGGREGATE_SQL_FUNCTION-CTo0-9iZ.mjs +0 -1
- package/dist/packem_shared/AGG_COUNT-CKtq03Go.mjs +0 -1
- package/dist/packem_shared/AUDIT_LOG_TABLE-Bl2mYtAQ.mjs +0 -8
- package/dist/packem_shared/CDC_LOG_TABLE-DNFFQwF_.mjs +0 -8
- package/dist/packem_shared/CLIENT_WATERMARK_TABLE-LrKfdxyt.mjs +0 -7
- package/dist/packem_shared/CountRlsUnsupportedError-8BqPYQoP.mjs +0 -1
- package/dist/packem_shared/DATA_MIGRATION_STATE_TABLE-DIQTu___.mjs +0 -31
- package/dist/packem_shared/DEFAULT_MAX_RELATION_KEYS-BV1RCoat.mjs +0 -1
- package/dist/packem_shared/DEFAULT_MAX_RELAYS-Cinp9pPC.mjs +0 -1
- package/dist/packem_shared/DEFAULT_PROMOTION_THRESHOLDS-DYGNAo1I.mjs +0 -1
- package/dist/packem_shared/DEFAULT_TRANSACTION_LIMITS-DLUzZbta.mjs +0 -1
- package/dist/packem_shared/DurableStreamRunner-B54Jt9Iu.mjs +0 -1
- package/dist/packem_shared/GEO_DEFAULT_PRECISION-DyI5zggj.mjs +0 -1
- package/dist/packem_shared/GLOBAL_SHAPE_SNAPSHOT_TABLE-B2LKe4KU.mjs +0 -7
- package/dist/packem_shared/IDEMPOTENCY_TABLE-tQ5mnqvw.mjs +0 -7
- package/dist/packem_shared/MAIL_RETENTION-CzZuX9bd.mjs +0 -18
- package/dist/packem_shared/MAX_SQL_ROWS-nMwkxv5f.mjs +0 -2
- package/dist/packem_shared/NotUniqueError-DYo7r67J.mjs +0 -1
- package/dist/packem_shared/QUEUE_TABLE-BX0nopuT.mjs +0 -17
- package/dist/packem_shared/RANK_TIEBREAK-BGk411OR.mjs +0 -1
- package/dist/packem_shared/RELATION_EXISTS_KEY-BaqSIFU1.mjs +0 -1
- package/dist/packem_shared/REPROJECTION_MIGRATION_PREFIX-D2dltRFC.mjs +0 -1
- package/dist/packem_shared/RLS_UNWRAP_SYMBOL-DcqORh2s.mjs +0 -1
- package/dist/packem_shared/ReactiveCache-D_T10KLy.mjs +0 -1
- package/dist/packem_shared/SCAN_DEP-D_yR9EeV.mjs +0 -1
- package/dist/packem_shared/SCHEMA_HISTORY_MAX_VERSIONS-CEK7b_7v.mjs +0 -6
- package/dist/packem_shared/SEARCH_STATE_TABLE-DRk_SB72.mjs +0 -1
- package/dist/packem_shared/ShardRunner-DIqVdWtk.mjs +0 -1
- package/dist/packem_shared/aggregateTableName-DN7gk6uh.mjs +0 -1
- package/dist/packem_shared/appendStreamChunk-ksZYy1hZ.mjs +0 -19
- package/dist/packem_shared/applyOnDelete-crbAzVfE.mjs +0 -1
- package/dist/packem_shared/applySelect-5w13bMAR.mjs +0 -1
- package/dist/packem_shared/awaitWsDrain-PT9o0d6J.mjs +0 -1
- package/dist/packem_shared/backfillAggregateIndexes-DTOIsYbi.mjs +0 -1
- package/dist/packem_shared/base64-fKomMf5D.mjs +0 -1
- package/dist/packem_shared/buildIndexRange-DFsdtPjD.mjs +0 -1
- package/dist/packem_shared/buildPokeFrames-DmB-FBeQ.mjs +0 -1
- package/dist/packem_shared/buildReprojectionMigration-JUwsTNTB.mjs +0 -1
- package/dist/packem_shared/buildSettings-COIJsw7a.mjs +0 -1
- package/dist/packem_shared/compileWhereSql-B3hq_v98.mjs +0 -1
- package/dist/packem_shared/computeRankPage-BU8LXvQs.mjs +0 -1
- package/dist/packem_shared/createCompanionSync-D-ckGBdA.mjs +0 -1
- package/dist/packem_shared/createReadFootprint-DIrrxRTE.mjs +0 -1
- package/dist/packem_shared/createReplicaLink-BMNW0SX6.mjs +0 -7
- package/dist/packem_shared/createSystemReader-DcDcrtM3.mjs +0 -1
- package/dist/packem_shared/ctx-db-companions-BJlCofon.mjs +0 -1
- package/dist/packem_shared/defineEngineContractSuite-CvdzORsy.mjs +0 -1
- package/dist/packem_shared/diffExternalSource-DMpkJta1.mjs +0 -1
- package/dist/packem_shared/do-sql-DKSFK627.mjs +0 -1
- package/dist/packem_shared/estimate-bytes-Drp8rhPs.mjs +0 -1
- package/dist/packem_shared/exportShardRows-Bbi_JGfn.mjs +0 -1
- package/dist/packem_shared/hasTrigger-CbkOHExZ.mjs +0 -1
- package/dist/packem_shared/isSoftDeleted-DyEJueIu.mjs +0 -9
- package/dist/packem_shared/liftSourceId-DApAbu7Q.mjs +0 -1
- package/dist/packem_shared/materializeExternalRows-C-5TKdc1.mjs +0 -1
- package/dist/packem_shared/mergeChangedKeys-BXtUgIPW.mjs +0 -1
- package/dist/packem_shared/param-CYxL68V-.mjs +0 -1
- package/dist/packem_shared/runDrizzle-C3n5gJsk.mjs +0 -1
- package/dist/packem_shared/runShardMigrations-BCuK60KT.mjs +0 -5
- package/dist/packem_shared/runSocketPool-DPQLVyWF.mjs +0 -1
- package/dist/packem_shared/selectExpiredIds-C4Ry_NxG.mjs +0 -1
- package/dist/packem_shared/selectShapeMemberIds-Bkkug6vU.mjs +0 -1
- package/dist/packem_shared/serializeSqlValue-BR4UOWoP.mjs +0 -1
- package/dist/packem_shared/sibling-channel-bg9FBL5s.mjs +0 -1
- package/dist/packem_shared/sql-projection-jfoe331H.mjs +0 -1
- package/dist/packem_shared/stableStringify-BjLh4gvA.mjs +0 -1
- package/dist/packem_shared/stableWireKey-Diuu1gGc.mjs +0 -1
- package/dist/packem_shared/wire-codec-Dh0j-GnY.mjs +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as c}from"./sql-projection-jfoe331H.mjs";const i=40,s=o=>{let r=0;const f=(e,t)=>typeof t=="bigint"?(r+=c+1+i,t.toString()):t instanceof ArrayBuffer||ArrayBuffer.isView(t)?(r+=2*Math.ceil(t.byteLength/3)*4+i,""):t;try{const e=JSON.stringify(o,f);return(e===void 0?0:e.length)+r}catch{return}};export{s as o};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{toErrorBody as f}from"@lunora/errors";const d=200,b=(r,s)=>{const n=o=>{const e=r.tables[o];return e!==void 0&&e.shardMode?.kind!=="global"};return(s&&s.length>0?[...s]:Object.keys(r.tables)).filter(o=>n(o))},u=async function*(r,s,n=d){let o=null,e=!1;for(;!e;){const t=await r.findMany(s,{cursor:o,limit:n});for(const a of t.page)yield{doc:a,table:s};o=t.continueCursor,e=t.isDone||o===null}},k=async function*(r,s,n){const o=b(s,n.tables),e=n.batchSize??d;for(const t of o)yield*u(r,t,e)},p=new Set(["_creationTime","_id"]),y=(r,s)=>{for(const[n,o]of Object.entries(r.shape)){const e=s[n];if(e===void 0&&o.kind==="optional")continue;const t=o.parse;if(typeof t=="function")try{t(e)}catch(a){const c=a instanceof Error?a.message:String(a);return`field "${n}": ${c}`}}},h=(r,s,n)=>{const o=r.tables[s];if(!o)return`unknown table: ${s}`;if(o.shardMode?.kind==="global")return`table "${s}" is a global (.global()) table and is not importable through the shard import path`;const e=Object.fromEntries(Object.entries(n).filter(([t])=>!p.has(t)));for(const t of Object.keys(e))if(!(t in o.shape))return`unexpected field "${t}": not declared in table "${s}"`;return y(o,e)},g=async(r,s)=>{try{return await r.get(s)!==null}catch{return!1}},m=async(r,s,n,o)=>{const{doc:e,table:t}=n;if(typeof t!="string"||t.length===0)return{error:{code:"BAD_ROW",line:o,message:"row is missing `table`",table:t},kind:"error"};if(!e||typeof e!="object"||Array.isArray(e))return{error:{code:"BAD_ROW",line:o,message:"row is missing or malformed `doc`",table:t},kind:"error"};const a=h(s,t,e);if(a!==void 0)return{error:{code:"VALIDATION_ERROR",line:o,message:a,table:t},kind:"error"};const c=typeof e._id=="string"?e._id:void 0;if(c!==void 0&&await g(r,c))return{kind:"conflict"};try{return await r.insert(t,e,{allowExplicitId:!0}),{kind:"inserted",table:t}}catch(i){const{body:l}=f(i,{fallbackCode:"INSERT_FAILED"});return{error:{code:l.code,line:o,message:l.message,table:t},kind:"error"}}},A=async(r,s,n)=>{const o=[],e={};let t=0,a=(n.startLine??1)-1;for(const c of n.rows){a+=1;const i=await m(r,s,c,a);i.kind==="error"?o.push(i.error):i.kind==="conflict"?t+=1:e[i.table]=(e[i.table]??0)+1}return{conflicts:t,errors:o,inserted:e}},S=r=>{const s=Array.isArray(r.tables)?r.tables.filter(n=>typeof n=="string"):void 0;return{batchSize:typeof r.batchSize=="number"?r.batchSize:void 0,tables:s}},v=r=>{const s=Array.isArray(r.rows)?r.rows:[],n=[];for(const e of s){if(!e||typeof e!="object")continue;const t=e;if(typeof t.table!="string"||!t.doc||typeof t.doc!="object"||Array.isArray(t.doc)){n.push({doc:t.doc??{},table:typeof t.table=="string"?t.table:""});continue}n.push({doc:t.doc,table:t.table})}const o=typeof r.startLine=="number"?r.startLine:void 0;return{rows:n,startLine:o}};export{k as exportShardRows,u as exportShardTable,A as importShardRows,S as parseExportShardArgs,v as parseImportShardArgs,b as selectExportTables,h as validateImportRow};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
const g=async t=>{const e=t.schema.tables[t.tableName]?.triggerMap;if(e)for(const a of Object.values(e))a.timing===t.timing&&a.op===t.op&&await a.handler(t.ctx,t.event)},i=(t,e,a)=>{const r=t.tables[e]?.triggerMap;return r?Object.values(r).some(s=>s.op===a):!1};export{i as hasTrigger,g as runTriggers};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import{LunoraError as E}from"@lunora/errors";import{sql as m}from"drizzle-orm";import{runDrizzle as h}from"./runDrizzle-C3n5gJsk.mjs";import{liftSourceId as x}from"./liftSourceId-DApAbu7Q.mjs";import{normalizeSourceValue as K}from"./liftSourceId-DApAbu7Q.mjs";import{runExternalSourceTick as v,materializeExternalRowsIncremental as M}from"./materializeExternalRows-C-5TKdc1.mjs";const _="__lunora_source_cursor",D=e=>e instanceof Date?`d:${e.toISOString()}`:typeof e=="bigint"?`b:${e.toString()}`:typeof e=="number"?`n:${e.toString()}`:`s:${e}`,R=e=>{const t=e.slice(2);switch(e[0]){case"b":return BigInt(t);case"d":return new Date(t);case"n":return Number(t);default:return t}},k=/^-?\d+$/,I=/^-?\d+(?:\.\d+)?$/,A=(e,t)=>e instanceof Date&&t instanceof Date?e.getTime()>t.getTime():typeof e=="bigint"&&typeof t=="bigint"||typeof e=="number"&&typeof t=="number"?e>t:typeof e=="string"&&typeof t=="string"&&I.test(e)&&I.test(t)?k.test(e)&&k.test(t)?BigInt(e)>BigInt(t):Number(e)>Number(t):String(e)>String(t),q=(e,t,a)=>{let n=a===null?void 0:R(a);for(const r of e){const s=r[t];if(s==null)continue;const i=s;(n===void 0||A(i,n))&&(n=i)}return n===void 0?null:D(n)},O=e=>{h(e,m`CREATE TABLE IF NOT EXISTS ${m.identifier(_)} (
|
|
2
|
-
table_name TEXT NOT NULL,
|
|
3
|
-
shard_key TEXT NOT NULL,
|
|
4
|
-
watermark TEXT,
|
|
5
|
-
last_reconcile_ms INTEGER,
|
|
6
|
-
PRIMARY KEY (table_name, shard_key)
|
|
7
|
-
)`)},B=(e,t,a)=>{const n=h(e,m`SELECT watermark, last_reconcile_ms FROM ${m.identifier(_)} WHERE table_name = ${t} AND shard_key = ${a} LIMIT 1`).toArray()[0];return{lastReconcileMs:n?.last_reconcile_ms??null,watermark:n?.watermark??null}},C=(e,t,a,n)=>{h(e,m`INSERT INTO ${m.identifier(_)} (table_name, shard_key, watermark, last_reconcile_ms)
|
|
8
|
-
VALUES (${t}, ${a}, ${n.watermark}, ${n.lastReconcileMs})
|
|
9
|
-
ON CONFLICT(table_name, shard_key) DO UPDATE SET watermark = excluded.watermark, last_reconcile_ms = excluded.last_reconcile_ms`)},P=(e,t,a)=>e==="manual"?!1:e===void 0||t===void 0?!0:a-t>=e.everyMs,T=async(e,t,a,n)=>{const r=await e.query(t,a);return{documents:r.map(s=>x(s,{idColumn:n.idColumn,map:n.map})),rows:r}},V=async(e,t,a,n,r,s)=>{const i=r.tenantBy?r.tenantBy(s):[],{documents:l}=await T(a,r.query,i,r);return v(e,t,l,{columns:r.columns,table:n})},N=(e,t)=>{const a=e[t];return a!=null&&a!==!1&&a!==0},Y=async(e,t,a,n,r,s,i)=>{const{cursor:l}=r;if(!l)throw new E("INTERNAL",`external-source: table "${n}" is mode "incremental" but has no \`cursor\` — this should have been rejected at defineSchema`);O(e);const u=B(e,n,s),b=r.tenantBy?r.tenantBy(s):[],g=r.reconcileEveryMs!==void 0&&(u.lastReconcileMs===null||i-u.lastReconcileMs>=r.reconcileEveryMs),w=u.watermark===null||g;let o,f;if(u.watermark===null||g){o=await T(a,r.query,b,r);const{softDeleteColumn:c}=r,y=c?o.documents.filter(($,p)=>{const d=o.rows[p];return!(d&&N(d,c))}):o.documents;({applied:f}=await v(e,t,y,{columns:r.columns,table:n}))}else{o=await T(a,l.query,[...b,R(u.watermark)],r);const{softDeleteColumn:c}=r,y=c?new Set(o.documents.flatMap(($,p)=>{const d=o.rows[p];return d&&N(d,c)?[String($._id)]:[]})):void 0;({applied:f}=await M(t,o.documents,{columns:r.columns,deletedIds:y,table:n}))}const S=q(o.rows,l.column,u.watermark);if(w&&S===null&&o.rows.length>0)throw new E("INTERNAL",`external-source: table "${n}" (mode "incremental") pulled ${String(o.rows.length)} rows but none carry the cursor column "${l.column}" — the seed \`query\` must project it (matching \`cursor.query\`'s alias), or the watermark can never advance.`);const L=o.rows.length>0&&o.rows.every(c=>c[l.column]===null||c[l.column]===void 0);if(!w&&L)throw new E("INTERNAL",`external-source: table "${n}" (mode "incremental") pulled ${String(o.rows.length)} rows but none carry the cursor column "${l.column}" — \`cursor.query\` must project it (matching the seed \`query\`'s alias), or the watermark can never advance and every tick re-pulls the same stranded slice.`);return C(e,n,s,{lastReconcileMs:w?i:u.lastReconcileMs,watermark:S}),{applied:f}};export{N as isSoftDeleted,P as isSourceDue,x as liftSourceId,K as normalizeSourceValue,Y as pullExternalSourceIncrementalTick,V as pullExternalSourceTick};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{LunoraError as m}from"@lunora/errors";const f=r=>r instanceof Date?r.toISOString():typeof r=="bigint"?String(r):Array.isArray(r)?r.map(t=>f(t)):r!==null&&typeof r=="object"&&Object.getPrototypeOf(r)===Object.prototype?n(r):r,n=r=>{const t={};for(const[o,i]of Object.entries(r))t[o]=f(i);return t},p=(r,t={})=>{const{idColumn:o="id",map:i}=t,e=r[o];if(e==null)throw new m("INTERNAL",`external-source: row is missing id column "${o}"`);if(typeof e!="string"&&typeof e!="number"&&typeof e!="bigint")throw new TypeError(`external-source: id column "${o}" must be a string or number`);const s=String(e);if(i)return n({...i(r),_id:s});const c={};for(const[u,a]of Object.entries(r))u!==o&&(c[u]=a);return n({...c,_id:s})};export{p as liftSourceId,n as normalizeSourceDocument,f as normalizeSourceValue};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{applyCdcChanges as m}from"./CDC_LOG_TABLE-DNFFQwF_.mjs";import{selectShapeRows as f}from"./selectShapeMemberIds-Bkkug6vU.mjs";import{diffExternalSource as g,projectExternalSourceRow as c}from"./diffExternalSource-DMpkJta1.mjs";import{stableStringify as p}from"./stableStringify-BjLh4gvA.mjs";const x=async(t,s,r,e)=>{const{changes:n,nextBaseline:a}=g(s,r,e);return await m(t,n),{applied:n.length,nextBaseline:a}},E=async(t,s,r)=>{const{columns:e,deletedIds:n,table:a}=r,i=[];for(const u of s){const l=c(u,e),o=String(l._id);if(n?.has(o)){await t.get(o,a)&&i.push({id:o,op:"delete",seq:0,table:a,ts:0});continue}const d=await t.get(o,a);d&&p(c({...d,_id:o},e))===p(l)||i.push({doc:l,id:o,op:"insert",seq:0,table:a,ts:0})}return await m(t,i),{applied:i.length}},h=(t,s,r)=>{const e=new Map;for(const{doc:n,id:a}of f(t,s,void 0))e.set(a,p(c({...n,_id:a},r)));return e},R=async(t,s,r,e)=>{const n=h(t,e.table,e.columns);return x(s,r,n,e)};export{x as materializeExternalRows,E as materializeExternalRowsIncremental,h as readExternalSourceBaseline,R as runExternalSourceTick};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{keysTouchRanges as g}from"./buildIndexRange-DFsdtPjD.mjs";const c=(s,t,o)=>{const e=s??new Map;for(const n of o){const r=t?.get(n),a=e.get(n),i=e.has(n)&&a===void 0;if(!t?.has(n)||r===void 0||i){e.set(n,void 0);continue}e.set(n,a?[...a,...r]:r)}return e},f=(s,t,o)=>{const e=s??new Map;if(e.has(t)&&e.get(t)===void 0)return e;if(!o||o.length===0)return e.set(t,void 0),e;const n=e.get(t);return e.set(t,n?[...n,...o]:[...o]),e},h=(s,t,o)=>{if(!o)return!0;for(const e of t){if(!s.tables.has(e))continue;const n=s.ranges?.get(e);if(!n||n.length===0||g(n,o.get(e)))return!0}return!1};export{c as mergeChangedKeys,f as recordChangedKeys,h as writeTouchesMemo};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{LunoraError as m}from"@lunora/errors";import{sql as r}from"drizzle-orm";import{MySqlDialect as c}from"drizzle-orm/mysql-core";import{PgDialect as u}from"drizzle-orm/pg-core";import{SQLiteSyncDialect as p}from"drizzle-orm/sqlite-core";const f=new u,d=new c,S=new p,g={mysql:d,postgres:f,sqlite:S},a={boundParams:100,compoundSelect:5,likePattern:50,sqlTextLength:1e5},h=a.boundParams/2,L=e=>e===null||typeof e=="boolean"?!0:typeof e=="number"?Number.isFinite(e):typeof e=="string"&&e.isWellFormed(),w=(e,t)=>{const{params:n,sql:o}=g[e].sqlToQuery(t);return{params:n,sql:o}},$=e=>r`${e}`,O=e=>{if(e.length===0)throw new Error("unionAll: expected at least one branch");let t=[...e];for(;t.length>a.compoundSelect;){const n=[];for(let o=0;o<t.length;o+=a.compoundSelect){const l=r.join(t.slice(o,o+a.compoundSelect),r` UNION ALL `);n.push(r`SELECT * FROM (${l}) ${r.identifier("__u__")}`)}t=n}return r.join(t,r` UNION ALL `)},I=(e,t,n,o=h)=>{const l=n?r` NOT IN `:r` IN `,s=t.every(i=>L(i));if(t.length>o&&!s)throw new m("BAD_REQUEST",`an "in" list of ${String(t.length)} values holds a value JSON cannot carry (bytes, a non-finite number, or malformed text), so it cannot be bound as one parameter — and ${String(t.length)} placeholders exceed SQLite's per-statement cap of 100 on Durable Objects and D1. Narrow the list to ${String(o)} values or fewer.`);return t.length<=o?r`${e}${l}(${r.join(t.map(i=>$(i)),r`, `)})`:r`${e}${l}(SELECT ${r.identifier("value")} FROM json_each(${JSON.stringify(t)}))`};export{a as WORKERD_SQLITE_LIMITS,$ as param,w as renderSql,I as sqliteInList,O as unionAll};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{LunoraError as l}from"@lunora/errors";import{renderSql as o,WORKERD_SQLITE_LIMITS as n}from"./param-CYxL68V-.mjs";const i=(t,e,...r)=>{if(e.length*3>n.sqlTextLength){const s=new TextEncoder().encode(e).length;if(s>n.sqlTextLength)throw new l("INTERNAL",`SQL statement is ${String(s)} bytes, over this runtime's ${String(n.sqlTextLength)}-byte limit`)}if(r.length>n.boundParams)throw new l("INTERNAL",`SQL statement binds ${String(r.length)} parameters, over this runtime's limit of ${String(n.boundParams)}`);return t.exec.call(t,e,...r)},u=(t,e)=>{const{params:r,sql:s}=o("sqlite",e);return i(t,s,...r)},h=t=>t??null,g=t=>{if(!(t==null||t===""))try{return JSON.parse(t)}catch{return}};export{g as decodeJsonColumn,h as orNull,u as runDrizzle,i as runSql};
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import{l as I,T as N,c as S}from"./ctx-db-companions-BJlCofon.mjs";import"@lunora/errors";import{sql as e}from"drizzle-orm";import{aggregateTableName as p}from"./aggregateTableName-DN7gk6uh.mjs";import{backfillSearchIndexesForTable as g}from"./backfillAggregateIndexes-DTOIsYbi.mjs";import{migrateCdcLog as l,migrateCdcMeta as h}from"./CDC_LOG_TABLE-DNFFQwF_.mjs";import{migrateClientWatermark as R}from"./CLIENT_WATERMARK_TABLE-LrKfdxyt.mjs";import{migrateGlobalShapeSnapshot as C}from"./GLOBAL_SHAPE_SNAPSHOT_TABLE-B2LKe4KU.mjs";import{migrateIdempotency as O}from"./IDEMPOTENCY_TABLE-tQ5mnqvw.mjs";import{migrateSearchState as u}from"./SEARCH_STATE_TABLE-DRk_SB72.mjs";import{runDrizzle as a}from"./runDrizzle-C3n5gJsk.mjs";import{a as U,N as E,y as _,I as b,C as X,c as x,p as B,T as c,h as D}from"./do-sql-DKSFK627.mjs";import{migrateDurableStreams as F}from"./appendStreamChunk-ksZYy1hZ.mjs";import{sortColumnName as M,rankTableName as Y}from"./RANK_TIEBREAK-BGk411OR.mjs";import{recordSchemaVersion as k}from"./SCHEMA_HISTORY_MAX_VERSIONS-CEK7b_7v.mjs";const y=(r,t,o)=>{for(const i of o.indexes){const n=`${t}_${i.name}`,s=e.join(i.fields.map(f=>E(f)),e`, `);a(r,_(n,t,s,i.unique??!1))}for(const[i,n]of b(o)){if(!n.unique)continue;const s=`${t}_unique_${i}`;a(r,_(s,t,E(i),!0))}},j=(r,t,o)=>{if(!(!o.searchIndexes||o.searchIndexes.length===0||!X(r))){for(const i of o.searchIndexes){const n=S(t,i.name);a(r,e`CREATE VIRTUAL TABLE IF NOT EXISTS ${e.identifier(n)} USING fts5(${e.identifier(I)}, ${e.identifier(N)} UNINDEXED)`),a(r,e`CREATE VIRTUAL TABLE IF NOT EXISTS ${e.identifier(`${n}__vocab`)} USING fts5vocab(${e.identifier(n)}, ${e.raw("instance")})`)}g(r,t,o)}},q=(r,t,o)=>{if(o.geoIndexes)for(const i of o.geoIndexes){const n=D(t,i.name);a(r,e`CREATE TABLE IF NOT EXISTS ${e.identifier(n)} (${e.identifier("__id__")} TEXT PRIMARY KEY, ${e.identifier("__geohash__")} TEXT NOT NULL, ${e.identifier("__lat__")} REAL NOT NULL, ${e.identifier("__lng__")} REAL NOT NULL)`);const s=`${t}__geo_${i.name}__btree`;a(r,_(s,n,e`${e.identifier("__geohash__")} ASC, ${e.identifier("__id__")} ASC`,!1))}},G=(r,t,o)=>{if(o.aggregateIndexes)for(const i of o.aggregateIndexes){const n=p(t,i.name);a(r,e`CREATE TABLE IF NOT EXISTS ${e.identifier(n)} (${x} TEXT PRIMARY KEY, ${B} REAL, ${c} INTEGER NOT NULL DEFAULT 0)`),a(r,e`PRAGMA table_info(${e.identifier(n)})`).toArray().some(s=>s.name==="__count__")||a(r,e`ALTER TABLE ${e.identifier(n)} ADD COLUMN ${c} INTEGER NOT NULL DEFAULT 0`)}},P=(r,t,o)=>{if(o.rankIndexes)for(const i of o.rankIndexes){const n=Y(t,i.name),s=i.sortBy.map((T,d)=>M(d)),f=s.map(T=>e`${e.identifier(T)} BLOB`),$=f.length>0?e`, ${e.join(f,e`, `)}`:e``;a(r,e`CREATE TABLE IF NOT EXISTS ${e.identifier(n)} (${e.identifier("__id__")} TEXT PRIMARY KEY, ${e.identifier("__partition__")} TEXT NOT NULL${$})`);const m=[e`${e.identifier("__partition__")} ASC`];for(const[T,d]of s.entries()){const A=i.sortBy[T]?.direction;m.push(e`${e.identifier(d)} ${e.raw(A==="desc"?"DESC":"ASC")}`)}m.push(e`${e.identifier("__id__")} ASC`);const L=`${t}__rank_${i.name}__btree`;a(r,_(L,n,e.join(m,e`, `),!1))}},te=(r,t,o={})=>{o.schemaSnapshot!==void 0&&k(r,o.schemaSnapshot.hash,o.schemaSnapshot.json),u(r);for(const[i,n]of Object.entries(t.tables))n.shardMode?.kind!=="global"&&(a(r,e`CREATE TABLE IF NOT EXISTS ${e.identifier(i)} (
|
|
2
|
-
id TEXT PRIMARY KEY,
|
|
3
|
-
_creationTime REAL NOT NULL,
|
|
4
|
-
${e.identifier(U)} TEXT NOT NULL
|
|
5
|
-
)`),y(r,i,n),j(r,i,n),q(r,i,n),G(r,i,n),P(r,i,n));o.cdc&&(l(r),h(r),R(r)),O(r),C(r),F(r)};export{te as runShardMigrations};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
const l=async(o,e,n=8)=>{let t=0;const c=async()=>{let a=o[t];for(t+=1;a!==void 0;){try{await e(a)}catch{}a=o[t],t+=1}};await Promise.all(Array.from({length:Math.min(n,o.length)},()=>c()))};export{l as runSocketPool};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{sql as e}from"drizzle-orm";import{runDrizzle as $}from"./runDrizzle-C3n5gJsk.mjs";import{N as r}from"./do-sql-DKSFK627.mjs";const E=(d,i,s,o)=>{const f=s-(i.after??0),t=[e`${r(i.field)} IS NOT NULL`,e`${r(i.field)} < ${f}`];i.softDeleteField!==void 0&&t.push(e`${r(i.softDeleteField)} IS NULL`);const a=e`SELECT id FROM ${e.identifier(i.table)} WHERE ${e.join(t,e` AND `)} LIMIT ${e.raw(String(Math.max(0,Math.floor(o))+1))}`,l=$(d,a).toArray(),n=l.length>o,m=l.slice(0,o).map(p=>p.id);return{hasMore:n,ids:m}};export{E as selectExpiredIds};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{sql as e}from"drizzle-orm";import{runDrizzle as m}from"./runDrizzle-C3n5gJsk.mjs";import{a as c,E as a,N as u}from"./do-sql-DKSFK627.mjs";import{sqliteInList as h}from"./param-CYxL68V-.mjs";import{compileWhereSql as S}from"./compileWhereSql-B3hq_v98.mjs";import{serializeSqlValue as E}from"./serializeSqlValue-BR4UOWoP.mjs";const $={fieldRef:u,serialize:E},R=i=>{if(i.length!==0)return h(e`${e.identifier("id")}`,i,!1)},p=(i,o)=>{const r=[];o&&r.push(o);const t=S(i,$);return t&&r.push(t),r.length===0?e``:e` WHERE ${e.join(r,e` AND `)}`},L=(i,o,r)=>{const t=p(r,void 0),f=m(i,e`SELECT id, _creationTime, ${e.identifier(c)} FROM ${e.identifier(o)}${t}`).toArray(),n=[];for(const s of f){const d=a(s),{id:l}=s;d!==void 0&&typeof l=="string"&&n.push({doc:d,id:l})}return n},M=(i,o,r,t)=>{if(t.length===0)return new Set;const f=p(r,R(t)),n=m(i,e`SELECT id FROM ${e.identifier(o)}${f}`).toArray();return new Set(n.map(s=>s.id))};export{M as selectShapeMemberIds,L as selectShapeRows};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{b as o}from"./sql-projection-jfoe331H.mjs";const t=e=>typeof e=="boolean"?e?1:0:e===null||typeof e=="string"||typeof e=="number"?e:o(e)??JSON.stringify(e);export{t as serializeSqlValue};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
const s=/^\d+$/,m=(n,t,o)=>{const e=n?.[t];let r=Number.NaN;return typeof e=="string"&&s.test(e.trim())?r=Number(e.trim()):typeof e=="number"&&(r=e),Number.isSafeInteger(r)&&r>0?r:o},c=(n,t)=>{const o=Math.max(n.length,t.length);let e=n.length^t.length;for(let r=0;r<o;r+=1){const i=r<n.length?n.charCodeAt(r):0,a=r<t.length?t.charCodeAt(r):0;e|=i^a}return e===0},u="LUNORA_RELAY_SECRET",y="x-lunora-relay-sig",l=n=>{const t=n?.[u];return typeof t=="string"&&t.length>0?t:void 0},g=async(n,t)=>{const o=new TextEncoder,e=await crypto.subtle.importKey("raw",o.encode(n),{hash:"SHA-256",name:"HMAC"},!1,["sign"]),r=await crypto.subtle.sign("HMAC",e,o.encode(t));return[...new Uint8Array(r)].map(i=>i.toString(16).padStart(2,"0")).join("")},d=async(n,t,o)=>{const e=l(n);return e===void 0?!0:t===null?!1:c(t,await g(e,o))},f=n=>{if(n===null||typeof n!="object")return;const t=n;return typeof t.idFromName=="function"&&typeof t.get=="function"?t:void 0},h=(n,t,o)=>{if(t===void 0)return;const e=f(n?.[t]);if(e!==void 0)return typeof e.getByName=="function"?e.getByName(o):e.get(e.idFromName(o))};export{d as f,y as g,h as l,g as o,l as s,m as u};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{LunoraError as g}from"@lunora/errors";import{a}from"./base64-fKomMf5D.mjs";const n=t=>{if(t.kind!=="optional")return t.kind;const r=t._meta?.inner;return r?n(r):t.kind},e=39,s="0",u="1",y=t=>{const r=t<0n,i=(r?-t:t).toString();if(i.length>e)throw new g("BAD_REQUEST",`bigint ${t.toString()} has ${String(i.length)} digits, over the ${String(e)}-digit limit for a queryable column`);const o=i.padStart(e,"0");return r?s+Array.from(o,f=>String(9-Number(f))).join(""):u+o},d=t=>typeof t=="bigint"?y(t):t instanceof ArrayBuffer?a(new Uint8Array(t)):ArrayBuffer.isView(t)?a(new Uint8Array(t.buffer,t.byteOffset,t.byteLength)):void 0,m=t=>{const r=n(t);return r==="bigint"||r==="bytes"},S=t=>{const r=n(t);return m(t)||r==="any"||r==="union"||r==="from"};export{d as b,m as f,e as r,S as y};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
const y=(e,t)=>e<t?-1:e>t?1:0,s=e=>{if(e===void 0)return"null";if(typeof e=="bigint")throw new TypeError("stableStringify: cannot use a bigint in a stable JSON cache key — pass it as a string, or use stableWireKey");if(e===null||typeof e!="object")return JSON.stringify(e);if(Array.isArray(e))return`[${e.map(r=>s(r)).join(",")}]`;const t=Object.getPrototypeOf(e);if(t!==null&&t!==Object.prototype){const r=e.constructor?.name??"value";throw new TypeError(`stableStringify: cannot use a ${r} in a stable JSON cache key — only plain objects, arrays, and JSON primitives are supported (wire-typed values key via stableWireKey)`)}const n=e,a=Object.keys(n).toSorted(y),i=[];for(const r of a){const o=n[r];o!==void 0&&i.push(`${JSON.stringify(r)}:${s(o)}`)}return`{${i.join(",")}}`};export{s as stableStringify};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{stableStringify as r}from"./stableStringify-BjLh4gvA.mjs";import{a as e}from"./wire-codec-Dh0j-GnY.mjs";const i=t=>r(e(t));export{i as stableWireKey};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as p,o as A}from"./base64-fKomMf5D.mjs";const i="$lunora.wire$",b=64,g=1024,d="__proto__",w={BigInt64Array,BigUint64Array,Float32Array,Float64Array,Int8Array,Int16Array,Int32Array,Uint8Array,Uint8ClampedArray,Uint16Array,Uint32Array},m={Error,EvalError,RangeError,ReferenceError,SyntaxError,TypeError,URIError},v=r=>{if(r===null||typeof r!="object")return!1;const a=Object.getPrototypeOf(r);return a===null||a===Object.prototype},c=(r,a=0)=>{if(a>b)throw new RangeError(`wire-codec: value nesting exceeds the ${b}-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",c(r.getTime(),a+1)];if(r instanceof Error){const e=r,n={};for(const f of Object.keys(e))e[f]!==void 0&&(n[f]=c(e[f],a+1));const o=[i,"error",e.name,e.message,n];return e.cause!==void 0&&o.push(c(e.cause,a+1)),o}if(r instanceof URL)return[i,"url",r.href];if(r instanceof Map)return[i,"map",[...r.entries()].map(([e,n])=>[c(e,a+1),c(n,a+1)])];if(r instanceof Set)return[i,"set",[...r].map(e=>c(e,a+1))];if(r instanceof ArrayBuffer)return[i,"bytes",p(new Uint8Array(r)),"ArrayBuffer"];if(ArrayBuffer.isView(r)){const e=r,n=e.constructor.name,o=new Uint8Array(e.buffer,e.byteOffset,e.byteLength);return n==="Uint8Array"?[i,"bytes",p(o)]:[i,"bytes",p(o),n]}if(Array.isArray(r)){const e=r.map(n=>c(n,a+1));return e.length>0&&e[0]===i?[i,"arr",e]:e}if(!v(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 l=r,t={};for(const e of Object.keys(l)){const n=l[e];if(n===void 0)continue;const o=c(n,a+1);e===d?Object.defineProperty(t,e,{configurable:!0,enumerable:!0,value:o,writable:!0}):t[e]=o}return t},u=(r,a=0)=>{if(a>b)throw new RangeError(`wire-codec: value nesting exceeds the ${b}-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(t=>u(t,a+1));case"bigint":{const t=r[2];if(typeof t!="string"||t.length>g||!/^-?\d+$/.test(t))throw new RangeError(`wire-codec: invalid or over-long bigint (max ${g} digits)`);return BigInt(t)}case"date":return new Date(u(r[2],a+1));case"map":return new Map(r[2].map(([t,e])=>[u(t,a+1),u(e,a+1)]));case"set":return new Set(r[2].map(t=>u(t,a+1)));case"url":return new URL(r[2]);case"error":{const t=r[2],e=r[3],n=(Object.hasOwn(m,t)?m[t]:void 0)??Error,o=new n(e);o.name!==t&&Object.defineProperty(o,"name",{configurable:!0,value:t,writable:!0});const f=u(r[4],a+1);for(const y of Object.keys(f))y===d?Object.defineProperty(o,y,{configurable:!0,enumerable:!0,value:f[y],writable:!0}):o[y]=f[y];return r.length>5&&Object.defineProperty(o,"cause",{configurable:!0,value:u(r[5],a+1),writable:!0}),o}case"bytes":{const t=A(r[2]),e=r[3]??"Uint8Array";if(e==="ArrayBuffer")return t.buffer.byteLength===t.byteLength?t.buffer:t.slice().buffer;const n=Object.hasOwn(w,e)?w[e]:void 0;return n?new n(t.slice().buffer):t}case"inf":return 1/0;case"nan":return Number.NaN;case"undefined":return;default:return r.map(t=>u(t,a+1))}return r.map(t=>u(t,a+1))}const s=r,l={};for(const t of Object.keys(s)){const e=u(s[t],a+1);t===d?Object.defineProperty(l,t,{configurable:!0,enumerable:!0,value:e,writable:!0}):l[t]=e}return l};export{v as A,c as a,u as s};
|