@lunora/shard-engine 1.0.0-alpha.24 → 1.0.0-alpha.26

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.
Files changed (38) hide show
  1. package/dist/conformance/index.mjs +1 -1
  2. package/dist/index.d.mts +79 -2
  3. package/dist/index.d.ts +79 -2
  4. package/dist/index.mjs +1 -1
  5. package/dist/packem_shared/{ADMIN_FUNCTIONS-B5HZoizX.mjs → ADMIN_FUNCTIONS-Cj1pJjVg.mjs} +1 -1
  6. package/dist/packem_shared/{AGG_COUNT-DmQFpsDX.mjs → AGG_COUNT-CKtq03Go.mjs} +1 -1
  7. package/dist/packem_shared/{CDC_LOG_TABLE-DH-KHUfU.mjs → CDC_LOG_TABLE-DNFFQwF_.mjs} +1 -1
  8. package/dist/packem_shared/{DEFAULT_MAX_RELATION_KEYS-DjKka36Z.mjs → DEFAULT_MAX_RELATION_KEYS-BV1RCoat.mjs} +1 -1
  9. package/dist/packem_shared/{DEFAULT_MAX_RELAYS-B19vrJxP.mjs → DEFAULT_MAX_RELAYS-Cinp9pPC.mjs} +1 -1
  10. package/dist/packem_shared/{DEFAULT_PROMOTION_THRESHOLDS-B2rUe1bg.mjs → DEFAULT_PROMOTION_THRESHOLDS-DYGNAo1I.mjs} +1 -1
  11. package/dist/packem_shared/DurableStreamRunner-B54Jt9Iu.mjs +1 -0
  12. package/dist/packem_shared/{NotUniqueError-By65lhla.mjs → NotUniqueError-DYo7r67J.mjs} +1 -1
  13. package/dist/packem_shared/{RANK_TIEBREAK-DDtST3gN.mjs → RANK_TIEBREAK-BGk411OR.mjs} +1 -1
  14. package/dist/packem_shared/{ReactiveCache-Cu8IfE1M.mjs → ReactiveCache-D_T10KLy.mjs} +1 -1
  15. package/dist/packem_shared/{aggregateTableName-DgYMC5tr.mjs → aggregateTableName-DN7gk6uh.mjs} +1 -1
  16. package/dist/packem_shared/appendStreamChunk-ksZYy1hZ.mjs +19 -0
  17. package/dist/packem_shared/{applyOnDelete-By23GK-k.mjs → applyOnDelete-crbAzVfE.mjs} +1 -1
  18. package/dist/packem_shared/{applySelect-UY-o13Ia.mjs → applySelect-5w13bMAR.mjs} +1 -1
  19. package/dist/packem_shared/awaitWsDrain-PT9o0d6J.mjs +1 -0
  20. package/dist/packem_shared/{backfillAggregateIndexes-BEMWTEq1.mjs → backfillAggregateIndexes-DTOIsYbi.mjs} +1 -1
  21. package/dist/packem_shared/{buildPokeFrames-CqxaN8_H.mjs → buildPokeFrames-DmB-FBeQ.mjs} +1 -1
  22. package/dist/packem_shared/{buildReprojectionMigration-YQSJX2cC.mjs → buildReprojectionMigration-JUwsTNTB.mjs} +1 -1
  23. package/dist/packem_shared/{computeRankPage-D1ygctSC.mjs → computeRankPage-BU8LXvQs.mjs} +1 -1
  24. package/dist/packem_shared/createCompanionSync-D-ckGBdA.mjs +1 -0
  25. package/dist/packem_shared/{ctx-db-companions-c12P7dbv.mjs → ctx-db-companions-BJlCofon.mjs} +1 -1
  26. package/dist/packem_shared/{defineEngineContractSuite-Dp5E4UvF.mjs → defineEngineContractSuite-CvdzORsy.mjs} +1 -1
  27. package/dist/packem_shared/{do-sql-C7qrlm6-.mjs → do-sql-DKSFK627.mjs} +1 -1
  28. package/dist/packem_shared/{isSoftDeleted-Tr2to2aw.mjs → isSoftDeleted-DyEJueIu.mjs} +1 -1
  29. package/dist/packem_shared/{materializeExternalRows-D53xwGfY.mjs → materializeExternalRows-C-5TKdc1.mjs} +1 -1
  30. package/dist/packem_shared/runShardMigrations-BCuK60KT.mjs +5 -0
  31. package/dist/packem_shared/{selectExpiredIds-C3Vv1gPm.mjs → selectExpiredIds-C4Ry_NxG.mjs} +1 -1
  32. package/dist/packem_shared/{selectShapeMemberIds-WzxOG62k.mjs → selectShapeMemberIds-Bkkug6vU.mjs} +1 -1
  33. package/dist/packem_shared/{stableWireKey-l3cjIt-9.mjs → stableWireKey-Diuu1gGc.mjs} +1 -1
  34. package/dist/packem_shared/{wire-codec-Dsy70M3Q.mjs → wire-codec-Dh0j-GnY.mjs} +1 -1
  35. package/package.json +3 -3
  36. package/dist/packem_shared/awaitWsDrain-Bp2jKzIb.mjs +0 -1
  37. package/dist/packem_shared/createCompanionSync-D7DEvUvt.mjs +0 -1
  38. package/dist/packem_shared/runShardMigrations-BWElJTC8.mjs +0 -5
@@ -1 +1 @@
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{c as a,u as s};
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};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/shard-engine",
3
- "version": "1.0.0-alpha.24",
3
+ "version": "1.0.0-alpha.26",
4
4
  "description": "Host-neutral reactive engine for Lunora: per-shard state, OCC, CDC, reactive subscriptions, and the poke protocol. Consumes @lunora/platform host contracts and can be mounted on any platform host.",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -48,8 +48,8 @@
