@lunora/replica 1.0.0-alpha.74 → 1.0.0-alpha.76
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/README.md +3 -1
- package/dist/index.mjs +1 -1
- package/dist/packem_shared/applyDiff-C6A5aCk4.mjs +1 -0
- package/dist/packem_shared/classifyChanges-BDEt9_BL.mjs +1 -0
- package/dist/packem_shared/fnv1a-SzTD85qB.mjs +1 -0
- package/package.json +1 -1
- package/dist/packem_shared/applyDiff-Da160K7_.mjs +0 -1
- package/dist/packem_shared/classifyChanges-ioMfjjbU.mjs +0 -1
package/README.md
CHANGED
|
@@ -112,9 +112,11 @@ const SQL = await initSqlJs();
|
|
|
112
112
|
const adapter = createSqlJsAdapter(new SQL.Database());
|
|
113
113
|
const mirror = new LocalMirror({ db: adapter });
|
|
114
114
|
|
|
115
|
+
// A diff is `{ table, timestamp, changes }` (plus an optional stable `id`).
|
|
116
|
+
// `createTableDiff("todos", changes)` fills the timestamp and id for you.
|
|
115
117
|
mirror.applyDiff({
|
|
116
118
|
table: "todos",
|
|
117
|
-
|
|
119
|
+
timestamp: Date.now(),
|
|
118
120
|
changes: [{ type: "insert", data: { id: "1", title: "hello", done: false } }],
|
|
119
121
|
});
|
|
120
122
|
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createBetterSqlite3Adapter as o}from"./adapters/better-sqlite3.mjs";import{createSqliteWasmAdapter as f}from"./adapters/sqlite-wasm.mjs";import{createSqlJsAdapter as i}from"./adapters/sqljs.mjs";import{applyDiff as m,applyDiffToSnapshot as n,applyDiffs as x}from"./packem_shared/applyDiff-
|
|
1
|
+
import{createBetterSqlite3Adapter as o}from"./adapters/better-sqlite3.mjs";import{createSqliteWasmAdapter as f}from"./adapters/sqlite-wasm.mjs";import{createSqlJsAdapter as i}from"./adapters/sqljs.mjs";import{applyDiff as m,applyDiffToSnapshot as n,applyDiffs as x}from"./packem_shared/applyDiff-C6A5aCk4.mjs";import{defineEvents as l}from"./packem_shared/defineEvents-DHo-VK7G.mjs";import{MaterializerRuntime as S,defineMaterializer as E}from"./packem_shared/MaterializerRuntime-D0HOAe24.mjs";import{applyDiffToDb as v,applyDiffsToDb as y}from"./packem_shared/applyDiffToDb-C6ek5Elp.mjs";import{EventEmitter as d}from"./packem_shared/EventEmitter-uo75adUL.mjs";import{EventLog as M}from"./packem_shared/EventLog-B1-yhArT.mjs";import{EventLogDO as u}from"./packem_shared/EventLogDO-CaZvpgJN.mjs";import{EventLogDOClient as T}from"./packem_shared/EventLogDOClient-DGDMj5L5.mjs";import{EventSource as C,UNHANDLED as h}from"./packem_shared/EventSource-BC0hKJSA.mjs";import{eventsContext as I}from"./packem_shared/eventsContext-Dxow9Y7S.mjs";import{LocalMirror as O}from"./packem_shared/LocalMirror-BIURA-He.mjs";import{isClientSeq as G,isGlobalSeq as H,isInputEvent as J}from"./packem_shared/isClientSeq-D2Xm0_lj.mjs";import{InMemorySnapshotStore as U}from"./packem_shared/InMemorySnapshotStore-C4taIG5K.mjs";import{subscribeToMirror as j}from"./packem_shared/subscribeToMirror-Rq100MXf.mjs";import{SubscriptionManager as w}from"./packem_shared/SubscriptionManager-AhPw3lFc.mjs";import{EventsSync as K}from"./packem_shared/EventsSync-DWyGGZQZ.mjs";import{classifyChanges as Q,createTableDiff as V,diffSize as X,isDiffEmpty as Y,mergeDiffs as Z}from"./packem_shared/classifyChanges-BDEt9_BL.mjs";export{d as EventEmitter,M as EventLog,u as EventLogDO,T as EventLogDOClient,C as EventSource,K as EventsSync,U as InMemorySnapshotStore,O as LocalMirror,S as MaterializerRuntime,w as SubscriptionManager,h as UNHANDLED,m as applyDiff,v as applyDiffToDb,n as applyDiffToSnapshot,x as applyDiffs,y as applyDiffsToDb,Q as classifyChanges,o as createBetterSqlite3Adapter,i as createSqlJsAdapter,f as createSqliteWasmAdapter,V as createTableDiff,l as defineEvents,E as defineMaterializer,X as diffSize,I as eventsContext,G as isClientSeq,Y as isDiffEmpty,H as isGlobalSeq,J as isInputEvent,Z as mergeDiffs,j as subscribeToMirror};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{f as i}from"./fnv1a-SzTD85qB.mjs";const r=t=>{if(Array.isArray(t))return t.map(e=>r(e));if(t!==null&&typeof t=="object"){const e=t,s=Object.keys(e);s.sort();const n={};for(const o of s)n[o]=r(e[o]);return n}return t},p=(t,e,s)=>{const n=t.id??String(t.timestamp),o=`${t.table}::${n}::${String(e)}::${JSON.stringify(r(s))}`;return`row-${i(o)}`},c=(t,e)=>{for(const[s,n]of e.changes.entries())switch(n.type){case"delete":{t.delete(n.id);break}case"insert":{const o=n.data.id,a=typeof o=="string"||typeof o=="number"?String(o):p(e,s,n.data);t.set(a,{...n.data,id:a});break}case"update":{const o=t.get(n.id);o&&t.set(n.id,{...o,...n.data});break}}},f=(t,e)=>{const s=new Map(t);return c(s,e),s},y=(t,e)=>{const s=new Map(t);for(const n of e)c(s,n);return s},b=(t,e)=>{const s=new Map(t),n=s.get(e.table)??new Map;return s.set(e.table,f(n,e)),s};export{f as applyDiff,b as applyDiffToSnapshot,y as applyDiffs,r as canonicalizeForHash,p as deriveInsertId,i as fnv1a64Hex};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{f as a}from"./fnv1a-SzTD85qB.mjs";let s=0;const c=()=>{if(typeof crypto<"u"&&typeof crypto.randomUUID=="function")return crypto.randomUUID();s+=1;const t=typeof crypto<"u"&&typeof crypto.getRandomValues=="function"?Array.from(crypto.getRandomValues(new Uint8Array(8)),n=>n.toString(16).padStart(2,"0")).join(""):Math.random().toString(16).slice(2,12);return`id_${Date.now().toString(36)}_${s.toString(36)}_${t}`},i=(t,n,o,r)=>({table:t,changes:n,timestamp:o??Date.now(),id:r??c()}),g=t=>t.changes.length===0,m=t=>t.changes.length,f=t=>{const n=[],o=[],r=[];for(const e of t.changes)e.type==="insert"?n.push(e):e.type==="update"?o.push(e):r.push(e);return{inserts:n,updates:o,deletes:r}},u=t=>{if(t.length===0)return null;const n=t[0],o=t[t.length-1],r=`merge:${a(t.map(e=>e.id??String(e.timestamp)).join("|"))}`;return i(n.table,t.flatMap(e=>e.changes),o.timestamp,r)};export{f as classifyChanges,i as createTableDiff,m as diffSize,g as isDiffEmpty,u as mergeDiffs};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const c=o=>o.toString(16).padStart(4,"0"),g=o=>{let t=8997,n=33826,e=40164,s=52210;for(let h=0;h<o.length;h+=1){const l=o.codePointAt(h)??0;t^=l&65535,n^=l>>>16&65535;const p=t*435,x=n*435,d=e*435+t*256,f=s*435+n*256,r=x+(p>>>16),a=d+(r>>>16),i=f+(a>>>16);t=p&65535,n=r&65535,e=a&65535,s=i&65535}return c(s)+c(e)+c(n)+c(t)};export{g as f};
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
const a=t=>{if(Array.isArray(t))return t.map(n=>a(n));if(t!==null&&typeof t=="object"){const n=t,e=Object.keys(n);e.sort();const o={};for(const s of e)o[s]=a(n[s]);return o}return t},r=t=>t.toString(16).padStart(4,"0"),u=t=>{let n=8997,e=33826,o=40164,s=52210;for(let c=0;c<t.length;c+=1){const i=t.codePointAt(c)??0;n^=i&65535,e^=i>>>16&65535;const p=n*435,y=e*435,h=o*435+n*256,b=s*435+e*256,d=y+(p>>>16),f=h+(d>>>16),g=b+(f>>>16);n=p&65535,e=d&65535,o=f&65535,s=g&65535}return r(s)+r(o)+r(e)+r(n)},x=(t,n,e)=>{const o=t.id??String(t.timestamp),s=`${t.table}::${o}::${String(n)}::${JSON.stringify(a(e))}`;return`row-${u(s)}`},l=(t,n)=>{for(const[e,o]of n.changes.entries())switch(o.type){case"delete":{t.delete(o.id);break}case"insert":{const s=o.data.id,c=typeof s=="string"||typeof s=="number"?String(s):x(n,e,o.data);t.set(c,{...o.data,id:c});break}case"update":{const s=t.get(o.id);s&&t.set(o.id,{...s,...o.data});break}}},w=(t,n)=>{const e=new Map(t);return l(e,n),e},S=(t,n)=>{const e=new Map(t);for(const o of n)l(e,o);return e},I=(t,n)=>{const e=new Map(t),o=e.get(n.table)??new Map;return e.set(n.table,w(o,n)),e};export{w as applyDiff,I as applyDiffToSnapshot,S as applyDiffs,a as canonicalizeForHash,x as deriveInsertId,u as fnv1a64Hex};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{fnv1a64Hex as a}from"./applyDiff-Da160K7_.mjs";let s=0;const c=()=>{if(typeof crypto<"u"&&typeof crypto.randomUUID=="function")return crypto.randomUUID();s+=1;const t=typeof crypto<"u"&&typeof crypto.getRandomValues=="function"?Array.from(crypto.getRandomValues(new Uint8Array(8)),n=>n.toString(16).padStart(2,"0")).join(""):Math.random().toString(16).slice(2,12);return`id_${Date.now().toString(36)}_${s.toString(36)}_${t}`},i=(t,n,o,r)=>({table:t,changes:n,timestamp:o??Date.now(),id:r??c()}),g=t=>t.changes.length===0,m=t=>t.changes.length,u=t=>{const n=[],o=[],r=[];for(const e of t.changes)e.type==="insert"?n.push(e):e.type==="update"?o.push(e):r.push(e);return{inserts:n,updates:o,deletes:r}},f=t=>{if(t.length===0)return null;const n=t[0],o=t[t.length-1],r=`merge:${a(t.map(e=>e.id??String(e.timestamp)).join("|"))}`;return i(n.table,t.flatMap(e=>e.changes),o.timestamp,r)};export{u as classifyChanges,i as createTableDiff,m as diffSize,g as isDiffEmpty,f as mergeDiffs};
|