@pierre/storage 1.3.2 → 1.4.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
@@ -214,6 +214,24 @@ const branches = await repo.listBranches({
214
214
  });
215
215
  console.log(branches.branches);
216
216
 
217
+ // List tags
218
+ const tags = await repo.listTags({
219
+ limit: 10,
220
+ cursor: undefined, // for pagination
221
+ });
222
+ console.log(tags.tags);
223
+
224
+ // Create a lightweight tag at a commit SHA
225
+ const createdTag = await repo.createTag({
226
+ name: 'v1.0.0',
227
+ target: '0123456789abcdef0123456789abcdef01234567',
228
+ });
229
+ console.log(createdTag.message);
230
+
231
+ // Delete a tag
232
+ const deletedTag = await repo.deleteTag({ name: 'v1.0.0' });
233
+ console.log(deletedTag.message);
234
+
217
235
  // List commits
218
236
  const commits = await repo.listCommits({
219
237
  branch: 'main', // optional
package/dist/index.cjs CHANGED
@@ -168,6 +168,25 @@ var createBranchResponseSchema = zod.z.object({
168
168
  target_is_ephemeral: zod.z.boolean(),
169
169
  commit_sha: zod.z.string().nullable().optional()
170
170
  });
171
+ var tagInfoSchema = zod.z.object({
172
+ cursor: zod.z.string(),
173
+ name: zod.z.string(),
174
+ sha: zod.z.string()
175
+ });
176
+ var listTagsResponseSchema = zod.z.object({
177
+ tags: zod.z.array(tagInfoSchema),
178
+ next_cursor: zod.z.string().nullable().optional(),
179
+ has_more: zod.z.boolean()
180
+ });
181
+ var createTagResponseSchema = zod.z.object({
182
+ name: zod.z.string(),
183
+ sha: zod.z.string(),
184
+ message: zod.z.string()
185
+ });
186
+ var deleteTagResponseSchema = zod.z.object({
187
+ name: zod.z.string(),
188
+ message: zod.z.string()
189
+ });
171
190
  var refUpdateResultSchema = zod.z.object({
172
191
  branch: zod.z.string(),
173
192
  old_sha: zod.z.string(),
@@ -530,7 +549,7 @@ function concatChunks(a, b) {
530
549
 
531
550
  // package.json
532
551
  var package_default = {
533
- version: "1.3.2"};
552
+ version: "1.4.0"};
534
553
 
535
554
  // src/version.ts
536
555
  var PACKAGE_NAME = "code-storage-sdk";
@@ -1684,6 +1703,33 @@ function transformCreateBranchResult(raw) {
1684
1703
  commitSha: raw.commit_sha ?? void 0
1685
1704
  };
1686
1705
  }
1706
+ function transformTagInfo(raw) {
1707
+ return {
1708
+ cursor: raw.cursor,
1709
+ name: raw.name,
1710
+ sha: raw.sha
1711
+ };
1712
+ }
1713
+ function transformListTagsResult(raw) {
1714
+ return {
1715
+ tags: raw.tags.map(transformTagInfo),
1716
+ nextCursor: raw.next_cursor ?? void 0,
1717
+ hasMore: raw.has_more
1718
+ };
1719
+ }
1720
+ function transformCreateTagResult(raw) {
1721
+ return {
1722
+ name: raw.name,
1723
+ sha: raw.sha,
1724
+ message: raw.message
1725
+ };
1726
+ }
1727
+ function transformDeleteTagResult(raw) {
1728
+ return {
1729
+ name: raw.name,
1730
+ message: raw.message
1731
+ };
1732
+ }
1687
1733
  function transformListReposResult(raw) {
1688
1734
  return {
1689
1735
  repos: raw.repos.map((repo) => ({
@@ -1956,6 +2002,31 @@ var RepoImpl = class {
1956
2002
  next_cursor: raw.next_cursor ?? void 0
1957
2003
  });
1958
2004
  }
2005
+ async listTags(options) {
2006
+ const ttl = resolveInvocationTtlSeconds(options, DEFAULT_TOKEN_TTL_SECONDS);
2007
+ const jwt = await this.generateJWT(this.id, {
2008
+ permissions: ["git:read"],
2009
+ ttl
2010
+ });
2011
+ const cursor = options?.cursor;
2012
+ const limit = options?.limit;
2013
+ let params;
2014
+ if (typeof cursor === "string" || typeof limit === "number") {
2015
+ params = {};
2016
+ if (typeof cursor === "string") {
2017
+ params.cursor = cursor;
2018
+ }
2019
+ if (typeof limit === "number") {
2020
+ params.limit = limit.toString();
2021
+ }
2022
+ }
2023
+ const response = await this.api.get({ path: "repos/tags", params }, jwt);
2024
+ const raw = listTagsResponseSchema.parse(await response.json());
2025
+ return transformListTagsResult({
2026
+ ...raw,
2027
+ next_cursor: raw.next_cursor ?? void 0
2028
+ });
2029
+ }
1959
2030
  async listCommits(options) {
1960
2031
  const ttl = resolveInvocationTtlSeconds(options, DEFAULT_TOKEN_TTL_SECONDS);
1961
2032
  const jwt = await this.generateJWT(this.id, {
@@ -2288,6 +2359,50 @@ var RepoImpl = class {
2288
2359
  const raw = createBranchResponseSchema.parse(await response.json());
2289
2360
  return transformCreateBranchResult(raw);
2290
2361
  }
2362
+ async createTag(options) {
2363
+ const name = options?.name?.trim();
2364
+ if (!name) {
2365
+ throw new Error("createTag name is required");
2366
+ }
2367
+ if (name.startsWith("refs/")) {
2368
+ throw new Error("createTag name must not start with refs/");
2369
+ }
2370
+ const target = options?.target?.trim();
2371
+ if (!target) {
2372
+ throw new Error("createTag target is required");
2373
+ }
2374
+ const ttl = resolveInvocationTtlSeconds(options, DEFAULT_TOKEN_TTL_SECONDS);
2375
+ const jwt = await this.generateJWT(this.id, {
2376
+ permissions: ["git:write"],
2377
+ ttl
2378
+ });
2379
+ const response = await this.api.post(
2380
+ { path: "repos/tags", body: { name, target } },
2381
+ jwt
2382
+ );
2383
+ const raw = createTagResponseSchema.parse(await response.json());
2384
+ return transformCreateTagResult(raw);
2385
+ }
2386
+ async deleteTag(options) {
2387
+ const name = options?.name?.trim();
2388
+ if (!name) {
2389
+ throw new Error("deleteTag name is required");
2390
+ }
2391
+ if (name.startsWith("refs/")) {
2392
+ throw new Error("deleteTag name must not start with refs/");
2393
+ }
2394
+ const ttl = resolveInvocationTtlSeconds(options, DEFAULT_TOKEN_TTL_SECONDS);
2395
+ const jwt = await this.generateJWT(this.id, {
2396
+ permissions: ["git:read", "git:write"],
2397
+ ttl
2398
+ });
2399
+ const response = await this.api.delete(
2400
+ { path: "repos/tags", body: { name } },
2401
+ jwt
2402
+ );
2403
+ const raw = deleteTagResponseSchema.parse(await response.json());
2404
+ return transformDeleteTagResult(raw);
2405
+ }
2291
2406
  async restoreCommit(options) {
2292
2407
  const targetBranch = options?.targetBranch?.trim();
2293
2408
  if (!targetBranch) {