@gitkraken/core-gitlens 0.45.0 → 0.46.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.
Files changed (235) hide show
  1. package/CHANGELOG.md +27 -1
  2. package/dist/git/models/remote.js +2 -2
  3. package/dist/git/models/remote.js.map +1 -1
  4. package/dist/git/remotes/matcher.js +25 -3
  5. package/dist/git/remotes/matcher.js.map +1 -1
  6. package/dist/git/utils/branchLanded.utils.d.ts +7 -0
  7. package/dist/git/utils/branchLanded.utils.js +10 -1
  8. package/dist/git/utils/branchLanded.utils.js.map +1 -1
  9. package/dist/git/utils/remote.utils.d.ts +1 -0
  10. package/dist/git/utils/remote.utils.js +14 -5
  11. package/dist/git/utils/remote.utils.js.map +1 -1
  12. package/dist/git-cli/parsers/logParser.js +227 -468
  13. package/dist/git-cli/parsers/logParser.js.map +1 -1
  14. package/dist/git-cli/parsers/refParser.js +4 -4
  15. package/dist/git-cli/parsers/refParser.js.map +1 -1
  16. package/dist/git-cli/providers/branches.d.ts +5 -0
  17. package/dist/git-cli/providers/branches.js +25 -21
  18. package/dist/git-cli/providers/branches.js.map +1 -1
  19. package/dist/plus/git-github/api/github.d.ts +6 -1
  20. package/dist/plus/git-github/api/github.js +14 -4
  21. package/dist/plus/git-github/api/github.js.map +1 -1
  22. package/dist/plus/git-github/api/issueWrites.d.ts +6 -1
  23. package/dist/plus/git-github/api/issueWrites.js +61 -31
  24. package/dist/plus/git-github/api/issueWrites.js.map +1 -1
  25. package/dist/plus/integrations/authentication/cloudIntegrationAuthenticationProvider.d.ts +44 -0
  26. package/dist/plus/integrations/authentication/cloudIntegrationAuthenticationProvider.js +199 -0
  27. package/dist/plus/integrations/authentication/cloudIntegrationAuthenticationProvider.js.map +1 -0
  28. package/dist/plus/integrations/authentication/configuredIntegrationService.d.ts +7 -0
  29. package/dist/plus/integrations/authentication/configuredIntegrationService.js +53 -7
  30. package/dist/plus/integrations/authentication/configuredIntegrationService.js.map +1 -1
  31. package/dist/plus/integrations/authentication/integrationAuthenticationProvider.d.ts +2 -38
  32. package/dist/plus/integrations/authentication/integrationAuthenticationProvider.js +0 -199
  33. package/dist/plus/integrations/authentication/integrationAuthenticationService.d.ts +4 -2
  34. package/dist/plus/integrations/authentication/integrationAuthenticationService.js +12 -1
  35. package/dist/plus/integrations/authentication/integrationAuthenticationService.js.map +1 -1
  36. package/dist/plus/integrations/authentication/models.d.ts +0 -1
  37. package/dist/plus/integrations/authentication/models.js +1 -2
  38. package/dist/plus/integrations/authentication/models.js.map +1 -1
  39. package/dist/plus/integrations/constants.d.ts +0 -10
  40. package/dist/plus/integrations/constants.js +1 -95
  41. package/dist/plus/integrations/constants.js.map +1 -1
  42. package/dist/plus/integrations/context.d.ts +13 -13
  43. package/dist/plus/integrations/index.d.ts +39 -24
  44. package/dist/plus/integrations/index.js +40 -8
  45. package/dist/plus/integrations/index.js.map +1 -1
  46. package/dist/plus/integrations/integrationService.d.ts +15 -22
  47. package/dist/plus/integrations/integrationService.js +39 -12
  48. package/dist/plus/integrations/integrationService.js.map +1 -1
  49. package/dist/plus/integrations/lite.js +1 -1
  50. package/dist/plus/integrations/lite.js.map +1 -1
  51. package/dist/plus/integrations/manager.d.ts +65 -17
  52. package/dist/plus/integrations/models/actionablePullRequest.d.ts +213 -0
  53. package/dist/plus/integrations/models/actionablePullRequest.js +25 -0
  54. package/dist/plus/integrations/models/actionablePullRequest.js.map +1 -0
  55. package/dist/plus/integrations/models/gitHostIntegration.d.ts +13 -46
  56. package/dist/plus/integrations/models/gitHostIntegration.js +15 -4
  57. package/dist/plus/integrations/models/gitHostIntegration.js.map +1 -1
  58. package/dist/plus/integrations/models/integration.d.ts +10 -175
  59. package/dist/plus/integrations/models/integration.js +11 -72
  60. package/dist/plus/integrations/models/integration.js.map +1 -1
  61. package/dist/plus/integrations/models/issuesIntegration.d.ts +9 -5
  62. package/dist/plus/integrations/models/issuesIntegration.js +5 -3
  63. package/dist/plus/integrations/models/issuesIntegration.js.map +1 -1
  64. package/dist/plus/integrations/models/publicIntegration.d.ts +252 -0
  65. package/dist/plus/integrations/models/publicIntegration.js +21 -0
  66. package/dist/plus/integrations/models/publicIntegration.js.map +1 -0
  67. package/dist/plus/integrations/providerFilters.d.ts +58 -0
  68. package/dist/plus/integrations/providerFilters.js.map +1 -1
  69. package/dist/plus/integrations/providers/actionablePullRequests.d.ts +19 -0
  70. package/dist/plus/integrations/providers/actionablePullRequests.js +32 -0
  71. package/dist/plus/integrations/providers/actionablePullRequests.js.map +1 -0
  72. package/dist/plus/integrations/providers/apiClients.d.ts +1 -2
  73. package/dist/plus/integrations/providers/apiClients.js.map +1 -1
  74. package/dist/plus/integrations/providers/asana.d.ts +3 -2
  75. package/dist/plus/integrations/providers/asana.js +2 -1
  76. package/dist/plus/integrations/providers/asana.js.map +1 -1
  77. package/dist/plus/integrations/providers/azure/azure.d.ts +1 -1
  78. package/dist/plus/integrations/providers/azure/azure.utils.d.ts +10 -3
  79. package/dist/plus/integrations/providers/azure/azure.utils.js +5 -1
  80. package/dist/plus/integrations/providers/azure/azure.utils.js.map +1 -1
  81. package/dist/plus/integrations/providers/azure/models.d.ts +1 -5
  82. package/dist/plus/integrations/providers/azure/models.js +1 -1
  83. package/dist/plus/integrations/providers/azure/models.js.map +1 -1
  84. package/dist/plus/integrations/providers/azureDevOps.d.ts +8 -5
  85. package/dist/plus/integrations/providers/azureDevOps.js +2 -1
  86. package/dist/plus/integrations/providers/azureDevOps.js.map +1 -1
  87. package/dist/plus/integrations/providers/azureDevOpsServer.d.ts +5 -4
  88. package/dist/plus/integrations/providers/azureDevOpsServer.js +3 -1
  89. package/dist/plus/integrations/providers/azureDevOpsServer.js.map +1 -1
  90. package/dist/plus/integrations/providers/bitbucket/bitbucket.d.ts +2 -2
  91. package/dist/plus/integrations/providers/bitbucket/bitbucket.js.map +1 -1
  92. package/dist/plus/integrations/providers/bitbucket/models.d.ts +1 -1
  93. package/dist/plus/integrations/providers/bitbucket/models.js.map +1 -1
  94. package/dist/plus/integrations/providers/bitbucket-server.d.ts +5 -4
  95. package/dist/plus/integrations/providers/bitbucket-server.js +2 -1
  96. package/dist/plus/integrations/providers/bitbucket-server.js.map +1 -1
  97. package/dist/plus/integrations/providers/bitbucket.d.ts +4 -3
  98. package/dist/plus/integrations/providers/bitbucket.js +2 -1
  99. package/dist/plus/integrations/providers/bitbucket.js.map +1 -1
  100. package/dist/plus/integrations/providers/github/github.d.ts +0 -1
  101. package/dist/plus/integrations/providers/github/github.js +1 -1
  102. package/dist/plus/integrations/providers/github/github.js.map +1 -1
  103. package/dist/plus/integrations/providers/github.d.ts +11 -6
  104. package/dist/plus/integrations/providers/github.js +70 -26
  105. package/dist/plus/integrations/providers/github.js.map +1 -1
  106. package/dist/plus/integrations/providers/gitlab/gitlab.d.ts +2 -2
  107. package/dist/plus/integrations/providers/gitlab/gitlab.js +1 -2
  108. package/dist/plus/integrations/providers/gitlab/gitlab.js.map +1 -1
  109. package/dist/plus/integrations/providers/gitlab/gitlab.utils.d.ts +14 -1
  110. package/dist/plus/integrations/providers/gitlab/gitlab.utils.js.map +1 -1
  111. package/dist/plus/integrations/providers/gitlab/models.d.ts +2 -10
  112. package/dist/plus/integrations/providers/gitlab/models.js.map +1 -1
  113. package/dist/plus/integrations/providers/gitlab.d.ts +7 -5
  114. package/dist/plus/integrations/providers/gitlab.js +2 -1
  115. package/dist/plus/integrations/providers/gitlab.js.map +1 -1
  116. package/dist/plus/integrations/providers/jira-server.d.ts +4 -4
  117. package/dist/plus/integrations/providers/jira-server.js +3 -2
  118. package/dist/plus/integrations/providers/jira-server.js.map +1 -1
  119. package/dist/plus/integrations/providers/jira.d.ts +3 -3
  120. package/dist/plus/integrations/providers/jira.js +3 -2
  121. package/dist/plus/integrations/providers/jira.js.map +1 -1
  122. package/dist/plus/integrations/providers/jiraIssueByKey.d.ts +1 -1
  123. package/dist/plus/integrations/providers/jiraIssueByKey.js.map +1 -1
  124. package/dist/plus/integrations/providers/linear.d.ts +4 -3
  125. package/dist/plus/integrations/providers/linear.js +3 -2
  126. package/dist/plus/integrations/providers/linear.js.map +1 -1
  127. package/dist/plus/integrations/providers/linearIssuesEtag.d.ts +1 -1
  128. package/dist/plus/integrations/providers/linearIssuesEtag.js +1 -1
  129. package/dist/plus/integrations/providers/linearIssuesEtag.js.map +1 -1
  130. package/dist/plus/integrations/providers/metadata.d.ts +136 -0
  131. package/dist/plus/integrations/providers/metadata.js +513 -0
  132. package/dist/plus/integrations/providers/metadata.js.map +1 -0
  133. package/dist/plus/integrations/providers/models.d.ts +10 -206
  134. package/dist/plus/integrations/providers/models.js +8 -539
  135. package/dist/plus/integrations/providers/models.js.map +1 -1
  136. package/dist/plus/integrations/providers/providersApi.d.ts +3 -2
  137. package/dist/plus/integrations/providers/providersApi.js +2 -1
  138. package/dist/plus/integrations/providers/providersApi.js.map +1 -1
  139. package/dist/plus/integrations/providers/trello.d.ts +1 -1
  140. package/dist/plus/integrations/providers/trello.js +2 -1
  141. package/dist/plus/integrations/providers/trello.js.map +1 -1
  142. package/dist/plus/integrations/providers/utils/providerPaging.d.ts +2 -0
  143. package/dist/plus/integrations/providers/utils/providerPaging.js +3 -2
  144. package/dist/plus/integrations/providers/utils/providerPaging.js.map +1 -1
  145. package/dist/plus/integrations/providers/utils.d.ts +119 -10
  146. package/dist/plus/integrations/providers/utils.js +57 -3
  147. package/dist/plus/integrations/providers/utils.js.map +1 -1
  148. package/dist/plus/integrations/reads/autolinks.d.ts +1 -1
  149. package/dist/plus/integrations/reads/autolinks.js +1 -1
  150. package/dist/plus/integrations/reads/autolinks.js.map +1 -1
  151. package/dist/plus/integrations/reads/broaden.d.ts +1 -1
  152. package/dist/plus/integrations/reads/broaden.js +3 -2
  153. package/dist/plus/integrations/reads/broaden.js.map +1 -1
  154. package/dist/plus/integrations/reads/context.d.ts +1 -1
  155. package/dist/plus/integrations/reads/counts.d.ts +1 -88
  156. package/dist/plus/integrations/reads/counts.js +4 -2
  157. package/dist/plus/integrations/reads/counts.js.map +1 -1
  158. package/dist/plus/integrations/reads/currentAccount.d.ts +1 -18
  159. package/dist/plus/integrations/reads/currentAccount.js.map +1 -1
  160. package/dist/plus/integrations/reads/drains.d.ts +3 -3
  161. package/dist/plus/integrations/reads/drains.js +1 -1
  162. package/dist/plus/integrations/reads/drains.js.map +1 -1
  163. package/dist/plus/integrations/reads/etag.d.ts +174 -3
  164. package/dist/plus/integrations/reads/etag.js +69 -14
  165. package/dist/plus/integrations/reads/etag.js.map +1 -1
  166. package/dist/plus/integrations/reads/filters.d.ts +3 -61
  167. package/dist/plus/integrations/reads/filters.js +1 -1
  168. package/dist/plus/integrations/reads/filters.js.map +1 -1
  169. package/dist/plus/integrations/reads/hierarchy.d.ts +1 -1
  170. package/dist/plus/integrations/reads/hierarchy.js +4 -2
  171. package/dist/plus/integrations/reads/hierarchy.js.map +1 -1
  172. package/dist/plus/integrations/reads/issueBatch.d.ts +2 -102
  173. package/dist/plus/integrations/reads/issueBatch.js +3 -4
  174. package/dist/plus/integrations/reads/issueBatch.js.map +1 -1
  175. package/dist/plus/integrations/reads/issueTracker.d.ts +1 -1
  176. package/dist/plus/integrations/reads/issueTracker.js +4 -3
  177. package/dist/plus/integrations/reads/issueTracker.js.map +1 -1
  178. package/dist/plus/integrations/reads/issues.d.ts +1 -1
  179. package/dist/plus/integrations/reads/issues.js +4 -2
  180. package/dist/plus/integrations/reads/issues.js.map +1 -1
  181. package/dist/plus/integrations/reads/paging.d.ts +1 -1
  182. package/dist/plus/integrations/reads/paging.js +1 -1
  183. package/dist/plus/integrations/reads/paging.js.map +1 -1
  184. package/dist/plus/integrations/reads/pullRequestActivity.d.ts +1 -24
  185. package/dist/plus/integrations/reads/pullRequestActivity.js +2 -1
  186. package/dist/plus/integrations/reads/pullRequestActivity.js.map +1 -1
  187. package/dist/plus/integrations/reads/pullRequestBatch.d.ts +2 -56
  188. package/dist/plus/integrations/reads/pullRequestBatch.js +23 -3
  189. package/dist/plus/integrations/reads/pullRequestBatch.js.map +1 -1
  190. package/dist/plus/integrations/reads/pullRequestBranches.d.ts +1 -47
  191. package/dist/plus/integrations/reads/pullRequestBranches.js +2 -1
  192. package/dist/plus/integrations/reads/pullRequestBranches.js.map +1 -1
  193. package/dist/plus/integrations/reads/pullRequestCheckLogs.d.ts +1 -15
  194. package/dist/plus/integrations/reads/pullRequestCheckLogs.js +2 -1
  195. package/dist/plus/integrations/reads/pullRequestCheckLogs.js.map +1 -1
  196. package/dist/plus/integrations/reads/pullRequests.js +4 -2
  197. package/dist/plus/integrations/reads/pullRequests.js.map +1 -1
  198. package/dist/plus/integrations/reads/pullRequestsForCommits.d.ts +1 -16
  199. package/dist/plus/integrations/reads/pullRequestsForCommits.js +2 -1
  200. package/dist/plus/integrations/reads/pullRequestsForCommits.js.map +1 -1
  201. package/dist/plus/integrations/reads/resolveRepository.js +10 -5
  202. package/dist/plus/integrations/reads/resolveRepository.js.map +1 -1
  203. package/dist/plus/integrations/reads/searchIssues.js +2 -1
  204. package/dist/plus/integrations/reads/searchIssues.js.map +1 -1
  205. package/dist/plus/integrations/reads/searchPullRequests.js +2 -1
  206. package/dist/plus/integrations/reads/searchPullRequests.js.map +1 -1
  207. package/dist/plus/integrations/reads/sweeps.d.ts +1 -1
  208. package/dist/plus/integrations/reads/sweeps.js +3 -2
  209. package/dist/plus/integrations/reads/sweeps.js.map +1 -1
  210. package/dist/plus/integrations/reads/warnings.d.ts +1 -1
  211. package/dist/plus/integrations/reads/warnings.js +1 -1
  212. package/dist/plus/integrations/reads/warnings.js.map +1 -1
  213. package/dist/plus/integrations/results.d.ts +324 -2
  214. package/dist/plus/integrations/results.js.map +1 -1
  215. package/dist/plus/integrations/telemetry.d.ts +0 -10
  216. package/dist/plus/integrations/telemetry.js +0 -11
  217. package/dist/plus/integrations/utils/domain.utils.d.ts +1 -0
  218. package/dist/plus/integrations/utils/domain.utils.js +10 -2
  219. package/dist/plus/integrations/utils/domain.utils.js.map +1 -1
  220. package/dist/plus/integrations/utils/integration.utils.d.ts +1 -6
  221. package/dist/plus/integrations/utils/integration.utils.js +2 -9
  222. package/dist/plus/integrations/utils/integration.utils.js.map +1 -1
  223. package/dist/utils/keys/chord.d.ts +13 -2
  224. package/dist/utils/keys/chord.js +76 -17
  225. package/dist/utils/keys/chord.js.map +1 -1
  226. package/dist/utils/keys/keybinding.d.ts +12 -0
  227. package/dist/utils/keys/keybinding.js +52 -2
  228. package/dist/utils/keys/keybinding.js.map +1 -1
  229. package/dist/utils/markdown.d.ts +21 -0
  230. package/dist/utils/markdown.js +33 -1
  231. package/dist/utils/markdown.js.map +1 -1
  232. package/docs/integrations.md +99 -16
  233. package/package.json +5 -1
  234. package/dist/plus/integrations/authentication/integrationAuthenticationProvider.js.map +0 -1
  235. package/dist/plus/integrations/telemetry.js.map +0 -1
