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

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 (67) hide show
  1. package/dist/apply/showing.js +1 -1
  2. package/dist/clash/bodmas.d.ts +4 -0
  3. package/dist/clash/bodmas.js +1 -1
  4. package/dist/clash/local-work.d.ts +2 -0
  5. package/dist/clash/local-work.js +1 -1
  6. package/dist/detection/batch.d.ts +2 -2
  7. package/dist/detection/record-order.d.ts +2 -2
  8. package/dist/detection/record-proposal.d.ts +6 -4
  9. package/dist/detection/record-proposal.js +1 -1
  10. package/dist/detection/removals.js +1 -1
  11. package/dist/detection/skip-policy.js +1 -1
  12. package/dist/drive/drive.d.ts +6 -4
  13. package/dist/drive/drive.js +1 -1
  14. package/dist/drive/map-index.d.ts +12 -2
  15. package/dist/drive/map-index.js +1 -1
  16. package/dist/drive/where.d.ts +7 -0
  17. package/dist/drive/where.js +2 -2
  18. package/dist/entities/accepted-view.js +1 -1
  19. package/dist/entities/cloud.d.ts +1 -1
  20. package/dist/entities/cloud.js +1 -1
  21. package/dist/entities/reducer.js +1 -1
  22. package/dist/entities/rules.d.ts +0 -5
  23. package/dist/entities/rules.js +1 -1
  24. package/dist/entities/units.d.ts +33 -0
  25. package/dist/entities/units.js +1 -1
  26. package/dist/files/accepted-files.d.ts +3 -1
  27. package/dist/files/accepted-files.js +1 -1
  28. package/dist/files/browser.js +1 -1
  29. package/dist/files/cloud-files.d.ts +11 -0
  30. package/dist/files/cloud-files.js +1 -1
  31. package/dist/files/trash.js +1 -1
  32. package/dist/git/artifact.d.ts +14 -1
  33. package/dist/git/artifact.js +1 -1
  34. package/dist/git/checkout-view.d.ts +15 -0
  35. package/dist/git/checkout-view.js +1 -0
  36. package/dist/git/checkout.d.ts +31 -0
  37. package/dist/git/checkout.js +1 -0
  38. package/dist/git/holds.js +1 -1
  39. package/dist/git/index.d.ts +2 -0
  40. package/dist/git/index.js +1 -1
  41. package/dist/transfer/download.d.ts +2 -0
  42. package/dist/transfer/download.js +1 -1
  43. package/dist-cjs/apply/showing.js +1 -1
  44. package/dist-cjs/clash/bodmas.js +1 -1
  45. package/dist-cjs/clash/local-work.js +1 -1
  46. package/dist-cjs/detection/record-proposal.js +1 -1
  47. package/dist-cjs/detection/removals.js +1 -1
  48. package/dist-cjs/detection/skip-policy.js +1 -1
  49. package/dist-cjs/drive/drive.js +1 -1
  50. package/dist-cjs/drive/map-index.js +1 -1
  51. package/dist-cjs/drive/where.js +2 -2
  52. package/dist-cjs/entities/accepted-view.js +1 -1
  53. package/dist-cjs/entities/cloud.js +1 -1
  54. package/dist-cjs/entities/reducer.js +1 -1
  55. package/dist-cjs/entities/rules.js +1 -1
  56. package/dist-cjs/entities/units.js +1 -1
  57. package/dist-cjs/files/accepted-files.js +1 -1
  58. package/dist-cjs/files/browser.js +1 -1
  59. package/dist-cjs/files/cloud-files.js +1 -1
  60. package/dist-cjs/files/trash.js +1 -1
  61. package/dist-cjs/git/artifact.js +1 -1
  62. package/dist-cjs/git/checkout-view.js +1 -0
  63. package/dist-cjs/git/checkout.js +1 -0
  64. package/dist-cjs/git/holds.js +1 -1
  65. package/dist-cjs/git/index.js +1 -1
  66. package/dist-cjs/transfer/download.js +1 -1
  67. 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 t=o(e.uuid),n=t?.available===!0,{root:r,returns:a}=m(e,o,u);if(r==="sealed")return"neither";if(r===null)return n?"leave":"neither";if(!n&&r.onDemand){const i=y(s=>s===e.uuid?e:void 0,c(o,a));if(I(e.uuid,i)===e.uuid&&!v(e.uuid,i))return"listed"}return n&&(p.has(t.type)||!p.has(e.type))?"apply":"enter"}f(M,"judgeShowing");function y(e,o){return u=>{const t=e(u);if(t?.parentUUID===null)return{...t,home:o(u)?.home===!0};if(t)return t;const n=o(u);return n?.root?{type:n.type,name:n.name,parentUUID:null,home:n.home}:n}}f(y,"shownUnits");function v(e,o,u=new Map){const t=o(e);if(t?.parentUUID===null)return!0;const n=new Set;let r=null;for(let a=e,i=t;i?.parentUUID!=null&&!n.has(a);){const s=u.get(a);if(s!==void 0){r=s;break}n.add(a);const l=o(i.parentUUID);if(l?.parentUUID===null){r={uuid:a,home:l.home===!0};break}a=i.parentUUID,i=l}for(const a of n)u.set(a,r);return r===null?!1:r.home&&b(o(r.uuid).name,r.uuid!==e)}f(v,"placedInRoot");function N(e,o,u){return m(e,o,u).returns}f(N,"lineReturns");function c(e,o){return o.size===0?e:u=>{const t=e(u),n=o.get(u);return t!==void 0&&n!==void 0?{...t,parentUUID:n}:t}}f(c,"returnedPlaces");const d=new Map;function m(e,o,u){const t=new Map;for(;;){const n=c(o,t),r=x(e,n);if(r===null||r==="sealed")return{root:r,returns:d};if("root"in r)return{root:r.root,returns:t};if(!(u&&r.loop.find(i=>!t.has(i)&&g(i,n,u,t))))return{root:null,returns:d}}}f(m,"showingWalk");function g(e,o,u,t){const n=u(e);return n===void 0||n===o(e)?.parentUUID?!1:(t.set(e,n),!0)}f(g,"returnTo");function x(e,o){if(e.status!=="active"||D(e))return null;if(h(e.type))return{root:w};const u=o(e.uuid);if(u?.root)return u.available?{root:u}:null;const t=[e.uuid],n=new Map([[e.uuid,0]]);for(let r=e.parentUUID;r!==null;){const a=n.get(r);if(a!==void 0)return{loop:t.slice(Math.max(a,1))};n.set(r,t.length),t.push(r);const i=o(r);if(!i||!i.available||!p.has(i.type))return null;if(i.sealed===!0)return"sealed";if(i.root)return{root:i};r=i.parentUUID}return null}f(x,"walkUp");export{A as APPLY_PLAYS,M as judgeShowing,N as lineReturns,v as placedInRoot,c as returnedPlaces,y as shownUnits};
1
+ var U=Object.defineProperty;var 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};
@@ -5,6 +5,10 @@ export interface PlayableChange {
5
5
  readonly facets: readonly ChangeFacet[];
6
6
  readonly result: CloudEntityRecord;
7
7
  readonly joins?: string | undefined;
8
+ readonly replay?: {
9
+ readonly kind: string;
10
+ readonly basedOnTransport?: string | null;
11
+ } | undefined;
8
12
  }
