@aeilab/s3ag 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.
Files changed (75) hide show
  1. package/LICENSE +201 -0
  2. package/dist/api.d.ts +156 -0
  3. package/dist/api.d.ts.map +1 -0
  4. package/dist/api.js +195 -0
  5. package/dist/api.js.map +1 -0
  6. package/dist/aws.d.ts +144 -0
  7. package/dist/aws.d.ts.map +1 -0
  8. package/dist/aws.js +357 -0
  9. package/dist/aws.js.map +1 -0
  10. package/dist/cli/git-lfs-s3ag.d.ts +3 -0
  11. package/dist/cli/git-lfs-s3ag.d.ts.map +1 -0
  12. package/dist/cli/git-lfs-s3ag.js +14 -0
  13. package/dist/cli/git-lfs-s3ag.js.map +1 -0
  14. package/dist/cli/git-remote-s3ag.d.ts +3 -0
  15. package/dist/cli/git-remote-s3ag.d.ts.map +1 -0
  16. package/dist/cli/git-remote-s3ag.js +7 -0
  17. package/dist/cli/git-remote-s3ag.js.map +1 -0
  18. package/dist/cli/s3ag.d.ts +3 -0
  19. package/dist/cli/s3ag.d.ts.map +1 -0
  20. package/dist/cli/s3ag.js +153 -0
  21. package/dist/cli/s3ag.js.map +1 -0
  22. package/dist/commits.d.ts +17 -0
  23. package/dist/commits.d.ts.map +1 -0
  24. package/dist/commits.js +82 -0
  25. package/dist/commits.js.map +1 -0
  26. package/dist/common.d.ts +55 -0
  27. package/dist/common.d.ts.map +1 -0
  28. package/dist/common.js +114 -0
  29. package/dist/common.js.map +1 -0
  30. package/dist/config.d.ts +17 -0
  31. package/dist/config.d.ts.map +1 -0
  32. package/dist/config.js +50 -0
  33. package/dist/config.js.map +1 -0
  34. package/dist/enums.d.ts +10 -0
  35. package/dist/enums.d.ts.map +1 -0
  36. package/dist/enums.js +14 -0
  37. package/dist/enums.js.map +1 -0
  38. package/dist/exit.d.ts +10 -0
  39. package/dist/exit.d.ts.map +1 -0
  40. package/dist/exit.js +17 -0
  41. package/dist/exit.js.map +1 -0
  42. package/dist/git.d.ts +44 -0
  43. package/dist/git.d.ts.map +1 -0
  44. package/dist/git.js +131 -0
  45. package/dist/git.js.map +1 -0
  46. package/dist/index.d.ts +9 -0
  47. package/dist/index.d.ts.map +1 -0
  48. package/dist/index.js +12 -0
  49. package/dist/index.js.map +1 -0
  50. package/dist/lfs.d.ts +38 -0
  51. package/dist/lfs.d.ts.map +1 -0
  52. package/dist/lfs.js +426 -0
  53. package/dist/lfs.js.map +1 -0
  54. package/dist/logger.d.ts +27 -0
  55. package/dist/logger.d.ts.map +1 -0
  56. package/dist/logger.js +93 -0
  57. package/dist/logger.js.map +1 -0
  58. package/dist/manage.d.ts +20 -0
  59. package/dist/manage.d.ts.map +1 -0
  60. package/dist/manage.js +164 -0
  61. package/dist/manage.js.map +1 -0
  62. package/dist/process.d.ts +21 -0
  63. package/dist/process.d.ts.map +1 -0
  64. package/dist/process.js +32 -0
  65. package/dist/process.js.map +1 -0
  66. package/dist/prompt.d.ts +9 -0
  67. package/dist/prompt.d.ts.map +1 -0
  68. package/dist/prompt.js +26 -0
  69. package/dist/prompt.js.map +1 -0
  70. package/dist/remote.d.ts +38 -0
  71. package/dist/remote.d.ts.map +1 -0
  72. package/dist/remote.js +446 -0
  73. package/dist/remote.js.map +1 -0
  74. package/package.json +31 -3
  75. package/README.md +0 -3