@@ -4,9 +4,9 @@ import { Issue, IssueShape } from "../../../git/models/issue.js";
4
4
  import { Account } from "../../../git/models/author.js";
5
5
  import { ProviderAuthenticationSession } from "../authentication/models.js";
6
6
  import { IssuesCloudHostIntegrationId } from "../constants.js";
7
+ import { IntegrationAuthenticationProviderDescriptor } from "../authentication/integrationAuthenticationProvider.js";
7
8
  import { IssuesForProjectOptions, ProjectIssuesDrain } from "../models/issueReads.js";
8
9
  import { IssuesIntegration } from "../models/issuesIntegration.js";
9
- import { IntegrationAuthenticationProviderDescriptor } from "../authentication/integrationAuthenticationProvider.js";
10
10
  //#region ../plus/integrations/src/providers/trello.d.ts
11
11
  /** A Trello board, surfaced as both a "resource" (org analogue) and a "project" for issue reads. */
12
12
  export interface TrelloBoardDescriptor extends IssueResourceDescriptor {}
@@ -2,8 +2,9 @@ import { PromiseCache } from "../../../utils/promiseCache.js";
2
2
  import { isIssueResourceDescriptor } from "../../../git/utils/resourceDescriptor.utils.js";
3
3
  import { IntegrationReadUnavailableError } from "../errors.js";
4
4
  import "../constants.js";
5
- import { fromProviderIssue, providersMetadata, toIssueShape } from "./models.js";
5
+ import { providersMetadata } from "./metadata.js";
6
6
  import { toTokenWithInfo } from "../authentication/models.js";
7
+ import { fromProviderIssue, toIssueShape } from "./models.js";
7
8
  import { IssuesIntegration } from "../models/issuesIntegration.js";
8
9
  //#region ../plus/integrations/src/providers/trello.ts
9
10
  const metadata = providersMetadata["trello"];
