@leed-ai/git-gateway-backend-artifacts 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 +29 -2
- package/dist/artifacts-backend.d.ts +45 -0
- package/dist/artifacts-backend.js +198 -0
- package/dist/artifacts-backend.js.map +1 -0
- package/dist/artifacts-binding.d.ts +38 -0
- package/dist/artifacts-binding.js +9 -0
- package/dist/artifacts-binding.js.map +1 -0
- package/dist/artifacts-errors.d.ts +29 -0
- package/dist/artifacts-errors.js +65 -0
- package/dist/artifacts-errors.js.map +1 -0
- package/dist/artifacts-git-reads.d.ts +24 -0
- package/dist/artifacts-git-reads.js +67 -0
- package/dist/artifacts-git-reads.js.map +1 -0
- package/dist/artifacts-mapping.d.ts +15 -0
- package/dist/artifacts-mapping.js +67 -0
- package/dist/artifacts-mapping.js.map +1 -0
- package/dist/artifacts-rest.d.ts +35 -0
- package/dist/artifacts-rest.js +91 -0
- package/dist/artifacts-rest.js.map +1 -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/schemas/artifacts-binding-results.d.ts +80 -0
- package/dist/schemas/artifacts-binding-results.js +160 -0
- package/dist/schemas/artifacts-binding-results.js.map +1 -0
- package/dist/schemas/artifacts-rest-results.d.ts +38 -0
- package/dist/schemas/artifacts-rest-results.js +66 -0
- package/dist/schemas/artifacts-rest-results.js.map +1 -0
- package/package.json +111 -4
- package/src/artifacts-backend.ts +256 -0
- package/src/artifacts-binding.ts +36 -0
- package/src/artifacts-errors.ts +85 -0
- package/src/artifacts-git-reads.ts +76 -0
- package/src/artifacts-mapping.ts +57 -0
- package/src/artifacts-rest.ts +112 -0
- package/src/package-name.ts +4 -0
- package/src/schemas/artifacts-binding-results.ts +205 -0
- package/src/schemas/artifacts-rest-results.ts +100 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { ArtifactsBindingError } from "./schemas/artifacts-binding-results.js";
|
|
2
|
+
import { isGatewayError } from "@leed-ai/git-gateway-contract/gateway-error";
|
|
3
|
+
import { repoExists, repoNotFound, storageUnavailable } from "@leed-ai/git-gateway-contract/storage/storage-errors";
|
|
4
|
+
// src/artifacts-errors.ts
|
|
5
|
+
/** The Artifacts error code of something thrown, or null when it is not an Artifacts error. */
|
|
6
|
+
function artifactsErrorCode(thrown) {
|
|
7
|
+
if (typeof thrown !== "object" || thrown === null) return null;
|
|
8
|
+
const parsed = ArtifactsBindingError.safeParse({
|
|
9
|
+
code: Reflect.get(thrown, "code"),
|
|
10
|
+
message: Reflect.get(thrown, "message")
|
|
11
|
+
});
|
|
12
|
+
return parsed.success ? parsed.data.code : null;
|
|
13
|
+
}
|
|
14
|
+
/** The REST API's numeric code for "already exists", which the binding's ArtifactsError carries. */
|
|
15
|
+
const ALREADY_EXISTS_NUMERIC = 10201;
|
|
16
|
+
const escapeRegExp = (text) => text.replaceAll(/[.*+?^${}()|[\]\\]/g, String.raw`\$&`);
|
|
17
|
+
/**
|
|
18
|
+
* Whether a failure of `create(repo)` says the repository already exists. The binding documents
|
|
19
|
+
* code ALREADY_EXISTS (numeric 10201), and the local simulator sends it; the live binding was seen
|
|
20
|
+
* to throw an error whose code did not survive, with only the message "repo already exists:
|
|
21
|
+
* <name>". So the code, then the numeric code, then exactly that message naming this repository
|
|
22
|
+
* (optionally after an "ArtifactsError: " prefix) are accepted.
|
|
23
|
+
*/
|
|
24
|
+
function isAlreadyExists(thrown, repo) {
|
|
25
|
+
if (artifactsErrorCode(thrown) === "ALREADY_EXISTS") return true;
|
|
26
|
+
if (typeof thrown !== "object" || thrown === null) return false;
|
|
27
|
+
if (Reflect.get(thrown, "numericCode") === ALREADY_EXISTS_NUMERIC) return true;
|
|
28
|
+
const message = Reflect.get(thrown, "message");
|
|
29
|
+
return typeof message === "string" && new RegExp(String.raw`^(?:ArtifactsError: )?repo already exists: ${escapeRegExp(repo)}$`, "i").test(message.trim());
|
|
30
|
+
}
|
|
31
|
+
/** The REST API's numeric code for "not found", which the binding's ArtifactsError carries. */
|
|
32
|
+
const NOT_FOUND_NUMERIC = 10200;
|
|
33
|
+
/**
|
|
34
|
+
* Whether a failure of a binding call on `repo` says the repository does not exist. The binding
|
|
35
|
+
* documents code NOT_FOUND (numeric 10200), and the local simulator sends it; the live binding was
|
|
36
|
+
* seen to throw an error whose code did not survive, with only the message "Repository not found:
|
|
37
|
+
* <name>." So the code, then the numeric code, then exactly that message naming this repository
|
|
38
|
+
* (optionally after an "ArtifactsError: " prefix, with or without the closing period) are
|
|
39
|
+
* accepted.
|
|
40
|
+
*/
|
|
41
|
+
function isRepoNotFound(thrown, repo) {
|
|
42
|
+
if (artifactsErrorCode(thrown) === "NOT_FOUND") return true;
|
|
43
|
+
if (typeof thrown !== "object" || thrown === null) return false;
|
|
44
|
+
if (Reflect.get(thrown, "numericCode") === NOT_FOUND_NUMERIC) return true;
|
|
45
|
+
const message = Reflect.get(thrown, "message");
|
|
46
|
+
return typeof message === "string" && new RegExp(String.raw`^(?:ArtifactsError: )?repository not found: ${escapeRegExp(repo)}\.?$`, "i").test(message.trim());
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Translates a failure of a binding call on repository `repo` into a GatewayError: NOT_FOUND is
|
|
50
|
+
* repo_not_found (also when only the numeric code or the message says so, see
|
|
51
|
+
* {@link isRepoNotFound}), ALREADY_EXISTS is repo_exists (for createRepo also when only the numeric code or
|
|
52
|
+
* the message says so, see {@link isAlreadyExists}), everything else (in-progress states,
|
|
53
|
+
* MEMORY_LIMIT, INTERNAL_ERROR, unparsable results) is storage_unavailable. GatewayErrors pass
|
|
54
|
+
* through unchanged.
|
|
55
|
+
*/
|
|
56
|
+
function toGatewayError(repo, what, thrown) {
|
|
57
|
+
if (isGatewayError(thrown) && thrown instanceof Error) return thrown;
|
|
58
|
+
const code = artifactsErrorCode(thrown);
|
|
59
|
+
if (isRepoNotFound(thrown, repo)) return repoNotFound(repo);
|
|
60
|
+
if (code === "ALREADY_EXISTS" || what === "createRepo" && isAlreadyExists(thrown, repo)) return repoExists(repo);
|
|
61
|
+
return storageUnavailable(`Artifacts ${what}`, thrown);
|
|
62
|
+
}
|
|
63
|
+
export { artifactsErrorCode, isAlreadyExists, isRepoNotFound, toGatewayError };
|
|
64
|
+
|
|
65
|
+
//# sourceMappingURL=artifacts-errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"artifacts-errors.js","names":[],"sources":["../src/artifacts-errors.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport { isGatewayError } from '@leed-ai/git-gateway-contract/gateway-error';\nimport {\n repoExists,\n repoNotFound,\n storageUnavailable,\n} from '@leed-ai/git-gateway-contract/storage/storage-errors';\n\nimport { ArtifactsBindingError } from './schemas/artifacts-binding-results.ts';\n\n/** The Artifacts error code of something thrown, or null when it is not an Artifacts error. */\nexport function artifactsErrorCode(thrown: unknown): string | null {\n if (typeof thrown !== 'object' || thrown === null) return null;\n const parsed = ArtifactsBindingError.safeParse({\n code: Reflect.get(thrown, 'code'),\n message: Reflect.get(thrown, 'message'),\n });\n return parsed.success ? parsed.data.code : null;\n}\n\n/** The REST API's numeric code for \"already exists\", which the binding's ArtifactsError carries. */\nconst ALREADY_EXISTS_NUMERIC = 10201;\n\nconst escapeRegExp = (text: string): string => text.replaceAll(/[.*+?^${}()|[\\]\\\\]/g, String.raw`\\$&`);\n\n/**\n * Whether a failure of `create(repo)` says the repository already exists. The binding documents\n * code ALREADY_EXISTS (numeric 10201), and the local simulator sends it; the live binding was seen\n * to throw an error whose code did not survive, with only the message \"repo already exists:\n * <name>\". So the code, then the numeric code, then exactly that message naming this repository\n * (optionally after an \"ArtifactsError: \" prefix) are accepted.\n */\nexport function isAlreadyExists(thrown: unknown, repo: string): boolean {\n if (artifactsErrorCode(thrown) === 'ALREADY_EXISTS') return true;\n if (typeof thrown !== 'object' || thrown === null) return false;\n if (Reflect.get(thrown, 'numericCode') === ALREADY_EXISTS_NUMERIC) return true;\n const message: unknown = Reflect.get(thrown, 'message');\n return (\n typeof message === 'string' &&\n new RegExp(String.raw`^(?:ArtifactsError: )?repo already exists: ${escapeRegExp(repo)}$`, 'i').test(\n message.trim(),\n )\n );\n}\n\n/** The REST API's numeric code for \"not found\", which the binding's ArtifactsError carries. */\nconst NOT_FOUND_NUMERIC = 10200;\n\n/**\n * Whether a failure of a binding call on `repo` says the repository does not exist. The binding\n * documents code NOT_FOUND (numeric 10200), and the local simulator sends it; the live binding was\n * seen to throw an error whose code did not survive, with only the message \"Repository not found:\n * <name>.\" So the code, then the numeric code, then exactly that message naming this repository\n * (optionally after an \"ArtifactsError: \" prefix, with or without the closing period) are\n * accepted.\n */\nexport function isRepoNotFound(thrown: unknown, repo: string): boolean {\n if (artifactsErrorCode(thrown) === 'NOT_FOUND') return true;\n if (typeof thrown !== 'object' || thrown === null) return false;\n if (Reflect.get(thrown, 'numericCode') === NOT_FOUND_NUMERIC) return true;\n const message: unknown = Reflect.get(thrown, 'message');\n return (\n typeof message === 'string' &&\n new RegExp(String.raw`^(?:ArtifactsError: )?repository not found: ${escapeRegExp(repo)}\\.?$`, 'i').test(\n message.trim(),\n )\n );\n}\n\n/**\n * Translates a failure of a binding call on repository `repo` into a GatewayError: NOT_FOUND is\n * repo_not_found (also when only the numeric code or the message says so, see\n * {@link isRepoNotFound}), ALREADY_EXISTS is repo_exists (for createRepo also when only the numeric code or\n * the message says so, see {@link isAlreadyExists}), everything else (in-progress states,\n * MEMORY_LIMIT, INTERNAL_ERROR, unparsable results) is storage_unavailable. GatewayErrors pass\n * through unchanged.\n */\nexport function toGatewayError(repo: string, what: string, thrown: unknown): Error {\n if (isGatewayError(thrown) && thrown instanceof Error) return thrown;\n const code = artifactsErrorCode(thrown);\n if (isRepoNotFound(thrown, repo)) return repoNotFound(repo);\n if (code === 'ALREADY_EXISTS' || (what === 'createRepo' && isAlreadyExists(thrown, repo)))\n return repoExists(repo);\n return storageUnavailable(`Artifacts ${what}`, thrown);\n}\n"],"mappings":";;;;;AAWA,SAAgB,mBAAmB,QAAgC;CACjE,IAAI,OAAO,WAAW,YAAY,WAAW,MAAM,OAAO;CAC1D,MAAM,SAAS,sBAAsB,UAAU;EAC7C,MAAM,QAAQ,IAAI,QAAQ,MAAM;EAChC,SAAS,QAAQ,IAAI,QAAQ,SAAS;CACxC,CAAC;CACD,OAAO,OAAO,UAAU,OAAO,KAAK,OAAO;AAC7C;;AAGA,MAAM,yBAAyB;AAE/B,MAAM,gBAAgB,SAAyB,KAAK,WAAW,uBAAuB,OAAO,GAAG,KAAK;;;;;;;;AASrG,SAAgB,gBAAgB,QAAiB,MAAuB;CACtE,IAAI,mBAAmB,MAAM,MAAM,kBAAkB,OAAO;CAC5D,IAAI,OAAO,WAAW,YAAY,WAAW,MAAM,OAAO;CAC1D,IAAI,QAAQ,IAAI,QAAQ,aAAa,MAAM,wBAAwB,OAAO;CAC1E,MAAM,UAAmB,QAAQ,IAAI,QAAQ,SAAS;CACtD,OACE,OAAO,YAAY,YACnB,IAAI,OAAO,OAAO,GAAG,8CAA8C,aAAa,IAAI,EAAE,IAAI,GAAG,CAAC,CAAC,KAC7F,QAAQ,KAAK,CACf;AAEJ;;AAGA,MAAM,oBAAoB;;;;;;;;;AAU1B,SAAgB,eAAe,QAAiB,MAAuB;CACrE,IAAI,mBAAmB,MAAM,MAAM,aAAa,OAAO;CACvD,IAAI,OAAO,WAAW,YAAY,WAAW,MAAM,OAAO;CAC1D,IAAI,QAAQ,IAAI,QAAQ,aAAa,MAAM,mBAAmB,OAAO;CACrE,MAAM,UAAmB,QAAQ,IAAI,QAAQ,SAAS;CACtD,OACE,OAAO,YAAY,YACnB,IAAI,OAAO,OAAO,GAAG,+CAA+C,aAAa,IAAI,EAAE,OAAO,GAAG,CAAC,CAAC,KACjG,QAAQ,KAAK,CACf;AAEJ;;;;;;;;;AAUA,SAAgB,eAAe,MAAc,MAAc,QAAwB;CACjF,IAAI,eAAe,MAAM,KAAK,kBAAkB,OAAO,OAAO;CAC9D,MAAM,OAAO,mBAAmB,MAAM;CACtC,IAAI,eAAe,QAAQ,IAAI,GAAG,OAAO,aAAa,IAAI;CAC1D,IAAI,SAAS,oBAAqB,SAAS,gBAAgB,gBAAgB,QAAQ,IAAI,GACrF,OAAO,WAAW,IAAI;CACxB,OAAO,mBAAmB,aAAa,QAAQ,MAAM;AACvD"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ArtifactsRepoHandle } from "./artifacts-binding.js";
|
|
2
|
+
import { GitRemote } from "@leed-ai/git-gateway-contract/storage/git-remote";
|
|
3
|
+
/**
|
|
4
|
+
* Whether a binding call failed only because its result, a Blob, could not be carried back. That
|
|
5
|
+
* is what wrangler's remote Artifacts binding (`"remote": true` under `wrangler dev`) does for
|
|
6
|
+
* readBlob and readFile: its proxy cannot serialize a Blob ("Cannot serialize value: [object
|
|
7
|
+
* Blob]"). The native binding in production returns the Blob and never takes this path.
|
|
8
|
+
*/
|
|
9
|
+
export declare function isUnserializableBlob(thrown: unknown): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* A blob's bytes read over the repository's git remote instead of the binding: one upload-pack
|
|
12
|
+
* request wanting just that id (a blob reaches nothing, so the pack holds that object alone),
|
|
13
|
+
* read with the core pack reader. Null when the server does not have the id (refused
|
|
14
|
+
* in-protocol, "not our ref") or it is not a blob. HTTP failures propagate.
|
|
15
|
+
*/
|
|
16
|
+
export declare function readBlobOverGit(remote: GitRemote, sha: string): Promise<Uint8Array | null>;
|
|
17
|
+
/**
|
|
18
|
+
* The id of the blob at `path` in `revision` (a commit id or a short branch name), found through
|
|
19
|
+
* the binding's own commit and tree reads, which carry plain data even where Blobs cannot travel.
|
|
20
|
+
* Null when the revision, a directory on the way or the file does not exist, or the path names a
|
|
21
|
+
* directory or submodule.
|
|
22
|
+
*/
|
|
23
|
+
export declare function blobIdAt(handle: ArtifactsRepoHandle, revision: string, path: string): Promise<string | null>;
|
|
24
|
+
//# sourceMappingURL=artifacts-git-reads.d.ts.map
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { ArtifactsCommit, ArtifactsTreeEntry } from "./schemas/artifacts-binding-results.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { isCoreError } from "@leed-ai/git-gateway-core/core-error";
|
|
4
|
+
import { GitHttpClient } from "@leed-ai/git-gateway-core/smart-http/git-http-client";
|
|
5
|
+
// src/artifacts-git-reads.ts
|
|
6
|
+
const SHA = /^[0-9a-f]{40}$/;
|
|
7
|
+
/**
|
|
8
|
+
* Whether a binding call failed only because its result, a Blob, could not be carried back. That
|
|
9
|
+
* is what wrangler's remote Artifacts binding (`"remote": true` under `wrangler dev`) does for
|
|
10
|
+
* readBlob and readFile: its proxy cannot serialize a Blob ("Cannot serialize value: [object
|
|
11
|
+
* Blob]"). The native binding in production returns the Blob and never takes this path.
|
|
12
|
+
*/
|
|
13
|
+
function isUnserializableBlob(thrown) {
|
|
14
|
+
if (typeof thrown !== "object" || thrown === null) return false;
|
|
15
|
+
const message = Reflect.get(thrown, "message");
|
|
16
|
+
return typeof message === "string" && message.includes("Cannot serialize value: [object Blob]");
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* A blob's bytes read over the repository's git remote instead of the binding: one upload-pack
|
|
20
|
+
* request wanting just that id (a blob reaches nothing, so the pack holds that object alone),
|
|
21
|
+
* read with the core pack reader. Null when the server does not have the id (refused
|
|
22
|
+
* in-protocol, "not our ref") or it is not a blob. HTTP failures propagate.
|
|
23
|
+
*/
|
|
24
|
+
async function readBlobOverGit(remote, sha) {
|
|
25
|
+
try {
|
|
26
|
+
const { objects } = await new GitHttpClient(remote).fetchPack({ wants: [sha] });
|
|
27
|
+
const object = objects.find((candidate) => candidate.sha === sha);
|
|
28
|
+
return object?.type === "blob" ? object.data : null;
|
|
29
|
+
} catch (error) {
|
|
30
|
+
if (isCoreError(error, "remote_error")) return null;
|
|
31
|
+
throw error;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The id of the blob at `path` in `revision` (a commit id or a short branch name), found through
|
|
36
|
+
* the binding's own commit and tree reads, which carry plain data even where Blobs cannot travel.
|
|
37
|
+
* Null when the revision, a directory on the way or the file does not exist, or the path names a
|
|
38
|
+
* directory or submodule.
|
|
39
|
+
*/
|
|
40
|
+
async function blobIdAt(handle, revision, path) {
|
|
41
|
+
let commitId = revision;
|
|
42
|
+
if (!SHA.test(revision)) {
|
|
43
|
+
const [head] = z.array(ArtifactsCommit).parse(await handle.log({
|
|
44
|
+
ref: revision,
|
|
45
|
+
limit: 1
|
|
46
|
+
}));
|
|
47
|
+
commitId = head?.hash ?? null;
|
|
48
|
+
}
|
|
49
|
+
if (commitId === null) return null;
|
|
50
|
+
const commit = await handle.readCommit(commitId);
|
|
51
|
+
if (commit === null) return null;
|
|
52
|
+
let tree = ArtifactsCommit.parse(commit).treeHash;
|
|
53
|
+
const segments = path.split("/");
|
|
54
|
+
for (const [index, segment] of segments.entries()) {
|
|
55
|
+
const listed = await handle.readTree(tree);
|
|
56
|
+
if (listed === null) return null;
|
|
57
|
+
const entry = z.array(ArtifactsTreeEntry).parse(listed).find((candidate) => candidate.name === segment);
|
|
58
|
+
if (entry === void 0) return null;
|
|
59
|
+
if (index === segments.length - 1) return entry.type === "tree" || entry.type === "gitlink" ? null : entry.hash;
|
|
60
|
+
if (entry.type !== "tree") return null;
|
|
61
|
+
tree = entry.hash;
|
|
62
|
+
}
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
export { blobIdAt, isUnserializableBlob, readBlobOverGit };
|
|
66
|
+
|
|
67
|
+
//# sourceMappingURL=artifacts-git-reads.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"artifacts-git-reads.js","names":[],"sources":["../src/artifacts-git-reads.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport type { GitRemote } from '@leed-ai/git-gateway-contract/storage/git-remote';\nimport { isCoreError } from '@leed-ai/git-gateway-core/core-error';\nimport { GitHttpClient } from '@leed-ai/git-gateway-core/smart-http/git-http-client';\nimport { z } from 'zod';\n\nimport type { ArtifactsRepoHandle } from './artifacts-binding.ts';\nimport { ArtifactsCommit, ArtifactsTreeEntry } from './schemas/artifacts-binding-results.ts';\n\nconst SHA = /^[0-9a-f]{40}$/;\n\n/**\n * Whether a binding call failed only because its result, a Blob, could not be carried back. That\n * is what wrangler's remote Artifacts binding (`\"remote\": true` under `wrangler dev`) does for\n * readBlob and readFile: its proxy cannot serialize a Blob (\"Cannot serialize value: [object\n * Blob]\"). The native binding in production returns the Blob and never takes this path.\n */\nexport function isUnserializableBlob(thrown: unknown): boolean {\n if (typeof thrown !== 'object' || thrown === null) return false;\n const message: unknown = Reflect.get(thrown, 'message');\n return typeof message === 'string' && message.includes('Cannot serialize value: [object Blob]');\n}\n\n/**\n * A blob's bytes read over the repository's git remote instead of the binding: one upload-pack\n * request wanting just that id (a blob reaches nothing, so the pack holds that object alone),\n * read with the core pack reader. Null when the server does not have the id (refused\n * in-protocol, \"not our ref\") or it is not a blob. HTTP failures propagate.\n */\nexport async function readBlobOverGit(remote: GitRemote, sha: string): Promise<Uint8Array | null> {\n try {\n const { objects } = await new GitHttpClient(remote).fetchPack({ wants: [sha] });\n const object = objects.find((candidate) => candidate.sha === sha);\n return object?.type === 'blob' ? object.data : null;\n } catch (error) {\n if (isCoreError(error, 'remote_error')) return null;\n throw error;\n }\n}\n\n/**\n * The id of the blob at `path` in `revision` (a commit id or a short branch name), found through\n * the binding's own commit and tree reads, which carry plain data even where Blobs cannot travel.\n * Null when the revision, a directory on the way or the file does not exist, or the path names a\n * directory or submodule.\n */\nexport async function blobIdAt(\n handle: ArtifactsRepoHandle,\n revision: string,\n path: string,\n): Promise<string | null> {\n let commitId: string | null = revision;\n if (!SHA.test(revision)) {\n const [head] = z.array(ArtifactsCommit).parse(await handle.log({ ref: revision, limit: 1 }));\n commitId = head?.hash ?? null;\n }\n if (commitId === null) return null;\n const commit = await handle.readCommit(commitId);\n if (commit === null) return null;\n let tree = ArtifactsCommit.parse(commit).treeHash;\n const segments = path.split('/');\n for (const [index, segment] of segments.entries()) {\n const listed = await handle.readTree(tree);\n if (listed === null) return null;\n const entry = z\n .array(ArtifactsTreeEntry)\n .parse(listed)\n .find((candidate) => candidate.name === segment);\n if (entry === undefined) return null;\n const last = index === segments.length - 1;\n if (last) return entry.type === 'tree' || entry.type === 'gitlink' ? null : entry.hash;\n if (entry.type !== 'tree') return null;\n tree = entry.hash;\n }\n return null;\n}\n"],"mappings":";;;;;AASA,MAAM,MAAM;;;;;;;AAQZ,SAAgB,qBAAqB,QAA0B;CAC7D,IAAI,OAAO,WAAW,YAAY,WAAW,MAAM,OAAO;CAC1D,MAAM,UAAmB,QAAQ,IAAI,QAAQ,SAAS;CACtD,OAAO,OAAO,YAAY,YAAY,QAAQ,SAAS,uCAAuC;AAChG;;;;;;;AAQA,eAAsB,gBAAgB,QAAmB,KAAyC;CAChG,IAAI;EACF,MAAM,EAAE,YAAY,MAAM,IAAI,cAAc,MAAM,CAAC,CAAC,UAAU,EAAE,OAAO,CAAC,GAAG,EAAE,CAAC;EAC9E,MAAM,SAAS,QAAQ,MAAM,cAAc,UAAU,QAAQ,GAAG;EAChE,OAAO,QAAQ,SAAS,SAAS,OAAO,OAAO;CACjD,SAAS,OAAO;EACd,IAAI,YAAY,OAAO,cAAc,GAAG,OAAO;EAC/C,MAAM;CACR;AACF;;;;;;;AAQA,eAAsB,SACpB,QACA,UACA,MACwB;CACxB,IAAI,WAA0B;CAC9B,IAAI,CAAC,IAAI,KAAK,QAAQ,GAAG;EACvB,MAAM,CAAC,QAAQ,EAAE,MAAM,eAAe,CAAC,CAAC,MAAM,MAAM,OAAO,IAAI;GAAE,KAAK;GAAU,OAAO;EAAE,CAAC,CAAC;EAC3F,WAAW,MAAM,QAAQ;CAC3B;CACA,IAAI,aAAa,MAAM,OAAO;CAC9B,MAAM,SAAS,MAAM,OAAO,WAAW,QAAQ;CAC/C,IAAI,WAAW,MAAM,OAAO;CAC5B,IAAI,OAAO,gBAAgB,MAAM,MAAM,CAAC,CAAC;CACzC,MAAM,WAAW,KAAK,MAAM,GAAG;CAC/B,KAAK,MAAM,CAAC,OAAO,YAAY,SAAS,QAAQ,GAAG;EACjD,MAAM,SAAS,MAAM,OAAO,SAAS,IAAI;EACzC,IAAI,WAAW,MAAM,OAAO;EAC5B,MAAM,QAAQ,EACX,MAAM,kBAAkB,CAAC,CACzB,MAAM,MAAM,CAAC,CACb,MAAM,cAAc,UAAU,SAAS,OAAO;EACjD,IAAI,UAAU,KAAA,GAAW,OAAO;EAEhC,IADa,UAAU,SAAS,SAAS,GAC/B,OAAO,MAAM,SAAS,UAAU,MAAM,SAAS,YAAY,OAAO,MAAM;EAClF,IAAI,MAAM,SAAS,QAAQ,OAAO;EAClC,OAAO,MAAM;CACf;CACA,OAAO;AACT"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ArtifactsCommit, ArtifactsTreeEntry } from "./schemas/artifacts-binding-results.js";
|
|
2
|
+
import { Commit } from "@leed-ai/git-gateway-contract/schemas/commit";
|
|
3
|
+
import { StorageTreeEntry } from "@leed-ai/git-gateway-contract/storage/storage-tree-entry";
|
|
4
|
+
/**
|
|
5
|
+
* Converts Artifacts commit metadata into a contract {@link Commit}. Artifacts removes one
|
|
6
|
+
* trailing newline from the message and reports dates without their time zone, so the full
|
|
7
|
+
* message is recovered by re-encoding the commit both ways (at +0000, as the gateway writes
|
|
8
|
+
* every commit) and keeping the candidate whose id matches. When neither matches (a commit made
|
|
9
|
+
* in another time zone, or with extra headers such as a signature) the message is given back
|
|
10
|
+
* with the trailing newline git itself always writes.
|
|
11
|
+
*/
|
|
12
|
+
export declare function toContractCommit(metadata: ArtifactsCommit): Promise<Commit>;
|
|
13
|
+
/** Converts an Artifacts tree entry into a contract {@link StorageTreeEntry} (mode "40000" becomes "040000"). */
|
|
14
|
+
export declare function toStorageTreeEntry(entry: ArtifactsTreeEntry): StorageTreeEntry;
|
|
15
|
+
//# sourceMappingURL=artifacts-mapping.d.ts.map
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { readIdempotencyTrailer } from "@leed-ai/git-gateway-contract/reference/trailer";
|
|
2
|
+
import { Commit } from "@leed-ai/git-gateway-contract/schemas/commit";
|
|
3
|
+
import { StorageTreeEntry } from "@leed-ai/git-gateway-contract/storage/storage-tree-entry";
|
|
4
|
+
import { encodeCommit } from "@leed-ai/git-gateway-core/objects/commit-object";
|
|
5
|
+
import { hashObject } from "@leed-ai/git-gateway-core/objects/hash-object";
|
|
6
|
+
// src/artifacts-mapping.ts
|
|
7
|
+
const isoOf = (seconds) => (/* @__PURE__ */ new Date(seconds * 1e3)).toISOString();
|
|
8
|
+
/** The contract commit for some Artifacts commit metadata, with a given full message. */
|
|
9
|
+
function commitWith(metadata, message) {
|
|
10
|
+
return Commit.parse({
|
|
11
|
+
sha: metadata.hash,
|
|
12
|
+
tree: metadata.treeHash,
|
|
13
|
+
parents: metadata.parents,
|
|
14
|
+
author: {
|
|
15
|
+
...metadata.author,
|
|
16
|
+
date: isoOf(metadata.authoredAt)
|
|
17
|
+
},
|
|
18
|
+
committer: {
|
|
19
|
+
...metadata.committer,
|
|
20
|
+
date: isoOf(metadata.committedAt)
|
|
21
|
+
},
|
|
22
|
+
message,
|
|
23
|
+
idempotencyKey: readIdempotencyTrailer(message)
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Converts Artifacts commit metadata into a contract {@link Commit}. Artifacts removes one
|
|
28
|
+
* trailing newline from the message and reports dates without their time zone, so the full
|
|
29
|
+
* message is recovered by re-encoding the commit both ways (at +0000, as the gateway writes
|
|
30
|
+
* every commit) and keeping the candidate whose id matches. When neither matches (a commit made
|
|
31
|
+
* in another time zone, or with extra headers such as a signature) the message is given back
|
|
32
|
+
* with the trailing newline git itself always writes.
|
|
33
|
+
*/
|
|
34
|
+
async function toContractCommit(metadata) {
|
|
35
|
+
const candidates = [`${metadata.message}\n`, metadata.message].filter((message) => message.length > 0);
|
|
36
|
+
for (const message of candidates) {
|
|
37
|
+
const commit = commitWith(metadata, message);
|
|
38
|
+
const { tree, parents, author, committer } = commit;
|
|
39
|
+
if (await hashObject("commit", encodeCommit({
|
|
40
|
+
tree,
|
|
41
|
+
parents: [...parents],
|
|
42
|
+
author,
|
|
43
|
+
committer,
|
|
44
|
+
message
|
|
45
|
+
})) === metadata.hash) return commit;
|
|
46
|
+
}
|
|
47
|
+
return commitWith(metadata, `${metadata.message}\n`);
|
|
48
|
+
}
|
|
49
|
+
const TYPES = {
|
|
50
|
+
tree: "tree",
|
|
51
|
+
gitlink: "commit",
|
|
52
|
+
blob: "blob",
|
|
53
|
+
exec: "blob",
|
|
54
|
+
symlink: "blob"
|
|
55
|
+
};
|
|
56
|
+
/** Converts an Artifacts tree entry into a contract {@link StorageTreeEntry} (mode "40000" becomes "040000"). */
|
|
57
|
+
function toStorageTreeEntry(entry) {
|
|
58
|
+
return StorageTreeEntry.parse({
|
|
59
|
+
name: entry.name,
|
|
60
|
+
type: TYPES[entry.type],
|
|
61
|
+
mode: entry.mode === "40000" ? "040000" : entry.mode,
|
|
62
|
+
sha: entry.hash
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
export { toContractCommit, toStorageTreeEntry };
|
|
66
|
+
|
|
67
|
+
//# sourceMappingURL=artifacts-mapping.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"artifacts-mapping.js","names":[],"sources":["../src/artifacts-mapping.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport { readIdempotencyTrailer } from '@leed-ai/git-gateway-contract/reference/trailer';\nimport { Commit } from '@leed-ai/git-gateway-contract/schemas/commit';\nimport { StorageTreeEntry } from '@leed-ai/git-gateway-contract/storage/storage-tree-entry';\nimport { encodeCommit } from '@leed-ai/git-gateway-core/objects/commit-object';\nimport { hashObject } from '@leed-ai/git-gateway-core/objects/hash-object';\n\nimport type { ArtifactsCommit, ArtifactsTreeEntry } from './schemas/artifacts-binding-results.ts';\n\nconst isoOf = (seconds: number): string => new Date(seconds * 1000).toISOString();\n\n/** The contract commit for some Artifacts commit metadata, with a given full message. */\nfunction commitWith(metadata: ArtifactsCommit, message: string): Commit {\n return Commit.parse({\n sha: metadata.hash,\n tree: metadata.treeHash,\n parents: metadata.parents,\n author: { ...metadata.author, date: isoOf(metadata.authoredAt) },\n committer: { ...metadata.committer, date: isoOf(metadata.committedAt) },\n message,\n idempotencyKey: readIdempotencyTrailer(message),\n });\n}\n\n/**\n * Converts Artifacts commit metadata into a contract {@link Commit}. Artifacts removes one\n * trailing newline from the message and reports dates without their time zone, so the full\n * message is recovered by re-encoding the commit both ways (at +0000, as the gateway writes\n * every commit) and keeping the candidate whose id matches. When neither matches (a commit made\n * in another time zone, or with extra headers such as a signature) the message is given back\n * with the trailing newline git itself always writes.\n */\nexport async function toContractCommit(metadata: ArtifactsCommit): Promise<Commit> {\n const candidates = [`${metadata.message}\\n`, metadata.message].filter((message) => message.length > 0);\n for (const message of candidates) {\n const commit = commitWith(metadata, message);\n const { tree, parents, author, committer } = commit;\n const sha = await hashObject(\n 'commit',\n encodeCommit({ tree, parents: [...parents], author, committer, message }),\n );\n if (sha === metadata.hash) return commit;\n }\n return commitWith(metadata, `${metadata.message}\\n`);\n}\n\nconst TYPES = { tree: 'tree', gitlink: 'commit', blob: 'blob', exec: 'blob', symlink: 'blob' } as const;\n\n/** Converts an Artifacts tree entry into a contract {@link StorageTreeEntry} (mode \"40000\" becomes \"040000\"). */\nexport function toStorageTreeEntry(entry: ArtifactsTreeEntry): StorageTreeEntry {\n return StorageTreeEntry.parse({\n name: entry.name,\n type: TYPES[entry.type],\n mode: entry.mode === '40000' ? '040000' : entry.mode,\n sha: entry.hash,\n });\n}\n"],"mappings":";;;;;;AASA,MAAM,SAAS,6BAA4B,IAAI,KAAK,UAAU,GAAI,EAAA,CAAE,YAAY;;AAGhF,SAAS,WAAW,UAA2B,SAAyB;CACtE,OAAO,OAAO,MAAM;EAClB,KAAK,SAAS;EACd,MAAM,SAAS;EACf,SAAS,SAAS;EAClB,QAAQ;GAAE,GAAG,SAAS;GAAQ,MAAM,MAAM,SAAS,UAAU;EAAE;EAC/D,WAAW;GAAE,GAAG,SAAS;GAAW,MAAM,MAAM,SAAS,WAAW;EAAE;EACtE;EACA,gBAAgB,uBAAuB,OAAO;CAChD,CAAC;AACH;;;;;;;;;AAUA,eAAsB,iBAAiB,UAA4C;CACjF,MAAM,aAAa,CAAC,GAAG,SAAS,QAAQ,KAAK,SAAS,OAAO,CAAC,CAAC,QAAQ,YAAY,QAAQ,SAAS,CAAC;CACrG,KAAK,MAAM,WAAW,YAAY;EAChC,MAAM,SAAS,WAAW,UAAU,OAAO;EAC3C,MAAM,EAAE,MAAM,SAAS,QAAQ,cAAc;EAK7C,IAAI,MAJc,WAChB,UACA,aAAa;GAAE;GAAM,SAAS,CAAC,GAAG,OAAO;GAAG;GAAQ;GAAW;EAAQ,CAAC,CAC1E,MACY,SAAS,MAAM,OAAO;CACpC;CACA,OAAO,WAAW,UAAU,GAAG,SAAS,QAAQ,GAAG;AACrD;AAEA,MAAM,QAAQ;CAAE,MAAM;CAAQ,SAAS;CAAU,MAAM;CAAQ,MAAM;CAAQ,SAAS;AAAO;;AAG7F,SAAgB,mBAAmB,OAA6C;CAC9E,OAAO,iBAAiB,MAAM;EAC5B,MAAM,MAAM;EACZ,MAAM,MAAM,MAAM;EAClB,MAAM,MAAM,SAAS,UAAU,WAAW,MAAM;EAChD,KAAK,MAAM;CACb,CAAC;AACH"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ArtifactsRestNamespace, ArtifactsRestRepo, ArtifactsRestToken } from "./schemas/artifacts-rest-results.js";
|
|
2
|
+
import { Cloudflare } from "cloudflare";
|
|
3
|
+
/** Where the REST control plane points: an account and one Artifacts namespace in it. */
|
|
4
|
+
export interface ArtifactsRestOptions {
|
|
5
|
+
/** A configured official Cloudflare SDK client (API token with Artifacts permissions). */
|
|
6
|
+
readonly client: Cloudflare;
|
|
7
|
+
readonly accountId: string;
|
|
8
|
+
readonly namespace: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* The Artifacts control plane over the Cloudflare REST API, for code that runs outside a Worker
|
|
12
|
+
* (provisioning scripts, CI, the live contract leg): namespaces, repositories and tokens. Every
|
|
13
|
+
* call goes through the official `cloudflare` SDK's generic request methods (it has no typed
|
|
14
|
+
* Artifacts resource yet) and every response is parsed with Zod. Inside a Worker, use the binding
|
|
15
|
+
* and {@link ArtifactsBackend} instead.
|
|
16
|
+
*/
|
|
17
|
+
export declare class ArtifactsRestControl {
|
|
18
|
+
#private;
|
|
19
|
+
constructor(options: ArtifactsRestOptions);
|
|
20
|
+
/** The namespace, or null when it does not exist. */
|
|
21
|
+
getNamespace(): Promise<ArtifactsRestNamespace | null>;
|
|
22
|
+
/** Creates the namespace (optionally pinned to a jurisdiction). */
|
|
23
|
+
createNamespace(name: string, jurisdiction?: 'eu' | 'us'): Promise<ArtifactsRestNamespace>;
|
|
24
|
+
/** Creates a repository; the initial token in the result is not returned. */
|
|
25
|
+
createRepo(name: string, defaultBranch: string): Promise<ArtifactsRestRepo>;
|
|
26
|
+
/** A repository, or null when it does not exist. */
|
|
27
|
+
getRepo(name: string): Promise<ArtifactsRestRepo | null>;
|
|
28
|
+
/** Deletes a repository; false when there was none. */
|
|
29
|
+
deleteRepo(name: string): Promise<boolean>;
|
|
30
|
+
/** Mints a repository token for git; `ttlSeconds` 60–31536000. */
|
|
31
|
+
createToken(repo: string, scope: 'read' | 'write', ttlSeconds: number): Promise<ArtifactsRestToken>;
|
|
32
|
+
/** Revokes a token by id; false when there was none. */
|
|
33
|
+
revokeToken(id: string): Promise<boolean>;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=artifacts-rest.d.ts.map
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { ArtifactsRestNamespace, ArtifactsRestRepo, ArtifactsRestToken, cloudflareEnvelope } from "./schemas/artifacts-rest-results.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
// src/artifacts-rest.ts
|
|
4
|
+
const NotFound = z.object({ status: z.literal(404) });
|
|
5
|
+
/** True when the SDK threw for a 404. */
|
|
6
|
+
function isNotFound(error) {
|
|
7
|
+
return NotFound.safeParse(error).success;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* The Artifacts control plane over the Cloudflare REST API, for code that runs outside a Worker
|
|
11
|
+
* (provisioning scripts, CI, the live contract leg): namespaces, repositories and tokens. Every
|
|
12
|
+
* call goes through the official `cloudflare` SDK's generic request methods (it has no typed
|
|
13
|
+
* Artifacts resource yet) and every response is parsed with Zod. Inside a Worker, use the binding
|
|
14
|
+
* and {@link ArtifactsBackend} instead.
|
|
15
|
+
*/
|
|
16
|
+
var ArtifactsRestControl = class {
|
|
17
|
+
#client;
|
|
18
|
+
#account;
|
|
19
|
+
#namespace;
|
|
20
|
+
constructor(options) {
|
|
21
|
+
this.#client = options.client;
|
|
22
|
+
this.#account = `/accounts/${encodeURIComponent(options.accountId)}/artifacts`;
|
|
23
|
+
this.#namespace = `${this.#account}/namespaces/${encodeURIComponent(options.namespace)}`;
|
|
24
|
+
}
|
|
25
|
+
/** The namespace, or null when it does not exist. */
|
|
26
|
+
async getNamespace() {
|
|
27
|
+
try {
|
|
28
|
+
return cloudflareEnvelope(ArtifactsRestNamespace).parse(await this.#client.get(this.#namespace)).result;
|
|
29
|
+
} catch (error) {
|
|
30
|
+
if (isNotFound(error)) return null;
|
|
31
|
+
throw error;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/** Creates the namespace (optionally pinned to a jurisdiction). */
|
|
35
|
+
async createNamespace(name, jurisdiction) {
|
|
36
|
+
const body = jurisdiction === void 0 ? { namespace: name } : {
|
|
37
|
+
namespace: name,
|
|
38
|
+
jurisdiction
|
|
39
|
+
};
|
|
40
|
+
return cloudflareEnvelope(ArtifactsRestNamespace).parse(await this.#client.post(`${this.#account}/namespaces`, { body })).result;
|
|
41
|
+
}
|
|
42
|
+
/** Creates a repository; the initial token in the result is not returned. */
|
|
43
|
+
async createRepo(name, defaultBranch) {
|
|
44
|
+
const response = await this.#client.post(`${this.#namespace}/repos`, { body: {
|
|
45
|
+
name,
|
|
46
|
+
default_branch: defaultBranch
|
|
47
|
+
} });
|
|
48
|
+
return cloudflareEnvelope(ArtifactsRestRepo).parse(response).result;
|
|
49
|
+
}
|
|
50
|
+
/** A repository, or null when it does not exist. */
|
|
51
|
+
async getRepo(name) {
|
|
52
|
+
try {
|
|
53
|
+
return cloudflareEnvelope(ArtifactsRestRepo).parse(await this.#client.get(`${this.#namespace}/repos/${encodeURIComponent(name)}`)).result;
|
|
54
|
+
} catch (error) {
|
|
55
|
+
if (isNotFound(error)) return null;
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/** Deletes a repository; false when there was none. */
|
|
60
|
+
async deleteRepo(name) {
|
|
61
|
+
try {
|
|
62
|
+
await this.#client.delete(`${this.#namespace}/repos/${encodeURIComponent(name)}`);
|
|
63
|
+
return true;
|
|
64
|
+
} catch (error) {
|
|
65
|
+
if (isNotFound(error)) return false;
|
|
66
|
+
throw error;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/** Mints a repository token for git; `ttlSeconds` 60–31536000. */
|
|
70
|
+
async createToken(repo, scope, ttlSeconds) {
|
|
71
|
+
const body = {
|
|
72
|
+
repo,
|
|
73
|
+
scope,
|
|
74
|
+
ttl: z.int().min(60).max(31536e3).parse(ttlSeconds)
|
|
75
|
+
};
|
|
76
|
+
return cloudflareEnvelope(ArtifactsRestToken).parse(await this.#client.post(`${this.#namespace}/tokens`, { body })).result;
|
|
77
|
+
}
|
|
78
|
+
/** Revokes a token by id; false when there was none. */
|
|
79
|
+
async revokeToken(id) {
|
|
80
|
+
try {
|
|
81
|
+
await this.#client.delete(`${this.#namespace}/tokens/${encodeURIComponent(id)}`);
|
|
82
|
+
return true;
|
|
83
|
+
} catch (error) {
|
|
84
|
+
if (isNotFound(error)) return false;
|
|
85
|
+
throw error;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
export { ArtifactsRestControl };
|
|
90
|
+
|
|
91
|
+
//# sourceMappingURL=artifacts-rest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"artifacts-rest.js","names":[],"sources":["../src/artifacts-rest.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport type { Cloudflare } from 'cloudflare';\nimport { z } from 'zod';\n\nimport {\n ArtifactsRestNamespace,\n ArtifactsRestRepo,\n ArtifactsRestToken,\n cloudflareEnvelope,\n} from './schemas/artifacts-rest-results.ts';\n\n/** Where the REST control plane points: an account and one Artifacts namespace in it. */\nexport interface ArtifactsRestOptions {\n /** A configured official Cloudflare SDK client (API token with Artifacts permissions). */\n readonly client: Cloudflare;\n readonly accountId: string;\n readonly namespace: string;\n}\n\nconst NotFound = z.object({ status: z.literal(404) });\n\n/** True when the SDK threw for a 404. */\nfunction isNotFound(error: unknown): boolean {\n return NotFound.safeParse(error).success;\n}\n\n/**\n * The Artifacts control plane over the Cloudflare REST API, for code that runs outside a Worker\n * (provisioning scripts, CI, the live contract leg): namespaces, repositories and tokens. Every\n * call goes through the official `cloudflare` SDK's generic request methods (it has no typed\n * Artifacts resource yet) and every response is parsed with Zod. Inside a Worker, use the binding\n * and {@link ArtifactsBackend} instead.\n */\nexport class ArtifactsRestControl {\n readonly #client: Cloudflare;\n readonly #account: string;\n readonly #namespace: string;\n\n constructor(options: ArtifactsRestOptions) {\n this.#client = options.client;\n this.#account = `/accounts/${encodeURIComponent(options.accountId)}/artifacts`;\n this.#namespace = `${this.#account}/namespaces/${encodeURIComponent(options.namespace)}`;\n }\n\n /** The namespace, or null when it does not exist. */\n async getNamespace(): Promise<ArtifactsRestNamespace | null> {\n try {\n return cloudflareEnvelope(ArtifactsRestNamespace).parse(await this.#client.get(this.#namespace)).result;\n } catch (error) {\n if (isNotFound(error)) return null;\n throw error;\n }\n }\n\n /** Creates the namespace (optionally pinned to a jurisdiction). */\n async createNamespace(name: string, jurisdiction?: 'eu' | 'us'): Promise<ArtifactsRestNamespace> {\n const body = jurisdiction === undefined ? { namespace: name } : { namespace: name, jurisdiction };\n return cloudflareEnvelope(ArtifactsRestNamespace).parse(\n await this.#client.post(`${this.#account}/namespaces`, { body }),\n ).result;\n }\n\n /** Creates a repository; the initial token in the result is not returned. */\n async createRepo(name: string, defaultBranch: string): Promise<ArtifactsRestRepo> {\n const response = await this.#client.post(`${this.#namespace}/repos`, {\n body: { name, default_branch: defaultBranch },\n });\n return cloudflareEnvelope(ArtifactsRestRepo).parse(response).result;\n }\n\n /** A repository, or null when it does not exist. */\n async getRepo(name: string): Promise<ArtifactsRestRepo | null> {\n try {\n return cloudflareEnvelope(ArtifactsRestRepo).parse(\n await this.#client.get(`${this.#namespace}/repos/${encodeURIComponent(name)}`),\n ).result;\n } catch (error) {\n if (isNotFound(error)) return null;\n throw error;\n }\n }\n\n /** Deletes a repository; false when there was none. */\n async deleteRepo(name: string): Promise<boolean> {\n try {\n await this.#client.delete(`${this.#namespace}/repos/${encodeURIComponent(name)}`);\n return true;\n } catch (error) {\n if (isNotFound(error)) return false;\n throw error;\n }\n }\n\n /** Mints a repository token for git; `ttlSeconds` 60–31536000. */\n async createToken(repo: string, scope: 'read' | 'write', ttlSeconds: number): Promise<ArtifactsRestToken> {\n const body = { repo, scope, ttl: z.int().min(60).max(31_536_000).parse(ttlSeconds) };\n return cloudflareEnvelope(ArtifactsRestToken).parse(\n await this.#client.post(`${this.#namespace}/tokens`, { body }),\n ).result;\n }\n\n /** Revokes a token by id; false when there was none. */\n async revokeToken(id: string): Promise<boolean> {\n try {\n await this.#client.delete(`${this.#namespace}/tokens/${encodeURIComponent(id)}`);\n return true;\n } catch (error) {\n if (isNotFound(error)) return false;\n throw error;\n }\n }\n}\n"],"mappings":";;;AAmBA,MAAM,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,GAAG,EAAE,CAAC;;AAGpD,SAAS,WAAW,OAAyB;CAC3C,OAAO,SAAS,UAAU,KAAK,CAAC,CAAC;AACnC;;;;;;;;AASA,IAAa,uBAAb,MAAkC;CAChC;CACA;CACA;CAEA,YAAY,SAA+B;EACzC,KAAK,UAAU,QAAQ;EACvB,KAAK,WAAW,aAAa,mBAAmB,QAAQ,SAAS,EAAE;EACnE,KAAK,aAAa,GAAG,KAAK,SAAS,cAAc,mBAAmB,QAAQ,SAAS;CACvF;;CAGA,MAAM,eAAuD;EAC3D,IAAI;GACF,OAAO,mBAAmB,sBAAsB,CAAC,CAAC,MAAM,MAAM,KAAK,QAAQ,IAAI,KAAK,UAAU,CAAC,CAAC,CAAC;EACnG,SAAS,OAAO;GACd,IAAI,WAAW,KAAK,GAAG,OAAO;GAC9B,MAAM;EACR;CACF;;CAGA,MAAM,gBAAgB,MAAc,cAA6D;EAC/F,MAAM,OAAO,iBAAiB,KAAA,IAAY,EAAE,WAAW,KAAK,IAAI;GAAE,WAAW;GAAM;EAAa;EAChG,OAAO,mBAAmB,sBAAsB,CAAC,CAAC,MAChD,MAAM,KAAK,QAAQ,KAAK,GAAG,KAAK,SAAS,cAAc,EAAE,KAAK,CAAC,CACjE,CAAC,CAAC;CACJ;;CAGA,MAAM,WAAW,MAAc,eAAmD;EAChF,MAAM,WAAW,MAAM,KAAK,QAAQ,KAAK,GAAG,KAAK,WAAW,SAAS,EACnE,MAAM;GAAE;GAAM,gBAAgB;EAAc,EAC9C,CAAC;EACD,OAAO,mBAAmB,iBAAiB,CAAC,CAAC,MAAM,QAAQ,CAAC,CAAC;CAC/D;;CAGA,MAAM,QAAQ,MAAiD;EAC7D,IAAI;GACF,OAAO,mBAAmB,iBAAiB,CAAC,CAAC,MAC3C,MAAM,KAAK,QAAQ,IAAI,GAAG,KAAK,WAAW,SAAS,mBAAmB,IAAI,GAAG,CAC/E,CAAC,CAAC;EACJ,SAAS,OAAO;GACd,IAAI,WAAW,KAAK,GAAG,OAAO;GAC9B,MAAM;EACR;CACF;;CAGA,MAAM,WAAW,MAAgC;EAC/C,IAAI;GACF,MAAM,KAAK,QAAQ,OAAO,GAAG,KAAK,WAAW,SAAS,mBAAmB,IAAI,GAAG;GAChF,OAAO;EACT,SAAS,OAAO;GACd,IAAI,WAAW,KAAK,GAAG,OAAO;GAC9B,MAAM;EACR;CACF;;CAGA,MAAM,YAAY,MAAc,OAAyB,YAAiD;EACxG,MAAM,OAAO;GAAE;GAAM;GAAO,KAAK,EAAE,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,OAAU,CAAC,CAAC,MAAM,UAAU;EAAE;EACnF,OAAO,mBAAmB,kBAAkB,CAAC,CAAC,MAC5C,MAAM,KAAK,QAAQ,KAAK,GAAG,KAAK,WAAW,UAAU,EAAE,KAAK,CAAC,CAC/D,CAAC,CAAC;CACJ;;CAGA,MAAM,YAAY,IAA8B;EAC9C,IAAI;GACF,MAAM,KAAK,QAAQ,OAAO,GAAG,KAAK,WAAW,UAAU,mBAAmB,EAAE,GAAG;GAC/E,OAAO;EACT,SAAS,OAAO;GACd,IAAI,WAAW,KAAK,GAAG,OAAO;GAC9B,MAAM;EACR;CACF;AACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package-name.js","names":[],"sources":["../src/package-name.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\n\n/** The npm name this package is published under. */\nexport const packageName = '@leed-ai/git-gateway-backend-artifacts' as const;\n"],"mappings":";;AAGA,MAAa,cAAc"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** Repository metadata from `ArtifactsRepo.info()`. */
|
|
3
|
+
export declare const ArtifactsRepoInfo: z.ZodObject<{
|
|
4
|
+
id: z.ZodString;
|
|
5
|
+
name: z.ZodString;
|
|
6
|
+
description: z.ZodNullable<z.ZodString>;
|
|
7
|
+
defaultBranch: z.ZodString;
|
|
8
|
+
createdAt: z.ZodISODateTime;
|
|
9
|
+
updatedAt: z.ZodISODateTime;
|
|
10
|
+
lastPushAt: z.ZodNullable<z.ZodISODateTime>;
|
|
11
|
+
source: z.ZodNullable<z.ZodString>;
|
|
12
|
+
readOnly: z.ZodBoolean;
|
|
13
|
+
remote: z.ZodURL;
|
|
14
|
+
}, z.core.$strip>;
|
|
15
|
+
/** Repository metadata from Artifacts, inferred from {@link ArtifactsRepoInfo}. */
|
|
16
|
+
export type ArtifactsRepoInfo = z.infer<typeof ArtifactsRepoInfo>;
|
|
17
|
+
/** The result of `Artifacts.create()`. */
|
|
18
|
+
export declare const ArtifactsCreateResult: z.ZodObject<{
|
|
19
|
+
id: z.ZodString;
|
|
20
|
+
name: z.ZodString;
|
|
21
|
+
defaultBranch: z.ZodString;
|
|
22
|
+
remote: z.ZodURL;
|
|
23
|
+
token: z.ZodString;
|
|
24
|
+
}, z.core.$strip>;
|
|
25
|
+
/** The result of creating an Artifacts repository, inferred from {@link ArtifactsCreateResult}. */
|
|
26
|
+
export type ArtifactsCreateResult = z.infer<typeof ArtifactsCreateResult>;
|
|
27
|
+
/** The result of `ArtifactsRepo.createToken()`. */
|
|
28
|
+
export declare const ArtifactsToken: z.ZodObject<{
|
|
29
|
+
id: z.ZodString;
|
|
30
|
+
plaintext: z.ZodString;
|
|
31
|
+
scope: z.ZodEnum<{
|
|
32
|
+
read: "read";
|
|
33
|
+
write: "write";
|
|
34
|
+
}>;
|
|
35
|
+
expiresAt: z.ZodISODateTime;
|
|
36
|
+
}, z.core.$strip>;
|
|
37
|
+
/** An Artifacts token, inferred from {@link ArtifactsToken}. */
|
|
38
|
+
export type ArtifactsToken = z.infer<typeof ArtifactsToken>;
|
|
39
|
+
/** One entry from `ArtifactsRepo.readTree()`. */
|
|
40
|
+
export declare const ArtifactsTreeEntry: z.ZodObject<{
|
|
41
|
+
name: z.ZodString;
|
|
42
|
+
mode: z.ZodString;
|
|
43
|
+
hash: z.ZodString;
|
|
44
|
+
type: z.ZodEnum<{
|
|
45
|
+
blob: "blob";
|
|
46
|
+
exec: "exec";
|
|
47
|
+
gitlink: "gitlink";
|
|
48
|
+
symlink: "symlink";
|
|
49
|
+
tree: "tree";
|
|
50
|
+
}>;
|
|
51
|
+
}, z.core.$strip>;
|
|
52
|
+
/** An Artifacts tree entry, inferred from {@link ArtifactsTreeEntry}. */
|
|
53
|
+
export type ArtifactsTreeEntry = z.infer<typeof ArtifactsTreeEntry>;
|
|
54
|
+
/** Commit metadata from `ArtifactsRepo.readCommit()` and `log()`. */
|
|
55
|
+
export declare const ArtifactsCommit: z.ZodObject<{
|
|
56
|
+
hash: z.ZodString;
|
|
57
|
+
treeHash: z.ZodString;
|
|
58
|
+
message: z.ZodString;
|
|
59
|
+
author: z.ZodObject<{
|
|
60
|
+
name: z.ZodString;
|
|
61
|
+
email: z.ZodString;
|
|
62
|
+
}, z.core.$strip>;
|
|
63
|
+
committer: z.ZodObject<{
|
|
64
|
+
name: z.ZodString;
|
|
65
|
+
email: z.ZodString;
|
|
66
|
+
}, z.core.$strip>;
|
|
67
|
+
parents: z.ZodArray<z.ZodString>;
|
|
68
|
+
authoredAt: z.ZodInt;
|
|
69
|
+
committedAt: z.ZodInt;
|
|
70
|
+
}, z.core.$strip>;
|
|
71
|
+
/** Artifacts commit metadata, inferred from {@link ArtifactsCommit}. */
|
|
72
|
+
export type ArtifactsCommit = z.infer<typeof ArtifactsCommit>;
|
|
73
|
+
/** The identifying fields of an error thrown by the Artifacts binding. */
|
|
74
|
+
export declare const ArtifactsBindingError: z.ZodObject<{
|
|
75
|
+
code: z.ZodString;
|
|
76
|
+
message: z.ZodString;
|
|
77
|
+
}, z.core.$strip>;
|
|
78
|
+
/** An Artifacts binding error, inferred from {@link ArtifactsBindingError}. */
|
|
79
|
+
export type ArtifactsBindingError = z.infer<typeof ArtifactsBindingError>;
|
|
80
|
+
//# sourceMappingURL=artifacts-binding-results.d.ts.map
|