@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/README.md +39 -0
- package/dist/index.cjs +70 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +127 -11
- package/dist/index.d.ts +127 -11
- package/dist/index.js +70 -1
- package/dist/index.js.map +1 -1
- package/package.json +5 -1
- package/src/index.ts +72 -0
- package/src/schemas.ts +24 -0
- package/src/types.ts +38 -0
package/README.md
CHANGED
|
@@ -171,6 +171,7 @@ const archiveResp = await repo.getArchiveStream({
|
|
|
171
171
|
ref: 'main',
|
|
172
172
|
includeGlobs: ['README.md'],
|
|
173
173
|
excludeGlobs: ['vendor/**'],
|
|
174
|
+
maxBlobSize: 1024 * 1024, // optional max file size in bytes
|
|
174
175
|
archivePrefix: 'repo/',
|
|
175
176
|
});
|
|
176
177
|
const archiveBytes = new Uint8Array(await archiveResp.arrayBuffer());
|
|
@@ -182,6 +183,13 @@ const files = await repo.listFiles({
|
|
|
182
183
|
});
|
|
183
184
|
console.log(files.paths); // Array of file paths
|
|
184
185
|
|
|
186
|
+
// List files with mode/size and last commit metadata
|
|
187
|
+
const metadata = await repo.listFilesWithMetadata({
|
|
188
|
+
ref: 'main',
|
|
189
|
+
});
|
|
190
|
+
console.log(metadata.files[0].lastCommitSha);
|
|
191
|
+
console.log(metadata.commits[metadata.files[0].lastCommitSha].author);
|
|
192
|
+
|
|
185
193
|
// List branches
|
|
186
194
|
const branches = await repo.listBranches({
|
|
187
195
|
limit: 10,
|
|
@@ -431,6 +439,9 @@ interface Repo {
|
|
|
431
439
|
getFileStream(options: GetFileOptions): Promise<Response>;
|
|
432
440
|
getArchiveStream(options?: ArchiveOptions): Promise<Response>;
|
|
433
441
|
listFiles(options?: ListFilesOptions): Promise<ListFilesResult>;
|
|
442
|
+
listFilesWithMetadata(
|
|
443
|
+
options?: ListFilesWithMetadataOptions
|
|
444
|
+
): Promise<ListFilesWithMetadataResult>;
|
|
434
445
|
listBranches(options?: ListBranchesOptions): Promise<ListBranchesResult>;
|
|
435
446
|
listCommits(options?: ListCommitsOptions): Promise<ListCommitsResult>;
|
|
436
447
|
getNote(options: GetNoteOptions): Promise<GetNoteResult>;
|
|
@@ -459,6 +470,7 @@ interface ArchiveOptions {
|
|
|
459
470
|
ref?: string; // Branch, tag, or commit SHA (defaults to default branch)
|
|
460
471
|
includeGlobs?: string[];
|
|
461
472
|
excludeGlobs?: string[];
|
|
473
|
+
maxBlobSize?: number; // Optional max file size in bytes
|
|
462
474
|
archivePrefix?: string;
|
|
463
475
|
ttl?: number;
|
|
464
476
|
}
|
|
@@ -467,6 +479,7 @@ interface ArchiveOptions {
|
|
|
467
479
|
|
|
468
480
|
interface ListFilesOptions {
|
|
469
481
|
ref?: string; // Branch, tag, or commit SHA
|
|
482
|
+
ephemeral?: boolean; // Resolve ref in ephemeral namespace
|
|
470
483
|
ttl?: number;
|
|
471
484
|
}
|
|
472
485
|
|
|
@@ -480,6 +493,32 @@ interface ListFilesResult {
|
|
|
480
493
|
ref: string;
|
|
481
494
|
}
|
|
482
495
|
|
|
496
|
+
interface ListFilesWithMetadataOptions {
|
|
497
|
+
ref?: string; // Branch, tag, or commit SHA
|
|
498
|
+
ephemeral?: boolean; // Resolve ref in ephemeral namespace
|
|
499
|
+
ttl?: number;
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
interface FileWithMetadata {
|
|
503
|
+
path: string;
|
|
504
|
+
mode: string;
|
|
505
|
+
size: number;
|
|
506
|
+
lastCommitSha: string;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
interface CommitMetadata {
|
|
510
|
+
author: string;
|
|
511
|
+
date: Date;
|
|
512
|
+
rawDate: string;
|
|
513
|
+
message: string;
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
interface ListFilesWithMetadataResult {
|
|
517
|
+
files: FileWithMetadata[];
|
|
518
|
+
commits: Record<string, CommitMetadata>;
|
|
519
|
+
ref: string;
|
|
520
|
+
}
|
|
521
|
+
|
|
483
522
|
interface GetNoteOptions {
|
|
484
523
|
sha: string; // Commit SHA to look up notes for
|
|
485
524
|
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
|
|
533
|
+
version: "1.2.1"};
|
|
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";
|
|
@@ -1819,6 +1862,9 @@ var RepoImpl = class {
|
|
|
1819
1862
|
if (Array.isArray(options.excludeGlobs) && options.excludeGlobs.length > 0) {
|
|
1820
1863
|
body.exclude_globs = options.excludeGlobs;
|
|
1821
1864
|
}
|
|
1865
|
+
if (typeof options.maxBlobSize === "number" && Number.isFinite(options.maxBlobSize)) {
|
|
1866
|
+
body.max_blob_size = options.maxBlobSize;
|
|
1867
|
+
}
|
|
1822
1868
|
if (typeof options.archivePrefix === "string") {
|
|
1823
1869
|
const prefix = options.archivePrefix.trim();
|
|
1824
1870
|
if (prefix) {
|
|
@@ -1851,6 +1897,29 @@ var RepoImpl = class {
|
|
|
1851
1897
|
const raw = listFilesResponseSchema.parse(await response.json());
|
|
1852
1898
|
return { paths: raw.paths, ref: raw.ref };
|
|
1853
1899
|
}
|
|
1900
|
+
async listFilesWithMetadata(options) {
|
|
1901
|
+
const ttl = resolveInvocationTtlSeconds(options, DEFAULT_TOKEN_TTL_SECONDS);
|
|
1902
|
+
const jwt = await this.generateJWT(this.id, {
|
|
1903
|
+
permissions: ["git:read"],
|
|
1904
|
+
ttl
|
|
1905
|
+
});
|
|
1906
|
+
const params = {};
|
|
1907
|
+
if (options?.ref) {
|
|
1908
|
+
params.ref = options.ref;
|
|
1909
|
+
}
|
|
1910
|
+
if (typeof options?.ephemeral === "boolean") {
|
|
1911
|
+
params.ephemeral = String(options.ephemeral);
|
|
1912
|
+
}
|
|
1913
|
+
const response = await this.api.get(
|
|
1914
|
+
{
|
|
1915
|
+
path: "repos/files/metadata",
|
|
1916
|
+
params: Object.keys(params).length ? params : void 0
|
|
1917
|
+
},
|
|
1918
|
+
jwt
|
|
1919
|
+
);
|
|
1920
|
+
const raw = listFilesWithMetadataResponseSchema.parse(await response.json());
|
|
1921
|
+
return transformListFilesWithMetadataResult(raw);
|
|
1922
|
+
}
|
|
1854
1923
|
async listBranches(options) {
|
|
1855
1924
|
const ttl = resolveInvocationTtlSeconds(options, DEFAULT_TOKEN_TTL_SECONDS);
|
|
1856
1925
|
const jwt = await this.generateJWT(this.id, {
|