@amalgm/live 0.2.81-preview.46345594395 → 0.2.81-preview.47045660115

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.
Files changed (81) hide show
  1. package/dist/apply/contracts.d.ts +1 -1
  2. package/dist/apply/journey.d.ts +7 -1
  3. package/dist/apply/journey.js +1 -1
  4. package/dist/apply/lane.d.ts +1 -0
  5. package/dist/apply/lane.js +1 -1
  6. package/dist/apply/line.d.ts +1 -1
  7. package/dist/apply/line.js +1 -1
  8. package/dist/apply/rail.d.ts +2 -1
  9. package/dist/apply/rail.js +1 -1
  10. package/dist/apply/settling.d.ts +2 -1
  11. package/dist/apply/settling.js +1 -1
  12. package/dist/apply/window.js +1 -1
  13. package/dist/detection/package-proposal.d.ts +1 -0
  14. package/dist/detection/package-proposal.js +1 -1
  15. package/dist/drive/contracts.d.ts +0 -1
  16. package/dist/drive/listing.js +1 -1
  17. package/dist/drive/where.d.ts +1 -1
  18. package/dist/drive/where.js +2 -2
  19. package/dist/entities/cloud.d.ts +3 -1
  20. package/dist/entities/cloud.js +1 -1
  21. package/dist/entities/package-pages.d.ts +3 -1
  22. package/dist/entities/package-pages.js +1 -1
  23. package/dist/files/browser.js +1 -1
  24. package/dist/files/commands.d.ts +12 -1
  25. package/dist/files/commands.js +1 -1
  26. package/dist/files/index.d.ts +1 -0
  27. package/dist/files/index.js +1 -1
  28. package/dist/files/secrets.d.ts +3 -0
  29. package/dist/files/secrets.js +1 -0
  30. package/dist/files/usage.d.ts +1 -0
  31. package/dist/files/usage.js +1 -1
  32. package/dist/git/holds.js +1 -1
  33. package/dist/records/authority.d.ts +19 -1
  34. package/dist/records/authority.js +1 -1
  35. package/dist/records/contracts.d.ts +12 -0
  36. package/dist/records/contracts.js +1 -1
  37. package/dist/records/outbox.d.ts +1 -1
  38. package/dist/records/outbox.js +1 -1
  39. package/dist/records/rail.js +1 -1
  40. package/dist/records/receive-loop.js +1 -1
  41. package/dist/records/send-batch.js +1 -1
  42. package/dist/records/send-preparation.js +1 -1
  43. package/dist/records/submit-frame.d.ts +1 -1
  44. package/dist/records/submit-frame.js +1 -1
  45. package/dist/registration/user-ground.d.ts +1 -0
  46. package/dist/registration/user-ground.js +1 -1
  47. package/dist/transfer/artifacts.d.ts +1 -1
  48. package/dist/transfer/artifacts.js +1 -1
  49. package/dist/versions/api.js +1 -1
  50. package/dist/versions/errors.d.ts +1 -1
  51. package/dist/versions/errors.js +1 -1
  52. package/dist-cjs/apply/journey.js +1 -1
  53. package/dist-cjs/apply/lane.js +1 -1
  54. package/dist-cjs/apply/line.js +1 -1
  55. package/dist-cjs/apply/rail.js +1 -1
  56. package/dist-cjs/apply/settling.js +1 -1
  57. package/dist-cjs/apply/window.js +1 -1
  58. package/dist-cjs/detection/package-proposal.js +1 -1
  59. package/dist-cjs/drive/listing.js +1 -1
  60. package/dist-cjs/drive/where.js +2 -2
  61. package/dist-cjs/entities/cloud.js +1 -1
  62. package/dist-cjs/entities/package-pages.js +1 -1
  63. package/dist-cjs/files/browser.js +1 -1
  64. package/dist-cjs/files/commands.js +1 -1
  65. package/dist-cjs/files/index.js +1 -1
  66. package/dist-cjs/files/secrets.js +1 -0
  67. package/dist-cjs/files/usage.js +1 -1
  68. package/dist-cjs/git/holds.js +1 -1
  69. package/dist-cjs/records/authority.js +1 -1
  70. package/dist-cjs/records/contracts.js +1 -1
  71. package/dist-cjs/records/outbox.js +1 -1
  72. package/dist-cjs/records/rail.js +1 -1
  73. package/dist-cjs/records/receive-loop.js +1 -1
  74. package/dist-cjs/records/send-batch.js +1 -1
  75. package/dist-cjs/records/send-preparation.js +1 -1
  76. package/dist-cjs/records/submit-frame.js +1 -1
  77. package/dist-cjs/registration/user-ground.js +1 -1
  78. package/dist-cjs/transfer/artifacts.js +1 -1
  79. package/dist-cjs/versions/api.js +1 -1
  80. package/dist-cjs/versions/errors.js +1 -1
  81. package/package.json +4 -4