@@ -1 +1 @@
1
- {"version":3,"file":"trello.js","names":[],"sources":["../../../../../plus/integrations/src/providers/trello.ts"],"sourcesContent":["import type { Account } from '@gitlens/git/models/author.js';\nimport type { Issue, IssueShape } from '@gitlens/git/models/issue.js';\nimport type { IssueOrPullRequest, IssueOrPullRequestType } from '@gitlens/git/models/issueOrPullRequest.js';\nimport type { IssueResourceDescriptor, ResourceDescriptor } from '@gitlens/git/models/resourceDescriptor.js';\nimport { isIssueResourceDescriptor } from '@gitlens/git/utils/resourceDescriptor.utils.js';\nimport { PromiseCache } from '@gitlens/utils/promiseCache.js';\nimport type { IntegrationAuthenticationProviderDescriptor } from '../authentication/integrationAuthenticationProvider.js';\nimport type { ProviderAuthenticationSession } from '../authentication/models.js';\nimport { toTokenWithInfo } from '../authentication/models.js';\nimport { IssuesCloudHostIntegrationId } from '../constants.js';\nimport { IntegrationReadUnavailableError } from '../errors.js';\nimport type { IssuesForProjectOptions, ProjectIssuesDrain } from '../models/issueReads.js';\nimport { IssuesIntegration } from '../models/issuesIntegration.js';\nimport { fromProviderIssue, providersMetadata, toIssueShape } from './models.js';\n\nconst metadata = providersMetadata[IssuesCloudHostIntegrationId.Trello];\nconst authProvider = Object.freeze({ id: metadata.id, scopes: metadata.scopes });\n/** Long enough to span one tracker read, short enough that a profile change shows on the next. */\nconst recentAccountTTL = 60 * 1000;\n\n/** A Trello board, surfaced as both a \"resource\" (org analogue) and a \"project\" for issue reads. */\nexport interface TrelloBoardDescriptor extends IssueResourceDescriptor {}\n\nexport class TrelloIntegration extends IssuesIntegration<IssuesCloudHostIntegrationId.Trello> {\n\treadonly authProvider: IntegrationAuthenticationProviderDescriptor = authProvider;\n\n\toverride get id(): IssuesCloudHostIntegrationId.Trello {\n\t\treturn IssuesCloudHostIntegrationId.Trello;\n\t}\n\tprotected override get key(): 'trello' {\n\t\treturn 'trello';\n\t}\n\toverride get name(): string {\n\t\treturn metadata.name;\n\t}\n\toverride get domain(): string {\n\t\treturn metadata.domain;\n\t}\n\n\t/** The Trello client requires the app key paired with the token; a session without one can't read. */\n\tprivate appKeyFor(session: ProviderAuthenticationSession): string | undefined {\n\t\treturn session.appKey;\n\t}\n\n\t/**\n\t * Resolves the app key or throws — a session that authenticated but carries no app key can't read Trello,\n\t * and must be surfaced as a broken read (warning + fetchFailed) rather than an empty account.\n\t */\n\tprivate requireAppKey(session: ProviderAuthenticationSession): string {\n\t\tconst appKey = this.appKeyFor(session);\n\t\tif (appKey == null) {\n\t\t\tthrow new IntegrationReadUnavailableError(metadata.name, 'missing app key (session has no appKey)');\n\t\t}\n\t\treturn appKey;\n\t}\n\n\t/**\n\t * Always asks Trello: the host's current-account cache decides when this runs. The member lookup is\n\t * account-wide, so the answer is lent briefly to the per-board lookup a tracker read makes right after it.\n\t */\n\tprotected override async getProviderCurrentAccount(\n\t\tsession: ProviderAuthenticationSession,\n\t): Promise<Account | undefined> {\n\t\tconst account = await this.fetchAccount(session);\n\t\tif (account != null) {\n\t\t\tthis._recentAccounts.set(session.accessToken, Promise.resolve(account));\n\t\t}\n\t\treturn account;\n\t}\n\n\tprotected override getProviderUncachedAccountForResource(\n\t\tsession: ProviderAuthenticationSession,\n\t\t_resource: ResourceDescriptor,\n\t): Promise<Account | undefined> {\n\t\treturn this.fetchAccount(session, this.requireAppKey(session));\n\t}\n\n\tprotected override async getProviderAccountForResource(\n\t\tsession: ProviderAuthenticationSession,\n\t\t_resource: ResourceDescriptor,\n\t): Promise<Account | undefined> {\n\t\tconst appKey = this.requireAppKey(session);\n\t\treturn this._recentAccounts.getOrCreate(session.accessToken, () => this.fetchAccount(session, appKey), {\n\t\t\tevictWhen: account => account == null,\n\t\t});\n\t}\n\n\tprotected override clearDiscoveryCaches(): void {\n\t\tthis._recentAccounts.clear();\n\t}\n\n\tprivate readonly _recentAccounts = new PromiseCache<string, Account | undefined>({\n\t\tcapacity: 10,\n\t\tcreateTTL: recentAccountTTL,\n\t});\n\n\tprivate async fetchAccount(\n\t\tsession: ProviderAuthenticationSession,\n\t\tappKey: string = this.requireAppKey(session),\n\t): Promise<Account | undefined> {\n\t\tconst api = await this.getProvidersApi();\n\t\tconst user = await api.getTrelloCurrentUser(toTokenWithInfo(this.id, session), appKey);\n\t\tif (user == null) return undefined;\n\n\t\treturn {\n\t\t\tprovider: this,\n\t\t\tid: user.id,\n\t\t\tname: user.name,\n\t\t\tusername: user.username,\n\t\t\temail: user.email,\n\t\t\tavatarUrl: user.avatarUrl ?? undefined,\n\t\t};\n\t}\n\n\tprotected override async getProviderResourcesForUser(\n\t\tsession: ProviderAuthenticationSession,\n\t): Promise<TrelloBoardDescriptor[] | undefined> {\n\t\tconst appKey = this.requireAppKey(session);\n\n\t\tconst api = await this.getProvidersApi();\n\t\tconst boards = await api.getTrelloBoardsForCurrentUser(toTokenWithInfo(this.id, session), appKey);\n\t\treturn boards?.map(b => ({ key: b.id, id: b.id, name: b.name }));\n\t}\n\n\tprotected override getProviderProjectsForResources(\n\t\t_session: ProviderAuthenticationSession,\n\t\tresources: ResourceDescriptor[],\n\t): Promise<TrelloBoardDescriptor[] | undefined> {\n\t\t// Trello boards are both the resource and the project scope, so projects are the boards themselves.\n\t\treturn Promise.resolve(\n\t\t\tresources.filter(isIssueResourceDescriptor).map(r => ({ key: r.key, id: r.id, name: r.name })),\n\t\t);\n\t}\n\n\tprotected override async getProviderIssuesForProject(\n\t\tsession: ProviderAuthenticationSession,\n\t\tproject: ResourceDescriptor,\n\t\toptions?: IssuesForProjectOptions,\n\t): Promise<IssueShape[] | undefined> {\n\t\treturn (await this.getProviderIssuesForProjectWithTruncation(session, project, options))?.values;\n\t}\n\n\tprotected override async getProviderIssuesForProjectWithTruncation(\n\t\tsession: ProviderAuthenticationSession,\n\t\tproject: ResourceDescriptor,\n\t\toptions?: IssuesForProjectOptions,\n\t): Promise<ProjectIssuesDrain | undefined> {\n\t\t// A non-issue descriptor genuinely has nothing to read (empty), but a missing app key is a broken read.\n\t\tif (!isIssueResourceDescriptor(project)) return undefined;\n\n\t\t// The board read always excludes archived cards, and a card has no other state, so only open cards can be\n\t\t// read. Refused rather than ignored: answering `closed` with the open cards would publish them as closed.\n\t\tif (options?.state != null && options.state !== 'open') {\n\t\t\tthrow new IntegrationReadUnavailableError(metadata.name, `issue state '${options.state}' is not supported`);\n\t\t}\n\n\t\tconst appKey = this.requireAppKey(session);\n\n\t\tconst api = await this.getProvidersApi();\n\t\tconst tokenWithInfo = toTokenWithInfo(this.id, session);\n\n\t\t// Enrich issues with their board list names (card status), mirroring gitkraken.dev's Trello reads.\n\t\tconst lists = await api.getTrelloListsForBoard(tokenWithInfo, appKey, project.id);\n\t\tconst trelloBoardListsById = lists?.reduce<Record<string, { name: string }>>((acc, list) => {\n\t\t\tacc[list.id] = { name: list.name };\n\t\t\treturn acc;\n\t\t}, {});\n\t\tconst boardProject = {\n\t\t\tid: project.id,\n\t\t\tname: project.name,\n\t\t\tresourceId: project.id,\n\t\t\tresourceName: project.name,\n\t\t};\n\n\t\tconst result = await api.getTrelloIssuesForBoard(tokenWithInfo, appKey, project.id, {\n\t\t\tassigneeLogins: options?.user != null ? [options.user] : undefined,\n\t\t\ttrelloBoardListsById: trelloBoardListsById,\n\t\t\tsort: options?.sort,\n\t\t});\n\n\t\tconst values = result.values.flatMap(issue => {\n\t\t\tconst mapped = toIssueShape(issue, this, { projection: 'project' });\n\t\t\treturn mapped == null ? [] : [{ ...mapped, project: boardProject } satisfies IssueShape];\n\t\t});\n\n\t\t// Trello's search caps results and reports the cap through `metadata.completeness` (partial/unknown),\n\t\t// never a cursor. Surface that as terminal truncation; there is no next page to fetch, so retrying the\n\t\t// same read cannot recover the omitted cards (D11).\n\t\tconst truncated = result.metadata != null && result.metadata.completeness !== 'complete';\n\t\treturn truncated\n\t\t\t? { values: values, truncated: true, recovery: 'none', metadata: result.metadata }\n\t\t\t: { values: values, truncated: false, metadata: result.metadata };\n\t}\n\n\tprotected override searchProviderMyIssues(\n\t\t_session: ProviderAuthenticationSession,\n\t\t_resources?: ResourceDescriptor[],\n\t\t_cancellation?: AbortSignal,\n\t): Promise<IssueShape[] | undefined> {\n\t\t// Trello has no cross-board \"issues assigned to me\" endpoint; issues are read per board via\n\t\t// getIssuesForProject. Callers that need them enumerate boards first.\n\t\treturn Promise.resolve(undefined);\n\t}\n\n\tprotected override getProviderLinkedIssueOrPullRequest(\n\t\t_session: ProviderAuthenticationSession,\n\t\t_resource: ResourceDescriptor,\n\t\t_id: { id: string; key: string },\n\t\t_type: undefined | IssueOrPullRequestType,\n\t): Promise<IssueOrPullRequest | undefined> {\n\t\treturn Promise.resolve(undefined);\n\t}\n\n\tprotected override async getProviderIssue(\n\t\tsession: ProviderAuthenticationSession,\n\t\tresource: ResourceDescriptor,\n\t\tid: string,\n\t): Promise<Issue | undefined> {\n\t\tif (!isIssueResourceDescriptor(resource)) return undefined;\n\n\t\tconst appKey = this.requireAppKey(session);\n\t\tconst api = await this.getProvidersApi();\n\t\tconst tokenWithInfo = toTokenWithInfo(this.id, session);\n\t\tconst lists = await api.getTrelloListsForBoard(tokenWithInfo, appKey, resource.id);\n\t\tconst trelloBoardListsById = lists?.reduce<Record<string, { name: string }>>((acc, list) => {\n\t\t\tacc[list.id] = { name: list.name };\n\t\t\treturn acc;\n\t\t}, {});\n\n\t\t// Branch-association round-trips use the encoded entity identifier's stable Trello card id. Resolve that\n\t\t// directly so large boards don't require a capped whole-board scan; keep a numeric idShort fallback so\n\t\t// legacy/manual callers that still pass the board-local display number continue to resolve.\n\t\tlet issue = await api.getTrelloCard(tokenWithInfo, appKey, id, {\n\t\t\ttrelloBoardListsById: trelloBoardListsById,\n\t\t});\n\t\tif (issue == null && /^[0-9]+$/.test(id)) {\n\t\t\tissue = (\n\t\t\t\tawait api.getTrelloIssuesForBoard(tokenWithInfo, appKey, resource.id, {\n\t\t\t\t\ttrelloBoardListsById: trelloBoardListsById,\n\t\t\t\t})\n\t\t\t).values.find(issue => issue.number === id);\n\t\t}\n\n\t\treturn issue != null\n\t\t\t? fromProviderIssue(issue, this, {\n\t\t\t\t\tprojection: 'point',\n\t\t\t\t\tproject: {\n\t\t\t\t\t\tid: resource.id,\n\t\t\t\t\t\tname: resource.name,\n\t\t\t\t\t\tresourceId: resource.id,\n\t\t\t\t\t\tresourceName: resource.name,\n\t\t\t\t\t},\n\t\t\t\t})\n\t\t\t: undefined;\n\t}\n}\n"],"mappings":";;;;;;;;AAeA,MAAM,WAAW,kBAAA;AACjB,MAAM,eAAe,OAAO,OAAO;CAAE,IAAI,SAAS;CAAI,QAAQ,SAAS;AAAO,CAAC;;AAE/E,MAAM,mBAAmB;AAKzB,IAAa,oBAAb,cAAuC,kBAAuD;CAC7F,eAAqE;CAErE,IAAa,KAA0C;EACtD,OAAA;CACD;CACA,IAAuB,MAAgB;EACtC,OAAO;CACR;CACA,IAAa,OAAe;EAC3B,OAAO,SAAS;CACjB;CACA,IAAa,SAAiB;EAC7B,OAAO,SAAS;CACjB;;CAGA,UAAkB,SAA4D;EAC7E,OAAO,QAAQ;CAChB;;;;;CAMA,cAAsB,SAAgD;EACrE,MAAM,SAAS,KAAK,UAAU,OAAO;EACrC,IAAI,UAAU,MACb,MAAM,IAAI,gCAAgC,SAAS,MAAM,yCAAyC;EAEnG,OAAO;CACR;;;;;CAMA,MAAyB,0BACxB,SAC+B;EAC/B,MAAM,UAAU,MAAM,KAAK,aAAa,OAAO;EAC/C,IAAI,WAAW,MACd,KAAK,gBAAgB,IAAI,QAAQ,aAAa,QAAQ,QAAQ,OAAO,CAAC;EAEvE,OAAO;CACR;CAEA,sCACC,SACA,WAC+B;EAC/B,OAAO,KAAK,aAAa,SAAS,KAAK,cAAc,OAAO,CAAC;CAC9D;CAEA,MAAyB,8BACxB,SACA,WAC+B;EAC/B,MAAM,SAAS,KAAK,cA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QAAQ,GAAG,OAAO,KAAA;EAEjD,MAAM,SAAS,KAAK,cAAc,OAAO;EACzC,MAAM,MAAM,MAAM,KAAK,gBAAgB;EACvC,MAAM,gBAAgB,gBAAgB,KAAK,IAAI,OAAO;EAEtD,MAAM,wBAAuB,MADT,IAAI,uBAAuB,eAAe,QAAQ,SAAS,EAAE,EAAA,EAC7C,QAA0C,KAAK,SAAS;GAC3F,IAAI,KAAK,MAAM,EAAE,MAAM,KAAK,KAAK;GACjC,OAAO;EACR,GAAG,CAAC,CAAC;EAKL,IAAI,QAAQ,MAAM,IAAI,cAAc,eAAe,QAAQ,IAAI,EACxC,qBACvB,CAAC;EACD,IAAI,SAAS,QAAQ,WAAW,KAAK,EAAE,GACtC,SACC,MAAM,IAAI,wBAAwB,eAAe,QAAQ,SAAS,IAAI,EAC/C,qBACvB,CAAC,EAAA,CACA,OAAO,MAAK,UAAS,MAAM,WAAW,EAAE;EAG3C,OAAO,SAAS,OACb,kBAAkB,OAAO,MAAM;GAC/B,YAAY;GACZ,SAAS;IACR,IAAI,SAAS;IACb,MAAM,SAAS;IACf,YAAY,SAAS;IACrB,cAAc,SAAS;GACxB;EACD,CAAC,IACA,KAAA;CACJ;AACD"}
1
+ {"version":3,"file":"trello.js","names":[],"sources":["../../../../../plus/integrations/src/providers/trello.ts"],"sourcesContent":["import type { Account } from '@gitlens/git/models/author.js';\nimport type { Issue, IssueShape } from '@gitlens/git/models/issue.js';\nimport type { IssueOrPullRequest, IssueOrPullRequestType } from '@gitlens/git/models/issueOrPullRequest.js';\nimport type { IssueResourceDescriptor, ResourceDescriptor } from '@gitlens/git/models/resourceDescriptor.js';\nimport { isIssueResourceDescriptor } from '@gitlens/git/utils/resourceDescriptor.utils.js';\nimport { PromiseCache } from '@gitlens/utils/promiseCache.js';\nimport type { IntegrationAuthenticationProviderDescriptor } from '../authentication/integrationAuthenticationProvider.js';\nimport type { ProviderAuthenticationSession } from '../authentication/models.js';\nimport { toTokenWithInfo } from '../authentication/models.js';\nimport { IssuesCloudHostIntegrationId } from '../constants.js';\nimport { IntegrationReadUnavailableError } from '../errors.js';\nimport type { IssuesForProjectOptions, ProjectIssuesDrain } from '../models/issueReads.js';\nimport { IssuesIntegration } from '../models/issuesIntegration.js';\nimport { providersMetadata } from './metadata.js';\nimport { fromProviderIssue, toIssueShape } from './models.js';\n\nconst metadata = providersMetadata[IssuesCloudHostIntegrationId.Trello];\nconst authProvider = Object.freeze({ id: metadata.id, scopes: metadata.scopes });\n/** Long enough to span one tracker read, short enough that a profile change shows on the next. */\nconst recentAccountTTL = 60 * 1000;\n\n/** A Trello board, surfaced as both a \"resource\" (org analogue) and a \"project\" for issue reads. */\nexport interface TrelloBoardDescriptor extends IssueResourceDescriptor {}\n\nexport class TrelloIntegration extends IssuesIntegration<IssuesCloudHostIntegrationId.Trello> {\n\treadonly authProvider: IntegrationAuthenticationProviderDescriptor = authProvider;\n\n\toverride get id(): IssuesCloudHostIntegrationId.Trello {\n\t\treturn IssuesCloudHostIntegrationId.Trello;\n\t}\n\tprotected override get key(): 'trello' {\n\t\treturn 'trello';\n\t}\n\toverride get name(): string {\n\t\treturn metadata.name;\n\t}\n\toverride get domain(): string {\n\t\treturn metadata.domain;\n\t}\n\n\t/** The Trello client requires the app key paired with the token; a session without one can't read. */\n\tprivate appKeyFor(session: ProviderAuthenticationSession): string | undefined {\n\t\treturn session.appKey;\n\t}\n\n\t/**\n\t * Resolves the app key or throws — a session that authenticated but carries no app key can't read Trello,\n\t * and must be surfaced as a broken read (warning + fetchFailed) rather than an empty account.\n\t */\n\tprivate requireAppKey(session: ProviderAuthenticationSession): string {\n\t\tconst appKey = this.appKeyFor(session);\n\t\tif (appKey == null) {\n\t\t\tthrow new IntegrationReadUnavailableError(metadata.name, 'missing app key (session has no appKey)');\n\t\t}\n\t\treturn appKey;\n\t}\n\n\t/**\n\t * Always asks Trello: the host's current-account cache decides when this runs. The member lookup is\n\t * account-wide, so the answer is lent briefly to the per-board lookup a tracker read makes right after it.\n\t */\n\tprotected override async getProviderCurrentAccount(\n\t\tsession: ProviderAuthenticationSession,\n\t): Promise<Account | undefined> {\n\t\tconst account = await this.fetchAccount(session);\n\t\tif (account != null) {\n\t\t\tthis._recentAccounts.set(session.accessToken, Promise.resolve(account));\n\t\t}\n\t\treturn account;\n\t}\n\n\tprotected override getProviderUncachedAccountForResource(\n\t\tsession: ProviderAuthenticationSession,\n\t\t_resource: ResourceDescriptor,\n\t): Promise<Account | undefined> {\n\t\treturn this.fetchAccount(session, this.requireAppKey(session));\n\t}\n\n\tprotected override async getProviderAccountForResource(\n\t\tsession: ProviderAuthenticationSession,\n\t\t_resource: ResourceDescriptor,\n\t): Promise<Account | undefined> {\n\t\tconst appKey = this.requireAppKey(session);\n\t\treturn this._recentAccounts.getOrCreate(session.accessToken, () => this.fetchAccount(session, appKey), {\n\t\t\tevictWhen: account => account == null,\n\t\t});\n\t}\n\n\tprotected override clearDiscoveryCaches(): void {\n\t\tthis._recentAccounts.clear();\n\t}\n\n\tprivate readonly _recentAccounts = new PromiseCache<string, Account | undefined>({\n\t\tcapacity: 10,\n\t\tcreateTTL: recentAccountTTL,\n\t});\n\n\tprivate async fetchAccount(\n\t\tsession: ProviderAuthenticationSession,\n\t\tappKey: string = this.requireAppKey(session),\n\t): Promise<Account | undefined> {\n\t\tconst api = await this.getProvidersApi();\n\t\tconst user = await api.getTrelloCurrentUser(toTokenWithInfo(this.id, session), appKey);\n\t\tif (user == null) return undefined;\n\n\t\treturn {\n\t\t\tprovider: this,\n\t\t\tid: user.id,\n\t\t\tname: user.name,\n\t\t\tusername: user.username,\n\t\t\temail: user.email,\n\t\t\tavatarUrl: user.avatarUrl ?? undefined,\n\t\t};\n\t}\n\n\tprotected override async getProviderResourcesForUser(\n\t\tsession: ProviderAuthenticationSession,\n\t): Promise<TrelloBoardDescriptor[] | undefined> {\n\t\tconst appKey = this.requireAppKey(session);\n\n\t\tconst api = await this.getProvidersApi();\n\t\tconst boards = await api.getTrelloBoardsForCurrentUser(toTokenWithInfo(this.id, session), appKey);\n\t\treturn boards?.map(b => ({ key: b.id, id: b.id, name: b.name }));\n\t}\n\n\tprotected override getProviderProjectsForResources(\n\t\t_session: ProviderAuthenticationSession,\n\t\tresources: ResourceDescriptor[],\n\t): Promise<TrelloBoardDescriptor[] | undefined> {\n\t\t// Trello boards are both the resource and the project scope, so projects are the boards themselves.\n\t\treturn Promise.resolve(\n\t\t\tresources.filter(isIssueResourceDescriptor).map(r => ({ key: r.key, id: r.id, name: r.name })),\n\t\t);\n\t}\n\n\tprotected override async getProviderIssuesForProject(\n\t\tsession: ProviderAuthenticationSession,\n\t\tproject: ResourceDescriptor,\n\t\toptions?: IssuesForProjectOptions,\n\t): Promise<IssueShape[] | undefined> {\n\t\treturn (await this.getProviderIssuesForProjectWithTruncation(session, project, options))?.values;\n\t}\n\n\tprotected override async getProviderIssuesForProjectWithTruncation(\n\t\tsession: ProviderAuthenticationSession,\n\t\tproject: ResourceDescriptor,\n\t\toptions?: IssuesForProjectOptions,\n\t): Promise<ProjectIssuesDrain | undefined> {\n\t\t// A non-issue descriptor genuinely has nothing to read (empty), but a missing app key is a broken read.\n\t\tif (!isIssueResourceDescriptor(project)) return undefined;\n\n\t\t// The board read always excludes archived cards, and a card has no other state, so only open cards can be\n\t\t// read. Refused rather than ignored: answering `closed` with the open cards would publish them as closed.\n\t\tif (options?.state != null && options.state !== 'open') {\n\t\t\tthrow new IntegrationReadUnavailableError(metadata.name, `issue state '${options.state}' is not supported`);\n\t\t}\n\n\t\tconst appKey = this.requireAppKey(session);\n\n\t\tconst api = await this.getProvidersApi();\n\t\tconst tokenWithInfo = toTokenWithInfo(this.id, session);\n\n\t\t// Enrich issues with their board list names (card status), mirroring gitkraken.dev's Trello reads.\n\t\tconst lists = await api.getTrelloListsForBoard(tokenWithInfo, appKey, project.id);\n\t\tconst trelloBoardListsById = lists?.reduce<Record<string, { name: string }>>((acc, list) => {\n\t\t\tacc[list.id] = { name: list.name };\n\t\t\treturn acc;\n\t\t}, {});\n\t\tconst boardProject = {\n\t\t\tid: project.id,\n\t\t\tname: project.name,\n\t\t\tresourceId: project.id,\n\t\t\tresourceName: project.name,\n\t\t};\n\n\t\tconst result = await api.getTrelloIssuesForBoard(tokenWithInfo, appKey, project.id, {\n\t\t\tassigneeLogins: options?.user != null ? [options.user] : undefined,\n\t\t\ttrelloBoardListsById: trelloBoardListsById,\n\t\t\tsort: options?.sort,\n\t\t});\n\n\t\tconst values = result.values.flatMap(issue => {\n\t\t\tconst mapped = toIssueShape(issue, this, { projection: 'project' });\n\t\t\treturn mapped == null ? [] : [{ ...mapped, project: boardProject } satisfies IssueShape];\n\t\t});\n\n\t\t// Trello's search caps results and reports the cap through `metadata.completeness` (partial/unknown),\n\t\t// never a cursor. Surface that as terminal truncation; there is no next page to fetch, so retrying the\n\t\t// same read cannot recover the omitted cards (D11).\n\t\tconst truncated = result.metadata != null && result.metadata.completeness !== 'complete';\n\t\treturn truncated\n\t\t\t? { values: values, truncated: true, recovery: 'none', metadata: result.metadata }\n\t\t\t: { values: values, truncated: false, metadata: result.metadata };\n\t}\n\n\tprotected override searchProviderMyIssues(\n\t\t_session: ProviderAuthenticationSession,\n\t\t_resources?: ResourceDescriptor[],\n\t\t_cancellation?: AbortSignal,\n\t): Promise<IssueShape[] | undefined> {\n\t\t// Trello has no cross-board \"issues assigned to me\" endpoint; issues are read per board via\n\t\t// getIssuesForProject. Callers that need them enumerate boards first.\n\t\treturn Promise.resolve(undefined);\n\t}\n\n\tprotected override getProviderLinkedIssueOrPullRequest(\n\t\t_session: ProviderAuthenticationSession,\n\t\t_resource: ResourceDescriptor,\n\t\t_id: { id: string; key: string },\n\t\t_type: undefined | IssueOrPullRequestType,\n\t): Promise<IssueOrPullRequest | undefined> {\n\t\treturn Promise.resolve(undefined);\n\t}\n\n\tprotected override async getProviderIssue(\n\t\tsession: ProviderAuthenticationSession,\n\t\tresource: ResourceDescriptor,\n\t\tid: string,\n\t): Promise<Issue | undefined> {\n\t\tif (!isIssueResourceDescriptor(resource)) return undefined;\n\n\t\tconst appKey = this.requireAppKey(session);\n\t\tconst api = await this.getProvidersApi();\n\t\tconst tokenWithInfo = toTokenWithInfo(this.id, session);\n\t\tconst lists = await api.getTrelloListsForBoard(tokenWithInfo, appKey, resource.id);\n\t\tconst trelloBoardListsById = lists?.reduce<Record<string, { name: string }>>((acc, list) => {\n\t\t\tacc[list.id] = { name: list.name };\n\t\t\treturn acc;\n\t\t}, {});\n\n\t\t// Branch-association round-trips use the encoded entity identifier's stable Trello card id. Resolve that\n\t\t// directly so large boards don't require a capped whole-board scan; keep a numeric idShort fallback so\n\t\t// legacy/manual callers that still pass the board-local display number continue to resolve.\n\t\tlet issue = await api.getTrelloCard(tokenWithInfo, appKey, id, {\n\t\t\ttrelloBoardListsById: trelloBoardListsById,\n\t\t});\n\t\tif (issue == null && /^[0-9]+$/.test(id)) {\n\t\t\tissue = (\n\t\t\t\tawait api.getTrelloIssuesForBoard(tokenWithInfo, appKey, resource.id, {\n\t\t\t\t\ttrelloBoardListsById: trelloBoardListsById,\n\t\t\t\t})\n\t\t\t).values.find(issue => issue.number === id);\n\t\t}\n\n\t\treturn issue != null\n\t\t\t? fromProviderIssue(issue, this, {\n\t\t\t\t\tprojection: 'point',\n\t\t\t\t\tproject: {\n\t\t\t\t\t\tid: resource.id,\n\t\t\t\t\t\tname: resource.name,\n\t\t\t\t\t\tresourceId: resource.id,\n\t\t\t\t\t\tresourceName: resource.name,\n\t\t\t\t\t},\n\t\t\t\t})\n\t\t\t: undefined;\n\t}\n}\n"],"mappings":";;;;;;;;;AAgBA,MAAM,WAAW,kBAAA;AACjB,MAAM,eAAe,OAAO,OAAO;CAAE,IAAI,SAAS;CAAI,QAAQ,SAAS;AAAO,CAAC;;AAE/E,MAAM,mBAAmB;AAKzB,IAAa,oBAAb,cAAuC,kBAAuD;CAC7F,eAAqE;CAErE,IAAa,KAA0C;EACtD,OAAA;CACD;CACA,IAAuB,MAAgB;EACtC,OAAO;CACR;C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ACZ,SAAS;IACR,IAAI,SAAS;IACb,MAAM,SAAS;IACf,YAAY,SAAS;IACrB,cAAc,SAAS;GACxB;EACD,CAAC,IACA,KAAA;CACJ;AACD"}
@@ -2,6 +2,8 @@ import { PullRequestShape } from "../../../../git/models/pullRequest.js";
2
2
  import { ProviderApiPagedResult, ProviderHierarchyResult } from "../models.js";
