@amalgm/live 0.2.81-main.47425704837 → 0.2.81-main.47486822282
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.
- package/dist/apply/contracts.d.ts +1 -1
- package/dist/apply/journey.d.ts +2 -2
- package/dist/apply/journey.js +1 -1
- package/dist/apply/line.d.ts +0 -1
- package/dist/apply/line.js +1 -1
- package/dist/apply/rail.d.ts +0 -1
- package/dist/apply/rail.js +1 -1
- package/dist/apply/window.d.ts +1 -2
- package/dist/apply/window.js +1 -1
- package/dist/clash/bodmas.d.ts +1 -0
- package/dist/clash/bodmas.js +1 -1
- package/dist/detection/batch.d.ts +1 -0
- package/dist/detection/package-proposal.d.ts +2 -2
- package/dist/detection/package-proposal.js +1 -1
- package/dist/detection/record-order.js +1 -1
- package/dist/git/config-text.d.ts +4 -0
- package/dist/git/config-text.js +1 -0
- package/dist/git/disk-settings.d.ts +3 -0
- package/dist/git/disk-settings.js +6 -0
- package/dist/git/index.d.ts +2 -0
- package/dist/git/index.js +1 -1
- package/dist/git/play.d.ts +5 -1
- package/dist/git/play.js +4 -4
- package/dist/git/refs.d.ts +7 -0
- package/dist/git/refs.js +10 -8
- package/dist/git/restore.js +1 -2
- package/dist/git/tag.d.ts +1 -1
- package/dist/git/tag.js +3 -3
- package/dist/records/rail-ports.d.ts +4 -1
- package/dist/records/send-line.js +1 -1
- package/dist/records/waits.d.ts +1 -0
- package/dist/records/waits.js +1 -1
- package/dist-cjs/apply/journey.js +1 -1
- package/dist-cjs/apply/line.js +1 -1
- package/dist-cjs/apply/rail.js +1 -1
- package/dist-cjs/apply/window.js +1 -1
- package/dist-cjs/clash/bodmas.js +1 -1
- package/dist-cjs/detection/package-proposal.js +1 -1
- package/dist-cjs/detection/record-order.js +1 -1
- package/dist-cjs/git/config-text.js +1 -0
- package/dist-cjs/git/disk-settings.js +6 -0
- package/dist-cjs/git/index.js +1 -1
- package/dist-cjs/git/play.js +4 -4
- package/dist-cjs/git/refs.js +10 -8
- package/dist-cjs/git/restore.js +1 -2
- package/dist-cjs/git/tag.js +3 -3
- package/dist-cjs/records/send-line.js +1 -1
- package/dist-cjs/records/waits.js +1 -1
- package/package.json +4 -4
|
@@ -236,7 +236,7 @@ export type ApplyGuardStage = 'look' | 'final';
|
|
|
236
236
|
type MaybePromise<T> = T | Promise<T>;
|
|
237
237
|
export interface EntityApplyStorePort {
|
|
238
238
|
readApplyAuthorities(): MaybePromise<readonly string[]>;
|
|
239
|
-
readApplyWindow(authorityId: string
|
|
239
|
+
readApplyWindow(authorityId: string): MaybePromise<EntityApplyLineStep>;
|
|
240
240
|
readFetchWindow(unit: string, through: number | null): MaybePromise<EntityApplyLaneStep>;
|
|
241
241
|
readOpenUnits(): MaybePromise<readonly string[]>;
|
|
242
242
|
localWorkAfter(authorityId: string, entityId: string, target: number | CloudEntityRecord): MaybePromise<LocalWork | null>;
|
package/dist/apply/journey.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ApplyBlocker, type ApplyDependency, type ApplyWindow, type EntityApplyRailOptions, type WindowMember } from './contracts.js';
|
|
2
|
-
export type HeadOutcome = 'progress' |
|
|
2
|
+
export type HeadOutcome = 'progress' | {
|
|
3
3
|
readonly kind: 'alone';
|
|
4
4
|
readonly entityId: string;
|
|
5
5
|
} | {
|
|
@@ -21,5 +21,5 @@ export declare class EntityApplyJourney {
|
|
|
21
21
|
constructor(options: EntityApplyRailOptions, wakeVersion: () => number, stopping: () => boolean);
|
|
22
22
|
targetOf(window: ApplyWindow): number | null;
|
|
23
23
|
run(window: ApplyWindow, emptying: () => string | null): Promise<HeadOutcome>;
|
|
24
|
-
alone(
|
|
24
|
+
alone(window: ApplyWindow, head?: WindowMember): Promise<HeadOutcome>;
|
|
25
25
|
}
|
package/dist/apply/journey.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var j=Object.defineProperty;var w=(l,e)=>j(l,"name",{value:e,configurable:!0});import{createApplyIntent as F,createApplyWindowIntent as
|
|
1
|
+
var j=Object.defineProperty;var w=(l,e)=>j(l,"name",{value:e,configurable:!0});import{createApplyIntent as F,createApplyWindowIntent as O}from"./contracts.js";import{planSelectedEntityApply as P}from"./plans.js";import{Recovering as M}from"../faults/recover.js";import{groundMoved as S}from"../faults/classify.js";import{localWorkWins as W}from"../clash/local-work.js";import{selectEntityApply as E}from"./selection.js";import{isSettlement as q}from"./settling.js";import{revealOrder as D}from"./window.js";function H(l,e){return l.unit===null&&l.authorityId!==e}w(H,"stepsAside");const I={kind:"park",reason:"its window ended with its head unplaced and named no wait",releaseOnProgress:!1,report:!1,again:!0},U=w(l=>l.kind==="captured-local"||l.kind==="rejudge","drops");function A(l){return l.kind==="retry"?{kind:"park",reason:l.reason??"machine truth is unsettled",releaseOnProgress:!1,report:!1}:l.kind==="dependency"?{kind:"park",reason:l.reason,releaseOnProgress:l.waitFor===void 0,report:!1,...l.waitFor?{dependency:l.waitFor}:{},...l.blocker?{blocker:l.blocker}:{},..."comparedAt"in l?{comparedAt:l.comparedAt}:{}}:l.kind==="conflict"?{kind:"park",reason:l.reason,releaseOnProgress:!0,report:!0}:null}w(A,"parkFor");async function B(l){try{return await l()}catch(e){return{kind:"park",reason:e instanceof Error?e.message:String(e),releaseOnProgress:!1,report:!S(e),cause:e}}}w(B,"outcomeOf");const v=w(l=>q(l.judgment)?{kind:"settled",settlement:l.judgment}:null,"settled");class C{static{w(this,"EntityApplyJourney")}#e;#r;#a;#n;constructor(e,t,a){this.#e=e,this.#r={sha256Hex:e.sha256Hex,loops:e.loops,deliveryPosition:e.deliveryPosition},this.#a=t,this.#n=a}targetOf(e){const t=e.members[0];return t===void 0?null:e.intent?.members.find(a=>a.entityId===t.work.entityId)?.throughSequence??(t.work.kept===null?t.work.records.at(-1)?.globalSequence:t.work.resolvedThrough)??null}async run(e,t){if(e.intent!==null)return this.#p(e,e.intent);const a={member:null};try{return await this.#d(e,t,a)}catch(i){if(a.member===null||this.#n())throw i;if(S(i))return{kind:"park",reason:i instanceof Error?i.message:String(i),releaseOnProgress:!1,report:!1};if(H(e,a.member.work.entityId))return this.alone(e,a.member);if(i instanceof M)return{kind:"park",reason:i.message,releaseOnProgress:!1,report:!1,dependency:{producer:"capability",entityIds:i.need.subject===null?[]:[i.need.subject.id]}};throw i}}async alone(e,t=e.members[0]){const{target:a}=E(t.work,this.#r),i=await this.#i({authorityId:t.work.authorityId,entityId:t.work.entityId,targetType:a.result.type,kept:a.record===null?a.result:null,throughSequence:a.throughSequence}),n=await this.#t(e.intent,[t],[{kind:"settled",settlement:i?"superseded":"waiting"}]);return n==="progress"&&!i?{kind:"alone",entityId:t.work.entityId}:n}async#d(e,t,a){const i=this.#e.newIntentId(),n=this.#e.now(),o=t(),s=new Map;for(const c of e.members){if(v(c))continue;const{work:f}=c,m=E(f,this.#r),b=F({attemptId:i,work:f,target:m.target,unit:e.unit,cutoff:e.cutoff,createdAt:n,emptied:f.entityId===o&&f.play==="enter"&&(m.target.result.type==="file.text"||m.target.result.type==="file.binary")}),k=P(f,m,this.#e.sha256Hex);s.set(f.entityId,{member:c,intent:b,plan:k,adapter:this.#e.effects.adapterFor(k.target.type),look:"safe"})}const{active:d,blocked:h}=await this.#o(e.members,s,"look",a);if(d.length===0)return h??I;const g=d.flatMap(c=>s.get(c.work.entityId)??[]);if(g.length===0)return this.#t(null,d,d.map(c=>v(c)));const y=O({attemptId:i,authorityId:e.authorityId,unit:e.unit,cutoff:e.cutoff,createdAt:n,members:g.map(c=>c.intent)});try{const c=await this.#u(d,s,a),f=c.active.flatMap(r=>s.get(r.work.entityId)??[]);if(f.length===0)return await this.#e.effects.discard(y),c.active.length===0?c.blocked??I:this.#t(null,c.active,c.active.map(r=>v(r)));const m=f.length===g.length?y:O({...y,members:f.map(r=>r.intent)}),b=await this.#e.effects.hold(m,f.map(r=>r.plan));let k,x;try{k=await this.#o(c.active,s,"final",a),x=await this.#c(m,k,s,t)}finally{b()}return k.unseen!==null&&k.active.length===0?this.#h(k.unseen):x}catch(c){throw await this.#e.effects.discard(y),c}}async#c(e,{active:t,blocked:a},i,n){const o=t.flatMap(r=>i.get(r.work.entityId)??[]);if(o.length===0)return await this.#e.effects.discard(e),t.length===0?a??I:this.#t(null,t,t.map(r=>v(r)));const s=O({...e,members:o.map(r=>r.intent)}),d=o.filter(r=>r.look==="safe");if(d.length>0){if(this.#n()||o.some(p=>p.intent.emptied&&n()!==p.intent.entityId))return await this.#e.effects.discard(e),I;const r=await this.#e.store.bindWindow(s);if(r)return await this.#e.effects.discard(e),r.kind==="stale"?I:A({...r,comparedAt:this.#a()})}const h=new Map,g=new Map,y=w((r,p,u=null)=>{h.set(r,{kind:"owed",reason:p}),u!==null&&g.set(r,u)},"owe"),c=w(r=>A(r.kind==="dependency"?{...r,comparedAt:this.#a()}:r),"waitFrom"),{order:f,cycle:m}=D(d.map(r=>({entityId:r.intent.entityId,play:r.plan.play,type:r.plan.target.type,parentUUID:r.plan.target.parentUUID}))),b="its parent chain closes among the window's members";for(const r of m)y(r,b,{kind:"park",reason:b,releaseOnProgress:!1,report:!0});for(const r of f){const p=i.get(r),u=await p.adapter.apply.reveal(p.intent,p.plan);u&&y(r,u.reason,u.kind==="dependency"?c(u):null)}for(const r of o){const p=r.intent.entityId;if(h.has(p))continue;const u=await r.adapter.verify.verify(r.intent,r.plan);u.kind==="match"?h.set(p,{kind:"materialized"}):u.kind==="local-change"?y(p,"a person's version stands in its place"):u.kind==="rejudge"||u.kind==="missing-target"?y(p,u.kind):y(p,u.reason??u.kind,c(u))}const k=t.map(r=>v(r)??h.get(r.work.entityId));if(d.length>0)return this.#s(s,t,k,g);const x=await this.#s(null,t,k,g);return await this.#e.effects.discard(e),x}async#s(e,t,a,i){const n=await this.#t(e,t,a),o=a[0];return n!=="progress"||o.kind!=="owed"?n:{...i.get(t[0].work.entityId)??{kind:"park",reason:o.reason,releaseOnProgress:!1,report:!1,again:!0},advanced:t.filter((d,h)=>a[h].kind!=="owed").map(d=>d.work.entityId)}}async#o(e,t,a,i){const n=[];for(const o of e){const s=t.get(o.work.entityId);if(!s){n.push(o);continue}let d;try{d=await this.#i(s.intent)?{kind:"captured-local"}:a==="look"?await this.#f(s):await s.adapter.apply.guard(s.intent,s.plan,a)}catch(g){if(n.length>0&&!this.#n())return{active:n,blocked:null,unseen:null};throw i.member=o,g}if(d.kind==="local-change"||d.kind==="unsettled-ground")return{active:n,blocked:n.length===0?I:null,unseen:s};if(U(d))return{active:n,blocked:n.length===0?I:null,unseen:null};const h=A(d);if(h)return{active:n,blocked:h,unseen:null};s.look=d.kind,n.push(o)}return{active:n,blocked:null,unseen:null}}async#u(e,t,a){for(const[i,n]of e.entries()){const o=t.get(n.work.entityId);if(!(!o||o.look!=="safe"))try{const s=await o.adapter.apply.prepare(o.intent,o.plan);if(s)return{active:e.slice(0,i),blocked:A(s)}}catch(s){if(i>0&&!this.#n())return{active:e.slice(0,i),blocked:null};throw a.member=n,s}}return{active:[...e],blocked:null}}async#p(e,t){const a=t.members.map(n=>{const o=e.members.find(d=>d.work.entityId===n.entityId);if(!o)return null;const s=n.kept===null?o.work:{...o.work,records:[],kept:n.kept};return s.records.length===0&&s.kept===null?null:P(s,E(s,this.#r,n),this.#e.sha256Hex)}),i=await this.#e.effects.recover(t,a);if(i.length!==t.members.length)throw new Error("Apply recovery answered for a different window");return this.#t(t,e.members,e.members.map(n=>v(n)??i[t.members.findIndex(o=>o.entityId===n.work.entityId)]??{kind:"owed",reason:"not a member of the bound window"}))}async#t(e,t,a){const i=await this.#e.store.endWindow(e,t,a);if(!i)return"progress";if(i.kind!=="stale"||!i.reason)throw new Error("Apply end commit returned an unknown refusal");return I}async#i(e){return W(e.targetType,await this.#e.store.localWorkAfter(e.authorityId,e.entityId,e.kept??e.throughSequence))}async#f(e){const{intent:t,plan:a,adapter:i}=e,n=await i.apply.guard(t,a,"look");if(n.kind!=="local-change"&&n.kind!=="unsettled-ground")return n;const o=await this.#l(t,a);if(o.kind!=="observed")return o;const s=await i.apply.guard(t,a,"look");return s.kind==="local-change"||s.kind==="unsettled-ground"?{kind:"retry",reason:"Ground still needs observation after Detect; this member cannot reveal."}:s}async#h(e){const t=await this.#l(e.intent,e.plan);return t.kind==="captured-local"?I:A(t.kind==="observed"?{kind:"retry",reason:"Its final guard found ground Detect had not recorded; it is judged again after Detect looks."}:t)}async#l(e,t){if(await this.#i(e))return{kind:"captured-local"};let a,i=!0;const n=await this.#e.effects.captureLocal(e,t,()=>{if(!i||a!==void 0)throw new Error("Apply capture comparison must be marked exactly once");a=this.#a()}).finally(()=>{i=!1});if(!n||!["settled","local-only","retry"].includes(n.kind))throw new Error("Apply capture returned no explicit observation outcome");if(await this.#i(e))return{kind:"captured-local"};if(n.kind==="retry")return n;if(n.kind==="local-only"){if(a===void 0)throw new Error("local-only capture requires a synchronous comparison fence");if(!n.reason||n.entityIds.length===0||n.entityIds.some(o=>!o))throw new Error("local-only capture must name the retained ground and its releasing condition");return{kind:"dependency",reason:n.reason,comparedAt:a,waitFor:{producer:"detect",entityIds:n.entityIds}}}return{kind:"observed"}}}export{C as EntityApplyJourney,B as outcomeOf,H as stepsAside};
|
package/dist/apply/line.d.ts
CHANGED
|
@@ -22,7 +22,6 @@ export interface ApplyTrack {
|
|
|
22
22
|
export interface ApplyLineState extends ApplyTrack {
|
|
23
23
|
readonly kind: 'line';
|
|
24
24
|
readonly authorityId: string;
|
|
25
|
-
endsBefore: number | null;
|
|
26
25
|
}
|
|
27
26
|
export declare function createApplyLine(authorityId: string): ApplyLineState;
|
|
28
27
|
export declare function releaseApplyLine(line: ApplyTrack, producer: ApplyDependency['producer'], entityIds: readonly string[] | undefined): boolean;
|
package/dist/apply/line.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var a=Object.defineProperty;var r=(e,n)=>a(e,"name",{value:n,configurable:!0});import{UUID_PATTERN as f}from"../entities/types.js";function w(e){return{kind:"line",authorityId:e,held:null,queued:!1,running:!1,again:!1}}r(w,"createApplyLine");function k(e,n,o){const i=e.held;return!i?.dependency||i.due||i.dependency.producer!==n||o!==void 0&&!i.dependency.entityIds.some(l=>o.includes(l))?!1:(i.due=!0,!0)}r(k,"releaseApplyLine");function g(e,n){if(e)return e.entityId===null||e.target===null?{entityId:e.entityId??n,reason:e.reason,throughSequence:e.target??e.cutoff??0}:{entityId:e.entityId,reason:e.reason,...e.dependency?{prerequisite:e.dependency}:{},throughSequence:e.target,...e.blocker?{blocker:e.blocker}:{}}}r(g,"heldWait");const d=new Set(["detect","apply","capability","send"]),c=r(e=>!!e&&d.has(e.producer)&&Array.isArray(e.entityIds)&&e.entityIds.length>0&&e.entityIds.every(n=>typeof n=="string"&&n.length>0),"namesRelease");function A(e){if(!c(e))throw new Error("Apply dependency must name the entities that can release it")}r(A,"assertApplyDependency");function b(e,n){(!n||typeof n!="object")&&u(`line step for ${e}`),n.kind!=="end"&&((n.kind!=="window"||n.window?.authorityId!==e||n.window.unit!==null||n.window.cutoff!==null||n.window.members?.some(o=>o.work?.kept!==null)||n.window.intent!==null&&(n.window.intent.unit!==null||n.window.intent.cutoff!==null))&&u(`line step for ${e}`),y(n.window,`line step for ${e}`))}r(b,"assertApplyLineStep");const u=r(e=>{throw new Error(`entity Apply store returned an invalid ${e}`)},"invalidStep");function y(e,n){Array.isArray(e.members)||u(n);const o=r((t,s)=>Number.isSafeInteger(t)&&t>=(s?0:1),"at");for(const t of e.members)(!f.test(t.work?.entityId??"")||t.work.authorityId!==e.authorityId||!o(t.deliverySequence,t.work.kept!==null))&&u(n),(t.unseen!==void 0||t.judgment==="unseen")&&(f.test(t.unseen??"")||u(n));const{deliverySequence:i}=e,l=e.members[0];(i===null?!e.intent:l===void 0||!o(i,l.work.kept!==null))&&u(n)}r(y,"assertApplyWindow");export{A as assertApplyDependency,b as assertApplyLineStep,y as assertApplyWindow,w as createApplyLine,g as heldWait,u as invalidStep,k as releaseApplyLine};
|
package/dist/apply/rail.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ import type { ApplyFetchAnswer, ApplyWait, EntityApplyRailOptions } from './cont
|
|
|
2
2
|
export declare const ENTITY_APPLY_DEFAULT_CONCURRENCY = 8;
|
|
3
3
|
export declare const ENTITY_APPLY_RETRY_BASE_MS = 1000;
|
|
4
4
|
export declare const ENTITY_APPLY_RETRY_MAX_MS = 30000;
|
|
5
|
-
export declare const ENTITY_APPLY_SAME_ANSWERS = 3;
|
|
6
5
|
export declare class EntityApplyRail {
|
|
7
6
|
#private;
|
|
8
7
|
constructor(options: EntityApplyRailOptions);
|
package/dist/apply/rail.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var E=Object.defineProperty;var d=(o,e)=>E(o,"name",{value:e,configurable:!0});import{UUID_PATTERN as u}from"../entities/types.js";import{FetchAhead as b}from"./fetch-ahead.js";import{EntityApplyJourney as P,outcomeOf as g,stepsAside as v}from"./journey.js";import{assertApplyLaneStep as O,createApplyLane as S}from"./lane.js";import{assertApplyDependency as $,assertApplyLineStep as q,createApplyLine as M,heldWait as c,releaseApplyLine as _}from"./line.js";import{windowEndForWait as m}from"./window.js";const x=8,B=1e3,A=3e4,p=3;class C{static{d(this,"EntityApplyRail")}#e;#g;#P;#_;#x;#o;#v;#d=!1;#t=!1;#a=new Map;#s=new Map;#l={queue:[],steps:new Set};#u={queue:[],steps:new Set};#n=!1;#h=null;#p=1/0;#m=[];#A=0;#O=new Map;#y=null;constructor(e){this.#e=e,this.#g=e.concurrency??x,this.#P=e.laneConcurrency??this.#g,this.#_=e.onBackgroundError??(()=>{}),this.#x=e.onIdle??(()=>{});for(const[t,s]of[["concurrency",this.#g],["lane concurrency",this.#P]])if(!Number.isSafeInteger(s)||s<1)throw new Error(`entity Apply ${t} must be a positive integer`);this.#o=new P(e,()=>this.#A,()=>this.#t),this.#v=new b(e.cargo,{sha256Hex:e.sha256Hex,loops:e.loops,deliveryPosition:e.deliveryPosition})}async start(){if(this.#d)throw new Error("entity Apply rail already started");if(this.#t)throw new Error("entity Apply rail is stopped");this.#d=!0;const e=await this.#e.store.readOpenUnits();if(!Array.isArray(e)||new Set(e).size!==e.length||e.some(t=>!u.test(t)))throw new Error("entity Apply store returned an invalid open unit list");for(const t of e)this.#E(t,null);await this.#B()}fetch(e,t){return this.#d?this.#t?Promise.reject(new Error("entity Apply rail is stopped")):u.test(e)?!Number.isFinite(t.stall)||t.stall<0?Promise.reject(new Error("entity Apply fetch needs a non-negative stall")):t.emptied!==void 0&&typeof t.emptied!="boolean"?Promise.reject(new Error("entity Apply fetch emptied must be a boolean")):new Promise((s,i)=>{const r=this.#E(e,null,t.emptied===!0),n=d(()=>this.#e.schedule.schedule(t.stall,()=>{r.waiters.delete(l)&&(r.emptied&&![...r.waiters].some(a=>a.emptied)&&(r.emptied=!1),s(this.#K(r)))}),"arm");let h=n();const l={emptied:t.emptied===!0,answer:d(a=>{h.cancel(),s(a)},"answer"),fail:d(a=>{h.cancel(),i(a)},"fail"),moved:d(()=>{h.cancel(),h=n()},"moved")};r.waiters.add(l),r.waitsOn===null&&this.#T(r),this.#r()}):Promise.reject(new Error("entity Apply fetch needs a unit UUID")):Promise.reject(new Error("entity Apply rail has not started"))}progressed(e,t){if(!u.test(e))throw new Error("entity Apply progress needs a unit UUID");if(!Number.isSafeInteger(t)||t<0)throw new Error("entity Apply progress needs a byte count");t>0&&!this.#t&&this.#b(e)}recordsAvailable(){this.#I()}localStateChanged(e){this.#c("detect",e),this.#c("apply",e),this.#I()}sendAccepted(e){this.#c("send",e),this.#I()}capabilityChanged(e){this.#c("capability",e),this.#I()}owe(e){if(e.some(t=>!u.test(t)))throw new Error("entity Apply owe needs entity UUIDs");if(!(!this.#d||this.#t)){for(const t of e)this.#S(t);this.#r()}}#I(){!this.#d||this.#t||(this.#n=!0,this.#r())}waiting(){return this.#w().flatMap(e=>c(e.held,y(e))??[])}async flush(){if(!this.#d)throw new Error("entity Apply rail has not started");this.#t||await this.#B()}async stop(){if(this.#t)return;this.#t=!0,this.#M();for(const t of[this.#l,this.#u])for(const s of t.queue.splice(0))s.queued=!1;const e=new Error("entity Apply rail stopped before the fetch answered");for(const t of this.#s.values())for(const s of t.waiters)s.fail(e);for(this.#s.clear();this.#R()>0||this.#h;)await Promise.allSettled([...this.#l.steps,...this.#u.steps,...this.#h?[this.#h]:[]]);await this.#v.stop();for(const t of this.#m.splice(0))t.resolve()}#B(){return new Promise((e,t)=>{this.#m.push({resolve:e,reject:t}),this.#n=!0,this.#r()})}#r(){if(!this.#t){if(this.#n&&this.#h===null){this.#n=!1;const e=this.#J();this.#h=e,e.then(()=>{this.#h=null,this.#r()})}for(const[e,t]of[[this.#u,this.#P],[this.#l,this.#g]])for(;e.steps.size<t&&e.queue.length>0;){const s=e.queue.shift();s.queued=!1,this.#F(s,e)}if(this.#R()===0&&this.#h===null&&!this.#n&&this.#l.queue.length===0&&this.#u.queue.length===0){if(this.#O.clear(),this.#D(this.#e.now())){this.#r();return}this.#q();for(const e of this.#m.splice(0))e.resolve();this.#x()}}}#R(){return this.#l.steps.size+this.#u.steps.size}#w(){return[...this.#a.values(),...this.#s.values()]}#k(e){return e.kind==="line"?this.#a.get(e.authorityId)===e:this.#s.get(e.unit)===e}#i(e){if(!this.#t){if(e.running){e.again=!0;return}e.queued||(e.queued=!0,(e.kind==="line"?this.#l:this.#u).queue.push(e))}}#F(e,t){e.running=!0,e.again=!1;const s=(e.kind==="line"?this.#H(e):this.#V(e)).then(i=>{e.running=!1,t.steps.delete(s),(i||e.again)&&this.#k(e)&&(e.again=!1,this.#i(e)),this.#r()});t.steps.add(s)}async#J(){try{const e=await this.#e.store.readApplyAuthorities();if(!Array.isArray(e)||new Set(e).size!==e.length||e.some(s=>typeof s!="string"||s.length===0))throw new Error("entity Apply store returned an invalid authority list");this.#p=1/0;const t=new Set(e);for(const[s,i]of this.#a)!t.has(s)&&!i.running&&!i.queued&&this.#a.delete(s);for(const s of e){let i=this.#a.get(s);i||(i=M(s),this.#a.set(s,i)),this.#i(i)}}catch(e){this.#p=this.#e.now()+A;const t=this.#m.splice(0);t.length===0&&this.#$(e);for(const s of t)s.reject(e)}}async#H(e){try{const t=e.held;if(t&&t.entityId===null&&!t.due&&t.notBefore>this.#e.now())return!1;const s=this.#A,i=await this.#e.store.readApplyWindow(e.authorityId,e.endsBefore);if(q(e.authorityId,i),this.#t)return!1;if(i.kind==="end"){e.held=null;const r=e.endsBefore!==null;return e.endsBefore=null,r}return i.window.deliverySequence!==null&&this.#v.advance(e.authorityId,i.window.deliverySequence),await this.#U(e,i.window,s)}catch(t){return this.#C(e,t),!1}}async#V(e){try{const t=e.held;if(t&&t.entityId===null&&!t.due&&t.notBefore>this.#e.now())return!1;const s=this.#A,i=await this.#e.store.readFetchWindow(e.unit,e.toPrefix?null:e.through);if(O(e.unit,i),this.#t||!this.#k(e))return!1;if(e.waitsOn=null,i.kind==="unseen")return this.#N(e,{producer:"detect",entityIds:[e.unit]},i.reason,s);if(!e.again&&(i.kind!=="window"||i.window.intent===null)&&(e.toPrefix=!1),e.through!==null&&i.through>e.through&&e.met.clear(),e.through=Math.max(e.through??0,i.through),i.kind!=="window"&&(e.held=null),e.again&&(i.kind==="end"||i.kind==="nowhere"))return!0;switch(i.kind){case"end":return this.#f(e,{kind:"placed"}),!1;case"nowhere":return this.#f(e,{kind:"nowhere",reason:i.reason}),!1;case"root":return await this.#X(e,i.through,i.reason);case"prerequisite":return this.#G(e,i.unit,i.reason,s);case"window":return await this.#U(e,i.window,s)}}catch(t){return this.#C(e,t),!1}}async#X(e,t,s){return e.met.has(e.unit)?(this.#f(e,{kind:"held",unit:e.unit,reason:`${e.unit} entered and still not held: ${s}`}),!1):(await this.#e.effects.enterRoot(e.unit,t),this.#t||!this.#k(e)?!1:(e.through===t&&e.met.add(e.unit),this.#b(e.unit),!0))}#S(e){const t=this.#E(e,null);t.toPrefix=!0,t.met.clear(),this.#i(t)}#E(e,t,s=!1){let i=this.#s.get(e);return i?t!==null&&(i.through===null||i.through<t)&&(i.through=t,i.met.clear(),this.#i(i)):(i=S(e,t,s),this.#s.set(e,i),this.#i(i)),i}#G(e,t,s,i){return e.met.has(t)?(this.#f(e,{kind:"held",unit:t,reason:`${t} placed and still needed: ${s}`}),!1):this.#L(e,t,s)?this.#N(e,{producer:"apply",entityIds:[t]},s,i):!1}#N(e,t,s,i){return e.held={entityId:null,target:null,kept:null,cutoff:null,attempt:1,notBefore:1/0,releaseOnProgress:!1,due:this.#z(t,i),reason:s,dependency:t},e.held.due}#T(e){const t=e.held;if(t?.dependency?.producer==="apply"){for(const s of t.dependency.entityIds)if(s!==e.unit&&!e.met.has(s)&&!this.#L(e,s,t.reason))return}}#L(e,t,s){const i=[e];let r=this.#s.get(t);for(;r&&r!==e&&!i.includes(r);)i.push(r),r=r.waitsOn===null?void 0:this.#s.get(r.waitsOn);if(r===e){for(const n of i)this.#f(n,{kind:"held",unit:t,reason:`prerequisite cycle through ${t}: ${s}`});return!1}return e.waitsOn??=t,this.#i(this.#E(t,e.through)),!0}#f(e,t){if(!this.#k(e))return;for(const i of e.waiters)i.answer(t);e.waiters.clear(),e.waitsOn=null,(t.kind==="placed"||e.held?.entityId==null)&&this.#s.delete(e.unit);const s=t.kind==="placed"||t.kind==="held"?t:{kind:"held",unit:e.unit,reason:`${e.unit} is nowhere here: ${t.reason}`};for(const i of[...this.#s.values()])if(i.waitsOn===e.unit){if(t.kind!=="placed"){this.#f(i,s);continue}i.met.add(e.unit)}t.kind==="placed"&&(this.#b(e.unit),this.#c("apply",[e.unit]))}#b(e){const t=new Map([[e,!0]]);for(const s of this.#s.values()){const i=new Set;let r=s.unit;for(;r!==null&&!t.has(r)&&!i.has(r);)i.add(r),r=this.#s.get(r)?.waitsOn??null;const n=r!==null&&t.get(r)===!0;for(const h of i)t.set(h,n);if(n)for(const h of s.waiters)h.moved()}}#K(e){let t=e;const s=new Set([e]);for(let i=e.waitsOn===null?void 0:this.#s.get(e.waitsOn);i&&!s.has(i);i=i.waitsOn===null?void 0:this.#s.get(i.waitsOn))s.add(i),t=i;return{kind:"held",unit:t.unit,reason:t.held?.reason??"still placing"}}async#U(e,t,s){const i=t.members[0]?.work.entityId??null;if(e.held&&e.held.entityId!==null&&e.held.entityId!==i&&(e.held=null),await this.#Z(e,t))return!1;let r=await g(()=>this.#o.run(t,()=>e.kind==="lane"&&e.emptied?e.unit:null));if(e.kind==="line"&&typeof r=="object"&&r.kind==="park"&&m(t,r.dependency)===null&&this.#Q(e,t,r)&&(r=await g(()=>this.#o.alone(t.members[0]))),r==="progress"||typeof r=="object"&&r.kind==="alone"){if(e.kind==="line")for(const n of t.members)(n.judgment==="waiting"||r!=="progress"&&n.work.entityId===r.entityId)&&this.#S(n.work.entityId);for(const n of t.members)n.unseen!==void 0&&this.#S(n.unseen);return this.#ee(e,r==="progress"?t.members.map(n=>n.work.entityId):[r.entityId])}if(r==="again")return e.held?.entityId===i&&(e.held=null),!0;if(r.advanced?.length&&this.#j(e,r.advanced),e.kind==="line"){const n=m(t,r.dependency);if(n!==null)return e.endsBefore=n,!0}return this.#te(e,t,r,s),e.kind==="lane"&&this.#T(e),e.held.due}#Q(e,t,s){const i=t.members[0].work.entityId;if(s.cause!==void 0||!v(t,i))return!1;const r=s.dependency?.entityIds??[i];return r.length===0||r.some(n=>n!==i)?!1:s.dependency?.producer==="capability"?!0:this.#Y(e,t)>=p}#Y(e,t){const s=e.held,i=t.members[0].work.entityId;return(s?.entityId===i&&s.target===this.#o.targetOf(t)?s.attempt:0)+1}async#Z(e,t){const s=e.held,i=t.members[0];return!s||i===void 0||s.entityId!==i.work.entityId||s.due||s.notBefore<=this.#e.now()||this.#o.targetOf(t)!==s.target||t.cutoff!==s.cutoff?!1:await this.#e.store.localWorkAfter(t.authorityId,i.work.entityId,s.kept??s.target)===null}#ee(e,t){return e.held&&(e.held.entityId===null||t.includes(e.held.entityId))&&(e.held=null),this.#j(e,t),!0}#j(e,t){e.kind==="lane"&&(this.#n=!0,this.#b(e.unit)),this.#c("apply",t);for(const s of this.#w())s!==e&&s.held?.releaseOnProgress&&!s.held.due&&(s.held.due=!0,this.#i(s))}#te(e,t,s,i){if(s.dependency&&$(s.dependency),s.blocker&&!s.dependency)throw new Error("Apply blocker must name the dependency that releases it");const r=t.members[0].work.entityId,n=e.held,h=this.#Y(e,t),l=this.#W(h),a=s.again===!0&&h<p,w={entityId:r,target:this.#o.targetOf(t),kept:t.members[0].work.kept,cutoff:t.cutoff,attempt:h,notBefore:s.dependency?1/0:this.#e.now()+(a?0:l),releaseOnProgress:s.releaseOnProgress,due:s.dependency?this.#z(s.dependency,s.comparedAt??i):a,reason:s.reason,...s.dependency?{dependency:s.dependency}:{},...s.blocker?{blocker:s.blocker}:{}};e.held=w,this.#q();const k=c(n,y(e)),f=c(w,y(e));f&&JSON.stringify(f)!==JSON.stringify(k)&&this.#e.onWaiting?.(f),!(!s.report&&(s.dependency!==void 0||h<p))&&this.#$(new Error(`${I(e)} holds at ${r}, which ${s.releaseOnProgress?"is parked on a conflict":s.report?"failed":s.again?"keeps ending unplaced":"stands on ground that keeps moving"}, and will retry in ${l}ms (attempt ${h}): ${s.reason}`,s.cause===void 0?void 0:{cause:s.cause}))}#C(e,t){if(e.kind==="lane"){for(const h of e.waiters)h.fail(t);e.waiters.clear()}const s=e.held,i=(s?.entityId===null?s.attempt:0)+1,r=this.#W(i),n=t instanceof Error?t.message:String(t);e.held={entityId:null,target:null,kept:null,cutoff:null,attempt:i,notBefore:this.#e.now()+r,releaseOnProgress:!1,due:!1,reason:n},this.#q(),this.#$(new Error(`${I(e)} faulted and will retry in ${r}ms (attempt ${i}): ${n}`,{cause:t}))}#$(e){try{this.#_(e)}catch{}}#W(e){const t=Math.min(A,B*2**Math.min(e-1,16)),s=Math.max(0,Math.min(1,this.#e.schedule.random()));return Math.round(t*(.5+s))}#c(e,t){const s=++this.#A;for(const i of t??["*"])this.#O.set(`${e}:${i}`,s);for(const i of this.#w())_(i,e,t)&&this.#i(i)}#z(e,t){return["*",...e.entityIds].some(s=>(this.#O.get(`${e.producer}:${s}`)??0)>t)}#q(){if(this.#t)return;let e=this.#p;for(const i of this.#w())i.held&&!i.held.due&&(e=Math.min(e,i.held.notBefore));if(e===1/0){this.#M();return}if(this.#y?.dueAt===e)return;this.#M();const t=Math.max(0,e-this.#e.now()),s=this.#e.schedule.schedule(t,()=>{this.#y=null,this.#D(e),this.#r()});this.#y={dueAt:e,cancel:d(()=>s.cancel(),"cancel")}}#D(e){let t=!1;for(const s of this.#w())s.held&&!s.held.due&&s.held.notBefore<=e&&(s.held.due=!0,this.#i(s),t=!0);return this.#p<=e&&(this.#p=1/0,this.#n=!0,t=!0),t}#M(){this.#y?.cancel(),this.#y=null}}const y=d(o=>o.kind==="line"?o.authorityId:o.unit,"owner"),I=d(o=>o.kind==="line"?`entity Apply line ${o.authorityId}`:`entity Apply fetch of ${o.unit}`,"label");export{x as ENTITY_APPLY_DEFAULT_CONCURRENCY,B as ENTITY_APPLY_RETRY_BASE_MS,A as ENTITY_APPLY_RETRY_MAX_MS,p as ENTITY_APPLY_SAME_ANSWERS,C as EntityApplyRail};
|
|
1
|
+
var I=Object.defineProperty;var a=(o,t)=>I(o,"name",{value:t,configurable:!0});import{UUID_PATTERN as u}from"../entities/types.js";import{FetchAhead as k}from"./fetch-ahead.js";import{EntityApplyJourney as b,outcomeOf as w,stepsAside as E}from"./journey.js";import{assertApplyLaneStep as P,createApplyLane as v}from"./lane.js";import{assertApplyDependency as O,assertApplyLineStep as $,createApplyLine as S,heldWait as p,releaseApplyLine as q}from"./line.js";const M=8,x=1e3,g=3e4;function _(o,t){const e=o.members[0];return t.cause===void 0&&e!==void 0&&E(o,e.work.entityId)}a(_,"stuck");class j{static{a(this,"EntityApplyRail")}#t;#g;#P;#x;#_;#o;#v;#a=!1;#e=!1;#d=new Map;#i=new Map;#l={queue:[],steps:new Set};#u={queue:[],steps:new Set};#r=!1;#h=null;#p=1/0;#m=[];#A=0;#O=new Map;#y=null;constructor(t){this.#t=t,this.#g=t.concurrency??M,this.#P=t.laneConcurrency??this.#g,this.#x=t.onBackgroundError??(()=>{}),this.#_=t.onIdle??(()=>{});for(const[e,i]of[["concurrency",this.#g],["lane concurrency",this.#P]])if(!Number.isSafeInteger(i)||i<1)throw new Error(`entity Apply ${e} must be a positive integer`);this.#o=new b(t,()=>this.#A,()=>this.#e),this.#v=new k(t.cargo,{sha256Hex:t.sha256Hex,loops:t.loops,deliveryPosition:t.deliveryPosition})}async start(){if(this.#a)throw new Error("entity Apply rail already started");if(this.#e)throw new Error("entity Apply rail is stopped");this.#a=!0;const t=await this.#t.store.readOpenUnits();if(!Array.isArray(t)||new Set(t).size!==t.length||t.some(e=>!u.test(e)))throw new Error("entity Apply store returned an invalid open unit list");for(const e of t)this.#b(e,null);await this.#R()}fetch(t,e){return this.#a?this.#e?Promise.reject(new Error("entity Apply rail is stopped")):u.test(t)?!Number.isFinite(e.stall)||e.stall<0?Promise.reject(new Error("entity Apply fetch needs a non-negative stall")):e.emptied!==void 0&&typeof e.emptied!="boolean"?Promise.reject(new Error("entity Apply fetch emptied must be a boolean")):new Promise((i,s)=>{const n=this.#b(t,null,e.emptied===!0),r=a(()=>this.#t.schedule.schedule(e.stall,()=>{n.waiters.delete(l)&&(n.emptied&&![...n.waiters].some(d=>d.emptied)&&(n.emptied=!1),i(this.#G(n)))}),"arm");let h=r();const l={emptied:e.emptied===!0,answer:a(d=>{h.cancel(),i(d)},"answer"),fail:a(d=>{h.cancel(),s(d)},"fail"),moved:a(()=>{h.cancel(),h=r()},"moved")};n.waiters.add(l),n.waitsOn===null&&this.#N(n),this.#n()}):Promise.reject(new Error("entity Apply fetch needs a unit UUID")):Promise.reject(new Error("entity Apply rail has not started"))}progressed(t,e){if(!u.test(t))throw new Error("entity Apply progress needs a unit UUID");if(!Number.isSafeInteger(e)||e<0)throw new Error("entity Apply progress needs a byte count");e>0&&!this.#e&&this.#E(t)}recordsAvailable(){this.#I()}localStateChanged(t){this.#c("detect",t),this.#c("apply",t),this.#I()}sendAccepted(t){this.#c("send",t),this.#I()}capabilityChanged(t){this.#c("capability",t),this.#I()}owe(t){if(t.some(e=>!u.test(e)))throw new Error("entity Apply owe needs entity UUIDs");if(!(!this.#a||this.#e)){for(const e of t)this.#$(e);this.#n()}}#I(){!this.#a||this.#e||(this.#r=!0,this.#n())}waiting(){return this.#w().flatMap(t=>p(t.held,y(t))??[])}async flush(){if(!this.#a)throw new Error("entity Apply rail has not started");this.#e||await this.#R()}async stop(){if(this.#e)return;this.#e=!0,this.#M();for(const e of[this.#l,this.#u])for(const i of e.queue.splice(0))i.queued=!1;const t=new Error("entity Apply rail stopped before the fetch answered");for(const e of this.#i.values())for(const i of e.waiters)i.fail(t);for(this.#i.clear();this.#B()>0||this.#h;)await Promise.allSettled([...this.#l.steps,...this.#u.steps,...this.#h?[this.#h]:[]]);await this.#v.stop();for(const e of this.#m.splice(0))e.resolve()}#R(){return new Promise((t,e)=>{this.#m.push({resolve:t,reject:e}),this.#r=!0,this.#n()})}#n(){if(!this.#e){if(this.#r&&this.#h===null){this.#r=!1;const t=this.#F();this.#h=t,t.then(()=>{this.#h=null,this.#n()})}for(const[t,e]of[[this.#u,this.#P],[this.#l,this.#g]])for(;t.steps.size<e&&t.queue.length>0;){const i=t.queue.shift();i.queued=!1,this.#W(i,t)}if(this.#B()===0&&this.#h===null&&!this.#r&&this.#l.queue.length===0&&this.#u.queue.length===0){if(this.#O.clear(),this.#D(this.#t.now())){this.#n();return}this.#q();for(const t of this.#m.splice(0))t.resolve();this.#_()}}}#B(){return this.#l.steps.size+this.#u.steps.size}#w(){return[...this.#d.values(),...this.#i.values()]}#k(t){return t.kind==="line"?this.#d.get(t.authorityId)===t:this.#i.get(t.unit)===t}#s(t){if(!this.#e){if(t.running){t.again=!0;return}t.queued||(t.queued=!0,(t.kind==="line"?this.#l:this.#u).queue.push(t))}}#W(t,e){t.running=!0,t.again=!1;const i=(t.kind==="line"?this.#J(t):this.#H(t)).then(s=>{t.running=!1,e.steps.delete(i),(s||t.again)&&this.#k(t)&&(t.again=!1,this.#s(t)),this.#n()});e.steps.add(i)}async#F(){try{const t=await this.#t.store.readApplyAuthorities();if(!Array.isArray(t)||new Set(t).size!==t.length||t.some(i=>typeof i!="string"||i.length===0))throw new Error("entity Apply store returned an invalid authority list");this.#p=1/0;const e=new Set(t);for(const[i,s]of this.#d)!e.has(i)&&!s.running&&!s.queued&&this.#d.delete(i);for(const i of t){let s=this.#d.get(i);s||(s=S(i),this.#d.set(i,s)),this.#s(s)}}catch(t){this.#p=this.#t.now()+g;const e=this.#m.splice(0);e.length===0&&this.#S(t);for(const i of e)i.reject(t)}}async#J(t){try{const e=t.held;if(e&&e.entityId===null&&!e.due&&e.notBefore>this.#t.now())return!1;const i=this.#A,s=await this.#t.store.readApplyWindow(t.authorityId);return $(t.authorityId,s),this.#e?!1:s.kind==="end"?(t.held=null,!1):(s.window.deliverySequence!==null&&this.#v.advance(t.authorityId,s.window.deliverySequence),await this.#U(t,s.window,i))}catch(e){return this.#Y(t,e),!1}}async#H(t){try{const e=t.held;if(e&&e.entityId===null&&!e.due&&e.notBefore>this.#t.now())return!1;const i=this.#A,s=await this.#t.store.readFetchWindow(t.unit,t.toPrefix?null:t.through);if(P(t.unit,s),this.#e||!this.#k(t))return!1;if(t.waitsOn=null,s.kind==="unseen")return this.#L(t,{producer:"detect",entityIds:[t.unit]},s.reason,i);if(!t.again&&(s.kind!=="window"||s.window.intent===null)&&(t.toPrefix=!1),t.through!==null&&s.through>t.through&&t.met.clear(),t.through=Math.max(t.through??0,s.through),s.kind!=="window"&&(t.held=null),t.again&&(s.kind==="end"||s.kind==="nowhere"))return!0;switch(s.kind){case"end":return this.#f(t,{kind:"placed"}),!1;case"nowhere":return this.#f(t,{kind:"nowhere",reason:s.reason}),!1;case"root":return await this.#V(t,s.through,s.reason);case"prerequisite":return this.#X(t,s.unit,s.reason,i);case"window":return await this.#U(t,s.window,i)}}catch(e){return this.#Y(t,e),!1}}async#V(t,e,i){return t.met.has(t.unit)?(this.#f(t,{kind:"held",unit:t.unit,reason:`${t.unit} entered and still not held: ${i}`}),!1):(await this.#t.effects.enterRoot(t.unit,e),this.#e||!this.#k(t)?!1:(t.through===e&&t.met.add(t.unit),this.#E(t.unit),!0))}#$(t){const e=this.#b(t,null);e.toPrefix=!0,e.met.clear(),this.#s(e)}#b(t,e,i=!1){let s=this.#i.get(t);return s?e!==null&&(s.through===null||s.through<e)&&(s.through=e,s.met.clear(),this.#s(s)):(s=v(t,e,i),this.#i.set(t,s),this.#s(s)),s}#X(t,e,i,s){return t.met.has(e)?(this.#f(t,{kind:"held",unit:e,reason:`${e} placed and still needed: ${i}`}),!1):this.#T(t,e,i)?this.#L(t,{producer:"apply",entityIds:[e]},i,s):!1}#L(t,e,i,s){return t.held={entityId:null,target:null,kept:null,cutoff:null,attempt:1,notBefore:1/0,releaseOnProgress:!1,due:this.#z(e,s),reason:i,dependency:e},t.held.due}#N(t){const e=t.held;if(e?.dependency?.producer==="apply"){for(const i of e.dependency.entityIds)if(i!==t.unit&&!t.met.has(i)&&!this.#T(t,i,e.reason))return}}#T(t,e,i){const s=[t];let n=this.#i.get(e);for(;n&&n!==t&&!s.includes(n);)s.push(n),n=n.waitsOn===null?void 0:this.#i.get(n.waitsOn);if(n===t){for(const r of s)this.#f(r,{kind:"held",unit:e,reason:`prerequisite cycle through ${e}: ${i}`});return!1}return t.waitsOn??=e,this.#s(this.#b(e,t.through)),!0}#f(t,e){if(!this.#k(t))return;for(const s of t.waiters)s.answer(e);t.waiters.clear(),t.waitsOn=null,(e.kind==="placed"||t.held?.entityId==null)&&this.#i.delete(t.unit);const i=e.kind==="placed"||e.kind==="held"?e:{kind:"held",unit:t.unit,reason:`${t.unit} is nowhere here: ${e.reason}`};for(const s of[...this.#i.values()])if(s.waitsOn===t.unit){if(e.kind!=="placed"){this.#f(s,i);continue}s.met.add(t.unit)}e.kind==="placed"&&(this.#E(t.unit),this.#c("apply",[t.unit]))}#E(t){const e=new Map([[t,!0]]);for(const i of this.#i.values()){const s=new Set;let n=i.unit;for(;n!==null&&!e.has(n)&&!s.has(n);)s.add(n),n=this.#i.get(n)?.waitsOn??null;const r=n!==null&&e.get(n)===!0;for(const h of s)e.set(h,r);if(r)for(const h of i.waiters)h.moved()}}#G(t){let e=t;const i=new Set([t]);for(let s=t.waitsOn===null?void 0:this.#i.get(t.waitsOn);s&&!i.has(s);s=s.waitsOn===null?void 0:this.#i.get(s.waitsOn))i.add(s),e=s;return{kind:"held",unit:e.unit,reason:e.held?.reason??"still placing"}}async#U(t,e,i){const s=e.members[0]?.work.entityId??null;if(t.held&&t.held.entityId!==null&&t.held.entityId!==s&&(t.held=null),await this.#Q(t,e))return!1;let n=await w(()=>this.#o.run(e,()=>t.kind==="lane"&&t.emptied?t.unit:null));if(t.kind==="line"&&!this.#e&&typeof n=="object"&&n.kind==="park"&&_(e,n)&&(n=await w(()=>this.#o.alone(e))),n==="progress"||typeof n=="object"&&n.kind==="alone"){if(t.kind==="line")for(const r of e.members)(r.judgment==="waiting"||n!=="progress"&&r.work.entityId===n.entityId)&&this.#$(r.work.entityId);for(const r of e.members)r.unseen!==void 0&&this.#$(r.unseen);return this.#Z(t,n!=="progress"?[n.entityId]:e.intent?.members.map(r=>r.entityId)??e.members.map(r=>r.work.entityId))}return n.advanced?.length&&this.#j(t,n.advanced),this.#tt(t,e,n,i),t.kind==="lane"&&this.#N(t),t.held.due}#K(t,e){const i=t.held,s=e.members[0]?.work.entityId??null;return(i?.entityId===s&&i.target===this.#o.targetOf(e)?i.attempt:0)+1}async#Q(t,e){const i=t.held,s=e.members[0];return!i||s===void 0||i.entityId!==s.work.entityId||i.due||i.notBefore<=this.#t.now()||this.#o.targetOf(e)!==i.target||e.cutoff!==i.cutoff?!1:await this.#t.store.localWorkAfter(e.authorityId,s.work.entityId,i.kept??i.target)===null}#Z(t,e){return t.held&&(t.held.entityId===null||e.includes(t.held.entityId))&&(t.held=null),this.#j(t,e),!0}#j(t,e){t.kind==="lane"&&(this.#r=!0,this.#E(t.unit)),this.#c("apply",e);for(const i of this.#w())i!==t&&i.held?.releaseOnProgress&&!i.held.due&&(i.held.due=!0,this.#s(i))}#tt(t,e,i,s){if(i.dependency&&O(i.dependency),i.blocker&&!i.dependency)throw new Error("Apply blocker must name the dependency that releases it");const n=e.members[0],r=t.held,h=this.#K(t,e),l=this.#C(h),d=i.again===!0&&h===1,f={entityId:n?.work.entityId??null,target:this.#o.targetOf(e),kept:n?.work.kept??null,cutoff:e.cutoff,attempt:h,notBefore:i.dependency?1/0:this.#t.now()+(d?0:l),releaseOnProgress:i.releaseOnProgress,due:i.dependency?this.#z(i.dependency,i.comparedAt??s):d,reason:i.reason,...i.dependency?{dependency:i.dependency}:{},...i.blocker?{blocker:i.blocker}:{}};t.held=f,this.#q();const A=p(r,y(t)),c=p(f,y(t));c&&JSON.stringify(c)!==JSON.stringify(A)&&this.#t.onWaiting?.(c),!(!i.report&&(i.dependency!==void 0||h===1))&&this.#S(new Error(`${m(t)} holds at ${f.entityId??"its open window"}, which ${i.releaseOnProgress?"is parked on a conflict":i.report?"failed":i.again?"keeps ending unplaced":"stands on ground that keeps moving"}, and will retry in ${l}ms (attempt ${h}): ${i.reason}`,i.cause===void 0?void 0:{cause:i.cause}))}#Y(t,e){if(t.kind==="lane"){for(const h of t.waiters)h.fail(e);t.waiters.clear()}const i=t.held,s=(i?.entityId===null?i.attempt:0)+1,n=this.#C(s),r=e instanceof Error?e.message:String(e);t.held={entityId:null,target:null,kept:null,cutoff:null,attempt:s,notBefore:this.#t.now()+n,releaseOnProgress:!1,due:!1,reason:r},this.#q(),this.#S(new Error(`${m(t)} faulted and will retry in ${n}ms (attempt ${s}): ${r}`,{cause:e}))}#S(t){try{this.#x(t)}catch{}}#C(t){const e=Math.min(g,x*2**Math.min(t-1,16)),i=Math.max(0,Math.min(1,this.#t.schedule.random()));return Math.round(e*(.5+i))}#c(t,e){const i=++this.#A;for(const s of e??["*"])this.#O.set(`${t}:${s}`,i);for(const s of this.#w())q(s,t,e)&&this.#s(s)}#z(t,e){return["*",...t.entityIds].some(i=>(this.#O.get(`${t.producer}:${i}`)??0)>e)}#q(){if(this.#e)return;let t=this.#p;for(const s of this.#w())s.held&&!s.held.due&&(t=Math.min(t,s.held.notBefore));if(t===1/0){this.#M();return}if(this.#y?.dueAt===t)return;this.#M();const e=Math.max(0,t-this.#t.now()),i=this.#t.schedule.schedule(e,()=>{this.#y=null,this.#D(t),this.#n()});this.#y={dueAt:t,cancel:a(()=>i.cancel(),"cancel")}}#D(t){let e=!1;for(const i of this.#w())i.held&&!i.held.due&&i.held.notBefore<=t&&(i.held.due=!0,this.#s(i),e=!0);return this.#p<=t&&(this.#p=1/0,this.#r=!0,e=!0),e}#M(){this.#y?.cancel(),this.#y=null}}const y=a(o=>o.kind==="line"?o.authorityId:o.unit,"owner"),m=a(o=>o.kind==="line"?`entity Apply line ${o.authorityId}`:`entity Apply fetch of ${o.unit}`,"label");export{M as ENTITY_APPLY_DEFAULT_CONCURRENCY,x as ENTITY_APPLY_RETRY_BASE_MS,g as ENTITY_APPLY_RETRY_MAX_MS,j as EntityApplyRail};
|
package/dist/apply/window.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { CloudEntityRecord } from '../entities/cloud.js';
|
|
2
2
|
import type { AcceptedEntityRecord } from '../records/contracts.js';
|
|
3
|
-
import type { ApplyAheadRow
|
|
3
|
+
import type { ApplyAheadRow } from './contracts.js';
|
|
4
4
|
import type { LineJudgment } from './settling.js';
|
|
5
5
|
import type { ApplyPlay, ShownPlace } from './showing.js';
|
|
6
6
|
export declare const WINDOW_MEMBERS = 4096;
|
|
@@ -22,7 +22,6 @@ export interface JudgedWindowMember extends WindowJudgment {
|
|
|
22
22
|
readonly member: FoldedMember;
|
|
23
23
|
}
|
|
24
24
|
export declare function readWindow(rows: readonly ApplyAheadRow[], judge: (member: FoldedMember) => WindowJudgment, place: (uuid: string) => ShownPlace | undefined, cap?: number): readonly JudgedWindowMember[];
|
|
25
|
-
export declare function windowEndForWait(window: ApplyWindow, dependency: ApplyDependency | undefined): number | null;
|
|
26
25
|
export interface OrderedMember {
|
|
27
26
|
readonly entityId: string;
|
|
28
27
|
readonly play: ApplyPlay;
|
package/dist/apply/window.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var M=Object.defineProperty;var a=(
|
|
1
|
+
var M=Object.defineProperty;var a=(o,i)=>M(o,"name",{value:i,configurable:!0});import{collisionBases as $}from"../entities/rules.js";import{CONTAINERS as z,isConstructType as k}from"../entities/types.js";const D=4096;function E(o,i=D){const d=new Map;let p=0;for(const u of o){const{entityId:f}=u.record;let l=d.get(f);if(l===void 0){if(d.size===i)break;d.set(f,l={records:[],deliverySequence:u.deliverySequence,through:0})}const t=l.records.at(-1);if(t!==void 0&&t.change.turn===void 0!=(u.record.change.turn===void 0))break;if(t!==void 0&&u.record.globalSequence!==t.globalSequence+1)throw new Error(`entity ${f} has a gap before sequence ${u.record.globalSequence} inside its window`);l.records.push(u.record),l.through=p=u.deliverySequence}return Object.freeze({members:Object.freeze([...d].map(([u,{records:f,deliverySequence:l,through:t}])=>Object.freeze({entityId:u,records:Object.freeze(f),deliverySequence:l,through:t}))),through:p})}a(E,"foldWindow");function B(o,i,d,p=D){const u=new Map;for(let f=o;;){const l=E(f,p).members.map(r=>{const g=`${r.entityId}:${r.records.at(-1).globalSequence}`;let y=u.get(g);return y===void 0&&u.set(g,y=i(r)),{member:r,judgment:y.judgment,result:y.result}}),t=C(l,d);if(t===null)return l;f=f.slice(0,f.findIndex(r=>r.deliverySequence>=t))}}a(B,"readWindow");const W=a((o,i)=>o!==void 0&&(o.root?o.type!==i.type:o.parentUUID!==i.parentUUID||o.name!==i.name||o.type!==i.type),"movesPlace");function C(o,i){const d=new Set,p=new Set;let u=null;for(const{member:n,judgment:e,result:s}of o)e==="leave"?p.add(n.entityId):(e==="enter"||e==="apply"&&W(i(n.entityId),s))&&d.add(n.entityId),e==="enter"&&z.has(s.type)&&n.through<(u?.through??1/0)&&(u=n);if(d.size===0&&p.size===0)return null;const f=new Map(o.map(({member:n})=>[n.entityId,n.deliverySequence])),l=a((n,e)=>n===null?[]:[e,...$(e)].map(s=>`${n}/${s}`),"slotKeys"),t=a(({member:n,result:e})=>e.status==="active"&&!i(n.entityId)?.root?l(e.parentUUID,e.name):[],"goesTo"),r=a(n=>{const e=i(n.member.entityId);return[...e&&!e.root?l(e.parentUUID,e.name):[],...t(n)]},"slotsOf"),g=new Map,y=new Map,j=a((n,e,s)=>{for(const h of e){const c=n.get(h);c===void 0?n.set(h,[s]):c.length<2&&!c.includes(s)&&c.push(s)}},"note");for(const n of o){const{entityId:e}=n.member;d.has(e)&&j(y,t(n),e),(d.has(e)||p.has(e))&&j(g,r(n),e)}const v=a((n,e)=>{let s;for(const h of l(e.parentUUID,e.name)){const[c,w]=y.get(h)??[],I=c===n?w:c;I!==void 0&&(s===void 0||f.get(I)<f.get(s))&&(s=I)}return s},"pusher"),S=a((n,e,s)=>{const h=new Set([n]);for(let c=e;c!==null&&!h.has(c);){h.add(c);const w=i(c),I=s(c,w);if(I!==void 0)return I;c=w.parentUUID}return null},"climbs"),x=a(n=>{const{member:e,judgment:s,result:h}=n;if(s==="superseded"||s==="own"||s==="unseen"||s==="turn"||s==="waiting")return[];if(k(h.type))return[];const c=[];for(const U of r(n)){const[m,O]=g.get(U)??[],q=m===e.entityId?O:m;q!==void 0&&c.push(q)}const w=i(e.entityId);if(w&&!w.root){const U=S(e.entityId,w.parentUUID,(m,O)=>d.has(m)?m:!O||O.root?null:v(e.entityId,O));U!==null&&c.push(U)}if(h.status!=="active"||w?.root)return c;const I=S(e.entityId,h.parentUUID,(U,m)=>d.has(U)||p.has(U)?U:m?!m.available||!z.has(m.type)||m.root?null:v(e.entityId,m):u!==null&&e.through>u.through?u.entityId:null);return I!==null&&c.push(I),c},"partnersOf");let b=null;for(const n of o){const e=n.member.deliverySequence;if(b!==null&&e>=b)break;for(const s of x(n)){const h=Math.max(e,f.get(s));(b===null||h<b)&&(b=h)}}return b}a(C,"windowCut");function P(o){const i=new Map(o.map((t,r)=>[t.entityId,{member:t,index:r}])),d=new Map,p=new Set,u=a((t,r)=>{const g=d.get(t);if(g!==void 0)return g;if(r.has(t)){for(const x of r)p.add(x);return-1}const y=i.get(t);if(!y||y.member.parentUUID===null)return 0;const j=i.get(y.member.parentUUID);if(!j)return d.set(t,0),0;r.add(t);const v=u(j.member.entityId,r);r.delete(t);const S=v<0?-1:v+1;return S>=0&&d.set(t,S),S},"depthOf"),f=[],l=[];for(const[t,r]of o.entries()){const g=u(r.entityId,new Set);if(g<0){p.add(r.entityId);continue}(r.play==="leave"?l:f).push({id:r.entityId,depth:g,index:t})}return f.sort((t,r)=>t.depth-r.depth||t.index-r.index),l.sort((t,r)=>r.depth-t.depth||t.index-r.index),Object.freeze({order:Object.freeze([...f,...l].map(({id:t})=>t)),cycle:Object.freeze([...p])})}a(P,"revealOrder");function A(o,i){let d=0;for(;d<o.length&&i(o[d]);)d+=1;return o.slice(0,d)}a(A,"resolvedPrefix");export{D as WINDOW_MEMBERS,E as foldWindow,B as readWindow,A as resolvedPrefix,P as revealOrder};
|
package/dist/clash/bodmas.d.ts
CHANGED
|
@@ -16,3 +16,4 @@ export interface RefusedMove {
|
|
|
16
16
|
}
|
|
17
17
|
export declare const contentKind: (type: string) => string;
|
|
18
18
|
export declare function playChange(previous: CloudEntityRecord | null, change: PlayableChange, sha256Hex: Sha256Hex, refused?: RefusedMove, readPosition?: () => number | undefined): Played;
|
|
19
|
+
export declare const sameFields: (left: CloudEntityRecord, right: CloudEntityRecord) => boolean;
|
package/dist/clash/bodmas.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var w=Object.defineProperty;var l=(t,o)=>w(t,"name",{value:o,configurable:!0});import{canonicalVersion as u,validPortableFileMode as p,validPortableMtime as P}from"../entities/rules.js";import{fileAbsent as y}from"../git/checkout.js";import{CONTAINERS as b}from"../entities/types.js";const U=l(t=>b.has(t)?t:"file","contentKind");function E(t,o,r,c,f){const e=k(t,o,r,c),s=e.row;if(s===null)return e;const a=t?.status==="active"&&s.parentUUID===t.parentUUID&&s.name===t.name,i=s.status!=="active"||s.parentUUID===null?void 0:a?t.slotPosition:o.deliverySequence??f?.();if(s.slotPosition===i)return e;const{slotPosition:n,...m}=s;return{...e,row:i===void 0?m:{...m,slotPosition:i}}}l(E,"playChange");function k(t,o,r,c){const{facets:f,result:e}=o;if(o.joins!==void 0)return t!==null&&t.status!=="deleted"&&t.version===o.joins?{row:e,setsPayload:!0}:{row:t,setsPayload:!1};const s=c===void 0?e.parentUUID:c.keeps;if(t===null||f.includes("create")){if(t?.status==="deleted")return{row:t,setsPayload:!1};if(s===e.parentUUID)return{row:e,setsPayload:!0};const d={...e,parentUUID:s};return{row:{...d,version:u(d,r)},setsPayload:!0}}if(t.status==="deleted")return{row:t,setsPayload:!1};let a=t,i=!1;const n=l(d=>{a={...a,...d}},"set"),m=l(()=>{n({type:e.type,fileMode:y(e)||!p(e.type,a.fileMode)?e.fileMode:a.fileMode,mtime:y(e)||!P(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}),i=!0},"becomes");for(const d of f)switch(d){case"move":n({parentUUID:s});break;case"rename":n({name:e.name});break;case"retype":m();break;case"content":U(a.type)===U(e.type)&&m();break;case"mode":!y(a)&&p(a.type,e.fileMode)&&n({fileMode:e.fileMode});break;case"time":!y(a)&&P(a.type,e.mtime)&&n({mtime:e.mtime});break;case"trash":n({status:"trashed"});break;case"restore":a.status==="trashed"&&n({status:"active"});break;case"delete":n({status:"deleted"});break;case"create":break}return a===t?{row:t,setsPayload:!1}:M(a,e)?{row:e,setsPayload:i}:{row:{...a,version:u(a,r)},setsPayload:i}}l(k,"playFacets");const I=["uuid","type","parentUUID","name","status","payloadVersion","fileMode","mtime","size","linkTarget","gitHomeEntity","gitHomePath","transportVersion"],M=l((t,o)=>I.every(r=>t[r]===o[r]),"sameFields");export{U as contentKind,E as playChange};
|
|
1
|
+
var w=Object.defineProperty;var l=(t,o)=>w(t,"name",{value:o,configurable:!0});import{canonicalVersion as u,validPortableFileMode as p,validPortableMtime as P}from"../entities/rules.js";import{fileAbsent as y}from"../git/checkout.js";import{CONTAINERS as b}from"../entities/types.js";const U=l(t=>b.has(t)?t:"file","contentKind");function E(t,o,r,c,f){const e=k(t,o,r,c),s=e.row;if(s===null)return e;const a=t?.status==="active"&&s.parentUUID===t.parentUUID&&s.name===t.name,i=s.status!=="active"||s.parentUUID===null?void 0:a?t.slotPosition:o.deliverySequence??f?.();if(s.slotPosition===i)return e;const{slotPosition:n,...m}=s;return{...e,row:i===void 0?m:{...m,slotPosition:i}}}l(E,"playChange");function k(t,o,r,c){const{facets:f,result:e}=o;if(o.joins!==void 0)return t!==null&&t.status!=="deleted"&&t.version===o.joins?{row:e,setsPayload:!0}:{row:t,setsPayload:!1};const s=c===void 0?e.parentUUID:c.keeps;if(t===null||f.includes("create")){if(t?.status==="deleted")return{row:t,setsPayload:!1};if(s===e.parentUUID)return{row:e,setsPayload:!0};const d={...e,parentUUID:s};return{row:{...d,version:u(d,r)},setsPayload:!0}}if(t.status==="deleted")return{row:t,setsPayload:!1};let a=t,i=!1;const n=l(d=>{a={...a,...d}},"set"),m=l(()=>{n({type:e.type,fileMode:y(e)||!p(e.type,a.fileMode)?e.fileMode:a.fileMode,mtime:y(e)||!P(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}),i=!0},"becomes");for(const d of f)switch(d){case"move":n({parentUUID:s});break;case"rename":n({name:e.name});break;case"retype":m();break;case"content":U(a.type)===U(e.type)&&m();break;case"mode":!y(a)&&p(a.type,e.fileMode)&&n({fileMode:e.fileMode});break;case"time":!y(a)&&P(a.type,e.mtime)&&n({mtime:e.mtime});break;case"trash":n({status:"trashed"});break;case"restore":a.status==="trashed"&&n({status:"active"});break;case"delete":n({status:"deleted"});break;case"create":break}return a===t?{row:t,setsPayload:!1}:M(a,e)?{row:e,setsPayload:i}:{row:{...a,version:u(a,r)},setsPayload:i}}l(k,"playFacets");const I=["uuid","type","parentUUID","name","status","payloadVersion","fileMode","mtime","size","linkTarget","gitHomeEntity","gitHomePath","transportVersion"],M=l((t,o)=>I.every(r=>t[r]===o[r]),"sameFields");export{U as contentKind,E as playChange,M as sameFields};
|
|
@@ -32,6 +32,7 @@ export interface ReadyDetectionBatch {
|
|
|
32
32
|
readonly missing: readonly CloudEntityRecord[];
|
|
33
33
|
readonly coverage: readonly DirectoryCoverageRequest[];
|
|
34
34
|
readonly settle: DetectionBatch;
|
|
35
|
+
readonly carriedBy?: ReadonlyMap<string, string>;
|
|
35
36
|
}
|
|
36
37
|
export type DetectionBatchPlan = RetryDetectionBatch | ReadyDetectionBatch;
|
|
37
38
|
export declare function planDetectionBatchSteps(batch: DetectionBatch, transitions: readonly SettledTransition[]): Steps<DetectionBatchPlan>;
|
|
@@ -13,5 +13,5 @@ export interface PackagedProposals {
|
|
|
13
13
|
readonly together: ReadonlyMap<string, readonly DetectedChangeProposal[]>;
|
|
14
14
|
readonly pages: readonly RecordPage[];
|
|
15
15
|
}
|
|
16
|
-
export declare function packageProposalsSteps(proposals: readonly DetectedChangeProposal[], sha256Hex: Sha256Hex): Steps<PackagedProposals>;
|
|
17
|
-
export declare function packageProposals(proposals: readonly DetectedChangeProposal[], sha256Hex: Sha256Hex): PackagedProposals;
|
|
16
|
+
export declare function packageProposalsSteps(proposals: readonly DetectedChangeProposal[], sha256Hex: Sha256Hex, carriedBy?: ReadonlyMap<string, string>): Steps<PackagedProposals>;
|
|
17
|
+
export declare function packageProposals(proposals: readonly DetectedChangeProposal[], sha256Hex: Sha256Hex, carriedBy?: ReadonlyMap<string, string>): PackagedProposals;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var R=Object.defineProperty;var d=(s,a)=>R(s,"name",{value:a,configurable:!0});import{assertRecord as v}from"../entities/cloud.js";import{anchorsPackage as x,carriers as z,packagePagesSteps as A}from"../entities/package-pages.js";import{CONTAINERS as N}from"../entities/types.js";import{eachStep as p,finishSteps as j}from"../steps.js";import{assertRepositoryReplay as T,CHANGE_PROPOSAL_CONTRACT as U,changeCargo as L,ownChange as D}from"./record-proposal.js";function*C(s,a,i){const c=yield*A(s,a,i);let b;for(const g of c)b??=g.items.find(y=>y.uuid===s.toLowerCase());const f=v(b),o={kind:"package",pages:Object.freeze(c.map(g=>g.ref))},u=Object.freeze({contract:U,origin:"detected",entityId:f.uuid,basedOnState:null,result:f,facets:Object.freeze(["create"]),replay:o,cargo:Object.freeze(L(f,o))}),l=D(u).replay;return l.kind==="repo.git"&&T(l,f),{proposal:u,pages:c}}d(C,"packageProposalSteps");function F(s,a,i){return j(C(s,a,i))}d(F,"packageProposal");function*E(s,a,i=new Map){const c=new Map;yield*p(s,e=>{e.basedOnState===null&&e.result.status==="active"&&c.set(e.entityId,e)});const b=z([...c.values()].map(e=>e.result)),f=d(e=>{const{parentUUID:t}=c.get(e).result;return t===null?b.get(e)?.uuid??null:N.has(c.get(t)?.result.type??"")?t:null},"holderOf"),o=new Map;yield*p([...c.keys()],e=>{const t=[];let n=null;for(let r=e;;){const w=o.get(r);if(w!==void 0){n=w;break}t.push(r);const k=f(r);if(k!==null&&!t.includes(k)){r=k;continue}n=k===null&&x(c.get(r).result.type)?r:null;break}for(const r of t)o.set(r,n)});const u=new Map;yield*p([...o],([e,t])=>{if(t===null)return;const n=u.get(t)??[];n.push(c.get(e).result),u.set(t,n)});const l=new Map;for(const[e,t]of u)for(const n of t)l.set(n.uuid,e);const g=d(e=>e.basedOnState!==null&&e.replay.kind!=="package"&&e.joins===void 0&&e.turn===void 0,"joinable"),y=new Map;yield*p(s,e=>{const{type:t,payloadVersion:n}=e.result,r=t==="reference"&&n!==null?n.toLowerCase():null;g(e)&&r!==null&&l.get(r)===r&&y.set(e.entityId,r)});const h=new Map(y),I=new Set;yield*p(s,e=>{const{parentUUID:t}=e.result;if(!g(e)||h.has(e.entityId))return;const n=t===null?void 0:l.get(t)??y.get(t);if(n!==void 0){h.set(e.entityId,n);return}const r=i.get(e.entityId);if(r!==void 0&&I.has(r)){h.set(e.entityId,r);return}I.add(e.entityId)});const P=new Set(h.values()),m=new Map;for(const[e,t]of u)(t.length>1||P.has(e))&&m.set(e,yield*C(e,t,a));const O=new Map,S=[],M=new Set;return yield*p(s,e=>{const t=h.get(e.entityId);if(t!==void 0){const w=O.get(t)??[];w.push(e),O.set(t,w);return}const n=o.get(e.entityId),r=n==null?void 0:m.get(n);if(!r){S.push(e);return}M.has(n)||(M.add(n),S.push(r.proposal))}),{proposals:S,together:O,pages:[...m.values()].flatMap(e=>e.pages)}}d(E,"packageProposalsSteps");function J(s,a,i){return j(E(s,a,i))}d(J,"packageProposals");export{F as packageProposal,C as packageProposalSteps,J as packageProposals,E as packageProposalsSteps};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var R=Object.defineProperty;var a=(t,l)=>R(t,"name",{value:l,configurable:!0});import{CONTAINERS as C}from"../entities/types.js";import{eachStep as b,ITEMS_PER_BOUNDARY as A}from"../steps.js";import{planDetectionBatchSteps as F}from"./batch.js";import{detectionBatch as H}from"./watch-boundary.js";function j(t){const l=new Map;return o=>{const i=[];let u=!0;for(let d=o;d!==null;){const s=l.get(d);if(s!==void 0){u=s;break}const f=t(d);if(!f||i.includes(d))break;if(i.push(d),f.status!=="active"){u=!1;break}d=f.parentUUID}for(const d of i)l.set(d,u);return u}}a(j,"livenessOf");const $=a(t=>t!=null&&C.has(t.type),"holdsChildren");function B(t,l){const o=[],i=new Set([t]);for(let u=l(t);u!==null&&!i.has(u);u=l(u))o.push(u),i.add(u);return o}a(B,"ancestorsOf");function T(t,l){let o=t.push(l)-1;for(let i=o-1>>1;o>0&&t[i]>l;i=o-1>>1)t[o]=t[i],o=i;t[o]=l}a(T,"pushPlace");function _(t){const l=t[0],o=t.pop();if(t.length===0)return l;let i=0;for(let u=1;u<t.length&&(u+1<t.length&&t[u+1]<t[u]&&(u+=1),!(t[u]>=o));u=2*i+1)t[i]=t[u],i=u;return t[i]=o,l}a(_,"popPlace");function*q(t,l,o,i){const u=new Map,d=new Set,s=new Set,f=new Set,c=new Set,v=[],g=[],M=new Set,S=j(e=>l.get(e)),E=j(e=>o.get(e)?.record);let h=-1;if(yield*b(t,e=>{if(h+=1,e.truth!=="present"){e.base&&u.set(e.base.uuid,h);return}const{base:n,result:r}=e;u.set(r.uuid,h),n?.status==="active"&&(r.status!=="active"||$(n)&&!$(r))&&f.add(r.uuid),n?.status==="active"&&r.status!=="active"&&!S(r.uuid)&&M.add(h),n!==null&&n.parentUUID!==r.parentUUID&&s.add(r.uuid),n!==null&&(n.status!=="active"||n.parentUUID!==r.parentUUID)&&!S(r.uuid)&&E(r.uuid)&&(c.add(r.uuid),s.add(r.uuid)),$(r)&&!$(n)&&d.add(r.uuid),o.get(r.uuid)?.gitFollows!==void 0&&v.push(h),o.get(r.uuid)?.gitHeld!==void 0&&g.push(h)}),d.size===0&&s.size===0&&f.size===0&&v.length===0&&g.length===0)return t;const y=new Map,D=new Map,w=a((e,n)=>{if(e===void 0||n===void 0||e===n)return;y.set(e,(y.get(e)??0)+1);const r=D.get(n);r?r.push(e):D.set(n,[e])},"wait"),P=a(e=>l.get(e)?.parentUUID??null,"parentBefore"),O=a(e=>o.get(e)?.record.parentUUID??null,"parentAfter");h=-1,yield*b(t,e=>{if(h+=1,e.truth!=="present")return;const{result:n}=e;if(M.has(h)){if(c.size>0)for(const r of B(n.uuid,O))c.has(r)&&w(u.get(r),h);return}if(n.parentUUID!==null&&d.has(n.parentUUID)&&w(h,u.get(n.parentUUID)),s.size>0&&s.has(n.uuid))for(const r of B(n.uuid,O))s.has(r)&&w(h,u.get(r))});for(const e of v){const n=t[e];if(n.truth==="present")for(const r of o.get(n.result.uuid).gitFollows)w(e,u.get(r))}const N=a(e=>{const n=e===void 0?void 0:t[e];return n?.truth==="present"&&n.base?.type==="repo.git"&&n.result.type!=="repo.git"},"retyped");for(const e of g){const n=t[e];if(n.truth!=="present")continue;const{repository:r,held:p}=o.get(n.result.uuid).gitHeld,U=u.get(r);p||N(U)?(w(e,U),U!==void 0&&i.set(n.result.uuid,r)):s.has(r)&&s.has(n.result.uuid)||w(U,e)}if(f.size>0&&(yield*b(o.values(),({record:e})=>{const n=l.get(e.uuid);if(n===void 0||n.parentUUID===e.parentUUID||!E(e.uuid)||!S(e.uuid))return;const r=B(e.uuid,P).filter(p=>f.has(p));if(r.length!==0){if(!u.has(e.uuid))throw new Error(`record order has no record placing ${e.uuid}, which moved out from beneath ${r.join(", ")}`);for(const p of r)w(u.get(p),u.get(e.uuid))}})),y.size===0)return t;const I=[],k=[];let m=0,z=0;for(;I.length<t.length;){let e;if(k.length>0)e=_(k);else{for(;m<t.length&&(y.get(m)??0)>0;)m+=1,++z%A===0&&(yield);if(m===t.length)break;e=m++}I.push(t[e]);for(const n of D.get(e)??[]){const r=y.get(n)-1;y.set(n,r),r===0&&n<m&&T(k,n),++z%A===0&&(yield)}++z%A===0&&(yield)}if(I.length<t.length){const e=a(r=>{const p=t[r];return p.truth==="present"?p.result.uuid:p.base?.uuid??"none"},"uuidAt"),n=[];e:for(const[r,p]of D)if((y.get(r)??0)!==0){for(const U of p)if((y.get(U)??0)!==0&&(n.push(`${e(U)} waits for ${e(r)}`),n.length===8))break e}throw new Error(`record order has a cycle: ${n.join(", ")}`)}return I}a(q,"causalOrderSteps");function*L(t){const l=H(t.rootId,t.suspicion),o=new Map;yield*b(t.before,s=>o.set(s.uuid,s));const i=new Map;yield*b(t.after,s=>i.set(s.record.uuid,s));const u=[],d=a(s=>{const f=o.get(s)??null,c=i.get(s)??null;if(c===null){u.push({truth:"absent",base:f});return}u.push({truth:"present",relPath:c.relativePath,base:f,result:c.record,replay:c.replay??{kind:"structure"},...c.lifecycleAuthorization?{lifecycleAuthorization:c.lifecycleAuthorization}:{},...c.echo?{echo:!0}:{}})},"transitionOf");yield*b(o.keys(),d),yield*b(i.keys(),s=>{o.has(s)||d(s)});try{const s=new Map,f=yield*q(u,o,i,s),c=yield*F(l,f);return c.kind==="ready"&&s.size>0?Object.freeze({...c,carriedBy:s}):c}catch(s){const f=s instanceof Error?s.message:String(s),c=u.slice(0,8).map(g=>g.truth==="present"?`${g.result.uuid}:${g.result.type}:${g.result.payloadVersion??"none"}`:`${g.base?.uuid??"none"}:absent`).join(","),v=u.length>8?`,+${u.length-8} more`:"";throw new Error(`Detect plan for ${t.rootId} failed (${c}${v}): ${f}`)}}a(L,"planGroundDetectionSteps");export{L as planGroundDetectionSteps};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare function sectionOf(line: string): string | null | undefined;
|
|
2
|
+
export declare const configLines: (text: string) => string[];
|
|
3
|
+
export declare const bareLine: (line: string) => string;
|
|
4
|
+
export declare function gitConfigWithout(text: string, drops: (section: string | null, key: string) => boolean): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var x=Object.defineProperty;var o=(n,t)=>x(n,"name",{value:t,configurable:!0});function g(n){const t=/^\s*\[([^\]]*)\]\s*([#;].*)?$/.exec(n);if(t===null)return/^\s*\[/.test(n)?null:void 0;const e=t[1].trim();return/^[A-Za-z0-9-]+$/.test(e)?e.toLowerCase():null}o(g,"sectionOf");const h=/(^|[^\\])(\\\\)*\\$/,$=/^\s*([A-Za-z][A-Za-z0-9-]*)\s*(=|$|[#;])/,C=o(n=>n.split(/(?<=\n)/).filter(t=>t!==""),"configLines"),L=o(n=>n.replace(/\r?\n$/,""),"bareLine");function A(n,t){const e=[];let i=null,l=-1,r=0,c=null;const f=o(()=>{l>=0&&r===0&&(i==="core"||i==="extensions")&&e.splice(l)},"close");for(const s of C(n)){const u=L(s);if(c!==null){c||e.push(s),h.test(u)||(c=null);continue}const p=g(u);if(p!==void 0){f(),i=p,l=e.length,r=0,e.push(s);continue}const a=$.exec(u)?.[1]?.toLowerCase();if(a===void 0){e.push(s);continue}const d=t(i,a);c=h.test(u)?d:null,!d&&(r+=1,e.push(s))}return f(),e.join("")}o(A,"gitConfigWithout");export{L as bareLine,C as configLines,A as gitConfigWithout,g as sectionOf};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
var l=Object.defineProperty;var i=(e,t)=>l(e,"name",{value:t,configurable:!0});import{bareLine as c,configLines as d,gitConfigWithout as a,sectionOf as u}from"./config-text.js";const G="config",p=new Set(["filemode","symlinks","ignorecase","precomposeunicode"]),m=i((e,t)=>e==="core"&&p.has(t),"measured"),h=i(e=>a(e,m),"portableGitConfig");function j(e,t){const o=d(h(e)),s=d(a(t,(n,g)=>!m(n,g))).filter(n=>u(c(n))===void 0&&c(n).trim()!=="").map(n=>n.endsWith(`
|
|
2
|
+
`)?n:`${n}
|
|
3
|
+
`);if(s.length===0)return o.join("");const r=o.findIndex(n=>u(c(n))==="core");if(r>=0)return[...o.slice(0,r+1),...s,...o.slice(r+1)].join("");const f=o.at(-1);return[...o,f===void 0||f.endsWith(`
|
|
4
|
+
`)?"":`
|
|
5
|
+
`,`[core]
|
|
6
|
+
`,...s].join("")}i(j,"localGitConfig");export{G as GIT_CONFIG_PATH,j as localGitConfig,h as portableGitConfig};
|
package/dist/git/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from './state.js';
|
|
2
2
|
export * from './alternates.js';
|
|
3
|
+
export * from './disk-settings.js';
|
|
3
4
|
export { compareGitText } from './text.js';
|
|
4
5
|
export * from './artifact.js';
|
|
5
6
|
export * from './chain.js';
|
|
@@ -13,3 +14,4 @@ export * from './checkout-view.js';
|
|
|
13
14
|
export * from './places.js';
|
|
14
15
|
export { GIT_PARTS, gitPartBlobs, gitParts, gitPartsChanged, type GitPart } from './parts.js';
|
|
15
16
|
export * from './restore.js';
|
|
17
|
+
export { gitRefsByMeaning, gitRefsTravelByMeaning } from './refs.js';
|
package/dist/git/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export*from"./state.js";export*from"./alternates.js";import{compareGitText as m}from"./text.js";export*from"./artifact.js";export*from"./chain.js";export*from"./plan.js";export*from"./play.js";export*from"./tag.js";export*from"./turns.js";export*from"./holds.js";export*from"./checkout.js";export*from"./checkout-view.js";export*from"./places.js";import{GIT_PARTS as
|
|
1
|
+
export*from"./state.js";export*from"./alternates.js";export*from"./disk-settings.js";import{compareGitText as m}from"./text.js";export*from"./artifact.js";export*from"./chain.js";export*from"./plan.js";export*from"./play.js";export*from"./tag.js";export*from"./turns.js";export*from"./holds.js";export*from"./checkout.js";export*from"./checkout-view.js";export*from"./places.js";import{GIT_PARTS as l,gitPartBlobs as y,gitParts as G,gitPartsChanged as M}from"./parts.js";export*from"./restore.js";import{gitRefsByMeaning as d,gitRefsTravelByMeaning as h}from"./refs.js";export{l as GIT_PARTS,m as compareGitText,y as gitPartBlobs,G as gitParts,M as gitPartsChanged,d as gitRefsByMeaning,h as gitRefsTravelByMeaning};
|
package/dist/git/play.d.ts
CHANGED
|
@@ -5,9 +5,13 @@ export interface GitPlaySides {
|
|
|
5
5
|
readonly basis: GitState | null;
|
|
6
6
|
readonly record: GitState;
|
|
7
7
|
}
|
|
8
|
+
export interface GitIndexSide {
|
|
9
|
+
readonly index: Uint8Array;
|
|
10
|
+
readonly head: string | null;
|
|
11
|
+
}
|
|
8
12
|
export interface GitPlayGit {
|
|
9
13
|
builtOn(commit: string, base: string): Promise<boolean>;
|
|
10
|
-
|
|
14
|
+
playIndex(line: GitIndexSide, basis: GitIndexSide | null, record: GitIndexSide | null, to: string | null): Promise<{
|
|
11
15
|
readonly meaning: string;
|
|
12
16
|
readonly bytes: Uint8Array;
|
|
13
17
|
} | null>;
|
package/dist/git/play.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var
|
|
2
|
-
`)):(
|
|
3
|
-
`).at(-1);s+=`${d} ${o}${
|
|
4
|
-
`}s===""?
|
|
1
|
+
var ce=Object.defineProperty;var r=(t,i)=>ce(t,"name",{value:i,configurable:!0});import{utf8Decode as fe,utf8Encode as le}from"../entities/bytes.js";import{GIT_ALTERNATES_PATH as de}from"./alternates.js";import{gitBlobId as ee}from"./artifact.js";import{gitChainReflog as me,gitDropPackedRefs as ue,gitLooseRef as he,gitPackedRefs as ge,gitReflogPlay as pe,gitReflogTop as te,gitRefsByMeaning as we}from"./refs.js";import{gitBytesForm as ye,gitSelfHeld as ke,gitSharesGitDir as be,gitSharesObjects as xe,gitTreeOf as Ee,isGitOid as ne}from"./state.js";import{compareGitText as z}from"./text.js";function Se(t){return t.facets.some(c=>c==="create"||c==="retype"||c==="content")&&t.result.status==="active"?t.result.transportVersion:null}r(Se,"gitOwnChange");function ve(t){let i=[],c=!1;for(const m of t){if(m.result.type!=="repo.git"){i=[],c=!0;continue}const u=Se(m);u!==null&&i.push(u)}return{reached:i,ended:c}}r(ve,"gitLineChanges");function Ce({line:t,basis:i,record:c}){const m=r(f=>f.files.find(g=>g.path===de)?.oid??null,"borrowed"),u=r(f=>f.files.some(g=>g.path==="reftable"),"reftable");return t.format===c.format&&(i===null||i.format===c.format)&&!xe(t)&&!ke(t.home)&&!be(t.home)&&t.home?.entity===c.home?.entity&&t.home?.path===c.home?.path&&m(t)===m(c)&&![t,c,...i?[i]:[]].some(f=>u(f)||ye(f))}r(Ce,"gitPlayable");const F="040000",N=r(t=>new Map(t.map(i=>[i.path,i])),"byPath"),j=r((t,i)=>t===void 0?i===void 0:i!==void 0&&t.mode===i.mode&&t.oid===i.oid,"same"),oe=r(t=>{const i=[];for(let c=t.indexOf("/");c>0;c=t.indexOf("/",c+1))i.push(t.slice(0,c));return i},"parents");function De(t,i,c){const m=new Set;for(const f of t.keys()){const g=oe(f).find(x=>t.has(x)&&t.get(x).mode!==F);g!==void 0&&m.add(g)}const u=r(f=>m.has(f)||oe(f).some(g=>m.has(g)),"clashed");if(m.size>0){for(const f of[...t.keys()])u(f)&&t.delete(f);for(const[f,g]of i)u(f)&&t.set(f,g)}return Ee(t.values(),c)}r(De,"asTree");const S=["line","basis","record"],I=r(t=>t.mode!==F&&(t.path==="HEAD"||t.path.startsWith("refs/")),"isLooseRef"),se=r(t=>I(t)||t.path==="packed-refs","isRefFile"),Ae=r(t=>t.startsWith("logs/"),"isReflogPath"),V="refs/stash",q="refs/heads/",J=`${q}amalgm`,Oe=7,Re=/^[0-9a-f]{7,}$/,K=r((t,i)=>t.startsWith(`${i}/`),"beneath");async function We(t,i,c,m){const u=new Map,f=r(async e=>{const n=e.files.find(a=>a.path==="packed-refs")?.oid,o=we(e,n?u.get(n)??await i(n):null,m);for(const[a,s]of o.made)u.set(a,s);return o.state},"meaning"),g={format:t.record.format,home:t.record.home,files:[],index:null},x={line:await f(t.line),basis:t.basis===null?g:await f(t.basis),record:await f(t.record)},l={line:N(x.line.files),basis:N(x.basis.files),record:N(x.record.files)},O=r((e,n)=>{const o=le(n),a=ee(o,m);return u.set(a,o),{path:e,mode:"100644",oid:a}},"make"),y=r(async e=>e?.oid?fe(u.get(e.oid)??await i(e.oid)):"","read"),P=new Map,$=r(e=>(P.has(e)||P.set(e,y(l[e].get("packed-refs")).then(ge)),P.get(e)),"packedOf"),k=r(async(e,n)=>{const o=l[e].get(n);return o!==void 0&&I(o)?he(await y(o)):n==="HEAD"?null:(await $(e)).get(n)??null},"value"),M=r(e=>!j(l.basis.get(e),l.record.get(e)),"recordChanged"),h=new Map;for(const e of new Set([...l.line.keys(),...l.basis.keys(),...l.record.keys()])){const n=M(e)?l.record.get(e):l.line.get(e);n!==void 0&&h.set(e,n)}const T=new Set;for(const e of new Set(S.flatMap(n=>[...l[n].keys()]))){const[n,o,a]=S.map(s=>l[s].get(e));if(!(j(n,o)&&j(o,a)))if(e==="packed-refs")for(const s of S)for(const d of(await $(s)).keys())T.add(d);else[n,o,a].some(s=>s!==void 0&&I(s))&&T.add(e)}const Q=r(async e=>{const[n,o,a]=S.map(s=>l[s].get(e));return[n,o,a].some(s=>s?.mode===F)?y(n):pe(await y(o),await y(a),await y(n))},"playLog"),E=`logs/${V}`;let D=null;M(E)&&(D=me(await Q(E)),D===""?h.delete(E):h.set(E,O(E,D)));const w=new Map,L=[];for(const e of[...T].sort(z)){const[n,o,a]=await Promise.all(S.map(d=>k(d,e)));let s=o!==a?a:n;if(e===V){if(D===null)continue;s=te(D)}else e.startsWith(q)&&n!==null&&n!==o&&s!==n&&[n,a].every(d=>d===null||ne(t.record.format,d))&&(a===null||!await c.builtOn(a,n))&&(s=n,a!==null&&!await c.builtOn(n,a)&&L.push({name:e,basis:o,record:a}));s!==n&&w.set(e,s)}const U=[];if(L.length>0){const e=new Map;for(const o of new Set([...l.line.keys(),...(await $("line")).keys(),...w.keys()])){if(o!==J&&!K(o,J))continue;const a=w.has(o)?w.get(o):await k("line",o);a!==null&&e.set(o,a)}const n=r((o,a)=>(e.get(o)??a)===a&&![...e.keys()].some(s=>K(o,s)||K(s,o)),"free");for(const{name:o,basis:a,record:s}of L){const d=`${J}/${o.slice(q.length)}-`;let p=[...e.keys()].sort(z).find(b=>e.get(b)===a&&b.startsWith(d)&&Re.test(b.slice(d.length)));for(let b=Oe;p===void 0&&b<=s.length;b+=1)n(d+s.slice(0,b),s)&&(p=d+s.slice(0,b));p!==void 0&&(await k("line",p)!==s&&w.set(p,s),e.set(p,s),U.push({branch:p,from:o,commit:s}))}}for(const[e,n]of[...h])se(n)&&h.delete(e);for(const e of x.line.files)se(e)&&h.set(e.path,e);const v=new Set;for(const[e,n]of w)n!==null?h.set(e,O(e,`${n}
|
|
2
|
+
`)):(h.has(e)&&I(h.get(e))&&h.delete(e),v.add(e));const X=l.line.get("packed-refs");if(v.size>0&&X!==void 0){const e=await y(X),n=ue(e,v);n!==e&&h.set("packed-refs",O("packed-refs",n))}const C=r(e=>w.has(e)?Promise.resolve(w.get(e)):k("line",e),"final"),W=r(async(e,n)=>e?.startsWith("ref: ")?n(e.slice(5)):e,"commitOf"),R=await W(await C("HEAD"),C),H=new Set;for(const e of S)for(const n of l[e].keys())Ae(n)&&n!==E&&H.add(n);for(const e of w.keys())e!==V&&H.add(`logs/${e}`);R!==await W(await k("line","HEAD"),e=>k("line",e))&&H.add("logs/HEAD");for(const e of[...H].sort(z)){const n=e.slice(5),o=n==="HEAD"?R:await C(n),a=M(e);if(!a&&(o===null||n!=="HEAD"&&!w.has(n)||!l.line.has(e)))continue;let s=a?await Q(e):await y(l.line.get(e));const d=te(s);if(o!==null&&d!==null&&d!==o&&ne(t.record.format,o)){const p=s.trimEnd().split(`
|
|
3
|
+
`).at(-1);s+=`${d} ${o}${p.slice(p.indexOf(" ",p.indexOf(" ")+1))}
|
|
4
|
+
`}s===""?h.delete(e):h.set(e,O(e,s))}const B=r(e=>k(e,"HEAD").then(n=>W(n,o=>k(e,o))),"headOf"),G=r(async e=>{const n=t[e]?.index;return n?.files.length===1?{index:await i(n.files[0].oid),head:await B(e)}:null},"indexOf"),[_,ae,Y,ie,re]=await Promise.all([G("line"),G("basis"),G("record"),t.basis?B("basis"):null,B("record")]),A=t.record.index?.meaning===t.basis?.index?.meaning&&re===ie;let Z=A?t.line.index:t.record.index;if(_!==null&&(A||Y!==null)&&!(A&&_.head===R)){const e=await c.playIndex(_,A?null:ae,A?null:Y,R);if(e!==null){const n=e.bytes,o=ee(n,m);u.set(o,n),Z={meaning:e.meaning,files:[{path:"index",mode:"100644",oid:o}]}}}return{state:await f({format:t.record.format,home:t.record.home,files:De(h,l.record,t.record.home),index:Z}),made:u,aside:U}}r(We,"gitPlayRecord");export{ve as gitLineChanges,Se as gitOwnChange,We as gitPlayRecord,Ce as gitPlayable};
|
package/dist/git/refs.d.ts
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
|
+
import type { Sha256Hex } from '../entities/types.js';
|
|
2
|
+
import { type GitState } from './state.js';
|
|
1
3
|
export declare const gitLooseRef: (text: string) => string;
|
|
2
4
|
export declare function gitPackedRefs(text: string): Map<string, string>;
|
|
3
5
|
export declare function gitDropPackedRefs(text: string, names: ReadonlySet<string>): string;
|
|
6
|
+
export declare const gitRefsTravelByMeaning: (state: GitState) => boolean;
|
|
7
|
+
export declare function gitRefsByMeaning(state: GitState, packed: Uint8Array | null, sha256: Sha256Hex): {
|
|
8
|
+
readonly state: GitState;
|
|
9
|
+
readonly made: ReadonlyMap<string, Uint8Array>;
|
|
10
|
+
};
|
|
4
11
|
export declare function gitReflogPlay(basis: string, record: string, line: string): string;
|
|
5
12
|
export declare function gitChainReflog(text: string): string;
|
|
6
13
|
export declare const gitReflogTop: (text: string) => string | null;
|
package/dist/git/refs.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
var
|
|
2
|
-
`,1)[0].trimEnd(),"gitLooseRef"),
|
|
3
|
-
`)){const
|
|
4
|
-
`))
|
|
5
|
-
`)}
|
|
6
|
-
`).
|
|
7
|
-
`)
|
|
8
|
-
|
|
1
|
+
var k=Object.defineProperty;var r=(e,n)=>k(e,"name",{value:n,configurable:!0});import{utf8Encode as R}from"../entities/bytes.js";import{gitBlobId as W}from"./artifact.js";import{gitBytesForm as $,gitSelfHeld as v,gitSharesGitDir as S,gitTreeOf as M,isGitOid as y}from"./state.js";const G=r(e=>e.split(`
|
|
2
|
+
`,1)[0].trimEnd(),"gitLooseRef"),x=r(e=>{const n=e.indexOf(" ");return e.startsWith("#")||e.startsWith("^")||n<=0?null:e.slice(n+1)},"packedName");function N(e){const n=new Map;for(const s of e.split(`
|
|
3
|
+
`)){const o=x(s);o!==null&&n.set(o,s.slice(0,s.indexOf(" ")))}return n}r(N,"gitPackedRefs");function z(e,n){const s=[];let o=!1;for(const t of e.split(`
|
|
4
|
+
`))t.startsWith("^")||(o=n.has(x(t)??"")),o||s.push(t);return s.join(`
|
|
5
|
+
`)}r(z,"gitDropPackedRefs");const h="040000",O="refs/";function b(e,n){const s=new Map;for(const o of e.split(`
|
|
6
|
+
`)){if(o===""||o.startsWith("#")||o.startsWith("^")&&y(n,o.slice(1)))continue;const t=x(o),f=o.slice(0,o.indexOf(" "));if(t===null||!t.startsWith(O)||!y(n,f))return null;s.set(t,f)}return s}r(b,"packedRefs");function D(e){try{return new TextDecoder("utf-8",{fatal:!0}).decode(e)}catch{return null}}r(D,"strictText");const E=r(e=>e.normalize("NFC").toLowerCase(),"folded"),T=r(e=>!/[<>:"|?*\\\x00-\x1f]|[. ]$/.test(e)&&!/^(aux|con|conin\$|conout\$|nul|prn|com[1-9]|lpt[1-9]) *(\.|$)/i.test(e),"onWindows");function j(e,n){if(!n.every(t=>t.split("/").every(T)))return!1;const s=new Set;for(const t of n)for(let f=t.indexOf("/");f>0;f=t.indexOf("/",f+1))s.add(t.slice(0,f));if(n.some(t=>s.has(t)))return!1;const o=new Map;for(const t of[...e,...n,...s]){const f=E(t),l=o.get(f);if(l!==void 0&&l!==t)return!1;o.set(f,t)}return!0}r(j,"looseOnEveryDisk");const B=r(e=>!$(e)&&!v(e.home)&&!S(e.home)&&!e.files.some(n=>n.path==="reftable"||n.path.startsWith("reftable/")),"gitRefsTravelByMeaning");function H(e,n,s){const o=new Map;if(!B(e))return{state:e,made:o};const t=new Map(e.files.map(i=>[i.path,i])),f=n===null||!/^100(644|755)$/.test(t.get("packed-refs")?.mode??"")?null:D(n),l=f===null?null:b(f,e.format),g=r(i=>(t.get(i)?.mode??h)!==h,"loose"),c=r(i=>t.get(i)?.mode!==h&&i.split("/").every((a,u,d)=>u===d.length-1||!g(d.slice(0,u+1).join("/"))),"clear");if(l!==null&&[...l.keys()].every(c)&&j([...t.keys()],[...l.keys()])){t.delete("packed-refs");for(const[i,a]of l){if(g(i))continue;const u=R(`${a}
|
|
7
|
+
`),d=W(u,s);o.set(d,u),t.set(i,{path:i,mode:"100644",oid:d})}}const w=new Set;for(const i of t.values())if(i.mode!==h)for(let a=i.path.indexOf("/");a>0;a=i.path.indexOf("/",a+1))w.add(i.path.slice(0,a));for(const[i,a]of t)a.mode===h&&i.startsWith(O)&&!w.has(i)&&t.delete(i);return{state:{...e,files:M(t.values(),e.home)},made:o}}r(H,"gitRefsByMeaning");const m=r(e=>e.split(`
|
|
8
|
+
`).filter(n=>n!==""),"lines"),p=r(e=>e.slice(e.indexOf(" ")+1),"entry");function I(e,n,s){const o=new Set(m(e).map(p)),t=m(n),f=new Set(t.map(p)),l=m(s),g=new Set(l.map(p));return[...l.filter(c=>!o.has(p(c))||f.has(p(c))),...t.filter(c=>!o.has(p(c))&&!g.has(p(c)))].map(c=>`${c}
|
|
9
|
+
`).join("")}r(I,"gitReflogPlay");function _(e){let n=null;return m(e).map(s=>{const o=s.split(" ",2)[1],t=`${n??"0".repeat(o.length)}${s.slice(s.indexOf(" "))}
|
|
10
|
+
`;return n=o,t}).join("")}r(_,"gitChainReflog");const q=r(e=>m(e).at(-1)?.split(" ",2)[1]??null,"gitReflogTop");export{_ as gitChainReflog,z as gitDropPackedRefs,G as gitLooseRef,N as gitPackedRefs,I as gitReflogPlay,q as gitReflogTop,H as gitRefsByMeaning,B as gitRefsTravelByMeaning};
|
package/dist/git/restore.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
var
|
|
2
|
-
`)));for(const t of n.files)(p(t)?E.test(t.path):T(t.path))&&r.set(t.path,t);if(i!==null){const t=q(i,new Set([...m(i).keys()].filter(c)));r.set(l,t===i?h(o):u(l,S(t)))}const y=s(t=>{const e=t.split("/");return e.slice(1).map((a,G)=>e.slice(0,G+1).join("/"))},"ancestors"),F=new Set([...r.keys()].flatMap(y)),_=s(t=>r.has(t.path)||!p(t)&&F.has(t.path)||y(t.path).some(e=>r.has(e)&&!p(r.get(e))),"inTheWay");for(const t of o.files)(p(t)?!E.test(t.path):t.path!==l&&!T(t.path)&&!x.has(t.path))&&!_(t)&&r.set(t.path,t);const R=L(r.values(),o.home),M={...o,files:R,index:n.index},P=C(M);if(!P.ok)return f(`the version cannot stand over this repository: ${P.error}`);const D=new Map(R.flatMap(t=>d.has(t.oid)?[[t.oid,d.get(t.oid)]]:[]));return A({state:M,blobs:D})}s(Y,"gitRestoreGoal");export{Y as gitRestoreGoal};
|
|
1
|
+
var F=Object.defineProperty;var s=(o,n)=>F(o,"name",{value:n,configurable:!0});import{fail as i,pass as B}from"../contracts/validate.js";import{gitOwnFile as G,gitOwnRef as y}from"./parts.js";import{gitRefsByMeaning as W}from"./refs.js";import{checkGitState as _,gitBytesForm as j,gitSelfHeld as q,gitTreeOf as A}from"./state.js";const b=/^(rebase-merge|rebase-apply|sequencer)(\/|$)/,f=s(o=>o.mode==="040000","isFolder"),k=s(o=>y(o)||G(o),"restored");function z(o,n,R,v){for(const t of[o,n]){if(j(t))return i("a repository in byte form cannot be restored");if(t.files.some(e=>e.path.startsWith("reftable/")))return i("a reftable repository cannot be restored");if(q(t.home))return i("a worktree of storage outside every folder cannot be restored")}if(o.format!==n.format)return i(`a ${o.format} repository cannot take a ${n.format} version`);const c=new Map,p=s(t=>{const e=t.files.find(a=>a.path==="packed-refs")?.oid,m=W(t,e?c.get(e)??R(e):null,v);for(const[a,E]of m.made)c.set(a,E);return m.state},"meaning"),[d,h]=[p(o),p(n)],g=s(t=>new Set(t.files.filter(e=>!f(e)&&y(e.path)).map(e=>e.path)),"ownRefs"),M=g(h),O=new Set([...g(d)].filter(t=>!M.has(t)).map(t=>`logs/${t}`)),r=new Map;for(const t of h.files)(f(t)?b.test(t.path):k(t.path))&&r.set(t.path,t);const u=s(t=>{const e=t.split("/");return e.slice(1).map((m,a)=>e.slice(0,a+1).join("/"))},"ancestors"),S=new Set([...r.keys()].flatMap(u)),$=s(t=>r.has(t.path)||!f(t)&&S.has(t.path)||u(t.path).some(e=>r.has(e)&&!f(r.get(e))),"inTheWay");for(const t of d.files)(f(t)?!b.test(t.path):!k(t.path)&&!O.has(t.path))&&!$(t)&&r.set(t.path,t);const l=p({...o,files:A(r.values(),o.home),index:n.index}),T=l.files,w=_(l);if(!w.ok)return i(`the version cannot stand over this repository: ${w.error}`);const x=new Map(T.flatMap(t=>c.has(t.oid)?[[t.oid,c.get(t.oid)]]:[]));return B({state:l,blobs:x})}s(z,"gitRestoreGoal");export{z as gitRestoreGoal};
|
package/dist/git/tag.d.ts
CHANGED
|
@@ -5,4 +5,4 @@ export declare const GIT_TAG_OFF: string;
|
|
|
5
5
|
export type GitTagEdit = readonly string[];
|
|
6
6
|
export declare function gitNamedObjectFormat(configuration: string): GitObjectFormat;
|
|
7
7
|
export declare function gitTagEdits(listing: string, on: boolean): readonly GitTagEdit[];
|
|
8
|
-
export declare
|
|
8
|
+
export declare const gitConfigUntagged: (text: string) => string;
|
package/dist/git/tag.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var
|
|
2
|
-
`);function
|
|
3
|
-
`);return
|
|
1
|
+
var d=Object.defineProperty;var f=(s,a)=>d(s,"name",{value:a,configurable:!0});import{gitConfigWithout as T}from"./config-text.js";const l="extensions.amalgm",p=4,n="core.repositoryformatversion",c="extensions.objectformat",h="index.version",u={sha1:"run-amalgm-setup-or-use-amalgm-git",sha256:"run-amalgm-setup-or-use-amalgm-git-sha256"},I=/^[\x21-\x7e]{1,64}$/,_=[`git config --file .git/config ${n} 1`,"git config --file .git/config --unset extensions.objectFormat",`git config --file .git/config --unset ${l}`,`git config --file .git/config ${n} 0`].join(`
|
|
2
|
+
`);function F(s){return/^\s*objectformat\s*=\s*"?(?:sha256|run-amalgm-setup-or-use-amalgm-git-sha256)"?\s*(?:[#;].*)?$/im.test(s)?"sha256":"sha1"}f(F,"gitNamedObjectFormat");function N(s,a){const e=new Map(s.split("\0").filter(t=>t!=="").map(t=>{const o=t.indexOf(`
|
|
3
|
+
`);return o<0?[t,""]:[t.slice(0,o),t.slice(o+1)]})),i=e.get(n)??"0",r=e.get(c)?.toLowerCase(),g=e.get(l);if(a){const t=g!==void 0&&I.test(g),o=u[r==="sha256"||r===u.sha256?"sha256":"sha1"];return[...e.get(h)===String(p)?[]:[["--replace-all",h,String(p)]],...t?[]:[...i==="1"?[]:[["--replace-all",n,"1"]],["--replace-all",l,"true"]],...t&&i==="2"?[]:[["--replace-all",n,"2"]],...r===o?[]:[["--replace-all",c,o]]]}const m=r===u.sha256?"sha256":r===u.sha1?"sha1":null;if(g===void 0&&i!=="2"&&m===null)return[];const x=[...e.keys()].some(t=>t.startsWith("extensions.")&&t!==l&&!(t===c&&m==="sha1"));return[...i==="2"?[["--replace-all",n,"1"]]:[],...m==="sha256"?[["--replace-all",c,"sha256"]]:m==="sha1"?[["--unset-all",c]]:[],...g===void 0?[]:[["--unset-all",l]],...x||i==="0"?[]:[["--replace-all",n,"0"]]]}f(N,"gitTagEdits");const G=f(s=>T(s,(a,e)=>a==="core"&&e==="repositoryformatversion"||a==="extensions"&&e==="amalgm"),"gitConfigUntagged");export{p as GIT_INDEX_VERSION,l as GIT_TAG,_ as GIT_TAG_OFF,G as gitConfigUntagged,F as gitNamedObjectFormat,N as gitTagEdits};
|