@@ -0,0 +1 @@
1
+ {"version":3,"file":"git.d.ts","sourceRoot":"","sources":["../src/git.ts"],"names":[],"mappings":"AAOA,qBAAa,QAAS,SAAQ,KAAK;CAAG;AAQtC,8DAA8D;AAC9D,wBAAgB,OAAO,CAAC,OAAO,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAcxE;AAED,gEAAgE;AAChE,wBAAgB,MAAM,CAAC,OAAO,EAAE;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;CACb,GAAG,MAAM,CAOT;AAED,4EAA4E;AAC5E,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAKpD;AAED,+DAA+D;AAC/D,wBAAgB,QAAQ,CAAC,OAAO,EAAE;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;CACb,GAAG,IAAI,CASP;AAED,6BAA6B;AAC7B,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAM7C;AAED,+DAA+D;AAC/D,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAOzE;AAED,gDAAgD;AAChD,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAQrD;AAMD,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CASvD;AAED,8DAA8D;AAC9D,wBAAgB,uBAAuB,IAAI,MAAM,CAQhD;AAED,MAAM,MAAM,cAAc,GAAG;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF;;;GAGG;AACH,wBAAgB,WAAW,CACzB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,GAAG,IAAI,EACrB,QAAQ,CAAC,EAAE,MAAM,GAChB,cAAc,EAAE,CA4BlB;AAED,wBAAgB,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAEpD"}
package/dist/git.js ADDED
@@ -0,0 +1,131 @@
1
+ // SPDX-FileCopyrightText: 2023-present Amazon.com, Inc. or its affiliates
2
+ //
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ import { spawnSync } from "node:child_process";
5
+ import * as fs from "node:fs";
6
+ export class GitError extends Error {
7
+ }
8
+ function runGit(args, stdio = "pipe") {
9
+ return spawnSync("git", args, {
10
+ stdio: stdio === "inherit" ? ["ignore", "inherit", "pipe"] : "pipe",
11
+ });
12
+ }
13
+ /** Archive the content of the folder into a repo.zip file. */
14
+ export function archive(options) {
15
+ const filePath = `${options.folder}/repo.zip`;
16
+ const result = runGit([
17
+ "archive",
18
+ "--format",
19
+ "zip",
20
+ "--output",
21
+ filePath,
22
+ options.ref,
23
+ ]);
24
+ if (result.status !== 0) {
25
+ throw new GitError((result.stderr ?? Buffer.alloc(0)).toString("utf8"));
26
+ }
27
+ return filePath;
28
+ }
29
+ /** Bundles the content of the folder into a sha.bundle file. */
30
+ export function bundle(options) {
31
+ const filePath = `${options.folder}/${options.sha}.bundle`;
32
+ const result = runGit(["bundle", "create", filePath, options.ref]);
33
+ if (result.status !== 0) {
34
+ throw new GitError((result.stderr ?? Buffer.alloc(0)).toString("utf8"));
35
+ }
36
+ return filePath;
37
+ }
38
+ /** Verifies that a bundle file is valid and can be applied to this repo. */
39
+ export function verify_bundle(filePath) {
40
+ const result = runGit(["bundle", "verify", filePath]);
41
+ if (result.status !== 0) {
42
+ throw new GitError((result.stderr ?? Buffer.alloc(0)).toString("utf8"));
43
+ }
44
+ }
45
+ /** Unbundles the content of the bundle referred by the sha. */
46
+ export function unbundle(options) {
47
+ const result = spawnSync("git", ["bundle", "unbundle", `${options.folder}/${options.sha}.bundle`, options.ref], { stdio: ["ignore", "inherit", "pipe"] });
48
+ if (result.status !== 0) {
49
+ throw new GitError((result.stderr ?? Buffer.alloc(0)).toString("utf8"));
50
+ }
51
+ }
52
+ /** Gets the sha of a ref. */
53
+ export function rev_parse(ref) {
54
+ const result = spawnSync("git", ["rev-parse", ref], { stdio: "pipe" });
55
+ if (result.status !== 0) {
56
+ throw new GitError(`fatal: ${ref} not found`);
57
+ }
58
+ return (result.stdout ?? Buffer.alloc(0)).toString("utf8").trim();
59
+ }
60
+ /** Checks if the ancestor is an ancestor of the descendant. */
61
+ export function is_ancestor(ancestor, descendant) {
62
+ const result = spawnSync("git", ["merge-base", "--is-ancestor", ancestor, descendant], { stdio: "ignore" });
63
+ return result.status === 0;
64
+ }
65
+ /** Gets the URL configured for a git remote. */
66
+ export function get_remote_url(remote) {
67
+ const result = spawnSync("git", ["remote", "get-url", remote], {
68
+ stdio: "pipe",
69
+ });
70
+ if (result.status !== 0) {
71
+ throw new GitError(`fatal: ${remote} not found`);
72
+ }
73
+ return (result.stdout ?? Buffer.alloc(0)).toString("utf8").trim();
74
+ }
75
+ // Validate refname according to
76
+ // https://github.com/git/git/blob/406f326d271e0bacecdb00425422c5fa3f314930/refs.c#L170
77
+ const INVALID_REF_CHARS_RE = /[:\?\[\]\\^\~\s\*]|[\x00-\x1f]/;
78
+ export function validate_ref_name(name) {
79
+ return !(name.startsWith(".") ||
80
+ name.includes("..") ||
81
+ INVALID_REF_CHARS_RE.test(name) ||
82
+ name.endsWith(".lock") ||
83
+ name.endsWith("/") ||
84
+ name.includes("@{"));
85
+ }
86
+ /** Gets the short sha and subject line of the last commit. */
87
+ export function get_last_commit_message() {
88
+ const result = spawnSync("git", ["log", "-1", "--pretty=%h %s"], {
89
+ stdio: "pipe",
90
+ });
91
+ if (result.status !== 0) {
92
+ throw new GitError("fatal: an error as occurred");
93
+ }
94
+ return (result.stdout ?? Buffer.alloc(0)).toString("utf8").trim();
95
+ }
96
+ /**
97
+ * Lists commits reachable from `newSha` but not from `notSha`, newest first.
98
+ * When `notSha` is null, lists the full history of `newSha`.
99
+ */
100
+ export function log_commits(newSha, notSha, maxCount) {
101
+ const args = ["log", "--format=%H%x1f%an%x1f%ae%x1f%aI%x1f%s"];
102
+ if (maxCount !== undefined) {
103
+ args.push(`--max-count=${maxCount}`);
104
+ }
105
+ args.push(newSha);
106
+ if (notSha !== null) {
107
+ args.push("--not", notSha);
108
+ }
109
+ const result = spawnSync("git", args, { stdio: "pipe" });
110
+ if (result.status !== 0) {
111
+ throw new GitError((result.stderr ?? Buffer.alloc(0)).toString("utf8"));
112
+ }
113
+ return (result.stdout ?? Buffer.alloc(0))
114
+ .toString("utf8")
115
+ .split(/\r?\n/)
116
+ .filter((line) => line.length > 0)
117
+ .map((line) => {
118
+ const [sha, authorName, authorEmail, authoredAt, message] = line.split("\x1f");
119
+ return {
120
+ sha: sha ?? "",
121
+ message: message ?? "",
122
+ authorName: authorName ?? "",
123
+ authorEmail: authorEmail ?? "",
124
+ authoredAt: authoredAt ?? "",
125
+ };
126
+ });
127
+ }
128
+ export function pathExists(filePath) {
129
+ return fs.existsSync(filePath);
130
+ }
131
+ //# sourceMappingURL=git.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"git.js","sourceRoot":"","sources":["../src/git.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,EAAE;AACF,sCAAsC;AAEtC,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAE9B,MAAM,OAAO,QAAS,SAAQ,KAAK;CAAG;AAEtC,SAAS,MAAM,CAAC,IAAc,EAAE,QAA4B,MAAM;IAChE,OAAO,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE;QAC5B,KAAK,EAAE,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM;KACpE,CAAC,CAAC;AACL,CAAC;AAED,8DAA8D;AAC9D,MAAM,UAAU,OAAO,CAAC,OAAwC;IAC9D,MAAM,QAAQ,GAAG,GAAG,OAAO,CAAC,MAAM,WAAW,CAAC;IAC9C,MAAM,MAAM,GAAG,MAAM,CAAC;QACpB,SAAS;QACT,UAAU;QACV,KAAK;QACL,UAAU;QACV,QAAQ;QACR,OAAO,CAAC,GAAG;KACZ,CAAC,CAAC;IACH,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxB,MAAM,IAAI,QAAQ,CA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AAE,UAAU,IAAI,EAAE;SAC7B,CAAC;IACJ,CAAC,CAAC,CAAC;AACP,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,QAAgB;IACzC,OAAO,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;AACjC,CAAC"}
@@ -0,0 +1,9 @@
1
+ export { S3Remote } from "./remote.js";
2
+ export * as git from "./git.js";
3
+ export { parse_git_url, synthetic_lfs_url, LFS_ALIAS_HOST } from "./common.js";
4
+ export { main as manage_main } from "./manage.js";
5
+ export { UriScheme } from "./enums.js";
6
+ export { LFSProcess, install as lfs_install } from "./lfs.js";
7
+ export { S3AgApiClient, ApiError } from "./api.js";
8
+ export { load_config, save_config } from "./config.js";
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC/E,OAAO,EAAE,IAAI,IAAI,WAAW,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,UAAU,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,12 @@
1
+ // SPDX-FileCopyrightText: 2024-present s3ag contributors
2
+ //
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ export { S3Remote } from "./remote.js";
5
+ export * as git from "./git.js";
6
+ export { parse_git_url, synthetic_lfs_url, LFS_ALIAS_HOST } from "./common.js";
7
+ export { main as manage_main } from "./manage.js";
8
+ export { UriScheme } from "./enums.js";
9
+ export { LFSProcess, install as lfs_install } from "./lfs.js";
10
+ export { S3AgApiClient, ApiError } from "./api.js";
11
+ export { load_config, save_config } from "./config.js";
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,EAAE;AACF,sCAAsC;AAEtC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC/E,OAAO,EAAE,IAAI,IAAI,WAAW,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,UAAU,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC"}
package/dist/lfs.d.ts ADDED
@@ -0,0 +1,38 @@
1
+ import { S3AgApiClient } from "./api.js";
2
+ export declare function _resolve_git_dir(): string;
3
+ export declare function _configure_logging(): void;
4
+ export declare class ProgressPercentage {
5
+ private _seen_so_far;
6
+ private _lock;
7
+ readonly oid: string;
8
+ constructor(oid: string);
9
+ report(bytes_amount: number): Promise<void>;
10
+ }
11
+ export declare function write_error_event(options: {
12
+ oid: string;
13
+ error: string;
14
+ }): void;
15
+ export declare const lfs_process_hooks: {
16
+ resolve_git_dir: typeof _resolve_git_dir;
17
+ mkdir: (dir: string, options: {
18
+ recursive: boolean;
19
+ }) => string | undefined;
20
+ };
21
+ export declare class LFSProcess {
22
+ owner: string;
23
+ repo: string;
24
+ api: S3AgApiClient;
25
+ invalid: boolean;
26
+ constructor(s3uri: string);
27
+ upload(event: Record<string, unknown>): Promise<void>;
28
+ download(event: Record<string, unknown>): Promise<void>;
29
+ }
30
+ export declare function _git_config_get(key: string): string | null;
31
+ export declare function _git_config_set(key: string, value: string): void;
32
+ export declare function _list_git_remotes(): string[];
33
+ export declare function _resolve_s3_remote(remote_name: string): [string, string];
34
+ export declare function install(options?: {
35
+ remote_name?: string | null;
36
+ }): void;
37
+ export declare function main(argv?: string[]): Promise<void>;
38
+ //# sourceMappingURL=lfs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lfs.d.ts","sourceRoot":"","sources":["../src/lfs.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAMzC,wBAAgB,gBAAgB,IAAI,MAAM,CAIzC;AAED,wBAAgB,kBAAkB,IAAI,IAAI,CAUzC;AAMD,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,YAAY,CAAK;IACzB,OAAO,CAAC,KAAK,CAAoC;IACjD,SAAgB,GAAG,EAAE,MAAM,CAAC;gBAEhB,GAAG,EAAE,MAAM;IAIjB,MAAM,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAqBlD;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE;IACzC,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;CACf,GAAG,IAAI,CAQP;AAMD,eAAO,MAAM,iBAAiB;;iBAEf,MAAM,WAAW;QAAE,SAAS,EAAE,OAAO,CAAA;KAAE;CAErD,CAAC;AAEF,qBAAa,UAAU;IACd,KAAK,EAAG,MAAM,CAAC;IACf,IAAI,EAAG,MAAM,CAAC;IACd,GAAG,EAAG,aAAa,CAAC;IACpB,OAAO,UAAS;gBAEX,KAAK,EAAE,MAAM;IAkBnB,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAyFrD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;CA2E9D;AAMD,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAI1D;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAUhE;AAED,wBAAgB,iBAAiB,IAAI,MAAM,EAAE,CAO5C;AAED,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAuBxE;AAMD,wBAAgB,OAAO,CAAC,OAAO,GAAE;IAAE,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAAO,GAAG,IAAI,CAM3E;AAuDD,wBAAsB,IAAI,CAAC,IAAI,GAAE,MAAM,EAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAyFvE"}
package/dist/lfs.js ADDED
@@ -0,0 +1,426 @@
1
+ // SPDX-FileCopyrightText: 2024-present s3ag contributors
2
+ //
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ import * as fs from "node:fs";
5
+ import * as path from "node:path";
6
+ import * as readline from "node:readline";
7
+ import { Readable } from "node:stream";
8
+ import { pipeline } from "node:stream/promises";
9
+ import { spawnSync } from "node:child_process";
10
+ import { is_lfs_oid, parse_git_url, synthetic_lfs_url } from "./common.js";
11
+ import { SystemExit } from "./exit.js";
12
+ import { validate_ref_name } from "./git.js";
13
+ import { LOG_LEVELS, defaultLfsLogFile, logger } from "./logger.js";
14
+ import * as proc from "./process.js";
15
+ import { S3AgApiClient } from "./api.js";
16
+ // ---------------------------------------------------------------------------
17
+ // Logging configuration
18
+ // ---------------------------------------------------------------------------
19
+ export function _resolve_git_dir() {
20
+ return proc
21
+ .check_output(["git", "rev-parse", "--absolute-git-dir"], { text: true })
22
+ .trim();
23
+ }
24
+ export function _configure_logging() {
25
+ try {
26
+ const gitDir = _resolve_git_dir();
27
+ const logDir = path.join(gitDir, "lfs", "tmp");
28
+ fs.mkdirSync(logDir, { recursive: true });
29
+ logger.setFile(defaultLfsLogFile(gitDir));
30
+ logger.setLevel(LOG_LEVELS.ERROR);
31
+ }
32
+ catch {
33
+ logger.setLevel(LOG_LEVELS.ERROR);
34
+ }
35
+ }
36
+ // ---------------------------------------------------------------------------
37
+ // Progress reporting
38
+ // ---------------------------------------------------------------------------
39
+ export class ProgressPercentage {
40
+ _seen_so_far = 0;
41
+ _lock = Promise.resolve();
42
+ oid;
43
+ constructor(oid) {
44
+ this.oid = oid;
45
+ }
46
+ async report(bytes_amount) {
47
+ const previous = this._lock;
48
+ let release;
49
+ this._lock = new Promise((resolve) => {
50
+ release = resolve;
51
+ });
52
+ await previous;
53
+ try {
54
+ this._seen_so_far += bytes_amount;
55
+ process.stdout.write(`${JSON.stringify({
56
+ event: "progress",
57
+ oid: this.oid,
58
+ bytesSoFar: this._seen_so_far,
59
+ bytesSinceLast: bytes_amount,
60
+ })}\n`);
61
+ }
62
+ finally {
63
+ release();
64
+ }
65
+ }
66
+ }
67
+ export function write_error_event(options) {
68
+ process.stdout.write(`${JSON.stringify({
69
+ event: "complete",
70
+ oid: options.oid,
71
+ error: { code: 2, message: options.error },
72
+ })}\n`);
73
+ }
74
+ // ---------------------------------------------------------------------------
75
+ // LFSProcess — talks to s3ag-server LFS batch API, then uses presigned URLs
76
+ // ---------------------------------------------------------------------------
77
+ export const lfs_process_hooks = {
78
+ resolve_git_dir: _resolve_git_dir,
79
+ mkdir: (dir, options) => fs.mkdirSync(dir, options),
80
+ };
81
+ export class LFSProcess {
82
+ owner;
83
+ repo;
84
+ api;
85
+ invalid = false;
86
+ constructor(s3uri) {
87
+ const [, , bucket, prefix] = parse_git_url(s3uri);
88
+ if (bucket === null || prefix === null) {
89
+ logger.error(`s3 uri ${s3uri} is invalid`);
90
+ process.stdout.write(`${JSON.stringify({
91
+ error: { code: 32, message: `s3 uri ${s3uri} is invalid` },
92
+ })}\n`);
93
+ this.invalid = true;
94
+ return;
95
+ }
96
+ this.owner = bucket;
97
+ this.repo = prefix;
98
+ this.api = S3AgApiClient.fromConfig();
99
+ process.stdout.write("{}\n");
100
+ }
101
+ async upload(event) {
102
+ logger.debug("upload");
103
+ const oid = String(event["oid"]);
104
+ if (!is_lfs_oid(oid)) {
105
+ const message = `invalid LFS oid: ${oid}`;
106
+ logger.error(message);
107
+ write_error_event({ oid, error: message });
108
+ return;
109
+ }
110
+ try {
111
+ const filePath = String(event["path"]);
112
+ const stat = fs.statSync(filePath);
113
+ if (!stat.isFile()) {
114
+ throw new Error(`LFS object path is not a regular file: ${filePath}`);
115
+ }
116
+ const size = stat.size;
117
+ // Ask the server for a presigned upload URL
118
+ const batch = await this.api.lfsBatch(this.owner, this.repo, {
119
+ operation: "upload",
120
+ objects: [{ oid, size }],
121
+ });
122
+ const obj = batch.objects[0];
123
+ if (!obj)
124
+ throw new Error("LFS batch returned no objects");
125
+ if (obj.error) {
126
+ throw new Error(obj.error.message);
127
+ }
128
+ // Already exists on server — skip
129
+ if (!obj.actions || !obj.actions.upload) {
130
+ logger.debug("object already exists");
131
+ process.stdout.write(`${JSON.stringify({ event: "complete", oid })}\n`);
132
+ return;
133
+ }
134
+ const uploadAction = obj.actions.upload;
135
+ const headers = { ...uploadAction.header };
136
+ // Node's fetch does not infer the length of a stream body, and S3
137
+ // presigned URLs may be signed with Content-Length. Prefer the header
138
+ // provided by the server, falling back to the file size.
139
+ const hasContentLength = Object.keys(headers).some((name) => name.toLowerCase() === "content-length");
140
+ if (!hasContentLength) {
141
+ headers["Content-Length"] = String(size);
142
+ }
143
+ // Upload directly to S3 via presigned URL, streaming the file so that a
144
+ // multi-gigabyte LFS object never has to fit in memory.
145
+ const stream = fs.createReadStream(filePath);
146
+ let res;
147
+ try {
148
+ res = await fetch(uploadAction.href, {
149
+ method: "PUT",
150
+ body: stream,
151
+ headers,
152
+ duplex: "half",
153
+ });
154
+ }
155
+ catch (error) {
156
+ stream.destroy();
157
+ throw error;
158
+ }
159
+ if (!res.ok) {
160
+ stream.destroy();
161
+ throw new Error(`LFS upload failed: HTTP ${res.status}`);
162
+ }
163
+ // Report progress
164
+ const progress = new ProgressPercentage(oid);
165
+ await progress.report(size);
166
+ process.stdout.write(`${JSON.stringify({ event: "complete", oid })}\n`);
167
+ }
168
+ catch (error) {
169
+ logger.error(error);
170
+ write_error_event({
171
+ oid: String(event["oid"]),
172
+ error: error instanceof Error ? error.message : String(error),
173
+ });
174
+ }
175
+ }
176
+ async download(event) {
177
+ logger.debug("download");
178
+ const oid = String(event["oid"]);
179
+ if (!is_lfs_oid(oid)) {
180
+ const message = `invalid LFS oid: ${oid}`;
181
+ logger.error(message);
182
+ write_error_event({ oid, error: message });
183
+ return;
184
+ }
185
+ try {
186
+ const size = Number(event["size"] ?? 0);
187
+ // Ask the server for a presigned download URL
188
+ const batch = await this.api.lfsBatch(this.owner, this.repo, {
189
+ operation: "download",
190
+ objects: [{ oid, size }],
191
+ });
192
+ const obj = batch.objects[0];
193
+ if (!obj)
194
+ throw new Error("LFS batch returned no objects");
195
+ if (obj.error) {
196
+ throw new Error(obj.error.message);
197
+ }
198
+ if (!obj.actions || !obj.actions.download) {
199
+ throw new Error("No download URL provided by server");
200
+ }
201
+ const downloadAction = obj.actions.download;
202
+ const tempDir = path.join(lfs_process_hooks.resolve_git_dir(), "lfs", "tmp");
203
+ lfs_process_hooks.mkdir(tempDir, { recursive: true });
204
+ // Download directly from S3 via presigned URL, streaming the response
205
+ // body to disk instead of buffering the whole object in memory.
206
+ const res = await fetch(downloadAction.href);
207
+ if (!res.ok) {
208
+ throw new Error(`LFS download failed: HTTP ${res.status}`);
209
+ }
210
+ if (!res.body) {
211
+ throw new Error("LFS download failed: empty response body");
212
+ }
213
+ const destPath = path.join(tempDir, oid);
214
+ try {
215
+ await pipeline(Readable.fromWeb(res.body), fs.createWriteStream(destPath));
216
+ }
217
+ catch (error) {
218
+ fs.rmSync(destPath, { force: true });
219
+ throw error;
220
+ }
221
+ // Report progress
222
+ const progress = new ProgressPercentage(oid);
223
+ await progress.report(size);
224
+ process.stdout.write(`${JSON.stringify({
225
+ event: "complete",
226
+ oid,
227
+ path: destPath,
228
+ })}\n`);
229
+ }
230
+ catch (error) {
231
+ logger.error(error);
232
+ write_error_event({
233
+ oid: String(event["oid"]),
234
+ error: error instanceof Error ? error.message : String(error),
235
+ });
236
+ }
237
+ }
238
+ }
239
+ // ---------------------------------------------------------------------------
240
+ // Git config helpers
241
+ // ---------------------------------------------------------------------------
242
+ export function _git_config_get(key) {
243
+ const res = spawnSync("git", ["config", "--get", key], { stdio: "pipe" });
244
+ if (res.status !== 0)
245
+ return null;
246
+ return (res.stdout ?? Buffer.alloc(0)).toString("utf8").trim();
247
+ }
248
+ export function _git_config_set(key, value) {
249
+ const res = spawnSync("git", ["config", "--replace-all", key, value], {
250
+ stdio: "pipe",
251
+ });
252
+ if (res.status !== 0) {
253
+ process.stderr.write((res.stderr ?? Buffer.alloc(0)).toString("utf8").trim() + "\n");
254
+ throw new SystemExit(1);
255
+ }
256
+ }
257
+ export function _list_git_remotes() {
258
+ const res = spawnSync("git", ["remote"], { stdio: "pipe" });
259
+ if (res.status !== 0)
260
+ return [];
261
+ return (res.stdout ?? Buffer.alloc(0))
262
+ .toString("utf8")
263
+ .split(/\r?\n/)
264
+ .filter((r) => r.trim().length > 0);
265
+ }
266
+ export function _resolve_s3_remote(remote_name) {
267
+ const res = spawnSync("git", ["remote", "get-url", remote_name], {
268
+ stdio: "pipe",
269
+ });
270
+ if (res.status !== 0) {
271
+ process.stderr.write(`error: remote '${remote_name}' is not configured. ` +
272
+ `Add it first with: ` +
273
+ `git remote add ${remote_name} s3ag://<owner>/<repo>\n`);
274
+ throw new SystemExit(1);
275
+ }
276
+ const url = (res.stdout ?? Buffer.alloc(0)).toString("utf8").trim();
277
+ const [, , bucket, prefix] = parse_git_url(url);
278
+ if (bucket === null || prefix === null) {
279
+ process.stderr.write(`error: remote '${remote_name}' has URL '${url}', which is not ` +
280
+ `an s3ag:// or s3ag+zip:// URL. --remote can only scope LFS ` +
281
+ `configuration for s3ag remotes.\n`);
282
+ throw new SystemExit(1);
283
+ }
284
+ return [bucket, prefix];
285
+ }
286
+ // ---------------------------------------------------------------------------
287
+ // install
288
+ // ---------------------------------------------------------------------------
289
+ export function install(options = {}) {
290
+ if (options.remote_name === undefined || options.remote_name === null) {
291
+ _install_unscoped();
292
+ }
293
+ else {
294
+ _install_scoped(options.remote_name);
295
+ }
296
+ }
297
+ function _install_unscoped() {
298
+ const remotes = _list_git_remotes();
299
+ if (remotes.length > 1) {
300
+ process.stderr.write(`warning: multiple remotes configured (${remotes.join(", ")}); ` +
301
+ "'git-lfs-s3ag install' writes unscoped configuration that " +
302
+ "applies to ALL remotes. If any non-s3ag remote uses LFS, " +
303
+ "push/pull may fail. Use 'git-lfs-s3ag install --remote <name>' " +
304
+ "to scope to a single s3ag remote.\n");
305
+ }
306
+ _git_config_set("lfs.customtransfer.git-lfs-s3ag.path", "git-lfs-s3ag");
307
+ _git_config_set("lfs.standalonetransferagent", "git-lfs-s3ag");
308
+ process.stdout.write("git-lfs-s3ag installed\n");
309
+ }
310
+ function _install_scoped(remote_name) {
311
+ const [owner, repo] = _resolve_s3_remote(remote_name);
312
+ const lfsUrl = synthetic_lfs_url(owner, repo);
313
+ const existingLfsUrl = _git_config_get(`remote.${remote_name}.lfsurl`);
314
+ if (existingLfsUrl !== null && existingLfsUrl !== lfsUrl) {
315
+ process.stderr.write(`error: remote.${remote_name}.lfsurl is already set to ` +
316
+ `'${existingLfsUrl}'. git-lfs-s3ag will not overwrite an ` +
317
+ `existing LFS URL. If this was set in error, unset it with:\n` +
318
+ ` git config --unset remote.${remote_name}.lfsurl\n`);
319
+ throw new SystemExit(1);
320
+ }
321
+ if (_git_config_get("lfs.standalonetransferagent") !== null) {
322
+ process.stderr.write("warning: lfs.standalonetransferagent is set unscoped; this " +
323
+ "applies git-lfs-s3ag to ALL remotes and will defeat per-remote " +
324
+ "scoping. Unset it with:\n" +
325
+ " git config --unset lfs.standalonetransferagent\n");
326
+ }
327
+ _git_config_set("lfs.customtransfer.git-lfs-s3ag.path", "git-lfs-s3ag");
328
+ _git_config_set(`remote.${remote_name}.lfsurl`, lfsUrl);
329
+ _git_config_set(`lfs.${lfsUrl}.standalonetransferagent`, "git-lfs-s3ag");
330
+ process.stdout.write(`git-lfs-s3ag installed for remote '${remote_name}' ` +
331
+ `(LFS alias: ${lfsUrl})\n`);
332
+ }
333
+ // ---------------------------------------------------------------------------
334
+ // main — entry point for git-lfs-s3ag
335
+ // ---------------------------------------------------------------------------
336
+ export async function main(argv = process.argv) {
337
+ _configure_logging();
338
+ if (argv.length > 1) {
339
+ if (argv[1] === "install") {
340
+ let remoteName = null;
341
+ const args = argv.slice(2);
342
+ let i = 0;
343
+ while (i < args.length) {
344
+ if (args[i] === "--remote") {
345
+ if (i + 1 >= args.length) {
346
+ process.stderr.write("error: --remote requires a value\n");
347
+ throw new SystemExit(2);
348
+ }
349
+ remoteName = args[i + 1];
350
+ i += 2;
351
+ }
352
+ else {
353
+ process.stderr.write(`error: unknown argument to install: ${args[i]}\n`);
354
+ throw new SystemExit(2);
355
+ }
356
+ }
357
+ install({ remote_name: remoteName });
358
+ return;
359
+ }
360
+ else if (argv[1] === "debug") {
361
+ logger.setLevel(LOG_LEVELS.DEBUG);
362
+ }
363
+ else if (argv[1] === "enable-debug") {
364
+ spawnSync("git", [
365
+ "config",
366
+ "--add",
367
+ "lfs.customtransfer.git-lfs-s3ag.args",
368
+ "debug",
369
+ ]);
370
+ process.stdout.write("debug enabled\n");
371
+ return;
372
+ }
373
+ else if (argv[1] === "disable-debug") {
374
+ spawnSync("git", [
375
+ "config",
376
+ "--unset",
377
+ "lfs.customtransfer.git-lfs-s3ag.args",
378
+ ]);
379
+ process.stdout.write("debug disabled\n");
380
+ return;
381
+ }
382
+ else {
383
+ process.stdout.write(`unknown command ${argv[1]}\n`);
384
+ throw new SystemExit(1);
385
+ }
386
+ }
387
+ let lfsProcess = null;
388
+ const rl = readline.createInterface({
389
+ input: process.stdin,
390
+ crlfDelay: Infinity,
391
+ });
392
+ for await (const line of rl) {
393
+ logger.debug("git-lfs-s3ag starting");
394
+ logger.debug(line);
395
+ const event = JSON.parse(line);
396
+ if (event["event"] === "init") {
397
+ if (!validate_ref_name(String(event["remote"]))) {
398
+ logger.error(`invalid ref ${event["remote"]}`);
399
+ process.stdout.write("{}\n");
400
+ throw new SystemExit(1);
401
+ }
402
+ const result = spawnSync("git", ["remote", "get-url", String(event["remote"])], {
403
+ stdio: "pipe",
404
+ });
405
+ if (result.status !== 0) {
406
+ logger.error((result.stderr ?? Buffer.alloc(0)).toString("utf8").trim());
407
+ process.stdout.write(`${JSON.stringify({
408
+ error: {
409
+ code: 2,
410
+ message: `cannot resolve remote "${event["remote"]}"`,
411
+ },
412
+ })}`);
413
+ throw new SystemExit(1);
414
+ }
415
+ const s3uri = (result.stdout ?? Buffer.alloc(0)).toString("utf8").trim();
416
+ lfsProcess = new LFSProcess(s3uri);
417
+ }
418
+ else if (event["event"] === "upload") {
419
+ await lfsProcess?.upload(event);
420
+ }
421
+ else if (event["event"] === "download") {
422
+ await lfsProcess?.download(event);
423
+ }
424
+ }
425
+ }
426
+ //# sourceMappingURL=lfs.js.map