@amalgm/live 0.2.81-preview.47210041585 → 0.2.81-preview.47276383685

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 (57) hide show
  1. package/dist/apply/showing.js +1 -1
  2. package/dist/clash/bodmas.js +1 -1
  3. package/dist/detection/record-proposal.d.ts +1 -1
  4. package/dist/detection/record-proposal.js +1 -1
  5. package/dist/detection/skip-policy.js +1 -1
  6. package/dist/drive/drive.d.ts +6 -4
  7. package/dist/drive/drive.js +1 -1
  8. package/dist/drive/map-index.d.ts +12 -2
  9. package/dist/drive/map-index.js +1 -1
  10. package/dist/drive/where.d.ts +7 -0
  11. package/dist/drive/where.js +2 -2
  12. package/dist/entities/accepted-view.js +1 -1
  13. package/dist/entities/cloud.d.ts +1 -1
  14. package/dist/entities/cloud.js +1 -1
  15. package/dist/entities/reducer.js +1 -1
  16. package/dist/entities/rules.d.ts +0 -5
  17. package/dist/entities/rules.js +1 -1
  18. package/dist/entities/units.d.ts +28 -0
  19. package/dist/entities/units.js +1 -1
  20. package/dist/files/accepted-files.d.ts +3 -1
  21. package/dist/files/accepted-files.js +1 -1
  22. package/dist/files/browser.js +1 -1
  23. package/dist/files/cloud-files.d.ts +11 -0
  24. package/dist/files/cloud-files.js +1 -1
  25. package/dist/git/artifact.d.ts +14 -1
  26. package/dist/git/artifact.js +1 -1
  27. package/dist/git/checkout-view.d.ts +15 -0
  28. package/dist/git/checkout-view.js +1 -0
  29. package/dist/git/checkout.d.ts +31 -0
  30. package/dist/git/checkout.js +1 -0
  31. package/dist/git/holds.js +1 -1
  32. package/dist/git/index.d.ts +2 -0
  33. package/dist/git/index.js +1 -1
  34. package/dist/transfer/download.d.ts +2 -0
  35. package/dist/transfer/download.js +1 -1
  36. package/dist-cjs/apply/showing.js +1 -1
  37. package/dist-cjs/clash/bodmas.js +1 -1
  38. package/dist-cjs/detection/record-proposal.js +1 -1
  39. package/dist-cjs/detection/skip-policy.js +1 -1
  40. package/dist-cjs/drive/drive.js +1 -1
  41. package/dist-cjs/drive/map-index.js +1 -1
  42. package/dist-cjs/drive/where.js +2 -2
  43. package/dist-cjs/entities/accepted-view.js +1 -1
  44. package/dist-cjs/entities/cloud.js +1 -1
  45. package/dist-cjs/entities/reducer.js +1 -1
  46. package/dist-cjs/entities/rules.js +1 -1
  47. package/dist-cjs/entities/units.js +1 -1
  48. package/dist-cjs/files/accepted-files.js +1 -1
  49. package/dist-cjs/files/browser.js +1 -1
  50. package/dist-cjs/files/cloud-files.js +1 -1
  51. package/dist-cjs/git/artifact.js +1 -1
  52. package/dist-cjs/git/checkout-view.js +1 -0
  53. package/dist-cjs/git/checkout.js +1 -0
  54. package/dist-cjs/git/holds.js +1 -1
  55. package/dist-cjs/git/index.js +1 -1
  56. package/dist-cjs/transfer/download.js +1 -1
  57. package/package.json +4 -4
