@amalgm/live 0.2.81-main.47244679900 → 0.2.81-main.47283630702

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 (74) hide show
  1. package/dist/apply/contracts.d.ts +4 -0
  2. package/dist/apply/lane.js +1 -1
  3. package/dist/apply/line.js +1 -1
  4. package/dist/apply/rail.js +1 -1
  5. package/dist/apply/settling.d.ts +1 -1
  6. package/dist/apply/showing.d.ts +4 -3
  7. package/dist/apply/showing.js +1 -1
  8. package/dist/apply/window.js +1 -1
  9. package/dist/clash/bodmas.js +1 -1
  10. package/dist/detection/record-proposal.d.ts +1 -1
  11. package/dist/detection/record-proposal.js +1 -1
  12. package/dist/detection/removals.js +1 -1
  13. package/dist/detection/skip-policy.js +1 -1
  14. package/dist/drive/drive.d.ts +6 -4
  15. package/dist/drive/drive.js +1 -1
  16. package/dist/drive/map-index.d.ts +12 -2
  17. package/dist/drive/map-index.js +1 -1
  18. package/dist/drive/where.d.ts +7 -0
  19. package/dist/drive/where.js +2 -2
  20. package/dist/entities/accepted-view.js +1 -1
  21. package/dist/entities/cloud.d.ts +1 -1
  22. package/dist/entities/cloud.js +1 -1
  23. package/dist/entities/reducer.js +1 -1
  24. package/dist/entities/rules.d.ts +0 -5
  25. package/dist/entities/rules.js +1 -1
  26. package/dist/entities/units.d.ts +28 -0
  27. package/dist/entities/units.js +1 -1
  28. package/dist/files/accepted-files.d.ts +3 -1
  29. package/dist/files/accepted-files.js +1 -1
  30. package/dist/files/browser.js +1 -1
  31. package/dist/files/cloud-files.d.ts +11 -0
  32. package/dist/files/cloud-files.js +1 -1
  33. package/dist/files/trash.js +1 -1
  34. package/dist/git/artifact.d.ts +14 -1
  35. package/dist/git/artifact.js +1 -1
  36. package/dist/git/checkout-view.d.ts +15 -0
  37. package/dist/git/checkout-view.js +1 -0
  38. package/dist/git/checkout.d.ts +31 -0
  39. package/dist/git/checkout.js +1 -0
  40. package/dist/git/holds.js +1 -1
  41. package/dist/git/index.d.ts +2 -0
  42. package/dist/git/index.js +1 -1
  43. package/dist/records/publication.js +1 -1
  44. package/dist/transfer/download.d.ts +2 -0
  45. package/dist/transfer/download.js +1 -1
  46. package/dist-cjs/apply/lane.js +1 -1
  47. package/dist-cjs/apply/line.js +1 -1
  48. package/dist-cjs/apply/rail.js +1 -1
  49. package/dist-cjs/apply/showing.js +1 -1
  50. package/dist-cjs/apply/window.js +1 -1
  51. package/dist-cjs/clash/bodmas.js +1 -1
  52. package/dist-cjs/detection/record-proposal.js +1 -1
  53. package/dist-cjs/detection/removals.js +1 -1
  54. package/dist-cjs/detection/skip-policy.js +1 -1
  55. package/dist-cjs/drive/drive.js +1 -1
  56. package/dist-cjs/drive/map-index.js +1 -1
  57. package/dist-cjs/drive/where.js +2 -2
  58. package/dist-cjs/entities/accepted-view.js +1 -1
  59. package/dist-cjs/entities/cloud.js +1 -1
  60. package/dist-cjs/entities/reducer.js +1 -1
  61. package/dist-cjs/entities/rules.js +1 -1
  62. package/dist-cjs/entities/units.js +1 -1
  63. package/dist-cjs/files/accepted-files.js +1 -1
  64. package/dist-cjs/files/browser.js +1 -1
  65. package/dist-cjs/files/cloud-files.js +1 -1
  66. package/dist-cjs/files/trash.js +1 -1
  67. package/dist-cjs/git/artifact.js +1 -1
  68. package/dist-cjs/git/checkout-view.js +1 -0
  69. package/dist-cjs/git/checkout.js +1 -0
  70. package/dist-cjs/git/holds.js +1 -1
  71. package/dist-cjs/git/index.js +1 -1
  72. package/dist-cjs/records/publication.js +1 -1
  73. package/dist-cjs/transfer/download.js +1 -1
  74. package/package.json +4 -4
@@ -64,6 +64,7 @@ export interface WindowMember {
64
64
  readonly work: EntityApplyWork;
65
65
  readonly judgment: LineJudgment;
66
66
  readonly deliverySequence: number;
67
+ readonly unseen?: string;
67
68
  }
