repo-sdk 0.1.1 → 0.1.2

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.
@@ -1,4 +1,4 @@
1
- import { O as ParsedWebhookEvent, P as RepoProvider, v as IncomingWebhookRequest, z as TokenProvider } from "./types-CTeiAxMy.js";
1
+ import { B as TokenProvider, F as RepoProvider, O as ParsedWebhookEvent, v as IncomingWebhookRequest } from "./types-DfiRluvJ.js";
2
2
  import { t as VerifyWebhookParams$1 } from "./verify-p6JsExms.js";
3
3
  //#region src/providers/azure-devops/auth.d.ts
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { O as ParsedWebhookEvent, P as RepoProvider, v as IncomingWebhookRequest, z as TokenProvider } from "./types-CTeiAxMy.js";
1
+ import { B as TokenProvider, F as RepoProvider, O as ParsedWebhookEvent, v as IncomingWebhookRequest } from "./types-DfiRluvJ.js";
2
2
  import { t as VerifyWebhookParams } from "./verify-p6JsExms.js";
3
3
  //#region src/providers/bitbucket/index.d.ts
4
4
  interface BitbucketProviderOptions {
@@ -1,4 +1,4 @@
1
- import { P as RepoProvider, z as TokenProvider } from "./types-CTeiAxMy.js";
1
+ import { B as TokenProvider, F as RepoProvider } from "./types-DfiRluvJ.js";
2
2
  //#region src/providers/git-http/index.d.ts
3
3
  interface GitHttpProviderOptions {
4
4
  /**
package/dist/gitea.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { O as ParsedWebhookEvent, P as RepoProvider, v as IncomingWebhookRequest, z as TokenProvider } from "./types-CTeiAxMy.js";
1
+ import { B as TokenProvider, F as RepoProvider, O as ParsedWebhookEvent, v as IncomingWebhookRequest } from "./types-DfiRluvJ.js";
2
2
  import { t as VerifyWebhookParams } from "./verify-p6JsExms.js";
3
3
  //#region src/providers/gitea/index.d.ts
4
4
  interface GiteaProviderOptions {
package/dist/github.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { O as ParsedWebhookEvent, P as RepoProvider, v as IncomingWebhookRequest, z as TokenProvider } from "./types-CTeiAxMy.js";
1
+ import { B as TokenProvider, F as RepoProvider, O as ParsedWebhookEvent, v as IncomingWebhookRequest } from "./types-DfiRluvJ.js";
2
2
  import { t as VerifyWebhookParams } from "./verify-p6JsExms.js";
3
3
  //#region src/providers/github/app-auth.d.ts
4
4
  interface InstallationToken {
package/dist/gitlab.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { O as ParsedWebhookEvent, P as RepoProvider, v as IncomingWebhookRequest, z as TokenProvider } from "./types-CTeiAxMy.js";
1
+ import { B as TokenProvider, F as RepoProvider, O as ParsedWebhookEvent, v as IncomingWebhookRequest } from "./types-DfiRluvJ.js";
2
2
  import { t as VerifyWebhookParams } from "./verify-p6JsExms.js";
3
3
  //#region src/providers/gitlab/index.d.ts
4
4
  interface GitLabProviderOptions {
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { A as ProviderSearchRefsParams, B as UpdateWebhookParams, C as ListTagsParams, D as Page, E as NamespaceKind, F as Repository, H as Webhook, I as ResolveRefParams, L as SearchRefsParams, M as RefType, N as RepoCapabilities, O as ParsedWebhookEvent, P as RepoProvider, R as Tag, S as ListRepositoriesParams, T as Namespace, U as WebhookEventType, V as UserRef, W as WebhookVerificationMethod, _ as GitActor, a as CloneUrl, b as ListCommitsParams, c as DeleteWebhookParams, d as GetBranchParams, f as GetCloneUrlParams, g as GetWebhookParams, h as GetTagParams, i as Branch, j as RefMatch, k as ProviderName, l as DownloadArchiveParams, m as GetRepositoryParams, n as ArchiveFormat, o as Commit, p as GetCommitParams, r as AuthenticatedUser, s as CreateWebhookParams, t as Archive, u as GetAuthenticatedUserParams, v as IncomingWebhookRequest, w as ListWebhooksParams, x as ListNamespacesParams, y as ListBranchesParams, z as TokenProvider } from "./types-CTeiAxMy.js";
1
+ import { A as ProviderRefMatch, B as TokenProvider, C as ListTagsParams, D as Page, E as NamespaceKind, F as RepoProvider, G as WebhookVerificationMethod, H as UserRef, I as Repository, L as ResolveRefParams, M as RefMatch, N as RefType, O as ParsedWebhookEvent, P as RepoCapabilities, R as SearchRefsParams, S as ListRepositoriesParams, T as Namespace, U as Webhook, V as UpdateWebhookParams, W as WebhookEventType, _ as GitActor, a as CloneUrl, b as ListCommitsParams, c as DeleteWebhookParams, d as GetBranchParams, f as GetCloneUrlParams, g as GetWebhookParams, h as GetTagParams, i as Branch, j as ProviderSearchRefsParams, k as ProviderName, l as DownloadArchiveParams, m as GetRepositoryParams, n as ArchiveFormat, o as Commit, p as GetCommitParams, r as AuthenticatedUser, s as CreateWebhookParams, t as Archive, u as GetAuthenticatedUserParams, v as IncomingWebhookRequest, w as ListWebhooksParams, x as ListNamespacesParams, y as ListBranchesParams, z as Tag } from "./types-DfiRluvJ.js";
2
2
  //#region src/client.d.ts
3
3
  interface RetryOptions {
4
4
  rateLimit?: boolean;
@@ -92,4 +92,4 @@ declare class RepoError extends Error {
92
92
  constructor(message: string, options: RepoErrorOptions);
93
93
  }
94
94
  //#endregion
95
- export { type Archive, type ArchiveFormat, type AuthenticatedUser, type Branch, type CloneUrl, type Commit, type CreateClientOptions, type CreateWebhookParams, type DeleteWebhookParams, type DetectWebhookProviderInput, type DownloadArchiveParams, type GetAuthenticatedUserParams, type GetBranchParams, type GetCloneUrlParams, type GetCommitParams, type GetRepositoryParams, type GetTagParams, type GetWebhookParams, type GitActor, type IncomingWebhookRequest, type ListBranchesParams, type ListCommitsParams, type ListNamespacesParams, type ListRepositoriesParams, type ListTagsParams, type ListWebhooksParams, type Namespace, type NamespaceKind, type Page, type ParsedWebhookEvent, type ProviderName, type ProviderSearchRefsParams, type RefMatch, type RefType, type RepoCapabilities, type RepoClient, RepoError, type RepoErrorCode, type RepoErrorOptions, type RepoProvider, type Repository, type ResolveRefParams, type RetryOptions, type SearchRefsParams, type Tag, type TokenProvider, type UpdateWebhookParams, type UserRef, type Webhook, type WebhookEventType, type WebhookVerificationMethod, createClient, detectWebhookProvider };
95
+ export { type Archive, type ArchiveFormat, type AuthenticatedUser, type Branch, type CloneUrl, type Commit, type CreateClientOptions, type CreateWebhookParams, type DeleteWebhookParams, type DetectWebhookProviderInput, type DownloadArchiveParams, type GetAuthenticatedUserParams, type GetBranchParams, type GetCloneUrlParams, type GetCommitParams, type GetRepositoryParams, type GetTagParams, type GetWebhookParams, type GitActor, type IncomingWebhookRequest, type ListBranchesParams, type ListCommitsParams, type ListNamespacesParams, type ListRepositoriesParams, type ListTagsParams, type ListWebhooksParams, type Namespace, type NamespaceKind, type Page, type ParsedWebhookEvent, type ProviderName, type ProviderRefMatch, type ProviderSearchRefsParams, type RefMatch, type RefType, type RepoCapabilities, type RepoClient, RepoError, type RepoErrorCode, type RepoErrorOptions, type RepoProvider, type Repository, type ResolveRefParams, type RetryOptions, type SearchRefsParams, type Tag, type TokenProvider, type UpdateWebhookParams, type UserRef, type Webhook, type WebhookEventType, type WebhookVerificationMethod, createClient, detectWebhookProvider };
package/dist/index.js CHANGED
@@ -10,29 +10,39 @@ const ALL_REF_TYPES = [
10
10
  "commit"
11
11
  ];
12
12
  const COMMIT_SHA_PATTERN = /^[0-9a-f]{4,40}$/i;
13
- function branchMatch(branch) {
13
+ const FULL_COMMIT_SHA_PATTERN = /^[0-9a-f]{40}$/i;
14
+ const BRANCH_REF_PREFIX = "refs/heads/";
15
+ const TAG_REF_PREFIX = "refs/tags/";
16
+ function qualifyRef(match) {
17
+ const ref = match.type === "branch" ? `${BRANCH_REF_PREFIX}${match.name}` : match.type === "tag" ? `${TAG_REF_PREFIX}${match.name}` : match.sha;
14
18
  return {
19
+ ...match,
20
+ ref
21
+ };
22
+ }
23
+ function branchMatch(branch) {
24
+ return qualifyRef({
15
25
  type: "branch",
16
26
  name: branch.name,
17
27
  sha: branch.sha,
18
28
  raw: branch.raw
19
- };
29
+ });
20
30
  }
21
31
  function tagMatch(tag) {
22
- return {
32
+ return qualifyRef({
23
33
  type: "tag",
24
34
  name: tag.name,
25
35
  sha: tag.sha,
26
36
  raw: tag.raw
27
- };
37
+ });
28
38
  }
29
39
  function commitMatch(commit) {
30
- return {
40
+ return qualifyRef({
31
41
  type: "commit",
32
42
  name: commit.sha,
33
43
  sha: commit.sha,
34
44
  raw: commit.raw
35
- };
45
+ });
36
46
  }
37
47
  function createClient(options) {
38
48
  const { provider } = options;
@@ -192,7 +202,7 @@ function createClient(options) {
192
202
  types: refTypes,
193
203
  limit,
194
204
  signal
195
- })) : [], types.includes("commit") && COMMIT_SHA_PATTERN.test(query) ? withRetry(() => provider.getCommit({
205
+ })).then((matches) => matches.map(qualifyRef)) : [], types.includes("commit") && COMMIT_SHA_PATTERN.test(query) ? withRetry(() => provider.getCommit({
196
206
  repo,
197
207
  ref: query,
198
208
  signal
@@ -205,8 +215,16 @@ function createClient(options) {
205
215
  resolve: async (params) => {
206
216
  requireNonEmpty(params.repo, "repo");
207
217
  requireNonEmpty(params.ref, "ref");
208
- const { repo, ref, type, signal } = params;
209
- if (ref === "HEAD" && (type === void 0 || type === "branch")) {
218
+ const { repo, signal } = params;
219
+ let { ref, type } = params;
220
+ const impliedType = ref.startsWith(BRANCH_REF_PREFIX) ? "branch" : ref.startsWith(TAG_REF_PREFIX) ? "tag" : void 0;
221
+ if (impliedType !== void 0) {
222
+ if (type !== void 0 && type !== impliedType) fail("validation", `Fully-qualified ref '${ref}' contradicts type '${type}'`);
223
+ type = impliedType;
224
+ ref = ref.slice(impliedType === "branch" ? 11 : 10);
225
+ requireNonEmpty(ref, "ref");
226
+ }
227
+ if (impliedType === void 0 && ref === "HEAD" && (type === void 0 || type === "branch")) {
210
228
  const defaultBranch = (await withRetry(() => provider.getRepository({
211
229
  repo,
212
230
  signal
@@ -226,6 +244,17 @@ function createClient(options) {
226
244
  ref,
227
245
  signal
228
246
  })));
247
+ let commitProbeError;
248
+ if (type === void 0 && FULL_COMMIT_SHA_PATTERN.test(ref)) try {
249
+ return commitMatch(await withRetry(() => provider.getCommit({
250
+ repo,
251
+ ref,
252
+ signal
253
+ })));
254
+ } catch (error) {
255
+ if (error instanceof RepoError && (error.code === "not_found" || error.code === "validation" || error.code === "unsupported")) commitProbeError = error;
256
+ else throw error;
257
+ }
229
258
  const [tagResult, branchResult] = await Promise.allSettled([type === "branch" ? void 0 : withRetry(() => provider.getTag({
230
259
  repo,
231
260
  name: ref,
@@ -242,11 +271,14 @@ function createClient(options) {
242
271
  if (branchResult.status === "fulfilled") {
243
272
  if (branchResult.value !== void 0) return branchMatch(branchResult.value);
244
273
  } else if (!isMiss(branchResult)) throw branchResult.reason;
245
- if (type === void 0 && COMMIT_SHA_PATTERN.test(ref)) return commitMatch(await withRetry(() => provider.getCommit({
246
- repo,
247
- ref,
248
- signal
249
- })));
274
+ if (type === void 0 && COMMIT_SHA_PATTERN.test(ref)) {
275
+ if (commitProbeError !== void 0) throw commitProbeError;
276
+ return commitMatch(await withRetry(() => provider.getCommit({
277
+ repo,
278
+ ref,
279
+ signal
280
+ })));
281
+ }
250
282
  throw new RepoError(`Ref not found: ${ref}`, {
251
283
  code: "not_found",
252
284
  provider: provider.name
package/dist/testing.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { E as NamespaceKind, F as Repository, H as Webhook, N as RepoCapabilities, P as RepoProvider, R as Tag, T as Namespace, U as WebhookEventType, i as Branch, k as ProviderName, o as Commit } from "./types-CTeiAxMy.js";
1
+ import { E as NamespaceKind, F as RepoProvider, I as Repository, P as RepoCapabilities, T as Namespace, U as Webhook, W as WebhookEventType, i as Branch, k as ProviderName, o as Commit, z as Tag } from "./types-DfiRluvJ.js";
2
2
  //#region src/providers/testing/index.d.ts
3
3
  interface InMemoryNamespaceSeed {
4
4
  id: string;
@@ -93,10 +93,14 @@ type RefType = 'branch' | 'tag' | 'commit';
93
93
  interface RefMatch {
94
94
  type: RefType;
95
95
  name: string;
96
+ /** Fully-qualified form — `refs/heads/<name>` for branches, `refs/tags/<name>` for tags, the SHA itself for commits. Any `ref` value round-trips through `refs.resolve`. */
97
+ ref: string;
96
98
  /** SHA the ref points to. In `refs.search` results on GitHub and Gitea, annotated tags carry the tag object SHA rather than the commit; `refs.resolve` and `tags.get` always return the peeled commit SHA. */
97
99
  sha: string;
98
100
  raw: unknown;
99
101
  }
102
+ /** `RefMatch` as produced by provider adapters, before the client derives the fully-qualified `ref`. */
103
+ type ProviderRefMatch = Omit<RefMatch, 'ref'>;
100
104
  interface Webhook {
101
105
  id: string;
102
106
  url: string;
@@ -188,8 +192,9 @@ interface GetTagParams extends BaseParams {
188
192
  }
189
193
  interface ResolveRefParams extends BaseParams {
190
194
  repo: string;
195
+ /** A branch or tag name, a fully-qualified ref (`refs/heads/…`, `refs/tags/…`), a 4–40 hex commit SHA, or `HEAD`. */
191
196
  ref: string;
192
- /** Restrict resolution to one ref type; when omitted, branches and tags are tried (tag wins on collision) before falling back to commit SHAs. */
197
+ /** Restrict resolution to one ref type; when omitted, a full 40-hex `ref` is tried as a commit first, then branches and tags (tag wins on collision), then abbreviated commit SHAs. A fully-qualified `ref` implies its type; passing a contradicting `type` throws a validation error. */
193
198
  type?: RefType;
194
199
  }
195
200
  interface SearchRefsParams extends BaseParams {
@@ -269,7 +274,7 @@ interface RepoProvider {
269
274
  /** Exact-match a tag by name, peeled to the commit SHA for annotated tags; throws `not_found` on a miss. */
270
275
  getTag(params: GetTagParams): Promise<Tag>;
271
276
  /** Prefix-match refs of the requested types, branches before tags, at most `limit` results. */
272
- searchRefs(params: ProviderSearchRefsParams): Promise<RefMatch[]>;
277
+ searchRefs(params: ProviderSearchRefsParams): Promise<ProviderRefMatch[]>;
273
278
  downloadArchive(params: DownloadArchiveParams): Promise<Archive>;
274
279
  getCloneUrl(params: GetCloneUrlParams): Promise<CloneUrl>;
275
280
  createWebhook(params: CreateWebhookParams): Promise<Webhook>;
@@ -279,4 +284,4 @@ interface RepoProvider {
279
284
  deleteWebhook(params: DeleteWebhookParams): Promise<void>;
280
285
  }
281
286
  //#endregion
282
- export { ProviderSearchRefsParams as A, UpdateWebhookParams as B, ListTagsParams as C, Page as D, NamespaceKind as E, Repository as F, Webhook as H, ResolveRefParams as I, SearchRefsParams as L, RefType as M, RepoCapabilities as N, ParsedWebhookEvent as O, RepoProvider as P, Tag as R, ListRepositoriesParams as S, Namespace as T, WebhookEventType as U, UserRef as V, WebhookVerificationMethod as W, GitActor as _, CloneUrl as a, ListCommitsParams as b, DeleteWebhookParams as c, GetBranchParams as d, GetCloneUrlParams as f, GetWebhookParams as g, GetTagParams as h, Branch as i, RefMatch as j, ProviderName as k, DownloadArchiveParams as l, GetRepositoryParams as m, ArchiveFormat as n, Commit as o, GetCommitParams as p, AuthenticatedUser as r, CreateWebhookParams as s, Archive as t, GetAuthenticatedUserParams as u, IncomingWebhookRequest as v, ListWebhooksParams as w, ListNamespacesParams as x, ListBranchesParams as y, TokenProvider as z };
287
+ export { ProviderRefMatch as A, TokenProvider as B, ListTagsParams as C, Page as D, NamespaceKind as E, RepoProvider as F, WebhookVerificationMethod as G, UserRef as H, Repository as I, ResolveRefParams as L, RefMatch as M, RefType as N, ParsedWebhookEvent as O, RepoCapabilities as P, SearchRefsParams as R, ListRepositoriesParams as S, Namespace as T, Webhook as U, UpdateWebhookParams as V, WebhookEventType as W, GitActor as _, CloneUrl as a, ListCommitsParams as b, DeleteWebhookParams as c, GetBranchParams as d, GetCloneUrlParams as f, GetWebhookParams as g, GetTagParams as h, Branch as i, ProviderSearchRefsParams as j, ProviderName as k, DownloadArchiveParams as l, GetRepositoryParams as m, ArchiveFormat as n, Commit as o, GetCommitParams as p, AuthenticatedUser as r, CreateWebhookParams as s, Archive as t, GetAuthenticatedUserParams as u, IncomingWebhookRequest as v, ListWebhooksParams as w, ListNamespacesParams as x, ListBranchesParams as y, Tag as z };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "repo-sdk",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Unified TypeScript SDK for git providers — GitHub, GitLab, Bitbucket, Azure DevOps, Gitea",
5
5
  "license": "MIT",
6
6
  "author": "Robin Genz <mail@robingenz.dev>",