9
13
  export interface Played {
10
14
  readonly row: CloudEntityRecord | null;
@@ -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 o=(t,a)=>P(t,"name",{value:a,configurable:!0});import{canonicalVersion as y,validPortableFileMode as u,validPortableMtime as V}from"../entities/rules.js";import{fileAbsent as d}from"../git/checkout.js";import{CONTAINERS as M}from"../entities/types.js";const b=o(t=>M.has(t)?t:"file","contentKind");function H(t,a,i,p){const{facets:f,result:e}=a;if(a.joins!==void 0)return t!==null&&t.status!=="deleted"&&t.version===a.joins?{row:e,setsPayload:!0}:{row:t,setsPayload:!1};const m=p===void 0?e.parentUUID:p.keeps;if(t===null||f.includes("create")){if(t?.status==="deleted")return{row:t,setsPayload:!1};if(m===e.parentUUID)return{row:e,setsPayload:!0};const n={...e,parentUUID:m};return{row:{...n,version:y(n,i)},setsPayload:!0}}if(t.status==="deleted")return{row:t,setsPayload:!1};let r=t,l=!1;const s=o(n=>{r={...r,...n}},"set"),c=o(()=>{s({type:e.type,fileMode:d(e)||!u(e.type,r.fileMode)?e.fileMode:r.fileMode,mtime:d(e)||!V(e.type,r.mtime)?e.mtime:r.mtime,payloadVersion:e.payloadVersion,size:e.size,linkTarget:e.linkTarget,gitHomeEntity:e.gitHomeEntity,gitHomePath:e.gitHomePath,transportVersion:k.has(e.type)?r.transportVersion??null:e.transportVersion}),l=!0},"becomes");for(const n of f)switch(n){case"move":s({parentUUID:m});break;case"rename":s({name:e.name});break;case"retype":c();break;case"content":b(r.type)===b(e.type)?c():U(r)&&e.type==="repo.git"&&a.replay?.kind==="repo.git"&&a.replay.basedOnTransport===r.transportVersion&&(s({transportVersion:e.transportVersion}),l=!0);break;case"mode":!d(r)&&u(r.type,e.fileMode)&&s({fileMode:e.fileMode});break;case"time":!d(r)&&V(r.type,e.mtime)&&s({mtime:e.mtime});break;case"trash":s({status:"trashed"});break;case"restore":r.status==="trashed"&&s({status:"active"});break;case"delete":s({status:"deleted"});break;case"create":break}return r===t?{row:t,setsPayload:!1}:w(r,t)?{row:{...t,transportVersion:r.transportVersion},setsPayload:l}:w(r,e)?{row:{...e,transportVersion:r.transportVersion},setsPayload:l}:{row:{...r,version:y(r,i)},setsPayload:l}}o(H,"playChange");const U=o(t=>k.has(t.type)&&t.transportVersion!==null,"remembers"),k=new Set(["workspace","folder"]),g=["uuid","type","parentUUID","name","status","payloadVersion","fileMode","mtime","size","linkTarget","gitHomeEntity","gitHomePath"],w=o((t,a)=>g.every(i=>t[i]===a[i])&&(t.type!=="repo.git"||t.transportVersion===a.transportVersion),"sameFields");export{b as contentKind,H as playChange};
@@ -11,6 +11,8 @@ export interface OwnLine {
11
11
  lineBefore(): string | null | undefined;
12
12
  admittedVersion(): string | undefined;
13
13
  playedVersion(): string;
14
+ admittedTransport(): string | undefined;
15
+ playedTransport(): string | undefined;
14
16
  }
15
17
  export declare function ownSettles(head: AcceptedEntityRecord, line: OwnLine): boolean;
16
18
  export declare function showAhead(result: CloudEntityRecord, ahead: readonly PlayableChange[], sha256Hex: Sha256Hex): CloudEntityRecord;
@@ -1 +1 @@
1
- var i=Object.defineProperty;var o=(e,t)=>i(e,"name",{value:t,configurable:!0});import{assertRecord as l}from"../entities/cloud.js";import{playChange as u}from"./bodmas.js";import{clashResolution as a}from"./resolution.js";const g=o((e,t)=>t!==null&&(a(e)==="replace"||t.status!=="active"||t.type!==e),"localWorkWins");function w(e,t){if(a(e.change.result.type)==="replace")return t.admittedVersion()===t.playedVersion();const r=e.change.joins!==void 0?e.change.result.version:e.change.basedOnState;return t.lineBefore()===r}o(w,"ownSettles");const f=new Set(["move","rename","trash","restore","delete"]);function S(e,t,r){let n=e;for(const s of t)s.joins===void 0&&(n=u(n,{facets:s.facets.filter(c=>f.has(c)),result:s.result},r).row);return l(n)}o(S,"showAhead");export{g as localWorkWins,w as ownSettles,S as showAhead};
1
+ var i=Object.defineProperty;var o=(t,e)=>i(t,"name",{value:e,configurable:!0});import{assertRecord as l}from"../entities/cloud.js";import{playChange as p}from"./bodmas.js";import{clashResolution as a}from"./resolution.js";const g=o((t,e)=>e!==null&&(a(t)==="replace"||e.status!=="active"||e.type!==t),"localWorkWins");function y(t,e){if(a(t.change.result.type)==="replace")return e.admittedVersion()===e.playedVersion()&&e.admittedTransport()===e.playedTransport();const n=t.change.joins!==void 0?t.change.result.version:t.change.basedOnState;return e.lineBefore()===n}o(y,"ownSettles");const u=new Set(["move","rename","trash","restore","delete"]);function w(t,e,n){let s=t;for(const r of e)r.joins===void 0&&(s=p(s,{facets:r.facets.filter(c=>u.has(c)),result:r.result,replay:r.replay},n).row);return l(s)}o(w,"showAhead");export{g as localWorkWins,y as ownSettles,w as showAhead};
@@ -1,5 +1,5 @@
1
1
  import type { CloudEntityRecord } from '../entities/cloud.js';
2
- import { type DetectedChangeProposal, type ReplayInstruction } from './record-proposal.js';
2
+ import { type DetectedChangeProposal, type ProposedReplay } from './record-proposal.js';
3
3
  import { type DetectionBatch, type DirectoryCoverageRequest } from './watch-boundary.js';
4
4
  import { type Steps } from '../steps.js';
5
5
  export interface PresentTransition {
@@ -7,7 +7,7 @@ export interface PresentTransition {
7
7
  readonly relPath: string;
8
8
  readonly base: CloudEntityRecord | null;
9
9
  readonly result: CloudEntityRecord;
10
- readonly replay: ReplayInstruction;
10
+ readonly replay: ProposedReplay;
11
11
  readonly lifecycleAuthorization?: 'trash' | 'restore';
12
12
  readonly echo?: true;
13
13
  }
@@ -2,11 +2,11 @@ import type { CloudEntityRecord } from '../entities/cloud.js';
2
2
  import { type Steps } from '../steps.js';
3
3
  import type { SuspicionSnapshot } from '../watching/suspicion.js';
4
4
  import { type DetectionBatchPlan } from './batch.js';
5
- import type { ReplayInstruction } from './record-proposal.js';
5
+ import type { ProposedReplay } from './record-proposal.js';
6
6
  export interface DetectedGroundRow {
7
7
  readonly record: CloudEntityRecord;
8
8
  readonly relativePath: string;
9
- readonly replay?: ReplayInstruction;
9
+ readonly replay?: ProposedReplay;
10
10
  readonly lifecycleAuthorization?: 'trash' | 'restore';
11
11
  readonly gitFollows?: readonly string[];
12
12
  readonly gitHeld?: {
@@ -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@8";
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 {
@@ -41,7 +41,9 @@ export interface RepositoryReplay {
41
41
  readonly kind: 'repo.git';
42
42
  readonly resultPayloadVersion: string;
43
43
  readonly transportVersion: string;
44
+ readonly basedOnTransport: string | null;
44
45
  }
46
+ export type ProposedReplay = Exclude<ReplayInstruction, RepositoryReplay> | Omit<RepositoryReplay, 'basedOnTransport'> | RepositoryReplay;
45
47
  export interface ConstructReplay {
46
48
  readonly kind: ConstructType;
47
49
  readonly resultPayloadVersion: string;
@@ -67,13 +69,13 @@ export interface DetectedChangeProposal {
67
69
  export interface DetectedChangeInput {
68
70
  readonly base: CloudEntityRecord | null;
69
71
  readonly result: CloudEntityRecord;
70
- readonly replay: ReplayInstruction;
72
+ readonly replay: ProposedReplay;
71
73
  readonly lifecycleAuthorization?: 'trash' | 'restore';
72
74
  }
73
75
  export interface IntentionalChangeInput {
74
76
  readonly base: CloudEntityRecord | null;
75
77
  readonly result: CloudEntityRecord;
76
- readonly replay: ReplayInstruction;
78
+ readonly replay: ProposedReplay;
77
79
  }
78
80
  export declare function changeCargo(result: CloudEntityRecord, replay: ReplayInstruction): readonly TransferArtifact[];
79
81
  export type OwnReplay = Exclude<ReplayInstruction, PackageReplay>;
@@ -91,7 +93,7 @@ export declare function turnProposal(input: {
91
93
  export declare function echoProposal(input: {
92
94
  readonly joins: CloudEntityRecord;
93
95
  readonly result: CloudEntityRecord;
94
- readonly replay: ReplayInstruction;
96
+ readonly replay: ProposedReplay;
95
97
  }): DetectedChangeProposal | null;
96
98
  export declare function detectedChangeProposal(input: DetectedChangeInput): DetectedChangeProposal | null;
97
99
  export declare function intentionalChangeProposal(input: IntentionalChangeInput): DetectedChangeProposal | null;
@@ -1 +1 @@
1
- var E=Object.defineProperty;var r=(t,e)=>E(t,"name",{value:e,configurable:!0});import{assertRecord as i}from"../entities/cloud.js";import{CONSTRUCT_TYPES as s,DERIVED_PAYLOAD as p}from"../entities/types.js";import{fileAbsent as u}from"../entities/rules.js";import{checkContentIndex as k,checkContentManifest as V}from"../contracts/content.js";import{artifactForRecord as v,artifactKindForType as P,pageArtifact as z}from"../transfer/artifacts.js";const d="amalgm.detected-change-proposal@7",c=/^[0-9a-f]{64}$/;function h(t,e){if(e.kind==="structure")return[];const n=v(t);if(e.kind==="package")return[...n===null?[]:[n],...e.pages.map(o=>z(t,o))];if(n===null)throw new Error(`${t.type} replay has no transferable artifact`);return[n]}r(h,"changeCargo");function A(t){if(t.replay.kind!=="package")return{replay:t.replay,cargo:t.cargo};const{result:e}=t;return e.type!=="repo.git"?{replay:{kind:"structure"},cargo:[]}:{replay:{kind:"repo.git",resultPayloadVersion:e.payloadVersion,transportVersion:e.transportVersion},cargo:t.cargo.slice(0,1)}}r(A,"ownChange");function x(t){return t!==null&&c.test(t)?t:null}r(x,"textReplayBase");const y=r((t,e)=>{if(t===null)return["create"];const n=[];t.parentUUID!==e.parentUUID&&n.push("move"),t.name!==e.name&&n.push("rename"),t.type!==e.type&&n.push("retype");const o=!p.has(e.type)&&e.type!=="reference";return(t.payloadVersion!==e.payloadVersion||u(t)!==u(e))&&o&&n.push("content"),t.fileMode!==e.fileMode&&e.fileMode!==null&&n.push("mode"),t.mtime!==e.mtime&&e.mtime!==null&&n.push("time"),t.status!==e.status&&(e.status==="deleted"?n.push("delete"):e.status==="trashed"?n.push("trash"):t.status==="trashed"&&e.status==="active"&&n.push("restore")),n},"changeFacets"),O=r((t,e,n)=>e.status==="active"&&(t===null||n.includes("content")||n.includes("retype"))&&P(e.type)!==null&&!((e.type==="file.text"||e.type==="file.binary")&&e.payloadVersion===null),"contentRequired"),w=r((t,e)=>{if(!(t.kind==="file.binary"?k(t.manifest,e.payloadVersion):V(t.manifest,e.payloadVersion)).ok||t.resultPayloadVersion!==e.payloadVersion)throw new Error(`${t.kind} replay does not name its complete result manifest`)},"validateManifestReplay");function j(t,e){if(Object.keys(t).length!==3||t.resultPayloadVersion!==e.payloadVersion||t.transportVersion!==e.transportVersion||!c.test(t.resultPayloadVersion)||!c.test(t.transportVersion))throw new Error("repository replay does not name the detected state and transport")}r(j,"assertRepositoryReplay");const m=r((t,e,n,o)=>{if(o.kind==="package")throw new Error("a package is proposed only by packageProposal");if(!O(t,e,n)){if(o.kind!=="structure")throw new Error("a structural-only change must use structure replay");return}if(o.kind!==e.type)throw new Error(`${e.type} content cannot use ${o.kind} replay`);if(e.payloadVersion===null)throw new Error(`${e.type} content has no result payload version`);switch(o.kind){case"file.text":const l=x(t?.payloadVersion??null);if((o.mode==="delta"||o.basePayloadVersion!==null)&&o.basePayloadVersion!==l||o.resultPayloadVersion!==e.payloadVersion||o.mode==="delta"!=(o.delta!==null))throw new Error("text replay does not name the detected base and result");if(!c.test(o.resultPayloadVersion)||o.basePayloadVersion!==null&&!c.test(o.basePayloadVersion))throw new Error("text replay has an invalid content head");if(o.delta!==null&&(!Number.isSafeInteger(o.delta.offset)||o.delta.offset<0||!Number.isSafeInteger(o.delta.deleteBytes)||o.delta.deleteBytes<0||!(o.delta.insert instanceof Uint8Array)))throw new Error("text replay has an invalid byte splice");if(o.delta!==null&&t!==null&&t.size!==null&&(o.delta.offset+o.delta.deleteBytes>t.size||e.size!==t.size-o.delta.deleteBytes+o.delta.insert.length))throw new Error("text replay splice does not hold its base and result sizes");break;case"file.binary":if(w(o,e),o.manifest.bytes!==e.size)throw new Error("binary replay manifest does not hold its result size");break;case"agent":case"automation":case"app":case"tool":case"secret":w(o,e);break;case"link":if(Object.keys(o).length!==2||o.resultPayloadVersion!==e.payloadVersion||!c.test(o.resultPayloadVersion))throw new Error("link replay does not name the detected result");break;case"repo.git":j(o,e);break}},"validateReplay"),f=r((t,e,n,o,a)=>{if(e!==null&&e.uuid!==n.uuid)throw new Error("a transition cannot change entity UUID");if(e===null&&n.status!=="active")throw new Error("a new entity must begin active");if(e?.status==="deleted")throw new Error("a change cannot resurrect a deleted tombstone");if(e?.version===n.version){if(!(e.type===n.type&&e.parentUUID===n.parentUUID&&e.name===n.name&&e.status===n.status&&e.payloadVersion===n.payloadVersion&&e.fileMode===n.fileMode&&e.mtime===n.mtime&&e.size===n.size&&e.linkTarget===n.linkTarget&&e.gitHomeEntity===n.gitHomeEntity&&e.gitHomePath===n.gitHomePath))throw new Error("one logical version cannot name two different entity states");return null}const l=y(e,n);if(l.length===0){if(e!==null&&p.has(e.type)&&e.type===n.type)return null;throw new Error("records disagree without a named logical facet")}if(e!==null&&e.payloadVersion===n.payloadVersion&&(e.size!==null&&n.size!==null&&e.size!==n.size||e.linkTarget!==null&&n.linkTarget!==null&&e.linkTarget!==n.linkTarget))throw new Error("one payload head cannot name two sizes or link targets");a(l),m(e,n,l,o);const g=h(n,o);return Object.freeze({contract:d,origin:t,entityId:n.uuid,basedOnState:e?.version??null,result:n,facets:Object.freeze(l),replay:o,cargo:Object.freeze(g)})},"changeProposal");function R(t){const e=i(t.row);if(e.type!=="repo.git")throw new Error("only a repository has a Git turn");const n=Object.freeze({kind:"structure"});return Object.freeze({contract:d,origin:"detected",entityId:e.uuid,basedOnState:e.version,result:e,facets:Object.freeze([]),replay:n,cargo:Object.freeze([]),turn:Object.freeze({...t.turn})})}r(R,"turnProposal");function H(t){const e=i(t.joins),n=i(t.result);if(e.uuid!==n.uuid)throw new Error("an echo cannot change entity UUID");if(s.has(n.type))throw new Error("a construct is never played, so never echoed");if(e.version===n.version)return null;const o=y(e,n);if(o.length===0||o.some(a=>!C.has(a)))throw new Error("an echo states a played payload or address, never a lifecycle or a type");return m(e,n,o,t.replay),Object.freeze({contract:d,origin:"detected",entityId:n.uuid,basedOnState:e.version,result:n,facets:Object.freeze([]),replay:t.replay,cargo:Object.freeze(h(n,t.replay)),joins:e.version})}r(H,"echoProposal");const C=new Set(["content","mode","time","rename","move"]);function M(t){const e=i(t.result),n=t.base===null?null:i(t.base);if(s.has(e.type)||n!==null&&s.has(n.type))throw new Error(`Detection cannot propose a ${e.type}; constructs bypass Detect`);if(e.status==="deleted")throw new Error("Detection cannot propose permanent deletion; deletion is an explicit lifecycle operation");return f("detected",n,e,t.replay,o=>{if(o.includes("trash")&&t.lifecycleAuthorization!=="trash")throw new Error("Trash requires proved removal or explicit lifecycle authority");if(o.includes("restore")&&t.lifecycleAuthorization!=="restore")throw new Error("restoring an entity requires explicit lifecycle authority")})}r(M,"detectedChangeProposal");function B(t){const e=i(t.result),n=t.base===null?null:i(t.base);if(!s.has(e.type))throw new Error(`an intentional change cannot propose a ${e.type}; files travel through Detect, and leave Trash for good only by permanentDeletionProposal`);return f("intentional",n,e,t.replay,()=>{})}r(B,"intentionalChangeProposal");function N(t){const e=i(t.result),n=i(t.base);if(s.has(n.type)||s.has(e.type))throw new Error(`a ${n.type} is deleted by its product through the intentional door`);if(t.effectiveStatus!=="trashed")throw new Error(`only Trash is deleted for good; ${n.uuid} is ${t.effectiveStatus}`);if(n.parentUUID===null)throw new Error(`${n.uuid} is a root; a root is not deleted for good`);if(e.status!=="deleted")throw new Error("a permanent deletion results in a deleted tombstone");const o=f("intentional",n,e,{kind:"structure"},a=>{if(a.length!==1||a[0]!=="delete")throw new Error(`a permanent deletion changes its status alone, not ${a.join(", ")}`)});if(o===null)throw new Error("a permanent deletion names a new version");return o}r(N,"permanentDeletionProposal");function _(t){return t.origin==="intentional"&&!s.has(t.result.type)&&t.result.status==="deleted"&&t.result.parentUUID!==null&&t.facets.length===1&&t.facets[0]==="delete"&&t.replay.kind==="structure"&&Object.keys(t.replay).length===1&&t.cargo.length===0}r(_,"isPermanentDeletionShape");export{d as CHANGE_PROPOSAL_CONTRACT,j as assertRepositoryReplay,h as changeCargo,y as changeFacets,M as detectedChangeProposal,H as echoProposal,B as intentionalChangeProposal,_ as isPermanentDeletionShape,A as ownChange,N as permanentDeletionProposal,x as textReplayBase,R as turnProposal};
1
+ var V=Object.defineProperty;var r=(t,e)=>V(t,"name",{value:e,configurable:!0});import{assertRecord as i}from"../entities/cloud.js";import{CONSTRUCT_TYPES as l,DERIVED_PAYLOAD as u}from"../entities/types.js";import{fileAbsent as h}from"../git/checkout.js";import{checkContentIndex as v,checkContentManifest as P}from"../contracts/content.js";import{artifactForRecord as O,artifactKindForType as z,pageArtifact as x}from"../transfer/artifacts.js";const f="amalgm.detected-change-proposal@8",y=r((t,e)=>e.kind==="repo.git"?Object.freeze({kind:"repo.git",resultPayloadVersion:e.resultPayloadVersion,transportVersion:e.transportVersion,basedOnTransport:t?.transportVersion??null}):e,"stamped"),d=/^[0-9a-f]{64}$/;function w(t,e){if(e.kind==="structure")return[];const n=O(t);if(e.kind==="package")return[...n===null?[]:[n],...e.pages.map(o=>x(t,o))];if(n===null)throw new Error(`${t.type} replay has no transferable artifact`);return[n]}r(w,"changeCargo");function H(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,basedOnTransport:null},cargo:t.cargo.slice(0,1)}}r(H,"ownChange");function T(t){return t!==null&&d.test(t)?t:null}r(T,"textReplayBase");const m=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=!u.has(e.type)&&e.type!=="reference";return(t.payloadVersion!==e.payloadVersion||h(t)!==h(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"),j=r((t,e,n)=>e.status==="active"&&(t===null||n.includes("content")||n.includes("retype"))&&z(e.type)!==null&&!((e.type==="file.text"||e.type==="file.binary")&&e.payloadVersion===null),"contentRequired"),g=r((t,e)=>{if(!(t.kind==="file.binary"?v(t.manifest,e.payloadVersion):P(t.manifest,e.payloadVersion)).ok||t.resultPayloadVersion!==e.payloadVersion)throw new Error(`${t.kind} replay does not name its complete result manifest`)},"validateManifestReplay");function C(t,e){if(Object.keys(t).length!==4||t.resultPayloadVersion!==e.payloadVersion||t.transportVersion!==e.transportVersion||!d.test(t.resultPayloadVersion)||!d.test(t.transportVersion)||t.basedOnTransport!==null&&!d.test(t.basedOnTransport))throw new Error("repository replay does not name the detected state and transport")}r(C,"assertRepositoryReplay");const k=r((t,e,n,o)=>{if(o.kind==="package")throw new Error("a package is proposed only by packageProposal");if(!j(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 s=T(t?.payloadVersion??null);if((o.mode==="delta"||o.basePayloadVersion!==null)&&o.basePayloadVersion!==s||o.resultPayloadVersion!==e.payloadVersion||o.mode==="delta"!=(o.delta!==null))throw new Error("text replay does not name the detected base and result");if(!d.test(o.resultPayloadVersion)||o.basePayloadVersion!==null&&!d.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(g(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":g(o,e);break;case"link":if(Object.keys(o).length!==2||o.resultPayloadVersion!==e.payloadVersion||!d.test(o.resultPayloadVersion))throw new Error("link replay does not name the detected result");break;case"repo.git":if(C(o,e),o.basedOnTransport!==(t?.transportVersion??null))throw new Error("repository replay does not name the package it was made on");break}},"validateReplay"),p=r((t,e,n,o,a)=>{const s=y(e,o);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 c=m(e,n);if(c.length===0){if(e!==null&&u.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(c),k(e,n,c,s);const E=w(n,s);return Object.freeze({contract:f,origin:t,entityId:n.uuid,basedOnState:e?.version??null,result:n,facets:Object.freeze(c),replay:s,cargo:Object.freeze(E)})},"changeProposal");function M(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:f,origin:"detected",entityId:e.uuid,basedOnState:e.version,result:e,facets:Object.freeze([]),replay:n,cargo:Object.freeze([]),turn:Object.freeze({...t.turn})})}r(M,"turnProposal");function B(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(l.has(n.type))throw new Error("a construct is never played, so never echoed");if(e.version===n.version)return null;const o=m(e,n);if(o.length===0||o.some(s=>!b.has(s)))throw new Error("an echo states a played payload or address, never a lifecycle or a type");const a=y(e,t.replay);return k(e,n,o,a),Object.freeze({contract:f,origin:"detected",entityId:n.uuid,basedOnState:e.version,result:n,facets:Object.freeze([]),replay:a,cargo:Object.freeze(w(n,a)),joins:e.version})}r(B,"echoProposal");const b=new Set(["content","mode","time","rename","move"]);function N(t){const e=i(t.result),n=t.base===null?null:i(t.base);if(l.has(e.type)||n!==null&&l.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 p("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(N,"detectedChangeProposal");function _(t){const e=i(t.result),n=t.base===null?null:i(t.base);if(!l.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 p("intentional",n,e,t.replay,()=>{})}r(_,"intentionalChangeProposal");function F(t){const e=i(t.result),n=i(t.base);if(l.has(n.type)||l.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=p("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(F,"permanentDeletionProposal");function q(t){return t.origin==="intentional"&&!l.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(q,"isPermanentDeletionShape");export{f as CHANGE_PROPOSAL_CONTRACT,C as assertRepositoryReplay,w as changeCargo,m as changeFacets,N as detectedChangeProposal,B as echoProposal,_ as intentionalChangeProposal,q as isPermanentDeletionShape,H as ownChange,F as permanentDeletionProposal,T as textReplayBase,M as turnProposal};
@@ -1 +1 @@
1
- var f=Object.defineProperty;var h=(a,s)=>f(a,"name",{value:s,configurable:!0});import{canonicalVersion as w,membershipHash as d}from"../entities/rules.js";import{eachStep as c}from"../steps.js";function*v(a,s,o){const r=new Map,i=new Map;yield*c(a,e=>{if(r.set(e.uuid,e),e.parentUUID===null||e.status!=="active")return;const t=i.get(e.parentUUID)??[];t.push(e),i.set(e.parentUUID,t)});const p=new Map;return yield*c(s,e=>{const t=r.get(e);if(!t)throw new Error(`removed entity ${e} is unknown`);if(t.parentUUID===null)throw new Error("missing workspace root cannot authorize Trash");if(t.status!=="active")return;let n=r.get(t.parentUUID);const l=new Set([e]);let u=!1;for(;n;){if(l.has(n.uuid))throw new Error("removed entity ancestry has a cycle");if(l.add(n.uuid),n.status!=="active"||s.has(n.uuid)){u=!0;break}n=n.parentUUID===null?void 0:r.get(n.parentUUID)}if(u)return;const U=t.type==="workspace"||t.type==="folder"?d(i.get(e)??[],o):t.payloadVersion;p.set(e,Object.freeze({...t,status:"trashed",version:w({...t,status:"trashed",payloadVersion:U},o)}))}),p}h(v,"trashRemovedEntitiesSteps");export{v as trashRemovedEntitiesSteps};
1
+ var h=Object.defineProperty;var U=(r,s)=>h(r,"name",{value:s,configurable:!0});import{canonicalVersion as d,membershipHash as w}from"../entities/rules.js";import{eachStep as c}from"../steps.js";function*D(r,s,o){const a=new Map,i=new Map;yield*c(r,e=>{if(a.set(e.uuid,e),e.parentUUID===null||e.status!=="active")return;const t=i.get(e.parentUUID)??[];t.push(e),i.set(e.parentUUID,t)});const p=new Map;return yield*c(s,e=>{const t=a.get(e);if(!t)throw new Error(`removed entity ${e} is unknown`);if(t.status!=="active")return;let n=t.parentUUID===null?void 0:a.get(t.parentUUID);const l=new Set([e]);let u=!1;for(;n;){if(l.has(n.uuid))throw new Error("removed entity ancestry has a cycle");if(l.add(n.uuid),n.status!=="active"||s.has(n.uuid)){u=!0;break}n=n.parentUUID===null?void 0:a.get(n.parentUUID)}if(u)return;const f=t.type==="workspace"||t.type==="folder"?w(i.get(e)??[],o):t.payloadVersion;p.set(e,Object.freeze({...t,status:"trashed",version:d({...t,status:"trashed",payloadVersion:f},o)}))}),p}U(D,"trashRemovedEntitiesSteps");export{D as trashRemovedEntitiesSteps};
@@ -1 +1 @@
1
- var U=Object.defineProperty;var l=(o,u)=>U(o,"name",{value:u,configurable:!0});import{isLocalOnlyPath as v}from"@amalgm/core/identity";import{FILES_FOLDER as W}from"../registration/home-layout.js";import{byteString as x,compileIgnoreLines as p}from"./ignore-lines.js";import{SHIPPED_INCLUDES as C,SKIP_DEFAULTS as H}from"./skip-defaults.js";function E(o){const u=String(o||"");return!u.startsWith("/")&&!u.startsWith("./")&&!u.endsWith("/")&&!u.includes("//")?u:u.replace(/^\.\//,"").replace(/^\/+|\/+$/g,"").replace(/\/{2,}/g,"/")}l(E,"normalizedRelativePath");const g=l(o=>o.slice(0,Math.max(0,o.lastIndexOf("/"))),"parentOf");function G(o){const u=new Set,k=new Set;for(const f of o){const c=E(f);u.add(c);for(let d=c;k.add(d),d!=="";d=g(d));}return{project(f){if(f==="")return null;for(let c=g(f);;c=g(c)){if(u.has(c))return c;if(c==="")return null}},holdsProject:l(f=>k.has(f),"holdsProject")}}l(G,"projectsAt");const b=p(H),F=p(C),N=new RegExp([F.screen,b.screen].filter(Boolean).join("|")||"(?!)","s");function J(o,u={}){const k=l(e=>u.home===!0&&(e===W||e.startsWith(`${W}/`))&&!v(e),"computers"),f=new Map,c=l(e=>{let n=f.get(e);if(n===void 0){const t=o.gitignore(e);f.set(e,n=t===null?null:p(t))}return n},"gitignoreAt"),d=l((e,n,t)=>{const i=x(e),s=F.verdict(i,n);if(s!==null)return s==="skip";if(t!==null)for(let r=g(e);;r=g(r)){const S=c(r);if(S!==null){const a=S.verdict(x(r===""?e:e.slice(r.length+1)),n);if(a!==null)return a==="skip"}if(r===t||r==="")break}return b.verdict(i,n)==="skip"},"skippedHere"),I=new Map,w=l((e,n)=>{const t=`${n??"\0"}\0${e}`;let i=I.get(t);return i===void 0&&I.set(t,i=d(e,!0,n)),i},"folderSkipped"),L=new Map,P=l((e,n)=>{if(e===n)return!1;const t=`${n}\0${e}`;let i=L.get(t);return i===void 0&&L.set(t,i=w(e,n)||P(g(e),n)),i},"skippedWithin"),O=l((e,n,t)=>{if(t===null&&!N.test(x(e)))return!1;for(let i=e.indexOf("/");i!==-1;i=e.indexOf("/",i+1)){const s=e.slice(0,i),r=t!==null&&(t===""||s.startsWith(`${t}/`))?t:null;if(w(s,r))return!0}return!M(e,n)&&d(e,n,t)},"judgedSkipped"),$=l(e=>{const n=new Map,t=l(s=>{let r=n.get(s);return r===void 0&&n.set(s,r=i(s,!0,e(s))),r},"folderTravels"),i=l((s,r,S)=>{if(!s||v(s))return!1;const a=o.project(s);if(a===null)return!O(s,r,null);if(o.tracks(a,s,r))return a===""||t(a);const m=g(s);if(m!==""&&!t(m))return!1;const D=!P(m,a)&&(M(s,r)||!d(s,r,a));return!r||!S?D:D||!O(s,r,null)},"decide");return(s,r)=>r&&s!==""?t(s):i(s,r,!1)},"verdicts"),A=$(o.holdsProject),R=l((e,n)=>{const t=E(e);return k(t)?n||!d(t,!1,null):A(t,n)},"travels"),T=$(()=>!0);return{travels:R,sealed:l(e=>{const n=E(e);return n!==""&&!v(n)&&!k(n)&&!T(n,!0)},"sealed")}}l(J,"createSkipPolicy");const M=l((o,u)=>!u&&o.slice(o.lastIndexOf("/")+1)===".gitignore","isIgnoreFile");export{J as createSkipPolicy,E as normalizedRelativePath,G as projectsAt};
1
+ var U=Object.defineProperty;var i=(l,o)=>U(l,"name",{value:o,configurable:!0});import{isLocalOnlyPath as m}from"@amalgm/core/identity";import{FILES_FOLDER as $}from"../registration/home-layout.js";import{byteString as v,compileIgnoreLines as x}from"./ignore-lines.js";import{SHIPPED_INCLUDES as C,SKIP_DEFAULTS as H}from"./skip-defaults.js";function E(l){const o=String(l||"");return!o.startsWith("/")&&!o.startsWith("./")&&!o.endsWith("/")&&!o.includes("//")?o:o.replace(/^\.\//,"").replace(/^\/+|\/+$/g,"").replace(/\/{2,}/g,"/")}i(E,"normalizedRelativePath");const g=i(l=>l.slice(0,Math.max(0,l.lastIndexOf("/"))),"parentOf");function G(l){const o=new Set,p=new Set;for(const f of l){const u=E(f);o.add(u);for(let d=u;p.add(d),d!=="";d=g(d));}return{project(f){if(f==="")return null;for(let u=g(f);;u=g(u)){if(o.has(u))return u;if(u==="")return null}},holdsProject:i(f=>p.has(f),"holdsProject")}}i(G,"projectsAt");const b=x(H),F=x(C),N=new RegExp([F.screen,b.screen].filter(Boolean).join("|")||"(?!)","s");function J(l,o={}){const p=i(e=>o.home===!0&&(e===$||e.startsWith(`${$}/`))&&!m(e),"computers"),f=new Map,u=i(e=>{let n=f.get(e);if(n===void 0){const t=l.gitignore(e);f.set(e,n=t===null?null:x(t))}return n},"gitignoreAt"),d=i((e,n,t)=>{const c=v(e),s=F.verdict(c,n);if(s!==null)return s==="skip";if(t!==null)for(let r=g(e);;r=g(r)){const k=u(r);if(k!==null){const a=k.verdict(v(r===""?e:e.slice(r.length+1)),n);if(a!==null)return a==="skip"}if(r===t||r==="")break}return b.verdict(c,n)==="skip"},"skippedHere"),I=new Map,j=i((e,n)=>{const t=`${n??"\0"}\0${e}`;let c=I.get(t);return c===void 0&&I.set(t,c=d(e,!0,n)),c},"folderSkipped"),w=new Map,L=i((e,n)=>{if(e===n)return!1;const t=`${n}\0${e}`;let c=w.get(t);return c===void 0&&w.set(t,c=j(e,n)||L(g(e),n)),c},"skippedWithin"),W=i((e,n)=>{if(!N.test(v(e)))return!1;for(let t=e.indexOf("/");t!==-1;t=e.indexOf("/",t+1))if(j(e.slice(0,t),null))return!0;return!M(e,n)&&d(e,n,null)},"shippedSkipped"),P=i(e=>{const n=new Map,t=i(s=>{let r=n.get(s);return r===void 0&&n.set(s,r=c(s,!0,e(s))),r},"folderTravels"),c=i((s,r,k)=>{if(!s||m(s))return!1;const a=l.project(s);if(a!==null&&l.tracks(a,s,r))return a===""||t(a);const S=g(s);if(S!==""&&!t(S))return!1;const O=a??"",D=!L(S,O)&&(M(s,r)||!d(s,r,O));return!r||!k?D:D||!W(s,r)},"decide");return(s,r)=>r&&s!==""?t(s):c(s,r,!1)},"verdicts"),A=P(l.holdsProject),R=i((e,n)=>{const t=E(e);return p(t)?n||!d(t,!1,null):A(t,n)},"travels"),T=P(()=>!0);return{travels:R,sealed:i(e=>{const n=E(e);return n!==""&&!m(n)&&!p(n)&&!T(n,!0)},"sealed")}}i(J,"createSkipPolicy");const M=i((l,o)=>!o&&l.slice(l.lastIndexOf("/")+1)===".gitignore","isIgnoreFile");export{J as createSkipPolicy,E as normalizedRelativePath,G as projectsAt};
@@ -1,7 +1,7 @@
1
1
  import type { DrivePorts, KeptOwner, Times, Unit } from './contracts.js';
2
2
  import { type Listing } from './listing.js';
3
3
  import { type Receipt } from './placements.js';
4
- import { type Look, type Where } from './where.js';
4
+ import { type DriveFile, type Look, type Where } from './where.js';
5
5
  export interface Looked {
6
6
  readonly look: Look;
7
7
  readonly placed: readonly Receipt[];
@@ -24,10 +24,11 @@ export declare class Drive {
24
24
  private readonly placements;
25
25
  constructor(ports: DrivePorts);
26
26
  where(path: readonly string[]): Promise<Where>;
27
+ pathOf(file: DriveFile): Promise<readonly string[] | null>;
27
28
  list(path: readonly string[]): Promise<Listing>;
28
29
  look(path: readonly string[]): Promise<Looked>;
29
- touch(path: readonly string[]): Promise<Touched>;
30
- change(path: readonly string[]): Promise<Touched | null>;
30
+ touch(path: readonly string[], file?: DriveFile): Promise<Touched>;
31
+ change(path: readonly string[], operation?: 'existing' | 'create'): Promise<Touched | null>;
31
32
  vacate(path: readonly string[]): Promise<Touched | 'not-empty' | null>;
32
33
  removable(path: readonly string[]): Promise<boolean>;
33
34
  remove(path: readonly string[], as: 'file' | 'directory'): Promise<Touched | Recorded | Refused | null>;
@@ -36,7 +37,7 @@ export declare class Drive {
36
37
  mode(path: readonly string[], mode: number): Promise<Touched | Recorded | Refused | null>;
37
38
  times(path: readonly string[], times: Times): Promise<Touched | Recorded | Refused | null>;
38
39
  keep(path: readonly string[], kept: KeptOwner): Promise<Touched | Recorded | Refused | null>;
39
- empty(path: readonly string[]): Promise<Touched | Refused | null>;
40
+ empty(path: readonly string[], file?: DriveFile): Promise<Touched | Refused | null>;
40
41
  private meets;
41
42
  private act;
42
43
  private again;
@@ -48,6 +49,7 @@ export declare class Drive {
48
49
  private movable;
49
50
  private destination;
50
51
  private settle;
52
+ private judgedFile;
51
53
  private judged;
52
54
  placing(): number;
53
55
  }
@@ -1 +1 @@
1
- var S=Object.defineProperty;var c=(o,t)=>S(o,"name",{value:t,configurable:!0});import{isRepositoryMetadataEntry as R}from"../detection/classify.js";import{isName as E,portableFileMode as A,portableMtime as I}from"../entities/rules.js";import{CONTAINERS as k}from"../entities/types.js";import{placedAtHome as C}from"../registration/home-layout.js";import{listing as D}from"./listing.js";import{Placements as F}from"./placements.js";import{CROSSES_ROOTS as T}from"./records.js";import{addressOnly as l,aloneInSlot as U,childAt as x,freeName as H,glance as b,outsideRepositories as v,rootOf as j,where as P}from"./where.js";class Q{static{c(this,"Drive")}ports;placements;constructor(t){this.ports=t,this.placements=new F(t)}where(t){return P(this.ports.roots,t)}list(t){return D(this.ports.roots,t)}async look(t){const r=await this.judged(t),n=b(r.at);if(n!==null)return{look:n,placed:[]};const{where:e,placed:i}=await this.settle(t,r),s=b(e);if(s!==null)return{look:s,placed:i};throw new Error("placed, yet the shelf does not stand here")}async touch(t){return this.settle(t,await this.judged(t))}async change(t){const r=await this.judged(t);return l(this.ports.roots,t,r.at)?null:(await this.freed(r.at),this.settle(t,r))}async vacate(t){const r=await this.judged(t);return l(this.ports.roots,t,r.at)?null:f(await this.list(t))?"not-empty":(await this.freed(r.at),this.settle(t,r))}async removable(t){return!l(this.ports.roots,t,await this.where(t))}async remove(t,r){const n=await this.judged(t);if(l(this.ports.roots,t,n.at))return null;const e=c(async()=>r==="file"||!f(await this.list(t)),"empty");return this.act(t,n,i=>this.refuses(t,r,i),i=>this.leavable(i),async i=>await e()&&this.ports.recorder.remove(i.unit),!0)}async refuses(t,r,n){const e=h(n);return e!==null?e:n.kind==="listed"&&n.entry.kind==="directory"!=(r==="directory")?r==="directory"?"not-directory":"directory":r==="directory"&&f(await this.list(t))?"not-empty":null}async move(t,r){const n=await this.judged(t);return l(this.ports.roots,t,n.at)||l(this.ports.roots,r,await this.where(r))?null:this.act(t,n,async e=>this.meets(e,r,await this.where(r)),e=>this.movable(e,r),async e=>(await this.ports.recorder.free({root:e.destination.root,address:e.destination.address}),this.ports.recorder.move(e.unit,e.destination)),!0)}async mode(t,r){const n=await this.judged(t);return l(this.ports.roots,t,n.at)?null:this.act(t,n,async e=>h(e),e=>this.modable(e,r),async e=>e.fileMode!==e.listed.mode&&!await this.ports.recorder.mode(e.unit,e.fileMode)?!1:(await this.ports.keeper.keep(e.unit,{mode:r&4095},{...e.listed,mode:e.fileMode}),!0),!1)}async times(t,r){const n=await this.judged(t);return l(this.ports.roots,t,n.at)?null:this.act(t,n,async e=>h(e),e=>this.keepable(e),async e=>{const i=r.mtimeNs===null?e.listed.mtime:I(e.listed.type,r.mtimeNs);return i!==e.listed.mtime&&!await this.ports.recorder.time(e.unit,i)?!1:(await this.ports.keeper.keep(e.unit,{atimeNs:r.atimeNs},{...e.listed,mtime:i}),!0)},!1)}async keep(t,r){const n=await this.judged(t);return l(this.ports.roots,t,n.at)?null:this.act(t,n,async e=>h(e),e=>this.keepable(e),async e=>(await this.ports.keeper.keep(e.unit,r,e.listed),!0),!1)}async empty(t){const r=await this.judged(t);if(l(this.ports.roots,t,r.at))return null;const n=h(r.at);return n!==null?{refused:n,placed:[]}:this.settle(t,r,async e=>(await this.keepable(e))?.unit.uuid??null)}async meets(t,r,n){const e=h(t)??M(n);if(e!==null)return e;if(t.kind!=="listed"||n.kind!=="listed"||t.entity.uuid===n.entity.uuid)return null;const i=t.entry.kind==="directory";return i!==(n.entry.kind==="directory")?i?"not-directory":"directory":i&&f(await this.list(r))?"not-empty":null}async act(t,r,n,e,i,s){const a=[];let d=!1;for(let u=r,w=!1;;u=await this.judged(t)){const y=await n(u.at);if(y!==null)return{refused:y,placed:a};const m="placing"in u.at?u.at.placing:[];if(w||m.length===0)return{where:u.at,placed:a};const p=d?null:await e(u.at);if(p!==null){const g=await this.placements.record(p.unit,()=>this.again(t,p,e,i),s);if(g===!0)return{recorded:p.unit,placed:a};d=g===!1;continue}const{receipts:N,complete:O}=await this.placements.place(m,u.seen);a.push(...N),w=O}}async again(t,r,n,e){const i=await n(await this.where(t));return i!==null&&i.unit.uuid===r.unit.uuid&&e(i)}async freed(t){"root"in t&&await this.ports.recorder.free({root:t.root,address:t.address})}async own(t){if(t.kind!=="listed")return null;const r=t.placing.at(-1);if(r?.uuid!==t.entity.uuid)return null;const n=await j(this.ports.roots,t.root);return n===null||!await v(n.map,t.address)?null:{unit:r,root:n,entity:t.entity}}async leavable(t){const r=await this.own(t);return r!==null&&await U(r.root.map,r.entity)?r:null}async keepable(t){const r=await this.own(t);if(r===null)return null;const{type:n,fileMode:e,mtime:i,payloadVersion:s,version:a}=r.entity;return e===null||i===null||s===null?null:{...r,listed:{type:n,mode:e,mtime:i,payloadVersion:s,version:a}}}async modable(t,r){const n=await this.keepable(t),e=n===null?null:A(n.entity.type,r);return n===null||e===null?null:{...n,fileMode:e}}async movable(t,r){const n=await this.leavable(t);if(n===null||k.has(n.unit.type))return null;const e=await this.destination(n,r);return e===null?null:{...n,destination:e}}async destination({unit:t,root:r},n){const e=n.at(-1);if(e===void 0||!E(e)||R(e))return null;const i=await this.where(n.slice(0,-1));if(i.kind!=="shelf"&&i.kind!=="listed"||i.root!==r.uuid&&!T.has(t.type))return null;const s=await j(this.ports.roots,i.root),a=i.entity;if(s===null||a===null||!k.has(a.type)||i.kind==="shelf"&&s.shelf.names(i.address)===null)return null;const d=[...i.address,e],u=i.address.length===0?e:(await x(s.map,s.map.root().uuid,i.address[0]))?.name;return u===void 0||!await H(s.map,a.uuid,e,t.uuid)||s.shelf.has(d)||!await v(s.map,i.address)||s.uuid===this.ports.roots.home.uuid&&C(u,d.length>1)||l(this.ports.roots,n,{root:s.uuid,address:d})?null:{root:s.uuid,parentUUID:a.uuid,name:e,address:d}}async settle(t,r,n=async()=>null){const e=[];for(let i=r;;){const s="placing"in i.at?i.at.placing:[];if(s.length===0)return{where:i.at,placed:e};const{receipts:a,complete:d}=await this.placements.place(s,i.seen,await n(i.at));if(e.push(...a),i=await this.judged(t),d)return{where:i.at,placed:e}}}async judged(t){const r=this.placements.recorded();return{at:await this.where(t),seen:r}}placing(){return this.placements.count()}}function h(o){return o.kind==="absent"?"nowhere":M(o)}c(h,"unnamed");function M(o){return o.kind==="nowhere"?"nowhere":o.kind==="notdir"?"not-directory":null}c(M,"noFolder");function f(o){return o.kind==="entries"&&o.entries.length>0}c(f,"shows");export{Q as Drive};
1
+ var F=Object.defineProperty;var c=(l,t)=>F(l,"name",{value:t,configurable:!0});import{isRepositoryMetadataEntry as S}from"../detection/classify.js";import{isName as R,portableFileMode as E,portableMtime as A}from"../entities/rules.js";import{CONTAINERS as k}from"../entities/types.js";import{placedAtHome as I}from"../registration/home-layout.js";import{listing as x}from"./listing.js";import{Placements as C}from"./placements.js";import{CROSSES_ROOTS as D}from"./records.js";import{addressOnly as d,aloneInSlot as T,childAt as U,freeName as H,glance as b,outsideRepositories as j,pathOfFile as P,rootOf as v,where as V}from"./where.js";class W{static{c(this,"Drive")}ports;placements;constructor(t){this.ports=t,this.placements=new C(t)}where(t){return V(this.ports.roots,t)}pathOf(t){return P(this.ports.roots,t)}list(t){return x(this.ports.roots,t)}async look(t){const r=await this.judged(t),n=b(r.at);if(n!==null)return{look:n,placed:[]};const{where:e,placed:i}=await this.settle(t,r),s=b(e);if(s!==null)return{look:s,placed:i};throw new Error("placed, yet the shelf does not stand here")}async touch(t,r){return this.settle(t,await this.judgedFile(t,r),void 0,r)}async change(t,r="existing"){const n=await this.judged(t);if(d(this.ports.roots,t,n.at))return null;if(await this.freed(n.at),r==="create"&&n.at.kind==="absent"){const e=await this.touch(t.slice(0,-1));if(e.where.kind!=="shelf")return e;const{root:i,address:s}=n.at;return e.where.root!==i||e.where.address.length+1!==s.length||!e.where.address.every((a,u)=>a===s[u])?{where:{kind:"nowhere"},placed:e.placed}:{where:{kind:"shelf",root:i,address:s,entity:null},placed:e.placed}}return this.settle(t,n)}async vacate(t){const r=await this.judged(t);return d(this.ports.roots,t,r.at)?null:f(await this.list(t))?"not-empty":(await this.freed(r.at),this.settle(t,r))}async removable(t){return!d(this.ports.roots,t,await this.where(t))}async remove(t,r){const n=await this.judged(t);if(d(this.ports.roots,t,n.at))return null;const e=c(async()=>r==="file"||!f(await this.list(t)),"empty");return this.act(t,n,i=>this.refuses(t,r,i),i=>this.leavable(i),async i=>await e()&&this.ports.recorder.remove(i.unit),!0)}async refuses(t,r,n){const e=h(n);return e!==null?e:n.kind==="listed"&&n.entry.kind==="directory"!=(r==="directory")?r==="directory"?"not-directory":"directory":r==="directory"&&f(await this.list(t))?"not-empty":null}async move(t,r){const n=await this.judged(t);return d(this.ports.roots,t,n.at)||d(this.ports.roots,r,await this.where(r))?null:this.act(t,n,async e=>this.meets(e,r,await this.where(r)),e=>this.movable(e,r),async e=>(await this.ports.recorder.free({root:e.destination.root,address:e.destination.address}),this.ports.recorder.move(e.unit,e.destination)),!0)}async mode(t,r){const n=await this.judged(t);return d(this.ports.roots,t,n.at)?null:this.act(t,n,async e=>h(e),e=>this.modable(e,r),async e=>e.fileMode!==e.listed.mode&&!await this.ports.recorder.mode(e.unit,e.fileMode)?!1:(await this.ports.keeper.keep(e.unit,{mode:r&4095},{...e.listed,mode:e.fileMode}),!0),!1)}async times(t,r){const n=await this.judged(t);return d(this.ports.roots,t,n.at)?null:this.act(t,n,async e=>h(e),e=>this.keepable(e),async e=>{const i=r.mtimeNs===null?e.listed.mtime:A(e.listed.type,r.mtimeNs);return i!==e.listed.mtime&&!await this.ports.recorder.time(e.unit,i)?!1:(await this.ports.keeper.keep(e.unit,{atimeNs:r.atimeNs},{...e.listed,mtime:i}),!0)},!1)}async keep(t,r){const n=await this.judged(t);return d(this.ports.roots,t,n.at)?null:this.act(t,n,async e=>h(e),e=>this.keepable(e),async e=>(await this.ports.keeper.keep(e.unit,r,e.listed),!0),!1)}async empty(t,r){const n=await this.judgedFile(t,r);if(d(this.ports.roots,t,n.at))return null;const e=h(n.at);return e!==null?{refused:e,placed:[]}:this.settle(t,n,async i=>(await this.keepable(i))?.unit.uuid??null,r)}async meets(t,r,n){const e=h(t)??O(n);if(e!==null)return e;if(t.kind!=="listed"||n.kind!=="listed"||t.entity.uuid===n.entity.uuid)return null;const i=t.entry.kind==="directory";return i!==(n.entry.kind==="directory")?i?"not-directory":"directory":i&&f(await this.list(r))?"not-empty":null}async act(t,r,n,e,i,s){const a=[];let u=!1;for(let o=r,p=!1;;o=await this.judged(t)){const y=await n(o.at);if(y!==null)return{refused:y,placed:a};const m="placing"in o.at?o.at.placing:[];if(p||m.length===0)return{where:o.at,placed:a};const w=u?null:await e(o.at);if(w!==null){const g=await this.placements.record(w.unit,()=>this.again(t,w,e,i),s);if(g===!0)return{recorded:w.unit,placed:a};u=g===!1;continue}const{receipts:M,complete:N}=await this.placements.place(m,o.seen);a.push(...M),p=N}}async again(t,r,n,e){const i=await n(await this.where(t));return i!==null&&i.unit.uuid===r.unit.uuid&&e(i)}async freed(t){"root"in t&&await this.ports.recorder.free({root:t.root,address:t.address})}async own(t){if(t.kind!=="listed")return null;const r=t.placing.at(-1);if(r?.uuid!==t.entity.uuid)return null;const n=await v(this.ports.roots,t.root);return n===null||!await j(n.map,t.address)?null:{unit:r,root:n,entity:t.entity}}async leavable(t){const r=await this.own(t);return r!==null&&await T(r.root.map,r.entity)?r:null}async keepable(t){const r=await this.own(t);if(r===null)return null;const{type:n,fileMode:e,mtime:i,payloadVersion:s,version:a}=r.entity;return e===null||i===null||s===null?null:{...r,listed:{type:n,mode:e,mtime:i,payloadVersion:s,version:a}}}async modable(t,r){const n=await this.keepable(t),e=n===null?null:E(n.entity.type,r);return n===null||e===null?null:{...n,fileMode:e}}async movable(t,r){const n=await this.leavable(t);if(n===null||k.has(n.unit.type))return null;const e=await this.destination(n,r);return e===null?null:{...n,destination:e}}async destination({unit:t,root:r},n){const e=n.at(-1);if(e===void 0||!R(e)||S(e))return null;const i=await this.where(n.slice(0,-1));if(i.kind!=="shelf"&&i.kind!=="listed"||i.root!==r.uuid&&!D.has(t.type))return null;const s=await v(this.ports.roots,i.root),a=i.entity;if(s===null||a===null||!k.has(a.type)||i.kind==="shelf"&&s.shelf.names(i.address)===null)return null;const u=[...i.address,e],o=i.address.length===0?e:(await U(s.map,s.map.root().uuid,i.address[0]))?.name;return o===void 0||!await H(s.map,a.uuid,e,t.uuid)||s.shelf.has(u)||!await j(s.map,i.address)||s.uuid===this.ports.roots.home.uuid&&I(o,u.length>1)||d(this.ports.roots,n,{root:s.uuid,address:u})?null:{root:s.uuid,parentUUID:a.uuid,name:e,address:u}}async settle(t,r,n=async()=>null,e){const i=[];for(let s=r;;){const a="placing"in s.at?s.at.placing:[];if(a.length===0)return{where:s.at,placed:i};const{receipts:u,complete:o}=await this.placements.place(a,s.seen,await n(s.at));if(i.push(...u),s=await this.judgedFile(t,e),o)return{where:s.at,placed:i}}}async judgedFile(t,r){const n=await this.judged(t);if(!r)return n;const e=c(s=>(s.kind==="listed"||s.kind==="shelf")&&s.root===r.root&&s.entity?.uuid===r.uuid,"matches");if(e(n.at))return n;const i=await this.pathOf(r);if(i){const s=await this.judged(i);if(e(s.at))return s}return{seen:n.seen,at:{kind:"nowhere"}}}async judged(t){const r=this.placements.recorded();return{at:await this.where(t),seen:r}}placing(){return this.placements.count()}}function h(l){return l.kind==="absent"?"nowhere":O(l)}c(h,"unnamed");function O(l){return l.kind==="nowhere"?"nowhere":l.kind==="notdir"?"not-directory":null}c(O,"noFolder");function f(l){return l.kind==="entries"&&l.entries.length>0}c(f,"shows");export{W as Drive};
@@ -1,21 +1,31 @@
1
1
  import type { CloudEntityRecord } from '../entities/cloud.js';
2
2
  import { type Sha256Hex } from '../entities/types.js';
3
- import type { MapEntity } from './contracts.js';
3
+ import type { GitSizes } from '../git/artifact.js';
4
+ import { type MapEntity } from './contracts.js';
4
5
  export declare class MapIndex {
5
6
  #private;
6
7
  constructor(rootUUID: string, sha256Hex: Sha256Hex);
7
8
  get rootUUID(): string;
8
9
  get size(): number;
9
10
  enter(parentUUID: string, children: Iterable<CloudEntityRecord>): boolean;
11
+ sizes(repositoryUUID: string, version: string, transportVersion: string, sizes: GitSizes | null): void;
12
+ sizesOwed(): {
13
+ readonly uuid: string;
14
+ readonly version: string;
15
+ readonly transportVersion: string;
16
+ }[];
10
17
  entered(uuid: string): boolean;
11
18
  accept(record: CloudEntityRecord): void;
12
19
  remove(uuid: string): void;
13
20
  has(uuid: string): boolean;
14
- get(uuid: string): MapEntity | undefined;
21
+ retained(uuid: string): MapEntity | undefined;
15
22
  parentOf(uuid: string): string | null | undefined;
16
23
  root(): MapEntity;
24
+ retainedChildren(parentUUID: string): readonly MapEntity[];
25
+ get(uuid: string): MapEntity | undefined;
17
26
  children(parentUUID: string): readonly MapEntity[];
18
27
  holders(parentUUID: string, name: string): readonly MapEntity[];
28
+ foldersOwed(): string[];
19
29
  takeTouched(): Set<string>;
20
30
  }
21
31
  export declare function mapEntity(record: CloudEntityRecord): MapEntity;
@@ -1 +1 @@
1
- var f=Object.defineProperty;var h=(n,e)=>f(n,"name",{value:e,configurable:!0});import{membershipVersion as l,recordGitHome as p}from"../entities/rules.js";import{DERIVED_PAYLOAD as c}from"../entities/types.js";class w{static{h(this,"MapIndex")}#s;#o;#e=new Map;#t=new Map;#i=new Set;#r=new Set;#u=new Set;constructor(e,t){this.#s=e,this.#o=t}get rootUUID(){return this.#s}get size(){return this.#e.size}enter(e,t){if(!this.#e.has(e))return!1;if(this.#i.has(e))return!0;this.#i.add(e),this.#n(e);for(const s of t)this.accept(s);return!0}entered(e){return this.#i.has(e)}accept(e){const t=U(e);if(t.uuid===this.#s){this.#e.set(t.uuid,t),this.#n(t.uuid);return}if(t.parentUUID===null||!this.#i.has(t.parentUUID)){this.remove(t.uuid);return}const s=this.#e.get(t.uuid);this.#e.set(t.uuid,t),s!==void 0&&(s.parentUUID!==t.parentUUID||s.name!==t.name)&&(this.#d(s),this.#n(s.parentUUID)),this.#a(t),this.#n(t.uuid),this.#n(t.parentUUID)}remove(e){const t=this.#e.get(e);t!==void 0&&e!==this.#s&&this.#n(t.parentUUID);const s=[e];for(let i=s.pop();i!==void 0;i=s.pop()){const r=this.#e.get(i);if(r===void 0)continue;this.#e.delete(i),this.#i.delete(i),this.#r.delete(i),this.#u.add(i),r.uuid!==this.#s&&this.#d(r);const u=this.#t.get(i);if(u!==void 0){this.#t.delete(i);for(const a of u.values())for(const d of o(a))s.push(d.uuid)}}}has(e){return this.#e.has(e)}get(e){const t=this.#e.get(e);return t===void 0?void 0:this.#h(t)}parentOf(e){return this.#e.get(e)?.parentUUID}root(){const e=this.#e.get(this.#s);if(e===void 0)throw new Error(`the map of ${this.#s} holds no root`);return this.#h(e)}children(e){const t=[];for(const s of this.#t.get(e)?.values()??[])t.push(...o(s));return t.map(s=>this.#h(s))}holders(e,t){const s=this.#t.get(e)?.get(t);return s===void 0?[]:o(s).map(i=>this.#h(i))}takeTouched(){const e=this.#u;return this.#u=new Set,e}#n(e){const t=this.#e.get(e);t!==void 0&&(this.#u.add(e),c.has(t.type)&&this.#i.has(e)?this.#r.add(e):this.#r.delete(e))}#h(e){if(!this.#r.delete(e.uuid))return e;const t=[];for(const r of this.#t.get(e.uuid)?.values()??[])for(const u of o(r))u.status==="active"&&t.push(u);const s=l(e,t,this.#o);if(s===e.version)return e;const i={...e,version:s};return this.#e.set(i.uuid,i),i.uuid!==this.#s&&this.#a(i),i}#a(e){if(e.parentUUID===null)return;let t=this.#t.get(e.parentUUID);t===void 0&&(t=new Map,this.#t.set(e.parentUUID,t));const s=t.get(e.name);if(s===void 0||!Array.isArray(s)&&s.uuid===e.uuid)t.set(e.name,e);else if(!Array.isArray(s))t.set(e.name,[s,e]);else{const i=s.findIndex(r=>r.uuid===e.uuid);i===-1?s.push(e):s[i]=e}}#d(e){if(e.parentUUID===null)return;const t=this.#t.get(e.parentUUID),s=t?.get(e.name);if(!(t===void 0||s===void 0)){if(Array.isArray(s)){const i=s.filter(r=>r.uuid!==e.uuid);i.length!==s.length&&t.set(e.name,i.length===1?i[0]:i);return}s.uuid===e.uuid&&(t.delete(e.name),t.size===0&&this.#t.delete(e.parentUUID))}}}function o(n){return Array.isArray(n)?n:[n]}h(o,"holdersOf");const m=new Set(["file.text","file.binary","link"]);function U(n){return{uuid:n.uuid,type:n.type,parentUUID:n.parentUUID,name:n.name,status:n.status,version:n.version,fileMode:n.fileMode,mtime:n.mtime,size:n.size,target:n.type==="reference"?n.payloadVersion:n.type==="link"?n.linkTarget:null,payloadVersion:m.has(n.type)?n.payloadVersion:null,gitHome:p(n)}}h(U,"mapEntity");export{w as MapIndex,U as mapEntity};
1
+ var l=Object.defineProperty;var r=(u,e)=>l(u,"name",{value:e,configurable:!0});import{membershipVersion as c,recordGitHome as p}from"../entities/rules.js";import{projectPath as g,speaksForCheckout as m}from"../entities/units.js";import{DERIVED_PAYLOAD as w}from"../entities/types.js";import{checkoutAsksProject as v,checkoutDirectories as U,checkoutFileOwner as k,checkoutFolderStands as D,checkoutStands as I}from"../git/checkout.js";import{DriveError as z}from"./contracts.js";class C{static{r(this,"MapIndex")}#i;#g;#e=new Map;#s=new Map;#u=new Set;#r=new Set;#d=new Set;#o=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.#d.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.#d.delete(e),this.#t.set(e,{version:t,sizes:s,directories:s===null?void 0:U(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 d(s))(o(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.#d){const i=this.#e.get(t),s=this.#n.get(t);i===void 0||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=x(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)),m(e)&&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.#d.add(e.uuid):this.#d.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.#p(s.parentUUID)),this.#v(t),t.type==="folder"&&!this.entered(t.uuid)&&this.#r.add(t.uuid),this.#h(t.uuid),this.#p(t.parentUUID)}remove(e){const t=this.#e.get(e);t!==void 0&&e!==this.#i&&this.#p(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.#d.delete(s),this.#o.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 d(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(...d(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?[]:d(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.#c(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=v(e)?this.#k(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)}#k(e){const t=this.#c(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 z("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}#p(e){this.#h(e);let t=this.#e.get(e);if(t?.type!=="folder")return;const i=this.#c(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),w.has(t.type)&&this.#u.has(e)?this.#o.add(e):this.#o.delete(e))}#l(e){if(o(e))return this.#D(e);if(!this.#o.has(e.uuid))return e;const t=[];for(const n of this.#s.get(e.uuid)?.values()??[])for(const h of d(n))h.status==="active"&&this.#f(h)&&t.push(h);const i=c(e,t,this.#g);if(this.#o.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}#D(e){const t=this.#c(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}}#c(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 d(u){return Array.isArray(u)?u:[u]}r(d,"holdersOf");const o=r(u=>k(u)==="git","gitHeld"),A=new Set(["file.text","file.binary","link"]);function x(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:A.has(u.type)?u.payloadVersion:null,gitHome:p(u)}}r(x,"mapEntity");export{C as MapIndex,x 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@11";
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 c=(e,t)=>V(e,"name",{value:t,configurable:!0});import{CONTAINERS as h,DERIVED_PAYLOAD as k,ROOT_TYPES as z,STATUSES as C,TYPES as M,UUID_PATTERN as y}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 m,ITEMS_PER_BOUNDARY as E,sortSteps as B}from"../steps.js";import{failure as J}from"../faults/need.js";const j="amalgm-entity-registry@11",S=1,D=/^[0-9a-f]{64}$/;function lt(e,t){return`pvr_${N(O(t(`private-user:${e}:${j}`))).slice(0,32)}`}c(lt,"privateEntityResourceId");function ct(e){return/^pvr_[A-Za-z0-9_-]{32}$/.test(e)}c(ct,"isPrivateEntityResourceId");const I=c(e=>JSON.stringify(e),"stableJson"),pt=c((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=w(e).records,n=w(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}c(R,"sameRecords");function W(e,t){const r=new Map(t.map(n=>[n.uuid,n]));return w(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})}c(W,"statedRecords");const b=new WeakSet;function Z(e){if(typeof e=="object"&&e!==null&&b.has(e))return e;const t=e;if(!t||typeof t!="object"||typeof t.uuid!="string"||!y.test(t.uuid)||typeof t.type!="string"||!M.has(t.type)||t.parentUUID!==null&&(typeof t.parentUUID!="string"||!y.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(!h.has(t.type)&&r!==null)throw new Error("only a repository, or the container one became, 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 b.add(n),n}c(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}c(q,"assertedRecordsSteps");function*U(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}}c(U,"snapshotFromRecordsSteps");function w(e){return m(U(e))}c(w,"snapshotFromRecords");function*T(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}c(T,"containedRecordsSteps");function dt(e,t){return m(T(e,t))}c(dt,"containedRecords");function*K(e,t){const r=yield*T((yield*U(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(!h.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 g=l.get(a.parentUUID);g?g.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),!!h.has(a.type))){for(const d of l.get(a.uuid)??[])d.status==="active"&&i.push(d);++s%E===0&&(yield)}}const p=[];return yield*f(r,a=>{u.has(a.uuid)&&p.push(a)}),p}c(K,"materializableRecordsSteps");function Q(e,t){return m(K(e,t))}c(Q,"materializableRecords");function ft(e,t){const r=e??[];if(!Array.isArray(r)||r.some(o=>typeof o!="string"||!y.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}c(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)}c(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=c(i=>{const s=[];let p=i,a=!1;for(;p!==void 0;){const d=l.get(p.uuid);if(d!==void 0){a=d;break}if(o.has(p.uuid)){a=!0,s.push(p.uuid);break}s.push(p.uuid),p=p.parentUUID===null?void 0:n.get(p.parentUUID)}for(const d of s)l.set(d,a);return a},"waitsBeneath");return e.filter(i=>!u(i))}c(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}}c(tt,"createRootResolver");function yt(e,t){return m(et(e,t))}c(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(!y.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*U(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,p)=>s!==r[p]))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"&&!h.has(a.type))throw new Error(`cloud root set entity ${s.uuid} has no container parent`)}const p=i(s);if(p===x)throw J("cloud root set has a parent cycle","graph-cycle","parent-cycle");if(p===v)throw new Error(`cloud root set entity ${s.uuid} has incomplete ancestry`);if(!l.has(p))throw new Error(`cloud root set entity ${s.uuid} is outside its declared roots`)}),n.records}c(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 w(t.records)}c(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,T as containedRecordsSteps,ht as installedSubtree,ct as isPrivateEntityResourceId,Q as materializableRecords,K as materializableRecordsSteps,mt as parseSnapshot,lt as privateEntityResourceId,pt as sameRecord,R as sameRecords,w as snapshotFromRecords,U 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;