68
69
  export interface ApplyWindow {
69
70
  readonly authorityId: string;
@@ -92,6 +93,9 @@ export type EntityApplyLaneStep = {
92
93
  } | {
93
94
  readonly kind: 'root';
94
95
  readonly reason: string;
96
+ } | {
97
+ readonly kind: 'unseen';
98
+ readonly reason: string;
95
99
  } | {
96
100
  readonly kind: 'prerequisite';
97
101
  readonly unit: string;
@@ -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,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};
1
+ var a=Object.defineProperty;var o=(n,e)=>a(n,"name",{value:e,configurable:!0});import{UUID_PATTERN as l}from"../entities/types.js";import{assertApplyWindow as u,invalidStep as t}from"./line.js";function s(n,e,r){return{kind:"lane",unit:n,emptied:r,through:e,toPrefix:!1,waitsOn:null,met:new Set,waiters:new Set,held:null,queued:!1,running:!1,again:!1}}o(s,"createApplyLane");function d(n,e){const r=`lane step for ${n}`;switch((!e||typeof e!="object"||!Number.isSafeInteger(e.through)||e.through<0)&&t(r),e.kind){case"end":return;case"nowhere":case"root":case"unseen":(typeof e.reason!="string"||e.reason.length===0)&&t(r);return;case"prerequisite":(!l.test(e.unit)||e.unit===n||typeof e.reason!="string"||e.reason.length===0)&&t(r);return;case"window":(e.window?.unit!==n||e.window.cutoff!==e.through||e.window.intent!==null&&(e.window.intent.unit!==n||e.window.intent.cutoff!==e.through))&&t(r),u(e.window,r),e.window.members.some(i=>i.work.kept!==null)&&f(e.window,r);return;default:t(r)}}o(d,"assertApplyLaneStep");function f(n,e){const[r]=n.members;(n.members.length!==1||r.work.play!=="enter"||r.work.records.length!==0||r.work.materialized!==null||r.deliverySequence!==n.cutoff||n.intent!==null&&n.intent.members.some(i=>i.kept===null))&&t(e)}o(f,"assertKeptWindow");export{d as assertApplyLaneStep,s as createApplyLane};
@@ -1 +1 @@
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};
1
+ var f=Object.defineProperty;var r=(e,n)=>f(e,"name",{value:n,configurable:!0});import{UUID_PATTERN as l}from"../entities/types.js";function m(e){return{kind:"line",authorityId:e,endsBefore:null,held:null,queued:!1,running:!1,again:!1}}r(m,"createApplyLine");function k(e,n,o){const i=e.held;return!i?.dependency||i.due||i.dependency.producer!==n||o!==void 0&&!i.dependency.entityIds.some(t=>o.includes(t))?!1:(i.due=!0,!0)}r(k,"releaseApplyLine");function w(e,n){if(e)return e.entityId===null||e.target===null?{entityId:e.entityId??n,reason:e.reason,throughSequence:e.target??e.cutoff??0}:{entityId:e.entityId,reason:e.reason,...e.dependency?{prerequisite:e.dependency}:{},throughSequence:e.target,...e.blocker?{blocker:e.blocker}:{}}}r(w,"heldWait");const a=new Set(["detect","apply","capability","send"]),c=r(e=>!!e&&a.has(e.producer)&&Array.isArray(e.entityIds)&&e.entityIds.length>0&&e.entityIds.every(n=>typeof n=="string"&&n.length>0),"namesRelease");function g(e){if(!c(e))throw new Error("Apply dependency must name the entities that can release it")}r(g,"assertApplyDependency");function b(e,n){(!n||typeof n!="object")&&u(`line step for ${e}`),n.kind!=="end"&&((n.kind!=="window"||n.window?.authorityId!==e||n.window.unit!==null||n.window.cutoff!==null||n.window.members?.some(o=>o.work?.kept!==null)||n.window.intent!==null&&(n.window.intent.unit!==null||n.window.intent.cutoff!==null))&&u(`line step for ${e}`),d(n.window,`line step for ${e}`))}r(b,"assertApplyLineStep");const u=r(e=>{throw new Error(`entity Apply store returned an invalid ${e}`)},"invalidStep");function d(e,n){(!Array.isArray(e.members)||e.members.length===0)&&u(n);const o=r((t,s)=>Number.isSafeInteger(t)&&t>=(s?0:1),"at");for(const t of e.members)(!l.test(t.work?.entityId??"")||t.work.authorityId!==e.authorityId||!o(t.deliverySequence,t.work.kept!==null))&&u(n),(t.unseen!==void 0||t.judgment==="unseen")&&(l.test(t.unseen??"")||u(n));const{deliverySequence:i}=e;(i===null?!e.intent:!o(i,e.members[0].work.kept!==null))&&u(n)}r(d,"assertApplyWindow");export{g as assertApplyDependency,b as assertApplyLineStep,d as assertApplyWindow,m as createApplyLine,w as heldWait,u as invalidStep,k as releaseApplyLine};
@@ -1 +1 @@
1
- var E=Object.defineProperty;var d=(o,e)=>E(o,"name",{value:e,configurable:!0});import{UUID_PATTERN as u}from"../entities/types.js";import{FetchAhead as b}from"./fetch-ahead.js";import{EntityApplyJourney as P,outcomeOf as g,stepsAside as O}from"./journey.js";import{assertApplyLaneStep as v,createApplyLane as S}from"./lane.js";import{assertApplyDependency as $,assertApplyLineStep as q,createApplyLine as M,heldWait as c,releaseApplyLine as _}from"./line.js";import{windowEndForWait as m}from"./window.js";const x=8,B=1e3,A=3e4,p=3;class C{static{d(this,"EntityApplyRail")}#e;#g;#P;#M;#_;#o;#O;#d=!1;#t=!1;#a=new Map;#s=new Map;#l={queue:[],steps:new Set};#u={queue:[],steps:new Set};#n=!1;#h=null;#p=1/0;#m=[];#A=0;#v=new Map;#y=null;constructor(e){this.#e=e,this.#g=e.concurrency??x,this.#P=e.laneConcurrency??this.#g,this.#M=e.onBackgroundError??(()=>{}),this.#_=e.onIdle??(()=>{});for(const[t,s]of[["concurrency",this.#g],["lane concurrency",this.#P]])if(!Number.isSafeInteger(s)||s<1)throw new Error(`entity Apply ${t} must be a positive integer`);this.#o=new P(e,()=>this.#A,()=>this.#t),this.#O=new b(e.cargo,{sha256Hex:e.sha256Hex,loops:e.loops})}async start(){if(this.#d)throw new Error("entity Apply rail already started");if(this.#t)throw new Error("entity Apply rail is stopped");this.#d=!0;const e=await this.#e.store.readOpenUnits();if(!Array.isArray(e)||new Set(e).size!==e.length||e.some(t=>!u.test(t)))throw new Error("entity Apply store returned an invalid open unit list");for(const t of e)this.#E(t,null);await this.#x()}fetch(e,t){return this.#d?this.#t?Promise.reject(new Error("entity Apply rail is stopped")):u.test(e)?!Number.isFinite(t.stall)||t.stall<0?Promise.reject(new Error("entity Apply fetch needs a non-negative stall")):t.emptied!==void 0&&typeof t.emptied!="boolean"?Promise.reject(new Error("entity Apply fetch emptied must be a boolean")):new Promise((s,i)=>{const r=this.#E(e,null,t.emptied===!0),n=d(()=>this.#e.schedule.schedule(t.stall,()=>{r.waiters.delete(l)&&(r.emptied&&![...r.waiters].some(a=>a.emptied)&&(r.emptied=!1),s(this.#G(r)))}),"arm");let h=n();const l={emptied:t.emptied===!0,answer:d(a=>{h.cancel(),s(a)},"answer"),fail:d(a=>{h.cancel(),i(a)},"fail"),moved:d(()=>{h.cancel(),h=n()},"moved")};r.waiters.add(l),r.waitsOn===null&&this.#N(r),this.#r()}):Promise.reject(new Error("entity Apply fetch needs a unit UUID")):Promise.reject(new Error("entity Apply rail has not started"))}progressed(e,t){if(!u.test(e))throw new Error("entity Apply progress needs a unit UUID");if(!Number.isSafeInteger(t)||t<0)throw new Error("entity Apply progress needs a byte count");t>0&&!this.#t&&this.#b(e)}recordsAvailable(){this.#I()}localStateChanged(e){this.#c("detect",e),this.#c("apply",e),this.#I()}sendAccepted(e){this.#c("send",e),this.#I()}capabilityChanged(e){this.#c("capability",e),this.#I()}owe(e){if(e.some(t=>!u.test(t)))throw new Error("entity Apply owe needs entity UUIDs");if(!(!this.#d||this.#t)){for(const t of e)this.#R(t);this.#r()}}#I(){!this.#d||this.#t||(this.#n=!0,this.#r())}waiting(){return this.#w().flatMap(e=>c(e.held,y(e))??[])}async flush(){if(!this.#d)throw new Error("entity Apply rail has not started");this.#t||await this.#x()}async stop(){if(this.#t)return;this.#t=!0,this.#q();for(const t of[this.#l,this.#u])for(const s of t.queue.splice(0))s.queued=!1;const e=new Error("entity Apply rail stopped before the fetch answered");for(const t of this.#s.values())for(const s of t.waiters)s.fail(e);for(this.#s.clear();this.#B()>0||this.#h;)await Promise.allSettled([...this.#l.steps,...this.#u.steps,...this.#h?[this.#h]:[]]);await this.#O.stop();for(const t of this.#m.splice(0))t.resolve()}#x(){return new Promise((e,t)=>{this.#m.push({resolve:e,reject:t}),this.#n=!0,this.#r()})}#r(){if(!this.#t){if(this.#n&&this.#h===null){this.#n=!1;const e=this.#F();this.#h=e,e.then(()=>{this.#h=null,this.#r()})}for(const[e,t]of[[this.#u,this.#P],[this.#l,this.#g]])for(;e.steps.size<t&&e.queue.length>0;){const s=e.queue.shift();s.queued=!1,this.#D(s,e)}if(this.#B()===0&&this.#h===null&&!this.#n&&this.#l.queue.length===0&&this.#u.queue.length===0){if(this.#v.clear(),this.#z(this.#e.now())){this.#r();return}this.#$();for(const e of this.#m.splice(0))e.resolve();this.#_()}}}#B(){return this.#l.steps.size+this.#u.steps.size}#w(){return[...this.#a.values(),...this.#s.values()]}#k(e){return e.kind==="line"?this.#a.get(e.authorityId)===e:this.#s.get(e.unit)===e}#i(e){if(!this.#t){if(e.running){e.again=!0;return}e.queued||(e.queued=!0,(e.kind==="line"?this.#l:this.#u).queue.push(e))}}#D(e,t){e.running=!0,e.again=!1;const s=(e.kind==="line"?this.#J(e):this.#H(e)).then(i=>{e.running=!1,t.steps.delete(s),(i||e.again)&&this.#k(e)&&(e.again=!1,this.#i(e)),this.#r()});t.steps.add(s)}async#F(){try{const e=await this.#e.store.readApplyAuthorities();if(!Array.isArray(e)||new Set(e).size!==e.length||e.some(s=>typeof s!="string"||s.length===0))throw new Error("entity Apply store returned an invalid authority list");this.#p=1/0;const t=new Set(e);for(const[s,i]of this.#a)!t.has(s)&&!i.running&&!i.queued&&this.#a.delete(s);for(const s of e){let i=this.#a.get(s);i||(i=M(s),this.#a.set(s,i)),this.#i(i)}}catch(e){this.#p=this.#e.now()+A;const t=this.#m.splice(0);t.length===0&&this.#S(e);for(const s of t)s.reject(e)}}async#J(e){try{const t=e.held;if(t&&t.entityId===null&&!t.due&&t.notBefore>this.#e.now())return!1;const s=this.#A,i=await this.#e.store.readApplyWindow(e.authorityId,e.endsBefore);if(q(e.authorityId,i),this.#t)return!1;if(i.kind==="end"){e.held=null;const r=e.endsBefore!==null;return e.endsBefore=null,r}return i.window.deliverySequence!==null&&this.#O.advance(e.authorityId,i.window.deliverySequence),await this.#L(e,i.window,s)}catch(t){return this.#j(e,t),!1}}async#H(e){try{const t=e.held;if(t&&t.entityId===null&&!t.due&&t.notBefore>this.#e.now())return!1;const s=this.#A,i=await this.#e.store.readFetchWindow(e.unit,e.toPrefix?null:e.through);if(v(e.unit,i),this.#t||!this.#k(e))return!1;switch((i.kind!=="window"||i.window.intent===null)&&(e.toPrefix=!1),e.through!==null&&i.through>e.through&&e.met.clear(),e.through=Math.max(e.through??0,i.through),e.waitsOn=null,i.kind!=="window"&&(e.held=null),i.kind){case"end":return this.#f(e,{kind:"placed"}),!1;case"nowhere":return this.#f(e,{kind:"nowhere",reason:i.reason}),!1;case"root":return await this.#V(e,i.through,i.reason);case"prerequisite":return this.#X(e,i.unit,i.reason,s);case"window":return await this.#L(e,i.window,s)}}catch(t){return this.#j(e,t),!1}}async#V(e,t,s){return e.met.has(e.unit)?(this.#f(e,{kind:"held",unit:e.unit,reason:`${e.unit} entered and still not held: ${s}`}),!1):(await this.#e.effects.enterRoot(e.unit,t),this.#t||!this.#k(e)?!1:(e.through===t&&e.met.add(e.unit),this.#b(e.unit),!0))}#R(e){const t=this.#E(e,null);t.toPrefix=!0,t.met.clear(),this.#i(t)}#E(e,t,s=!1){let i=this.#s.get(e);return i?t!==null&&(i.through===null||i.through<t)&&(i.through=t,i.met.clear(),this.#i(i)):(i=S(e,t,s),this.#s.set(e,i),this.#i(i)),i}#X(e,t,s,i){if(e.met.has(t))return this.#f(e,{kind:"held",unit:t,reason:`${t} placed and still needed: ${s}`}),!1;if(!this.#T(e,t,s))return!1;const r={producer:"apply",entityIds:[t]};return e.held={entityId:null,target:null,kept:null,cutoff:null,attempt:1,notBefore:1/0,releaseOnProgress:!1,due:this.#W(r,i),reason:s,dependency:r},e.held.due}#N(e){const t=e.held;if(t?.dependency?.producer==="apply"){for(const s of t.dependency.entityIds)if(s!==e.unit&&!e.met.has(s)&&!this.#T(e,s,t.reason))return}}#T(e,t,s){const i=[e];let r=this.#s.get(t);for(;r&&r!==e&&!i.includes(r);)i.push(r),r=r.waitsOn===null?void 0:this.#s.get(r.waitsOn);if(r===e){for(const n of i)this.#f(n,{kind:"held",unit:t,reason:`prerequisite cycle through ${t}: ${s}`});return!1}return e.waitsOn??=t,this.#i(this.#E(t,e.through)),!0}#f(e,t){if(!this.#k(e))return;for(const i of e.waiters)i.answer(t);e.waiters.clear(),e.waitsOn=null,(t.kind==="placed"||e.held?.entityId==null)&&this.#s.delete(e.unit);const s=t.kind==="placed"||t.kind==="held"?t:{kind:"held",unit:e.unit,reason:`${e.unit} is nowhere here: ${t.reason}`};for(const i of[...this.#s.values()])if(i.waitsOn===e.unit){if(t.kind!=="placed"){this.#f(i,s);continue}i.met.add(e.unit)}t.kind==="placed"&&(this.#b(e.unit),this.#c("apply",[e.unit]))}#b(e){const t=new Map([[e,!0]]);for(const s of this.#s.values()){const i=new Set;let r=s.unit;for(;r!==null&&!t.has(r)&&!i.has(r);)i.add(r),r=this.#s.get(r)?.waitsOn??null;const n=r!==null&&t.get(r)===!0;for(const h of i)t.set(h,n);if(n)for(const h of s.waiters)h.moved()}}#G(e){let t=e;const s=new Set([e]);for(let i=e.waitsOn===null?void 0:this.#s.get(e.waitsOn);i&&!s.has(i);i=i.waitsOn===null?void 0:this.#s.get(i.waitsOn))s.add(i),t=i;return{kind:"held",unit:t.unit,reason:t.held?.reason??"still placing"}}async#L(e,t,s){const i=t.members[0]?.work.entityId??null;if(e.held&&e.held.entityId!==null&&e.held.entityId!==i&&(e.held=null),await this.#Q(e,t))return!1;let r=await g(()=>this.#o.run(t,()=>e.kind==="lane"&&e.emptied?e.unit:null));if(e.kind==="line"&&typeof r=="object"&&r.kind==="park"&&m(t,r.dependency)===null&&this.#K(e,t,r)&&(r=await g(()=>this.#o.alone(t.members[0]))),r==="progress"||typeof r=="object"&&r.kind==="alone"){if(e.kind==="line")for(const n of t.members)(n.judgment==="waiting"||r!=="progress"&&n.work.entityId===r.entityId)&&this.#R(n.work.entityId);return this.#Z(e,r==="progress"?t.members.map(n=>n.work.entityId):[r.entityId])}if(r==="again")return e.held?.entityId===i&&(e.held=null),!0;if(r.advanced?.length&&this.#Y(e,r.advanced),e.kind==="line"){const n=m(t,r.dependency);if(n!==null)return e.endsBefore=n,!0}return this.#ee(e,t,r,s),e.kind==="lane"&&this.#N(e),e.held.due}#K(e,t,s){const i=t.members[0].work.entityId;if(s.cause!==void 0||!O(t,i))return!1;const r=s.dependency?.entityIds??[i];return r.length===0||r.some(n=>n!==i)?!1:s.dependency?.producer==="capability"?!0:this.#U(e,t)>=p}#U(e,t){const s=e.held,i=t.members[0].work.entityId;return(s?.entityId===i&&s.target===this.#o.targetOf(t)?s.attempt:0)+1}async#Q(e,t){const s=e.held,i=t.members[0];return!s||i===void 0||s.entityId!==i.work.entityId||s.due||s.notBefore<=this.#e.now()||this.#o.targetOf(t)!==s.target||t.cutoff!==s.cutoff?!1:await this.#e.store.localWorkAfter(t.authorityId,i.work.entityId,s.kept??s.target)===null}#Z(e,t){return e.held&&(e.held.entityId===null||t.includes(e.held.entityId))&&(e.held=null),this.#Y(e,t),!0}#Y(e,t){e.kind==="lane"&&(this.#n=!0,this.#b(e.unit)),this.#c("apply",t);for(const s of this.#w())s!==e&&s.held?.releaseOnProgress&&!s.held.due&&(s.held.due=!0,this.#i(s))}#ee(e,t,s,i){if(s.dependency&&$(s.dependency),s.blocker&&!s.dependency)throw new Error("Apply blocker must name the dependency that releases it");const r=t.members[0].work.entityId,n=e.held,h=this.#U(e,t),l=this.#C(h),a=s.again===!0&&h<p,w={entityId:r,target:this.#o.targetOf(t),kept:t.members[0].work.kept,cutoff:t.cutoff,attempt:h,notBefore:s.dependency?1/0:this.#e.now()+(a?0:l),releaseOnProgress:s.releaseOnProgress,due:s.dependency?this.#W(s.dependency,s.comparedAt??i):a,reason:s.reason,...s.dependency?{dependency:s.dependency}:{},...s.blocker?{blocker:s.blocker}:{}};e.held=w,this.#$();const k=c(n,y(e)),f=c(w,y(e));f&&JSON.stringify(f)!==JSON.stringify(k)&&this.#e.onWaiting?.(f),!(!s.report&&(s.dependency!==void 0||h<p))&&this.#S(new Error(`${I(e)} holds at ${r}, which ${s.releaseOnProgress?"is parked on a conflict":s.report?"failed":s.again?"keeps ending unplaced":"stands on ground that keeps moving"}, and will retry in ${l}ms (attempt ${h}): ${s.reason}`,s.cause===void 0?void 0:{cause:s.cause}))}#j(e,t){if(e.kind==="lane"){for(const h of e.waiters)h.fail(t);e.waiters.clear()}const s=e.held,i=(s?.entityId===null?s.attempt:0)+1,r=this.#C(i),n=t instanceof Error?t.message:String(t);e.held={entityId:null,target:null,kept:null,cutoff:null,attempt:i,notBefore:this.#e.now()+r,releaseOnProgress:!1,due:!1,reason:n},this.#$(),this.#S(new Error(`${I(e)} faulted and will retry in ${r}ms (attempt ${i}): ${n}`,{cause:t}))}#S(e){try{this.#M(e)}catch{}}#C(e){const t=Math.min(A,B*2**Math.min(e-1,16)),s=Math.max(0,Math.min(1,this.#e.schedule.random()));return Math.round(t*(.5+s))}#c(e,t){const s=++this.#A;for(const i of t??["*"])this.#v.set(`${e}:${i}`,s);for(const i of this.#w())_(i,e,t)&&this.#i(i)}#W(e,t){return["*",...e.entityIds].some(s=>(this.#v.get(`${e.producer}:${s}`)??0)>t)}#$(){if(this.#t)return;let e=this.#p;for(const i of this.#w())i.held&&!i.held.due&&(e=Math.min(e,i.held.notBefore));if(e===1/0){this.#q();return}if(this.#y?.dueAt===e)return;this.#q();const t=Math.max(0,e-this.#e.now()),s=this.#e.schedule.schedule(t,()=>{this.#y=null,this.#z(e),this.#r()});this.#y={dueAt:e,cancel:d(()=>s.cancel(),"cancel")}}#z(e){let t=!1;for(const s of this.#w())s.held&&!s.held.due&&s.held.notBefore<=e&&(s.held.due=!0,this.#i(s),t=!0);return this.#p<=e&&(this.#p=1/0,this.#n=!0,t=!0),t}#q(){this.#y?.cancel(),this.#y=null}}const y=d(o=>o.kind==="line"?o.authorityId:o.unit,"owner"),I=d(o=>o.kind==="line"?`entity Apply line ${o.authorityId}`:`entity Apply fetch of ${o.unit}`,"label");export{x as ENTITY_APPLY_DEFAULT_CONCURRENCY,B as ENTITY_APPLY_RETRY_BASE_MS,A as ENTITY_APPLY_RETRY_MAX_MS,p as ENTITY_APPLY_SAME_ANSWERS,C as EntityApplyRail};
1
+ var E=Object.defineProperty;var d=(o,e)=>E(o,"name",{value:e,configurable:!0});import{UUID_PATTERN as u}from"../entities/types.js";import{FetchAhead as b}from"./fetch-ahead.js";import{EntityApplyJourney as P,outcomeOf as g,stepsAside as O}from"./journey.js";import{assertApplyLaneStep as v,createApplyLane as S}from"./lane.js";import{assertApplyDependency as $,assertApplyLineStep as q,createApplyLine as M,heldWait as c,releaseApplyLine as _}from"./line.js";import{windowEndForWait as m}from"./window.js";const x=8,B=1e3,A=3e4,p=3;class C{static{d(this,"EntityApplyRail")}#e;#g;#P;#_;#x;#o;#O;#d=!1;#t=!1;#a=new Map;#s=new Map;#l={queue:[],steps:new Set};#u={queue:[],steps:new Set};#n=!1;#h=null;#p=1/0;#m=[];#A=0;#v=new Map;#y=null;constructor(e){this.#e=e,this.#g=e.concurrency??x,this.#P=e.laneConcurrency??this.#g,this.#_=e.onBackgroundError??(()=>{}),this.#x=e.onIdle??(()=>{});for(const[t,s]of[["concurrency",this.#g],["lane concurrency",this.#P]])if(!Number.isSafeInteger(s)||s<1)throw new Error(`entity Apply ${t} must be a positive integer`);this.#o=new P(e,()=>this.#A,()=>this.#t),this.#O=new b(e.cargo,{sha256Hex:e.sha256Hex,loops:e.loops})}async start(){if(this.#d)throw new Error("entity Apply rail already started");if(this.#t)throw new Error("entity Apply rail is stopped");this.#d=!0;const e=await this.#e.store.readOpenUnits();if(!Array.isArray(e)||new Set(e).size!==e.length||e.some(t=>!u.test(t)))throw new Error("entity Apply store returned an invalid open unit list");for(const t of e)this.#E(t,null);await this.#B()}fetch(e,t){return this.#d?this.#t?Promise.reject(new Error("entity Apply rail is stopped")):u.test(e)?!Number.isFinite(t.stall)||t.stall<0?Promise.reject(new Error("entity Apply fetch needs a non-negative stall")):t.emptied!==void 0&&typeof t.emptied!="boolean"?Promise.reject(new Error("entity Apply fetch emptied must be a boolean")):new Promise((s,i)=>{const r=this.#E(e,null,t.emptied===!0),n=d(()=>this.#e.schedule.schedule(t.stall,()=>{r.waiters.delete(l)&&(r.emptied&&![...r.waiters].some(a=>a.emptied)&&(r.emptied=!1),s(this.#K(r)))}),"arm");let h=n();const l={emptied:t.emptied===!0,answer:d(a=>{h.cancel(),s(a)},"answer"),fail:d(a=>{h.cancel(),i(a)},"fail"),moved:d(()=>{h.cancel(),h=n()},"moved")};r.waiters.add(l),r.waitsOn===null&&this.#T(r),this.#r()}):Promise.reject(new Error("entity Apply fetch needs a unit UUID")):Promise.reject(new Error("entity Apply rail has not started"))}progressed(e,t){if(!u.test(e))throw new Error("entity Apply progress needs a unit UUID");if(!Number.isSafeInteger(t)||t<0)throw new Error("entity Apply progress needs a byte count");t>0&&!this.#t&&this.#b(e)}recordsAvailable(){this.#I()}localStateChanged(e){this.#c("detect",e),this.#c("apply",e),this.#I()}sendAccepted(e){this.#c("send",e),this.#I()}capabilityChanged(e){this.#c("capability",e),this.#I()}owe(e){if(e.some(t=>!u.test(t)))throw new Error("entity Apply owe needs entity UUIDs");if(!(!this.#d||this.#t)){for(const t of e)this.#S(t);this.#r()}}#I(){!this.#d||this.#t||(this.#n=!0,this.#r())}waiting(){return this.#w().flatMap(e=>c(e.held,y(e))??[])}async flush(){if(!this.#d)throw new Error("entity Apply rail has not started");this.#t||await this.#B()}async stop(){if(this.#t)return;this.#t=!0,this.#M();for(const t of[this.#l,this.#u])for(const s of t.queue.splice(0))s.queued=!1;const e=new Error("entity Apply rail stopped before the fetch answered");for(const t of this.#s.values())for(const s of t.waiters)s.fail(e);for(this.#s.clear();this.#R()>0||this.#h;)await Promise.allSettled([...this.#l.steps,...this.#u.steps,...this.#h?[this.#h]:[]]);await this.#O.stop();for(const t of this.#m.splice(0))t.resolve()}#B(){return new Promise((e,t)=>{this.#m.push({resolve:e,reject:t}),this.#n=!0,this.#r()})}#r(){if(!this.#t){if(this.#n&&this.#h===null){this.#n=!1;const e=this.#J();this.#h=e,e.then(()=>{this.#h=null,this.#r()})}for(const[e,t]of[[this.#u,this.#P],[this.#l,this.#g]])for(;e.steps.size<t&&e.queue.length>0;){const s=e.queue.shift();s.queued=!1,this.#F(s,e)}if(this.#R()===0&&this.#h===null&&!this.#n&&this.#l.queue.length===0&&this.#u.queue.length===0){if(this.#v.clear(),this.#D(this.#e.now())){this.#r();return}this.#q();for(const e of this.#m.splice(0))e.resolve();this.#x()}}}#R(){return this.#l.steps.size+this.#u.steps.size}#w(){return[...this.#a.values(),...this.#s.values()]}#k(e){return e.kind==="line"?this.#a.get(e.authorityId)===e:this.#s.get(e.unit)===e}#i(e){if(!this.#t){if(e.running){e.again=!0;return}e.queued||(e.queued=!0,(e.kind==="line"?this.#l:this.#u).queue.push(e))}}#F(e,t){e.running=!0,e.again=!1;const s=(e.kind==="line"?this.#H(e):this.#V(e)).then(i=>{e.running=!1,t.steps.delete(s),(i||e.again)&&this.#k(e)&&(e.again=!1,this.#i(e)),this.#r()});t.steps.add(s)}async#J(){try{const e=await this.#e.store.readApplyAuthorities();if(!Array.isArray(e)||new Set(e).size!==e.length||e.some(s=>typeof s!="string"||s.length===0))throw new Error("entity Apply store returned an invalid authority list");this.#p=1/0;const t=new Set(e);for(const[s,i]of this.#a)!t.has(s)&&!i.running&&!i.queued&&this.#a.delete(s);for(const s of e){let i=this.#a.get(s);i||(i=M(s),this.#a.set(s,i)),this.#i(i)}}catch(e){this.#p=this.#e.now()+A;const t=this.#m.splice(0);t.length===0&&this.#$(e);for(const s of t)s.reject(e)}}async#H(e){try{const t=e.held;if(t&&t.entityId===null&&!t.due&&t.notBefore>this.#e.now())return!1;const s=this.#A,i=await this.#e.store.readApplyWindow(e.authorityId,e.endsBefore);if(q(e.authorityId,i),this.#t)return!1;if(i.kind==="end"){e.held=null;const r=e.endsBefore!==null;return e.endsBefore=null,r}return i.window.deliverySequence!==null&&this.#O.advance(e.authorityId,i.window.deliverySequence),await this.#U(e,i.window,s)}catch(t){return this.#C(e,t),!1}}async#V(e){try{const t=e.held;if(t&&t.entityId===null&&!t.due&&t.notBefore>this.#e.now())return!1;const s=this.#A,i=await this.#e.store.readFetchWindow(e.unit,e.toPrefix?null:e.through);if(v(e.unit,i),this.#t||!this.#k(e))return!1;if(e.waitsOn=null,i.kind==="unseen")return this.#N(e,{producer:"detect",entityIds:[e.unit]},i.reason,s);if(!e.again&&(i.kind!=="window"||i.window.intent===null)&&(e.toPrefix=!1),e.through!==null&&i.through>e.through&&e.met.clear(),e.through=Math.max(e.through??0,i.through),i.kind!=="window"&&(e.held=null),e.again&&(i.kind==="end"||i.kind==="nowhere"))return!0;switch(i.kind){case"end":return this.#f(e,{kind:"placed"}),!1;case"nowhere":return this.#f(e,{kind:"nowhere",reason:i.reason}),!1;case"root":return await this.#X(e,i.through,i.reason);case"prerequisite":return this.#G(e,i.unit,i.reason,s);case"window":return await this.#U(e,i.window,s)}}catch(t){return this.#C(e,t),!1}}async#X(e,t,s){return e.met.has(e.unit)?(this.#f(e,{kind:"held",unit:e.unit,reason:`${e.unit} entered and still not held: ${s}`}),!1):(await this.#e.effects.enterRoot(e.unit,t),this.#t||!this.#k(e)?!1:(e.through===t&&e.met.add(e.unit),this.#b(e.unit),!0))}#S(e){const t=this.#E(e,null);t.toPrefix=!0,t.met.clear(),this.#i(t)}#E(e,t,s=!1){let i=this.#s.get(e);return i?t!==null&&(i.through===null||i.through<t)&&(i.through=t,i.met.clear(),this.#i(i)):(i=S(e,t,s),this.#s.set(e,i),this.#i(i)),i}#G(e,t,s,i){return e.met.has(t)?(this.#f(e,{kind:"held",unit:t,reason:`${t} placed and still needed: ${s}`}),!1):this.#L(e,t,s)?this.#N(e,{producer:"apply",entityIds:[t]},s,i):!1}#N(e,t,s,i){return e.held={entityId:null,target:null,kept:null,cutoff:null,attempt:1,notBefore:1/0,releaseOnProgress:!1,due:this.#z(t,i),reason:s,dependency:t},e.held.due}#T(e){const t=e.held;if(t?.dependency?.producer==="apply"){for(const s of t.dependency.entityIds)if(s!==e.unit&&!e.met.has(s)&&!this.#L(e,s,t.reason))return}}#L(e,t,s){const i=[e];let r=this.#s.get(t);for(;r&&r!==e&&!i.includes(r);)i.push(r),r=r.waitsOn===null?void 0:this.#s.get(r.waitsOn);if(r===e){for(const n of i)this.#f(n,{kind:"held",unit:t,reason:`prerequisite cycle through ${t}: ${s}`});return!1}return e.waitsOn??=t,this.#i(this.#E(t,e.through)),!0}#f(e,t){if(!this.#k(e))return;for(const i of e.waiters)i.answer(t);e.waiters.clear(),e.waitsOn=null,(t.kind==="placed"||e.held?.entityId==null)&&this.#s.delete(e.unit);const s=t.kind==="placed"||t.kind==="held"?t:{kind:"held",unit:e.unit,reason:`${e.unit} is nowhere here: ${t.reason}`};for(const i of[...this.#s.values()])if(i.waitsOn===e.unit){if(t.kind!=="placed"){this.#f(i,s);continue}i.met.add(e.unit)}t.kind==="placed"&&(this.#b(e.unit),this.#c("apply",[e.unit]))}#b(e){const t=new Map([[e,!0]]);for(const s of this.#s.values()){const i=new Set;let r=s.unit;for(;r!==null&&!t.has(r)&&!i.has(r);)i.add(r),r=this.#s.get(r)?.waitsOn??null;const n=r!==null&&t.get(r)===!0;for(const h of i)t.set(h,n);if(n)for(const h of s.waiters)h.moved()}}#K(e){let t=e;const s=new Set([e]);for(let i=e.waitsOn===null?void 0:this.#s.get(e.waitsOn);i&&!s.has(i);i=i.waitsOn===null?void 0:this.#s.get(i.waitsOn))s.add(i),t=i;return{kind:"held",unit:t.unit,reason:t.held?.reason??"still placing"}}async#U(e,t,s){const i=t.members[0]?.work.entityId??null;if(e.held&&e.held.entityId!==null&&e.held.entityId!==i&&(e.held=null),await this.#Z(e,t))return!1;let r=await g(()=>this.#o.run(t,()=>e.kind==="lane"&&e.emptied?e.unit:null));if(e.kind==="line"&&typeof r=="object"&&r.kind==="park"&&m(t,r.dependency)===null&&this.#Q(e,t,r)&&(r=await g(()=>this.#o.alone(t.members[0]))),r==="progress"||typeof r=="object"&&r.kind==="alone"){if(e.kind==="line")for(const n of t.members)(n.judgment==="waiting"||r!=="progress"&&n.work.entityId===r.entityId)&&this.#S(n.work.entityId);for(const n of t.members)n.unseen!==void 0&&this.#S(n.unseen);return this.#ee(e,r==="progress"?t.members.map(n=>n.work.entityId):[r.entityId])}if(r==="again")return e.held?.entityId===i&&(e.held=null),!0;if(r.advanced?.length&&this.#j(e,r.advanced),e.kind==="line"){const n=m(t,r.dependency);if(n!==null)return e.endsBefore=n,!0}return this.#te(e,t,r,s),e.kind==="lane"&&this.#T(e),e.held.due}#Q(e,t,s){const i=t.members[0].work.entityId;if(s.cause!==void 0||!O(t,i))return!1;const r=s.dependency?.entityIds??[i];return r.length===0||r.some(n=>n!==i)?!1:s.dependency?.producer==="capability"?!0:this.#Y(e,t)>=p}#Y(e,t){const s=e.held,i=t.members[0].work.entityId;return(s?.entityId===i&&s.target===this.#o.targetOf(t)?s.attempt:0)+1}async#Z(e,t){const s=e.held,i=t.members[0];return!s||i===void 0||s.entityId!==i.work.entityId||s.due||s.notBefore<=this.#e.now()||this.#o.targetOf(t)!==s.target||t.cutoff!==s.cutoff?!1:await this.#e.store.localWorkAfter(t.authorityId,i.work.entityId,s.kept??s.target)===null}#ee(e,t){return e.held&&(e.held.entityId===null||t.includes(e.held.entityId))&&(e.held=null),this.#j(e,t),!0}#j(e,t){e.kind==="lane"&&(this.#n=!0,this.#b(e.unit)),this.#c("apply",t);for(const s of this.#w())s!==e&&s.held?.releaseOnProgress&&!s.held.due&&(s.held.due=!0,this.#i(s))}#te(e,t,s,i){if(s.dependency&&$(s.dependency),s.blocker&&!s.dependency)throw new Error("Apply blocker must name the dependency that releases it");const r=t.members[0].work.entityId,n=e.held,h=this.#Y(e,t),l=this.#W(h),a=s.again===!0&&h<p,w={entityId:r,target:this.#o.targetOf(t),kept:t.members[0].work.kept,cutoff:t.cutoff,attempt:h,notBefore:s.dependency?1/0:this.#e.now()+(a?0:l),releaseOnProgress:s.releaseOnProgress,due:s.dependency?this.#z(s.dependency,s.comparedAt??i):a,reason:s.reason,...s.dependency?{dependency:s.dependency}:{},...s.blocker?{blocker:s.blocker}:{}};e.held=w,this.#q();const k=c(n,y(e)),f=c(w,y(e));f&&JSON.stringify(f)!==JSON.stringify(k)&&this.#e.onWaiting?.(f),!(!s.report&&(s.dependency!==void 0||h<p))&&this.#$(new Error(`${I(e)} holds at ${r}, which ${s.releaseOnProgress?"is parked on a conflict":s.report?"failed":s.again?"keeps ending unplaced":"stands on ground that keeps moving"}, and will retry in ${l}ms (attempt ${h}): ${s.reason}`,s.cause===void 0?void 0:{cause:s.cause}))}#C(e,t){if(e.kind==="lane"){for(const h of e.waiters)h.fail(t);e.waiters.clear()}const s=e.held,i=(s?.entityId===null?s.attempt:0)+1,r=this.#W(i),n=t instanceof Error?t.message:String(t);e.held={entityId:null,target:null,kept:null,cutoff:null,attempt:i,notBefore:this.#e.now()+r,releaseOnProgress:!1,due:!1,reason:n},this.#q(),this.#$(new Error(`${I(e)} faulted and will retry in ${r}ms (attempt ${i}): ${n}`,{cause:t}))}#$(e){try{this.#_(e)}catch{}}#W(e){const t=Math.min(A,B*2**Math.min(e-1,16)),s=Math.max(0,Math.min(1,this.#e.schedule.random()));return Math.round(t*(.5+s))}#c(e,t){const s=++this.#A;for(const i of t??["*"])this.#v.set(`${e}:${i}`,s);for(const i of this.#w())_(i,e,t)&&this.#i(i)}#z(e,t){return["*",...e.entityIds].some(s=>(this.#v.get(`${e.producer}:${s}`)??0)>t)}#q(){if(this.#t)return;let e=this.#p;for(const i of this.#w())i.held&&!i.held.due&&(e=Math.min(e,i.held.notBefore));if(e===1/0){this.#M();return}if(this.#y?.dueAt===e)return;this.#M();const t=Math.max(0,e-this.#e.now()),s=this.#e.schedule.schedule(t,()=>{this.#y=null,this.#D(e),this.#r()});this.#y={dueAt:e,cancel:d(()=>s.cancel(),"cancel")}}#D(e){let t=!1;for(const s of this.#w())s.held&&!s.held.due&&s.held.notBefore<=e&&(s.held.due=!0,this.#i(s),t=!0);return this.#p<=e&&(this.#p=1/0,this.#n=!0,t=!0),t}#M(){this.#y?.cancel(),this.#y=null}}const y=d(o=>o.kind==="line"?o.authorityId:o.unit,"owner"),I=d(o=>o.kind==="line"?`entity Apply line ${o.authorityId}`:`entity Apply fetch of ${o.unit}`,"label");export{x as ENTITY_APPLY_DEFAULT_CONCURRENCY,B as ENTITY_APPLY_RETRY_BASE_MS,A as ENTITY_APPLY_RETRY_MAX_MS,p as ENTITY_APPLY_SAME_ANSWERS,C as EntityApplyRail};
@@ -2,7 +2,7 @@ import { type LocalWork, type OwnLine } from '../clash/local-work.js';
2
2
  import type { AcceptedEntityRecord } from '../records/contracts.js';
3
3
  import { type OutboxRow } from '../records/outbox.js';
4
4
  import { type ApplyPlay, type ShowingJudgment } from './showing.js';
5
- export type ApplySettlement = 'superseded' | 'own' | 'neither' | 'listed' | 'turn' | 'waiting';
5
+ export type ApplySettlement = 'superseded' | 'own' | 'neither' | 'listed' | 'unseen' | 'turn' | 'waiting';
6
6
  export type LineJudgment = ApplySettlement | ApplyPlay;
7
7
  export interface LineHeadFacts extends OwnLine {
8
8
  localWorkAfter(): LocalWork | null;
@@ -2,7 +2,7 @@ import type { CloudEntityRecord } from '../entities/cloud.js';
2
2
  import { type EntityType } from '../entities/types.js';
3
3
  import { type UnitPlace } from '../entities/units.js';
4
4
  export type ApplyPlay = 'apply' | 'enter' | 'leave';
5
- export type ShowingJudgment = ApplyPlay | 'neither' | 'listed';
5
+ export type ShowingJudgment = ApplyPlay | 'neither' | 'listed' | 'unseen';
6
6
  export declare const APPLY_PLAYS: ReadonlySet<ApplyPlay>;
7
7
  export interface ShownPlace {
8
8
  readonly parentUUID: string | null;
@@ -15,7 +15,8 @@ export interface ShownPlace {
15
15
  readonly sealed?: boolean;
16
16
  }
17
17
  export type LineParent = (uuid: string) => string | undefined;
18
- export declare function judgeShowing(result: CloudEntityRecord, shownPlace: (uuid: string) => ShownPlace | undefined, lineParent?: LineParent): ShowingJudgment;
18
+ export type BoundPlace = (uuid: string) => ShownPlace | undefined;
19
+ export declare function judgeShowing(result: CloudEntityRecord, shownPlace: (uuid: string) => ShownPlace | undefined, lineParent?: LineParent, bound?: BoundPlace): ShowingJudgment;
19
20
  export interface ShownUnit extends UnitPlace {
20
21
  readonly name: string;
21
22
  readonly home?: boolean;
@@ -26,5 +27,5 @@ export interface TopEntry {
26
27
  readonly uuid: string;
27
28
  readonly home: boolean;
28
29
  }
29
- export declare function lineReturns(result: CloudEntityRecord, shownPlace: (uuid: string) => ShownPlace | undefined, lineParent: LineParent): ReadonlyMap<string, string>;
30
+ export declare function lineReturns(result: CloudEntityRecord, shownPlace: (uuid: string) => ShownPlace | undefined, lineParent: LineParent, bound?: BoundPlace): ReadonlyMap<string, string>;
30
31
  export declare function returnedPlaces(shownPlace: (uuid: string) => ShownPlace | undefined, returns: ReadonlyMap<string, string>): (uuid: string) => ShownPlace | undefined;
@@ -1 +1 @@
1
- var U=Object.defineProperty;var f=(e,o)=>U(e,"name",{value:o,configurable:!0});import{CONTAINERS as p,isConstructType as h}from"../entities/types.js";import{fileAbsent as D}from"../entities/rules.js";import{unitOf as I}from"../entities/units.js";import{placedAtHome as b}from"../registration/home-layout.js";const A=new Set(["apply","enter","leave"]),w={onDemand:!1};function M(e,o,u){const t=o(e.uuid),n=t?.available===!0,{root:r,returns:a}=m(e,o,u);if(r==="sealed")return"neither";if(r===null)return n?"leave":"neither";if(!n&&r.onDemand){const i=y(s=>s===e.uuid?e:void 0,c(o,a));if(I(e.uuid,i)===e.uuid&&!v(e.uuid,i))return"listed"}return n&&(p.has(t.type)||!p.has(e.type))?"apply":"enter"}f(M,"judgeShowing");function y(e,o){return u=>{const t=e(u);if(t?.parentUUID===null)return{...t,home:o(u)?.home===!0};if(t)return t;const n=o(u);return n?.root?{type:n.type,name:n.name,parentUUID:null,home:n.home}:n}}f(y,"shownUnits");function v(e,o,u=new Map){const t=o(e);if(t?.parentUUID===null)return!0;const n=new Set;let r=null;for(let a=e,i=t;i?.parentUUID!=null&&!n.has(a);){const s=u.get(a);if(s!==void 0){r=s;break}n.add(a);const l=o(i.parentUUID);if(l?.parentUUID===null){r={uuid:a,home:l.home===!0};break}a=i.parentUUID,i=l}for(const a of n)u.set(a,r);return r===null?!1:r.home&&b(o(r.uuid).name,r.uuid!==e)}f(v,"placedInRoot");function N(e,o,u){return m(e,o,u).returns}f(N,"lineReturns");function c(e,o){return o.size===0?e:u=>{const t=e(u),n=o.get(u);return t!==void 0&&n!==void 0?{...t,parentUUID:n}:t}}f(c,"returnedPlaces");const d=new Map;function m(e,o,u){const t=new Map;for(;;){const n=c(o,t),r=x(e,n);if(r===null||r==="sealed")return{root:r,returns:d};if("root"in r)return{root:r.root,returns:t};if(!(u&&r.loop.find(i=>!t.has(i)&&g(i,n,u,t))))return{root:null,returns:d}}}f(m,"showingWalk");function g(e,o,u,t){const n=u(e);return n===void 0||n===o(e)?.parentUUID?!1:(t.set(e,n),!0)}f(g,"returnTo");function x(e,o){if(e.status!=="active"||D(e))return null;if(h(e.type))return{root:w};const u=o(e.uuid);if(u?.root)return u.available?{root:u}:null;const t=[e.uuid],n=new Map([[e.uuid,0]]);for(let r=e.parentUUID;r!==null;){const a=n.get(r);if(a!==void 0)return{loop:t.slice(Math.max(a,1))};n.set(r,t.length),t.push(r);const i=o(r);if(!i||!i.available||!p.has(i.type))return null;if(i.sealed===!0)return"sealed";if(i.root)return{root:i};r=i.parentUUID}return null}f(x,"walkUp");export{A as APPLY_PLAYS,M as judgeShowing,N as lineReturns,v as placedInRoot,c as returnedPlaces,y as shownUnits};
1
+ var U=Object.defineProperty;var s=(e,r)=>U(e,"name",{value:r,configurable:!0});import{CONTAINERS as l,isConstructType as h}from"../entities/types.js";import{fileAbsent as D}from"../git/checkout.js";import{unitOf as I}from"../entities/units.js";import{placedAtHome as b}from"../registration/home-layout.js";const A=new Set(["apply","enter","leave"]),v={onDemand:!1};function M(e,r,u,o){const n=r(e.uuid);if(n!==void 0&&!n.available)return"unseen";const i=n!==void 0,{root:t,returns:f}=m(e,r,u,o);if(t==="sealed")return"neither";if(t==="unseen")return i?"leave":"unseen";if(t===null)return i?"leave":"neither";if(!i&&t.onDemand){const a=w(p=>p===e.uuid?e:void 0,d(r,f));if(I(e.uuid,a)===e.uuid&&!y(e.uuid,a))return"listed"}return i&&(l.has(n.type)||!l.has(e.type))?"apply":"enter"}s(M,"judgeShowing");function w(e,r){return u=>{const o=e(u);if(o?.parentUUID===null)return{...o,home:r(u)?.home===!0};if(o)return o;const n=r(u);return n?.root?{type:n.type,name:n.name,parentUUID:null,home:n.home}:n}}s(w,"shownUnits");function y(e,r,u=new Map){const o=r(e);if(o?.parentUUID===null)return!0;const n=new Set;let i=null;for(let t=e,f=o;f?.parentUUID!=null&&!n.has(t);){const a=u.get(t);if(a!==void 0){i=a;break}n.add(t);const p=r(f.parentUUID);if(p?.parentUUID===null){i={uuid:t,home:p.home===!0};break}t=f.parentUUID,f=p}for(const t of n)u.set(t,i);return i===null?!1:i.home&&b(r(i.uuid).name,i.uuid!==e)}s(y,"placedInRoot");function N(e,r,u,o){return m(e,r,u,o).returns}s(N,"lineReturns");function d(e,r){return r.size===0?e:u=>{const o=e(u),n=r.get(u);return o!==void 0&&n!==void 0?{...o,parentUUID:n}:o}}s(d,"returnedPlaces");const c=new Map;function m(e,r,u,o){const n=new Map;for(;;){const i=d(r,n),t=x(e,i,o);if(t===null||t==="sealed"||t==="unseen")return{root:t,returns:c};if("root"in t)return{root:t.root,returns:n};if(!(u&&t.loop.find(a=>!n.has(a)&&g(a,i,u,n))))return{root:null,returns:c}}}s(m,"showingWalk");function g(e,r,u,o){const n=u(e);return n===void 0||n===r(e)?.parentUUID?!1:(o.set(e,n),!0)}s(g,"returnTo");function x(e,r,u){if(e.status!=="active"||D(e))return null;if(h(e.type))return{root:v};const o=r(e.uuid)??u?.(e.uuid);if(o?.root)return o.available?{root:o}:"unseen";const n=[e.uuid],i=new Map([[e.uuid,0]]);for(let t=e.parentUUID;t!==null;){const f=i.get(t);if(f!==void 0)return{loop:n.slice(Math.max(f,1))};i.set(t,n.length),n.push(t);const a=r(t);if(a?.available===!1)return"unseen";if(!a||!l.has(a.type))return null;if(a.sealed===!0)return"sealed";if(a.root)return{root:a};t=a.parentUUID}return null}s(x,"walkUp");export{A as APPLY_PLAYS,M as judgeShowing,N as lineReturns,y as placedInRoot,d as returnedPlaces,w as shownUnits};
@@ -1 +1 @@
1
- var M=Object.defineProperty;var a=(r,s)=>M(r,"name",{value:s,configurable:!0});import{collisionBases as k}from"../entities/rules.js";import{CONTAINERS as z,isConstructType as $}from"../entities/types.js";const D=4096;function E(r,s=D){const d=new Map;let p=0;for(const u of r){const{entityId:f}=u.record;let l=d.get(f);if(l===void 0){if(d.size===s)break;d.set(f,l={records:[],deliverySequence:u.deliverySequence,through:0})}const t=l.records.at(-1);if(t!==void 0&&t.change.turn===void 0!=(u.record.change.turn===void 0))break;if(t!==void 0&&u.record.globalSequence!==t.globalSequence+1)throw new Error(`entity ${f} has a gap before sequence ${u.record.globalSequence} inside its window`);l.records.push(u.record),l.through=p=u.deliverySequence}return Object.freeze({members:Object.freeze([...d].map(([u,{records:f,deliverySequence:l,through:t}])=>Object.freeze({entityId:u,records:Object.freeze(f),deliverySequence:l,through:t}))),through:p})}a(E,"foldWindow");function B(r,s,d,p=D){const u=new Map;for(let f=r;;){const l=E(f,p).members.map(o=>{const y=`${o.entityId}:${o.records.at(-1).globalSequence}`;let g=u.get(y);return g===void 0&&u.set(y,g=s(o)),{member:o,judgment:g.judgment,result:g.result}}),t=C(l,d);if(t===null)return l;f=f.slice(0,f.findIndex(o=>o.deliverySequence>=t))}}a(B,"readWindow");const W=a((r,s)=>r!==void 0&&(r.root?r.type!==s.type:r.parentUUID!==s.parentUUID||r.name!==s.name||r.type!==s.type),"movesPlace");function C(r,s){const d=new Set,p=new Set;let u=null;for(const{member:n,judgment:e,result:i}of r)e==="leave"?p.add(n.entityId):(e==="enter"||e==="apply"&&W(s(n.entityId),i))&&d.add(n.entityId),e==="enter"&&z.has(i.type)&&n.through<(u?.through??1/0)&&(u=n);if(d.size===0&&p.size===0)return null;const f=new Map(r.map(({member:n})=>[n.entityId,n.deliverySequence])),l=a((n,e)=>n===null?[]:[e,...k(e)].map(i=>`${n}/${i}`),"slotKeys"),t=a(({member:n,result:e})=>e.status==="active"&&!s(n.entityId)?.root?l(e.parentUUID,e.name):[],"goesTo"),o=a(n=>{const e=s(n.member.entityId);return[...e&&!e.root?l(e.parentUUID,e.name):[],...t(n)]},"slotsOf"),y=new Map,g=new Map,j=a((n,e,i)=>{for(const h of e){const c=n.get(h);c===void 0?n.set(h,[i]):c.length<2&&!c.includes(i)&&c.push(i)}},"note");for(const n of r){const{entityId:e}=n.member;d.has(e)&&j(g,t(n),e),(d.has(e)||p.has(e))&&j(y,o(n),e)}const v=a((n,e)=>{let i;for(const h of l(e.parentUUID,e.name)){const[c,w]=g.get(h)??[],I=c===n?w:c;I!==void 0&&(i===void 0||f.get(I)<f.get(i))&&(i=I)}return i},"pusher"),S=a((n,e,i)=>{const h=new Set([n]);for(let c=e;c!==null&&!h.has(c);){h.add(c);const w=s(c),I=i(c,w);if(I!==void 0)return I;c=w.parentUUID}return null},"climbs"),O=a(n=>{const{member:e,judgment:i,result:h}=n;if(i==="superseded"||i==="own"||i==="turn"||i==="waiting")return[];if($(h.type))return[];const c=[];for(const U of o(n)){const[m,x]=y.get(U)??[],q=m===e.entityId?x:m;q!==void 0&&c.push(q)}const w=s(e.entityId);if(w&&!w.root){const U=S(e.entityId,w.parentUUID,(m,x)=>d.has(m)?m:!x||x.root?null:v(e.entityId,x));U!==null&&c.push(U)}if(h.status!=="active"||w?.root)return c;const I=S(e.entityId,h.parentUUID,(U,m)=>d.has(U)||p.has(U)?U:m?!m.available||!z.has(m.type)||m.root?null:v(e.entityId,m):u!==null&&e.through>u.through?u.entityId:null);return I!==null&&c.push(I),c},"partnersOf");let b=null;for(const n of r){const e=n.member.deliverySequence;if(b!==null&&e>=b)break;for(const i of O(n)){const h=Math.max(e,f.get(i));(b===null||h<b)&&(b=h)}}return b}a(C,"windowCut");function P(r,s){return r.intent!==null||r.unit!==null||s?.producer!=="apply"?null:r.members.slice(1).find(p=>s.entityIds.includes(p.work.entityId))?.deliverySequence??null}a(P,"windowEndForWait");function A(r){const s=new Map(r.map((t,o)=>[t.entityId,{member:t,index:o}])),d=new Map,p=new Set,u=a((t,o)=>{const y=d.get(t);if(y!==void 0)return y;if(o.has(t)){for(const O of o)p.add(O);return-1}const g=s.get(t);if(!g||g.member.parentUUID===null)return 0;const j=s.get(g.member.parentUUID);if(!j)return d.set(t,0),0;o.add(t);const v=u(j.member.entityId,o);o.delete(t);const S=v<0?-1:v+1;return S>=0&&d.set(t,S),S},"depthOf"),f=[],l=[];for(const[t,o]of r.entries()){const y=u(o.entityId,new Set);if(y<0){p.add(o.entityId);continue}(o.play==="leave"?l:f).push({id:o.entityId,depth:y,index:t})}return f.sort((t,o)=>t.depth-o.depth||t.index-o.index),l.sort((t,o)=>o.depth-t.depth||t.index-o.index),Object.freeze({order:Object.freeze([...f,...l].map(({id:t})=>t)),cycle:Object.freeze([...p])})}a(A,"revealOrder");function F(r,s){let d=0;for(;d<r.length&&s(r[d]);)d+=1;return r.slice(0,d)}a(F,"resolvedPrefix");export{D as WINDOW_MEMBERS,E as foldWindow,B as readWindow,F as resolvedPrefix,A as revealOrder,P as windowEndForWait};
1
+ var M=Object.defineProperty;var a=(r,s)=>M(r,"name",{value:s,configurable:!0});import{collisionBases as k}from"../entities/rules.js";import{CONTAINERS as z,isConstructType as $}from"../entities/types.js";const D=4096;function E(r,s=D){const d=new Map;let p=0;for(const u of r){const{entityId:f}=u.record;let l=d.get(f);if(l===void 0){if(d.size===s)break;d.set(f,l={records:[],deliverySequence:u.deliverySequence,through:0})}const t=l.records.at(-1);if(t!==void 0&&t.change.turn===void 0!=(u.record.change.turn===void 0))break;if(t!==void 0&&u.record.globalSequence!==t.globalSequence+1)throw new Error(`entity ${f} has a gap before sequence ${u.record.globalSequence} inside its window`);l.records.push(u.record),l.through=p=u.deliverySequence}return Object.freeze({members:Object.freeze([...d].map(([u,{records:f,deliverySequence:l,through:t}])=>Object.freeze({entityId:u,records:Object.freeze(f),deliverySequence:l,through:t}))),through:p})}a(E,"foldWindow");function B(r,s,d,p=D){const u=new Map;for(let f=r;;){const l=E(f,p).members.map(o=>{const y=`${o.entityId}:${o.records.at(-1).globalSequence}`;let g=u.get(y);return g===void 0&&u.set(y,g=s(o)),{member:o,judgment:g.judgment,result:g.result}}),t=C(l,d);if(t===null)return l;f=f.slice(0,f.findIndex(o=>o.deliverySequence>=t))}}a(B,"readWindow");const W=a((r,s)=>r!==void 0&&(r.root?r.type!==s.type:r.parentUUID!==s.parentUUID||r.name!==s.name||r.type!==s.type),"movesPlace");function C(r,s){const d=new Set,p=new Set;let u=null;for(const{member:n,judgment:e,result:i}of r)e==="leave"?p.add(n.entityId):(e==="enter"||e==="apply"&&W(s(n.entityId),i))&&d.add(n.entityId),e==="enter"&&z.has(i.type)&&n.through<(u?.through??1/0)&&(u=n);if(d.size===0&&p.size===0)return null;const f=new Map(r.map(({member:n})=>[n.entityId,n.deliverySequence])),l=a((n,e)=>n===null?[]:[e,...k(e)].map(i=>`${n}/${i}`),"slotKeys"),t=a(({member:n,result:e})=>e.status==="active"&&!s(n.entityId)?.root?l(e.parentUUID,e.name):[],"goesTo"),o=a(n=>{const e=s(n.member.entityId);return[...e&&!e.root?l(e.parentUUID,e.name):[],...t(n)]},"slotsOf"),y=new Map,g=new Map,j=a((n,e,i)=>{for(const h of e){const c=n.get(h);c===void 0?n.set(h,[i]):c.length<2&&!c.includes(i)&&c.push(i)}},"note");for(const n of r){const{entityId:e}=n.member;d.has(e)&&j(g,t(n),e),(d.has(e)||p.has(e))&&j(y,o(n),e)}const v=a((n,e)=>{let i;for(const h of l(e.parentUUID,e.name)){const[c,w]=g.get(h)??[],I=c===n?w:c;I!==void 0&&(i===void 0||f.get(I)<f.get(i))&&(i=I)}return i},"pusher"),S=a((n,e,i)=>{const h=new Set([n]);for(let c=e;c!==null&&!h.has(c);){h.add(c);const w=s(c),I=i(c,w);if(I!==void 0)return I;c=w.parentUUID}return null},"climbs"),O=a(n=>{const{member:e,judgment:i,result:h}=n;if(i==="superseded"||i==="own"||i==="unseen"||i==="turn"||i==="waiting")return[];if($(h.type))return[];const c=[];for(const U of o(n)){const[m,x]=y.get(U)??[],q=m===e.entityId?x:m;q!==void 0&&c.push(q)}const w=s(e.entityId);if(w&&!w.root){const U=S(e.entityId,w.parentUUID,(m,x)=>d.has(m)?m:!x||x.root?null:v(e.entityId,x));U!==null&&c.push(U)}if(h.status!=="active"||w?.root)return c;const I=S(e.entityId,h.parentUUID,(U,m)=>d.has(U)||p.has(U)?U:m?!m.available||!z.has(m.type)||m.root?null:v(e.entityId,m):u!==null&&e.through>u.through?u.entityId:null);return I!==null&&c.push(I),c},"partnersOf");let b=null;for(const n of r){const e=n.member.deliverySequence;if(b!==null&&e>=b)break;for(const i of O(n)){const h=Math.max(e,f.get(i));(b===null||h<b)&&(b=h)}}return b}a(C,"windowCut");function P(r,s){return r.intent!==null||r.unit!==null||s?.producer!=="apply"?null:r.members.slice(1).find(p=>s.entityIds.includes(p.work.entityId))?.deliverySequence??null}a(P,"windowEndForWait");function A(r){const s=new Map(r.map((t,o)=>[t.entityId,{member:t,index:o}])),d=new Map,p=new Set,u=a((t,o)=>{const y=d.get(t);if(y!==void 0)return y;if(o.has(t)){for(const O of o)p.add(O);return-1}const g=s.get(t);if(!g||g.member.parentUUID===null)return 0;const j=s.get(g.member.parentUUID);if(!j)return d.set(t,0),0;o.add(t);const v=u(j.member.entityId,o);o.delete(t);const S=v<0?-1:v+1;return S>=0&&d.set(t,S),S},"depthOf"),f=[],l=[];for(const[t,o]of r.entries()){const y=u(o.entityId,new Set);if(y<0){p.add(o.entityId);continue}(o.play==="leave"?l:f).push({id:o.entityId,depth:y,index:t})}return f.sort((t,o)=>t.depth-o.depth||t.index-o.index),l.sort((t,o)=>o.depth-t.depth||t.index-o.index),Object.freeze({order:Object.freeze([...f,...l].map(({id:t})=>t)),cycle:Object.freeze([...p])})}a(A,"revealOrder");function F(r,s){let d=0;for(;d<r.length&&s(r[d]);)d+=1;return r.slice(0,d)}a(F,"resolvedPrefix");export{D as WINDOW_MEMBERS,E as foldWindow,B as readWindow,F as resolvedPrefix,A as revealOrder,P as windowEndForWait};
@@ -1 +1 @@
1
- var P=Object.defineProperty;var n=(t,r)=>P(t,"name",{value:r,configurable:!0});import{canonicalVersion as u,fileAbsent as l,validPortableFileMode as p,validPortableMtime as b}from"../entities/rules.js";import{CONTAINERS as w}from"../entities/types.js";const k=n(t=>w.has(t)?t:"file","contentKind");function h(t,r,i,f){const{facets:c,result:e}=r;if(r.joins!==void 0)return t!==null&&t.status!=="deleted"&&t.version===r.joins?{row:e,setsPayload:!0}:{row:t,setsPayload:!1};const d=f===void 0?e.parentUUID:f.keeps;if(t===null||c.includes("create")){if(t?.status==="deleted")return{row:t,setsPayload:!1};if(d===e.parentUUID)return{row:e,setsPayload:!0};const o={...e,parentUUID:d};return{row:{...o,version:u(o,i)},setsPayload:!0}}if(t.status==="deleted")return{row:t,setsPayload:!1};let a=t,m=!1;const s=n(o=>{a={...a,...o}},"set"),y=n(()=>{s({type:e.type,fileMode:l(e)||!p(e.type,a.fileMode)?e.fileMode:a.fileMode,mtime:l(e)||!b(e.type,a.mtime)?e.mtime:a.mtime,payloadVersion:e.payloadVersion,size:e.size,linkTarget:e.linkTarget,gitHomeEntity:e.gitHomeEntity,gitHomePath:e.gitHomePath,transportVersion:e.transportVersion}),m=!0},"becomes");for(const o of c)switch(o){case"move":s({parentUUID:d});break;case"rename":s({name:e.name});break;case"retype":y();break;case"content":k(a.type)===k(e.type)&&y();break;case"mode":!l(a)&&p(a.type,e.fileMode)&&s({fileMode:e.fileMode});break;case"time":!l(a)&&b(a.type,e.mtime)&&s({mtime:e.mtime});break;case"trash":s({status:"trashed"});break;case"restore":a.status==="trashed"&&s({status:"active"});break;case"delete":s({status:"deleted"});break;case"create":break}return a===t?{row:t,setsPayload:!1}:U(a,e)?{row:e,setsPayload:m}:{row:{...a,version:u(a,i)},setsPayload:m}}n(h,"playChange");const M=["uuid","type","parentUUID","name","status","payloadVersion","fileMode","mtime","size","linkTarget","gitHomeEntity","gitHomePath","transportVersion"],U=n((t,r)=>M.every(i=>t[i]===r[i]),"sameFields");export{k as contentKind,h as playChange};
1
+ var P=Object.defineProperty;var n=(t,r)=>P(t,"name",{value:r,configurable:!0});import{canonicalVersion as p,validPortableFileMode as u,validPortableMtime as b}from"../entities/rules.js";import{fileAbsent as l}from"../git/checkout.js";import{CONTAINERS as w}from"../entities/types.js";const k=n(t=>w.has(t)?t:"file","contentKind");function D(t,r,i,f){const{facets:c,result:e}=r;if(r.joins!==void 0)return t!==null&&t.status!=="deleted"&&t.version===r.joins?{row:e,setsPayload:!0}:{row:t,setsPayload:!1};const d=f===void 0?e.parentUUID:f.keeps;if(t===null||c.includes("create")){if(t?.status==="deleted")return{row:t,setsPayload:!1};if(d===e.parentUUID)return{row:e,setsPayload:!0};const o={...e,parentUUID:d};return{row:{...o,version:p(o,i)},setsPayload:!0}}if(t.status==="deleted")return{row:t,setsPayload:!1};let a=t,m=!1;const s=n(o=>{a={...a,...o}},"set"),y=n(()=>{s({type:e.type,fileMode:l(e)||!u(e.type,a.fileMode)?e.fileMode:a.fileMode,mtime:l(e)||!b(e.type,a.mtime)?e.mtime:a.mtime,payloadVersion:e.payloadVersion,size:e.size,linkTarget:e.linkTarget,gitHomeEntity:e.gitHomeEntity,gitHomePath:e.gitHomePath,transportVersion:e.transportVersion}),m=!0},"becomes");for(const o of c)switch(o){case"move":s({parentUUID:d});break;case"rename":s({name:e.name});break;case"retype":y();break;case"content":k(a.type)===k(e.type)&&y();break;case"mode":!l(a)&&u(a.type,e.fileMode)&&s({fileMode:e.fileMode});break;case"time":!l(a)&&b(a.type,e.mtime)&&s({mtime:e.mtime});break;case"trash":s({status:"trashed"});break;case"restore":a.status==="trashed"&&s({status:"active"});break;case"delete":s({status:"deleted"});break;case"create":break}return a===t?{row:t,setsPayload:!1}:U(a,e)?{row:e,setsPayload:m}:{row:{...a,version:p(a,i)},setsPayload:m}}n(D,"playChange");const M=["uuid","type","parentUUID","name","status","payloadVersion","fileMode","mtime","size","linkTarget","gitHomeEntity","gitHomePath","transportVersion"],U=n((t,r)=>M.every(i=>t[i]===r[i]),"sameFields");export{k as contentKind,D as playChange};
@@ -3,7 +3,7 @@ import { type ConstructType, type EntityStatus } from '../entities/types.js';
3
3
  import { type ContentIndex, type ContentManifest } from '../contracts/content.js';
4
4
  import type { GraphPageRef } from '../entities/graph-pages.js';
5
5
  import { type TransferArtifact } from '../transfer/artifacts.js';
6
- export declare const CHANGE_PROPOSAL_CONTRACT = "amalgm.detected-change-proposal@7";
6
+ export declare const CHANGE_PROPOSAL_CONTRACT = "amalgm.detected-change-proposal@9";
7
7
  export type ChangeOrigin = 'detected' | 'intentional';
8
8
  export type ChangeFacet = 'create' | 'rename' | 'move' | 'retype' | 'content' | 'mode' | 'time' | 'trash' | 'restore' | 'delete';
9
9
  export interface StructureReplay {
@@ -1 +1 @@
1
- var E=Object.defineProperty;var r=(t,e)=>E(t,"name",{value:e,configurable:!0});import{assertRecord as i}from"../entities/cloud.js";import{CONSTRUCT_TYPES as s,DERIVED_PAYLOAD as p}from"../entities/types.js";import{fileAbsent as u}from"../entities/rules.js";import{checkContentIndex as k,checkContentManifest as V}from"../contracts/content.js";import{artifactForRecord as v,artifactKindForType as P,pageArtifact as z}from"../transfer/artifacts.js";const d="amalgm.detected-change-proposal@7",c=/^[0-9a-f]{64}$/;function h(t,e){if(e.kind==="structure")return[];const n=v(t);if(e.kind==="package")return[...n===null?[]:[n],...e.pages.map(o=>z(t,o))];if(n===null)throw new Error(`${t.type} replay has no transferable artifact`);return[n]}r(h,"changeCargo");function A(t){if(t.replay.kind!=="package")return{replay:t.replay,cargo:t.cargo};const{result:e}=t;return e.type!=="repo.git"?{replay:{kind:"structure"},cargo:[]}:{replay:{kind:"repo.git",resultPayloadVersion:e.payloadVersion,transportVersion:e.transportVersion},cargo:t.cargo.slice(0,1)}}r(A,"ownChange");function x(t){return t!==null&&c.test(t)?t:null}r(x,"textReplayBase");const y=r((t,e)=>{if(t===null)return["create"];const n=[];t.parentUUID!==e.parentUUID&&n.push("move"),t.name!==e.name&&n.push("rename"),t.type!==e.type&&n.push("retype");const o=!p.has(e.type)&&e.type!=="reference";return(t.payloadVersion!==e.payloadVersion||u(t)!==u(e))&&o&&n.push("content"),t.fileMode!==e.fileMode&&e.fileMode!==null&&n.push("mode"),t.mtime!==e.mtime&&e.mtime!==null&&n.push("time"),t.status!==e.status&&(e.status==="deleted"?n.push("delete"):e.status==="trashed"?n.push("trash"):t.status==="trashed"&&e.status==="active"&&n.push("restore")),n},"changeFacets"),O=r((t,e,n)=>e.status==="active"&&(t===null||n.includes("content")||n.includes("retype"))&&P(e.type)!==null&&!((e.type==="file.text"||e.type==="file.binary")&&e.payloadVersion===null),"contentRequired"),w=r((t,e)=>{if(!(t.kind==="file.binary"?k(t.manifest,e.payloadVersion):V(t.manifest,e.payloadVersion)).ok||t.resultPayloadVersion!==e.payloadVersion)throw new Error(`${t.kind} replay does not name its complete result manifest`)},"validateManifestReplay");function j(t,e){if(Object.keys(t).length!==3||t.resultPayloadVersion!==e.payloadVersion||t.transportVersion!==e.transportVersion||!c.test(t.resultPayloadVersion)||!c.test(t.transportVersion))throw new Error("repository replay does not name the detected state and transport")}r(j,"assertRepositoryReplay");const m=r((t,e,n,o)=>{if(o.kind==="package")throw new Error("a package is proposed only by packageProposal");if(!O(t,e,n)){if(o.kind!=="structure")throw new Error("a structural-only change must use structure replay");return}if(o.kind!==e.type)throw new Error(`${e.type} content cannot use ${o.kind} replay`);if(e.payloadVersion===null)throw new Error(`${e.type} content has no result payload version`);switch(o.kind){case"file.text":const l=x(t?.payloadVersion??null);if((o.mode==="delta"||o.basePayloadVersion!==null)&&o.basePayloadVersion!==l||o.resultPayloadVersion!==e.payloadVersion||o.mode==="delta"!=(o.delta!==null))throw new Error("text replay does not name the detected base and result");if(!c.test(o.resultPayloadVersion)||o.basePayloadVersion!==null&&!c.test(o.basePayloadVersion))throw new Error("text replay has an invalid content head");if(o.delta!==null&&(!Number.isSafeInteger(o.delta.offset)||o.delta.offset<0||!Number.isSafeInteger(o.delta.deleteBytes)||o.delta.deleteBytes<0||!(o.delta.insert instanceof Uint8Array)))throw new Error("text replay has an invalid byte splice");if(o.delta!==null&&t!==null&&t.size!==null&&(o.delta.offset+o.delta.deleteBytes>t.size||e.size!==t.size-o.delta.deleteBytes+o.delta.insert.length))throw new Error("text replay splice does not hold its base and result sizes");break;case"file.binary":if(w(o,e),o.manifest.bytes!==e.size)throw new Error("binary replay manifest does not hold its result size");break;case"agent":case"automation":case"app":case"tool":case"secret":w(o,e);break;case"link":if(Object.keys(o).length!==2||o.resultPayloadVersion!==e.payloadVersion||!c.test(o.resultPayloadVersion))throw new Error("link replay does not name the detected result");break;case"repo.git":j(o,e);break}},"validateReplay"),f=r((t,e,n,o,a)=>{if(e!==null&&e.uuid!==n.uuid)throw new Error("a transition cannot change entity UUID");if(e===null&&n.status!=="active")throw new Error("a new entity must begin active");if(e?.status==="deleted")throw new Error("a change cannot resurrect a deleted tombstone");if(e?.version===n.version){if(!(e.type===n.type&&e.parentUUID===n.parentUUID&&e.name===n.name&&e.status===n.status&&e.payloadVersion===n.payloadVersion&&e.fileMode===n.fileMode&&e.mtime===n.mtime&&e.size===n.size&&e.linkTarget===n.linkTarget&&e.gitHomeEntity===n.gitHomeEntity&&e.gitHomePath===n.gitHomePath))throw new Error("one logical version cannot name two different entity states");return null}const l=y(e,n);if(l.length===0){if(e!==null&&p.has(e.type)&&e.type===n.type)return null;throw new Error("records disagree without a named logical facet")}if(e!==null&&e.payloadVersion===n.payloadVersion&&(e.size!==null&&n.size!==null&&e.size!==n.size||e.linkTarget!==null&&n.linkTarget!==null&&e.linkTarget!==n.linkTarget))throw new Error("one payload head cannot name two sizes or link targets");a(l),m(e,n,l,o);const g=h(n,o);return Object.freeze({contract:d,origin:t,entityId:n.uuid,basedOnState:e?.version??null,result:n,facets:Object.freeze(l),replay:o,cargo:Object.freeze(g)})},"changeProposal");function R(t){const e=i(t.row);if(e.type!=="repo.git")throw new Error("only a repository has a Git turn");const n=Object.freeze({kind:"structure"});return Object.freeze({contract:d,origin:"detected",entityId:e.uuid,basedOnState:e.version,result:e,facets:Object.freeze([]),replay:n,cargo:Object.freeze([]),turn:Object.freeze({...t.turn})})}r(R,"turnProposal");function H(t){const e=i(t.joins),n=i(t.result);if(e.uuid!==n.uuid)throw new Error("an echo cannot change entity UUID");if(s.has(n.type))throw new Error("a construct is never played, so never echoed");if(e.version===n.version)return null;const o=y(e,n);if(o.length===0||o.some(a=>!C.has(a)))throw new Error("an echo states a played payload or address, never a lifecycle or a type");return m(e,n,o,t.replay),Object.freeze({contract:d,origin:"detected",entityId:n.uuid,basedOnState:e.version,result:n,facets:Object.freeze([]),replay:t.replay,cargo:Object.freeze(h(n,t.replay)),joins:e.version})}r(H,"echoProposal");const C=new Set(["content","mode","time","rename","move"]);function M(t){const e=i(t.result),n=t.base===null?null:i(t.base);if(s.has(e.type)||n!==null&&s.has(n.type))throw new Error(`Detection cannot propose a ${e.type}; constructs bypass Detect`);if(e.status==="deleted")throw new Error("Detection cannot propose permanent deletion; deletion is an explicit lifecycle operation");return f("detected",n,e,t.replay,o=>{if(o.includes("trash")&&t.lifecycleAuthorization!=="trash")throw new Error("Trash requires proved removal or explicit lifecycle authority");if(o.includes("restore")&&t.lifecycleAuthorization!=="restore")throw new Error("restoring an entity requires explicit lifecycle authority")})}r(M,"detectedChangeProposal");function B(t){const e=i(t.result),n=t.base===null?null:i(t.base);if(!s.has(e.type))throw new Error(`an intentional change cannot propose a ${e.type}; files travel through Detect, and leave Trash for good only by permanentDeletionProposal`);return f("intentional",n,e,t.replay,()=>{})}r(B,"intentionalChangeProposal");function N(t){const e=i(t.result),n=i(t.base);if(s.has(n.type)||s.has(e.type))throw new Error(`a ${n.type} is deleted by its product through the intentional door`);if(t.effectiveStatus!=="trashed")throw new Error(`only Trash is deleted for good; ${n.uuid} is ${t.effectiveStatus}`);if(n.parentUUID===null)throw new Error(`${n.uuid} is a root; a root is not deleted for good`);if(e.status!=="deleted")throw new Error("a permanent deletion results in a deleted tombstone");const o=f("intentional",n,e,{kind:"structure"},a=>{if(a.length!==1||a[0]!=="delete")throw new Error(`a permanent deletion changes its status alone, not ${a.join(", ")}`)});if(o===null)throw new Error("a permanent deletion names a new version");return o}r(N,"permanentDeletionProposal");function _(t){return t.origin==="intentional"&&!s.has(t.result.type)&&t.result.status==="deleted"&&t.result.parentUUID!==null&&t.facets.length===1&&t.facets[0]==="delete"&&t.replay.kind==="structure"&&Object.keys(t.replay).length===1&&t.cargo.length===0}r(_,"isPermanentDeletionShape");export{d as CHANGE_PROPOSAL_CONTRACT,j as assertRepositoryReplay,h as changeCargo,y as changeFacets,M as detectedChangeProposal,H as echoProposal,B as intentionalChangeProposal,_ as isPermanentDeletionShape,A as ownChange,N as permanentDeletionProposal,x as textReplayBase,R as turnProposal};
1
+ var E=Object.defineProperty;var r=(t,e)=>E(t,"name",{value:e,configurable:!0});import{assertRecord as i}from"../entities/cloud.js";import{CONSTRUCT_TYPES as s,DERIVED_PAYLOAD as p}from"../entities/types.js";import{fileAbsent as u}from"../git/checkout.js";import{checkContentIndex as k,checkContentManifest as V}from"../contracts/content.js";import{artifactForRecord as v,artifactKindForType as P,pageArtifact as z}from"../transfer/artifacts.js";const d="amalgm.detected-change-proposal@9",c=/^[0-9a-f]{64}$/;function h(t,e){if(e.kind==="structure")return[];const n=v(t);if(e.kind==="package")return[...n===null?[]:[n],...e.pages.map(o=>z(t,o))];if(n===null)throw new Error(`${t.type} replay has no transferable artifact`);return[n]}r(h,"changeCargo");function R(t){if(t.replay.kind!=="package")return{replay:t.replay,cargo:t.cargo};const{result:e}=t;return e.type!=="repo.git"?{replay:{kind:"structure"},cargo:[]}:{replay:{kind:"repo.git",resultPayloadVersion:e.payloadVersion,transportVersion:e.transportVersion},cargo:t.cargo.slice(0,1)}}r(R,"ownChange");function x(t){return t!==null&&c.test(t)?t:null}r(x,"textReplayBase");const y=r((t,e)=>{if(t===null)return["create"];const n=[];t.parentUUID!==e.parentUUID&&n.push("move"),t.name!==e.name&&n.push("rename"),t.type!==e.type&&n.push("retype");const o=!p.has(e.type)&&e.type!=="reference";return(t.payloadVersion!==e.payloadVersion||u(t)!==u(e))&&o&&n.push("content"),t.fileMode!==e.fileMode&&e.fileMode!==null&&n.push("mode"),t.mtime!==e.mtime&&e.mtime!==null&&n.push("time"),t.status!==e.status&&(e.status==="deleted"?n.push("delete"):e.status==="trashed"?n.push("trash"):t.status==="trashed"&&e.status==="active"&&n.push("restore")),n},"changeFacets"),O=r((t,e,n)=>e.status==="active"&&(t===null||n.includes("content")||n.includes("retype"))&&P(e.type)!==null&&!((e.type==="file.text"||e.type==="file.binary")&&e.payloadVersion===null),"contentRequired"),w=r((t,e)=>{if(!(t.kind==="file.binary"?k(t.manifest,e.payloadVersion):V(t.manifest,e.payloadVersion)).ok||t.resultPayloadVersion!==e.payloadVersion)throw new Error(`${t.kind} replay does not name its complete result manifest`)},"validateManifestReplay");function j(t,e){if(Object.keys(t).length!==3||t.resultPayloadVersion!==e.payloadVersion||t.transportVersion!==e.transportVersion||!c.test(t.resultPayloadVersion)||!c.test(t.transportVersion))throw new Error("repository replay does not name the detected state and transport")}r(j,"assertRepositoryReplay");const m=r((t,e,n,o)=>{if(o.kind==="package")throw new Error("a package is proposed only by packageProposal");if(!O(t,e,n)){if(o.kind!=="structure")throw new Error("a structural-only change must use structure replay");return}if(o.kind!==e.type)throw new Error(`${e.type} content cannot use ${o.kind} replay`);if(e.payloadVersion===null)throw new Error(`${e.type} content has no result payload version`);switch(o.kind){case"file.text":const l=x(t?.payloadVersion??null);if((o.mode==="delta"||o.basePayloadVersion!==null)&&o.basePayloadVersion!==l||o.resultPayloadVersion!==e.payloadVersion||o.mode==="delta"!=(o.delta!==null))throw new Error("text replay does not name the detected base and result");if(!c.test(o.resultPayloadVersion)||o.basePayloadVersion!==null&&!c.test(o.basePayloadVersion))throw new Error("text replay has an invalid content head");if(o.delta!==null&&(!Number.isSafeInteger(o.delta.offset)||o.delta.offset<0||!Number.isSafeInteger(o.delta.deleteBytes)||o.delta.deleteBytes<0||!(o.delta.insert instanceof Uint8Array)))throw new Error("text replay has an invalid byte splice");if(o.delta!==null&&t!==null&&t.size!==null&&(o.delta.offset+o.delta.deleteBytes>t.size||e.size!==t.size-o.delta.deleteBytes+o.delta.insert.length))throw new Error("text replay splice does not hold its base and result sizes");break;case"file.binary":if(w(o,e),o.manifest.bytes!==e.size)throw new Error("binary replay manifest does not hold its result size");break;case"agent":case"automation":case"app":case"tool":case"secret":w(o,e);break;case"link":if(Object.keys(o).length!==2||o.resultPayloadVersion!==e.payloadVersion||!c.test(o.resultPayloadVersion))throw new Error("link replay does not name the detected result");break;case"repo.git":j(o,e);break}},"validateReplay"),f=r((t,e,n,o,a)=>{if(e!==null&&e.uuid!==n.uuid)throw new Error("a transition cannot change entity UUID");if(e===null&&n.status!=="active")throw new Error("a new entity must begin active");if(e?.status==="deleted")throw new Error("a change cannot resurrect a deleted tombstone");if(e?.version===n.version){if(!(e.type===n.type&&e.parentUUID===n.parentUUID&&e.name===n.name&&e.status===n.status&&e.payloadVersion===n.payloadVersion&&e.fileMode===n.fileMode&&e.mtime===n.mtime&&e.size===n.size&&e.linkTarget===n.linkTarget&&e.gitHomeEntity===n.gitHomeEntity&&e.gitHomePath===n.gitHomePath))throw new Error("one logical version cannot name two different entity states");return null}const l=y(e,n);if(l.length===0){if(e!==null&&p.has(e.type)&&e.type===n.type)return null;throw new Error("records disagree without a named logical facet")}if(e!==null&&e.payloadVersion===n.payloadVersion&&(e.size!==null&&n.size!==null&&e.size!==n.size||e.linkTarget!==null&&n.linkTarget!==null&&e.linkTarget!==n.linkTarget))throw new Error("one payload head cannot name two sizes or link targets");a(l),m(e,n,l,o);const g=h(n,o);return Object.freeze({contract:d,origin:t,entityId:n.uuid,basedOnState:e?.version??null,result:n,facets:Object.freeze(l),replay:o,cargo:Object.freeze(g)})},"changeProposal");function $(t){const e=i(t.row);if(e.type!=="repo.git")throw new Error("only a repository has a Git turn");const n=Object.freeze({kind:"structure"});return Object.freeze({contract:d,origin:"detected",entityId:e.uuid,basedOnState:e.version,result:e,facets:Object.freeze([]),replay:n,cargo:Object.freeze([]),turn:Object.freeze({...t.turn})})}r($,"turnProposal");function H(t){const e=i(t.joins),n=i(t.result);if(e.uuid!==n.uuid)throw new Error("an echo cannot change entity UUID");if(s.has(n.type))throw new Error("a construct is never played, so never echoed");if(e.version===n.version)return null;const o=y(e,n);if(o.length===0||o.some(a=>!C.has(a)))throw new Error("an echo states a played payload or address, never a lifecycle or a type");return m(e,n,o,t.replay),Object.freeze({contract:d,origin:"detected",entityId:n.uuid,basedOnState:e.version,result:n,facets:Object.freeze([]),replay:t.replay,cargo:Object.freeze(h(n,t.replay)),joins:e.version})}r(H,"echoProposal");const C=new Set(["content","mode","time","rename","move"]);function M(t){const e=i(t.result),n=t.base===null?null:i(t.base);if(s.has(e.type)||n!==null&&s.has(n.type))throw new Error(`Detection cannot propose a ${e.type}; constructs bypass Detect`);if(e.status==="deleted")throw new Error("Detection cannot propose permanent deletion; deletion is an explicit lifecycle operation");return f("detected",n,e,t.replay,o=>{if(o.includes("trash")&&t.lifecycleAuthorization!=="trash")throw new Error("Trash requires proved removal or explicit lifecycle authority");if(o.includes("restore")&&t.lifecycleAuthorization!=="restore")throw new Error("restoring an entity requires explicit lifecycle authority")})}r(M,"detectedChangeProposal");function B(t){const e=i(t.result),n=t.base===null?null:i(t.base);if(!s.has(e.type))throw new Error(`an intentional change cannot propose a ${e.type}; files travel through Detect, and leave Trash for good only by permanentDeletionProposal`);return f("intentional",n,e,t.replay,()=>{})}r(B,"intentionalChangeProposal");function N(t){const e=i(t.result),n=i(t.base);if(s.has(n.type)||s.has(e.type))throw new Error(`a ${n.type} is deleted by its product through the intentional door`);if(t.effectiveStatus!=="trashed")throw new Error(`only Trash is deleted for good; ${n.uuid} is ${t.effectiveStatus}`);if(e.status!=="deleted")throw new Error("a permanent deletion results in a deleted tombstone");const o=f("intentional",n,e,{kind:"structure"},a=>{if(a.length!==1||a[0]!=="delete")throw new Error(`a permanent deletion changes its status alone, not ${a.join(", ")}`)});if(o===null)throw new Error("a permanent deletion names a new version");return o}r(N,"permanentDeletionProposal");function _(t){return t.origin==="intentional"&&!s.has(t.result.type)&&t.result.status==="deleted"&&t.facets.length===1&&t.facets[0]==="delete"&&t.replay.kind==="structure"&&Object.keys(t.replay).length===1&&t.cargo.length===0}r(_,"isPermanentDeletionShape");export{d as CHANGE_PROPOSAL_CONTRACT,j as assertRepositoryReplay,h as changeCargo,y as changeFacets,M as detectedChangeProposal,H as echoProposal,B as intentionalChangeProposal,_ as isPermanentDeletionShape,R as ownChange,N as permanentDeletionProposal,x as textReplayBase,$ as turnProposal};
@@ -1 +1 @@
1
- var f=Object.defineProperty;var h=(a,s)=>f(a,"name",{value:s,configurable:!0});import{canonicalVersion as w,membershipHash as d}from"../entities/rules.js";import{eachStep as c}from"../steps.js";function*v(a,s,o){const r=new Map,i=new Map;yield*c(a,e=>{if(r.set(e.uuid,e),e.parentUUID===null||e.status!=="active")return;const t=i.get(e.parentUUID)??[];t.push(e),i.set(e.parentUUID,t)});const p=new Map;return yield*c(s,e=>{const t=r.get(e);if(!t)throw new Error(`removed entity ${e} is unknown`);if(t.parentUUID===null)throw new Error("missing workspace root cannot authorize Trash");if(t.status!=="active")return;let n=r.get(t.parentUUID);const l=new Set([e]);let u=!1;for(;n;){if(l.has(n.uuid))throw new Error("removed entity ancestry has a cycle");if(l.add(n.uuid),n.status!=="active"||s.has(n.uuid)){u=!0;break}n=n.parentUUID===null?void 0:r.get(n.parentUUID)}if(u)return;const U=t.type==="workspace"||t.type==="folder"?d(i.get(e)??[],o):t.payloadVersion;p.set(e,Object.freeze({...t,status:"trashed",version:w({...t,status:"trashed",payloadVersion:U},o)}))}),p}h(v,"trashRemovedEntitiesSteps");export{v as trashRemovedEntitiesSteps};
1
+ var h=Object.defineProperty;var U=(r,s)=>h(r,"name",{value:s,configurable:!0});import{canonicalVersion as d,membershipHash as w}from"../entities/rules.js";import{eachStep as c}from"../steps.js";function*D(r,s,o){const a=new Map,i=new Map;yield*c(r,e=>{if(a.set(e.uuid,e),e.parentUUID===null||e.status!=="active")return;const t=i.get(e.parentUUID)??[];t.push(e),i.set(e.parentUUID,t)});const p=new Map;return yield*c(s,e=>{const t=a.get(e);if(!t)throw new Error(`removed entity ${e} is unknown`);if(t.status!=="active")return;let n=t.parentUUID===null?void 0:a.get(t.parentUUID);const l=new Set([e]);let u=!1;for(;n;){if(l.has(n.uuid))throw new Error("removed entity ancestry has a cycle");if(l.add(n.uuid),n.status!=="active"||s.has(n.uuid)){u=!0;break}n=n.parentUUID===null?void 0:a.get(n.parentUUID)}if(u)return;const f=t.type==="workspace"||t.type==="folder"?w(i.get(e)??[],o):t.payloadVersion;p.set(e,Object.freeze({...t,status:"trashed",version:d({...t,status:"trashed",payloadVersion:f},o)}))}),p}U(D,"trashRemovedEntitiesSteps");export{D as trashRemovedEntitiesSteps};
@@ -1 +1 @@
1
- var U=Object.defineProperty;var l=(o,u)=>U(o,"name",{value:u,configurable:!0});import{isLocalOnlyPath as v}from"@amalgm/core/identity";import{FILES_FOLDER as W}from"../registration/home-layout.js";import{byteString as x,compileIgnoreLines as p}from"./ignore-lines.js";import{SHIPPED_INCLUDES as C,SKIP_DEFAULTS as H}from"./skip-defaults.js";function E(o){const u=String(o||"");return!u.startsWith("/")&&!u.startsWith("./")&&!u.endsWith("/")&&!u.includes("//")?u:u.replace(/^\.\//,"").replace(/^\/+|\/+$/g,"").replace(/\/{2,}/g,"/")}l(E,"normalizedRelativePath");const g=l(o=>o.slice(0,Math.max(0,o.lastIndexOf("/"))),"parentOf");function G(o){const u=new Set,k=new Set;for(const f of o){const c=E(f);u.add(c);for(let d=c;k.add(d),d!=="";d=g(d));}return{project(f){if(f==="")return null;for(let c=g(f);;c=g(c)){if(u.has(c))return c;if(c==="")return null}},holdsProject:l(f=>k.has(f),"holdsProject")}}l(G,"projectsAt");const b=p(H),F=p(C),N=new RegExp([F.screen,b.screen].filter(Boolean).join("|")||"(?!)","s");function J(o,u={}){const k=l(e=>u.home===!0&&(e===W||e.startsWith(`${W}/`))&&!v(e),"computers"),f=new Map,c=l(e=>{let n=f.get(e);if(n===void 0){const t=o.gitignore(e);f.set(e,n=t===null?null:p(t))}return n},"gitignoreAt"),d=l((e,n,t)=>{const i=x(e),s=F.verdict(i,n);if(s!==null)return s==="skip";if(t!==null)for(let r=g(e);;r=g(r)){const S=c(r);if(S!==null){const a=S.verdict(x(r===""?e:e.slice(r.length+1)),n);if(a!==null)return a==="skip"}if(r===t||r==="")break}return b.verdict(i,n)==="skip"},"skippedHere"),I=new Map,w=l((e,n)=>{const t=`${n??"\0"}\0${e}`;let i=I.get(t);return i===void 0&&I.set(t,i=d(e,!0,n)),i},"folderSkipped"),L=new Map,P=l((e,n)=>{if(e===n)return!1;const t=`${n}\0${e}`;let i=L.get(t);return i===void 0&&L.set(t,i=w(e,n)||P(g(e),n)),i},"skippedWithin"),O=l((e,n,t)=>{if(t===null&&!N.test(x(e)))return!1;for(let i=e.indexOf("/");i!==-1;i=e.indexOf("/",i+1)){const s=e.slice(0,i),r=t!==null&&(t===""||s.startsWith(`${t}/`))?t:null;if(w(s,r))return!0}return!M(e,n)&&d(e,n,t)},"judgedSkipped"),$=l(e=>{const n=new Map,t=l(s=>{let r=n.get(s);return r===void 0&&n.set(s,r=i(s,!0,e(s))),r},"folderTravels"),i=l((s,r,S)=>{if(!s||v(s))return!1;const a=o.project(s);if(a===null)return!O(s,r,null);if(o.tracks(a,s,r))return a===""||t(a);const m=g(s);if(m!==""&&!t(m))return!1;const D=!P(m,a)&&(M(s,r)||!d(s,r,a));return!r||!S?D:D||!O(s,r,null)},"decide");return(s,r)=>r&&s!==""?t(s):i(s,r,!1)},"verdicts"),A=$(o.holdsProject),R=l((e,n)=>{const t=E(e);return k(t)?n||!d(t,!1,null):A(t,n)},"travels"),T=$(()=>!0);return{travels:R,sealed:l(e=>{const n=E(e);return n!==""&&!v(n)&&!k(n)&&!T(n,!0)},"sealed")}}l(J,"createSkipPolicy");const M=l((o,u)=>!u&&o.slice(o.lastIndexOf("/")+1)===".gitignore","isIgnoreFile");export{J as createSkipPolicy,E as normalizedRelativePath,G as projectsAt};
1
+ var U=Object.defineProperty;var i=(l,o)=>U(l,"name",{value:o,configurable:!0});import{isLocalOnlyPath as m}from"@amalgm/core/identity";import{FILES_FOLDER as $}from"../registration/home-layout.js";import{byteString as v,compileIgnoreLines as x}from"./ignore-lines.js";import{SHIPPED_INCLUDES as C,SKIP_DEFAULTS as H}from"./skip-defaults.js";function E(l){const o=String(l||"");return!o.startsWith("/")&&!o.startsWith("./")&&!o.endsWith("/")&&!o.includes("//")?o:o.replace(/^\.\//,"").replace(/^\/+|\/+$/g,"").replace(/\/{2,}/g,"/")}i(E,"normalizedRelativePath");const g=i(l=>l.slice(0,Math.max(0,l.lastIndexOf("/"))),"parentOf");function G(l){const o=new Set,p=new Set;for(const f of l){const u=E(f);o.add(u);for(let d=u;p.add(d),d!=="";d=g(d));}return{project(f){if(f==="")return null;for(let u=g(f);;u=g(u)){if(o.has(u))return u;if(u==="")return null}},holdsProject:i(f=>p.has(f),"holdsProject")}}i(G,"projectsAt");const b=x(H),F=x(C),N=new RegExp([F.screen,b.screen].filter(Boolean).join("|")||"(?!)","s");function J(l,o={}){const p=i(e=>o.home===!0&&(e===$||e.startsWith(`${$}/`))&&!m(e),"computers"),f=new Map,u=i(e=>{let n=f.get(e);if(n===void 0){const t=l.gitignore(e);f.set(e,n=t===null?null:x(t))}return n},"gitignoreAt"),d=i((e,n,t)=>{const c=v(e),s=F.verdict(c,n);if(s!==null)return s==="skip";if(t!==null)for(let r=g(e);;r=g(r)){const k=u(r);if(k!==null){const a=k.verdict(v(r===""?e:e.slice(r.length+1)),n);if(a!==null)return a==="skip"}if(r===t||r==="")break}return b.verdict(c,n)==="skip"},"skippedHere"),I=new Map,j=i((e,n)=>{const t=`${n??"\0"}\0${e}`;let c=I.get(t);return c===void 0&&I.set(t,c=d(e,!0,n)),c},"folderSkipped"),w=new Map,L=i((e,n)=>{if(e===n)return!1;const t=`${n}\0${e}`;let c=w.get(t);return c===void 0&&w.set(t,c=j(e,n)||L(g(e),n)),c},"skippedWithin"),W=i((e,n)=>{if(!N.test(v(e)))return!1;for(let t=e.indexOf("/");t!==-1;t=e.indexOf("/",t+1))if(j(e.slice(0,t),null))return!0;return!M(e,n)&&d(e,n,null)},"shippedSkipped"),P=i(e=>{const n=new Map,t=i(s=>{let r=n.get(s);return r===void 0&&n.set(s,r=c(s,!0,e(s))),r},"folderTravels"),c=i((s,r,k)=>{if(!s||m(s))return!1;const a=l.project(s);if(a!==null&&l.tracks(a,s,r))return a===""||t(a);const S=g(s);if(S!==""&&!t(S))return!1;const O=a??"",D=!L(S,O)&&(M(s,r)||!d(s,r,O));return!r||!k?D:D||!W(s,r)},"decide");return(s,r)=>r&&s!==""?t(s):c(s,r,!1)},"verdicts"),A=P(l.holdsProject),R=i((e,n)=>{const t=E(e);return p(t)?n||!d(t,!1,null):A(t,n)},"travels"),T=P(()=>!0);return{travels:R,sealed:i(e=>{const n=E(e);return n!==""&&!m(n)&&!p(n)&&!T(n,!0)},"sealed")}}i(J,"createSkipPolicy");const M=i((l,o)=>!o&&l.slice(l.lastIndexOf("/")+1)===".gitignore","isIgnoreFile");export{J as createSkipPolicy,E as normalizedRelativePath,G as projectsAt};
@@ -1,7 +1,7 @@
1
1
  import type { DrivePorts, KeptOwner, Times, Unit } from './contracts.js';
2
2
  import { type Listing } from './listing.js';
3
3
  import { type Receipt } from './placements.js';
4
- import { type Look, type Where } from './where.js';
4
+ import { type DriveFile, type Look, type Where } from './where.js';
5
5
  export interface Looked {
6
6
  readonly look: Look;
7
7
  readonly placed: readonly Receipt[];
@@ -24,10 +24,11 @@ export declare class Drive {
24
24
  private readonly placements;
25
25
  constructor(ports: DrivePorts);
26
26
  where(path: readonly string[]): Promise<Where>;
27
+ pathOf(file: DriveFile): Promise<readonly string[] | null>;
27
28
  list(path: readonly string[]): Promise<Listing>;
28
29
  look(path: readonly string[]): Promise<Looked>;
29
- touch(path: readonly string[]): Promise<Touched>;
30
- change(path: readonly string[]): Promise<Touched | null>;
30
+ touch(path: readonly string[], file?: DriveFile): Promise<Touched>;
31
+ change(path: readonly string[], operation?: 'existing' | 'create'): Promise<Touched | null>;
31
32
  vacate(path: readonly string[]): Promise<Touched | 'not-empty' | null>;
32
33
  removable(path: readonly string[]): Promise<boolean>;
33
34
  remove(path: readonly string[], as: 'file' | 'directory'): Promise<Touched | Recorded | Refused | null>;
@@ -36,7 +37,7 @@ export declare class Drive {
36
37
  mode(path: readonly string[], mode: number): Promise<Touched | Recorded | Refused | null>;
37
38
  times(path: readonly string[], times: Times): Promise<Touched | Recorded | Refused | null>;
38
39
  keep(path: readonly string[], kept: KeptOwner): Promise<Touched | Recorded | Refused | null>;
39
- empty(path: readonly string[]): Promise<Touched | Refused | null>;
40
+ empty(path: readonly string[], file?: DriveFile): Promise<Touched | Refused | null>;
40
41
  private meets;
41
42
  private act;
42
43
  private again;
@@ -48,6 +49,7 @@ export declare class Drive {
48
49
  private movable;
49
50
  private destination;
50
51
  private settle;
52
+ private judgedFile;
51
53
  private judged;
52
54
  placing(): number;
53
55
  }
@@ -1 +1 @@
1
- var S=Object.defineProperty;var c=(o,t)=>S(o,"name",{value:t,configurable:!0});import{isRepositoryMetadataEntry as R}from"../detection/classify.js";import{isName as E,portableFileMode as A,portableMtime as I}from"../entities/rules.js";import{CONTAINERS as k}from"../entities/types.js";import{placedAtHome as C}from"../registration/home-layout.js";import{listing as D}from"./listing.js";import{Placements as F}from"./placements.js";import{CROSSES_ROOTS as T}from"./records.js";import{addressOnly as l,aloneInSlot as U,childAt as x,freeName as H,glance as b,outsideRepositories as v,rootOf as j,where as P}from"./where.js";class Q{static{c(this,"Drive")}ports;placements;constructor(t){this.ports=t,this.placements=new F(t)}where(t){return P(this.ports.roots,t)}list(t){return D(this.ports.roots,t)}async look(t){const r=await this.judged(t),n=b(r.at);if(n!==null)return{look:n,placed:[]};const{where:e,placed:i}=await this.settle(t,r),s=b(e);if(s!==null)return{look:s,placed:i};throw new Error("placed, yet the shelf does not stand here")}async touch(t){return this.settle(t,await this.judged(t))}async change(t){const r=await this.judged(t);return l(this.ports.roots,t,r.at)?null:(await this.freed(r.at),this.settle(t,r))}async vacate(t){const r=await this.judged(t);return l(this.ports.roots,t,r.at)?null:f(await this.list(t))?"not-empty":(await this.freed(r.at),this.settle(t,r))}async removable(t){return!l(this.ports.roots,t,await this.where(t))}async remove(t,r){const n=await this.judged(t);if(l(this.ports.roots,t,n.at))return null;const e=c(async()=>r==="file"||!f(await this.list(t)),"empty");return this.act(t,n,i=>this.refuses(t,r,i),i=>this.leavable(i),async i=>await e()&&this.ports.recorder.remove(i.unit),!0)}async refuses(t,r,n){const e=h(n);return e!==null?e:n.kind==="listed"&&n.entry.kind==="directory"!=(r==="directory")?r==="directory"?"not-directory":"directory":r==="directory"&&f(await this.list(t))?"not-empty":null}async move(t,r){const n=await this.judged(t);return l(this.ports.roots,t,n.at)||l(this.ports.roots,r,await this.where(r))?null:this.act(t,n,async e=>this.meets(e,r,await this.where(r)),e=>this.movable(e,r),async e=>(await this.ports.recorder.free({root:e.destination.root,address:e.destination.address}),this.ports.recorder.move(e.unit,e.destination)),!0)}async mode(t,r){const n=await this.judged(t);return l(this.ports.roots,t,n.at)?null:this.act(t,n,async e=>h(e),e=>this.modable(e,r),async e=>e.fileMode!==e.listed.mode&&!await this.ports.recorder.mode(e.unit,e.fileMode)?!1:(await this.ports.keeper.keep(e.unit,{mode:r&4095},{...e.listed,mode:e.fileMode}),!0),!1)}async times(t,r){const n=await this.judged(t);return l(this.ports.roots,t,n.at)?null:this.act(t,n,async e=>h(e),e=>this.keepable(e),async e=>{const i=r.mtimeNs===null?e.listed.mtime:I(e.listed.type,r.mtimeNs);return i!==e.listed.mtime&&!await this.ports.recorder.time(e.unit,i)?!1:(await this.ports.keeper.keep(e.unit,{atimeNs:r.atimeNs},{...e.listed,mtime:i}),!0)},!1)}async keep(t,r){const n=await this.judged(t);return l(this.ports.roots,t,n.at)?null:this.act(t,n,async e=>h(e),e=>this.keepable(e),async e=>(await this.ports.keeper.keep(e.unit,r,e.listed),!0),!1)}async empty(t){const r=await this.judged(t);if(l(this.ports.roots,t,r.at))return null;const n=h(r.at);return n!==null?{refused:n,placed:[]}:this.settle(t,r,async e=>(await this.keepable(e))?.unit.uuid??null)}async meets(t,r,n){const e=h(t)??M(n);if(e!==null)return e;if(t.kind!=="listed"||n.kind!=="listed"||t.entity.uuid===n.entity.uuid)return null;const i=t.entry.kind==="directory";return i!==(n.entry.kind==="directory")?i?"not-directory":"directory":i&&f(await this.list(r))?"not-empty":null}async act(t,r,n,e,i,s){const a=[];let d=!1;for(let u=r,w=!1;;u=await this.judged(t)){const y=await n(u.at);if(y!==null)return{refused:y,placed:a};const m="placing"in u.at?u.at.placing:[];if(w||m.length===0)return{where:u.at,placed:a};const p=d?null:await e(u.at);if(p!==null){const g=await this.placements.record(p.unit,()=>this.again(t,p,e,i),s);if(g===!0)return{recorded:p.unit,placed:a};d=g===!1;continue}const{receipts:N,complete:O}=await this.placements.place(m,u.seen);a.push(...N),w=O}}async again(t,r,n,e){const i=await n(await this.where(t));return i!==null&&i.unit.uuid===r.unit.uuid&&e(i)}async freed(t){"root"in t&&await this.ports.recorder.free({root:t.root,address:t.address})}async own(t){if(t.kind!=="listed")return null;const r=t.placing.at(-1);if(r?.uuid!==t.entity.uuid)return null;const n=await j(this.ports.roots,t.root);return n===null||!await v(n.map,t.address)?null:{unit:r,root:n,entity:t.entity}}async leavable(t){const r=await this.own(t);return r!==null&&await U(r.root.map,r.entity)?r:null}async keepable(t){const r=await this.own(t);if(r===null)return null;const{type:n,fileMode:e,mtime:i,payloadVersion:s,version:a}=r.entity;return e===null||i===null||s===null?null:{...r,listed:{type:n,mode:e,mtime:i,payloadVersion:s,version:a}}}async modable(t,r){const n=await this.keepable(t),e=n===null?null:A(n.entity.type,r);return n===null||e===null?null:{...n,fileMode:e}}async movable(t,r){const n=await this.leavable(t);if(n===null||k.has(n.unit.type))return null;const e=await this.destination(n,r);return e===null?null:{...n,destination:e}}async destination({unit:t,root:r},n){const e=n.at(-1);if(e===void 0||!E(e)||R(e))return null;const i=await this.where(n.slice(0,-1));if(i.kind!=="shelf"&&i.kind!=="listed"||i.root!==r.uuid&&!T.has(t.type))return null;const s=await j(this.ports.roots,i.root),a=i.entity;if(s===null||a===null||!k.has(a.type)||i.kind==="shelf"&&s.shelf.names(i.address)===null)return null;const d=[...i.address,e],u=i.address.length===0?e:(await x(s.map,s.map.root().uuid,i.address[0]))?.name;return u===void 0||!await H(s.map,a.uuid,e,t.uuid)||s.shelf.has(d)||!await v(s.map,i.address)||s.uuid===this.ports.roots.home.uuid&&C(u,d.length>1)||l(this.ports.roots,n,{root:s.uuid,address:d})?null:{root:s.uuid,parentUUID:a.uuid,name:e,address:d}}async settle(t,r,n=async()=>null){const e=[];for(let i=r;;){const s="placing"in i.at?i.at.placing:[];if(s.length===0)return{where:i.at,placed:e};const{receipts:a,complete:d}=await this.placements.place(s,i.seen,await n(i.at));if(e.push(...a),i=await this.judged(t),d)return{where:i.at,placed:e}}}async judged(t){const r=this.placements.recorded();return{at:await this.where(t),seen:r}}placing(){return this.placements.count()}}function h(o){return o.kind==="absent"?"nowhere":M(o)}c(h,"unnamed");function M(o){return o.kind==="nowhere"?"nowhere":o.kind==="notdir"?"not-directory":null}c(M,"noFolder");function f(o){return o.kind==="entries"&&o.entries.length>0}c(f,"shows");export{Q as Drive};
1
+ var F=Object.defineProperty;var c=(l,t)=>F(l,"name",{value:t,configurable:!0});import{isRepositoryMetadataEntry as S}from"../detection/classify.js";import{isName as R,portableFileMode as E,portableMtime as A}from"../entities/rules.js";import{CONTAINERS as k}from"../entities/types.js";import{placedAtHome as I}from"../registration/home-layout.js";import{listing as x}from"./listing.js";import{Placements as C}from"./placements.js";import{CROSSES_ROOTS as D}from"./records.js";import{addressOnly as d,aloneInSlot as T,childAt as U,freeName as H,glance as b,outsideRepositories as j,pathOfFile as P,rootOf as v,where as V}from"./where.js";class W{static{c(this,"Drive")}ports;placements;constructor(t){this.ports=t,this.placements=new C(t)}where(t){return V(this.ports.roots,t)}pathOf(t){return P(this.ports.roots,t)}list(t){return x(this.ports.roots,t)}async look(t){const r=await this.judged(t),n=b(r.at);if(n!==null)return{look:n,placed:[]};const{where:e,placed:i}=await this.settle(t,r),s=b(e);if(s!==null)return{look:s,placed:i};throw new Error("placed, yet the shelf does not stand here")}async touch(t,r){return this.settle(t,await this.judgedFile(t,r),void 0,r)}async change(t,r="existing"){const n=await this.judged(t);if(d(this.ports.roots,t,n.at))return null;if(await this.freed(n.at),r==="create"&&n.at.kind==="absent"){const e=await this.touch(t.slice(0,-1));if(e.where.kind!=="shelf")return e;const{root:i,address:s}=n.at;return e.where.root!==i||e.where.address.length+1!==s.length||!e.where.address.every((a,u)=>a===s[u])?{where:{kind:"nowhere"},placed:e.placed}:{where:{kind:"shelf",root:i,address:s,entity:null},placed:e.placed}}return this.settle(t,n)}async vacate(t){const r=await this.judged(t);return d(this.ports.roots,t,r.at)?null:f(await this.list(t))?"not-empty":(await this.freed(r.at),this.settle(t,r))}async removable(t){return!d(this.ports.roots,t,await this.where(t))}async remove(t,r){const n=await this.judged(t);if(d(this.ports.roots,t,n.at))return null;const e=c(async()=>r==="file"||!f(await this.list(t)),"empty");return this.act(t,n,i=>this.refuses(t,r,i),i=>this.leavable(i),async i=>await e()&&this.ports.recorder.remove(i.unit),!0)}async refuses(t,r,n){const e=h(n);return e!==null?e:n.kind==="listed"&&n.entry.kind==="directory"!=(r==="directory")?r==="directory"?"not-directory":"directory":r==="directory"&&f(await this.list(t))?"not-empty":null}async move(t,r){const n=await this.judged(t);return d(this.ports.roots,t,n.at)||d(this.ports.roots,r,await this.where(r))?null:this.act(t,n,async e=>this.meets(e,r,await this.where(r)),e=>this.movable(e,r),async e=>(await this.ports.recorder.free({root:e.destination.root,address:e.destination.address}),this.ports.recorder.move(e.unit,e.destination)),!0)}async mode(t,r){const n=await this.judged(t);return d(this.ports.roots,t,n.at)?null:this.act(t,n,async e=>h(e),e=>this.modable(e,r),async e=>e.fileMode!==e.listed.mode&&!await this.ports.recorder.mode(e.unit,e.fileMode)?!1:(await this.ports.keeper.keep(e.unit,{mode:r&4095},{...e.listed,mode:e.fileMode}),!0),!1)}async times(t,r){const n=await this.judged(t);return d(this.ports.roots,t,n.at)?null:this.act(t,n,async e=>h(e),e=>this.keepable(e),async e=>{const i=r.mtimeNs===null?e.listed.mtime:A(e.listed.type,r.mtimeNs);return i!==e.listed.mtime&&!await this.ports.recorder.time(e.unit,i)?!1:(await this.ports.keeper.keep(e.unit,{atimeNs:r.atimeNs},{...e.listed,mtime:i}),!0)},!1)}async keep(t,r){const n=await this.judged(t);return d(this.ports.roots,t,n.at)?null:this.act(t,n,async e=>h(e),e=>this.keepable(e),async e=>(await this.ports.keeper.keep(e.unit,r,e.listed),!0),!1)}async empty(t,r){const n=await this.judgedFile(t,r);if(d(this.ports.roots,t,n.at))return null;const e=h(n.at);return e!==null?{refused:e,placed:[]}:this.settle(t,n,async i=>(await this.keepable(i))?.unit.uuid??null,r)}async meets(t,r,n){const e=h(t)??O(n);if(e!==null)return e;if(t.kind!=="listed"||n.kind!=="listed"||t.entity.uuid===n.entity.uuid)return null;const i=t.entry.kind==="directory";return i!==(n.entry.kind==="directory")?i?"not-directory":"directory":i&&f(await this.list(r))?"not-empty":null}async act(t,r,n,e,i,s){const a=[];let u=!1;for(let o=r,p=!1;;o=await this.judged(t)){const y=await n(o.at);if(y!==null)return{refused:y,placed:a};const m="placing"in o.at?o.at.placing:[];if(p||m.length===0)return{where:o.at,placed:a};const w=u?null:await e(o.at);if(w!==null){const g=await this.placements.record(w.unit,()=>this.again(t,w,e,i),s);if(g===!0)return{recorded:w.unit,placed:a};u=g===!1;continue}const{receipts:M,complete:N}=await this.placements.place(m,o.seen);a.push(...M),p=N}}async again(t,r,n,e){const i=await n(await this.where(t));return i!==null&&i.unit.uuid===r.unit.uuid&&e(i)}async freed(t){"root"in t&&await this.ports.recorder.free({root:t.root,address:t.address})}async own(t){if(t.kind!=="listed")return null;const r=t.placing.at(-1);if(r?.uuid!==t.entity.uuid)return null;const n=await v(this.ports.roots,t.root);return n===null||!await j(n.map,t.address)?null:{unit:r,root:n,entity:t.entity}}async leavable(t){const r=await this.own(t);return r!==null&&await T(r.root.map,r.entity)?r:null}async keepable(t){const r=await this.own(t);if(r===null)return null;const{type:n,fileMode:e,mtime:i,payloadVersion:s,version:a}=r.entity;return e===null||i===null||s===null?null:{...r,listed:{type:n,mode:e,mtime:i,payloadVersion:s,version:a}}}async modable(t,r){const n=await this.keepable(t),e=n===null?null:E(n.entity.type,r);return n===null||e===null?null:{...n,fileMode:e}}async movable(t,r){const n=await this.leavable(t);if(n===null||k.has(n.unit.type))return null;const e=await this.destination(n,r);return e===null?null:{...n,destination:e}}async destination({unit:t,root:r},n){const e=n.at(-1);if(e===void 0||!R(e)||S(e))return null;const i=await this.where(n.slice(0,-1));if(i.kind!=="shelf"&&i.kind!=="listed"||i.root!==r.uuid&&!D.has(t.type))return null;const s=await v(this.ports.roots,i.root),a=i.entity;if(s===null||a===null||!k.has(a.type)||i.kind==="shelf"&&s.shelf.names(i.address)===null)return null;const u=[...i.address,e],o=i.address.length===0?e:(await U(s.map,s.map.root().uuid,i.address[0]))?.name;return o===void 0||!await H(s.map,a.uuid,e,t.uuid)||s.shelf.has(u)||!await j(s.map,i.address)||s.uuid===this.ports.roots.home.uuid&&I(o,u.length>1)||d(this.ports.roots,n,{root:s.uuid,address:u})?null:{root:s.uuid,parentUUID:a.uuid,name:e,address:u}}async settle(t,r,n=async()=>null,e){const i=[];for(let s=r;;){const a="placing"in s.at?s.at.placing:[];if(a.length===0)return{where:s.at,placed:i};const{receipts:u,complete:o}=await this.placements.place(a,s.seen,await n(s.at));if(i.push(...u),s=await this.judgedFile(t,e),o)return{where:s.at,placed:i}}}async judgedFile(t,r){const n=await this.judged(t);if(!r)return n;const e=c(s=>(s.kind==="listed"||s.kind==="shelf")&&s.root===r.root&&s.entity?.uuid===r.uuid,"matches");if(e(n.at))return n;const i=await this.pathOf(r);if(i){const s=await this.judged(i);if(e(s.at))return s}return{seen:n.seen,at:{kind:"nowhere"}}}async judged(t){const r=this.placements.recorded();return{at:await this.where(t),seen:r}}placing(){return this.placements.count()}}function h(l){return l.kind==="absent"?"nowhere":O(l)}c(h,"unnamed");function O(l){return l.kind==="nowhere"?"nowhere":l.kind==="notdir"?"not-directory":null}c(O,"noFolder");function f(l){return l.kind==="entries"&&l.entries.length>0}c(f,"shows");export{W as Drive};
@@ -1,21 +1,31 @@
1
1
  import type { CloudEntityRecord } from '../entities/cloud.js';
2
2
  import { type Sha256Hex } from '../entities/types.js';
3
- import type { MapEntity } from './contracts.js';
3
+ import type { GitSizes } from '../git/artifact.js';
4
+ import { type MapEntity } from './contracts.js';
4
5
  export declare class MapIndex {
5
6
  #private;
6
7
  constructor(rootUUID: string, sha256Hex: Sha256Hex);
7
8
  get rootUUID(): string;
8
9
  get size(): number;
9
10
  enter(parentUUID: string, children: Iterable<CloudEntityRecord>): boolean;
11
+ sizes(repositoryUUID: string, version: string, transportVersion: string, sizes: GitSizes | null): void;
12
+ sizesOwed(): {
13
+ readonly uuid: string;
14
+ readonly version: string;
15
+ readonly transportVersion: string;
16
+ }[];
10
17
  entered(uuid: string): boolean;
11
18
  accept(record: CloudEntityRecord): void;
12
19
  remove(uuid: string): void;
13
20
  has(uuid: string): boolean;
14
- get(uuid: string): MapEntity | undefined;
21
+ retained(uuid: string): MapEntity | undefined;
15
22
  parentOf(uuid: string): string | null | undefined;
16
23
  root(): MapEntity;
24
+ retainedChildren(parentUUID: string): readonly MapEntity[];
25
+ get(uuid: string): MapEntity | undefined;
17
26
  children(parentUUID: string): readonly MapEntity[];
18
27
  holders(parentUUID: string, name: string): readonly MapEntity[];
28
+ foldersOwed(): string[];
19
29
  takeTouched(): Set<string>;
20
30
  }
21
31
  export declare function mapEntity(record: CloudEntityRecord): MapEntity;
@@ -1 +1 @@
1
- var f=Object.defineProperty;var h=(n,e)=>f(n,"name",{value:e,configurable:!0});import{membershipVersion as l,recordGitHome as p}from"../entities/rules.js";import{DERIVED_PAYLOAD as c}from"../entities/types.js";class w{static{h(this,"MapIndex")}#s;#o;#e=new Map;#t=new Map;#i=new Set;#r=new Set;#u=new Set;constructor(e,t){this.#s=e,this.#o=t}get rootUUID(){return this.#s}get size(){return this.#e.size}enter(e,t){if(!this.#e.has(e))return!1;if(this.#i.has(e))return!0;this.#i.add(e),this.#n(e);for(const s of t)this.accept(s);return!0}entered(e){return this.#i.has(e)}accept(e){const t=U(e);if(t.uuid===this.#s){this.#e.set(t.uuid,t),this.#n(t.uuid);return}if(t.parentUUID===null||!this.#i.has(t.parentUUID)){this.remove(t.uuid);return}const s=this.#e.get(t.uuid);this.#e.set(t.uuid,t),s!==void 0&&(s.parentUUID!==t.parentUUID||s.name!==t.name)&&(this.#d(s),this.#n(s.parentUUID)),this.#a(t),this.#n(t.uuid),this.#n(t.parentUUID)}remove(e){const t=this.#e.get(e);t!==void 0&&e!==this.#s&&this.#n(t.parentUUID);const s=[e];for(let i=s.pop();i!==void 0;i=s.pop()){const r=this.#e.get(i);if(r===void 0)continue;this.#e.delete(i),this.#i.delete(i),this.#r.delete(i),this.#u.add(i),r.uuid!==this.#s&&this.#d(r);const u=this.#t.get(i);if(u!==void 0){this.#t.delete(i);for(const a of u.values())for(const d of o(a))s.push(d.uuid)}}}has(e){return this.#e.has(e)}get(e){const t=this.#e.get(e);return t===void 0?void 0:this.#h(t)}parentOf(e){return this.#e.get(e)?.parentUUID}root(){const e=this.#e.get(this.#s);if(e===void 0)throw new Error(`the map of ${this.#s} holds no root`);return this.#h(e)}children(e){const t=[];for(const s of this.#t.get(e)?.values()??[])t.push(...o(s));return t.map(s=>this.#h(s))}holders(e,t){const s=this.#t.get(e)?.get(t);return s===void 0?[]:o(s).map(i=>this.#h(i))}takeTouched(){const e=this.#u;return this.#u=new Set,e}#n(e){const t=this.#e.get(e);t!==void 0&&(this.#u.add(e),c.has(t.type)&&this.#i.has(e)?this.#r.add(e):this.#r.delete(e))}#h(e){if(!this.#r.delete(e.uuid))return e;const t=[];for(const r of this.#t.get(e.uuid)?.values()??[])for(const u of o(r))u.status==="active"&&t.push(u);const s=l(e,t,this.#o);if(s===e.version)return e;const i={...e,version:s};return this.#e.set(i.uuid,i),i.uuid!==this.#s&&this.#a(i),i}#a(e){if(e.parentUUID===null)return;let t=this.#t.get(e.parentUUID);t===void 0&&(t=new Map,this.#t.set(e.parentUUID,t));const s=t.get(e.name);if(s===void 0||!Array.isArray(s)&&s.uuid===e.uuid)t.set(e.name,e);else if(!Array.isArray(s))t.set(e.name,[s,e]);else{const i=s.findIndex(r=>r.uuid===e.uuid);i===-1?s.push(e):s[i]=e}}#d(e){if(e.parentUUID===null)return;const t=this.#t.get(e.parentUUID),s=t?.get(e.name);if(!(t===void 0||s===void 0)){if(Array.isArray(s)){const i=s.filter(r=>r.uuid!==e.uuid);i.length!==s.length&&t.set(e.name,i.length===1?i[0]:i);return}s.uuid===e.uuid&&(t.delete(e.name),t.size===0&&this.#t.delete(e.parentUUID))}}}function o(n){return Array.isArray(n)?n:[n]}h(o,"holdersOf");const m=new Set(["file.text","file.binary","link"]);function U(n){return{uuid:n.uuid,type:n.type,parentUUID:n.parentUUID,name:n.name,status:n.status,version:n.version,fileMode:n.fileMode,mtime:n.mtime,size:n.size,target:n.type==="reference"?n.payloadVersion:n.type==="link"?n.linkTarget:null,payloadVersion:m.has(n.type)?n.payloadVersion:null,gitHome:p(n)}}h(U,"mapEntity");export{w as MapIndex,U as mapEntity};
1
+ var l=Object.defineProperty;var r=(u,e)=>l(u,"name",{value:e,configurable:!0});import{membershipVersion as p,recordGitHome as c}from"../entities/rules.js";import{projectPath as g}from"../entities/units.js";import{DERIVED_PAYLOAD as m}from"../entities/types.js";import{checkoutAsksProject as w,checkoutDirectories as v,checkoutFileOwner as U,checkoutFolderStands as D,checkoutStands as I}from"../git/checkout.js";import{DriveError as k}from"./contracts.js";class O{static{r(this,"MapIndex")}#i;#g;#e=new Map;#s=new Map;#u=new Set;#r=new Set;#o=new Set;#d=new Set;#a=new Set;#t=new Map;#n=new Map;constructor(e,t){this.#i=e,this.#g=t}get rootUUID(){return this.#i}get size(){return this.#e.size}enter(e,t){if(!this.#e.has(e))return!1;if(this.#u.has(e))return!0;this.#u.add(e),this.#r.delete(e),this.#n.has(e)&&!this.#t.has(e)&&this.#o.add(e),this.#h(e);for(const i of t)this.accept(i);return!0}sizes(e,t,i,s){this.#e.get(e)?.version!==t||this.#n.get(e)!==i||(this.#o.delete(e),this.#t.set(e,{version:t,sizes:s,directories:s===null?void 0:v(s)}),this.#m(e))}#m(e){this.#h(e);const t=[e];for(let i=t.pop();i!==void 0;i=t.pop())for(const s of this.#s.get(i)?.values()??[])for(const n of o(s))(d(n)||n.type==="folder")&&this.#h(n.uuid),n.type==="folder"&&(this.entered(n.uuid)||this.#r.add(n.uuid),t.push(n.uuid))}sizesOwed(){const e=[];for(const t of this.#o){const i=this.#e.get(t),s=this.#n.get(t);i?.type!=="repo.git"||s===void 0||this.#t.get(t)?.version!==i.version&&e.push({uuid:t,version:i.version,transportVersion:s})}return e}entered(e){return this.#u.has(e)}accept(e){const t=A(e),i=this.#t.get(e.uuid);if(i&&(this.#n.get(e.uuid)!==(e.transportVersion??void 0)||i.version!==t.version)&&(this.#t.delete(e.uuid),this.#m(e.uuid)),e.type==="repo.git"&&e.transportVersion!==null?this.#n.set(e.uuid,e.transportVersion):this.#n.delete(e.uuid),this.#u.has(e.uuid)&&this.#n.has(e.uuid)&&!this.#t.has(e.uuid)?this.#o.add(e.uuid):this.#o.delete(e.uuid),t.uuid===this.#i){this.#e.set(t.uuid,t),this.#h(t.uuid);return}if(t.parentUUID===null||!this.#u.has(t.parentUUID)){this.remove(t.uuid);return}const s=this.#e.get(t.uuid);this.#e.set(t.uuid,t),s!==void 0&&(s.parentUUID!==t.parentUUID||s.name!==t.name)&&(this.#U(s),this.#c(s.parentUUID)),this.#v(t),t.type==="folder"&&!this.entered(t.uuid)&&this.#r.add(t.uuid),this.#h(t.uuid),this.#c(t.parentUUID)}remove(e){const t=this.#e.get(e);t!==void 0&&e!==this.#i&&this.#c(t.parentUUID);const i=[e];for(let s=i.pop();s!==void 0;s=i.pop()){const n=this.#e.get(s);if(n===void 0)continue;this.#e.delete(s),this.#t.delete(s),this.#n.delete(s),this.#u.delete(s),this.#r.delete(s),this.#o.delete(s),this.#d.delete(s),this.#a.add(s),n.uuid!==this.#i&&this.#U(n);const h=this.#s.get(s);if(h!==void 0){this.#s.delete(s);for(const a of h.values())for(const f of o(a))i.push(f.uuid)}}}has(e){return this.#e.has(e)}retained(e){return this.#e.get(e)}parentOf(e){return this.#e.get(e)?.parentUUID}root(){const e=this.#e.get(this.#i);if(e===void 0)throw new Error(`the map of ${this.#i} holds no root`);return this.#l(e)}retainedChildren(e){const t=[];for(const i of this.#s.get(e)?.values()??[])t.push(...o(i));return t}get(e){const t=this.#e.get(e);return t===void 0||!this.#f(t)?void 0:this.#l(t)}children(e){return this.retainedChildren(e).filter(t=>this.#f(t)).map(t=>this.#l(t))}holders(e,t){const i=this.#s.get(e)?.get(t);return i===void 0?[]:o(i).filter(s=>this.#f(s)).map(s=>this.#l(s))}foldersOwed(){const e=[];for(const t of this.#r){const i=this.#e.get(t);if(i===void 0||i.type!=="folder"||i.status!=="active"||this.entered(t))continue;const s=this.#p(i);if(!s)continue;const n=this.#t.get(s.project.uuid);n&&!n.directories?.has(s.path)&&e.push(i.uuid)}return this.#r.clear(),e}#w(e){if(e.status!=="active"||e.uuid===this.#i)return!0;const t=w(e)?this.#D(e):null,i=I(e,t);if(i!=="children")return i;const s=this.entered(e.uuid)?this.retainedChildren(e.uuid).filter(n=>n.status==="active").map(n=>this.#w(n)):void 0;return D(t,s)}#D(e){const t=this.#p(e);if(!t)return null;const i=this.#t.get(t.project.uuid);return{files:i?.sizes,directories:i?.directories,path:t.path}}#f(e){const t=this.#w(e);if(t!==void 0)return t;throw new k("unavailable",`Checkout membership is unavailable for ${e.name}`,{root:this.#i,uuid:e.uuid,type:e.type,address:[]})}takeTouched(){const e=this.#a;return this.#a=new Set,e}#c(e){this.#h(e);let t=this.#e.get(e);if(t?.type!=="folder")return;const i=this.#p(t);if(!i)return;const s=this.#t.get(i.project.uuid)?.directories;let n=i.path;for(;t?.type==="folder"&&t.parentUUID!==null&&!s?.has(n);)this.#h(t.parentUUID),t=this.#e.get(t.parentUUID),n=n.slice(0,Math.max(0,n.lastIndexOf("/")))}#h(e){const t=this.#e.get(e);t!==void 0&&(this.#a.add(e),m.has(t.type)&&this.#u.has(e)?this.#d.add(e):this.#d.delete(e))}#l(e){if(d(e))return this.#I(e);if(!this.#d.has(e.uuid))return e;const t=[];for(const n of this.#s.get(e.uuid)?.values()??[])for(const h of o(n))h.status==="active"&&this.#f(h)&&t.push(h);const i=p(e,t,this.#g);if(this.#d.delete(e.uuid),i===e.version)return e;const s={...e,version:i};return this.#e.set(s.uuid,s),s.uuid!==this.#i&&this.#v(s),s}#I(e){const t=this.#p(e),i=t?this.#t.get(t.project.uuid):void 0;if(!t||i===void 0||i.version!==t.project.version)return e;const s=i.sizes?.get(t.path)?.size;return s===void 0?e:{...e,size:s}}#p(e){return g(e,t=>this.#e.get(t))??null}#v(e){if(e.parentUUID===null)return;let t=this.#s.get(e.parentUUID);t===void 0&&(t=new Map,this.#s.set(e.parentUUID,t));const i=t.get(e.name);if(i===void 0||!Array.isArray(i)&&i.uuid===e.uuid)t.set(e.name,e);else if(!Array.isArray(i))t.set(e.name,[i,e]);else{const s=i.findIndex(n=>n.uuid===e.uuid);s===-1?i.push(e):i[s]=e}}#U(e){if(e.parentUUID===null)return;const t=this.#s.get(e.parentUUID),i=t?.get(e.name);if(!(t===void 0||i===void 0)){if(Array.isArray(i)){const s=i.filter(n=>n.uuid!==e.uuid);s.length!==i.length&&t.set(e.name,s.length===1?s[0]:s);return}i.uuid===e.uuid&&(t.delete(e.name),t.size===0&&this.#s.delete(e.parentUUID))}}}function o(u){return Array.isArray(u)?u:[u]}r(o,"holdersOf");const d=r(u=>U(u)==="git","gitHeld"),z=new Set(["file.text","file.binary","link"]);function A(u){return{uuid:u.uuid,type:u.type,parentUUID:u.parentUUID,name:u.name,status:u.status,version:u.version,fileMode:u.fileMode,mtime:u.mtime,size:u.size,target:u.type==="reference"?u.payloadVersion:u.type==="link"?u.linkTarget:null,payloadVersion:z.has(u.type)?u.payloadVersion:null,gitHome:c(u)}}r(A,"mapEntity");export{O as MapIndex,A as mapEntity};
@@ -60,6 +60,13 @@ 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 interface DriveFile {
64
+ readonly root: string;
65
+ readonly uuid: string;
66
+ readonly prefix: readonly string[];
67
+ }
68
+ export declare function fileAt(path: readonly string[], at: Where): DriveFile | null;
69
+ export declare function pathOfFile(roots: RootsPort, file: DriveFile): Promise<readonly string[] | null>;
63
70
  export declare function unshown(path: readonly string[]): boolean;
64
71
  export declare function addressOnly(roots: RootsPort, path: readonly string[], at: Where | Place): boolean;
65
72
  export declare function childAt(map: MapPort, parentUUID: string, name: string): Promise<MapEntity | null>;
@@ -1,2 +1,2 @@
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};
1
+ var U=Object.defineProperty;var l=(e,n)=>U(e,"name",{value:n,configurable:!0});import{LOCAL_DIR_NAME as _}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 S}from"../entities/bytes.js";import{collisionBases as b,materializedSlotNames as P}from"../entities/rules.js";import{fileAbsent as $}from"../git/checkout.js";import{CONTAINERS as L}from"../entities/types.js";import{FILES_FOLDER as j}from"../registration/home-layout.js";function B(e){return e.kind==="directory"||e.size!==null}l(B,"described");async function ue(e,n){if(z(n))return{kind:"nowhere"};const t=[];let r=!1,u=e.home.uuid,s=e.home.shelf,i=e.home.map,o=i.root(),d=[],O=o.name,w=!1;const A=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=i.placed(o.uuid),g=A();if(o.type==="reference"&&o.target!==null&&m===g){const f=await e.top(o.target);f!==null&&(!m&&!r&&t.push(R(u,o,d)),u=f.uuid,s=f.shelf,i=null,o=f.entity,d=[],w=!1,m=f.placed,g=A())}if(m){if(E)return{kind:"shelf",root:u,address:d,entity:o};if(!g)return{kind:"shelf",root:u,address:h(a),entity:null}}else{if(g)return{kind:"shelf",root:u,address:h(a),entity:null};{const f=o.type==="repo.git";if((f||!r)&&t.push(R(u,o,d)),f&&(r=!0),E)return{kind:"listed",root:u,address:d,entity:o,entry:v(o,O),placing:t};if(!L.has(o.type))return{kind:"notdir"}}}if(i??=(await e.enter(u))?.map??null,i===null||!await i.enter(o.uuid))return{kind:"nowhere"};const p=n[a],I=await C(i,o.uuid,p);if(d=[...d,p],O=p,I===null){if(r&&o.type==="repo.git"&&N(p)){const f=await Y(i,o);return a+1===n.length?{kind:"door",root:u,address:h(a+1),entry:f,placing:t}:f?.kind==="file"?{kind:"notdir"}:{kind:"door",root:u,address:h(a+1),entry:null,placing:t}}return t.length===0?(o.type==="repo.git"&&o.gitHome===null&&N(p)&&s.has(d)?await V(i,s,u,o,d,n.slice(a+1)):null)??{kind:"shelf",root:u,address:h(a+1),entity:null}:a+1===n.length?{kind:"absent",root:u,address:d,placing:t}:{kind:"nowhere"}}o=I}}l(ue,"where");function oe(e){return e.kind!=="listed"&&e.kind!=="door"?e:e.entry!==null&&B(e.entry)?{...e,entry:e.entry}:null}l(oe,"glance");async function G(e,n){return n===e.home.uuid?e.home:await e.enter(n)}l(G,"rootOf");function le(e,n){return n.kind!=="listed"&&n.kind!=="shelf"||!n.entity||n.entity.type!=="file.text"&&n.entity.type!=="file.binary"?null:{root:n.root,uuid:n.entity.uuid,prefix:e.slice(0,e.length-n.address.length)}}l(le,"fileAt");async function se(e,n){const t=await G(e,n.root);if(!t)return null;const r=t.map;r.get(n.uuid)||await r.enter(n.uuid);const u=[],s=new Set;let i=r.get(n.uuid);for(;i&&i.uuid!==t.uuid;){if(i.status!=="active"||!x(i)||i.parentUUID===null||s.has(i.uuid))return null;s.add(i.uuid);const o=i.parentUUID;if(!await r.enter(o))return null;const d=T(r,i);if(d===null)return null;u.push(d),i=r.get(o)}return i?.uuid===t.uuid?[...n.prefix,...u.reverse()]:null}l(se,"pathOfFile");function R(e,n,t){return{root:e,uuid:n.uuid,type:n.type,address:t}}l(R,"unitOf");function z(e){return e.some(n=>n.toLowerCase()===_)}l(z,"unshown");function de(e,n,t){return z(n)?!0:"root"in t?t.root===e.home.uuid?t.address[0]===j:t.address.length===0:!1}l(de,"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 x(r[0]);if(r.length===0&&!H(e,n,t))return null;for(const[u,s]of M(c(e.children(n))))if(s===t)return x(u);return null}l(C,"childAt");function x(e){return $(e)?null:e}l(x,"shows");async function fe(e,n){const t=n.parentUUID;return t!==null&&await e.enter(t)&&D(e,t,n)}l(fe,"aloneInSlot");function D(e,n,t){const r=c(e.holders(n,t.name));return r.length===1&&r[0]?.uuid===t.uuid&&!H(e,n,t.name)}l(D,"soleHolder");async function ae(e,n,t,r){if(!await e.enter(n))return!1;const u=k(t),s=new Map(b(t).map(i=>[k(i),0]));for(const i of c(e.children(n))){if(i.uuid===r)continue;const o=k(i.name);if(o===u)return!1;const d=s.get(o);d!==void 0&&s.set(o,d+1)}return[...s.values()].every(i=>i<2)}l(ae,"freeName");function k(e){return e.normalize("NFC").toLowerCase()}l(k,"folded");function H(e,n,t){return b(t).some(r=>c(e.holders(n,r)).length>1)}l(H,"derivable");async function ce(e,n){let t=e.root();for(const r of n){if(t.type==="repo.git")return!1;const u=await C(e,t.uuid,r);if(u===null)return!1;t=u}return t.type!=="repo.git"}l(ce,"outsideRepositories");function M(e){const n=P(e);return e.map(t=>[t,n.get(t.uuid)??t.name])}l(M,"derivedNames");function v(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?S(r):e.size,target:r,version:e.version,payloadVersion:e.payloadVersion}}l(v,"entryOf");async function Y(e,n){if(n.gitHome===null)return v(n,y,"directory");const t=await J(e,n),r=F(e,n);if(r===null||t===null)return null;const u=S(q(r,t));return{...v(n,y,"file"),size:u,payloadVersion:null}}l(Y,"gitEntry");function q(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(q,"gitPointer");async function J(e,n){const t=[],r=new Set([n.uuid]);let u=n;for(;u.gitHome!==null;){const{entity:i,path:o}=u.gitHome;if(i===null||r.has(i))return null;r.add(i),t.push(o===""?[]:o.split("/"));const d=e.get(i)??(await e.enter(i)?e.get(i):void 0);if(d===void 0||d.type!=="repo.git"||d.status!=="active")return null;u=d}const s=F(e,u);return s===null?null:[...s,y,...t.reverse().flat()]}l(J,"gitDirectoryIn");function F(e,n){const t=e.root().uuid,r=[],u=new Set;for(let s=n;s.uuid!==t;){const i=s.parentUUID===null?void 0:e.get(s.parentUUID);if(i===void 0||u.has(s.uuid)||s.status!=="active")return null;u.add(s.uuid);const o=T(e,s);if(o===null)return null;r.push(o),s=i}return r.reverse()}l(F,"addressIn");function T(e,n){const t=n.parentUUID;if(D(e,t,n))return n.name;for(const[r,u]of M(c(e.children(t))))if(r.uuid===n.uuid)return u;return null}l(T,"shownName");function K(e){if(L.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,F as addressIn,de as addressOnly,fe as aloneInSlot,C as childAt,M as derivedNames,B as described,v as entryOf,le as fileAt,ae as freeName,Y as gitEntry,q as gitPointer,oe as glance,K as kindOf,ce as outsideRepositories,se as pathOfFile,G as rootOf,x as shows,z as unshown,ue as where};
@@ -1 +1 @@
1
- var v=Object.defineProperty;var f=(u,e)=>v(u,"name",{value:e,configurable:!0});import{assertRecord as y}from"./cloud.js";import{playChange as D}from"../clash/bodmas.js";import{failure as I}from"../faults/need.js";import{membershipVersion as b}from"./rules.js";import{DERIVED_PAYLOAD as M}from"./types.js";const U=f(u=>I(`accepted entity ${u.uuid} has a parent cycle`,"graph-cycle","parent-cycle",{id:u.uuid,type:u.type}),"cycle");class O{static{f(this,"AcceptedView")}head;sha256Hex;#t=new Map;#e=new Map;#n=new Set;#i=new Map;#s=0;constructor(e,s){this.head=e,this.sha256Hex=s}async advance(e){const s=e.map(({facets:o,result:r,joins:h})=>({facets:o,result:y(r),joins:h})),n=[...new Set(s.map(({result:o})=>o.uuid).filter(o=>!this.#t.has(o)))],t=n.length>0?await this.head.records(n):new Map,i=new Set,a=[];for(const[o,r]of s.entries()){const{uuid:h,parentUUID:w}=r.result,g=this.#t.get(h),d=g??t.get(h)??null,p=d!==null&&w!==null&&r.facets.includes("move")&&await this.#d(h,w)?{keeps:d.parentUUID}:void 0;p&&a.push({index:o,...p});const{row:c}=D(d,r,this.sha256Hex,p);if(c===null||c===d)continue;const l=d?.parentUUID??null;if(l!==null&&i.add(l),g!==void 0&&l!==null&&this.#e.get(l).delete(h),this.#t.set(h,c),i.add(h),c.parentUUID===null)continue;i.add(c.parentUUID);const m=this.#e.get(c.parentUUID);m?m.add(h):this.#e.set(c.parentUUID,new Set([h]))}this.#s+=1;for(const o of i)this.#n.add(o),this.#i.delete(o);return{touched:i,loops:a}}async#d(e,s){const n=new Set;for(let t=s;t!==null&&!n.has(t);){if(t===e)return!0;n.add(t);const i=this.#t.get(t);if(i){t=i.parentUUID;continue}const a=(await this.head.chains([t])).get(t);if(!a)return!1;const o=a.findIndex(r=>this.#t.has(r));for(const r of o<0?a:a.slice(0,o)){if(r===e)return!0;n.add(r)}t=o<0?null:a[o]}return!1}async row(e){return(await this.rows([e])).get(e)}async rows(e){const s=this.#s;return this.#r(await this.#a(e),s)}async children(e){const s=this.#s,[n,t]=await Promise.all([this.#a([e]),this.#o([e])]);return n.has(e)?[...(await this.#r(new Map(t.get(e).map(a=>[a.uuid,a])),s)).values()]:[]}async locate(e){const s=await this.row(e);return s?{root:await this.#u(s),record:s}:null}async subtree(e){const s=await this.#a([e]);if(!s.has(e))return[];const n=new Map;for(let t=[e];t.length>0;){const i=await this.#o(t);t=[];for(const[a,o]of i){n.set(a,o);for(const r of o){if(s.has(r.uuid))throw U(r);s.set(r.uuid,r),t.push(r.uuid)}}}return[...s.values()].map(t=>this.#h(t)?this.#c(t,n.get(t.uuid)):t)}async reached(){const e=new Set;for(const s of(await this.head.chains([...this.#n])).values())e.add(s[s.length-1]);for(const s of this.#t.values())e.add(await this.#u(s));return[...e]}async#a(e){const s=new Map,n=[];for(const t of e){const i=this.#t.get(t);i?s.set(t,i):n.push(t)}if(n.length>0)for(const[t,i]of await this.head.records(n))s.set(t,i);return s}async#o(e){const s=await this.head.children(e);return new Map(e.map(n=>{const t=(s.get(n)??[]).filter(i=>!this.#t.has(i.uuid));for(const i of this.#e.get(n)??[])t.push(this.#t.get(i));return[n,t]}))}async#r(e,s){const n=[];for(const t of e.values()){if(!this.#h(t))continue;const i=this.#i.get(t.uuid);i?e.set(t.uuid,i):n.push(t.uuid)}if(n.length===0)return e;for(const[t,i]of await this.#o(n)){const a=this.#c(e.get(t),i);s===this.#s&&this.#i.set(t,a),e.set(t,a)}return e}#h(e){return this.#n.has(e.uuid)&&M.has(e.type)}#c(e,s){const n=b(e,s.filter(({status:t})=>t==="active"),this.sha256Hex);return n===e.version?e:{...e,version:n}}async#u(e){const s=new Set([e.uuid]),n=f(t=>{if(s.has(t))throw U(e);s.add(t)},"visit");for(let t=e;;){if(t.parentUUID===null)return t.uuid;const i=this.#t.get(t.parentUUID);if(i){n(i.uuid),t=i;continue}const a=(await this.head.chains([t.parentUUID])).get(t.parentUUID);if(!a)throw new Error(`accepted entity ${e.uuid} descends from no committed root`);const o=a.findIndex(r=>this.#t.has(r));for(const r of o<0?a:a.slice(0,o+1))n(r);if(o<0)return a[a.length-1];t=this.#t.get(a[o])}}}export{O as AcceptedView};
1
+ var v=Object.defineProperty;var f=(u,e)=>v(u,"name",{value:e,configurable:!0});import{assertRecord as y}from"./cloud.js";import{playChange as D}from"../clash/bodmas.js";import{failure as I}from"../faults/need.js";import{membershipVersion as b}from"./rules.js";import{DERIVED_PAYLOAD as M}from"./types.js";const U=f(u=>I(`accepted entity ${u.uuid} has a parent cycle`,"graph-cycle","parent-cycle",{id:u.uuid,type:u.type}),"cycle");class O{static{f(this,"AcceptedView")}head;sha256Hex;#t=new Map;#e=new Map;#n=new Set;#i=new Map;#s=0;constructor(e,s){this.head=e,this.sha256Hex=s}async advance(e){const s=e.map(r=>({...r,result:y(r.result)})),n=[...new Set(s.map(({result:r})=>r.uuid).filter(r=>!this.#t.has(r)))],t=n.length>0?await this.head.records(n):new Map,i=new Set,a=[];for(const[r,o]of s.entries()){const{uuid:h,parentUUID:w}=o.result,g=this.#t.get(h),d=g??t.get(h)??null,p=d!==null&&w!==null&&o.facets.includes("move")&&await this.#d(h,w)?{keeps:d.parentUUID}:void 0;p&&a.push({index:r,...p});const{row:c}=D(d,o,this.sha256Hex,p);if(c===null||c===d)continue;const l=d?.parentUUID??null;if(l!==null&&i.add(l),g!==void 0&&l!==null&&this.#e.get(l).delete(h),this.#t.set(h,c),i.add(h),c.parentUUID===null)continue;i.add(c.parentUUID);const m=this.#e.get(c.parentUUID);m?m.add(h):this.#e.set(c.parentUUID,new Set([h]))}this.#s+=1;for(const r of i)this.#n.add(r),this.#i.delete(r);return{touched:i,loops:a}}async#d(e,s){const n=new Set;for(let t=s;t!==null&&!n.has(t);){if(t===e)return!0;n.add(t);const i=this.#t.get(t);if(i){t=i.parentUUID;continue}const a=(await this.head.chains([t])).get(t);if(!a)return!1;const r=a.findIndex(o=>this.#t.has(o));for(const o of r<0?a:a.slice(0,r)){if(o===e)return!0;n.add(o)}t=r<0?null:a[r]}return!1}async row(e){return(await this.rows([e])).get(e)}async rows(e){const s=this.#s;return this.#o(await this.#a(e),s)}async children(e){const s=this.#s,[n,t]=await Promise.all([this.#a([e]),this.#r([e])]);return n.has(e)?[...(await this.#o(new Map(t.get(e).map(a=>[a.uuid,a])),s)).values()]:[]}async locate(e){const s=await this.row(e);return s?{root:await this.#u(s),record:s}:null}async subtree(e){const s=await this.#a([e]);if(!s.has(e))return[];const n=new Map;for(let t=[e];t.length>0;){const i=await this.#r(t);t=[];for(const[a,r]of i){n.set(a,r);for(const o of r){if(s.has(o.uuid))throw U(o);s.set(o.uuid,o),t.push(o.uuid)}}}return[...s.values()].map(t=>this.#h(t)?this.#c(t,n.get(t.uuid)):t)}async reached(){const e=new Set;for(const s of(await this.head.chains([...this.#n])).values())e.add(s[s.length-1]);for(const s of this.#t.values())e.add(await this.#u(s));return[...e]}async#a(e){const s=new Map,n=[];for(const t of e){const i=this.#t.get(t);i?s.set(t,i):n.push(t)}if(n.length>0)for(const[t,i]of await this.head.records(n))s.set(t,i);return s}async#r(e){const s=await this.head.children(e);return new Map(e.map(n=>{const t=(s.get(n)??[]).filter(i=>!this.#t.has(i.uuid));for(const i of this.#e.get(n)??[])t.push(this.#t.get(i));return[n,t]}))}async#o(e,s){const n=[];for(const t of e.values()){if(!this.#h(t))continue;const i=this.#i.get(t.uuid);i?e.set(t.uuid,i):n.push(t.uuid)}if(n.length===0)return e;for(const[t,i]of await this.#r(n)){const a=this.#c(e.get(t),i);s===this.#s&&this.#i.set(t,a),e.set(t,a)}return e}#h(e){return this.#n.has(e.uuid)&&M.has(e.type)}#c(e,s){const n=b(e,s.filter(({status:t})=>t==="active"),this.sha256Hex);return n===e.version?e:{...e,version:n}}async#u(e){const s=new Set([e.uuid]),n=f(t=>{if(s.has(t))throw U(e);s.add(t)},"visit");for(let t=e;;){if(t.parentUUID===null)return t.uuid;const i=this.#t.get(t.parentUUID);if(i){n(i.uuid),t=i;continue}const a=(await this.head.chains([t.parentUUID])).get(t.parentUUID);if(!a)throw new Error(`accepted entity ${e.uuid} descends from no committed root`);const r=a.findIndex(o=>this.#t.has(o));for(const o of r<0?a:a.slice(0,r+1))n(o);if(r<0)return a[a.length-1];t=this.#t.get(a[r])}}}export{O as AcceptedView};
@@ -1,6 +1,6 @@
1
1
  import { type EntityStatus, type EntityType, type PortableFileMode, type PortableMtime, type Sha256Hex } from './types.js';
2
2
  import { type Steps } from '../steps.js';
3
- export declare const ENTITY_CLOUD_CONTRACT = "amalgm-entity-registry@10";
3
+ export declare const ENTITY_CLOUD_CONTRACT = "amalgm-entity-registry@12";
4
4
  export declare const ENTITY_CLOUD_SCHEMA_VERSION = 1;
5
5
  export interface CloudEntityRecord {
6
6
  readonly uuid: string;