@amalgm/live 0.2.81-main.47337359401 → 0.2.81-main.47344836802
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
var k=Object.defineProperty;var l=(c,t)=>k(c,"name",{value:t,configurable:!0});import{classifyFault as I}from"../faults/classify.js";import{OwnedEffects as O}from"./owned-effects.js";import{RetryClock as S}from"./retry-clock.js";import{ENTITY_RECORD_CARGO_MISSING as T,ENTITY_RECORD_OVER_STORAGE_LIMIT as E,EntityRecordRefusedError as g,acceptedPrefix as P,selectBatch as q}from"./send-batch.js";import{AheadScan as _}from"./send-ahead.js";import{ENTITY_RECORD_LOOKAHEAD_ROWS as p,SendPreparation as D}from"./send-preparation.js";const b=Object.freeze({progressed:!1,failure:null}),m=Object.freeze({progressed:!0,failure:null}),R=l(()=>new Error("entity record Send stopped before stamping the rows it owes"),"sendStopped");function A(c){if(c instanceof g)return c.code!==E;const t=I(c);return t.kind==="refusal"||t.kind==="need"&&t.need.subject?.type!=="authority"}l(A,"aboutOneRow");class x{static{l(this,"SendLine")}#e;#p;#
|
|
1
|
+
var k=Object.defineProperty;var l=(c,t)=>k(c,"name",{value:t,configurable:!0});import{classifyFault as I}from"../faults/classify.js";import{OwnedEffects as O}from"./owned-effects.js";import{RetryClock as S}from"./retry-clock.js";import{ENTITY_RECORD_CARGO_MISSING as T,ENTITY_RECORD_OVER_STORAGE_LIMIT as E,EntityRecordRefusedError as g,acceptedPrefix as P,selectBatch as q}from"./send-batch.js";import{AheadScan as _}from"./send-ahead.js";import{ENTITY_RECORD_LOOKAHEAD_ROWS as p,SendPreparation as D}from"./send-preparation.js";const b=Object.freeze({progressed:!1,failure:null}),m=Object.freeze({progressed:!0,failure:null}),R=l(()=>new Error("entity record Send stopped before stamping the rows it owes"),"sendStopped");function A(c){if(c instanceof g)return c.code!==E;const t=I(c);return t.kind==="refusal"||t.kind==="need"&&t.need.subject?.type!=="authority"}l(A,"aboutOneRow");class x{static{l(this,"SendLine")}#e;#p;#i;#h;#m;#s=new O(R);#I;#a;#o=null;#b=!1;#l=!1;#n=!1;#r=new Map;#t=null;#c=null;#y=0;#S=!1;#R=0;#O=[];#E=null;#u=null;#k=new Set;#d=0;#f=0;#T=0;#g=0;constructor(t){this.#e=t.store,this.#p=t.authority,this.#I=t.onStamped,this.#a=t.onError,this.#i=new D(t.cargo,t.onError),this.#h=new S(t.schedule),this.#m=new S(t.schedule)}get stamped(){return this.#T}get uncertainThrough(){return this.#b?this.#d:void 0}get paused(){return this.#t?.error??null}get held(){return this.#t?this.#t.error:this.#r.size>0?this.#D():null}async waits(t){if(this.#t)return this.#t.error;const e=this.#c;if(!e)return null;const i=await this.#s.run(()=>this.#e.readPlace(t)),n={type:i?.type??"folder",parentUUID:i?.parentUUID??null,name:""};return await e.behind({entityId:t,facets:[],result:n})?this.held:null}start(){if(!this.#o){const t=l(()=>this.resume(),"resume");this.#O=[this.#p.onStorageChanged(t),this.#p.onDisconnect(t)]}return this.#o??=this.#s.run(()=>this.#e.readLocalSequence()).then(t=>{this.#d=this.#f=t,this.#b=!0,this.wake()}),this.#o}resume(){this.#R+=1,this.#S=!1,this.#t&&(this.#t=null,this.#w(),this.wake())}wake(){this.#l||(this.#n=!0,this.#P())}async settle(){if(!this.#o)throw new Error("entity record Send has not started");const t=this.#s.run(()=>this.#e.readLocalSequence()),e=t.catch(()=>0);this.#k.add(e);try{const[,i]=await Promise.all([this.#o,t]);this.#r.size>0&&this.#_();let n=null,a=!1;for(;this.#g<i;){const[o]=await this.#s.run(()=>this.#e.readPending(1));if(!o||o.localSequence>i)break;if(o.localSequence<=this.#g)continue;if(n)throw n.error;if(this.#t)throw this.#t.error;if(a)throw this.#D();const s=this.#u,h=await(s??this.#q());n=h.failure,a=!s&&!h.progressed&&this.#r.size>0}return i}finally{this.#k.delete(e),this.wake()}}async stop(){this.#l=!0,this.#h.cancel(),this.#m.cancel();for(const t of this.#O)t();await Promise.allSettled([this.#o,this.#E,this.#u,this.#i.stop(),this.#s.stop()])}#P(){if(!this.#b||this.#l||this.#h.armed||this.#E)return;const t=this.#A();this.#E=t,t.then(()=>{this.#E=null,this.#n&&this.#P()})}async#A(){for(;!this.#l&&this.#n&&!this.#h.armed;){this.#n=!1;const t=await(this.#u??this.#q());if(t.failure)return;t.progressed&&(this.#n=!0)}}#q(){this.#h.cancel();const t=this.#N();return this.#u=t,t.then(()=>{this.#u===t&&(this.#u=null)}),t}async#L(){const t=this.#c;if(!t)return this.#s.run(()=>this.#e.readPending(p));for(;t.wanting;){const e=await this.#s.run(()=>this.#e.readPending(p,t.after));if(await t.judge(e),e.length<p)break}return t!==this.#c?null:t.reach!==null?(this.#t=null,this.#y=t.reach,this.#S=!0,this.#w(),null):t.ready}async#N(){let t=[],e=0,i;const n=this.#R,a=this.#y;this.#y=0;const o=this.#c;try{const s=await this.#L();if(s===null)return m;const h=await this.#C(),u=s.filter(r=>r.localSequence<=h),y=this.#f;if(this.#i.retain(u,y),i=u[0],!i||(await this.#i.head(i),a>0&&await this.#i.settledThrough(a),this.#l))return b;const w=q(u,r=>this.#i.prepared(r));await this.#s.run(()=>this.#e.durableThrough(w[w.length-1].row.localSequence)),t=w;const f=await this.#p.submit(t.map(({submission:r})=>r)),d=P(t.map(({row:r})=>r),f);if(d.length>0&&(await this.#e.stampAccepted(d),e=d.length,o?.stamped(d.map(({row:r})=>r)),this.#M(d,o===null),this.#h.succeeded(),o===null&&this.#m.succeeded(),this.#t||(this.#S=!1)),f.refusal){const r=t[e].row;if(r.localSequence>y||f.refusal.code!==T)throw this.#i.forget([r]),i=r,new g(r.record.mutationId,f.refusal,{id:r.record.entityId,type:r.record.change.result.type});this.#f=r.localSequence-1}return m}catch(s){const h=s instanceof g;if(!h&&t.length>e&&(this.#d=Math.max(this.#d,t[t.length-1].row.localSequence)),this.#f=this.#d,h||(this.#y||=a),this.#l)return{progressed:e>0,failure:{error:s}};if(i&&(h||t.length===0)&&(A(s)||h&&this.#t))return await this.#z(i,s),this.#a(s),m;if(h&&s.code===E){const u=this.#R===n;return u&&(this.#t={error:s,row:i},this.#w(),this.#i.retain([],this.#f)),this.#n=!0,u&&a>0||this.#a(s),{progressed:e>0,failure:{error:s}}}return this.#h.arm(()=>this.wake()),this.#a(s),{progressed:e>0,failure:{error:s}}}}async#z(t,e){this.#r.set(t.localSequence,e),this.#i.forget([t]);const i=this.#c;try{i?await i.stepAside(t):this.#w()}catch(n){this.#a(n),this.#w()}this.#m.arm(()=>this.#_()),this.#n=!0}#_(){this.#r.clear(),this.#w(),this.#f=this.#d,this.wake()}#w(){const t=this.#t;this.#c=this.#r.size>0||t?new _({waiting:this.#r,pause:t&&{row:t.row,reached:this.#S},readPage:l(e=>this.#s.run(()=>this.#e.readPackagePage(e)),"readPage"),readPlace:l(e=>this.#s.run(()=>this.#e.readPlace(e)),"readPlace")}):null}#D(){return this.#r.get(Math.min(...this.#r.keys()))??R()}async#C(){for(const t of[...this.#k]){const e=await t;if(e>this.#g)return e}return Number.POSITIVE_INFINITY}#M(t,e){this.#T+=t.length,e&&(this.#g=Math.max(this.#g,t[t.length-1].row.localSequence)),this.#i.forget(t.map(({row:i})=>i));try{this.#I(t)}catch(i){this.#a(i)}}}export{x as SendLine};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var m=Object.defineProperty;var u=(l,t)=>m(l,"name",{value:t,configurable:!0});Object.defineProperty(exports,"__esModule",{value:!0}),exports.SendLine=void 0;const O=require("../faults/classify.js"),T=require("./owned-effects.js"),E=require("./retry-clock.js"),a=require("./send-batch.js"),I=require("./send-ahead.js"),g=require("./send-preparation.js"),S=Object.freeze({progressed:!1,failure:null}),_=Object.freeze({progressed:!0,failure:null}),R=u(()=>new Error("entity record Send stopped before stamping the rows it owes"),"sendStopped");function b(l){if(l instanceof a.EntityRecordRefusedError)return l.code!==a.ENTITY_RECORD_OVER_STORAGE_LIMIT;const t=(0,O.classifyFault)(l);return t.kind==="refusal"||t.kind==="need"&&t.need.subject?.type!=="authority"}u(b,"aboutOneRow");class k{static{u(this,"SendLine")}#e;#p;#s;#n;#_;#i=new T.OwnedEffects(R);#T;#a;#c=null;#R=!1;#o=!1;#h=!1;#r=new Map;#t=null;#u=null;#y=0;#E=!1;#m=0;#I=[];#S=null;#l=null;#O=new Set;#d=0;#f=0;#b=0;#g=0;constructor(t){this.#e=t.store,this.#p=t.authority,this.#T=t.onStamped,this.#a=t.onError,this.#s=new g.SendPreparation(t.cargo,t.onError),this.#n=new E.RetryClock(t.schedule),this.#_=new E.RetryClock(t.schedule)}get stamped(){return this.#b}get uncertainThrough(){return this.#R?this.#d:void 0}get paused(){return this.#t?.error??null}get held(){return this.#t?this.#t.error:this.#r.size>0?this.#
|
|
1
|
+
"use strict";var m=Object.defineProperty;var u=(l,t)=>m(l,"name",{value:t,configurable:!0});Object.defineProperty(exports,"__esModule",{value:!0}),exports.SendLine=void 0;const O=require("../faults/classify.js"),T=require("./owned-effects.js"),E=require("./retry-clock.js"),a=require("./send-batch.js"),I=require("./send-ahead.js"),g=require("./send-preparation.js"),S=Object.freeze({progressed:!1,failure:null}),_=Object.freeze({progressed:!0,failure:null}),R=u(()=>new Error("entity record Send stopped before stamping the rows it owes"),"sendStopped");function b(l){if(l instanceof a.EntityRecordRefusedError)return l.code!==a.ENTITY_RECORD_OVER_STORAGE_LIMIT;const t=(0,O.classifyFault)(l);return t.kind==="refusal"||t.kind==="need"&&t.need.subject?.type!=="authority"}u(b,"aboutOneRow");class k{static{u(this,"SendLine")}#e;#p;#s;#n;#_;#i=new T.OwnedEffects(R);#T;#a;#c=null;#R=!1;#o=!1;#h=!1;#r=new Map;#t=null;#u=null;#y=0;#E=!1;#m=0;#I=[];#S=null;#l=null;#O=new Set;#d=0;#f=0;#b=0;#g=0;constructor(t){this.#e=t.store,this.#p=t.authority,this.#T=t.onStamped,this.#a=t.onError,this.#s=new g.SendPreparation(t.cargo,t.onError),this.#n=new E.RetryClock(t.schedule),this.#_=new E.RetryClock(t.schedule)}get stamped(){return this.#b}get uncertainThrough(){return this.#R?this.#d:void 0}get paused(){return this.#t?.error??null}get held(){return this.#t?this.#t.error:this.#r.size>0?this.#D():null}async waits(t){if(this.#t)return this.#t.error;const e=this.#u;if(!e)return null;const s=await this.#i.run(()=>this.#e.readPlace(t)),h={type:s?.type??"folder",parentUUID:s?.parentUUID??null,name:""};return await e.behind({entityId:t,facets:[],result:h})?this.held:null}start(){if(!this.#c){const t=u(()=>this.resume(),"resume");this.#I=[this.#p.onStorageChanged(t),this.#p.onDisconnect(t)]}return this.#c??=this.#i.run(()=>this.#e.readLocalSequence()).then(t=>{this.#d=this.#f=t,this.#R=!0,this.wake()}),this.#c}resume(){this.#m+=1,this.#E=!1,this.#t&&(this.#t=null,this.#w(),this.wake())}wake(){this.#o||(this.#h=!0,this.#k())}async settle(){if(!this.#c)throw new Error("entity record Send has not started");const t=this.#i.run(()=>this.#e.readLocalSequence()),e=t.catch(()=>0);this.#O.add(e);try{const[,s]=await Promise.all([this.#c,t]);this.#r.size>0&&this.#P();let h=null,c=!1;for(;this.#g<s;){const[o]=await this.#i.run(()=>this.#e.readPending(1));if(!o||o.localSequence>s)break;if(o.localSequence<=this.#g)continue;if(h)throw h.error;if(this.#t)throw this.#t.error;if(c)throw this.#D();const i=this.#l,n=await(i??this.#q());h=n.failure,c=!i&&!n.progressed&&this.#r.size>0}return s}finally{this.#O.delete(e),this.wake()}}async stop(){this.#o=!0,this.#n.cancel(),this.#_.cancel();for(const t of this.#I)t();await Promise.allSettled([this.#c,this.#S,this.#l,this.#s.stop(),this.#i.stop()])}#k(){if(!this.#R||this.#o||this.#n.armed||this.#S)return;const t=this.#A();this.#S=t,t.then(()=>{this.#S=null,this.#h&&this.#k()})}async#A(){for(;!this.#o&&this.#h&&!this.#n.armed;){this.#h=!1;const t=await(this.#l??this.#q());if(t.failure)return;t.progressed&&(this.#h=!0)}}#q(){this.#n.cancel();const t=this.#j();return this.#l=t,t.then(()=>{this.#l===t&&(this.#l=null)}),t}async#L(){const t=this.#u;if(!t)return this.#i.run(()=>this.#e.readPending(g.ENTITY_RECORD_LOOKAHEAD_ROWS));for(;t.wanting;){const e=await this.#i.run(()=>this.#e.readPending(g.ENTITY_RECORD_LOOKAHEAD_ROWS,t.after));if(await t.judge(e),e.length<g.ENTITY_RECORD_LOOKAHEAD_ROWS)break}return t!==this.#u?null:t.reach!==null?(this.#t=null,this.#y=t.reach,this.#E=!0,this.#w(),null):t.ready}async#j(){let t=[],e=0,s;const h=this.#m,c=this.#y;this.#y=0;const o=this.#u;try{const i=await this.#L();if(i===null)return _;const n=await this.#N(),d=i.filter(r=>r.localSequence<=n),y=this.#f;if(this.#s.retain(d,y),s=d[0],!s||(await this.#s.head(s),c>0&&await this.#s.settledThrough(c),this.#o))return S;const p=(0,a.selectBatch)(d,r=>this.#s.prepared(r));await this.#i.run(()=>this.#e.durableThrough(p[p.length-1].row.localSequence)),t=p;const w=await this.#p.submit(t.map(({submission:r})=>r)),f=(0,a.acceptedPrefix)(t.map(({row:r})=>r),w);if(f.length>0&&(await this.#e.stampAccepted(f),e=f.length,o?.stamped(f.map(({row:r})=>r)),this.#M(f,o===null),this.#n.succeeded(),o===null&&this.#_.succeeded(),this.#t||(this.#E=!1)),w.refusal){const r=t[e].row;if(r.localSequence>y||w.refusal.code!==a.ENTITY_RECORD_CARGO_MISSING)throw this.#s.forget([r]),s=r,new a.EntityRecordRefusedError(r.record.mutationId,w.refusal,{id:r.record.entityId,type:r.record.change.result.type});this.#f=r.localSequence-1}return _}catch(i){const n=i instanceof a.EntityRecordRefusedError;if(!n&&t.length>e&&(this.#d=Math.max(this.#d,t[t.length-1].row.localSequence)),this.#f=this.#d,n||(this.#y||=c),this.#o)return{progressed:e>0,failure:{error:i}};if(s&&(n||t.length===0)&&(b(i)||n&&this.#t))return await this.#C(s,i),this.#a(i),_;if(n&&i.code===a.ENTITY_RECORD_OVER_STORAGE_LIMIT){const d=this.#m===h;return d&&(this.#t={error:i,row:s},this.#w(),this.#s.retain([],this.#f)),this.#h=!0,d&&c>0||this.#a(i),{progressed:e>0,failure:{error:i}}}return this.#n.arm(()=>this.wake()),this.#a(i),{progressed:e>0,failure:{error:i}}}}async#C(t,e){this.#r.set(t.localSequence,e),this.#s.forget([t]);const s=this.#u;try{s?await s.stepAside(t):this.#w()}catch(h){this.#a(h),this.#w()}this.#_.arm(()=>this.#P()),this.#h=!0}#P(){this.#r.clear(),this.#w(),this.#f=this.#d,this.wake()}#w(){const t=this.#t;this.#u=this.#r.size>0||t?new I.AheadScan({waiting:this.#r,pause:t&&{row:t.row,reached:this.#E},readPage:u(e=>this.#i.run(()=>this.#e.readPackagePage(e)),"readPage"),readPlace:u(e=>this.#i.run(()=>this.#e.readPlace(e)),"readPlace")}):null}#D(){return this.#r.get(Math.min(...this.#r.keys()))??R()}async#N(){for(const t of[...this.#O]){const e=await t;if(e>this.#g)return e}return Number.POSITIVE_INFINITY}#M(t,e){this.#b+=t.length,e&&(this.#g=Math.max(this.#g,t[t.length-1].row.localSequence)),this.#s.forget(t.map(({row:s})=>s));try{this.#T(t)}catch(s){this.#a(s)}}}exports.SendLine=k;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amalgm/live",
|
|
3
|
-
"version": "0.2.81-main.
|
|
3
|
+
"version": "0.2.81-main.47344836802",
|
|
4
4
|
"description": "Portable realtime SDK for Amalgm — wire contracts, mutation discipline, and delivery state machines behind host-injected adapters.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist-cjs/index.js",
|
|
@@ -133,11 +133,11 @@
|
|
|
133
133
|
"dependencies": {
|
|
134
134
|
"@amalgm/core": "0.5.1-main.46384328664"
|
|
135
135
|
},
|
|
136
|
-
"gitHead": "
|
|
136
|
+
"gitHead": "e48f36e7deb99c1adbd3ce646f74a3c4bb8aa08c",
|
|
137
137
|
"amalgmSource": {
|
|
138
138
|
"repository": "amalgm-inc/amalgm-live",
|
|
139
139
|
"branch": "main",
|
|
140
|
-
"commit": "
|
|
141
|
-
"occurrence": "
|
|
140
|
+
"commit": "e48f36e7deb99c1adbd3ce646f74a3c4bb8aa08c",
|
|
141
|
+
"occurrence": "47344836802"
|
|
142
142
|
}
|
|
143
143
|
}
|