@catamorphic/git 0.0.0-stage → 0.1.0-alpha.30
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/LICENSE.txt +202 -0
- package/NOTICE.txt +32 -0
- package/dist/checkout-remote-backend.d.ts +12 -0
- package/dist/checkout-remote-backend.d.ts.map +1 -0
- package/dist/file-reads.d.ts +15 -0
- package/dist/file-reads.d.ts.map +1 -0
- package/dist/fs-backend.d.ts +30 -0
- package/dist/fs-backend.d.ts.map +1 -0
- package/dist/fs-remote-backend.d.ts +47 -0
- package/dist/fs-remote-backend.d.ts.map +1 -0
- package/dist/git-object-codec.d.ts +31 -0
- package/dist/git-object-codec.d.ts.map +1 -0
- package/dist/git-sync.d.ts +61 -0
- package/dist/git-sync.d.ts.map +1 -0
- package/dist/in-memory-object-store.d.ts +23 -0
- package/dist/in-memory-object-store.d.ts.map +1 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4746 -0
- package/dist/index.js.map +32 -0
- package/dist/migrate-workflow.d.ts +12 -0
- package/dist/migrate-workflow.d.ts.map +1 -0
- package/dist/native-git.d.ts +25 -0
- package/dist/native-git.d.ts.map +1 -0
- package/dist/native-project-repo.d.ts +57 -0
- package/dist/native-project-repo.d.ts.map +1 -0
- package/dist/network-sync.d.ts +58 -0
- package/dist/network-sync.d.ts.map +1 -0
- package/dist/network.d.ts +81 -0
- package/dist/network.d.ts.map +1 -0
- package/dist/object-remote-backend.d.ts +95 -0
- package/dist/object-remote-backend.d.ts.map +1 -0
- package/dist/object-store.d.ts +42 -0
- package/dist/object-store.d.ts.map +1 -0
- package/dist/origin-draft.d.ts +264 -0
- package/dist/origin-draft.d.ts.map +1 -0
- package/dist/origin-objects.d.ts +201 -0
- package/dist/origin-objects.d.ts.map +1 -0
- package/dist/personal-files.d.ts +6 -0
- package/dist/personal-files.d.ts.map +1 -0
- package/dist/project-manager.d.ts +214 -0
- package/dist/project-manager.d.ts.map +1 -0
- package/dist/project-repo.d.ts +79 -0
- package/dist/project-repo.d.ts.map +1 -0
- package/dist/ref-moved-error.d.ts +13 -0
- package/dist/ref-moved-error.d.ts.map +1 -0
- package/dist/ref-names.d.ts +18 -0
- package/dist/ref-names.d.ts.map +1 -0
- package/dist/types.d.ts +276 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/workspace-mirror.d.ts +110 -0
- package/dist/workspace-mirror.d.ts.map +1 -0
- package/package.json +53 -4
- package/src/checkout-remote-backend.ts +154 -0
- package/src/diff3.d.ts +16 -0
- package/src/file-reads.ts +53 -0
- package/src/fs-backend.ts +206 -0
- package/src/fs-remote-backend.ts +252 -0
- package/src/git-object-codec.ts +87 -0
- package/src/git-sync.ts +539 -0
- package/src/in-memory-object-store.ts +60 -0
- package/src/index.ts +110 -0
- package/src/migrate-workflow.ts +30 -0
- package/src/native-git.ts +177 -0
- package/src/native-project-repo.ts +515 -0
- package/src/network-sync.ts +239 -0
- package/src/network.ts +269 -0
- package/src/object-remote-backend.ts +366 -0
- package/src/object-store.ts +41 -0
- package/src/origin-draft.ts +1033 -0
- package/src/origin-objects.ts +906 -0
- package/src/personal-files.ts +57 -0
- package/src/project-manager.ts +743 -0
- package/src/project-repo.ts +800 -0
- package/src/ref-moved-error.ts +18 -0
- package/src/ref-names.ts +47 -0
- package/src/types.ts +289 -0
- package/src/workspace-mirror.ts +400 -0
- package/README.md +0 -3
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ProjectManager } from "./project-manager.js";
|
|
2
|
+
export declare function migrateWorkflowToProject({ projectManager, tenantId, projectId, workflowName, workflowCode, }: {
|
|
3
|
+
projectManager: ProjectManager;
|
|
4
|
+
tenantId: string;
|
|
5
|
+
projectId: string;
|
|
6
|
+
workflowName: string;
|
|
7
|
+
workflowCode: string;
|
|
8
|
+
}): Promise<{
|
|
9
|
+
projectId: string;
|
|
10
|
+
commitSha: string;
|
|
11
|
+
}>;
|
|
12
|
+
//# sourceMappingURL=migrate-workflow.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrate-workflow.d.ts","sourceRoot":"","sources":["../src/migrate-workflow.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAE3D,wBAAsB,wBAAwB,CAAC,EAC7C,cAAc,EACd,QAAQ,EACR,SAAS,EACT,YAAY,EACZ,YAAY,GACb,EAAE;IACD,cAAc,EAAE,cAAc,CAAC;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;CACtB;;;GAeA"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export interface NativeGitAuth {
|
|
2
|
+
url: string;
|
|
3
|
+
username: string;
|
|
4
|
+
password: string;
|
|
5
|
+
}
|
|
6
|
+
/** Native Git runs outside the host event loop and never refreshes the index on reads. */
|
|
7
|
+
export declare function nativeGit(cwd: string, args: readonly string[], auth?: NativeGitAuth): Promise<string>;
|
|
8
|
+
export declare function nativeGitBytes(cwd: string, args: readonly string[], input?: Uint8Array): Promise<Uint8Array>;
|
|
9
|
+
export interface LocalFolder {
|
|
10
|
+
path: string;
|
|
11
|
+
commonDirectory: string | null;
|
|
12
|
+
branch: string | null;
|
|
13
|
+
defaultBranch: string | null;
|
|
14
|
+
remoteUrl: string | null;
|
|
15
|
+
remoteBranch: string | null;
|
|
16
|
+
}
|
|
17
|
+
/** A .git directory or worktree pointer belongs to this folder, not an ancestor. */
|
|
18
|
+
export declare function hasLocalGit({ path: root, }: {
|
|
19
|
+
path: string;
|
|
20
|
+
}): Promise<boolean>;
|
|
21
|
+
/** Resolve subfolders, symlink aliases and linked worktrees without modifying the checkout. */
|
|
22
|
+
export declare function discoverLocalFolder(input: {
|
|
23
|
+
path: string;
|
|
24
|
+
}): Promise<LocalFolder>;
|
|
25
|
+
//# sourceMappingURL=native-git.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"native-git.d.ts","sourceRoot":"","sources":["../src/native-git.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,aAAa;IAC5B,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,0FAA0F;AAC1F,wBAAsB,SAAS,CAC7B,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,SAAS,MAAM,EAAE,EACvB,IAAI,CAAC,EAAE,aAAa,GACnB,OAAO,CAAC,MAAM,CAAC,CAuBjB;AAED,wBAAsB,cAAc,CAClC,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,SAAS,MAAM,EAAE,EACvB,KAAK,CAAC,EAAE,UAAU,GACjB,OAAO,CAAC,UAAU,CAAC,CASrB;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B;AAED,oFAAoF;AACpF,wBAAsB,WAAW,CAAC,EAChC,IAAI,EAAE,IAAI,GACX,EAAE;IACD,IAAI,EAAE,MAAM,CAAC;CACd,GAAG,OAAO,CAAC,OAAO,CAAC,CASnB;AAED,+FAA+F;AAC/F,wBAAsB,mBAAmB,CAAC,KAAK,EAAE;IAC/C,IAAI,EAAE,MAAM,CAAC;CACd,GAAG,OAAO,CAAC,WAAW,CAAC,CA0FvB"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { type FileReadOptions } from "./file-reads.js";
|
|
2
|
+
import { ProjectRepoImpl } from "./project-repo.js";
|
|
3
|
+
import type { BranchInfo, CommitInfo, DiffEntry, RepoStatus } from "./types.js";
|
|
4
|
+
/** Local-checkout adapter. File IO stays shared; Git honors the user's repository format and tools. */
|
|
5
|
+
export declare class NativeProjectRepo extends ProjectRepoImpl {
|
|
6
|
+
protected readonly followsSymlinks = true;
|
|
7
|
+
readFileBytes(filePath: string): Promise<Uint8Array | null>;
|
|
8
|
+
readAllFiles(options?: FileReadOptions): Promise<Record<string, string>>;
|
|
9
|
+
listFiles(opts?: {
|
|
10
|
+
prefix?: string;
|
|
11
|
+
}): Promise<string[]>;
|
|
12
|
+
findFilesContaining(input: {
|
|
13
|
+
text: string;
|
|
14
|
+
ref?: string;
|
|
15
|
+
globs: readonly string[];
|
|
16
|
+
}): Promise<string[]>;
|
|
17
|
+
resolveRef(ref?: string): Promise<string>;
|
|
18
|
+
currentBranch(): Promise<string>;
|
|
19
|
+
status(): Promise<RepoStatus>;
|
|
20
|
+
commit(message: string, author: {
|
|
21
|
+
name: string;
|
|
22
|
+
email: string;
|
|
23
|
+
}, opts?: {
|
|
24
|
+
paths?: readonly string[];
|
|
25
|
+
allowEmpty?: boolean;
|
|
26
|
+
}): Promise<string>;
|
|
27
|
+
workdirDiff(): Promise<DiffEntry[]>;
|
|
28
|
+
resetWorkingTree(): Promise<void>;
|
|
29
|
+
checkout(ref?: string): Promise<void>;
|
|
30
|
+
createBranch(name: string, fromRef?: string): Promise<void>;
|
|
31
|
+
deleteBranch(name: string): Promise<void>;
|
|
32
|
+
hasBranch(name: string): Promise<boolean>;
|
|
33
|
+
moveBranch(name: string, sha: string): Promise<void>;
|
|
34
|
+
listBranches(): Promise<BranchInfo[]>;
|
|
35
|
+
log(options?: {
|
|
36
|
+
maxCount?: number;
|
|
37
|
+
ref?: string;
|
|
38
|
+
}): Promise<CommitInfo[]>;
|
|
39
|
+
listFilesAtRef(ref: string, opts?: {
|
|
40
|
+
prefix?: string;
|
|
41
|
+
}): Promise<string[]>;
|
|
42
|
+
listBlobsAtRef(ref: string, opts?: {
|
|
43
|
+
prefix?: string;
|
|
44
|
+
}): Promise<Array<{
|
|
45
|
+
path: string;
|
|
46
|
+
oid: string;
|
|
47
|
+
}>>;
|
|
48
|
+
readBlobAtRef(ref: string, filePath: string, options?: {
|
|
49
|
+
maxBytes?: number;
|
|
50
|
+
}): Promise<Uint8Array | null>;
|
|
51
|
+
readAllFilesAtRef(ref: string, options?: FileReadOptions): Promise<Record<string, string>>;
|
|
52
|
+
readFilesAtRef(ref: string, opts: {
|
|
53
|
+
prefix: string;
|
|
54
|
+
}): Promise<Record<string, string>>;
|
|
55
|
+
private readTextSnapshotAtRef;
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=native-project-repo.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"native-project-repo.d.ts","sourceRoot":"","sources":["../src/native-project-repo.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,KAAK,eAAe,EAAoB,MAAM,iBAAiB,CAAC;AAMzE,OAAO,EAEL,eAAe,EAEhB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAEhF,uGAAuG;AACvG,qBAAa,iBAAkB,SAAQ,eAAe;IACpD,mBAA4B,eAAe,QAAQ;IAEpC,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAqBzE;IAEc,YAAY,CACzB,OAAO,GAAE,eAAoB,GAC5B,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAgBjC;IAEc,SAAS,CAAC,IAAI,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAmCtE;IAEK,mBAAmB,CAAC,KAAK,EAAE;QAC/B,IAAI,EAAE,MAAM,CAAC;QACb,GAAG,CAAC,EAAE,MAAM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C;KACd,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC,CAqBxB;IACc,cAAc,CAC3B,GAAG,EAAE,MAAM,EACX,IAAI,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,GACzB,OAAO,CAAC,MAAM,EAAE,CAAC,CAEnB;IACc,cAAc,CAC3B,GAAG,EAAE,MAAM,EACX,IAAI,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,GACzB,OAAO,CAAC,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC,CAmB/C;IACc,aAAa,CAC1B,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,GAC9B,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAqB5B;IACc,iBAAiB,CAC9B,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAEjC;IACc,cAAc,CAC3B,GAAG,EAAE,MAAM,EACX,IAAI,EAAE;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,GACvB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAEjC;YACa,qBAAqB;CA4BpC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { type RemoteOwnership } from "./network.js";
|
|
2
|
+
import type { GitCredentials, ProjectRepo } from "./types.js";
|
|
3
|
+
export type NetworkSyncStatus =
|
|
4
|
+
/** Not on `main` (a deploy owns the tree right now) — nothing done. */
|
|
5
|
+
"no-op" | "up-to-date"
|
|
6
|
+
/** Owned remotes: local commits pushed (including creating a missing
|
|
7
|
+
* remote branch). */
|
|
8
|
+
| "pushed"
|
|
9
|
+
/** Remote commits fast-forwarded into the local tree. */
|
|
10
|
+
| "pulled"
|
|
11
|
+
/** Owned remotes: histories diverged; a clean 3-way merge landed and was
|
|
12
|
+
* pushed. */
|
|
13
|
+
| "merged"
|
|
14
|
+
/** The tree has uncommitted edits and integrating the remote would touch
|
|
15
|
+
* it — deferred untouched; the next sync retries. */
|
|
16
|
+
| "deferred"
|
|
17
|
+
/** Attached remotes: the local branch has commits the remote does not
|
|
18
|
+
* (or the remote branch does not exist). Work never pushes them; they
|
|
19
|
+
* reach the repository as a pull request. */
|
|
20
|
+
| "ahead"
|
|
21
|
+
/** Histories diverged. Owned remotes: the merge conflicts, and local
|
|
22
|
+
* `main` was pushed to `rescueBranch` so no work is stranded. Attached
|
|
23
|
+
* remotes: nothing was merged or pushed; the local commits reach the
|
|
24
|
+
* repository as a pull request. The user's tree is never touched. */
|
|
25
|
+
| "diverged";
|
|
26
|
+
export interface NetworkSyncResult {
|
|
27
|
+
status: NetworkSyncStatus;
|
|
28
|
+
localSha: string | null;
|
|
29
|
+
remoteSha: string | null;
|
|
30
|
+
rescueBranch?: string;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Converge the dev repo's current branch with a branch on a network git
|
|
34
|
+
* remote. Knows nothing about any particular code host — a URL plus optional
|
|
35
|
+
* credentials is the entire contract (ADR 0044).
|
|
36
|
+
*
|
|
37
|
+
* Both ownerships fetch, report equality, and fast-forward over a clean tree
|
|
38
|
+
* when strictly behind. Only an owned remote is ever written to (ADR 0170):
|
|
39
|
+
* missing remote branch or strictly ahead → push; diverged → 3-way merge
|
|
40
|
+
* that aborts on conflict (a background sync must NEVER leave conflict
|
|
41
|
+
* markers), falling back to pushing a rescue branch. An attached remote
|
|
42
|
+
* reports `ahead` or `diverged` instead and pushes nothing.
|
|
43
|
+
*/
|
|
44
|
+
export declare function syncWithNetworkRemote(opts: {
|
|
45
|
+
dev: ProjectRepo;
|
|
46
|
+
url: string;
|
|
47
|
+
credentials?: GitCredentials;
|
|
48
|
+
remoteBranch: string;
|
|
49
|
+
/** Who created the remote; only owned remotes are pushed to. */
|
|
50
|
+
ownership: RemoteOwnership;
|
|
51
|
+
author: {
|
|
52
|
+
name: string;
|
|
53
|
+
email: string;
|
|
54
|
+
};
|
|
55
|
+
/** Injectable clock for deterministic rescue-branch names in tests. */
|
|
56
|
+
now?: Date;
|
|
57
|
+
}): Promise<NetworkSyncResult>;
|
|
58
|
+
//# sourceMappingURL=network-sync.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"network-sync.d.ts","sourceRoot":"","sources":["../src/network-sync.ts"],"names":[],"mappings":"AAKA,OAAO,EAGL,KAAK,eAAe,EACrB,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9D,MAAM,MAAM,iBAAiB;AAC3B,uEAAuE;AACrE,OAAO,GACP,YAAY;AACd;qBACqB;GACnB,QAAQ;AACV,yDAAyD;GACvD,QAAQ;AACV;aACa;GACX,QAAQ;AACV;qDACqD;GACnD,UAAU;AACZ;;6CAE6C;GAC3C,OAAO;AACT;;;qEAGqE;GACnE,UAAU,CAAC;AAEf,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,iBAAiB,CAAC;IAC1B,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,qBAAqB,CAAC,IAAI,EAAE;IAChD,GAAG,EAAE,WAAW,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,CAAC,EAAE,cAAc,CAAC;IAC7B,YAAY,EAAE,MAAM,CAAC;IACrB,gEAAgE;IAChE,SAAS,EAAE,eAAe,CAAC;IAC3B,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IACxC,uEAAuE;IACvE,GAAG,CAAC,EAAE,IAAI,CAAC;CACZ,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAkK7B"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { GitCredentials } from "./types.js";
|
|
2
|
+
export interface CloneFromRemoteOptions {
|
|
3
|
+
native?: boolean;
|
|
4
|
+
/** Directory that already holds an initialized (empty) git repo. */
|
|
5
|
+
repoPath: string;
|
|
6
|
+
url: string;
|
|
7
|
+
credentials?: GitCredentials;
|
|
8
|
+
/** Branch to clone; defaults to the remote's default branch. */
|
|
9
|
+
branch?: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Populate a freshly-initialized repo from a network git remote (e.g. a
|
|
13
|
+
* GitHub repository). The remote's history lands on the local `main` branch
|
|
14
|
+
* regardless of the remote's branch name — catamorphic's internal sync
|
|
15
|
+
* (`git-sync`, drafts, checkout seeding) assumes `main` throughout, so the remote
|
|
16
|
+
* branch name is only remembered by the caller for push-back.
|
|
17
|
+
*
|
|
18
|
+
* Returns the checked-out sha and the remote's branch name.
|
|
19
|
+
*/
|
|
20
|
+
export declare function cloneFromRemote(opts: CloneFromRemoteOptions): Promise<{
|
|
21
|
+
sha: string;
|
|
22
|
+
remoteBranch: string;
|
|
23
|
+
}>;
|
|
24
|
+
/**
|
|
25
|
+
* Who created a linked network remote (ADR 0170). `owned`: Work created the
|
|
26
|
+
* repository, so ADR 0044 sync may update its tracked branch. `attached`: the
|
|
27
|
+
* repository existed before Work (an opened folder with an origin, a clone,
|
|
28
|
+
* an imported company repository). Work never updates its default branch or
|
|
29
|
+
* any branch it did not create there.
|
|
30
|
+
*/
|
|
31
|
+
export type RemoteOwnership = "owned" | "attached";
|
|
32
|
+
export declare class RemotePushRefusedError extends Error {
|
|
33
|
+
readonly remoteBranch: string;
|
|
34
|
+
constructor(remoteBranch: string, reason: string);
|
|
35
|
+
}
|
|
36
|
+
/** Whether `branch` is one Work creates: `work/<something>`. */
|
|
37
|
+
export declare function isManagedBranch(branch: string): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* The one push rule (ADR 0170). On an attached remote Work may only create or
|
|
40
|
+
* fast-forward branches under `work/`; the default branch and every other
|
|
41
|
+
* branch belong to the people who share the repository, and history there is
|
|
42
|
+
* never rewritten. Owned remotes are unrestricted.
|
|
43
|
+
*/
|
|
44
|
+
export declare function assertPushAllowed(input: {
|
|
45
|
+
ownership: RemoteOwnership;
|
|
46
|
+
remoteBranch: string;
|
|
47
|
+
force?: boolean;
|
|
48
|
+
}): void;
|
|
49
|
+
/**
|
|
50
|
+
* Push a local ref to a network git remote, bypassing the repo's configured
|
|
51
|
+
* `origin` (which catamorphic points at its internal remote backend). Every
|
|
52
|
+
* network push goes through here, so {@link assertPushAllowed} decides what
|
|
53
|
+
* may reach a remote before anything is sent.
|
|
54
|
+
*/
|
|
55
|
+
export declare function pushToRemote(opts: {
|
|
56
|
+
repoPath: string;
|
|
57
|
+
native?: boolean;
|
|
58
|
+
url: string;
|
|
59
|
+
credentials?: GitCredentials;
|
|
60
|
+
/** Who created the remote: attached remotes only accept Work's branches. */
|
|
61
|
+
ownership: RemoteOwnership;
|
|
62
|
+
/** Local ref to push. */
|
|
63
|
+
ref: string;
|
|
64
|
+
/** Branch name on the remote (a plain name, not `refs/heads/...`). */
|
|
65
|
+
remoteBranch: string;
|
|
66
|
+
force?: boolean;
|
|
67
|
+
}): Promise<void>;
|
|
68
|
+
/**
|
|
69
|
+
* Fetch a branch from a network remote into a tracking ref without touching
|
|
70
|
+
* the working tree. Returns the fetched sha (null when the remote branch does
|
|
71
|
+
* not exist).
|
|
72
|
+
*/
|
|
73
|
+
export declare function fetchFromRemote(opts: {
|
|
74
|
+
repoPath: string;
|
|
75
|
+
url: string;
|
|
76
|
+
credentials?: GitCredentials;
|
|
77
|
+
branch: string;
|
|
78
|
+
}): Promise<{
|
|
79
|
+
sha: string | null;
|
|
80
|
+
}>;
|
|
81
|
+
//# sourceMappingURL=network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,SAAS,EAAE,eAAe,CAAC;IAC3B,yBAAyB;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,sEAAsE;IACtE,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,GAAG,OAAO,CAAC,IAAI,CAAC,CAiChB;AAED;;;;GAIG;AACH,wBAAsB,eAAe,CAAC,IAAI,EAAE;IAC1C,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,CAAC,EAAE,cAAc,CAAC;IAC7B,MAAM,EAAE,MAAM,CAAC;CAChB,GAAG,OAAO,CAAC;IAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAC,CAkClC"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { type GitObjectType } from "./git-object-codec.js";
|
|
2
|
+
import { type ObjectStore } from "./object-store.js";
|
|
3
|
+
import type { CommitInfo, DraftSupport, OriginRepo, RemoteBackend } from "./types.js";
|
|
4
|
+
/**
|
|
5
|
+
* Check that a store enforces the preconditions drafts rely on: a put with
|
|
6
|
+
* `ifNoneMatch` on an existing key, and deletes with a stale or the current
|
|
7
|
+
* `ifMatch`. Returns why it does not, or null when it does. The probe key
|
|
8
|
+
* is removed afterwards.
|
|
9
|
+
*/
|
|
10
|
+
export declare function probeConditionalWrites(input: {
|
|
11
|
+
store: ObjectStore;
|
|
12
|
+
key: string;
|
|
13
|
+
}): Promise<string | null>;
|
|
14
|
+
export interface ObjectRemoteBackendOpts {
|
|
15
|
+
store: ObjectStore;
|
|
16
|
+
/**
|
|
17
|
+
* Key prefix so multiple catamorphic environments can share a bucket.
|
|
18
|
+
* Project layout: `<keyPrefix><tenantId>/<projectId>/{repo.json,objects/,refs/}`.
|
|
19
|
+
*/
|
|
20
|
+
keyPrefix?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* `RemoteBackend` storing each project's canonical bare repository directly
|
|
24
|
+
* in a host-injected object store. S3 and Postgres backends share the same
|
|
25
|
+
* immutable objects and conditional ref updates, without a local origin mirror.
|
|
26
|
+
*
|
|
27
|
+
* Git objects are immutable and content-addressed, so they map cleanly onto
|
|
28
|
+
* object storage; ref updates use conditional PUTs (`If-Match` /
|
|
29
|
+
* `If-None-Match`) for the compare-and-swap semantics `OriginRepo.updateRef`
|
|
30
|
+
* requires. Buckets don't speak the git protocol, so `getCloneSource` is not
|
|
31
|
+
* implemented and sandboxes receive file uploads (same as `FsRemoteBackend`).
|
|
32
|
+
* See docs/decisions/0012.
|
|
33
|
+
*/
|
|
34
|
+
export declare class ObjectRemoteBackend implements RemoteBackend {
|
|
35
|
+
private readonly store;
|
|
36
|
+
private readonly keyPrefix;
|
|
37
|
+
private draftCheck;
|
|
38
|
+
constructor(opts: ObjectRemoteBackendOpts);
|
|
39
|
+
private basePath;
|
|
40
|
+
private markerKey;
|
|
41
|
+
initRemote(tenantId: string, projectId: string): Promise<void>;
|
|
42
|
+
deleteRemote(tenantId: string, projectId: string): Promise<void>;
|
|
43
|
+
exists(tenantId: string, projectId: string): Promise<boolean>;
|
|
44
|
+
/**
|
|
45
|
+
* Drafts need conditional puts and deletes that the store really
|
|
46
|
+
* enforces (ADR 0191). Some S3-compatible stores ignore `If-Match` on
|
|
47
|
+
* DeleteObject, so the store is probed once per process before any draft
|
|
48
|
+
* is written, and drafts are refused on a store that fails.
|
|
49
|
+
*/
|
|
50
|
+
draftSupport(): Promise<DraftSupport>;
|
|
51
|
+
withOrigin<T>(tenantId: string, projectId: string, fn: (origin: OriginRepo) => Promise<T>): Promise<T>;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* `OriginRepo` over a key prefix in an object store:
|
|
55
|
+
* - `objects/<sha>` — wrapped git objects (`<type> <len>\0<content>`), so
|
|
56
|
+
* `sha1(body) == key` and every object is self-verifying.
|
|
57
|
+
* - `refs/heads/<branch>` — the 40-char commit SHA as the body.
|
|
58
|
+
*/
|
|
59
|
+
export declare class ObjectOriginRepo implements OriginRepo {
|
|
60
|
+
private readonly store;
|
|
61
|
+
private readonly basePath;
|
|
62
|
+
/** Synthetic identifier — this origin has no on-disk git directory. */
|
|
63
|
+
readonly gitdir: string;
|
|
64
|
+
constructor(opts: {
|
|
65
|
+
store: ObjectStore;
|
|
66
|
+
basePath: string;
|
|
67
|
+
});
|
|
68
|
+
private refKey;
|
|
69
|
+
private objectKey;
|
|
70
|
+
resolveRef(ref: string): Promise<string | null>;
|
|
71
|
+
listRefs(prefix: string): Promise<{
|
|
72
|
+
ref: string;
|
|
73
|
+
sha: string;
|
|
74
|
+
}[]>;
|
|
75
|
+
updateRef(opts: {
|
|
76
|
+
ref: string;
|
|
77
|
+
sha: string;
|
|
78
|
+
expected?: string | null;
|
|
79
|
+
}): Promise<void>;
|
|
80
|
+
deleteRef(input: {
|
|
81
|
+
ref: string;
|
|
82
|
+
expected?: string;
|
|
83
|
+
}): Promise<void>;
|
|
84
|
+
hasObject(sha: string): Promise<boolean>;
|
|
85
|
+
readObject(sha: string): Promise<{
|
|
86
|
+
type: GitObjectType;
|
|
87
|
+
data: Uint8Array;
|
|
88
|
+
}>;
|
|
89
|
+
writeObject(opts: {
|
|
90
|
+
type: GitObjectType;
|
|
91
|
+
data: Uint8Array;
|
|
92
|
+
}): Promise<string>;
|
|
93
|
+
log(ref: string, maxCount?: number): Promise<CommitInfo[]>;
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=object-remote-backend.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"object-remote-backend.d.ts","sourceRoot":"","sources":["../src/object-remote-backend.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,aAAa,EAInB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,KAAK,WAAW,EAA2B,MAAM,mBAAmB,CAAC;AAG9E,OAAO,KAAK,EACV,UAAU,EACV,YAAY,EACZ,UAAU,EACV,aAAa,EACd,MAAM,YAAY,CAAC;AAmBp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**
|
|
2
|
+
* Minimal object-storage contract the git origin needs. `S3ObjectStore` is
|
|
3
|
+
* the production implementation; `InMemoryObjectStore` backs unit tests.
|
|
4
|
+
*
|
|
5
|
+
* Semantics implementations must honor:
|
|
6
|
+
* - `put` with `ifNoneMatch: "*"` fails with {@link PreconditionFailedError}
|
|
7
|
+
* when the key already exists.
|
|
8
|
+
* - `put` and `delete` with `ifMatch` fail with
|
|
9
|
+
* {@link PreconditionFailedError} when the key is missing or its ETag
|
|
10
|
+
* differs. ETags are opaque — callers only pass
|
|
11
|
+
* back values previously returned by `get`.
|
|
12
|
+
*/
|
|
13
|
+
export interface ObjectStore {
|
|
14
|
+
/** Read an object, or null when the key does not exist. */
|
|
15
|
+
get(key: string): Promise<{
|
|
16
|
+
data: Uint8Array;
|
|
17
|
+
etag: string;
|
|
18
|
+
} | null>;
|
|
19
|
+
/** Whether the key exists (no body transfer). */
|
|
20
|
+
has(key: string): Promise<boolean>;
|
|
21
|
+
put(key: string, data: Uint8Array, opts?: {
|
|
22
|
+
ifMatch?: string;
|
|
23
|
+
ifNoneMatch?: "*";
|
|
24
|
+
}): Promise<void>;
|
|
25
|
+
/** List full keys under a prefix. */
|
|
26
|
+
list(prefix: string): Promise<string[]>;
|
|
27
|
+
/**
|
|
28
|
+
* Delete exactly one key; a missing key is a no-op. With `ifMatch`, fails
|
|
29
|
+
* with {@link PreconditionFailedError} when the key is missing or its ETag
|
|
30
|
+
* differs.
|
|
31
|
+
*/
|
|
32
|
+
delete(key: string, opts?: {
|
|
33
|
+
ifMatch?: string;
|
|
34
|
+
}): Promise<void>;
|
|
35
|
+
/** Delete every object under a prefix. */
|
|
36
|
+
deletePrefix(prefix: string): Promise<void>;
|
|
37
|
+
}
|
|
38
|
+
/** A conditional `put` lost the race (HTTP 412 on S3-compatible stores). */
|
|
39
|
+
export declare class PreconditionFailedError extends Error {
|
|
40
|
+
constructor(key: string);
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=object-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"object-store.d.ts","sourceRoot":"","sources":["../src/object-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,WAAW;IAC1B,2DAA2D;IAC3D,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,IAAI,EAAE,UAAU,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC,CAAC;IACrE,iDAAiD;IACjD,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACnC,GAAG,CACD,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,UAAU,EAChB,IAAI,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,GAAG,CAAA;KAAE,GAC7C,OAAO,CAAC,IAAI,CAAC,CAAC;IACjB,qCAAqC;IACrC,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IACxC;;;;OAIG;IACH,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAChE,0CAA0C;IAC1C,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC7C;AAED,4EAA4E;AAC5E,qBAAa,uBAAwB,SAAQ,KAAK;IAChD,YAAY,GAAG,EAAE,MAAM,EAGtB;CACF"}
|