@amalgm/live 0.2.81-preview.47276383685 → 0.2.81-preview.47301712017
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/apply/contracts.d.ts +4 -0
- package/dist/apply/lane.js +1 -1
- package/dist/apply/line.js +1 -1
- package/dist/apply/rail.js +1 -1
- package/dist/apply/settling.d.ts +1 -1
- package/dist/apply/showing.d.ts +4 -3
- package/dist/apply/showing.js +1 -1
- package/dist/apply/window.js +1 -1
- package/dist/records/publication.js +1 -1
- package/dist/records/rail-ports.d.ts +2 -0
- package/dist/records/rail.d.ts +2 -1
- package/dist/records/rail.js +1 -1
- package/dist/records/send-ahead.d.ts +25 -0
- package/dist/records/send-ahead.js +1 -0
- package/dist/records/send-batch.js +1 -1
- package/dist/records/send-line.d.ts +2 -1
- package/dist/records/send-line.js +1 -1
- package/dist/records/send-preparation.js +1 -1
- package/dist/records/waits.d.ts +27 -0
- package/dist/records/waits.js +1 -0
- package/dist-cjs/apply/lane.js +1 -1
- package/dist-cjs/apply/line.js +1 -1
- package/dist-cjs/apply/rail.js +1 -1
- package/dist-cjs/apply/showing.js +1 -1
- package/dist-cjs/apply/window.js +1 -1
- package/dist-cjs/records/publication.js +1 -1
- package/dist-cjs/records/rail.js +1 -1
- package/dist-cjs/records/send-ahead.js +1 -0
- package/dist-cjs/records/send-batch.js +1 -1
- package/dist-cjs/records/send-line.js +1 -1
- package/dist-cjs/records/send-preparation.js +1 -1
- package/dist-cjs/records/waits.js +1 -0
- package/package.json +4 -4
- package/dist/records/send-freeing.d.ts +0 -14
- package/dist/records/send-freeing.js +0 -1
- package/dist-cjs/records/send-freeing.js +0 -1
|
@@ -64,6 +64,7 @@ export interface WindowMember {
|
|
|
64
64
|
readonly work: EntityApplyWork;
|
|
65
65
|
readonly judgment: LineJudgment;
|
|
66
66
|
readonly deliverySequence: number;
|
|
67
|
+
readonly unseen?: string;
|
|
67
68
|
}
|
|
68
69
|
export interface ApplyWindow {
|
|
69
70
|
readonly authorityId: string;
|
|
@@ -92,6 +93,9 @@ export type EntityApplyLaneStep = {
|
|
|
92
93
|
} | {
|
|
93
94
|
readonly kind: 'root';
|
|
94
95
|
readonly reason: string;
|
|
96
|
+
} | {
|
|
97
|
+
readonly kind: 'unseen';
|
|
98
|
+
readonly reason: string;
|
|
95
99
|
} | {
|
|
96
100
|
readonly kind: 'prerequisite';
|
|
97
101
|
readonly unit: string;
|
package/dist/apply/lane.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var a=Object.defineProperty;var o=(n,e)=>a(n,"name",{value:e,configurable:!0});import{UUID_PATTERN as l}from"../entities/types.js";import{assertApplyWindow as u,invalidStep as t}from"./line.js";function s(n,e,r){return{kind:"lane",unit:n,emptied:r,through:e,toPrefix:!1,waitsOn:null,met:new Set,waiters:new Set,held:null,queued:!1,running:!1,again:!1}}o(s,"createApplyLane");function d(n,e){const r=`lane step for ${n}`;switch((!e||typeof e!="object"||!Number.isSafeInteger(e.through)||e.through<0)&&t(r),e.kind){case"end":return;case"nowhere":case"root":case"unseen":(typeof e.reason!="string"||e.reason.length===0)&&t(r);return;case"prerequisite":(!l.test(e.unit)||e.unit===n||typeof e.reason!="string"||e.reason.length===0)&&t(r);return;case"window":(e.window?.unit!==n||e.window.cutoff!==e.through||e.window.intent!==null&&(e.window.intent.unit!==n||e.window.intent.cutoff!==e.through))&&t(r),u(e.window,r),e.window.members.some(i=>i.work.kept!==null)&&f(e.window,r);return;default:t(r)}}o(d,"assertApplyLaneStep");function f(n,e){const[r]=n.members;(n.members.length!==1||r.work.play!=="enter"||r.work.records.length!==0||r.work.materialized!==null||r.deliverySequence!==n.cutoff||n.intent!==null&&n.intent.members.some(i=>i.kept===null))&&t(e)}o(f,"assertKeptWindow");export{d as assertApplyLaneStep,s as createApplyLane};
|
package/dist/apply/line.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var f=Object.defineProperty;var
|
|
1
|
+
var f=Object.defineProperty;var r=(e,n)=>f(e,"name",{value:n,configurable:!0});import{UUID_PATTERN as l}from"../entities/types.js";function m(e){return{kind:"line",authorityId:e,endsBefore:null,held:null,queued:!1,running:!1,again:!1}}r(m,"createApplyLine");function k(e,n,o){const i=e.held;return!i?.dependency||i.due||i.dependency.producer!==n||o!==void 0&&!i.dependency.entityIds.some(t=>o.includes(t))?!1:(i.due=!0,!0)}r(k,"releaseApplyLine");function w(e,n){if(e)return e.entityId===null||e.target===null?{entityId:e.entityId??n,reason:e.reason,throughSequence:e.target??e.cutoff??0}:{entityId:e.entityId,reason:e.reason,...e.dependency?{prerequisite:e.dependency}:{},throughSequence:e.target,...e.blocker?{blocker:e.blocker}:{}}}r(w,"heldWait");const a=new Set(["detect","apply","capability","send"]),c=r(e=>!!e&&a.has(e.producer)&&Array.isArray(e.entityIds)&&e.entityIds.length>0&&e.entityIds.every(n=>typeof n=="string"&&n.length>0),"namesRelease");function g(e){if(!c(e))throw new Error("Apply dependency must name the entities that can release it")}r(g,"assertApplyDependency");function b(e,n){(!n||typeof n!="object")&&u(`line step for ${e}`),n.kind!=="end"&&((n.kind!=="window"||n.window?.authorityId!==e||n.window.unit!==null||n.window.cutoff!==null||n.window.members?.some(o=>o.work?.kept!==null)||n.window.intent!==null&&(n.window.intent.unit!==null||n.window.intent.cutoff!==null))&&u(`line step for ${e}`),d(n.window,`line step for ${e}`))}r(b,"assertApplyLineStep");const u=r(e=>{throw new Error(`entity Apply store returned an invalid ${e}`)},"invalidStep");function d(e,n){(!Array.isArray(e.members)||e.members.length===0)&&u(n);const o=r((t,s)=>Number.isSafeInteger(t)&&t>=(s?0:1),"at");for(const t of e.members)(!l.test(t.work?.entityId??"")||t.work.authorityId!==e.authorityId||!o(t.deliverySequence,t.work.kept!==null))&&u(n),(t.unseen!==void 0||t.judgment==="unseen")&&(l.test(t.unseen??"")||u(n));const{deliverySequence:i}=e;(i===null?!e.intent:!o(i,e.members[0].work.kept!==null))&&u(n)}r(d,"assertApplyWindow");export{g as assertApplyDependency,b as assertApplyLineStep,d as assertApplyWindow,m as createApplyLine,w as heldWait,u as invalidStep,k as releaseApplyLine};
|
package/dist/apply/rail.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var E=Object.defineProperty;var d=(o,e)=>E(o,"name",{value:e,configurable:!0});import{UUID_PATTERN as u}from"../entities/types.js";import{FetchAhead as b}from"./fetch-ahead.js";import{EntityApplyJourney as P,outcomeOf as g,stepsAside as O}from"./journey.js";import{assertApplyLaneStep as v,createApplyLane as S}from"./lane.js";import{assertApplyDependency as $,assertApplyLineStep as q,createApplyLine as M,heldWait as c,releaseApplyLine as _}from"./line.js";import{windowEndForWait as m}from"./window.js";const x=8,B=1e3,A=3e4,p=3;class C{static{d(this,"EntityApplyRail")}#e;#g;#P;#M;#_;#o;#O;#d=!1;#t=!1;#a=new Map;#s=new Map;#l={queue:[],steps:new Set};#u={queue:[],steps:new Set};#n=!1;#h=null;#p=1/0;#m=[];#A=0;#v=new Map;#y=null;constructor(e){this.#e=e,this.#g=e.concurrency??x,this.#P=e.laneConcurrency??this.#g,this.#M=e.onBackgroundError??(()=>{}),this.#_=e.onIdle??(()=>{});for(const[t,s]of[["concurrency",this.#g],["lane concurrency",this.#P]])if(!Number.isSafeInteger(s)||s<1)throw new Error(`entity Apply ${t} must be a positive integer`);this.#o=new P(e,()=>this.#A,()=>this.#t),this.#O=new b(e.cargo,{sha256Hex:e.sha256Hex,loops:e.loops})}async start(){if(this.#d)throw new Error("entity Apply rail already started");if(this.#t)throw new Error("entity Apply rail is stopped");this.#d=!0;const e=await this.#e.store.readOpenUnits();if(!Array.isArray(e)||new Set(e).size!==e.length||e.some(t=>!u.test(t)))throw new Error("entity Apply store returned an invalid open unit list");for(const t of e)this.#E(t,null);await this.#x()}fetch(e,t){return this.#d?this.#t?Promise.reject(new Error("entity Apply rail is stopped")):u.test(e)?!Number.isFinite(t.stall)||t.stall<0?Promise.reject(new Error("entity Apply fetch needs a non-negative stall")):t.emptied!==void 0&&typeof t.emptied!="boolean"?Promise.reject(new Error("entity Apply fetch emptied must be a boolean")):new Promise((s,i)=>{const r=this.#E(e,null,t.emptied===!0),n=d(()=>this.#e.schedule.schedule(t.stall,()=>{r.waiters.delete(l)&&(r.emptied&&![...r.waiters].some(a=>a.emptied)&&(r.emptied=!1),s(this.#G(r)))}),"arm");let h=n();const l={emptied:t.emptied===!0,answer:d(a=>{h.cancel(),s(a)},"answer"),fail:d(a=>{h.cancel(),i(a)},"fail"),moved:d(()=>{h.cancel(),h=n()},"moved")};r.waiters.add(l),r.waitsOn===null&&this.#N(r),this.#r()}):Promise.reject(new Error("entity Apply fetch needs a unit UUID")):Promise.reject(new Error("entity Apply rail has not started"))}progressed(e,t){if(!u.test(e))throw new Error("entity Apply progress needs a unit UUID");if(!Number.isSafeInteger(t)||t<0)throw new Error("entity Apply progress needs a byte count");t>0&&!this.#t&&this.#b(e)}recordsAvailable(){this.#I()}localStateChanged(e){this.#c("detect",e),this.#c("apply",e),this.#I()}sendAccepted(e){this.#c("send",e),this.#I()}capabilityChanged(e){this.#c("capability",e),this.#I()}owe(e){if(e.some(t=>!u.test(t)))throw new Error("entity Apply owe needs entity UUIDs");if(!(!this.#d||this.#t)){for(const t of e)this.#R(t);this.#r()}}#I(){!this.#d||this.#t||(this.#n=!0,this.#r())}waiting(){return this.#w().flatMap(e=>c(e.held,y(e))??[])}async flush(){if(!this.#d)throw new Error("entity Apply rail has not started");this.#t||await this.#x()}async stop(){if(this.#t)return;this.#t=!0,this.#q();for(const t of[this.#l,this.#u])for(const s of t.queue.splice(0))s.queued=!1;const e=new Error("entity Apply rail stopped before the fetch answered");for(const t of this.#s.values())for(const s of t.waiters)s.fail(e);for(this.#s.clear();this.#B()>0||this.#h;)await Promise.allSettled([...this.#l.steps,...this.#u.steps,...this.#h?[this.#h]:[]]);await this.#O.stop();for(const t of this.#m.splice(0))t.resolve()}#x(){return new Promise((e,t)=>{this.#m.push({resolve:e,reject:t}),this.#n=!0,this.#r()})}#r(){if(!this.#t){if(this.#n&&this.#h===null){this.#n=!1;const e=this.#F();this.#h=e,e.then(()=>{this.#h=null,this.#r()})}for(const[e,t]of[[this.#u,this.#P],[this.#l,this.#g]])for(;e.steps.size<t&&e.queue.length>0;){const s=e.queue.shift();s.queued=!1,this.#D(s,e)}if(this.#B()===0&&this.#h===null&&!this.#n&&this.#l.queue.length===0&&this.#u.queue.length===0){if(this.#v.clear(),this.#z(this.#e.now())){this.#r();return}this.#$();for(const e of this.#m.splice(0))e.resolve();this.#_()}}}#B(){return this.#l.steps.size+this.#u.steps.size}#w(){return[...this.#a.values(),...this.#s.values()]}#k(e){return e.kind==="line"?this.#a.get(e.authorityId)===e:this.#s.get(e.unit)===e}#i(e){if(!this.#t){if(e.running){e.again=!0;return}e.queued||(e.queued=!0,(e.kind==="line"?this.#l:this.#u).queue.push(e))}}#D(e,t){e.running=!0,e.again=!1;const s=(e.kind==="line"?this.#J(e):this.#H(e)).then(i=>{e.running=!1,t.steps.delete(s),(i||e.again)&&this.#k(e)&&(e.again=!1,this.#i(e)),this.#r()});t.steps.add(s)}async#F(){try{const e=await this.#e.store.readApplyAuthorities();if(!Array.isArray(e)||new Set(e).size!==e.length||e.some(s=>typeof s!="string"||s.length===0))throw new Error("entity Apply store returned an invalid authority list");this.#p=1/0;const t=new Set(e);for(const[s,i]of this.#a)!t.has(s)&&!i.running&&!i.queued&&this.#a.delete(s);for(const s of e){let i=this.#a.get(s);i||(i=M(s),this.#a.set(s,i)),this.#i(i)}}catch(e){this.#p=this.#e.now()+A;const t=this.#m.splice(0);t.length===0&&this.#S(e);for(const s of t)s.reject(e)}}async#J(e){try{const t=e.held;if(t&&t.entityId===null&&!t.due&&t.notBefore>this.#e.now())return!1;const s=this.#A,i=await this.#e.store.readApplyWindow(e.authorityId,e.endsBefore);if(q(e.authorityId,i),this.#t)return!1;if(i.kind==="end"){e.held=null;const r=e.endsBefore!==null;return e.endsBefore=null,r}return i.window.deliverySequence!==null&&this.#O.advance(e.authorityId,i.window.deliverySequence),await this.#L(e,i.window,s)}catch(t){return this.#j(e,t),!1}}async#H(e){try{const t=e.held;if(t&&t.entityId===null&&!t.due&&t.notBefore>this.#e.now())return!1;const s=this.#A,i=await this.#e.store.readFetchWindow(e.unit,e.toPrefix?null:e.through);if(v(e.unit,i),this.#t||!this.#k(e))return!1;switch((i.kind!=="window"||i.window.intent===null)&&(e.toPrefix=!1),e.through!==null&&i.through>e.through&&e.met.clear(),e.through=Math.max(e.through??0,i.through),e.waitsOn=null,i.kind!=="window"&&(e.held=null),i.kind){case"end":return this.#f(e,{kind:"placed"}),!1;case"nowhere":return this.#f(e,{kind:"nowhere",reason:i.reason}),!1;case"root":return await this.#V(e,i.through,i.reason);case"prerequisite":return this.#X(e,i.unit,i.reason,s);case"window":return await this.#L(e,i.window,s)}}catch(t){return this.#j(e,t),!1}}async#V(e,t,s){return e.met.has(e.unit)?(this.#f(e,{kind:"held",unit:e.unit,reason:`${e.unit} entered and still not held: ${s}`}),!1):(await this.#e.effects.enterRoot(e.unit,t),this.#t||!this.#k(e)?!1:(e.through===t&&e.met.add(e.unit),this.#b(e.unit),!0))}#R(e){const t=this.#E(e,null);t.toPrefix=!0,t.met.clear(),this.#i(t)}#E(e,t,s=!1){let i=this.#s.get(e);return i?t!==null&&(i.through===null||i.through<t)&&(i.through=t,i.met.clear(),this.#i(i)):(i=S(e,t,s),this.#s.set(e,i),this.#i(i)),i}#X(e,t,s,i){if(e.met.has(t))return this.#f(e,{kind:"held",unit:t,reason:`${t} placed and still needed: ${s}`}),!1;if(!this.#T(e,t,s))return!1;const r={producer:"apply",entityIds:[t]};return e.held={entityId:null,target:null,kept:null,cutoff:null,attempt:1,notBefore:1/0,releaseOnProgress:!1,due:this.#W(r,i),reason:s,dependency:r},e.held.due}#N(e){const t=e.held;if(t?.dependency?.producer==="apply"){for(const s of t.dependency.entityIds)if(s!==e.unit&&!e.met.has(s)&&!this.#T(e,s,t.reason))return}}#T(e,t,s){const i=[e];let r=this.#s.get(t);for(;r&&r!==e&&!i.includes(r);)i.push(r),r=r.waitsOn===null?void 0:this.#s.get(r.waitsOn);if(r===e){for(const n of i)this.#f(n,{kind:"held",unit:t,reason:`prerequisite cycle through ${t}: ${s}`});return!1}return e.waitsOn??=t,this.#i(this.#E(t,e.through)),!0}#f(e,t){if(!this.#k(e))return;for(const i of e.waiters)i.answer(t);e.waiters.clear(),e.waitsOn=null,(t.kind==="placed"||e.held?.entityId==null)&&this.#s.delete(e.unit);const s=t.kind==="placed"||t.kind==="held"?t:{kind:"held",unit:e.unit,reason:`${e.unit} is nowhere here: ${t.reason}`};for(const i of[...this.#s.values()])if(i.waitsOn===e.unit){if(t.kind!=="placed"){this.#f(i,s);continue}i.met.add(e.unit)}t.kind==="placed"&&(this.#b(e.unit),this.#c("apply",[e.unit]))}#b(e){const t=new Map([[e,!0]]);for(const s of this.#s.values()){const i=new Set;let r=s.unit;for(;r!==null&&!t.has(r)&&!i.has(r);)i.add(r),r=this.#s.get(r)?.waitsOn??null;const n=r!==null&&t.get(r)===!0;for(const h of i)t.set(h,n);if(n)for(const h of s.waiters)h.moved()}}#G(e){let t=e;const s=new Set([e]);for(let i=e.waitsOn===null?void 0:this.#s.get(e.waitsOn);i&&!s.has(i);i=i.waitsOn===null?void 0:this.#s.get(i.waitsOn))s.add(i),t=i;return{kind:"held",unit:t.unit,reason:t.held?.reason??"still placing"}}async#L(e,t,s){const i=t.members[0]?.work.entityId??null;if(e.held&&e.held.entityId!==null&&e.held.entityId!==i&&(e.held=null),await this.#Q(e,t))return!1;let r=await g(()=>this.#o.run(t,()=>e.kind==="lane"&&e.emptied?e.unit:null));if(e.kind==="line"&&typeof r=="object"&&r.kind==="park"&&m(t,r.dependency)===null&&this.#K(e,t,r)&&(r=await g(()=>this.#o.alone(t.members[0]))),r==="progress"||typeof r=="object"&&r.kind==="alone"){if(e.kind==="line")for(const n of t.members)(n.judgment==="waiting"||r!=="progress"&&n.work.entityId===r.entityId)&&this.#R(n.work.entityId);return this.#Z(e,r==="progress"?t.members.map(n=>n.work.entityId):[r.entityId])}if(r==="again")return e.held?.entityId===i&&(e.held=null),!0;if(r.advanced?.length&&this.#Y(e,r.advanced),e.kind==="line"){const n=m(t,r.dependency);if(n!==null)return e.endsBefore=n,!0}return this.#ee(e,t,r,s),e.kind==="lane"&&this.#N(e),e.held.due}#K(e,t,s){const i=t.members[0].work.entityId;if(s.cause!==void 0||!O(t,i))return!1;const r=s.dependency?.entityIds??[i];return r.length===0||r.some(n=>n!==i)?!1:s.dependency?.producer==="capability"?!0:this.#U(e,t)>=p}#U(e,t){const s=e.held,i=t.members[0].work.entityId;return(s?.entityId===i&&s.target===this.#o.targetOf(t)?s.attempt:0)+1}async#Q(e,t){const s=e.held,i=t.members[0];return!s||i===void 0||s.entityId!==i.work.entityId||s.due||s.notBefore<=this.#e.now()||this.#o.targetOf(t)!==s.target||t.cutoff!==s.cutoff?!1:await this.#e.store.localWorkAfter(t.authorityId,i.work.entityId,s.kept??s.target)===null}#Z(e,t){return e.held&&(e.held.entityId===null||t.includes(e.held.entityId))&&(e.held=null),this.#Y(e,t),!0}#Y(e,t){e.kind==="lane"&&(this.#n=!0,this.#b(e.unit)),this.#c("apply",t);for(const s of this.#w())s!==e&&s.held?.releaseOnProgress&&!s.held.due&&(s.held.due=!0,this.#i(s))}#ee(e,t,s,i){if(s.dependency&&$(s.dependency),s.blocker&&!s.dependency)throw new Error("Apply blocker must name the dependency that releases it");const r=t.members[0].work.entityId,n=e.held,h=this.#U(e,t),l=this.#C(h),a=s.again===!0&&h<p,w={entityId:r,target:this.#o.targetOf(t),kept:t.members[0].work.kept,cutoff:t.cutoff,attempt:h,notBefore:s.dependency?1/0:this.#e.now()+(a?0:l),releaseOnProgress:s.releaseOnProgress,due:s.dependency?this.#W(s.dependency,s.comparedAt??i):a,reason:s.reason,...s.dependency?{dependency:s.dependency}:{},...s.blocker?{blocker:s.blocker}:{}};e.held=w,this.#$();const k=c(n,y(e)),f=c(w,y(e));f&&JSON.stringify(f)!==JSON.stringify(k)&&this.#e.onWaiting?.(f),!(!s.report&&(s.dependency!==void 0||h<p))&&this.#S(new Error(`${I(e)} holds at ${r}, which ${s.releaseOnProgress?"is parked on a conflict":s.report?"failed":s.again?"keeps ending unplaced":"stands on ground that keeps moving"}, and will retry in ${l}ms (attempt ${h}): ${s.reason}`,s.cause===void 0?void 0:{cause:s.cause}))}#j(e,t){if(e.kind==="lane"){for(const h of e.waiters)h.fail(t);e.waiters.clear()}const s=e.held,i=(s?.entityId===null?s.attempt:0)+1,r=this.#C(i),n=t instanceof Error?t.message:String(t);e.held={entityId:null,target:null,kept:null,cutoff:null,attempt:i,notBefore:this.#e.now()+r,releaseOnProgress:!1,due:!1,reason:n},this.#$(),this.#S(new Error(`${I(e)} faulted and will retry in ${r}ms (attempt ${i}): ${n}`,{cause:t}))}#S(e){try{this.#M(e)}catch{}}#C(e){const t=Math.min(A,B*2**Math.min(e-1,16)),s=Math.max(0,Math.min(1,this.#e.schedule.random()));return Math.round(t*(.5+s))}#c(e,t){const s=++this.#A;for(const i of t??["*"])this.#v.set(`${e}:${i}`,s);for(const i of this.#w())_(i,e,t)&&this.#i(i)}#W(e,t){return["*",...e.entityIds].some(s=>(this.#v.get(`${e.producer}:${s}`)??0)>t)}#$(){if(this.#t)return;let e=this.#p;for(const i of this.#w())i.held&&!i.held.due&&(e=Math.min(e,i.held.notBefore));if(e===1/0){this.#q();return}if(this.#y?.dueAt===e)return;this.#q();const t=Math.max(0,e-this.#e.now()),s=this.#e.schedule.schedule(t,()=>{this.#y=null,this.#z(e),this.#r()});this.#y={dueAt:e,cancel:d(()=>s.cancel(),"cancel")}}#z(e){let t=!1;for(const s of this.#w())s.held&&!s.held.due&&s.held.notBefore<=e&&(s.held.due=!0,this.#i(s),t=!0);return this.#p<=e&&(this.#p=1/0,this.#n=!0,t=!0),t}#q(){this.#y?.cancel(),this.#y=null}}const y=d(o=>o.kind==="line"?o.authorityId:o.unit,"owner"),I=d(o=>o.kind==="line"?`entity Apply line ${o.authorityId}`:`entity Apply fetch of ${o.unit}`,"label");export{x as ENTITY_APPLY_DEFAULT_CONCURRENCY,B as ENTITY_APPLY_RETRY_BASE_MS,A as ENTITY_APPLY_RETRY_MAX_MS,p as ENTITY_APPLY_SAME_ANSWERS,C as EntityApplyRail};
|
|
1
|
+
var E=Object.defineProperty;var d=(o,e)=>E(o,"name",{value:e,configurable:!0});import{UUID_PATTERN as u}from"../entities/types.js";import{FetchAhead as b}from"./fetch-ahead.js";import{EntityApplyJourney as P,outcomeOf as g,stepsAside as O}from"./journey.js";import{assertApplyLaneStep as v,createApplyLane as S}from"./lane.js";import{assertApplyDependency as $,assertApplyLineStep as q,createApplyLine as M,heldWait as c,releaseApplyLine as _}from"./line.js";import{windowEndForWait as m}from"./window.js";const x=8,B=1e3,A=3e4,p=3;class C{static{d(this,"EntityApplyRail")}#e;#g;#P;#_;#x;#o;#O;#d=!1;#t=!1;#a=new Map;#s=new Map;#l={queue:[],steps:new Set};#u={queue:[],steps:new Set};#n=!1;#h=null;#p=1/0;#m=[];#A=0;#v=new Map;#y=null;constructor(e){this.#e=e,this.#g=e.concurrency??x,this.#P=e.laneConcurrency??this.#g,this.#_=e.onBackgroundError??(()=>{}),this.#x=e.onIdle??(()=>{});for(const[t,s]of[["concurrency",this.#g],["lane concurrency",this.#P]])if(!Number.isSafeInteger(s)||s<1)throw new Error(`entity Apply ${t} must be a positive integer`);this.#o=new P(e,()=>this.#A,()=>this.#t),this.#O=new b(e.cargo,{sha256Hex:e.sha256Hex,loops:e.loops})}async start(){if(this.#d)throw new Error("entity Apply rail already started");if(this.#t)throw new Error("entity Apply rail is stopped");this.#d=!0;const e=await this.#e.store.readOpenUnits();if(!Array.isArray(e)||new Set(e).size!==e.length||e.some(t=>!u.test(t)))throw new Error("entity Apply store returned an invalid open unit list");for(const t of e)this.#E(t,null);await this.#B()}fetch(e,t){return this.#d?this.#t?Promise.reject(new Error("entity Apply rail is stopped")):u.test(e)?!Number.isFinite(t.stall)||t.stall<0?Promise.reject(new Error("entity Apply fetch needs a non-negative stall")):t.emptied!==void 0&&typeof t.emptied!="boolean"?Promise.reject(new Error("entity Apply fetch emptied must be a boolean")):new Promise((s,i)=>{const r=this.#E(e,null,t.emptied===!0),n=d(()=>this.#e.schedule.schedule(t.stall,()=>{r.waiters.delete(l)&&(r.emptied&&![...r.waiters].some(a=>a.emptied)&&(r.emptied=!1),s(this.#K(r)))}),"arm");let h=n();const l={emptied:t.emptied===!0,answer:d(a=>{h.cancel(),s(a)},"answer"),fail:d(a=>{h.cancel(),i(a)},"fail"),moved:d(()=>{h.cancel(),h=n()},"moved")};r.waiters.add(l),r.waitsOn===null&&this.#T(r),this.#r()}):Promise.reject(new Error("entity Apply fetch needs a unit UUID")):Promise.reject(new Error("entity Apply rail has not started"))}progressed(e,t){if(!u.test(e))throw new Error("entity Apply progress needs a unit UUID");if(!Number.isSafeInteger(t)||t<0)throw new Error("entity Apply progress needs a byte count");t>0&&!this.#t&&this.#b(e)}recordsAvailable(){this.#I()}localStateChanged(e){this.#c("detect",e),this.#c("apply",e),this.#I()}sendAccepted(e){this.#c("send",e),this.#I()}capabilityChanged(e){this.#c("capability",e),this.#I()}owe(e){if(e.some(t=>!u.test(t)))throw new Error("entity Apply owe needs entity UUIDs");if(!(!this.#d||this.#t)){for(const t of e)this.#S(t);this.#r()}}#I(){!this.#d||this.#t||(this.#n=!0,this.#r())}waiting(){return this.#w().flatMap(e=>c(e.held,y(e))??[])}async flush(){if(!this.#d)throw new Error("entity Apply rail has not started");this.#t||await this.#B()}async stop(){if(this.#t)return;this.#t=!0,this.#M();for(const t of[this.#l,this.#u])for(const s of t.queue.splice(0))s.queued=!1;const e=new Error("entity Apply rail stopped before the fetch answered");for(const t of this.#s.values())for(const s of t.waiters)s.fail(e);for(this.#s.clear();this.#R()>0||this.#h;)await Promise.allSettled([...this.#l.steps,...this.#u.steps,...this.#h?[this.#h]:[]]);await this.#O.stop();for(const t of this.#m.splice(0))t.resolve()}#B(){return new Promise((e,t)=>{this.#m.push({resolve:e,reject:t}),this.#n=!0,this.#r()})}#r(){if(!this.#t){if(this.#n&&this.#h===null){this.#n=!1;const e=this.#J();this.#h=e,e.then(()=>{this.#h=null,this.#r()})}for(const[e,t]of[[this.#u,this.#P],[this.#l,this.#g]])for(;e.steps.size<t&&e.queue.length>0;){const s=e.queue.shift();s.queued=!1,this.#F(s,e)}if(this.#R()===0&&this.#h===null&&!this.#n&&this.#l.queue.length===0&&this.#u.queue.length===0){if(this.#v.clear(),this.#D(this.#e.now())){this.#r();return}this.#q();for(const e of this.#m.splice(0))e.resolve();this.#x()}}}#R(){return this.#l.steps.size+this.#u.steps.size}#w(){return[...this.#a.values(),...this.#s.values()]}#k(e){return e.kind==="line"?this.#a.get(e.authorityId)===e:this.#s.get(e.unit)===e}#i(e){if(!this.#t){if(e.running){e.again=!0;return}e.queued||(e.queued=!0,(e.kind==="line"?this.#l:this.#u).queue.push(e))}}#F(e,t){e.running=!0,e.again=!1;const s=(e.kind==="line"?this.#H(e):this.#V(e)).then(i=>{e.running=!1,t.steps.delete(s),(i||e.again)&&this.#k(e)&&(e.again=!1,this.#i(e)),this.#r()});t.steps.add(s)}async#J(){try{const e=await this.#e.store.readApplyAuthorities();if(!Array.isArray(e)||new Set(e).size!==e.length||e.some(s=>typeof s!="string"||s.length===0))throw new Error("entity Apply store returned an invalid authority list");this.#p=1/0;const t=new Set(e);for(const[s,i]of this.#a)!t.has(s)&&!i.running&&!i.queued&&this.#a.delete(s);for(const s of e){let i=this.#a.get(s);i||(i=M(s),this.#a.set(s,i)),this.#i(i)}}catch(e){this.#p=this.#e.now()+A;const t=this.#m.splice(0);t.length===0&&this.#$(e);for(const s of t)s.reject(e)}}async#H(e){try{const t=e.held;if(t&&t.entityId===null&&!t.due&&t.notBefore>this.#e.now())return!1;const s=this.#A,i=await this.#e.store.readApplyWindow(e.authorityId,e.endsBefore);if(q(e.authorityId,i),this.#t)return!1;if(i.kind==="end"){e.held=null;const r=e.endsBefore!==null;return e.endsBefore=null,r}return i.window.deliverySequence!==null&&this.#O.advance(e.authorityId,i.window.deliverySequence),await this.#U(e,i.window,s)}catch(t){return this.#C(e,t),!1}}async#V(e){try{const t=e.held;if(t&&t.entityId===null&&!t.due&&t.notBefore>this.#e.now())return!1;const s=this.#A,i=await this.#e.store.readFetchWindow(e.unit,e.toPrefix?null:e.through);if(v(e.unit,i),this.#t||!this.#k(e))return!1;if(e.waitsOn=null,i.kind==="unseen")return this.#N(e,{producer:"detect",entityIds:[e.unit]},i.reason,s);if(!e.again&&(i.kind!=="window"||i.window.intent===null)&&(e.toPrefix=!1),e.through!==null&&i.through>e.through&&e.met.clear(),e.through=Math.max(e.through??0,i.through),i.kind!=="window"&&(e.held=null),e.again&&(i.kind==="end"||i.kind==="nowhere"))return!0;switch(i.kind){case"end":return this.#f(e,{kind:"placed"}),!1;case"nowhere":return this.#f(e,{kind:"nowhere",reason:i.reason}),!1;case"root":return await this.#X(e,i.through,i.reason);case"prerequisite":return this.#G(e,i.unit,i.reason,s);case"window":return await this.#U(e,i.window,s)}}catch(t){return this.#C(e,t),!1}}async#X(e,t,s){return e.met.has(e.unit)?(this.#f(e,{kind:"held",unit:e.unit,reason:`${e.unit} entered and still not held: ${s}`}),!1):(await this.#e.effects.enterRoot(e.unit,t),this.#t||!this.#k(e)?!1:(e.through===t&&e.met.add(e.unit),this.#b(e.unit),!0))}#S(e){const t=this.#E(e,null);t.toPrefix=!0,t.met.clear(),this.#i(t)}#E(e,t,s=!1){let i=this.#s.get(e);return i?t!==null&&(i.through===null||i.through<t)&&(i.through=t,i.met.clear(),this.#i(i)):(i=S(e,t,s),this.#s.set(e,i),this.#i(i)),i}#G(e,t,s,i){return e.met.has(t)?(this.#f(e,{kind:"held",unit:t,reason:`${t} placed and still needed: ${s}`}),!1):this.#L(e,t,s)?this.#N(e,{producer:"apply",entityIds:[t]},s,i):!1}#N(e,t,s,i){return e.held={entityId:null,target:null,kept:null,cutoff:null,attempt:1,notBefore:1/0,releaseOnProgress:!1,due:this.#z(t,i),reason:s,dependency:t},e.held.due}#T(e){const t=e.held;if(t?.dependency?.producer==="apply"){for(const s of t.dependency.entityIds)if(s!==e.unit&&!e.met.has(s)&&!this.#L(e,s,t.reason))return}}#L(e,t,s){const i=[e];let r=this.#s.get(t);for(;r&&r!==e&&!i.includes(r);)i.push(r),r=r.waitsOn===null?void 0:this.#s.get(r.waitsOn);if(r===e){for(const n of i)this.#f(n,{kind:"held",unit:t,reason:`prerequisite cycle through ${t}: ${s}`});return!1}return e.waitsOn??=t,this.#i(this.#E(t,e.through)),!0}#f(e,t){if(!this.#k(e))return;for(const i of e.waiters)i.answer(t);e.waiters.clear(),e.waitsOn=null,(t.kind==="placed"||e.held?.entityId==null)&&this.#s.delete(e.unit);const s=t.kind==="placed"||t.kind==="held"?t:{kind:"held",unit:e.unit,reason:`${e.unit} is nowhere here: ${t.reason}`};for(const i of[...this.#s.values()])if(i.waitsOn===e.unit){if(t.kind!=="placed"){this.#f(i,s);continue}i.met.add(e.unit)}t.kind==="placed"&&(this.#b(e.unit),this.#c("apply",[e.unit]))}#b(e){const t=new Map([[e,!0]]);for(const s of this.#s.values()){const i=new Set;let r=s.unit;for(;r!==null&&!t.has(r)&&!i.has(r);)i.add(r),r=this.#s.get(r)?.waitsOn??null;const n=r!==null&&t.get(r)===!0;for(const h of i)t.set(h,n);if(n)for(const h of s.waiters)h.moved()}}#K(e){let t=e;const s=new Set([e]);for(let i=e.waitsOn===null?void 0:this.#s.get(e.waitsOn);i&&!s.has(i);i=i.waitsOn===null?void 0:this.#s.get(i.waitsOn))s.add(i),t=i;return{kind:"held",unit:t.unit,reason:t.held?.reason??"still placing"}}async#U(e,t,s){const i=t.members[0]?.work.entityId??null;if(e.held&&e.held.entityId!==null&&e.held.entityId!==i&&(e.held=null),await this.#Z(e,t))return!1;let r=await g(()=>this.#o.run(t,()=>e.kind==="lane"&&e.emptied?e.unit:null));if(e.kind==="line"&&typeof r=="object"&&r.kind==="park"&&m(t,r.dependency)===null&&this.#Q(e,t,r)&&(r=await g(()=>this.#o.alone(t.members[0]))),r==="progress"||typeof r=="object"&&r.kind==="alone"){if(e.kind==="line")for(const n of t.members)(n.judgment==="waiting"||r!=="progress"&&n.work.entityId===r.entityId)&&this.#S(n.work.entityId);for(const n of t.members)n.unseen!==void 0&&this.#S(n.unseen);return this.#ee(e,r==="progress"?t.members.map(n=>n.work.entityId):[r.entityId])}if(r==="again")return e.held?.entityId===i&&(e.held=null),!0;if(r.advanced?.length&&this.#j(e,r.advanced),e.kind==="line"){const n=m(t,r.dependency);if(n!==null)return e.endsBefore=n,!0}return this.#te(e,t,r,s),e.kind==="lane"&&this.#T(e),e.held.due}#Q(e,t,s){const i=t.members[0].work.entityId;if(s.cause!==void 0||!O(t,i))return!1;const r=s.dependency?.entityIds??[i];return r.length===0||r.some(n=>n!==i)?!1:s.dependency?.producer==="capability"?!0:this.#Y(e,t)>=p}#Y(e,t){const s=e.held,i=t.members[0].work.entityId;return(s?.entityId===i&&s.target===this.#o.targetOf(t)?s.attempt:0)+1}async#Z(e,t){const s=e.held,i=t.members[0];return!s||i===void 0||s.entityId!==i.work.entityId||s.due||s.notBefore<=this.#e.now()||this.#o.targetOf(t)!==s.target||t.cutoff!==s.cutoff?!1:await this.#e.store.localWorkAfter(t.authorityId,i.work.entityId,s.kept??s.target)===null}#ee(e,t){return e.held&&(e.held.entityId===null||t.includes(e.held.entityId))&&(e.held=null),this.#j(e,t),!0}#j(e,t){e.kind==="lane"&&(this.#n=!0,this.#b(e.unit)),this.#c("apply",t);for(const s of this.#w())s!==e&&s.held?.releaseOnProgress&&!s.held.due&&(s.held.due=!0,this.#i(s))}#te(e,t,s,i){if(s.dependency&&$(s.dependency),s.blocker&&!s.dependency)throw new Error("Apply blocker must name the dependency that releases it");const r=t.members[0].work.entityId,n=e.held,h=this.#Y(e,t),l=this.#W(h),a=s.again===!0&&h<p,w={entityId:r,target:this.#o.targetOf(t),kept:t.members[0].work.kept,cutoff:t.cutoff,attempt:h,notBefore:s.dependency?1/0:this.#e.now()+(a?0:l),releaseOnProgress:s.releaseOnProgress,due:s.dependency?this.#z(s.dependency,s.comparedAt??i):a,reason:s.reason,...s.dependency?{dependency:s.dependency}:{},...s.blocker?{blocker:s.blocker}:{}};e.held=w,this.#q();const k=c(n,y(e)),f=c(w,y(e));f&&JSON.stringify(f)!==JSON.stringify(k)&&this.#e.onWaiting?.(f),!(!s.report&&(s.dependency!==void 0||h<p))&&this.#$(new Error(`${I(e)} holds at ${r}, which ${s.releaseOnProgress?"is parked on a conflict":s.report?"failed":s.again?"keeps ending unplaced":"stands on ground that keeps moving"}, and will retry in ${l}ms (attempt ${h}): ${s.reason}`,s.cause===void 0?void 0:{cause:s.cause}))}#C(e,t){if(e.kind==="lane"){for(const h of e.waiters)h.fail(t);e.waiters.clear()}const s=e.held,i=(s?.entityId===null?s.attempt:0)+1,r=this.#W(i),n=t instanceof Error?t.message:String(t);e.held={entityId:null,target:null,kept:null,cutoff:null,attempt:i,notBefore:this.#e.now()+r,releaseOnProgress:!1,due:!1,reason:n},this.#q(),this.#$(new Error(`${I(e)} faulted and will retry in ${r}ms (attempt ${i}): ${n}`,{cause:t}))}#$(e){try{this.#_(e)}catch{}}#W(e){const t=Math.min(A,B*2**Math.min(e-1,16)),s=Math.max(0,Math.min(1,this.#e.schedule.random()));return Math.round(t*(.5+s))}#c(e,t){const s=++this.#A;for(const i of t??["*"])this.#v.set(`${e}:${i}`,s);for(const i of this.#w())_(i,e,t)&&this.#i(i)}#z(e,t){return["*",...e.entityIds].some(s=>(this.#v.get(`${e.producer}:${s}`)??0)>t)}#q(){if(this.#t)return;let e=this.#p;for(const i of this.#w())i.held&&!i.held.due&&(e=Math.min(e,i.held.notBefore));if(e===1/0){this.#M();return}if(this.#y?.dueAt===e)return;this.#M();const t=Math.max(0,e-this.#e.now()),s=this.#e.schedule.schedule(t,()=>{this.#y=null,this.#D(e),this.#r()});this.#y={dueAt:e,cancel:d(()=>s.cancel(),"cancel")}}#D(e){let t=!1;for(const s of this.#w())s.held&&!s.held.due&&s.held.notBefore<=e&&(s.held.due=!0,this.#i(s),t=!0);return this.#p<=e&&(this.#p=1/0,this.#n=!0,t=!0),t}#M(){this.#y?.cancel(),this.#y=null}}const y=d(o=>o.kind==="line"?o.authorityId:o.unit,"owner"),I=d(o=>o.kind==="line"?`entity Apply line ${o.authorityId}`:`entity Apply fetch of ${o.unit}`,"label");export{x as ENTITY_APPLY_DEFAULT_CONCURRENCY,B as ENTITY_APPLY_RETRY_BASE_MS,A as ENTITY_APPLY_RETRY_MAX_MS,p as ENTITY_APPLY_SAME_ANSWERS,C as EntityApplyRail};
|
package/dist/apply/settling.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { type LocalWork, type OwnLine } from '../clash/local-work.js';
|
|
|
2
2
|
import type { AcceptedEntityRecord } from '../records/contracts.js';
|
|
3
3
|
import { type OutboxRow } from '../records/outbox.js';
|
|
4
4
|
import { type ApplyPlay, type ShowingJudgment } from './showing.js';
|
|
5
|
-
export type ApplySettlement = 'superseded' | 'own' | 'neither' | 'listed' | 'turn' | 'waiting';
|
|
5
|
+
export type ApplySettlement = 'superseded' | 'own' | 'neither' | 'listed' | 'unseen' | 'turn' | 'waiting';
|
|
6
6
|
export type LineJudgment = ApplySettlement | ApplyPlay;
|
|
7
7
|
export interface LineHeadFacts extends OwnLine {
|
|
8
8
|
localWorkAfter(): LocalWork | null;
|
package/dist/apply/showing.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { CloudEntityRecord } from '../entities/cloud.js';
|
|
|
2
2
|
import { type EntityType } from '../entities/types.js';
|
|
3
3
|
import { type UnitPlace } from '../entities/units.js';
|
|
4
4
|
export type ApplyPlay = 'apply' | 'enter' | 'leave';
|
|
5
|
-
export type ShowingJudgment = ApplyPlay | 'neither' | 'listed';
|
|
5
|
+
export type ShowingJudgment = ApplyPlay | 'neither' | 'listed' | 'unseen';
|
|
6
6
|
export declare const APPLY_PLAYS: ReadonlySet<ApplyPlay>;
|
|
7
7
|
export interface ShownPlace {
|
|
8
8
|
readonly parentUUID: string | null;
|
|
@@ -15,7 +15,8 @@ export interface ShownPlace {
|
|
|
15
15
|
readonly sealed?: boolean;
|
|
16
16
|
}
|
|
17
17
|
export type LineParent = (uuid: string) => string | undefined;
|
|
18
|
-
export
|
|
18
|
+
export type BoundPlace = (uuid: string) => ShownPlace | undefined;
|
|
19
|
+
export declare function judgeShowing(result: CloudEntityRecord, shownPlace: (uuid: string) => ShownPlace | undefined, lineParent?: LineParent, bound?: BoundPlace): ShowingJudgment;
|
|
19
20
|
export interface ShownUnit extends UnitPlace {
|
|
20
21
|
readonly name: string;
|
|
21
22
|
readonly home?: boolean;
|
|
@@ -26,5 +27,5 @@ export interface TopEntry {
|
|
|
26
27
|
readonly uuid: string;
|
|
27
28
|
readonly home: boolean;
|
|
28
29
|
}
|
|
29
|
-
export declare function lineReturns(result: CloudEntityRecord, shownPlace: (uuid: string) => ShownPlace | undefined, lineParent: LineParent): ReadonlyMap<string, string>;
|
|
30
|
+
export declare function lineReturns(result: CloudEntityRecord, shownPlace: (uuid: string) => ShownPlace | undefined, lineParent: LineParent, bound?: BoundPlace): ReadonlyMap<string, string>;
|
|
30
31
|
export declare function returnedPlaces(shownPlace: (uuid: string) => ShownPlace | undefined, returns: ReadonlyMap<string, string>): (uuid: string) => ShownPlace | undefined;
|
package/dist/apply/showing.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var U=Object.defineProperty;var
|
|
1
|
+
var U=Object.defineProperty;var s=(e,r)=>U(e,"name",{value:r,configurable:!0});import{CONTAINERS as l,isConstructType as h}from"../entities/types.js";import{fileAbsent as D}from"../git/checkout.js";import{unitOf as I}from"../entities/units.js";import{placedAtHome as b}from"../registration/home-layout.js";const A=new Set(["apply","enter","leave"]),v={onDemand:!1};function M(e,r,u,o){const n=r(e.uuid);if(n!==void 0&&!n.available)return"unseen";const i=n!==void 0,{root:t,returns:f}=m(e,r,u,o);if(t==="sealed")return"neither";if(t==="unseen")return i?"leave":"unseen";if(t===null)return i?"leave":"neither";if(!i&&t.onDemand){const a=w(p=>p===e.uuid?e:void 0,d(r,f));if(I(e.uuid,a)===e.uuid&&!y(e.uuid,a))return"listed"}return i&&(l.has(n.type)||!l.has(e.type))?"apply":"enter"}s(M,"judgeShowing");function w(e,r){return u=>{const o=e(u);if(o?.parentUUID===null)return{...o,home:r(u)?.home===!0};if(o)return o;const n=r(u);return n?.root?{type:n.type,name:n.name,parentUUID:null,home:n.home}:n}}s(w,"shownUnits");function y(e,r,u=new Map){const o=r(e);if(o?.parentUUID===null)return!0;const n=new Set;let i=null;for(let t=e,f=o;f?.parentUUID!=null&&!n.has(t);){const a=u.get(t);if(a!==void 0){i=a;break}n.add(t);const p=r(f.parentUUID);if(p?.parentUUID===null){i={uuid:t,home:p.home===!0};break}t=f.parentUUID,f=p}for(const t of n)u.set(t,i);return i===null?!1:i.home&&b(r(i.uuid).name,i.uuid!==e)}s(y,"placedInRoot");function N(e,r,u,o){return m(e,r,u,o).returns}s(N,"lineReturns");function d(e,r){return r.size===0?e:u=>{const o=e(u),n=r.get(u);return o!==void 0&&n!==void 0?{...o,parentUUID:n}:o}}s(d,"returnedPlaces");const c=new Map;function m(e,r,u,o){const n=new Map;for(;;){const i=d(r,n),t=x(e,i,o);if(t===null||t==="sealed"||t==="unseen")return{root:t,returns:c};if("root"in t)return{root:t.root,returns:n};if(!(u&&t.loop.find(a=>!n.has(a)&&g(a,i,u,n))))return{root:null,returns:c}}}s(m,"showingWalk");function g(e,r,u,o){const n=u(e);return n===void 0||n===r(e)?.parentUUID?!1:(o.set(e,n),!0)}s(g,"returnTo");function x(e,r,u){if(e.status!=="active"||D(e))return null;if(h(e.type))return{root:v};const o=r(e.uuid)??u?.(e.uuid);if(o?.root)return o.available?{root:o}:"unseen";const n=[e.uuid],i=new Map([[e.uuid,0]]);for(let t=e.parentUUID;t!==null;){const f=i.get(t);if(f!==void 0)return{loop:n.slice(Math.max(f,1))};i.set(t,n.length),n.push(t);const a=r(t);if(a?.available===!1)return"unseen";if(!a||!l.has(a.type))return null;if(a.sealed===!0)return"sealed";if(a.root)return{root:a};t=a.parentUUID}return null}s(x,"walkUp");export{A as APPLY_PLAYS,M as judgeShowing,N as lineReturns,y as placedInRoot,d as returnedPlaces,w as shownUnits};
|
package/dist/apply/window.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var M=Object.defineProperty;var a=(r,s)=>M(r,"name",{value:s,configurable:!0});import{collisionBases as k}from"../entities/rules.js";import{CONTAINERS as z,isConstructType as $}from"../entities/types.js";const D=4096;function E(r,s=D){const d=new Map;let p=0;for(const u of r){const{entityId:f}=u.record;let l=d.get(f);if(l===void 0){if(d.size===s)break;d.set(f,l={records:[],deliverySequence:u.deliverySequence,through:0})}const t=l.records.at(-1);if(t!==void 0&&t.change.turn===void 0!=(u.record.change.turn===void 0))break;if(t!==void 0&&u.record.globalSequence!==t.globalSequence+1)throw new Error(`entity ${f} has a gap before sequence ${u.record.globalSequence} inside its window`);l.records.push(u.record),l.through=p=u.deliverySequence}return Object.freeze({members:Object.freeze([...d].map(([u,{records:f,deliverySequence:l,through:t}])=>Object.freeze({entityId:u,records:Object.freeze(f),deliverySequence:l,through:t}))),through:p})}a(E,"foldWindow");function B(r,s,d,p=D){const u=new Map;for(let f=r;;){const l=E(f,p).members.map(o=>{const y=`${o.entityId}:${o.records.at(-1).globalSequence}`;let g=u.get(y);return g===void 0&&u.set(y,g=s(o)),{member:o,judgment:g.judgment,result:g.result}}),t=C(l,d);if(t===null)return l;f=f.slice(0,f.findIndex(o=>o.deliverySequence>=t))}}a(B,"readWindow");const W=a((r,s)=>r!==void 0&&(r.root?r.type!==s.type:r.parentUUID!==s.parentUUID||r.name!==s.name||r.type!==s.type),"movesPlace");function C(r,s){const d=new Set,p=new Set;let u=null;for(const{member:n,judgment:e,result:i}of r)e==="leave"?p.add(n.entityId):(e==="enter"||e==="apply"&&W(s(n.entityId),i))&&d.add(n.entityId),e==="enter"&&z.has(i.type)&&n.through<(u?.through??1/0)&&(u=n);if(d.size===0&&p.size===0)return null;const f=new Map(r.map(({member:n})=>[n.entityId,n.deliverySequence])),l=a((n,e)=>n===null?[]:[e,...k(e)].map(i=>`${n}/${i}`),"slotKeys"),t=a(({member:n,result:e})=>e.status==="active"&&!s(n.entityId)?.root?l(e.parentUUID,e.name):[],"goesTo"),o=a(n=>{const e=s(n.member.entityId);return[...e&&!e.root?l(e.parentUUID,e.name):[],...t(n)]},"slotsOf"),y=new Map,g=new Map,j=a((n,e,i)=>{for(const h of e){const c=n.get(h);c===void 0?n.set(h,[i]):c.length<2&&!c.includes(i)&&c.push(i)}},"note");for(const n of r){const{entityId:e}=n.member;d.has(e)&&j(g,t(n),e),(d.has(e)||p.has(e))&&j(y,o(n),e)}const v=a((n,e)=>{let i;for(const h of l(e.parentUUID,e.name)){const[c,w]=g.get(h)??[],I=c===n?w:c;I!==void 0&&(i===void 0||f.get(I)<f.get(i))&&(i=I)}return i},"pusher"),S=a((n,e,i)=>{const h=new Set([n]);for(let c=e;c!==null&&!h.has(c);){h.add(c);const w=s(c),I=i(c,w);if(I!==void 0)return I;c=w.parentUUID}return null},"climbs"),O=a(n=>{const{member:e,judgment:i,result:h}=n;if(i==="superseded"||i==="own"||i==="turn"||i==="waiting")return[];if($(h.type))return[];const c=[];for(const U of o(n)){const[m,x]=y.get(U)??[],q=m===e.entityId?x:m;q!==void 0&&c.push(q)}const w=s(e.entityId);if(w&&!w.root){const U=S(e.entityId,w.parentUUID,(m,x)=>d.has(m)?m:!x||x.root?null:v(e.entityId,x));U!==null&&c.push(U)}if(h.status!=="active"||w?.root)return c;const I=S(e.entityId,h.parentUUID,(U,m)=>d.has(U)||p.has(U)?U:m?!m.available||!z.has(m.type)||m.root?null:v(e.entityId,m):u!==null&&e.through>u.through?u.entityId:null);return I!==null&&c.push(I),c},"partnersOf");let b=null;for(const n of r){const e=n.member.deliverySequence;if(b!==null&&e>=b)break;for(const i of O(n)){const h=Math.max(e,f.get(i));(b===null||h<b)&&(b=h)}}return b}a(C,"windowCut");function P(r,s){return r.intent!==null||r.unit!==null||s?.producer!=="apply"?null:r.members.slice(1).find(p=>s.entityIds.includes(p.work.entityId))?.deliverySequence??null}a(P,"windowEndForWait");function A(r){const s=new Map(r.map((t,o)=>[t.entityId,{member:t,index:o}])),d=new Map,p=new Set,u=a((t,o)=>{const y=d.get(t);if(y!==void 0)return y;if(o.has(t)){for(const O of o)p.add(O);return-1}const g=s.get(t);if(!g||g.member.parentUUID===null)return 0;const j=s.get(g.member.parentUUID);if(!j)return d.set(t,0),0;o.add(t);const v=u(j.member.entityId,o);o.delete(t);const S=v<0?-1:v+1;return S>=0&&d.set(t,S),S},"depthOf"),f=[],l=[];for(const[t,o]of r.entries()){const y=u(o.entityId,new Set);if(y<0){p.add(o.entityId);continue}(o.play==="leave"?l:f).push({id:o.entityId,depth:y,index:t})}return f.sort((t,o)=>t.depth-o.depth||t.index-o.index),l.sort((t,o)=>o.depth-t.depth||t.index-o.index),Object.freeze({order:Object.freeze([...f,...l].map(({id:t})=>t)),cycle:Object.freeze([...p])})}a(A,"revealOrder");function F(r,s){let d=0;for(;d<r.length&&s(r[d]);)d+=1;return r.slice(0,d)}a(F,"resolvedPrefix");export{D as WINDOW_MEMBERS,E as foldWindow,B as readWindow,F as resolvedPrefix,A as revealOrder,P as windowEndForWait};
|
|
1
|
+
var M=Object.defineProperty;var a=(r,s)=>M(r,"name",{value:s,configurable:!0});import{collisionBases as k}from"../entities/rules.js";import{CONTAINERS as z,isConstructType as $}from"../entities/types.js";const D=4096;function E(r,s=D){const d=new Map;let p=0;for(const u of r){const{entityId:f}=u.record;let l=d.get(f);if(l===void 0){if(d.size===s)break;d.set(f,l={records:[],deliverySequence:u.deliverySequence,through:0})}const t=l.records.at(-1);if(t!==void 0&&t.change.turn===void 0!=(u.record.change.turn===void 0))break;if(t!==void 0&&u.record.globalSequence!==t.globalSequence+1)throw new Error(`entity ${f} has a gap before sequence ${u.record.globalSequence} inside its window`);l.records.push(u.record),l.through=p=u.deliverySequence}return Object.freeze({members:Object.freeze([...d].map(([u,{records:f,deliverySequence:l,through:t}])=>Object.freeze({entityId:u,records:Object.freeze(f),deliverySequence:l,through:t}))),through:p})}a(E,"foldWindow");function B(r,s,d,p=D){const u=new Map;for(let f=r;;){const l=E(f,p).members.map(o=>{const y=`${o.entityId}:${o.records.at(-1).globalSequence}`;let g=u.get(y);return g===void 0&&u.set(y,g=s(o)),{member:o,judgment:g.judgment,result:g.result}}),t=C(l,d);if(t===null)return l;f=f.slice(0,f.findIndex(o=>o.deliverySequence>=t))}}a(B,"readWindow");const W=a((r,s)=>r!==void 0&&(r.root?r.type!==s.type:r.parentUUID!==s.parentUUID||r.name!==s.name||r.type!==s.type),"movesPlace");function C(r,s){const d=new Set,p=new Set;let u=null;for(const{member:n,judgment:e,result:i}of r)e==="leave"?p.add(n.entityId):(e==="enter"||e==="apply"&&W(s(n.entityId),i))&&d.add(n.entityId),e==="enter"&&z.has(i.type)&&n.through<(u?.through??1/0)&&(u=n);if(d.size===0&&p.size===0)return null;const f=new Map(r.map(({member:n})=>[n.entityId,n.deliverySequence])),l=a((n,e)=>n===null?[]:[e,...k(e)].map(i=>`${n}/${i}`),"slotKeys"),t=a(({member:n,result:e})=>e.status==="active"&&!s(n.entityId)?.root?l(e.parentUUID,e.name):[],"goesTo"),o=a(n=>{const e=s(n.member.entityId);return[...e&&!e.root?l(e.parentUUID,e.name):[],...t(n)]},"slotsOf"),y=new Map,g=new Map,j=a((n,e,i)=>{for(const h of e){const c=n.get(h);c===void 0?n.set(h,[i]):c.length<2&&!c.includes(i)&&c.push(i)}},"note");for(const n of r){const{entityId:e}=n.member;d.has(e)&&j(g,t(n),e),(d.has(e)||p.has(e))&&j(y,o(n),e)}const v=a((n,e)=>{let i;for(const h of l(e.parentUUID,e.name)){const[c,w]=g.get(h)??[],I=c===n?w:c;I!==void 0&&(i===void 0||f.get(I)<f.get(i))&&(i=I)}return i},"pusher"),S=a((n,e,i)=>{const h=new Set([n]);for(let c=e;c!==null&&!h.has(c);){h.add(c);const w=s(c),I=i(c,w);if(I!==void 0)return I;c=w.parentUUID}return null},"climbs"),O=a(n=>{const{member:e,judgment:i,result:h}=n;if(i==="superseded"||i==="own"||i==="unseen"||i==="turn"||i==="waiting")return[];if($(h.type))return[];const c=[];for(const U of o(n)){const[m,x]=y.get(U)??[],q=m===e.entityId?x:m;q!==void 0&&c.push(q)}const w=s(e.entityId);if(w&&!w.root){const U=S(e.entityId,w.parentUUID,(m,x)=>d.has(m)?m:!x||x.root?null:v(e.entityId,x));U!==null&&c.push(U)}if(h.status!=="active"||w?.root)return c;const I=S(e.entityId,h.parentUUID,(U,m)=>d.has(U)||p.has(U)?U:m?!m.available||!z.has(m.type)||m.root?null:v(e.entityId,m):u!==null&&e.through>u.through?u.entityId:null);return I!==null&&c.push(I),c},"partnersOf");let b=null;for(const n of r){const e=n.member.deliverySequence;if(b!==null&&e>=b)break;for(const i of O(n)){const h=Math.max(e,f.get(i));(b===null||h<b)&&(b=h)}}return b}a(C,"windowCut");function P(r,s){return r.intent!==null||r.unit!==null||s?.producer!=="apply"?null:r.members.slice(1).find(p=>s.entityIds.includes(p.work.entityId))?.deliverySequence??null}a(P,"windowEndForWait");function A(r){const s=new Map(r.map((t,o)=>[t.entityId,{member:t,index:o}])),d=new Map,p=new Set,u=a((t,o)=>{const y=d.get(t);if(y!==void 0)return y;if(o.has(t)){for(const O of o)p.add(O);return-1}const g=s.get(t);if(!g||g.member.parentUUID===null)return 0;const j=s.get(g.member.parentUUID);if(!j)return d.set(t,0),0;o.add(t);const v=u(j.member.entityId,o);o.delete(t);const S=v<0?-1:v+1;return S>=0&&d.set(t,S),S},"depthOf"),f=[],l=[];for(const[t,o]of r.entries()){const y=u(o.entityId,new Set);if(y<0){p.add(o.entityId);continue}(o.play==="leave"?l:f).push({id:o.entityId,depth:y,index:t})}return f.sort((t,o)=>t.depth-o.depth||t.index-o.index),l.sort((t,o)=>o.depth-t.depth||t.index-o.index),Object.freeze({order:Object.freeze([...f,...l].map(({id:t})=>t)),cycle:Object.freeze([...p])})}a(A,"revealOrder");function F(r,s){let d=0;for(;d<r.length&&s(r[d]);)d+=1;return r.slice(0,d)}a(F,"resolvedPrefix");export{D as WINDOW_MEMBERS,E as foldWindow,B as readWindow,F as resolvedPrefix,A as revealOrder,P as windowEndForWait};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var ee=Object.defineProperty;var f=(e,t)=>ee(e,"name",{value:t,configurable:!0});import{collisionBases as J,materializedSlotProjectionSteps as te}from"../entities/rules.js";import{CONTAINERS as E,CONSTRUCT_TYPES as ne,TYPES as se}from"../entities/types.js";import{eachStep as d,finishSteps as re,ITEMS_PER_BOUNDARY as K,sortSteps as oe}from"../steps.js";const Ue=f(e=>e==="ignored"||e==="waiting","holdsOnlyItself"),Ie=f(e=>(e.type==="repo.git"||e.type==="file.text"||e.type==="file.binary")&&(e.payloadVersion??null)===null,"groundWaits");function V(e,t){const a=new Map;return u=>{const r=new Set;let o=u,c;for(;c===void 0;)o==null||r.has(o)?c=!1:(c=a.get(o))===void 0&&(e.has(o)?c=!0:(r.add(o),o=t(o)));for(const g of r)a.set(g,c);return c}}f(V,"beneath");const $=f(e=>JSON.stringify([e.parentUUID,e.name]),"slot"),B=f((e,t)=>!e||!t||e.parentUUID!==t.parentUUID||e.name!==t.name||e.type!==t.type,"structuralChange");function be(e){const t=new Set;for(const{name:a}of e)for(const u of[a,...J(a)])t.add(u);return[...t]}f(be,"childGroupNames");function we(e,t){const a=new Map;for(const{uuid:r,name:o}of e)a.set(o,(a.get(o)??new Set).add(r));const u=f(r=>new Set([...t(r),...a.get(r)??[]]).size>1,"shared");return[...a.keys()].some(r=>u(r)||J(r).some(u))}f(we,"childGroupOwed");class ie extends Error{static{f(this,"PublicationScopeExceeded")}entityIds;constructor(t){super("scoped publication selection changes context outside its targets"),this.entityIds=t}}function*ae(e,t,a,u){const r=new Map;yield*d(e.before,U=>r.set(U.uuid,U));const o=new Map,c=new Set;yield*d(u.selected,U=>o.set(U.uuid,U)),yield*d(u.withheld,U=>{o.has(U.entityId)||c.add(U.entityId)});const g=new Set,w=[],M=f(U=>{if(g.has(U))return;g.add(U);const O=r.get(U),x=o.get(U);(O===void 0?x!==void 0:!c.has(U)&&(B(O,x)||O.relativePath!==x.relativePath))&&w.push(U)},"judge");yield*d(r.keys(),M),yield*d(e.observed,U=>M(U.uuid)),yield*d(a,M);const S=new Set(w),P=yield*C(yield*A(t)),I=yield*C(yield*A(u.selected));if(yield*d(r,([U,O])=>{const x=I.get(U);E.has(O.type)&&!c.has(U)&&!S.has(U)&&x&&!_(P.get(U),x)&&w.push(U)}),w.length)throw new ie(w.sort())}f(ae,"requireClosedScope");function*le(e,t){let a=0;for(const u of e){const r=t.get(u.uuid);if(B(u,r)||r.uuid!==u.uuid||r.relativePath!==u.relativePath)return!1;++a%K===0&&(yield)}return!0}f(le,"sameStructure");function*H(e){const t=new Set,a=new Set;return yield*d(e.keys(),u=>{if(t.has(u))return;const r=[],o=new Map;let c=u;for(;c!==null&&e.has(c)&&!t.has(c);){const g=o.get(c);if(g!==void 0){for(const w of r.slice(g))a.add(w);break}o.set(c,r.length),r.push(c),c=e.get(c).parentUUID}for(const g of r)t.add(g)}),a}f(H,"cycles");const L=f(e=>!!e.uuid&&se.has(e.type)&&!ne.has(e.type)&&!e.relativePath.startsWith("/")&&(e.relativePath===""||e.relativePath.split("/").every(t=>t&&t!==".."&&t!=="."))&&(e.parentUUID===null||!!e.name&&!e.name.includes("/")),"physical");function*A(e){const t=new Map;if(yield*d(e,a=>{if(!L(a)||t.has(a.uuid))throw new Error("publication input is not a physical identity graph");t.set(a.uuid,a)}),yield*d(e,a=>{if(a.parentUUID===null)return;const u=t.get(a.parentUUID);if(!u||!E.has(u.type))throw new Error("publication input has an invalid parent")}),(yield*H(t)).size)throw new Error("publication input has a parent cycle");return t}f(A,"graph");function*C(e){const t=new Map;yield*d(e.values(),o=>{if(o.parentUUID===null)return;const c=t.get(o.parentUUID)??[];c.push(o),t.set(o.parentUUID,c)});const a=new Map;let u=0;for(const[o,c]of t)a.set(o,yield*te(c)),u+=c.length,u>=K&&(u=0,yield);const r=new Map;return yield*d(e.values(),o=>{const c=[];let g=o;for(;g&&!r.has(g.uuid);)c.push(g),g=g.parentUUID===null?void 0:e.get(g.parentUUID);for(const w of c.reverse()){const M=w.parentUUID===null?null:e.get(w.parentUUID),S=M===null?null:r.get(M.uuid),P=w.parentUUID===null?void 0:a.get(w.parentUUID),I=P?.names.get(w.uuid)??w.name;r.set(w.uuid,{rootId:S?.rootId??w.uuid,path:S===null?"":S.path?`${S.path}/${I}`:I,policyPath:w.relativePath,directory:E.has(w.type),localName:I,siblings:P?.dependencies.get(w.uuid)??new Set})}}),r}f(C,"addresses");const de=f((e,t)=>e&&t?`${e}/${t}`:e||t,"joined"),_=f((e,t)=>e.rootId===t.rootId&&e.path===t.path,"sameAddress");function*ce(e,t){const a=new Map;return yield*d(e,u=>{const{row:r}=u;if(!L(r)||r.parentUUID===null||t.has(r.uuid)||a.has(r.uuid))throw new Error("publication hidden statement is not a retained row outside the active graph");a.set(r.uuid,u)}),a}f(ce,"statements");function*ue(e,t){let a=!0;const u=f(r=>{let o=t.get(r);for(;o&&o.parentUUID!==null;)o=t.get(o.parentUUID);return o?.uuid??null},"rootOf");return yield*d(e.values(),r=>{if(r.parentUUID!==null)return;const o=u(r.uuid);a&&=o===r.uuid||o!==null&&!e.has(o)}),yield*d(t.values(),r=>{r.parentUUID===null&&e.has(r.uuid)&&(a&&=e.get(r.uuid).parentUUID===null)}),a}f(ue,"rootsKept");function*fe(e,t,a){const u=new Map;if(yield*d(t.values(),o=>{const c=a.get(o.uuid);o.parentUUID===null&&c&&c.rootId!==o.uuid&&u.set(o.uuid,c)}),u.size===0)return e;const r=new Map;return yield*d(e,([o,c])=>{const g=u.get(c.rootId);r.set(o,g===void 0?c:{...c,rootId:g.rootId,path:c.path?`${g.path}/${c.path}`:g.path})}),r}f(fe,"absorbedFrame");function*Q(e){if(e.context!==void 0){const n=new Map,l=new Map;yield*d(e.before,s=>n.set(s.uuid,s)),yield*d(e.observed,s=>l.set(s.uuid,s));const i=new Set,h=new Set;yield*d(e.context.before,s=>i.add(s.uuid)),yield*d(e.context.observed,s=>h.add(s.uuid));const p=new Map,m=[];yield*d(e.hidden??[],({row:s})=>p.set(s.uuid,s)),yield*d(e.context.hidden??[],({row:s})=>m.push(s.uuid));const D=f(s=>n.has(s)||l.has(s)||p.has(s),"target");let z=n.size!==e.before.length||l.size!==e.observed.length||i.size!==e.context.before.length||h.size!==e.context.observed.length;if(yield*d([...n.keys(),...l.keys(),...p.keys()],s=>{z||=i.has(s)||h.has(s)}),yield*d(m,s=>{z||=D(s)}),z)throw new Error("publication scope names an identity twice");let j=!1;if(yield*d(e.before,s=>{j||=s.parentUUID!==null&&!(i.has(s.parentUUID)||n.has(s.parentUUID))}),yield*d(e.observed,s=>{j||=s.parentUUID!==null&&!(h.has(s.parentUUID)||l.has(s.parentUUID))}),j)throw new Error("publication scope lacks a target parent");const y=[...e.context.before,...e.before],b=yield*Q({before:y,observed:[...e.context.observed,...e.observed],travels:e.travels,...e.waiting&&{waiting:e.waiting},hidden:[...e.hidden??[],...e.context.hidden??[]]});yield*ae(e.context,y,m,b);const v=f(s=>n.get(s)??p.get(s)??null,"retained"),k=[],N=new Map;return yield*d(b.selected,s=>{if(!D(s.uuid))return;const T=b.sources.get(s.uuid);k.push(T==="before"?v(s.uuid):l.get(s.uuid)),N.set(s.uuid,T)}),Object.freeze({selected:Object.freeze(k),sources:N,withheld:Object.freeze(b.withheld.filter(s=>D(s.entityId)).map(s=>Object.freeze({...s,before:v(s.entityId),observed:l.get(s.entityId)??null})))})}const t=yield*A(e.before),a=yield*A(e.observed);if(!(yield*ue(t,a)))throw new Error("publication cannot remove or replace materialization roots");const u=yield*ce(e.hidden??[],t),r=t.size===a.size&&(yield*le(t.values(),a)),o=yield*C(t),c=r?o:yield*C(a),g=new Map,w=f(n=>{const l=new Set;let i=n,h;for(;(h=g.has(i)?g.get(i):o.get(i)?.rootId)===void 0;){const p=u.get(i)?.row.parentUUID;if(p===void 0||l.has(i)){h=null;break}l.add(i),i=p}for(const p of l)g.set(p,h);return h},"rootOf"),M=new Map;yield*d(u,([n,{row:l}])=>{const i=w(n);i!==null&&M.set(n,{rootId:i,policyPath:l.relativePath,directory:E.has(l.type)})});const S=new Set;yield*d(t.keys(),n=>S.add(n)),yield*d(a.keys(),n=>S.add(n)),yield*d(M.keys(),n=>S.add(n));const P=yield*oe(S,(n,l)=>n<l?-1:n>l?1:0),I=new Map,U=f((n,l)=>l.rootId===n||e.travels(l.policyPath,l.rootId,l.directory),"admitted"),O=new Set;yield*d(P,n=>{const l=o.get(n)??M.get(n),i=c.get(n);if(i===void 0)return;const h=l===void 0?void 0:c.get(l.rootId),p=l!==void 0&&h!==void 0&&h.rootId===i.rootId&&de(h.policyPath,l.policyPath)===i.policyPath&&l.directory===i.directory;if(p&&t.has(n))return;const m=U(n,i);m!==!0&&(m===!1&&!p&&t.get(n)?.parentUUID?O.add(n):I.set(n,"ignored"))});const x=e.waiting;if(x&&x.size>0){const n=V(x,i=>t.get(i)?.parentUUID??u.get(i)?.row.parentUUID),l=V(x,i=>a.get(i)?.parentUUID);yield*d(P,i=>{!I.has(i)&&(n(i)||l(i))&&I.set(i,"waiting")})}const X=f(n=>{const l=u.get(n);return t.get(n)??(l&&!l.trashed?l.row:void 0)},"retained");function*G(){const n=new Map;yield*d(P,i=>{const h=I.has(i)?X(i):O.has(i)?void 0:a.get(i);h&&n.set(i,h)});const l=new Map;return yield*d(P,i=>{if(!I.has(i)||!n.has(i))return;const h=[];let p=i,m;for(;m===void 0&&(m=l.get(p),m===void 0);){h.push(p);const D=n.get(p).parentUUID;D===null?m=!1:n.has(D)?!t.has(p)&&!E.has(n.get(D).type)?m=!0:I.has(D)?p=D:m=!1:m=!0}for(const D of h)l.set(D,m)}),yield*d(l,([i,h])=>{h&&n.delete(i)}),n}f(G,"select");function*W(n){const l=[],i=new Map;yield*d(n,([p,m])=>{l.push(m),i.set(p,I.has(p)?"before":"observed")});const h=[];return yield*d(P,p=>{I.has(p)&&h.push(Object.freeze({entityId:p,before:t.get(p)??u.get(p)?.row??null,observed:a.get(p)??null,reason:I.get(p)}))}),Object.freeze({selected:Object.freeze(l),sources:i,withheld:Object.freeze(h)})}if(f(W,"result"),r)return yield*W(yield*G());const Z=yield*fe(o,t,c),q=f(n=>(I.has(n)?Z:c).get(n),"expectedAddress");for(;;){const n=yield*G(),l=new Map,i=new Map,h=f((y,b,v=!0)=>{const k=v?l:i;!I.has(y)&&!k.has(y)&&k.set(y,b)},"hold");let p=!0;yield*d(n,([y,b])=>{if(b.parentUUID===null)return;const v=n.get(b.parentUUID);(!v||!E.has(v.type))&&(p=!1,I.has(y)?h(b.parentUUID,"parent"):h(y,"parent",!1))});const m=new Set;yield*d(n,([y,b])=>{I.has(y)&&m.add($(b))}),yield*d(n,([y,b])=>{const v=t.get(y);!I.has(y)&&m.has($(b))&&(!v||$(v)!==$(b))&&h(y,"address")});const D=yield*H(n);for(const y of D)h(y,"cycle");const z=p&&D.size===0?yield*C(n):null;z!==null&&(yield*d(n,([y,b])=>{const v=z.get(y),k=q(y);if(k===void 0||_(v,k))return;const N=v.rootId!==k.rootId?"root":"address";if(!I.has(y)){h(y,N,!1);return}let s=b;for(;s;){const T=n.get(s.uuid);B(s,T)&&h(s.uuid,N);const F=o.get(s.uuid),R=z.get(s.uuid);if(R&&F.localName!==R.localName)for(const Y of new Set([...F.siblings,...R.siblings]))B(t.get(Y),n.get(Y))&&h(Y,"address");s=s.parentUUID===null?void 0:t.get(s.parentUUID)}}));const j=l.size?l:i;if(j.size===0){yield*A([...n.values()]);let y=z===null;if(z!==null&&(yield*d(n.keys(),b=>{const v=q(b);y||=v!==void 0&&!_(z.get(b),v)})),y)throw new Error("publication could not retain a coherent address");return yield*W(n)}for(const[y,b]of j)I.set(y,b)}}f(Q,"selectPublicationSteps");function me(e){return re(Q(e))}f(me,"selectPublication");export{ie as PublicationScopeExceeded,be as childGroupNames,we as childGroupOwed,Ie as groundWaits,Ue as holdsOnlyItself,me as selectPublication,Q as selectPublicationSteps};
|
|
1
|
+
var ee=Object.defineProperty;var f=(e,t)=>ee(e,"name",{value:t,configurable:!0});import{collisionBases as J,materializedSlotProjectionSteps as te}from"../entities/rules.js";import{CONTAINERS as E,CONSTRUCT_TYPES as ne,TYPES as se}from"../entities/types.js";import{eachStep as d,finishSteps as re,ITEMS_PER_BOUNDARY as K,sortSteps as oe}from"../steps.js";const Ue=f(e=>e==="ignored"||e==="waiting","holdsOnlyItself"),Ie=f(e=>(e.type==="repo.git"||e.type==="file.text"||e.type==="file.binary")&&(e.payloadVersion??null)===null,"groundWaits");function V(e,t){const a=new Map;return u=>{const r=new Set;let o=u,c;for(;c===void 0;)o==null||r.has(o)?c=!1:(c=a.get(o))===void 0&&(e.has(o)?c=!0:(r.add(o),o=t(o)));for(const g of r)a.set(g,c);return c}}f(V,"beneath");const $=f(e=>JSON.stringify([e.parentUUID,e.name]),"slot"),B=f((e,t)=>!e||!t||e.parentUUID!==t.parentUUID||e.name!==t.name||e.type!==t.type,"structuralChange");function be(e){const t=new Set;for(const{name:a}of e)for(const u of[a,...J(a)])t.add(u);return[...t]}f(be,"childGroupNames");function we(e,t){const a=new Map;for(const{uuid:r,name:o}of e)a.set(o,(a.get(o)??new Set).add(r));const u=f(r=>new Set([...t(r),...a.get(r)??[]]).size>1,"shared");return[...a.keys()].some(r=>u(r)||J(r).some(u))}f(we,"childGroupOwed");class ie extends Error{static{f(this,"PublicationScopeExceeded")}entityIds;constructor(t){super("scoped publication selection changes context outside its targets"),this.entityIds=t}}function*ae(e,t,a,u){const r=new Map;yield*d(e.before,U=>r.set(U.uuid,U));const o=new Map,c=new Set;yield*d(u.selected,U=>o.set(U.uuid,U)),yield*d(u.withheld,U=>{o.has(U.entityId)||c.add(U.entityId)});const g=new Set,w=[],M=f(U=>{if(g.has(U))return;g.add(U);const O=r.get(U),x=o.get(U);(O===void 0?x!==void 0:!c.has(U)&&(B(O,x)||O.relativePath!==x.relativePath))&&w.push(U)},"judge");yield*d(r.keys(),M),yield*d(e.observed,U=>M(U.uuid)),yield*d(a,M);const S=new Set(w),P=yield*C(yield*A(t)),I=yield*C(yield*A(u.selected));if(yield*d(r,([U,O])=>{const x=I.get(U);E.has(O.type)&&!c.has(U)&&!S.has(U)&&x&&!_(P.get(U),x)&&w.push(U)}),w.length)throw new ie(w.sort())}f(ae,"requireClosedScope");function*le(e,t){let a=0;for(const u of e){const r=t.get(u.uuid);if(B(u,r)||r.uuid!==u.uuid||r.relativePath!==u.relativePath)return!1;++a%K===0&&(yield)}return!0}f(le,"sameStructure");function*H(e){const t=new Set,a=new Set;return yield*d(e.keys(),u=>{if(t.has(u))return;const r=[],o=new Map;let c=u;for(;c!==null&&e.has(c)&&!t.has(c);){const g=o.get(c);if(g!==void 0){for(const w of r.slice(g))a.add(w);break}o.set(c,r.length),r.push(c),c=e.get(c).parentUUID}for(const g of r)t.add(g)}),a}f(H,"cycles");const L=f(e=>!!e.uuid&&se.has(e.type)&&!ne.has(e.type)&&!e.relativePath.startsWith("/")&&(e.relativePath===""||e.relativePath.split("/").every(t=>t&&t!==".."&&t!=="."))&&(e.parentUUID===null||!!e.name&&!e.name.includes("/")),"physical");function*A(e){const t=new Map;if(yield*d(e,a=>{if(!L(a)||t.has(a.uuid))throw new Error("publication input is not a physical identity graph");t.set(a.uuid,a)}),yield*d(e,a=>{if(a.parentUUID===null)return;const u=t.get(a.parentUUID);if(!u||!E.has(u.type))throw new Error("publication input has an invalid parent")}),(yield*H(t)).size)throw new Error("publication input has a parent cycle");return t}f(A,"graph");function*C(e){const t=new Map;yield*d(e.values(),o=>{if(o.parentUUID===null)return;const c=t.get(o.parentUUID)??[];c.push(o),t.set(o.parentUUID,c)});const a=new Map;let u=0;for(const[o,c]of t)a.set(o,yield*te(c)),u+=c.length,u>=K&&(u=0,yield);const r=new Map;return yield*d(e.values(),o=>{const c=[];let g=o;for(;g&&!r.has(g.uuid);)c.push(g),g=g.parentUUID===null?void 0:e.get(g.parentUUID);for(const w of c.reverse()){const M=w.parentUUID===null?null:e.get(w.parentUUID),S=M===null?null:r.get(M.uuid),P=w.parentUUID===null?void 0:a.get(w.parentUUID),I=P?.names.get(w.uuid)??w.name;r.set(w.uuid,{rootId:S?.rootId??w.uuid,path:S===null?"":S.path?`${S.path}/${I}`:I,policyPath:w.relativePath,directory:E.has(w.type),localName:I,siblings:P?.dependencies.get(w.uuid)??new Set})}}),r}f(C,"addresses");const de=f((e,t)=>e&&t?`${e}/${t}`:e||t,"joined"),_=f((e,t)=>e.rootId===t.rootId&&e.path===t.path,"sameAddress");function*ce(e,t){const a=new Map;return yield*d(e,u=>{const{row:r}=u;if(!L(r)||t.has(r.uuid)||a.has(r.uuid))throw new Error("publication hidden statement is not a retained row outside the active graph");a.set(r.uuid,u)}),a}f(ce,"statements");function*ue(e,t){let a=!0;const u=f(r=>{let o=t.get(r);for(;o&&o.parentUUID!==null;)o=t.get(o.parentUUID);return o?.uuid??null},"rootOf");return yield*d(e.values(),r=>{if(r.parentUUID!==null)return;const o=u(r.uuid);a&&=o===r.uuid||o!==null&&!e.has(o)}),yield*d(t.values(),r=>{r.parentUUID===null&&e.has(r.uuid)&&(a&&=e.get(r.uuid).parentUUID===null)}),a}f(ue,"rootsKept");function*fe(e,t,a){const u=new Map;if(yield*d(t.values(),o=>{const c=a.get(o.uuid);o.parentUUID===null&&c&&c.rootId!==o.uuid&&u.set(o.uuid,c)}),u.size===0)return e;const r=new Map;return yield*d(e,([o,c])=>{const g=u.get(c.rootId);r.set(o,g===void 0?c:{...c,rootId:g.rootId,path:c.path?`${g.path}/${c.path}`:g.path})}),r}f(fe,"absorbedFrame");function*Q(e){if(e.context!==void 0){const n=new Map,l=new Map;yield*d(e.before,s=>n.set(s.uuid,s)),yield*d(e.observed,s=>l.set(s.uuid,s));const i=new Set,h=new Set;yield*d(e.context.before,s=>i.add(s.uuid)),yield*d(e.context.observed,s=>h.add(s.uuid));const p=new Map,m=[];yield*d(e.hidden??[],({row:s})=>p.set(s.uuid,s)),yield*d(e.context.hidden??[],({row:s})=>m.push(s.uuid));const D=f(s=>n.has(s)||l.has(s)||p.has(s),"target");let z=n.size!==e.before.length||l.size!==e.observed.length||i.size!==e.context.before.length||h.size!==e.context.observed.length;if(yield*d([...n.keys(),...l.keys(),...p.keys()],s=>{z||=i.has(s)||h.has(s)}),yield*d(m,s=>{z||=D(s)}),z)throw new Error("publication scope names an identity twice");let j=!1;if(yield*d(e.before,s=>{j||=s.parentUUID!==null&&!(i.has(s.parentUUID)||n.has(s.parentUUID))}),yield*d(e.observed,s=>{j||=s.parentUUID!==null&&!(h.has(s.parentUUID)||l.has(s.parentUUID))}),j)throw new Error("publication scope lacks a target parent");const y=[...e.context.before,...e.before],b=yield*Q({before:y,observed:[...e.context.observed,...e.observed],travels:e.travels,...e.waiting&&{waiting:e.waiting},hidden:[...e.hidden??[],...e.context.hidden??[]]});yield*ae(e.context,y,m,b);const v=f(s=>n.get(s)??p.get(s)??null,"retained"),k=[],N=new Map;return yield*d(b.selected,s=>{if(!D(s.uuid))return;const T=b.sources.get(s.uuid);k.push(T==="before"?v(s.uuid):l.get(s.uuid)),N.set(s.uuid,T)}),Object.freeze({selected:Object.freeze(k),sources:N,withheld:Object.freeze(b.withheld.filter(s=>D(s.entityId)).map(s=>Object.freeze({...s,before:v(s.entityId),observed:l.get(s.entityId)??null})))})}const t=yield*A(e.before),a=yield*A(e.observed);if(!(yield*ue(t,a)))throw new Error("publication cannot remove or replace materialization roots");const u=yield*ce(e.hidden??[],t),r=t.size===a.size&&(yield*le(t.values(),a)),o=yield*C(t),c=r?o:yield*C(a),g=new Map,w=f(n=>{const l=new Set;let i=n,h;for(;(h=g.has(i)?g.get(i):o.get(i)?.rootId)===void 0;){const p=u.get(i)?.row.parentUUID;if(p===void 0||l.has(i)){h=null;break}l.add(i),i=p}for(const p of l)g.set(p,h);return h},"rootOf"),M=new Map;yield*d(u,([n,{row:l}])=>{const i=w(n);i!==null&&M.set(n,{rootId:i,policyPath:l.relativePath,directory:E.has(l.type)})});const S=new Set;yield*d(t.keys(),n=>S.add(n)),yield*d(a.keys(),n=>S.add(n)),yield*d(M.keys(),n=>S.add(n));const P=yield*oe(S,(n,l)=>n<l?-1:n>l?1:0),I=new Map,U=f((n,l)=>l.rootId===n||e.travels(l.policyPath,l.rootId,l.directory),"admitted"),O=new Set;yield*d(P,n=>{const l=o.get(n)??M.get(n),i=c.get(n);if(i===void 0)return;const h=l===void 0?void 0:c.get(l.rootId),p=l!==void 0&&h!==void 0&&h.rootId===i.rootId&&de(h.policyPath,l.policyPath)===i.policyPath&&l.directory===i.directory;if(p&&t.has(n))return;const m=U(n,i);m!==!0&&(m===!1&&!p&&t.get(n)?.parentUUID?O.add(n):I.set(n,"ignored"))});const x=e.waiting;if(x&&x.size>0){const n=V(x,i=>t.get(i)?.parentUUID??u.get(i)?.row.parentUUID),l=V(x,i=>a.get(i)?.parentUUID);yield*d(P,i=>{!I.has(i)&&(n(i)||l(i))&&I.set(i,"waiting")})}const X=f(n=>{const l=u.get(n);return t.get(n)??(l&&!l.trashed?l.row:void 0)},"retained");function*G(){const n=new Map;yield*d(P,i=>{const h=I.has(i)?X(i):O.has(i)?void 0:a.get(i);h&&n.set(i,h)});const l=new Map;return yield*d(P,i=>{if(!I.has(i)||!n.has(i))return;const h=[];let p=i,m;for(;m===void 0&&(m=l.get(p),m===void 0);){h.push(p);const D=n.get(p).parentUUID;D===null?m=!1:n.has(D)?!t.has(p)&&!E.has(n.get(D).type)?m=!0:I.has(D)?p=D:m=!1:m=!0}for(const D of h)l.set(D,m)}),yield*d(l,([i,h])=>{h&&n.delete(i)}),n}f(G,"select");function*W(n){const l=[],i=new Map;yield*d(n,([p,m])=>{l.push(m),i.set(p,I.has(p)?"before":"observed")});const h=[];return yield*d(P,p=>{I.has(p)&&h.push(Object.freeze({entityId:p,before:t.get(p)??u.get(p)?.row??null,observed:a.get(p)??null,reason:I.get(p)}))}),Object.freeze({selected:Object.freeze(l),sources:i,withheld:Object.freeze(h)})}if(f(W,"result"),r)return yield*W(yield*G());const Z=yield*fe(o,t,c),q=f(n=>(I.has(n)?Z:c).get(n),"expectedAddress");for(;;){const n=yield*G(),l=new Map,i=new Map,h=f((y,b,v=!0)=>{const k=v?l:i;!I.has(y)&&!k.has(y)&&k.set(y,b)},"hold");let p=!0;yield*d(n,([y,b])=>{if(b.parentUUID===null)return;const v=n.get(b.parentUUID);(!v||!E.has(v.type))&&(p=!1,I.has(y)?h(b.parentUUID,"parent"):h(y,"parent",!1))});const m=new Set;yield*d(n,([y,b])=>{I.has(y)&&m.add($(b))}),yield*d(n,([y,b])=>{const v=t.get(y);!I.has(y)&&m.has($(b))&&(!v||$(v)!==$(b))&&h(y,"address")});const D=yield*H(n);for(const y of D)h(y,"cycle");const z=p&&D.size===0?yield*C(n):null;z!==null&&(yield*d(n,([y,b])=>{const v=z.get(y),k=q(y);if(k===void 0||_(v,k))return;const N=v.rootId!==k.rootId?"root":"address";if(!I.has(y)){h(y,N,!1);return}let s=b;for(;s;){const T=n.get(s.uuid);B(s,T)&&h(s.uuid,N);const F=o.get(s.uuid),R=z.get(s.uuid);if(R&&F.localName!==R.localName)for(const Y of new Set([...F.siblings,...R.siblings]))B(t.get(Y),n.get(Y))&&h(Y,"address");s=s.parentUUID===null?void 0:t.get(s.parentUUID)}}));const j=l.size?l:i;if(j.size===0){yield*A([...n.values()]);let y=z===null;if(z!==null&&(yield*d(n.keys(),b=>{const v=q(b);y||=v!==void 0&&!_(z.get(b),v)})),y)throw new Error("publication could not retain a coherent address");return yield*W(n)}for(const[y,b]of j)I.set(y,b)}}f(Q,"selectPublicationSteps");function me(e){return re(Q(e))}f(me,"selectPublication");export{ie as PublicationScopeExceeded,be as childGroupNames,we as childGroupOwed,Ie as groundWaits,Ue as holdsOnlyItself,me as selectPublication,Q as selectPublicationSteps};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { UnitPlace } from '../entities/units.js';
|
|
1
2
|
import type { GraphPageRef } from '../entities/graph-pages.js';
|
|
2
3
|
import type { OutboxRow } from './outbox.js';
|
|
3
4
|
import type { AcceptedEntityRecord, EntityRecordInlineCargo, LocalEntityRecord } from './contracts.js';
|
|
@@ -45,6 +46,7 @@ export interface EntityRecordStorePort {
|
|
|
45
46
|
countPending(through?: number): MaybePromise<number>;
|
|
46
47
|
durableThrough(localSequence: number): MaybePromise<void>;
|
|
47
48
|
readPackagePage(ref: GraphPageRef): MaybePromise<readonly unknown[]>;
|
|
49
|
+
readPlace(uuid: string): MaybePromise<UnitPlace | null>;
|
|
48
50
|
stampAccepted(stamps: readonly EntityRecordStamp[]): MaybePromise<void>;
|
|
49
51
|
readReceipts(authorityId: string, through: number): MaybePromise<EntityRecordReceipts>;
|
|
50
52
|
readDeliveryCursor(authorityId: string): MaybePromise<number | null>;
|
package/dist/records/rail.d.ts
CHANGED
|
@@ -5,7 +5,8 @@ export declare class EntityRecordRail {
|
|
|
5
5
|
constructor(options: EntityRecordRailOptions);
|
|
6
6
|
start(): Promise<void>;
|
|
7
7
|
get sendPaused(): EntityRecordRefusedError | null;
|
|
8
|
-
get sendHeld():
|
|
8
|
+
get sendHeld(): unknown;
|
|
9
|
+
sendWaits(entityId: string): Promise<unknown>;
|
|
9
10
|
localRecordsAvailable(): void;
|
|
10
11
|
hold(entityId: string): void;
|
|
11
12
|
release(entityId: string): void;
|
package/dist/records/rail.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var u=Object.defineProperty;var
|
|
1
|
+
var u=Object.defineProperty;var n=(o,t)=>u(o,"name",{value:t,configurable:!0});import{channelRecords as l}from"./contracts.js";import{ReceiveLoop as y}from"./receive-loop.js";import{SendLine as w}from"./send-line.js";import{UnsentCount as f}from"./unsent-count.js";class v{static{n(this,"EntityRecordRail")}#n;#h;#o;#d;#c;#e;#t;#s;#r=!1;#i=null;constructor(t){if(!t.authorityId.trim())throw new Error("entity record authority is required");this.#n=t.authorityId,this.#h=t.store,this.#o=t.schedule,this.#d=t.onOutboxAccepted??(()=>{}),this.#c=t.onBackgroundError??(()=>{});const r=n(e=>this.#a(e),"onError");this.#e=new y({authorityId:t.authorityId,store:t.store,authority:t.authority,schedule:t.schedule,channels:t.channels??[],onInboxCommitted:t.onInboxCommitted??(()=>{}),onError:r}),this.#t=new w({store:t.store,cargo:t.cargo,authority:t.authority,schedule:t.schedule,onStamped:n(e=>this.#u(e),"onStamped"),onError:r});const i=t.onUnsent;this.#s=i?new f({read:n(()=>t.store.countPending(),"read"),say:i,onError:r,schedule:t.schedule}):null}async start(){if(this.#r)throw new Error("entity record rail already started");if(this.#i)throw new Error("entity record rail is stopped");this.#r=!0,this.#s?.changed(),this.#e.start(),await this.#t.start()}get sendPaused(){return this.#t.paused}get sendHeld(){return this.#t.held}sendWaits(t){return this.#t.waits(t)}localRecordsAvailable(){this.#s?.changed(),this.#t.wake()}hold(t){this.#e.hold(t)}release(t){this.#e.release(t)}async flush(){if(!this.#r)throw new Error("entity record rail has not started");if(this.#i)throw new Error("entity record rail is stopped");await this.#e.coverReceipts(await this.#t.settle())}async receiveThrough(t){if(!this.#r)throw new Error("entity record rail has not started");await this.#e.receiveThrough(t)}async receiveCurrent(){if(!this.#r)throw new Error("entity record rail has not started");await this.#e.receiveCurrent()}async close(t,r){if(!Number.isFinite(t)||t<0)throw new Error("entity record close budget must be a non-negative number of milliseconds");const i=this.#t.stamped;if(this.#r&&!this.#i&&t>0){let s=n(()=>{},"expire");const h=new Promise(a=>{s=a}),c=this.#o.schedule(t,()=>s());try{const a=this.#t.settle();await Promise.race([a.catch(d=>{!this.#i&&d!==this.#t.paused&&this.#a(d)}),h])}finally{c.cancel()}}const e=this.stop();return await r(),await e,{accepted:this.#t.stamped-i,pending:await this.#h.countPending(),unconfirmed:await this.#h.countPending(this.#t.uncertainThrough)}}stop(){return this.#i??=Promise.all([this.#e.stop(),this.#t.stop(),this.#s?.stop()]).then(()=>{}),this.#i}#u(t){this.#s?.changed();const r=new Set;let i=!1;for(const{row:e,accepted:s}of t){for(const{entityId:h}of l(e.record))r.add(h),s.authorityId!==this.#n&&this.#e.ring({authorityId:s.authorityId,entityId:h});s.authorityId===this.#n&&(i=!0)}i&&this.#e.ring({authorityId:this.#n,entityId:null});try{this.#d([...r])}catch(e){this.#a(e)}}#a(t){try{this.#c(t)}catch{}}}export{v as EntityRecordRail};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { GraphPageRef } from '../entities/graph-pages.js';
|
|
2
|
+
import type { UnitPlace } from '../entities/units.js';
|
|
3
|
+
import type { MaybePromise, PendingEntityRecord } from './rail-ports.js';
|
|
4
|
+
import { type WaitingChange } from './waits.js';
|
|
5
|
+
export interface AheadScanInput {
|
|
6
|
+
readonly waiting: ReadonlyMap<number, unknown>;
|
|
7
|
+
readonly pause: {
|
|
8
|
+
readonly row: PendingEntityRecord;
|
|
9
|
+
readonly reached: boolean;
|
|
10
|
+
} | null;
|
|
11
|
+
readonly readPage: (ref: GraphPageRef) => MaybePromise<readonly unknown[]>;
|
|
12
|
+
readonly readPlace: (uuid: string) => MaybePromise<UnitPlace | null>;
|
|
13
|
+
}
|
|
14
|
+
export declare class AheadScan {
|
|
15
|
+
#private;
|
|
16
|
+
constructor(input: AheadScanInput);
|
|
17
|
+
get after(): number;
|
|
18
|
+
get reach(): number | null;
|
|
19
|
+
get ready(): readonly PendingEntityRecord[];
|
|
20
|
+
get wanting(): boolean;
|
|
21
|
+
behind(change: WaitingChange): Promise<boolean>;
|
|
22
|
+
judge(rows: readonly PendingEntityRecord[]): Promise<void>;
|
|
23
|
+
stamped(rows: readonly PendingEntityRecord[]): void;
|
|
24
|
+
stepAside(refused: PendingEntityRecord): Promise<void>;
|
|
25
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var l=Object.defineProperty;var o=(c,e)=>l(c,"name",{value:e,configurable:!0});import{channelRecords as h}from"./contracts.js";import{freesStorage as u}from"./send-batch.js";import{ENTITY_RECORD_LOOKAHEAD_ROWS as f}from"./send-preparation.js";import{Waits as d}from"./waits.js";class q{static{o(this,"AheadScan")}#t;#s;#e=[];#a=0;#i=null;#r=new Set;constructor(e){this.#t=e,this.#s=new d(e.readPlace)}get after(){return this.#a}get reach(){return this.#i}get ready(){return this.#e}get wanting(){return this.#e.length<f}behind(e){return this.#s.behind(e)}async judge(e){for(const t of e){if(!this.wanting)return;await this.#n(t),this.#a=t.localSequence}}stamped(e){const t=new Set(e.map(s=>s.localSequence));this.#e.splice(0,this.#e.length,...this.#e.filter(s=>!t.has(s.localSequence)))}async stepAside(e){const t=e.localSequence,s=this.#e.filter(a=>a.localSequence>t);this.#e.splice(0,this.#e.length,...this.#e.filter(a=>a.localSequence<t)),await this.#c(e);for(const a of s)await this.#n(a)}async#n(e){const{pause:t,waiting:s}=this.#t;if(t?.row.localSequence!==e.localSequence&&!s.has(e.localSequence)&&this.#o(e)){if(!await this.#h(e)){this.#e.push(e);return}t&&!t.reached&&this.#r.has(e.record.entityId)&&(this.#i??=e.localSequence)}await this.#c(e)}#o(e){const{pause:t}=this.#t;return t===null||e.record.authorityId===t.row.record.authorityId&&u(e)}async#h(e){for(const{entityId:t,change:s}of h(e.record))if(await this.#s.behind({entityId:t,facets:s.facets,result:s.result}))return!0;return!1}async#c(e){const t=this.#t.pause?.row.localSequence===e.localSequence;for(const{entityId:s,change:a}of h(e.record)){const i=[];if(a.replay.kind==="package")for(const r of a.replay.pages)for(const n of await this.#t.readPage(r))i.push(n);if(await this.#s.hold({entityId:s,facets:a.facets,result:a.result},i),t)for(const r of[s,...i.map(({uuid:n})=>n)])this.#r.add(r)}}}export{q as AheadScan};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var g=Object.defineProperty;var a=(r,e)=>g(r,"name",{value:e,configurable:!0});import{failure as _,recoveryTrigger as y}from"../faults/need.js";import{asRefusal as p}from"../detection/refusal.js";import{channelRecords as E}from"./contracts.js";import{acceptOutboxRow as R,isOwnRecord as w}from"./outbox.js";const b=256,S=16*1024*1024,N="entity_record_cargo_missing",I="files_over_storage_limit",m=new Set(["trash","delete"]);function k(r){const{facets:e,cargo:t}=r.record.change;return t.length===0&&e.length>0&&e.every(o=>m.has(o))}a(k,"freesStorage");function q(r,e){const t=r[0];if(!t)return[];const o=[];let n=0;for(const d of r){if(d.record.authorityId!==t.record.authorityId||o.length===b)break;const c=e(d);if(!c||o.length>0&&n+c.bytes>S)break;o.push(c),n+=c.bytes}return o}a(q,"selectBatch");const T=new Set(["entity_record_read_forbidden","entity_record_write_forbidden",I]);class Y extends Error{static{a(this,"EntityRecordRefusedError")}code;mutationId;need;constructor(e,t,o=null){super(`entity record ${e} was refused: ${t.code}: ${t.message}`),this.name="EntityRecordRefusedError",this.code=t.code,this.mutationId=e;const n=T.has(t.code);this.need=n?null:{law:"record-refused",trigger:y(t.code),subject:o,lost:e},n&&p(this)}}function B(r,e){const t=r[0],o=t?{id:t.record.authorityId,type:"authority"}:null,n=a(()=>_("entity record batch answer does not match the offered batch","invariant-broken","answer-not-offered",o),"notOffered"),d=new Map,c=[];let l=0;for(;l<e.accepted.length;){const s=r[c.length];if(s===void 0)throw n();const f=E(s.record),h=e.accepted.slice(l,l+f.length);if(h.length!==f.length)throw n();R(s,h[0].record),h.forEach(({record:i},u)=>{if(u>0&&!w(s,i)||i.entityId!==f[u].entityId)throw n();if(i.globalSequence<=(d.get(i.entityId)??0))throw _("entity record batch answer breaks this computer's acceptance order","invariant-broken","answer-out-of-order",o,s.record.mutationId);d.set(i.entityId,i.globalSequence)}),c.push(Object.freeze({row:s,accepted:h[0].record,deliverySequence:h.at(-1).deliverySequence})),l+=f.length}if(e.refusal===null!=(c.length===r.length))throw n();return c}a(B,"acceptedPrefix");export{S as ENTITY_RECORD_BATCH_BYTES,b as ENTITY_RECORD_BATCH_ROWS,N as ENTITY_RECORD_CARGO_MISSING,I as ENTITY_RECORD_OVER_STORAGE_LIMIT,Y as EntityRecordRefusedError,B as acceptedPrefix,k as freesStorage,q as selectBatch};
|
|
@@ -14,7 +14,8 @@ export declare class SendLine {
|
|
|
14
14
|
get stamped(): number;
|
|
15
15
|
get uncertainThrough(): number | undefined;
|
|
16
16
|
get paused(): EntityRecordRefusedError | null;
|
|
17
|
-
get held():
|
|
17
|
+
get held(): unknown;
|
|
18
|
+
waits(entityId: string): Promise<unknown>;
|
|
18
19
|
start(): Promise<void>;
|
|
19
20
|
resume(): void;
|
|
20
21
|
wake(): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
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;#s;#h;#m;#i=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.#s=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.#_():null}async waits(t){if(this.#t)return this.#t.error;const e=this.#c;if(!e)return null;const s=await this.#i.run(()=>this.#e.readPlace(t)),n={type:s?.type??"folder",parentUUID:s?.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.#i.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.#i.run(()=>this.#e.readLocalSequence()),e=t.catch(()=>0);this.#k.add(e);try{const[,s]=await Promise.all([this.#o,t]);let n=null,a=!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(n)throw n.error;if(this.#t)throw this.#t.error;if(a)throw this.#_();const i=this.#u,h=await(i??this.#q());n=h.failure,a=!i&&!h.progressed&&this.#r.size>0}return s}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.#s.stop(),this.#i.stop()])}#P(){if(!this.#b||this.#l||this.#h.armed||this.#E)return;const t=this.#D();this.#E=t,t.then(()=>{this.#E=null,this.#n&&this.#P()})}async#D(){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.#L();return this.#u=t,t.then(()=>{this.#u===t&&(this.#u=null)}),t}async#A(){const t=this.#c;if(!t)return this.#i.run(()=>this.#e.readPending(p));for(;t.wanting;){const e=await this.#i.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#L(){let t=[],e=0,s;const n=this.#R,a=this.#y;this.#y=0;const o=this.#c;try{const i=await this.#A();if(i===null)return m;const h=await this.#M(),u=i.filter(r=>r.localSequence<=h),y=this.#f;if(this.#s.retain(u,y),s=u[0],!s||(await this.#s.head(s),a>0&&await this.#s.settledThrough(a),this.#l))return b;const w=q(u,r=>this.#s.prepared(r));await this.#i.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.#j(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.#s.forget([r]),s=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(i){const h=i 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:i}};if(s&&(h||t.length===0)&&(A(i)||h&&this.#t))return await this.#N(s,i),this.#a(i),m;if(h&&i.code===E){const u=this.#R===n;return u&&(this.#t={error:i,row:s},this.#w(),this.#s.retain([],this.#f)),this.#n=!0,u&&a>0||this.#a(i),{progressed:e>0,failure:{error:i}}}return this.#h.arm(()=>this.wake()),this.#a(i),{progressed:e>0,failure:{error:i}}}}async#N(t,e){this.#r.set(t.localSequence,e),this.#s.forget([t]);const s=this.#c;try{s?await s.stepAside(t):this.#w()}catch(n){this.#a(n),this.#w()}this.#m.arm(()=>this.#C()),this.#n=!0}#C(){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.#i.run(()=>this.#e.readPackagePage(e)),"readPage"),readPlace:l(e=>this.#i.run(()=>this.#e.readPlace(e)),"readPlace")}):null}#_(){return this.#r.get(Math.min(...this.#r.keys()))??R()}async#M(){for(const t of[...this.#k]){const e=await t;if(e>this.#g)return e}return Number.POSITIVE_INFINITY}#j(t,e){this.#T+=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.#I(t)}catch(s){this.#a(s)}}}export{x as SendLine};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var m=Object.defineProperty;var d=(n,t)=>m(n,"name",{value:t,configurable:!0});import{utf8Length as g}from"../entities/bytes.js";import{failure as c}from"../faults/need.js";import{encodeEntityRecord as I}from"./codec.js";import{recordCargo as f}from"./contracts.js";import{ENTITY_RECORD_BATCH_BYTES as u}from"./send-batch.js";import{INLINE_ARTIFACT_FRAME_BYTES as y,submissionBytes as E}from"./submit-frame.js";const l=d(n=>({id:n.record.entityId,type:n.record.change.result.type}),"subjectOf"),z=512,p=u,b=4,R=Promise.resolve();class P{static{d(this,"SendPreparation")}#c;#f;#t=new Map;#e=[];#u=0;#s=0;#d=0;#r=!1;#i=new Set;constructor(t,e){this.#c=t,this.#f=e}retain(t,e){if(this.#r)return;this.#e=t,this.#u=e;const r=new Map(t.map(i=>[i.record.mutationId,i]));for(const[i,s]of this.#t){const o=r.get(i);(!o||s.carriesCargo!==this.#h(o))&&this.#o(i)}this.#n()}forget(t){if(t.length===0)return;const e=new Set(t.map(r=>r.record.mutationId));this.#e=this.#e.filter(r=>!e.has(r.record.mutationId));for(const r of e)this.#o(r);this.#n()}prepared(t){return this.#t.get(t.record.mutationId)?.ready??null}async head(t){if(t!==this.#e[0])throw new Error("only the lookahead head is awaited");this.#t.get(t.record.mutationId)?.failure&&this.#o(t.record.mutationId),this.#n();let e=this.#t.get(t.record.mutationId);for(;!e;){if(this.#r)throw new Error("entity record preparation stopped");if(this.#i.size===0)throw c(`entity record ${t.record.mutationId} exceeds the prepared byte bound`,"invariant-broken","row-too-large",l(t),t.record.mutationId);await Promise.race(this.#i),e=this.#t.get(t.record.mutationId)}if(await e.settled,e.failure)throw e.failure.error;return e.ready}async settledThrough(t){for(;;){const e=[...this.#t.values()].filter(({row:r,ready:i,failure:s})=>r.localSequence<=t&&!i&&!s);if(e.length===0)return;await Promise.race(e.map(({settled:r})=>r))}}stop(){this.#r=!0,this.#e=[];for(const t of[...this.#t.keys()])this.#o(t);return Promise.allSettled([...this.#i]).then(()=>{})}#n(){if(!this.#r)for(const[t,e]of this.#e.entries()){if(this.#t.has(e.record.mutationId))continue;const r=this.#h(e)?f(e.record).length*y:0;if(r>0&&this.#d>=b)return;const i=I(e.record),s=g(i),o=s+Math.min(r,Math.max(0,u-s));if(t===0&&this.#l(o),this.#s+o>p)return;this.#p(e,i,o)}}#l(t){for(let e=this.#e.length-1;e>0&&this.#s+t>p;e-=1){const r=this.#e[e].record.mutationId;this.#t.get(r)?.ready&&this.#o(r)}}#h(t){return t.localSequence>this.#u&&f(t.record).length>0}#p(t,e,r){if(this.#s+=r,!this.#h(t)){const o=Object.freeze({recordJson:e,cargo:Object.freeze([])});this.#t.set(t.record.mutationId,{row:t,carriesCargo:!1,reserved:r,ready:Object.freeze({row:t,submission:o,bytes:r}),failure:null,settled:R,dropped:!1});return}this.#d+=1;let i;const s=Promise.resolve().then(()=>{if(this.#r)throw new Error("entity record preparation stopped");return this.#c.ensure(t.record)}).then(o=>{const h=Object.freeze({recordJson:e,cargo:Object.freeze([...o??[]])}),a=E(h);if(a>r)throw c(`cargo for ${t.record.mutationId} exceeds what one row may carry inline`,"invariant-broken","cargo-too-large",l(t),t.record.mutationId);i.ready=Object.freeze({row:t,submission:h,bytes:a}),this.#a(i,a)}).catch(o=>{i.failure={error:o},this.#a(i,0)}).finally(()=>{this.#d-=1,this.#i.delete(s),i.dropped&&this.#a(i,0),this.#n()}).catch(o=>this.#f(o));i={row:t,carriesCargo:!0,reserved:r,ready:null,failure:null,settled:s,dropped:!1},this.#i.add(s),this.#t.set(t.record.mutationId,i)}#o(t){const e=this.#t.get(t);e&&(this.#t.delete(t),e.dropped=!0,(e.ready||e.failure)&&this.#a(e,0))}#a(t,e){const r=t.dropped?0:e;this.#s+=r-t.reserved,t.reserved=r}}export{b as ENTITY_RECORD_CARGO_READS,z as ENTITY_RECORD_LOOKAHEAD_ROWS,p as ENTITY_RECORD_PREPARED_BYTES,P as SendPreparation};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ChangeFacet } from '../detection/record-proposal.js';
|
|
2
|
+
import type { EntityType } from '../entities/types.js';
|
|
3
|
+
import type { UnitPlace } from '../entities/units.js';
|
|
4
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
5
|
+
export interface WaitingChange {
|
|
6
|
+
readonly entityId: string;
|
|
7
|
+
readonly facets: readonly ChangeFacet[];
|
|
8
|
+
readonly result: {
|
|
9
|
+
readonly type: EntityType;
|
|
10
|
+
readonly parentUUID: string | null;
|
|
11
|
+
readonly name: string;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export interface WaitingMember {
|
|
15
|
+
readonly uuid: string;
|
|
16
|
+
readonly type: EntityType;
|
|
17
|
+
readonly parentUUID: string | null;
|
|
18
|
+
readonly name: string;
|
|
19
|
+
}
|
|
20
|
+
export declare class Waits {
|
|
21
|
+
#private;
|
|
22
|
+
constructor(place: (uuid: string) => MaybePromise<UnitPlace | null>);
|
|
23
|
+
get empty(): boolean;
|
|
24
|
+
hold(change: WaitingChange, members?: readonly WaitingMember[]): Promise<void>;
|
|
25
|
+
behind(change: WaitingChange): Promise<boolean>;
|
|
26
|
+
}
|
|
27
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var u=Object.defineProperty;var a=(n,t)=>u(n,"name",{value:t,configurable:!0});const l=new Set(["create","rename","move","restore"]),h=new Set(["move","restore","delete"]),o=a((n,t)=>n===null?null:`${n}\0${t}`,"slot");class f{static{a(this,"Waits")}#r;#e=new Map;#t=new Set;#i=new Set;#n=new Set;#a=new Set;#l=!1;#s=!1;constructor(t){this.#r=t}get empty(){return this.#t.size===0}async hold(t,i=[]){this.#t.add(t.entityId),this.#o(t.result.parentUUID,t.result.name,t.result.type),t.facets.includes("rename")&&t.result.parentUUID!==null&&this.#a.add(t.result.parentUUID),t.facets.includes("move")&&(this.#l=!0);for(const s of i)this.#t.add(s.uuid),this.#o(s.parentUUID,s.name,s.type);let e=t.result.type==="repo.git"?t.entityId:null;for(const s of await this.#u(t.result.parentUUID))this.#i.add(s),e===null&&(await this.#h(s))?.type==="repo.git"&&(e=s);e!==null&&(this.#t.add(e),this.#s=!0)}async behind(t){if(this.empty)return!1;const{entityId:i,facets:r,result:e}=t;if(this.#t.has(i)||r.some(s=>l.has(s))&&e.parentUUID!==null&&(this.#n.has(o(e.parentUUID,e.name))||this.#a.has(e.parentUUID))||this.#l&&r.some(s=>l.has(s)||s==="delete")||this.#s&&e.type==="repo.git"||this.#i.has(i)&&r.some(s=>h.has(s)))return!0;for(const s of await this.#u(e.parentUUID))if(this.#t.has(s))return!0;return!1}#o(t,i,r){const e=o(t,i);e!==null&&this.#n.add(e),r==="repo.git"&&(this.#s=!0)}async#u(t){const i=[];for(let r=t;r!==null&&!i.includes(r);){i.push(r);const e=await this.#h(r);if(!e)break;r=e.parentUUID}return i}async#h(t){return this.#e.has(t)||this.#e.set(t,await this.#r(t)),this.#e.get(t)}}export{f as Waits};
|
package/dist-cjs/apply/lane.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var l=Object.defineProperty;var i=(n,e)=>l(n,"name",{value:e,configurable:!0});Object.defineProperty(exports,"__esModule",{value:!0}),exports.createApplyLane=u,exports.assertApplyLaneStep=s;const o=require("../entities/types.js"),r=require("./line.js");function u(n,e,t){return{kind:"lane",unit:n,emptied:t,through:e,toPrefix:!1,waitsOn:null,met:new Set,waiters:new Set,held:null,queued:!1,running:!1,again:!1}}i(u,"createApplyLane");function s(n,e){const t=`lane step for ${n}`;switch((!e||typeof e!="object"||!Number.isSafeInteger(e.through)||e.through<0)&&(0,r.invalidStep)(t),e.kind){case"end":return;case"nowhere":case"root":case"unseen":(typeof e.reason!="string"||e.reason.length===0)&&(0,r.invalidStep)(t);return;case"prerequisite":(!o.UUID_PATTERN.test(e.unit)||e.unit===n||typeof e.reason!="string"||e.reason.length===0)&&(0,r.invalidStep)(t);return;case"window":(e.window?.unit!==n||e.window.cutoff!==e.through||e.window.intent!==null&&(e.window.intent.unit!==n||e.window.intent.cutoff!==e.through))&&(0,r.invalidStep)(t),(0,r.assertApplyWindow)(e.window,t),e.window.members.some(a=>a.work.kept!==null)&&f(e.window,t);return;default:(0,r.invalidStep)(t)}}i(s,"assertApplyLaneStep");function f(n,e){const[t]=n.members;(n.members.length!==1||t.work.play!=="enter"||t.work.records.length!==0||t.work.materialized!==null||t.deliverySequence!==n.cutoff||n.intent!==null&&n.intent.members.some(a=>a.kept===null))&&(0,r.invalidStep)(e)}i(f,"assertKeptWindow");
|
package/dist-cjs/apply/line.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var a=Object.defineProperty;var i=(e,n)=>a(e,"name",{value:n,configurable:!0});Object.defineProperty(exports,"__esModule",{value:!0}),exports.invalidStep=void 0,exports.createApplyLine=d,exports.releaseApplyLine=f,exports.heldWait=p,exports.assertApplyDependency=m,exports.assertApplyLineStep=A,exports.assertApplyWindow=s;const u=require("../entities/types.js");function d(e){return{kind:"line",authorityId:e,endsBefore:null,held:null,queued:!1,running:!1,again:!1}}i(d,"createApplyLine");function f(e,n,l){const r=e.held;return!r?.dependency||r.due||r.dependency.producer!==n||l!==void 0&&!r.dependency.entityIds.some(t=>l.includes(t))?!1:(r.due=!0,!0)}i(f,"releaseApplyLine");function p(e,n){if(e)return e.entityId===null||e.target===null?{entityId:e.entityId??n,reason:e.reason,throughSequence:e.target??e.cutoff??0}:{entityId:e.entityId,reason:e.reason,...e.dependency?{prerequisite:e.dependency}:{},throughSequence:e.target,...e.blocker?{blocker:e.blocker}:{}}}i(p,"heldWait");const c=new Set(["detect","apply","capability","send"]),y=i(e=>!!e&&c.has(e.producer)&&Array.isArray(e.entityIds)&&e.entityIds.length>0&&e.entityIds.every(n=>typeof n=="string"&&n.length>0),"namesRelease");function m(e){if(!y(e))throw new Error("Apply dependency must name the entities that can release it")}i(m,"assertApplyDependency");function A(e,n){(!n||typeof n!="object")&&(0,exports.invalidStep)(`line step for ${e}`),n.kind!=="end"&&((n.kind!=="window"||n.window?.authorityId!==e||n.window.unit!==null||n.window.cutoff!==null||n.window.members?.some(l=>l.work?.kept!==null)||n.window.intent!==null&&(n.window.intent.unit!==null||n.window.intent.cutoff!==null))&&(0,exports.invalidStep)(`line step for ${e}`),s(n.window,`line step for ${e}`))}i(A,"assertApplyLineStep");const S=i(e=>{throw new Error(`entity Apply store returned an invalid ${e}`)},"invalidStep");exports.invalidStep=S;function s(e,n){(!Array.isArray(e.members)||e.members.length===0)&&(0,exports.invalidStep)(n);const l=i((t,o)=>Number.isSafeInteger(t)&&t>=(o?0:1),"at");for(const t of e.members)(!u.UUID_PATTERN.test(t.work?.entityId??"")||t.work.authorityId!==e.authorityId||!l(t.deliverySequence,t.work.kept!==null))&&(0,exports.invalidStep)(n),(t.unseen!==void 0||t.judgment==="unseen")&&(u.UUID_PATTERN.test(t.unseen??"")||(0,exports.invalidStep)(n));const{deliverySequence:r}=e;(r===null?!e.intent:!l(r,e.members[0].work.kept!==null))&&(0,exports.invalidStep)(n)}i(s,"assertApplyWindow");
|
package/dist-cjs/apply/rail.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var E=Object.defineProperty;var a=(d,e)=>E(d,"name",{value:e,configurable:!0});Object.defineProperty(exports,"__esModule",{value:!0}),exports.EntityApplyRail=exports.ENTITY_APPLY_SAME_ANSWERS=exports.ENTITY_APPLY_RETRY_MAX_MS=exports.ENTITY_APPLY_RETRY_BASE_MS=exports.ENTITY_APPLY_DEFAULT_CONCURRENCY=void 0;const f=require("../entities/types.js"),I=require("./fetch-ahead.js"),c=require("./journey.js"),A=require("./lane.js"),l=require("./line.js"),g=require("./window.js");exports.ENTITY_APPLY_DEFAULT_CONCURRENCY=8,exports.ENTITY_APPLY_RETRY_BASE_MS=1e3,exports.ENTITY_APPLY_RETRY_MAX_MS=3e4,exports.ENTITY_APPLY_SAME_ANSWERS=3;class P{static{a(this,"EntityApplyRail")}#e;#A;#T;#b;#O;#d;#k;#a=!1;#t=!1;#o=new Map;#s=new Map;#l={queue:[],steps:new Set};#u={queue:[],steps:new Set};#r=!1;#h=null;#p=1/0;#g=[];#m=0;#S=new Map;#y=null;constructor(e){this.#e=e,this.#A=e.concurrency??exports.ENTITY_APPLY_DEFAULT_CONCURRENCY,this.#T=e.laneConcurrency??this.#A,this.#b=e.onBackgroundError??(()=>{}),this.#O=e.onIdle??(()=>{});for(const[t,s]of[["concurrency",this.#A],["lane concurrency",this.#T]])if(!Number.isSafeInteger(s)||s<1)throw new Error(`entity Apply ${t} must be a positive integer`);this.#d=new c.EntityApplyJourney(e,()=>this.#m,()=>this.#t),this.#k=new I.FetchAhead(e.cargo,{sha256Hex:e.sha256Hex,loops:e.loops})}async start(){if(this.#a)throw new Error("entity Apply rail already started");if(this.#t)throw new Error("entity Apply rail is stopped");this.#a=!0;const e=await this.#e.store.readOpenUnits();if(!Array.isArray(e)||new Set(e).size!==e.length||e.some(t=>!f.UUID_PATTERN.test(t)))throw new Error("entity Apply store returned an invalid open unit list");for(const t of e)this.#I(t,null);await this.#M()}fetch(e,t){return this.#a?this.#t?Promise.reject(new Error("entity Apply rail is stopped")):f.UUID_PATTERN.test(e)?!Number.isFinite(t.stall)||t.stall<0?Promise.reject(new Error("entity Apply fetch needs a non-negative stall")):t.emptied!==void 0&&typeof t.emptied!="boolean"?Promise.reject(new Error("entity Apply fetch emptied must be a boolean")):new Promise((s,i)=>{const n=this.#I(e,null,t.emptied===!0),r=a(()=>this.#e.schedule.schedule(t.stall,()=>{n.waiters.delete(u)&&(n.emptied&&![...n.waiters].some(o=>o.emptied)&&(n.emptied=!1),s(this.#G(n)))}),"arm");let h=r();const u={emptied:t.emptied===!0,answer:a(o=>{h.cancel(),s(o)},"answer"),fail:a(o=>{h.cancel(),i(o)},"fail"),moved:a(()=>{h.cancel(),h=r()},"moved")};n.waiters.add(u),n.waitsOn===null&&this.#L(n),this.#n()}):Promise.reject(new Error("entity Apply fetch needs a unit UUID")):Promise.reject(new Error("entity Apply rail has not started"))}progressed(e,t){if(!f.UUID_PATTERN.test(e))throw new Error("entity Apply progress needs a unit UUID");if(!Number.isSafeInteger(t)||t<0)throw new Error("entity Apply progress needs a byte count");t>0&&!this.#t&&this.#P(e)}recordsAvailable(){this.#_()}localStateChanged(e){this.#c("detect",e),this.#c("apply",e),this.#_()}sendAccepted(e){this.#c("send",e),this.#_()}capabilityChanged(e){this.#c("capability",e),this.#_()}owe(e){if(e.some(t=>!f.UUID_PATTERN.test(t)))throw new Error("entity Apply owe needs entity UUIDs");if(!(!this.#a||this.#t)){for(const t of e)this.#q(t);this.#n()}}#_(){!this.#a||this.#t||(this.#r=!0,this.#n())}waiting(){return this.#w().flatMap(e=>(0,l.heldWait)(e.held,y(e))??[])}async flush(){if(!this.#a)throw new Error("entity Apply rail has not started");this.#t||await this.#M()}async stop(){if(this.#t)return;this.#t=!0,this.#N();for(const t of[this.#l,this.#u])for(const s of t.queue.splice(0))s.queued=!1;const e=new Error("entity Apply rail stopped before the fetch answered");for(const t of this.#s.values())for(const s of t.waiters)s.fail(e);for(this.#s.clear();this.#v()>0||this.#h;)await Promise.allSettled([...this.#l.steps,...this.#u.steps,...this.#h?[this.#h]:[]]);await this.#k.stop();for(const t of this.#g.splice(0))t.resolve()}#M(){return new Promise((e,t)=>{this.#g.push({resolve:e,reject:t}),this.#r=!0,this.#n()})}#n(){if(!this.#t){if(this.#r&&this.#h===null){this.#r=!1;const e=this.#z();this.#h=e,e.then(()=>{this.#h=null,this.#n()})}for(const[e,t]of[[this.#u,this.#T],[this.#l,this.#A]])for(;e.steps.size<t&&e.queue.length>0;){const s=e.queue.shift();s.queued=!1,this.#F(s,e)}if(this.#v()===0&&this.#h===null&&!this.#r&&this.#l.queue.length===0&&this.#u.queue.length===0){if(this.#S.clear(),this.#x(this.#e.now())){this.#n();return}this.#R();for(const e of this.#g.splice(0))e.resolve();this.#O()}}}#v(){return this.#l.steps.size+this.#u.steps.size}#w(){return[...this.#o.values(),...this.#s.values()]}#E(e){return e.kind==="line"?this.#o.get(e.authorityId)===e:this.#s.get(e.unit)===e}#i(e){if(!this.#t){if(e.running){e.again=!0;return}e.queued||(e.queued=!0,(e.kind==="line"?this.#l:this.#u).queue.push(e))}}#F(e,t){e.running=!0,e.again=!1;const s=(e.kind==="line"?this.#X(e):this.#J(e)).then(i=>{e.running=!1,t.steps.delete(s),(i||e.again)&&this.#E(e)&&(e.again=!1,this.#i(e)),this.#n()});t.steps.add(s)}async#z(){try{const e=await this.#e.store.readApplyAuthorities();if(!Array.isArray(e)||new Set(e).size!==e.length||e.some(s=>typeof s!="string"||s.length===0))throw new Error("entity Apply store returned an invalid authority list");this.#p=1/0;const t=new Set(e);for(const[s,i]of this.#o)!t.has(s)&&!i.running&&!i.queued&&this.#o.delete(s);for(const s of e){let i=this.#o.get(s);i||(i=(0,l.createApplyLine)(s),this.#o.set(s,i)),this.#i(i)}}catch(e){this.#p=this.#e.now()+exports.ENTITY_APPLY_RETRY_MAX_MS;const t=this.#g.splice(0);t.length===0&&this.#Y(e);for(const s of t)s.reject(e)}}async#X(e){try{const t=e.held;if(t&&t.entityId===null&&!t.due&&t.notBefore>this.#e.now())return!1;const s=this.#m,i=await this.#e.store.readApplyWindow(e.authorityId,e.endsBefore);if((0,l.assertApplyLineStep)(e.authorityId,i),this.#t)return!1;if(i.kind==="end"){e.held=null;const n=e.endsBefore!==null;return e.endsBefore=null,n}return i.window.deliverySequence!==null&&this.#k.advance(e.authorityId,i.window.deliverySequence),await this.#U(e,i.window,s)}catch(t){return this.#W(e,t),!1}}async#J(e){try{const t=e.held;if(t&&t.entityId===null&&!t.due&&t.notBefore>this.#e.now())return!1;const s=this.#m,i=await this.#e.store.readFetchWindow(e.unit,e.toPrefix?null:e.through);if((0,A.assertApplyLaneStep)(e.unit,i),this.#t||!this.#E(e))return!1;switch((i.kind!=="window"||i.window.intent===null)&&(e.toPrefix=!1),e.through!==null&&i.through>e.through&&e.met.clear(),e.through=Math.max(e.through??0,i.through),e.waitsOn=null,i.kind!=="window"&&(e.held=null),i.kind){case"end":return this.#f(e,{kind:"placed"}),!1;case"nowhere":return this.#f(e,{kind:"nowhere",reason:i.reason}),!1;case"root":return await this.#H(e,i.through,i.reason);case"prerequisite":return this.#V(e,i.unit,i.reason,s);case"window":return await this.#U(e,i.window,s)}}catch(t){return this.#W(e,t),!1}}async#H(e,t,s){return e.met.has(e.unit)?(this.#f(e,{kind:"held",unit:e.unit,reason:`${e.unit} entered and still not held: ${s}`}),!1):(await this.#e.effects.enterRoot(e.unit,t),this.#t||!this.#E(e)?!1:(e.through===t&&e.met.add(e.unit),this.#P(e.unit),!0))}#q(e){const t=this.#I(e,null);t.toPrefix=!0,t.met.clear(),this.#i(t)}#I(e,t,s=!1){let i=this.#s.get(e);return i?t!==null&&(i.through===null||i.through<t)&&(i.through=t,i.met.clear(),this.#i(i)):(i=(0,A.createApplyLane)(e,t,s),this.#s.set(e,i),this.#i(i)),i}#V(e,t,s,i){if(e.met.has(t))return this.#f(e,{kind:"held",unit:t,reason:`${t} placed and still needed: ${s}`}),!1;if(!this.#$(e,t,s))return!1;const n={producer:"apply",entityIds:[t]};return e.held={entityId:null,target:null,kept:null,cutoff:null,attempt:1,notBefore:1/0,releaseOnProgress:!1,due:this.#D(n,i),reason:s,dependency:n},e.held.due}#L(e){const t=e.held;if(t?.dependency?.producer==="apply"){for(const s of t.dependency.entityIds)if(s!==e.unit&&!e.met.has(s)&&!this.#$(e,s,t.reason))return}}#$(e,t,s){const i=[e];let n=this.#s.get(t);for(;n&&n!==e&&!i.includes(n);)i.push(n),n=n.waitsOn===null?void 0:this.#s.get(n.waitsOn);if(n===e){for(const r of i)this.#f(r,{kind:"held",unit:t,reason:`prerequisite cycle through ${t}: ${s}`});return!1}return e.waitsOn??=t,this.#i(this.#I(t,e.through)),!0}#f(e,t){if(!this.#E(e))return;for(const i of e.waiters)i.answer(t);e.waiters.clear(),e.waitsOn=null,(t.kind==="placed"||e.held?.entityId==null)&&this.#s.delete(e.unit);const s=t.kind==="placed"||t.kind==="held"?t:{kind:"held",unit:e.unit,reason:`${e.unit} is nowhere here: ${t.reason}`};for(const i of[...this.#s.values()])if(i.waitsOn===e.unit){if(t.kind!=="placed"){this.#f(i,s);continue}i.met.add(e.unit)}t.kind==="placed"&&(this.#P(e.unit),this.#c("apply",[e.unit]))}#P(e){const t=new Map([[e,!0]]);for(const s of this.#s.values()){const i=new Set;let n=s.unit;for(;n!==null&&!t.has(n)&&!i.has(n);)i.add(n),n=this.#s.get(n)?.waitsOn??null;const r=n!==null&&t.get(n)===!0;for(const h of i)t.set(h,r);if(r)for(const h of s.waiters)h.moved()}}#G(e){let t=e;const s=new Set([e]);for(let i=e.waitsOn===null?void 0:this.#s.get(e.waitsOn);i&&!s.has(i);i=i.waitsOn===null?void 0:this.#s.get(i.waitsOn))s.add(i),t=i;return{kind:"held",unit:t.unit,reason:t.held?.reason??"still placing"}}async#U(e,t,s){const i=t.members[0]?.work.entityId??null;if(e.held&&e.held.entityId!==null&&e.held.entityId!==i&&(e.held=null),await this.#Q(e,t))return!1;let n=await(0,c.outcomeOf)(()=>this.#d.run(t,()=>e.kind==="lane"&&e.emptied?e.unit:null));if(e.kind==="line"&&typeof n=="object"&&n.kind==="park"&&(0,g.windowEndForWait)(t,n.dependency)===null&&this.#K(e,t,n)&&(n=await(0,c.outcomeOf)(()=>this.#d.alone(t.members[0]))),n==="progress"||typeof n=="object"&&n.kind==="alone"){if(e.kind==="line")for(const r of t.members)(r.judgment==="waiting"||n!=="progress"&&r.work.entityId===n.entityId)&&this.#q(r.work.entityId);return this.#Z(e,n==="progress"?t.members.map(r=>r.work.entityId):[n.entityId])}if(n==="again")return e.held?.entityId===i&&(e.held=null),!0;if(n.advanced?.length&&this.#B(e,n.advanced),e.kind==="line"){const r=(0,g.windowEndForWait)(t,n.dependency);if(r!==null)return e.endsBefore=r,!0}return this.#ee(e,t,n,s),e.kind==="lane"&&this.#L(e),e.held.due}#K(e,t,s){const i=t.members[0].work.entityId;if(s.cause!==void 0||!(0,c.stepsAside)(t,i))return!1;const n=s.dependency?.entityIds??[i];return n.length===0||n.some(r=>r!==i)?!1:s.dependency?.producer==="capability"?!0:this.#j(e,t)>=exports.ENTITY_APPLY_SAME_ANSWERS}#j(e,t){const s=e.held,i=t.members[0].work.entityId;return(s?.entityId===i&&s.target===this.#d.targetOf(t)?s.attempt:0)+1}async#Q(e,t){const s=e.held,i=t.members[0];return!s||i===void 0||s.entityId!==i.work.entityId||s.due||s.notBefore<=this.#e.now()||this.#d.targetOf(t)!==s.target||t.cutoff!==s.cutoff?!1:await this.#e.store.localWorkAfter(t.authorityId,i.work.entityId,s.kept??s.target)===null}#Z(e,t){return e.held&&(e.held.entityId===null||t.includes(e.held.entityId))&&(e.held=null),this.#B(e,t),!0}#B(e,t){e.kind==="lane"&&(this.#r=!0,this.#P(e.unit)),this.#c("apply",t);for(const s of this.#w())s!==e&&s.held?.releaseOnProgress&&!s.held.due&&(s.held.due=!0,this.#i(s))}#ee(e,t,s,i){if(s.dependency&&(0,l.assertApplyDependency)(s.dependency),s.blocker&&!s.dependency)throw new Error("Apply blocker must name the dependency that releases it");const n=t.members[0].work.entityId,r=e.held,h=this.#j(e,t),u=this.#C(h),o=s.again===!0&&h<exports.ENTITY_APPLY_SAME_ANSWERS,w={entityId:n,target:this.#d.targetOf(t),kept:t.members[0].work.kept,cutoff:t.cutoff,attempt:h,notBefore:s.dependency?1/0:this.#e.now()+(o?0:u),releaseOnProgress:s.releaseOnProgress,due:s.dependency?this.#D(s.dependency,s.comparedAt??i):o,reason:s.reason,...s.dependency?{dependency:s.dependency}:{},...s.blocker?{blocker:s.blocker}:{}};e.held=w,this.#R();const _=(0,l.heldWait)(r,y(e)),p=(0,l.heldWait)(w,y(e));p&&JSON.stringify(p)!==JSON.stringify(_)&&this.#e.onWaiting?.(p),!(!s.report&&(s.dependency!==void 0||h<exports.ENTITY_APPLY_SAME_ANSWERS))&&this.#Y(new Error(`${m(e)} holds at ${n}, which ${s.releaseOnProgress?"is parked on a conflict":s.report?"failed":s.again?"keeps ending unplaced":"stands on ground that keeps moving"}, and will retry in ${u}ms (attempt ${h}): ${s.reason}`,s.cause===void 0?void 0:{cause:s.cause}))}#W(e,t){if(e.kind==="lane"){for(const h of e.waiters)h.fail(t);e.waiters.clear()}const s=e.held,i=(s?.entityId===null?s.attempt:0)+1,n=this.#C(i),r=t instanceof Error?t.message:String(t);e.held={entityId:null,target:null,kept:null,cutoff:null,attempt:i,notBefore:this.#e.now()+n,releaseOnProgress:!1,due:!1,reason:r},this.#R(),this.#Y(new Error(`${m(e)} faulted and will retry in ${n}ms (attempt ${i}): ${r}`,{cause:t}))}#Y(e){try{this.#b(e)}catch{}}#C(e){const t=Math.min(exports.ENTITY_APPLY_RETRY_MAX_MS,exports.ENTITY_APPLY_RETRY_BASE_MS*2**Math.min(e-1,16)),s=Math.max(0,Math.min(1,this.#e.schedule.random()));return Math.round(t*(.5+s))}#c(e,t){const s=++this.#m;for(const i of t??["*"])this.#S.set(`${e}:${i}`,s);for(const i of this.#w())(0,l.releaseApplyLine)(i,e,t)&&this.#i(i)}#D(e,t){return["*",...e.entityIds].some(s=>(this.#S.get(`${e.producer}:${s}`)??0)>t)}#R(){if(this.#t)return;let e=this.#p;for(const i of this.#w())i.held&&!i.held.due&&(e=Math.min(e,i.held.notBefore));if(e===1/0){this.#N();return}if(this.#y?.dueAt===e)return;this.#N();const t=Math.max(0,e-this.#e.now()),s=this.#e.schedule.schedule(t,()=>{this.#y=null,this.#x(e),this.#n()});this.#y={dueAt:e,cancel:a(()=>s.cancel(),"cancel")}}#x(e){let t=!1;for(const s of this.#w())s.held&&!s.held.due&&s.held.notBefore<=e&&(s.held.due=!0,this.#i(s),t=!0);return this.#p<=e&&(this.#p=1/0,this.#r=!0,t=!0),t}#N(){this.#y?.cancel(),this.#y=null}}exports.EntityApplyRail=P;const y=a(d=>d.kind==="line"?d.authorityId:d.unit,"owner"),m=a(d=>d.kind==="line"?`entity Apply line ${d.authorityId}`:`entity Apply fetch of ${d.unit}`,"label");
|
|
1
|
+
"use strict";var E=Object.defineProperty;var a=(d,e)=>E(d,"name",{value:e,configurable:!0});Object.defineProperty(exports,"__esModule",{value:!0}),exports.EntityApplyRail=exports.ENTITY_APPLY_SAME_ANSWERS=exports.ENTITY_APPLY_RETRY_MAX_MS=exports.ENTITY_APPLY_RETRY_BASE_MS=exports.ENTITY_APPLY_DEFAULT_CONCURRENCY=void 0;const f=require("../entities/types.js"),I=require("./fetch-ahead.js"),c=require("./journey.js"),g=require("./lane.js"),u=require("./line.js"),A=require("./window.js");exports.ENTITY_APPLY_DEFAULT_CONCURRENCY=8,exports.ENTITY_APPLY_RETRY_BASE_MS=1e3,exports.ENTITY_APPLY_RETRY_MAX_MS=3e4,exports.ENTITY_APPLY_SAME_ANSWERS=3;class P{static{a(this,"EntityApplyRail")}#e;#g;#k;#O;#M;#d;#T;#a=!1;#t=!1;#o=new Map;#s=new Map;#u={queue:[],steps:new Set};#l={queue:[],steps:new Set};#r=!1;#h=null;#p=1/0;#A=[];#m=0;#S=new Map;#y=null;constructor(e){this.#e=e,this.#g=e.concurrency??exports.ENTITY_APPLY_DEFAULT_CONCURRENCY,this.#k=e.laneConcurrency??this.#g,this.#O=e.onBackgroundError??(()=>{}),this.#M=e.onIdle??(()=>{});for(const[t,s]of[["concurrency",this.#g],["lane concurrency",this.#k]])if(!Number.isSafeInteger(s)||s<1)throw new Error(`entity Apply ${t} must be a positive integer`);this.#d=new c.EntityApplyJourney(e,()=>this.#m,()=>this.#t),this.#T=new I.FetchAhead(e.cargo,{sha256Hex:e.sha256Hex,loops:e.loops})}async start(){if(this.#a)throw new Error("entity Apply rail already started");if(this.#t)throw new Error("entity Apply rail is stopped");this.#a=!0;const e=await this.#e.store.readOpenUnits();if(!Array.isArray(e)||new Set(e).size!==e.length||e.some(t=>!f.UUID_PATTERN.test(t)))throw new Error("entity Apply store returned an invalid open unit list");for(const t of e)this.#I(t,null);await this.#v()}fetch(e,t){return this.#a?this.#t?Promise.reject(new Error("entity Apply rail is stopped")):f.UUID_PATTERN.test(e)?!Number.isFinite(t.stall)||t.stall<0?Promise.reject(new Error("entity Apply fetch needs a non-negative stall")):t.emptied!==void 0&&typeof t.emptied!="boolean"?Promise.reject(new Error("entity Apply fetch emptied must be a boolean")):new Promise((s,i)=>{const n=this.#I(e,null,t.emptied===!0),r=a(()=>this.#e.schedule.schedule(t.stall,()=>{n.waiters.delete(l)&&(n.emptied&&![...n.waiters].some(o=>o.emptied)&&(n.emptied=!1),s(this.#K(n)))}),"arm");let h=r();const l={emptied:t.emptied===!0,answer:a(o=>{h.cancel(),s(o)},"answer"),fail:a(o=>{h.cancel(),i(o)},"fail"),moved:a(()=>{h.cancel(),h=r()},"moved")};n.waiters.add(l),n.waitsOn===null&&this.#$(n),this.#n()}):Promise.reject(new Error("entity Apply fetch needs a unit UUID")):Promise.reject(new Error("entity Apply rail has not started"))}progressed(e,t){if(!f.UUID_PATTERN.test(e))throw new Error("entity Apply progress needs a unit UUID");if(!Number.isSafeInteger(t)||t<0)throw new Error("entity Apply progress needs a byte count");t>0&&!this.#t&&this.#P(e)}recordsAvailable(){this.#_()}localStateChanged(e){this.#c("detect",e),this.#c("apply",e),this.#_()}sendAccepted(e){this.#c("send",e),this.#_()}capabilityChanged(e){this.#c("capability",e),this.#_()}owe(e){if(e.some(t=>!f.UUID_PATTERN.test(t)))throw new Error("entity Apply owe needs entity UUIDs");if(!(!this.#a||this.#t)){for(const t of e)this.#Y(t);this.#n()}}#_(){!this.#a||this.#t||(this.#r=!0,this.#n())}waiting(){return this.#w().flatMap(e=>(0,u.heldWait)(e.held,y(e))??[])}async flush(){if(!this.#a)throw new Error("entity Apply rail has not started");this.#t||await this.#v()}async stop(){if(this.#t)return;this.#t=!0,this.#N();for(const t of[this.#u,this.#l])for(const s of t.queue.splice(0))s.queued=!1;const e=new Error("entity Apply rail stopped before the fetch answered");for(const t of this.#s.values())for(const s of t.waiters)s.fail(e);for(this.#s.clear();this.#q()>0||this.#h;)await Promise.allSettled([...this.#u.steps,...this.#l.steps,...this.#h?[this.#h]:[]]);await this.#T.stop();for(const t of this.#A.splice(0))t.resolve()}#v(){return new Promise((e,t)=>{this.#A.push({resolve:e,reject:t}),this.#r=!0,this.#n()})}#n(){if(!this.#t){if(this.#r&&this.#h===null){this.#r=!1;const e=this.#X();this.#h=e,e.then(()=>{this.#h=null,this.#n()})}for(const[e,t]of[[this.#l,this.#k],[this.#u,this.#g]])for(;e.steps.size<t&&e.queue.length>0;){const s=e.queue.shift();s.queued=!1,this.#z(s,e)}if(this.#q()===0&&this.#h===null&&!this.#r&&this.#u.queue.length===0&&this.#l.queue.length===0){if(this.#S.clear(),this.#F(this.#e.now())){this.#n();return}this.#b();for(const e of this.#A.splice(0))e.resolve();this.#M()}}}#q(){return this.#u.steps.size+this.#l.steps.size}#w(){return[...this.#o.values(),...this.#s.values()]}#E(e){return e.kind==="line"?this.#o.get(e.authorityId)===e:this.#s.get(e.unit)===e}#i(e){if(!this.#t){if(e.running){e.again=!0;return}e.queued||(e.queued=!0,(e.kind==="line"?this.#u:this.#l).queue.push(e))}}#z(e,t){e.running=!0,e.again=!1;const s=(e.kind==="line"?this.#J(e):this.#H(e)).then(i=>{e.running=!1,t.steps.delete(s),(i||e.again)&&this.#E(e)&&(e.again=!1,this.#i(e)),this.#n()});t.steps.add(s)}async#X(){try{const e=await this.#e.store.readApplyAuthorities();if(!Array.isArray(e)||new Set(e).size!==e.length||e.some(s=>typeof s!="string"||s.length===0))throw new Error("entity Apply store returned an invalid authority list");this.#p=1/0;const t=new Set(e);for(const[s,i]of this.#o)!t.has(s)&&!i.running&&!i.queued&&this.#o.delete(s);for(const s of e){let i=this.#o.get(s);i||(i=(0,u.createApplyLine)(s),this.#o.set(s,i)),this.#i(i)}}catch(e){this.#p=this.#e.now()+exports.ENTITY_APPLY_RETRY_MAX_MS;const t=this.#A.splice(0);t.length===0&&this.#R(e);for(const s of t)s.reject(e)}}async#J(e){try{const t=e.held;if(t&&t.entityId===null&&!t.due&&t.notBefore>this.#e.now())return!1;const s=this.#m,i=await this.#e.store.readApplyWindow(e.authorityId,e.endsBefore);if((0,u.assertApplyLineStep)(e.authorityId,i),this.#t)return!1;if(i.kind==="end"){e.held=null;const n=e.endsBefore!==null;return e.endsBefore=null,n}return i.window.deliverySequence!==null&&this.#T.advance(e.authorityId,i.window.deliverySequence),await this.#j(e,i.window,s)}catch(t){return this.#C(e,t),!1}}async#H(e){try{const t=e.held;if(t&&t.entityId===null&&!t.due&&t.notBefore>this.#e.now())return!1;const s=this.#m,i=await this.#e.store.readFetchWindow(e.unit,e.toPrefix?null:e.through);if((0,g.assertApplyLaneStep)(e.unit,i),this.#t||!this.#E(e))return!1;if(e.waitsOn=null,i.kind==="unseen")return this.#L(e,{producer:"detect",entityIds:[e.unit]},i.reason,s);if(!e.again&&(i.kind!=="window"||i.window.intent===null)&&(e.toPrefix=!1),e.through!==null&&i.through>e.through&&e.met.clear(),e.through=Math.max(e.through??0,i.through),i.kind!=="window"&&(e.held=null),e.again&&(i.kind==="end"||i.kind==="nowhere"))return!0;switch(i.kind){case"end":return this.#f(e,{kind:"placed"}),!1;case"nowhere":return this.#f(e,{kind:"nowhere",reason:i.reason}),!1;case"root":return await this.#V(e,i.through,i.reason);case"prerequisite":return this.#G(e,i.unit,i.reason,s);case"window":return await this.#j(e,i.window,s)}}catch(t){return this.#C(e,t),!1}}async#V(e,t,s){return e.met.has(e.unit)?(this.#f(e,{kind:"held",unit:e.unit,reason:`${e.unit} entered and still not held: ${s}`}),!1):(await this.#e.effects.enterRoot(e.unit,t),this.#t||!this.#E(e)?!1:(e.through===t&&e.met.add(e.unit),this.#P(e.unit),!0))}#Y(e){const t=this.#I(e,null);t.toPrefix=!0,t.met.clear(),this.#i(t)}#I(e,t,s=!1){let i=this.#s.get(e);return i?t!==null&&(i.through===null||i.through<t)&&(i.through=t,i.met.clear(),this.#i(i)):(i=(0,g.createApplyLane)(e,t,s),this.#s.set(e,i),this.#i(i)),i}#G(e,t,s,i){return e.met.has(t)?(this.#f(e,{kind:"held",unit:t,reason:`${t} placed and still needed: ${s}`}),!1):this.#U(e,t,s)?this.#L(e,{producer:"apply",entityIds:[t]},s,i):!1}#L(e,t,s,i){return e.held={entityId:null,target:null,kept:null,cutoff:null,attempt:1,notBefore:1/0,releaseOnProgress:!1,due:this.#x(t,i),reason:s,dependency:t},e.held.due}#$(e){const t=e.held;if(t?.dependency?.producer==="apply"){for(const s of t.dependency.entityIds)if(s!==e.unit&&!e.met.has(s)&&!this.#U(e,s,t.reason))return}}#U(e,t,s){const i=[e];let n=this.#s.get(t);for(;n&&n!==e&&!i.includes(n);)i.push(n),n=n.waitsOn===null?void 0:this.#s.get(n.waitsOn);if(n===e){for(const r of i)this.#f(r,{kind:"held",unit:t,reason:`prerequisite cycle through ${t}: ${s}`});return!1}return e.waitsOn??=t,this.#i(this.#I(t,e.through)),!0}#f(e,t){if(!this.#E(e))return;for(const i of e.waiters)i.answer(t);e.waiters.clear(),e.waitsOn=null,(t.kind==="placed"||e.held?.entityId==null)&&this.#s.delete(e.unit);const s=t.kind==="placed"||t.kind==="held"?t:{kind:"held",unit:e.unit,reason:`${e.unit} is nowhere here: ${t.reason}`};for(const i of[...this.#s.values()])if(i.waitsOn===e.unit){if(t.kind!=="placed"){this.#f(i,s);continue}i.met.add(e.unit)}t.kind==="placed"&&(this.#P(e.unit),this.#c("apply",[e.unit]))}#P(e){const t=new Map([[e,!0]]);for(const s of this.#s.values()){const i=new Set;let n=s.unit;for(;n!==null&&!t.has(n)&&!i.has(n);)i.add(n),n=this.#s.get(n)?.waitsOn??null;const r=n!==null&&t.get(n)===!0;for(const h of i)t.set(h,r);if(r)for(const h of s.waiters)h.moved()}}#K(e){let t=e;const s=new Set([e]);for(let i=e.waitsOn===null?void 0:this.#s.get(e.waitsOn);i&&!s.has(i);i=i.waitsOn===null?void 0:this.#s.get(i.waitsOn))s.add(i),t=i;return{kind:"held",unit:t.unit,reason:t.held?.reason??"still placing"}}async#j(e,t,s){const i=t.members[0]?.work.entityId??null;if(e.held&&e.held.entityId!==null&&e.held.entityId!==i&&(e.held=null),await this.#Z(e,t))return!1;let n=await(0,c.outcomeOf)(()=>this.#d.run(t,()=>e.kind==="lane"&&e.emptied?e.unit:null));if(e.kind==="line"&&typeof n=="object"&&n.kind==="park"&&(0,A.windowEndForWait)(t,n.dependency)===null&&this.#Q(e,t,n)&&(n=await(0,c.outcomeOf)(()=>this.#d.alone(t.members[0]))),n==="progress"||typeof n=="object"&&n.kind==="alone"){if(e.kind==="line")for(const r of t.members)(r.judgment==="waiting"||n!=="progress"&&r.work.entityId===n.entityId)&&this.#Y(r.work.entityId);for(const r of t.members)r.unseen!==void 0&&this.#Y(r.unseen);return this.#ee(e,n==="progress"?t.members.map(r=>r.work.entityId):[n.entityId])}if(n==="again")return e.held?.entityId===i&&(e.held=null),!0;if(n.advanced?.length&&this.#W(e,n.advanced),e.kind==="line"){const r=(0,A.windowEndForWait)(t,n.dependency);if(r!==null)return e.endsBefore=r,!0}return this.#te(e,t,n,s),e.kind==="lane"&&this.#$(e),e.held.due}#Q(e,t,s){const i=t.members[0].work.entityId;if(s.cause!==void 0||!(0,c.stepsAside)(t,i))return!1;const n=s.dependency?.entityIds??[i];return n.length===0||n.some(r=>r!==i)?!1:s.dependency?.producer==="capability"?!0:this.#B(e,t)>=exports.ENTITY_APPLY_SAME_ANSWERS}#B(e,t){const s=e.held,i=t.members[0].work.entityId;return(s?.entityId===i&&s.target===this.#d.targetOf(t)?s.attempt:0)+1}async#Z(e,t){const s=e.held,i=t.members[0];return!s||i===void 0||s.entityId!==i.work.entityId||s.due||s.notBefore<=this.#e.now()||this.#d.targetOf(t)!==s.target||t.cutoff!==s.cutoff?!1:await this.#e.store.localWorkAfter(t.authorityId,i.work.entityId,s.kept??s.target)===null}#ee(e,t){return e.held&&(e.held.entityId===null||t.includes(e.held.entityId))&&(e.held=null),this.#W(e,t),!0}#W(e,t){e.kind==="lane"&&(this.#r=!0,this.#P(e.unit)),this.#c("apply",t);for(const s of this.#w())s!==e&&s.held?.releaseOnProgress&&!s.held.due&&(s.held.due=!0,this.#i(s))}#te(e,t,s,i){if(s.dependency&&(0,u.assertApplyDependency)(s.dependency),s.blocker&&!s.dependency)throw new Error("Apply blocker must name the dependency that releases it");const n=t.members[0].work.entityId,r=e.held,h=this.#B(e,t),l=this.#D(h),o=s.again===!0&&h<exports.ENTITY_APPLY_SAME_ANSWERS,w={entityId:n,target:this.#d.targetOf(t),kept:t.members[0].work.kept,cutoff:t.cutoff,attempt:h,notBefore:s.dependency?1/0:this.#e.now()+(o?0:l),releaseOnProgress:s.releaseOnProgress,due:s.dependency?this.#x(s.dependency,s.comparedAt??i):o,reason:s.reason,...s.dependency?{dependency:s.dependency}:{},...s.blocker?{blocker:s.blocker}:{}};e.held=w,this.#b();const _=(0,u.heldWait)(r,y(e)),p=(0,u.heldWait)(w,y(e));p&&JSON.stringify(p)!==JSON.stringify(_)&&this.#e.onWaiting?.(p),!(!s.report&&(s.dependency!==void 0||h<exports.ENTITY_APPLY_SAME_ANSWERS))&&this.#R(new Error(`${m(e)} holds at ${n}, which ${s.releaseOnProgress?"is parked on a conflict":s.report?"failed":s.again?"keeps ending unplaced":"stands on ground that keeps moving"}, and will retry in ${l}ms (attempt ${h}): ${s.reason}`,s.cause===void 0?void 0:{cause:s.cause}))}#C(e,t){if(e.kind==="lane"){for(const h of e.waiters)h.fail(t);e.waiters.clear()}const s=e.held,i=(s?.entityId===null?s.attempt:0)+1,n=this.#D(i),r=t instanceof Error?t.message:String(t);e.held={entityId:null,target:null,kept:null,cutoff:null,attempt:i,notBefore:this.#e.now()+n,releaseOnProgress:!1,due:!1,reason:r},this.#b(),this.#R(new Error(`${m(e)} faulted and will retry in ${n}ms (attempt ${i}): ${r}`,{cause:t}))}#R(e){try{this.#O(e)}catch{}}#D(e){const t=Math.min(exports.ENTITY_APPLY_RETRY_MAX_MS,exports.ENTITY_APPLY_RETRY_BASE_MS*2**Math.min(e-1,16)),s=Math.max(0,Math.min(1,this.#e.schedule.random()));return Math.round(t*(.5+s))}#c(e,t){const s=++this.#m;for(const i of t??["*"])this.#S.set(`${e}:${i}`,s);for(const i of this.#w())(0,u.releaseApplyLine)(i,e,t)&&this.#i(i)}#x(e,t){return["*",...e.entityIds].some(s=>(this.#S.get(`${e.producer}:${s}`)??0)>t)}#b(){if(this.#t)return;let e=this.#p;for(const i of this.#w())i.held&&!i.held.due&&(e=Math.min(e,i.held.notBefore));if(e===1/0){this.#N();return}if(this.#y?.dueAt===e)return;this.#N();const t=Math.max(0,e-this.#e.now()),s=this.#e.schedule.schedule(t,()=>{this.#y=null,this.#F(e),this.#n()});this.#y={dueAt:e,cancel:a(()=>s.cancel(),"cancel")}}#F(e){let t=!1;for(const s of this.#w())s.held&&!s.held.due&&s.held.notBefore<=e&&(s.held.due=!0,this.#i(s),t=!0);return this.#p<=e&&(this.#p=1/0,this.#r=!0,t=!0),t}#N(){this.#y?.cancel(),this.#y=null}}exports.EntityApplyRail=P;const y=a(d=>d.kind==="line"?d.authorityId:d.unit,"owner"),m=a(d=>d.kind==="line"?`entity Apply line ${d.authorityId}`:`entity Apply fetch of ${d.unit}`,"label");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var I=Object.defineProperty;var
|
|
1
|
+
"use strict";var I=Object.defineProperty;var f=(e,r)=>I(e,"name",{value:r,configurable:!0});Object.defineProperty(exports,"__esModule",{value:!0}),exports.APPLY_PLAYS=void 0,exports.judgeShowing=v,exports.shownUnits=p,exports.placedInRoot=U,exports.lineReturns=w,exports.returnedPlaces=d;const c=require("../entities/types.js"),_=require("../git/checkout.js"),D=require("../entities/units.js"),b=require("../registration/home-layout.js");exports.APPLY_PLAYS=new Set(["apply","enter","leave"]);const y={onDemand:!1};function v(e,r,u,o){const n=r(e.uuid);if(n!==void 0&&!n.available)return"unseen";const i=n!==void 0,{root:t,returns:a}=h(e,r,u,o);if(t==="sealed")return"neither";if(t==="unseen")return i?"leave":"unseen";if(t===null)return i?"leave":"neither";if(!i&&t.onDemand){const s=p(l=>l===e.uuid?e:void 0,d(r,a));if((0,D.unitOf)(e.uuid,s)===e.uuid&&!U(e.uuid,s))return"listed"}return i&&(c.CONTAINERS.has(n.type)||!c.CONTAINERS.has(e.type))?"apply":"enter"}f(v,"judgeShowing");function p(e,r){return u=>{const o=e(u);if(o?.parentUUID===null)return{...o,home:r(u)?.home===!0};if(o)return o;const n=r(u);return n?.root?{type:n.type,name:n.name,parentUUID:null,home:n.home}:n}}f(p,"shownUnits");function U(e,r,u=new Map){const o=r(e);if(o?.parentUUID===null)return!0;const n=new Set;let i=null;for(let t=e,a=o;a?.parentUUID!=null&&!n.has(t);){const s=u.get(t);if(s!==void 0){i=s;break}n.add(t);const l=r(a.parentUUID);if(l?.parentUUID===null){i={uuid:t,home:l.home===!0};break}t=a.parentUUID,a=l}for(const t of n)u.set(t,i);return i===null?!1:i.home&&(0,b.placedAtHome)(r(i.uuid).name,i.uuid!==e)}f(U,"placedInRoot");function w(e,r,u,o){return h(e,r,u,o).returns}f(w,"lineReturns");function d(e,r){return r.size===0?e:u=>{const o=e(u),n=r.get(u);return o!==void 0&&n!==void 0?{...o,parentUUID:n}:o}}f(d,"returnedPlaces");const m=new Map;function h(e,r,u,o){const n=new Map;for(;;){const i=d(r,n),t=S(e,i,o);if(t===null||t==="sealed"||t==="unseen")return{root:t,returns:m};if("root"in t)return{root:t.root,returns:n};if(!(u&&t.loop.find(s=>!n.has(s)&&R(s,i,u,n))))return{root:null,returns:m}}}f(h,"showingWalk");function R(e,r,u,o){const n=u(e);return n===void 0||n===r(e)?.parentUUID?!1:(o.set(e,n),!0)}f(R,"returnTo");function S(e,r,u){if(e.status!=="active"||(0,_.fileAbsent)(e))return null;if((0,c.isConstructType)(e.type))return{root:y};const o=r(e.uuid)??u?.(e.uuid);if(o?.root)return o.available?{root:o}:"unseen";const n=[e.uuid],i=new Map([[e.uuid,0]]);for(let t=e.parentUUID;t!==null;){const a=i.get(t);if(a!==void 0)return{loop:n.slice(Math.max(a,1))};i.set(t,n.length),n.push(t);const s=r(t);if(s?.available===!1)return"unseen";if(!s||!c.CONTAINERS.has(s.type))return null;if(s.sealed===!0)return"sealed";if(s.root)return{root:s};t=s.parentUUID}return null}f(S,"walkUp");
|
package/dist-cjs/apply/window.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var E=Object.defineProperty;var a=(r,s)=>E(r,"name",{value:s,configurable:!0});Object.defineProperty(exports,"__esModule",{value:!0}),exports.WINDOW_MEMBERS=void 0,exports.foldWindow=D,exports.readWindow=_,exports.windowEndForWait=R,exports.revealOrder=k,exports.resolvedPrefix=$;const z=require("../entities/rules.js"),q=require("../entities/types.js");exports.WINDOW_MEMBERS=4096;function D(r,s=exports.WINDOW_MEMBERS){const d=new Map;let h=0;for(const u of r){const{entityId:l}=u.record;let f=d.get(l);if(f===void 0){if(d.size===s)break;d.set(l,f={records:[],deliverySequence:u.deliverySequence,through:0})}const n=f.records.at(-1);if(n!==void 0&&n.change.turn===void 0!=(u.record.change.turn===void 0))break;if(n!==void 0&&u.record.globalSequence!==n.globalSequence+1)throw new Error(`entity ${l} has a gap before sequence ${u.record.globalSequence} inside its window`);f.records.push(u.record),f.through=h=u.deliverySequence}return Object.freeze({members:Object.freeze([...d].map(([u,{records:l,deliverySequence:f,through:n}])=>Object.freeze({entityId:u,records:Object.freeze(l),deliverySequence:f,through:n}))),through:h})}a(D,"foldWindow");function _(r,s,d,h=exports.WINDOW_MEMBERS){const u=new Map;for(let l=r;;){const f=D(l,h).members.map(o=>{const y=`${o.entityId}:${o.records.at(-1).globalSequence}`;let g=u.get(y);return g===void 0&&u.set(y,g=s(o)),{member:o,judgment:g.judgment,result:g.result}}),n=N(f,d);if(n===null)return f;l=l.slice(0,l.findIndex(o=>o.deliverySequence>=n))}}a(_,"readWindow");const x=a((r,s)=>r!==void 0&&(r.root?r.type!==s.type:r.parentUUID!==s.parentUUID||r.name!==s.name||r.type!==s.type),"movesPlace");function N(r,s){const d=new Set,h=new Set;let u=null;for(const{member:t,judgment:e,result:i}of r)e==="leave"?h.add(t.entityId):(e==="enter"||e==="apply"&&x(s(t.entityId),i))&&d.add(t.entityId),e==="enter"&&q.CONTAINERS.has(i.type)&&t.through<(u?.through??1/0)&&(u=t);if(d.size===0&&h.size===0)return null;const l=new Map(r.map(({member:t})=>[t.entityId,t.deliverySequence])),f=a((t,e)=>t===null?[]:[e,...(0,z.collisionBases)(e)].map(i=>`${t}/${i}`),"slotKeys"),n=a(({member:t,result:e})=>e.status==="active"&&!s(t.entityId)?.root?f(e.parentUUID,e.name):[],"goesTo"),o=a(t=>{const e=s(t.member.entityId);return[...e&&!e.root?f(e.parentUUID,e.name):[],...n(t)]},"slotsOf"),y=new Map,g=new Map,v=a((t,e,i)=>{for(const p of e){const c=t.get(p);c===void 0?t.set(p,[i]):c.length<2&&!c.includes(i)&&c.push(i)}},"note");for(const t of r){const{entityId:e}=t.member;d.has(e)&&v(g,n(t),e),(d.has(e)||h.has(e))&&v(y,o(t),e)}const b=a((t,e)=>{let i;for(const p of f(e.parentUUID,e.name)){const[c,I]=g.get(p)??[],m=c===t?I:c;m!==void 0&&(i===void 0||l.get(m)<l.get(i))&&(i=m)}return i},"pusher"),O=a((t,e,i)=>{const p=new Set([t]);for(let c=e;c!==null&&!p.has(c);){p.add(c);const I=s(c),m=i(c,I);if(m!==void 0)return m;c=I.parentUUID}return null},"climbs"),M=a(t=>{const{member:e,judgment:i,result:p}=t;if(i==="superseded"||i==="own"||i==="turn"||i==="waiting")return[];if((0,q.isConstructType)(p.type))return[];const c=[];for(const S of o(t)){const[w,j]=y.get(S)??[],W=w===e.entityId?j:w;W!==void 0&&c.push(W)}const I=s(e.entityId);if(I&&!I.root){const S=O(e.entityId,I.parentUUID,(w,j)=>d.has(w)?w:!j||j.root?null:b(e.entityId,j));S!==null&&c.push(S)}if(p.status!=="active"||I?.root)return c;const m=O(e.entityId,p.parentUUID,(S,w)=>d.has(S)||h.has(S)?S:w?!w.available||!q.CONTAINERS.has(w.type)||w.root?null:b(e.entityId,w):u!==null&&e.through>u.through?u.entityId:null);return m!==null&&c.push(m),c},"partnersOf");let U=null;for(const t of r){const e=t.member.deliverySequence;if(U!==null&&e>=U)break;for(const i of M(t)){const p=Math.max(e,l.get(i));(U===null||p<U)&&(U=p)}}return U}a(N,"windowCut");function R(r,s){return r.intent!==null||r.unit!==null||s?.producer!=="apply"?null:r.members.slice(1).find(h=>s.entityIds.includes(h.work.entityId))?.deliverySequence??null}a(R,"windowEndForWait");function k(r){const s=new Map(r.map((n,o)=>[n.entityId,{member:n,index:o}])),d=new Map,h=new Set,u=a((n,o)=>{const y=d.get(n);if(y!==void 0)return y;if(o.has(n)){for(const M of o)h.add(M);return-1}const g=s.get(n);if(!g||g.member.parentUUID===null)return 0;const v=s.get(g.member.parentUUID);if(!v)return d.set(n,0),0;o.add(n);const b=u(v.member.entityId,o);o.delete(n);const O=b<0?-1:b+1;return O>=0&&d.set(n,O),O},"depthOf"),l=[],f=[];for(const[n,o]of r.entries()){const y=u(o.entityId,new Set);if(y<0){h.add(o.entityId);continue}(o.play==="leave"?f:l).push({id:o.entityId,depth:y,index:n})}return l.sort((n,o)=>n.depth-o.depth||n.index-o.index),f.sort((n,o)=>o.depth-n.depth||n.index-o.index),Object.freeze({order:Object.freeze([...l,...f].map(({id:n})=>n)),cycle:Object.freeze([...h])})}a(k,"revealOrder");function $(r,s){let d=0;for(;d<r.length&&s(r[d]);)d+=1;return r.slice(0,d)}a($,"resolvedPrefix");
|
|
1
|
+
"use strict";var E=Object.defineProperty;var a=(r,s)=>E(r,"name",{value:s,configurable:!0});Object.defineProperty(exports,"__esModule",{value:!0}),exports.WINDOW_MEMBERS=void 0,exports.foldWindow=D,exports.readWindow=_,exports.windowEndForWait=R,exports.revealOrder=k,exports.resolvedPrefix=$;const z=require("../entities/rules.js"),q=require("../entities/types.js");exports.WINDOW_MEMBERS=4096;function D(r,s=exports.WINDOW_MEMBERS){const d=new Map;let h=0;for(const u of r){const{entityId:l}=u.record;let f=d.get(l);if(f===void 0){if(d.size===s)break;d.set(l,f={records:[],deliverySequence:u.deliverySequence,through:0})}const n=f.records.at(-1);if(n!==void 0&&n.change.turn===void 0!=(u.record.change.turn===void 0))break;if(n!==void 0&&u.record.globalSequence!==n.globalSequence+1)throw new Error(`entity ${l} has a gap before sequence ${u.record.globalSequence} inside its window`);f.records.push(u.record),f.through=h=u.deliverySequence}return Object.freeze({members:Object.freeze([...d].map(([u,{records:l,deliverySequence:f,through:n}])=>Object.freeze({entityId:u,records:Object.freeze(l),deliverySequence:f,through:n}))),through:h})}a(D,"foldWindow");function _(r,s,d,h=exports.WINDOW_MEMBERS){const u=new Map;for(let l=r;;){const f=D(l,h).members.map(o=>{const y=`${o.entityId}:${o.records.at(-1).globalSequence}`;let g=u.get(y);return g===void 0&&u.set(y,g=s(o)),{member:o,judgment:g.judgment,result:g.result}}),n=N(f,d);if(n===null)return f;l=l.slice(0,l.findIndex(o=>o.deliverySequence>=n))}}a(_,"readWindow");const x=a((r,s)=>r!==void 0&&(r.root?r.type!==s.type:r.parentUUID!==s.parentUUID||r.name!==s.name||r.type!==s.type),"movesPlace");function N(r,s){const d=new Set,h=new Set;let u=null;for(const{member:t,judgment:e,result:i}of r)e==="leave"?h.add(t.entityId):(e==="enter"||e==="apply"&&x(s(t.entityId),i))&&d.add(t.entityId),e==="enter"&&q.CONTAINERS.has(i.type)&&t.through<(u?.through??1/0)&&(u=t);if(d.size===0&&h.size===0)return null;const l=new Map(r.map(({member:t})=>[t.entityId,t.deliverySequence])),f=a((t,e)=>t===null?[]:[e,...(0,z.collisionBases)(e)].map(i=>`${t}/${i}`),"slotKeys"),n=a(({member:t,result:e})=>e.status==="active"&&!s(t.entityId)?.root?f(e.parentUUID,e.name):[],"goesTo"),o=a(t=>{const e=s(t.member.entityId);return[...e&&!e.root?f(e.parentUUID,e.name):[],...n(t)]},"slotsOf"),y=new Map,g=new Map,v=a((t,e,i)=>{for(const p of e){const c=t.get(p);c===void 0?t.set(p,[i]):c.length<2&&!c.includes(i)&&c.push(i)}},"note");for(const t of r){const{entityId:e}=t.member;d.has(e)&&v(g,n(t),e),(d.has(e)||h.has(e))&&v(y,o(t),e)}const b=a((t,e)=>{let i;for(const p of f(e.parentUUID,e.name)){const[c,I]=g.get(p)??[],m=c===t?I:c;m!==void 0&&(i===void 0||l.get(m)<l.get(i))&&(i=m)}return i},"pusher"),O=a((t,e,i)=>{const p=new Set([t]);for(let c=e;c!==null&&!p.has(c);){p.add(c);const I=s(c),m=i(c,I);if(m!==void 0)return m;c=I.parentUUID}return null},"climbs"),M=a(t=>{const{member:e,judgment:i,result:p}=t;if(i==="superseded"||i==="own"||i==="unseen"||i==="turn"||i==="waiting")return[];if((0,q.isConstructType)(p.type))return[];const c=[];for(const S of o(t)){const[w,j]=y.get(S)??[],W=w===e.entityId?j:w;W!==void 0&&c.push(W)}const I=s(e.entityId);if(I&&!I.root){const S=O(e.entityId,I.parentUUID,(w,j)=>d.has(w)?w:!j||j.root?null:b(e.entityId,j));S!==null&&c.push(S)}if(p.status!=="active"||I?.root)return c;const m=O(e.entityId,p.parentUUID,(S,w)=>d.has(S)||h.has(S)?S:w?!w.available||!q.CONTAINERS.has(w.type)||w.root?null:b(e.entityId,w):u!==null&&e.through>u.through?u.entityId:null);return m!==null&&c.push(m),c},"partnersOf");let U=null;for(const t of r){const e=t.member.deliverySequence;if(U!==null&&e>=U)break;for(const i of M(t)){const p=Math.max(e,l.get(i));(U===null||p<U)&&(U=p)}}return U}a(N,"windowCut");function R(r,s){return r.intent!==null||r.unit!==null||s?.producer!=="apply"?null:r.members.slice(1).find(h=>s.entityIds.includes(h.work.entityId))?.deliverySequence??null}a(R,"windowEndForWait");function k(r){const s=new Map(r.map((n,o)=>[n.entityId,{member:n,index:o}])),d=new Map,h=new Set,u=a((n,o)=>{const y=d.get(n);if(y!==void 0)return y;if(o.has(n)){for(const M of o)h.add(M);return-1}const g=s.get(n);if(!g||g.member.parentUUID===null)return 0;const v=s.get(g.member.parentUUID);if(!v)return d.set(n,0),0;o.add(n);const b=u(v.member.entityId,o);o.delete(n);const O=b<0?-1:b+1;return O>=0&&d.set(n,O),O},"depthOf"),l=[],f=[];for(const[n,o]of r.entries()){const y=u(o.entityId,new Set);if(y<0){h.add(o.entityId);continue}(o.play==="leave"?f:l).push({id:o.entityId,depth:y,index:n})}return l.sort((n,o)=>n.depth-o.depth||n.index-o.index),f.sort((n,o)=>o.depth-n.depth||n.index-o.index),Object.freeze({order:Object.freeze([...l,...f].map(({id:n})=>n)),cycle:Object.freeze([...h])})}a(k,"revealOrder");function $(r,s){let d=0;for(;d<r.length&&s(r[d]);)d+=1;return r.slice(0,d)}a($,"resolvedPrefix");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var ee=Object.defineProperty;var h=(e,t)=>ee(e,"name",{value:t,configurable:!0});Object.defineProperty(exports,"__esModule",{value:!0}),exports.PublicationScopeExceeded=exports.groundWaits=exports.holdsOnlyItself=void 0,exports.childGroupNames=se,exports.childGroupOwed=re,exports.selectPublicationSteps=W,exports.selectPublication=ue;const q=require("../entities/rules.js"),x=require("../entities/types.js"),i=require("../steps.js"),te=h(e=>e==="ignored"||e==="waiting","holdsOnlyItself");exports.holdsOnlyItself=te;const ne=h(e=>(e.type==="repo.git"||e.type==="file.text"||e.type==="file.binary")&&(e.payloadVersion??null)===null,"groundWaits");exports.groundWaits=ne;function V(e,t){const c=new Map;return u=>{const r=new Set;let a=u,d;for(;d===void 0;)a==null||r.has(a)?d=!1:(d=c.get(a))===void 0&&(e.has(a)?d=!0:(r.add(a),a=t(a)));for(const g of r)c.set(g,d);return d}}h(V,"beneath");const C=h(e=>JSON.stringify([e.parentUUID,e.name]),"slot"),R=h((e,t)=>!e||!t||e.parentUUID!==t.parentUUID||e.name!==t.name||e.type!==t.type,"structuralChange");function se(e){const t=new Set;for(const{name:c}of e)for(const u of[c,...(0,q.collisionBases)(c)])t.add(u);return[...t]}h(se,"childGroupNames");function re(e,t){const c=new Map;for(const{uuid:r,name:a}of e)c.set(a,(c.get(a)??new Set).add(r));const u=h(r=>new Set([...t(r),...c.get(r)??[]]).size>1,"shared");return[...c.keys()].some(r=>u(r)||(0,q.collisionBases)(r).some(u))}h(re,"childGroupOwed");class H extends Error{static{h(this,"PublicationScopeExceeded")}entityIds;constructor(t){super("scoped publication selection changes context outside its targets"),this.entityIds=t}}exports.PublicationScopeExceeded=H;function*ae(e,t,c,u){const r=new Map;yield*(0,i.eachStep)(e.before,S=>r.set(S.uuid,S));const a=new Map,d=new Set;yield*(0,i.eachStep)(u.selected,S=>a.set(S.uuid,S)),yield*(0,i.eachStep)(u.withheld,S=>{a.has(S.entityId)||d.add(S.entityId)});const g=new Set,b=[],M=h(S=>{if(g.has(S))return;g.add(S);const N=r.get(S),P=a.get(S);(N===void 0?P!==void 0:!d.has(S)&&(R(N,P)||N.relativePath!==P.relativePath))&&b.push(S)},"judge");yield*(0,i.eachStep)(r.keys(),M),yield*(0,i.eachStep)(e.observed,S=>M(S.uuid)),yield*(0,i.eachStep)(c,M);const D=new Set(b),O=yield*_(yield*A(t)),U=yield*_(yield*A(u.selected));if(yield*(0,i.eachStep)(r,([S,N])=>{const P=U.get(S);x.CONTAINERS.has(N.type)&&!d.has(S)&&!D.has(S)&&P&&!G(O.get(S),P)&&b.push(S)}),b.length)throw new H(b.sort())}h(ae,"requireClosedScope");function*oe(e,t){let c=0;for(const u of e){const r=t.get(u.uuid);if(R(u,r)||r.uuid!==u.uuid||r.relativePath!==u.relativePath)return!1;++c%i.ITEMS_PER_BOUNDARY===0&&(yield)}return!0}h(oe,"sameStructure");function*L(e){const t=new Set,c=new Set;return yield*(0,i.eachStep)(e.keys(),u=>{if(t.has(u))return;const r=[],a=new Map;let d=u;for(;d!==null&&e.has(d)&&!t.has(d);){const g=a.get(d);if(g!==void 0){for(const b of r.slice(g))c.add(b);break}a.set(d,r.length),r.push(d),d=e.get(d).parentUUID}for(const g of r)t.add(g)}),c}h(L,"cycles");const Q=h(e=>!!e.uuid&&x.TYPES.has(e.type)&&!x.CONSTRUCT_TYPES.has(e.type)&&!e.relativePath.startsWith("/")&&(e.relativePath===""||e.relativePath.split("/").every(t=>t&&t!==".."&&t!=="."))&&(e.parentUUID===null||!!e.name&&!e.name.includes("/")),"physical");function*A(e){const t=new Map;if(yield*(0,i.eachStep)(e,c=>{if(!Q(c)||t.has(c.uuid))throw new Error("publication input is not a physical identity graph");t.set(c.uuid,c)}),yield*(0,i.eachStep)(e,c=>{if(c.parentUUID===null)return;const u=t.get(c.parentUUID);if(!u||!x.CONTAINERS.has(u.type))throw new Error("publication input has an invalid parent")}),(yield*L(t)).size)throw new Error("publication input has a parent cycle");return t}h(A,"graph");function*_(e){const t=new Map;yield*(0,i.eachStep)(e.values(),a=>{if(a.parentUUID===null)return;const d=t.get(a.parentUUID)??[];d.push(a),t.set(a.parentUUID,d)});const c=new Map;let u=0;for(const[a,d]of t)c.set(a,yield*(0,q.materializedSlotProjectionSteps)(d)),u+=d.length,u>=i.ITEMS_PER_BOUNDARY&&(u=0,yield);const r=new Map;return yield*(0,i.eachStep)(e.values(),a=>{const d=[];let g=a;for(;g&&!r.has(g.uuid);)d.push(g),g=g.parentUUID===null?void 0:e.get(g.parentUUID);for(const b of d.reverse()){const M=b.parentUUID===null?null:e.get(b.parentUUID),D=M===null?null:r.get(M.uuid),O=b.parentUUID===null?void 0:c.get(b.parentUUID),U=O?.names.get(b.uuid)??b.name;r.set(b.uuid,{rootId:D?.rootId??b.uuid,path:D===null?"":D.path?`${D.path}/${U}`:U,policyPath:b.relativePath,directory:x.CONTAINERS.has(b.type),localName:U,siblings:O?.dependencies.get(b.uuid)??new Set})}}),r}h(_,"addresses");const ie=h((e,t)=>e&&t?`${e}/${t}`:e||t,"joined"),G=h((e,t)=>e.rootId===t.rootId&&e.path===t.path,"sameAddress");function*ce(e,t){const c=new Map;return yield*(0,i.eachStep)(e,u=>{const{row:r}=u;if(!Q(r)||r.parentUUID===null||t.has(r.uuid)||c.has(r.uuid))throw new Error("publication hidden statement is not a retained row outside the active graph");c.set(r.uuid,u)}),c}h(ce,"statements");function*le(e,t){let c=!0;const u=h(r=>{let a=t.get(r);for(;a&&a.parentUUID!==null;)a=t.get(a.parentUUID);return a?.uuid??null},"rootOf");return yield*(0,i.eachStep)(e.values(),r=>{if(r.parentUUID!==null)return;const a=u(r.uuid);c&&=a===r.uuid||a!==null&&!e.has(a)}),yield*(0,i.eachStep)(t.values(),r=>{r.parentUUID===null&&e.has(r.uuid)&&(c&&=e.get(r.uuid).parentUUID===null)}),c}h(le,"rootsKept");function*de(e,t,c){const u=new Map;if(yield*(0,i.eachStep)(t.values(),a=>{const d=c.get(a.uuid);a.parentUUID===null&&d&&d.rootId!==a.uuid&&u.set(a.uuid,d)}),u.size===0)return e;const r=new Map;return yield*(0,i.eachStep)(e,([a,d])=>{const g=u.get(d.rootId);r.set(a,g===void 0?d:{...d,rootId:g.rootId,path:d.path?`${g.path}/${d.path}`:g.path})}),r}h(de,"absorbedFrame");function*W(e){if(e.context!==void 0){const n=new Map,l=new Map;yield*(0,i.eachStep)(e.before,s=>n.set(s.uuid,s)),yield*(0,i.eachStep)(e.observed,s=>l.set(s.uuid,s));const o=new Set,p=new Set;yield*(0,i.eachStep)(e.context.before,s=>o.add(s.uuid)),yield*(0,i.eachStep)(e.context.observed,s=>p.add(s.uuid));const f=new Map,w=[];yield*(0,i.eachStep)(e.hidden??[],({row:s})=>f.set(s.uuid,s)),yield*(0,i.eachStep)(e.context.hidden??[],({row:s})=>w.push(s.uuid));const v=h(s=>n.has(s)||l.has(s)||f.has(s),"target");let E=n.size!==e.before.length||l.size!==e.observed.length||o.size!==e.context.before.length||p.size!==e.context.observed.length;if(yield*(0,i.eachStep)([...n.keys(),...l.keys(),...f.keys()],s=>{E||=o.has(s)||p.has(s)}),yield*(0,i.eachStep)(w,s=>{E||=v(s)}),E)throw new Error("publication scope names an identity twice");let j=!1;if(yield*(0,i.eachStep)(e.before,s=>{j||=s.parentUUID!==null&&!(o.has(s.parentUUID)||n.has(s.parentUUID))}),yield*(0,i.eachStep)(e.observed,s=>{j||=s.parentUUID!==null&&!(p.has(s.parentUUID)||l.has(s.parentUUID))}),j)throw new Error("publication scope lacks a target parent");const y=[...e.context.before,...e.before],I=yield*W({before:y,observed:[...e.context.observed,...e.observed],travels:e.travels,...e.waiting&&{waiting:e.waiting},hidden:[...e.hidden??[],...e.context.hidden??[]]});yield*ae(e.context,y,w,I);const m=h(s=>n.get(s)??f.get(s)??null,"retained"),z=[],k=new Map;return yield*(0,i.eachStep)(I.selected,s=>{if(!v(s.uuid))return;const T=I.sources.get(s.uuid);z.push(T==="before"?m(s.uuid):l.get(s.uuid)),k.set(s.uuid,T)}),Object.freeze({selected:Object.freeze(z),sources:k,withheld:Object.freeze(I.withheld.filter(s=>v(s.entityId)).map(s=>Object.freeze({...s,before:m(s.entityId),observed:l.get(s.entityId)??null})))})}const t=yield*A(e.before),c=yield*A(e.observed);if(!(yield*le(t,c)))throw new Error("publication cannot remove or replace materialization roots");const u=yield*ce(e.hidden??[],t),r=t.size===c.size&&(yield*oe(t.values(),c)),a=yield*_(t),d=r?a:yield*_(c),g=new Map,b=h(n=>{const l=new Set;let o=n,p;for(;(p=g.has(o)?g.get(o):a.get(o)?.rootId)===void 0;){const f=u.get(o)?.row.parentUUID;if(f===void 0||l.has(o)){p=null;break}l.add(o),o=f}for(const f of l)g.set(f,p);return p},"rootOf"),M=new Map;yield*(0,i.eachStep)(u,([n,{row:l}])=>{const o=b(n);o!==null&&M.set(n,{rootId:o,policyPath:l.relativePath,directory:x.CONTAINERS.has(l.type)})});const D=new Set;yield*(0,i.eachStep)(t.keys(),n=>D.add(n)),yield*(0,i.eachStep)(c.keys(),n=>D.add(n)),yield*(0,i.eachStep)(M.keys(),n=>D.add(n));const O=yield*(0,i.sortSteps)(D,(n,l)=>n<l?-1:n>l?1:0),U=new Map,S=h((n,l)=>l.rootId===n||e.travels(l.policyPath,l.rootId,l.directory),"admitted"),N=new Set;yield*(0,i.eachStep)(O,n=>{const l=a.get(n)??M.get(n),o=d.get(n);if(o===void 0)return;const p=l===void 0?void 0:d.get(l.rootId),f=l!==void 0&&p!==void 0&&p.rootId===o.rootId&&ie(p.policyPath,l.policyPath)===o.policyPath&&l.directory===o.directory;if(f&&t.has(n))return;const w=S(n,o);w!==!0&&(w===!1&&!f&&t.get(n)?.parentUUID?N.add(n):U.set(n,"ignored"))});const P=e.waiting;if(P&&P.size>0){const n=V(P,o=>t.get(o)?.parentUUID??u.get(o)?.row.parentUUID),l=V(P,o=>c.get(o)?.parentUUID);yield*(0,i.eachStep)(O,o=>{!U.has(o)&&(n(o)||l(o))&&U.set(o,"waiting")})}const X=h(n=>{const l=u.get(n);return t.get(n)??(l&&!l.trashed?l.row:void 0)},"retained");function*Y(){const n=new Map;yield*(0,i.eachStep)(O,o=>{const p=U.has(o)?X(o):N.has(o)?void 0:c.get(o);p&&n.set(o,p)});const l=new Map;return yield*(0,i.eachStep)(O,o=>{if(!U.has(o)||!n.has(o))return;const p=[];let f=o,w;for(;w===void 0&&(w=l.get(f),w===void 0);){p.push(f);const v=n.get(f).parentUUID;v===null?w=!1:n.has(v)?!t.has(f)&&!x.CONTAINERS.has(n.get(v).type)?w=!0:U.has(v)?f=v:w=!1:w=!0}for(const v of p)l.set(v,w)}),yield*(0,i.eachStep)(l,([o,p])=>{p&&n.delete(o)}),n}h(Y,"select");function*F(n){const l=[],o=new Map;yield*(0,i.eachStep)(n,([f,w])=>{l.push(w),o.set(f,U.has(f)?"before":"observed")});const p=[];return yield*(0,i.eachStep)(O,f=>{U.has(f)&&p.push(Object.freeze({entityId:f,before:t.get(f)??u.get(f)?.row??null,observed:c.get(f)??null,reason:U.get(f)}))}),Object.freeze({selected:Object.freeze(l),sources:o,withheld:Object.freeze(p)})}if(h(F,"result"),r)return yield*F(yield*Y());const Z=yield*de(a,t,d),J=h(n=>(U.has(n)?Z:d).get(n),"expectedAddress");for(;;){const n=yield*Y(),l=new Map,o=new Map,p=h((y,I,m=!0)=>{const z=m?l:o;!U.has(y)&&!z.has(y)&&z.set(y,I)},"hold");let f=!0;yield*(0,i.eachStep)(n,([y,I])=>{if(I.parentUUID===null)return;const m=n.get(I.parentUUID);(!m||!x.CONTAINERS.has(m.type))&&(f=!1,U.has(y)?p(I.parentUUID,"parent"):p(y,"parent",!1))});const w=new Set;yield*(0,i.eachStep)(n,([y,I])=>{U.has(y)&&w.add(C(I))}),yield*(0,i.eachStep)(n,([y,I])=>{const m=t.get(y);!U.has(y)&&w.has(C(I))&&(!m||C(m)!==C(I))&&p(y,"address")});const v=yield*L(n);for(const y of v)p(y,"cycle");const E=f&&v.size===0?yield*_(n):null;E!==null&&(yield*(0,i.eachStep)(n,([y,I])=>{const m=E.get(y),z=J(y);if(z===void 0||G(m,z))return;const k=m.rootId!==z.rootId?"root":"address";if(!U.has(y)){p(y,k,!1);return}let s=I;for(;s;){const T=n.get(s.uuid);R(s,T)&&p(s.uuid,k);const K=a.get(s.uuid),B=E.get(s.uuid);if(B&&K.localName!==B.localName)for(const $ of new Set([...K.siblings,...B.siblings]))R(t.get($),n.get($))&&p($,"address");s=s.parentUUID===null?void 0:t.get(s.parentUUID)}}));const j=l.size?l:o;if(j.size===0){yield*A([...n.values()]);let y=E===null;if(E!==null&&(yield*(0,i.eachStep)(n.keys(),I=>{const m=J(I);y||=m!==void 0&&!G(E.get(I),m)})),y)throw new Error("publication could not retain a coherent address");return yield*F(n)}for(const[y,I]of j)U.set(y,I)}}h(W,"selectPublicationSteps");function ue(e){return(0,i.finishSteps)(W(e))}h(ue,"selectPublication");
|
|
1
|
+
"use strict";var ee=Object.defineProperty;var h=(e,t)=>ee(e,"name",{value:t,configurable:!0});Object.defineProperty(exports,"__esModule",{value:!0}),exports.PublicationScopeExceeded=exports.groundWaits=exports.holdsOnlyItself=void 0,exports.childGroupNames=se,exports.childGroupOwed=re,exports.selectPublicationSteps=W,exports.selectPublication=ue;const q=require("../entities/rules.js"),x=require("../entities/types.js"),i=require("../steps.js"),te=h(e=>e==="ignored"||e==="waiting","holdsOnlyItself");exports.holdsOnlyItself=te;const ne=h(e=>(e.type==="repo.git"||e.type==="file.text"||e.type==="file.binary")&&(e.payloadVersion??null)===null,"groundWaits");exports.groundWaits=ne;function V(e,t){const c=new Map;return u=>{const r=new Set;let a=u,d;for(;d===void 0;)a==null||r.has(a)?d=!1:(d=c.get(a))===void 0&&(e.has(a)?d=!0:(r.add(a),a=t(a)));for(const g of r)c.set(g,d);return d}}h(V,"beneath");const C=h(e=>JSON.stringify([e.parentUUID,e.name]),"slot"),R=h((e,t)=>!e||!t||e.parentUUID!==t.parentUUID||e.name!==t.name||e.type!==t.type,"structuralChange");function se(e){const t=new Set;for(const{name:c}of e)for(const u of[c,...(0,q.collisionBases)(c)])t.add(u);return[...t]}h(se,"childGroupNames");function re(e,t){const c=new Map;for(const{uuid:r,name:a}of e)c.set(a,(c.get(a)??new Set).add(r));const u=h(r=>new Set([...t(r),...c.get(r)??[]]).size>1,"shared");return[...c.keys()].some(r=>u(r)||(0,q.collisionBases)(r).some(u))}h(re,"childGroupOwed");class H extends Error{static{h(this,"PublicationScopeExceeded")}entityIds;constructor(t){super("scoped publication selection changes context outside its targets"),this.entityIds=t}}exports.PublicationScopeExceeded=H;function*ae(e,t,c,u){const r=new Map;yield*(0,i.eachStep)(e.before,S=>r.set(S.uuid,S));const a=new Map,d=new Set;yield*(0,i.eachStep)(u.selected,S=>a.set(S.uuid,S)),yield*(0,i.eachStep)(u.withheld,S=>{a.has(S.entityId)||d.add(S.entityId)});const g=new Set,b=[],M=h(S=>{if(g.has(S))return;g.add(S);const N=r.get(S),P=a.get(S);(N===void 0?P!==void 0:!d.has(S)&&(R(N,P)||N.relativePath!==P.relativePath))&&b.push(S)},"judge");yield*(0,i.eachStep)(r.keys(),M),yield*(0,i.eachStep)(e.observed,S=>M(S.uuid)),yield*(0,i.eachStep)(c,M);const D=new Set(b),O=yield*_(yield*A(t)),U=yield*_(yield*A(u.selected));if(yield*(0,i.eachStep)(r,([S,N])=>{const P=U.get(S);x.CONTAINERS.has(N.type)&&!d.has(S)&&!D.has(S)&&P&&!G(O.get(S),P)&&b.push(S)}),b.length)throw new H(b.sort())}h(ae,"requireClosedScope");function*oe(e,t){let c=0;for(const u of e){const r=t.get(u.uuid);if(R(u,r)||r.uuid!==u.uuid||r.relativePath!==u.relativePath)return!1;++c%i.ITEMS_PER_BOUNDARY===0&&(yield)}return!0}h(oe,"sameStructure");function*L(e){const t=new Set,c=new Set;return yield*(0,i.eachStep)(e.keys(),u=>{if(t.has(u))return;const r=[],a=new Map;let d=u;for(;d!==null&&e.has(d)&&!t.has(d);){const g=a.get(d);if(g!==void 0){for(const b of r.slice(g))c.add(b);break}a.set(d,r.length),r.push(d),d=e.get(d).parentUUID}for(const g of r)t.add(g)}),c}h(L,"cycles");const Q=h(e=>!!e.uuid&&x.TYPES.has(e.type)&&!x.CONSTRUCT_TYPES.has(e.type)&&!e.relativePath.startsWith("/")&&(e.relativePath===""||e.relativePath.split("/").every(t=>t&&t!==".."&&t!=="."))&&(e.parentUUID===null||!!e.name&&!e.name.includes("/")),"physical");function*A(e){const t=new Map;if(yield*(0,i.eachStep)(e,c=>{if(!Q(c)||t.has(c.uuid))throw new Error("publication input is not a physical identity graph");t.set(c.uuid,c)}),yield*(0,i.eachStep)(e,c=>{if(c.parentUUID===null)return;const u=t.get(c.parentUUID);if(!u||!x.CONTAINERS.has(u.type))throw new Error("publication input has an invalid parent")}),(yield*L(t)).size)throw new Error("publication input has a parent cycle");return t}h(A,"graph");function*_(e){const t=new Map;yield*(0,i.eachStep)(e.values(),a=>{if(a.parentUUID===null)return;const d=t.get(a.parentUUID)??[];d.push(a),t.set(a.parentUUID,d)});const c=new Map;let u=0;for(const[a,d]of t)c.set(a,yield*(0,q.materializedSlotProjectionSteps)(d)),u+=d.length,u>=i.ITEMS_PER_BOUNDARY&&(u=0,yield);const r=new Map;return yield*(0,i.eachStep)(e.values(),a=>{const d=[];let g=a;for(;g&&!r.has(g.uuid);)d.push(g),g=g.parentUUID===null?void 0:e.get(g.parentUUID);for(const b of d.reverse()){const M=b.parentUUID===null?null:e.get(b.parentUUID),D=M===null?null:r.get(M.uuid),O=b.parentUUID===null?void 0:c.get(b.parentUUID),U=O?.names.get(b.uuid)??b.name;r.set(b.uuid,{rootId:D?.rootId??b.uuid,path:D===null?"":D.path?`${D.path}/${U}`:U,policyPath:b.relativePath,directory:x.CONTAINERS.has(b.type),localName:U,siblings:O?.dependencies.get(b.uuid)??new Set})}}),r}h(_,"addresses");const ie=h((e,t)=>e&&t?`${e}/${t}`:e||t,"joined"),G=h((e,t)=>e.rootId===t.rootId&&e.path===t.path,"sameAddress");function*ce(e,t){const c=new Map;return yield*(0,i.eachStep)(e,u=>{const{row:r}=u;if(!Q(r)||t.has(r.uuid)||c.has(r.uuid))throw new Error("publication hidden statement is not a retained row outside the active graph");c.set(r.uuid,u)}),c}h(ce,"statements");function*le(e,t){let c=!0;const u=h(r=>{let a=t.get(r);for(;a&&a.parentUUID!==null;)a=t.get(a.parentUUID);return a?.uuid??null},"rootOf");return yield*(0,i.eachStep)(e.values(),r=>{if(r.parentUUID!==null)return;const a=u(r.uuid);c&&=a===r.uuid||a!==null&&!e.has(a)}),yield*(0,i.eachStep)(t.values(),r=>{r.parentUUID===null&&e.has(r.uuid)&&(c&&=e.get(r.uuid).parentUUID===null)}),c}h(le,"rootsKept");function*de(e,t,c){const u=new Map;if(yield*(0,i.eachStep)(t.values(),a=>{const d=c.get(a.uuid);a.parentUUID===null&&d&&d.rootId!==a.uuid&&u.set(a.uuid,d)}),u.size===0)return e;const r=new Map;return yield*(0,i.eachStep)(e,([a,d])=>{const g=u.get(d.rootId);r.set(a,g===void 0?d:{...d,rootId:g.rootId,path:d.path?`${g.path}/${d.path}`:g.path})}),r}h(de,"absorbedFrame");function*W(e){if(e.context!==void 0){const n=new Map,l=new Map;yield*(0,i.eachStep)(e.before,s=>n.set(s.uuid,s)),yield*(0,i.eachStep)(e.observed,s=>l.set(s.uuid,s));const o=new Set,p=new Set;yield*(0,i.eachStep)(e.context.before,s=>o.add(s.uuid)),yield*(0,i.eachStep)(e.context.observed,s=>p.add(s.uuid));const f=new Map,w=[];yield*(0,i.eachStep)(e.hidden??[],({row:s})=>f.set(s.uuid,s)),yield*(0,i.eachStep)(e.context.hidden??[],({row:s})=>w.push(s.uuid));const v=h(s=>n.has(s)||l.has(s)||f.has(s),"target");let E=n.size!==e.before.length||l.size!==e.observed.length||o.size!==e.context.before.length||p.size!==e.context.observed.length;if(yield*(0,i.eachStep)([...n.keys(),...l.keys(),...f.keys()],s=>{E||=o.has(s)||p.has(s)}),yield*(0,i.eachStep)(w,s=>{E||=v(s)}),E)throw new Error("publication scope names an identity twice");let j=!1;if(yield*(0,i.eachStep)(e.before,s=>{j||=s.parentUUID!==null&&!(o.has(s.parentUUID)||n.has(s.parentUUID))}),yield*(0,i.eachStep)(e.observed,s=>{j||=s.parentUUID!==null&&!(p.has(s.parentUUID)||l.has(s.parentUUID))}),j)throw new Error("publication scope lacks a target parent");const y=[...e.context.before,...e.before],I=yield*W({before:y,observed:[...e.context.observed,...e.observed],travels:e.travels,...e.waiting&&{waiting:e.waiting},hidden:[...e.hidden??[],...e.context.hidden??[]]});yield*ae(e.context,y,w,I);const m=h(s=>n.get(s)??f.get(s)??null,"retained"),z=[],k=new Map;return yield*(0,i.eachStep)(I.selected,s=>{if(!v(s.uuid))return;const T=I.sources.get(s.uuid);z.push(T==="before"?m(s.uuid):l.get(s.uuid)),k.set(s.uuid,T)}),Object.freeze({selected:Object.freeze(z),sources:k,withheld:Object.freeze(I.withheld.filter(s=>v(s.entityId)).map(s=>Object.freeze({...s,before:m(s.entityId),observed:l.get(s.entityId)??null})))})}const t=yield*A(e.before),c=yield*A(e.observed);if(!(yield*le(t,c)))throw new Error("publication cannot remove or replace materialization roots");const u=yield*ce(e.hidden??[],t),r=t.size===c.size&&(yield*oe(t.values(),c)),a=yield*_(t),d=r?a:yield*_(c),g=new Map,b=h(n=>{const l=new Set;let o=n,p;for(;(p=g.has(o)?g.get(o):a.get(o)?.rootId)===void 0;){const f=u.get(o)?.row.parentUUID;if(f===void 0||l.has(o)){p=null;break}l.add(o),o=f}for(const f of l)g.set(f,p);return p},"rootOf"),M=new Map;yield*(0,i.eachStep)(u,([n,{row:l}])=>{const o=b(n);o!==null&&M.set(n,{rootId:o,policyPath:l.relativePath,directory:x.CONTAINERS.has(l.type)})});const D=new Set;yield*(0,i.eachStep)(t.keys(),n=>D.add(n)),yield*(0,i.eachStep)(c.keys(),n=>D.add(n)),yield*(0,i.eachStep)(M.keys(),n=>D.add(n));const O=yield*(0,i.sortSteps)(D,(n,l)=>n<l?-1:n>l?1:0),U=new Map,S=h((n,l)=>l.rootId===n||e.travels(l.policyPath,l.rootId,l.directory),"admitted"),N=new Set;yield*(0,i.eachStep)(O,n=>{const l=a.get(n)??M.get(n),o=d.get(n);if(o===void 0)return;const p=l===void 0?void 0:d.get(l.rootId),f=l!==void 0&&p!==void 0&&p.rootId===o.rootId&&ie(p.policyPath,l.policyPath)===o.policyPath&&l.directory===o.directory;if(f&&t.has(n))return;const w=S(n,o);w!==!0&&(w===!1&&!f&&t.get(n)?.parentUUID?N.add(n):U.set(n,"ignored"))});const P=e.waiting;if(P&&P.size>0){const n=V(P,o=>t.get(o)?.parentUUID??u.get(o)?.row.parentUUID),l=V(P,o=>c.get(o)?.parentUUID);yield*(0,i.eachStep)(O,o=>{!U.has(o)&&(n(o)||l(o))&&U.set(o,"waiting")})}const X=h(n=>{const l=u.get(n);return t.get(n)??(l&&!l.trashed?l.row:void 0)},"retained");function*Y(){const n=new Map;yield*(0,i.eachStep)(O,o=>{const p=U.has(o)?X(o):N.has(o)?void 0:c.get(o);p&&n.set(o,p)});const l=new Map;return yield*(0,i.eachStep)(O,o=>{if(!U.has(o)||!n.has(o))return;const p=[];let f=o,w;for(;w===void 0&&(w=l.get(f),w===void 0);){p.push(f);const v=n.get(f).parentUUID;v===null?w=!1:n.has(v)?!t.has(f)&&!x.CONTAINERS.has(n.get(v).type)?w=!0:U.has(v)?f=v:w=!1:w=!0}for(const v of p)l.set(v,w)}),yield*(0,i.eachStep)(l,([o,p])=>{p&&n.delete(o)}),n}h(Y,"select");function*F(n){const l=[],o=new Map;yield*(0,i.eachStep)(n,([f,w])=>{l.push(w),o.set(f,U.has(f)?"before":"observed")});const p=[];return yield*(0,i.eachStep)(O,f=>{U.has(f)&&p.push(Object.freeze({entityId:f,before:t.get(f)??u.get(f)?.row??null,observed:c.get(f)??null,reason:U.get(f)}))}),Object.freeze({selected:Object.freeze(l),sources:o,withheld:Object.freeze(p)})}if(h(F,"result"),r)return yield*F(yield*Y());const Z=yield*de(a,t,d),J=h(n=>(U.has(n)?Z:d).get(n),"expectedAddress");for(;;){const n=yield*Y(),l=new Map,o=new Map,p=h((y,I,m=!0)=>{const z=m?l:o;!U.has(y)&&!z.has(y)&&z.set(y,I)},"hold");let f=!0;yield*(0,i.eachStep)(n,([y,I])=>{if(I.parentUUID===null)return;const m=n.get(I.parentUUID);(!m||!x.CONTAINERS.has(m.type))&&(f=!1,U.has(y)?p(I.parentUUID,"parent"):p(y,"parent",!1))});const w=new Set;yield*(0,i.eachStep)(n,([y,I])=>{U.has(y)&&w.add(C(I))}),yield*(0,i.eachStep)(n,([y,I])=>{const m=t.get(y);!U.has(y)&&w.has(C(I))&&(!m||C(m)!==C(I))&&p(y,"address")});const v=yield*L(n);for(const y of v)p(y,"cycle");const E=f&&v.size===0?yield*_(n):null;E!==null&&(yield*(0,i.eachStep)(n,([y,I])=>{const m=E.get(y),z=J(y);if(z===void 0||G(m,z))return;const k=m.rootId!==z.rootId?"root":"address";if(!U.has(y)){p(y,k,!1);return}let s=I;for(;s;){const T=n.get(s.uuid);R(s,T)&&p(s.uuid,k);const K=a.get(s.uuid),B=E.get(s.uuid);if(B&&K.localName!==B.localName)for(const $ of new Set([...K.siblings,...B.siblings]))R(t.get($),n.get($))&&p($,"address");s=s.parentUUID===null?void 0:t.get(s.parentUUID)}}));const j=l.size?l:o;if(j.size===0){yield*A([...n.values()]);let y=E===null;if(E!==null&&(yield*(0,i.eachStep)(n.keys(),I=>{const m=J(I);y||=m!==void 0&&!G(E.get(I),m)})),y)throw new Error("publication could not retain a coherent address");return yield*F(n)}for(const[y,I]of j)U.set(y,I)}}h(W,"selectPublicationSteps");function ue(e){return(0,i.finishSteps)(W(e))}h(ue,"selectPublication");
|
package/dist-cjs/records/rail.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var u=Object.defineProperty;var n=(o,t)=>u(o,"name",{value:t,configurable:!0});Object.defineProperty(exports,"__esModule",{value:!0}),exports.EntityRecordRail=void 0;const l=require("./contracts.js"),y=require("./receive-loop.js"),w=require("./send-line.js"),f=require("./unsent-count.js");class m{static{n(this,"EntityRecordRail")}#n;#h;#o;#d;#c;#e;#t;#s;#r=!1;#i=null;constructor(t){if(!t.authorityId.trim())throw new Error("entity record authority is required");this.#n=t.authorityId,this.#h=t.store,this.#o=t.schedule,this.#d=t.onOutboxAccepted??(()=>{}),this.#c=t.onBackgroundError??(()=>{});const r=n(e=>this.#a(e),"onError");this.#e=new y.ReceiveLoop({authorityId:t.authorityId,store:t.store,authority:t.authority,schedule:t.schedule,channels:t.channels??[],onInboxCommitted:t.onInboxCommitted??(()=>{}),onError:r}),this.#t=new w.SendLine({store:t.store,cargo:t.cargo,authority:t.authority,schedule:t.schedule,onStamped:n(e=>this.#u(e),"onStamped"),onError:r});const i=t.onUnsent;this.#s=i?new f.UnsentCount({read:n(()=>t.store.countPending(),"read"),say:i,onError:r,schedule:t.schedule}):null}async start(){if(this.#r)throw new Error("entity record rail already started");if(this.#i)throw new Error("entity record rail is stopped");this.#r=!0,this.#s?.changed(),this.#e.start(),await this.#t.start()}get sendPaused(){return this.#t.paused}get sendHeld(){return this.#t.held}localRecordsAvailable(){this.#s?.changed(),this.#t.wake()}hold(t){this.#e.hold(t)}release(t){this.#e.release(t)}async flush(){if(!this.#r)throw new Error("entity record rail has not started");if(this.#i)throw new Error("entity record rail is stopped");await this.#e.coverReceipts(await this.#t.settle())}async receiveThrough(t){if(!this.#r)throw new Error("entity record rail has not started");await this.#e.receiveThrough(t)}async receiveCurrent(){if(!this.#r)throw new Error("entity record rail has not started");await this.#e.receiveCurrent()}async close(t,r){if(!Number.isFinite(t)||t<0)throw new Error("entity record close budget must be a non-negative number of milliseconds");const i=this.#t.stamped;if(this.#r&&!this.#i&&t>0){let s=n(()=>{},"expire");const h=new Promise(a=>{s=a}),c=this.#o.schedule(t,()=>s());try{const a=this.#t.settle();await Promise.race([a.catch(d=>{!this.#i&&d!==this.#t.paused&&this.#a(d)}),h])}finally{c.cancel()}}const e=this.stop();return await r(),await e,{accepted:this.#t.stamped-i,pending:await this.#h.countPending(),unconfirmed:await this.#h.countPending(this.#t.uncertainThrough)}}stop(){return this.#i??=Promise.all([this.#e.stop(),this.#t.stop(),this.#s?.stop()]).then(()=>{}),this.#i}#u(t){this.#s?.changed();const r=new Set;let i=!1;for(const{row:e,accepted:s}of t){for(const{entityId:h}of(0,l.channelRecords)(e.record))r.add(h),s.authorityId!==this.#n&&this.#e.ring({authorityId:s.authorityId,entityId:h});s.authorityId===this.#n&&(i=!0)}i&&this.#e.ring({authorityId:this.#n,entityId:null});try{this.#d([...r])}catch(e){this.#a(e)}}#a(t){try{this.#c(t)}catch{}}}exports.EntityRecordRail=m;
|
|
1
|
+
"use strict";var u=Object.defineProperty;var n=(o,t)=>u(o,"name",{value:t,configurable:!0});Object.defineProperty(exports,"__esModule",{value:!0}),exports.EntityRecordRail=void 0;const l=require("./contracts.js"),y=require("./receive-loop.js"),w=require("./send-line.js"),f=require("./unsent-count.js");class m{static{n(this,"EntityRecordRail")}#n;#h;#o;#d;#c;#e;#t;#s;#r=!1;#i=null;constructor(t){if(!t.authorityId.trim())throw new Error("entity record authority is required");this.#n=t.authorityId,this.#h=t.store,this.#o=t.schedule,this.#d=t.onOutboxAccepted??(()=>{}),this.#c=t.onBackgroundError??(()=>{});const r=n(e=>this.#a(e),"onError");this.#e=new y.ReceiveLoop({authorityId:t.authorityId,store:t.store,authority:t.authority,schedule:t.schedule,channels:t.channels??[],onInboxCommitted:t.onInboxCommitted??(()=>{}),onError:r}),this.#t=new w.SendLine({store:t.store,cargo:t.cargo,authority:t.authority,schedule:t.schedule,onStamped:n(e=>this.#u(e),"onStamped"),onError:r});const i=t.onUnsent;this.#s=i?new f.UnsentCount({read:n(()=>t.store.countPending(),"read"),say:i,onError:r,schedule:t.schedule}):null}async start(){if(this.#r)throw new Error("entity record rail already started");if(this.#i)throw new Error("entity record rail is stopped");this.#r=!0,this.#s?.changed(),this.#e.start(),await this.#t.start()}get sendPaused(){return this.#t.paused}get sendHeld(){return this.#t.held}sendWaits(t){return this.#t.waits(t)}localRecordsAvailable(){this.#s?.changed(),this.#t.wake()}hold(t){this.#e.hold(t)}release(t){this.#e.release(t)}async flush(){if(!this.#r)throw new Error("entity record rail has not started");if(this.#i)throw new Error("entity record rail is stopped");await this.#e.coverReceipts(await this.#t.settle())}async receiveThrough(t){if(!this.#r)throw new Error("entity record rail has not started");await this.#e.receiveThrough(t)}async receiveCurrent(){if(!this.#r)throw new Error("entity record rail has not started");await this.#e.receiveCurrent()}async close(t,r){if(!Number.isFinite(t)||t<0)throw new Error("entity record close budget must be a non-negative number of milliseconds");const i=this.#t.stamped;if(this.#r&&!this.#i&&t>0){let s=n(()=>{},"expire");const h=new Promise(a=>{s=a}),c=this.#o.schedule(t,()=>s());try{const a=this.#t.settle();await Promise.race([a.catch(d=>{!this.#i&&d!==this.#t.paused&&this.#a(d)}),h])}finally{c.cancel()}}const e=this.stop();return await r(),await e,{accepted:this.#t.stamped-i,pending:await this.#h.countPending(),unconfirmed:await this.#h.countPending(this.#t.uncertainThrough)}}stop(){return this.#i??=Promise.all([this.#e.stop(),this.#t.stop(),this.#s?.stop()]).then(()=>{}),this.#i}#u(t){this.#s?.changed();const r=new Set;let i=!1;for(const{row:e,accepted:s}of t){for(const{entityId:h}of(0,l.channelRecords)(e.record))r.add(h),s.authorityId!==this.#n&&this.#e.ring({authorityId:s.authorityId,entityId:h});s.authorityId===this.#n&&(i=!0)}i&&this.#e.ring({authorityId:this.#n,entityId:null});try{this.#d([...r])}catch(e){this.#a(e)}}#a(t){try{this.#c(t)}catch{}}}exports.EntityRecordRail=m;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var l=Object.defineProperty;var o=(r,e)=>l(r,"name",{value:e,configurable:!0});Object.defineProperty(exports,"__esModule",{value:!0}),exports.AheadScan=void 0;const h=require("./contracts.js"),u=require("./send-batch.js"),d=require("./send-preparation.js"),f=require("./waits.js");class p{static{o(this,"AheadScan")}#t;#s;#e=[];#a=0;#n=null;#c=new Set;constructor(e){this.#t=e,this.#s=new f.Waits(e.readPlace)}get after(){return this.#a}get reach(){return this.#n}get ready(){return this.#e}get wanting(){return this.#e.length<d.ENTITY_RECORD_LOOKAHEAD_ROWS}behind(e){return this.#s.behind(e)}async judge(e){for(const t of e){if(!this.wanting)return;await this.#i(t),this.#a=t.localSequence}}stamped(e){const t=new Set(e.map(s=>s.localSequence));this.#e.splice(0,this.#e.length,...this.#e.filter(s=>!t.has(s.localSequence)))}async stepAside(e){const t=e.localSequence,s=this.#e.filter(a=>a.localSequence>t);this.#e.splice(0,this.#e.length,...this.#e.filter(a=>a.localSequence<t)),await this.#r(e);for(const a of s)await this.#i(a)}async#i(e){const{pause:t,waiting:s}=this.#t;if(t?.row.localSequence!==e.localSequence&&!s.has(e.localSequence)&&this.#o(e)){if(!await this.#h(e)){this.#e.push(e);return}t&&!t.reached&&this.#c.has(e.record.entityId)&&(this.#n??=e.localSequence)}await this.#r(e)}#o(e){const{pause:t}=this.#t;return t===null||e.record.authorityId===t.row.record.authorityId&&(0,u.freesStorage)(e)}async#h(e){for(const{entityId:t,change:s}of(0,h.channelRecords)(e.record))if(await this.#s.behind({entityId:t,facets:s.facets,result:s.result}))return!0;return!1}async#r(e){const t=this.#t.pause?.row.localSequence===e.localSequence;for(const{entityId:s,change:a}of(0,h.channelRecords)(e.record)){const n=[];if(a.replay.kind==="package")for(const c of a.replay.pages)for(const i of await this.#t.readPage(c))n.push(i);if(await this.#s.hold({entityId:s,facets:a.facets,result:a.result},n),t)for(const c of[s,...n.map(({uuid:i})=>i)])this.#c.add(c)}}}exports.AheadScan=p;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var T=Object.defineProperty;var a=(r,e)=>T(r,"name",{value:e,configurable:!0});Object.defineProperty(exports,"__esModule",{value:!0}),exports.EntityRecordRefusedError=exports.ENTITY_RECORD_OVER_STORAGE_LIMIT=exports.ENTITY_RECORD_CARGO_MISSING=exports.ENTITY_RECORD_BATCH_BYTES=exports.ENTITY_RECORD_BATCH_ROWS=void 0,exports.freesStorage=g,exports.selectBatch=O,exports.acceptedPrefix=w;const u=require("../faults/need.js"),f=require("../detection/refusal.js"),I=require("./contracts.js"),l=require("./outbox.js");exports.ENTITY_RECORD_BATCH_ROWS=256,exports.ENTITY_RECORD_BATCH_BYTES=16*1024*1024,exports.ENTITY_RECORD_CARGO_MISSING="entity_record_cargo_missing",exports.ENTITY_RECORD_OVER_STORAGE_LIMIT="files_over_storage_limit";const y=new Set(["trash","delete"]);function g(r){const{facets:e,cargo:t}=r.record.change;return t.length===0&&e.length>0&&e.every(n=>y.has(n))}a(g,"freesStorage");function O(r,e){const t=r[0];if(!t)return[];const n=[];let o=0;for(const d of r){if(d.record.authorityId!==t.record.authorityId||n.length===exports.ENTITY_RECORD_BATCH_ROWS)break;const c=e(d);if(!c||n.length>0&&o+c.bytes>exports.ENTITY_RECORD_BATCH_BYTES)break;n.push(c),o+=c.bytes}return n}a(O,"selectBatch");const S=new Set(["entity_record_read_forbidden","entity_record_write_forbidden",exports.ENTITY_RECORD_OVER_STORAGE_LIMIT]);class C extends Error{static{a(this,"EntityRecordRefusedError")}code;mutationId;need;constructor(e,t,n=null){super(`entity record ${e} was refused: ${t.code}: ${t.message}`),this.name="EntityRecordRefusedError",this.code=t.code,this.mutationId=e;const o=S.has(t.code);this.need=o?null:{law:"record-refused",trigger:(0,u.recoveryTrigger)(t.code),subject:n,lost:e},o&&(0,f.asRefusal)(this)}}exports.EntityRecordRefusedError=C;function w(r,e){const t=r[0],n=t?{id:t.record.authorityId,type:"authority"}:null,o=a(()=>(0,u.failure)("entity record batch answer does not match the offered batch","invariant-broken","answer-not-offered",n),"notOffered"),d=new Map,c=[];let h=0;for(;h<e.accepted.length;){const s=r[c.length];if(s===void 0)throw o();const R=(0,I.channelRecords)(s.record),_=e.accepted.slice(h,h+R.length);if(_.length!==R.length)throw o();(0,l.acceptOutboxRow)(s,_[0].record),_.forEach(({record:i},E)=>{if(E>0&&!(0,l.isOwnRecord)(s,i)||i.entityId!==R[E].entityId)throw o();if(i.globalSequence<=(d.get(i.entityId)??0))throw(0,u.failure)("entity record batch answer breaks this computer's acceptance order","invariant-broken","answer-out-of-order",n,s.record.mutationId);d.set(i.entityId,i.globalSequence)}),c.push(Object.freeze({row:s,accepted:_[0].record,deliverySequence:_.at(-1).deliverySequence})),h+=R.length}if(e.refusal===null!=(c.length===r.length))throw o();return c}a(w,"acceptedPrefix");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
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.#P():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]);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.#P();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.#D();this.#S=t,t.then(()=>{this.#S=null,this.#h&&this.#k()})}async#D(){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.#L();return this.#l=t,t.then(()=>{this.#l===t&&(this.#l=null)}),t}async#A(){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#L(){let t=[],e=0,s;const h=this.#m,c=this.#y;this.#y=0;const o=this.#u;try{const i=await this.#A();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.#j(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#j(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.#C()),this.#h=!0}#C(){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}#P(){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;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var E=Object.defineProperty;var d=(n,e)=>E(n,"name",{value:e,configurable:!0});Object.defineProperty(exports,"__esModule",{value:!0}),exports.SendPreparation=exports.ENTITY_RECORD_CARGO_READS=exports.ENTITY_RECORD_PREPARED_BYTES=exports.ENTITY_RECORD_LOOKAHEAD_ROWS=void 0;const p=require("../entities/bytes.js"),h=require("../faults/need.js"),R=require("./codec.js"),u=require("./contracts.js"),l=require("./send-batch.js"),f=require("./submit-frame.js"),_=d(n=>({id:n.record.entityId,type:n.record.change.result.type}),"subjectOf");exports.ENTITY_RECORD_LOOKAHEAD_ROWS=512,exports.ENTITY_RECORD_PREPARED_BYTES=l.ENTITY_RECORD_BATCH_BYTES,exports.ENTITY_RECORD_CARGO_READS=4;const m=Promise.resolve();class T{static{d(this,"SendPreparation")}#h;#u;#e=new Map;#t=[];#l=0;#o=0;#d=0;#r=!1;#i=new Set;constructor(e,t){this.#h=e,this.#u=t}retain(e,t){if(this.#r)return;this.#t=e,this.#l=t;const r=new Map(e.map(i=>[i.record.mutationId,i]));for(const[i,o]of this.#e){const s=r.get(i);(!s||o.carriesCargo!==this.#c(s))&&this.#s(i)}this.#n()}forget(e){if(e.length===0)return;const t=new Set(e.map(r=>r.record.mutationId));this.#t=this.#t.filter(r=>!t.has(r.record.mutationId));for(const r of t)this.#s(r);this.#n()}prepared(e){return this.#e.get(e.record.mutationId)?.ready??null}async head(e){if(e!==this.#t[0])throw new Error("only the lookahead head is awaited");this.#e.get(e.record.mutationId)?.failure&&this.#s(e.record.mutationId),this.#n();let t=this.#e.get(e.record.mutationId);for(;!t;){if(this.#r)throw new Error("entity record preparation stopped");if(this.#i.size===0)throw(0,h.failure)(`entity record ${e.record.mutationId} exceeds the prepared byte bound`,"invariant-broken","row-too-large",_(e),e.record.mutationId);await Promise.race(this.#i),t=this.#e.get(e.record.mutationId)}if(await t.settled,t.failure)throw t.failure.error;return t.ready}async settledThrough(e){for(;;){const t=[...this.#e.values()].filter(({row:r,ready:i,failure:o})=>r.localSequence<=e&&!i&&!o);if(t.length===0)return;await Promise.race(t.map(({settled:r})=>r))}}stop(){this.#r=!0,this.#t=[];for(const e of[...this.#e.keys()])this.#s(e);return Promise.allSettled([...this.#i]).then(()=>{})}#n(){if(!this.#r)for(const[e,t]of this.#t.entries()){if(this.#e.has(t.record.mutationId))continue;const r=this.#c(t)?(0,u.recordCargo)(t.record).length*f.INLINE_ARTIFACT_FRAME_BYTES:0;if(r>0&&this.#d>=exports.ENTITY_RECORD_CARGO_READS)return;const i=(0,R.encodeEntityRecord)(t.record),o=(0,p.utf8Length)(i),s=o+Math.min(r,Math.max(0,l.ENTITY_RECORD_BATCH_BYTES-o));if(e===0&&this.#f(s),this.#o+s>exports.ENTITY_RECORD_PREPARED_BYTES)return;this.#_(t,i,s)}}#f(e){for(let t=this.#t.length-1;t>0&&this.#o+e>exports.ENTITY_RECORD_PREPARED_BYTES;t-=1){const r=this.#t[t].record.mutationId;this.#e.get(r)?.ready&&this.#s(r)}}#c(e){return e.localSequence>this.#l&&(0,u.recordCargo)(e.record).length>0}#_(e,t,r){if(this.#o+=r,!this.#c(e)){const s=Object.freeze({recordJson:t,cargo:Object.freeze([])});this.#e.set(e.record.mutationId,{row:e,carriesCargo:!1,reserved:r,ready:Object.freeze({row:e,submission:s,bytes:r}),failure:null,settled:m,dropped:!1});return}this.#d+=1;let i;const o=Promise.resolve().then(()=>{if(this.#r)throw new Error("entity record preparation stopped");return this.#h.ensure(e.record)}).then(s=>{const c=Object.freeze({recordJson:t,cargo:Object.freeze([...s??[]])}),a=(0,f.submissionBytes)(c);if(a>r)throw(0,h.failure)(`cargo for ${e.record.mutationId} exceeds what one row may carry inline`,"invariant-broken","cargo-too-large",_(e),e.record.mutationId);i.ready=Object.freeze({row:e,submission:c,bytes:a}),this.#a(i,a)}).catch(s=>{i.failure={error:s},this.#a(i,0)}).finally(()=>{this.#d-=1,this.#i.delete(o),i.dropped&&this.#a(i,0),this.#n()}).catch(s=>this.#u(s));i={row:e,carriesCargo:!0,reserved:r,ready:null,failure:null,settled:o,dropped:!1},this.#i.add(o),this.#e.set(e.record.mutationId,i)}#s(e){const t=this.#e.get(e);t&&(this.#e.delete(e),t.dropped=!0,(t.ready||t.failure)&&this.#a(t,0))}#a(e,t){const r=e.dropped?0:t;this.#o+=r-e.reserved,e.reserved=r}}exports.SendPreparation=T;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var u=Object.defineProperty;var a=(n,t)=>u(n,"name",{value:t,configurable:!0});Object.defineProperty(exports,"__esModule",{value:!0}),exports.Waits=void 0;const l=new Set(["create","rename","move","restore"]),h=new Set(["move","restore","delete"]),o=a((n,t)=>n===null?null:`${n}\0${t}`,"slot");class p{static{a(this,"Waits")}#r;#e=new Map;#t=new Set;#i=new Set;#n=new Set;#a=new Set;#l=!1;#s=!1;constructor(t){this.#r=t}get empty(){return this.#t.size===0}async hold(t,i=[]){this.#t.add(t.entityId),this.#o(t.result.parentUUID,t.result.name,t.result.type),t.facets.includes("rename")&&t.result.parentUUID!==null&&this.#a.add(t.result.parentUUID),t.facets.includes("move")&&(this.#l=!0);for(const s of i)this.#t.add(s.uuid),this.#o(s.parentUUID,s.name,s.type);let e=t.result.type==="repo.git"?t.entityId:null;for(const s of await this.#u(t.result.parentUUID))this.#i.add(s),e===null&&(await this.#h(s))?.type==="repo.git"&&(e=s);e!==null&&(this.#t.add(e),this.#s=!0)}async behind(t){if(this.empty)return!1;const{entityId:i,facets:r,result:e}=t;if(this.#t.has(i)||r.some(s=>l.has(s))&&e.parentUUID!==null&&(this.#n.has(o(e.parentUUID,e.name))||this.#a.has(e.parentUUID))||this.#l&&r.some(s=>l.has(s)||s==="delete")||this.#s&&e.type==="repo.git"||this.#i.has(i)&&r.some(s=>h.has(s)))return!0;for(const s of await this.#u(e.parentUUID))if(this.#t.has(s))return!0;return!1}#o(t,i,r){const e=o(t,i);e!==null&&this.#n.add(e),r==="repo.git"&&(this.#s=!0)}async#u(t){const i=[];for(let r=t;r!==null&&!i.includes(r);){i.push(r);const e=await this.#h(r);if(!e)break;r=e.parentUUID}return i}async#h(t){return this.#e.has(t)||this.#e.set(t,await this.#r(t)),this.#e.get(t)}}exports.Waits=p;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amalgm/live",
|
|
3
|
-
"version": "0.2.81-preview.
|
|
3
|
+
"version": "0.2.81-preview.47301712017",
|
|
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-preview.46345295340"
|
|
135
135
|
},
|
|
136
|
-
"gitHead": "
|
|
136
|
+
"gitHead": "cf2b4a0cda52f6d04bbb2719b12d06b127095b41",
|
|
137
137
|
"amalgmSource": {
|
|
138
138
|
"repository": "amalgm-inc/amalgm-live",
|
|
139
139
|
"branch": "preview",
|
|
140
|
-
"commit": "
|
|
141
|
-
"occurrence": "
|
|
140
|
+
"commit": "cf2b4a0cda52f6d04bbb2719b12d06b127095b41",
|
|
141
|
+
"occurrence": "47301712017"
|
|
142
142
|
}
|
|
143
143
|
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { type GraphPageRef } from '../entities/graph-pages.js';
|
|
2
|
-
import type { EntityRecordStamp, MaybePromise, PendingEntityRecord } from './rail-ports.js';
|
|
3
|
-
import { type PreparedEntityRecord } from './send-batch.js';
|
|
4
|
-
export declare class FreeingScan {
|
|
5
|
-
#private;
|
|
6
|
-
constructor(reached: boolean, readPage: (ref: GraphPageRef) => MaybePromise<readonly unknown[]>);
|
|
7
|
-
get after(): number;
|
|
8
|
-
get reach(): number | null;
|
|
9
|
-
get wanting(): boolean;
|
|
10
|
-
judge(rows: readonly PendingEntityRecord[]): Promise<void>;
|
|
11
|
-
offer(): readonly PreparedEntityRecord[];
|
|
12
|
-
stamped(stamps: readonly EntityRecordStamp[]): void;
|
|
13
|
-
refused(): void;
|
|
14
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var d=Object.defineProperty;var o=(c,e)=>d(c,"name",{value:e,configurable:!0});import{pageHolding as f}from"../entities/graph-pages.js";import{encodeEntityRecord as u}from"./codec.js";import{ENTITY_RECORD_BATCH_BYTES as l,ENTITY_RECORD_BATCH_ROWS as g,freesStorage as p}from"./send-batch.js";import{submissionBytes as y}from"./submit-frame.js";class T{static{o(this,"FreeingScan")}#i;#t=null;#s=new Set;#e=[];#c=!1;#o=null;#a=0;#h=[];#d;#r=null;constructor(e,t){this.#i=e,this.#d=t}get after(){return this.#a}get reach(){return this.#o}get wanting(){return this.#e.length<g}async judge(e){for(const t of e){if(!this.wanting)return;if(this.#a=t.localSequence,this.#t??=t,t.record.authorityId===this.#t.record.authorityId&&p(t)){const{entityId:r}=t.record,s=this.#s.has(r)?r:await this.#f(t);if(s===null&&!(this.#c&&t.record.change.facets.includes("delete"))){this.#e.push(t);continue}!this.#i&&s===this.#t.record.entityId&&(this.#o??=t.localSequence)}this.#n(t,this.#s)}}async#f(e){const t=[e.record.change.result.parentUUID,e.record.entityId];for(const{anchor:r,pages:s}of this.#h){const n=f(s,t);if(n<0)continue;const i=s[n];if(this.#r?.sha256!==i.sha256){const a=await this.#d(i);this.#r={sha256:i.sha256,members:new Set(a.map(h=>h.uuid))}}if(this.#r.members.has(e.record.entityId))return r}return null}offer(){const e=[];let t=0;for(const r of this.#e){const s=Object.freeze({recordJson:u(r.record),cargo:Object.freeze([])}),n=y(s);if(e.length>0&&t+n>l)break;e.push(Object.freeze({row:r,submission:s,bytes:n})),t+=n}return e}stamped(e){this.#e.splice(0,e.length)}refused(){const[e,...t]=this.#e.splice(0),r=new Set;this.#n(e,r);for(const s of t)r.has(s.record.entityId)?this.#n(s,r):this.#e.push(s);for(const s of r)this.#s.add(s)}#n(e,t){e.record.change.facets.includes("move")&&(this.#c=!0);const{replay:r}=e.record.change;r.kind==="package"&&this.#h.push({anchor:e.record.entityId,pages:r.pages}),t.add(e.record.entityId);const s=e.record.change.result.parentUUID;s!==null&&t.add(s)}}export{T as FreeingScan};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var u=Object.defineProperty;var o=(a,e)=>u(a,"name",{value:e,configurable:!0});Object.defineProperty(exports,"__esModule",{value:!0}),exports.FreeingScan=void 0;const f=require("../entities/graph-pages.js"),l=require("./codec.js"),i=require("./send-batch.js"),g=require("./submit-frame.js");class p{static{o(this,"FreeingScan")}#c;#t=null;#s=new Set;#e=[];#i=!1;#a=null;#o=0;#h=[];#d;#r=null;constructor(e,t){this.#c=e,this.#d=t}get after(){return this.#o}get reach(){return this.#a}get wanting(){return this.#e.length<i.ENTITY_RECORD_BATCH_ROWS}async judge(e){for(const t of e){if(!this.wanting)return;if(this.#o=t.localSequence,this.#t??=t,t.record.authorityId===this.#t.record.authorityId&&(0,i.freesStorage)(t)){const{entityId:r}=t.record,s=this.#s.has(r)?r:await this.#u(t);if(s===null&&!(this.#i&&t.record.change.facets.includes("delete"))){this.#e.push(t);continue}!this.#c&&s===this.#t.record.entityId&&(this.#a??=t.localSequence)}this.#n(t,this.#s)}}async#u(e){const t=[e.record.change.result.parentUUID,e.record.entityId];for(const{anchor:r,pages:s}of this.#h){const n=(0,f.pageHolding)(s,t);if(n<0)continue;const c=s[n];if(this.#r?.sha256!==c.sha256){const h=await this.#d(c);this.#r={sha256:c.sha256,members:new Set(h.map(d=>d.uuid))}}if(this.#r.members.has(e.record.entityId))return r}return null}offer(){const e=[];let t=0;for(const r of this.#e){const s=Object.freeze({recordJson:(0,l.encodeEntityRecord)(r.record),cargo:Object.freeze([])}),n=(0,g.submissionBytes)(s);if(e.length>0&&t+n>i.ENTITY_RECORD_BATCH_BYTES)break;e.push(Object.freeze({row:r,submission:s,bytes:n})),t+=n}return e}stamped(e){this.#e.splice(0,e.length)}refused(){const[e,...t]=this.#e.splice(0),r=new Set;this.#n(e,r);for(const s of t)r.has(s.record.entityId)?this.#n(s,r):this.#e.push(s);for(const s of r)this.#s.add(s)}#n(e,t){e.record.change.facets.includes("move")&&(this.#i=!0);const{replay:r}=e.record.change;r.kind==="package"&&this.#h.push({anchor:e.record.entityId,pages:r.pages}),t.add(e.record.entityId);const s=e.record.change.result.parentUUID;s!==null&&t.add(s)}}exports.FreeingScan=p;
|