@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pierre/storage",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "Pierre Git Storage SDK",
5
5
  "license": "MIT",
6
6
  "type": "module",
package/src/index.ts CHANGED
@@ -24,6 +24,7 @@ import {
24
24
  listBranchesResponseSchema,
25
25
  listCommitsResponseSchema,
26
26
  listFilesResponseSchema,
27
+ listFilesWithMetadataResponseSchema,
27
28
  listReposResponseSchema,
28
29
  noteReadResponseSchema,
29
30
  noteWriteResponseSchema,
@@ -36,6 +37,7 @@ import type {
36
37
  BranchInfo,
37
38
  CommitBuilder,
38
39
  CommitInfo,
40
+ CommitMetadata,
39
41
  CommitResult,
40
42
  CreateBranchOptions,
41
43
  CreateBranchResponse,
@@ -48,6 +50,7 @@ import type {
48
50
  DeleteRepoOptions,
49
51
  DeleteRepoResult,
50
52
  DiffFileState,
53
+ FileWithMetadata,
51
54
  FileDiff,
52
55
  FilteredFile,
53
56
  FindOneOptions,
@@ -74,13 +77,18 @@ import type {
74
77
  ListCommitsResult,
75
78
  ListFilesOptions,
76
79
  ListFilesResult,
80
+ ListFilesWithMetadataOptions,
81
+ ListFilesWithMetadataResponse,
82
+ ListFilesWithMetadataResult,
77
83
  ListReposOptions,
78
84
  ListReposResponse,
79
85
  ListReposResult,
80
86
  NoteWriteResult,
81
87
  PullUpstreamOptions,
82
88
  RawBranchInfo,
89
+ RawCommitMetadata,
83
90
  RawCommitInfo,
91
+ RawFileWithMetadata,
84
92
  RawFileDiff,
85
93
  RawFilteredFile,
86
94
  RefUpdate,
@@ -311,6 +319,39 @@ function transformListCommitsResult(
311
319
  };
312
320
  }
313
321
 
322
+ function transformFileWithMetadata(raw: RawFileWithMetadata): FileWithMetadata {
323
+ return {
324
+ path: raw.path,
325
+ mode: raw.mode,
326
+ size: raw.size,
327
+ lastCommitSha: raw.last_commit_sha,
328
+ };
329
+ }
330
+
331
+ function transformCommitMetadata(raw: RawCommitMetadata): CommitMetadata {
332
+ return {
333
+ author: raw.author,
334
+ date: new Date(raw.date),
335
+ rawDate: raw.date,
336
+ message: raw.message,
337
+ };
338
+ }
339
+
340
+ function transformListFilesWithMetadataResult(
341
+ raw: ListFilesWithMetadataResponse
342
+ ): ListFilesWithMetadataResult {
343
+ const commits: Record<string, CommitMetadata> = {};
344
+ for (const [sha, commit] of Object.entries(raw.commits)) {
345
+ commits[sha] = transformCommitMetadata(commit);
346
+ }
347
+
348
+ return {
349
+ files: raw.files.map(transformFileWithMetadata),
350
+ commits,
351
+ ref: raw.ref,
352
+ };
353
+ }
354
+
314
355
  function normalizeDiffState(rawState: string): DiffFileState {
315
356
  if (!rawState) {
316
357
  return 'unknown';
@@ -676,6 +717,34 @@ class RepoImpl implements Repo {
676
717
  return { paths: raw.paths, ref: raw.ref };
677
718
  }
678
719
 
720
+ async listFilesWithMetadata(
721
+ options?: ListFilesWithMetadataOptions
722
+ ): Promise<ListFilesWithMetadataResult> {
723
+ const ttl = resolveInvocationTtlSeconds(options, DEFAULT_TOKEN_TTL_SECONDS);
724
+ const jwt = await this.generateJWT(this.id, {
725
+ permissions: ['git:read'],
726
+ ttl,
727
+ });
728
+
729
+ const params: Record<string, string> = {};
730
+ if (options?.ref) {
731
+ params.ref = options.ref;
732
+ }
733
+ if (typeof options?.ephemeral === 'boolean') {
734
+ params.ephemeral = String(options.ephemeral);
735
+ }
736
+ const response = await this.api.get(
737
+ {
738
+ path: 'repos/files/metadata',
739
+ params: Object.keys(params).length ? params : undefined,
740
+ },
741
+ jwt
742
+ );
743
+
744
+ const raw = listFilesWithMetadataResponseSchema.parse(await response.json());
745
+ return transformListFilesWithMetadataResult(raw);
746
+ }
747
+
679
748
  async listBranches(
680
749
  options?: ListBranchesOptions
681
750
  ): Promise<ListBranchesResult> {
package/src/schemas.ts CHANGED
@@ -5,6 +5,25 @@ export const listFilesResponseSchema = z.object({
5
5
  ref: z.string(),
6
6
  });
7
7
 
8
+ export const fileWithMetadataRawSchema = z.object({
9
+ path: z.string(),
10
+ mode: z.string(),
11
+ size: z.number(),
12
+ last_commit_sha: z.string(),
13
+ });
14
+
15
+ export const commitMetadataRawSchema = z.object({
16
+ author: z.string(),
17
+ date: z.string(),
18
+ message: z.string(),
19
+ });
20
+
21
+ export const listFilesWithMetadataResponseSchema = z.object({
22
+ files: z.array(fileWithMetadataRawSchema),
23
+ commits: z.record(commitMetadataRawSchema),
24
+ ref: z.string(),
25
+ });
26
+
8
27
  export const branchInfoSchema = z.object({
9
28
  cursor: z.string(),
10
29
  name: z.string(),
@@ -202,6 +221,11 @@ export const errorEnvelopeSchema = z.object({
202
221
  });
203
222
 
204
223
  export type ListFilesResponseRaw = z.infer<typeof listFilesResponseSchema>;
224
+ export type RawFileWithMetadata = z.infer<typeof fileWithMetadataRawSchema>;
225
+ export type RawCommitMetadata = z.infer<typeof commitMetadataRawSchema>;
226
+ export type ListFilesWithMetadataResponseRaw = z.infer<
227
+ typeof listFilesWithMetadataResponseSchema
228
+ >;
205
229
  export type RawBranchInfo = z.infer<typeof branchInfoSchema>;
206
230
  export type ListBranchesResponseRaw = z.infer<
207
231
  typeof listBranchesResponseSchema
package/src/types.ts CHANGED
@@ -8,11 +8,14 @@ import type {
8
8
  ListBranchesResponseRaw,
9
9
  ListCommitsResponseRaw,
10
10
  ListFilesResponseRaw,
11
+ ListFilesWithMetadataResponseRaw,
11
12
  ListReposResponseRaw,
12
13
  NoteReadResponseRaw,
13
14
  NoteWriteResponseRaw,
14
15
  RawBranchInfo as SchemaRawBranchInfo,
16
+ RawCommitMetadata as SchemaRawCommitMetadata,
15
17
  RawCommitInfo as SchemaRawCommitInfo,
18
+ RawFileWithMetadata as SchemaRawFileWithMetadata,
16
19
  RawFileDiff as SchemaRawFileDiff,
17
20
  RawFilteredFile as SchemaRawFilteredFile,
18
21
  RawRepoBaseInfo as SchemaRawRepoBaseInfo,
@@ -49,6 +52,9 @@ export interface Repo {
49
52
  getFileStream(options: GetFileOptions): Promise<Response>;
50
53
  getArchiveStream(options?: ArchiveOptions): Promise<Response>;
51
54
  listFiles(options?: ListFilesOptions): Promise<ListFilesResult>;
55
+ listFilesWithMetadata(
56
+ options?: ListFilesWithMetadataOptions
57
+ ): Promise<ListFilesWithMetadataResult>;
52
58
  listBranches(options?: ListBranchesOptions): Promise<ListBranchesResult>;
53
59
  listCommits(options?: ListCommitsOptions): Promise<ListCommitsResult>;
54
60
  getNote(options: GetNoteOptions): Promise<GetNoteResult>;
@@ -196,6 +202,37 @@ export interface ListFilesResult {
196
202
  ref: string;
197
203
  }
198
204
 
205
+ export interface ListFilesWithMetadataOptions extends GitStorageInvocationOptions {
206
+ ref?: string;
207
+ ephemeral?: boolean;
208
+ }
209
+
210
+ export type RawFileWithMetadata = SchemaRawFileWithMetadata;
211
+
212
+ export interface FileWithMetadata {
213
+ path: string;
214
+ mode: string;
215
+ size: number;
216
+ lastCommitSha: string;
217
+ }
218
+
219
+ export type RawCommitMetadata = SchemaRawCommitMetadata;
220
+
221
+ export interface CommitMetadata {
222
+ author: string;
223
+ date: Date;
224
+ rawDate: string;
225
+ message: string;
226
+ }
227
+
228
+ export type ListFilesWithMetadataResponse = ListFilesWithMetadataResponseRaw;
229
+
230
+ export interface ListFilesWithMetadataResult {
231
+ files: FileWithMetadata[];
232
+ commits: Record<string, CommitMetadata>;
233
+ ref: string;
234
+ }
235
+
199
236
  // List Branches API types
200
237
  export interface ListBranchesOptions extends GitStorageInvocationOptions {
201
238
  cursor?: string;