@pierre/storage 0.0.11 → 0.1.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/README.md +159 -78
- package/dist/index.cjs +739 -72
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +560 -88
- package/dist/index.d.ts +560 -88
- package/dist/index.js +738 -73
- package/dist/index.js.map +1 -1
- package/package.json +39 -37
- package/src/commit.ts +196 -43
- package/src/errors.ts +50 -0
- package/src/fetch.ts +75 -5
- package/src/index.ts +389 -47
- package/src/schemas.ts +138 -0
- package/src/types.ts +182 -89
- package/src/util.ts +0 -18
- package/src/webhook.ts +75 -3
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
|
|
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(
|
|
137
|
-
console.log(
|
|
138
|
-
console.log(
|
|
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
|
|
144
|
-
|
|
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
|
|
149
|
-
|
|
150
|
-
|
|
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`
|
|
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
|
-
|
|
166
|
-
|
|
167
|
-
|
|
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<
|
|
242
|
-
listBranches(options?: ListBranchesOptions): Promise<
|
|
243
|
-
listCommits(options?: ListCommitsOptions): Promise<
|
|
244
|
-
getBranchDiff(options: GetBranchDiffOptions): Promise<
|
|
245
|
-
getCommitDiff(options: GetCommitDiffOptions): Promise<
|
|
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
|
-
|
|
278
|
-
|
|
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
|
-
|
|
285
|
-
|
|
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
|
-
|
|
297
|
-
|
|
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
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
date:
|
|
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
|
-
|
|
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
|
-
|
|
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:
|
|
344
|
-
|
|
402
|
+
state: DiffFileState;
|
|
403
|
+
rawState: string;
|
|
404
|
+
oldPath?: string;
|
|
345
405
|
bytes: number;
|
|
346
|
-
|
|
347
|
-
|
|
406
|
+
isEof: boolean;
|
|
407
|
+
raw: string;
|
|
348
408
|
}
|
|
349
409
|
|
|
350
410
|
interface FilteredFile {
|
|
351
411
|
path: string;
|
|
352
|
-
state:
|
|
353
|
-
|
|
412
|
+
state: DiffFileState;
|
|
413
|
+
rawState: string;
|
|
414
|
+
oldPath?: string;
|
|
354
415
|
bytes: number;
|
|
355
|
-
|
|
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 RestoreCommitOptions {
|
|
435
|
+
targetBranch: string;
|
|
436
|
+
targetCommitSha: string;
|
|
437
|
+
commitMessage?: string;
|
|
438
|
+
expectedHeadSha?: string;
|
|
439
|
+
author: CommitSignature;
|
|
440
|
+
committer?: CommitSignature;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
interface RestoreCommitResult {
|
|
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
|
-
|
|
389
|
-
|
|
390
|
-
|
|
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, `restoreCommit`) 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
|
|