@leed-ai/git-gateway-contract 0.0.0-stage → 0.1.0
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 +201 -0
- package/README.md +50 -2
- package/dist/behaviour/assertions.d.ts +23 -0
- package/dist/behaviour/assertions.js +56 -0
- package/dist/behaviour/assertions.js.map +1 -0
- package/dist/behaviour/behaviour-case.d.ts +19 -0
- package/dist/behaviour/behaviour-case.js +12 -0
- package/dist/behaviour/behaviour-case.js.map +1 -0
- package/dist/behaviour/behaviour-suite.d.ts +30 -0
- package/dist/behaviour/behaviour-suite.js +50 -0
- package/dist/behaviour/behaviour-suite.js.map +1 -0
- package/dist/behaviour/commit-action-cases.d.ts +4 -0
- package/dist/behaviour/commit-action-cases.js +342 -0
- package/dist/behaviour/commit-action-cases.js.map +1 -0
- package/dist/behaviour/commit-write-cases.d.ts +4 -0
- package/dist/behaviour/commit-write-cases.js +234 -0
- package/dist/behaviour/commit-write-cases.js.map +1 -0
- package/dist/behaviour/fixtures.d.ts +29 -0
- package/dist/behaviour/fixtures.js +83 -0
- package/dist/behaviour/fixtures.js.map +1 -0
- package/dist/behaviour/lifecycle-cases.d.ts +4 -0
- package/dist/behaviour/lifecycle-cases.js +158 -0
- package/dist/behaviour/lifecycle-cases.js.map +1 -0
- package/dist/behaviour/promote-cases.d.ts +4 -0
- package/dist/behaviour/promote-cases.js +122 -0
- package/dist/behaviour/promote-cases.js.map +1 -0
- package/dist/behaviour/read-cases.d.ts +4 -0
- package/dist/behaviour/read-cases.js +248 -0
- package/dist/behaviour/read-cases.js.map +1 -0
- package/dist/behaviour/sync-cases.d.ts +4 -0
- package/dist/behaviour/sync-cases.js +205 -0
- package/dist/behaviour/sync-cases.js.map +1 -0
- package/dist/clock-B3MlpmVY.d.ts +10 -0
- package/dist/commit-BEZmeAOl.d.ts +23 -0
- package/dist/file-map-CxUveLWz.d.ts +18 -0
- package/dist/gateway-config-oVsdTEeK.d.ts +39 -0
- package/dist/gateway-error-body-BWzZFAQI.d.ts +214 -0
- package/dist/gateway-error.d.ts +30 -0
- package/dist/gateway-error.js +63 -0
- package/dist/gateway-error.js.map +1 -0
- package/dist/git-gateway-VA9Tc5tn.d.ts +358 -0
- package/dist/git-gateway.d.ts +2 -0
- package/dist/git-gateway.js +65 -0
- package/dist/git-gateway.js.map +1 -0
- package/dist/health.d.ts +9 -0
- package/dist/health.js +18 -0
- package/dist/health.js.map +1 -0
- package/dist/history-CqvHaUE-.d.ts +20 -0
- package/dist/package-name.d.ts +3 -0
- package/dist/package-name.js +6 -0
- package/dist/package-name.js.map +1 -0
- package/dist/proxy/audit-event.d.ts +61 -0
- package/dist/proxy/audit-event.js +97 -0
- package/dist/proxy/audit-event.js.map +1 -0
- package/dist/proxy/branch-rule.d.ts +72 -0
- package/dist/proxy/branch-rule.js +106 -0
- package/dist/proxy/branch-rule.js.map +1 -0
- package/dist/proxy/gateway-hooks.d.ts +58 -0
- package/dist/proxy/gateway-hooks.js +0 -0
- package/dist/proxy/git-operation.d.ts +17 -0
- package/dist/proxy/git-operation.js +32 -0
- package/dist/proxy/git-operation.js.map +1 -0
- package/dist/proxy/policy-result.d.ts +51 -0
- package/dist/proxy/policy-result.js +90 -0
- package/dist/proxy/policy-result.js.map +1 -0
- package/dist/proxy/principal.d.ts +18 -0
- package/dist/proxy/principal.js +32 -0
- package/dist/proxy/principal.js.map +1 -0
- package/dist/proxy/push-policy-result.d.ts +34 -0
- package/dist/proxy/push-policy-result.js +48 -0
- package/dist/proxy/push-policy-result.js.map +1 -0
- package/dist/proxy/push-policy.d.ts +146 -0
- package/dist/proxy/push-policy.js +112 -0
- package/dist/proxy/push-policy.js.map +1 -0
- package/dist/proxy/request-credential.d.ts +22 -0
- package/dist/proxy/request-credential.js +46 -0
- package/dist/proxy/request-credential.js.map +1 -0
- package/dist/proxy/smart-http-config.d.ts +22 -0
- package/dist/proxy/smart-http-config.js +40 -0
- package/dist/proxy/smart-http-config.js.map +1 -0
- package/dist/reference/apply-actions.d.ts +9 -0
- package/dist/reference/apply-actions.js +84 -0
- package/dist/reference/apply-actions.js.map +1 -0
- package/dist/reference/branch-methods.d.ts +7 -0
- package/dist/reference/branch-methods.js +105 -0
- package/dist/reference/branch-methods.js.map +1 -0
- package/dist/reference/bytes.d.ts +22 -0
- package/dist/reference/bytes.js +62 -0
- package/dist/reference/bytes.js.map +1 -0
- package/dist/reference/clock.d.ts +2 -0
- package/dist/reference/clock.js +18 -0
- package/dist/reference/clock.js.map +1 -0
- package/dist/reference/commit-method.d.ts +5 -0
- package/dist/reference/commit-method.js +83 -0
- package/dist/reference/commit-method.js.map +1 -0
- package/dist/reference/file-map.d.ts +2 -0
- package/dist/reference/file-map.js +24 -0
- package/dist/reference/file-map.js.map +1 -0
- package/dist/reference/hash.d.ts +10 -0
- package/dist/reference/hash.js +25 -0
- package/dist/reference/hash.js.map +1 -0
- package/dist/reference/history.d.ts +2 -0
- package/dist/reference/history.js +65 -0
- package/dist/reference/history.js.map +1 -0
- package/dist/reference/lifecycle-methods.d.ts +9 -0
- package/dist/reference/lifecycle-methods.js +48 -0
- package/dist/reference/lifecycle-methods.js.map +1 -0
- package/dist/reference/read-methods.d.ts +13 -0
- package/dist/reference/read-methods.js +68 -0
- package/dist/reference/read-methods.js.map +1 -0
- package/dist/reference/reference-gateway.d.ts +18 -0
- package/dist/reference/reference-gateway.js +35 -0
- package/dist/reference/reference-gateway.js.map +1 -0
- package/dist/reference/repo-state.d.ts +43 -0
- package/dist/reference/repo-state.js +45 -0
- package/dist/reference/repo-state.js.map +1 -0
- package/dist/reference/run-method.d.ts +13 -0
- package/dist/reference/run-method.js +15 -0
- package/dist/reference/run-method.js.map +1 -0
- package/dist/reference/three-way-merge.d.ts +16 -0
- package/dist/reference/three-way-merge.js +45 -0
- package/dist/reference/three-way-merge.js.map +1 -0
- package/dist/reference/trailer.d.ts +7 -0
- package/dist/reference/trailer.js +16 -0
- package/dist/reference/trailer.js.map +1 -0
- package/dist/reference/tree-index.d.ts +2 -0
- package/dist/reference/tree-index.js +66 -0
- package/dist/reference/tree-index.js.map +1 -0
- package/dist/reference/write-commit.d.ts +15 -0
- package/dist/reference/write-commit.js +44 -0
- package/dist/reference/write-commit.js.map +1 -0
- package/dist/rpc/commit-exists.d.ts +16 -0
- package/dist/rpc/commit-exists.js +30 -0
- package/dist/rpc/commit-exists.js.map +1 -0
- package/dist/rpc/commit.d.ts +172 -0
- package/dist/rpc/commit.js +115 -0
- package/dist/rpc/commit.js.map +1 -0
- package/dist/rpc/list-tree.d.ts +59 -0
- package/dist/rpc/list-tree.js +54 -0
- package/dist/rpc/list-tree.js.map +1 -0
- package/dist/rpc/log.d.ts +35 -0
- package/dist/rpc/log.js +41 -0
- package/dist/rpc/log.js.map +1 -0
- package/dist/rpc/mint-read-token.d.ts +17 -0
- package/dist/rpc/mint-read-token.js +36 -0
- package/dist/rpc/mint-read-token.js.map +1 -0
- package/dist/rpc/promote.d.ts +39 -0
- package/dist/rpc/promote.js +69 -0
- package/dist/rpc/promote.js.map +1 -0
- package/dist/rpc/read-file.d.ts +44 -0
- package/dist/rpc/read-file.js +56 -0
- package/dist/rpc/read-file.js.map +1 -0
- package/dist/rpc/repo-lifecycle.d.ts +39 -0
- package/dist/rpc/repo-lifecycle.js +64 -0
- package/dist/rpc/repo-lifecycle.js.map +1 -0
- package/dist/rpc/resolve-ref.d.ts +15 -0
- package/dist/rpc/resolve-ref.js +28 -0
- package/dist/rpc/resolve-ref.js.map +1 -0
- package/dist/rpc/sync-branch.d.ts +107 -0
- package/dist/rpc/sync-branch.js +114 -0
- package/dist/rpc/sync-branch.js.map +1 -0
- package/dist/schemas/commit-action.d.ts +100 -0
- package/dist/schemas/commit-action.js +138 -0
- package/dist/schemas/commit-action.js.map +1 -0
- package/dist/schemas/commit.d.ts +2 -0
- package/dist/schemas/commit.js +24 -0
- package/dist/schemas/commit.js.map +1 -0
- package/dist/schemas/content-encoding.d.ts +24 -0
- package/dist/schemas/content-encoding.js +41 -0
- package/dist/schemas/content-encoding.js.map +1 -0
- package/dist/schemas/examples.d.ts +38 -0
- package/dist/schemas/examples.js +32 -0
- package/dist/schemas/examples.js.map +1 -0
- package/dist/schemas/gateway-config.d.ts +2 -0
- package/dist/schemas/gateway-config.js +72 -0
- package/dist/schemas/gateway-config.js.map +1 -0
- package/dist/schemas/gateway-error-body.d.ts +2 -0
- package/dist/schemas/gateway-error-body.js +188 -0
- package/dist/schemas/gateway-error-body.js.map +1 -0
- package/dist/schemas/identity.d.ts +21 -0
- package/dist/schemas/identity.js +40 -0
- package/dist/schemas/identity.js.map +1 -0
- package/dist/schemas/names.d.ts +26 -0
- package/dist/schemas/names.js +58 -0
- package/dist/schemas/names.js.map +1 -0
- package/dist/schemas/ref-update.d.ts +10 -0
- package/dist/schemas/ref-update.js +25 -0
- package/dist/schemas/ref-update.js.map +1 -0
- package/dist/schemas/sha.d.ts +8 -0
- package/dist/schemas/sha.js +14 -0
- package/dist/schemas/sha.js.map +1 -0
- package/dist/schemas/tree-entry.d.ts +2 -0
- package/dist/schemas/tree-entry.js +62 -0
- package/dist/schemas/tree-entry.js.map +1 -0
- package/dist/storage/git-remote.d.ts +17 -0
- package/dist/storage/git-remote.js +31 -0
- package/dist/storage/git-remote.js.map +1 -0
- package/dist/storage/storage-backend.d.ts +61 -0
- package/dist/storage/storage-backend.js +0 -0
- package/dist/storage/storage-errors.d.ts +12 -0
- package/dist/storage/storage-errors.js +22 -0
- package/dist/storage/storage-errors.js.map +1 -0
- package/dist/storage/storage-input.d.ts +7 -0
- package/dist/storage/storage-input.js +14 -0
- package/dist/storage/storage-input.js.map +1 -0
- package/dist/storage/storage-read.d.ts +13 -0
- package/dist/storage/storage-read.js +30 -0
- package/dist/storage/storage-read.js.map +1 -0
- package/dist/storage/storage-repo-info.d.ts +16 -0
- package/dist/storage/storage-repo-info.js +30 -0
- package/dist/storage/storage-repo-info.js.map +1 -0
- package/dist/storage/storage-tree-entry.d.ts +21 -0
- package/dist/storage/storage-tree-entry.js +17 -0
- package/dist/storage/storage-tree-entry.js.map +1 -0
- package/dist/tree-entry-BM_1gou1.d.ts +41 -0
- package/dist/tree-index-Bk721Phv.d.ts +14 -0
- package/package.json +401 -4
- package/src/behaviour/assertions.ts +75 -0
- package/src/behaviour/behaviour-case.ts +28 -0
- package/src/behaviour/behaviour-suite.ts +76 -0
- package/src/behaviour/commit-action-cases.ts +253 -0
- package/src/behaviour/commit-write-cases.ts +205 -0
- package/src/behaviour/fixtures.ts +103 -0
- package/src/behaviour/lifecycle-cases.ts +104 -0
- package/src/behaviour/promote-cases.ts +78 -0
- package/src/behaviour/read-cases.ts +176 -0
- package/src/behaviour/sync-cases.ts +156 -0
- package/src/gateway-error.ts +72 -0
- package/src/git-gateway.ts +76 -0
- package/src/health.ts +26 -0
- package/src/package-name.ts +4 -0
- package/src/proxy/audit-event.ts +135 -0
- package/src/proxy/branch-rule.ts +190 -0
- package/src/proxy/gateway-hooks.ts +67 -0
- package/src/proxy/git-operation.ts +36 -0
- package/src/proxy/policy-result.ts +127 -0
- package/src/proxy/principal.ts +81 -0
- package/src/proxy/push-policy-result.ts +86 -0
- package/src/proxy/push-policy.ts +158 -0
- package/src/proxy/request-credential.ts +47 -0
- package/src/proxy/smart-http-config.ts +158 -0
- package/src/reference/apply-actions.ts +96 -0
- package/src/reference/branch-methods.ts +105 -0
- package/src/reference/bytes.ts +66 -0
- package/src/reference/clock.ts +19 -0
- package/src/reference/commit-method.ts +97 -0
- package/src/reference/file-map.ts +35 -0
- package/src/reference/hash.ts +25 -0
- package/src/reference/history.ts +78 -0
- package/src/reference/lifecycle-methods.ts +52 -0
- package/src/reference/read-methods.ts +87 -0
- package/src/reference/reference-gateway.ts +50 -0
- package/src/reference/repo-state.ts +83 -0
- package/src/reference/run-method.ts +25 -0
- package/src/reference/three-way-merge.ts +42 -0
- package/src/reference/trailer.ts +18 -0
- package/src/reference/tree-index.ts +65 -0
- package/src/reference/write-commit.ts +44 -0
- package/src/rpc/commit-exists.ts +46 -0
- package/src/rpc/commit.ts +156 -0
- package/src/rpc/list-tree.ts +78 -0
- package/src/rpc/log.ts +51 -0
- package/src/rpc/mint-read-token.ts +59 -0
- package/src/rpc/promote.ts +72 -0
- package/src/rpc/read-file.ts +75 -0
- package/src/rpc/repo-lifecycle.ts +103 -0
- package/src/rpc/resolve-ref.ts +41 -0
- package/src/rpc/sync-branch.ts +149 -0
- package/src/schemas/commit-action.ts +157 -0
- package/src/schemas/commit.ts +43 -0
- package/src/schemas/content-encoding.ts +58 -0
- package/src/schemas/examples.ts +24 -0
- package/src/schemas/gateway-config.ts +116 -0
- package/src/schemas/gateway-error-body.ts +230 -0
- package/src/schemas/identity.ts +57 -0
- package/src/schemas/names.ts +126 -0
- package/src/schemas/ref-update.ts +38 -0
- package/src/schemas/sha.ts +20 -0
- package/src/schemas/tree-entry.ts +72 -0
- package/src/storage/git-remote.ts +58 -0
- package/src/storage/storage-backend.ts +65 -0
- package/src/storage/storage-errors.ts +24 -0
- package/src/storage/storage-input.ts +14 -0
- package/src/storage/storage-read.ts +45 -0
- package/src/storage/storage-repo-info.ts +46 -0
- package/src/storage/storage-tree-entry.ts +20 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
|
|
3
|
+
/** The trailer the gateway appends to every commit made with an idempotency key. */
|
|
4
|
+
export const IDEMPOTENCY_TRAILER = 'Gateway-Idempotency-Key';
|
|
5
|
+
|
|
6
|
+
const TRAILER_LINE = new RegExp(`^${IDEMPOTENCY_TRAILER}: ([A-Za-z0-9][A-Za-z0-9._:-]{0,127})$`, 'm');
|
|
7
|
+
|
|
8
|
+
/** The message with the idempotency trailer appended as its last paragraph. */
|
|
9
|
+
export function appendIdempotencyTrailer(message: string, key: string): string {
|
|
10
|
+
return `${message.trimEnd()}\n\n${IDEMPOTENCY_TRAILER}: ${key}\n`;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** The idempotency key in a message's trailer, or null when it has none. */
|
|
14
|
+
export function readIdempotencyTrailer(message: string): string | null {
|
|
15
|
+
const lines = message.trimEnd().split('\n');
|
|
16
|
+
const last = lines.at(-1) ?? '';
|
|
17
|
+
return TRAILER_LINE.exec(last)?.[1] ?? null;
|
|
18
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
import type { TreeEntry } from '../schemas/tree-entry.ts';
|
|
3
|
+
import { byteOrder } from './bytes.ts';
|
|
4
|
+
import { parentDirectories, type FileMap } from './file-map.ts';
|
|
5
|
+
import { modelSha } from './hash.ts';
|
|
6
|
+
|
|
7
|
+
/** Every directory of a snapshot with its entries, and the root tree id. */
|
|
8
|
+
export interface TreeIndex {
|
|
9
|
+
readonly rootSha: string;
|
|
10
|
+
/** Directory path ('' for the root) → its direct entries, sorted by path in byte order. */
|
|
11
|
+
readonly directories: ReadonlyMap<string, readonly TreeEntry[]>;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const nameOf = (path: string): string => path.slice(path.lastIndexOf('/') + 1);
|
|
15
|
+
const dirOf = (path: string): string => (path.includes('/') ? path.slice(0, path.lastIndexOf('/')) : '');
|
|
16
|
+
const depth = (path: string): number => (path === '' ? 0 : path.split('/').length);
|
|
17
|
+
|
|
18
|
+
/** Builds the directory index of a snapshot, computing each tree id from its entries bottom-up. */
|
|
19
|
+
export async function buildTreeIndex(files: FileMap): Promise<TreeIndex> {
|
|
20
|
+
const children = new Map<string, Map<string, TreeEntry>>([['', new Map()]]);
|
|
21
|
+
const childMap = (dir: string): Map<string, TreeEntry> => {
|
|
22
|
+
let map = children.get(dir);
|
|
23
|
+
if (map === undefined) {
|
|
24
|
+
map = new Map();
|
|
25
|
+
children.set(dir, map);
|
|
26
|
+
}
|
|
27
|
+
return map;
|
|
28
|
+
};
|
|
29
|
+
for (const [path, file] of files) {
|
|
30
|
+
for (const dir of parentDirectories(path)) childMap(dir);
|
|
31
|
+
childMap(dirOf(path)).set(path, {
|
|
32
|
+
path,
|
|
33
|
+
name: nameOf(path),
|
|
34
|
+
type: 'blob',
|
|
35
|
+
mode: file.executable ? '100755' : '100644',
|
|
36
|
+
sha: file.sha,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
const deepestFirst = [...children.keys()].toSorted((a, b) => depth(b) - depth(a) || byteOrder(a, b));
|
|
40
|
+
const directories = new Map<string, readonly TreeEntry[]>();
|
|
41
|
+
let rootSha = '';
|
|
42
|
+
for (const dir of deepestFirst) {
|
|
43
|
+
const entries = [...(children.get(dir)?.values() ?? [])].toSorted((a, b) => byteOrder(a.path, b.path));
|
|
44
|
+
directories.set(dir, entries);
|
|
45
|
+
const sha = await modelSha('tree', entries.map((e) => `${e.mode} ${e.name} ${e.sha}`).join('\n'));
|
|
46
|
+
if (dir === '') rootSha = sha;
|
|
47
|
+
else childMap(dirOf(dir)).set(dir, { path: dir, name: nameOf(dir), type: 'tree', mode: '040000', sha });
|
|
48
|
+
}
|
|
49
|
+
return { rootSha, directories };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Every entry beneath a directory ('' for the root), sorted by full path in byte order. */
|
|
53
|
+
export function entriesBeneath(index: TreeIndex, dir: string, recursive: boolean): TreeEntry[] {
|
|
54
|
+
const direct = index.directories.get(dir) ?? [];
|
|
55
|
+
if (!recursive) return [...direct];
|
|
56
|
+
const all: TreeEntry[] = [];
|
|
57
|
+
const visit = (entries: readonly TreeEntry[]): void => {
|
|
58
|
+
for (const entry of entries) {
|
|
59
|
+
all.push(entry);
|
|
60
|
+
if (entry.type === 'tree') visit(index.directories.get(entry.path) ?? []);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
visit(direct);
|
|
64
|
+
return all.toSorted((a, b) => byteOrder(a.path, b.path));
|
|
65
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
import type { Commit } from '../schemas/commit.ts';
|
|
3
|
+
import type { Identity } from '../schemas/identity.ts';
|
|
4
|
+
import type { FileMap } from './file-map.ts';
|
|
5
|
+
import { modelSha } from './hash.ts';
|
|
6
|
+
import type { RepoState, StoredCommit } from './repo-state.ts';
|
|
7
|
+
import { readIdempotencyTrailer } from './trailer.ts';
|
|
8
|
+
import { buildTreeIndex } from './tree-index.ts';
|
|
9
|
+
|
|
10
|
+
/** What a new commit records. */
|
|
11
|
+
export interface NewCommit {
|
|
12
|
+
readonly parents: readonly string[];
|
|
13
|
+
readonly files: FileMap;
|
|
14
|
+
readonly author: Identity;
|
|
15
|
+
readonly committer: Identity;
|
|
16
|
+
readonly message: string;
|
|
17
|
+
readonly date: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Builds a commit from a snapshot, stores it in the repository and returns it. Moves no branch. */
|
|
21
|
+
export async function writeCommit(repo: RepoState, next: NewCommit): Promise<StoredCommit> {
|
|
22
|
+
const tree = await buildTreeIndex(next.files);
|
|
23
|
+
const author = { name: next.author.name, email: next.author.email, date: next.date };
|
|
24
|
+
const committer = { name: next.committer.name, email: next.committer.email, date: next.date };
|
|
25
|
+
const canonical = JSON.stringify({
|
|
26
|
+
tree: tree.rootSha,
|
|
27
|
+
parents: next.parents,
|
|
28
|
+
author,
|
|
29
|
+
committer,
|
|
30
|
+
message: next.message,
|
|
31
|
+
});
|
|
32
|
+
const commit: Commit = {
|
|
33
|
+
sha: await modelSha('commit', canonical),
|
|
34
|
+
tree: tree.rootSha,
|
|
35
|
+
parents: [...next.parents],
|
|
36
|
+
author,
|
|
37
|
+
committer,
|
|
38
|
+
message: next.message,
|
|
39
|
+
idempotencyKey: readIdempotencyTrailer(next.message),
|
|
40
|
+
};
|
|
41
|
+
const stored = { commit, files: next.files, tree };
|
|
42
|
+
repo.commits.set(commit.sha, stored);
|
|
43
|
+
return stored;
|
|
44
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
import { EXAMPLE_SHA_B } from '../schemas/examples.ts';
|
|
5
|
+
import { BranchName, RepoName } from '../schemas/names.ts';
|
|
6
|
+
import { Sha } from '../schemas/sha.ts';
|
|
7
|
+
|
|
8
|
+
/** Input of `commitExists`. */
|
|
9
|
+
export const CommitExistsInput = z
|
|
10
|
+
.object({
|
|
11
|
+
repo: RepoName.describe('Repository to look in.'),
|
|
12
|
+
sha: Sha.describe('Commit id to look for.'),
|
|
13
|
+
branch: BranchName.optional().describe(
|
|
14
|
+
"When given, the commit must also be reachable from this branch's head (the head itself or an ancestor). Absent: any commit in the repository counts.",
|
|
15
|
+
),
|
|
16
|
+
})
|
|
17
|
+
.strict()
|
|
18
|
+
.meta({
|
|
19
|
+
id: 'CommitExistsInput',
|
|
20
|
+
title: 'commitExists input',
|
|
21
|
+
description: 'Input of commitExists(): is this commit in the repository, optionally on a branch?',
|
|
22
|
+
examples: [{ repo: 'acme-raw-content', sha: EXAMPLE_SHA_B, branch: 'main' }],
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
/** Input of `commitExists`, inferred from {@link CommitExistsInput}. */
|
|
26
|
+
export type CommitExistsInput = z.input<typeof CommitExistsInput>;
|
|
27
|
+
|
|
28
|
+
/** Output of `commitExists`. */
|
|
29
|
+
export const CommitExistsOutput = z
|
|
30
|
+
.object({
|
|
31
|
+
exists: z
|
|
32
|
+
.boolean()
|
|
33
|
+
.describe(
|
|
34
|
+
'true when the commit exists (and is reachable from `branch` when one was named); false otherwise, including when the branch does not exist.',
|
|
35
|
+
),
|
|
36
|
+
})
|
|
37
|
+
.strict()
|
|
38
|
+
.meta({
|
|
39
|
+
id: 'CommitExistsOutput',
|
|
40
|
+
title: 'commitExists output',
|
|
41
|
+
description: 'Output of commitExists().',
|
|
42
|
+
examples: [{ exists: true }],
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
/** Output of `commitExists`, inferred from {@link CommitExistsOutput}. */
|
|
46
|
+
export type CommitExistsOutput = z.infer<typeof CommitExistsOutput>;
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
import { Commit } from '../schemas/commit.ts';
|
|
5
|
+
import { CommitAction } from '../schemas/commit-action.ts';
|
|
6
|
+
import {
|
|
7
|
+
EXAMPLE_COMMIT as COMMIT_EXAMPLE,
|
|
8
|
+
EXAMPLE_IDENTITY as ADA,
|
|
9
|
+
EXAMPLE_SHA_A as SHA_A,
|
|
10
|
+
EXAMPLE_SHA_B as SHA_B,
|
|
11
|
+
} from '../schemas/examples.ts';
|
|
12
|
+
import { Identity } from '../schemas/identity.ts';
|
|
13
|
+
import { BranchName, IdempotencyKey, RepoName } from '../schemas/names.ts';
|
|
14
|
+
import { RefUpdate } from '../schemas/ref-update.ts';
|
|
15
|
+
import { Sha } from '../schemas/sha.ts';
|
|
16
|
+
|
|
17
|
+
/** Input of `commit`. */
|
|
18
|
+
export const CommitInput = z
|
|
19
|
+
.object({
|
|
20
|
+
repo: RepoName.describe('Repository to commit to.'),
|
|
21
|
+
branch: BranchName.describe(
|
|
22
|
+
'Branch to commit to. If it does not exist it is created: from `startBranch` when given, or as a root commit when the repository has no branches at all; otherwise the call fails with ref_not_found.',
|
|
23
|
+
),
|
|
24
|
+
startBranch: BranchName.optional().describe(
|
|
25
|
+
'Branch to start `branch` from when `branch` does not exist yet; ignored when it does. Absent: no start branch.',
|
|
26
|
+
),
|
|
27
|
+
expectedHead: Sha.nullable()
|
|
28
|
+
.optional()
|
|
29
|
+
.describe(
|
|
30
|
+
'Head the caller based its change on. When given and the branch head differs, the call fails with stale_head; null expects the branch not to exist yet. Absent: commit onto whatever the head is.',
|
|
31
|
+
),
|
|
32
|
+
message: z
|
|
33
|
+
.string()
|
|
34
|
+
.min(1)
|
|
35
|
+
.max(65_536)
|
|
36
|
+
.refine((text) => text.trim().length > 0, { message: 'message must not be blank' })
|
|
37
|
+
.describe(
|
|
38
|
+
'Commit message, 1–65536 characters and not blank. The gateway appends the idempotency trailer.',
|
|
39
|
+
),
|
|
40
|
+
author: Identity.describe('Who wrote the change.'),
|
|
41
|
+
committer: Identity.optional().describe('Who records the commit. Absent: the author.'),
|
|
42
|
+
actions: z
|
|
43
|
+
.array(CommitAction)
|
|
44
|
+
.min(1)
|
|
45
|
+
.max(1000)
|
|
46
|
+
.describe('Changes to apply, in order, each to the result of the previous; 1–1000 actions.'),
|
|
47
|
+
idempotencyKey: IdempotencyKey.describe(
|
|
48
|
+
'Makes the call safe to retry: if a commit with this key is in the branch\'s recent history, it is returned (status "replayed") and nothing is written.',
|
|
49
|
+
),
|
|
50
|
+
})
|
|
51
|
+
.strict()
|
|
52
|
+
.meta({
|
|
53
|
+
id: 'CommitInput',
|
|
54
|
+
title: 'commit input',
|
|
55
|
+
description:
|
|
56
|
+
'Input of commit(): a multi-file commit to one branch, built without a clone. Checked in this order: idempotency replay, then stale head, then the actions.',
|
|
57
|
+
examples: [
|
|
58
|
+
{
|
|
59
|
+
repo: 'acme-raw-content',
|
|
60
|
+
branch: 'staging',
|
|
61
|
+
expectedHead: SHA_A,
|
|
62
|
+
message: 'Update about page',
|
|
63
|
+
author: ADA,
|
|
64
|
+
actions: [{ action: 'update', path: 'content/about.md', content: '# About us\n', encoding: 'text' }],
|
|
65
|
+
idempotencyKey: 'cms:publish:2f9c1e',
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
/** Input of `commit` as accepted (defaults optional). */
|
|
71
|
+
export type CommitInput = z.input<typeof CommitInput>;
|
|
72
|
+
|
|
73
|
+
/** A new commit was written. */
|
|
74
|
+
export const CommitCommitted = z
|
|
75
|
+
.object({
|
|
76
|
+
status: z.literal('committed').describe('A new commit was written and the branch moved to it.'),
|
|
77
|
+
commit: Commit.describe('The commit written.'),
|
|
78
|
+
refUpdate: RefUpdate.describe('How the branch moved; oldSha is all zeros when the commit created it.'),
|
|
79
|
+
})
|
|
80
|
+
.strict()
|
|
81
|
+
.meta({
|
|
82
|
+
id: 'CommitCommitted',
|
|
83
|
+
title: 'commit: committed',
|
|
84
|
+
description: 'commit() wrote a new commit and moved the branch to it.',
|
|
85
|
+
examples: [
|
|
86
|
+
{
|
|
87
|
+
status: 'committed',
|
|
88
|
+
commit: COMMIT_EXAMPLE,
|
|
89
|
+
refUpdate: { ref: 'refs/heads/staging', oldSha: SHA_A, newSha: SHA_B },
|
|
90
|
+
},
|
|
91
|
+
],
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
/** The key was found in recent history; that commit is returned. */
|
|
95
|
+
export const CommitReplayed = z
|
|
96
|
+
.object({
|
|
97
|
+
status: z
|
|
98
|
+
.literal('replayed')
|
|
99
|
+
.describe('A commit with the same idempotency key already exists; nothing was written.'),
|
|
100
|
+
commit: Commit.describe('The earlier commit carrying the same idempotency key.'),
|
|
101
|
+
})
|
|
102
|
+
.strict()
|
|
103
|
+
.meta({
|
|
104
|
+
id: 'CommitReplayed',
|
|
105
|
+
title: 'commit: replayed',
|
|
106
|
+
description:
|
|
107
|
+
"commit() found a commit with the same idempotency key in the branch's recent history and returned it without writing.",
|
|
108
|
+
examples: [{ status: 'replayed', commit: COMMIT_EXAMPLE }],
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
/** The actions changed nothing. */
|
|
112
|
+
export const CommitNoop = z
|
|
113
|
+
.object({
|
|
114
|
+
status: z.literal('noop').describe('The actions left the tree unchanged; nothing was written or pushed.'),
|
|
115
|
+
head: Sha.nullable().describe('The branch head, unchanged; null when the branch does not exist.'),
|
|
116
|
+
})
|
|
117
|
+
.strict()
|
|
118
|
+
.meta({
|
|
119
|
+
id: 'CommitNoop',
|
|
120
|
+
title: 'commit: no-op',
|
|
121
|
+
description:
|
|
122
|
+
"commit() applied the actions and the resulting tree equals the head's, so nothing was written.",
|
|
123
|
+
examples: [{ status: 'noop', head: SHA_A }],
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
/** Inline retries ran out; a Workflow finishes the commit. */
|
|
127
|
+
export const CommitQueued = z
|
|
128
|
+
.object({
|
|
129
|
+
status: z.literal('queued').describe('Inline retries ran out; a CommitWorkflow finishes the commit.'),
|
|
130
|
+
workflowInstanceId: z
|
|
131
|
+
.string()
|
|
132
|
+
.min(1)
|
|
133
|
+
.max(100)
|
|
134
|
+
.describe('Id of the CommitWorkflow instance carrying the same idempotency key.'),
|
|
135
|
+
})
|
|
136
|
+
.strict()
|
|
137
|
+
.meta({
|
|
138
|
+
id: 'CommitQueued',
|
|
139
|
+
title: 'commit: queued',
|
|
140
|
+
description:
|
|
141
|
+
'commit() hit stale-head refusals more times than the inline retry budget and handed the commit to a CommitWorkflow with the same idempotency key. The in-memory reference never returns this.',
|
|
142
|
+
examples: [{ status: 'queued', workflowInstanceId: 'commit-cms-publish-2f9c1e' }],
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
/** Output of `commit`, discriminated by `status`. */
|
|
146
|
+
export const CommitOutput = z
|
|
147
|
+
.discriminatedUnion('status', [CommitCommitted, CommitReplayed, CommitNoop, CommitQueued])
|
|
148
|
+
.meta({
|
|
149
|
+
id: 'CommitOutput',
|
|
150
|
+
title: 'commit output',
|
|
151
|
+
description: 'Output of commit(), discriminated by `status`.',
|
|
152
|
+
examples: [{ status: 'noop', head: SHA_A }],
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
/** Output of `commit`, inferred from {@link CommitOutput}. */
|
|
156
|
+
export type CommitOutput = z.infer<typeof CommitOutput>;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
import { EXAMPLE_SHA_B } from '../schemas/examples.ts';
|
|
5
|
+
import { FilePath, RepoName, Revision } from '../schemas/names.ts';
|
|
6
|
+
import { Sha } from '../schemas/sha.ts';
|
|
7
|
+
import { TreeEntry } from '../schemas/tree-entry.ts';
|
|
8
|
+
|
|
9
|
+
/** Input of `listTree`. */
|
|
10
|
+
export const ListTreeInput = z
|
|
11
|
+
.object({
|
|
12
|
+
repo: RepoName.describe('Repository to read from.'),
|
|
13
|
+
ref: Revision.describe('Branch name or commit id to list at.'),
|
|
14
|
+
path: FilePath.optional().describe('Directory to list. Absent: the repository root.'),
|
|
15
|
+
recursive: z
|
|
16
|
+
.boolean()
|
|
17
|
+
.default(false)
|
|
18
|
+
.describe(
|
|
19
|
+
'true lists every entry beneath the directory (directories included); false (default) one level.',
|
|
20
|
+
),
|
|
21
|
+
})
|
|
22
|
+
.strict()
|
|
23
|
+
.meta({
|
|
24
|
+
id: 'ListTreeInput',
|
|
25
|
+
title: 'listTree input',
|
|
26
|
+
description:
|
|
27
|
+
'Input of listTree(): a directory listing at a branch or commit. Fails with ref_not_found if the ref is missing.',
|
|
28
|
+
examples: [{ repo: 'acme-raw-content', ref: 'main', path: 'content', recursive: false }],
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
/** Input of `listTree` as accepted (defaults optional). */
|
|
32
|
+
export type ListTreeInput = z.input<typeof ListTreeInput>;
|
|
33
|
+
|
|
34
|
+
/** A directory listing. */
|
|
35
|
+
export const TreeListing = z
|
|
36
|
+
.object({
|
|
37
|
+
commit: Sha.describe('Id of the commit listed (the ref resolved).'),
|
|
38
|
+
path: FilePath.nullable().describe('The directory listed; null for the repository root.'),
|
|
39
|
+
entries: z
|
|
40
|
+
.array(TreeEntry)
|
|
41
|
+
.describe('Entries sorted by full path in byte order; empty for a repository root with no files.'),
|
|
42
|
+
})
|
|
43
|
+
.strict()
|
|
44
|
+
.meta({
|
|
45
|
+
id: 'TreeListing',
|
|
46
|
+
title: 'Tree listing',
|
|
47
|
+
description: 'A directory listing at a commit.',
|
|
48
|
+
examples: [
|
|
49
|
+
{
|
|
50
|
+
commit: EXAMPLE_SHA_B,
|
|
51
|
+
path: 'content',
|
|
52
|
+
entries: [
|
|
53
|
+
{
|
|
54
|
+
path: 'content/about.md',
|
|
55
|
+
name: 'about.md',
|
|
56
|
+
type: 'blob',
|
|
57
|
+
mode: '100644',
|
|
58
|
+
sha: 'f2a5b0a7d1d3d1f1c1c3e7e5d2b9b7e1a3c5d7e9',
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
/** A directory listing, inferred from {@link TreeListing}. */
|
|
66
|
+
export type TreeListing = z.infer<typeof TreeListing>;
|
|
67
|
+
|
|
68
|
+
/** Output of `listTree`: the listing, or null when the path is not a directory. */
|
|
69
|
+
export const ListTreeOutput = TreeListing.nullable().meta({
|
|
70
|
+
id: 'ListTreeOutput',
|
|
71
|
+
title: 'listTree output',
|
|
72
|
+
description:
|
|
73
|
+
'Output of listTree(): the listing, or null when the path is not a directory at that ref (absent or a file).',
|
|
74
|
+
examples: [null],
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
/** Output of `listTree`, inferred from {@link ListTreeOutput}. */
|
|
78
|
+
export type ListTreeOutput = z.infer<typeof ListTreeOutput>;
|
package/src/rpc/log.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
import { Commit } from '../schemas/commit.ts';
|
|
5
|
+
import { EXAMPLE_COMMIT } from '../schemas/examples.ts';
|
|
6
|
+
import { Timestamp } from '../schemas/identity.ts';
|
|
7
|
+
import { RepoName, Revision } from '../schemas/names.ts';
|
|
8
|
+
|
|
9
|
+
/** Input of `log`. */
|
|
10
|
+
export const LogInput = z
|
|
11
|
+
.object({
|
|
12
|
+
repo: RepoName.describe('Repository to read from.'),
|
|
13
|
+
ref: Revision.describe('Branch name or commit id whose history is listed, starting at that commit.'),
|
|
14
|
+
limit: z.int().min(1).max(500).default(50).describe('Most commits returned; 1–500, default 50.'),
|
|
15
|
+
offset: z.int().min(0).default(0).describe('Commits skipped from the newest before listing; default 0.'),
|
|
16
|
+
since: Timestamp.optional().describe(
|
|
17
|
+
'When given, only commits whose committer date is at or after this time are listed. Absent: no lower bound.',
|
|
18
|
+
),
|
|
19
|
+
})
|
|
20
|
+
.strict()
|
|
21
|
+
.meta({
|
|
22
|
+
id: 'LogInput',
|
|
23
|
+
title: 'log input',
|
|
24
|
+
description:
|
|
25
|
+
'Input of log(): the history reachable from a branch or commit, newest committer date first (children always before their parents). Fails with ref_not_found if the ref is missing.',
|
|
26
|
+
examples: [
|
|
27
|
+
{ repo: 'acme-raw-content', ref: 'main', limit: 20, offset: 0, since: '2026-11-01T00:00:00.000Z' },
|
|
28
|
+
],
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
/** Input of `log` as accepted (defaults optional). */
|
|
32
|
+
export type LogInput = z.input<typeof LogInput>;
|
|
33
|
+
|
|
34
|
+
/** Output of `log`. */
|
|
35
|
+
export const LogOutput = z
|
|
36
|
+
.object({
|
|
37
|
+
commits: z
|
|
38
|
+
.array(Commit)
|
|
39
|
+
.describe('The page of history, newest committer date first; empty when nothing matches.'),
|
|
40
|
+
hasMore: z.boolean().describe('true when further matching commits exist beyond this page.'),
|
|
41
|
+
})
|
|
42
|
+
.strict()
|
|
43
|
+
.meta({
|
|
44
|
+
id: 'LogOutput',
|
|
45
|
+
title: 'log output',
|
|
46
|
+
description: 'Output of log(): one page of history.',
|
|
47
|
+
examples: [{ commits: [EXAMPLE_COMMIT], hasMore: false }],
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
/** Output of `log`, inferred from {@link LogOutput}. */
|
|
51
|
+
export type LogOutput = z.infer<typeof LogOutput>;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
import { EXAMPLE_TIMESTAMP } from '../schemas/examples.ts';
|
|
5
|
+
import { Timestamp } from '../schemas/identity.ts';
|
|
6
|
+
import { RepoName } from '../schemas/names.ts';
|
|
7
|
+
|
|
8
|
+
/** Input of `mintReadToken`. */
|
|
9
|
+
export const MintReadTokenInput = z
|
|
10
|
+
.object({
|
|
11
|
+
repo: RepoName.describe('Repository the token may read.'),
|
|
12
|
+
ttlSeconds: z
|
|
13
|
+
.int()
|
|
14
|
+
.min(60)
|
|
15
|
+
.max(86_400)
|
|
16
|
+
.default(3600)
|
|
17
|
+
.describe('Lifetime of the token in seconds; 60–86400, default 3600.'),
|
|
18
|
+
})
|
|
19
|
+
.strict()
|
|
20
|
+
.meta({
|
|
21
|
+
id: 'MintReadTokenInput',
|
|
22
|
+
title: 'mintReadToken input',
|
|
23
|
+
description:
|
|
24
|
+
'Input of mintReadToken(): a short-lived credential that can clone and fetch one repository through the gateway and nothing else. Fails with repo_not_found.',
|
|
25
|
+
examples: [{ repo: 'acme-raw-content', ttlSeconds: 900 }],
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
/** Input of `mintReadToken` as accepted (defaults optional). */
|
|
29
|
+
export type MintReadTokenInput = z.input<typeof MintReadTokenInput>;
|
|
30
|
+
|
|
31
|
+
/** Output of `mintReadToken`. */
|
|
32
|
+
export const MintReadTokenOutput = z
|
|
33
|
+
.object({
|
|
34
|
+
token: z
|
|
35
|
+
.string()
|
|
36
|
+
.min(16)
|
|
37
|
+
.max(4096)
|
|
38
|
+
.describe(
|
|
39
|
+
'The credential: send it as the HTTP Basic password (any username) or as a Bearer token. Secret.',
|
|
40
|
+
),
|
|
41
|
+
expiresAt: Timestamp.describe('When the token stops working.'),
|
|
42
|
+
remoteUrl: z.url().describe('Clone URL the token is good for: <publicBaseUrl>/<repo>.git.'),
|
|
43
|
+
})
|
|
44
|
+
.strict()
|
|
45
|
+
.meta({
|
|
46
|
+
id: 'MintReadTokenOutput',
|
|
47
|
+
title: 'mintReadToken output',
|
|
48
|
+
description: 'Output of mintReadToken(): a read-only credential for one repository and where to use it.',
|
|
49
|
+
examples: [
|
|
50
|
+
{
|
|
51
|
+
token: 'ggr_0123456789abcdef0123456789abcdef',
|
|
52
|
+
expiresAt: EXAMPLE_TIMESTAMP,
|
|
53
|
+
remoteUrl: 'https://git.example.com/acme-raw-content.git',
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
/** Output of `mintReadToken`, inferred from {@link MintReadTokenOutput}. */
|
|
59
|
+
export type MintReadTokenOutput = z.infer<typeof MintReadTokenOutput>;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
import { EXAMPLE_SHA_A, EXAMPLE_SHA_B } from '../schemas/examples.ts';
|
|
5
|
+
import { BranchName, RepoName } from '../schemas/names.ts';
|
|
6
|
+
import { RefUpdate } from '../schemas/ref-update.ts';
|
|
7
|
+
import { Sha } from '../schemas/sha.ts';
|
|
8
|
+
|
|
9
|
+
/** Input of `promote`. */
|
|
10
|
+
export const PromoteInput = z
|
|
11
|
+
.object({
|
|
12
|
+
repo: RepoName.describe('Repository holding both branches.'),
|
|
13
|
+
from: BranchName.describe('Branch whose head is promoted, e.g. staging.'),
|
|
14
|
+
into: BranchName.describe('Branch fast-forwarded, e.g. main. Created at `sha` if it does not exist.'),
|
|
15
|
+
sha: Sha.describe('The commit to promote; must be the current head of `from`.'),
|
|
16
|
+
})
|
|
17
|
+
.strict()
|
|
18
|
+
.refine((input) => input.from !== input.into, { message: 'from and into must differ', path: ['into'] })
|
|
19
|
+
.meta({
|
|
20
|
+
id: 'PromoteInput',
|
|
21
|
+
title: 'promote input',
|
|
22
|
+
description:
|
|
23
|
+
'Input of promote(): fast-forward `into` to `sha`, only if `sha` is the head of `from` and contains the head of `into`. Never merges, never forces. Refusals: ref_not_found (from missing), not_head_of_source, not_fast_forward.',
|
|
24
|
+
examples: [{ repo: 'acme-raw-content', from: 'staging', into: 'main', sha: EXAMPLE_SHA_B }],
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
/** Input of `promote`, inferred from {@link PromoteInput}. */
|
|
28
|
+
export type PromoteInput = z.input<typeof PromoteInput>;
|
|
29
|
+
|
|
30
|
+
/** `into` was fast-forwarded (or created) at `sha`. */
|
|
31
|
+
export const PromotePromoted = z
|
|
32
|
+
.object({
|
|
33
|
+
status: z.literal('promoted').describe('`into` now points at `sha`.'),
|
|
34
|
+
refUpdate: RefUpdate.describe('How `into` moved; oldSha is all zeros when promote created it.'),
|
|
35
|
+
})
|
|
36
|
+
.strict()
|
|
37
|
+
.meta({
|
|
38
|
+
id: 'PromotePromoted',
|
|
39
|
+
title: 'promote: promoted',
|
|
40
|
+
description: 'promote() fast-forwarded `into` to `sha`, or created it there.',
|
|
41
|
+
examples: [
|
|
42
|
+
{
|
|
43
|
+
status: 'promoted',
|
|
44
|
+
refUpdate: { ref: 'refs/heads/main', oldSha: EXAMPLE_SHA_A, newSha: EXAMPLE_SHA_B },
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
/** `into` already pointed at `sha`. */
|
|
50
|
+
export const PromoteUpToDate = z
|
|
51
|
+
.object({
|
|
52
|
+
status: z.literal('up_to_date').describe('`into` already points at `sha`; nothing changed.'),
|
|
53
|
+
head: Sha.describe('The head of `into`, equal to `sha`.'),
|
|
54
|
+
})
|
|
55
|
+
.strict()
|
|
56
|
+
.meta({
|
|
57
|
+
id: 'PromoteUpToDate',
|
|
58
|
+
title: 'promote: up to date',
|
|
59
|
+
description: 'promote() found `into` already at `sha`.',
|
|
60
|
+
examples: [{ status: 'up_to_date', head: EXAMPLE_SHA_B }],
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
/** Output of `promote`, discriminated by `status`. */
|
|
64
|
+
export const PromoteOutput = z.discriminatedUnion('status', [PromotePromoted, PromoteUpToDate]).meta({
|
|
65
|
+
id: 'PromoteOutput',
|
|
66
|
+
title: 'promote output',
|
|
67
|
+
description: 'Output of promote(), discriminated by `status`. Refusals are thrown as GatewayErrors.',
|
|
68
|
+
examples: [{ status: 'up_to_date', head: EXAMPLE_SHA_B }],
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
/** Output of `promote`, inferred from {@link PromoteOutput}. */
|
|
72
|
+
export type PromoteOutput = z.infer<typeof PromoteOutput>;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
import { ContentEncoding, ReadContent } from '../schemas/content-encoding.ts';
|
|
5
|
+
import { EXAMPLE_SHA_B } from '../schemas/examples.ts';
|
|
6
|
+
import { FilePath, RepoName, Revision } from '../schemas/names.ts';
|
|
7
|
+
import { Sha } from '../schemas/sha.ts';
|
|
8
|
+
|
|
9
|
+
/** Input of `readFile`. */
|
|
10
|
+
export const ReadFileInput = z
|
|
11
|
+
.object({
|
|
12
|
+
repo: RepoName.describe('Repository to read from.'),
|
|
13
|
+
ref: Revision.describe('Branch name or commit id to read the file at.'),
|
|
14
|
+
path: FilePath.describe('Path of the file to read.'),
|
|
15
|
+
encoding: ContentEncoding.default('text').describe(
|
|
16
|
+
'Preferred encoding of the returned content. "text" (default) returns text when the bytes are valid UTF-8 and falls back to base64 otherwise; "base64" always returns base64.',
|
|
17
|
+
),
|
|
18
|
+
})
|
|
19
|
+
.strict()
|
|
20
|
+
.meta({
|
|
21
|
+
id: 'ReadFileInput',
|
|
22
|
+
title: 'readFile input',
|
|
23
|
+
description:
|
|
24
|
+
'Input of readFile(): one file at a branch or commit. Fails with ref_not_found if the ref is missing.',
|
|
25
|
+
examples: [{ repo: 'acme-raw-content', ref: 'main', path: 'content/about.md', encoding: 'text' }],
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
/** Input of `readFile` as accepted (defaults optional). */
|
|
29
|
+
export type ReadFileInput = z.input<typeof ReadFileInput>;
|
|
30
|
+
|
|
31
|
+
/** A file read from a repository. */
|
|
32
|
+
export const FileRead = z
|
|
33
|
+
.object({
|
|
34
|
+
path: FilePath.describe('Path of the file read.'),
|
|
35
|
+
commit: Sha.describe('Id of the commit the file was read at (the ref resolved).'),
|
|
36
|
+
sha: Sha.describe("Id of the file's blob. Equal content always has an equal id."),
|
|
37
|
+
size: z.int().min(0).describe('Size of the file in bytes.'),
|
|
38
|
+
executable: z.boolean().describe('true when the file mode is 100755.'),
|
|
39
|
+
encoding: ContentEncoding.describe(
|
|
40
|
+
'How `content` is encoded; may be base64 even when text was requested.',
|
|
41
|
+
),
|
|
42
|
+
content: ReadContent.describe("The file's content, encoded as `encoding` says."),
|
|
43
|
+
})
|
|
44
|
+
.strict()
|
|
45
|
+
.meta({
|
|
46
|
+
id: 'FileRead',
|
|
47
|
+
title: 'File read',
|
|
48
|
+
description: 'A file read from a repository at a commit, with its blob id, size and mode.',
|
|
49
|
+
examples: [
|
|
50
|
+
{
|
|
51
|
+
path: 'content/about.md',
|
|
52
|
+
commit: EXAMPLE_SHA_B,
|
|
53
|
+
sha: 'f2a5b0a7d1d3d1f1c1c3e7e5d2b9b7e1a3c5d7e9',
|
|
54
|
+
size: 11,
|
|
55
|
+
executable: false,
|
|
56
|
+
encoding: 'text',
|
|
57
|
+
content: '# About us\n',
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
/** A file read, inferred from {@link FileRead}. */
|
|
63
|
+
export type FileRead = z.infer<typeof FileRead>;
|
|
64
|
+
|
|
65
|
+
/** Output of `readFile`: the file, or null when no file is at the path. */
|
|
66
|
+
export const ReadFileOutput = FileRead.nullable().meta({
|
|
67
|
+
id: 'ReadFileOutput',
|
|
68
|
+
title: 'readFile output',
|
|
69
|
+
description:
|
|
70
|
+
'Output of readFile(): the file, or null when the path is not a file at that ref (absent or a directory).',
|
|
71
|
+
examples: [null],
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
/** Output of `readFile`, inferred from {@link ReadFileOutput}. */
|
|
75
|
+
export type ReadFileOutput = z.infer<typeof ReadFileOutput>;
|