@pierre/storage 1.1.0 → 1.2.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/README.md CHANGED
@@ -182,6 +182,13 @@ const files = await repo.listFiles({
182
182
  });
183
183
  console.log(files.paths); // Array of file paths
184
184
 
185
+ // List files with mode/size and last commit metadata
186
+ const metadata = await repo.listFilesWithMetadata({
187
+ ref: 'main',
188
+ });
189
+ console.log(metadata.files[0].lastCommitSha);
190
+ console.log(metadata.commits[metadata.files[0].lastCommitSha].author);
191
+
185
192
  // List branches
186
193
  const branches = await repo.listBranches({
187
194
  limit: 10,
@@ -431,6 +438,9 @@ interface Repo {
431
438
  getFileStream(options: GetFileOptions): Promise<Response>;
432
439
  getArchiveStream(options?: ArchiveOptions): Promise<Response>;
433
440
  listFiles(options?: ListFilesOptions): Promise<ListFilesResult>;
441
+ listFilesWithMetadata(
442
+ options?: ListFilesWithMetadataOptions
443
+ ): Promise<ListFilesWithMetadataResult>;
434
444
  listBranches(options?: ListBranchesOptions): Promise<ListBranchesResult>;
435
445
  listCommits(options?: ListCommitsOptions): Promise<ListCommitsResult>;
436
446
  getNote(options: GetNoteOptions): Promise<GetNoteResult>;
@@ -467,6 +477,7 @@ interface ArchiveOptions {
467
477
 
468
478
  interface ListFilesOptions {
469
479
  ref?: string; // Branch, tag, or commit SHA
480
+ ephemeral?: boolean; // Resolve ref in ephemeral namespace
470
481
  ttl?: number;
471
482
  }
472
483
 
@@ -480,6 +491,32 @@ interface ListFilesResult {
480
491
  ref: string;
481
492
  }
482
493
 
494
+ interface ListFilesWithMetadataOptions {
495
+ ref?: string; // Branch, tag, or commit SHA
496
+ ephemeral?: boolean; // Resolve ref in ephemeral namespace
497
+ ttl?: number;
498
+ }
499
+
500
+ interface FileWithMetadata {
501
+ path: string;
502
+ mode: string;
503
+ size: number;
504
+ lastCommitSha: string;
505
+ }
506
+
507
+ interface CommitMetadata {
508
+ author: string;
509
+ date: Date;
510
+ rawDate: string;
511
+ message: string;
512
+ }
513
+
514
+ interface ListFilesWithMetadataResult {
515
+ files: FileWithMetadata[];
516
+ commits: Record<string, CommitMetadata>;
517
+ ref: string;
518
+ }
519
+
483
520
  interface GetNoteOptions {
484
521
  sha: string; // Commit SHA to look up notes for
485
522
  ttl?: number;
package/dist/index.cjs CHANGED
@@ -51,6 +51,22 @@ var listFilesResponseSchema = zod.z.object({
51
51
  paths: zod.z.array(zod.z.string()),
52
52
  ref: zod.z.string()
53
53
  });
54
+ var fileWithMetadataRawSchema = zod.z.object({
55
+ path: zod.z.string(),
56
+ mode: zod.z.string(),
57
+ size: zod.z.number(),
58
+ last_commit_sha: zod.z.string()
59
+ });
60
+ var commitMetadataRawSchema = zod.z.object({
61
+ author: zod.z.string(),
62
+ date: zod.z.string(),
63
+ message: zod.z.string()
64
+ });
65
+ var listFilesWithMetadataResponseSchema = zod.z.object({
66
+ files: zod.z.array(fileWithMetadataRawSchema),
67
+ commits: zod.z.record(commitMetadataRawSchema),
68
+ ref: zod.z.string()
69
+ });
54
70
  var branchInfoSchema = zod.z.object({
55
71
  cursor: zod.z.string(),
56
72
  name: zod.z.string(),
@@ -514,7 +530,7 @@ function concatChunks(a, b) {
514
530
 
515
531
  // package.json
516
532
  var package_default = {
517
- version: "1.1.0"};
533
+ version: "1.2.0"};
518
534
 
519
535
  // src/version.ts
520
536
  var PACKAGE_NAME = "code-storage-sdk";
@@ -1567,6 +1583,33 @@ function transformListCommitsResult(raw) {
1567
1583
  hasMore: raw.has_more
1568
1584
  };
1569
1585
  }
1586
+ function transformFileWithMetadata(raw) {
1587
+ return {
1588
+ path: raw.path,
1589
+ mode: raw.mode,
1590
+ size: raw.size,
1591
+ lastCommitSha: raw.last_commit_sha
1592
+ };
1593
+ }
1594
+ function transformCommitMetadata(raw) {
1595
+ return {
1596
+ author: raw.author,
1597
+ date: new Date(raw.date),
1598
+ rawDate: raw.date,
1599
+ message: raw.message
1600
+ };
1601
+ }
1602
+ function transformListFilesWithMetadataResult(raw) {
1603
+ const commits = {};
1604
+ for (const [sha, commit] of Object.entries(raw.commits)) {
1605
+ commits[sha] = transformCommitMetadata(commit);
1606
+ }
1607
+ return {
1608
+ files: raw.files.map(transformFileWithMetadata),
1609
+ commits,
1610
+ ref: raw.ref
1611
+ };
1612
+ }
1570
1613
  function normalizeDiffState(rawState) {
1571
1614
  if (!rawState) {
1572
1615
  return "unknown";
@@ -1851,6 +1894,29 @@ var RepoImpl = class {
1851
1894
  const raw = listFilesResponseSchema.parse(await response.json());
1852
1895
  return { paths: raw.paths, ref: raw.ref };
1853
1896
  }
1897
+ async listFilesWithMetadata(options) {
1898
+ const ttl = resolveInvocationTtlSeconds(options, DEFAULT_TOKEN_TTL_SECONDS);
1899
+ const jwt = await this.generateJWT(this.id, {
1900
+ permissions: ["git:read"],
1901
+ ttl
1902
+ });
1903
+ const params = {};
1904
+ if (options?.ref) {
1905
+ params.ref = options.ref;
1906
+ }
1907
+ if (typeof options?.ephemeral === "boolean") {
1908
+ params.ephemeral = String(options.ephemeral);
1909
+ }
1910
+ const response = await this.api.get(
1911
+ {
1912
+ path: "repos/files/metadata",
1913
+ params: Object.keys(params).length ? params : void 0
1914
+ },
1915
+ jwt
1916
+ );
1917
+ const raw = listFilesWithMetadataResponseSchema.parse(await response.json());
1918
+ return transformListFilesWithMetadataResult(raw);
1919
+ }
1854
1920
  async listBranches(options) {
1855
1921
  const ttl = resolveInvocationTtlSeconds(options, DEFAULT_TOKEN_TTL_SECONDS);
1856
1922
  const jwt = await this.generateJWT(this.id, {