48
48
  "access": "public"
49
49
  },
50
50
  "dependencies": {
51
- "@lunora/errors": "1.0.0-alpha.20",
52
- "@lunora/platform": "1.0.0-alpha.9",
51
+ "@lunora/errors": "1.0.0-alpha.21",
52
+ "@lunora/platform": "1.0.0-alpha.10",
53
53
  "drizzle-orm": "^0.45.2"
54
54
  },
55
55
  "engines": {
@@ -1 +0,0 @@
1
- import{a as l}from"./wire-codec-Dsy70M3Q.mjs";const c="_id",p="__lunora__",b=e=>{if(typeof e!="object"||e===null||Array.isArray(e))return;const r=e[c];return typeof r=="string"?r:void 0},y=e=>{const r=new Map,o=[];for(const s of e){const t=b(s);if(t===void 0||r.has(t))return;r.set(t,s),o.push(t)}return{byId:r,order:o}},g=(e,r)=>{const o=e.order.filter(t=>r.byId.has(t)),s=r.order.filter(t=>e.byId.has(t));return o.length!==s.length?!1:o.every((t,n)=>s[n]===t)},h=(e,r,o,s)=>{const t=[];for(const n of e.order)r.byId.has(n)||t.push({delta:{key:n,op:"delete",table:o},frame:`{"key":${JSON.stringify(n)},"op":"delete","table":${s}}`});return t},m=(e,r,o,s)=>{const t=[];for(const n of r.order){const a=r.byId.get(n),i=e.byId.get(n),f=JSON.stringify(l(a)),d=i===void 0?void 0:JSON.stringify(i);if(d===f)continue;const u=d===void 0?"insert":"update";t.push({delta:{key:n,op:u,row:a,table:o},frame:`{"key":${JSON.stringify(n)},"op":"${u}","row":${f},"table":${s}}`})}return t},S=(e,r,o,s)=>{let t;try{t=JSON.parse(e)}catch{return}if(!Array.isArray(t)||!Array.isArray(r))return;const n=y(t),a=y(r);if(n===void 0||a===void 0||!g(n,a))return;const i=o===""?p:o,f=JSON.stringify(i),d=[...h(n,a,i,f),...m(n,a,i,f)];if(!(d.length>a.order.length)){if(s!==void 0)for(const{frame:u}of d)s.push(u);return d.map(({delta:u})=>u)}},$=(e,r)=>{try{return e.send(r),!0}catch{return!1}},I=(e,r,o,s,t)=>{const n=JSON.stringify(r),a=t===void 0?"":`,"lastMutationId":${String(t)}`;let i=!0;for(const f of o)$(e,`{"type":"delta","id":${n},"delta":${f}${a}${s}}`)||(i=!1);return i},w=async e=>{let r=0;for(;r<100;){r+=1;const{bufferedAmount:o}=e;if(typeof o!="number"||o<1048576)return;await new Promise(s=>{setTimeout(s,20)})}};export{w as awaitWsDrain,I as sendDeltaFrames,S as subscriptionListDeltas,$ as trySendFrame};
@@ -1 +0,0 @@
1
- import{S as C,W as R,B as f}from"./ctx-db-companions-c12P7dbv.mjs";import"@lunora/errors";import"drizzle-orm";import"./AGGREGATE_SQL_FUNCTION-CTo0-9iZ.mjs";import"./aggregateTableName-DgYMC5tr.mjs";import"./runDrizzle-C3n5gJsk.mjs";import"./do-sql-C7qrlm6-.mjs";import"./param-CYxL68V-.mjs";import"./GEO_DEFAULT_PRECISION-DyI5zggj.mjs";import"./applySelect-UY-o13Ia.mjs";import"./RANK_TIEBREAK-DDtST3gN.mjs";import"./sql-projection-jfoe331H.mjs";import"./serializeSqlValue-BR4UOWoP.mjs";export{C as createCompanionSync,R as insertRankRow,f as rankColumnsSql};
@@ -1,5 +0,0 @@
1
- import{l as I,T as N,c as S}from"./ctx-db-companions-c12P7dbv.mjs";import"@lunora/errors";import{sql as e}from"drizzle-orm";import{aggregateTableName as p}from"./aggregateTableName-DgYMC5tr.mjs";import{backfillSearchIndexesForTable as g}from"./backfillAggregateIndexes-BEMWTEq1.mjs";import{migrateCdcLog as h,migrateCdcMeta as l}from"./CDC_LOG_TABLE-DH-KHUfU.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 X,C as b,c as x,p as B,T as c,h as F}from"./do-sql-C7qrlm6-.mjs";import{sortColumnName as M,rankTableName as Y}from"./RANK_TIEBREAK-DDtST3gN.mjs";import{recordSchemaVersion as D}from"./SCHEMA_HISTORY_MAX_VERSIONS-CEK7b_7v.mjs";const k=(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 X(o)){if(!n.unique)continue;const s=`${t}_unique_${i}`;a(r,_(s,t,E(i),!0))}},y=(r,t,o)=>{if(!(!o.searchIndexes||o.searchIndexes.length===0||!b(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)}},j=(r,t,o)=>{if(o.geoIndexes)for(const i of o.geoIndexes){const n=F(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))}},q=(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`)}},G=(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))}},ne=(r,t,o={})=>{o.schemaSnapshot!==void 0&&D(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
- )`),k(r,i,n),y(r,i,n),j(r,i,n),q(r,i,n),G(r,i,n));o.cdc&&(h(r),l(r),R(r)),O(r),C(r)};export{ne as runShardMigrations};