@pierre/storage 0.4.2 → 0.6.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/dist/index.cjs CHANGED
@@ -472,7 +472,7 @@ function concatChunks(a, b) {
472
472
 
473
473
  // package.json
474
474
  var package_default = {
475
- version: "0.4.2"};
475
+ version: "0.6.0"};
476
476
 
477
477
  // src/version.ts
478
478
  var PACKAGE_NAME = "code-storage-sdk";
@@ -1010,7 +1010,17 @@ var ApiFetcher = class {
1010
1010
  if (typeof path === "string") {
1011
1011
  return `${this.getBaseUrl()}/${path}`;
1012
1012
  } else if (path.params) {
1013
- const paramStr = new URLSearchParams(path.params).toString();
1013
+ const searchParams = new URLSearchParams();
1014
+ for (const [key, value] of Object.entries(path.params)) {
1015
+ if (Array.isArray(value)) {
1016
+ for (const v of value) {
1017
+ searchParams.append(key, v);
1018
+ }
1019
+ } else {
1020
+ searchParams.append(key, value);
1021
+ }
1022
+ }
1023
+ const paramStr = searchParams.toString();
1014
1024
  return `${this.getBaseUrl()}/${path.path}${paramStr ? `?${paramStr}` : ""}`;
1015
1025
  } else {
1016
1026
  return `${this.getBaseUrl()}/${path.path}`;
@@ -1555,8 +1565,9 @@ function transformGrepFileMatch(raw) {
1555
1565
  };
1556
1566
  }
1557
1567
  var RepoImpl = class {
1558
- constructor(id, options, generateJWT) {
1568
+ constructor(id, defaultBranch, options, generateJWT) {
1559
1569
  this.id = id;
1570
+ this.defaultBranch = defaultBranch;
1560
1571
  this.options = options;
1561
1572
  this.generateJWT = generateJWT;
1562
1573
  this.api = getApiInstance(
@@ -1686,6 +1697,9 @@ var RepoImpl = class {
1686
1697
  if (typeof options.ephemeralBase === "boolean") {
1687
1698
  params.ephemeral_base = String(options.ephemeralBase);
1688
1699
  }
1700
+ if (options.paths && options.paths.length > 0) {
1701
+ params.path = options.paths;
1702
+ }
1689
1703
  const response = await this.api.get({ path: "repos/branches/diff", params }, jwt);
1690
1704
  const raw = branchDiffResponseSchema.parse(await response.json());
1691
1705
  return transformBranchDiffResult(raw);
@@ -1702,6 +1716,9 @@ var RepoImpl = class {
1702
1716
  if (options.baseSha) {
1703
1717
  params.baseSha = options.baseSha;
1704
1718
  }
1719
+ if (options.paths && options.paths.length > 0) {
1720
+ params.path = options.paths;
1721
+ }
1705
1722
  const response = await this.api.get({ path: "repos/diff", params }, jwt);
1706
1723
  const raw = commitDiffResponseSchema.parse(await response.json());
1707
1724
  return transformCommitDiffResult(raw);
@@ -1971,7 +1988,7 @@ var GitStorage = class _GitStorage {
1971
1988
  provider: "github",
1972
1989
  ...snakecaseKeys__default.default(options.baseRepo)
1973
1990
  } : null;
1974
- const defaultBranch = options?.defaultBranch ?? "main";
1991
+ const defaultBranch = options?.baseRepo?.defaultBranch ?? options?.defaultBranch ?? "main";
1975
1992
  const createRepoPath = baseRepoOptions || defaultBranch ? {
1976
1993
  path: "repos",
1977
1994
  body: {
@@ -1983,7 +2000,7 @@ var GitStorage = class _GitStorage {
1983
2000
  if (resp.status === 409) {
1984
2001
  throw new Error("Repository already exists");
1985
2002
  }
1986
- return new RepoImpl(repoId, this.options, this.generateJWT.bind(this));
2003
+ return new RepoImpl(repoId, defaultBranch, this.options, this.generateJWT.bind(this));
1987
2004
  }
1988
2005
  /**
1989
2006
  * Find a repository by ID
@@ -1999,7 +2016,9 @@ var GitStorage = class _GitStorage {
1999
2016
  if (resp.status === 404) {
2000
2017
  return null;
2001
2018
  }
2002
- return new RepoImpl(options.id, this.options, this.generateJWT.bind(this));
2019
+ const body = await resp.json();
2020
+ const defaultBranch = body.default_branch ?? "main";
2021
+ return new RepoImpl(options.id, defaultBranch, this.options, this.generateJWT.bind(this));
2003
2022
  }
2004
2023
  /**
2005
2024
  * Delete a repository by ID