@pierre/storage 0.0.11 → 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/README.md CHANGED
@@ -123,31 +123,50 @@ console.log(commitDiff.files);
123
123
 
124
124
  // Create a commit using the streaming helper
125
125
  const fs = await import('node:fs/promises');
126
- const response = await repo
126
+ const result = await repo
127
127
  .createCommit({
128
128
  targetRef: 'refs/heads/main',
129
129
  commitMessage: 'Update docs',
130
+ author: { name: 'Docs Bot', email: 'docs@example.com' },
130
131
  })
131
132
  .addFileFromString('docs/changelog.md', '# v2.0.1\n- add streaming SDK\n')
132
133
  .addFile('docs/readme.md', await fs.readFile('README.md'))
133
134
  .deletePath('docs/legacy.txt')
134
135
  .send();
135
136
 
136
- console.log(response.commit.commit_sha);
137
- console.log(response.result.new_sha);
138
- console.log(response.result.old_sha); // 40 hex chars; all zeroes for brand-new branches
137
+ console.log(result.commitSha);
138
+ console.log(result.refUpdate.newSha);
139
+ console.log(result.refUpdate.oldSha); // All zeroes when the ref is created
139
140
  ```
140
141
 
141
142
  The builder exposes:
142
143
 
143
- - `addFile(path, source, options)` to attach bytes, async iterables, readable streams, or buffers.
144
- - `addFileFromString(path, contents, options)` for UTF-8 text helpers.
144
+ - `addFile(path, source, options)` to attach bytes from strings, typed arrays, ArrayBuffers, `Blob`
145
+ or `File` objects, `ReadableStream`s, or iterable/async-iterable sources.
146
+ - `addFileFromString(path, contents, options)` for text helpers (defaults to UTF-8 and accepts any
147
+ Node.js `BufferEncoding`).
145
148
  - `deletePath(path)` to remove files or folders.
146
149
  - `send()` to finalize the commit and receive metadata about the new commit.
147
150
 
148
- `send()` resolves to `{ commit, result }`. The `result` payload mirrors the HTTP response, including
149
- `old_sha` (always a 40-character hex string; it is all zeroes when the target ref is being created),
150
- `new_sha`, `status`, and an optional `message`.
151
+ `send()` resolves to an object with the new commit metadata plus the ref update:
152
+
153
+ ```ts
154
+ type CommitResult = {
155
+ commitSha: string;
156
+ treeSha: string;
157
+ targetRef: string;
158
+ packBytes: number;
159
+ blobCount: number;
160
+ refUpdate: {
161
+ ref: string;
162
+ oldSha: string; // All zeroes when the ref is created
163
+ newSha: string;
164
+ };
165
+ };
166
+ ```
167
+
168
+ If the backend reports a failure (for example, the branch advanced past `baseRef`) the builder
169
+ throws a `RefUpdateError` containing the status, reason, and ref details.
151
170
 
152
171
  **Options**
153
172
 
@@ -156,35 +175,16 @@ The builder exposes:
156
175
  - `baseRef` (optional): Branch or commit that must match the remote tip; omit to fast-forward
157
176
  unconditionally.
158
177
  - `commitMessage` (required): The commit message.
159
- - `author` and `committer` (optional): Include `name`, `email`, and optional ISO 8601 `date`.
178
+ - `author` (required): Include `name` and `email` for the commit author.
179
+ - `committer` (optional): Include `name` and `email`. If omitted, the author identity is reused.
160
180
  - `signal` (optional): Abort an in-flight upload with `AbortController`.
161
181
 
162
182
  > Files are chunked into 4 MiB segments under the hood, so you can stream large assets without
163
183
  > buffering them entirely in memory. File paths are normalized relative to the repository root.
164
184
 
165
- ### Creating a new branch
166
-
167
- You can create and populate a new branch in a single request by pointing `targetRef` at the new ref
168
- and setting `baseRef` to the branch (or commit SHA) you want to fork from.
169
-
170
- ```typescript
171
- const baseBranch = 'main';
172
- const featureBranch = 'refs/heads/feature/onboarding';
173
-
174
- await repo
175
- .createCommit({
176
- targetRef: featureBranch,
177
- baseRef: `refs/heads/${baseBranch}`,
178
- commitMessage: 'feat: add onboarding copy',
179
- })
180
- .addFileFromString('apps/dashboard/Onboarding.tsx', '<Onboarding />\n')
181
- .send();
182
- ```
183
-
184
- > If you omit `baseRef` while referencing a brand-new `targetRef`, the service creates an orphan
185
- > commit with no parent. The new branch starts from an empty tree, so only the files you include in
186
- > this commit will exist. Always provide `baseRef` when you need the branch to inherit history or
187
- > files from another branch.
185
+ > The `targetRef` must already exist on the remote repository. To seed an empty repository, point to
186
+ > the default branch and omit `baseRef`; the service will create the first commit only when no refs
187
+ > are present.
188
188
 
189
189
  ### Streaming Large Files
190
190
 
@@ -199,6 +199,7 @@ await repo
199
199
  targetRef: 'refs/heads/assets',
200
200
  baseRef: 'refs/heads/main',
201
201
  commitMessage: 'Upload latest design bundle',
202
+ author: { name: 'Assets Uploader', email: 'assets@example.com' },
202
203
  })
203
204
  .addFile('assets/design-kit.zip', createReadStream('/tmp/design-kit.zip'))
204
205
  .send();
@@ -223,6 +224,7 @@ class GitStorage {
223
224
  interface GitStorageOptions {
224
225
  name: string; // Your identifier
225
226
  key: string; // Your API key
227
+ defaultTTL?: number; // Default TTL for generated JWTs (seconds)
226
228
  }
227
229
 
228
230
  interface CreateRepoOptions {
@@ -238,11 +240,11 @@ interface Repo {
238
240
  getRemoteURL(options?: GetRemoteURLOptions): Promise<string>;
239
241
 
240
242
  getFileStream(options: GetFileOptions): Promise<Response>;
241
- listFiles(options?: ListFilesOptions): Promise<ListFilesResponse>;
242
- listBranches(options?: ListBranchesOptions): Promise<ListBranchesResponse>;
243
- listCommits(options?: ListCommitsOptions): Promise<ListCommitsResponse>;
244
- getBranchDiff(options: GetBranchDiffOptions): Promise<GetBranchDiffResponse>;
245
- getCommitDiff(options: GetCommitDiffOptions): Promise<GetCommitDiffResponse>;
243
+ listFiles(options?: ListFilesOptions): Promise<ListFilesResult>;
244
+ listBranches(options?: ListBranchesOptions): Promise<ListBranchesResult>;
245
+ listCommits(options?: ListCommitsOptions): Promise<ListCommitsResult>;
246
+ getBranchDiff(options: GetBranchDiffOptions): Promise<GetBranchDiffResult>;
247
+ getCommitDiff(options: GetCommitDiffOptions): Promise<GetCommitDiffResult>;
246
248
  }
247
249
 
248
250
  interface GetRemoteURLOptions {
@@ -254,12 +256,14 @@ interface GetRemoteURLOptions {
254
256
  interface GetFileOptions {
255
257
  path: string;
256
258
  ref?: string; // Branch, tag, or commit SHA
259
+ ttl?: number;
257
260
  }
258
261
 
259
262
  // getFileStream() returns a standard Fetch Response for streaming bytes
260
263
 
261
264
  interface ListFilesOptions {
262
265
  ref?: string; // Branch, tag, or commit SHA
266
+ ttl?: number;
263
267
  }
264
268
 
265
269
  interface ListFilesResponse {
@@ -267,53 +271,75 @@ interface ListFilesResponse {
267
271
  ref: string; // The resolved reference
268
272
  }
269
273
 
274
+ interface ListFilesResult {
275
+ paths: string[];
276
+ ref: string;
277
+ }
278
+
270
279
  interface ListBranchesOptions {
271
280
  cursor?: string;
272
281
  limit?: number;
282
+ ttl?: number;
273
283
  }
274
284
 
275
285
  interface ListBranchesResponse {
276
286
  branches: BranchInfo[];
277
- next_cursor?: string;
278
- has_more: boolean;
287
+ nextCursor?: string;
288
+ hasMore: boolean;
289
+ }
290
+
291
+ interface ListBranchesResult {
292
+ branches: BranchInfo[];
293
+ nextCursor?: string;
294
+ hasMore: boolean;
279
295
  }
280
296
 
281
297
  interface BranchInfo {
282
298
  cursor: string;
283
299
  name: string;
284
- head_sha: string;
285
- created_at: string;
300
+ headSha: string;
301
+ createdAt: string;
286
302
  }
287
303
 
288
304
  interface ListCommitsOptions {
289
305
  branch?: string;
290
306
  cursor?: string;
291
307
  limit?: number;
308
+ ttl?: number;
292
309
  }
293
310
 
294
311
  interface ListCommitsResponse {
295
312
  commits: CommitInfo[];
296
- next_cursor?: string;
297
- has_more: boolean;
313
+ nextCursor?: string;
314
+ hasMore: boolean;
315
+ }
316
+
317
+ interface ListCommitsResult {
318
+ commits: CommitInfo[];
319
+ nextCursor?: string;
320
+ hasMore: boolean;
298
321
  }
299
322
 
300
323
  interface CommitInfo {
301
324
  sha: string;
302
325
  message: string;
303
- author_name: string;
304
- author_email: string;
305
- committer_name: string;
306
- committer_email: string;
307
- date: string;
326
+ authorName: string;
327
+ authorEmail: string;
328
+ committerName: string;
329
+ committerEmail: string;
330
+ date: Date;
331
+ rawDate: string;
308
332
  }
309
333
 
310
334
  interface GetBranchDiffOptions {
311
335
  branch: string;
312
336
  base?: string; // Defaults to 'main'
337
+ ttl?: number;
313
338
  }
314
339
 
315
340
  interface GetCommitDiffOptions {
316
341
  sha: string;
342
+ ttl?: number;
317
343
  }
318
344
 
319
345
  interface GetBranchDiffResponse {
@@ -321,16 +347,30 @@ interface GetBranchDiffResponse {
321
347
  base: string;
322
348
  stats: DiffStats;
323
349
  files: FileDiff[];
324
- filtered_files: FilteredFile[];
350
+ filteredFiles: FilteredFile[];
351
+ }
352
+
353
+ interface GetBranchDiffResult {
354
+ branch: string;
355
+ base: string;
356
+ stats: DiffStats;
357
+ files: FileDiff[];
358
+ filteredFiles: FilteredFile[];
325
359
  }
326
360
 
327
361
  interface GetCommitDiffResponse {
328
362
  sha: string;
329
363
  stats: DiffStats;
330
364
  files: FileDiff[];
331
- filtered_files: FilteredFile[];
365
+ filteredFiles: FilteredFile[];
332
366
  }
333
367
 
368
+ interface GetCommitDiffResult {
369
+ sha: string;
370
+ stats: DiffStats;
371
+ files: FileDiff[];
372
+ filteredFiles: FilteredFile[];
373
+ }
334
374
  interface DiffStats {
335
375
  files: number;
336
376
  additions: number;
@@ -338,21 +378,78 @@ interface DiffStats {
338
378
  changes: number;
339
379
  }
340
380
 
381
+ type DiffFileState =
382
+ | 'added'
383
+ | 'modified'
384
+ | 'deleted'
385
+ | 'renamed'
386
+ | 'copied'
387
+ | 'type_changed'
388
+ | 'unmerged'
389
+ | 'unknown';
390
+
391
+ interface DiffFileBase {
392
+ path: string;
393
+ state: DiffFileState;
394
+ rawState: string;
395
+ oldPath?: string;
396
+ bytes: number;
397
+ isEof: boolean;
398
+ }
399
+
341
400
  interface FileDiff {
342
401
  path: string;
343
- state: string;
344
- old_path?: string;
402
+ state: DiffFileState;
403
+ rawState: string;
404
+ oldPath?: string;
345
405
  bytes: number;
346
- is_eof: boolean;
347
- diff: string;
406
+ isEof: boolean;
407
+ raw: string;
348
408
  }
349
409
 
350
410
  interface FilteredFile {
351
411
  path: string;
352
- state: string;
353
- old_path?: string;
412
+ state: DiffFileState;
413
+ rawState: string;
414
+ oldPath?: string;
354
415
  bytes: number;
355
- is_eof: boolean;
416
+ isEof: boolean;
417
+ }
418
+
419
+ interface RefUpdate {
420
+ ref: string;
421
+ oldSha: string;
422
+ newSha: string;
423
+ }
424
+
425
+ interface CommitResult {
426
+ commitSha: string;
427
+ treeSha: string;
428
+ targetRef: string;
429
+ packBytes: number;
430
+ blobCount: number;
431
+ refUpdate: RefUpdate;
432
+ }
433
+
434
+ interface ResetCommitOptions {
435
+ targetBranch: string;
436
+ targetCommitSha: string;
437
+ commitMessage?: string;
438
+ expectedHeadSha?: string;
439
+ author: CommitSignature;
440
+ committer?: CommitSignature;
441
+ }
442
+
443
+ interface ResetCommitResult {
444
+ commitSha: string;
445
+ treeSha: string;
446
+ targetBranch: string;
447
+ packBytes: number;
448
+ refUpdate: {
449
+ branch: string;
450
+ oldSha: string;
451
+ newSha: string;
452
+ };
356
453
  }
357
454
  ```
358
455
 
@@ -383,28 +480,12 @@ try {
383
480
  } catch (error) {
384
481
  // Error: GitStorage key must be a non-empty string.
385
482
  }
483
+ -
386
484
  ```
387
485
 
388
- ## Development
389
-
390
- This package is part of the Pierre monorepo. To work on it locally:
391
-
392
- ```bash
393
- # Install dependencies
394
- pnpm install
395
-
396
- # Build the package
397
- moon git-storage-sdk:build
398
-
399
- # Run tests
400
- moon git-storage-sdk:test
401
-
402
- # Run in watch mode
403
- moon git-storage-sdk:dev
404
-
405
- # Format code
406
- moon git-storage-sdk:format-write
407
- ```
486
+ - Mutating operations (commit builder, `resetCommit`) throw `RefUpdateError` when the backend
487
+ reports a ref failure. Inspect `error.status`, `error.reason`, `error.message`, and
488
+ `error.refUpdate` for details.
408
489
 
409
490
  ## License
410
491