3
3
  import { CollectionMetadata, CollectionScopeFailure, CollectionSkippedItems } from "@gitkraken/provider-apis";
4
4
  //#region ../plus/integrations/src/providers/utils/providerPaging.d.ts
5
+ /** Upper bound on concurrent provider requests when a read fans out across repos, orgs or batches. */
6
+ export declare const providerFanOutConcurrency = 6;
5
7
  /**
6
8
  * Encodes an opaque numeric paging token as the `{ value, type: 'page' }` cursor the paging layer uses.
7
9
  * The value is whatever the consumer round-trips unchanged: a 1-based page number for numbered-page reads,
@@ -2,10 +2,11 @@ import { uniqueBy } from "../../../../utils/iterable.js";
2
2
  import { chunk } from "../../../../utils/array.js";
3
3
  import { isCancellationError } from "../../../../utils/cancellation.js";
4
4
  import { mapSettledBounded } from "../../../../utils/promise.js";
5
- import "../../constants.js";
6
5
  import { collectionScopeKey, mergeUnreadableItems } from "../../results.js";
7
6
  import { normalizeSkippedItems, throwIfCallerContractError, toCollectionScopeFailure } from "../../collectionMetadata.js";
8
7
  //#region ../plus/integrations/src/providers/utils/providerPaging.ts
8
+ /** Upper bound on concurrent provider requests when a read fans out across repos, orgs or batches. */
9
+ const providerFanOutConcurrency = 6;
9
10
  /**
10
11
  * Encodes an opaque numeric paging token as the `{ value, type: 'page' }` cursor the paging layer uses.
11
12
  * The value is whatever the consumer round-trips unchanged: a 1-based page number for numbered-page reads,
@@ -292,6 +293,6 @@ async function collectProviderPagedResult(fetch, maxPages = 20, scope) {
292
293
  return build();
293
294
  }
294
295
  //#endregion
295
- export { collectProviderPagedResult, flatSettledOrThrow, flatSettledResultsOrThrow, mergeCollectionMetadata, mergeSkippedItems, parsePageCursor, readEtagFieldsByRepository, resolveBranchPullRequests, selectBranchPullRequests, throwIfAllSettledFailed, toPageCursor };
296
+ export { collectProviderPagedResult, flatSettledOrThrow, flatSettledResultsOrThrow, mergeCollectionMetadata, mergeSkippedItems, parsePageCursor, providerFanOutConcurrency, readEtagFieldsByRepository, resolveBranchPullRequests, selectBranchPullRequests, throwIfAllSettledFailed, toPageCursor };
296
297
 
297
298
  //# sourceMappingURL=providerPaging.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"providerPaging.js","names":[],"sources":["../../../../../../plus/integrations/src/providers/utils/providerPaging.ts"],"sourcesContent":["import type {\n\tCollectionCompleteness,\n\tCollectionMetadata,\n\tCollectionOmission,\n\tCollectionScopeFailure,\n\tCollectionSkippedItems,\n} from '@gitkraken/provider-apis';\nimport type { PullRequestShape } from '@gitlens/git/models/pullRequest.js';\nimport { chunk } from '@gitlens/utils/array.js';\nimport { isCancellationError } from '@gitlens/utils/cancellation.js';\nimport { uniqueBy } from '@gitlens/utils/iterable.js';\nimport { mapSettledBounded } from '@gitlens/utils/promise.js';\nimport type { ProviderScopeFailure } from '../../collectionMetadata.js';\nimport {\n\tnormalizeSkippedItems,\n\tthrowIfCallerContractError,\n\ttoCollectionScopeFailure,\n} from '../../collectionMetadata.js';\nimport { providerFanOutConcurrency } from '../../constants.js';\nimport { collectionScopeKey, mergeUnreadableItems } from '../../results.js';\nimport type { ProviderApiPagedResult, ProviderHierarchyResult } from '../models.js';\n\n/**\n * Encodes an opaque numeric paging token as the `{ value, type: 'page' }` cursor the paging layer uses.\n * The value is whatever the consumer round-trips unchanged: a 1-based page number for numbered-page reads,\n * or a provider offset (e.g. Bitbucket Server's `nextPageStart`) that is never reinterpreted here.\n */\nexport function toPageCursor(page: number): string {\n\treturn JSON.stringify({ value: page, type: 'page' });\n}\n\n/** Extracts the numeric paging token from a `{ value, type: 'page' }` cursor; undefined when absent/malformed. */\nexport function parsePageCursor(cursor: string | undefined): number | undefined {\n\tif (cursor == null || cursor === '{}') return undefined;\n\n\ttry {\n\t\tconst parsed = JSON.parse(cursor) as { value?: unknown; type?: unknown };\n\t\tif (parsed.type === 'page' && typeof parsed.value === 'number') return parsed.value;\n\t} catch {}\n\n\treturn undefined;\n}\n\n/** Preserves successful sibling scopes, but doesn't turn an all-scope provider failure into an empty success. */\nexport function throwIfAllSettledFailed<T>(results: PromiseSettledResult<T>[]): void {\n\tif (results.some(result => result.status === 'fulfilled')) return;\n\n\tconst rejected = results.find((result): result is PromiseRejectedResult => result.status === 'rejected');\n\tif (rejected != null) throw rejected.reason;\n}\n\n/**\n * The answer a pull-requests-by-branch read gives for one branch: the rows `matchesHead` accepts, newest first, at\n * most `limit` of them, each passed through `map`. Rows are filtered before they're mapped, so a non-matching row\n * can't fail the answer. `more` says the host holds rows it didn't return; the filter can't see those, so they make\n * the answer `truncated` however few rows passed it.\n */\nexport function selectBranchPullRequests<T, R>(\n\trows: readonly T[],\n\toptions: {\n\t\tmatchesHead: (row: T) => boolean;\n\t\tupdatedAt: (row: T) => number;\n\t\tmap: (row: T) => R;\n\t\tlimit: number;\n\t\tmore: boolean;\n\t},\n): { values: R[]; truncated: boolean } {\n\tconst matched = rows.filter(options.matchesHead).sort((a, b) => options.updatedAt(b) - options.updatedAt(a));\n\treturn {\n\t\tvalues: matched.slice(0, options.limit).map(options.map),\n\t\ttruncated: options.more || matched.length > options.limit,\n\t};\n}\n\n/**\n * The second step of a pull-requests-by-branch read on a host whose branch query can't return the batch read's\n * rows: resolves each target's matched numbers through `resolve` (the host's `getProviderPullRequestsBatch`), so a\n * pull request comes back identical whichever read found it.\n *\n * One `resolve` call for every target's numbers, so the host's own fan-out bounds the concurrency. A number it\n * reports absent (deleted between the two steps) is dropped; one it couldn't check rejects the whole target, since\n * a partial list would read as a complete one. The first step's order is kept.\n */\nexport async function resolveBranchPullRequests(\n\ttargets: readonly { owner: string; repo: string; project?: string }[],\n\tfound: readonly PromiseSettledResult<{ numbers: number[]; truncated: boolean }>[],\n\tresolve: (\n\t\tcoordinates: { owner: string; repo: string; number: number; project?: string }[],\n\t) => Promise<PromiseSettledResult<PullRequestShape | undefined>[] | undefined>,\n): Promise<PromiseSettledResult<{ pullRequests: PullRequestShape[]; truncated: boolean }>[]> {\n\tconst coordinates = found.flatMap((slot, i) =>\n\t\tslot.status === 'fulfilled'\n\t\t\t? slot.value.numbers.map(number => ({\n\t\t\t\t\towner: targets[i].owner,\n\t\t\t\t\trepo: targets[i].repo,\n\t\t\t\t\tnumber: number,\n\t\t\t\t\tproject: targets[i].project,\n\t\t\t\t}))\n\t\t\t: [],\n\t);\n\n\tlet resolved: PromiseSettledResult<PullRequestShape | undefined>[] = [];\n\tif (coordinates.length > 0) {\n\t\ttry {\n\t\t\tresolved =\n\t\t\t\t(await resolve(coordinates)) ??\n\t\t\t\tcoordinates.map(() => ({\n\t\t\t\t\tstatus: 'rejected',\n\t\t\t\t\treason: new Error('Pull requests could not be resolved'),\n\t\t\t\t}));\n\t\t} catch (ex) {\n\t\t\tresolved = coordinates.map(() => ({ status: 'rejected', reason: ex }));\n\t\t}\n\t}\n\n\tlet offset = 0;\n\treturn found.map(slot => {\n\t\tif (slot.status === 'rejected') return slot;\n\n\t\tconst slots = resolved.slice(offset, offset + slot.value.numbers.length);\n\t\toffset += slot.value.numbers.length;\n\n\t\tconst failure = slots.find((s): s is PromiseRejectedResult => s.status === 'rejected');\n\t\tif (failure != null) return failure;\n\n\t\treturn {\n\t\t\tstatus: 'fulfilled',\n\t\t\tvalue: {\n\t\t\t\tpullRequests: slots.flatMap(s => (s.status === 'fulfilled' && s.value != null ? [s.value] : [])),\n\t\t\t\ttruncated: slot.value.truncated,\n\t\t\t},\n\t\t};\n\t});\n}\n\n/**\n * Runs a cheap etag read over `coordinates` with one request per repository and chunk of `chunkSize` numbers, with\n * bounded concurrency, and maps the answers back to the coordinates positionally (`read` answers one entry per\n * number, in order, `undefined` for a proven absence). Settled per target: a request that throws rejects only its\n * own slots, and a slot whose conversion throws rejects only itself.\n */\nexport async function readEtagFieldsByRepository<Node, Fields>(\n\tcoordinates: readonly { owner: string; repo: string; number: number }[],\n\tchunkSize: number,\n\tread: (owner: string, repo: string, numbers: number[]) => Promise<(Node | undefined)[]>,\n\tmap: (node: Node) => Fields,\n): Promise<PromiseSettledResult<Fields | undefined>[]> {\n\tconst byRepository = new Map<string, number[]>();\n\tfor (const [index, c] of coordinates.entries()) {\n\t\tconst key = `${c.owner}/${c.repo}`;\n\t\tlet indices = byRepository.get(key);\n\t\tif (indices == null) {\n\t\t\tindices = [];\n\t\t\tbyRepository.set(key, indices);\n\t\t}\n\t\tindices.push(index);\n\t}\n\n\tconst requests = [...byRepository.values()].flatMap(indices =>\n\t\tchunk(indices, chunkSize).map(chunkIndices => ({ indices: chunkIndices })),\n\t);\n\tconst answers = await mapSettledBounded(requests, providerFanOutConcurrency, r => {\n\t\tconst { owner, repo } = coordinates[r.indices[0]];\n\t\treturn read(\n\t\t\towner,\n\t\t\trepo,\n\t\t\tr.indices.map(i => coordinates[i].number),\n\t\t);\n\t});\n\n\tconst slots = new Array<PromiseSettledResult<Fields | undefined>>(coordinates.length);\n\tfor (const [i, answer] of answers.entries()) {\n\t\tfor (const [j, index] of requests[i].indices.entries()) {\n\t\t\tif (answer.status === 'rejected') {\n\t\t\t\tslots[index] = answer;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst node = answer.value[j];\n\t\t\ttry {\n\t\t\t\tslots[index] = { status: 'fulfilled', value: node != null ? map(node) : undefined };\n\t\t\t} catch (ex) {\n\t\t\t\tslots[index] = { status: 'rejected', reason: ex };\n\t\t\t}\n\t\t}\n\t}\n\treturn slots;\n}\n\nexport function flatSettledResultsOrThrow<T>(results: PromiseSettledResult<T[]>[]): T[] {\n\tthrowIfAllSettledFailed(results);\n\n\tconst fulfilled = results.filter((result): result is PromiseFulfilledResult<T[]> => result.status === 'fulfilled');\n\treturn fulfilled.flatMap(result => result.value);\n}\n\nexport async function flatSettledOrThrow<T>(promises: Promise<T[]>[]): Promise<T[]> {\n\treturn flatSettledResultsOrThrow(await Promise.allSettled(promises));\n}\n\n/** Precedence for merged completeness: any known omission (`partial`) wins, then inability to confirm\n * (`unknown`), and only an all-`complete` set of pages stays `complete`. */\nconst completenessRank: Record<CollectionCompleteness, number> = { partial: 2, unknown: 1, complete: 0 };\n\n/**\n * A stable key for deduplicating structurally-identical scope failures accumulated across drained pages: kind, scope IDs\n * and message. A failure that reports skipped items is keyed by kind and scope alone, never by message: it is one\n * account of what a scope skipped, however the reads that reported it worded it or split the issues over their pages\n * (the message is display prose, and names a different handful of issues and pages in each). And it never shares a key\n * with one that doesn't: that one says nothing of which items were read, however alike their messages.\n */\nfunction collectionFailureKey(failure: CollectionScopeFailure): string {\n\treturn failure.skippedItems != null\n\t\t? ['skipped', failure.kind, collectionScopeKey(failure.scope)].join(' ')\n\t\t: [failure.kind, collectionScopeKey(failure.scope), failure.message ?? ''].join(' ');\n}\n\n/**\n * The items two reports of skipped items left out together: the union of their keys in reported order, complete only\n * when both are, and a total that depends on whether the reads can overlap. Reads of the same scope that each search for\n * something else (an issue the assignee and the author relationships both reach) are `'overlapping'`: which issues they\n * share isn't known, so the total is the larger of the two and never less than the keys named, a lower bound. The pages\n * of one drain are `'disjoint'`, so their totals add (a key repeated across pages that shifted counts once per page).\n * Both are normalized first ({@link normalizeSkippedItems}).\n */\nexport function mergeSkippedItems(\n\texisting: CollectionSkippedItems,\n\tnext: CollectionSkippedItems,\n\treads: 'disjoint' | 'overlapping',\n): CollectionSkippedItems {\n\tconst a = normalizeSkippedItems(existing);\n\tconst b = normalizeSkippedItems(next);\n\tconst { keys, complete } = mergeUnreadableItems(a, b);\n\treturn {\n\t\tkeys: keys,\n\t\ttotal: reads === 'disjoint' ? a.total + b.total : Math.max(a.total, b.total, keys.length),\n\t\tcomplete: complete,\n\t};\n}\n\n/**\n * A stable key for collapsing omissions accumulated across drained pages, matching the SDK's own\n * `dedupeOmissions`: kind plus scope IDs, deliberately WITHOUT `limit`/`totalCount`.\n *\n * Those counts are a re-measurement, not an identity. GitHub recomputes the match total on every request, so\n * one repository drained over several pages reports the same cap with a drifting total; keying on the total\n * would emit a near-identical warning per page (\"matched 1393…\", \"matched 1402…\") that\n * `appendDedupedWarning` cannot collapse, since the messages genuinely differ. Independently-scoped omissions\n * still stay distinct, which is the case that carries information.\n */\nfunction collectionOmissionKey(omission: CollectionOmission): string {\n\treturn [omission.kind, collectionScopeKey(omission.scope)].join(' ');\n}\n\n/**\n * Merges SDK collection metadata across drained pages. Completeness follows {@link completenessRank};\n * failures are deduplicated by kind and scope IDs for those that report `skippedItems` ({@link collectionFailureKey}),\n * and by kind, scope IDs and message for the rest, and omissions are collapsed per kind and scope\n * keeping the highest reported total ({@link collectionOmissionKey}). Both preserve first-reported order. Two failures\n * that report skipped items merge them instead of the first winning ({@link mergeSkippedItems}), and the merged failure\n * keeps the message of the one that names more keys (the first when they name as many), so the text covers at least\n * what the larger report does, whichever came first. `reads` says how the items add up: `'overlapping'`, the default,\n * suits any reads that may reach the same item (a user's relationships), and a caller merging the successive pages of\n * one drain says `'disjoint'`. Returns `undefined` when no page supplied metadata, so metadata-free providers and test\n * doubles keep behaving as before.\n */\nexport function mergeCollectionMetadata(\n\tbase: CollectionMetadata | undefined,\n\tnext: CollectionMetadata | undefined,\n\treads: 'disjoint' | 'overlapping' = 'overlapping',\n): CollectionMetadata | undefined {\n\tif (base == null) return next;\n\tif (next == null) return base;\n\n\tconst completeness =\n\t\tcompletenessRank[next.completeness] > completenessRank[base.completeness]\n\t\t\t? next.completeness\n\t\t\t: base.completeness;\n\n\t// First occurrence wins: a repeated failure carries no new information, since what identifies it is what it says.\n\t// Except for one that reports skipped items, which is keyed without its message and so merges what each report\n\t// skipped; the key guarantees `current` reports skipped items too.\n\tconst failures = [\n\t\t...uniqueBy<string, ProviderScopeFailure>(\n\t\t\t[...(base.failures ?? []), ...(next.failures ?? [])],\n\t\t\tcollectionFailureKey,\n\t\t\t(original, current) => {\n\t\t\t\tif (original.skippedItems == null) return undefined;\n\n\t\t\t\tconst reported = current.skippedItems ?? original.skippedItems;\n\t\t\t\tconst named = (skipped: CollectionSkippedItems) => normalizeSkippedItems(skipped).keys.length;\n\t\t\t\tconst fuller = named(reported) > named(original.skippedItems) ? current : original;\n\t\t\t\treturn {\n\t\t\t\t\t...original,\n\t\t\t\t\t...(fuller.message != null ? { message: fuller.message } : {}),\n\t\t\t\t\tskippedItems: mergeSkippedItems(original.skippedItems, reported, reads),\n\t\t\t\t};\n\t\t\t},\n\t\t),\n\t];\n\t// Highest total wins, so re-measuring one cap across pages collapses to a single omission holding the\n\t// largest figure reported for it — the same rule the SDK applies in `createCollectionMetadata`.\n\tconst omissions = [\n\t\t...uniqueBy(\n\t\t\t[...(base.omissions ?? []), ...(next.omissions ?? [])],\n\t\t\tcollectionOmissionKey,\n\t\t\t(original, current) => ((current.totalCount ?? -1) > (original.totalCount ?? -1) ? current : undefined),\n\t\t),\n\t];\n\n\treturn {\n\t\tcompleteness: completeness,\n\t\t...(failures.length ? { failures: failures } : {}),\n\t\t...(omissions.length ? { omissions: omissions } : {}),\n\t};\n}\n\n/**\n * Drains a provider paged fetcher into a single result while preserving enough metadata to\n * signal whether the defensive backstop interrupted the drain, and merging SDK collection metadata\n * ({@link mergeCollectionMetadata}) across the fetched pages.\n *\n * The local `truncated` flag and SDK `metadata` are distinct facts: a page-drain backstop must remain visible\n * even if every fetched page reported `complete`, and SDK incompleteness is preserved even when the drain\n * finished within its page budget.\n */\nexport async function collectProviderPagedResult<T>(\n\tfetch: (cursor: string | undefined) => Promise<ProviderApiPagedResult<T> | undefined>,\n\tmaxPages = 20,\n\tscope?: CollectionScopeFailure['scope'],\n): Promise<ProviderHierarchyResult<T>> {\n\tconst values: NonNullable<T>[] = [];\n\tlet cursor: string | undefined;\n\tlet metadata: CollectionMetadata | undefined;\n\tlet truncated = false;\n\n\t// Omit `metadata` entirely when no page supplied it, so a metadata-free drain stays deep-equal to its\n\t// pre-metadata shape (and consumers never see an explicit `undefined`).\n\tconst build = (extra?: Partial<ProviderHierarchyResult<T>>): ProviderHierarchyResult<T> => {\n\t\tconst mergedMetadata = extra?.metadata ?? metadata;\n\t\treturn {\n\t\t\tvalues: values,\n\t\t\t...extra,\n\t\t\t...(truncated || extra?.truncated === true ? { truncated: true } : {}),\n\t\t\t...(mergedMetadata != null ? { metadata: mergedMetadata } : {}),\n\t\t};\n\t};\n\n\tfor (let page = 0; page < maxPages; page++) {\n\t\tlet result: ProviderApiPagedResult<T> | undefined;\n\t\ttry {\n\t\t\tresult = await fetch(cursor);\n\t\t} catch (ex) {\n\t\t\tif (isCancellationError(ex)) throw ex;\n\n\t\t\t// A caller-contract error is not a fact about this scope, so it is never recorded as one — see\n\t\t\t// `throwIfCallerContractError`. Checked alongside cancellation because both are errors that a\n\t\t\t// per-scope failure would misdescribe.\n\t\t\tthrowIfCallerContractError(ex);\n\n\t\t\t// When the caller supplied a scope, preserve the items already fetched from that scope and record the\n\t\t\t// failure in collection metadata rather than re-throwing and discarding the prefix. Callers without a\n\t\t\t// scope keep the legacy throw behavior.\n\t\t\tif (scope == null) throw ex;\n\t\t\treturn build({\n\t\t\t\ttruncated: true,\n\t\t\t\tmetadata: mergeCollectionMetadata(metadata, {\n\t\t\t\t\tcompleteness: 'partial',\n\t\t\t\t\tfailures: [toCollectionScopeFailure(scope, ex)],\n\t\t\t\t}),\n\t\t\t});\n\t\t}\n\t\tif (result == null) {\n\t\t\tif (page === 0) return build();\n\n\t\t\treturn build({\n\t\t\t\ttruncated: true,\n\t\t\t\t...(scope != null\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tmetadata: mergeCollectionMetadata(metadata, {\n\t\t\t\t\t\t\t\tcompleteness: 'partial',\n\t\t\t\t\t\t\t\tfailures: [\n\t\t\t\t\t\t\t\t\ttoCollectionScopeFailure(\n\t\t\t\t\t\t\t\t\t\tscope,\n\t\t\t\t\t\t\t\t\t\tnew Error('Provider returned no page after advertising a continuation'),\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t}\n\t\t\t\t\t: undefined),\n\t\t\t});\n\t\t}\n\n\t\tvalues.push(...result.values);\n\t\tmetadata = mergeCollectionMetadata(metadata, result.metadata, 'disjoint');\n\t\ttruncated ||= result.paging?.truncated === true;\n\n\t\tif (!result.paging?.more) return build();\n\n\t\tif (result.paging.cursor === cursor) {\n\t\t\treturn build({ truncated: true });\n\t\t}\n\n\t\tcursor = result.paging.cursor;\n\t\tif (cursor == null || cursor === '{}') {\n\t\t\treturn build({ truncated: true });\n\t\t}\n\t\tif (page === maxPages - 1) {\n\t\t\treturn build({ paging: result.paging, truncated: true });\n\t\t}\n\t}\n\n\treturn build();\n}\n"],"mappings":";;;;;;;;;;;;;AA2BA,SAAgB,aAAa,MAAsB;CAClD,OAAO,KAAK,UAAU;EAAE,OAAO;EAAM,MAAM;CAAO,CAAC;AACpD;;AAGA,SAAgB,gBAAgB,QAAgD;CAC/E,IAAI,UAAU,QAAQ,WAAW,MAAM,OAAO,KAAA;CAE9C,IAAI;EACH,MAAM,SAAS,KAAK,MAAM,MAAM;EAChC,IAAI,OAAO,SAAS,UAAU,OAAO,OAAO,UAAU,UAAU,OAAO,OAAO;CAC/E,QAAQ,CAAC;AAGV;;AAGA,SAAgB,wBAA2B,SAA0C;CACpF,IAAI,QAAQ,MAAK,WAAU,OAAO,WAAW,WAAW,GAAG;CAE3D,MAAM,WAAW,QAAQ,MAAM,WAA4C,OAAO,WAAW,UAAU;CACvG,IAAI,YAAY,MAAM,MAAM,SAAS;AACtC;;;;;;;AAQA,SAAgB,yBACf,MACA,SAOsC;CACtC,MAAM,UAAU,KAAK,OAAO,QAAQ,WAAW,CAAC,CAAC,MAAM,GAAG,MAAM,QAAQ,UAAU,CAAC,IAAI,QAAQ,UAAU,CAAC,CAAC;CAC3G,OAAO;EACN,QAAQ,QAAQ,MAAM,GAAG,QAAQ,KAAK,CAAC,CAAC,IAAI,QAAQ,GAAG;EACvD,WAAW,QAAQ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,UAAU,wBAAwB,UAAU;KAC3C,cAAc;KACd,UAAU,CACT,yBACC,uBACA,IAAI,MAAM,4DAA4D,CACvE,CACD;IACD,CAAC,EACF,IACC,KAAA;GACJ,CAAC;EACF;EAEA,OAAO,KAAK,GAAG,OAAO,MAAM;EAC5B,WAAW,wBAAwB,UAAU,OAAO,UAAU,UAAU;EACxE,cAAc,OAAO,QAAQ,cAAc;EAE3C,IAAI,CAAC,OAAO,QAAQ,MAAM,OAAO,MAAM;EAEvC,IAAI,OAAO,OAAO,WAAW,QAC5B,OAAO,MAAM,EAAE,WAAW,KAAK,CAAC;EAGjC,SAAS,OAAO,OAAO;EACvB,IAAI,UAAU,QAAQ,WAAW,MAChC,OAAO,MAAM,EAAE,WAAW,KAAK,CAAC;EAEjC,IAAI,SAAS,WAAW,GACvB,OAAO,MAAM;GAAE,QAAQ,OAAO;GAAQ,WAAW;EAAK,CAAC;CAEzD;CAEA,OAAO,MAAM;AACd"}
1
+ {"version":3,"file":"providerPaging.js","names":[],"sources":["../../../../../../plus/integrations/src/providers/utils/providerPaging.ts"],"sourcesContent":["import type {\n\tCollectionCompleteness,\n\tCollectionMetadata,\n\tCollectionOmission,\n\tCollectionScopeFailure,\n\tCollectionSkippedItems,\n} from '@gitkraken/provider-apis';\nimport type { PullRequestShape } from '@gitlens/git/models/pullRequest.js';\nimport { chunk } from '@gitlens/utils/array.js';\nimport { isCancellationError } from '@gitlens/utils/cancellation.js';\nimport { uniqueBy } from '@gitlens/utils/iterable.js';\nimport { mapSettledBounded } from '@gitlens/utils/promise.js';\nimport type { ProviderScopeFailure } from '../../collectionMetadata.js';\nimport {\n\tnormalizeSkippedItems,\n\tthrowIfCallerContractError,\n\ttoCollectionScopeFailure,\n} from '../../collectionMetadata.js';\nimport { collectionScopeKey, mergeUnreadableItems } from '../../results.js';\nimport type { ProviderApiPagedResult, ProviderHierarchyResult } from '../models.js';\n\n/** Upper bound on concurrent provider requests when a read fans out across repos, orgs or batches. */\nexport const providerFanOutConcurrency = 6;\n\n/**\n * Encodes an opaque numeric paging token as the `{ value, type: 'page' }` cursor the paging layer uses.\n * The value is whatever the consumer round-trips unchanged: a 1-based page number for numbered-page reads,\n * or a provider offset (e.g. Bitbucket Server's `nextPageStart`) that is never reinterpreted here.\n */\nexport function toPageCursor(page: number): string {\n\treturn JSON.stringify({ value: page, type: 'page' });\n}\n\n/** Extracts the numeric paging token from a `{ value, type: 'page' }` cursor; undefined when absent/malformed. */\nexport function parsePageCursor(cursor: string | undefined): number | undefined {\n\tif (cursor == null || cursor === '{}') return undefined;\n\n\ttry {\n\t\tconst parsed = JSON.parse(cursor) as { value?: unknown; type?: unknown };\n\t\tif (parsed.type === 'page' && typeof parsed.value === 'number') return parsed.value;\n\t} catch {}\n\n\treturn undefined;\n}\n\n/** Preserves successful sibling scopes, but doesn't turn an all-scope provider failure into an empty success. */\nexport function throwIfAllSettledFailed<T>(results: PromiseSettledResult<T>[]): void {\n\tif (results.some(result => result.status === 'fulfilled')) return;\n\n\tconst rejected = results.find((result): result is PromiseRejectedResult => result.status === 'rejected');\n\tif (rejected != null) throw rejected.reason;\n}\n\n/**\n * The answer a pull-requests-by-branch read gives for one branch: the rows `matchesHead` accepts, newest first, at\n * most `limit` of them, each passed through `map`. Rows are filtered before they're mapped, so a non-matching row\n * can't fail the answer. `more` says the host holds rows it didn't return; the filter can't see those, so they make\n * the answer `truncated` however few rows passed it.\n */\nexport function selectBranchPullRequests<T, R>(\n\trows: readonly T[],\n\toptions: {\n\t\tmatchesHead: (row: T) => boolean;\n\t\tupdatedAt: (row: T) => number;\n\t\tmap: (row: T) => R;\n\t\tlimit: number;\n\t\tmore: boolean;\n\t},\n): { values: R[]; truncated: boolean } {\n\tconst matched = rows.filter(options.matchesHead).sort((a, b) => options.updatedAt(b) - options.updatedAt(a));\n\treturn {\n\t\tvalues: matched.slice(0, options.limit).map(options.map),\n\t\ttruncated: options.more || matched.length > options.limit,\n\t};\n}\n\n/**\n * The second step of a pull-requests-by-branch read on a host whose branch query can't return the batch read's\n * rows: resolves each target's matched numbers through `resolve` (the host's `getProviderPullRequestsBatch`), so a\n * pull request comes back identical whichever read found it.\n *\n * One `resolve` call for every target's numbers, so the host's own fan-out bounds the concurrency. A number it\n * reports absent (deleted between the two steps) is dropped; one it couldn't check rejects the whole target, since\n * a partial list would read as a complete one. The first step's order is kept.\n */\nexport async function resolveBranchPullRequests(\n\ttargets: readonly { owner: string; repo: string; project?: string }[],\n\tfound: readonly PromiseSettledResult<{ numbers: number[]; truncated: boolean }>[],\n\tresolve: (\n\t\tcoordinates: { owner: string; repo: string; number: number; project?: string }[],\n\t) => Promise<PromiseSettledResult<PullRequestShape | undefined>[] | undefined>,\n): Promise<PromiseSettledResult<{ pullRequests: PullRequestShape[]; truncated: boolean }>[]> {\n\tconst coordinates = found.flatMap((slot, i) =>\n\t\tslot.status === 'fulfilled'\n\t\t\t? slot.value.numbers.map(number => ({\n\t\t\t\t\towner: targets[i].owner,\n\t\t\t\t\trepo: targets[i].repo,\n\t\t\t\t\tnumber: number,\n\t\t\t\t\tproject: targets[i].project,\n\t\t\t\t}))\n\t\t\t: [],\n\t);\n\n\tlet resolved: PromiseSettledResult<PullRequestShape | undefined>[] = [];\n\tif (coordinates.length > 0) {\n\t\ttry {\n\t\t\tresolved =\n\t\t\t\t(await resolve(coordinates)) ??\n\t\t\t\tcoordinates.map(() => ({\n\t\t\t\t\tstatus: 'rejected',\n\t\t\t\t\treason: new Error('Pull requests could not be resolved'),\n\t\t\t\t}));\n\t\t} catch (ex) {\n\t\t\tresolved = coordinates.map(() => ({ status: 'rejected', reason: ex }));\n\t\t}\n\t}\n\n\tlet offset = 0;\n\treturn found.map(slot => {\n\t\tif (slot.status === 'rejected') return slot;\n\n\t\tconst slots = resolved.slice(offset, offset + slot.value.numbers.length);\n\t\toffset += slot.value.numbers.length;\n\n\t\tconst failure = slots.find((s): s is PromiseRejectedResult => s.status === 'rejected');\n\t\tif (failure != null) return failure;\n\n\t\treturn {\n\t\t\tstatus: 'fulfilled',\n\t\t\tvalue: {\n\t\t\t\tpullRequests: slots.flatMap(s => (s.status === 'fulfilled' && s.value != null ? [s.value] : [])),\n\t\t\t\ttruncated: slot.value.truncated,\n\t\t\t},\n\t\t};\n\t});\n}\n\n/**\n * Runs a cheap etag read over `coordinates` with one request per repository and chunk of `chunkSize` numbers, with\n * bounded concurrency, and maps the answers back to the coordinates positionally (`read` answers one entry per\n * number, in order, `undefined` for a proven absence). Settled per target: a request that throws rejects only its\n * own slots, and a slot whose conversion throws rejects only itself.\n */\nexport async function readEtagFieldsByRepository<Node, Fields>(\n\tcoordinates: readonly { owner: string; repo: string; number: number }[],\n\tchunkSize: number,\n\tread: (owner: string, repo: string, numbers: number[]) => Promise<(Node | undefined)[]>,\n\tmap: (node: Node) => Fields,\n): Promise<PromiseSettledResult<Fields | undefined>[]> {\n\tconst byRepository = new Map<string, number[]>();\n\tfor (const [index, c] of coordinates.entries()) {\n\t\tconst key = `${c.owner}/${c.repo}`;\n\t\tlet indices = byRepository.get(key);\n\t\tif (indices == null) {\n\t\t\tindices = [];\n\t\t\tbyRepository.set(key, indices);\n\t\t}\n\t\tindices.push(index);\n\t}\n\n\tconst requests = [...byRepository.values()].flatMap(indices =>\n\t\tchunk(indices, chunkSize).map(chunkIndices => ({ indices: chunkIndices })),\n\t);\n\tconst answers = await mapSettledBounded(requests, providerFanOutConcurrency, r => {\n\t\tconst { owner, repo } = coordinates[r.indices[0]];\n\t\treturn read(\n\t\t\towner,\n\t\t\trepo,\n\t\t\tr.indices.map(i => coordinates[i].number),\n\t\t);\n\t});\n\n\tconst slots = new Array<PromiseSettledResult<Fields | undefined>>(coordinates.length);\n\tfor (const [i, answer] of answers.entries()) {\n\t\tfor (const [j, index] of requests[i].indices.entries()) {\n\t\t\tif (answer.status === 'rejected') {\n\t\t\t\tslots[index] = answer;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst node = answer.value[j];\n\t\t\ttry {\n\t\t\t\tslots[index] = { status: 'fulfilled', value: node != null ? map(node) : undefined };\n\t\t\t} catch (ex) {\n\t\t\t\tslots[index] = { status: 'rejected', reason: ex };\n\t\t\t}\n\t\t}\n\t}\n\treturn slots;\n}\n\nexport function flatSettledResultsOrThrow<T>(results: PromiseSettledResult<T[]>[]): T[] {\n\tthrowIfAllSettledFailed(results);\n\n\tconst fulfilled = results.filter((result): result is PromiseFulfilledResult<T[]> => result.status === 'fulfilled');\n\treturn fulfilled.flatMap(result => result.value);\n}\n\nexport async function flatSettledOrThrow<T>(promises: Promise<T[]>[]): Promise<T[]> {\n\treturn flatSettledResultsOrThrow(await Promise.allSettled(promises));\n}\n\n/** Precedence for merged completeness: any known omission (`partial`) wins, then inability to confirm\n * (`unknown`), and only an all-`complete` set of pages stays `complete`. */\nconst completenessRank: Record<CollectionCompleteness, number> = { partial: 2, unknown: 1, complete: 0 };\n\n/**\n * A stable key for deduplicating structurally-identical scope failures accumulated across drained pages: kind, scope IDs\n * and message. A failure that reports skipped items is keyed by kind and scope alone, never by message: it is one\n * account of what a scope skipped, however the reads that reported it worded it or split the issues over their pages\n * (the message is display prose, and names a different handful of issues and pages in each). And it never shares a key\n * with one that doesn't: that one says nothing of which items were read, however alike their messages.\n */\nfunction collectionFailureKey(failure: CollectionScopeFailure): string {\n\treturn failure.skippedItems != null\n\t\t? ['skipped', failure.kind, collectionScopeKey(failure.scope)].join(' ')\n\t\t: [failure.kind, collectionScopeKey(failure.scope), failure.message ?? ''].join(' ');\n}\n\n/**\n * The items two reports of skipped items left out together: the union of their keys in reported order, complete only\n * when both are, and a total that depends on whether the reads can overlap. Reads of the same scope that each search for\n * something else (an issue the assignee and the author relationships both reach) are `'overlapping'`: which issues they\n * share isn't known, so the total is the larger of the two and never less than the keys named, a lower bound. The pages\n * of one drain are `'disjoint'`, so their totals add (a key repeated across pages that shifted counts once per page).\n * Both are normalized first ({@link normalizeSkippedItems}).\n */\nexport function mergeSkippedItems(\n\texisting: CollectionSkippedItems,\n\tnext: CollectionSkippedItems,\n\treads: 'disjoint' | 'overlapping',\n): CollectionSkippedItems {\n\tconst a = normalizeSkippedItems(existing);\n\tconst b = normalizeSkippedItems(next);\n\tconst { keys, complete } = mergeUnreadableItems(a, b);\n\treturn {\n\t\tkeys: keys,\n\t\ttotal: reads === 'disjoint' ? a.total + b.total : Math.max(a.total, b.total, keys.length),\n\t\tcomplete: complete,\n\t};\n}\n\n/**\n * A stable key for collapsing omissions accumulated across drained pages, matching the SDK's own\n * `dedupeOmissions`: kind plus scope IDs, deliberately WITHOUT `limit`/`totalCount`.\n *\n * Those counts are a re-measurement, not an identity. GitHub recomputes the match total on every request, so\n * one repository drained over several pages reports the same cap with a drifting total; keying on the total\n * would emit a near-identical warning per page (\"matched 1393…\", \"matched 1402…\") that\n * `appendDedupedWarning` cannot collapse, since the messages genuinely differ. Independently-scoped omissions\n * still stay distinct, which is the case that carries information.\n */\nfunction collectionOmissionKey(omission: CollectionOmission): string {\n\treturn [omission.kind, collectionScopeKey(omission.scope)].join(' ');\n}\n\n/**\n * Merges SDK collection metadata across drained pages. Completeness follows {@link completenessRank};\n * failures are deduplicated by kind and scope IDs for those that report `skippedItems` ({@link collectionFailureKey}),\n * and by kind, scope IDs and message for the rest, and omissions are collapsed per kind and scope\n * keeping the highest reported total ({@link collectionOmissionKey}). Both preserve first-reported order. Two failures\n * that report skipped items merge them instead of the first winning ({@link mergeSkippedItems}), and the merged failure\n * keeps the message of the one that names more keys (the first when they name as many), so the text covers at least\n * what the larger report does, whichever came first. `reads` says how the items add up: `'overlapping'`, the default,\n * suits any reads that may reach the same item (a user's relationships), and a caller merging the successive pages of\n * one drain says `'disjoint'`. Returns `undefined` when no page supplied metadata, so metadata-free providers and test\n * doubles keep behaving as before.\n */\nexport function mergeCollectionMetadata(\n\tbase: CollectionMetadata | undefined,\n\tnext: CollectionMetadata | undefined,\n\treads: 'disjoint' | 'overlapping' = 'overlapping',\n): CollectionMetadata | undefined {\n\tif (base == null) return next;\n\tif (next == null) return base;\n\n\tconst completeness =\n\t\tcompletenessRank[next.completeness] > completenessRank[base.completeness]\n\t\t\t? next.completeness\n\t\t\t: base.completeness;\n\n\t// First occurrence wins: a repeated failure carries no new information, since what identifies it is what it says.\n\t// Except for one that reports skipped items, which is keyed without its message and so merges what each report\n\t// skipped; the key guarantees `current` reports skipped items too.\n\tconst failures = [\n\t\t...uniqueBy<string, ProviderScopeFailure>(\n\t\t\t[...(base.failures ?? []), ...(next.failures ?? [])],\n\t\t\tcollectionFailureKey,\n\t\t\t(original, current) => {\n\t\t\t\tif (original.skippedItems == null) return undefined;\n\n\t\t\t\tconst reported = current.skippedItems ?? original.skippedItems;\n\t\t\t\tconst named = (skipped: CollectionSkippedItems) => normalizeSkippedItems(skipped).keys.length;\n\t\t\t\tconst fuller = named(reported) > named(original.skippedItems) ? current : original;\n\t\t\t\treturn {\n\t\t\t\t\t...original,\n\t\t\t\t\t...(fuller.message != null ? { message: fuller.message } : {}),\n\t\t\t\t\tskippedItems: mergeSkippedItems(original.skippedItems, reported, reads),\n\t\t\t\t};\n\t\t\t},\n\t\t),\n\t];\n\t// Highest total wins, so re-measuring one cap across pages collapses to a single omission holding the\n\t// largest figure reported for it — the same rule the SDK applies in `createCollectionMetadata`.\n\tconst omissions = [\n\t\t...uniqueBy(\n\t\t\t[...(base.omissions ?? []), ...(next.omissions ?? [])],\n\t\t\tcollectionOmissionKey,\n\t\t\t(original, current) => ((current.totalCount ?? -1) > (original.totalCount ?? -1) ? current : undefined),\n\t\t),\n\t];\n\n\treturn {\n\t\tcompleteness: completeness,\n\t\t...(failures.length ? { failures: failures } : {}),\n\t\t...(omissions.length ? { omissions: omissions } : {}),\n\t};\n}\n\n/**\n * Drains a provider paged fetcher into a single result while preserving enough metadata to\n * signal whether the defensive backstop interrupted the drain, and merging SDK collection metadata\n * ({@link mergeCollectionMetadata}) across the fetched pages.\n *\n * The local `truncated` flag and SDK `metadata` are distinct facts: a page-drain backstop must remain visible\n * even if every fetched page reported `complete`, and SDK incompleteness is preserved even when the drain\n * finished within its page budget.\n */\nexport async function collectProviderPagedResult<T>(\n\tfetch: (cursor: string | undefined) => Promise<ProviderApiPagedResult<T> | undefined>,\n\tmaxPages = 20,\n\tscope?: CollectionScopeFailure['scope'],\n): Promise<ProviderHierarchyResult<T>> {\n\tconst values: NonNullable<T>[] = [];\n\tlet cursor: string | undefined;\n\tlet metadata: CollectionMetadata | undefined;\n\tlet truncated = false;\n\n\t// Omit `metadata` entirely when no page supplied it, so a metadata-free drain stays deep-equal to its\n\t// pre-metadata shape (and consumers never see an explicit `undefined`).\n\tconst build = (extra?: Partial<ProviderHierarchyResult<T>>): ProviderHierarchyResult<T> => {\n\t\tconst mergedMetadata = extra?.metadata ?? metadata;\n\t\treturn {\n\t\t\tvalues: values,\n\t\t\t...extra,\n\t\t\t...(truncated || extra?.truncated === true ? { truncated: true } : {}),\n\t\t\t...(mergedMetadata != null ? { metadata: mergedMetadata } : {}),\n\t\t};\n\t};\n\n\tfor (let page = 0; page < maxPages; page++) {\n\t\tlet result: ProviderApiPagedResult<T> | undefined;\n\t\ttry {\n\t\t\tresult = await fetch(cursor);\n\t\t} catch (ex) {\n\t\t\tif (isCancellationError(ex)) throw ex;\n\n\t\t\t// A caller-contract error is not a fact about this scope, so it is never recorded as one — see\n\t\t\t// `throwIfCallerContractError`. Checked alongside cancellation because both are errors that a\n\t\t\t// per-scope failure would misdescribe.\n\t\t\tthrowIfCallerContractError(ex);\n\n\t\t\t// When the caller supplied a scope, preserve the items already fetched from that scope and record the\n\t\t\t// failure in collection metadata rather than re-throwing and discarding the prefix. Callers without a\n\t\t\t// scope keep the legacy throw behavior.\n\t\t\tif (scope == null) throw ex;\n\t\t\treturn build({\n\t\t\t\ttruncated: true,\n\t\t\t\tmetadata: mergeCollectionMetadata(metadata, {\n\t\t\t\t\tcompleteness: 'partial',\n\t\t\t\t\tfailures: [toCollectionScopeFailure(scope, ex)],\n\t\t\t\t}),\n\t\t\t});\n\t\t}\n\t\tif (result == null) {\n\t\t\tif (page === 0) return build();\n\n\t\t\treturn build({\n\t\t\t\ttruncated: true,\n\t\t\t\t...(scope != null\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tmetadata: mergeCollectionMetadata(metadata, {\n\t\t\t\t\t\t\t\tcompleteness: 'partial',\n\t\t\t\t\t\t\t\tfailures: [\n\t\t\t\t\t\t\t\t\ttoCollectionScopeFailure(\n\t\t\t\t\t\t\t\t\t\tscope,\n\t\t\t\t\t\t\t\t\t\tnew Error('Provider returned no page after advertising a continuation'),\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t}\n\t\t\t\t\t: undefined),\n\t\t\t});\n\t\t}\n\n\t\tvalues.push(...result.values);\n\t\tmetadata = mergeCollectionMetadata(metadata, result.metadata, 'disjoint');\n\t\ttruncated ||= result.paging?.truncated === true;\n\n\t\tif (!result.paging?.more) return build();\n\n\t\tif (result.paging.cursor === cursor) {\n\t\t\treturn build({ truncated: true });\n\t\t}\n\n\t\tcursor = result.paging.cursor;\n\t\tif (cursor == null || cursor === '{}') {\n\t\t\treturn build({ truncated: true });\n\t\t}\n\t\tif (page === maxPages - 1) {\n\t\t\treturn build({ paging: result.paging, truncated: true });\n\t\t}\n\t}\n\n\treturn build();\n}\n"],"mappings":";;;;;;;;AAsBA,MAAa,4BAA4B;;;;;;AAOzC,SAAgB,aAAa,MAAsB;CAClD,OAAO,KAAK,UAAU;EAAE,OAAO;EAAM,MAAM;CAAO,CAAC;AACpD;;AAGA,SAAgB,gBAAgB,QAAgD;CAC/E,IAAI,UAAU,QAAQ,WAAW,MAAM,OAAO,KAAA;CAE9C,IAAI;EACH,MAAM,SAAS,KAAK,MAAM,MAAM;EAChC,IAAI,OAAO,SAAS,UAAU,OAAO,OAAO,UAAU,UAAU,OAAO,OAAO;CAC/E,QAAQ,CAAC;AAGV;;AAGA,SAAgB,wBAA2B,SAA0C;CACpF,IAAI,QAAQ,MAAK,WAAU,OA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SAAS,MAAM,MAAM,MAAM;EAC5B,SAAS,IAAI;GACZ,IAAI,oBAAoB,EAAE,GAAG,MAAM;GAKnC,2BAA2B,EAAE;GAK7B,IAAI,SAAS,MAAM,MAAM;GACzB,OAAO,MAAM;IACZ,WAAW;IACX,UAAU,wBAAwB,UAAU;KAC3C,cAAc;KACd,UAAU,CAAC,yBAAyB,OAAO,EAAE,CAAC;IAC/C,CAAC;GACF,CAAC;EACF;EACA,IAAI,UAAU,MAAM;GACnB,IAAI,SAAS,GAAG,OAAO,MAAM;GAE7B,OAAO,MAAM;IACZ,WAAW;IACX,GAAI,SAAS,OACV,EACA,UAAU,wBAAwB,UAAU;KAC3C,cAAc;KACd,UAAU,CACT,yBACC,uBACA,IAAI,MAAM,4DAA4D,CACvE,CACD;IACD,CAAC,EACF,IACC,KAAA;GACJ,CAAC;EACF;EAEA,OAAO,KAAK,GAAG,OAAO,MAAM;EAC5B,WAAW,wBAAwB,UAAU,OAAO,UAAU,UAAU;EACxE,cAAc,OAAO,QAAQ,cAAc;EAE3C,IAAI,CAAC,OAAO,QAAQ,MAAM,OAAO,MAAM;EAEvC,IAAI,OAAO,OAAO,WAAW,QAC5B,OAAO,MAAM,EAAE,WAAW,KAAK,CAAC;EAGjC,SAAS,OAAO,OAAO;EACvB,IAAI,UAAU,QAAQ,WAAW,MAChC,OAAO,MAAM,EAAE,WAAW,KAAK,CAAC;EAEjC,IAAI,SAAS,WAAW,GACvB,OAAO,MAAM;GAAE,QAAQ,OAAO;GAAQ,WAAW;EAAK,CAAC;CAEzD;CAEA,OAAO,MAAM;AACd"}
@@ -1,10 +1,7 @@
1
1
  import { IssueResourceDescriptor, RepositoryDescriptor, ResourceDescriptor } from "../../../git/models/resourceDescriptor.js";
2
- import { Issue as Issue$1, IssueShape } from "../../../git/models/issue.js";
2
+ import { Issue, IssueShape } from "../../../git/models/issue.js";
3
3
  import { PullRequest } from "../../../git/models/pullRequest.js";
4
4
  import { IntegrationIds } from "../constants.js";
5
- import { GitConfigEntityIdentifier } from "./models.js";
6
- import { AzureProjectInputDescriptor } from "./azure/models.js";
7
- import { AnyEntityIdentifierInput, EntityIdentifier } from "@gitkraken/provider-apis";
8
5
  //#region ../plus/integrations/src/providers/utils.d.ts
9
6
  export declare const EntityIdentifierProviderType: {
10
7
  readonly Azure: 'azure';
@@ -28,6 +25,102 @@ export declare const EntityType: {
28
25
  export declare const EntityVersion: {
29
26
  readonly One: '1';
30
27
  };
28
+ export type EntityIdentifierProviderType = (typeof EntityIdentifierProviderType)[keyof typeof EntityIdentifierProviderType];
29
+ export type EntityType = (typeof EntityType)[keyof typeof EntityType];
30
+ /**
31
+ * A decoded entity identifier: a GitLens-neutral copy of provider-apis' `EntityIdentifier`, so consumers never name
32
+ * the SDK. `version` names every version the SDK decodes, unlike {@link EntityVersion}, which lists the one written.
33
+ */
34
+ export interface EntityIdentifier {
35
+ provider: EntityIdentifierProviderType;
36
+ entityType: EntityType;
37
+ version: '0' | '1';
38
+ domain: string | null;
39
+ resourceId: string | null;
40
+ accountOrOrgId: string | null;
41
+ organizationName: string | null;
42
+ projectId: string | null;
43
+ repoId: string | null;
44
+ entityId: string;
45
+ }
46
+ /** The fields an entity identifier can carry. Which of them one needs depends on its provider and entity type. */
47
+ interface EntityIdentifierValues {
48
+ version?: '0' | '1';
49
+ entityId: string;
50
+ domain?: string | null;
51
+ resourceId?: string | null;
52
+ accountOrOrgId?: string | null;
53
+ organizationName?: string | null;
54
+ projectId?: string | null;
55
+ repoId?: string | null;
56
+ }
57
+ /**
58
+ * An entity identifier's fields as {@link getEntityIdentifierInput} builds them for any issue or pull request, and as
59
+ * a branch-issue association stores them ({@link GitConfigEntityIdentifier}): every provider (Linear included), with
60
+ * each provider-specific field nullable. Not every one of these encodes; {@link EntityIdentifierInput} is the subset
61
+ * that does.
62
+ */
63
+ export interface EntityIdentifierFields extends EntityIdentifierValues {
64
+ provider: EntityIdentifierProviderType;
65
+ entityType: EntityType;
66
+ }
67
+ type ProviderOf<K extends keyof typeof EntityIdentifierProviderType> = (typeof EntityIdentifierProviderType)[K];
68
+ /**
69
+ * What {@link encodeEntityIdentifier} accepts: one arm per provider and entity type the codec encodes, each requiring
70
+ * the fields the codec refuses to encode without. Linear isn't encodable at all, and Jira and Trello have no pull
71
+ * requests. The fields an arm doesn't require may still be present (as {@link getEntityIdentifierInput} fills them),
72
+ * and are ignored.
73
+ */
74
+ export type EntityIdentifierInput = (EntityIdentifierValues & {
75
+ provider: ProviderOf<'Github' | 'GithubEnterprise' | 'Gitlab' | 'GitlabSelfHosted'>;
76
+ entityType: EntityType;
77
+ }) | (EntityIdentifierValues & {
78
+ provider: ProviderOf<'Bitbucket' | 'BitbucketServer'>;
79
+ entityType: EntityType;
80
+ repoId: string;
81
+ }) | (EntityIdentifierValues & {
82
+ provider: ProviderOf<'Azure' | 'AzureDevOpsServer'>;
83
+ entityType: typeof EntityType.Issue;
84
+ organizationName: string;
85
+ projectId: string;
86
+ }) | (EntityIdentifierValues & {
87
+ provider: ProviderOf<'Azure' | 'AzureDevOpsServer'>;
88
+ entityType: typeof EntityType.PullRequest;
89
+ organizationName: string;
90
+ projectId: string;
91
+ repoId: string;
92
+ }) | (EntityIdentifierValues & {
93
+ provider: ProviderOf<'Jira' | 'JiraServer'>;
94
+ entityType: typeof EntityType.Issue;
95
+ projectId: string;
96
+ }) | (EntityIdentifierValues & {
97
+ provider: ProviderOf<'Trello'>;
98
+ entityType: typeof EntityType.Issue;
99
+ accountOrOrgId: string;
100
+ projectId: string;
101
+ });
102
+ /** The {@link EntityIdentifierInput} arms for a pull request: what a pull request's identifier encodes as. */
103
+ export type PullRequestEntityIdentifierInput = EntityIdentifierInput & {
104
+ entityType: typeof EntityType.PullRequest;
105
+ };
106
+ /** A branch-issue association as git config stores it: the identifier's fields plus what resolves it back. */
107
+ export type GitConfigEntityIdentifier = EntityIdentifierFields & {
108
+ metadata: {
109
+ id: string;
110
+ owner: {
111
+ key: string;
112
+ name: string;
113
+ id: string | undefined;
114
+ owner: string | undefined;
115
+ };
116
+ createdDate: string;
117
+ isCloudEnterprise?: boolean;
118
+ };
119
+ };
120
+ /** Encodes an entity identifier into the string form Launchpad keys pins/snoozes by and drafts store. */
121
+ export declare function encodeEntityIdentifier(entity: EntityIdentifierInput): string;
122
+ /** Decodes an identifier written by {@link encodeEntityIdentifier}; throws on a malformed one. */
123
+ export declare function decodeEntityIdentifier(encoded: string): EntityIdentifier;
31
124
  /**
32
125
  * Forward-compatible structural shape of the host's `LaunchpadItem`. The package
33
126
  * uses this for narrowing inside {@link getEntityIdentifierInput}; the host's
@@ -53,14 +146,25 @@ type LaunchpadItem = {
53
146
  };
54
147
  };
55
148
  };
56
- export declare function getEntityIdentifierInput(entity: Issue$1 | PullRequest | LaunchpadItem): AnyEntityIdentifierInput;
57
- export declare function getProviderIdFromEntityIdentifier(entityIdentifier: EntityIdentifier | AnyEntityIdentifierInput | GitConfigEntityIdentifier): IntegrationIds | undefined;
58
- export declare function encodeIssueOrPullRequestForGitConfig(entity: Issue$1 | PullRequest, owner: RepositoryDescriptor | IssueResourceDescriptor): GitConfigEntityIdentifier;
149
+ /**
150
+ * The identifier fields of an issue or pull request. A pull request's are checked to encode (see
151
+ * {@link toPullRequestEntityIdentifierInput}), so they can go straight to {@link encodeEntityIdentifier}.
152
+ */
153
+ export declare function getEntityIdentifierInput(entity: PullRequest): PullRequestEntityIdentifierInput;
154
+ export declare function getEntityIdentifierInput(entity: Issue | PullRequest | LaunchpadItem): EntityIdentifierFields;
155
+ export declare function getProviderIdFromEntityIdentifier(entityIdentifier: EntityIdentifier | EntityIdentifierFields | EntityIdentifierInput | GitConfigEntityIdentifier): IntegrationIds | undefined;
156
+ /**
157
+ * Builds the git-config form of a branch-issue association from an issue (the only thing production callers pass).
158
+ * A pull request is accepted but goes through {@link getEntityIdentifierInput}, so it throws when its provider can't
159
+ * encode pull requests (Jira, Trello, Linear) or a field its arm requires is missing (Bitbucket and Bitbucket Server
160
+ * need `repoId`; Azure and Azure DevOps Server need an organization, a project and `repoId`).
161
+ */
162
+ export declare function encodeIssueOrPullRequestForGitConfig(entity: Issue | PullRequest, owner: RepositoryDescriptor | IssueResourceDescriptor): GitConfigEntityIdentifier;
59
163
  export declare function isGitConfigEntityIdentifier(entity: unknown): entity is GitConfigEntityIdentifier;
60
164
  export declare function isGitConfigEntityIdentifiers(entities: unknown): entities is GitConfigEntityIdentifier[];
61
165
  export declare function decodeEntityIdentifiersFromGitConfig(str: string): GitConfigEntityIdentifier[];
62
166
  interface IssueResolvableIntegration {
63
- getIssue(owner: unknown, id: string): Promise<Issue$1 | undefined>;
167
+ getIssue(owner: unknown, id: string): Promise<Issue | undefined>;
64
168
  }
65
169
  /**
66
170
  * Resolves the issue a branch association names.
@@ -81,8 +185,13 @@ export declare function getIssueFromGitConfigEntityIdentifier(resolveIntegration
81
185
  * host (which owns the cache) provides this to satisfy a cache-only read. When omitted, `cached`
82
186
  * yields undefined rather than falling through to a remote fetch.
83
187
  */
84
- peekCachedIssue?: (integration: IssueResolvableIntegration | undefined, resource: ResourceDescriptor, id: string) => Issue$1 | undefined;
85
- }): Promise<Issue$1 | undefined>;
188
+ peekCachedIssue?: (integration: IssueResolvableIntegration | undefined, resource: ResourceDescriptor, id: string) => Issue | undefined;
189
+ }): Promise<Issue | undefined>;
190
+ /** An Azure DevOps project as {@link getIssueOwner} names it: the organization as `owner`, the project as `name`. */
191
+ export interface AzureProjectInputDescriptor extends ResourceDescriptor {
192
+ owner: string;
193
+ name: string;
194
+ }
86
195
  export declare function getIssueOwner(issue: IssueShape): RepositoryDescriptor | IssueResourceDescriptor | AzureProjectInputDescriptor | undefined;
