@amalgm/live 0.2.81-preview.47446204525 → 0.2.81-preview.47470355497

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.
@@ -21,5 +21,5 @@ export declare class EntityApplyJourney {
21
21
  constructor(options: EntityApplyRailOptions, wakeVersion: () => number, stopping: () => boolean);
22
22
  targetOf(window: ApplyWindow): number | null;
23
23
  run(window: ApplyWindow, emptying: () => string | null): Promise<HeadOutcome>;
24
- alone(head: WindowMember): Promise<HeadOutcome>;
24
+ alone(window: ApplyWindow, head?: WindowMember): Promise<HeadOutcome>;
25
25
  }
@@ -1 +1 @@
1
- var j=Object.defineProperty;var m=(l,e)=>j(l,"name",{value:e,configurable:!0});import{createApplyIntent as F,createApplyWindowIntent as O}from"./contracts.js";import{planSelectedEntityApply as P}from"./plans.js";import{Recovering as M}from"../faults/recover.js";import{groundMoved as S}from"../faults/classify.js";import{localWorkWins as W}from"../clash/local-work.js";import{selectEntityApply as E}from"./selection.js";import{isSettlement as q}from"./settling.js";import{revealOrder as D}from"./window.js";function H(l,e){return l.unit===null&&l.authorityId!==e}m(H,"stepsAside");const I={kind:"park",reason:"its window ended with its head unplaced and named no wait",releaseOnProgress:!1,report:!1,again:!0},U=m(l=>l.kind==="captured-local"||l.kind==="rejudge","drops");function A(l){return l.kind==="retry"?{kind:"park",reason:l.reason??"machine truth is unsettled",releaseOnProgress:!1,report:!1}:l.kind==="dependency"?{kind:"park",reason:l.reason,releaseOnProgress:l.waitFor===void 0,report:!1,...l.waitFor?{dependency:l.waitFor}:{},...l.blocker?{blocker:l.blocker}:{},..."comparedAt"in l?{comparedAt:l.comparedAt}:{}}:l.kind==="conflict"?{kind:"park",reason:l.reason,releaseOnProgress:!0,report:!0}:null}m(A,"parkFor");async function B(l){try{return await l()}catch(e){return{kind:"park",reason:e instanceof Error?e.message:String(e),releaseOnProgress:!1,report:!S(e),cause:e}}}m(B,"outcomeOf");const v=m(l=>q(l.judgment)?{kind:"settled",settlement:l.judgment}:null,"settled");class C{static{m(this,"EntityApplyJourney")}#e;#r;#a;#n;constructor(e,t,i){this.#e=e,this.#r={sha256Hex:e.sha256Hex,loops:e.loops,deliveryPosition:e.deliveryPosition},this.#a=t,this.#n=i}targetOf(e){const t=e.members[0];return t===void 0?null:e.intent?.members.find(i=>i.entityId===t.work.entityId)?.throughSequence??(t.work.kept===null?t.work.records.at(-1)?.globalSequence:t.work.resolvedThrough)??null}async run(e,t){if(e.intent!==null)return this.#p(e,e.intent);const i={member:null};try{return await this.#d(e,t,i)}catch(a){if(i.member===null||this.#n())throw a;if(S(a))return{kind:"park",reason:a instanceof Error?a.message:String(a),releaseOnProgress:!1,report:!1};if(H(e,i.member.work.entityId))return this.alone(i.member);if(a instanceof M)return{kind:"park",reason:a.message,releaseOnProgress:!1,report:!1,dependency:{producer:"capability",entityIds:a.need.subject===null?[]:[a.need.subject.id]}};throw a}}async alone(e){const{target:t}=E(e.work,this.#r),i=await this.#i({authorityId:e.work.authorityId,entityId:e.work.entityId,targetType:t.result.type,kept:t.record===null?t.result:null,throughSequence:t.throughSequence}),a=await this.#t(null,[e],[{kind:"settled",settlement:i?"superseded":"waiting"}]);return a==="progress"&&!i?{kind:"alone",entityId:e.work.entityId}:a}async#d(e,t,i){const a=this.#e.newIntentId(),n=this.#e.now(),o=t(),s=new Map;for(const c of e.members){if(v(c))continue;const{work:f}=c,w=E(f,this.#r),b=F({attemptId:a,work:f,target:w.target,unit:e.unit,cutoff:e.cutoff,createdAt:n,emptied:f.entityId===o&&f.play==="enter"&&(w.target.result.type==="file.text"||w.target.result.type==="file.binary")}),k=P(f,w,this.#e.sha256Hex);s.set(f.entityId,{member:c,intent:b,plan:k,adapter:this.#e.effects.adapterFor(k.target.type),look:"safe"})}const{active:d,blocked:h}=await this.#o(e.members,s,"look",i);if(d.length===0)return h??I;const g=d.flatMap(c=>s.get(c.work.entityId)??[]);if(g.length===0)return this.#t(null,d,d.map(c=>v(c)));const y=O({attemptId:a,authorityId:e.authorityId,unit:e.unit,cutoff:e.cutoff,createdAt:n,members:g.map(c=>c.intent)});try{const c=await this.#u(d,s,i),f=c.active.flatMap(r=>s.get(r.work.entityId)??[]);if(f.length===0)return await this.#e.effects.discard(y),c.active.length===0?c.blocked??I:this.#t(null,c.active,c.active.map(r=>v(r)));const w=f.length===g.length?y:O({...y,members:f.map(r=>r.intent)}),b=await this.#e.effects.hold(w,f.map(r=>r.plan));let k,x;try{k=await this.#o(c.active,s,"final",i),x=await this.#c(w,k,s,t)}finally{b()}return k.unseen!==null&&k.active.length===0?this.#h(k.unseen):x}catch(c){throw await this.#e.effects.discard(y),c}}async#c(e,{active:t,blocked:i},a,n){const o=t.flatMap(r=>a.get(r.work.entityId)??[]);if(o.length===0)return await this.#e.effects.discard(e),t.length===0?i??I:this.#t(null,t,t.map(r=>v(r)));const s=O({...e,members:o.map(r=>r.intent)}),d=o.filter(r=>r.look==="safe");if(d.length>0){if(this.#n()||o.some(p=>p.intent.emptied&&n()!==p.intent.entityId))return await this.#e.effects.discard(e),I;const r=await this.#e.store.bindWindow(s);if(r)return await this.#e.effects.discard(e),r.kind==="stale"?I:A({...r,comparedAt:this.#a()})}const h=new Map,g=new Map,y=m((r,p,u=null)=>{h.set(r,{kind:"owed",reason:p}),u!==null&&g.set(r,u)},"owe"),c=m(r=>A(r.kind==="dependency"?{...r,comparedAt:this.#a()}:r),"waitFrom"),{order:f,cycle:w}=D(d.map(r=>({entityId:r.intent.entityId,play:r.plan.play,type:r.plan.target.type,parentUUID:r.plan.target.parentUUID}))),b="its parent chain closes among the window's members";for(const r of w)y(r,b,{kind:"park",reason:b,releaseOnProgress:!1,report:!0});for(const r of f){const p=a.get(r),u=await p.adapter.apply.reveal(p.intent,p.plan);u&&y(r,u.reason,u.kind==="dependency"?c(u):null)}for(const r of o){const p=r.intent.entityId;if(h.has(p))continue;const u=await r.adapter.verify.verify(r.intent,r.plan);u.kind==="match"?h.set(p,{kind:"materialized"}):u.kind==="local-change"?y(p,"a person's version stands in its place"):u.kind==="rejudge"||u.kind==="missing-target"?y(p,u.kind):y(p,u.reason??u.kind,c(u))}const k=t.map(r=>v(r)??h.get(r.work.entityId));if(d.length>0)return this.#s(s,t,k,g);const x=await this.#s(null,t,k,g);return await this.#e.effects.discard(e),x}async#s(e,t,i,a){const n=await this.#t(e,t,i),o=i[0];return n!=="progress"||o.kind!=="owed"?n:{...a.get(t[0].work.entityId)??{kind:"park",reason:o.reason,releaseOnProgress:!1,report:!1,again:!0},advanced:t.filter((d,h)=>i[h].kind!=="owed").map(d=>d.work.entityId)}}async#o(e,t,i,a){const n=[];for(const o of e){const s=t.get(o.work.entityId);if(!s){n.push(o);continue}let d;try{d=await this.#i(s.intent)?{kind:"captured-local"}:i==="look"?await this.#f(s):await s.adapter.apply.guard(s.intent,s.plan,i)}catch(g){if(n.length>0&&!this.#n())return{active:n,blocked:null,unseen:null};throw a.member=o,g}if(d.kind==="local-change"||d.kind==="unsettled-ground")return{active:n,blocked:n.length===0?I:null,unseen:s};if(U(d))return{active:n,blocked:n.length===0?I:null,unseen:null};const h=A(d);if(h)return{active:n,blocked:h,unseen:null};s.look=d.kind,n.push(o)}return{active:n,blocked:null,unseen:null}}async#u(e,t,i){for(const[a,n]of e.entries()){const o=t.get(n.work.entityId);if(!(!o||o.look!=="safe"))try{const s=await o.adapter.apply.prepare(o.intent,o.plan);if(s)return{active:e.slice(0,a),blocked:A(s)}}catch(s){if(a>0&&!this.#n())return{active:e.slice(0,a),blocked:null};throw i.member=n,s}}return{active:[...e],blocked:null}}async#p(e,t){const i=t.members.map(n=>{const o=e.members.find(d=>d.work.entityId===n.entityId);if(!o)return null;const s=n.kept===null?o.work:{...o.work,records:[],kept:n.kept};return s.records.length===0&&s.kept===null?null:P(s,E(s,this.#r,n),this.#e.sha256Hex)}),a=await this.#e.effects.recover(t,i);if(a.length!==t.members.length)throw new Error("Apply recovery answered for a different window");return this.#t(t,e.members,e.members.map(n=>v(n)??a[t.members.findIndex(o=>o.entityId===n.work.entityId)]??{kind:"owed",reason:"not a member of the bound window"}))}async#t(e,t,i){const a=await this.#e.store.endWindow(e,t,i);if(!a)return"progress";if(a.kind!=="stale"||!a.reason)throw new Error("Apply end commit returned an unknown refusal");return I}async#i(e){return W(e.targetType,await this.#e.store.localWorkAfter(e.authorityId,e.entityId,e.kept??e.throughSequence))}async#f(e){const{intent:t,plan:i,adapter:a}=e,n=await a.apply.guard(t,i,"look");if(n.kind!=="local-change"&&n.kind!=="unsettled-ground")return n;const o=await this.#l(t,i);if(o.kind!=="observed")return o;const s=await a.apply.guard(t,i,"look");return s.kind==="local-change"||s.kind==="unsettled-ground"?{kind:"retry",reason:"Ground still needs observation after Detect; this member cannot reveal."}:s}async#h(e){const t=await this.#l(e.intent,e.plan);return t.kind==="captured-local"?I:A(t.kind==="observed"?{kind:"retry",reason:"Its final guard found ground Detect had not recorded; it is judged again after Detect looks."}:t)}async#l(e,t){if(await this.#i(e))return{kind:"captured-local"};let i,a=!0;const n=await this.#e.effects.captureLocal(e,t,()=>{if(!a||i!==void 0)throw new Error("Apply capture comparison must be marked exactly once");i=this.#a()}).finally(()=>{a=!1});if(!n||!["settled","local-only","retry"].includes(n.kind))throw new Error("Apply capture returned no explicit observation outcome");if(await this.#i(e))return{kind:"captured-local"};if(n.kind==="retry")return n;if(n.kind==="local-only"){if(i===void 0)throw new Error("local-only capture requires a synchronous comparison fence");if(!n.reason||n.entityIds.length===0||n.entityIds.some(o=>!o))throw new Error("local-only capture must name the retained ground and its releasing condition");return{kind:"dependency",reason:n.reason,comparedAt:i,waitFor:{producer:"detect",entityIds:n.entityIds}}}return{kind:"observed"}}}export{C as EntityApplyJourney,B as outcomeOf,H as stepsAside};
1
+ var j=Object.defineProperty;var w=(l,e)=>j(l,"name",{value:e,configurable:!0});import{createApplyIntent as F,createApplyWindowIntent as O}from"./contracts.js";import{planSelectedEntityApply as P}from"./plans.js";import{Recovering as M}from"../faults/recover.js";import{groundMoved as S}from"../faults/classify.js";import{localWorkWins as W}from"../clash/local-work.js";import{selectEntityApply as E}from"./selection.js";import{isSettlement as q}from"./settling.js";import{revealOrder as D}from"./window.js";function H(l,e){return l.unit===null&&l.authorityId!==e}w(H,"stepsAside");const I={kind:"park",reason:"its window ended with its head unplaced and named no wait",releaseOnProgress:!1,report:!1,again:!0},U=w(l=>l.kind==="captured-local"||l.kind==="rejudge","drops");function A(l){return l.kind==="retry"?{kind:"park",reason:l.reason??"machine truth is unsettled",releaseOnProgress:!1,report:!1}:l.kind==="dependency"?{kind:"park",reason:l.reason,releaseOnProgress:l.waitFor===void 0,report:!1,...l.waitFor?{dependency:l.waitFor}:{},...l.blocker?{blocker:l.blocker}:{},..."comparedAt"in l?{comparedAt:l.comparedAt}:{}}:l.kind==="conflict"?{kind:"park",reason:l.reason,releaseOnProgress:!0,report:!0}:null}w(A,"parkFor");async function B(l){try{return await l()}catch(e){return{kind:"park",reason:e instanceof Error?e.message:String(e),releaseOnProgress:!1,report:!S(e),cause:e}}}w(B,"outcomeOf");const v=w(l=>q(l.judgment)?{kind:"settled",settlement:l.judgment}:null,"settled");class C{static{w(this,"EntityApplyJourney")}#e;#r;#a;#n;constructor(e,t,a){this.#e=e,this.#r={sha256Hex:e.sha256Hex,loops:e.loops,deliveryPosition:e.deliveryPosition},this.#a=t,this.#n=a}targetOf(e){const t=e.members[0];return t===void 0?null:e.intent?.members.find(a=>a.entityId===t.work.entityId)?.throughSequence??(t.work.kept===null?t.work.records.at(-1)?.globalSequence:t.work.resolvedThrough)??null}async run(e,t){if(e.intent!==null)return this.#p(e,e.intent);const a={member:null};try{return await this.#d(e,t,a)}catch(i){if(a.member===null||this.#n())throw i;if(S(i))return{kind:"park",reason:i instanceof Error?i.message:String(i),releaseOnProgress:!1,report:!1};if(H(e,a.member.work.entityId))return this.alone(e,a.member);if(i instanceof M)return{kind:"park",reason:i.message,releaseOnProgress:!1,report:!1,dependency:{producer:"capability",entityIds:i.need.subject===null?[]:[i.need.subject.id]}};throw i}}async alone(e,t=e.members[0]){const{target:a}=E(t.work,this.#r),i=await this.#i({authorityId:t.work.authorityId,entityId:t.work.entityId,targetType:a.result.type,kept:a.record===null?a.result:null,throughSequence:a.throughSequence}),n=await this.#t(e.intent,[t],[{kind:"settled",settlement:i?"superseded":"waiting"}]);return n==="progress"&&!i?{kind:"alone",entityId:t.work.entityId}:n}async#d(e,t,a){const i=this.#e.newIntentId(),n=this.#e.now(),o=t(),s=new Map;for(const c of e.members){if(v(c))continue;const{work:f}=c,m=E(f,this.#r),b=F({attemptId:i,work:f,target:m.target,unit:e.unit,cutoff:e.cutoff,createdAt:n,emptied:f.entityId===o&&f.play==="enter"&&(m.target.result.type==="file.text"||m.target.result.type==="file.binary")}),k=P(f,m,this.#e.sha256Hex);s.set(f.entityId,{member:c,intent:b,plan:k,adapter:this.#e.effects.adapterFor(k.target.type),look:"safe"})}const{active:d,blocked:h}=await this.#o(e.members,s,"look",a);if(d.length===0)return h??I;const g=d.flatMap(c=>s.get(c.work.entityId)??[]);if(g.length===0)return this.#t(null,d,d.map(c=>v(c)));const y=O({attemptId:i,authorityId:e.authorityId,unit:e.unit,cutoff:e.cutoff,createdAt:n,members:g.map(c=>c.intent)});try{const c=await this.#u(d,s,a),f=c.active.flatMap(r=>s.get(r.work.entityId)??[]);if(f.length===0)return await this.#e.effects.discard(y),c.active.length===0?c.blocked??I:this.#t(null,c.active,c.active.map(r=>v(r)));const m=f.length===g.length?y:O({...y,members:f.map(r=>r.intent)}),b=await this.#e.effects.hold(m,f.map(r=>r.plan));let k,x;try{k=await this.#o(c.active,s,"final",a),x=await this.#c(m,k,s,t)}finally{b()}return k.unseen!==null&&k.active.length===0?this.#h(k.unseen):x}catch(c){throw await this.#e.effects.discard(y),c}}async#c(e,{active:t,blocked:a},i,n){const o=t.flatMap(r=>i.get(r.work.entityId)??[]);if(o.length===0)return await this.#e.effects.discard(e),t.length===0?a??I:this.#t(null,t,t.map(r=>v(r)));const s=O({...e,members:o.map(r=>r.intent)}),d=o.filter(r=>r.look==="safe");if(d.length>0){if(this.#n()||o.some(p=>p.intent.emptied&&n()!==p.intent.entityId))return await this.#e.effects.discard(e),I;const r=await this.#e.store.bindWindow(s);if(r)return await this.#e.effects.discard(e),r.kind==="stale"?I:A({...r,comparedAt:this.#a()})}const h=new Map,g=new Map,y=w((r,p,u=null)=>{h.set(r,{kind:"owed",reason:p}),u!==null&&g.set(r,u)},"owe"),c=w(r=>A(r.kind==="dependency"?{...r,comparedAt:this.#a()}:r),"waitFrom"),{order:f,cycle:m}=D(d.map(r=>({entityId:r.intent.entityId,play:r.plan.play,type:r.plan.target.type,parentUUID:r.plan.target.parentUUID}))),b="its parent chain closes among the window's members";for(const r of m)y(r,b,{kind:"park",reason:b,releaseOnProgress:!1,report:!0});for(const r of f){const p=i.get(r),u=await p.adapter.apply.reveal(p.intent,p.plan);u&&y(r,u.reason,u.kind==="dependency"?c(u):null)}for(const r of o){const p=r.intent.entityId;if(h.has(p))continue;const u=await r.adapter.verify.verify(r.intent,r.plan);u.kind==="match"?h.set(p,{kind:"materialized"}):u.kind==="local-change"?y(p,"a person's version stands in its place"):u.kind==="rejudge"||u.kind==="missing-target"?y(p,u.kind):y(p,u.reason??u.kind,c(u))}const k=t.map(r=>v(r)??h.get(r.work.entityId));if(d.length>0)return this.#s(s,t,k,g);const x=await this.#s(null,t,k,g);return await this.#e.effects.discard(e),x}async#s(e,t,a,i){const n=await this.#t(e,t,a),o=a[0];return n!=="progress"||o.kind!=="owed"?n:{...i.get(t[0].work.entityId)??{kind:"park",reason:o.reason,releaseOnProgress:!1,report:!1,again:!0},advanced:t.filter((d,h)=>a[h].kind!=="owed").map(d=>d.work.entityId)}}async#o(e,t,a,i){const n=[];for(const o of e){const s=t.get(o.work.entityId);if(!s){n.push(o);continue}let d;try{d=await this.#i(s.intent)?{kind:"captured-local"}:a==="look"?await this.#f(s):await s.adapter.apply.guard(s.intent,s.plan,a)}catch(g){if(n.length>0&&!this.#n())return{active:n,blocked:null,unseen:null};throw i.member=o,g}if(d.kind==="local-change"||d.kind==="unsettled-ground")return{active:n,blocked:n.length===0?I:null,unseen:s};if(U(d))return{active:n,blocked:n.length===0?I:null,unseen:null};const h=A(d);if(h)return{active:n,blocked:h,unseen:null};s.look=d.kind,n.push(o)}return{active:n,blocked:null,unseen:null}}async#u(e,t,a){for(const[i,n]of e.entries()){const o=t.get(n.work.entityId);if(!(!o||o.look!=="safe"))try{const s=await o.adapter.apply.prepare(o.intent,o.plan);if(s)return{active:e.slice(0,i),blocked:A(s)}}catch(s){if(i>0&&!this.#n())return{active:e.slice(0,i),blocked:null};throw a.member=n,s}}return{active:[...e],blocked:null}}async#p(e,t){const a=t.members.map(n=>{const o=e.members.find(d=>d.work.entityId===n.entityId);if(!o)return null;const s=n.kept===null?o.work:{...o.work,records:[],kept:n.kept};return s.records.length===0&&s.kept===null?null:P(s,E(s,this.#r,n),this.#e.sha256Hex)}),i=await this.#e.effects.recover(t,a);if(i.length!==t.members.length)throw new Error("Apply recovery answered for a different window");return this.#t(t,e.members,e.members.map(n=>v(n)??i[t.members.findIndex(o=>o.entityId===n.work.entityId)]??{kind:"owed",reason:"not a member of the bound window"}))}async#t(e,t,a){const i=await this.#e.store.endWindow(e,t,a);if(!i)return"progress";if(i.kind!=="stale"||!i.reason)throw new Error("Apply end commit returned an unknown refusal");return I}async#i(e){return W(e.targetType,await this.#e.store.localWorkAfter(e.authorityId,e.entityId,e.kept??e.throughSequence))}async#f(e){const{intent:t,plan:a,adapter:i}=e,n=await i.apply.guard(t,a,"look");if(n.kind!=="local-change"&&n.kind!=="unsettled-ground")return n;const o=await this.#l(t,a);if(o.kind!=="observed")return o;const s=await i.apply.guard(t,a,"look");return s.kind==="local-change"||s.kind==="unsettled-ground"?{kind:"retry",reason:"Ground still needs observation after Detect; this member cannot reveal."}:s}async#h(e){const t=await this.#l(e.intent,e.plan);return t.kind==="captured-local"?I:A(t.kind==="observed"?{kind:"retry",reason:"Its final guard found ground Detect had not recorded; it is judged again after Detect looks."}:t)}async#l(e,t){if(await this.#i(e))return{kind:"captured-local"};let a,i=!0;const n=await this.#e.effects.captureLocal(e,t,()=>{if(!i||a!==void 0)throw new Error("Apply capture comparison must be marked exactly once");a=this.#a()}).finally(()=>{i=!1});if(!n||!["settled","local-only","retry"].includes(n.kind))throw new Error("Apply capture returned no explicit observation outcome");if(await this.#i(e))return{kind:"captured-local"};if(n.kind==="retry")return n;if(n.kind==="local-only"){if(a===void 0)throw new Error("local-only capture requires a synchronous comparison fence");if(!n.reason||n.entityIds.length===0||n.entityIds.some(o=>!o))throw new Error("local-only capture must name the retained ground and its releasing condition");return{kind:"dependency",reason:n.reason,comparedAt:a,waitFor:{producer:"detect",entityIds:n.entityIds}}}return{kind:"observed"}}}export{C as EntityApplyJourney,B as outcomeOf,H as stepsAside};
@@ -1 +1 @@
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,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};
1
+ var a=Object.defineProperty;var r=(e,n)=>a(e,"name",{value:n,configurable:!0});import{UUID_PATTERN as f}from"../entities/types.js";function w(e){return{kind:"line",authorityId:e,held:null,queued:!1,running:!1,again:!1}}r(w,"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(l=>o.includes(l))?!1:(i.due=!0,!0)}r(k,"releaseApplyLine");function g(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(g,"heldWait");const d=new Set(["detect","apply","capability","send"]),c=r(e=>!!e&&d.has(e.producer)&&Array.isArray(e.entityIds)&&e.entityIds.length>0&&e.entityIds.every(n=>typeof n=="string"&&n.length>0),"namesRelease");function A(e){if(!c(e))throw new Error("Apply dependency must name the entities that can release it")}r(A,"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}`),y(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 y(e,n){Array.isArray(e.members)||u(n);const o=r((t,s)=>Number.isSafeInteger(t)&&t>=(s?0:1),"at");for(const t of e.members)(!f.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")&&(f.test(t.unseen??"")||u(n));const{deliverySequence:i}=e,l=e.members[0];(i===null?!e.intent:l===void 0||!o(i,l.work.kept!==null))&&u(n)}r(y,"assertApplyWindow");export{A as assertApplyDependency,b as assertApplyLineStep,y as assertApplyWindow,w as createApplyLine,g as heldWait,u as invalidStep,k as releaseApplyLine};
@@ -1 +1 @@
1
- var I=Object.defineProperty;var a=(o,t)=>I(o,"name",{value:t,configurable:!0});import{UUID_PATTERN as u}from"../entities/types.js";import{FetchAhead as k}from"./fetch-ahead.js";import{EntityApplyJourney as b,outcomeOf as w,stepsAside as E}from"./journey.js";import{assertApplyLaneStep as P,createApplyLane as v}from"./lane.js";import{assertApplyDependency as O,assertApplyLineStep as $,createApplyLine as S,heldWait as c,releaseApplyLine as q}from"./line.js";const M=8,x=1e3,g=3e4;function _(o,t){return t.cause===void 0&&E(o,o.members[0].work.entityId)}a(_,"stuck");class j{static{a(this,"EntityApplyRail")}#t;#g;#P;#x;#_;#o;#v;#a=!1;#e=!1;#d=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;#O=new Map;#y=null;constructor(t){this.#t=t,this.#g=t.concurrency??M,this.#P=t.laneConcurrency??this.#g,this.#x=t.onBackgroundError??(()=>{}),this.#_=t.onIdle??(()=>{});for(const[e,s]of[["concurrency",this.#g],["lane concurrency",this.#P]])if(!Number.isSafeInteger(s)||s<1)throw new Error(`entity Apply ${e} must be a positive integer`);this.#o=new b(t,()=>this.#A,()=>this.#e),this.#v=new k(t.cargo,{sha256Hex:t.sha256Hex,loops:t.loops,deliveryPosition:t.deliveryPosition})}async start(){if(this.#a)throw new Error("entity Apply rail already started");if(this.#e)throw new Error("entity Apply rail is stopped");this.#a=!0;const t=await this.#t.store.readOpenUnits();if(!Array.isArray(t)||new Set(t).size!==t.length||t.some(e=>!u.test(e)))throw new Error("entity Apply store returned an invalid open unit list");for(const e of t)this.#b(e,null);await this.#R()}fetch(t,e){return this.#a?this.#e?Promise.reject(new Error("entity Apply rail is stopped")):u.test(t)?!Number.isFinite(e.stall)||e.stall<0?Promise.reject(new Error("entity Apply fetch needs a non-negative stall")):e.emptied!==void 0&&typeof e.emptied!="boolean"?Promise.reject(new Error("entity Apply fetch emptied must be a boolean")):new Promise((s,i)=>{const r=this.#b(t,null,e.emptied===!0),n=a(()=>this.#t.schedule.schedule(e.stall,()=>{r.waiters.delete(l)&&(r.emptied&&![...r.waiters].some(d=>d.emptied)&&(r.emptied=!1),s(this.#G(r)))}),"arm");let h=n();const l={emptied:e.emptied===!0,answer:a(d=>{h.cancel(),s(d)},"answer"),fail:a(d=>{h.cancel(),i(d)},"fail"),moved:a(()=>{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(t,e){if(!u.test(t))throw new Error("entity Apply progress needs a unit UUID");if(!Number.isSafeInteger(e)||e<0)throw new Error("entity Apply progress needs a byte count");e>0&&!this.#e&&this.#E(t)}recordsAvailable(){this.#I()}localStateChanged(t){this.#c("detect",t),this.#c("apply",t),this.#I()}sendAccepted(t){this.#c("send",t),this.#I()}capabilityChanged(t){this.#c("capability",t),this.#I()}owe(t){if(t.some(e=>!u.test(e)))throw new Error("entity Apply owe needs entity UUIDs");if(!(!this.#a||this.#e)){for(const e of t)this.#$(e);this.#r()}}#I(){!this.#a||this.#e||(this.#n=!0,this.#r())}waiting(){return this.#w().flatMap(t=>c(t.held,p(t))??[])}async flush(){if(!this.#a)throw new Error("entity Apply rail has not started");this.#e||await this.#R()}async stop(){if(this.#e)return;this.#e=!0,this.#M();for(const e of[this.#l,this.#u])for(const s of e.queue.splice(0))s.queued=!1;const t=new Error("entity Apply rail stopped before the fetch answered");for(const e of this.#s.values())for(const s of e.waiters)s.fail(t);for(this.#s.clear();this.#B()>0||this.#h;)await Promise.allSettled([...this.#l.steps,...this.#u.steps,...this.#h?[this.#h]:[]]);await this.#v.stop();for(const e of this.#m.splice(0))e.resolve()}#R(){return new Promise((t,e)=>{this.#m.push({resolve:t,reject:e}),this.#n=!0,this.#r()})}#r(){if(!this.#e){if(this.#n&&this.#h===null){this.#n=!1;const t=this.#F();this.#h=t,t.then(()=>{this.#h=null,this.#r()})}for(const[t,e]of[[this.#u,this.#P],[this.#l,this.#g]])for(;t.steps.size<e&&t.queue.length>0;){const s=t.queue.shift();s.queued=!1,this.#W(s,t)}if(this.#B()===0&&this.#h===null&&!this.#n&&this.#l.queue.length===0&&this.#u.queue.length===0){if(this.#O.clear(),this.#D(this.#t.now())){this.#r();return}this.#q();for(const t of this.#m.splice(0))t.resolve();this.#_()}}}#B(){return this.#l.steps.size+this.#u.steps.size}#w(){return[...this.#d.values(),...this.#s.values()]}#k(t){return t.kind==="line"?this.#d.get(t.authorityId)===t:this.#s.get(t.unit)===t}#i(t){if(!this.#e){if(t.running){t.again=!0;return}t.queued||(t.queued=!0,(t.kind==="line"?this.#l:this.#u).queue.push(t))}}#W(t,e){t.running=!0,t.again=!1;const s=(t.kind==="line"?this.#J(t):this.#H(t)).then(i=>{t.running=!1,e.steps.delete(s),(i||t.again)&&this.#k(t)&&(t.again=!1,this.#i(t)),this.#r()});e.steps.add(s)}async#F(){try{const t=await this.#t.store.readApplyAuthorities();if(!Array.isArray(t)||new Set(t).size!==t.length||t.some(s=>typeof s!="string"||s.length===0))throw new Error("entity Apply store returned an invalid authority list");this.#p=1/0;const e=new Set(t);for(const[s,i]of this.#d)!e.has(s)&&!i.running&&!i.queued&&this.#d.delete(s);for(const s of t){let i=this.#d.get(s);i||(i=S(s),this.#d.set(s,i)),this.#i(i)}}catch(t){this.#p=this.#t.now()+g;const e=this.#m.splice(0);e.length===0&&this.#S(t);for(const s of e)s.reject(t)}}async#J(t){try{const e=t.held;if(e&&e.entityId===null&&!e.due&&e.notBefore>this.#t.now())return!1;const s=this.#A,i=await this.#t.store.readApplyWindow(t.authorityId);return $(t.authorityId,i),this.#e?!1:i.kind==="end"?(t.held=null,!1):(i.window.deliverySequence!==null&&this.#v.advance(t.authorityId,i.window.deliverySequence),await this.#U(t,i.window,s))}catch(e){return this.#Y(t,e),!1}}async#H(t){try{const e=t.held;if(e&&e.entityId===null&&!e.due&&e.notBefore>this.#t.now())return!1;const s=this.#A,i=await this.#t.store.readFetchWindow(t.unit,t.toPrefix?null:t.through);if(P(t.unit,i),this.#e||!this.#k(t))return!1;if(t.waitsOn=null,i.kind==="unseen")return this.#L(t,{producer:"detect",entityIds:[t.unit]},i.reason,s);if(!t.again&&(i.kind!=="window"||i.window.intent===null)&&(t.toPrefix=!1),t.through!==null&&i.through>t.through&&t.met.clear(),t.through=Math.max(t.through??0,i.through),i.kind!=="window"&&(t.held=null),t.again&&(i.kind==="end"||i.kind==="nowhere"))return!0;switch(i.kind){case"end":return this.#f(t,{kind:"placed"}),!1;case"nowhere":return this.#f(t,{kind:"nowhere",reason:i.reason}),!1;case"root":return await this.#V(t,i.through,i.reason);case"prerequisite":return this.#X(t,i.unit,i.reason,s);case"window":return await this.#U(t,i.window,s)}}catch(e){return this.#Y(t,e),!1}}async#V(t,e,s){return t.met.has(t.unit)?(this.#f(t,{kind:"held",unit:t.unit,reason:`${t.unit} entered and still not held: ${s}`}),!1):(await this.#t.effects.enterRoot(t.unit,e),this.#e||!this.#k(t)?!1:(t.through===e&&t.met.add(t.unit),this.#E(t.unit),!0))}#$(t){const e=this.#b(t,null);e.toPrefix=!0,e.met.clear(),this.#i(e)}#b(t,e,s=!1){let i=this.#s.get(t);return i?e!==null&&(i.through===null||i.through<e)&&(i.through=e,i.met.clear(),this.#i(i)):(i=v(t,e,s),this.#s.set(t,i),this.#i(i)),i}#X(t,e,s,i){return t.met.has(e)?(this.#f(t,{kind:"held",unit:e,reason:`${e} placed and still needed: ${s}`}),!1):this.#T(t,e,s)?this.#L(t,{producer:"apply",entityIds:[e]},s,i):!1}#L(t,e,s,i){return t.held={entityId:null,target:null,kept:null,cutoff:null,attempt:1,notBefore:1/0,releaseOnProgress:!1,due:this.#z(e,i),reason:s,dependency:e},t.held.due}#N(t){const e=t.held;if(e?.dependency?.producer==="apply"){for(const s of e.dependency.entityIds)if(s!==t.unit&&!t.met.has(s)&&!this.#T(t,s,e.reason))return}}#T(t,e,s){const i=[t];let r=this.#s.get(e);for(;r&&r!==t&&!i.includes(r);)i.push(r),r=r.waitsOn===null?void 0:this.#s.get(r.waitsOn);if(r===t){for(const n of i)this.#f(n,{kind:"held",unit:e,reason:`prerequisite cycle through ${e}: ${s}`});return!1}return t.waitsOn??=e,this.#i(this.#b(e,t.through)),!0}#f(t,e){if(!this.#k(t))return;for(const i of t.waiters)i.answer(e);t.waiters.clear(),t.waitsOn=null,(e.kind==="placed"||t.held?.entityId==null)&&this.#s.delete(t.unit);const s=e.kind==="placed"||e.kind==="held"?e:{kind:"held",unit:t.unit,reason:`${t.unit} is nowhere here: ${e.reason}`};for(const i of[...this.#s.values()])if(i.waitsOn===t.unit){if(e.kind!=="placed"){this.#f(i,s);continue}i.met.add(t.unit)}e.kind==="placed"&&(this.#E(t.unit),this.#c("apply",[t.unit]))}#E(t){const e=new Map([[t,!0]]);for(const s of this.#s.values()){const i=new Set;let r=s.unit;for(;r!==null&&!e.has(r)&&!i.has(r);)i.add(r),r=this.#s.get(r)?.waitsOn??null;const n=r!==null&&e.get(r)===!0;for(const h of i)e.set(h,n);if(n)for(const h of s.waiters)h.moved()}}#G(t){let e=t;const s=new Set([t]);for(let i=t.waitsOn===null?void 0:this.#s.get(t.waitsOn);i&&!s.has(i);i=i.waitsOn===null?void 0:this.#s.get(i.waitsOn))s.add(i),e=i;return{kind:"held",unit:e.unit,reason:e.held?.reason??"still placing"}}async#U(t,e,s){const i=e.members[0]?.work.entityId??null;if(t.held&&t.held.entityId!==null&&t.held.entityId!==i&&(t.held=null),await this.#Q(t,e))return!1;let r=await w(()=>this.#o.run(e,()=>t.kind==="lane"&&t.emptied?t.unit:null));if(t.kind==="line"&&!this.#e&&typeof r=="object"&&r.kind==="park"&&_(e,r)&&(r=await w(()=>this.#o.alone(e.members[0]))),r==="progress"||typeof r=="object"&&r.kind==="alone"){if(t.kind==="line")for(const n of e.members)(n.judgment==="waiting"||r!=="progress"&&n.work.entityId===r.entityId)&&this.#$(n.work.entityId);for(const n of e.members)n.unseen!==void 0&&this.#$(n.unseen);return this.#Z(t,r==="progress"?e.members.map(n=>n.work.entityId):[r.entityId])}return r.advanced?.length&&this.#j(t,r.advanced),this.#tt(t,e,r,s),t.kind==="lane"&&this.#N(t),t.held.due}#K(t,e){const s=t.held,i=e.members[0].work.entityId;return(s?.entityId===i&&s.target===this.#o.targetOf(e)?s.attempt:0)+1}async#Q(t,e){const s=t.held,i=e.members[0];return!s||i===void 0||s.entityId!==i.work.entityId||s.due||s.notBefore<=this.#t.now()||this.#o.targetOf(e)!==s.target||e.cutoff!==s.cutoff?!1:await this.#t.store.localWorkAfter(e.authorityId,i.work.entityId,s.kept??s.target)===null}#Z(t,e){return t.held&&(t.held.entityId===null||e.includes(t.held.entityId))&&(t.held=null),this.#j(t,e),!0}#j(t,e){t.kind==="lane"&&(this.#n=!0,this.#E(t.unit)),this.#c("apply",e);for(const s of this.#w())s!==t&&s.held?.releaseOnProgress&&!s.held.due&&(s.held.due=!0,this.#i(s))}#tt(t,e,s,i){if(s.dependency&&O(s.dependency),s.blocker&&!s.dependency)throw new Error("Apply blocker must name the dependency that releases it");const r=e.members[0].work.entityId,n=t.held,h=this.#K(t,e),l=this.#C(h),d=s.again===!0&&h===1,y={entityId:r,target:this.#o.targetOf(e),kept:e.members[0].work.kept,cutoff:e.cutoff,attempt:h,notBefore:s.dependency?1/0:this.#t.now()+(d?0:l),releaseOnProgress:s.releaseOnProgress,due:s.dependency?this.#z(s.dependency,s.comparedAt??i):d,reason:s.reason,...s.dependency?{dependency:s.dependency}:{},...s.blocker?{blocker:s.blocker}:{}};t.held=y,this.#q();const A=c(n,p(t)),f=c(y,p(t));f&&JSON.stringify(f)!==JSON.stringify(A)&&this.#t.onWaiting?.(f),!(!s.report&&(s.dependency!==void 0||h===1))&&this.#S(new Error(`${m(t)} 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}))}#Y(t,e){if(t.kind==="lane"){for(const h of t.waiters)h.fail(e);t.waiters.clear()}const s=t.held,i=(s?.entityId===null?s.attempt:0)+1,r=this.#C(i),n=e instanceof Error?e.message:String(e);t.held={entityId:null,target:null,kept:null,cutoff:null,attempt:i,notBefore:this.#t.now()+r,releaseOnProgress:!1,due:!1,reason:n},this.#q(),this.#S(new Error(`${m(t)} faulted and will retry in ${r}ms (attempt ${i}): ${n}`,{cause:e}))}#S(t){try{this.#x(t)}catch{}}#C(t){const e=Math.min(g,x*2**Math.min(t-1,16)),s=Math.max(0,Math.min(1,this.#t.schedule.random()));return Math.round(e*(.5+s))}#c(t,e){const s=++this.#A;for(const i of e??["*"])this.#O.set(`${t}:${i}`,s);for(const i of this.#w())q(i,t,e)&&this.#i(i)}#z(t,e){return["*",...t.entityIds].some(s=>(this.#O.get(`${t.producer}:${s}`)??0)>e)}#q(){if(this.#e)return;let t=this.#p;for(const i of this.#w())i.held&&!i.held.due&&(t=Math.min(t,i.held.notBefore));if(t===1/0){this.#M();return}if(this.#y?.dueAt===t)return;this.#M();const e=Math.max(0,t-this.#t.now()),s=this.#t.schedule.schedule(e,()=>{this.#y=null,this.#D(t),this.#r()});this.#y={dueAt:t,cancel:a(()=>s.cancel(),"cancel")}}#D(t){let e=!1;for(const s of this.#w())s.held&&!s.held.due&&s.held.notBefore<=t&&(s.held.due=!0,this.#i(s),e=!0);return this.#p<=t&&(this.#p=1/0,this.#n=!0,e=!0),e}#M(){this.#y?.cancel(),this.#y=null}}const p=a(o=>o.kind==="line"?o.authorityId:o.unit,"owner"),m=a(o=>o.kind==="line"?`entity Apply line ${o.authorityId}`:`entity Apply fetch of ${o.unit}`,"label");export{M as ENTITY_APPLY_DEFAULT_CONCURRENCY,x as ENTITY_APPLY_RETRY_BASE_MS,g as ENTITY_APPLY_RETRY_MAX_MS,j as EntityApplyRail};
1
+ var I=Object.defineProperty;var a=(o,t)=>I(o,"name",{value:t,configurable:!0});import{UUID_PATTERN as u}from"../entities/types.js";import{FetchAhead as k}from"./fetch-ahead.js";import{EntityApplyJourney as b,outcomeOf as w,stepsAside as E}from"./journey.js";import{assertApplyLaneStep as P,createApplyLane as v}from"./lane.js";import{assertApplyDependency as O,assertApplyLineStep as $,createApplyLine as S,heldWait as p,releaseApplyLine as q}from"./line.js";const M=8,x=1e3,g=3e4;function _(o,t){const e=o.members[0];return t.cause===void 0&&e!==void 0&&E(o,e.work.entityId)}a(_,"stuck");class j{static{a(this,"EntityApplyRail")}#t;#g;#P;#x;#_;#o;#v;#a=!1;#e=!1;#d=new Map;#i=new Map;#l={queue:[],steps:new Set};#u={queue:[],steps:new Set};#r=!1;#h=null;#p=1/0;#m=[];#A=0;#O=new Map;#y=null;constructor(t){this.#t=t,this.#g=t.concurrency??M,this.#P=t.laneConcurrency??this.#g,this.#x=t.onBackgroundError??(()=>{}),this.#_=t.onIdle??(()=>{});for(const[e,i]of[["concurrency",this.#g],["lane concurrency",this.#P]])if(!Number.isSafeInteger(i)||i<1)throw new Error(`entity Apply ${e} must be a positive integer`);this.#o=new b(t,()=>this.#A,()=>this.#e),this.#v=new k(t.cargo,{sha256Hex:t.sha256Hex,loops:t.loops,deliveryPosition:t.deliveryPosition})}async start(){if(this.#a)throw new Error("entity Apply rail already started");if(this.#e)throw new Error("entity Apply rail is stopped");this.#a=!0;const t=await this.#t.store.readOpenUnits();if(!Array.isArray(t)||new Set(t).size!==t.length||t.some(e=>!u.test(e)))throw new Error("entity Apply store returned an invalid open unit list");for(const e of t)this.#b(e,null);await this.#R()}fetch(t,e){return this.#a?this.#e?Promise.reject(new Error("entity Apply rail is stopped")):u.test(t)?!Number.isFinite(e.stall)||e.stall<0?Promise.reject(new Error("entity Apply fetch needs a non-negative stall")):e.emptied!==void 0&&typeof e.emptied!="boolean"?Promise.reject(new Error("entity Apply fetch emptied must be a boolean")):new Promise((i,s)=>{const n=this.#b(t,null,e.emptied===!0),r=a(()=>this.#t.schedule.schedule(e.stall,()=>{n.waiters.delete(l)&&(n.emptied&&![...n.waiters].some(d=>d.emptied)&&(n.emptied=!1),i(this.#G(n)))}),"arm");let h=r();const l={emptied:e.emptied===!0,answer:a(d=>{h.cancel(),i(d)},"answer"),fail:a(d=>{h.cancel(),s(d)},"fail"),moved:a(()=>{h.cancel(),h=r()},"moved")};n.waiters.add(l),n.waitsOn===null&&this.#N(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(t,e){if(!u.test(t))throw new Error("entity Apply progress needs a unit UUID");if(!Number.isSafeInteger(e)||e<0)throw new Error("entity Apply progress needs a byte count");e>0&&!this.#e&&this.#E(t)}recordsAvailable(){this.#I()}localStateChanged(t){this.#c("detect",t),this.#c("apply",t),this.#I()}sendAccepted(t){this.#c("send",t),this.#I()}capabilityChanged(t){this.#c("capability",t),this.#I()}owe(t){if(t.some(e=>!u.test(e)))throw new Error("entity Apply owe needs entity UUIDs");if(!(!this.#a||this.#e)){for(const e of t)this.#$(e);this.#n()}}#I(){!this.#a||this.#e||(this.#r=!0,this.#n())}waiting(){return this.#w().flatMap(t=>p(t.held,y(t))??[])}async flush(){if(!this.#a)throw new Error("entity Apply rail has not started");this.#e||await this.#R()}async stop(){if(this.#e)return;this.#e=!0,this.#M();for(const e of[this.#l,this.#u])for(const i of e.queue.splice(0))i.queued=!1;const t=new Error("entity Apply rail stopped before the fetch answered");for(const e of this.#i.values())for(const i of e.waiters)i.fail(t);for(this.#i.clear();this.#B()>0||this.#h;)await Promise.allSettled([...this.#l.steps,...this.#u.steps,...this.#h?[this.#h]:[]]);await this.#v.stop();for(const e of this.#m.splice(0))e.resolve()}#R(){return new Promise((t,e)=>{this.#m.push({resolve:t,reject:e}),this.#r=!0,this.#n()})}#n(){if(!this.#e){if(this.#r&&this.#h===null){this.#r=!1;const t=this.#F();this.#h=t,t.then(()=>{this.#h=null,this.#n()})}for(const[t,e]of[[this.#u,this.#P],[this.#l,this.#g]])for(;t.steps.size<e&&t.queue.length>0;){const i=t.queue.shift();i.queued=!1,this.#W(i,t)}if(this.#B()===0&&this.#h===null&&!this.#r&&this.#l.queue.length===0&&this.#u.queue.length===0){if(this.#O.clear(),this.#D(this.#t.now())){this.#n();return}this.#q();for(const t of this.#m.splice(0))t.resolve();this.#_()}}}#B(){return this.#l.steps.size+this.#u.steps.size}#w(){return[...this.#d.values(),...this.#i.values()]}#k(t){return t.kind==="line"?this.#d.get(t.authorityId)===t:this.#i.get(t.unit)===t}#s(t){if(!this.#e){if(t.running){t.again=!0;return}t.queued||(t.queued=!0,(t.kind==="line"?this.#l:this.#u).queue.push(t))}}#W(t,e){t.running=!0,t.again=!1;const i=(t.kind==="line"?this.#J(t):this.#H(t)).then(s=>{t.running=!1,e.steps.delete(i),(s||t.again)&&this.#k(t)&&(t.again=!1,this.#s(t)),this.#n()});e.steps.add(i)}async#F(){try{const t=await this.#t.store.readApplyAuthorities();if(!Array.isArray(t)||new Set(t).size!==t.length||t.some(i=>typeof i!="string"||i.length===0))throw new Error("entity Apply store returned an invalid authority list");this.#p=1/0;const e=new Set(t);for(const[i,s]of this.#d)!e.has(i)&&!s.running&&!s.queued&&this.#d.delete(i);for(const i of t){let s=this.#d.get(i);s||(s=S(i),this.#d.set(i,s)),this.#s(s)}}catch(t){this.#p=this.#t.now()+g;const e=this.#m.splice(0);e.length===0&&this.#S(t);for(const i of e)i.reject(t)}}async#J(t){try{const e=t.held;if(e&&e.entityId===null&&!e.due&&e.notBefore>this.#t.now())return!1;const i=this.#A,s=await this.#t.store.readApplyWindow(t.authorityId);return $(t.authorityId,s),this.#e?!1:s.kind==="end"?(t.held=null,!1):(s.window.deliverySequence!==null&&this.#v.advance(t.authorityId,s.window.deliverySequence),await this.#U(t,s.window,i))}catch(e){return this.#Y(t,e),!1}}async#H(t){try{const e=t.held;if(e&&e.entityId===null&&!e.due&&e.notBefore>this.#t.now())return!1;const i=this.#A,s=await this.#t.store.readFetchWindow(t.unit,t.toPrefix?null:t.through);if(P(t.unit,s),this.#e||!this.#k(t))return!1;if(t.waitsOn=null,s.kind==="unseen")return this.#L(t,{producer:"detect",entityIds:[t.unit]},s.reason,i);if(!t.again&&(s.kind!=="window"||s.window.intent===null)&&(t.toPrefix=!1),t.through!==null&&s.through>t.through&&t.met.clear(),t.through=Math.max(t.through??0,s.through),s.kind!=="window"&&(t.held=null),t.again&&(s.kind==="end"||s.kind==="nowhere"))return!0;switch(s.kind){case"end":return this.#f(t,{kind:"placed"}),!1;case"nowhere":return this.#f(t,{kind:"nowhere",reason:s.reason}),!1;case"root":return await this.#V(t,s.through,s.reason);case"prerequisite":return this.#X(t,s.unit,s.reason,i);case"window":return await this.#U(t,s.window,i)}}catch(e){return this.#Y(t,e),!1}}async#V(t,e,i){return t.met.has(t.unit)?(this.#f(t,{kind:"held",unit:t.unit,reason:`${t.unit} entered and still not held: ${i}`}),!1):(await this.#t.effects.enterRoot(t.unit,e),this.#e||!this.#k(t)?!1:(t.through===e&&t.met.add(t.unit),this.#E(t.unit),!0))}#$(t){const e=this.#b(t,null);e.toPrefix=!0,e.met.clear(),this.#s(e)}#b(t,e,i=!1){let s=this.#i.get(t);return s?e!==null&&(s.through===null||s.through<e)&&(s.through=e,s.met.clear(),this.#s(s)):(s=v(t,e,i),this.#i.set(t,s),this.#s(s)),s}#X(t,e,i,s){return t.met.has(e)?(this.#f(t,{kind:"held",unit:e,reason:`${e} placed and still needed: ${i}`}),!1):this.#T(t,e,i)?this.#L(t,{producer:"apply",entityIds:[e]},i,s):!1}#L(t,e,i,s){return t.held={entityId:null,target:null,kept:null,cutoff:null,attempt:1,notBefore:1/0,releaseOnProgress:!1,due:this.#z(e,s),reason:i,dependency:e},t.held.due}#N(t){const e=t.held;if(e?.dependency?.producer==="apply"){for(const i of e.dependency.entityIds)if(i!==t.unit&&!t.met.has(i)&&!this.#T(t,i,e.reason))return}}#T(t,e,i){const s=[t];let n=this.#i.get(e);for(;n&&n!==t&&!s.includes(n);)s.push(n),n=n.waitsOn===null?void 0:this.#i.get(n.waitsOn);if(n===t){for(const r of s)this.#f(r,{kind:"held",unit:e,reason:`prerequisite cycle through ${e}: ${i}`});return!1}return t.waitsOn??=e,this.#s(this.#b(e,t.through)),!0}#f(t,e){if(!this.#k(t))return;for(const s of t.waiters)s.answer(e);t.waiters.clear(),t.waitsOn=null,(e.kind==="placed"||t.held?.entityId==null)&&this.#i.delete(t.unit);const i=e.kind==="placed"||e.kind==="held"?e:{kind:"held",unit:t.unit,reason:`${t.unit} is nowhere here: ${e.reason}`};for(const s of[...this.#i.values()])if(s.waitsOn===t.unit){if(e.kind!=="placed"){this.#f(s,i);continue}s.met.add(t.unit)}e.kind==="placed"&&(this.#E(t.unit),this.#c("apply",[t.unit]))}#E(t){const e=new Map([[t,!0]]);for(const i of this.#i.values()){const s=new Set;let n=i.unit;for(;n!==null&&!e.has(n)&&!s.has(n);)s.add(n),n=this.#i.get(n)?.waitsOn??null;const r=n!==null&&e.get(n)===!0;for(const h of s)e.set(h,r);if(r)for(const h of i.waiters)h.moved()}}#G(t){let e=t;const i=new Set([t]);for(let s=t.waitsOn===null?void 0:this.#i.get(t.waitsOn);s&&!i.has(s);s=s.waitsOn===null?void 0:this.#i.get(s.waitsOn))i.add(s),e=s;return{kind:"held",unit:e.unit,reason:e.held?.reason??"still placing"}}async#U(t,e,i){const s=e.members[0]?.work.entityId??null;if(t.held&&t.held.entityId!==null&&t.held.entityId!==s&&(t.held=null),await this.#Q(t,e))return!1;let n=await w(()=>this.#o.run(e,()=>t.kind==="lane"&&t.emptied?t.unit:null));if(t.kind==="line"&&!this.#e&&typeof n=="object"&&n.kind==="park"&&_(e,n)&&(n=await w(()=>this.#o.alone(e))),n==="progress"||typeof n=="object"&&n.kind==="alone"){if(t.kind==="line")for(const r of e.members)(r.judgment==="waiting"||n!=="progress"&&r.work.entityId===n.entityId)&&this.#$(r.work.entityId);for(const r of e.members)r.unseen!==void 0&&this.#$(r.unseen);return this.#Z(t,n!=="progress"?[n.entityId]:e.intent?.members.map(r=>r.entityId)??e.members.map(r=>r.work.entityId))}return n.advanced?.length&&this.#j(t,n.advanced),this.#tt(t,e,n,i),t.kind==="lane"&&this.#N(t),t.held.due}#K(t,e){const i=t.held,s=e.members[0]?.work.entityId??null;return(i?.entityId===s&&i.target===this.#o.targetOf(e)?i.attempt:0)+1}async#Q(t,e){const i=t.held,s=e.members[0];return!i||s===void 0||i.entityId!==s.work.entityId||i.due||i.notBefore<=this.#t.now()||this.#o.targetOf(e)!==i.target||e.cutoff!==i.cutoff?!1:await this.#t.store.localWorkAfter(e.authorityId,s.work.entityId,i.kept??i.target)===null}#Z(t,e){return t.held&&(t.held.entityId===null||e.includes(t.held.entityId))&&(t.held=null),this.#j(t,e),!0}#j(t,e){t.kind==="lane"&&(this.#r=!0,this.#E(t.unit)),this.#c("apply",e);for(const i of this.#w())i!==t&&i.held?.releaseOnProgress&&!i.held.due&&(i.held.due=!0,this.#s(i))}#tt(t,e,i,s){if(i.dependency&&O(i.dependency),i.blocker&&!i.dependency)throw new Error("Apply blocker must name the dependency that releases it");const n=e.members[0],r=t.held,h=this.#K(t,e),l=this.#C(h),d=i.again===!0&&h===1,f={entityId:n?.work.entityId??null,target:this.#o.targetOf(e),kept:n?.work.kept??null,cutoff:e.cutoff,attempt:h,notBefore:i.dependency?1/0:this.#t.now()+(d?0:l),releaseOnProgress:i.releaseOnProgress,due:i.dependency?this.#z(i.dependency,i.comparedAt??s):d,reason:i.reason,...i.dependency?{dependency:i.dependency}:{},...i.blocker?{blocker:i.blocker}:{}};t.held=f,this.#q();const A=p(r,y(t)),c=p(f,y(t));c&&JSON.stringify(c)!==JSON.stringify(A)&&this.#t.onWaiting?.(c),!(!i.report&&(i.dependency!==void 0||h===1))&&this.#S(new Error(`${m(t)} holds at ${f.entityId??"its open window"}, which ${i.releaseOnProgress?"is parked on a conflict":i.report?"failed":i.again?"keeps ending unplaced":"stands on ground that keeps moving"}, and will retry in ${l}ms (attempt ${h}): ${i.reason}`,i.cause===void 0?void 0:{cause:i.cause}))}#Y(t,e){if(t.kind==="lane"){for(const h of t.waiters)h.fail(e);t.waiters.clear()}const i=t.held,s=(i?.entityId===null?i.attempt:0)+1,n=this.#C(s),r=e instanceof Error?e.message:String(e);t.held={entityId:null,target:null,kept:null,cutoff:null,attempt:s,notBefore:this.#t.now()+n,releaseOnProgress:!1,due:!1,reason:r},this.#q(),this.#S(new Error(`${m(t)} faulted and will retry in ${n}ms (attempt ${s}): ${r}`,{cause:e}))}#S(t){try{this.#x(t)}catch{}}#C(t){const e=Math.min(g,x*2**Math.min(t-1,16)),i=Math.max(0,Math.min(1,this.#t.schedule.random()));return Math.round(e*(.5+i))}#c(t,e){const i=++this.#A;for(const s of e??["*"])this.#O.set(`${t}:${s}`,i);for(const s of this.#w())q(s,t,e)&&this.#s(s)}#z(t,e){return["*",...t.entityIds].some(i=>(this.#O.get(`${t.producer}:${i}`)??0)>e)}#q(){if(this.#e)return;let t=this.#p;for(const s of this.#w())s.held&&!s.held.due&&(t=Math.min(t,s.held.notBefore));if(t===1/0){this.#M();return}if(this.#y?.dueAt===t)return;this.#M();const e=Math.max(0,t-this.#t.now()),i=this.#t.schedule.schedule(e,()=>{this.#y=null,this.#D(t),this.#n()});this.#y={dueAt:t,cancel:a(()=>i.cancel(),"cancel")}}#D(t){let e=!1;for(const i of this.#w())i.held&&!i.held.due&&i.held.notBefore<=t&&(i.held.due=!0,this.#s(i),e=!0);return this.#p<=t&&(this.#p=1/0,this.#r=!0,e=!0),e}#M(){this.#y?.cancel(),this.#y=null}}const y=a(o=>o.kind==="line"?o.authorityId:o.unit,"owner"),m=a(o=>o.kind==="line"?`entity Apply line ${o.authorityId}`:`entity Apply fetch of ${o.unit}`,"label");export{M as ENTITY_APPLY_DEFAULT_CONCURRENCY,x as ENTITY_APPLY_RETRY_BASE_MS,g as ENTITY_APPLY_RETRY_MAX_MS,j as EntityApplyRail};
@@ -14,3 +14,4 @@ export * from './checkout-view.js';
14
14
  export * from './places.js';
15
15
  export { GIT_PARTS, gitPartBlobs, gitParts, gitPartsChanged, type GitPart } from './parts.js';
16
16
  export * from './restore.js';
17
+ export { gitRefsByMeaning, gitRefsTravelByMeaning } from './refs.js';
package/dist/git/index.js CHANGED
@@ -1 +1 @@
1
- export*from"./state.js";export*from"./alternates.js";export*from"./disk-settings.js";import{compareGitText as p}from"./text.js";export*from"./artifact.js";export*from"./chain.js";export*from"./plan.js";export*from"./play.js";export*from"./tag.js";export*from"./turns.js";export*from"./holds.js";export*from"./checkout.js";export*from"./checkout-view.js";export*from"./places.js";import{GIT_PARTS as d,gitPartBlobs as h,gitParts as l,gitPartsChanged as n}from"./parts.js";export*from"./restore.js";export{d as GIT_PARTS,p as compareGitText,h as gitPartBlobs,l as gitParts,n as gitPartsChanged};
1
+ export*from"./state.js";export*from"./alternates.js";export*from"./disk-settings.js";import{compareGitText as m}from"./text.js";export*from"./artifact.js";export*from"./chain.js";export*from"./plan.js";export*from"./play.js";export*from"./tag.js";export*from"./turns.js";export*from"./holds.js";export*from"./checkout.js";export*from"./checkout-view.js";export*from"./places.js";import{GIT_PARTS as l,gitPartBlobs as y,gitParts as G,gitPartsChanged as M}from"./parts.js";export*from"./restore.js";import{gitRefsByMeaning as d,gitRefsTravelByMeaning as h}from"./refs.js";export{l as GIT_PARTS,m as compareGitText,y as gitPartBlobs,G as gitParts,M as gitPartsChanged,d as gitRefsByMeaning,h as gitRefsTravelByMeaning};
package/dist/git/play.js CHANGED
@@ -1,4 +1,4 @@
1
- var re=Object.defineProperty;var f=(t,i)=>re(t,"name",{value:i,configurable:!0});import{utf8Decode as fe,utf8Encode as ce}from"../entities/bytes.js";import{GIT_ALTERNATES_PATH as le}from"./alternates.js";import{gitBlobId as Z}from"./artifact.js";import{gitChainReflog as de,gitDropPackedRefs as me,gitLooseRef as ue,gitPackedRefs as he,gitReflogPlay as ge,gitReflogTop as ee}from"./refs.js";import{gitBytesForm as pe,gitSelfHeld as we,gitSharesGitDir as ye,gitSharesObjects as ke,gitTreeOf as be,isGitOid as te}from"./state.js";import{compareGitText as z}from"./text.js";function xe(t){return t.facets.some(c=>c==="create"||c==="retype"||c==="content")&&t.result.status==="active"?t.result.transportVersion:null}f(xe,"gitOwnChange");function Me(t){let i=[],c=!1;for(const u of t){if(u.result.type!=="repo.git"){i=[],c=!0;continue}const p=xe(u);p!==null&&i.push(p)}return{reached:i,ended:c}}f(Me,"gitLineChanges");function Le({line:t,basis:i,record:c}){const u=f(l=>l.files.find(a=>a.path===le)?.oid??null,"borrowed"),p=f(l=>l.files.some(a=>a.path==="reftable"),"reftable");return t.format===c.format&&(i===null||i.format===c.format)&&!ke(t)&&!we(t.home)&&!ye(t.home)&&t.home?.entity===c.home?.entity&&t.home?.path===c.home?.path&&u(t)===u(c)&&![t,c,...i?[i]:[]].some(l=>p(l)||pe(l))}f(Le,"gitPlayable");const B="040000",F=f(t=>new Map(t.map(i=>[i.path,i])),"byPath"),N=f((t,i)=>t===void 0?i===void 0:i!==void 0&&t.mode===i.mode&&t.oid===i.oid,"same"),ne=f(t=>{const i=[];for(let c=t.indexOf("/");c>0;c=t.indexOf("/",c+1))i.push(t.slice(0,c));return i},"parents");function Ee(t,i,c){const u=new Set;for(const l of t.keys()){const a=ne(l).find(b=>t.has(b)&&t.get(b).mode!==B);a!==void 0&&u.add(a)}const p=f(l=>u.has(l)||ne(l).some(a=>u.has(a)),"clashed");if(u.size>0){for(const l of[...t.keys()])p(l)&&t.delete(l);for(const[l,a]of i)p(l)&&t.set(l,a)}return be(t.values(),c)}f(Ee,"asTree");const E=["line","basis","record"],R=f(t=>t.mode!==B&&(t.path==="HEAD"||t.path.startsWith("refs/")),"isLooseRef"),oe=f(t=>R(t)||t.path==="packed-refs","isRefFile"),Se=f(t=>t.startsWith("logs/"),"isReflogPath"),j="refs/stash",V="refs/heads/",q=`${V}amalgm`,De=7,Ae=/^[0-9a-f]{7,}$/,J=f((t,i)=>t.startsWith(`${i}/`),"beneath");async function ve(t,i,c,u){const p={format:t.record.format,home:t.record.home,files:[],index:null},l={line:t.line,basis:t.basis??p,record:t.record},a={line:F(l.line.files),basis:F(l.basis.files),record:F(l.record.files)},b=new Map,A=f((e,n)=>{const o=ce(n),r=Z(o,u);return b.set(r,o),{path:e,mode:"100644",oid:r}},"make"),w=f(async e=>e?.oid?fe(b.get(e.oid)??await i(e.oid)):"","read"),I=new Map,P=f(e=>(I.has(e)||I.set(e,w(a[e].get("packed-refs")).then(he)),I.get(e)),"packedOf"),y=f(async(e,n)=>{const o=a[e].get(n);return o!==void 0&&R(o)?ue(await w(o)):n==="HEAD"?null:(await P(e)).get(n)??null},"value"),$=f(e=>!N(a.basis.get(e),a.record.get(e)),"recordChanged"),m=new Map;for(const e of new Set([...a.line.keys(),...a.basis.keys(),...a.record.keys()])){const n=$(e)?a.record.get(e):a.line.get(e);n!==void 0&&m.set(e,n)}const T=new Set;for(const e of new Set(E.flatMap(n=>[...a[n].keys()]))){const[n,o,r]=E.map(s=>a[s].get(e));if(!(N(n,o)&&N(o,r)))if(e==="packed-refs")for(const s of E)for(const d of(await P(s)).keys())T.add(d);else[n,o,r].some(s=>s!==void 0&&R(s))&&T.add(e)}const K=f(async e=>{const[n,o,r]=E.map(s=>a[s].get(e));return[n,o,r].some(s=>s?.mode===B)?w(n):ge(await w(o),await w(r),await w(n))},"playLog"),x=`logs/${j}`;let S=null;$(x)&&(S=de(await K(x)),S===""?m.delete(x):m.set(x,A(x,S)));const g=new Map,M=[];for(const e of[...T].sort(z)){const[n,o,r]=await Promise.all(E.map(d=>y(d,e)));let s=o!==r?r:n;if(e===j){if(S===null)continue;s=ee(S)}else e.startsWith(V)&&n!==null&&n!==o&&s!==n&&[n,r].every(d=>d===null||te(t.record.format,d))&&(r===null||!await c.builtOn(r,n))&&(s=n,r!==null&&!await c.builtOn(n,r)&&M.push({name:e,basis:o,record:r}));s!==n&&g.set(e,s)}const Q=[];if(M.length>0){const e=new Map;for(const o of new Set([...a.line.keys(),...(await P("line")).keys(),...g.keys()])){if(o!==q&&!J(o,q))continue;const r=g.has(o)?g.get(o):await y("line",o);r!==null&&e.set(o,r)}const n=f((o,r)=>(e.get(o)??r)===r&&![...e.keys()].some(s=>J(o,s)||J(s,o)),"free");for(const{name:o,basis:r,record:s}of M){const d=`${q}/${o.slice(V.length)}-`;let h=[...e.keys()].sort(z).find(k=>e.get(k)===r&&k.startsWith(d)&&Ae.test(k.slice(d.length)));for(let k=De;h===void 0&&k<=s.length;k+=1)n(d+s.slice(0,k),s)&&(h=d+s.slice(0,k));h!==void 0&&(await y("line",h)!==s&&g.set(h,s),e.set(h,s),Q.push({branch:h,from:o,commit:s}))}}for(const[e,n]of[...m])oe(n)&&m.delete(e);for(const e of l.line.files)oe(e)&&m.set(e.path,e);const L=new Set;for(const[e,n]of g)n!==null?m.set(e,A(e,`${n}
2
- `)):(m.has(e)&&R(m.get(e))&&m.delete(e),L.add(e));const U=a.line.get("packed-refs");if(L.size>0&&U!==void 0){const e=await w(U),n=me(e,L);n!==e&&m.set("packed-refs",A("packed-refs",n))}const v=f(e=>g.has(e)?Promise.resolve(g.get(e)):y("line",e),"final"),C=f(async(e,n)=>e?.startsWith("ref: ")?n(e.slice(5)):e,"commitOf"),O=await C(await v("HEAD"),v),H=new Set;for(const e of E)for(const n of a[e].keys())Se(n)&&n!==x&&H.add(n);for(const e of g.keys())e!==j&&H.add(`logs/${e}`);O!==await C(await y("line","HEAD"),e=>y("line",e))&&H.add("logs/HEAD");for(const e of[...H].sort(z)){const n=e.slice(5),o=n==="HEAD"?O:await v(n),r=$(e);if(!r&&(o===null||n!=="HEAD"&&!g.has(n)||!a.line.has(e)))continue;let s=r?await K(e):await w(a.line.get(e));const d=ee(s);if(o!==null&&d!==null&&d!==o&&te(t.record.format,o)){const h=s.trimEnd().split(`
3
- `).at(-1);s+=`${d} ${o}${h.slice(h.indexOf(" ",h.indexOf(" ")+1))}
4
- `}s===""?m.delete(e):m.set(e,A(e,s))}const W=f(e=>y(e,"HEAD").then(n=>C(n,o=>y(e,o))),"headOf"),G=f(async e=>{const n=t[e]?.index;return n?.files.length===1?{index:await i(n.files[0].oid),head:await W(e)}:null},"indexOf"),[_,se,X,ie,ae]=await Promise.all([G("line"),G("basis"),G("record"),t.basis?W("basis"):null,W("record")]),D=t.record.index?.meaning===t.basis?.index?.meaning&&ae===ie;let Y=D?t.line.index:t.record.index;if(_!==null&&(D||X!==null)&&!(D&&_.head===O)){const e=await c.playIndex(_,D?null:se,D?null:X,O);if(e!==null){const n=e.bytes,o=Z(n,u);b.set(o,n),Y={meaning:e.meaning,files:[{path:"index",mode:"100644",oid:o}]}}}return{state:{format:t.record.format,home:t.record.home,files:Ee(m,a.record,t.record.home),index:Y},made:b,aside:Q}}f(ve,"gitPlayRecord");export{Me as gitLineChanges,xe as gitOwnChange,ve as gitPlayRecord,Le as gitPlayable};
1
+ var ce=Object.defineProperty;var r=(t,i)=>ce(t,"name",{value:i,configurable:!0});import{utf8Decode as fe,utf8Encode as le}from"../entities/bytes.js";import{GIT_ALTERNATES_PATH as de}from"./alternates.js";import{gitBlobId as ee}from"./artifact.js";import{gitChainReflog as me,gitDropPackedRefs as ue,gitLooseRef as he,gitPackedRefs as ge,gitReflogPlay as pe,gitReflogTop as te,gitRefsByMeaning as we}from"./refs.js";import{gitBytesForm as ye,gitSelfHeld as ke,gitSharesGitDir as be,gitSharesObjects as xe,gitTreeOf as Ee,isGitOid as ne}from"./state.js";import{compareGitText as z}from"./text.js";function Se(t){return t.facets.some(c=>c==="create"||c==="retype"||c==="content")&&t.result.status==="active"?t.result.transportVersion:null}r(Se,"gitOwnChange");function ve(t){let i=[],c=!1;for(const m of t){if(m.result.type!=="repo.git"){i=[],c=!0;continue}const u=Se(m);u!==null&&i.push(u)}return{reached:i,ended:c}}r(ve,"gitLineChanges");function Ce({line:t,basis:i,record:c}){const m=r(f=>f.files.find(g=>g.path===de)?.oid??null,"borrowed"),u=r(f=>f.files.some(g=>g.path==="reftable"),"reftable");return t.format===c.format&&(i===null||i.format===c.format)&&!xe(t)&&!ke(t.home)&&!be(t.home)&&t.home?.entity===c.home?.entity&&t.home?.path===c.home?.path&&m(t)===m(c)&&![t,c,...i?[i]:[]].some(f=>u(f)||ye(f))}r(Ce,"gitPlayable");const F="040000",N=r(t=>new Map(t.map(i=>[i.path,i])),"byPath"),j=r((t,i)=>t===void 0?i===void 0:i!==void 0&&t.mode===i.mode&&t.oid===i.oid,"same"),oe=r(t=>{const i=[];for(let c=t.indexOf("/");c>0;c=t.indexOf("/",c+1))i.push(t.slice(0,c));return i},"parents");function De(t,i,c){const m=new Set;for(const f of t.keys()){const g=oe(f).find(x=>t.has(x)&&t.get(x).mode!==F);g!==void 0&&m.add(g)}const u=r(f=>m.has(f)||oe(f).some(g=>m.has(g)),"clashed");if(m.size>0){for(const f of[...t.keys()])u(f)&&t.delete(f);for(const[f,g]of i)u(f)&&t.set(f,g)}return Ee(t.values(),c)}r(De,"asTree");const S=["line","basis","record"],I=r(t=>t.mode!==F&&(t.path==="HEAD"||t.path.startsWith("refs/")),"isLooseRef"),se=r(t=>I(t)||t.path==="packed-refs","isRefFile"),Ae=r(t=>t.startsWith("logs/"),"isReflogPath"),V="refs/stash",q="refs/heads/",J=`${q}amalgm`,Oe=7,Re=/^[0-9a-f]{7,}$/,K=r((t,i)=>t.startsWith(`${i}/`),"beneath");async function We(t,i,c,m){const u=new Map,f=r(async e=>{const n=e.files.find(a=>a.path==="packed-refs")?.oid,o=we(e,n?u.get(n)??await i(n):null,m);for(const[a,s]of o.made)u.set(a,s);return o.state},"meaning"),g={format:t.record.format,home:t.record.home,files:[],index:null},x={line:await f(t.line),basis:t.basis===null?g:await f(t.basis),record:await f(t.record)},l={line:N(x.line.files),basis:N(x.basis.files),record:N(x.record.files)},O=r((e,n)=>{const o=le(n),a=ee(o,m);return u.set(a,o),{path:e,mode:"100644",oid:a}},"make"),y=r(async e=>e?.oid?fe(u.get(e.oid)??await i(e.oid)):"","read"),P=new Map,$=r(e=>(P.has(e)||P.set(e,y(l[e].get("packed-refs")).then(ge)),P.get(e)),"packedOf"),k=r(async(e,n)=>{const o=l[e].get(n);return o!==void 0&&I(o)?he(await y(o)):n==="HEAD"?null:(await $(e)).get(n)??null},"value"),M=r(e=>!j(l.basis.get(e),l.record.get(e)),"recordChanged"),h=new Map;for(const e of new Set([...l.line.keys(),...l.basis.keys(),...l.record.keys()])){const n=M(e)?l.record.get(e):l.line.get(e);n!==void 0&&h.set(e,n)}const T=new Set;for(const e of new Set(S.flatMap(n=>[...l[n].keys()]))){const[n,o,a]=S.map(s=>l[s].get(e));if(!(j(n,o)&&j(o,a)))if(e==="packed-refs")for(const s of S)for(const d of(await $(s)).keys())T.add(d);else[n,o,a].some(s=>s!==void 0&&I(s))&&T.add(e)}const Q=r(async e=>{const[n,o,a]=S.map(s=>l[s].get(e));return[n,o,a].some(s=>s?.mode===F)?y(n):pe(await y(o),await y(a),await y(n))},"playLog"),E=`logs/${V}`;let D=null;M(E)&&(D=me(await Q(E)),D===""?h.delete(E):h.set(E,O(E,D)));const w=new Map,L=[];for(const e of[...T].sort(z)){const[n,o,a]=await Promise.all(S.map(d=>k(d,e)));let s=o!==a?a:n;if(e===V){if(D===null)continue;s=te(D)}else e.startsWith(q)&&n!==null&&n!==o&&s!==n&&[n,a].every(d=>d===null||ne(t.record.format,d))&&(a===null||!await c.builtOn(a,n))&&(s=n,a!==null&&!await c.builtOn(n,a)&&L.push({name:e,basis:o,record:a}));s!==n&&w.set(e,s)}const U=[];if(L.length>0){const e=new Map;for(const o of new Set([...l.line.keys(),...(await $("line")).keys(),...w.keys()])){if(o!==J&&!K(o,J))continue;const a=w.has(o)?w.get(o):await k("line",o);a!==null&&e.set(o,a)}const n=r((o,a)=>(e.get(o)??a)===a&&![...e.keys()].some(s=>K(o,s)||K(s,o)),"free");for(const{name:o,basis:a,record:s}of L){const d=`${J}/${o.slice(q.length)}-`;let p=[...e.keys()].sort(z).find(b=>e.get(b)===a&&b.startsWith(d)&&Re.test(b.slice(d.length)));for(let b=Oe;p===void 0&&b<=s.length;b+=1)n(d+s.slice(0,b),s)&&(p=d+s.slice(0,b));p!==void 0&&(await k("line",p)!==s&&w.set(p,s),e.set(p,s),U.push({branch:p,from:o,commit:s}))}}for(const[e,n]of[...h])se(n)&&h.delete(e);for(const e of x.line.files)se(e)&&h.set(e.path,e);const v=new Set;for(const[e,n]of w)n!==null?h.set(e,O(e,`${n}
2
+ `)):(h.has(e)&&I(h.get(e))&&h.delete(e),v.add(e));const X=l.line.get("packed-refs");if(v.size>0&&X!==void 0){const e=await y(X),n=ue(e,v);n!==e&&h.set("packed-refs",O("packed-refs",n))}const C=r(e=>w.has(e)?Promise.resolve(w.get(e)):k("line",e),"final"),W=r(async(e,n)=>e?.startsWith("ref: ")?n(e.slice(5)):e,"commitOf"),R=await W(await C("HEAD"),C),H=new Set;for(const e of S)for(const n of l[e].keys())Ae(n)&&n!==E&&H.add(n);for(const e of w.keys())e!==V&&H.add(`logs/${e}`);R!==await W(await k("line","HEAD"),e=>k("line",e))&&H.add("logs/HEAD");for(const e of[...H].sort(z)){const n=e.slice(5),o=n==="HEAD"?R:await C(n),a=M(e);if(!a&&(o===null||n!=="HEAD"&&!w.has(n)||!l.line.has(e)))continue;let s=a?await Q(e):await y(l.line.get(e));const d=te(s);if(o!==null&&d!==null&&d!==o&&ne(t.record.format,o)){const p=s.trimEnd().split(`
3
+ `).at(-1);s+=`${d} ${o}${p.slice(p.indexOf(" ",p.indexOf(" ")+1))}
4
+ `}s===""?h.delete(e):h.set(e,O(e,s))}const B=r(e=>k(e,"HEAD").then(n=>W(n,o=>k(e,o))),"headOf"),G=r(async e=>{const n=t[e]?.index;return n?.files.length===1?{index:await i(n.files[0].oid),head:await B(e)}:null},"indexOf"),[_,ae,Y,ie,re]=await Promise.all([G("line"),G("basis"),G("record"),t.basis?B("basis"):null,B("record")]),A=t.record.index?.meaning===t.basis?.index?.meaning&&re===ie;let Z=A?t.line.index:t.record.index;if(_!==null&&(A||Y!==null)&&!(A&&_.head===R)){const e=await c.playIndex(_,A?null:ae,A?null:Y,R);if(e!==null){const n=e.bytes,o=ee(n,m);u.set(o,n),Z={meaning:e.meaning,files:[{path:"index",mode:"100644",oid:o}]}}}return{state:await f({format:t.record.format,home:t.record.home,files:De(h,l.record,t.record.home),index:Z}),made:u,aside:U}}r(We,"gitPlayRecord");export{ve as gitLineChanges,Se as gitOwnChange,We as gitPlayRecord,Ce as gitPlayable};
@@ -1,6 +1,13 @@
1
+ import type { Sha256Hex } from '../entities/types.js';
2
+ import { type GitState } from './state.js';
1
3
  export declare const gitLooseRef: (text: string) => string;
2
4
  export declare function gitPackedRefs(text: string): Map<string, string>;
3
5
  export declare function gitDropPackedRefs(text: string, names: ReadonlySet<string>): string;
6
+ export declare const gitRefsTravelByMeaning: (state: GitState) => boolean;
7
+ export declare function gitRefsByMeaning(state: GitState, packed: Uint8Array | null, sha256: Sha256Hex): {
8
+ readonly state: GitState;
9
+ readonly made: ReadonlyMap<string, Uint8Array>;
10
+ };
4
11
  export declare function gitReflogPlay(basis: string, record: string, line: string): string;
5
12
  export declare function gitChainReflog(text: string): string;
6
13
  export declare const gitReflogTop: (text: string) => string | null;
package/dist/git/refs.js CHANGED
@@ -1,8 +1,10 @@
1
- var h=Object.defineProperty;var o=(t,n)=>h(t,"name",{value:n,configurable:!0});const d=o(t=>t.split(`
2
- `,1)[0].trimEnd(),"gitLooseRef"),f=o(t=>{const n=t.indexOf(" ");return t.startsWith("#")||t.startsWith("^")||n<=0?null:t.slice(n+1)},"packedName");function m(t){const n=new Map;for(const e of t.split(`
3
- `)){const s=f(e);s!==null&&n.set(s,e.slice(0,e.indexOf(" ")))}return n}o(m,"gitPackedRefs");function x(t,n){const e=[];let s=!1;for(const i of t.split(`
4
- `))i.startsWith("^")||(s=n.has(f(i)??"")),s||e.push(i);return e.join(`
5
- `)}o(x,"gitDropPackedRefs");const p=o(t=>t.split(`
6
- `).filter(n=>n!==""),"lines"),c=o(t=>t.slice(t.indexOf(" ")+1),"entry");function w(t,n,e){const s=new Set(p(t).map(c)),i=p(n),l=new Set(i.map(c)),a=p(e),u=new Set(a.map(c));return[...a.filter(r=>!s.has(c(r))||l.has(c(r))),...i.filter(r=>!s.has(c(r))&&!u.has(c(r)))].map(r=>`${r}
7
- `).join("")}o(w,"gitReflogPlay");function R(t){let n=null;return p(t).map(e=>{const s=e.split(" ",2)[1],i=`${n??"0".repeat(s.length)}${e.slice(e.indexOf(" "))}
8
- `;return n=s,i}).join("")}o(R,"gitChainReflog");const k=o(t=>p(t).at(-1)?.split(" ",2)[1]??null,"gitReflogTop");export{R as gitChainReflog,x as gitDropPackedRefs,d as gitLooseRef,m as gitPackedRefs,w as gitReflogPlay,k as gitReflogTop};
1
+ var k=Object.defineProperty;var r=(e,n)=>k(e,"name",{value:n,configurable:!0});import{utf8Encode as R}from"../entities/bytes.js";import{gitBlobId as W}from"./artifact.js";import{gitBytesForm as $,gitSelfHeld as v,gitSharesGitDir as S,gitTreeOf as M,isGitOid as y}from"./state.js";const G=r(e=>e.split(`
2
+ `,1)[0].trimEnd(),"gitLooseRef"),x=r(e=>{const n=e.indexOf(" ");return e.startsWith("#")||e.startsWith("^")||n<=0?null:e.slice(n+1)},"packedName");function N(e){const n=new Map;for(const s of e.split(`
3
+ `)){const o=x(s);o!==null&&n.set(o,s.slice(0,s.indexOf(" ")))}return n}r(N,"gitPackedRefs");function z(e,n){const s=[];let o=!1;for(const t of e.split(`
4
+ `))t.startsWith("^")||(o=n.has(x(t)??"")),o||s.push(t);return s.join(`
5
+ `)}r(z,"gitDropPackedRefs");const h="040000",O="refs/";function b(e,n){const s=new Map;for(const o of e.split(`
6
+ `)){if(o===""||o.startsWith("#")||o.startsWith("^")&&y(n,o.slice(1)))continue;const t=x(o),f=o.slice(0,o.indexOf(" "));if(t===null||!t.startsWith(O)||!y(n,f))return null;s.set(t,f)}return s}r(b,"packedRefs");function D(e){try{return new TextDecoder("utf-8",{fatal:!0}).decode(e)}catch{return null}}r(D,"strictText");const E=r(e=>e.normalize("NFC").toLowerCase(),"folded"),T=r(e=>!/[<>:"|?*\\\x00-\x1f]|[. ]$/.test(e)&&!/^(aux|con|conin\$|conout\$|nul|prn|com[1-9]|lpt[1-9]) *(\.|$)/i.test(e),"onWindows");function j(e,n){if(!n.every(t=>t.split("/").every(T)))return!1;const s=new Set;for(const t of n)for(let f=t.indexOf("/");f>0;f=t.indexOf("/",f+1))s.add(t.slice(0,f));if(n.some(t=>s.has(t)))return!1;const o=new Map;for(const t of[...e,...n,...s]){const f=E(t),l=o.get(f);if(l!==void 0&&l!==t)return!1;o.set(f,t)}return!0}r(j,"looseOnEveryDisk");const B=r(e=>!$(e)&&!v(e.home)&&!S(e.home)&&!e.files.some(n=>n.path==="reftable"||n.path.startsWith("reftable/")),"gitRefsTravelByMeaning");function H(e,n,s){const o=new Map;if(!B(e))return{state:e,made:o};const t=new Map(e.files.map(i=>[i.path,i])),f=n===null||!/^100(644|755)$/.test(t.get("packed-refs")?.mode??"")?null:D(n),l=f===null?null:b(f,e.format),g=r(i=>(t.get(i)?.mode??h)!==h,"loose"),c=r(i=>t.get(i)?.mode!==h&&i.split("/").every((a,u,d)=>u===d.length-1||!g(d.slice(0,u+1).join("/"))),"clear");if(l!==null&&[...l.keys()].every(c)&&j([...t.keys()],[...l.keys()])){t.delete("packed-refs");for(const[i,a]of l){if(g(i))continue;const u=R(`${a}
7
+ `),d=W(u,s);o.set(d,u),t.set(i,{path:i,mode:"100644",oid:d})}}const w=new Set;for(const i of t.values())if(i.mode!==h)for(let a=i.path.indexOf("/");a>0;a=i.path.indexOf("/",a+1))w.add(i.path.slice(0,a));for(const[i,a]of t)a.mode===h&&i.startsWith(O)&&!w.has(i)&&t.delete(i);return{state:{...e,files:M(t.values(),e.home)},made:o}}r(H,"gitRefsByMeaning");const m=r(e=>e.split(`
8
+ `).filter(n=>n!==""),"lines"),p=r(e=>e.slice(e.indexOf(" ")+1),"entry");function I(e,n,s){const o=new Set(m(e).map(p)),t=m(n),f=new Set(t.map(p)),l=m(s),g=new Set(l.map(p));return[...l.filter(c=>!o.has(p(c))||f.has(p(c))),...t.filter(c=>!o.has(p(c))&&!g.has(p(c)))].map(c=>`${c}
9
+ `).join("")}r(I,"gitReflogPlay");function _(e){let n=null;return m(e).map(s=>{const o=s.split(" ",2)[1],t=`${n??"0".repeat(o.length)}${s.slice(s.indexOf(" "))}
10
+ `;return n=o,t}).join("")}r(_,"gitChainReflog");const q=r(e=>m(e).at(-1)?.split(" ",2)[1]??null,"gitReflogTop");export{_ as gitChainReflog,z as gitDropPackedRefs,G as gitLooseRef,N as gitPackedRefs,I as gitReflogPlay,q as gitReflogTop,H as gitRefsByMeaning,B as gitRefsTravelByMeaning};
@@ -1,2 +1 @@
1
- var I=Object.defineProperty;var s=(o,n)=>I(o,"name",{value:n,configurable:!0});import{fail as f,pass as A}from"../contracts/validate.js";import{utf8Decode as B,utf8Encode as S}from"../entities/bytes.js";import{gitBlobId as W}from"./artifact.js";import{GIT_PACKED_REFS as l,gitOwnFile as j,gitOwnRef as c}from"./parts.js";import{gitDropPackedRefs as q,gitPackedRefs as m}from"./refs.js";import{checkGitState as C,gitBytesForm as H,gitSelfHeld as K,gitTreeOf as L}from"./state.js";const E=/^(rebase-merge|rebase-apply|sequencer)(\/|$)/,p=s(o=>o.mode==="040000","isFolder"),T=s(o=>c(o)||j(o),"restored");function Y(o,n,$,v){for(const t of[o,n]){if(H(t))return f("a repository in byte form cannot be restored");if(t.files.some(e=>e.path.startsWith("reftable/")))return f("a reftable repository cannot be restored");if(K(t.home))return f("a worktree of storage outside every folder cannot be restored")}if(o.format!==n.format)return f(`a ${o.format} repository cannot take a ${n.format} version`);const d=new Map,u=s((t,e)=>{const a=W(e,v);return d.set(a,e),{path:t,mode:"100644",oid:a}},"blob"),h=s(t=>t.files.find(e=>e.path===l),"packed"),k=s(t=>{const e=h(t);return e===void 0?null:B($(e.oid))},"packedText"),i=k(o),g=k(n),b=g===null?new Map:m(g),w=s((t,e)=>new Set([...t.files.filter(a=>!p(a)&&c(a.path)).map(a=>a.path),...[...e.keys()].filter(c)]),"ownRefs"),O=w(n,b),x=new Set([...w(o,i===null?new Map:m(i))].filter(t=>!O.has(t)).map(t=>`logs/${t}`)),r=new Map;for(const[t,e]of b)c(t)&&r.set(t,u(t,S(`${e}
2
- `)));for(const t of n.files)(p(t)?E.test(t.path):T(t.path))&&r.set(t.path,t);if(i!==null){const t=q(i,new Set([...m(i).keys()].filter(c)));r.set(l,t===i?h(o):u(l,S(t)))}const y=s(t=>{const e=t.split("/");return e.slice(1).map((a,G)=>e.slice(0,G+1).join("/"))},"ancestors"),F=new Set([...r.keys()].flatMap(y)),_=s(t=>r.has(t.path)||!p(t)&&F.has(t.path)||y(t.path).some(e=>r.has(e)&&!p(r.get(e))),"inTheWay");for(const t of o.files)(p(t)?!E.test(t.path):t.path!==l&&!T(t.path)&&!x.has(t.path))&&!_(t)&&r.set(t.path,t);const R=L(r.values(),o.home),M={...o,files:R,index:n.index},P=C(M);if(!P.ok)return f(`the version cannot stand over this repository: ${P.error}`);const D=new Map(R.flatMap(t=>d.has(t.oid)?[[t.oid,d.get(t.oid)]]:[]));return A({state:M,blobs:D})}s(Y,"gitRestoreGoal");export{Y as gitRestoreGoal};
1
+ var F=Object.defineProperty;var s=(o,n)=>F(o,"name",{value:n,configurable:!0});import{fail as i,pass as B}from"../contracts/validate.js";import{gitOwnFile as G,gitOwnRef as y}from"./parts.js";import{gitRefsByMeaning as W}from"./refs.js";import{checkGitState as _,gitBytesForm as j,gitSelfHeld as q,gitTreeOf as A}from"./state.js";const b=/^(rebase-merge|rebase-apply|sequencer)(\/|$)/,f=s(o=>o.mode==="040000","isFolder"),k=s(o=>y(o)||G(o),"restored");function z(o,n,R,v){for(const t of[o,n]){if(j(t))return i("a repository in byte form cannot be restored");if(t.files.some(e=>e.path.startsWith("reftable/")))return i("a reftable repository cannot be restored");if(q(t.home))return i("a worktree of storage outside every folder cannot be restored")}if(o.format!==n.format)return i(`a ${o.format} repository cannot take a ${n.format} version`);const c=new Map,p=s(t=>{const e=t.files.find(a=>a.path==="packed-refs")?.oid,m=W(t,e?c.get(e)??R(e):null,v);for(const[a,E]of m.made)c.set(a,E);return m.state},"meaning"),[d,h]=[p(o),p(n)],g=s(t=>new Set(t.files.filter(e=>!f(e)&&y(e.path)).map(e=>e.path)),"ownRefs"),M=g(h),O=new Set([...g(d)].filter(t=>!M.has(t)).map(t=>`logs/${t}`)),r=new Map;for(const t of h.files)(f(t)?b.test(t.path):k(t.path))&&r.set(t.path,t);const u=s(t=>{const e=t.split("/");return e.slice(1).map((m,a)=>e.slice(0,a+1).join("/"))},"ancestors"),S=new Set([...r.keys()].flatMap(u)),$=s(t=>r.has(t.path)||!f(t)&&S.has(t.path)||u(t.path).some(e=>r.has(e)&&!f(r.get(e))),"inTheWay");for(const t of d.files)(f(t)?!b.test(t.path):!k(t.path)&&!O.has(t.path))&&!$(t)&&r.set(t.path,t);const l=p({...o,files:A(r.values(),o.home),index:n.index}),T=l.files,w=_(l);if(!w.ok)return i(`the version cannot stand over this repository: ${w.error}`);const x=new Map(T.flatMap(t=>c.has(t.oid)?[[t.oid,c.get(t.oid)]]:[]));return B({state:l,blobs:x})}s(z,"gitRestoreGoal");export{z as gitRestoreGoal};
@@ -1 +1 @@
1
- "use strict";var x=Object.defineProperty;var m=(l,e)=>x(l,"name",{value:e,configurable:!0});Object.defineProperty(exports,"__esModule",{value:!0}),exports.EntityApplyJourney=void 0,exports.stepsAside=P,exports.outcomeOf=H;const j=require("./contracts.js"),q=require("./plans.js"),S=require("../faults/recover.js"),O=require("../faults/classify.js"),M=require("../clash/local-work.js"),E=require("./selection.js"),W=require("./settling.js"),F=require("./window.js");function P(l,e){return l.unit===null&&l.authorityId!==e}m(P,"stepsAside");const I={kind:"park",reason:"its window ended with its head unplaced and named no wait",releaseOnProgress:!1,report:!1,again:!0},D=m(l=>l.kind==="captured-local"||l.kind==="rejudge","drops");function A(l){return l.kind==="retry"?{kind:"park",reason:l.reason??"machine truth is unsettled",releaseOnProgress:!1,report:!1}:l.kind==="dependency"?{kind:"park",reason:l.reason,releaseOnProgress:l.waitFor===void 0,report:!1,...l.waitFor?{dependency:l.waitFor}:{},...l.blocker?{blocker:l.blocker}:{},..."comparedAt"in l?{comparedAt:l.comparedAt}:{}}:l.kind==="conflict"?{kind:"park",reason:l.reason,releaseOnProgress:!0,report:!0}:null}m(A,"parkFor");async function H(l){try{return await l()}catch(e){return{kind:"park",reason:e instanceof Error?e.message:String(e),releaseOnProgress:!1,report:!(0,O.groundMoved)(e),cause:e}}}m(H,"outcomeOf");const v=m(l=>(0,W.isSettlement)(l.judgment)?{kind:"settled",settlement:l.judgment}:null,"settled");class U{static{m(this,"EntityApplyJourney")}#e;#r;#s;#n;constructor(e,t,i){this.#e=e,this.#r={sha256Hex:e.sha256Hex,loops:e.loops,deliveryPosition:e.deliveryPosition},this.#s=t,this.#n=i}targetOf(e){const t=e.members[0];return t===void 0?null:e.intent?.members.find(i=>i.entityId===t.work.entityId)?.throughSequence??(t.work.kept===null?t.work.records.at(-1)?.globalSequence:t.work.resolvedThrough)??null}async run(e,t){if(e.intent!==null)return this.#p(e,e.intent);const i={member:null};try{return await this.#d(e,t,i)}catch(s){if(i.member===null||this.#n())throw s;if((0,O.groundMoved)(s))return{kind:"park",reason:s instanceof Error?s.message:String(s),releaseOnProgress:!1,report:!1};if(P(e,i.member.work.entityId))return this.alone(i.member);if(s instanceof S.Recovering)return{kind:"park",reason:s.message,releaseOnProgress:!1,report:!1,dependency:{producer:"capability",entityIds:s.need.subject===null?[]:[s.need.subject.id]}};throw s}}async alone(e){const{target:t}=(0,E.selectEntityApply)(e.work,this.#r),i=await this.#i({authorityId:e.work.authorityId,entityId:e.work.entityId,targetType:t.result.type,kept:t.record===null?t.result:null,throughSequence:t.throughSequence}),s=await this.#t(null,[e],[{kind:"settled",settlement:i?"superseded":"waiting"}]);return s==="progress"&&!i?{kind:"alone",entityId:e.work.entityId}:s}async#d(e,t,i){const s=this.#e.newIntentId(),n=this.#e.now(),o=t(),a=new Map;for(const c of e.members){if(v(c))continue;const{work:f}=c,w=(0,E.selectEntityApply)(f,this.#r),b=(0,j.createApplyIntent)({attemptId:s,work:f,target:w.target,unit:e.unit,cutoff:e.cutoff,createdAt:n,emptied:f.entityId===o&&f.play==="enter"&&(w.target.result.type==="file.text"||w.target.result.type==="file.binary")}),h=(0,q.planSelectedEntityApply)(f,w,this.#e.sha256Hex);a.set(f.entityId,{member:c,intent:b,plan:h,adapter:this.#e.effects.adapterFor(h.target.type),look:"safe"})}const{active:d,blocked:y}=await this.#o(e.members,a,"look",i);if(d.length===0)return y??I;const g=d.flatMap(c=>a.get(c.work.entityId)??[]);if(g.length===0)return this.#t(null,d,d.map(c=>v(c)));const k=(0,j.createApplyWindowIntent)({attemptId:s,authorityId:e.authorityId,unit:e.unit,cutoff:e.cutoff,createdAt:n,members:g.map(c=>c.intent)});try{const c=await this.#u(d,a,i),f=c.active.flatMap(r=>a.get(r.work.entityId)??[]);if(f.length===0)return await this.#e.effects.discard(k),c.active.length===0?c.blocked??I:this.#t(null,c.active,c.active.map(r=>v(r)));const w=f.length===g.length?k:(0,j.createApplyWindowIntent)({...k,members:f.map(r=>r.intent)}),b=await this.#e.effects.hold(w,f.map(r=>r.plan));let h,_;try{h=await this.#o(c.active,a,"final",i),_=await this.#c(w,h,a,t)}finally{b()}return h.unseen!==null&&h.active.length===0?this.#y(h.unseen):_}catch(c){throw await this.#e.effects.discard(k),c}}async#c(e,{active:t,blocked:i},s,n){const o=t.flatMap(r=>s.get(r.work.entityId)??[]);if(o.length===0)return await this.#e.effects.discard(e),t.length===0?i??I:this.#t(null,t,t.map(r=>v(r)));const a=(0,j.createApplyWindowIntent)({...e,members:o.map(r=>r.intent)}),d=o.filter(r=>r.look==="safe");if(d.length>0){if(this.#n()||o.some(p=>p.intent.emptied&&n()!==p.intent.entityId))return await this.#e.effects.discard(e),I;const r=await this.#e.store.bindWindow(a);if(r)return await this.#e.effects.discard(e),r.kind==="stale"?I:A({...r,comparedAt:this.#s()})}const y=new Map,g=new Map,k=m((r,p,u=null)=>{y.set(r,{kind:"owed",reason:p}),u!==null&&g.set(r,u)},"owe"),c=m(r=>A(r.kind==="dependency"?{...r,comparedAt:this.#s()}:r),"waitFrom"),{order:f,cycle:w}=(0,F.revealOrder)(d.map(r=>({entityId:r.intent.entityId,play:r.plan.play,type:r.plan.target.type,parentUUID:r.plan.target.parentUUID}))),b="its parent chain closes among the window's members";for(const r of w)k(r,b,{kind:"park",reason:b,releaseOnProgress:!1,report:!0});for(const r of f){const p=s.get(r),u=await p.adapter.apply.reveal(p.intent,p.plan);u&&k(r,u.reason,u.kind==="dependency"?c(u):null)}for(const r of o){const p=r.intent.entityId;if(y.has(p))continue;const u=await r.adapter.verify.verify(r.intent,r.plan);u.kind==="match"?y.set(p,{kind:"materialized"}):u.kind==="local-change"?k(p,"a person's version stands in its place"):u.kind==="rejudge"||u.kind==="missing-target"?k(p,u.kind):k(p,u.reason??u.kind,c(u))}const h=t.map(r=>v(r)??y.get(r.work.entityId));if(d.length>0)return this.#a(a,t,h,g);const _=await this.#a(null,t,h,g);return await this.#e.effects.discard(e),_}async#a(e,t,i,s){const n=await this.#t(e,t,i),o=i[0];return n!=="progress"||o.kind!=="owed"?n:{...s.get(t[0].work.entityId)??{kind:"park",reason:o.reason,releaseOnProgress:!1,report:!1,again:!0},advanced:t.filter((d,y)=>i[y].kind!=="owed").map(d=>d.work.entityId)}}async#o(e,t,i,s){const n=[];for(const o of e){const a=t.get(o.work.entityId);if(!a){n.push(o);continue}let d;try{d=await this.#i(a.intent)?{kind:"captured-local"}:i==="look"?await this.#f(a):await a.adapter.apply.guard(a.intent,a.plan,i)}catch(g){if(n.length>0&&!this.#n())return{active:n,blocked:null,unseen:null};throw s.member=o,g}if(d.kind==="local-change"||d.kind==="unsettled-ground")return{active:n,blocked:n.length===0?I:null,unseen:a};if(D(d))return{active:n,blocked:n.length===0?I:null,unseen:null};const y=A(d);if(y)return{active:n,blocked:y,unseen:null};a.look=d.kind,n.push(o)}return{active:n,blocked:null,unseen:null}}async#u(e,t,i){for(const[s,n]of e.entries()){const o=t.get(n.work.entityId);if(!(!o||o.look!=="safe"))try{const a=await o.adapter.apply.prepare(o.intent,o.plan);if(a)return{active:e.slice(0,s),blocked:A(a)}}catch(a){if(s>0&&!this.#n())return{active:e.slice(0,s),blocked:null};throw i.member=n,a}}return{active:[...e],blocked:null}}async#p(e,t){const i=t.members.map(n=>{const o=e.members.find(d=>d.work.entityId===n.entityId);if(!o)return null;const a=n.kept===null?o.work:{...o.work,records:[],kept:n.kept};return a.records.length===0&&a.kept===null?null:(0,q.planSelectedEntityApply)(a,(0,E.selectEntityApply)(a,this.#r,n),this.#e.sha256Hex)}),s=await this.#e.effects.recover(t,i);if(s.length!==t.members.length)throw new Error("Apply recovery answered for a different window");return this.#t(t,e.members,e.members.map(n=>v(n)??s[t.members.findIndex(o=>o.entityId===n.work.entityId)]??{kind:"owed",reason:"not a member of the bound window"}))}async#t(e,t,i){const s=await this.#e.store.endWindow(e,t,i);if(!s)return"progress";if(s.kind!=="stale"||!s.reason)throw new Error("Apply end commit returned an unknown refusal");return I}async#i(e){return(0,M.localWorkWins)(e.targetType,await this.#e.store.localWorkAfter(e.authorityId,e.entityId,e.kept??e.throughSequence))}async#f(e){const{intent:t,plan:i,adapter:s}=e,n=await s.apply.guard(t,i,"look");if(n.kind!=="local-change"&&n.kind!=="unsettled-ground")return n;const o=await this.#l(t,i);if(o.kind!=="observed")return o;const a=await s.apply.guard(t,i,"look");return a.kind==="local-change"||a.kind==="unsettled-ground"?{kind:"retry",reason:"Ground still needs observation after Detect; this member cannot reveal."}:a}async#y(e){const t=await this.#l(e.intent,e.plan);return t.kind==="captured-local"?I:A(t.kind==="observed"?{kind:"retry",reason:"Its final guard found ground Detect had not recorded; it is judged again after Detect looks."}:t)}async#l(e,t){if(await this.#i(e))return{kind:"captured-local"};let i,s=!0;const n=await this.#e.effects.captureLocal(e,t,()=>{if(!s||i!==void 0)throw new Error("Apply capture comparison must be marked exactly once");i=this.#s()}).finally(()=>{s=!1});if(!n||!["settled","local-only","retry"].includes(n.kind))throw new Error("Apply capture returned no explicit observation outcome");if(await this.#i(e))return{kind:"captured-local"};if(n.kind==="retry")return n;if(n.kind==="local-only"){if(i===void 0)throw new Error("local-only capture requires a synchronous comparison fence");if(!n.reason||n.entityIds.length===0||n.entityIds.some(o=>!o))throw new Error("local-only capture must name the retained ground and its releasing condition");return{kind:"dependency",reason:n.reason,comparedAt:i,waitFor:{producer:"detect",entityIds:n.entityIds}}}return{kind:"observed"}}}exports.EntityApplyJourney=U;
1
+ "use strict";var x=Object.defineProperty;var m=(l,e)=>x(l,"name",{value:e,configurable:!0});Object.defineProperty(exports,"__esModule",{value:!0}),exports.EntityApplyJourney=void 0,exports.stepsAside=P,exports.outcomeOf=H;const j=require("./contracts.js"),q=require("./plans.js"),S=require("../faults/recover.js"),O=require("../faults/classify.js"),M=require("../clash/local-work.js"),E=require("./selection.js"),W=require("./settling.js"),F=require("./window.js");function P(l,e){return l.unit===null&&l.authorityId!==e}m(P,"stepsAside");const I={kind:"park",reason:"its window ended with its head unplaced and named no wait",releaseOnProgress:!1,report:!1,again:!0},D=m(l=>l.kind==="captured-local"||l.kind==="rejudge","drops");function A(l){return l.kind==="retry"?{kind:"park",reason:l.reason??"machine truth is unsettled",releaseOnProgress:!1,report:!1}:l.kind==="dependency"?{kind:"park",reason:l.reason,releaseOnProgress:l.waitFor===void 0,report:!1,...l.waitFor?{dependency:l.waitFor}:{},...l.blocker?{blocker:l.blocker}:{},..."comparedAt"in l?{comparedAt:l.comparedAt}:{}}:l.kind==="conflict"?{kind:"park",reason:l.reason,releaseOnProgress:!0,report:!0}:null}m(A,"parkFor");async function H(l){try{return await l()}catch(e){return{kind:"park",reason:e instanceof Error?e.message:String(e),releaseOnProgress:!1,report:!(0,O.groundMoved)(e),cause:e}}}m(H,"outcomeOf");const v=m(l=>(0,W.isSettlement)(l.judgment)?{kind:"settled",settlement:l.judgment}:null,"settled");class U{static{m(this,"EntityApplyJourney")}#e;#r;#s;#n;constructor(e,t,s){this.#e=e,this.#r={sha256Hex:e.sha256Hex,loops:e.loops,deliveryPosition:e.deliveryPosition},this.#s=t,this.#n=s}targetOf(e){const t=e.members[0];return t===void 0?null:e.intent?.members.find(s=>s.entityId===t.work.entityId)?.throughSequence??(t.work.kept===null?t.work.records.at(-1)?.globalSequence:t.work.resolvedThrough)??null}async run(e,t){if(e.intent!==null)return this.#p(e,e.intent);const s={member:null};try{return await this.#d(e,t,s)}catch(i){if(s.member===null||this.#n())throw i;if((0,O.groundMoved)(i))return{kind:"park",reason:i instanceof Error?i.message:String(i),releaseOnProgress:!1,report:!1};if(P(e,s.member.work.entityId))return this.alone(e,s.member);if(i instanceof S.Recovering)return{kind:"park",reason:i.message,releaseOnProgress:!1,report:!1,dependency:{producer:"capability",entityIds:i.need.subject===null?[]:[i.need.subject.id]}};throw i}}async alone(e,t=e.members[0]){const{target:s}=(0,E.selectEntityApply)(t.work,this.#r),i=await this.#i({authorityId:t.work.authorityId,entityId:t.work.entityId,targetType:s.result.type,kept:s.record===null?s.result:null,throughSequence:s.throughSequence}),n=await this.#t(e.intent,[t],[{kind:"settled",settlement:i?"superseded":"waiting"}]);return n==="progress"&&!i?{kind:"alone",entityId:t.work.entityId}:n}async#d(e,t,s){const i=this.#e.newIntentId(),n=this.#e.now(),o=t(),a=new Map;for(const c of e.members){if(v(c))continue;const{work:f}=c,w=(0,E.selectEntityApply)(f,this.#r),b=(0,j.createApplyIntent)({attemptId:i,work:f,target:w.target,unit:e.unit,cutoff:e.cutoff,createdAt:n,emptied:f.entityId===o&&f.play==="enter"&&(w.target.result.type==="file.text"||w.target.result.type==="file.binary")}),h=(0,q.planSelectedEntityApply)(f,w,this.#e.sha256Hex);a.set(f.entityId,{member:c,intent:b,plan:h,adapter:this.#e.effects.adapterFor(h.target.type),look:"safe"})}const{active:d,blocked:y}=await this.#o(e.members,a,"look",s);if(d.length===0)return y??I;const g=d.flatMap(c=>a.get(c.work.entityId)??[]);if(g.length===0)return this.#t(null,d,d.map(c=>v(c)));const k=(0,j.createApplyWindowIntent)({attemptId:i,authorityId:e.authorityId,unit:e.unit,cutoff:e.cutoff,createdAt:n,members:g.map(c=>c.intent)});try{const c=await this.#u(d,a,s),f=c.active.flatMap(r=>a.get(r.work.entityId)??[]);if(f.length===0)return await this.#e.effects.discard(k),c.active.length===0?c.blocked??I:this.#t(null,c.active,c.active.map(r=>v(r)));const w=f.length===g.length?k:(0,j.createApplyWindowIntent)({...k,members:f.map(r=>r.intent)}),b=await this.#e.effects.hold(w,f.map(r=>r.plan));let h,_;try{h=await this.#o(c.active,a,"final",s),_=await this.#c(w,h,a,t)}finally{b()}return h.unseen!==null&&h.active.length===0?this.#y(h.unseen):_}catch(c){throw await this.#e.effects.discard(k),c}}async#c(e,{active:t,blocked:s},i,n){const o=t.flatMap(r=>i.get(r.work.entityId)??[]);if(o.length===0)return await this.#e.effects.discard(e),t.length===0?s??I:this.#t(null,t,t.map(r=>v(r)));const a=(0,j.createApplyWindowIntent)({...e,members:o.map(r=>r.intent)}),d=o.filter(r=>r.look==="safe");if(d.length>0){if(this.#n()||o.some(p=>p.intent.emptied&&n()!==p.intent.entityId))return await this.#e.effects.discard(e),I;const r=await this.#e.store.bindWindow(a);if(r)return await this.#e.effects.discard(e),r.kind==="stale"?I:A({...r,comparedAt:this.#s()})}const y=new Map,g=new Map,k=m((r,p,u=null)=>{y.set(r,{kind:"owed",reason:p}),u!==null&&g.set(r,u)},"owe"),c=m(r=>A(r.kind==="dependency"?{...r,comparedAt:this.#s()}:r),"waitFrom"),{order:f,cycle:w}=(0,F.revealOrder)(d.map(r=>({entityId:r.intent.entityId,play:r.plan.play,type:r.plan.target.type,parentUUID:r.plan.target.parentUUID}))),b="its parent chain closes among the window's members";for(const r of w)k(r,b,{kind:"park",reason:b,releaseOnProgress:!1,report:!0});for(const r of f){const p=i.get(r),u=await p.adapter.apply.reveal(p.intent,p.plan);u&&k(r,u.reason,u.kind==="dependency"?c(u):null)}for(const r of o){const p=r.intent.entityId;if(y.has(p))continue;const u=await r.adapter.verify.verify(r.intent,r.plan);u.kind==="match"?y.set(p,{kind:"materialized"}):u.kind==="local-change"?k(p,"a person's version stands in its place"):u.kind==="rejudge"||u.kind==="missing-target"?k(p,u.kind):k(p,u.reason??u.kind,c(u))}const h=t.map(r=>v(r)??y.get(r.work.entityId));if(d.length>0)return this.#a(a,t,h,g);const _=await this.#a(null,t,h,g);return await this.#e.effects.discard(e),_}async#a(e,t,s,i){const n=await this.#t(e,t,s),o=s[0];return n!=="progress"||o.kind!=="owed"?n:{...i.get(t[0].work.entityId)??{kind:"park",reason:o.reason,releaseOnProgress:!1,report:!1,again:!0},advanced:t.filter((d,y)=>s[y].kind!=="owed").map(d=>d.work.entityId)}}async#o(e,t,s,i){const n=[];for(const o of e){const a=t.get(o.work.entityId);if(!a){n.push(o);continue}let d;try{d=await this.#i(a.intent)?{kind:"captured-local"}:s==="look"?await this.#f(a):await a.adapter.apply.guard(a.intent,a.plan,s)}catch(g){if(n.length>0&&!this.#n())return{active:n,blocked:null,unseen:null};throw i.member=o,g}if(d.kind==="local-change"||d.kind==="unsettled-ground")return{active:n,blocked:n.length===0?I:null,unseen:a};if(D(d))return{active:n,blocked:n.length===0?I:null,unseen:null};const y=A(d);if(y)return{active:n,blocked:y,unseen:null};a.look=d.kind,n.push(o)}return{active:n,blocked:null,unseen:null}}async#u(e,t,s){for(const[i,n]of e.entries()){const o=t.get(n.work.entityId);if(!(!o||o.look!=="safe"))try{const a=await o.adapter.apply.prepare(o.intent,o.plan);if(a)return{active:e.slice(0,i),blocked:A(a)}}catch(a){if(i>0&&!this.#n())return{active:e.slice(0,i),blocked:null};throw s.member=n,a}}return{active:[...e],blocked:null}}async#p(e,t){const s=t.members.map(n=>{const o=e.members.find(d=>d.work.entityId===n.entityId);if(!o)return null;const a=n.kept===null?o.work:{...o.work,records:[],kept:n.kept};return a.records.length===0&&a.kept===null?null:(0,q.planSelectedEntityApply)(a,(0,E.selectEntityApply)(a,this.#r,n),this.#e.sha256Hex)}),i=await this.#e.effects.recover(t,s);if(i.length!==t.members.length)throw new Error("Apply recovery answered for a different window");return this.#t(t,e.members,e.members.map(n=>v(n)??i[t.members.findIndex(o=>o.entityId===n.work.entityId)]??{kind:"owed",reason:"not a member of the bound window"}))}async#t(e,t,s){const i=await this.#e.store.endWindow(e,t,s);if(!i)return"progress";if(i.kind!=="stale"||!i.reason)throw new Error("Apply end commit returned an unknown refusal");return I}async#i(e){return(0,M.localWorkWins)(e.targetType,await this.#e.store.localWorkAfter(e.authorityId,e.entityId,e.kept??e.throughSequence))}async#f(e){const{intent:t,plan:s,adapter:i}=e,n=await i.apply.guard(t,s,"look");if(n.kind!=="local-change"&&n.kind!=="unsettled-ground")return n;const o=await this.#l(t,s);if(o.kind!=="observed")return o;const a=await i.apply.guard(t,s,"look");return a.kind==="local-change"||a.kind==="unsettled-ground"?{kind:"retry",reason:"Ground still needs observation after Detect; this member cannot reveal."}:a}async#y(e){const t=await this.#l(e.intent,e.plan);return t.kind==="captured-local"?I:A(t.kind==="observed"?{kind:"retry",reason:"Its final guard found ground Detect had not recorded; it is judged again after Detect looks."}:t)}async#l(e,t){if(await this.#i(e))return{kind:"captured-local"};let s,i=!0;const n=await this.#e.effects.captureLocal(e,t,()=>{if(!i||s!==void 0)throw new Error("Apply capture comparison must be marked exactly once");s=this.#s()}).finally(()=>{i=!1});if(!n||!["settled","local-only","retry"].includes(n.kind))throw new Error("Apply capture returned no explicit observation outcome");if(await this.#i(e))return{kind:"captured-local"};if(n.kind==="retry")return n;if(n.kind==="local-only"){if(s===void 0)throw new Error("local-only capture requires a synchronous comparison fence");if(!n.reason||n.entityIds.length===0||n.entityIds.some(o=>!o))throw new Error("local-only capture must name the retained ground and its releasing condition");return{kind:"dependency",reason:n.reason,comparedAt:s,waitFor:{producer:"detect",entityIds:n.entityIds}}}return{kind:"observed"}}}exports.EntityApplyJourney=U;
@@ -1 +1 @@
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=p,exports.heldWait=f,exports.assertApplyDependency=m,exports.assertApplyLineStep=A,exports.assertApplyWindow=s;const u=require("../entities/types.js");function d(e){return{kind:"line",authorityId:e,held:null,queued:!1,running:!1,again:!1}}i(d,"createApplyLine");function p(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(p,"releaseApplyLine");function f(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(f,"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");
1
+ "use strict";var d=Object.defineProperty;var i=(e,n)=>d(e,"name",{value:n,configurable:!0});Object.defineProperty(exports,"__esModule",{value:!0}),exports.invalidStep=void 0,exports.createApplyLine=f,exports.releaseApplyLine=p,exports.heldWait=c,exports.assertApplyDependency=S,exports.assertApplyLineStep=m,exports.assertApplyWindow=s;const o=require("../entities/types.js");function f(e){return{kind:"line",authorityId:e,held:null,queued:!1,running:!1,again:!1}}i(f,"createApplyLine");function p(e,n,u){const r=e.held;return!r?.dependency||r.due||r.dependency.producer!==n||u!==void 0&&!r.dependency.entityIds.some(l=>u.includes(l))?!1:(r.due=!0,!0)}i(p,"releaseApplyLine");function c(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(c,"heldWait");const y=new Set(["detect","apply","capability","send"]),A=i(e=>!!e&&y.has(e.producer)&&Array.isArray(e.entityIds)&&e.entityIds.length>0&&e.entityIds.every(n=>typeof n=="string"&&n.length>0),"namesRelease");function S(e){if(!A(e))throw new Error("Apply dependency must name the entities that can release it")}i(S,"assertApplyDependency");function m(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(u=>u.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(m,"assertApplyLineStep");const w=i(e=>{throw new Error(`entity Apply store returned an invalid ${e}`)},"invalidStep");exports.invalidStep=w;function s(e,n){Array.isArray(e.members)||(0,exports.invalidStep)(n);const u=i((t,a)=>Number.isSafeInteger(t)&&t>=(a?0:1),"at");for(const t of e.members)(!o.UUID_PATTERN.test(t.work?.entityId??"")||t.work.authorityId!==e.authorityId||!u(t.deliverySequence,t.work.kept!==null))&&(0,exports.invalidStep)(n),(t.unseen!==void 0||t.judgment==="unseen")&&(o.UUID_PATTERN.test(t.unseen??"")||(0,exports.invalidStep)(n));const{deliverySequence:r}=e,l=e.members[0];(r===null?!e.intent:l===void 0||!u(r,l.work.kept!==null))&&(0,exports.invalidStep)(n)}i(s,"assertApplyWindow");
@@ -1 +1 @@
1
- "use strict";var I=Object.defineProperty;var o=(a,e)=>I(a,"name",{value:e,configurable:!0});Object.defineProperty(exports,"__esModule",{value:!0}),exports.EntityApplyRail=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"),_=require("./fetch-ahead.js"),c=require("./journey.js"),g=require("./lane.js"),l=require("./line.js");exports.ENTITY_APPLY_DEFAULT_CONCURRENCY=8,exports.ENTITY_APPLY_RETRY_BASE_MS=1e3,exports.ENTITY_APPLY_RETRY_MAX_MS=3e4;function E(a,e){return e.cause===void 0&&(0,c.stepsAside)(a,a.members[0].work.entityId)}o(E,"stuck");class k{static{o(this,"EntityApplyRail")}#e;#g;#P;#Y;#M;#a;#T;#o=!1;#t=!1;#d=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;#b=new Map;#y=null;constructor(e){this.#e=e,this.#g=e.concurrency??exports.ENTITY_APPLY_DEFAULT_CONCURRENCY,this.#P=e.laneConcurrency??this.#g,this.#Y=e.onBackgroundError??(()=>{}),this.#M=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.#a=new c.EntityApplyJourney(e,()=>this.#A,()=>this.#t),this.#T=new _.FetchAhead(e.cargo,{sha256Hex:e.sha256Hex,loops:e.loops,deliveryPosition:e.deliveryPosition})}async start(){if(this.#o)throw new Error("entity Apply rail already started");if(this.#t)throw new Error("entity Apply rail is stopped");this.#o=!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.#E(t,null);await this.#N()}fetch(e,t){return this.#o?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 r=this.#E(e,null,t.emptied===!0),n=o(()=>this.#e.schedule.schedule(t.stall,()=>{r.waiters.delete(u)&&(r.emptied&&![...r.waiters].some(d=>d.emptied)&&(r.emptied=!1),s(this.#G(r)))}),"arm");let h=n();const u={emptied:t.emptied===!0,answer:o(d=>{h.cancel(),s(d)},"answer"),fail:o(d=>{h.cancel(),i(d)},"fail"),moved:o(()=>{h.cancel(),h=n()},"moved")};r.waiters.add(u),r.waitsOn===null&&this.#U(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(!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.#k(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=>!f.UUID_PATTERN.test(t)))throw new Error("entity Apply owe needs entity UUIDs");if(!(!this.#o||this.#t)){for(const t of e)this.#O(t);this.#r()}}#I(){!this.#o||this.#t||(this.#n=!0,this.#r())}waiting(){return this.#w().flatMap(e=>(0,l.heldWait)(e.held,y(e))??[])}async flush(){if(!this.#o)throw new Error("entity Apply rail has not started");this.#t||await this.#N()}async stop(){if(this.#t)return;this.#t=!0,this.#S();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.#$()>0||this.#h;)await Promise.allSettled([...this.#l.steps,...this.#u.steps,...this.#h?[this.#h]:[]]);await this.#T.stop();for(const t of this.#m.splice(0))t.resolve()}#N(){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.#z(s,e)}if(this.#$()===0&&this.#h===null&&!this.#n&&this.#l.queue.length===0&&this.#u.queue.length===0){if(this.#b.clear(),this.#W(this.#e.now())){this.#r();return}this.#v();for(const e of this.#m.splice(0))e.resolve();this.#M()}}}#$(){return this.#l.steps.size+this.#u.steps.size}#w(){return[...this.#d.values(),...this.#s.values()]}#_(e){return e.kind==="line"?this.#d.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))}}#z(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.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.#d)!t.has(s)&&!i.running&&!i.queued&&this.#d.delete(s);for(const s of e){let i=this.#d.get(s);i||(i=(0,l.createApplyLine)(s),this.#d.set(s,i)),this.#i(i)}}catch(e){this.#p=this.#e.now()+exports.ENTITY_APPLY_RETRY_MAX_MS;const t=this.#m.splice(0);t.length===0&&this.#R(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.#A,i=await this.#e.store.readApplyWindow(e.authorityId);return(0,l.assertApplyLineStep)(e.authorityId,i),this.#t?!1:i.kind==="end"?(e.held=null,!1):(i.window.deliverySequence!==null&&this.#T.advance(e.authorityId,i.window.deliverySequence),await this.#j(e,i.window,s))}catch(t){return this.#B(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.#A,i=await this.#e.store.readFetchWindow(e.unit,e.toPrefix?null:e.through);if((0,g.assertApplyLaneStep)(e.unit,i),this.#t||!this.#_(e))return!1;if(e.waitsOn=null,i.kind==="unseen")return this.#q(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.#H(e,i.through,i.reason);case"prerequisite":return this.#V(e,i.unit,i.reason,s);case"window":return await this.#j(e,i.window,s)}}catch(t){return this.#B(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)?!1:(e.through===t&&e.met.add(e.unit),this.#k(e.unit),!0))}#O(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=(0,g.createApplyLane)(e,t,s),this.#s.set(e,i),this.#i(i)),i}#V(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.#q(e,{producer:"apply",entityIds:[t]},s,i):!1}#q(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}#U(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.#_(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.#k(e.unit),this.#c("apply",[e.unit]))}#k(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#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.#Q(e,t))return!1;let r=await(0,c.outcomeOf)(()=>this.#a.run(t,()=>e.kind==="lane"&&e.emptied?e.unit:null));if(e.kind==="line"&&!this.#t&&typeof r=="object"&&r.kind==="park"&&E(t,r)&&(r=await(0,c.outcomeOf)(()=>this.#a.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.#O(n.work.entityId);for(const n of t.members)n.unseen!==void 0&&this.#O(n.unseen);return this.#Z(e,r==="progress"?t.members.map(n=>n.work.entityId):[r.entityId])}return r.advanced?.length&&this.#C(e,r.advanced),this.#ee(e,t,r,s),e.kind==="lane"&&this.#U(e),e.held.due}#K(e,t){const s=e.held,i=t.members[0].work.entityId;return(s?.entityId===i&&s.target===this.#a.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.#a.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.#C(e,t),!0}#C(e,t){e.kind==="lane"&&(this.#n=!0,this.#k(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 r=t.members[0].work.entityId,n=e.held,h=this.#K(e,t),u=this.#D(h),d=s.again===!0&&h===1,w={entityId:r,target:this.#a.targetOf(t),kept:t.members[0].work.kept,cutoff:t.cutoff,attempt:h,notBefore:s.dependency?1/0:this.#e.now()+(d?0:u),releaseOnProgress:s.releaseOnProgress,due:s.dependency?this.#x(s.dependency,s.comparedAt??i):d,reason:s.reason,...s.dependency?{dependency:s.dependency}:{},...s.blocker?{blocker:s.blocker}:{}};e.held=w,this.#v();const A=(0,l.heldWait)(n,y(e)),p=(0,l.heldWait)(w,y(e));p&&JSON.stringify(p)!==JSON.stringify(A)&&this.#e.onWaiting?.(p),!(!s.report&&(s.dependency!==void 0||h===1))&&this.#R(new Error(`${m(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 ${u}ms (attempt ${h}): ${s.reason}`,s.cause===void 0?void 0:{cause:s.cause}))}#B(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.#D(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.#v(),this.#R(new Error(`${m(e)} faulted and will retry in ${r}ms (attempt ${i}): ${n}`,{cause:t}))}#R(e){try{this.#Y(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.#A;for(const i of t??["*"])this.#b.set(`${e}:${i}`,s);for(const i of this.#w())(0,l.releaseApplyLine)(i,e,t)&&this.#i(i)}#x(e,t){return["*",...e.entityIds].some(s=>(this.#b.get(`${e.producer}:${s}`)??0)>t)}#v(){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.#S();return}if(this.#y?.dueAt===e)return;this.#S();const t=Math.max(0,e-this.#e.now()),s=this.#e.schedule.schedule(t,()=>{this.#y=null,this.#W(e),this.#r()});this.#y={dueAt:e,cancel:o(()=>s.cancel(),"cancel")}}#W(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}#S(){this.#y?.cancel(),this.#y=null}}exports.EntityApplyRail=k;const y=o(a=>a.kind==="line"?a.authorityId:a.unit,"owner"),m=o(a=>a.kind==="line"?`entity Apply line ${a.authorityId}`:`entity Apply fetch of ${a.unit}`,"label");
1
+ "use strict";var I=Object.defineProperty;var o=(a,e)=>I(a,"name",{value:e,configurable:!0});Object.defineProperty(exports,"__esModule",{value:!0}),exports.EntityApplyRail=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"),_=require("./fetch-ahead.js"),c=require("./journey.js"),g=require("./lane.js"),l=require("./line.js");exports.ENTITY_APPLY_DEFAULT_CONCURRENCY=8,exports.ENTITY_APPLY_RETRY_BASE_MS=1e3,exports.ENTITY_APPLY_RETRY_MAX_MS=3e4;function E(a,e){const t=a.members[0];return e.cause===void 0&&t!==void 0&&(0,c.stepsAside)(a,t.work.entityId)}o(E,"stuck");class k{static{o(this,"EntityApplyRail")}#e;#g;#P;#Y;#M;#a;#T;#o=!1;#t=!1;#d=new Map;#s=new Map;#l={queue:[],steps:new Set};#u={queue:[],steps:new Set};#r=!1;#h=null;#p=1/0;#m=[];#A=0;#b=new Map;#y=null;constructor(e){this.#e=e,this.#g=e.concurrency??exports.ENTITY_APPLY_DEFAULT_CONCURRENCY,this.#P=e.laneConcurrency??this.#g,this.#Y=e.onBackgroundError??(()=>{}),this.#M=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.#a=new c.EntityApplyJourney(e,()=>this.#A,()=>this.#t),this.#T=new _.FetchAhead(e.cargo,{sha256Hex:e.sha256Hex,loops:e.loops,deliveryPosition:e.deliveryPosition})}async start(){if(this.#o)throw new Error("entity Apply rail already started");if(this.#t)throw new Error("entity Apply rail is stopped");this.#o=!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.#E(t,null);await this.#N()}fetch(e,t){return this.#o?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.#E(e,null,t.emptied===!0),r=o(()=>this.#e.schedule.schedule(t.stall,()=>{n.waiters.delete(u)&&(n.emptied&&![...n.waiters].some(d=>d.emptied)&&(n.emptied=!1),s(this.#G(n)))}),"arm");let h=r();const u={emptied:t.emptied===!0,answer:o(d=>{h.cancel(),s(d)},"answer"),fail:o(d=>{h.cancel(),i(d)},"fail"),moved:o(()=>{h.cancel(),h=r()},"moved")};n.waiters.add(u),n.waitsOn===null&&this.#U(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.#k(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=>!f.UUID_PATTERN.test(t)))throw new Error("entity Apply owe needs entity UUIDs");if(!(!this.#o||this.#t)){for(const t of e)this.#O(t);this.#n()}}#I(){!this.#o||this.#t||(this.#r=!0,this.#n())}waiting(){return this.#w().flatMap(e=>(0,l.heldWait)(e.held,w(e))??[])}async flush(){if(!this.#o)throw new Error("entity Apply rail has not started");this.#t||await this.#N()}async stop(){if(this.#t)return;this.#t=!0,this.#S();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.#$()>0||this.#h;)await Promise.allSettled([...this.#l.steps,...this.#u.steps,...this.#h?[this.#h]:[]]);await this.#T.stop();for(const t of this.#m.splice(0))t.resolve()}#N(){return new Promise((e,t)=>{this.#m.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.#F();this.#h=e,e.then(()=>{this.#h=null,this.#n()})}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.#z(s,e)}if(this.#$()===0&&this.#h===null&&!this.#r&&this.#l.queue.length===0&&this.#u.queue.length===0){if(this.#b.clear(),this.#W(this.#e.now())){this.#n();return}this.#v();for(const e of this.#m.splice(0))e.resolve();this.#M()}}}#$(){return this.#l.steps.size+this.#u.steps.size}#w(){return[...this.#d.values(),...this.#s.values()]}#_(e){return e.kind==="line"?this.#d.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))}}#z(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.again=!1,this.#i(e)),this.#n()});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.#d)!t.has(s)&&!i.running&&!i.queued&&this.#d.delete(s);for(const s of e){let i=this.#d.get(s);i||(i=(0,l.createApplyLine)(s),this.#d.set(s,i)),this.#i(i)}}catch(e){this.#p=this.#e.now()+exports.ENTITY_APPLY_RETRY_MAX_MS;const t=this.#m.splice(0);t.length===0&&this.#R(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.#A,i=await this.#e.store.readApplyWindow(e.authorityId);return(0,l.assertApplyLineStep)(e.authorityId,i),this.#t?!1:i.kind==="end"?(e.held=null,!1):(i.window.deliverySequence!==null&&this.#T.advance(e.authorityId,i.window.deliverySequence),await this.#j(e,i.window,s))}catch(t){return this.#B(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.#A,i=await this.#e.store.readFetchWindow(e.unit,e.toPrefix?null:e.through);if((0,g.assertApplyLaneStep)(e.unit,i),this.#t||!this.#_(e))return!1;if(e.waitsOn=null,i.kind==="unseen")return this.#q(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.#H(e,i.through,i.reason);case"prerequisite":return this.#V(e,i.unit,i.reason,s);case"window":return await this.#j(e,i.window,s)}}catch(t){return this.#B(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)?!1:(e.through===t&&e.met.add(e.unit),this.#k(e.unit),!0))}#O(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=(0,g.createApplyLane)(e,t,s),this.#s.set(e,i),this.#i(i)),i}#V(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.#q(e,{producer:"apply",entityIds:[t]},s,i):!1}#q(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}#U(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 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.#E(t,e.through)),!0}#f(e,t){if(!this.#_(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.#k(e.unit),this.#c("apply",[e.unit]))}#k(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#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.#Q(e,t))return!1;let n=await(0,c.outcomeOf)(()=>this.#a.run(t,()=>e.kind==="lane"&&e.emptied?e.unit:null));if(e.kind==="line"&&!this.#t&&typeof n=="object"&&n.kind==="park"&&E(t,n)&&(n=await(0,c.outcomeOf)(()=>this.#a.alone(t))),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.#O(r.work.entityId);for(const r of t.members)r.unseen!==void 0&&this.#O(r.unseen);return this.#Z(e,n!=="progress"?[n.entityId]:t.intent?.members.map(r=>r.entityId)??t.members.map(r=>r.work.entityId))}return n.advanced?.length&&this.#C(e,n.advanced),this.#ee(e,t,n,s),e.kind==="lane"&&this.#U(e),e.held.due}#K(e,t){const s=e.held,i=t.members[0]?.work.entityId??null;return(s?.entityId===i&&s.target===this.#a.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.#a.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.#C(e,t),!0}#C(e,t){e.kind==="lane"&&(this.#r=!0,this.#k(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],r=e.held,h=this.#K(e,t),u=this.#D(h),d=s.again===!0&&h===1,p={entityId:n?.work.entityId??null,target:this.#a.targetOf(t),kept:n?.work.kept??null,cutoff:t.cutoff,attempt:h,notBefore:s.dependency?1/0:this.#e.now()+(d?0:u),releaseOnProgress:s.releaseOnProgress,due:s.dependency?this.#x(s.dependency,s.comparedAt??i):d,reason:s.reason,...s.dependency?{dependency:s.dependency}:{},...s.blocker?{blocker:s.blocker}:{}};e.held=p,this.#v();const A=(0,l.heldWait)(r,w(e)),y=(0,l.heldWait)(p,w(e));y&&JSON.stringify(y)!==JSON.stringify(A)&&this.#e.onWaiting?.(y),!(!s.report&&(s.dependency!==void 0||h===1))&&this.#R(new Error(`${m(e)} holds at ${p.entityId??"its open window"}, 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}))}#B(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.#v(),this.#R(new Error(`${m(e)} faulted and will retry in ${n}ms (attempt ${i}): ${r}`,{cause:t}))}#R(e){try{this.#Y(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.#A;for(const i of t??["*"])this.#b.set(`${e}:${i}`,s);for(const i of this.#w())(0,l.releaseApplyLine)(i,e,t)&&this.#i(i)}#x(e,t){return["*",...e.entityIds].some(s=>(this.#b.get(`${e.producer}:${s}`)??0)>t)}#v(){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.#S();return}if(this.#y?.dueAt===e)return;this.#S();const t=Math.max(0,e-this.#e.now()),s=this.#e.schedule.schedule(t,()=>{this.#y=null,this.#W(e),this.#n()});this.#y={dueAt:e,cancel:o(()=>s.cancel(),"cancel")}}#W(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}#S(){this.#y?.cancel(),this.#y=null}}exports.EntityApplyRail=k;const w=o(a=>a.kind==="line"?a.authorityId:a.unit,"owner"),m=o(a=>a.kind==="line"?`entity Apply line ${a.authorityId}`:`entity Apply fetch of ${a.unit}`,"label");
@@ -1 +1 @@
1
- "use strict";var o=Object.defineProperty;var u=(i,r)=>o(i,"name",{value:r,configurable:!0});var f=exports&&exports.__createBinding||(Object.create?(function(i,r,t,n){n===void 0&&(n=t);var a=Object.getOwnPropertyDescriptor(r,t);(!a||("get"in a?!r.__esModule:a.writable||a.configurable))&&(a={enumerable:!0,get:u(function(){return r[t]},"get")}),Object.defineProperty(i,n,a)}):(function(i,r,t,n){n===void 0&&(n=t),i[n]=r[t]})),e=exports&&exports.__exportStar||function(i,r){for(var t in i)t!=="default"&&!Object.prototype.hasOwnProperty.call(r,t)&&f(r,i,t)};Object.defineProperty(exports,"__esModule",{value:!0}),exports.gitPartsChanged=exports.gitParts=exports.gitPartBlobs=exports.GIT_PARTS=exports.compareGitText=void 0,e(require("./state.js"),exports),e(require("./alternates.js"),exports),e(require("./disk-settings.js"),exports);var g=require("./text.js");Object.defineProperty(exports,"compareGitText",{enumerable:!0,get:u(function(){return g.compareGitText},"get")}),e(require("./artifact.js"),exports),e(require("./chain.js"),exports),e(require("./plan.js"),exports),e(require("./play.js"),exports),e(require("./tag.js"),exports),e(require("./turns.js"),exports),e(require("./holds.js"),exports),e(require("./checkout.js"),exports),e(require("./checkout-view.js"),exports),e(require("./places.js"),exports);var c=require("./parts.js");Object.defineProperty(exports,"GIT_PARTS",{enumerable:!0,get:u(function(){return c.GIT_PARTS},"get")}),Object.defineProperty(exports,"gitPartBlobs",{enumerable:!0,get:u(function(){return c.gitPartBlobs},"get")}),Object.defineProperty(exports,"gitParts",{enumerable:!0,get:u(function(){return c.gitParts},"get")}),Object.defineProperty(exports,"gitPartsChanged",{enumerable:!0,get:u(function(){return c.gitPartsChanged},"get")}),e(require("./restore.js"),exports);
1
+ "use strict";var c=Object.defineProperty;var i=(n,r)=>c(n,"name",{value:r,configurable:!0});var o=exports&&exports.__createBinding||(Object.create?(function(n,r,t,u){u===void 0&&(u=t);var a=Object.getOwnPropertyDescriptor(r,t);(!a||("get"in a?!r.__esModule:a.writable||a.configurable))&&(a={enumerable:!0,get:i(function(){return r[t]},"get")}),Object.defineProperty(n,u,a)}):(function(n,r,t,u){u===void 0&&(u=t),n[u]=r[t]})),e=exports&&exports.__exportStar||function(n,r){for(var t in n)t!=="default"&&!Object.prototype.hasOwnProperty.call(r,t)&&o(r,n,t)};Object.defineProperty(exports,"__esModule",{value:!0}),exports.gitRefsTravelByMeaning=exports.gitRefsByMeaning=exports.gitPartsChanged=exports.gitParts=exports.gitPartBlobs=exports.GIT_PARTS=exports.compareGitText=void 0,e(require("./state.js"),exports),e(require("./alternates.js"),exports),e(require("./disk-settings.js"),exports);var s=require("./text.js");Object.defineProperty(exports,"compareGitText",{enumerable:!0,get:i(function(){return s.compareGitText},"get")}),e(require("./artifact.js"),exports),e(require("./chain.js"),exports),e(require("./plan.js"),exports),e(require("./play.js"),exports),e(require("./tag.js"),exports),e(require("./turns.js"),exports),e(require("./holds.js"),exports),e(require("./checkout.js"),exports),e(require("./checkout-view.js"),exports),e(require("./places.js"),exports);var g=require("./parts.js");Object.defineProperty(exports,"GIT_PARTS",{enumerable:!0,get:i(function(){return g.GIT_PARTS},"get")}),Object.defineProperty(exports,"gitPartBlobs",{enumerable:!0,get:i(function(){return g.gitPartBlobs},"get")}),Object.defineProperty(exports,"gitParts",{enumerable:!0,get:i(function(){return g.gitParts},"get")}),Object.defineProperty(exports,"gitPartsChanged",{enumerable:!0,get:i(function(){return g.gitPartsChanged},"get")}),e(require("./restore.js"),exports);var f=require("./refs.js");Object.defineProperty(exports,"gitRefsByMeaning",{enumerable:!0,get:i(function(){return f.gitRefsByMeaning},"get")}),Object.defineProperty(exports,"gitRefsTravelByMeaning",{enumerable:!0,get:i(function(){return f.gitRefsTravelByMeaning},"get")});
@@ -1,4 +1,4 @@
1
- "use strict";var fe=Object.defineProperty;var c=(t,i)=>fe(t,"name",{value:i,configurable:!0});Object.defineProperty(exports,"__esModule",{value:!0}),exports.gitOwnChange=se,exports.gitLineChanges=de,exports.gitPlayable=ue,exports.gitPlayRecord=we;const te=require("../entities/bytes.js"),le=require("./alternates.js"),ne=require("./artifact.js"),x=require("./refs.js"),E=require("./state.js"),B=require("./text.js");function se(t){return t.facets.some(f=>f==="create"||f==="retype"||f==="content")&&t.result.status==="active"?t.result.transportVersion:null}c(se,"gitOwnChange");function de(t){let i=[],f=!1;for(const h of t){if(h.result.type!=="repo.git"){i=[],f=!0;continue}const p=se(h);p!==null&&i.push(p)}return{reached:i,ended:f}}c(de,"gitLineChanges");function ue({line:t,basis:i,record:f}){const h=c(l=>l.files.find(a=>a.path===le.GIT_ALTERNATES_PATH)?.oid??null,"borrowed"),p=c(l=>l.files.some(a=>a.path==="reftable"),"reftable");return t.format===f.format&&(i===null||i.format===f.format)&&!(0,E.gitSharesObjects)(t)&&!(0,E.gitSelfHeld)(t.home)&&!(0,E.gitSharesGitDir)(t.home)&&t.home?.entity===f.home?.entity&&t.home?.path===f.home?.path&&h(t)===h(f)&&![t,f,...i?[i]:[]].some(l=>p(l)||(0,E.gitBytesForm)(l))}c(ue,"gitPlayable");const z="040000",F=c(t=>new Map(t.map(i=>[i.path,i])),"byPath"),N=c((t,i)=>t===void 0?i===void 0:i!==void 0&&t.mode===i.mode&&t.oid===i.oid,"same"),oe=c(t=>{const i=[];for(let f=t.indexOf("/");f>0;f=t.indexOf("/",f+1))i.push(t.slice(0,f));return i},"parents");function he(t,i,f){const h=new Set;for(const l of t.keys()){const a=oe(l).find(k=>t.has(k)&&t.get(k).mode!==z);a!==void 0&&h.add(a)}const p=c(l=>h.has(l)||oe(l).some(a=>h.has(a)),"clashed");if(h.size>0){for(const l of[...t.keys()])p(l)&&t.delete(l);for(const[l,a]of i)p(l)&&t.set(l,a)}return(0,E.gitTreeOf)(t.values(),f)}c(he,"asTree");const D=["line","basis","record"],P=c(t=>t.mode!==z&&(t.path==="HEAD"||t.path.startsWith("refs/")),"isLooseRef"),ie=c(t=>P(t)||t.path==="packed-refs","isRefFile"),ge=c(t=>t.startsWith("logs/"),"isReflogPath"),V="refs/stash",J="refs/heads/",K=`${J}amalgm`,me=7,pe=/^[0-9a-f]{7,}$/,Q=c((t,i)=>t.startsWith(`${i}/`),"beneath");async function we(t,i,f,h){const p={format:t.record.format,home:t.record.home,files:[],index:null},l={line:t.line,basis:t.basis??p,record:t.record},a={line:F(l.line.files),basis:F(l.basis.files),record:F(l.record.files)},k=new Map,A=c((e,n)=>{const s=(0,te.utf8Encode)(n),r=(0,ne.gitBlobId)(s,h);return k.set(r,s),{path:e,mode:"100644",oid:r}},"make"),w=c(async e=>e?.oid?(0,te.utf8Decode)(k.get(e.oid)??await i(e.oid)):"","read"),I=new Map,T=c(e=>(I.has(e)||I.set(e,w(a[e].get("packed-refs")).then(x.gitPackedRefs)),I.get(e)),"packedOf"),y=c(async(e,n)=>{const s=a[e].get(n);return s!==void 0&&P(s)?(0,x.gitLooseRef)(await w(s)):n==="HEAD"?null:(await T(e)).get(n)??null},"value"),$=c(e=>!N(a.basis.get(e),a.record.get(e)),"recordChanged"),u=new Map;for(const e of new Set([...a.line.keys(),...a.basis.keys(),...a.record.keys()])){const n=$(e)?a.record.get(e):a.line.get(e);n!==void 0&&u.set(e,n)}const M=new Set;for(const e of new Set(D.flatMap(n=>[...a[n].keys()]))){const[n,s,r]=D.map(o=>a[o].get(e));if(!(N(n,s)&&N(s,r)))if(e==="packed-refs")for(const o of D)for(const d of(await T(o)).keys())M.add(d);else[n,s,r].some(o=>o!==void 0&&P(o))&&M.add(e)}const U=c(async e=>{const[n,s,r]=D.map(o=>a[o].get(e));return[n,s,r].some(o=>o?.mode===z)?w(n):(0,x.gitReflogPlay)(await w(s),await w(r),await w(n))},"playLog"),S=`logs/${V}`;let O=null;$(S)&&(O=(0,x.gitChainReflog)(await U(S)),O===""?u.delete(S):u.set(S,A(S,O)));const m=new Map,j=[];for(const e of[...M].sort(B.compareGitText)){const[n,s,r]=await Promise.all(D.map(d=>y(d,e)));let o=s!==r?r:n;if(e===V){if(O===null)continue;o=(0,x.gitReflogTop)(O)}else e.startsWith(J)&&n!==null&&n!==s&&o!==n&&[n,r].every(d=>d===null||(0,E.isGitOid)(t.record.format,d))&&(r===null||!await f.builtOn(r,n))&&(o=n,r!==null&&!await f.builtOn(n,r)&&j.push({name:e,basis:s,record:r}));o!==n&&m.set(e,o)}const X=[];if(j.length>0){const e=new Map;for(const s of new Set([...a.line.keys(),...(await T("line")).keys(),...m.keys()])){if(s!==K&&!Q(s,K))continue;const r=m.has(s)?m.get(s):await y("line",s);r!==null&&e.set(s,r)}const n=c((s,r)=>(e.get(s)??r)===r&&![...e.keys()].some(o=>Q(s,o)||Q(o,s)),"free");for(const{name:s,basis:r,record:o}of j){const d=`${K}/${s.slice(J.length)}-`;let g=[...e.keys()].sort(B.compareGitText).find(b=>e.get(b)===r&&b.startsWith(d)&&pe.test(b.slice(d.length)));for(let b=me;g===void 0&&b<=o.length;b+=1)n(d+o.slice(0,b),o)&&(g=d+o.slice(0,b));g!==void 0&&(await y("line",g)!==o&&m.set(g,o),e.set(g,o),X.push({branch:g,from:s,commit:o}))}}for(const[e,n]of[...u])ie(n)&&u.delete(e);for(const e of l.line.files)ie(e)&&u.set(e.path,e);const C=new Set;for(const[e,n]of m)n!==null?u.set(e,A(e,`${n}
2
- `)):(u.has(e)&&P(u.get(e))&&u.delete(e),C.add(e));const Y=a.line.get("packed-refs");if(C.size>0&&Y!==void 0){const e=await w(Y),n=(0,x.gitDropPackedRefs)(e,C);n!==e&&u.set("packed-refs",A("packed-refs",n))}const L=c(e=>m.has(e)?Promise.resolve(m.get(e)):y("line",e),"final"),v=c(async(e,n)=>e?.startsWith("ref: ")?n(e.slice(5)):e,"commitOf"),R=await v(await L("HEAD"),L),H=new Set;for(const e of D)for(const n of a[e].keys())ge(n)&&n!==S&&H.add(n);for(const e of m.keys())e!==V&&H.add(`logs/${e}`);R!==await v(await y("line","HEAD"),e=>y("line",e))&&H.add("logs/HEAD");for(const e of[...H].sort(B.compareGitText)){const n=e.slice(5),s=n==="HEAD"?R:await L(n),r=$(e);if(!r&&(s===null||n!=="HEAD"&&!m.has(n)||!a.line.has(e)))continue;let o=r?await U(e):await w(a.line.get(e));const d=(0,x.gitReflogTop)(o);if(s!==null&&d!==null&&d!==s&&(0,E.isGitOid)(t.record.format,s)){const g=o.trimEnd().split(`
3
- `).at(-1);o+=`${d} ${s}${g.slice(g.indexOf(" ",g.indexOf(" ")+1))}
4
- `}o===""?u.delete(e):u.set(e,A(e,o))}const G=c(e=>y(e,"HEAD").then(n=>v(n,s=>y(e,s))),"headOf"),q=c(async e=>{const n=t[e]?.index;return n?.files.length===1?{index:await i(n.files[0].oid),head:await G(e)}:null},"indexOf"),[W,ae,Z,re,ce]=await Promise.all([q("line"),q("basis"),q("record"),t.basis?G("basis"):null,G("record")]),_=t.record.index?.meaning===t.basis?.index?.meaning&&ce===re;let ee=_?t.line.index:t.record.index;if(W!==null&&(_||Z!==null)&&!(_&&W.head===R)){const e=await f.playIndex(W,_?null:ae,_?null:Z,R);if(e!==null){const n=e.bytes,s=(0,ne.gitBlobId)(n,h);k.set(s,n),ee={meaning:e.meaning,files:[{path:"index",mode:"100644",oid:s}]}}}return{state:{format:t.record.format,home:t.record.home,files:he(u,a.record,t.record.home),index:ee},made:k,aside:X}}c(we,"gitPlayRecord");
1
+ "use strict";var le=Object.defineProperty;var c=(t,i)=>le(t,"name",{value:i,configurable:!0});Object.defineProperty(exports,"__esModule",{value:!0}),exports.gitOwnChange=oe,exports.gitLineChanges=ue,exports.gitPlayable=ge,exports.gitPlayRecord=ye;const ne=require("../entities/bytes.js"),de=require("./alternates.js"),se=require("./artifact.js"),x=require("./refs.js"),S=require("./state.js"),z=require("./text.js");function oe(t){return t.facets.some(r=>r==="create"||r==="retype"||r==="content")&&t.result.status==="active"?t.result.transportVersion:null}c(oe,"gitOwnChange");function ue(t){let i=[],r=!1;for(const u of t){if(u.result.type!=="repo.git"){i=[],r=!0;continue}const g=oe(u);g!==null&&i.push(g)}return{reached:i,ended:r}}c(ue,"gitLineChanges");function ge({line:t,basis:i,record:r}){const u=c(f=>f.files.find(m=>m.path===de.GIT_ALTERNATES_PATH)?.oid??null,"borrowed"),g=c(f=>f.files.some(m=>m.path==="reftable"),"reftable");return t.format===r.format&&(i===null||i.format===r.format)&&!(0,S.gitSharesObjects)(t)&&!(0,S.gitSelfHeld)(t.home)&&!(0,S.gitSharesGitDir)(t.home)&&t.home?.entity===r.home?.entity&&t.home?.path===r.home?.path&&u(t)===u(r)&&![t,r,...i?[i]:[]].some(f=>g(f)||(0,S.gitBytesForm)(f))}c(ge,"gitPlayable");const F="040000",N=c(t=>new Map(t.map(i=>[i.path,i])),"byPath"),V=c((t,i)=>t===void 0?i===void 0:i!==void 0&&t.mode===i.mode&&t.oid===i.oid,"same"),ae=c(t=>{const i=[];for(let r=t.indexOf("/");r>0;r=t.indexOf("/",r+1))i.push(t.slice(0,r));return i},"parents");function he(t,i,r){const u=new Set;for(const f of t.keys()){const m=ae(f).find(E=>t.has(E)&&t.get(E).mode!==F);m!==void 0&&u.add(m)}const g=c(f=>u.has(f)||ae(f).some(m=>u.has(m)),"clashed");if(u.size>0){for(const f of[...t.keys()])g(f)&&t.delete(f);for(const[f,m]of i)g(f)&&t.set(f,m)}return(0,S.gitTreeOf)(t.values(),r)}c(he,"asTree");const O=["line","basis","record"],I=c(t=>t.mode!==F&&(t.path==="HEAD"||t.path.startsWith("refs/")),"isLooseRef"),ie=c(t=>I(t)||t.path==="packed-refs","isRefFile"),me=c(t=>t.startsWith("logs/"),"isReflogPath"),J="refs/stash",K="refs/heads/",Q=`${K}amalgm`,pe=7,we=/^[0-9a-f]{7,}$/,U=c((t,i)=>t.startsWith(`${i}/`),"beneath");async function ye(t,i,r,u){const g=new Map,f=c(async e=>{const n=e.files.find(a=>a.path==="packed-refs")?.oid,s=(0,x.gitRefsByMeaning)(e,n?g.get(n)??await i(n):null,u);for(const[a,o]of s.made)g.set(a,o);return s.state},"meaning"),m={format:t.record.format,home:t.record.home,files:[],index:null},E={line:await f(t.line),basis:t.basis===null?m:await f(t.basis),record:await f(t.record)},l={line:N(E.line.files),basis:N(E.basis.files),record:N(E.record.files)},R=c((e,n)=>{const s=(0,ne.utf8Encode)(n),a=(0,se.gitBlobId)(s,u);return g.set(a,s),{path:e,mode:"100644",oid:a}},"make"),y=c(async e=>e?.oid?(0,ne.utf8Decode)(g.get(e.oid)??await i(e.oid)):"","read"),T=new Map,$=c(e=>(T.has(e)||T.set(e,y(l[e].get("packed-refs")).then(x.gitPackedRefs)),T.get(e)),"packedOf"),b=c(async(e,n)=>{const s=l[e].get(n);return s!==void 0&&I(s)?(0,x.gitLooseRef)(await y(s)):n==="HEAD"?null:(await $(e)).get(n)??null},"value"),M=c(e=>!V(l.basis.get(e),l.record.get(e)),"recordChanged"),h=new Map;for(const e of new Set([...l.line.keys(),...l.basis.keys(),...l.record.keys()])){const n=M(e)?l.record.get(e):l.line.get(e);n!==void 0&&h.set(e,n)}const j=new Set;for(const e of new Set(O.flatMap(n=>[...l[n].keys()]))){const[n,s,a]=O.map(o=>l[o].get(e));if(!(V(n,s)&&V(s,a)))if(e==="packed-refs")for(const o of O)for(const d of(await $(o)).keys())j.add(d);else[n,s,a].some(o=>o!==void 0&&I(o))&&j.add(e)}const X=c(async e=>{const[n,s,a]=O.map(o=>l[o].get(e));return[n,s,a].some(o=>o?.mode===F)?y(n):(0,x.gitReflogPlay)(await y(s),await y(a),await y(n))},"playLog"),D=`logs/${J}`;let _=null;M(D)&&(_=(0,x.gitChainReflog)(await X(D)),_===""?h.delete(D):h.set(D,R(D,_)));const w=new Map,C=[];for(const e of[...j].sort(z.compareGitText)){const[n,s,a]=await Promise.all(O.map(d=>b(d,e)));let o=s!==a?a:n;if(e===J){if(_===null)continue;o=(0,x.gitReflogTop)(_)}else e.startsWith(K)&&n!==null&&n!==s&&o!==n&&[n,a].every(d=>d===null||(0,S.isGitOid)(t.record.format,d))&&(a===null||!await r.builtOn(a,n))&&(o=n,a!==null&&!await r.builtOn(n,a)&&C.push({name:e,basis:s,record:a}));o!==n&&w.set(e,o)}const Y=[];if(C.length>0){const e=new Map;for(const s of new Set([...l.line.keys(),...(await $("line")).keys(),...w.keys()])){if(s!==Q&&!U(s,Q))continue;const a=w.has(s)?w.get(s):await b("line",s);a!==null&&e.set(s,a)}const n=c((s,a)=>(e.get(s)??a)===a&&![...e.keys()].some(o=>U(s,o)||U(o,s)),"free");for(const{name:s,basis:a,record:o}of C){const d=`${Q}/${s.slice(K.length)}-`;let p=[...e.keys()].sort(z.compareGitText).find(k=>e.get(k)===a&&k.startsWith(d)&&we.test(k.slice(d.length)));for(let k=pe;p===void 0&&k<=o.length;k+=1)n(d+o.slice(0,k),o)&&(p=d+o.slice(0,k));p!==void 0&&(await b("line",p)!==o&&w.set(p,o),e.set(p,o),Y.push({branch:p,from:s,commit:o}))}}for(const[e,n]of[...h])ie(n)&&h.delete(e);for(const e of E.line.files)ie(e)&&h.set(e.path,e);const L=new Set;for(const[e,n]of w)n!==null?h.set(e,R(e,`${n}
2
+ `)):(h.has(e)&&I(h.get(e))&&h.delete(e),L.add(e));const Z=l.line.get("packed-refs");if(L.size>0&&Z!==void 0){const e=await y(Z),n=(0,x.gitDropPackedRefs)(e,L);n!==e&&h.set("packed-refs",R("packed-refs",n))}const v=c(e=>w.has(e)?Promise.resolve(w.get(e)):b("line",e),"final"),G=c(async(e,n)=>e?.startsWith("ref: ")?n(e.slice(5)):e,"commitOf"),H=await G(await v("HEAD"),v),P=new Set;for(const e of O)for(const n of l[e].keys())me(n)&&n!==D&&P.add(n);for(const e of w.keys())e!==J&&P.add(`logs/${e}`);H!==await G(await b("line","HEAD"),e=>b("line",e))&&P.add("logs/HEAD");for(const e of[...P].sort(z.compareGitText)){const n=e.slice(5),s=n==="HEAD"?H:await v(n),a=M(e);if(!a&&(s===null||n!=="HEAD"&&!w.has(n)||!l.line.has(e)))continue;let o=a?await X(e):await y(l.line.get(e));const d=(0,x.gitReflogTop)(o);if(s!==null&&d!==null&&d!==s&&(0,S.isGitOid)(t.record.format,s)){const p=o.trimEnd().split(`
3
+ `).at(-1);o+=`${d} ${s}${p.slice(p.indexOf(" ",p.indexOf(" ")+1))}
4
+ `}o===""?h.delete(e):h.set(e,R(e,o))}const q=c(e=>b(e,"HEAD").then(n=>G(n,s=>b(e,s))),"headOf"),W=c(async e=>{const n=t[e]?.index;return n?.files.length===1?{index:await i(n.files[0].oid),head:await q(e)}:null},"indexOf"),[B,ce,ee,re,fe]=await Promise.all([W("line"),W("basis"),W("record"),t.basis?q("basis"):null,q("record")]),A=t.record.index?.meaning===t.basis?.index?.meaning&&fe===re;let te=A?t.line.index:t.record.index;if(B!==null&&(A||ee!==null)&&!(A&&B.head===H)){const e=await r.playIndex(B,A?null:ce,A?null:ee,H);if(e!==null){const n=e.bytes,s=(0,se.gitBlobId)(n,u);g.set(s,n),te={meaning:e.meaning,files:[{path:"index",mode:"100644",oid:s}]}}}return{state:await f({format:t.record.format,home:t.record.home,files:he(h,l.record,t.record.home),index:te}),made:g,aside:Y}}c(ye,"gitPlayRecord");
@@ -1,8 +1,10 @@
1
- "use strict";var u=Object.defineProperty;var o=(t,e)=>u(t,"name",{value:e,configurable:!0});Object.defineProperty(exports,"__esModule",{value:!0}),exports.gitReflogTop=exports.gitLooseRef=void 0,exports.gitPackedRefs=h,exports.gitDropPackedRefs=R,exports.gitReflogPlay=m,exports.gitChainReflog=k;const d=o(t=>t.split(`
2
- `,1)[0].trimEnd(),"gitLooseRef");exports.gitLooseRef=d;const r=o(t=>{const e=t.indexOf(" ");return t.startsWith("#")||t.startsWith("^")||e<=0?null:t.slice(e+1)},"packedName");function h(t){const e=new Map;for(const n of t.split(`
3
- `)){const s=r(n);s!==null&&e.set(s,n.slice(0,n.indexOf(" ")))}return e}o(h,"gitPackedRefs");function R(t,e){const n=[];let s=!1;for(const i of t.split(`
4
- `))i.startsWith("^")||(s=e.has(r(i)??"")),s||n.push(i);return n.join(`
5
- `)}o(R,"gitDropPackedRefs");const a=o(t=>t.split(`
6
- `).filter(e=>e!==""),"lines"),l=o(t=>t.slice(t.indexOf(" ")+1),"entry");function m(t,e,n){const s=new Set(a(t).map(l)),i=a(e),p=new Set(i.map(l)),c=a(n),g=new Set(c.map(l));return[...c.filter(f=>!s.has(l(f))||p.has(l(f))),...i.filter(f=>!s.has(l(f))&&!g.has(l(f)))].map(f=>`${f}
7
- `).join("")}o(m,"gitReflogPlay");function k(t){let e=null;return a(t).map(n=>{const s=n.split(" ",2)[1],i=`${e??"0".repeat(s.length)}${n.slice(n.indexOf(" "))}
8
- `;return e=s,i}).join("")}o(k,"gitChainReflog");const w=o(t=>a(t).at(-1)?.split(" ",2)[1]??null,"gitReflogTop");exports.gitReflogTop=w;
1
+ "use strict";var k=Object.defineProperty;var r=(e,n)=>k(e,"name",{value:n,configurable:!0});Object.defineProperty(exports,"__esModule",{value:!0}),exports.gitReflogTop=exports.gitRefsTravelByMeaning=exports.gitLooseRef=void 0,exports.gitPackedRefs=T,exports.gitDropPackedRefs=W,exports.gitRefsByMeaning=P,exports.gitReflogPlay=D,exports.gitChainReflog=E;const v=require("../entities/bytes.js"),x=require("./artifact.js"),d=require("./state.js"),M=r(e=>e.split(`
2
+ `,1)[0].trimEnd(),"gitLooseRef");exports.gitLooseRef=M;const y=r(e=>{const n=e.indexOf(" ");return e.startsWith("#")||e.startsWith("^")||n<=0?null:e.slice(n+1)},"packedName");function T(e){const n=new Map;for(const o of e.split(`
3
+ `)){const s=y(o);s!==null&&n.set(s,o.slice(0,o.indexOf(" ")))}return n}r(T,"gitPackedRefs");function W(e,n){const o=[];let s=!1;for(const t of e.split(`
4
+ `))t.startsWith("^")||(s=n.has(y(t)??"")),s||o.push(t);return o.join(`
5
+ `)}r(W,"gitDropPackedRefs");const h="040000",O="refs/";function _(e,n){const o=new Map;for(const s of e.split(`
6
+ `)){if(s===""||s.startsWith("#")||s.startsWith("^")&&(0,d.isGitOid)(n,s.slice(1)))continue;const t=y(s),f=s.slice(0,s.indexOf(" "));if(t===null||!t.startsWith(O)||!(0,d.isGitOid)(n,f))return null;o.set(t,f)}return o}r(_,"packedRefs");function $(e){try{return new TextDecoder("utf-8",{fatal:!0}).decode(e)}catch{return null}}r($,"strictText");const j=r(e=>e.normalize("NFC").toLowerCase(),"folded"),B=r(e=>!/[<>:"|?*\\\x00-\x1f]|[. ]$/.test(e)&&!/^(aux|con|conin\$|conout\$|nul|prn|com[1-9]|lpt[1-9]) *(\.|$)/i.test(e),"onWindows");function S(e,n){if(!n.every(t=>t.split("/").every(B)))return!1;const o=new Set;for(const t of n)for(let f=t.indexOf("/");f>0;f=t.indexOf("/",f+1))o.add(t.slice(0,f));if(n.some(t=>o.has(t)))return!1;const s=new Map;for(const t of[...e,...n,...o]){const f=j(t),l=s.get(f);if(l!==void 0&&l!==t)return!1;s.set(f,t)}return!0}r(S,"looseOnEveryDisk");const b=r(e=>!(0,d.gitBytesForm)(e)&&!(0,d.gitSelfHeld)(e.home)&&!(0,d.gitSharesGitDir)(e.home)&&!e.files.some(n=>n.path==="reftable"||n.path.startsWith("reftable/")),"gitRefsTravelByMeaning");exports.gitRefsTravelByMeaning=b;function P(e,n,o){const s=new Map;if(!(0,exports.gitRefsTravelByMeaning)(e))return{state:e,made:s};const t=new Map(e.files.map(i=>[i.path,i])),f=n===null||!/^100(644|755)$/.test(t.get("packed-refs")?.mode??"")?null:$(n),l=f===null?null:_(f,e.format),R=r(i=>(t.get(i)?.mode??h)!==h,"loose"),c=r(i=>t.get(i)?.mode!==h&&i.split("/").every((a,p,g)=>p===g.length-1||!R(g.slice(0,p+1).join("/"))),"clear");if(l!==null&&[...l.keys()].every(c)&&S([...t.keys()],[...l.keys()])){t.delete("packed-refs");for(const[i,a]of l){if(R(i))continue;const p=(0,v.utf8Encode)(`${a}
7
+ `),g=(0,x.gitBlobId)(p,o);s.set(g,p),t.set(i,{path:i,mode:"100644",oid:g})}}const w=new Set;for(const i of t.values())if(i.mode!==h)for(let a=i.path.indexOf("/");a>0;a=i.path.indexOf("/",a+1))w.add(i.path.slice(0,a));for(const[i,a]of t)a.mode===h&&i.startsWith(O)&&!w.has(i)&&t.delete(i);return{state:{...e,files:(0,d.gitTreeOf)(t.values(),e.home)},made:s}}r(P,"gitRefsByMeaning");const m=r(e=>e.split(`
8
+ `).filter(n=>n!==""),"lines"),u=r(e=>e.slice(e.indexOf(" ")+1),"entry");function D(e,n,o){const s=new Set(m(e).map(u)),t=m(n),f=new Set(t.map(u)),l=m(o),R=new Set(l.map(u));return[...l.filter(c=>!s.has(u(c))||f.has(u(c))),...t.filter(c=>!s.has(u(c))&&!R.has(u(c)))].map(c=>`${c}
9
+ `).join("")}r(D,"gitReflogPlay");function E(e){let n=null;return m(e).map(o=>{const s=o.split(" ",2)[1],t=`${n??"0".repeat(s.length)}${o.slice(o.indexOf(" "))}
10
+ `;return n=s,t}).join("")}r(E,"gitChainReflog");const L=r(e=>m(e).at(-1)?.split(" ",2)[1]??null,"gitReflogTop");exports.gitReflogTop=L;
@@ -1,2 +1 @@
1
- "use strict";var I=Object.defineProperty;var o=(s,a)=>I(s,"name",{value:a,configurable:!0});Object.defineProperty(exports,"__esModule",{value:!0}),exports.gitRestoreGoal=A;const f=require("../contracts/validate.js"),g=require("../entities/bytes.js"),$=require("./artifact.js"),n=require("./parts.js"),d=require("./refs.js"),p=require("./state.js"),O=/^(rebase-merge|rebase-apply|sequencer)(\/|$)/,l=o(s=>s.mode==="040000","isFolder"),S=o(s=>(0,n.gitOwnRef)(s)||(0,n.gitOwnFile)(s),"restored");function A(s,a,T,j){for(const e of[s,a]){if((0,p.gitBytesForm)(e))return(0,f.fail)("a repository in byte form cannot be restored");if(e.files.some(t=>t.path.startsWith("reftable/")))return(0,f.fail)("a reftable repository cannot be restored");if((0,p.gitSelfHeld)(e.home))return(0,f.fail)("a worktree of storage outside every folder cannot be restored")}if(s.format!==a.format)return(0,f.fail)(`a ${s.format} repository cannot take a ${a.format} version`);const u=new Map,_=o((e,t)=>{const i=(0,$.gitBlobId)(t,j);return u.set(i,t),{path:e,mode:"100644",oid:i}},"blob"),k=o(e=>e.files.find(t=>t.path===n.GIT_PACKED_REFS),"packed"),R=o(e=>{const t=k(e);return t===void 0?null:(0,g.utf8Decode)(T(t.oid))},"packedText"),c=R(s),h=R(a),m=h===null?new Map:(0,d.gitPackedRefs)(h),w=o((e,t)=>new Set([...e.files.filter(i=>!l(i)&&(0,n.gitOwnRef)(i.path)).map(i=>i.path),...[...t.keys()].filter(n.gitOwnRef)]),"ownRefs"),M=w(a,m),q=new Set([...w(s,c===null?new Map:(0,d.gitPackedRefs)(c))].filter(e=>!M.has(e)).map(e=>`logs/${e}`)),r=new Map;for(const[e,t]of m)(0,n.gitOwnRef)(e)&&r.set(e,_(e,(0,g.utf8Encode)(`${t}
2
- `)));for(const e of a.files)(l(e)?O.test(e.path):S(e.path))&&r.set(e.path,e);if(c!==null){const e=(0,d.gitDropPackedRefs)(c,new Set([...(0,d.gitPackedRefs)(c).keys()].filter(n.gitOwnRef)));r.set(n.GIT_PACKED_REFS,e===c?k(s):_(n.GIT_PACKED_REFS,(0,g.utf8Encode)(e)))}const b=o(e=>{const t=e.split("/");return t.slice(1).map((i,D)=>t.slice(0,D+1).join("/"))},"ancestors"),v=new Set([...r.keys()].flatMap(b)),F=o(e=>r.has(e.path)||!l(e)&&v.has(e.path)||b(e.path).some(t=>r.has(t)&&!l(r.get(t))),"inTheWay");for(const e of s.files)(l(e)?!O.test(e.path):e.path!==n.GIT_PACKED_REFS&&!S(e.path)&&!q.has(e.path))&&!F(e)&&r.set(e.path,e);const y=(0,p.gitTreeOf)(r.values(),s.home),E={...s,files:y,index:a.index},P=(0,p.checkGitState)(E);if(!P.ok)return(0,f.fail)(`the version cannot stand over this repository: ${P.error}`);const G=new Map(y.flatMap(e=>u.has(e.oid)?[[e.oid,u.get(e.oid)]]:[]));return(0,f.pass)({state:E,blobs:G})}o(A,"gitRestoreGoal");
1
+ "use strict";var E=Object.defineProperty;var o=(s,n)=>E(s,"name",{value:n,configurable:!0});Object.defineProperty(exports,"__esModule",{value:!0}),exports.gitRestoreGoal=G;const r=require("../contracts/validate.js"),u=require("./parts.js"),F=require("./refs.js"),p=require("./state.js"),b=/^(rebase-merge|rebase-apply|sequencer)(\/|$)/,f=o(s=>s.mode==="040000","isFolder"),k=o(s=>(0,u.gitOwnRef)(s)||(0,u.gitOwnFile)(s),"restored");function G(s,n,R,v){for(const e of[s,n]){if((0,p.gitBytesForm)(e))return(0,r.fail)("a repository in byte form cannot be restored");if(e.files.some(t=>t.path.startsWith("reftable/")))return(0,r.fail)("a reftable repository cannot be restored");if((0,p.gitSelfHeld)(e.home))return(0,r.fail)("a worktree of storage outside every folder cannot be restored")}if(s.format!==n.format)return(0,r.fail)(`a ${s.format} repository cannot take a ${n.format} version`);const c=new Map,l=o(e=>{const t=e.files.find(i=>i.path==="packed-refs")?.oid,h=(0,F.gitRefsByMeaning)(e,t?c.get(t)??R(t):null,v);for(const[i,T]of h.made)c.set(i,T);return h.state},"meaning"),[g,m]=[l(s),l(n)],w=o(e=>new Set(e.files.filter(t=>!f(t)&&(0,u.gitOwnRef)(t.path)).map(t=>t.path)),"ownRefs"),M=w(m),O=new Set([...w(g)].filter(e=>!M.has(e)).map(e=>`logs/${e}`)),a=new Map;for(const e of m.files)(f(e)?b.test(e.path):k(e.path))&&a.set(e.path,e);const y=o(e=>{const t=e.split("/");return t.slice(1).map((h,i)=>t.slice(0,i+1).join("/"))},"ancestors"),j=new Set([...a.keys()].flatMap(y)),q=o(e=>a.has(e.path)||!f(e)&&j.has(e.path)||y(e.path).some(t=>a.has(t)&&!f(a.get(t))),"inTheWay");for(const e of g.files)(f(e)?!b.test(e.path):!k(e.path)&&!O.has(e.path))&&!q(e)&&a.set(e.path,e);const d=l({...s,files:(0,p.gitTreeOf)(a.values(),s.home),index:n.index}),S=d.files,_=(0,p.checkGitState)(d);if(!_.ok)return(0,r.fail)(`the version cannot stand over this repository: ${_.error}`);const $=new Map(S.flatMap(e=>c.has(e.oid)?[[e.oid,c.get(e.oid)]]:[]));return(0,r.pass)({state:d,blobs:$})}o(G,"gitRestoreGoal");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amalgm/live",
3
- "version": "0.2.81-preview.47446204525",
3
+ "version": "0.2.81-preview.47470355497",
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": "1bd1d2b8fe47f06a11faf8be4f7397d77bc03db1",
136
+ "gitHead": "5068c4c2051906ecced45cb40b78395b01d23e57",
137
137
  "amalgmSource": {
138
138
  "repository": "amalgm-inc/amalgm-live",
139
139
  "branch": "preview",
140
- "commit": "1bd1d2b8fe47f06a11faf8be4f7397d77bc03db1",
141
- "occurrence": "47446204525"
140
+ "commit": "5068c4c2051906ecced45cb40b78395b01d23e57",
141
+ "occurrence": "47470355497"
142
142
  }
143
143
  }