@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.d.cts CHANGED
@@ -447,6 +447,7 @@ interface GetRemoteURLOptions {
447
447
  }
448
448
  interface Repo {
449
449
  id: string;
450
+ defaultBranch: string;
450
451
  getRemoteURL(options?: GetRemoteURLOptions): Promise<string>;
451
452
  getEphemeralRemoteURL(options?: GetRemoteURLOptions): Promise<string>;
452
453
  getFileStream(options: GetFileOptions): Promise<Response>;
@@ -466,7 +467,7 @@ type ValidMethod = 'GET' | 'POST' | 'PUT' | 'DELETE';
466
467
  type SimplePath = string;
467
468
  type ComplexPath = {
468
469
  path: string;
469
- params?: Record<string, string>;
470
+ params?: Record<string, string | string[]>;
470
471
  body?: Record<string, any>;
471
472
  };
472
473
  type ValidPath = SimplePath | ComplexPath;
@@ -573,6 +574,8 @@ interface GetBranchDiffOptions extends GitStorageInvocationOptions {
573
574
  base?: string;
574
575
  ephemeral?: boolean;
575
576
  ephemeralBase?: boolean;
577
+ /** Optional paths to filter the diff to specific files */
578
+ paths?: string[];
576
579
  }
577
580
  type GetBranchDiffResponse = GetBranchDiffResponseRaw;
578
581
  interface GetBranchDiffResult {
@@ -585,6 +588,8 @@ interface GetBranchDiffResult {
585
588
  interface GetCommitDiffOptions extends GitStorageInvocationOptions {
586
589
  sha: string;
587
590
  baseSha?: string;
591
+ /** Optional paths to filter the diff to specific files */
592
+ paths?: string[];
588
593
  }
589
594
  type GetCommitDiffResponse = GetCommitDiffResponseRaw;
590
595
  interface GetCommitDiffResult {
package/dist/index.d.ts CHANGED
@@ -447,6 +447,7 @@ interface GetRemoteURLOptions {
447
447
  }
448
448
  interface Repo {
449
449
  id: string;
450
+ defaultBranch: string;
450
451
  getRemoteURL(options?: GetRemoteURLOptions): Promise<string>;
451
452
  getEphemeralRemoteURL(options?: GetRemoteURLOptions): Promise<string>;
452
453
  getFileStream(options: GetFileOptions): Promise<Response>;
@@ -466,7 +467,7 @@ type ValidMethod = 'GET' | 'POST' | 'PUT' | 'DELETE';
466
467
  type SimplePath = string;
467
468
  type ComplexPath = {
468
469
  path: string;
469
- params?: Record<string, string>;
470
+ params?: Record<string, string | string[]>;
470
471
  body?: Record<string, any>;
471
472
  };
472
473
  type ValidPath = SimplePath | ComplexPath;
@@ -573,6 +574,8 @@ interface GetBranchDiffOptions extends GitStorageInvocationOptions {
573
574
  base?: string;
574
575
  ephemeral?: boolean;
575
576
  ephemeralBase?: boolean;
577
+ /** Optional paths to filter the diff to specific files */
578
+ paths?: string[];
576
579
  }
577
580
  type GetBranchDiffResponse = GetBranchDiffResponseRaw;
578
581
  interface GetBranchDiffResult {
@@ -585,6 +588,8 @@ interface GetBranchDiffResult {
585
588
  interface GetCommitDiffOptions extends GitStorageInvocationOptions {
586
589
  sha: string;
587
590
  baseSha?: string;
591
+ /** Optional paths to filter the diff to specific files */
592
+ paths?: string[];
588
593
  }
589
594
  type GetCommitDiffResponse = GetCommitDiffResponseRaw;
590
595
  interface GetCommitDiffResult {
package/dist/index.js CHANGED
@@ -466,7 +466,7 @@ function concatChunks(a, b) {
466
466
 
467
467
  // package.json
468
468
  var package_default = {
469
- version: "0.4.2"};
469
+ version: "0.6.0"};
470
470
 
471
471
  // src/version.ts
472
472
  var PACKAGE_NAME = "code-storage-sdk";
@@ -1004,7 +1004,17 @@ var ApiFetcher = class {
1004
1004
  if (typeof path === "string") {
1005
1005
  return `${this.getBaseUrl()}/${path}`;
1006
1006
  } else if (path.params) {
1007
- const paramStr = new URLSearchParams(path.params).toString();
1007
+ const searchParams = new URLSearchParams();
1008
+ for (const [key, value] of Object.entries(path.params)) {
1009
+ if (Array.isArray(value)) {
1010
+ for (const v of value) {
1011
+ searchParams.append(key, v);
1012
+ }
1013
+ } else {
1014
+ searchParams.append(key, value);
1015
+ }
1016
+ }
1017
+ const paramStr = searchParams.toString();
1008
1018
  return `${this.getBaseUrl()}/${path.path}${paramStr ? `?${paramStr}` : ""}`;
1009
1019
  } else {
1010
1020
  return `${this.getBaseUrl()}/${path.path}`;
@@ -1549,8 +1559,9 @@ function transformGrepFileMatch(raw) {
1549
1559
  };
1550
1560
  }
1551
1561
  var RepoImpl = class {
1552
- constructor(id, options, generateJWT) {
1562
+ constructor(id, defaultBranch, options, generateJWT) {
1553
1563
  this.id = id;
1564
+ this.defaultBranch = defaultBranch;
1554
1565
  this.options = options;
1555
1566
  this.generateJWT = generateJWT;
1556
1567
  this.api = getApiInstance(
@@ -1680,6 +1691,9 @@ var RepoImpl = class {
1680
1691
  if (typeof options.ephemeralBase === "boolean") {
1681
1692
  params.ephemeral_base = String(options.ephemeralBase);
1682
1693
  }
1694
+ if (options.paths && options.paths.length > 0) {
1695
+ params.path = options.paths;
1696
+ }
1683
1697
  const response = await this.api.get({ path: "repos/branches/diff", params }, jwt);
1684
1698
  const raw = branchDiffResponseSchema.parse(await response.json());
1685
1699
  return transformBranchDiffResult(raw);
@@ -1696,6 +1710,9 @@ var RepoImpl = class {
1696
1710
  if (options.baseSha) {
1697
1711
  params.baseSha = options.baseSha;
1698
1712
  }
1713
+ if (options.paths && options.paths.length > 0) {
1714
+ params.path = options.paths;
1715
+ }
1699
1716
  const response = await this.api.get({ path: "repos/diff", params }, jwt);
1700
1717
  const raw = commitDiffResponseSchema.parse(await response.json());
1701
1718
  return transformCommitDiffResult(raw);
@@ -1965,7 +1982,7 @@ var GitStorage = class _GitStorage {
1965
1982
  provider: "github",
1966
1983
  ...snakecaseKeys(options.baseRepo)
1967
1984
  } : null;
1968
- const defaultBranch = options?.defaultBranch ?? "main";
1985
+ const defaultBranch = options?.baseRepo?.defaultBranch ?? options?.defaultBranch ?? "main";
1969
1986
  const createRepoPath = baseRepoOptions || defaultBranch ? {
1970
1987
  path: "repos",
1971
1988
  body: {
@@ -1977,7 +1994,7 @@ var GitStorage = class _GitStorage {
1977
1994
  if (resp.status === 409) {
1978
1995
  throw new Error("Repository already exists");
1979
1996
  }
1980
- return new RepoImpl(repoId, this.options, this.generateJWT.bind(this));
1997
+ return new RepoImpl(repoId, defaultBranch, this.options, this.generateJWT.bind(this));
1981
1998
  }
1982
1999
  /**
1983
2000
  * Find a repository by ID
@@ -1993,7 +2010,9 @@ var GitStorage = class _GitStorage {
1993
2010
  if (resp.status === 404) {
1994
2011
  return null;
1995
2012
  }
1996
- return new RepoImpl(options.id, this.options, this.generateJWT.bind(this));
2013
+ const body = await resp.json();
2014
+ const defaultBranch = body.default_branch ?? "main";
2015
+ return new RepoImpl(options.id, defaultBranch, this.options, this.generateJWT.bind(this));
1997
2016
  }
1998
2017
  /**
1999
2018
  * Delete a repository by ID