87
196
  //#endregion
88
197
  //# sourceMappingURL=utils.d.ts.map
@@ -1,9 +1,10 @@
1
1
  import { Logger as _logger } from "../../../utils/logger.js";
2
2
  import { isIssueResourceDescriptor, isRepositoryDescriptor } from "../../../git/utils/resourceDescriptor.utils.js";
3
3
  import "../constants.js";
4
+ import { isGitHubDotCom, isGitLabDotCom } from "./metadata.js";
4
5
  import { getSingleConfiguredDomain } from "../utils/domain.utils.js";
5
- import { isGitHubDotCom, isGitLabDotCom } from "./models.js";
6
6
  import { isCloudGitSelfManagedHostIntegrationId, isGitSelfManagedHostIntegrationId, isSelfManagedHostIntegrationId } from "../utils/integration.utils.js";
7
+ import { EntityIdentifierUtils } from "@gitkraken/provider-apis";
7
8
  //#region ../plus/integrations/src/providers/utils.ts
8
9
  const EntityIdentifierProviderType = {
9
10
  Azure: "azure",
@@ -25,6 +26,14 @@ const EntityType = {
25
26
  Issue: "issue"
26
27
  };
27
28
  const EntityVersion = { One: "1" };
29
+ /** Encodes an entity identifier into the string form Launchpad keys pins/snoozes by and drafts store. */
30
+ function encodeEntityIdentifier(entity) {
31
+ return EntityIdentifierUtils.encode(entity);
32
+ }
33
+ /** Decodes an identifier written by {@link encodeEntityIdentifier}; throws on a malformed one. */
34
+ function decodeEntityIdentifier(encoded) {
35
+ return EntityIdentifierUtils.decode(encoded);
36
+ }
28
37
  function isLaunchpadItem(item) {
29
38
  return item.uuid !== void 0;
30
39
  }
@@ -76,7 +85,7 @@ function getEntityIdentifierInput(entity) {
76
85
  } else if (provider === EntityIdentifierProviderType.Bitbucket || provider === EntityIdentifierProviderType.BitbucketServer) repoId = isLaunchpadItem(entity) ? entity.underlyingPullRequest?.repository?.id : entity.repository?.id;
77
86
  let entityId = isLaunchpadItem(entity) ? entity.graphQLId : entity.nodeId;
78
87
  if (provider === EntityIdentifierProviderType.Azure || provider === EntityIdentifierProviderType.AzureDevOpsServer) entityId = isLaunchpadItem(entity) ? entity.underlyingPullRequest?.id : entity.id;
79
- return {
88
+ const fields = {
80
89
  accountOrOrgId,
81
90
  organizationName,
82
91
  projectId,
@@ -88,6 +97,45 @@ function getEntityIdentifierInput(entity) {
88
97
  domain,
89
98
  entityId
90
99
  };
100
+ return entityType === EntityType.PullRequest && !isLaunchpadItem(entity) ? toPullRequestEntityIdentifierInput(fields) : fields;
101
+ }
102
+ /**
103
+ * Narrows a pull request's identifier fields to the arm the codec encodes it by, throwing (as the codec would) when a
104
+ * field that arm requires is missing.
105
+ */
106
+ function toPullRequestEntityIdentifierInput(fields) {
107
+ const { provider, organizationName, projectId, repoId } = fields;
108
+ switch (provider) {
109
+ case EntityIdentifierProviderType.Github:
110
+ case EntityIdentifierProviderType.GithubEnterprise:
111
+ case EntityIdentifierProviderType.Gitlab:
112
+ case EntityIdentifierProviderType.GitlabSelfHosted: return {
113
+ ...fields,
114
+ provider,
115
+ entityType: EntityType.PullRequest
116
+ };
117
+ case EntityIdentifierProviderType.Bitbucket:
118
+ case EntityIdentifierProviderType.BitbucketServer:
119
+ if (repoId == null) throw new Error("Bitbucket PRs must have a repository ID to be encoded");
120
+ return {
121
+ ...fields,
122
+ provider,
123
+ entityType: EntityType.PullRequest,
124
+ repoId
125
+ };
126
+ case EntityIdentifierProviderType.Azure:
127
+ case EntityIdentifierProviderType.AzureDevOpsServer:
128
+ if (organizationName == null || projectId == null || repoId == null) throw new Error("Azure PRs must have an organization, a project and a repository ID to be encoded");
129
+ return {
130
+ ...fields,
131
+ provider,
132
+ entityType: EntityType.PullRequest,
133
+ organizationName,
134
+ projectId,
135
+ repoId
136
+ };
137
+ default: throw new Error(`Pull requests from '${provider}' can't be encoded`);
138
+ }
91
139
  }
92
140
  function getProviderIdFromEntityIdentifier(entityIdentifier) {
93
141
  switch (entityIdentifier.provider) {
@@ -127,6 +175,12 @@ function fromStringToEntityIdentifierProviderType(str) {
127
175
  default: throw new Error(`Unknown provider type '${str}'`);
128
176
  }
129
177
  }
178
+ /**
179
+ * Builds the git-config form of a branch-issue association from an issue (the only thing production callers pass).
180
+ * A pull request is accepted but goes through {@link getEntityIdentifierInput}, so it throws when its provider can't
181
+ * encode pull requests (Jira, Trello, Linear) or a field its arm requires is missing (Bitbucket and Bitbucket Server
182
+ * need `repoId`; Azure and Azure DevOps Server need an organization, a project and `repoId`).
183
+ */
130
184
  function encodeIssueOrPullRequestForGitConfig(entity, owner) {
131
185
  const encodedOwner = {
132
186
  key: owner.key,
@@ -233,6 +287,6 @@ function getIssueOwner(issue) {
233
287
  } : void 0;
234
288
  }
235
289
  //#endregion
236
- export { EntityIdentifierProviderType, EntityType, EntityVersion, decodeEntityIdentifiersFromGitConfig, encodeIssueOrPullRequestForGitConfig, getEntityIdentifierInput, getIssueFromGitConfigEntityIdentifier, getIssueOwner, getProviderIdFromEntityIdentifier, isGitConfigEntityIdentifier, isGitConfigEntityIdentifiers };
290
+ export { EntityIdentifierProviderType, EntityType, EntityVersion, decodeEntityIdentifier, decodeEntityIdentifiersFromGitConfig, encodeEntityIdentifier, encodeIssueOrPullRequestForGitConfig, getEntityIdentifierInput, getIssueFromGitConfigEntityIdentifier, getIssueOwner, getProviderIdFromEntityIdentifier, isGitConfigEntityIdentifier, isGitConfigEntityIdentifiers };
237
291
 
238
292
  //# sourceMappingURL=utils.js.map