@@ -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 n=o(e.uuid);if(n!==void 0&&!n.available)return"neither";const t=n!==void 0,{root:r,returns:a}=m(e,o,u);if(r==="sealed")return"neither";if(r===null)return t?"leave":"neither";if(!t&&r.onDemand){const i=y(s=>s===e.uuid?e:void 0,d(o,a));if(I(e.uuid,i)===e.uuid&&!v(e.uuid,i))return"listed"}return t&&(p.has(n.type)||!p.has(e.type))?"apply":"enter"}f(M,"judgeShowing");function y(e,o){return u=>{const n=e(u);if(n?.parentUUID===null)return{...n,home:o(u)?.home===!0};if(n)return n;const t=o(u);return t?.root?{type:t.type,name:t.name,parentUUID:null,home:t.home}:t}}f(y,"shownUnits");function v(e,o,u=new Map){const n=o(e);if(n?.parentUUID===null)return!0;const t=new Set;let r=null;for(let a=e,i=n;i?.parentUUID!=null&&!t.has(a);){const s=u.get(a);if(s!==void 0){r=s;break}t.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 t)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 d(e,o){return o.size===0?e:u=>{const n=e(u),t=o.get(u);return n!==void 0&&t!==void 0?{...n,parentUUID:t}:n}}f(d,"returnedPlaces");const c=new Map;function m(e,o,u){const n=new Map;for(;;){const t=d(o,n),r=x(e,t);if(r===null||r==="sealed")return{root:r,returns:c};if("root"in r)return{root:r.root,returns:n};if(!(u&&r.loop.find(i=>!n.has(i)&&g(i,t,u,n))))return{root:null,returns:c}}}f(m,"showingWalk");function g(e,o,u,n){const t=u(e);return t===void 0||t===o(e)?.parentUUID?!1:(n.set(e,t),!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 n=[e.uuid],t=new Map([[e.uuid,0]]);for(let r=e.parentUUID;r!==null;){const a=t.get(r);if(a!==void 0)return{loop:n.slice(Math.max(a,1))};t.set(r,n.length),n.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,d as returnedPlaces,y as shownUnits};
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"../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"]),w={onDemand:!1};function M(e,o,u){const n=o(e.uuid);if(n!==void 0&&!n.available)return"neither";const t=n!==void 0,{root:r,returns:a}=m(e,o,u);if(r==="sealed")return"neither";if(r===null)return t?"leave":"neither";if(!t&&r.onDemand){const i=y(s=>s===e.uuid?e:void 0,d(o,a));if(I(e.uuid,i)===e.uuid&&!v(e.uuid,i))return"listed"}return t&&(p.has(n.type)||!p.has(e.type))?"apply":"enter"}f(M,"judgeShowing");function y(e,o){return u=>{const n=e(u);if(n?.parentUUID===null)return{...n,home:o(u)?.home===!0};if(n)return n;const t=o(u);return t?.root?{type:t.type,name:t.name,parentUUID:null,home:t.home}:t}}f(y,"shownUnits");function v(e,o,u=new Map){const n=o(e);if(n?.parentUUID===null)return!0;const t=new Set;let r=null;for(let a=e,i=n;i?.parentUUID!=null&&!t.has(a);){const s=u.get(a);if(s!==void 0){r=s;break}t.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 t)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 d(e,o){return o.size===0?e:u=>{const n=e(u),t=o.get(u);return n!==void 0&&t!==void 0?{...n,parentUUID:t}:n}}f(d,"returnedPlaces");const c=new Map;function m(e,o,u){const n=new Map;for(;;){const t=d(o,n),r=x(e,t);if(r===null||r==="sealed")return{root:r,returns:c};if("root"in r)return{root:r.root,returns:n};if(!(u&&r.loop.find(i=>!n.has(i)&&g(i,t,u,n))))return{root:null,returns:c}}}f(m,"showingWalk");function g(e,o,u,n){const t=u(e);return t===void 0||t===o(e)?.parentUUID?!1:(n.set(e,t),!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 n=[e.uuid],t=new Map([[e.uuid,0]]);for(let r=e.parentUUID;r!==null;){const a=t.get(r);if(a!==void 0)return{loop:n.slice(Math.max(a,1))};t.set(r,n.length),n.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,d as returnedPlaces,y as shownUnits};
@@ -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 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
+ 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 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;
@@ -1 +1 @@
1
- var V=Object.defineProperty;var p=(e,t)=>V(e,"name",{value:t,configurable:!0});import{CONTAINERS as w,DERIVED_PAYLOAD as k,ROOT_TYPES as z,STATUSES as C,TYPES as M,UUID_PATTERN as h}from"./types.js";import{bytesToBase64Url as N,hexToBytes as O,utf8Decode as A}from"./bytes.js";import{isName as _,validFileState as P,validGitHome as $,validLinkTarget as L,validPortableMtime as H,validPortableSize as Y}from"./rules.js";import{clashResolution as F}from"../clash/resolution.js";import{eachStep as f,finishSteps as y,ITEMS_PER_BOUNDARY as E,sortSteps as B}from"../steps.js";import{failure as J}from"../faults/need.js";const j="amalgm-entity-registry@10",S=1,D=/^[0-9a-f]{64}$/;function lt(e,t){return`pvr_${N(O(t(`private-user:${e}:${j}`))).slice(0,32)}`}p(lt,"privateEntityResourceId");function pt(e){return/^pvr_[A-Za-z0-9_-]{32}$/.test(e)}p(pt,"isPrivateEntityResourceId");const I=p(e=>JSON.stringify(e),"stableJson"),ct=p((e,t)=>I(e)===I(t),"sameRecord"),G=["uuid","type","parentUUID","name","status","version","payloadVersion","fileMode","mtime","size","linkTarget","gitHomeEntity","gitHomePath","transportVersion"];function R(e,t){const r=m(e).records,n=m(t).records;if(r.length!==n.length)return!1;for(let o=0;o<r.length;o+=1){const l=r[o],u=n[o];if(l!==u){for(const i of G)if(l[i]!==u[i])return!1}}return!0}p(R,"sameRecords");function W(e,t){const r=new Map(t.map(n=>[n.uuid,n]));return m(e).records.map(n=>{const o=r.get(n.uuid);return o&&F(n.type)==="play"&&o.type===n.type&&o.parentUUID===n.parentUUID&&o.name===n.name&&o.status===n.status?o:n})}p(W,"statedRecords");const T=new WeakSet;function Z(e){if(typeof e=="object"&&e!==null&&T.has(e))return e;const t=e;if(!t||typeof t!="object"||typeof t.uuid!="string"||!h.test(t.uuid)||typeof t.type!="string"||!M.has(t.type)||t.parentUUID!==null&&(typeof t.parentUUID!="string"||!h.test(t.parentUUID))||!_(t.name)||!C.has(t.status)||typeof t.version!="string"||!D.test(t.version)||t.payloadVersion!==null&&typeof t.payloadVersion!="string"||!P(t.type,t.payloadVersion,t.fileMode)||!H(t.type,t.mtime,t.payloadVersion===null&&t.fileMode===null)||!Y(t.type,t.payloadVersion,t.size)||!L(t.type,t.payloadVersion,t.linkTarget)||!$(t.type,t.gitHomeEntity??null,t.gitHomePath??null)||t.transportVersion!==void 0&&t.transportVersion!==null&&(typeof t.transportVersion!="string"||!D.test(t.transportVersion)))throw new Error("cloud entity snapshot has an invalid record");if(t.parentUUID===null&&!z.has(t.type))throw new Error(`cloud entity ${t.uuid} is not a valid tree root`);if(k.has(t.type)&&t.payloadVersion!==null)throw new Error("workspace and folder payloads are derived membership, never transported heads");const r=t.transportVersion??null;if(t.type!=="repo.git"&&r!==null)throw new Error("only a repository may declare a transport head");const n=Object.freeze({uuid:t.uuid.toLowerCase(),type:t.type,parentUUID:t.parentUUID===null?null:t.parentUUID.toLowerCase(),name:t.name,status:t.status,version:t.version,payloadVersion:t.payloadVersion,fileMode:t.fileMode,mtime:t.mtime,size:t.size,linkTarget:t.linkTarget,gitHomeEntity:t.gitHomeEntity??null,gitHomePath:t.gitHomePath??null,transportVersion:r});return T.add(n),n}p(Z,"assertRecord");function*q(e){const t=[],r=new Set;return yield*f(e,n=>{const o=Z(n);if(r.has(o.uuid))throw new Error("cloud entity snapshot has duplicate UUIDs");r.add(o.uuid),t.push(o)}),t}p(q,"assertedRecordsSteps");function*g(e){const t=yield*B(yield*q(e),(r,n)=>r.uuid<n.uuid?-1:r.uuid>n.uuid?1:0);return{schemaVersion:S,kind:"amalgm-entity-registry",records:t}}p(g,"snapshotFromRecordsSteps");function m(e){return y(g(e))}p(m,"snapshotFromRecords");function*b(e,t){const r=new Map;yield*f(e,i=>{if(i.parentUUID===null)return;const s=r.get(i.parentUUID);s?s.push(i):r.set(i.parentUUID,[i])});const n=new Set([t]),o=[t];let l=0;for(;o.length>0;){for(const i of r.get(o.pop())??[])n.has(i.uuid)||(n.add(i.uuid),o.push(i.uuid));++l%E===0&&(yield)}const u=[];return yield*f(e,i=>{n.has(i.uuid)&&u.push(i)}),u}p(b,"containedRecordsSteps");function dt(e,t){return y(b(e,t))}p(dt,"containedRecords");function*K(e,t){const r=yield*b((yield*g(e)).records,t),n=new Map;yield*f(r,a=>n.set(a.uuid,a));const o=n.get(t);if(!o||o.status!=="active")return[];if(!w.has(o.type))throw new Error(`cloud materialization root ${o.uuid} is not a container`);const l=new Map;yield*f(r,a=>{if(a.uuid===o.uuid)return;if(a.parentUUID===null)throw new Error(`cloud materialization entity ${a.uuid} escapes its selected root`);if(!n.get(a.parentUUID))throw new Error(`cloud materialization entity ${a.uuid} has incomplete ancestry`);const U=l.get(a.parentUUID);U?U.push(a):l.set(a.parentUUID,[a])});const u=new Set,i=[o];let s=0;for(;i.length>0;){const a=i.pop();if(!(a.status!=="active"||u.has(a.uuid))&&(u.add(a.uuid),!!w.has(a.type))){for(const d of l.get(a.uuid)??[])d.status==="active"&&i.push(d);++s%E===0&&(yield)}}const c=[];return yield*f(r,a=>{u.has(a.uuid)&&c.push(a)}),c}p(K,"materializableRecordsSteps");function Q(e,t){return y(K(e,t))}p(Q,"materializableRecords");function ft(e,t){const r=e??[];if(!Array.isArray(r)||r.some(o=>typeof o!="string"||!h.test(o)))throw new Error(`${t} names invalid waiting entities`);const n=r.map(o=>o.toLowerCase());if(new Set(n).size!==n.length)throw new Error(`${t} names a waiting entity twice`);return n}p(ft,"waitingEntities");function ht(e,t,r,n,o=[]){const l=W(e,r),u=Q(r,n),i=new Set(u.map(({uuid:s})=>s));return t.some(({uuid:s})=>i.has(s))?!1:R(l,X(u,n,o))&&R([...u,...t],r)}p(ht,"installedSubtree");function X(e,t,r){if(r.length===0)return e;const n=new Map(e.map(i=>[i.uuid,i])),o=new Set(r);for(const i of o)if(i===t||!n.has(i))throw new Error("a waiting entity is not one the placement places beneath its root");const l=new Map,u=p(i=>{const s=[];let c=i,a=!1;for(;c!==void 0;){const d=l.get(c.uuid);if(d!==void 0){a=d;break}if(o.has(c.uuid)){a=!0,s.push(c.uuid);break}s.push(c.uuid),c=c.parentUUID===null?void 0:n.get(c.parentUUID)}for(const d of s)l.set(d,a);return a},"waitsBeneath");return e.filter(i=>!u(i))}p(X,"withoutWaiting");const x=Symbol("parent cycle"),v=Symbol("incomplete ancestry");function tt(e){const t=new Map;return r=>{const n=[],o=new Set;let l=r,u;for(;;){const i=t.get(l.uuid);if(i!==void 0){u=i;break}if(l.parentUUID===null){u=l.uuid;break}if(o.has(l.uuid)){u=x;break}o.add(l.uuid),n.push(l.uuid);const s=e.get(l.parentUUID);if(!s){u=v;break}l=s}for(const i of n)t.set(i,u);return u}}p(tt,"createRootResolver");function yt(e,t){return y(et(e,t))}p(yt,"completeRootsFromRecords");function*et(e,t){if(e.length===0)throw new Error("cloud root set has no roots");const r=e.map(s=>{if(!h.test(s))throw new Error("cloud root set has an invalid root UUID");return s.toLowerCase()}).sort();if(new Set(r).size!==r.length)throw new Error("cloud root set has duplicate roots");const n=yield*g(t),o=new Map;yield*f(n.records,s=>{o.set(s.uuid,s)});const l=new Set(r),u=n.records.filter(s=>s.parentUUID===null).map(s=>s.uuid).sort();if(u.length!==r.length||u.some((s,c)=>s!==r[c]))throw new Error("cloud root set records do not exactly match its roots");const i=tt(o);return yield*f(n.records,s=>{if(s.parentUUID!==null){const a=o.get(s.parentUUID);if(!a||s.status==="active"&&!w.has(a.type))throw new Error(`cloud root set entity ${s.uuid} has no container parent`)}const c=i(s);if(c===x)throw J("cloud root set has a parent cycle","graph-cycle","parent-cycle");if(c===v)throw new Error(`cloud root set entity ${s.uuid} has incomplete ancestry`);if(!l.has(c))throw new Error(`cloud root set entity ${s.uuid} is outside its declared roots`)}),n.records}p(et,"completeRootsFromRecordsSteps");function mt(e){let t;try{t=JSON.parse(typeof e=="string"?e:A(e))}catch{throw new Error("cloud entity snapshot is not JSON")}if(t?.schemaVersion!==S||t?.kind!=="amalgm-entity-registry"||!Array.isArray(t.records))throw new Error("cloud entity snapshot has an unsupported shape");return m(t.records)}p(mt,"parseSnapshot");export{j as ENTITY_CLOUD_CONTRACT,S as ENTITY_CLOUD_SCHEMA_VERSION,Z as assertRecord,q as assertedRecordsSteps,yt as completeRootsFromRecords,et as completeRootsFromRecordsSteps,dt as containedRecords,b as containedRecordsSteps,ht as installedSubtree,pt as isPrivateEntityResourceId,Q as materializableRecords,K as materializableRecordsSteps,mt as parseSnapshot,lt as privateEntityResourceId,ct as sameRecord,R as sameRecords,m as snapshotFromRecords,g as snapshotFromRecordsSteps,I as stableJson,W as statedRecords,ft as waitingEntities,X as withoutWaiting};
1
+ var V=Object.defineProperty;var p=(e,t)=>V(e,"name",{value:t,configurable:!0});import{CONTAINERS as w,DERIVED_PAYLOAD as k,ROOT_TYPES as z,STATUSES as C,TYPES as M,UUID_PATTERN as h}from"./types.js";import{bytesToBase64Url as N,hexToBytes as O,utf8Decode as A}from"./bytes.js";import{isName as _,validFileState as P,validGitHome as $,validLinkTarget as L,validPortableMtime as H,validPortableSize as Y}from"./rules.js";import{clashResolution as F}from"../clash/resolution.js";import{eachStep as f,finishSteps as y,ITEMS_PER_BOUNDARY as E,sortSteps as B}from"../steps.js";import{failure as J}from"../faults/need.js";const j="amalgm-entity-registry@12",S=1,D=/^[0-9a-f]{64}$/;function lt(e,t){return`pvr_${N(O(t(`private-user:${e}:${j}`))).slice(0,32)}`}p(lt,"privateEntityResourceId");function pt(e){return/^pvr_[A-Za-z0-9_-]{32}$/.test(e)}p(pt,"isPrivateEntityResourceId");const I=p(e=>JSON.stringify(e),"stableJson"),ct=p((e,t)=>I(e)===I(t),"sameRecord"),G=["uuid","type","parentUUID","name","status","version","payloadVersion","fileMode","mtime","size","linkTarget","gitHomeEntity","gitHomePath","transportVersion"];function R(e,t){const r=m(e).records,n=m(t).records;if(r.length!==n.length)return!1;for(let o=0;o<r.length;o+=1){const l=r[o],u=n[o];if(l!==u){for(const i of G)if(l[i]!==u[i])return!1}}return!0}p(R,"sameRecords");function W(e,t){const r=new Map(t.map(n=>[n.uuid,n]));return m(e).records.map(n=>{const o=r.get(n.uuid);return!o||o.type!==n.type||o.parentUUID!==n.parentUUID||o.name!==n.name||o.status!==n.status?n:F(n.type)==="play"?o:n})}p(W,"statedRecords");const T=new WeakSet;function Z(e){if(typeof e=="object"&&e!==null&&T.has(e))return e;const t=e;if(!t||typeof t!="object"||typeof t.uuid!="string"||!h.test(t.uuid)||typeof t.type!="string"||!M.has(t.type)||t.parentUUID!==null&&(typeof t.parentUUID!="string"||!h.test(t.parentUUID))||!_(t.name)||!C.has(t.status)||typeof t.version!="string"||!D.test(t.version)||t.payloadVersion!==null&&typeof t.payloadVersion!="string"||!P(t.type,t.payloadVersion,t.fileMode)||!H(t.type,t.mtime,t.payloadVersion===null&&t.fileMode===null)||!Y(t.type,t.payloadVersion,t.size)||!L(t.type,t.payloadVersion,t.linkTarget)||!$(t.type,t.gitHomeEntity??null,t.gitHomePath??null)||t.transportVersion!==void 0&&t.transportVersion!==null&&(typeof t.transportVersion!="string"||!D.test(t.transportVersion)))throw new Error("cloud entity snapshot has an invalid record");if(t.parentUUID===null&&!z.has(t.type))throw new Error(`cloud entity ${t.uuid} is not a valid tree root`);if(k.has(t.type)&&t.payloadVersion!==null)throw new Error("workspace and folder payloads are derived membership, never transported heads");const r=t.transportVersion??null;if(t.type!=="repo.git"&&r!==null)throw new Error("only a repository may declare a transport head");const n=Object.freeze({uuid:t.uuid.toLowerCase(),type:t.type,parentUUID:t.parentUUID===null?null:t.parentUUID.toLowerCase(),name:t.name,status:t.status,version:t.version,payloadVersion:t.payloadVersion,fileMode:t.fileMode,mtime:t.mtime,size:t.size,linkTarget:t.linkTarget,gitHomeEntity:t.gitHomeEntity??null,gitHomePath:t.gitHomePath??null,transportVersion:r});return T.add(n),n}p(Z,"assertRecord");function*q(e){const t=[],r=new Set;return yield*f(e,n=>{const o=Z(n);if(r.has(o.uuid))throw new Error("cloud entity snapshot has duplicate UUIDs");r.add(o.uuid),t.push(o)}),t}p(q,"assertedRecordsSteps");function*g(e){const t=yield*B(yield*q(e),(r,n)=>r.uuid<n.uuid?-1:r.uuid>n.uuid?1:0);return{schemaVersion:S,kind:"amalgm-entity-registry",records:t}}p(g,"snapshotFromRecordsSteps");function m(e){return y(g(e))}p(m,"snapshotFromRecords");function*b(e,t){const r=new Map;yield*f(e,i=>{if(i.parentUUID===null)return;const s=r.get(i.parentUUID);s?s.push(i):r.set(i.parentUUID,[i])});const n=new Set([t]),o=[t];let l=0;for(;o.length>0;){for(const i of r.get(o.pop())??[])n.has(i.uuid)||(n.add(i.uuid),o.push(i.uuid));++l%E===0&&(yield)}const u=[];return yield*f(e,i=>{n.has(i.uuid)&&u.push(i)}),u}p(b,"containedRecordsSteps");function dt(e,t){return y(b(e,t))}p(dt,"containedRecords");function*K(e,t){const r=yield*b((yield*g(e)).records,t),n=new Map;yield*f(r,a=>n.set(a.uuid,a));const o=n.get(t);if(!o||o.status!=="active")return[];if(!w.has(o.type))throw new Error(`cloud materialization root ${o.uuid} is not a container`);const l=new Map;yield*f(r,a=>{if(a.uuid===o.uuid)return;if(a.parentUUID===null)throw new Error(`cloud materialization entity ${a.uuid} escapes its selected root`);if(!n.get(a.parentUUID))throw new Error(`cloud materialization entity ${a.uuid} has incomplete ancestry`);const U=l.get(a.parentUUID);U?U.push(a):l.set(a.parentUUID,[a])});const u=new Set,i=[o];let s=0;for(;i.length>0;){const a=i.pop();if(!(a.status!=="active"||u.has(a.uuid))&&(u.add(a.uuid),!!w.has(a.type))){for(const d of l.get(a.uuid)??[])d.status==="active"&&i.push(d);++s%E===0&&(yield)}}const c=[];return yield*f(r,a=>{u.has(a.uuid)&&c.push(a)}),c}p(K,"materializableRecordsSteps");function Q(e,t){return y(K(e,t))}p(Q,"materializableRecords");function ft(e,t){const r=e??[];if(!Array.isArray(r)||r.some(o=>typeof o!="string"||!h.test(o)))throw new Error(`${t} names invalid waiting entities`);const n=r.map(o=>o.toLowerCase());if(new Set(n).size!==n.length)throw new Error(`${t} names a waiting entity twice`);return n}p(ft,"waitingEntities");function ht(e,t,r,n,o=[]){const l=W(e,r),u=Q(r,n),i=new Set(u.map(({uuid:s})=>s));return t.some(({uuid:s})=>i.has(s))?!1:R(l,X(u,n,o))&&R([...u,...t],r)}p(ht,"installedSubtree");function X(e,t,r){if(r.length===0)return e;const n=new Map(e.map(i=>[i.uuid,i])),o=new Set(r);for(const i of o)if(i===t||!n.has(i))throw new Error("a waiting entity is not one the placement places beneath its root");const l=new Map,u=p(i=>{const s=[];let c=i,a=!1;for(;c!==void 0;){const d=l.get(c.uuid);if(d!==void 0){a=d;break}if(o.has(c.uuid)){a=!0,s.push(c.uuid);break}s.push(c.uuid),c=c.parentUUID===null?void 0:n.get(c.parentUUID)}for(const d of s)l.set(d,a);return a},"waitsBeneath");return e.filter(i=>!u(i))}p(X,"withoutWaiting");const x=Symbol("parent cycle"),v=Symbol("incomplete ancestry");function tt(e){const t=new Map;return r=>{const n=[],o=new Set;let l=r,u;for(;;){const i=t.get(l.uuid);if(i!==void 0){u=i;break}if(l.parentUUID===null){u=l.uuid;break}if(o.has(l.uuid)){u=x;break}o.add(l.uuid),n.push(l.uuid);const s=e.get(l.parentUUID);if(!s){u=v;break}l=s}for(const i of n)t.set(i,u);return u}}p(tt,"createRootResolver");function yt(e,t){return y(et(e,t))}p(yt,"completeRootsFromRecords");function*et(e,t){if(e.length===0)throw new Error("cloud root set has no roots");const r=e.map(s=>{if(!h.test(s))throw new Error("cloud root set has an invalid root UUID");return s.toLowerCase()}).sort();if(new Set(r).size!==r.length)throw new Error("cloud root set has duplicate roots");const n=yield*g(t),o=new Map;yield*f(n.records,s=>{o.set(s.uuid,s)});const l=new Set(r),u=n.records.filter(s=>s.parentUUID===null).map(s=>s.uuid).sort();if(u.length!==r.length||u.some((s,c)=>s!==r[c]))throw new Error("cloud root set records do not exactly match its roots");const i=tt(o);return yield*f(n.records,s=>{if(s.parentUUID!==null){const a=o.get(s.parentUUID);if(!a||s.status==="active"&&!w.has(a.type))throw new Error(`cloud root set entity ${s.uuid} has no container parent`)}const c=i(s);if(c===x)throw J("cloud root set has a parent cycle","graph-cycle","parent-cycle");if(c===v)throw new Error(`cloud root set entity ${s.uuid} has incomplete ancestry`);if(!l.has(c))throw new Error(`cloud root set entity ${s.uuid} is outside its declared roots`)}),n.records}p(et,"completeRootsFromRecordsSteps");function mt(e){let t;try{t=JSON.parse(typeof e=="string"?e:A(e))}catch{throw new Error("cloud entity snapshot is not JSON")}if(t?.schemaVersion!==S||t?.kind!=="amalgm-entity-registry"||!Array.isArray(t.records))throw new Error("cloud entity snapshot has an unsupported shape");return m(t.records)}p(mt,"parseSnapshot");export{j as ENTITY_CLOUD_CONTRACT,S as ENTITY_CLOUD_SCHEMA_VERSION,Z as assertRecord,q as assertedRecordsSteps,yt as completeRootsFromRecords,et as completeRootsFromRecordsSteps,dt as containedRecords,b as containedRecordsSteps,ht as installedSubtree,pt as isPrivateEntityResourceId,Q as materializableRecords,K as materializableRecordsSteps,mt as parseSnapshot,lt as privateEntityResourceId,ct as sameRecord,R as sameRecords,m as snapshotFromRecords,g as snapshotFromRecordsSteps,I as stableJson,W as statedRecords,ft as waitingEntities,X as withoutWaiting};
@@ -1 +1 @@
1
- var c=Object.defineProperty;var p=(o,e)=>c(o,"name",{value:e,configurable:!0});import{assertRecord as f,snapshotFromRecordsSteps as U}from"./cloud.js";import{playChange as D}from"../clash/bodmas.js";import{membershipVersion as S}from"./rules.js";import{DERIVED_PAYLOAD as m}from"./types.js";import{eachStep as y,finishSteps as I,ITEMS_PER_BOUNDARY as g,sortSteps as v}from"../steps.js";class l{static{p(this,"Reduction")}sha256Hex;#e=new Map;#t=new Map;#s=new Set;constructor(e){this.sha256Hex=e}static*openSteps(e,t){const s=new l(t);return yield*y((yield*U(e)).records,n=>s.#i(n)),s}get touched(){return this.#s}touches(e){return this.#s.has(e)}row(e){return this.#e.get(e)}childrenOf(e){return[...this.#t.get(e)??[]]}*playSteps(e){const t=new Set,s=p((n,u)=>{const i=new Set;for(let r=u;r!==null&&!i.has(r);r=this.#e.get(r)?.parentUUID??null){if(r===n)return!0;i.add(r)}return!1},"loops");for(let n=0;n<e.length;n+=1){const{facets:u,result:i,joins:r}=e[n],d=this.#e.get(i.uuid)??null,h=d!==null&&i.parentUUID!==null&&u.includes("move")&&s(i.uuid,i.parentUUID)?{keeps:d.parentUUID}:void 0,{row:a}=D(d,{facets:u,result:f(i),joins:r},this.sha256Hex,h);a!==null&&a!==d&&this.#n(a,t),(n+1)%g===0&&(yield)}yield*this.#r(t)}#n(e,t){const s=this.#e.get(e.uuid);s?.parentUUID&&t.add(s.parentUUID),e.parentUUID!==null&&t.add(e.parentUUID),t.add(e.uuid),this.#i(e)}*#r(e){for(const t of e){this.#s.add(t);const s=this.#e.get(t);if(!s||!m.has(s.type))continue;const n=this.childrenOf(t).map(i=>this.#e.get(i)).filter(({status:i})=>i==="active"),u=S(s,n,this.sha256Hex);u!==s.version&&this.#e.set(t,{...s,version:u}),yield}}*recordsSteps(){return yield*v(this.#e.values(),(e,t)=>e.uuid<t.uuid?-1:e.uuid>t.uuid?1:0)}#i(e){const t=this.#e.get(e.uuid);if(t?.parentUUID&&this.#t.get(t.parentUUID)?.delete(e.uuid),this.#e.set(e.uuid,e),e.parentUUID===null)return;const s=this.#t.get(e.parentUUID);s?s.add(e.uuid):this.#t.set(e.parentUUID,new Set([e.uuid]))}}function*x(o,e,t){const s=yield*l.openSteps(o,t);return yield*s.playSteps(e),{records:yield*s.recordsSteps(),touched:s.touched}}p(x,"playChangesSteps");function C(o,e,t){return I(x(o,e,t)).records}p(C,"playChanges");export{l as Reduction,C as playChanges,x as playChangesSteps};
1
+ var c=Object.defineProperty;var p=(o,e)=>c(o,"name",{value:e,configurable:!0});import{assertRecord as f,snapshotFromRecordsSteps as U}from"./cloud.js";import{playChange as D}from"../clash/bodmas.js";import{membershipVersion as S}from"./rules.js";import{DERIVED_PAYLOAD as g}from"./types.js";import{eachStep as m,finishSteps as y,ITEMS_PER_BOUNDARY as I,sortSteps as v}from"../steps.js";class l{static{p(this,"Reduction")}sha256Hex;#e=new Map;#t=new Map;#s=new Set;constructor(e){this.sha256Hex=e}static*openSteps(e,t){const s=new l(t);return yield*m((yield*U(e)).records,n=>s.#i(n)),s}get touched(){return this.#s}touches(e){return this.#s.has(e)}row(e){return this.#e.get(e)}childrenOf(e){return[...this.#t.get(e)??[]]}*playSteps(e){const t=new Set,s=p((n,u)=>{const r=new Set;for(let i=u;i!==null&&!r.has(i);i=this.#e.get(i)?.parentUUID??null){if(i===n)return!0;r.add(i)}return!1},"loops");for(let n=0;n<e.length;n+=1){const u=e[n],{facets:r,result:i}=u,d=this.#e.get(i.uuid)??null,h=d!==null&&i.parentUUID!==null&&r.includes("move")&&s(i.uuid,i.parentUUID)?{keeps:d.parentUUID}:void 0,{row:a}=D(d,{...u,result:f(i)},this.sha256Hex,h);a!==null&&a!==d&&this.#n(a,t),(n+1)%I===0&&(yield)}yield*this.#r(t)}#n(e,t){const s=this.#e.get(e.uuid);s?.parentUUID&&t.add(s.parentUUID),e.parentUUID!==null&&t.add(e.parentUUID),t.add(e.uuid),this.#i(e)}*#r(e){for(const t of e){this.#s.add(t);const s=this.#e.get(t);if(!s||!g.has(s.type))continue;const n=this.childrenOf(t).map(r=>this.#e.get(r)).filter(({status:r})=>r==="active"),u=S(s,n,this.sha256Hex);u!==s.version&&this.#e.set(t,{...s,version:u}),yield}}*recordsSteps(){return yield*v(this.#e.values(),(e,t)=>e.uuid<t.uuid?-1:e.uuid>t.uuid?1:0)}#i(e){const t=this.#e.get(e.uuid);if(t?.parentUUID&&this.#t.get(t.parentUUID)?.delete(e.uuid),this.#e.set(e.uuid,e),e.parentUUID===null)return;const s=this.#t.get(e.parentUUID);s?s.add(e.uuid):this.#t.set(e.parentUUID,new Set([e.uuid]))}}function*x(o,e,t){const s=yield*l.openSteps(o,t);return yield*s.playSteps(e),{records:yield*s.recordsSteps(),touched:s.touched}}p(x,"playChangesSteps");function C(o,e,t){return y(x(o,e,t)).records}p(C,"playChanges");export{l as Reduction,C as playChanges,x as playChangesSteps};
@@ -5,11 +5,6 @@ export declare function portableFileMode(type: EntityType, mode: number | null |
5
5
  export declare function validPortableFileMode(type: EntityType, mode: unknown): mode is PortableFileMode | null;
6
6
  export declare function portableMtime(type: EntityType, mtimeNs: bigint): PortableMtime | null;
7
7
  export declare function validPortableMtime(type: EntityType, mtime: unknown, absent?: boolean): mtime is PortableMtime | null;
8
- export declare function fileAbsent(row: {
9
- readonly type: EntityType;
10
- readonly payloadVersion?: string | null;
11
- readonly fileMode?: PortableFileMode | null;
12
- }): boolean;
13
8
  export declare function validFileState(type: EntityType, payloadVersion: string | null, mode: unknown): boolean;
14
9
  export declare function validPortableSize(type: EntityType, payloadVersion: string | null, size: unknown): size is number | null;
15
10
  export declare function validLinkTarget(type: EntityType, payloadVersion: string | null, target: unknown): target is string | null;
@@ -1 +1 @@
1
- var M=Object.defineProperty;var i=(e,t)=>M(e,"name",{value:t,configurable:!0});import{eachStep as y,finishSteps as N,ITEMS_PER_BOUNDARY as g,sortSteps as E}from"../steps.js";import{isGitHome as U}from"../git/state.js";const d=new Set(["file.text","file.binary"]);function B(e,t){return d.has(e)?((t??0)&73)===0?420:493:null}i(B,"portableFileMode");function F(e,t){return d.has(e)?t===420||t===493:t===null}i(F,"validPortableFileMode");const H=/^(?:0|-?[1-9][0-9]{0,21})$/;function C(e,t){return d.has(e)?t.toString():null}i(C,"portableMtime");function T(e,t,n=!1){return!d.has(e)||n?t===null:typeof t=="string"&&H.test(t)}i(T,"validPortableMtime");function J(e){return d.has(e.type)&&(e.payloadVersion??null)===null&&(e.fileMode??null)===null}i(J,"fileAbsent");function _(e,t,n){return F(e,n)||d.has(e)&&n===null&&t===null}i(_,"validFileState");function R(e,t,n){return d.has(e)&&t!==null?typeof n=="number"&&Number.isSafeInteger(n)&&n>=0:n===null}i(R,"validPortableSize");function X(e,t,n){return e==="link"&&t!==null?typeof n=="string":n===null}i(X,"validLinkTarget");function q(e,t,n){return t===null&&n===null||e==="repo.git"&&U({entity:t,path:n})}i(q,"validGitHome");const z=i(e=>e.gitHomePath==null?null:{entity:e.gitHomeEntity,path:e.gitHomePath},"recordGitHome");function I(e,t){const n=t(e);if(!n)throw new Error(`no entity ${e}`);return n}i(I,"mustGet");function k({type:e,parentUUID:t=null,name:n,status:o,payloadVersion:r=null,fileMode:u=null,mtime:f=null},h){if(!_(e,r,u))throw new Error(`canonical ${e} state has an invalid portable file mode`);if(!T(e,f,u===null&&r===null))throw new Error(`canonical ${e} state has an invalid portable modified time`);return h(JSON.stringify([e,t,n,o,u===null?r:[r,u,f]]))}i(k,"canonicalVersion");function V(e){return typeof e=="string"&&e!==""&&e!=="."&&e!==".."&&!e.includes("/")&&!e.includes("\0")}i(V,"isName");function G(e,t){const n=[],o=new Set;let r=e;for(;r!==null;){if(o.has(r))throw new Error(`registry corrupt: parent cycle at ${r}`);o.add(r),n.push(r),r=I(r,t).parentUuid}return n}i(G,"ancestorsOf");function K(e,t){const n=[e.status,...G(e.parentUuid,t).map(o=>I(o,t).status)];return n.includes("deleted")?"deleted":n.includes("trashed")?"trashed":e.status}i(K,"effectiveStatusOf");const w=i((e,t)=>e<t?-1:e>t?1:0,"codeUnitOrder");function L(e,t){const n=[...e].sort((o,r)=>w(o.uuid,r.uuid)).map(o=>[o.uuid,o.name]);return t(JSON.stringify(n))}i(L,"membershipHash");function Q(e,t,n){return k({type:e.type,parentUUID:e.parentUUID??null,name:e.name,status:e.status,payloadVersion:L(t,n)},n)}i(Q,"membershipVersion");const D=new Set(["file.text","file.binary","link"]);function W(e){return N(O(e,!1)).names}i(W,"materializedSlotNames");function Z(e){return O(e,!0)}i(Z,"materializedSlotProjectionSteps");function*O(e,t){const n=new Map;yield*y(e,l=>{const x=n.get(l.name);x?x.push(l):n.set(l.name,[l])});const o=new Map,r=new Map,u=[];yield*y(n,l=>{l[1].length>1?u.push(l):t&&r.set(l[1][0].uuid,new Set([l[1][0].uuid]))});const f=new Map;let h=0;for(const[l,x]of yield*E(u,([S],[p])=>w(S,p))){const S=yield*E(x,(s,a)=>w(s.uuid,a.uuid)),p=t?new Set(x.map(s=>s.uuid)):null;p&&r.set(S[0].uuid,p);for(const s of S.slice(1)){const a=p?new Set(p):null;let m=1,c=P(l,s.type,m);for(;n.has(c)||f.has(c);){if(a){const b=f.get(c);if(b!==void 0)a.add(b);else for(const v of n.get(c))a.add(v.uuid)}m+=1,c=P(l,s.type,m),++h%g===0&&(yield)}f.set(c,s.uuid),o.set(s.uuid,c),a&&r.set(s.uuid,a),++h%g===0&&(yield)}}return{names:o,dependencies:r}}i(O,"projectMaterializedSlotsSteps");function P(e,t,n){const o=D.has(t)?e.lastIndexOf("."):0;return o>0?`${e.slice(0,o)} (${n})${e.slice(o)}`:`${e} (${n})`}i(P,"collisionCandidate");const $=/ \(([1-9][0-9]*)\)$/;function ee(e){const t=new Set,n=$.exec(e);n&&n.index>0&&t.add(e.slice(0,n.index));const o=e.lastIndexOf("."),r=o>0?$.exec(e.slice(0,o)):null;return r&&r.index>0&&t.add(e.slice(0,r.index)+e.slice(o)),[...t]}i(ee,"collisionBases");export{G as ancestorsOf,k as canonicalVersion,ee as collisionBases,K as effectiveStatusOf,J as fileAbsent,V as isName,W as materializedSlotNames,Z as materializedSlotProjectionSteps,L as membershipHash,Q as membershipVersion,I as mustGet,B as portableFileMode,C as portableMtime,z as recordGitHome,_ as validFileState,q as validGitHome,X as validLinkTarget,F as validPortableFileMode,T as validPortableMtime,R as validPortableSize};
1
+ var M=Object.defineProperty;var r=(t,e)=>M(t,"name",{value:e,configurable:!0});import{eachStep as g,finishSteps as N,ITEMS_PER_BOUNDARY as y,sortSteps as E}from"../steps.js";import{isGitHome as U}from"../git/state.js";const p=new Set(["file.text","file.binary"]);function C(t,e){return p.has(t)?((e??0)&73)===0?420:493:null}r(C,"portableFileMode");function F(t,e){return p.has(t)?e===420||e===493:e===null}r(F,"validPortableFileMode");const H=/^(?:0|-?[1-9][0-9]{0,21})$/;function J(t,e){return p.has(t)?e.toString():null}r(J,"portableMtime");function T(t,e,n=!1){return!p.has(t)||n?e===null:typeof e=="string"&&H.test(e)}r(T,"validPortableMtime");function _(t,e,n){return F(t,n)||p.has(t)&&n===null&&e===null}r(_,"validFileState");function R(t,e,n){return p.has(t)&&e!==null?typeof n=="number"&&Number.isSafeInteger(n)&&n>=0:n===null}r(R,"validPortableSize");function X(t,e,n){return t==="link"&&e!==null?typeof n=="string":n===null}r(X,"validLinkTarget");function q(t,e,n){return e===null&&n===null||t==="repo.git"&&U({entity:e,path:n})}r(q,"validGitHome");const z=r(t=>t.gitHomePath==null?null:{entity:t.gitHomeEntity,path:t.gitHomePath},"recordGitHome");function I(t,e){const n=e(t);if(!n)throw new Error(`no entity ${t}`);return n}r(I,"mustGet");function k({type:t,parentUUID:e=null,name:n,status:o,payloadVersion:i=null,fileMode:l=null,mtime:d=null},S){if(!_(t,i,l))throw new Error(`canonical ${t} state has an invalid portable file mode`);if(!T(t,d,l===null&&i===null))throw new Error(`canonical ${t} state has an invalid portable modified time`);return S(JSON.stringify([t,e,n,o,l===null?i:[i,l,d]]))}r(k,"canonicalVersion");function A(t){return typeof t=="string"&&t!==""&&t!=="."&&t!==".."&&!t.includes("/")&&!t.includes("\0")}r(A,"isName");function G(t,e){const n=[],o=new Set;let i=t;for(;i!==null;){if(o.has(i))throw new Error(`registry corrupt: parent cycle at ${i}`);o.add(i),n.push(i),i=I(i,e).parentUuid}return n}r(G,"ancestorsOf");function K(t,e){const n=[t.status,...G(t.parentUuid,e).map(o=>I(o,e).status)];return n.includes("deleted")?"deleted":n.includes("trashed")?"trashed":t.status}r(K,"effectiveStatusOf");const w=r((t,e)=>t<e?-1:t>e?1:0,"codeUnitOrder");function L(t,e){const n=[...t].sort((o,i)=>w(o.uuid,i.uuid)).map(o=>[o.uuid,o.name]);return e(JSON.stringify(n))}r(L,"membershipHash");function Q(t,e,n){return k({type:t.type,parentUUID:t.parentUUID??null,name:t.name,status:t.status,payloadVersion:L(e,n)},n)}r(Q,"membershipVersion");const D=new Set(["file.text","file.binary","link"]);function V(t){return N(O(t,!1)).names}r(V,"materializedSlotNames");function W(t){return O(t,!0)}r(W,"materializedSlotProjectionSteps");function*O(t,e){const n=new Map;yield*g(t,s=>{const x=n.get(s.name);x?x.push(s):n.set(s.name,[s])});const o=new Map,i=new Map,l=[];yield*g(n,s=>{s[1].length>1?l.push(s):e&&i.set(s[1][0].uuid,new Set([s[1][0].uuid]))});const d=new Map;let S=0;for(const[s,x]of yield*E(l,([h],[f])=>w(h,f))){const h=yield*E(x,(u,a)=>w(u.uuid,a.uuid)),f=e?new Set(x.map(u=>u.uuid)):null;f&&i.set(h[0].uuid,f);for(const u of h.slice(1)){const a=f?new Set(f):null;let m=1,c=P(s,u.type,m);for(;n.has(c)||d.has(c);){if(a){const b=d.get(c);if(b!==void 0)a.add(b);else for(const v of n.get(c))a.add(v.uuid)}m+=1,c=P(s,u.type,m),++S%y===0&&(yield)}d.set(c,u.uuid),o.set(u.uuid,c),a&&i.set(u.uuid,a),++S%y===0&&(yield)}}return{names:o,dependencies:i}}r(O,"projectMaterializedSlotsSteps");function P(t,e,n){const o=D.has(e)?t.lastIndexOf("."):0;return o>0?`${t.slice(0,o)} (${n})${t.slice(o)}`:`${t} (${n})`}r(P,"collisionCandidate");const $=/ \(([1-9][0-9]*)\)$/;function Z(t){const e=new Set,n=$.exec(t);n&&n.index>0&&e.add(t.slice(0,n.index));const o=t.lastIndexOf("."),i=o>0?$.exec(t.slice(0,o)):null;return i&&i.index>0&&e.add(t.slice(0,i.index)+t.slice(o)),[...e]}r(Z,"collisionBases");export{G as ancestorsOf,k as canonicalVersion,Z as collisionBases,K as effectiveStatusOf,A as isName,V as materializedSlotNames,W as materializedSlotProjectionSteps,L as membershipHash,Q as membershipVersion,I as mustGet,C as portableFileMode,J as portableMtime,z as recordGitHome,_ as validFileState,q as validGitHome,X as validLinkTarget,F as validPortableFileMode,T as validPortableMtime,R as validPortableSize};
@@ -4,3 +4,31 @@ export interface UnitPlace {
4
4
  readonly parentUUID: string | null;
5
5
  }
6
6
  export declare function unitOf(uuid: string, place: (uuid: string) => UnitPlace | undefined, known?: Map<string, string | null>): string;
7
+ export interface ProjectPlace extends UnitPlace {
8
+ readonly uuid: string;
9
+ readonly name: string;
10
+ }
11
+ export interface ProjectPath<P extends ProjectPlace> {
12
+ readonly project: P;
13
+ readonly path: string;
14
+ }
15
+ type Walked<P extends Spoken> = {
16
+ readonly project: P;
17
+ readonly path: string;
18
+ } | null | undefined;
19
+ type Spoken = {
20
+ readonly uuid: string;
21
+ readonly type: string;
22
+ readonly parentUUID: string | null;
23
+ readonly name?: string;
24
+ };
25
+ type Read<P> = P | null | undefined;
26
+ type Located = {
27
+ readonly uuid: string;
28
+ readonly name: string;
29
+ readonly parentUUID: string | null;
30
+ };
31
+ export declare function projectPath<P extends ProjectPlace>(entity: Located, place: (uuid: string) => Read<P>): Walked<P>;
32
+ export declare function projectAt<P extends Spoken>(at: string | null, place: (uuid: string) => Read<P>): P | null;
33
+ export declare function readProjectPath<P extends ProjectPlace>(entity: Located, place: (uuid: string) => Read<P> | Promise<Read<P>>): Promise<Walked<P>>;
34
+ export {};
@@ -1 +1 @@
1
- var d=Object.defineProperty;var s=(t,n)=>d(t,"name",{value:n,configurable:!0});function c(t,n,a=new Map){const f=new Set;let r=null;for(let e=t;e!==null;){const i=a.get(e);if(i!==void 0){r=i;break}if(f.has(e))break;const o=n(e);if(!o)break;if(f.add(e),o.type==="repo.git"){r=e;break}e=o.parentUUID}for(const e of f)a.set(e,r);return r??t}s(c,"unitOf");export{c as unitOf};
1
+ var c=Object.defineProperty;var u=(e,n)=>c(e,"name",{value:n,configurable:!0});function s(e,n,r=new Map){const t=new Set;let a=null;for(let o=e;o!==null;){const l=r.get(o);if(l!==void 0){a=l;break}if(t.has(o))break;const f=n(o);if(!f)break;if(t.add(o),f.type==="repo.git"){a=o;break}o=f.parentUUID}for(const o of t)r.set(o,a);return a??e}u(s,"unitOf");function*i(e,n,r){for(;e!==null;){if(r.has(e))return;r.add(e);const t=yield e;if(!t)return;if(t.type==="repo.git")return{project:t,path:n?.reverse().join("/")??""};n?.push(t.name),e=t.parentUUID}return null}u(i,"projectWalk");function p(e,n){for(let r=e.next();;){if(r.done)return r.value;r=e.next(n(r.value))}}u(p,"walked");function x(e,n){return p(i(e.parentUUID,[e.name],new Set([e.uuid])),n)}u(x,"projectPath");function U(e,n){return p(i(e,null,new Set),n)?.project??null}u(U,"projectAt");async function h(e,n){const r=i(e.parentUUID,[e.name],new Set([e.uuid]));for(let t=r.next();;){if(t.done)return t.value;t=r.next(await n(t.value))}}u(h,"readProjectPath");export{U as projectAt,x as projectPath,h as readProjectPath,s as unitOf};
@@ -1,8 +1,9 @@
1
1
  import type { PlayableChange } from '../clash/bodmas.js';
2
2
  import type { ChangeFacet } from '../detection/record-proposal.js';
3
3
  import { type HeadPoints } from '../entities/accepted-view.js';
4
- import type { CloudEntityRecord } from '../entities/cloud.js';
4
+ import { type CloudEntityRecord } from '../entities/cloud.js';
5
5
  import type { GraphPageRef } from '../entities/graph-pages.js';
6
+ import type { GitSizes } from '../git/artifact.js';
6
7
  import type { Sha256Hex } from '../entities/types.js';
7
8
  import { type FilesBody } from './browse-types.js';
8
9
  import type { CloudFilesPort } from './cloud-files.js';
@@ -16,6 +17,7 @@ export interface AcceptedFilesState {
16
17
  }
17
18
  export interface AcceptedFilesHost {
18
19
  open(): Promise<AcceptedFilesState>;
20
+ checkout(transport: string): Promise<GitSizes | null>;
19
21
  content(input: {
20
22
  readonly contentHash: string;
21
23
  readonly bytes: number;
@@ -1 +1 @@
1
- var k=Object.defineProperty;var f=(t,r)=>k(t,"name",{value:r,configurable:!0});import{AcceptedView as b}from"../entities/accepted-view.js";import{utf8Encode as U}from"../entities/bytes.js";import{unpack as E}from"../entities/package-pages.js";import{fileAbsent as v}from"../entities/rules.js";import{findUserGroundRoot as R}from"../registration/user-ground.js";import{artifactForRecord as F}from"../transfer/artifacts.js";import{FilesRequestError as y,canonicalUserEmail as I}from"./browse-types.js";import{filesMediaType as M}from"./media-type.js";async function O(t,r,n){const i=f(o=>o.replay.kind==="package"?o.replay.pages??[]:[],"pagesOf"),s=new Map;for(const o of t)for(const e of i(o))s.set(e.sha256,e);const l=[...s.values()],p=await r(l);if(p.length!==l.length)throw new Error("package pages were read short");const h=new Map(l.map((o,e)=>[o.sha256,p[e]]));return t.flatMap(o=>o.replay.kind==="package"?E(o.result,i(o),e=>h.get(e.sha256),n).map(e=>({facets:["create"],result:e})):[{facets:o.facets,result:o.result,...o.joins===void 0?{}:{joins:o.joins}}])}f(O,"statedResults");function S(t,r,n){return n(`amalgm-files-accepted:${t}:${r}`)}f(S,"acceptedFilesChecksum");async function g(t,r){const n=new b(t.head,r);await n.advance(t.tail);const i=new Set(t.head.rootIds());for(const{result:s}of t.tail)s.parentUUID===null&&i.add(s.uuid);return{view:n,rows:await n.rows([...i])}}f(g,"acceptedRoots");async function P(t,r){const{view:n,rows:i}=await g(t,r),s=[];for(const l of i.values())l.parentUUID===null&&s.push(...await n.subtree(l.uuid));return s}f(P,"acceptedFilesRecords");function V(t,r,n){const i=I(t);let s=null,l=new Set;const p=[],h=new Map,o=f(e=>{if(s===null||s.checksum!==e.checksum)throw new Error("cloud files asked about a head this port did not open");return s.view},"viewOf");return{async openActiveHead(){if(s!==null)throw new Error("a cloud files port opens one accepted state");const e=await r.open();if(!Number.isSafeInteger(e.through)||e.through<0)throw new Error("accepted files state has an invalid delivery position");const{view:u,rows:c}=await g(e,n),d=R(c.values(),i);if(d===null)throw new y(404,"ground_not_found","this account has no cloud files yet");const w=S(e.headChecksum,e.through,n);return s={checksum:w,view:u},l=new Set([...c.values()].filter(a=>a.parentUUID===null).map(({uuid:a})=>a)),p.push(d),{checksum:w,version:e.through,root:c.get(d)}},async list({head:e,parentId:u}){const c=o(e),[d,w]=await Promise.all([c.row(u),c.children(u)]);return{directory:d,entries:w.filter(a=>a.status==="active"&&!v(a))}},async entry({head:e,entityId:u}){const c=await o(e).row(u);return c?.status==="active"&&!v(c)?c:null},async read({head:e,entity:u}){return o(e),T(u,r)},async referenceTo({head:e,targetId:u}){const c=o(e);for(;!h.has(u)&&p.length>0;){const d=p.shift(),w=new Set([d]);for(const a of await c.subtree(d)){if(a.status!=="active"||!w.has(a.parentUUID))continue;w.add(a.uuid);const m=a.type==="reference"?a.payloadVersion?.toLowerCase()??null:null;m===null||!l.has(m)||m===e.root.uuid||h.has(m)||(h.set(m,a),p.push(m))}}return h.get(u)??null}}}f(V,"acceptedFilesPort");async function T(t,r){if(t.type==="link"){const i=U(t.linkTarget??"");return{body:i,mediaType:"text/plain; charset=utf-8",bytes:i.byteLength,version:t.version}}const n=F(t);if(n===null||t.size===null)throw new y(409,"content_pending","this file's bytes are not in the cloud as a file");return{body:await r.content({contentHash:n.contentHash,bytes:t.size}),mediaType:M(t.name),bytes:t.size,version:t.version}}f(T,"readEntity");export{S as acceptedFilesChecksum,V as acceptedFilesPort,P as acceptedFilesRecords,O as statedResults};
1
+ var U=Object.defineProperty;var u=(n,a)=>U(n,"name",{value:a,configurable:!0});import{AcceptedView as E}from"../entities/accepted-view.js";import{utf8Encode as T}from"../entities/bytes.js";import{sameRecord as I}from"../entities/cloud.js";import{unpack as R}from"../entities/package-pages.js";import{materializedSlotNames as S}from"../entities/rules.js";import{CheckoutView as _}from"../git/checkout-view.js";import{findUserGroundRoot as x}from"../registration/user-ground.js";import{artifactForRecord as z}from"../transfer/artifacts.js";import{FilesRequestError as g,canonicalUserEmail as D}from"./browse-types.js";import{filesMediaType as C}from"./media-type.js";async function B(n,a,i){const f=u(r=>r.replay.kind==="package"?r.replay.pages??[]:[],"pagesOf"),c=new Map;for(const r of n)for(const l of f(r))c.set(l.sha256,l);const p=[...c.values()],w=await a(p);if(w.length!==p.length)throw new Error("package pages were read short");const m=new Map(p.map((r,l)=>[r.sha256,w[l]]));return n.flatMap(r=>r.replay.kind==="package"?R(r.result,f(r),l=>m.get(l.sha256),i).map(l=>({facets:["create"],result:l})):[{facets:r.facets,result:r.result,...r.joins===void 0?{}:{joins:r.joins}}])}u(B,"statedResults");function F(n,a,i){return i(`amalgm-files-accepted:${n}:${a}`)}u(F,"acceptedFilesChecksum");async function b(n,a){const i=new E(n.head,a);await i.advance(n.tail);const f=new Set(n.head.rootIds());for(const{result:c}of n.tail)c.parentUUID===null&&f.add(c.uuid);return{view:i,rows:await i.rows([...f])}}u(b,"acceptedRoots");async function J(n,a){const{view:i,rows:f}=await b(n,a),c=[];for(const p of f.values())p.parentUUID===null&&c.push(...await i.subtree(p.uuid));return c}u(J,"acceptedFilesRecords");function K(n,a,i){const f=D(n);let c=null,p=new Set;const w=[],m=new Map;let r;const l=u(async t=>{if(t==null)return null;const e=await r.presence(t);if(e===!1)return null;if(e===void 0)throw new g(503,"checkout_pending","The checkout index is unavailable.");return t},"shown"),k=u(async t=>(await Promise.all(t.map(l))).filter(e=>e!==null),"visibleChildren"),v=u(t=>{if(c===null||c.checksum!==t.checksum)throw new Error("cloud files asked about a head this port did not open");return c.view},"viewOf");return{async openActiveHead(){if(c!==null)throw new Error("a cloud files port opens one accepted state");const t=await a.open();if(!Number.isSafeInteger(t.through)||t.through<0)throw new Error("accepted files state has an invalid delivery position");const{view:e,rows:o}=await b(t,i),d=x(o.values(),f);if(d===null)throw new g(404,"ground_not_found","this account has no cloud files yet");const h=F(t.headChecksum,t.through,i);return c={checksum:h,view:e},r=new _({row:u(s=>e.row(s),"row"),children:u(s=>e.children(s),"children"),index:u(s=>s.transportVersion===null?null:a.checkout(s.transportVersion),"index")}),p=new Set([...o.values()].filter(s=>s.parentUUID===null).map(({uuid:s})=>s)),w.push(d),{checksum:h,version:t.through,root:o.get(d)}},async list({head:t,parentId:e}){const o=v(t),[d,h]=await Promise.all([o.row(e),o.children(e)]);return{directory:await l(d),entries:await k(h)}},async placementName({head:t,entity:e}){if(e.parentUUID===null)return e.name;const o=await v(t).children(e.parentUUID);return o.some(d=>d.status==="active"&&d.uuid!==e.uuid&&d.name===e.name)?S(await k(o)).get(e.uuid)??e.name:e.name},async entry({head:t,entityId:e}){const o=await v(t).row(e);return l(o)},async checkoutSize({head:t,entity:e}){return v(t),(await r.file(e))?.size??null},async read({head:t,entity:e}){const o=await l(await v(t).row(e.uuid));if(!o)throw new g(404,"entity_not_found","The file is absent at this revision.");if(!I(o,e))throw new g(409,"version_changed","The requested file version differs from this revision.");return M(o,a)},async referenceTo({head:t,targetId:e}){const o=v(t);for(;!m.has(e)&&w.length>0;){const d=w.shift(),h=new Set([d]);for(const s of await o.subtree(d)){if(s.status!=="active"||!h.has(s.parentUUID))continue;h.add(s.uuid);const y=s.type==="reference"?s.payloadVersion?.toLowerCase()??null:null;y===null||!p.has(y)||y===t.root.uuid||m.has(y)||(m.set(y,s),w.push(y))}}return m.get(e)??null}}}u(K,"acceptedFilesPort");async function M(n,a){if(n.type==="link"){const f=T(n.linkTarget??"");return{body:f,mediaType:"text/plain; charset=utf-8",bytes:f.byteLength,version:n.version}}const i=z(n);if(i===null||n.size===null)throw new g(409,"content_pending","this file's bytes are not in the cloud as a file");return{body:await a.content({contentHash:i.contentHash,bytes:n.size}),mediaType:C(n.name),bytes:n.size,version:n.version}}u(M,"readEntity");export{F as acceptedFilesChecksum,K as acceptedFilesPort,J as acceptedFilesRecords,B as statedResults};