@pierre/storage 1.1.0 → 1.2.1

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,7 +1,11 @@
1
1
  {
2
2
  "name": "@pierre/storage",
3
- "version": "1.1.0",
3
+ "version": "1.2.1",
4
4
  "description": "Pierre Git Storage SDK",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/pierrecomputer/sdk"
8
+ },
5
9
  "license": "MIT",
6
10
  "type": "module",
7
11
  "main": "./dist/index.cjs",
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';
@@ -637,6 +678,9 @@ class RepoImpl implements Repo {
637
678
  if (Array.isArray(options.excludeGlobs) && options.excludeGlobs.length > 0) {
638
679
  body.exclude_globs = options.excludeGlobs;
639
680
  }
681
+ if (typeof options.maxBlobSize === 'number' && Number.isFinite(options.maxBlobSize)) {
682
+ body.max_blob_size = options.maxBlobSize;
683
+ }
640
684
  if (typeof options.archivePrefix === 'string') {
641
685
  const prefix = options.archivePrefix.trim();
642
686
  if (prefix) {
@@ -676,6 +720,34 @@ class RepoImpl implements Repo {
676
720
  return { paths: raw.paths, ref: raw.ref };
677
721
  }
678
722
 
723
+ async listFilesWithMetadata(
724
+ options?: ListFilesWithMetadataOptions
725
+ ): Promise<ListFilesWithMetadataResult> {
726
+ const ttl = resolveInvocationTtlSeconds(options, DEFAULT_TOKEN_TTL_SECONDS);
727
+ const jwt = await this.generateJWT(this.id, {
728
+ permissions: ['git:read'],
729
+ ttl,
730
+ });
731
+
732
+ const params: Record<string, string> = {};
733
+ if (options?.ref) {
734
+ params.ref = options.ref;
735
+ }
736
+ if (typeof options?.ephemeral === 'boolean') {
737
+ params.ephemeral = String(options.ephemeral);
738
+ }
739
+ const response = await this.api.get(
740
+ {
741
+ path: 'repos/files/metadata',
742
+ params: Object.keys(params).length ? params : undefined,
743
+ },
744
+ jwt
745
+ );
746
+
747
+ const raw = listFilesWithMetadataResponseSchema.parse(await response.json());
748
+ return transformListFilesWithMetadataResult(raw);
749
+ }
750
+
679
751
  async listBranches(
680
752
  options?: ListBranchesOptions
681
753
  ): 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>;
@@ -176,6 +182,7 @@ export interface ArchiveOptions extends GitStorageInvocationOptions {
176
182
  ref?: string;
177
183
  includeGlobs?: string[];
178
184
  excludeGlobs?: string[];
185
+ maxBlobSize?: number;
179
186
  archivePrefix?: string;
180
187
  }
181
188
 
@@ -196,6 +203,37 @@ export interface ListFilesResult {
196
203
  ref: string;
197
204
  }
198
205
 
206
+ export interface ListFilesWithMetadataOptions extends GitStorageInvocationOptions {
207
+ ref?: string;
208
+ ephemeral?: boolean;
209
+ }
210
+
211
+ export type RawFileWithMetadata = SchemaRawFileWithMetadata;
212
+
213
+ export interface FileWithMetadata {
214
+ path: string;
215
+ mode: string;
216
+ size: number;
217
+ lastCommitSha: string;
218
+ }
219
+
220
+ export type RawCommitMetadata = SchemaRawCommitMetadata;
221
+
222
+ export interface CommitMetadata {
223
+ author: string;
224
+ date: Date;
225
+ rawDate: string;
226
+ message: string;
227
+ }
228
+
229
+ export type ListFilesWithMetadataResponse = ListFilesWithMetadataResponseRaw;
230
+
231
+ export interface ListFilesWithMetadataResult {
232
+ files: FileWithMetadata[];
233
+ commits: Record<string, CommitMetadata>;
234
+ ref: string;
235
+ }
236
+
199
237
  // List Branches API types
200
238
  export interface ListBranchesOptions extends GitStorageInvocationOptions {
201
239
  cursor?: string;