@@ -191,7 +191,7 @@ export interface ApplyDeclinedReveal {
191
191
  export interface ApplyWait {
192
192
  readonly entityId: string;
193
193
  readonly reason: string;
194
- readonly prerequisite: ApplyDependency;
194
+ readonly prerequisite?: ApplyDependency;
195
195
  readonly throughSequence: number;
196
196
  readonly blocker?: ApplyBlocker;
197
197
  }
@@ -1,5 +1,8 @@
1
- import { type ApplyBlocker, type ApplyDependency, type ApplyWindow, type EntityApplyRailOptions } from './contracts.js';
1
+ import { type ApplyBlocker, type ApplyDependency, type ApplyWindow, type EntityApplyRailOptions, type WindowMember } from './contracts.js';
2
2
  export type HeadOutcome = 'progress' | 'again' | {
3
+ readonly kind: 'alone';
4
+ readonly entityId: string;
5
+ } | {
3
6
  readonly kind: 'park';
4
7
  readonly reason: string;
5
8
  readonly releaseOnProgress: boolean;
@@ -9,11 +12,14 @@ export type HeadOutcome = 'progress' | 'again' | {
9
12
  readonly blocker?: ApplyBlocker;
10
13
  readonly comparedAt?: number;
11
14
  readonly advanced?: readonly string[];
15
+ readonly again?: true;
12
16
  };
17
+ export declare function stepsAside(window: ApplyWindow, head: string): boolean;
13
18
  export declare function outcomeOf(attempt: () => Promise<HeadOutcome>): Promise<HeadOutcome>;
14
19
  export declare class EntityApplyJourney {
15
20
  #private;
16
21
  constructor(options: EntityApplyRailOptions, wakeVersion: () => number, stopping: () => boolean);
17
22
  targetOf(window: ApplyWindow): number | null;
18
23
  run(window: ApplyWindow, emptying: () => string | null): Promise<HeadOutcome>;
24
+ alone(head: WindowMember): Promise<HeadOutcome>;
19
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 x}from"./contracts.js";import{planSelectedEntityApply as E}from"./plans.js";import{Recovering as M}from"../faults/recover.js";import{groundMoved as W}from"../faults/classify.js";import{localWorkWins as D}from"../clash/local-work.js";import{selectEntityApply as O}from"./selection.js";import{isSettlement as P}from"./settling.js";import{revealOrder as S}from"./window.js";const q=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 _(l){try{return await l()}catch(e){return{kind:"park",reason:e instanceof Error?e.message:String(e),releaseOnProgress:!1,report:!W(e),cause:e}}}m(_,"outcomeOf");const I=m(l=>P(l.judgment)?{kind:"settled",settlement:l.judgment}:null,"settled");class B{static{m(this,"EntityApplyJourney")}#e;#r;#n;#a;constructor(e,n,i){this.#e=e,this.#r={sha256Hex:e.sha256Hex,loops:e.loops},this.#n=n,this.#a=i}targetOf(e){const n=e.members[0];return n===void 0?null:e.intent?.members.find(i=>i.entityId===n.work.entityId)?.throughSequence??(n.work.kept===null?n.work.records.at(-1)?.globalSequence:n.work.resolvedThrough)??null}async run(e,n){if(e.intent!==null)return this.#u(e,e.intent);const i=this.#e.newIntentId(),s=this.#e.now(),r=n(),t=new Map;for(const d of e.members){if(I(d))continue;const{work:u}=d,k=O(u,this.#r),b=F({attemptId:i,work:u,target:k.target,unit:e.unit,cutoff:e.cutoff,createdAt:s,emptied:u.entityId===r&&u.play==="enter"&&(k.target.result.type==="file.text"||k.target.result.type==="file.binary")}),h=E(u,k,this.#e.sha256Hex);t.set(u.entityId,{member:d,intent:b,plan:h,adapter:this.#e.effects.adapterFor(h.target.type),look:"safe"})}const{active:o,blocked:f}=await this.#o(e.members,t,"look");if(o.length===0)return f??"again";const g=o.flatMap(d=>t.get(d.work.entityId)??[]);if(g.length===0)return this.#t(null,o,o.map(d=>I(d)));const w=x({attemptId:i,authorityId:e.authorityId,unit:e.unit,cutoff:e.cutoff,createdAt:s,members:g.map(d=>d.intent)});try{const d=await this.#c(o,t),u=d.active.flatMap(y=>t.get(y.work.entityId)??[]);if(u.length===0)return await this.#e.effects.discard(w),d.active.length===0?d.blocked??"again":this.#t(null,d.active,d.active.map(y=>I(y)));const k=u.length===g.length?w:x({...w,members:u.map(y=>y.intent)}),b=await this.#e.effects.hold(k,u.map(y=>y.plan));let h,v;try{h=await this.#o(d.active,t,"final"),v=await this.#d(k,h,t,n)}finally{b()}return h.unseen!==null&&h.active.length===0?this.#f(h.unseen):v}catch(d){throw await this.#e.effects.discard(w),d}}async#d(e,{active:n,blocked:i},s,r){const t=n.flatMap(a=>s.get(a.work.entityId)??[]);if(t.length===0)return await this.#e.effects.discard(e),n.length===0?i??"again":this.#t(null,n,n.map(a=>I(a)));const o=x({...e,members:t.map(a=>a.intent)}),f=t.filter(a=>a.look==="safe");if(f.length>0){if(this.#a()||t.some(p=>p.intent.emptied&&r()!==p.intent.entityId))return await this.#e.effects.discard(e),"again";const a=await this.#e.store.bindWindow(o);if(a)return await this.#e.effects.discard(e),a.kind==="stale"?"again":A({...a,comparedAt:this.#n()})}const g=new Map,w=new Map,d=m((a,p,c=null)=>{g.set(a,{kind:"owed",reason:p}),c!==null&&w.set(a,c)},"owe"),u=m(a=>A(a.kind==="dependency"?{...a,comparedAt:this.#n()}:a),"waitFrom"),{order:k,cycle:b}=S(f.map(a=>({entityId:a.intent.entityId,play:a.plan.play,type:a.plan.target.type,parentUUID:a.plan.target.parentUUID}))),h="its parent chain closes among the window's members";for(const a of b)d(a,h,{kind:"park",reason:h,releaseOnProgress:!1,report:!0});for(const a of k){const p=s.get(a),c=await p.adapter.apply.reveal(p.intent,p.plan);c&&d(a,c.reason,c.kind==="dependency"?u(c):null)}for(const a of t){const p=a.intent.entityId;if(g.has(p))continue;const c=await a.adapter.verify.verify(a.intent,a.plan);c.kind==="match"?g.set(p,{kind:"materialized"}):c.kind==="local-change"?d(p,"a person's version stands in its place"):c.kind==="rejudge"||c.kind==="missing-target"?d(p,c.kind):d(p,c.reason??c.kind,u(c))}const v=n.map(a=>I(a)??g.get(a.work.entityId));if(f.length>0)return this.#s(o,n,v,w);const y=await this.#s(null,n,v,w);return await this.#e.effects.discard(e),y}async#s(e,n,i,s){const r=await this.#t(e,n,i),t=r==="progress"?s.get(n[0].work.entityId):void 0;return t===void 0?r:{...t,advanced:n.filter((o,f)=>i[f].kind!=="owed").map(o=>o.work.entityId)}}async#o(e,n,i){const s=[];for(const r of e){const t=n.get(r.work.entityId);if(!t){s.push(r);continue}const o=await this.#i(t.intent)?{kind:"captured-local"}:i==="look"?await this.#p(t):await t.adapter.apply.guard(t.intent,t.plan,i);if(o.kind==="local-change"||o.kind==="unsettled-ground")return{active:s,blocked:s.length===0?"again":null,unseen:t};if(q(o))return{active:s,blocked:s.length===0?"again":null,unseen:null};const f=A(o);if(f)return{active:s,blocked:f,unseen:null};t.look=o.kind,s.push(r)}return{active:s,blocked:null,unseen:null}}async#c(e,n){for(const[i,s]of e.entries()){const r=n.get(s.work.entityId);if(!(!r||r.look!=="safe"))try{const t=await r.adapter.apply.prepare(r.intent,r.plan);if(t)return{active:e.slice(0,i),blocked:A(t)}}catch(t){if(t instanceof M)return{active:e.slice(0,i),blocked:{kind:"park",reason:t.message,releaseOnProgress:!1,report:!1,dependency:{producer:"capability",entityIds:t.need.subject===null?[]:[t.need.subject.id]}}};if(i===0||this.#a())throw t;return{active:e.slice(0,i),blocked:null}}}return{active:[...e],blocked:null}}async#u(e,n){const i=n.members.map(r=>{const t=e.members.find(f=>f.work.entityId===r.entityId);if(!t)return null;const o=r.kept===null?t.work:{...t.work,records:[],kept:r.kept};return o.records.length===0&&o.kept===null?null:E(o,O(o,this.#r,r),this.#e.sha256Hex)}),s=await this.#e.effects.recover(n,i);if(s.length!==n.members.length)throw new Error("Apply recovery answered for a different window");return this.#t(n,e.members,e.members.map(r=>I(r)??s[n.members.findIndex(t=>t.entityId===r.work.entityId)]??{kind:"owed",reason:"not a member of the bound window"}))}async#t(e,n,i){const s=await this.#e.store.endWindow(e,n,i);if(!s)return"progress";if(s.kind!=="stale"||!s.reason)throw new Error("Apply end commit returned an unknown refusal");return"again"}async#i(e){return D(e.targetType,await this.#e.store.localWorkAfter(e.authorityId,e.entityId,e.kept??e.throughSequence))}async#p(e){const{intent:n,plan:i,adapter:s}=e,r=await s.apply.guard(n,i,"look");if(r.kind!=="local-change"&&r.kind!=="unsettled-ground")return r;const t=await this.#l(n,i);if(t.kind!=="observed")return t;const o=await s.apply.guard(n,i,"look");return o.kind==="local-change"||o.kind==="unsettled-ground"?{kind:"retry",reason:"Ground still needs observation after Detect; this member cannot reveal."}:o}async#f(e){const n=await this.#l(e.intent,e.plan);return n.kind==="captured-local"?"again":A(n.kind==="observed"?{kind:"retry",reason:"Its final guard found ground Detect had not recorded; it is judged again after Detect looks."}:n)}async#l(e,n){if(await this.#i(e))return{kind:"captured-local"};let i,s=!0;const r=await this.#e.effects.captureLocal(e,n,()=>{if(!s||i!==void 0)throw new Error("Apply capture comparison must be marked exactly once");i=this.#n()}).finally(()=>{s=!1});if(!r||!["settled","local-only","retry"].includes(r.kind))throw new Error("Apply capture returned no explicit observation outcome");if(await this.#i(e))return{kind:"captured-local"};if(r.kind==="retry")return r;if(r.kind==="local-only"){if(i===void 0)throw new Error("local-only capture requires a synchronous comparison fence");if(!r.reason||r.entityIds.length===0||r.entityIds.some(t=>!t))throw new Error("local-only capture must name the retained ground and its releasing condition");return{kind:"dependency",reason:r.reason,comparedAt:i,waitFor:{producer:"detect",entityIds:r.entityIds}}}return{kind:"observed"}}}export{B as EntityApplyJourney,_ as outcomeOf};
1
+ var j=Object.defineProperty;var w=(l,e)=>j(l,"name",{value:e,configurable:!0});import{createApplyIntent as F,createApplyWindowIntent as x}from"./contracts.js";import{planSelectedEntityApply as E}from"./plans.js";import{Recovering as M}from"../faults/recover.js";import{groundMoved as O}from"../faults/classify.js";import{localWorkWins as S}from"../clash/local-work.js";import{selectEntityApply as P}from"./selection.js";import{isSettlement as W}from"./settling.js";import{revealOrder as D}from"./window.js";function q(l,e){return l.unit===null&&l.authorityId!==e}w(q,"stepsAside");const H=w(l=>l.kind==="captured-local"||l.kind==="rejudge","drops");function v(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(v,"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:!O(e),cause:e}}}w(B,"outcomeOf");const I=w(l=>W(l.judgment)?{kind:"settled",settlement:l.judgment}:null,"settled");class C{static{w(this,"EntityApplyJourney")}#e;#a;#r;#n;constructor(e,t,i){this.#e=e,this.#a={sha256Hex:e.sha256Hex,loops:e.loops},this.#r=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(O(a))return{kind:"park",reason:a instanceof Error?a.message:String(a),releaseOnProgress:!1,report:!1};if(q(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 t=await this.#t(null,[e],[{kind:"settled",settlement:"waiting"}]);return t==="progress"?{kind:"alone",entityId:e.work.entityId}:t}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(I(c))continue;const{work:f}=c,m=P(f,this.#a),b=F({attemptId:a,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=E(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",i);if(d.length===0)return h??"again";const g=d.flatMap(c=>s.get(c.work.entityId)??[]);if(g.length===0)return this.#t(null,d,d.map(c=>I(c)));const y=x({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??"again":this.#t(null,c.active,c.active.map(r=>I(r)));const m=f.length===g.length?y:x({...y,members:f.map(r=>r.intent)}),b=await this.#e.effects.hold(m,f.map(r=>r.plan));let k,A;try{k=await this.#o(c.active,s,"final",i),A=await this.#c(m,k,s,t)}finally{b()}return k.unseen!==null&&k.active.length===0?this.#h(k.unseen):A}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??"again":this.#t(null,t,t.map(r=>I(r)));const s=x({...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),"again";const r=await this.#e.store.bindWindow(s);if(r)return await this.#e.effects.discard(e),r.kind==="stale"?"again":v({...r,comparedAt:this.#r()})}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=>v(r.kind==="dependency"?{...r,comparedAt:this.#r()}: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=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=>I(r)??h.get(r.work.entityId));if(d.length>0)return this.#s(s,t,k,g);const A=await this.#s(null,t,k,g);return await this.#e.effects.discard(e),A}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?"again":null,unseen:s};if(H(d))return{active:n,blocked:n.length===0?"again":null,unseen:null};const h=v(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:v(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:E(s,P(s,this.#a,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=>I(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"again"}async#i(e){return S(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"?"again":v(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.#r()}).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,q as stepsAside};
@@ -11,6 +11,7 @@ export interface ApplyLaneState extends ApplyTrack {
11
11
  readonly unit: string;
12
12
  emptied: boolean;
13
13
  through: number | null;
14
+ toPrefix: boolean;
14
15
  waitsOn: string | null;
15
16
  readonly met: Set<string>;
16
17
  readonly waiters: Set<FetchWaiter>;
@@ -1 +1 @@
1
- var l=Object.defineProperty;var o=(n,e)=>l(n,"name",{value:e,configurable:!0});import{UUID_PATTERN as a}from"../entities/types.js";import{assertApplyWindow as u,invalidStep as t}from"./line.js";function d(n,e,r){return{kind:"lane",unit:n,emptied:r,through:e,waitsOn:null,met:new Set,waiters:new Set,held:null,queued:!1,running:!1,again:!1}}o(d,"createApplyLane");function h(n,e){const r=`lane step for ${n}`;switch((!e||typeof e!="object"||!Number.isSafeInteger(e.through)||e.through<0)&&t(r),e.kind){case"end":return;case"nowhere":case"root":(typeof e.reason!="string"||e.reason.length===0)&&t(r);return;case"prerequisite":(!a.test(e.unit)||e.unit===n||typeof e.reason!="string"||e.reason.length===0)&&t(r);return;case"window":(e.window?.unit!==n||e.window.cutoff!==e.through||e.window.intent!==null&&(e.window.intent.unit!==n||e.window.intent.cutoff!==e.through))&&t(r),u(e.window,r),e.window.members.some(i=>i.work.kept!==null)&&f(e.window,r);return;default:t(r)}}o(h,"assertApplyLaneStep");function f(n,e){const[r]=n.members;(n.members.length!==1||r.work.play!=="enter"||r.work.records.length!==0||r.work.materialized!==null||r.deliverySequence!==n.cutoff||n.intent!==null&&n.intent.members.some(i=>i.kept===null))&&t(e)}o(f,"assertKeptWindow");export{h as assertApplyLaneStep,d as createApplyLane};
1
+ var l=Object.defineProperty;var o=(n,e)=>l(n,"name",{value:e,configurable:!0});import{UUID_PATTERN as a}from"../entities/types.js";import{assertApplyWindow as u,invalidStep as t}from"./line.js";function d(n,e,r){return{kind:"lane",unit:n,emptied:r,through:e,toPrefix:!1,waitsOn:null,met:new Set,waiters:new Set,held:null,queued:!1,running:!1,again:!1}}o(d,"createApplyLane");function s(n,e){const r=`lane step for ${n}`;switch((!e||typeof e!="object"||!Number.isSafeInteger(e.through)||e.through<0)&&t(r),e.kind){case"end":return;case"nowhere":case"root":(typeof e.reason!="string"||e.reason.length===0)&&t(r);return;case"prerequisite":(!a.test(e.unit)||e.unit===n||typeof e.reason!="string"||e.reason.length===0)&&t(r);return;case"window":(e.window?.unit!==n||e.window.cutoff!==e.through||e.window.intent!==null&&(e.window.intent.unit!==n||e.window.intent.cutoff!==e.through))&&t(r),u(e.window,r),e.window.members.some(i=>i.work.kept!==null)&&f(e.window,r);return;default:t(r)}}o(s,"assertApplyLaneStep");function f(n,e){const[r]=n.members;(n.members.length!==1||r.work.play!=="enter"||r.work.records.length!==0||r.work.materialized!==null||r.deliverySequence!==n.cutoff||n.intent!==null&&n.intent.members.some(i=>i.kept===null))&&t(e)}o(f,"assertKeptWindow");export{s as assertApplyLaneStep,d as createApplyLane};
@@ -26,7 +26,7 @@ export interface ApplyLineState extends ApplyTrack {
26
26
  }
27
27
  export declare function createApplyLine(authorityId: string): ApplyLineState;
28
28
  export declare function releaseApplyLine(line: ApplyTrack, producer: ApplyDependency['producer'], entityIds: readonly string[] | undefined): boolean;
29
- export declare function heldWait(held: HeldHead | null): ApplyWait | undefined;
29
+ export declare function heldWait(held: HeldHead | null, owner: string): ApplyWait | undefined;
30
30
  export declare function assertApplyDependency(dependency: ApplyDependency | undefined): void;
31
31
  export declare function assertApplyLineStep(authorityId: string, step: EntityApplyLineStep): void;
32
32
  export declare const invalidStep: (what: string) => never;
@@ -1 +1 @@
1
- var s=Object.defineProperty;var t=(e,n)=>s(e,"name",{value:n,configurable:!0});import{UUID_PATTERN as f}from"../entities/types.js";function m(e){return{kind:"line",authorityId:e,endsBefore:null,held:null,queued:!1,running:!1,again:!1}}t(m,"createApplyLine");function w(e,n,o){const i=e.held;return!i?.dependency||i.due||i.dependency.producer!==n||o!==void 0&&!i.dependency.entityIds.some(r=>o.includes(r))?!1:(i.due=!0,!0)}t(w,"releaseApplyLine");function k(e){if(!(!e?.dependency||e.entityId===null||e.target===null))return{entityId:e.entityId,reason:e.reason,prerequisite:e.dependency,throughSequence:e.target,...e.blocker?{blocker:e.blocker}:{}}}t(k,"heldWait");const a=new Set(["detect","apply","capability","send"]),d=t(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 b(e){if(!d(e))throw new Error("Apply dependency must name the entities that can release it")}t(b,"assertApplyDependency");function A(e,n){(!n||typeof n!="object")&&l(`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))&&l(`line step for ${e}`),c(n.window,`line step for ${e}`))}t(A,"assertApplyLineStep");const l=t(e=>{throw new Error(`entity Apply store returned an invalid ${e}`)},"invalidStep");function c(e,n){(!Array.isArray(e.members)||e.members.length===0)&&l(n);const o=t((r,u)=>Number.isSafeInteger(r)&&r>=(u?0:1),"at");for(const r of e.members)(!f.test(r.work?.entityId??"")||r.work.authorityId!==e.authorityId||!o(r.deliverySequence,r.work.kept!==null))&&l(n);const{deliverySequence:i}=e;(i===null?!e.intent:!o(i,e.members[0].work.kept!==null))&&l(n)}t(c,"assertApplyWindow");export{b as assertApplyDependency,A as assertApplyLineStep,c as assertApplyWindow,m as createApplyLine,k as heldWait,l as invalidStep,w as releaseApplyLine};
1
+ var f=Object.defineProperty;var t=(e,n)=>f(e,"name",{value:n,configurable:!0});import{UUID_PATTERN as s}from"../entities/types.js";function m(e){return{kind:"line",authorityId:e,endsBefore:null,held:null,queued:!1,running:!1,again:!1}}t(m,"createApplyLine");function w(e,n,o){const i=e.held;return!i?.dependency||i.due||i.dependency.producer!==n||o!==void 0&&!i.dependency.entityIds.some(r=>o.includes(r))?!1:(i.due=!0,!0)}t(w,"releaseApplyLine");function k(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}:{}}}t(k,"heldWait");const a=new Set(["detect","apply","capability","send"]),c=t(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 b(e){if(!c(e))throw new Error("Apply dependency must name the entities that can release it")}t(b,"assertApplyDependency");function g(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}`))}t(g,"assertApplyLineStep");const u=t(e=>{throw new Error(`entity Apply store returned an invalid ${e}`)},"invalidStep");function y(e,n){(!Array.isArray(e.members)||e.members.length===0)&&u(n);const o=t((r,l)=>Number.isSafeInteger(r)&&r>=(l?0:1),"at");for(const r of e.members)(!s.test(r.work?.entityId??"")||r.work.authorityId!==e.authorityId||!o(r.deliverySequence,r.work.kept!==null))&&u(n);const{deliverySequence:i}=e;(i===null?!e.intent:!o(i,e.members[0].work.kept!==null))&&u(n)}t(y,"assertApplyWindow");export{b as assertApplyDependency,g as assertApplyLineStep,y as assertApplyWindow,m as createApplyLine,k as heldWait,u as invalidStep,w as releaseApplyLine};
@@ -2,7 +2,7 @@ import type { ApplyFetchAnswer, ApplyWait, EntityApplyRailOptions } from './cont
2
2
  export declare const ENTITY_APPLY_DEFAULT_CONCURRENCY = 8;
3
3
  export declare const ENTITY_APPLY_RETRY_BASE_MS = 1000;
4
4
  export declare const ENTITY_APPLY_RETRY_MAX_MS = 30000;
5
- export declare const ENTITY_APPLY_QUIET_ATTEMPTS = 8;
5
+ export declare const ENTITY_APPLY_SAME_ANSWERS = 3;
6
6
  export declare class EntityApplyRail {
7
7
  #private;
8
8
  constructor(options: EntityApplyRailOptions);
@@ -16,6 +16,7 @@ export declare class EntityApplyRail {
16
16
  localStateChanged(entityIds?: readonly string[]): void;
17
17
  sendAccepted(entityIds: readonly string[]): void;
18
18
  capabilityChanged(entityIds?: readonly string[]): void;
19
+ owe(entityIds: readonly string[]): void;
19
20
  waiting(): readonly ApplyWait[];
20
21
  flush(): Promise<void>;
21
22
  stop(): Promise<void>;
@@ -1 +1 @@
1
- var g=Object.defineProperty;var a=(d,t)=>g(d,"name",{value:t,configurable:!0});import{UUID_PATTERN as f}from"../entities/types.js";import{FetchAhead as m}from"./fetch-ahead.js";import{EntityApplyJourney as A,outcomeOf as I}from"./journey.js";import{assertApplyLaneStep as k,createApplyLane as E}from"./lane.js";import{assertApplyDependency as P,assertApplyLineStep as b,createApplyLine as v,heldWait as c,releaseApplyLine as O}from"./line.js";import{windowEndForWait as $}from"./window.js";const S=8,q=1e3,p=3e4,M=8;class Y{static{a(this,"EntityApplyRail")}#t;#w;#P;#M;#T;#g;#b;#f=!1;#e=!1;#o=new Map;#s=new Map;#a={queue:[],steps:new Set};#d={queue:[],steps:new Set};#r=!1;#n=null;#c=1/0;#m=[];#A=0;#v=new Map;#p=null;constructor(t){this.#t=t,this.#w=t.concurrency??S,this.#P=t.laneConcurrency??this.#w,this.#M=t.onBackgroundError??(()=>{}),this.#T=t.onIdle??(()=>{});for(const[e,s]of[["concurrency",this.#w],["lane concurrency",this.#P]])if(!Number.isSafeInteger(s)||s<1)throw new Error(`entity Apply ${e} must be a positive integer`);this.#g=new A(t,()=>this.#A,()=>this.#e),this.#b=new m(t.cargo,{sha256Hex:t.sha256Hex,loops:t.loops})}async start(){if(this.#f)throw new Error("entity Apply rail already started");if(this.#e)throw new Error("entity Apply rail is stopped");this.#f=!0;const t=await this.#t.store.readOpenUnits();if(!Array.isArray(t)||new Set(t).size!==t.length||t.some(e=>!f.test(e)))throw new Error("entity Apply store returned an invalid open unit list");for(const e of t)this.#O(e,null);await this.#_()}fetch(t,e){return this.#f?this.#e?Promise.reject(new Error("entity Apply rail is stopped")):f.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.#O(t,null,e.emptied===!0),n=a(()=>this.#t.schedule.schedule(e.stall,()=>{r.waiters.delete(l)&&(r.emptied&&![...r.waiters].some(o=>o.emptied)&&(r.emptied=!1),s(this.#Q(r)))}),"arm");let h=n();const l={emptied:e.emptied===!0,answer:a(o=>{h.cancel(),s(o)},"answer"),fail:a(o=>{h.cancel(),i(o)},"fail"),moved:a(()=>{h.cancel(),h=n()},"moved")};r.waiters.add(l),r.waitsOn===null&&this.#R(r),this.#h()}):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(!f.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.#u("detect",t),this.#u("apply",t),this.#I()}sendAccepted(t){this.#u("send",t),this.#I()}capabilityChanged(t){this.#u("capability",t),this.#I()}#I(){!this.#f||this.#e||(this.#r=!0,this.#h())}waiting(){return this.#y().flatMap(t=>c(t.held)??[])}async flush(){if(!this.#f)throw new Error("entity Apply rail has not started");this.#e||await this.#_()}async stop(){if(this.#e)return;this.#e=!0,this.#q();for(const e of[this.#a,this.#d])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.#n;)await Promise.allSettled([...this.#a.steps,...this.#d.steps,...this.#n?[this.#n]:[]]);await this.#b.stop();for(const e of this.#m.splice(0))e.resolve()}#_(){return new Promise((t,e)=>{this.#m.push({resolve:t,reject:e}),this.#r=!0,this.#h()})}#h(){if(!this.#e){if(this.#r&&this.#n===null){this.#r=!1;const t=this.#W();this.#n=t,t.then(()=>{this.#n=null,this.#h()})}for(const[t,e]of[[this.#d,this.#P],[this.#a,this.#w]])for(;t.steps.size<e&&t.queue.length>0;){const s=t.queue.shift();s.queued=!1,this.#z(s,t)}if(this.#B()===0&&this.#n===null&&!this.#r&&this.#a.queue.length===0&&this.#d.queue.length===0){if(this.#v.clear(),this.#j(this.#t.now())){this.#h();return}this.#S();for(const t of this.#m.splice(0))t.resolve();this.#T()}}}#B(){return this.#a.steps.size+this.#d.steps.size}#y(){return[...this.#o.values(),...this.#s.values()]}#k(t){return t.kind==="line"?this.#o.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.#a:this.#d).queue.push(t))}}#z(t,e){t.running=!0,t.again=!1;const s=(t.kind==="line"?this.#D(t):this.#F(t)).then(i=>{t.running=!1,e.steps.delete(s),(i||t.again)&&this.#k(t)&&(t.again=!1,this.#i(t)),this.#h()});e.steps.add(s)}async#W(){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.#c=1/0;const e=new Set(t);for(const[s,i]of this.#o)!e.has(s)&&!i.running&&!i.queued&&this.#o.delete(s);for(const s of t){let i=this.#o.get(s);i||(i=v(s),this.#o.set(s,i)),this.#i(i)}}catch(t){this.#c=this.#t.now()+p;const e=this.#m.splice(0);e.length===0&&this.#$(t);for(const s of e)s.reject(t)}}async#D(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,t.endsBefore);if(b(t.authorityId,i),this.#e)return!1;if(i.kind==="end"){t.held=null;const r=t.endsBefore!==null;return t.endsBefore=null,r}return i.window.deliverySequence!==null&&this.#b.advance(t.authorityId,i.window.deliverySequence),await this.#L(t,i.window,s)}catch(e){return this.#Y(t,e),!1}}async#F(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.through);if(k(t.unit,i),this.#e||!this.#k(t))return!1;switch(t.through!==null&&i.through>t.through&&t.met.clear(),t.through=Math.max(t.through??0,i.through),t.waitsOn=null,i.kind!=="window"&&(t.held=null),i.kind){case"end":return this.#l(t,{kind:"placed"}),!1;case"nowhere":return this.#l(t,{kind:"nowhere",reason:i.reason}),!1;case"root":return await this.#J(t,i.through,i.reason);case"prerequisite":return this.#H(t,i.unit,i.reason,s);case"window":return await this.#L(t,i.window,s)}}catch(e){return this.#Y(t,e),!1}}async#J(t,e,s){return t.met.has(t.unit)?(this.#l(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))}#O(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=E(t,e,s),this.#s.set(t,i),this.#i(i)),i}#H(t,e,s,i){if(t.met.has(e))return this.#l(t,{kind:"held",unit:e,reason:`${e} placed and still needed: ${s}`}),!1;if(!this.#x(t,e,s))return!1;const r={producer:"apply",entityIds:[e]};return t.held={entityId:null,target:null,kept:null,cutoff:null,attempt:1,notBefore:1/0,releaseOnProgress:!1,due:this.#C(r,i),reason:s,dependency:r},t.held.due}#R(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.#x(t,s,e.reason))return}}#x(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.#l(n,{kind:"held",unit:e,reason:`prerequisite cycle through ${e}: ${s}`});return!1}return t.waitsOn??=e,this.#i(this.#O(e,t.through)),!0}#l(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.#l(i,s);continue}i.met.add(t.unit)}e.kind==="placed"&&(this.#E(t.unit),this.#u("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()}}#Q(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#L(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.#V(t,e))return!1;const r=await I(()=>this.#g.run(e,()=>t.kind==="lane"&&t.emptied?t.unit:null));if(r==="progress")return this.#X(t,e.members.map(n=>n.work.entityId));if(r==="again")return t.held?.entityId===i&&(t.held=null),!0;if(r.advanced?.length&&this.#N(t,r.advanced),t.kind==="line"){const n=$(e,r.dependency);if(n!==null)return t.endsBefore=n,!0}return this.#G(t,e,r,s),t.kind==="lane"&&this.#R(t),t.held.due}async#V(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.#g.targetOf(e)!==s.target||e.cutoff!==s.cutoff?!1:await this.#t.store.localWorkAfter(e.authorityId,i.work.entityId,s.kept??s.target)===null}#X(t,e){return t.held&&(t.held.entityId===null||e.includes(t.held.entityId))&&(t.held=null),this.#N(t,e),!0}#N(t,e){t.kind==="lane"&&(this.#r=!0,this.#E(t.unit)),this.#u("apply",e);for(const s of this.#y())s!==t&&s.held?.releaseOnProgress&&!s.held.due&&(s.held.due=!0,this.#i(s))}#G(t,e,s,i){if(s.dependency&&P(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=(n?.entityId===r?n.attempt:0)+1,l=this.#U(h),o={entityId:r,target:this.#g.targetOf(e),kept:e.members[0].work.kept,cutoff:e.cutoff,attempt:h,notBefore:s.dependency?1/0:this.#t.now()+l,releaseOnProgress:s.releaseOnProgress,due:s.dependency?this.#C(s.dependency,s.comparedAt??i):!1,reason:s.reason,...s.dependency?{dependency:s.dependency}:{},...s.blocker?{blocker:s.blocker}:{}};t.held=o,this.#S();const w=c(n),u=c(o);u&&JSON.stringify(u)!==JSON.stringify(w)&&this.#t.onWaiting?.(u),!(!s.report&&h<M)&&this.#$(new Error(`${y(t)} holds at ${r}, which ${s.releaseOnProgress?"is parked on a conflict":s.report?"failed":"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.#U(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.#S(),this.#$(new Error(`${y(t)} faulted and will retry in ${r}ms (attempt ${i}): ${n}`,{cause:e}))}#$(t){try{this.#M(t)}catch{}}#U(t){const e=Math.min(p,q*2**Math.min(t-1,16)),s=Math.max(0,Math.min(1,this.#t.schedule.random()));return Math.round(e*(.5+s))}#u(t,e){const s=++this.#A;for(const i of e??["*"])this.#v.set(`${t}:${i}`,s);for(const i of this.#y())O(i,t,e)&&this.#i(i)}#C(t,e){return["*",...t.entityIds].some(s=>(this.#v.get(`${t.producer}:${s}`)??0)>e)}#S(){if(this.#e)return;let t=this.#c;for(const i of this.#y())i.held&&!i.held.due&&(t=Math.min(t,i.held.notBefore));if(t===1/0){this.#q();return}if(this.#p?.dueAt===t)return;this.#q();const e=Math.max(0,t-this.#t.now()),s=this.#t.schedule.schedule(e,()=>{this.#p=null,this.#j(t),this.#h()});this.#p={dueAt:t,cancel:a(()=>s.cancel(),"cancel")}}#j(t){let e=!1;for(const s of this.#y())s.held&&!s.held.due&&s.held.notBefore<=t&&(s.held.due=!0,this.#i(s),e=!0);return this.#c<=t&&(this.#c=1/0,this.#r=!0,e=!0),e}#q(){this.#p?.cancel(),this.#p=null}}const y=a(d=>d.kind==="line"?`entity Apply line ${d.authorityId}`:`entity Apply fetch of ${d.unit}`,"label");export{S as ENTITY_APPLY_DEFAULT_CONCURRENCY,M as ENTITY_APPLY_QUIET_ATTEMPTS,q as ENTITY_APPLY_RETRY_BASE_MS,p as ENTITY_APPLY_RETRY_MAX_MS,Y as EntityApplyRail};
1
+ var E=Object.defineProperty;var d=(o,e)=>E(o,"name",{value:e,configurable:!0});import{UUID_PATTERN as u}from"../entities/types.js";import{FetchAhead as b}from"./fetch-ahead.js";import{EntityApplyJourney as P,outcomeOf as g,stepsAside as O}from"./journey.js";import{assertApplyLaneStep as v,createApplyLane as S}from"./lane.js";import{assertApplyDependency as $,assertApplyLineStep as q,createApplyLine as M,heldWait as c,releaseApplyLine as _}from"./line.js";import{windowEndForWait as m}from"./window.js";const x=8,B=1e3,A=3e4,p=3;class C{static{d(this,"EntityApplyRail")}#e;#g;#P;#M;#_;#o;#O;#d=!1;#t=!1;#a=new Map;#s=new Map;#l={queue:[],steps:new Set};#u={queue:[],steps:new Set};#n=!1;#h=null;#p=1/0;#m=[];#A=0;#v=new Map;#y=null;constructor(e){this.#e=e,this.#g=e.concurrency??x,this.#P=e.laneConcurrency??this.#g,this.#M=e.onBackgroundError??(()=>{}),this.#_=e.onIdle??(()=>{});for(const[t,s]of[["concurrency",this.#g],["lane concurrency",this.#P]])if(!Number.isSafeInteger(s)||s<1)throw new Error(`entity Apply ${t} must be a positive integer`);this.#o=new P(e,()=>this.#A,()=>this.#t),this.#O=new b(e.cargo,{sha256Hex:e.sha256Hex,loops:e.loops})}async start(){if(this.#d)throw new Error("entity Apply rail already started");if(this.#t)throw new Error("entity Apply rail is stopped");this.#d=!0;const e=await this.#e.store.readOpenUnits();if(!Array.isArray(e)||new Set(e).size!==e.length||e.some(t=>!u.test(t)))throw new Error("entity Apply store returned an invalid open unit list");for(const t of e)this.#E(t,null);await this.#x()}fetch(e,t){return this.#d?this.#t?Promise.reject(new Error("entity Apply rail is stopped")):u.test(e)?!Number.isFinite(t.stall)||t.stall<0?Promise.reject(new Error("entity Apply fetch needs a non-negative stall")):t.emptied!==void 0&&typeof t.emptied!="boolean"?Promise.reject(new Error("entity Apply fetch emptied must be a boolean")):new Promise((s,i)=>{const r=this.#E(e,null,t.emptied===!0),n=d(()=>this.#e.schedule.schedule(t.stall,()=>{r.waiters.delete(l)&&(r.emptied&&![...r.waiters].some(a=>a.emptied)&&(r.emptied=!1),s(this.#G(r)))}),"arm");let h=n();const l={emptied:t.emptied===!0,answer:d(a=>{h.cancel(),s(a)},"answer"),fail:d(a=>{h.cancel(),i(a)},"fail"),moved:d(()=>{h.cancel(),h=n()},"moved")};r.waiters.add(l),r.waitsOn===null&&this.#N(r),this.#r()}):Promise.reject(new Error("entity Apply fetch needs a unit UUID")):Promise.reject(new Error("entity Apply rail has not started"))}progressed(e,t){if(!u.test(e))throw new Error("entity Apply progress needs a unit UUID");if(!Number.isSafeInteger(t)||t<0)throw new Error("entity Apply progress needs a byte count");t>0&&!this.#t&&this.#b(e)}recordsAvailable(){this.#I()}localStateChanged(e){this.#c("detect",e),this.#c("apply",e),this.#I()}sendAccepted(e){this.#c("send",e),this.#I()}capabilityChanged(e){this.#c("capability",e),this.#I()}owe(e){if(e.some(t=>!u.test(t)))throw new Error("entity Apply owe needs entity UUIDs");if(!(!this.#d||this.#t)){for(const t of e)this.#R(t);this.#r()}}#I(){!this.#d||this.#t||(this.#n=!0,this.#r())}waiting(){return this.#w().flatMap(e=>c(e.held,y(e))??[])}async flush(){if(!this.#d)throw new Error("entity Apply rail has not started");this.#t||await this.#x()}async stop(){if(this.#t)return;this.#t=!0,this.#q();for(const t of[this.#l,this.#u])for(const s of t.queue.splice(0))s.queued=!1;const e=new Error("entity Apply rail stopped before the fetch answered");for(const t of this.#s.values())for(const s of t.waiters)s.fail(e);for(this.#s.clear();this.#B()>0||this.#h;)await Promise.allSettled([...this.#l.steps,...this.#u.steps,...this.#h?[this.#h]:[]]);await this.#O.stop();for(const t of this.#m.splice(0))t.resolve()}#x(){return new Promise((e,t)=>{this.#m.push({resolve:e,reject:t}),this.#n=!0,this.#r()})}#r(){if(!this.#t){if(this.#n&&this.#h===null){this.#n=!1;const e=this.#F();this.#h=e,e.then(()=>{this.#h=null,this.#r()})}for(const[e,t]of[[this.#u,this.#P],[this.#l,this.#g]])for(;e.steps.size<t&&e.queue.length>0;){const s=e.queue.shift();s.queued=!1,this.#D(s,e)}if(this.#B()===0&&this.#h===null&&!this.#n&&this.#l.queue.length===0&&this.#u.queue.length===0){if(this.#v.clear(),this.#z(this.#e.now())){this.#r();return}this.#$();for(const e of this.#m.splice(0))e.resolve();this.#_()}}}#B(){return this.#l.steps.size+this.#u.steps.size}#w(){return[...this.#a.values(),...this.#s.values()]}#k(e){return e.kind==="line"?this.#a.get(e.authorityId)===e:this.#s.get(e.unit)===e}#i(e){if(!this.#t){if(e.running){e.again=!0;return}e.queued||(e.queued=!0,(e.kind==="line"?this.#l:this.#u).queue.push(e))}}#D(e,t){e.running=!0,e.again=!1;const s=(e.kind==="line"?this.#J(e):this.#H(e)).then(i=>{e.running=!1,t.steps.delete(s),(i||e.again)&&this.#k(e)&&(e.again=!1,this.#i(e)),this.#r()});t.steps.add(s)}async#F(){try{const e=await this.#e.store.readApplyAuthorities();if(!Array.isArray(e)||new Set(e).size!==e.length||e.some(s=>typeof s!="string"||s.length===0))throw new Error("entity Apply store returned an invalid authority list");this.#p=1/0;const t=new Set(e);for(const[s,i]of this.#a)!t.has(s)&&!i.running&&!i.queued&&this.#a.delete(s);for(const s of e){let i=this.#a.get(s);i||(i=M(s),this.#a.set(s,i)),this.#i(i)}}catch(e){this.#p=this.#e.now()+A;const t=this.#m.splice(0);t.length===0&&this.#S(e);for(const s of t)s.reject(e)}}async#J(e){try{const t=e.held;if(t&&t.entityId===null&&!t.due&&t.notBefore>this.#e.now())return!1;const s=this.#A,i=await this.#e.store.readApplyWindow(e.authorityId,e.endsBefore);if(q(e.authorityId,i),this.#t)return!1;if(i.kind==="end"){e.held=null;const r=e.endsBefore!==null;return e.endsBefore=null,r}return i.window.deliverySequence!==null&&this.#O.advance(e.authorityId,i.window.deliverySequence),await this.#L(e,i.window,s)}catch(t){return this.#j(e,t),!1}}async#H(e){try{const t=e.held;if(t&&t.entityId===null&&!t.due&&t.notBefore>this.#e.now())return!1;const s=this.#A,i=await this.#e.store.readFetchWindow(e.unit,e.toPrefix?null:e.through);if(v(e.unit,i),this.#t||!this.#k(e))return!1;switch((i.kind!=="window"||i.window.intent===null)&&(e.toPrefix=!1),e.through!==null&&i.through>e.through&&e.met.clear(),e.through=Math.max(e.through??0,i.through),e.waitsOn=null,i.kind!=="window"&&(e.held=null),i.kind){case"end":return this.#f(e,{kind:"placed"}),!1;case"nowhere":return this.#f(e,{kind:"nowhere",reason:i.reason}),!1;case"root":return await this.#V(e,i.through,i.reason);case"prerequisite":return this.#X(e,i.unit,i.reason,s);case"window":return await this.#L(e,i.window,s)}}catch(t){return this.#j(e,t),!1}}async#V(e,t,s){return e.met.has(e.unit)?(this.#f(e,{kind:"held",unit:e.unit,reason:`${e.unit} entered and still not held: ${s}`}),!1):(await this.#e.effects.enterRoot(e.unit,t),this.#t||!this.#k(e)?!1:(e.through===t&&e.met.add(e.unit),this.#b(e.unit),!0))}#R(e){const t=this.#E(e,null);t.toPrefix=!0,t.met.clear(),this.#i(t)}#E(e,t,s=!1){let i=this.#s.get(e);return i?t!==null&&(i.through===null||i.through<t)&&(i.through=t,i.met.clear(),this.#i(i)):(i=S(e,t,s),this.#s.set(e,i),this.#i(i)),i}#X(e,t,s,i){if(e.met.has(t))return this.#f(e,{kind:"held",unit:t,reason:`${t} placed and still needed: ${s}`}),!1;if(!this.#T(e,t,s))return!1;const r={producer:"apply",entityIds:[t]};return e.held={entityId:null,target:null,kept:null,cutoff:null,attempt:1,notBefore:1/0,releaseOnProgress:!1,due:this.#W(r,i),reason:s,dependency:r},e.held.due}#N(e){const t=e.held;if(t?.dependency?.producer==="apply"){for(const s of t.dependency.entityIds)if(s!==e.unit&&!e.met.has(s)&&!this.#T(e,s,t.reason))return}}#T(e,t,s){const i=[e];let r=this.#s.get(t);for(;r&&r!==e&&!i.includes(r);)i.push(r),r=r.waitsOn===null?void 0:this.#s.get(r.waitsOn);if(r===e){for(const n of i)this.#f(n,{kind:"held",unit:t,reason:`prerequisite cycle through ${t}: ${s}`});return!1}return e.waitsOn??=t,this.#i(this.#E(t,e.through)),!0}#f(e,t){if(!this.#k(e))return;for(const i of e.waiters)i.answer(t);e.waiters.clear(),e.waitsOn=null,(t.kind==="placed"||e.held?.entityId==null)&&this.#s.delete(e.unit);const s=t.kind==="placed"||t.kind==="held"?t:{kind:"held",unit:e.unit,reason:`${e.unit} is nowhere here: ${t.reason}`};for(const i of[...this.#s.values()])if(i.waitsOn===e.unit){if(t.kind!=="placed"){this.#f(i,s);continue}i.met.add(e.unit)}t.kind==="placed"&&(this.#b(e.unit),this.#c("apply",[e.unit]))}#b(e){const t=new Map([[e,!0]]);for(const s of this.#s.values()){const i=new Set;let r=s.unit;for(;r!==null&&!t.has(r)&&!i.has(r);)i.add(r),r=this.#s.get(r)?.waitsOn??null;const n=r!==null&&t.get(r)===!0;for(const h of i)t.set(h,n);if(n)for(const h of s.waiters)h.moved()}}#G(e){let t=e;const s=new Set([e]);for(let i=e.waitsOn===null?void 0:this.#s.get(e.waitsOn);i&&!s.has(i);i=i.waitsOn===null?void 0:this.#s.get(i.waitsOn))s.add(i),t=i;return{kind:"held",unit:t.unit,reason:t.held?.reason??"still placing"}}async#L(e,t,s){const i=t.members[0]?.work.entityId??null;if(e.held&&e.held.entityId!==null&&e.held.entityId!==i&&(e.held=null),await this.#Q(e,t))return!1;let r=await g(()=>this.#o.run(t,()=>e.kind==="lane"&&e.emptied?e.unit:null));if(e.kind==="line"&&typeof r=="object"&&r.kind==="park"&&m(t,r.dependency)===null&&this.#K(e,t,r)&&(r=await g(()=>this.#o.alone(t.members[0]))),r==="progress"||typeof r=="object"&&r.kind==="alone"){if(e.kind==="line")for(const n of t.members)(n.judgment==="waiting"||r!=="progress"&&n.work.entityId===r.entityId)&&this.#R(n.work.entityId);return this.#Z(e,r==="progress"?t.members.map(n=>n.work.entityId):[r.entityId])}if(r==="again")return e.held?.entityId===i&&(e.held=null),!0;if(r.advanced?.length&&this.#Y(e,r.advanced),e.kind==="line"){const n=m(t,r.dependency);if(n!==null)return e.endsBefore=n,!0}return this.#ee(e,t,r,s),e.kind==="lane"&&this.#N(e),e.held.due}#K(e,t,s){const i=t.members[0].work.entityId;if(s.cause!==void 0||!O(t,i))return!1;const r=s.dependency?.entityIds??[i];return r.length===0||r.some(n=>n!==i)?!1:s.dependency?.producer==="capability"?!0:this.#U(e,t)>=p}#U(e,t){const s=e.held,i=t.members[0].work.entityId;return(s?.entityId===i&&s.target===this.#o.targetOf(t)?s.attempt:0)+1}async#Q(e,t){const s=e.held,i=t.members[0];return!s||i===void 0||s.entityId!==i.work.entityId||s.due||s.notBefore<=this.#e.now()||this.#o.targetOf(t)!==s.target||t.cutoff!==s.cutoff?!1:await this.#e.store.localWorkAfter(t.authorityId,i.work.entityId,s.kept??s.target)===null}#Z(e,t){return e.held&&(e.held.entityId===null||t.includes(e.held.entityId))&&(e.held=null),this.#Y(e,t),!0}#Y(e,t){e.kind==="lane"&&(this.#n=!0,this.#b(e.unit)),this.#c("apply",t);for(const s of this.#w())s!==e&&s.held?.releaseOnProgress&&!s.held.due&&(s.held.due=!0,this.#i(s))}#ee(e,t,s,i){if(s.dependency&&$(s.dependency),s.blocker&&!s.dependency)throw new Error("Apply blocker must name the dependency that releases it");const r=t.members[0].work.entityId,n=e.held,h=this.#U(e,t),l=this.#C(h),a=s.again===!0&&h<p,w={entityId:r,target:this.#o.targetOf(t),kept:t.members[0].work.kept,cutoff:t.cutoff,attempt:h,notBefore:s.dependency?1/0:this.#e.now()+(a?0:l),releaseOnProgress:s.releaseOnProgress,due:s.dependency?this.#W(s.dependency,s.comparedAt??i):a,reason:s.reason,...s.dependency?{dependency:s.dependency}:{},...s.blocker?{blocker:s.blocker}:{}};e.held=w,this.#$();const k=c(n,y(e)),f=c(w,y(e));f&&JSON.stringify(f)!==JSON.stringify(k)&&this.#e.onWaiting?.(f),!(!s.report&&(s.dependency!==void 0||h<p))&&this.#S(new Error(`${I(e)} holds at ${r}, which ${s.releaseOnProgress?"is parked on a conflict":s.report?"failed":s.again?"keeps ending unplaced":"stands on ground that keeps moving"}, and will retry in ${l}ms (attempt ${h}): ${s.reason}`,s.cause===void 0?void 0:{cause:s.cause}))}#j(e,t){if(e.kind==="lane"){for(const h of e.waiters)h.fail(t);e.waiters.clear()}const s=e.held,i=(s?.entityId===null?s.attempt:0)+1,r=this.#C(i),n=t instanceof Error?t.message:String(t);e.held={entityId:null,target:null,kept:null,cutoff:null,attempt:i,notBefore:this.#e.now()+r,releaseOnProgress:!1,due:!1,reason:n},this.#$(),this.#S(new Error(`${I(e)} faulted and will retry in ${r}ms (attempt ${i}): ${n}`,{cause:t}))}#S(e){try{this.#M(e)}catch{}}#C(e){const t=Math.min(A,B*2**Math.min(e-1,16)),s=Math.max(0,Math.min(1,this.#e.schedule.random()));return Math.round(t*(.5+s))}#c(e,t){const s=++this.#A;for(const i of t??["*"])this.#v.set(`${e}:${i}`,s);for(const i of this.#w())_(i,e,t)&&this.#i(i)}#W(e,t){return["*",...e.entityIds].some(s=>(this.#v.get(`${e.producer}:${s}`)??0)>t)}#$(){if(this.#t)return;let e=this.#p;for(const i of this.#w())i.held&&!i.held.due&&(e=Math.min(e,i.held.notBefore));if(e===1/0){this.#q();return}if(this.#y?.dueAt===e)return;this.#q();const t=Math.max(0,e-this.#e.now()),s=this.#e.schedule.schedule(t,()=>{this.#y=null,this.#z(e),this.#r()});this.#y={dueAt:e,cancel:d(()=>s.cancel(),"cancel")}}#z(e){let t=!1;for(const s of this.#w())s.held&&!s.held.due&&s.held.notBefore<=e&&(s.held.due=!0,this.#i(s),t=!0);return this.#p<=e&&(this.#p=1/0,this.#n=!0,t=!0),t}#q(){this.#y?.cancel(),this.#y=null}}const y=d(o=>o.kind==="line"?o.authorityId:o.unit,"owner"),I=d(o=>o.kind==="line"?`entity Apply line ${o.authorityId}`:`entity Apply fetch of ${o.unit}`,"label");export{x as ENTITY_APPLY_DEFAULT_CONCURRENCY,B as ENTITY_APPLY_RETRY_BASE_MS,A as ENTITY_APPLY_RETRY_MAX_MS,p as ENTITY_APPLY_SAME_ANSWERS,C as EntityApplyRail};
@@ -2,12 +2,13 @@ import { type LocalWork, type OwnLine } from '../clash/local-work.js';
2
2
  import type { AcceptedEntityRecord } from '../records/contracts.js';
3
3
  import { type OutboxRow } from '../records/outbox.js';
4
4
  import { type ApplyPlay, type ShowingJudgment } from './showing.js';
5
- export type ApplySettlement = 'superseded' | 'own' | 'neither' | 'listed' | 'turn';
5
+ export type ApplySettlement = 'superseded' | 'own' | 'neither' | 'listed' | 'turn' | 'waiting';
6
6
  export type LineJudgment = ApplySettlement | ApplyPlay;
7
7
  export interface LineHeadFacts extends OwnLine {
8
8
  localWorkAfter(): LocalWork | null;
9
9
  outboxRow(): OutboxRow | undefined;
10
10
  showing(): ShowingJudgment;
11
+ waiting?(): boolean;
11
12
  }
12
13
  export declare function judgeLineHead(head: AcceptedEntityRecord, facts: LineHeadFacts): LineJudgment;
13
14
  export declare function isSettlement(judgment: LineJudgment): judgment is ApplySettlement;
@@ -1 +1 @@
1
- var t=Object.defineProperty;var n=(r,e)=>t(r,"name",{value:e,configurable:!0});import{localWorkWins as i,ownSettles as u}from"../clash/local-work.js";import{isOwnRecord as f}from"../records/outbox.js";import{APPLY_PLAYS as l}from"./showing.js";function w(r,e){if(r.change.turn!==void 0)return"turn";if(i(r.change.result.type,e.localWorkAfter()))return"superseded";const o=e.outboxRow();return o!==void 0&&f(o,r)&&u(r,e)?"own":e.showing()}n(w,"judgeLineHead");function c(r){return!l.has(r)}n(c,"isSettlement");export{c as isSettlement,w as judgeLineHead};
1
+ var o=Object.defineProperty;var e=(r,n)=>o(r,"name",{value:n,configurable:!0});import{localWorkWins as i,ownSettles as u}from"../clash/local-work.js";import{isOwnRecord as f}from"../records/outbox.js";import{APPLY_PLAYS as w}from"./showing.js";function g(r,n){if(r.change.turn!==void 0)return"turn";if(n.waiting?.()===!0)return"waiting";if(i(r.change.result.type,n.localWorkAfter()))return"superseded";const t=n.outboxRow();return t!==void 0&&f(t,r)&&u(r,n)?"own":n.showing()}e(g,"judgeLineHead");function s(r){return!w.has(r)}e(s,"isSettlement");export{s as isSettlement,g as judgeLineHead};
@@ -1 +1 @@
1
- var M=Object.defineProperty;var a=(r,s)=>M(r,"name",{value:s,configurable:!0});import{collisionBases as k}from"../entities/rules.js";import{CONTAINERS as z,isConstructType as $}from"../entities/types.js";const D=4096;function E(r,s=D){const d=new Map;let p=0;for(const i of r){const{entityId:f}=i.record;let l=d.get(f);if(l===void 0){if(d.size===s)break;d.set(f,l={records:[],deliverySequence:i.deliverySequence,through:0})}const t=l.records.at(-1);if(t!==void 0&&t.change.turn===void 0!=(i.record.change.turn===void 0))break;if(t!==void 0&&i.record.globalSequence!==t.globalSequence+1)throw new Error(`entity ${f} has a gap before sequence ${i.record.globalSequence} inside its window`);l.records.push(i.record),l.through=p=i.deliverySequence}return Object.freeze({members:Object.freeze([...d].map(([i,{records:f,deliverySequence:l,through:t}])=>Object.freeze({entityId:i,records:Object.freeze(f),deliverySequence:l,through:t}))),through:p})}a(E,"foldWindow");function B(r,s,d,p=D){const i=new Map;for(let f=r;;){const l=E(f,p).members.map(o=>{const y=`${o.entityId}:${o.records.at(-1).globalSequence}`;let g=i.get(y);return g===void 0&&i.set(y,g=s(o)),{member:o,judgment:g.judgment,result:g.result}}),t=C(l,d);if(t===null)return l;f=f.slice(0,f.findIndex(o=>o.deliverySequence>=t))}}a(B,"readWindow");const W=a((r,s)=>r!==void 0&&(r.root?r.type!==s.type:r.parentUUID!==s.parentUUID||r.name!==s.name||r.type!==s.type),"movesPlace");function C(r,s){const d=new Set,p=new Set;let i=null;for(const{member:n,judgment:e,result:u}of r)e==="leave"?p.add(n.entityId):(e==="enter"||e==="apply"&&W(s(n.entityId),u))&&d.add(n.entityId),e==="enter"&&z.has(u.type)&&n.through<(i?.through??1/0)&&(i=n);if(d.size===0&&p.size===0)return null;const f=new Map(r.map(({member:n})=>[n.entityId,n.deliverySequence])),l=a((n,e)=>n===null?[]:[e,...k(e)].map(u=>`${n}/${u}`),"slotKeys"),t=a(({member:n,result:e})=>e.status==="active"&&!s(n.entityId)?.root?l(e.parentUUID,e.name):[],"goesTo"),o=a(n=>{const e=s(n.member.entityId);return[...e&&!e.root?l(e.parentUUID,e.name):[],...t(n)]},"slotsOf"),y=new Map,g=new Map,j=a((n,e,u)=>{for(const h of e){const c=n.get(h);c===void 0?n.set(h,[u]):c.length<2&&!c.includes(u)&&c.push(u)}},"note");for(const n of r){const{entityId:e}=n.member;d.has(e)&&j(g,t(n),e),(d.has(e)||p.has(e))&&j(y,o(n),e)}const v=a((n,e)=>{let u;for(const h of l(e.parentUUID,e.name)){const[c,w]=g.get(h)??[],I=c===n?w:c;I!==void 0&&(u===void 0||f.get(I)<f.get(u))&&(u=I)}return u},"pusher"),S=a((n,e,u)=>{const h=new Set([n]);for(let c=e;c!==null&&!h.has(c);){h.add(c);const w=s(c),I=u(c,w);if(I!==void 0)return I;c=w.parentUUID}return null},"climbs"),O=a(n=>{const{member:e,judgment:u,result:h}=n;if(u==="superseded"||u==="own"||u==="turn")return[];if($(h.type))return[];const c=[];for(const U of o(n)){const[m,x]=y.get(U)??[],q=m===e.entityId?x:m;q!==void 0&&c.push(q)}const w=s(e.entityId);if(w&&!w.root){const U=S(e.entityId,w.parentUUID,(m,x)=>d.has(m)?m:!x||x.root?null:v(e.entityId,x));U!==null&&c.push(U)}if(h.status!=="active"||w?.root)return c;const I=S(e.entityId,h.parentUUID,(U,m)=>d.has(U)||p.has(U)?U:m?!m.available||!z.has(m.type)||m.root?null:v(e.entityId,m):i!==null&&e.through>i.through?i.entityId:null);return I!==null&&c.push(I),c},"partnersOf");let b=null;for(const n of r){const e=n.member.deliverySequence;if(b!==null&&e>=b)break;for(const u of O(n)){const h=Math.max(e,f.get(u));(b===null||h<b)&&(b=h)}}return b}a(C,"windowCut");function P(r,s){return r.intent!==null||r.unit!==null||s?.producer!=="apply"?null:r.members.slice(1).find(p=>s.entityIds.includes(p.work.entityId))?.deliverySequence??null}a(P,"windowEndForWait");function A(r){const s=new Map(r.map((t,o)=>[t.entityId,{member:t,index:o}])),d=new Map,p=new Set,i=a((t,o)=>{const y=d.get(t);if(y!==void 0)return y;if(o.has(t)){for(const O of o)p.add(O);return-1}const g=s.get(t);if(!g||g.member.parentUUID===null)return 0;const j=s.get(g.member.parentUUID);if(!j)return d.set(t,0),0;o.add(t);const v=i(j.member.entityId,o);o.delete(t);const S=v<0?-1:v+1;return S>=0&&d.set(t,S),S},"depthOf"),f=[],l=[];for(const[t,o]of r.entries()){const y=i(o.entityId,new Set);if(y<0){p.add(o.entityId);continue}(o.play==="leave"?l:f).push({id:o.entityId,depth:y,index:t})}return f.sort((t,o)=>t.depth-o.depth||t.index-o.index),l.sort((t,o)=>o.depth-t.depth||t.index-o.index),Object.freeze({order:Object.freeze([...f,...l].map(({id:t})=>t)),cycle:Object.freeze([...p])})}a(A,"revealOrder");function F(r,s){let d=0;for(;d<r.length&&s(r[d]);)d+=1;return r.slice(0,d)}a(F,"resolvedPrefix");export{D as WINDOW_MEMBERS,E as foldWindow,B as readWindow,F as resolvedPrefix,A as revealOrder,P as windowEndForWait};
1
+ var M=Object.defineProperty;var a=(r,s)=>M(r,"name",{value:s,configurable:!0});import{collisionBases as k}from"../entities/rules.js";import{CONTAINERS as z,isConstructType as $}from"../entities/types.js";const D=4096;function E(r,s=D){const d=new Map;let p=0;for(const u of r){const{entityId:f}=u.record;let l=d.get(f);if(l===void 0){if(d.size===s)break;d.set(f,l={records:[],deliverySequence:u.deliverySequence,through:0})}const t=l.records.at(-1);if(t!==void 0&&t.change.turn===void 0!=(u.record.change.turn===void 0))break;if(t!==void 0&&u.record.globalSequence!==t.globalSequence+1)throw new Error(`entity ${f} has a gap before sequence ${u.record.globalSequence} inside its window`);l.records.push(u.record),l.through=p=u.deliverySequence}return Object.freeze({members:Object.freeze([...d].map(([u,{records:f,deliverySequence:l,through:t}])=>Object.freeze({entityId:u,records:Object.freeze(f),deliverySequence:l,through:t}))),through:p})}a(E,"foldWindow");function B(r,s,d,p=D){const u=new Map;for(let f=r;;){const l=E(f,p).members.map(o=>{const y=`${o.entityId}:${o.records.at(-1).globalSequence}`;let g=u.get(y);return g===void 0&&u.set(y,g=s(o)),{member:o,judgment:g.judgment,result:g.result}}),t=C(l,d);if(t===null)return l;f=f.slice(0,f.findIndex(o=>o.deliverySequence>=t))}}a(B,"readWindow");const W=a((r,s)=>r!==void 0&&(r.root?r.type!==s.type:r.parentUUID!==s.parentUUID||r.name!==s.name||r.type!==s.type),"movesPlace");function C(r,s){const d=new Set,p=new Set;let u=null;for(const{member:n,judgment:e,result:i}of r)e==="leave"?p.add(n.entityId):(e==="enter"||e==="apply"&&W(s(n.entityId),i))&&d.add(n.entityId),e==="enter"&&z.has(i.type)&&n.through<(u?.through??1/0)&&(u=n);if(d.size===0&&p.size===0)return null;const f=new Map(r.map(({member:n})=>[n.entityId,n.deliverySequence])),l=a((n,e)=>n===null?[]:[e,...k(e)].map(i=>`${n}/${i}`),"slotKeys"),t=a(({member:n,result:e})=>e.status==="active"&&!s(n.entityId)?.root?l(e.parentUUID,e.name):[],"goesTo"),o=a(n=>{const e=s(n.member.entityId);return[...e&&!e.root?l(e.parentUUID,e.name):[],...t(n)]},"slotsOf"),y=new Map,g=new Map,j=a((n,e,i)=>{for(const h of e){const c=n.get(h);c===void 0?n.set(h,[i]):c.length<2&&!c.includes(i)&&c.push(i)}},"note");for(const n of r){const{entityId:e}=n.member;d.has(e)&&j(g,t(n),e),(d.has(e)||p.has(e))&&j(y,o(n),e)}const v=a((n,e)=>{let i;for(const h of l(e.parentUUID,e.name)){const[c,w]=g.get(h)??[],I=c===n?w:c;I!==void 0&&(i===void 0||f.get(I)<f.get(i))&&(i=I)}return i},"pusher"),S=a((n,e,i)=>{const h=new Set([n]);for(let c=e;c!==null&&!h.has(c);){h.add(c);const w=s(c),I=i(c,w);if(I!==void 0)return I;c=w.parentUUID}return null},"climbs"),O=a(n=>{const{member:e,judgment:i,result:h}=n;if(i==="superseded"||i==="own"||i==="turn"||i==="waiting")return[];if($(h.type))return[];const c=[];for(const U of o(n)){const[m,x]=y.get(U)??[],q=m===e.entityId?x:m;q!==void 0&&c.push(q)}const w=s(e.entityId);if(w&&!w.root){const U=S(e.entityId,w.parentUUID,(m,x)=>d.has(m)?m:!x||x.root?null:v(e.entityId,x));U!==null&&c.push(U)}if(h.status!=="active"||w?.root)return c;const I=S(e.entityId,h.parentUUID,(U,m)=>d.has(U)||p.has(U)?U:m?!m.available||!z.has(m.type)||m.root?null:v(e.entityId,m):u!==null&&e.through>u.through?u.entityId:null);return I!==null&&c.push(I),c},"partnersOf");let b=null;for(const n of r){const e=n.member.deliverySequence;if(b!==null&&e>=b)break;for(const i of O(n)){const h=Math.max(e,f.get(i));(b===null||h<b)&&(b=h)}}return b}a(C,"windowCut");function P(r,s){return r.intent!==null||r.unit!==null||s?.producer!=="apply"?null:r.members.slice(1).find(p=>s.entityIds.includes(p.work.entityId))?.deliverySequence??null}a(P,"windowEndForWait");function A(r){const s=new Map(r.map((t,o)=>[t.entityId,{member:t,index:o}])),d=new Map,p=new Set,u=a((t,o)=>{const y=d.get(t);if(y!==void 0)return y;if(o.has(t)){for(const O of o)p.add(O);return-1}const g=s.get(t);if(!g||g.member.parentUUID===null)return 0;const j=s.get(g.member.parentUUID);if(!j)return d.set(t,0),0;o.add(t);const v=u(j.member.entityId,o);o.delete(t);const S=v<0?-1:v+1;return S>=0&&d.set(t,S),S},"depthOf"),f=[],l=[];for(const[t,o]of r.entries()){const y=u(o.entityId,new Set);if(y<0){p.add(o.entityId);continue}(o.play==="leave"?l:f).push({id:o.entityId,depth:y,index:t})}return f.sort((t,o)=>t.depth-o.depth||t.index-o.index),l.sort((t,o)=>o.depth-t.depth||t.index-o.index),Object.freeze({order:Object.freeze([...f,...l].map(({id:t})=>t)),cycle:Object.freeze([...p])})}a(A,"revealOrder");function F(r,s){let d=0;for(;d<r.length&&s(r[d]);)d+=1;return r.slice(0,d)}a(F,"resolvedPrefix");export{D as WINDOW_MEMBERS,E as foldWindow,B as readWindow,F as resolvedPrefix,A as revealOrder,P as windowEndForWait};
@@ -10,6 +10,7 @@ export declare function packageProposalSteps(anchorId: string, records: readonly
10
10
  export declare function packageProposal(anchorId: string, records: readonly unknown[], sha256Hex: Sha256Hex): PackageProposal;
11
11
  export interface PackagedProposals {
12
12
  readonly proposals: readonly DetectedChangeProposal[];
13
+ readonly together: ReadonlyMap<string, readonly DetectedChangeProposal[]>;
13
14
  readonly pages: readonly RecordPage[];
14
15
  }
15
16
  export declare function packageProposalsSteps(proposals: readonly DetectedChangeProposal[], sha256Hex: Sha256Hex): Steps<PackagedProposals>;
@@ -1 +1 @@
1
- var b=Object.defineProperty;var f=(n,s)=>b(n,"name",{value:s,configurable:!0});import{assertRecord as O}from"../entities/cloud.js";import{packagePagesSteps as S}from"../entities/package-pages.js";import{CONTAINERS as w}from"../entities/types.js";import{eachStep as y,finishSteps as h}from"../steps.js";import{assertRepositoryReplay as C,CHANGE_PROPOSAL_CONTRACT as P,changeCargo as R,ownChange as M}from"./record-proposal.js";function*m(n,s,r){const i=yield*S(n,s,r);let p;for(const e of i)p??=e.items.find(t=>t.uuid===n.toLowerCase());const a=O(p),u={kind:"package",pages:Object.freeze(i.map(e=>e.ref))},l=Object.freeze({contract:P,origin:"detected",entityId:a.uuid,basedOnState:null,result:a,facets:Object.freeze(["create"]),replay:u,cargo:Object.freeze(R(a,u))}),d=M(l).replay;return d.kind==="repo.git"&&C(d,a),{proposal:l,pages:i}}f(m,"packageProposalSteps");function v(n,s,r){return h(m(n,s,r))}f(v,"packageProposal");function*j(n,s){const r=new Map;yield*y(n,e=>{e.basedOnState===null&&e.result.status==="active"&&r.set(e.entityId,e)});const i=f(e=>e!==null&&w.has(r.get(e)?.result.type??""),"isContainer"),p=new Map;yield*y([...r.keys()],e=>{const t=[];let o=null;for(let c=e;;){const k=p.get(c);if(k!==void 0){o=k;break}t.push(c);const g=r.get(c).result.parentUUID;if(i(g)&&!t.includes(g)){c=g;continue}o=i(c)&&!i(g)?c:null;break}for(const c of t)p.set(c,o)});const a=new Map;yield*y([...p],([e,t])=>{if(t===null)return;const o=a.get(t)??[];o.push(r.get(e).result),a.set(t,o)});const u=new Map;for(const[e,t]of a)t.length>1&&u.set(e,yield*m(e,t,s));const l=[],d=new Set;return yield*y(n,e=>{const t=p.get(e.entityId),o=t==null?void 0:u.get(t);if(!o){l.push(e);return}d.has(t)||(d.add(t),l.push(o.proposal))}),{proposals:l,pages:[...u.values()].flatMap(e=>e.pages)}}f(j,"packageProposalsSteps");function E(n,s){return h(j(n,s))}f(E,"packageProposals");export{v as packageProposal,m as packageProposalSteps,E as packageProposals,j as packageProposalsSteps};
1
+ var C=Object.defineProperty;var d=(s,a)=>C(s,"name",{value:a,configurable:!0});import{assertRecord as P}from"../entities/cloud.js";import{anchorsPackage as R,carriers as v,packagePagesSteps as x}from"../entities/package-pages.js";import{CONTAINERS as z}from"../entities/types.js";import{eachStep as g,finishSteps as j}from"../steps.js";import{assertRepositoryReplay as A,CHANGE_PROPOSAL_CONTRACT as N,changeCargo as T,ownChange as U}from"./record-proposal.js";function*I(s,a,c){const p=yield*x(s,a,c);let b;for(const u of p)b??=u.items.find(f=>f.uuid===s.toLowerCase());const o=P(b),i={kind:"package",pages:Object.freeze(p.map(u=>u.ref))},l=Object.freeze({contract:N,origin:"detected",entityId:o.uuid,basedOnState:null,result:o,facets:Object.freeze(["create"]),replay:i,cargo:Object.freeze(T(o,i))}),y=U(l).replay;return y.kind==="repo.git"&&A(y,o),{proposal:l,pages:p}}d(I,"packageProposalSteps");function q(s,a,c){return j(I(s,a,c))}d(q,"packageProposal");function*L(s,a){const c=new Map;yield*g(s,e=>{e.basedOnState===null&&e.result.status==="active"&&c.set(e.entityId,e)});const p=v([...c.values()].map(e=>e.result)),b=d(e=>{const{parentUUID:t}=c.get(e).result;return t===null?p.get(e)?.uuid??null:z.has(c.get(t)?.result.type??"")?t:null},"holderOf"),o=new Map;yield*g([...c.keys()],e=>{const t=[];let n=null;for(let r=e;;){const h=o.get(r);if(h!==void 0){n=h;break}t.push(r);const k=b(r);if(k!==null&&!t.includes(k)){r=k;continue}n=k===null&&R(c.get(r).result.type)?r:null;break}for(const r of t)o.set(r,n)});const i=new Map;yield*g([...o],([e,t])=>{if(t===null)return;const n=i.get(t)??[];n.push(c.get(e).result),i.set(t,n)});const l=new Map;for(const[e,t]of i)for(const n of t)l.set(n.uuid,e);const y=d(e=>e.basedOnState!==null&&e.replay.kind!=="package"&&e.joins===void 0&&e.turn===void 0,"joinable"),u=new Map;yield*g(s,e=>{const{type:t,payloadVersion:n}=e.result,r=t==="reference"&&n!==null?n.toLowerCase():null;y(e)&&r!==null&&l.get(r)===r&&u.set(e.entityId,r)});const f=new Map(u);yield*g(s,e=>{const{parentUUID:t}=e.result;if(!y(e)||f.has(e.entityId)||t===null)return;const n=l.get(t)??u.get(t);n!==void 0&&f.set(e.entityId,n)});const M=new Set(f.values()),m=new Map;for(const[e,t]of i)(t.length>1||M.has(e))&&m.set(e,yield*I(e,t,a));const w=new Map,O=[],S=new Set;return yield*g(s,e=>{const t=f.get(e.entityId);if(t!==void 0){const h=w.get(t)??[];h.push(e),w.set(t,h);return}const n=o.get(e.entityId),r=n==null?void 0:m.get(n);if(!r){O.push(e);return}S.has(n)||(S.add(n),O.push(r.proposal))}),{proposals:O,together:w,pages:[...m.values()].flatMap(e=>e.pages)}}d(L,"packageProposalsSteps");function B(s,a){return j(L(s,a))}d(B,"packageProposals");export{q as packageProposal,I as packageProposalSteps,B as packageProposals,L as packageProposalsSteps};
@@ -40,7 +40,6 @@ export interface Top {
40
40
  }
41
41
  export interface RootsPort {
42
42
  readonly home: Root;
43
- readonly computer: string | null;
44
43
  top(rootUUID: string): Promise<Top | null>;
45
44
  enter(rootUUID: string): Promise<Root | null>;
46
45
  }
@@ -1 +1 @@
1
- var v=Object.defineProperty;var c=(t,a)=>v(t,"name",{value:a,configurable:!0});import{CONTAINERS as E}from"../entities/types.js";import{active as p,derivedNames as m,entryOf as w,gitEntry as S,rootOf as y,shows as k,unshown as b,where as x}from"./where.js";async function R(t,a){const r=c(n=>!b(t,[...a,n]),"shown"),e=await x(t,a);switch(e.kind){case"shelf":{const n=await y(t,e.root);if(n===null)return{kind:"nowhere"};const s=n.shelf.names(e.address);if(s===null)return n.shelf.has(e.address)?{kind:"notdir"}:{kind:"nowhere"};const o=s.filter(r),l=new Set(s),f=(e.homes??[]).filter(i=>!l.has(i.name)&&r(i.name)),u={kind:"entries",root:e.root,address:e.address,shelf:o,entries:f,standing:[]};if(e.entity===null||!E.has(e.entity.type))return u;if(!await n.map.enter(e.entity.uuid))return{kind:"nowhere"};const h=m(p(n.map.children(e.entity.uuid))).filter(([i,d])=>k(i)!==null&&r(d)),N=h.filter(([i,d])=>!n.map.placed(i.uuid)&&!l.has(d)),O=h.filter(([i,d])=>n.map.placed(i.uuid)&&l.has(d)).map(([i,d])=>({name:d,uuid:i.uuid}));return{...u,entries:await g(t,N),standing:O}}case"listed":{if(e.entry.kind!=="directory")return{kind:"notdir"};const n=await y(t,e.root);if(n===null)return{kind:"nowhere"};if(!await n.map.enter(e.entry.uuid))return{kind:"nowhere"};const s=m(p(n.map.children(e.entry.uuid))).filter(([f,u])=>k(f)!==null&&r(u)),o=e.entry.type==="repo.git"?await S(n.map,e.entity):void 0;if(o===null)return{kind:"place-first",placing:e.placing};const l=[...await g(t,s),...o===void 0?[]:[o]];return{kind:"entries",root:e.root,address:e.address,shelf:[],entries:l,standing:[]}}case"door":return e.entry?.kind==="file"?{kind:"notdir"}:e.homes===void 0?{kind:"place-first",placing:e.placing}:{kind:"entries",root:e.root,address:e.address,shelf:[],entries:e.homes.filter(n=>r(n.name)),standing:[]};case"absent":return{kind:"nowhere"};default:return e}}c(R,"listing");async function g(t,a){const r=[];for(const[e,n]of a){const s=e.type==="reference"&&e.target!==null&&await t.top(e.target)!==null;r.push(s?w(e,n,"directory"):w(e,n))}return r}c(g,"entries");export{R as listing};
1
+ var v=Object.defineProperty;var c=(i,a)=>v(i,"name",{value:a,configurable:!0});import{CONTAINERS as E}from"../entities/types.js";import{active as p,derivedNames as m,entryOf as w,gitEntry as S,rootOf as y,shows as k,unshown as b,where as x}from"./where.js";async function R(i,a){const r=c(n=>!b([...a,n]),"shown"),e=await x(i,a);switch(e.kind){case"shelf":{const n=await y(i,e.root);if(n===null)return{kind:"nowhere"};const s=n.shelf.names(e.address);if(s===null)return n.shelf.has(e.address)?{kind:"notdir"}:{kind:"nowhere"};const o=s.filter(r),l=new Set(s),f=(e.homes??[]).filter(t=>!l.has(t.name)&&r(t.name)),u={kind:"entries",root:e.root,address:e.address,shelf:o,entries:f,standing:[]};if(e.entity===null||!E.has(e.entity.type))return u;if(!await n.map.enter(e.entity.uuid))return{kind:"nowhere"};const h=m(p(n.map.children(e.entity.uuid))).filter(([t,d])=>k(t)!==null&&r(d)),N=h.filter(([t,d])=>!n.map.placed(t.uuid)&&!l.has(d)),O=h.filter(([t,d])=>n.map.placed(t.uuid)&&l.has(d)).map(([t,d])=>({name:d,uuid:t.uuid}));return{...u,entries:await g(i,N),standing:O}}case"listed":{if(e.entry.kind!=="directory")return{kind:"notdir"};const n=await y(i,e.root);if(n===null)return{kind:"nowhere"};if(!await n.map.enter(e.entry.uuid))return{kind:"nowhere"};const s=m(p(n.map.children(e.entry.uuid))).filter(([f,u])=>k(f)!==null&&r(u)),o=e.entry.type==="repo.git"?await S(n.map,e.entity):void 0;if(o===null)return{kind:"place-first",placing:e.placing};const l=[...await g(i,s),...o===void 0?[]:[o]];return{kind:"entries",root:e.root,address:e.address,shelf:[],entries:l,standing:[]}}case"door":return e.entry?.kind==="file"?{kind:"notdir"}:e.homes===void 0?{kind:"place-first",placing:e.placing}:{kind:"entries",root:e.root,address:e.address,shelf:[],entries:e.homes.filter(n=>r(n.name)),standing:[]};case"absent":return{kind:"nowhere"};default:return e}}c(R,"listing");async function g(i,a){const r=[];for(const[e,n]of a){const s=e.type==="reference"&&e.target!==null&&await i.top(e.target)!==null;r.push(s?w(e,n,"directory"):w(e,n))}return r}c(g,"entries");export{R as listing};
@@ -60,7 +60,7 @@ export type Look = Extract<Where, {
60
60
  });
61
61
  export declare function glance(at: Where): Look | null;
62
62
  export declare function rootOf(roots: RootsPort, uuid: string): Promise<Root | null>;
63
- export declare function unshown(roots: RootsPort, path: readonly string[]): boolean;
63
+ export declare function unshown(path: readonly string[]): boolean;
64
64
  export declare function addressOnly(roots: RootsPort, path: readonly string[], at: Where | Place): boolean;
65
65
  export declare function childAt(map: MapPort, parentUUID: string, name: string): Promise<MapEntity | null>;
66
66
  export declare function shows(entity: MapEntity): MapEntity | null;
@@ -1,2 +1,2 @@
1
- var F=Object.defineProperty;var l=(e,n)=>F(e,"name",{value:n,configurable:!0});import{LOCAL_DIR_NAME as V}from"@amalgm/core/identity";import{isRepositoryMetadataEntry as N,REPOSITORY_METADATA as y}from"../detection/classify.js";import{inGitDirectory as P}from"./homes.js";import{utf8Length as I}from"../entities/bytes.js";import{collisionBases as L,fileAbsent as $,materializedSlotNames as j}from"../entities/rules.js";import{CONTAINERS as R}from"../entities/types.js";import{FILES_FOLDER as S}from"../registration/home-layout.js";function B(e){return e.kind==="directory"||e.size!==null}l(B,"described");async function re(e,n){if(z(e,n))return{kind:"nowhere"};const t=[];let r=!1,i=e.home.uuid,s=e.home.shelf,o=e.home.map,u=o.root(),d=[],v=u.name,w=!1;const O=l(()=>w?!1:s.has(d)?!0:(w=!0,!1),"standing");for(let a=0;;a+=1){const E=a===n.length,h=l(f=>[...d,...n.slice(f)],"whole");let m=o.placed(u.uuid),g=O();if(u.type==="reference"&&u.target!==null&&m===g){const f=await e.top(u.target);f!==null&&(!m&&!r&&t.push(b(i,u,d)),i=f.uuid,s=f.shelf,o=null,u=f.entity,d=[],w=!1,m=f.placed,g=O())}if(m){if(E)return{kind:"shelf",root:i,address:d,entity:u};if(!g)return{kind:"shelf",root:i,address:h(a),entity:null}}else{if(g)return{kind:"shelf",root:i,address:h(a),entity:null};{const f=u.type==="repo.git";if((f||!r)&&t.push(b(i,u,d)),f&&(r=!0),E)return{kind:"listed",root:i,address:d,entity:u,entry:k(u,v),placing:t};if(!R.has(u.type))return{kind:"notdir"}}}if(o??=(await e.enter(i))?.map??null,o===null||!await o.enter(u.uuid))return{kind:"nowhere"};const p=n[a],A=await C(o,u.uuid,p);if(d=[...d,p],v=p,A===null){if(r&&u.type==="repo.git"&&N(p)){const f=await G(o,u);return a+1===n.length?{kind:"door",root:i,address:h(a+1),entry:f,placing:t}:f?.kind==="file"?{kind:"notdir"}:{kind:"door",root:i,address:h(a+1),entry:null,placing:t}}return t.length===0?(u.type==="repo.git"&&u.gitHome===null&&N(p)&&s.has(d)?await P(o,s,i,u,d,n.slice(a+1)):null)??{kind:"shelf",root:i,address:h(a+1),entity:null}:a+1===n.length?{kind:"absent",root:i,address:d,placing:t}:{kind:"nowhere"}}u=A}}l(re,"where");function ie(e){return e.kind!=="listed"&&e.kind!=="door"?e:e.entry!==null&&B(e.entry)?{...e,entry:e.entry}:null}l(ie,"glance");async function ue(e,n){return n===e.home.uuid?e.home:await e.enter(n)}l(ue,"rootOf");function b(e,n,t){return{root:e,uuid:n.uuid,type:n.type,address:t}}l(b,"unitOf");function z(e,n){return n.some(t=>t.toLowerCase()===V)?!0:e.computer!==null&&n.length>=2&&n[0]===S&&n[1]===e.computer}l(z,"unshown");function le(e,n,t){return z(e,n)?!0:"root"in t?t.root===e.home.uuid?t.address[0]===S:t.address.length===0:!1}l(le,"addressOnly");async function C(e,n,t){if(!await e.enter(n))return null;const r=c(e.holders(n,t));if(r.length===1)return H(r[0]);if(r.length===0&&!T(e,n,t))return null;for(const[i,s]of _(c(e.children(n))))if(s===t)return H(i);return null}l(C,"childAt");function H(e){return $(e)?null:e}l(H,"shows");async function oe(e,n){const t=n.parentUUID;return t!==null&&await e.enter(t)&&M(e,t,n)}l(oe,"aloneInSlot");function M(e,n,t){const r=c(e.holders(n,t.name));return r.length===1&&r[0]?.uuid===t.uuid&&!T(e,n,t.name)}l(M,"soleHolder");async function se(e,n,t,r){if(!await e.enter(n))return!1;const i=x(t),s=new Map(L(t).map(o=>[x(o),0]));for(const o of c(e.children(n))){if(o.uuid===r)continue;const u=x(o.name);if(u===i)return!1;const d=s.get(u);d!==void 0&&s.set(u,d+1)}return[...s.values()].every(o=>o<2)}l(se,"freeName");function x(e){return e.normalize("NFC").toLowerCase()}l(x,"folded");function T(e,n,t){return L(t).some(r=>c(e.holders(n,r)).length>1)}l(T,"derivable");async function de(e,n){let t=e.root();for(const r of n){if(t.type==="repo.git")return!1;const i=await C(e,t.uuid,r);if(i===null)return!1;t=i}return t.type!=="repo.git"}l(de,"outsideRepositories");function _(e){const n=j(e);return e.map(t=>[t,n.get(t.uuid)??t.name])}l(_,"derivedNames");function k(e,n,t=K(e.type)){const r=e.type==="link"?e.target:null;return{name:n,uuid:e.uuid,type:e.type,kind:t,mode:e.fileMode,mtime:e.mtime,size:r!==null?I(r):e.size,target:r,version:e.version,payloadVersion:e.payloadVersion}}l(k,"entryOf");async function G(e,n){if(n.gitHome===null)return k(n,y,"directory");const t=await q(e,n),r=D(e,n);if(r===null||t===null)return null;const i=I(Y(r,t));return{...k(n,y,"file"),size:i,payloadVersion:null}}l(G,"gitEntry");function Y(e,n){let t=0;for(;t<e.length&&t<n.length&&e[t]===n[t];)t+=1;return`gitdir: ${[...e.slice(t).map(()=>".."),...n.slice(t)].join("/")}
2
- `}l(Y,"gitPointer");async function q(e,n){const t=[],r=new Set([n.uuid]);let i=n;for(;i.gitHome!==null;){const{entity:o,path:u}=i.gitHome;if(o===null||r.has(o))return null;r.add(o),t.push(u===""?[]:u.split("/"));const d=e.get(o)??(await e.enter(o)?e.get(o):void 0);if(d===void 0||d.type!=="repo.git"||d.status!=="active")return null;i=d}const s=D(e,i);return s===null?null:[...s,y,...t.reverse().flat()]}l(q,"gitDirectoryIn");function D(e,n){const t=e.root().uuid,r=[],i=new Set;for(let s=n;s.uuid!==t;){const o=s.parentUUID===null?void 0:e.get(s.parentUUID);if(o===void 0||i.has(s.uuid)||s.status!=="active")return null;i.add(s.uuid);const u=J(e,s);if(u===null)return null;r.push(u),s=o}return r.reverse()}l(D,"addressIn");function J(e,n){const t=n.parentUUID;if(M(e,t,n))return n.name;for(const[r,i]of _(c(e.children(t))))if(r.uuid===n.uuid)return i;return null}l(J,"shownName");function K(e){if(R.has(e))return"directory";if(e==="file.text"||e==="file.binary")return"file";if(e==="link"||e==="reference")return"link";throw new Error(`a ${e} cannot stand in a folder`)}l(K,"kindOf");function c(e){return e.filter(n=>n.status==="active")}l(c,"active");export{c as active,D as addressIn,le as addressOnly,oe as aloneInSlot,C as childAt,_ as derivedNames,B as described,k as entryOf,se as freeName,G as gitEntry,Y as gitPointer,ie as glance,K as kindOf,de as outsideRepositories,ue as rootOf,H as shows,z as unshown,re as where};
1
+ var D=Object.defineProperty;var o=(e,n)=>D(e,"name",{value:n,configurable:!0});import{LOCAL_DIR_NAME as F}from"@amalgm/core/identity";import{isRepositoryMetadataEntry as N,REPOSITORY_METADATA as y}from"../detection/classify.js";import{inGitDirectory as V}from"./homes.js";import{utf8Length as I}from"../entities/bytes.js";import{collisionBases as L,fileAbsent as P,materializedSlotNames as $}from"../entities/rules.js";import{CONTAINERS as R}from"../entities/types.js";import{FILES_FOLDER as j}from"../registration/home-layout.js";function B(e){return e.kind==="directory"||e.size!==null}o(B,"described");async function re(e,n){if(b(n))return{kind:"nowhere"};const t=[];let r=!1,i=e.home.uuid,s=e.home.shelf,l=e.home.map,u=l.root(),d=[],v=u.name,w=!1;const O=o(()=>w?!1:s.has(d)?!0:(w=!0,!1),"standing");for(let a=0;;a+=1){const E=a===n.length,h=o(f=>[...d,...n.slice(f)],"whole");let m=l.placed(u.uuid),g=O();if(u.type==="reference"&&u.target!==null&&m===g){const f=await e.top(u.target);f!==null&&(!m&&!r&&t.push(S(i,u,d)),i=f.uuid,s=f.shelf,l=null,u=f.entity,d=[],w=!1,m=f.placed,g=O())}if(m){if(E)return{kind:"shelf",root:i,address:d,entity:u};if(!g)return{kind:"shelf",root:i,address:h(a),entity:null}}else{if(g)return{kind:"shelf",root:i,address:h(a),entity:null};{const f=u.type==="repo.git";if((f||!r)&&t.push(S(i,u,d)),f&&(r=!0),E)return{kind:"listed",root:i,address:d,entity:u,entry:k(u,v),placing:t};if(!R.has(u.type))return{kind:"notdir"}}}if(l??=(await e.enter(i))?.map??null,l===null||!await l.enter(u.uuid))return{kind:"nowhere"};const p=n[a],A=await z(l,u.uuid,p);if(d=[...d,p],v=p,A===null){if(r&&u.type==="repo.git"&&N(p)){const f=await G(l,u);return a+1===n.length?{kind:"door",root:i,address:h(a+1),entry:f,placing:t}:f?.kind==="file"?{kind:"notdir"}:{kind:"door",root:i,address:h(a+1),entry:null,placing:t}}return t.length===0?(u.type==="repo.git"&&u.gitHome===null&&N(p)&&s.has(d)?await V(l,s,i,u,d,n.slice(a+1)):null)??{kind:"shelf",root:i,address:h(a+1),entity:null}:a+1===n.length?{kind:"absent",root:i,address:d,placing:t}:{kind:"nowhere"}}u=A}}o(re,"where");function ie(e){return e.kind!=="listed"&&e.kind!=="door"?e:e.entry!==null&&B(e.entry)?{...e,entry:e.entry}:null}o(ie,"glance");async function ue(e,n){return n===e.home.uuid?e.home:await e.enter(n)}o(ue,"rootOf");function S(e,n,t){return{root:e,uuid:n.uuid,type:n.type,address:t}}o(S,"unitOf");function b(e){return e.some(n=>n.toLowerCase()===F)}o(b,"unshown");function oe(e,n,t){return b(n)?!0:"root"in t?t.root===e.home.uuid?t.address[0]===j:t.address.length===0:!1}o(oe,"addressOnly");async function z(e,n,t){if(!await e.enter(n))return null;const r=c(e.holders(n,t));if(r.length===1)return C(r[0]);if(r.length===0&&!M(e,n,t))return null;for(const[i,s]of T(c(e.children(n))))if(s===t)return C(i);return null}o(z,"childAt");function C(e){return P(e)?null:e}o(C,"shows");async function le(e,n){const t=n.parentUUID;return t!==null&&await e.enter(t)&&H(e,t,n)}o(le,"aloneInSlot");function H(e,n,t){const r=c(e.holders(n,t.name));return r.length===1&&r[0]?.uuid===t.uuid&&!M(e,n,t.name)}o(H,"soleHolder");async function se(e,n,t,r){if(!await e.enter(n))return!1;const i=x(t),s=new Map(L(t).map(l=>[x(l),0]));for(const l of c(e.children(n))){if(l.uuid===r)continue;const u=x(l.name);if(u===i)return!1;const d=s.get(u);d!==void 0&&s.set(u,d+1)}return[...s.values()].every(l=>l<2)}o(se,"freeName");function x(e){return e.normalize("NFC").toLowerCase()}o(x,"folded");function M(e,n,t){return L(t).some(r=>c(e.holders(n,r)).length>1)}o(M,"derivable");async function de(e,n){let t=e.root();for(const r of n){if(t.type==="repo.git")return!1;const i=await z(e,t.uuid,r);if(i===null)return!1;t=i}return t.type!=="repo.git"}o(de,"outsideRepositories");function T(e){const n=$(e);return e.map(t=>[t,n.get(t.uuid)??t.name])}o(T,"derivedNames");function k(e,n,t=K(e.type)){const r=e.type==="link"?e.target:null;return{name:n,uuid:e.uuid,type:e.type,kind:t,mode:e.fileMode,mtime:e.mtime,size:r!==null?I(r):e.size,target:r,version:e.version,payloadVersion:e.payloadVersion}}o(k,"entryOf");async function G(e,n){if(n.gitHome===null)return k(n,y,"directory");const t=await q(e,n),r=_(e,n);if(r===null||t===null)return null;const i=I(Y(r,t));return{...k(n,y,"file"),size:i,payloadVersion:null}}o(G,"gitEntry");function Y(e,n){let t=0;for(;t<e.length&&t<n.length&&e[t]===n[t];)t+=1;return`gitdir: ${[...e.slice(t).map(()=>".."),...n.slice(t)].join("/")}
2
+ `}o(Y,"gitPointer");async function q(e,n){const t=[],r=new Set([n.uuid]);let i=n;for(;i.gitHome!==null;){const{entity:l,path:u}=i.gitHome;if(l===null||r.has(l))return null;r.add(l),t.push(u===""?[]:u.split("/"));const d=e.get(l)??(await e.enter(l)?e.get(l):void 0);if(d===void 0||d.type!=="repo.git"||d.status!=="active")return null;i=d}const s=_(e,i);return s===null?null:[...s,y,...t.reverse().flat()]}o(q,"gitDirectoryIn");function _(e,n){const t=e.root().uuid,r=[],i=new Set;for(let s=n;s.uuid!==t;){const l=s.parentUUID===null?void 0:e.get(s.parentUUID);if(l===void 0||i.has(s.uuid)||s.status!=="active")return null;i.add(s.uuid);const u=J(e,s);if(u===null)return null;r.push(u),s=l}return r.reverse()}o(_,"addressIn");function J(e,n){const t=n.parentUUID;if(H(e,t,n))return n.name;for(const[r,i]of T(c(e.children(t))))if(r.uuid===n.uuid)return i;return null}o(J,"shownName");function K(e){if(R.has(e))return"directory";if(e==="file.text"||e==="file.binary")return"file";if(e==="link"||e==="reference")return"link";throw new Error(`a ${e} cannot stand in a folder`)}o(K,"kindOf");function c(e){return e.filter(n=>n.status==="active")}o(c,"active");export{c as active,_ as addressIn,oe as addressOnly,le as aloneInSlot,z as childAt,T as derivedNames,B as described,k as entryOf,se as freeName,G as gitEntry,Y as gitPointer,ie as glance,K as kindOf,de as outsideRepositories,ue as rootOf,C as shows,b as unshown,re as where};
@@ -37,7 +37,9 @@ export declare function containedRecordsSteps(records: readonly CloudEntityRecor
37
37
  export declare function containedRecords(records: readonly CloudEntityRecord[], rootUuid: string): readonly CloudEntityRecord[];
38
38
  export declare function materializableRecordsSteps(records: readonly CloudEntityRecord[], rootUuid: string): Steps<readonly CloudEntityRecord[]>;
39
39
  export declare function materializableRecords(records: readonly CloudEntityRecord[], rootUuid: string): readonly CloudEntityRecord[];
40
- export declare function installedSubtree(installed: readonly unknown[], setAside: readonly CloudEntityRecord[], subtree: readonly CloudEntityRecord[], rootUuid: string): boolean;
40
+ export declare function waitingEntities(value: unknown, what: string): readonly string[];
41
+ export declare function installedSubtree(installed: readonly unknown[], setAside: readonly CloudEntityRecord[], subtree: readonly CloudEntityRecord[], rootUuid: string, waiting?: readonly string[]): boolean;
42
+ export declare function withoutWaiting(placed: readonly CloudEntityRecord[], root: string, waiting: readonly string[]): readonly CloudEntityRecord[];
41
43
  export declare function completeRootsFromRecords(rootIds: readonly string[], records: readonly unknown[]): readonly CloudEntityRecord[];
42
44
  export declare function completeRootsFromRecordsSteps(rootIds: readonly string[], records: readonly unknown[]): Steps<readonly CloudEntityRecord[]>;
43
45
  export declare function parseSnapshot(bytes: Uint8Array | string): CloudSnapshot;
@@ -1 +1 @@
1
- var V=Object.defineProperty;var p=(e,t)=>V(e,"name",{value:t,configurable:!0});import{CONTAINERS as m,DERIVED_PAYLOAD as z,ROOT_TYPES as N,STATUSES as O,TYPES as C,UUID_PATTERN as U}from"./types.js";import{bytesToBase64Url as _,hexToBytes as k,utf8Decode as M}from"./bytes.js";import{isName as A,validFileState as P,validGitHome as $,validLinkTarget as L,validPortableMtime as H,validPortableSize as Y}from"./rules.js";import{clashResolution as F}from"../clash/resolution.js";import{eachStep as d,finishSteps as y,ITEMS_PER_BOUNDARY as E,sortSteps as J}from"../steps.js";import{failure as j}from"../faults/need.js";const B="amalgm-entity-registry@10",S=1,D=/^[0-9a-f]{64}$/;function ut(e,t){return`pvr_${_(k(t(`private-user:${e}:${B}`))).slice(0,32)}`}p(ut,"privateEntityResourceId");function lt(e){return/^pvr_[A-Za-z0-9_-]{32}$/.test(e)}p(lt,"isPrivateEntityResourceId");const I=p(e=>JSON.stringify(e),"stableJson"),pt=p((e,t)=>I(e)===I(t),"sameRecord"),G=["uuid","type","parentUUID","name","status","version","payloadVersion","fileMode","mtime","size","linkTarget","gitHomeEntity","gitHomePath","transportVersion"];function R(e,t){const r=f(e).records,n=f(t).records;if(r.length!==n.length)return!1;for(let o=0;o<r.length;o+=1){const l=r[o],u=n[o];if(l!==u){for(const s of G)if(l[s]!==u[s])return!1}}return!0}p(R,"sameRecords");function W(e,t){const r=new Map(t.map(n=>[n.uuid,n]));return f(e).records.map(n=>{const o=r.get(n.uuid);return o&&F(n.type)==="play"&&o.type===n.type&&o.parentUUID===n.parentUUID&&o.name===n.name&&o.status===n.status?o:n})}p(W,"statedRecords");const T=new WeakSet;function Z(e){if(typeof e=="object"&&e!==null&&T.has(e))return e;const t=e;if(!t||typeof t!="object"||typeof t.uuid!="string"||!U.test(t.uuid)||typeof t.type!="string"||!C.has(t.type)||t.parentUUID!==null&&(typeof t.parentUUID!="string"||!U.test(t.parentUUID))||!A(t.name)||!O.has(t.status)||typeof t.version!="string"||!D.test(t.version)||t.payloadVersion!==null&&typeof t.payloadVersion!="string"||!P(t.type,t.payloadVersion,t.fileMode)||!H(t.type,t.mtime,t.payloadVersion===null&&t.fileMode===null)||!Y(t.type,t.payloadVersion,t.size)||!L(t.type,t.payloadVersion,t.linkTarget)||!$(t.type,t.gitHomeEntity??null,t.gitHomePath??null)||t.transportVersion!==void 0&&t.transportVersion!==null&&(typeof t.transportVersion!="string"||!D.test(t.transportVersion)))throw new Error("cloud entity snapshot has an invalid record");if(t.parentUUID===null&&!N.has(t.type))throw new Error(`cloud entity ${t.uuid} is not a valid tree root`);if(z.has(t.type)&&t.payloadVersion!==null)throw new Error("workspace and folder payloads are derived membership, never transported heads");const r=t.transportVersion??null;if(t.type!=="repo.git"&&r!==null)throw new Error("only a repository may declare a transport head");const n=Object.freeze({uuid:t.uuid.toLowerCase(),type:t.type,parentUUID:t.parentUUID===null?null:t.parentUUID.toLowerCase(),name:t.name,status:t.status,version:t.version,payloadVersion:t.payloadVersion,fileMode:t.fileMode,mtime:t.mtime,size:t.size,linkTarget:t.linkTarget,gitHomeEntity:t.gitHomeEntity??null,gitHomePath:t.gitHomePath??null,transportVersion:r});return T.add(n),n}p(Z,"assertRecord");function*q(e){const t=[],r=new Set;return yield*d(e,n=>{const o=Z(n);if(r.has(o.uuid))throw new Error("cloud entity snapshot has duplicate UUIDs");r.add(o.uuid),t.push(o)}),t}p(q,"assertedRecordsSteps");function*w(e){const t=yield*J(yield*q(e),(r,n)=>r.uuid<n.uuid?-1:r.uuid>n.uuid?1:0);return{schemaVersion:S,kind:"amalgm-entity-registry",records:t}}p(w,"snapshotFromRecordsSteps");function f(e){return y(w(e))}p(f,"snapshotFromRecords");function*x(e,t){const r=new Map;yield*d(e,s=>{if(s.parentUUID===null)return;const i=r.get(s.parentUUID);i?i.push(s):r.set(s.parentUUID,[s])});const n=new Set([t]),o=[t];let l=0;for(;o.length>0;){for(const s of r.get(o.pop())??[])n.has(s.uuid)||(n.add(s.uuid),o.push(s.uuid));++l%E===0&&(yield)}const u=[];return yield*d(e,s=>{n.has(s.uuid)&&u.push(s)}),u}p(x,"containedRecordsSteps");function ct(e,t){return y(x(e,t))}p(ct,"containedRecords");function*K(e,t){const r=yield*x((yield*w(e)).records,t),n=new Map;yield*d(r,a=>n.set(a.uuid,a));const o=n.get(t);if(!o||o.status!=="active")return[];if(!m.has(o.type))throw new Error(`cloud materialization root ${o.uuid} is not a container`);const l=new Map;yield*d(r,a=>{if(a.uuid===o.uuid)return;if(a.parentUUID===null)throw new Error(`cloud materialization entity ${a.uuid} escapes its selected root`);if(!n.get(a.parentUUID))throw new Error(`cloud materialization entity ${a.uuid} has incomplete ancestry`);const g=l.get(a.parentUUID);g?g.push(a):l.set(a.parentUUID,[a])});const u=new Set,s=[o];let i=0;for(;s.length>0;){const a=s.pop();if(!(a.status!=="active"||u.has(a.uuid))&&(u.add(a.uuid),!!m.has(a.type))){for(const h of l.get(a.uuid)??[])h.status==="active"&&s.push(h);++i%E===0&&(yield)}}const c=[];return yield*d(r,a=>{u.has(a.uuid)&&c.push(a)}),c}p(K,"materializableRecordsSteps");function Q(e,t){return y(K(e,t))}p(Q,"materializableRecords");function dt(e,t,r,n){const o=W(e,r),l=new Set(o.map(({uuid:s})=>s));if(t.some(({uuid:s})=>l.has(s)))return!1;const u=f([...o,...t]).records;return R(Q(u,n),o)&&R(u,r)}p(dt,"installedSubtree");const v=Symbol("parent cycle"),b=Symbol("incomplete ancestry");function X(e){const t=new Map;return r=>{const n=[],o=new Set;let l=r,u;for(;;){const s=t.get(l.uuid);if(s!==void 0){u=s;break}if(l.parentUUID===null){u=l.uuid;break}if(o.has(l.uuid)){u=v;break}o.add(l.uuid),n.push(l.uuid);const i=e.get(l.parentUUID);if(!i){u=b;break}l=i}for(const s of n)t.set(s,u);return u}}p(X,"createRootResolver");function ft(e,t){return y(tt(e,t))}p(ft,"completeRootsFromRecords");function*tt(e,t){if(e.length===0)throw new Error("cloud root set has no roots");const r=e.map(i=>{if(!U.test(i))throw new Error("cloud root set has an invalid root UUID");return i.toLowerCase()}).sort();if(new Set(r).size!==r.length)throw new Error("cloud root set has duplicate roots");const n=yield*w(t),o=new Map;yield*d(n.records,i=>{o.set(i.uuid,i)});const l=new Set(r),u=n.records.filter(i=>i.parentUUID===null).map(i=>i.uuid).sort();if(u.length!==r.length||u.some((i,c)=>i!==r[c]))throw new Error("cloud root set records do not exactly match its roots");const s=X(o);return yield*d(n.records,i=>{if(i.parentUUID!==null){const a=o.get(i.parentUUID);if(!a||i.status==="active"&&!m.has(a.type))throw new Error(`cloud root set entity ${i.uuid} has no container parent`)}const c=s(i);if(c===v)throw j("cloud root set has a parent cycle","graph-cycle","parent-cycle");if(c===b)throw new Error(`cloud root set entity ${i.uuid} has incomplete ancestry`);if(!l.has(c))throw new Error(`cloud root set entity ${i.uuid} is outside its declared roots`)}),n.records}p(tt,"completeRootsFromRecordsSteps");function yt(e){let t;try{t=JSON.parse(typeof e=="string"?e:M(e))}catch{throw new Error("cloud entity snapshot is not JSON")}if(t?.schemaVersion!==S||t?.kind!=="amalgm-entity-registry"||!Array.isArray(t.records))throw new Error("cloud entity snapshot has an unsupported shape");return f(t.records)}p(yt,"parseSnapshot");export{B as ENTITY_CLOUD_CONTRACT,S as ENTITY_CLOUD_SCHEMA_VERSION,Z as assertRecord,q as assertedRecordsSteps,ft as completeRootsFromRecords,tt as completeRootsFromRecordsSteps,ct as containedRecords,x as containedRecordsSteps,dt as installedSubtree,lt as isPrivateEntityResourceId,Q as materializableRecords,K as materializableRecordsSteps,yt as parseSnapshot,ut as privateEntityResourceId,pt as sameRecord,R as sameRecords,f as snapshotFromRecords,w as snapshotFromRecordsSteps,I as stableJson,W as statedRecords};
1
+ var V=Object.defineProperty;var p=(e,t)=>V(e,"name",{value:t,configurable:!0});import{CONTAINERS as w,DERIVED_PAYLOAD as k,ROOT_TYPES as z,STATUSES as C,TYPES as M,UUID_PATTERN as h}from"./types.js";import{bytesToBase64Url as N,hexToBytes as O,utf8Decode as A}from"./bytes.js";import{isName as _,validFileState as P,validGitHome as $,validLinkTarget as L,validPortableMtime as H,validPortableSize as Y}from"./rules.js";import{clashResolution as F}from"../clash/resolution.js";import{eachStep as f,finishSteps as y,ITEMS_PER_BOUNDARY as E,sortSteps as B}from"../steps.js";import{failure as J}from"../faults/need.js";const j="amalgm-entity-registry@10",S=1,D=/^[0-9a-f]{64}$/;function lt(e,t){return`pvr_${N(O(t(`private-user:${e}:${j}`))).slice(0,32)}`}p(lt,"privateEntityResourceId");function pt(e){return/^pvr_[A-Za-z0-9_-]{32}$/.test(e)}p(pt,"isPrivateEntityResourceId");const I=p(e=>JSON.stringify(e),"stableJson"),ct=p((e,t)=>I(e)===I(t),"sameRecord"),G=["uuid","type","parentUUID","name","status","version","payloadVersion","fileMode","mtime","size","linkTarget","gitHomeEntity","gitHomePath","transportVersion"];function R(e,t){const r=m(e).records,n=m(t).records;if(r.length!==n.length)return!1;for(let o=0;o<r.length;o+=1){const l=r[o],u=n[o];if(l!==u){for(const i of G)if(l[i]!==u[i])return!1}}return!0}p(R,"sameRecords");function W(e,t){const r=new Map(t.map(n=>[n.uuid,n]));return m(e).records.map(n=>{const o=r.get(n.uuid);return o&&F(n.type)==="play"&&o.type===n.type&&o.parentUUID===n.parentUUID&&o.name===n.name&&o.status===n.status?o:n})}p(W,"statedRecords");const T=new WeakSet;function Z(e){if(typeof e=="object"&&e!==null&&T.has(e))return e;const t=e;if(!t||typeof t!="object"||typeof t.uuid!="string"||!h.test(t.uuid)||typeof t.type!="string"||!M.has(t.type)||t.parentUUID!==null&&(typeof t.parentUUID!="string"||!h.test(t.parentUUID))||!_(t.name)||!C.has(t.status)||typeof t.version!="string"||!D.test(t.version)||t.payloadVersion!==null&&typeof t.payloadVersion!="string"||!P(t.type,t.payloadVersion,t.fileMode)||!H(t.type,t.mtime,t.payloadVersion===null&&t.fileMode===null)||!Y(t.type,t.payloadVersion,t.size)||!L(t.type,t.payloadVersion,t.linkTarget)||!$(t.type,t.gitHomeEntity??null,t.gitHomePath??null)||t.transportVersion!==void 0&&t.transportVersion!==null&&(typeof t.transportVersion!="string"||!D.test(t.transportVersion)))throw new Error("cloud entity snapshot has an invalid record");if(t.parentUUID===null&&!z.has(t.type))throw new Error(`cloud entity ${t.uuid} is not a valid tree root`);if(k.has(t.type)&&t.payloadVersion!==null)throw new Error("workspace and folder payloads are derived membership, never transported heads");const r=t.transportVersion??null;if(t.type!=="repo.git"&&r!==null)throw new Error("only a repository may declare a transport head");const n=Object.freeze({uuid:t.uuid.toLowerCase(),type:t.type,parentUUID:t.parentUUID===null?null:t.parentUUID.toLowerCase(),name:t.name,status:t.status,version:t.version,payloadVersion:t.payloadVersion,fileMode:t.fileMode,mtime:t.mtime,size:t.size,linkTarget:t.linkTarget,gitHomeEntity:t.gitHomeEntity??null,gitHomePath:t.gitHomePath??null,transportVersion:r});return T.add(n),n}p(Z,"assertRecord");function*q(e){const t=[],r=new Set;return yield*f(e,n=>{const o=Z(n);if(r.has(o.uuid))throw new Error("cloud entity snapshot has duplicate UUIDs");r.add(o.uuid),t.push(o)}),t}p(q,"assertedRecordsSteps");function*g(e){const t=yield*B(yield*q(e),(r,n)=>r.uuid<n.uuid?-1:r.uuid>n.uuid?1:0);return{schemaVersion:S,kind:"amalgm-entity-registry",records:t}}p(g,"snapshotFromRecordsSteps");function m(e){return y(g(e))}p(m,"snapshotFromRecords");function*b(e,t){const r=new Map;yield*f(e,i=>{if(i.parentUUID===null)return;const s=r.get(i.parentUUID);s?s.push(i):r.set(i.parentUUID,[i])});const n=new Set([t]),o=[t];let l=0;for(;o.length>0;){for(const i of r.get(o.pop())??[])n.has(i.uuid)||(n.add(i.uuid),o.push(i.uuid));++l%E===0&&(yield)}const u=[];return yield*f(e,i=>{n.has(i.uuid)&&u.push(i)}),u}p(b,"containedRecordsSteps");function dt(e,t){return y(b(e,t))}p(dt,"containedRecords");function*K(e,t){const r=yield*b((yield*g(e)).records,t),n=new Map;yield*f(r,a=>n.set(a.uuid,a));const o=n.get(t);if(!o||o.status!=="active")return[];if(!w.has(o.type))throw new Error(`cloud materialization root ${o.uuid} is not a container`);const l=new Map;yield*f(r,a=>{if(a.uuid===o.uuid)return;if(a.parentUUID===null)throw new Error(`cloud materialization entity ${a.uuid} escapes its selected root`);if(!n.get(a.parentUUID))throw new Error(`cloud materialization entity ${a.uuid} has incomplete ancestry`);const U=l.get(a.parentUUID);U?U.push(a):l.set(a.parentUUID,[a])});const u=new Set,i=[o];let s=0;for(;i.length>0;){const a=i.pop();if(!(a.status!=="active"||u.has(a.uuid))&&(u.add(a.uuid),!!w.has(a.type))){for(const d of l.get(a.uuid)??[])d.status==="active"&&i.push(d);++s%E===0&&(yield)}}const c=[];return yield*f(r,a=>{u.has(a.uuid)&&c.push(a)}),c}p(K,"materializableRecordsSteps");function Q(e,t){return y(K(e,t))}p(Q,"materializableRecords");function ft(e,t){const r=e??[];if(!Array.isArray(r)||r.some(o=>typeof o!="string"||!h.test(o)))throw new Error(`${t} names invalid waiting entities`);const n=r.map(o=>o.toLowerCase());if(new Set(n).size!==n.length)throw new Error(`${t} names a waiting entity twice`);return n}p(ft,"waitingEntities");function ht(e,t,r,n,o=[]){const l=W(e,r),u=Q(r,n),i=new Set(u.map(({uuid:s})=>s));return t.some(({uuid:s})=>i.has(s))?!1:R(l,X(u,n,o))&&R([...u,...t],r)}p(ht,"installedSubtree");function X(e,t,r){if(r.length===0)return e;const n=new Map(e.map(i=>[i.uuid,i])),o=new Set(r);for(const i of o)if(i===t||!n.has(i))throw new Error("a waiting entity is not one the placement places beneath its root");const l=new Map,u=p(i=>{const s=[];let c=i,a=!1;for(;c!==void 0;){const d=l.get(c.uuid);if(d!==void 0){a=d;break}if(o.has(c.uuid)){a=!0,s.push(c.uuid);break}s.push(c.uuid),c=c.parentUUID===null?void 0:n.get(c.parentUUID)}for(const d of s)l.set(d,a);return a},"waitsBeneath");return e.filter(i=>!u(i))}p(X,"withoutWaiting");const x=Symbol("parent cycle"),v=Symbol("incomplete ancestry");function tt(e){const t=new Map;return r=>{const n=[],o=new Set;let l=r,u;for(;;){const i=t.get(l.uuid);if(i!==void 0){u=i;break}if(l.parentUUID===null){u=l.uuid;break}if(o.has(l.uuid)){u=x;break}o.add(l.uuid),n.push(l.uuid);const s=e.get(l.parentUUID);if(!s){u=v;break}l=s}for(const i of n)t.set(i,u);return u}}p(tt,"createRootResolver");function yt(e,t){return y(et(e,t))}p(yt,"completeRootsFromRecords");function*et(e,t){if(e.length===0)throw new Error("cloud root set has no roots");const r=e.map(s=>{if(!h.test(s))throw new Error("cloud root set has an invalid root UUID");return s.toLowerCase()}).sort();if(new Set(r).size!==r.length)throw new Error("cloud root set has duplicate roots");const n=yield*g(t),o=new Map;yield*f(n.records,s=>{o.set(s.uuid,s)});const l=new Set(r),u=n.records.filter(s=>s.parentUUID===null).map(s=>s.uuid).sort();if(u.length!==r.length||u.some((s,c)=>s!==r[c]))throw new Error("cloud root set records do not exactly match its roots");const i=tt(o);return yield*f(n.records,s=>{if(s.parentUUID!==null){const a=o.get(s.parentUUID);if(!a||s.status==="active"&&!w.has(a.type))throw new Error(`cloud root set entity ${s.uuid} has no container parent`)}const c=i(s);if(c===x)throw J("cloud root set has a parent cycle","graph-cycle","parent-cycle");if(c===v)throw new Error(`cloud root set entity ${s.uuid} has incomplete ancestry`);if(!l.has(c))throw new Error(`cloud root set entity ${s.uuid} is outside its declared roots`)}),n.records}p(et,"completeRootsFromRecordsSteps");function mt(e){let t;try{t=JSON.parse(typeof e=="string"?e:A(e))}catch{throw new Error("cloud entity snapshot is not JSON")}if(t?.schemaVersion!==S||t?.kind!=="amalgm-entity-registry"||!Array.isArray(t.records))throw new Error("cloud entity snapshot has an unsupported shape");return m(t.records)}p(mt,"parseSnapshot");export{j as ENTITY_CLOUD_CONTRACT,S as ENTITY_CLOUD_SCHEMA_VERSION,Z as assertRecord,q as assertedRecordsSteps,yt as completeRootsFromRecords,et as completeRootsFromRecordsSteps,dt as containedRecords,b as containedRecordsSteps,ht as installedSubtree,pt as isPrivateEntityResourceId,Q as materializableRecords,K as materializableRecordsSteps,mt as parseSnapshot,lt as privateEntityResourceId,ct as sameRecord,R as sameRecords,m as snapshotFromRecords,g as snapshotFromRecordsSteps,I as stableJson,W as statedRecords,ft as waitingEntities,X as withoutWaiting};
@@ -1,7 +1,9 @@
1
1
  import { type Steps } from '../steps.js';
2
2
  import { type CloudEntityRecord } from './cloud.js';
3
3
  import { type GraphPageRef, type RecordPage } from './graph-pages.js';
4
- import { type Sha256Hex } from './types.js';
4
+ import { type EntityType, type Sha256Hex } from './types.js';
5
+ export declare const anchorsPackage: (type: EntityType | string) => boolean;
6
+ export declare function carriers(records: Iterable<CloudEntityRecord>): Map<string, CloudEntityRecord>;
5
7
  export declare function packageSubtreeSteps(anchorId: string, records: readonly unknown[]): Steps<readonly CloudEntityRecord[]>;
6
8
  export declare function packageSubtree(anchorId: string, records: readonly unknown[]): readonly CloudEntityRecord[];
7
9
  export declare function packagePagesSteps(anchorId: string, records: readonly unknown[], sha256Hex: Sha256Hex): Steps<readonly RecordPage[]>;
@@ -1 +1 @@
1
- var w=Object.defineProperty;var s=(e,t)=>w(e,"name",{value:t,configurable:!0});import{finishSteps as d,eachStep as g}from"../steps.js";import{sameRecord as m,snapshotFromRecordsSteps as y}from"./cloud.js";import{parseGraphPage as k,recordPagesSteps as h,samePages as S}from"./graph-pages.js";import{CONTAINERS as l}from"./types.js";function*f(e,t){const r=(yield*y(t)).records,a=new Map;yield*g(r,o=>{a.set(o.uuid,o)});const i=a.get(e.toLowerCase());if(!i||!l.has(i.type))throw new Error("a package anchor must be a container in its subtree");if(i.parentUUID!==null&&a.has(i.parentUUID))throw new Error("a package anchor cannot hang inside its own subtree");const u=new Set([i.uuid]);return yield*g(r,o=>{if(o.status!=="active")throw new Error(`package entity ${o.uuid} is not new: it is ${o.status}`);const p=[];for(let n=o;!u.has(n.uuid);){p.push(n.uuid);const c=n.parentUUID===null?void 0:a.get(n.parentUUID);if(!c||!l.has(c.type)||p.includes(c.uuid))throw new Error(`package entity ${o.uuid} does not hang from its anchor`);n=c}for(const n of p)u.add(n)}),r}s(f,"packageSubtreeSteps");function D(e,t){return d(f(e,t))}s(D,"packageSubtree");function*U(e,t,r){return yield*h(yield*f(e,t),r)}s(U,"packagePagesSteps");function R(e,t,r){return d(U(e,t,r))}s(R,"packagePages");function*b(e,t,r,a){const i=[];for(const n of t){for(const c of k(n,r(n),a))i.push(c);yield}const u=yield*f(e.uuid,i),o=yield*h(u,a);if(!S(o.map(n=>n.ref),t))throw new Error(`package ${e.uuid} is not canonically paginated`);const p=u.find(n=>n.uuid===e.uuid);if(!p||!m(p,e))throw new Error(`package ${e.uuid} pages a different anchor than its result`);return u}s(b,"unpackSteps");function C(e,t,r,a){return d(b(e,t,r,a))}s(C,"unpack");export{R as packagePages,U as packagePagesSteps,D as packageSubtree,f as packageSubtreeSteps,C as unpack,b as unpackSteps};
1
+ var k=Object.defineProperty;var a=(e,r)=>k(e,"name",{value:r,configurable:!0});import{finishSteps as g,eachStep as l}from"../steps.js";import{sameRecord as m,snapshotFromRecordsSteps as S}from"./cloud.js";import{parseGraphPage as U,recordPagesSteps as w,samePages as b}from"./graph-pages.js";import{CONTAINERS as y}from"./types.js";const E=a(e=>y.has(e)||e==="reference","anchorsPackage");function x(e){const r=new Map;for(const n of e){if(n.type!=="reference"||n.payloadVersion===null)continue;const o=n.payloadVersion.toLowerCase();if(r.has(o))throw new Error(`package root ${o} is named by two references`);r.set(o,n)}return r}a(x,"carriers");function*h(e,r){const n=(yield*S(r)).records,o=new Map;yield*l(n,t=>{o.set(t.uuid,t)});const c=x(n),p=a(t=>{if(t.parentUUID===null)return c.get(t.uuid);const i=o.get(t.parentUUID);return i&&y.has(i.type)?i:void 0},"holder"),s=o.get(e.toLowerCase());if(!s||!E(s.type))throw new Error("a package anchor must be a container or a reference in its package");if(s.parentUUID!==null&&o.has(s.parentUUID)||c.has(s.uuid))throw new Error("a package anchor cannot hang inside its own package");const d=new Set([s.uuid]);return yield*l(n,t=>{if(t.status!=="active")throw new Error(`package entity ${t.uuid} is not new: it is ${t.status}`);const i=[];for(let u=t;!d.has(u.uuid);){i.push(u.uuid);const f=p(u);if(!f||i.includes(f.uuid))throw new Error(`package entity ${t.uuid} does not hang from its anchor`);u=f}for(const u of i)d.add(u)}),n}a(h,"packageSubtreeSteps");function L(e,r){return g(h(e,r))}a(L,"packageSubtree");function*P(e,r,n){return yield*w(yield*h(e,r),n)}a(P,"packagePagesSteps");function M(e,r,n){return g(P(e,r,n))}a(M,"packagePages");function*$(e,r,n,o){const c=[];for(const t of r){for(const i of U(t,n(t),o))c.push(i);yield}const p=yield*h(e.uuid,c),s=yield*w(p,o);if(!b(s.map(t=>t.ref),r))throw new Error(`package ${e.uuid} is not canonically paginated`);const d=p.find(t=>t.uuid===e.uuid);if(!d||!m(d,e))throw new Error(`package ${e.uuid} pages a different anchor than its result`);return p}a($,"unpackSteps");function N(e,r,n,o){return g($(e,r,n,o))}a(N,"unpack");export{E as anchorsPackage,x as carriers,M as packagePages,P as packagePagesSteps,L as packageSubtree,h as packageSubtreeSteps,N as unpack,$ as unpackSteps};
@@ -1 +1 @@
1
- var m=Object.defineProperty;var c=(e,t)=>m(e,"name",{value:t,configurable:!0});import{amalgmUserRoot as y}from"./browse-types.js";import{CloudFiles as p,assertReadable as h}from"./cloud-files.js";import{LocalFiles as I}from"./local-files.js";class x{static{c(this,"FilesBrowser")}root;cloud;local;constructor(t){this.cloud=new p(t.userEmail,t.cloud),this.local=new I(t.local),this.root=y(t.userEmail)}async listAmalgm(t={}){const a=await this.cloud.open(),l=await a.list(t.parentId),o=w([l.directory,...l.entries]),r=u(t.computerId),s=r===null?new Map:await this.local.available(r,a.head,o);return{scope:"amalgm",root:this.root,head:i(a.head),computerId:r,directory:n(l.directory,s),entries:l.entries.map(d=>n(d,s))}}async locateAmalgm(t){const a=await this.cloud.open(),l=await a.place(t.entityId);return{scope:"amalgm",root:this.root,head:i(a.head),entries:l.map(o=>n(o,new Map))}}async readAmalgm(t){const a=await this.cloud.open(),l=await a.entry(t.entityId);h(l);const o=u(t.computerId);if(o!==null){const r=await this.local.readIfMaterialized(o,a.head,l);if(r!==null)return{scope:"amalgm",head:i(a.head),entityId:l.uuid,source:"local",content:r}}return{scope:"amalgm",head:i(a.head),entityId:l.uuid,source:"cloud",content:await a.read(l)}}listLocal(t){return this.local.list(t.computerId,t.path)}async readLocal(t){return{scope:"local-only",computerId:t.computerId.trim(),source:"local",content:await this.local.read(t.computerId,t.path)}}}function n(e,t){const a=t.get(e.entity.uuid)??null,l=a!==null;return{entryId:e.entryId,entityId:e.entity.uuid,parentEntityId:e.parentEntityId,referenceId:e.referenceId,name:e.name,type:e.entity.type,status:e.entity.status,version:e.entity.version,size:e.entity.size,availability:{cloud:!0,local:l,localVersion:a,matchesCloud:a===null?null:a===e.entity.version},source:l?"local":"cloud"}}c(n,"present");function w(e){return[...new Map(e.map(t=>[t.entity.uuid,t.entity])).values()]}c(w,"uniqueEntities");function i(e){return{checksum:e.checksum,version:e.version}}c(i,"headDescriptor");function u(e){return e===void 0?null:e.trim()||null}c(u,"optionalText");export{x as FilesBrowser};
1
+ var p=Object.defineProperty;var c=(e,t)=>p(e,"name",{value:t,configurable:!0});import{amalgmUserRoot as y}from"./browse-types.js";import{CloudFiles as h,assertReadable as I}from"./cloud-files.js";import{LocalFiles as w}from"./local-files.js";import{assertLeavesComputers as u,lastName as f}from"./secrets.js";class b{static{c(this,"FilesBrowser")}root;cloud;local;constructor(t){this.cloud=new h(t.userEmail,t.cloud),this.local=new w(t.local),this.root=y(t.userEmail)}async listAmalgm(t={}){const a=await this.cloud.open(),o=await a.list(t.parentId),r=g([o.directory,...o.entries]),l=d(t.computerId),s=l===null?new Map:await this.local.available(l,a.head,r);return{scope:"amalgm",root:this.root,head:i(a.head),computerId:l,directory:n(o.directory,s),entries:o.entries.map(m=>n(m,s))}}async locateAmalgm(t){const a=await this.cloud.open(),o=await a.place(t.entityId);return{scope:"amalgm",root:this.root,head:i(a.head),entries:o.map(r=>n(r,new Map))}}async readAmalgm(t){const a=await this.cloud.open(),o=await a.entry(t.entityId);I(o),u(o.name);const r=d(t.computerId);if(r!==null){const l=await this.local.readIfMaterialized(r,a.head,o);if(l!==null)return{scope:"amalgm",head:i(a.head),entityId:o.uuid,source:"local",content:l}}return{scope:"amalgm",head:i(a.head),entityId:o.uuid,source:"cloud",content:await a.read(o)}}listLocal(t){return this.local.list(t.computerId,t.path)}async readLocal(t){return u(f(t.path)),{scope:"local-only",computerId:t.computerId.trim(),source:"local",content:await this.local.read(t.computerId,t.path)}}}function n(e,t){const a=t.get(e.entity.uuid)??null,o=a!==null;return{entryId:e.entryId,entityId:e.entity.uuid,parentEntityId:e.parentEntityId,referenceId:e.referenceId,name:e.name,type:e.entity.type,status:e.entity.status,version:e.entity.version,size:e.entity.size,availability:{cloud:!0,local:o,localVersion:a,matchesCloud:a===null?null:a===e.entity.version},source:o?"local":"cloud"}}c(n,"present");function g(e){return[...new Map(e.map(t=>[t.entity.uuid,t.entity])).values()]}c(g,"uniqueEntities");function i(e){return{checksum:e.checksum,version:e.version}}c(i,"headDescriptor");function d(e){return e===void 0?null:e.trim()||null}c(d,"optionalText");export{b as FilesBrowser};
@@ -20,6 +20,14 @@ export interface FilesRegisterPorts {
20
20
  readonly referenceName: string;
21
21
  readonly referencePath: string;
22
22
  }>;
23
+ recordWorkspace(input: {
24
+ readonly workspaceId: string;
25
+ readonly absolutePath: string;
26
+ readonly referencePath: string;
27
+ }): Promise<{
28
+ readonly recorded: boolean;
29
+ }>;
30
+ accepted(): Promise<void>;
23
31
  }
24
32
  export interface FilesRegisterResult {
25
33
  readonly workspaceId: string;
@@ -27,8 +35,9 @@ export interface FilesRegisterResult {
27
35
  readonly externalPath: string;
28
36
  readonly referenceName: string;
29
37
  readonly referencePath: string;
30
- readonly declared: true;
31
38
  readonly created: boolean;
39
+ readonly recorded: boolean;
40
+ readonly accepted: true;
32
41
  }
33
42
  export declare function registerFilesWorkspace(path: string, ports: FilesRegisterPorts): Promise<FilesRegisterResult>;
34
43
  export interface FilesAddPorts {
@@ -60,6 +69,7 @@ export interface FilesAddPorts {
60
69
  readonly syncingReferences: readonly string[];
61
70
  readonly listedReferences: readonly string[];
62
71
  readonly alreadyMaterialized: boolean;
72
+ readonly waiting?: readonly string[];
63
73
  }>;
64
74
  coverWorkspace(input: {
65
75
  readonly workspaceId: string;
@@ -78,6 +88,7 @@ export interface FilesAddResult {
78
88
  readonly alreadyMaterialized: boolean;
79
89
  readonly syncing: boolean;
80
90
  readonly syncingReferences: readonly string[];
91
+ readonly waiting: readonly string[];
81
92
  readonly watcherRoots: number;
82
93
  }
83
94
  export declare function workspaceGraph(records: readonly CloudEntityRecord[], workspaceId: string): {
@@ -1 +1 @@
1
- var P=Object.defineProperty;var w=(o,s)=>P(o,"name",{value:s,configurable:!0});import{CONTAINERS as N,UUID_PATTERN as S,containedRecords as W,installedSubtree as F,materializableRecords as U,sameRecords as b,snapshotFromRecords as v}from"../entities/index.js";import{computerAddress as $}from"./computer-address.js";import{ownFolderRefusal as x}from"./own-folders.js";function h(o,s){const e=typeof o=="string"?o.trim().toLowerCase():"";if(!S.test(e))throw new Error(`${s} must be a UUID`);return e}w(h,"uuid");function d(o,s){const e=typeof o=="string"?o.trim():"";if(!e)throw new Error(`${s} is required`);return e}w(d,"required");async function C(o,s){const e=d(o,"workspace path"),r=await s.inspectExternalWorkspace(e),c=d(r.absolutePath,"external workspace path"),i=x("files register",c,r.amalgmFolders);if(i)throw i;const l=d(r.name,"workspace name"),a=r.workspaceId===null?h(s.randomUuid(),"generated workspace id"):h(r.workspaceId,"existing workspace id"),p=await s.placeWorkspaceReference({workspaceId:a,absolutePath:c,address:$(await s.computerFolder(),c)});return{workspaceId:a,workspaceName:l,externalPath:c,referenceName:d(p.referenceName,"reference name"),referencePath:d(p.referencePath,"reference path"),declared:!0,created:p.created===!0}}w(C,"registerFilesWorkspace");function A(o,s){const e=h(s,"workspace id"),r=v(o),c=r.records.find(a=>a.uuid===e);if(!c||c.status!=="active")throw new Error(`workspace ${e} does not exist in this user's cloud registry`);if(!N.has(c.type))throw new Error(`entity ${e} is not a registered workspace boundary`);const i=r.records.filter(a=>a.status==="active"&&a.type==="reference"&&a.payloadVersion===e);if(i.length!==1)throw new Error(`workspace ${e} must have exactly one durable reference`);const l=W(r.records,e);return{workspace:c,reference:i[0],subtree:l,records:U(l,e)}}w(A,"workspaceGraph");async function H(o,s,e){const r=h(o,"workspace id"),c=d(s,"destination directory"),i=await e.lookupRegistry(r),{subtree:l,...a}=A(i.snapshot.records,r),p=await e.inspectDestination({workspaceId:r,destinationParent:c,name:a.workspace.name}),g=x("files add",d(p.absolutePath,"destination path"),p.amalgmFolders);if(g)throw g;const E=new Set(a.records.map(({uuid:t})=>t)),y=l.filter(({uuid:t})=>!E.has(t)),m=i.snapshot.records.filter(t=>t.status==="active"&&t.type==="reference"),n=await e.materializeWorkspace({...a,setAside:y,references:m,destinationParent:c,cloudHead:d(i.checksum,"cloud head"),deliveryWatermark:i.deliveryWatermark}),R=v(n.records||[]).records,f=new Set(n.syncingReferences),k=new Set(n.listedReferences),z=new Set(m.map(({uuid:t})=>t)),I=F(R,y,l,r);if(!Number.isSafeInteger(n.rows)||n.rows!==R.length||!I&&n.alreadyMaterialized!==!0||!b([n.reference],[a.reference])||f.size!==n.syncingReferences.length||k.size!==n.listedReferences.length||[...f].some(t=>!z.has(t))||[...k].some(t=>!z.has(t)||f.has(t))||!b(n.references,m.filter(({uuid:t})=>!f.has(t)&&!k.has(t))))throw new Error("workspace materialization did not persist exactly the selected graph");const u=await e.coverWorkspace({workspaceId:r});if(u.active!==!0||!Number.isSafeInteger(u.roots)||u.roots<1)throw new Error("workspace watcher coverage is not active");return{workspaceId:r,workspaceName:a.workspace.name,path:d(n.path,"materialized workspace path"),rows:n.rows,cloudHead:i.checksum,materialized:!0,alreadyMaterialized:n.alreadyMaterialized===!0,syncing:!I,syncingReferences:[...f].sort(),watcherRoots:u.roots}}w(H,"addFilesWorkspace");export{H as addFilesWorkspace,C as registerFilesWorkspace,A as workspaceGraph};
1
+ var N=Object.defineProperty;var p=(n,r)=>N(n,"name",{value:r,configurable:!0});import{CONTAINERS as W,UUID_PATTERN as S,containedRecords as F,installedSubtree as U,waitingEntities as $,materializableRecords as A,sameRecords as v,snapshotFromRecords as x}from"../entities/index.js";import{computerAddress as q}from"./computer-address.js";import{ownFolderRefusal as P}from"./own-folders.js";function h(n,r){const e=typeof n=="string"?n.trim().toLowerCase():"";if(!S.test(e))throw new Error(`${r} must be a UUID`);return e}p(h,"uuid");function d(n,r){const e=typeof n=="string"?n.trim():"";if(!e)throw new Error(`${r} is required`);return e}p(d,"required");async function G(n,r){const e=d(n,"workspace path"),t=await r.inspectExternalWorkspace(e),c=d(t.absolutePath,"external workspace path"),i=P("files register",c,t.amalgmFolders);if(i)throw i;const l=d(t.name,"workspace name"),s=t.workspaceId===null?h(r.randomUuid(),"generated workspace id"):h(t.workspaceId,"existing workspace id"),w=await r.placeWorkspaceReference({workspaceId:s,absolutePath:c,address:q(await r.computerFolder(),c)}),f=d(w.referencePath,"reference path"),{recorded:k}=await r.recordWorkspace({workspaceId:s,absolutePath:c,referencePath:f});return await r.accepted(),{workspaceId:s,workspaceName:l,externalPath:c,referenceName:d(w.referenceName,"reference name"),referencePath:f,created:w.created===!0,recorded:k===!0,accepted:!0}}p(G,"registerFilesWorkspace");function D(n,r){const e=h(r,"workspace id"),t=x(n),c=t.records.find(s=>s.uuid===e);if(!c||c.status!=="active")throw new Error(`workspace ${e} does not exist in this user's cloud registry`);if(!W.has(c.type))throw new Error(`entity ${e} is not a registered workspace boundary`);const i=t.records.filter(s=>s.status==="active"&&s.type==="reference"&&s.payloadVersion===e);if(i.length!==1)throw new Error(`workspace ${e} must have exactly one durable reference`);const l=F(t.records,e);return{workspace:c,reference:i[0],subtree:l,records:A(l,e)}}p(D,"workspaceGraph");async function L(n,r,e){const t=h(n,"workspace id"),c=d(r,"destination directory"),i=await e.lookupRegistry(t),{subtree:l,...s}=D(i.snapshot.records,t),w=await e.inspectDestination({workspaceId:t,destinationParent:c,name:s.workspace.name}),f=P("files add",d(w.absolutePath,"destination path"),w.amalgmFolders);if(f)throw f;const k=new Set(s.records.map(({uuid:a})=>a)),R=l.filter(({uuid:a})=>!k.has(a)),g=i.snapshot.records.filter(a=>a.status==="active"&&a.type==="reference"),o=await e.materializeWorkspace({...s,setAside:R,references:g,destinationParent:c,cloudHead:d(i.checksum,"cloud head"),deliveryWatermark:i.deliveryWatermark}),z=x(o.records||[]).records,u=new Set(o.syncingReferences),y=new Set(o.listedReferences),I=new Set(g.map(({uuid:a})=>a)),b=$(o.waiting,"workspace materialization"),E=U(z,R,l,t,b);if(!Number.isSafeInteger(o.rows)||o.rows!==z.length||!E&&o.alreadyMaterialized!==!0||!v([o.reference],[s.reference])||u.size!==o.syncingReferences.length||y.size!==o.listedReferences.length||[...u].some(a=>!I.has(a))||[...y].some(a=>!I.has(a)||u.has(a))||!v(o.references,g.filter(({uuid:a})=>!u.has(a)&&!y.has(a))))throw new Error("workspace materialization did not persist exactly the selected graph");const m=await e.coverWorkspace({workspaceId:t});if(m.active!==!0||!Number.isSafeInteger(m.roots)||m.roots<1)throw new Error("workspace watcher coverage is not active");return{workspaceId:t,workspaceName:s.workspace.name,path:d(o.path,"materialized workspace path"),rows:o.rows,cloudHead:i.checksum,materialized:!0,alreadyMaterialized:o.alreadyMaterialized===!0,syncing:!E,syncingReferences:[...u].sort(),waiting:[...b].sort(),watcherRoots:m.roots}}p(L,"addFilesWorkspace");export{L as addFilesWorkspace,G as registerFilesWorkspace,D as workspaceGraph};