@lunora/db 1.0.0-alpha.253 → 1.0.0-alpha.255
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
|
@@ -42,7 +42,7 @@ interface ChangePlan {
|
|
|
42
42
|
* satisfies it.
|
|
43
43
|
*
|
|
44
44
|
* The `never` parameter positions are deliberate, not laziness. `ctx.db.delete` is
|
|
45
|
-
* `<T extends string>(id: Id<T>) => …` over the **branded** `Id<T>`, and under
|
|
45
|
+
* `<T extends string>(table: T, id: Id<T>) => …` over the **branded** `Id<T>`, and under
|
|
46
46
|
* `strictFunctionTypes` a parameter is contravariant — so declaring `id: string` here
|
|
47
47
|
* would make the real `ctx.db` un-assignable to `PlanWriter` (`string` is not
|
|
48
48
|
* assignable to `string & { __table }`), and every caller would need a cast at the
|
|
@@ -54,11 +54,11 @@ interface ChangePlan {
|
|
|
54
54
|
* id)` when building the plan to catch a malformed id at the boundary.
|
|
55
55
|
*/
|
|
56
56
|
interface PlanWriter {
|
|
57
|
-
delete: (id: never) => Promise<void>;
|
|
57
|
+
delete: (table: never, id: never) => Promise<void>;
|
|
58
58
|
insert: (tableName: never, document: Record<string, unknown>, options?: {
|
|
59
59
|
clientId?: string;
|
|
60
60
|
}) => Promise<unknown>;
|
|
61
|
-
patch: (id: never, patch: Record<string, unknown>) => Promise<void>;
|
|
61
|
+
patch: (table: never, id: never, patch: Record<string, unknown>) => Promise<void>;
|
|
62
62
|
}
|
|
63
63
|
/**
|
|
64
64
|
* Apply `plan` to a map of TanStack collections — the client (optimistic) half.
|
package/dist/index.d.ts
CHANGED
|
@@ -42,7 +42,7 @@ interface ChangePlan {
|
|
|
42
42
|
* satisfies it.
|
|
43
43
|
*
|
|
44
44
|
* The `never` parameter positions are deliberate, not laziness. `ctx.db.delete` is
|
|
45
|
-
* `<T extends string>(id: Id<T>) => …` over the **branded** `Id<T>`, and under
|
|
45
|
+
* `<T extends string>(table: T, id: Id<T>) => …` over the **branded** `Id<T>`, and under
|
|
46
46
|
* `strictFunctionTypes` a parameter is contravariant — so declaring `id: string` here
|
|
47
47
|
* would make the real `ctx.db` un-assignable to `PlanWriter` (`string` is not
|
|
48
48
|
* assignable to `string & { __table }`), and every caller would need a cast at the
|
|
@@ -54,11 +54,11 @@ interface ChangePlan {
|
|
|
54
54
|
* id)` when building the plan to catch a malformed id at the boundary.
|
|
55
55
|
*/
|
|
56
56
|
interface PlanWriter {
|
|
57
|
-
delete: (id: never) => Promise<void>;
|
|
57
|
+
delete: (table: never, id: never) => Promise<void>;
|
|
58
58
|
insert: (tableName: never, document: Record<string, unknown>, options?: {
|
|
59
59
|
clientId?: string;
|
|
60
60
|
}) => Promise<unknown>;
|
|
61
|
-
patch: (id: never, patch: Record<string, unknown>) => Promise<void>;
|
|
61
|
+
patch: (table: never, id: never, patch: Record<string, unknown>) => Promise<void>;
|
|
62
62
|
}
|
|
63
63
|
/**
|
|
64
64
|
* Apply `plan` to a map of TanStack collections — the client (optimistic) half.
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{applyPlanToCollections as r,applyPlanToDb as i}from"./packem_shared/applyPlanToCollections-
|
|
1
|
+
import{applyPlanToCollections as r,applyPlanToDb as i}from"./packem_shared/applyPlanToCollections-DRwloPsc.mjs";import{CHECKPOINT_FALLBACK_MS as a,createCheckpointRegistry as p,getShardCheckpoints as c,lunoraCollectionOptions as l,releaseShardCheckpoints as s}from"./packem_shared/CHECKPOINT_FALLBACK_MS-Dnkx44kO.mjs";import{defineCollections as O}from"./packem_shared/defineCollections-D4Y0GiBS.mjs";import{DIRECT_TRANSACTION_METADATA_KEY as f,bindMutators as u,defineMutator as x,initMutators as A}from"./packem_shared/DIRECT_TRANSACTION_METADATA_KEY-BGf7W7d4.mjs";import{OUTBOX_MUTATION_FN_NAME as m,createExecutorOutboxSink as E,createOptimisticOnlineDetector as _,makeDiffEmit as N,runOutboxMutation as S,toMap as d}from"./packem_shared/OUTBOX_MUTATION_FN_NAME-rGyegnLw.mjs";const t="0.0.0";export{a as CHECKPOINT_FALLBACK_MS,f as DIRECT_TRANSACTION_METADATA_KEY,m as OUTBOX_MUTATION_FN_NAME,t as VERSION,r as applyPlanToCollections,i as applyPlanToDb,u as bindMutators,p as createCheckpointRegistry,E as createExecutorOutboxSink,_ as createOptimisticOnlineDetector,O as defineCollections,x as defineMutator,c as getShardCheckpoints,A as initMutators,l as lunoraCollectionOptions,N as makeDiffEmit,s as releaseShardCheckpoints,S as runOutboxMutation,d as toMap};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const h=t=>{if(t===null||typeof t!="object")return!1;const n=Object.getPrototypeOf(t);return n===null||n===Object.prototype};class a extends Error{}const p=t=>t.includes("."),O=t=>{const n=t.split(".");if(n.length>4||n.includes(""))throw new a(`field path "${t}" must have 1 to ${String(4)} non-empty segments`);return n},
|
|
1
|
+
const h=t=>{if(t===null||typeof t!="object")return!1;const n=Object.getPrototypeOf(t);return n===null||n===Object.prototype};class a extends Error{}const p=t=>t.includes("."),O=t=>{const n=t.split(".");if(n.length>4||n.includes(""))throw new a(`field path "${t}" must have 1 to ${String(4)} non-empty segments`);return n},b=(t,n,e,s)=>{const[o,...r]=n;if(o===void 0)throw new a(`field path "${s}" is empty`);if(t!=null&&!h(t))throw new a(`cannot set "${s}": "${o}" sits inside a value that is not an object`);const i=t??{};return{...i,[o]:r.length===0?e:b(i[o],r,e,s)}},$=(t,n)=>{const e=Object.keys(t).filter(o=>p(o));if(e.length===0)return t;for(const o of e){const r=e.find(i=>i!==o&&i.startsWith(`${o}.`));if(r!==void 0)throw new a(`patch sets both "${o}" and "${r}", which overlap; set one or the other`)}const s={};for(const[o,r]of Object.entries(t))p(o)||(s[o]=r);for(const o of e){const[r="",...i]=O(o);if(Object.hasOwn(t,r))throw new a(`patch sets both "${r}" and "${o}"; set one or the other`);s[r]=b(Object.hasOwn(s,r)?s[r]:n[r],i,t[o],o)}return s},f={decrement:{apply:(t,n)=>t-n,kind:"number"},divide:{apply:(t,n)=>t/n,kind:"number"},increment:{apply:(t,n)=>t+n,kind:"number"},multiply:{apply:(t,n)=>t*n,kind:"number"},toggle:{kind:"boolean"}};class c extends Error{}const y=t=>{if(!h(t))return;const n=Object.keys(t),[e]=n;if(!(n.length!==1||e===void 0||!Object.hasOwn(f,e)))return{operand:t[e],operator:e}},w=t=>y(t)!==void 0,g=(t,n,e,s)=>{const o=f[n];if(o.apply===void 0){if(e!==!0)throw new c(`patch: use { toggle: true } on "${t}".`);if(typeof s!="boolean")throw new c(`patch: cannot toggle "${t}" — its current value is ${String(s)}; set a boolean first.`);return!s}if(typeof e!="number"||!Number.isFinite(e))throw new c(`patch: "${n}" on "${t}" needs a finite number, got ${String(e)}.`);if(typeof s!="number"||!Number.isFinite(s))throw new c(`patch: cannot ${n} "${t}" — its current value is ${String(s)}; set a number first.`);if(n==="divide"&&e===0)throw new c(`patch: cannot divide "${t}" by zero.`);const r=o.apply(s,e);if(!Number.isFinite(r))throw new c(`patch: "${n}" on "${t}" overflows to ${String(r)}.`);return r},u=(t,n)=>{const e=new Set;for(const[s,o]of Object.entries(t))n(s)!==void 0&&w(o)&&e.add(s);return e},m=(t,n,e)=>{let s;for(const o of u(t,e)){const{operand:r,operator:i}=y(t[o]),l=e(o);if(f[i].kind!==l)throw new c(`patch: "${i}" does not apply to the ${String(l)} column "${o}".`);s??={...t},s[o]=g(o,i,r,n[o])}return s??t},v=(t,n)=>{const e=o=>{const r=n[o];return typeof r=="number"||typeof r=="boolean"?typeof r:void 0},s={...t};for(const o of u(t,e))try{Object.assign(s,m({[o]:t[o]},n,e))}catch(r){if(!(r instanceof c))throw r}try{return $(s,n)}catch(o){if(o instanceof a)return s;throw o}},P=(t,n)=>{for(const e of n.deletes??[])t[e.table]?.delete(e.id);for(const e of n.patches??[]){const s=t[e.table];s&&s.update(e.id,o=>{const r=Object.entries(v(e.fields,o)).filter(([i,l])=>{const d=o[i];return!w(l)||typeof d=="object"&&d!==null});Object.assign(o,Object.fromEntries(r))})}for(const e of n.inserts??[]){const s=t[e.table];if(s){if(typeof e.row._id!="string")throw new TypeError(`applyPlanToCollections: insert into "${e.table}" needs an "_id" — mint it client-side so the optimistic row keys match the persisted one`);s.insert(e.row)}}},j=async(t,n)=>{for(const e of n.deletes??[])await t.delete(e.table,e.id);for(const e of n.patches??[])await t.patch(e.table,e.id,e.fields);for(const e of n.inserts??[]){const{_id:s,...o}=e.row;await t.insert(e.table,o,...typeof s=="string"?[{clientId:s}]:[])}};export{P as applyPlanToCollections,j as applyPlanToDb};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lunora/db",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.255",
|
|
4
4
|
"description": "TanStack DB binding: typed, live-synced collections and a durable offline outbox over the Lunora client",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"access": "public"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@lunora/client": "1.0.0-alpha.
|
|
57
|
+
"@lunora/client": "1.0.0-alpha.254",
|
|
58
58
|
"@lunora/errors": ">=1.0.0-alpha.51 <2.0.0-0"
|
|
59
59
|
},
|
|
60
60
|
"peerDependencies": {
|