@gitkraken/core-gitlens 0.38.0 → 0.38.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -27,15 +27,6 @@ export declare class LinearIntegration extends IssuesIntegration<IssuesCloudHost
27
27
  */
28
28
  private readonly _autolinks;
29
29
  private readonly _autolinksBuilds;
30
- /**
31
- * Moves whenever `_autolinks` is dropped for a list a build reads, so a build that then fails keeps no fallback
32
- * over a list it didn't read; the next render builds from it instead (#6183). Rule: every writer that stores a
33
- * different team list must bump it and retire the token's build, through {@link onTeamListStored}, today only
34
- * `getTeamsWithMetadata`'s store; the same list stored again does neither while a complete set is kept (#6184). The
35
- * organization map deliberately doesn't: it only changes the links' url, on a forced read. Drops need no bump: they
36
- * move `_teams.generation`, which fails the build.
37
- */
38
- private _autolinksResets;
39
30
  autolinks(): Promise<(AutolinkReference | DynamicAutolinkReference)[]>;
40
31
  /**
41
32
  * One build per token at a time: concurrent renders share it rather than each re-reading the teams. A drop or a
@@ -44,9 +35,11 @@ export declare class LinearIntegration extends IssuesIntegration<IssuesCloudHost
44
35
  */
45
36
  private buildAutolinks;
46
37
  private buildAutolinksCore;
38
+ private deriveAutolinks;
39
+ private onDiscoveryStored;
47
40
  /** The workspace is the token's organization; kept only as a complete, trimmed pair. */
48
41
  getProviderResourceForSession(session: ProviderAuthenticationSession): Promise<ConnectionResource | undefined>;
49
- private _organizations;
42
+ private readonly _organizations;
50
43
  /**
51
44
  * In flight by token and discovery generation. The request can't be aborted (provider-apis takes no signal), so a
52
45
  * lookup that outlives its caller's timeout is joined by the next one rather than piling another request on top of
@@ -59,20 +52,6 @@ export declare class LinearIntegration extends IssuesIntegration<IssuesCloudHost
59
52
  private readonly _teams;
60
53
  private getTeams;
61
54
  private getTeamsWithMetadata;
62
- /**
63
- * The team list was stored, and the autolinks are built from it. A different one drops them, so a build that then
64
- * fails keeps no fallback, and retires the build in flight, which may hold the list as it was. The same one again
65
- * keeps a complete set and the build in flight; otherwise it drops the incomplete set kept, if any, so the next
66
- * render builds from the list again, and still fences a failing build's fallback (#6183, #6184). Other tokens' sets
67
- * and builds stay; only `_autolinksResets`, shared by all tokens, also stops their failing builds' fallback.
68
- *
69
- * A known limit: a build whose own read stores a different list, or the first one (with nothing stored since a start
70
- * or a clear, every first store reads as different), retires itself too. A render in the microtasks before that
71
- * build resumes then starts a second one rather than joining it; that one builds from the team list just stored and
72
- * the organization cached, without reading the network. A loss of the sharing core had, with no effect on what is
73
- * kept, and none on an identical list, which retires nothing.
74
- */
75
- private onTeamListStored;
76
55
  private readTeams;
77
56
  /**
78
57
  * The workspace's Linear Projects (Linear's `Project` entity), drained across their pages. Separate from the
@@ -5,7 +5,6 @@ import { mapSettledBounded } from "../../../utils/promise.js";
5
5
  import { trace } from "../../../utils/decorators/log.js";
6
6
  import { PromiseCache } from "../../../utils/promiseCache.js";
7
7
  import __decorate from "../../../_virtual/@oxc-project+runtime/helpers/esm/decorate.js";
8
- import { areEqual } from "../../../utils/object.js";
9
8
  import { isIssueResourceDescriptor } from "../../../git/utils/resourceDescriptor.utils.js";
10
9
  import { IntegrationReadUnavailableError, toError } from "../errors.js";
11
10
  import "../constants.js";
@@ -17,7 +16,7 @@ import { toTokenWithInfo } from "../authentication/models.js";
17
16
  import { isReadSessionFailure } from "../models/integration.js";
18
17
  import { IssuesIntegration, groupProjectIssuesSearches, splitProjectIssuesSearch } from "../models/issuesIntegration.js";
19
18
  import { createIssueAutolinkReferences } from "./utils/issueAutolinks.js";
20
- import { DiscoveryCache, isAutolinkSetExpired, isEmptyAutolinkFallback } from "./utils/discoveryCache.js";
19
+ import { DiscoveryCache, isAutolinkSetExpired } from "./utils/discoveryCache.js";
21
20
  import { toLinearIssueEtagFields } from "./linearIssuesEtag.js";
22
21
  //#region ../plus/integrations/src/providers/linear.ts
23
22
  const metadata = providersMetadata["linear"];
@@ -71,22 +70,13 @@ var LinearIntegration = class extends IssuesIntegration {
71
70
  */
72
71
  _autolinks = /* @__PURE__ */ new Map();
73
72
  _autolinksBuilds = /* @__PURE__ */ new Map();
74
- /**
75
- * Moves whenever `_autolinks` is dropped for a list a build reads, so a build that then fails keeps no fallback
76
- * over a list it didn't read; the next render builds from it instead (#6183). Rule: every writer that stores a
77
- * different team list must bump it and retire the token's build, through {@link onTeamListStored}, today only
78
- * `getTeamsWithMetadata`'s store; the same list stored again does neither while a complete set is kept (#6184). The
79
- * organization map deliberately doesn't: it only changes the links' url, on a forced read. Drops need no bump: they
80
- * move `_teams.generation`, which fails the build.
81
- */
82
- _autolinksResets = 0;
83
73
  async autolinks() {
84
74
  if (!(this.maybeConnected ?? await this.isConnected()) || this._session == null) return [];
85
75
  const session = this._session;
86
76
  const cached = this._autolinks.get(session.accessToken);
87
77
  if (this.connectionExpired === true) return cached?.autolinks ?? [];
88
- if (cached == null) return this.buildAutolinks(session);
89
- if (isAutolinkSetExpired(cached)) this.buildAutolinks(session);
78
+ if (cached == null || cached.builtAt === 0 && !cached.complete && cached.autolinks.length === 0) return this.buildAutolinks(session);
79
+ if (cached.builtAt === 0 || isAutolinkSetExpired(cached)) this.buildAutolinks(session);
90
80
  return cached.autolinks;
91
81
  }
92
82
  /**
@@ -98,41 +88,41 @@ var LinearIntegration = class extends IssuesIntegration {
98
88
  const { accessToken } = session;
99
89
  let build = this._autolinksBuilds.get(accessToken);
100
90
  if (build == null) {
101
- build = this.buildAutolinksCore(session).finally(() => {
91
+ build = this.buildAutolinksCore(session, () => build).finally(() => {
102
92
  if (this._autolinksBuilds.get(accessToken) === build) this._autolinksBuilds.delete(accessToken);
103
93
  });
104
94
  this._autolinksBuilds.set(accessToken, build);
105
95
  }
106
96
  return build;
107
97
  }
108
- async buildAutolinksCore(session) {
98
+ async buildAutolinksCore(session, reader) {
109
99
  const { accessToken } = session;
110
100
  const generation = this._teams.generation;
111
- const resets = this._autolinksResets;
112
- const held = this._autolinks.get(accessToken);
113
- const keep = (autolinks, complete) => {
114
- const kept = this._autolinks.get(accessToken);
115
- if (this._teams.generation === generation && (complete || kept == null || kept === held || isEmptyAutolinkFallback(kept))) this._autolinks.set(accessToken, {
116
- autolinks,
117
- builtAt: Date.now(),
118
- complete
119
- });
120
- return autolinks;
121
- };
122
- const keepHeld = () => this._autolinksResets === resets ? keep(held?.autolinks ?? [], false) : held?.autolinks ?? [];
123
101
  try {
124
- const organization = await this.getOrganization(session);
125
- if (organization == null) return keepHeld();
126
- const teams = await this.getTeamsWithMetadata(session);
127
- if (teams == null) return keepHeld();
128
- const cached = this._teams.generation === generation ? this._teams.get(accessToken) : void 0;
129
- const autolinks = [];
130
- for (const team of cached ?? teams.values) autolinks.push(...createIssueAutolinkReferences(team.key, `${organization.url}/issue/${team.key}-<num>`, organization));
131
- return keep(autolinks, cached != null && areEqual(this._organizations?.get(accessToken), organization));
102
+ const organization = await this.getOrganization(session, false, reader);
103
+ if (organization != null && this._teams.generation === generation) {
104
+ const teams = await this.getTeamsWithMetadata(session, false, reader);
105
+ if (teams != null && this._teams.generation !== generation) return getTeamAutolinks(organization, teams.values);
106
+ }
132
107
  } catch (ex) {
133
108
  _logger.error(ex, "LinearIntegration.autolinks");
134
- return keepHeld();
135
109
  }
110
+ return this.deriveAutolinks(accessToken, { store: this._teams.generation === generation });
111
+ }
112
+ deriveAutolinks(accessToken, options) {
113
+ const organization = this._organizations.peek(accessToken);
114
+ const complete = this._organizations.get(accessToken) != null && this._teams.get(accessToken) != null;
115
+ const autolinks = organization != null ? getTeamAutolinks(organization, this._teams.peek(accessToken) ?? []) : [];
116
+ if (options?.store !== false) this._autolinks.set(accessToken, {
117
+ autolinks,
118
+ complete,
119
+ builtAt: options?.settled !== false ? Date.now() : this._autolinks.get(accessToken)?.builtAt || (complete ? Date.now() : 0)
120
+ });
121
+ return autolinks;
122
+ }
123
+ onDiscoveryStored(accessToken, reader) {
124
+ if (this._autolinksBuilds.get(accessToken) !== reader?.()) this._autolinksBuilds.delete(accessToken);
125
+ this.deriveAutolinks(accessToken, { settled: false });
136
126
  }
137
127
  /** The workspace is the token's organization; kept only as a complete, trimmed pair. */
138
128
  async getProviderResourceForSession(session) {
@@ -144,27 +134,33 @@ var LinearIntegration = class extends IssuesIntegration {
144
134
  name
145
135
  } : void 0;
146
136
  }
147
- _organizations;
137
+ _organizations = new DiscoveryCache();
148
138
  /**
149
139
  * In flight by token and discovery generation. The request can't be aborted (provider-apis takes no signal), so a
150
140
  * lookup that outlives its caller's timeout is joined by the next one rather than piling another request on top of
151
141
  * it; but not across a drop, since a lookup started before a forced refresh answers as from before it (#6162).
152
142
  */
153
143
  _organizationRequests = /* @__PURE__ */ new Map();
154
- async getOrganization(session, force = false) {
144
+ async getOrganization(session, force = false, reader) {
155
145
  const { accessToken } = session;
156
- const organizations = this._organizations ??= /* @__PURE__ */ new Map();
157
- if (organizations.get(accessToken) == null || force) {
158
- const requestKey = `${this.discoveryGeneration}:${accessToken}`;
159
- let request = this._organizationRequests.get(requestKey);
160
- if (request == null) {
161
- request = this.fetchOrganization(session).finally(() => this._organizationRequests.delete(requestKey));
162
- this._organizationRequests.set(requestKey, request);
163
- }
164
- const descriptor = await request;
165
- if (descriptor) organizations.set(accessToken, descriptor);
146
+ const cached = this._organizations.get(accessToken);
147
+ if (cached != null && !force) return cached;
148
+ const generation = this._organizations.generation;
149
+ const started = this._organizations.startRead();
150
+ const requestKey = `${this.discoveryGeneration}:${accessToken}`;
151
+ let request = this._organizationRequests.get(requestKey);
152
+ if (request == null) {
153
+ request = this.fetchOrganization(session).finally(() => this._organizationRequests.delete(requestKey));
154
+ this._organizationRequests.set(requestKey, request);
166
155
  }
167
- return organizations.get(accessToken);
156
+ const organization = await request;
157
+ if (organization == null) return void 0;
158
+ const stored = this._organizations.set(accessToken, organization, {
159
+ generation,
160
+ read: started
161
+ });
162
+ if (stored === "changed") this.onDiscoveryStored(accessToken, reader);
163
+ return stored === false && this._organizations.generation === generation ? this._organizations.peek(accessToken) : organization;
168
164
  }
169
165
  async fetchOrganization(session) {
170
166
  const organization = await (await this.getProvidersApi()).getLinearOrganization(toTokenWithInfo(this.id, session));
@@ -180,41 +176,26 @@ var LinearIntegration = class extends IssuesIntegration {
180
176
  async getTeams(session, force = false) {
181
177
  return (await this.getTeamsWithMetadata(session, force))?.values;
182
178
  }
183
- async getTeamsWithMetadata(session, force = false) {
179
+ async getTeamsWithMetadata(session, force = false, reader) {
184
180
  const { accessToken } = session;
185
181
  const cachedResources = this._teams.get(accessToken);
186
182
  if (cachedResources != null && !force) return { values: cachedResources };
187
183
  const generation = this._teams.generation;
188
184
  const started = this._teams.startRead();
189
185
  const read = await this.readTeams(session);
190
- if (read == null || read.metadata != null) return read;
186
+ if (read == null) return read;
191
187
  const stored = this._teams.set(accessToken, read.values, {
192
188
  generation,
193
- read: started
189
+ read: started,
190
+ complete: read.metadata == null || read.metadata.completeness === "complete"
194
191
  });
195
- if (stored !== false) this.onTeamListStored(accessToken, stored);
196
- else if (this._teams.generation === generation) return { values: this._teams.peek(accessToken) ?? read.values };
192
+ if (stored === "changed") this.onDiscoveryStored(accessToken, reader);
193
+ else if (stored === false && this._teams.generation === generation) return {
194
+ values: this._teams.peek(accessToken) ?? read.values,
195
+ metadata: this._teams.get(accessToken) == null ? { completeness: "unknown" } : void 0
196
+ };
197
197
  return read;
198
198
  }
199
- /**
200
- * The team list was stored, and the autolinks are built from it. A different one drops them, so a build that then
201
- * fails keeps no fallback, and retires the build in flight, which may hold the list as it was. The same one again
202
- * keeps a complete set and the build in flight; otherwise it drops the incomplete set kept, if any, so the next
203
- * render builds from the list again, and still fences a failing build's fallback (#6183, #6184). Other tokens' sets
204
- * and builds stay; only `_autolinksResets`, shared by all tokens, also stops their failing builds' fallback.
205
- *
206
- * A known limit: a build whose own read stores a different list, or the first one (with nothing stored since a start
207
- * or a clear, every first store reads as different), retires itself too. A render in the microtasks before that
208
- * build resumes then starts a second one rather than joining it; that one builds from the team list just stored and
209
- * the organization cached, without reading the network. A loss of the sharing core had, with no effect on what is
210
- * kept, and none on an identical list, which retires nothing.
211
- */
212
- onTeamListStored(accessToken, stored) {
213
- if (stored === "changed") this._autolinksBuilds.delete(accessToken);
214
- else if (this._autolinks.get(accessToken)?.complete === true) return;
215
- this._autolinks.delete(accessToken);
216
- this._autolinksResets++;
217
- }
218
199
  async readTeams(session) {
219
200
  const descriptors = (await (await this.getProvidersApi()).getLinearTeamsForCurrentUser(toTokenWithInfo(this.id, session)))?.map((t) => ({
220
201
  id: t.id,
@@ -331,7 +312,7 @@ var LinearIntegration = class extends IssuesIntegration {
331
312
  };
332
313
  }
333
314
  clearDiscoveryCaches() {
334
- this._organizations = void 0;
315
+ this._organizations.clear();
335
316
  this._teams.clear();
336
317
  this._workspaceProjects.clear();
337
318
  this._workspaceProjectsReads.clear();
@@ -707,6 +688,9 @@ var LinearIntegration = class extends IssuesIntegration {
707
688
  }
708
689
  };
709
690
  __decorate([trace()], LinearIntegration.prototype, "getWorkspaceProjectsResult", null);
691
+ function getTeamAutolinks(organization, teams) {
692
+ return teams.flatMap((team) => createIssueAutolinkReferences(team.key, `${organization.url}/issue/${team.key}-<num>`, organization));
693
+ }
710
694
  //#endregion
711
695
  export { LinearIntegration };
712
696
 
@@ -1 +1 @@
1
- {"version":3,"file":"linear.js","names":[],"sources":["../../../../../plus/integrations/src/providers/linear.ts"],"sourcesContent":["import type { CollectionMetadata, CollectionScopeFailure, GitIssueState } from '@gitkraken/provider-apis';\nimport type { Account } from '@gitlens/git/models/author.js';\nimport type { AutolinkReference, DynamicAutolinkReference } from '@gitlens/git/models/autolink.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 { chunk } from '@gitlens/utils/array.js';\nimport { trace } from '@gitlens/utils/decorators/log.js';\nimport { Logger } from '@gitlens/utils/logger.js';\nimport { getScopedLogger } from '@gitlens/utils/logger.scoped.js';\nimport { areEqual } from '@gitlens/utils/object.js';\nimport { mapSettledBounded } from '@gitlens/utils/promise.js';\nimport { PromiseCache } from '@gitlens/utils/promiseCache.js';\nimport type { IntegrationAuthenticationProviderDescriptor } from '../authentication/integrationAuthenticationProvider.js';\nimport type { ConnectionResource, ProviderAuthenticationSession } from '../authentication/models.js';\nimport { toTokenWithInfo } from '../authentication/models.js';\nimport { toCollectionScopeFailure } from '../collectionMetadata.js';\nimport { IssuesCloudHostIntegrationId, providerFanOutConcurrency } from '../constants.js';\nimport { IntegrationReadUnavailableError, toError } from '../errors.js';\nimport type { IntegrationResult, IssueEtagFields } from '../models/integration.js';\nimport { isReadSessionFailure } from '../models/integration.js';\nimport type {\n\tAccountWideIssuesResult,\n\tIssuesForProjectOptions,\n\tProjectIssuesDrain,\n\tProjectIssuesRequest,\n\tSearchMyIssuesOptions,\n} from '../models/issueReads.js';\nimport {\n\tgroupProjectIssuesSearches,\n\tIssuesIntegration,\n\tsplitProjectIssuesSearch,\n} from '../models/issuesIntegration.js';\nimport { IssueFilter } from '../providerFilters.js';\nimport type { LinearIssueEtagNode } from './linearIssuesEtag.js';\nimport { linearIssuesEtagMaxNumbers, toLinearIssueEtagFields } from './linearIssuesEtag.js';\nimport type {\n\tProviderApiCollectionResult,\n\tProviderHierarchyResult,\n\tProviderIssue,\n\tProviderLinearProject,\n} from './models.js';\nimport { fromProviderIssue, providersMetadata, toIssueShape, toProviderIssueStates } from './models.js';\nimport { DiscoveryCache, isAutolinkSetExpired, isEmptyAutolinkFallback } from './utils/discoveryCache.js';\nimport { createIssueAutolinkReferences } from './utils/issueAutolinks.js';\nimport { collectProviderPagedResult, mergeCollectionMetadata } from './utils/providerPaging.js';\n\nconst metadata = providersMetadata[IssuesCloudHostIntegrationId.Linear];\nconst authProvider = Object.freeze({ id: metadata.id, scopes: metadata.scopes });\nconst maxPagesPerRequest = 10;\n/**\n * The account-wide drain's own backstop, separate from {@link maxPagesPerRequest}.\n *\n * Raised to 50 (5,000 issues at the SDK's 100-per-page) because 10 no longer means what it used to. That read\n * once fanned out over four overlapping relationship queries and merged them, so most of what a page cost was\n * rows already returned — a low budget capped the waste. It is now a single server-ordered query over an `or`\n * filter, so every page is 100 issues the caller has not seen, and the same budget just truncates real results\n * at 1,000.\n *\n * Reaching it is reported rather than silent: {@link LinearIntegration.searchProviderMyIssuesWithTruncation}\n * returns `truncated`, so the facade can say the read was incomplete instead of publishing a capped list as a\n * whole account. The bound stays — a runaway cursor must not spend requests forever — but it is now set where a\n * real Linear account is unlikely to reach it rather than where the duplication used to hurt.\n */\nconst maxAccountWidePagesPerRequest = 50;\nconst linearImplicitTeamsPageSize = 50;\n/** The workspace Projects read's backstop: provider-apis pages them 100 at a time, so 2,000 Projects. */\nconst maxWorkspaceProjectPages = 20;\n/** Long enough to span one tracker read, short enough that a profile change shows on the next. */\nconst recentAccountTTL = 60 * 1000;\n/** A team key and issue number, as Linear writes an issue's identifier (`ENG-123`). */\nconst linearIdentifier = /^([A-Za-z0-9]+)-(\\d+)$/;\n\nexport interface LinearTeamDescriptor extends IssueResourceDescriptor {\n\tavatarUrl: string | undefined;\n}\n\nexport interface LinearOrganizationDescriptor extends IssueResourceDescriptor {\n\turl: string;\n}\n\nexport interface LinearProjectDescriptor extends IssueResourceDescriptor {}\n\n/** The part of a team read's filter that narrows it to the viewer. */\ntype LinearViewerScope = { assignees: string[]; githubSyncedCreators?: string[] };\n\n/**\n * How a user-scoped team read narrows to the viewer: the issues assigned to them, plus, unless the caller asked for\n * assigned issues by name, the GitHub-synced issues they created. Linear's GitHub Issues sync makes the GitHub author\n * of an issue (one who linked their GitHub account) the creator of its Linear copy but assigns no one GitHub doesn't,\n * so an assignee-only read never returns the copy of a GitHub issue the user filed (gitkraken/kepler#4480). Only\n * synced issues widen, and only those the viewer created on either side: the rest of what the user created in Linear\n * stays out of \"my issues\", as does a synced issue they merely follow.\n */\nfunction viewerScope(viewerId: string, filters: IssueFilter[] | undefined): LinearViewerScope {\n\treturn filters?.includes(IssueFilter.Assignee)\n\t\t? { assignees: [viewerId] }\n\t\t: { assignees: [viewerId], githubSyncedCreators: [viewerId] };\n}\n\nexport class LinearIntegration extends IssuesIntegration<IssuesCloudHostIntegrationId.Linear> {\n\t/**\n\t * Built from the teams, so it follows them: rebuilt when the team list changes or the caches are dropped, and once\n\t * {@link isAutolinkSetExpired}: older than the TTL, or than a shorter retry delay when the organization or the teams\n\t * couldn't be read whole. An expired set is still served while it is rebuilt in the background, because autolinks\n\t * are read on every render of a commit message and must not wait on the network (#5907, #6183).\n\t */\n\tprivate readonly _autolinks = new Map<\n\t\tstring,\n\t\t{ autolinks: (AutolinkReference | DynamicAutolinkReference)[]; builtAt: number; complete: boolean }\n\t>();\n\tprivate readonly _autolinksBuilds = new Map<string, Promise<(AutolinkReference | DynamicAutolinkReference)[]>>();\n\t/**\n\t * Moves whenever `_autolinks` is dropped for a list a build reads, so a build that then fails keeps no fallback\n\t * over a list it didn't read; the next render builds from it instead (#6183). Rule: every writer that stores a\n\t * different team list must bump it and retire the token's build, through {@link onTeamListStored}, today only\n\t * `getTeamsWithMetadata`'s store; the same list stored again does neither while a complete set is kept (#6184). The\n\t * organization map deliberately doesn't: it only changes the links' url, on a forced read. Drops need no bump: they\n\t * move `_teams.generation`, which fails the build.\n\t */\n\tprivate _autolinksResets = 0;\n\n\toverride async autolinks(): Promise<(AutolinkReference | DynamicAutolinkReference)[]> {\n\t\tconst connected = this.maybeConnected ?? (await this.isConnected());\n\t\tif (!connected || this._session == null) {\n\t\t\treturn [];\n\t\t}\n\n\t\tconst session = this._session;\n\t\tconst cached = this._autolinks.get(session.accessToken);\n\t\t// A session kept through a failed refresh is expired: building with it would send that token to the provider\n\t\t// on every render, so serve whatever was built before (none after a forced re-sync) until a read refreshes it.\n\t\tif (this.connectionExpired === true) return cached?.autolinks ?? [];\n\t\tif (cached == null) return this.buildAutolinks(session);\n\n\t\tif (isAutolinkSetExpired(cached)) {\n\t\t\tvoid this.buildAutolinks(session);\n\t\t}\n\t\treturn cached.autolinks;\n\t}\n\n\t/**\n\t * One build per token at a time: concurrent renders share it rather than each re-reading the teams. A drop or a\n\t * change to the team list retires it, so a render after one doesn't join a build reading the teams as they were\n\t * before (#6170, #6184).\n\t */\n\tprivate buildAutolinks(\n\t\tsession: ProviderAuthenticationSession,\n\t): Promise<(AutolinkReference | DynamicAutolinkReference)[]> {\n\t\tconst { accessToken } = session;\n\t\tlet build = this._autolinksBuilds.get(accessToken);\n\t\tif (build == null) {\n\t\t\tbuild = this.buildAutolinksCore(session).finally(() => {\n\t\t\t\t// A drop or a list change meanwhile retired this build, and the entry may be a later one's now.\n\t\t\t\tif (this._autolinksBuilds.get(accessToken) === build) {\n\t\t\t\t\tthis._autolinksBuilds.delete(accessToken);\n\t\t\t\t}\n\t\t\t});\n\t\t\tthis._autolinksBuilds.set(accessToken, build);\n\t\t}\n\t\treturn build;\n\t}\n\n\tprivate async buildAutolinksCore(\n\t\tsession: ProviderAuthenticationSession,\n\t): Promise<(AutolinkReference | DynamicAutolinkReference)[]> {\n\t\tconst { accessToken } = session;\n\t\tconst generation = this._teams.generation;\n\t\tconst resets = this._autolinksResets;\n\t\t// What this build falls back on when it can't read the organization or the teams\n\t\tconst held = this._autolinks.get(accessToken);\n\t\t// Kept even when incomplete, to be retried sooner rather than by every render (#6183); not when built from\n\t\t// teams read before the caches were dropped. Complete only when built from the team list and the organization\n\t\t// as stored now. Once a list change retired this build, another may have kept a set meanwhile: a complete set\n\t\t// still replaces it, and any replaces an empty incomplete one, the fallback of a build that read none;\n\t\t// otherwise, as it also rests on what only this build read (an organization since read again and changed, a\n\t\t// read cut short) or held, it only replaces the set it held, or none (#6184). Refused, it still answers the\n\t\t// renders waiting on it with its own result, a known limit.\n\t\tconst keep = (\n\t\t\tautolinks: (AutolinkReference | DynamicAutolinkReference)[],\n\t\t\tcomplete: boolean,\n\t\t): (AutolinkReference | DynamicAutolinkReference)[] => {\n\t\t\tconst kept = this._autolinks.get(accessToken);\n\t\t\tif (\n\t\t\t\tthis._teams.generation === generation &&\n\t\t\t\t(complete || kept == null || kept === held || isEmptyAutolinkFallback(kept))\n\t\t\t) {\n\t\t\t\tthis._autolinks.set(accessToken, {\n\t\t\t\t\tautolinks: autolinks,\n\t\t\t\t\tbuiltAt: Date.now(),\n\t\t\t\t\tcomplete: complete,\n\t\t\t\t});\n\t\t\t}\n\t\t\treturn autolinks;\n\t\t};\n\t\t// Serves the held set until the retry, unless a team list was stored meanwhile\n\t\tconst keepHeld = (): (AutolinkReference | DynamicAutolinkReference)[] =>\n\t\t\tthis._autolinksResets === resets ? keep(held?.autolinks ?? [], false) : (held?.autolinks ?? []);\n\t\ttry {\n\t\t\tconst organization = await this.getOrganization(session);\n\t\t\tif (organization == null) return keepHeld();\n\n\t\t\tconst teams = await this.getTeamsWithMetadata(session);\n\t\t\tif (teams == null) return keepHeld();\n\n\t\t\t// While this build is current, a team list cached meanwhile outranks its read, as with Jira's sites\n\t\t\tconst cached = this._teams.generation === generation ? this._teams.get(accessToken) : undefined;\n\t\t\tconst autolinks: (AutolinkReference | DynamicAutolinkReference)[] = [];\n\t\t\tfor (const team of cached ?? teams.values) {\n\t\t\t\tautolinks.push(\n\t\t\t\t\t...createIssueAutolinkReferences(\n\t\t\t\t\t\tteam.key,\n\t\t\t\t\t\t`${organization.url}/issue/${team.key}-<num>`,\n\t\t\t\t\t\torganization,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// Built from teams not cached now, an incomplete read or a newer list since expired, or with an organization\n\t\t\t// that differs from the one stored now, the set is served, and read again after the retry delay\n\t\t\treturn keep(autolinks, cached != null && areEqual(this._organizations?.get(accessToken), organization));\n\t\t} catch (ex) {\n\t\t\t// Autolinks are decoration: don't fail the render that asked\n\t\t\tLogger.error(ex, 'LinearIntegration.autolinks');\n\t\t\treturn keepHeld();\n\t\t}\n\t}\n\n\t/** The workspace is the token's organization; kept only as a complete, trimmed pair. */\n\toverride async getProviderResourceForSession(\n\t\tsession: ProviderAuthenticationSession,\n\t): Promise<ConnectionResource | undefined> {\n\t\tconst organization = await this.getOrganization(session, true);\n\t\tconst id = organization?.id.trim();\n\t\tconst name = organization?.name.trim();\n\t\treturn id && name ? { id: id, name: name } : undefined;\n\t}\n\n\tprivate _organizations: Map<string, LinearOrganizationDescriptor | undefined> | undefined;\n\t/**\n\t * In flight by token and discovery generation. The request can't be aborted (provider-apis takes no signal), so a\n\t * lookup that outlives its caller's timeout is joined by the next one rather than piling another request on top of\n\t * it; but not across a drop, since a lookup started before a forced refresh answers as from before it (#6162).\n\t */\n\tprivate readonly _organizationRequests = new Map<string, Promise<LinearOrganizationDescriptor | undefined>>();\n\tprivate async getOrganization(\n\t\tsession: ProviderAuthenticationSession,\n\t\tforce: boolean = false,\n\t): Promise<LinearOrganizationDescriptor | undefined> {\n\t\tconst { accessToken } = session;\n\t\t// Held across the await: a re-sync drops `_organizations` meanwhile, and this read must still complete.\n\t\tconst organizations = (this._organizations ??= new Map<string, LinearOrganizationDescriptor | undefined>());\n\n\t\tconst cachedResources = organizations.get(accessToken);\n\n\t\tif (cachedResources == null || force) {\n\t\t\tconst requestKey = `${this.discoveryGeneration}:${accessToken}`;\n\t\t\tlet request = this._organizationRequests.get(requestKey);\n\t\t\tif (request == null) {\n\t\t\t\trequest = this.fetchOrganization(session).finally(() => this._organizationRequests.delete(requestKey));\n\t\t\t\tthis._organizationRequests.set(requestKey, request);\n\t\t\t}\n\n\t\t\tconst descriptor = await request;\n\t\t\tif (descriptor) {\n\t\t\t\torganizations.set(accessToken, descriptor);\n\t\t\t}\n\t\t}\n\n\t\treturn organizations.get(accessToken);\n\t}\n\n\tprivate async fetchOrganization(\n\t\tsession: ProviderAuthenticationSession,\n\t): Promise<LinearOrganizationDescriptor | undefined> {\n\t\tconst api = await this.getProvidersApi();\n\t\tconst organization = await api.getLinearOrganization(toTokenWithInfo(this.id, session));\n\t\treturn (\n\t\t\torganization && {\n\t\t\t\tid: organization.id,\n\t\t\t\tkey: organization.key,\n\t\t\t\tname: organization.name,\n\t\t\t\turl: organization.url,\n\t\t\t}\n\t\t);\n\t}\n\n\t/** Expires, and is dropped on a re-sync, so a team created or left mid-session is picked up (#5907). */\n\tprivate readonly _teams = new DiscoveryCache<LinearTeamDescriptor[]>();\n\tprivate async getTeams(\n\t\tsession: ProviderAuthenticationSession,\n\t\tforce: boolean = false,\n\t): Promise<LinearTeamDescriptor[] | undefined> {\n\t\treturn (await this.getTeamsWithMetadata(session, force))?.values;\n\t}\n\n\tprivate async getTeamsWithMetadata(\n\t\tsession: ProviderAuthenticationSession,\n\t\tforce: boolean = false,\n\t): Promise<ProviderApiCollectionResult<LinearTeamDescriptor> | undefined> {\n\t\tconst { accessToken } = session;\n\n\t\tconst cachedResources = this._teams.get(accessToken);\n\t\tif (cachedResources != null && !force) return { values: cachedResources };\n\n\t\tconst generation = this._teams.generation;\n\t\tconst started = this._teams.startRead();\n\t\tconst read = await this.readTeams(session);\n\t\tif (read == null || read.metadata != null) return read;\n\n\t\t// Not stored when the cache was dropped, or a read started after this one stored the teams, while this read\n\t\t// was in flight.\n\t\tconst stored = this._teams.set(accessToken, read.values, { generation: generation, read: started });\n\t\tif (stored !== false) {\n\t\t\tthis.onTeamListStored(accessToken, stored);\n\t\t} else if (this._teams.generation === generation) {\n\t\t\t// Refused for a read started after it: answers with that read's newer list, which this older one must not\n\t\t\t// stand in for, not even once expired (#6184).\n\t\t\treturn { values: this._teams.peek(accessToken) ?? read.values };\n\t\t}\n\t\treturn read;\n\t}\n\n\t/**\n\t * The team list was stored, and the autolinks are built from it. A different one drops them, so a build that then\n\t * fails keeps no fallback, and retires the build in flight, which may hold the list as it was. The same one again\n\t * keeps a complete set and the build in flight; otherwise it drops the incomplete set kept, if any, so the next\n\t * render builds from the list again, and still fences a failing build's fallback (#6183, #6184). Other tokens' sets\n\t * and builds stay; only `_autolinksResets`, shared by all tokens, also stops their failing builds' fallback.\n\t *\n\t * A known limit: a build whose own read stores a different list, or the first one (with nothing stored since a start\n\t * or a clear, every first store reads as different), retires itself too. A render in the microtasks before that\n\t * build resumes then starts a second one rather than joining it; that one builds from the team list just stored and\n\t * the organization cached, without reading the network. A loss of the sharing core had, with no effect on what is\n\t * kept, and none on an identical list, which retires nothing.\n\t */\n\tprivate onTeamListStored(accessToken: string, stored: 'changed' | 'unchanged'): void {\n\t\tif (stored === 'changed') {\n\t\t\tthis._autolinksBuilds.delete(accessToken);\n\t\t} else if (this._autolinks.get(accessToken)?.complete === true) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis._autolinks.delete(accessToken);\n\t\tthis._autolinksResets++;\n\t}\n\n\tprivate async readTeams(\n\t\tsession: ProviderAuthenticationSession,\n\t): Promise<ProviderApiCollectionResult<LinearTeamDescriptor> | undefined> {\n\t\tconst api = await this.getProvidersApi();\n\t\tconst teams = await api.getLinearTeamsForCurrentUser(toTokenWithInfo(this.id, session));\n\t\tconst descriptors: LinearTeamDescriptor[] | undefined = teams?.map(t => ({\n\t\t\tid: t.id,\n\t\t\tkey: t.key,\n\t\t\tname: t.name,\n\t\t\tavatarUrl: t.iconUrl,\n\t\t}));\n\t\tif (descriptors == null) return undefined;\n\n\t\t// provider-apis currently requests Linear's teams connection without pageInfo or a cursor. Linear's\n\t\t// implicit page size is 50, so exactly a full page cannot prove there is no team 51. Preserve the useful\n\t\t// prefix, but mark it unknown and leave it uncached so the next read retries instead of treating it as\n\t\t// authoritative. Once provider-apis exposes a paged primitive, replace this fail-closed guard with a drain.\n\t\tif (descriptors.length >= linearImplicitTeamsPageSize) {\n\t\t\treturn { values: descriptors, metadata: { completeness: 'unknown' } };\n\t\t}\n\n\t\treturn { values: descriptors };\n\t}\n\n\t/**\n\t * The workspace's Linear Projects (Linear's `Project` entity), drained across their pages. Separate from the\n\t * teams this integration lists as its projects: a Linear Project can span several teams, and selecting one\n\t * narrows an issue read (`IssuesForProjectOptions.linearProjects`) rather than naming what is read.\n\t *\n\t * Cached like the teams, and only when complete: a drain cut short by its backstop or a failed page is returned\n\t * with its `truncated`/`metadata` so the facade can say so, and read again next time. A first-page failure\n\t * rejects, which the result wrapper turns into `{ error }`. `fresh` reads past the cache and any read in flight,\n\t * for a caller that must not take a list from before what it needs to see (a Project created since).\n\t */\n\t@trace()\n\tasync getWorkspaceProjectsResult(\n\t\tconnectionId?: string,\n\t\toptions?: { fresh?: boolean },\n\t): Promise<IntegrationResult<ProviderHierarchyResult<ProviderLinearProject>>> {\n\t\tconst scope = getScopedLogger();\n\t\t// `connectionId` targets a specific account (multi-account); omitted reads the primary.\n\t\tconst session = await this.resolveReadSession(connectionId, scope);\n\t\tif (session == null || isReadSessionFailure(session)) return session && { error: session.error };\n\n\t\ttry {\n\t\t\tconst projects = await this.getWorkspaceProjects(session, options?.fresh === true);\n\t\t\tawait this.confirmScopedAuthFailures(session, projects.metadata);\n\t\t\tthis.resetRequestExceptionCount('getProjectsForResources', connectionId);\n\t\t\treturn { value: projects };\n\t\t} catch (ex) {\n\t\t\tthis.handleProviderException('getProjectsForResources', ex, { connectionId: connectionId });\n\t\t\treturn { error: toError(ex) };\n\t\t}\n\t}\n\n\t/** Expires, and is dropped on a re-sync, so a Project created or archived mid-session is picked up. */\n\tprivate readonly _workspaceProjects = new DiscoveryCache<ProviderLinearProject[]>();\n\t/**\n\t * In flight by token, with the cache generation it started under: concurrent cold reads share one drain, but a\n\t * read after the cache was dropped (a `forceSync`) never joins one started before, which could miss what it asks\n\t * to see.\n\t */\n\tprivate readonly _workspaceProjectsReads = new Map<\n\t\tstring,\n\t\t{ generation: number; read: Promise<ProviderHierarchyResult<ProviderLinearProject>> }\n\t>();\n\tprivate getWorkspaceProjects(\n\t\tsession: ProviderAuthenticationSession,\n\t\tfresh: boolean,\n\t): Promise<ProviderHierarchyResult<ProviderLinearProject>> {\n\t\tconst { accessToken } = session;\n\t\tconst generation = this._workspaceProjects.generation;\n\t\tif (!fresh) {\n\t\t\tconst cached = this._workspaceProjects.get(accessToken);\n\t\t\tif (cached != null) return Promise.resolve({ values: cached });\n\n\t\t\tconst inFlight = this._workspaceProjectsReads.get(accessToken);\n\t\t\tif (inFlight?.generation === generation) return inFlight.read;\n\t\t}\n\n\t\tconst entry = { generation: generation, read: this.readWorkspaceProjects(session) };\n\t\tentry.read = entry.read.then(result => {\n\t\t\tif (\n\t\t\t\tthis._workspaceProjectsReads.get(accessToken) === entry &&\n\t\t\t\tresult.truncated !== true &&\n\t\t\t\t(result.metadata == null || result.metadata.completeness === 'complete')\n\t\t\t) {\n\t\t\t\tthis._workspaceProjects.set(accessToken, result.values, { generation: generation });\n\t\t\t}\n\t\t\treturn result;\n\t\t});\n\t\tthis._workspaceProjectsReads.set(accessToken, entry);\n\t\tvoid entry.read\n\t\t\t.finally(() => {\n\t\t\t\tif (this._workspaceProjectsReads.get(accessToken) === entry) {\n\t\t\t\t\tthis._workspaceProjectsReads.delete(accessToken);\n\t\t\t\t}\n\t\t\t})\n\t\t\t.catch(() => {});\n\t\treturn entry.read;\n\t}\n\n\t/**\n\t * Drains the Projects cursor up to {@link maxWorkspaceProjectPages}. A first-page failure rejects, so the read\n\t * fails as the team read does rather than reading as a workspace with no Projects; a later one keeps the prefix\n\t * and records the failure, as do a stalled cursor and the backstop with pages left.\n\t */\n\tprivate async readWorkspaceProjects(\n\t\tsession: ProviderAuthenticationSession,\n\t): Promise<ProviderHierarchyResult<ProviderLinearProject>> {\n\t\tconst api = await this.getProvidersApi();\n\t\tconst tokenWithInfo = toTokenWithInfo(this.id, session);\n\t\tlet pagesRead = 0;\n\t\tlet firstPageError: Error | undefined;\n\t\tconst read = await collectProviderPagedResult(\n\t\t\tasync cursor => {\n\t\t\t\ttry {\n\t\t\t\t\tconst page = await api.getLinearProjects(tokenWithInfo, { cursor: cursor });\n\t\t\t\t\tpagesRead++;\n\t\t\t\t\treturn page;\n\t\t\t\t} catch (ex) {\n\t\t\t\t\tif (pagesRead === 0) {\n\t\t\t\t\t\tfirstPageError = toError(ex);\n\t\t\t\t\t}\n\t\t\t\t\tthrow ex;\n\t\t\t\t}\n\t\t\t},\n\t\t\tmaxWorkspaceProjectPages,\n\t\t\t{ providerId: this.id },\n\t\t);\n\t\t// The drain records any failure against its scope and keeps the prefix; with no prefix, there is no list.\n\t\tif (firstPageError != null) throw firstPageError;\n\n\t\treturn read;\n\t}\n\n\tprotected override async getProviderResourcesForUser(\n\t\tsession: ProviderAuthenticationSession,\n\t): Promise<ResourceDescriptor[] | undefined> {\n\t\tconst organization = await this.getOrganization(session);\n\t\treturn organization != null ? [organization] : undefined;\n\t}\n\tprotected override async getProviderUncachedResourcesForUser(\n\t\tsession: ProviderAuthenticationSession,\n\t): Promise<ResourceDescriptor[] | undefined> {\n\t\t// Joins none in flight, unlike `getOrganization`: one may have started before what the caller needs to see.\n\t\tconst organization = await this.fetchOrganization(session);\n\t\treturn organization != null ? [organization] : undefined;\n\t}\n\tprotected override getProviderProjectsForResources(\n\t\tsession: ProviderAuthenticationSession,\n\t\t_resources: ResourceDescriptor[],\n\t): Promise<ResourceDescriptor[] | undefined> {\n\t\treturn this.getTeams(session);\n\t}\n\tprotected override async getProviderProjectsForResourcesWithMetadata(\n\t\tsession: ProviderAuthenticationSession,\n\t\t_resources: ResourceDescriptor[],\n\t): Promise<ProviderApiCollectionResult<ResourceDescriptor>> {\n\t\treturn (await this.getTeamsWithMetadata(session)) ?? { values: [], metadata: { completeness: 'unknown' } };\n\t}\n\tprotected override async getProviderUncachedProjectsForResourcesWithMetadata(\n\t\tsession: ProviderAuthenticationSession,\n\t\t_resources: ResourceDescriptor[],\n\t): Promise<ProviderApiCollectionResult<ResourceDescriptor>> {\n\t\treturn (await this.readTeams(session)) ?? { values: [], metadata: { completeness: 'unknown' } };\n\t}\n\n\tprotected override clearDiscoveryCaches(): void {\n\t\tthis._organizations = undefined;\n\t\tthis._teams.clear();\n\t\tthis._workspaceProjects.clear();\n\t\tthis._workspaceProjectsReads.clear();\n\t\tthis._autolinks.clear();\n\t\tthis._autolinksBuilds.clear();\n\t\tthis._recentAccounts.clear();\n\t}\n\treadonly authProvider: IntegrationAuthenticationProviderDescriptor = authProvider;\n\n\t/**\n\t * Always asks Linear: the host's current-account cache decides when this runs. The viewer query is account-wide,\n\t * so the answer is lent briefly to the per-resource 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);\n\t}\n\n\tprotected override async getProviderAccountForResource(\n\t\tsession: ProviderAuthenticationSession,\n\t\t_resource: ResourceDescriptor,\n\t): Promise<Account | undefined> {\n\t\treturn this._recentAccounts.getOrCreate(session.accessToken, () => this.fetchAccount(session), {\n\t\t\tevictWhen: account => account == null,\n\t\t});\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(session: ProviderAuthenticationSession): Promise<Account | undefined> {\n\t\tconst api = await this.getProvidersApi();\n\t\t// Linear's viewer isn't a ProviderAccount (no username/avatar), so build the Account manually\n\t\t// (Trello-style) from the fields the viewer query returns.\n\t\tconst user = await api.getLinearCurrentUser(toTokenWithInfo(this.id, session));\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 ?? user.displayName ?? undefined,\n\t\t\tusername: user.displayName ?? undefined,\n\t\t\temail: user.email ?? undefined,\n\t\t\tavatarUrl: undefined,\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\tif (!isIssueResourceDescriptor(project)) return undefined;\n\n\t\t// Scope to \"my issues\" by the viewer's stable id, not the passed display name: Linear's `name` (full name)\n\t\t// and `displayName` (nickname) are distinct fields, and assignees are normalized with `.name` = the full\n\t\t// name while the caller's `user` is the displayName — so a name string can miss. The assignee `.id` is the\n\t\t// Linear user id, which is unambiguous.\n\t\tlet viewerId: string | undefined;\n\t\tif (options?.user != null) {\n\t\t\tviewerId = await this.getViewerId(session, options);\n\t\t\t// If the viewer can't be resolved we can't scope to \"my issues\" — returning the unfiltered team\n\t\t\t// issues would leak everyone else's, and returning [] is indistinguishable from \"no issues assigned\n\t\t\t// to me\". Throw so the facade (getIssuesForProjectResult → runCaptured) surfaces a warning +\n\t\t\t// fetchFailed the caller can act on, instead of a silent empty.\n\t\t\tif (viewerId == null) {\n\t\t\t\tthrow new IntegrationReadUnavailableError(\n\t\t\t\t\tmetadata.name,\n\t\t\t\t\t'could not resolve the current user to scope issues to',\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\t// `getProviderProjectsForResources` returns Linear teams, so `project.id` is a team id here.\n\t\t//\n\t\t// The state and the viewer are narrowed server-side, not after the drain: a team's done work and other\n\t\t// people's issues would otherwise count against the backstop, so a busy team runs out of pages before the\n\t\t// viewer's open issues and hands back a page that looks complete.\n\t\tconst drain = await this.drainIssues(\n\t\t\tsession,\n\t\t\t{\n\t\t\t\tteams: [project.id],\n\t\t\t\t...(options?.linearProjects?.length ? { projects: [...options.linearProjects] } : {}),\n\t\t\t\t...(viewerId != null ? viewerScope(viewerId, options?.filters) : {}),\n\t\t\t\tstates: toProviderIssueStates(options?.state),\n\t\t\t},\n\t\t\toptions?.sort,\n\t\t\t{ providerId: this.id, projectId: project.id },\n\t\t);\n\n\t\treturn drain.truncated\n\t\t\t? { values: drain.issues, truncated: true, recovery: 'none', metadata: drain.metadata }\n\t\t\t: { values: drain.issues, truncated: false, metadata: drain.metadata };\n\t}\n\n\t/**\n\t * Searches every team of a user-scoped read together: one `getIssues` names all of them and the viewer's scope\n\t * (see {@link viewerScope}), so a team with none of the user's issues costs no request of its own. Linear's filter\n\t * is a GraphQL body, not a query string, so there is no key bound to chunk at.\n\t *\n\t * A read narrowed to Linear Projects is searched together even across every assignee: the Projects already bound\n\t * it to a few teams' worth of issues, so a team holding none of them costs no request either. An unnarrowed read\n\t * of every assignee is still read team by team, since a search over all of them would just spend one team's page\n\t * budget before falling back.\n\t */\n\tprotected override getProjectIssuesSearches(\n\t\trequests: readonly ProjectIssuesRequest<ResourceDescriptor>[],\n\t): number[][] | undefined {\n\t\treturn groupProjectIssuesSearches(requests, ({ project, options }) =>\n\t\t\t(options.user != null || options.linearProjects?.length) && isIssueResourceDescriptor(project)\n\t\t\t\t? [\n\t\t\t\t\t\toptions.user ?? '',\n\t\t\t\t\t\toptions.userId ?? '',\n\t\t\t\t\t\toptions.sort ?? '',\n\t\t\t\t\t\toptions.state ?? '',\n\t\t\t\t\t\toptions.filters?.join(',') ?? '',\n\t\t\t\t\t\t...(options.linearProjects ?? []),\n\t\t\t\t\t].join('\\0')\n\t\t\t\t: undefined,\n\t\t);\n\t}\n\n\tprotected override async searchProviderProjectIssues(\n\t\tsession: ProviderAuthenticationSession,\n\t\trequests: readonly ProjectIssuesRequest<ResourceDescriptor>[],\n\t): Promise<IssueShape[][] | undefined> {\n\t\t// Every request of a search shares every option read here (see the key in `getProjectIssuesSearches`).\n\t\tconst { options } = requests[0];\n\t\tlet viewerId: string | undefined;\n\t\tif (options.user != null) {\n\t\t\t// Unresolvable here means each team's own read throws the same warning, so let them.\n\t\t\tviewerId = await this.getViewerId(session, options);\n\t\t\tif (viewerId == null) return undefined;\n\t\t} else if (!options.linearProjects?.length) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst teams = requests.map(request => request.project).filter(isIssueResourceDescriptor);\n\t\tif (teams.length !== requests.length) return undefined;\n\n\t\tconst drain = await this.drainIssues(\n\t\t\tsession,\n\t\t\t{\n\t\t\t\tteams: teams.map(team => team.id),\n\t\t\t\t...(options.linearProjects?.length ? { projects: [...options.linearProjects] } : {}),\n\t\t\t\t...(viewerId != null ? viewerScope(viewerId, options.filters) : {}),\n\t\t\t\tstates: toProviderIssueStates(options.state),\n\t\t\t},\n\t\t\toptions.sort,\n\t\t\t// Never published: an incomplete search is read again per team, which records its own failures.\n\t\t\t{ providerId: this.id },\n\t\t);\n\t\t// Deliberately discarded rather than served: an incomplete search says nothing about which of its teams it\n\t\t// covered, so only the per-team reads can report each one's completeness. The waste is bounded by one team's\n\t\t// page budget, and paid only by a search that needed more than that or failed partway.\n\t\tif (drain.truncated || (drain.metadata != null && drain.metadata.completeness !== 'complete')) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\t// A normalized Linear issue carries its team only inside `project`, which is absent for an issue in no\n\t\t// Linear project, so split by the identifier instead: Linear numbers every issue `<team key>-<n>`, and\n\t\t// renumbers it under its new team's key when it moves.\n\t\treturn splitProjectIssuesSearch(\n\t\t\tteams.map(team => team.key),\n\t\t\tdrain.issues,\n\t\t\tissue => {\n\t\t\t\tconst separator = issue.id.lastIndexOf('-');\n\t\t\t\treturn separator > 0 ? issue.id.slice(0, separator) : undefined;\n\t\t\t},\n\t\t);\n\t}\n\n\tprivate readonly _viewerIds = new PromiseCache<string, string | undefined>({ capacity: 10 });\n\t/**\n\t * The viewer's Linear user id: the caller's resolved `userId` when it has one, else the viewer query, shared per\n\t * token. A tracker read hands each team the id of the team's own resource, which Linear's team descriptors don't\n\t * name, so without sharing every team read (and a search's fallback) would ask for the viewer again.\n\t */\n\tprivate getViewerId(\n\t\tsession: ProviderAuthenticationSession,\n\t\toptions: IssuesForProjectOptions,\n\t): Promise<string | undefined> {\n\t\tif (options.userId) return Promise.resolve(options.userId);\n\n\t\treturn this._viewerIds.getOrCreate(\n\t\t\tsession.accessToken,\n\t\t\tasync () => {\n\t\t\t\tconst api = await this.getProvidersApi();\n\t\t\t\treturn (await api.getLinearCurrentUser(toTokenWithInfo(this.id, session)))?.id;\n\t\t\t},\n\t\t\t// Only a resolved id is worth keeping; an unresolved viewer is asked for again next time, as is a failure.\n\t\t\t{ evictWhen: id => id == null },\n\t\t);\n\t}\n\n\t/**\n\t * Follows `getIssues`' cursor up to {@link maxPagesPerRequest}. `truncated` is set when that backstop stopped\n\t * the drain with more pages still available, when the provider stalled its cursor or flagged its paging as\n\t * truncated, or when a page after the first failed, which is recorded at `failureScope` while the prefix is\n\t * kept. A failure before any issue was kept throws, so the caller sees a hard error rather than an empty success.\n\t */\n\tprivate async drainIssues(\n\t\tsession: ProviderAuthenticationSession,\n\t\tfilter: { teams: string[]; projects?: string[]; states?: GitIssueState[] } & Partial<LinearViewerScope>,\n\t\tsort: IssuesForProjectOptions['sort'],\n\t\tfailureScope: CollectionScopeFailure['scope'],\n\t): Promise<{ issues: IssueShape[]; truncated: boolean; metadata?: CollectionMetadata }> {\n\t\tconst api = await this.getProvidersApi();\n\t\tconst assignees = filter.assignees?.length ? filter.assignees : undefined;\n\t\tconst syncedCreators = filter.githubSyncedCreators?.length ? filter.githubSyncedCreators : undefined;\n\t\tlet cursor: string | undefined;\n\t\tlet hasMore: boolean;\n\t\tlet requestCount = 0;\n\t\tlet truncated = false;\n\t\tlet collectionMetadata: CollectionMetadata | undefined;\n\t\tconst issues: IssueShape[] = [];\n\t\tdo {\n\t\t\tlet result: Awaited<ReturnType<typeof api.getLinearIssues>>;\n\t\t\ttry {\n\t\t\t\tresult = await api.getLinearIssues(toTokenWithInfo(this.id, session), filter, {\n\t\t\t\t\tcursor: cursor,\n\t\t\t\t\tsort: sort,\n\t\t\t\t});\n\t\t\t} catch (ex) {\n\t\t\t\t// Keyed on what was kept, not on the page: provider-apis can empty a page it filters after the query\n\t\t\t\t// (synced-creator reads) and still report more, and a drain that kept nothing has nothing to serve, so\n\t\t\t\t// its caller retries it rather than recording an empty prefix as read.\n\t\t\t\tif (issues.length === 0) throw ex;\n\n\t\t\t\ttruncated = true;\n\t\t\t\tcollectionMetadata = mergeCollectionMetadata(collectionMetadata, {\n\t\t\t\t\tcompleteness: 'partial',\n\t\t\t\t\tfailures: [toCollectionScopeFailure(failureScope, ex)],\n\t\t\t\t});\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\trequestCount += 1;\n\t\t\thasMore = result.paging?.more ?? false;\n\t\t\tconst nextCursor = result.paging?.cursor;\n\t\t\ttruncated ||= result.paging?.truncated === true;\n\t\t\tcollectionMetadata = mergeCollectionMetadata(collectionMetadata, result.metadata);\n\t\t\tfor (const issue of result.values) {\n\t\t\t\tconst shape = toIssueShape(issue, this, { projection: 'project' });\n\t\t\t\t// The read already scopes to the assignees and to the synced issues the creators filed, leaving out the\n\t\t\t\t// issues with no GitHub sync link (`[]`) and keeping one whose link list Linear failed to resolve\n\t\t\t\t// (absent). Checking again keeps another user's issue, or an unsynced one only its GitHub attachment\n\t\t\t\t// matched, out of \"my issues\" should the provider ever return one.\n\t\t\t\tif (\n\t\t\t\t\tshape != null &&\n\t\t\t\t\t(assignees == null ||\n\t\t\t\t\t\tshape.assignees?.some(a => assignees.includes(a.id)) ||\n\t\t\t\t\t\t(syncedCreators != null &&\n\t\t\t\t\t\t\tshape.author != null &&\n\t\t\t\t\t\t\tsyncedCreators.includes(shape.author.id) &&\n\t\t\t\t\t\t\tshape.syncedWith?.length !== 0))\n\t\t\t\t) {\n\t\t\t\t\tissues.push(shape);\n\t\t\t\t}\n\t\t\t}\n\t\t\t// The provider claims more but returns no advancing cursor: we can't continue without re-reading the\n\t\t\t// same page, so the drain is incomplete — flag it rather than silently stopping.\n\t\t\tif (hasMore && (nextCursor == null || nextCursor === cursor)) {\n\t\t\t\ttruncated = true;\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcursor = nextCursor;\n\t\t\tif (hasMore && requestCount >= maxPagesPerRequest) {\n\t\t\t\ttruncated = true;\n\t\t\t}\n\t\t} while (requestCount < maxPagesPerRequest && hasMore);\n\n\t\treturn { issues: issues, truncated: truncated, metadata: collectionMetadata };\n\t}\n\n\toverride get id(): IssuesCloudHostIntegrationId.Linear {\n\t\treturn IssuesCloudHostIntegrationId.Linear;\n\t}\n\tprotected override get key(): 'linear' {\n\t\treturn 'linear';\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\tprotected override async searchProviderMyIssues(\n\t\tsession: ProviderAuthenticationSession,\n\t\tresources?: ResourceDescriptor[],\n\t\tcancellation?: AbortSignal,\n\t): Promise<IssueShape[] | undefined> {\n\t\treturn (await this.searchProviderMyIssuesWithTruncation(session, resources, cancellation))?.values;\n\t}\n\n\t/**\n\t * Account-wide \"my issues\" for Linear, drained to exhaustion and reporting whether it got there.\n\t *\n\t * The SDK read is one server-ordered query over an `or` filter across the four relationships (assigned,\n\t * created, named in an issue's content, named in a comment), so each page is 100 issues the caller has not\n\t * seen and the pages are ordered as one sequence. Draining it is therefore just following the cursor.\n\t *\n\t * Overridden rather than left to the base default because that default hardcodes `truncated: false`, and a\n\t * bounded drain that stops early is exactly the case a caller must be able to see. Three things end the\n\t * drain, and only one of them is completion:\n\t *\n\t * - the provider says there is no next page — complete;\n\t * - the backstop is reached — `truncated`, because issues beyond it exist and were not read;\n\t * - the provider claims a next page but hands back a cursor that does not advance — also `truncated`, since\n\t * the read cannot continue and the remainder is unreachable rather than absent.\n\t *\n\t * Cancellation is deliberately NOT truncation: the caller asked for the read to stop, so the partial list is\n\t * what it asked for, and flagging it would surface an incompleteness warning for a user action.\n\t */\n\tprotected override async searchProviderMyIssuesWithTruncation(\n\t\tsession: ProviderAuthenticationSession,\n\t\tresources?: ResourceDescriptor[],\n\t\tcancellation?: AbortSignal,\n\t\toptions?: SearchMyIssuesOptions,\n\t): Promise<AccountWideIssuesResult | undefined> {\n\t\tif (resources != null) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst api = await this.getProvidersApi();\n\t\tconst states = toProviderIssueStates(options?.state);\n\t\tlet cursor = undefined;\n\t\t// Starts false so an immediate cancellation, which leaves the loop before the first response, reads as\n\t\t// \"no more pages known\" rather than as an unfinished drain.\n\t\tlet hasMore = false;\n\t\tlet requestCount = 0;\n\t\tlet truncated = false;\n\t\tconst issues = [];\n\t\ttry {\n\t\t\tdo {\n\t\t\t\tif (cancellation?.aborted) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tconst result = await api.getIssuesForCurrentUser(toTokenWithInfo(this.id, session), {\n\t\t\t\t\tcursor: cursor,\n\t\t\t\t\tstates: states,\n\t\t\t\t\tsort: options?.sort,\n\t\t\t\t});\n\t\t\t\trequestCount += 1;\n\t\t\t\thasMore = result.paging?.more ?? false;\n\t\t\t\tconst nextCursor = result.paging?.cursor;\n\n\t\t\t\t// Keep this page before deciding whether to continue: the request is already paid for, so\n\t\t\t\t// dropping its rows would lose real results to save nothing.\n\t\t\t\tconst formattedIssues = result.values\n\t\t\t\t\t.map(issue => toIssueShape(issue, this, { projection: 'account' }))\n\t\t\t\t\t.filter((result): result is IssueShape => result != null);\n\t\t\t\tif (formattedIssues.length > 0) {\n\t\t\t\t\tissues.push(...formattedIssues);\n\t\t\t\t}\n\n\t\t\t\t// The provider claims more but hands back no advancing cursor: continuing would re-read the page\n\t\t\t\t// just returned. `ProvidersApi.getPagedResult` already normalizes this into `more: false`, so\n\t\t\t\t// this is a backstop for if that ever stops holding rather than a case seen today -- but the rest\n\t\t\t\t// of the account is unreachable either way, which is what `truncated` says.\n\t\t\t\tif (hasMore && (nextCursor == null || nextCursor === cursor)) {\n\t\t\t\t\ttruncated = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tcursor = nextCursor;\n\t\t\t} while (requestCount < maxAccountWidePagesPerRequest && hasMore);\n\n\t\t\t// Ran out of budget with pages still to come.\n\t\t\tif (hasMore && requestCount >= maxAccountWidePagesPerRequest) {\n\t\t\t\ttruncated = true;\n\t\t\t}\n\t\t} catch (ex) {\n\t\t\tif (issues.length === 0) {\n\t\t\t\tthrow ex;\n\t\t\t}\n\n\t\t\t// Kept what was already fetched, so the list is real but short of the account.\n\t\t\ttruncated = true;\n\t\t\tLogger.error(ex, 'searchProviderMyIssues');\n\t\t}\n\t\treturn { values: issues, truncated: truncated };\n\t}\n\tprotected override async getProviderLinkedIssueOrPullRequest(\n\t\tsession: ProviderAuthenticationSession,\n\t\tresource: ResourceDescriptor,\n\t\t{ key }: { id: string; key: string },\n\t\t_type: undefined | IssueOrPullRequestType,\n\t): Promise<IssueOrPullRequest | undefined> {\n\t\tconst issue = await this.getRawProviderIssue(session, resource, key);\n\t\tconst autolinkableIssue: ProviderIssue | undefined = issue && {\n\t\t\t...issue,\n\t\t\turl: this.getIssueAutolinkLikeUrl(issue),\n\t\t};\n\t\treturn autolinkableIssue && toIssueShape(autolinkableIssue, this, { projection: 'point' });\n\t}\n\tprotected override async getProviderIssue(\n\t\tsession: ProviderAuthenticationSession,\n\t\tresource: ResourceDescriptor,\n\t\tid: string,\n\t): Promise<Issue | undefined> {\n\t\tconst result = await this.getRawProviderIssue(session, resource, id);\n\t\treturn result && fromProviderIssue(result, this, { projection: 'point' });\n\t}\n\n\tprotected override async getProviderIssueByResourceId(\n\t\tsession: ProviderAuthenticationSession,\n\t\tresourceId: string,\n\t\tid: string,\n\t\t_resourceUrl: string | undefined,\n\t): Promise<Issue | undefined> {\n\t\tconst api = await this.getProvidersApi();\n\t\tconst result = await api.getIssue(toTokenWithInfo(this.id, session), {\n\t\t\tresourceId: resourceId,\n\t\t\tnumber: id,\n\t\t});\n\t\treturn result && fromProviderIssue(result, this, { projection: 'batch' });\n\t}\n\n\t/**\n\t * The cheap check behind the batch issue read's etags: one `issues` query per team and\n\t * {@link linearIssuesEtagMaxNumbers} distinct numbers, where {@link getProviderIssueByResourceId} sends one request\n\t * per issue. A request that throws rejects only its own targets' slots, with its error classified as the full\n\t * read's would be.\n\t *\n\t * Never proves an absence. The query filters by the team's CURRENT key and asks for archived issues too, but the\n\t * full read's `issue(id:)` may also resolve an identifier the issue no longer carries (its team was renamed, or it\n\t * moved to another team), so an issue the query leaves out may still exist. Its target's slot is rejected, as is a\n\t * target whose identifier isn't a team key and a number, so the full read decides. When no target was answered and\n\t * nothing failed, the check declines instead, so a batch of only such targets costs a full read, not a failure.\n\t */\n\tprotected override async getProviderIssuesEtagFieldsByResourceId(\n\t\tsession: ProviderAuthenticationSession,\n\t\ttargets: readonly { resourceId: string; identifier: string; resourceUrl?: string }[],\n\t): Promise<PromiseSettledResult<IssueEtagFields | undefined>[] | undefined> {\n\t\tconst slots = new Array<PromiseSettledResult<IssueEtagFields | undefined>>(targets.length);\n\t\tlet answered = false;\n\t\tlet failed = false;\n\n\t\t// Each workspace and team's distinct numbers, with the targets asking for each.\n\t\tconst byTeam = new Map<string, { teamKey: string; numbers: Map<number, number[]> }>();\n\t\tfor (const [index, target] of targets.entries()) {\n\t\t\tconst match = linearIdentifier.exec(target.identifier);\n\t\t\tconst number = match != null ? Number(match[2]) : Number.NaN;\n\t\t\t// Only a number written as Linear writes it, so `ENG-012` never answers for `ENG-12`.\n\t\t\tif (match == null || !Number.isSafeInteger(number) || String(number) !== match[2]) {\n\t\t\t\tslots[index] = {\n\t\t\t\t\tstatus: 'rejected',\n\t\t\t\t\treason: new Error(`Not a Linear issue identifier: ${target.identifier}`),\n\t\t\t\t};\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst teamKey = match[1].toUpperCase();\n\t\t\tconst groupKey = `${target.resourceId}\\n${teamKey}`;\n\t\t\tlet group = byTeam.get(groupKey);\n\t\t\tif (group == null) {\n\t\t\t\tgroup = { teamKey: teamKey, numbers: new Map() };\n\t\t\t\tbyTeam.set(groupKey, group);\n\t\t\t}\n\n\t\t\tlet indices = group.numbers.get(number);\n\t\t\tif (indices == null) {\n\t\t\t\tindices = [];\n\t\t\t\tgroup.numbers.set(number, indices);\n\t\t\t}\n\t\t\tindices.push(index);\n\t\t}\n\n\t\tconst requests = [...byTeam.values()].flatMap(({ teamKey, numbers }) =>\n\t\t\tchunk([...numbers], linearIssuesEtagMaxNumbers).map(entries => ({ teamKey: teamKey, entries: entries })),\n\t\t);\n\t\tif (requests.length) {\n\t\t\tconst api = await this.getProvidersApi();\n\t\t\tconst tokenWithInfo = toTokenWithInfo(this.id, session);\n\t\t\tconst answers = await mapSettledBounded(requests, providerFanOutConcurrency, r =>\n\t\t\t\tapi.getLinearIssuesEtagFields(\n\t\t\t\t\ttokenWithInfo,\n\t\t\t\t\tr.teamKey,\n\t\t\t\t\tr.entries.map(([number]) => number),\n\t\t\t\t),\n\t\t\t);\n\n\t\t\tfor (const [i, answer] of answers.entries()) {\n\t\t\t\tconst { teamKey, entries } = requests[i];\n\t\t\t\tif (answer.status === 'rejected') {\n\t\t\t\t\tfailed = true;\n\t\t\t\t\tfor (const [, indices] of entries) {\n\t\t\t\t\t\tfor (const index of indices) {\n\t\t\t\t\t\t\tslots[index] = answer;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\t// By number, never by position: Linear returns the issues in its own order, and only the ones it found.\n\t\t\t\tconst byNumber = new Map<number, LinearIssueEtagNode>();\n\t\t\t\tfor (const issue of answer.value) {\n\t\t\t\t\tbyNumber.set(issue.number, issue);\n\t\t\t\t}\n\n\t\t\t\tfor (const [number, indices] of entries) {\n\t\t\t\t\tconst issue = byNumber.get(number);\n\t\t\t\t\tlet slot: PromiseSettledResult<IssueEtagFields | undefined>;\n\t\t\t\t\tif (issue == null) {\n\t\t\t\t\t\tslot = { status: 'rejected', reason: new Error(`Linear did not return ${teamKey}-${number}`) };\n\t\t\t\t\t} else {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tslot = { status: 'fulfilled', value: toLinearIssueEtagFields(issue) };\n\t\t\t\t\t\t\tanswered = true;\n\t\t\t\t\t\t} catch (ex) {\n\t\t\t\t\t\t\tslot = { status: 'rejected', reason: ex };\n\t\t\t\t\t\t\tfailed = true;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tfor (const index of indices) {\n\t\t\t\t\t\tslots[index] = slot;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn answered || failed ? slots : undefined;\n\t}\n\n\tprivate async getRawProviderIssue(\n\t\tsession: ProviderAuthenticationSession,\n\t\tresource: ResourceDescriptor,\n\t\tid: string,\n\t): Promise<ProviderIssue | undefined> {\n\t\tconst api = await this.getProvidersApi();\n\t\tif (!isIssueResourceDescriptor(resource)) {\n\t\t\tLogger.error(undefined, 'getProviderIssue: resource is not an IssueResourceDescriptor');\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn api.getIssue(toTokenWithInfo(this.id, session), {\n\t\t\tresourceId: resource.id,\n\t\t\tnumber: id,\n\t\t});\n\t}\n\tprivate getIssueAutolinkLikeUrl(issue: ProviderIssue): string | null {\n\t\tconst url = issue.url;\n\t\tif (url == null) return null;\n\n\t\tconst lastSegment = url.split('/').pop();\n\t\tif (!lastSegment || issue.number === lastSegment) {\n\t\t\treturn url;\n\t\t}\n\t\treturn url.substring(0, url.length - lastSegment.length - 1);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAgDA,MAAM,WAAW,kBAAA;AACjB,MAAM,eAAe,OAAO,OAAO;CAAE,IAAI,SAAS;CAAI,QAAQ,SAAS;AAAO,CAAC;AAC/E,MAAM,qBAAqB;;;;;;;;;;;;;;;AAe3B,MAAM,gCAAgC;AACtC,MAAM,8BAA8B;;AAEpC,MAAM,2BAA2B;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AC,CAAC,IAAI;EACvC,IAAI,CAAC,eAAe,MAAM,WAAW,aACpC,OAAO;EAER,OAAO,IAAI,UAAU,GAAG,IAAI,SAAS,YAAY,SAAS,CAAC;CAC5D;AACD;AAvsBE,WAAA,CAAA,MAAM,CAAA,GAAA,kBAAA,WAAA,8BAAA,IAAA"}
1
+ {"version":3,"file":"linear.js","names":[],"sources":["../../../../../plus/integrations/src/providers/linear.ts"],"sourcesContent":["import type { CollectionMetadata, CollectionScopeFailure, GitIssueState } from '@gitkraken/provider-apis';\nimport type { Account } from '@gitlens/git/models/author.js';\nimport type { AutolinkReference, DynamicAutolinkReference } from '@gitlens/git/models/autolink.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 { chunk } from '@gitlens/utils/array.js';\nimport { trace } from '@gitlens/utils/decorators/log.js';\nimport { Logger } from '@gitlens/utils/logger.js';\nimport { getScopedLogger } from '@gitlens/utils/logger.scoped.js';\nimport { mapSettledBounded } from '@gitlens/utils/promise.js';\nimport { PromiseCache } from '@gitlens/utils/promiseCache.js';\nimport type { IntegrationAuthenticationProviderDescriptor } from '../authentication/integrationAuthenticationProvider.js';\nimport type { ConnectionResource, ProviderAuthenticationSession } from '../authentication/models.js';\nimport { toTokenWithInfo } from '../authentication/models.js';\nimport { toCollectionScopeFailure } from '../collectionMetadata.js';\nimport { IssuesCloudHostIntegrationId, providerFanOutConcurrency } from '../constants.js';\nimport { IntegrationReadUnavailableError, toError } from '../errors.js';\nimport type { IntegrationResult, IssueEtagFields } from '../models/integration.js';\nimport { isReadSessionFailure } from '../models/integration.js';\nimport type {\n\tAccountWideIssuesResult,\n\tIssuesForProjectOptions,\n\tProjectIssuesDrain,\n\tProjectIssuesRequest,\n\tSearchMyIssuesOptions,\n} from '../models/issueReads.js';\nimport {\n\tgroupProjectIssuesSearches,\n\tIssuesIntegration,\n\tsplitProjectIssuesSearch,\n} from '../models/issuesIntegration.js';\nimport { IssueFilter } from '../providerFilters.js';\nimport type { LinearIssueEtagNode } from './linearIssuesEtag.js';\nimport { linearIssuesEtagMaxNumbers, toLinearIssueEtagFields } from './linearIssuesEtag.js';\nimport type {\n\tProviderApiCollectionResult,\n\tProviderHierarchyResult,\n\tProviderIssue,\n\tProviderLinearProject,\n} from './models.js';\nimport { fromProviderIssue, providersMetadata, toIssueShape, toProviderIssueStates } from './models.js';\nimport { DiscoveryCache, isAutolinkSetExpired } from './utils/discoveryCache.js';\nimport { createIssueAutolinkReferences } from './utils/issueAutolinks.js';\nimport { collectProviderPagedResult, mergeCollectionMetadata } from './utils/providerPaging.js';\n\nconst metadata = providersMetadata[IssuesCloudHostIntegrationId.Linear];\nconst authProvider = Object.freeze({ id: metadata.id, scopes: metadata.scopes });\nconst maxPagesPerRequest = 10;\n/**\n * The account-wide drain's own backstop, separate from {@link maxPagesPerRequest}.\n *\n * Raised to 50 (5,000 issues at the SDK's 100-per-page) because 10 no longer means what it used to. That read\n * once fanned out over four overlapping relationship queries and merged them, so most of what a page cost was\n * rows already returned — a low budget capped the waste. It is now a single server-ordered query over an `or`\n * filter, so every page is 100 issues the caller has not seen, and the same budget just truncates real results\n * at 1,000.\n *\n * Reaching it is reported rather than silent: {@link LinearIntegration.searchProviderMyIssuesWithTruncation}\n * returns `truncated`, so the facade can say the read was incomplete instead of publishing a capped list as a\n * whole account. The bound stays — a runaway cursor must not spend requests forever — but it is now set where a\n * real Linear account is unlikely to reach it rather than where the duplication used to hurt.\n */\nconst maxAccountWidePagesPerRequest = 50;\nconst linearImplicitTeamsPageSize = 50;\n/** The workspace Projects read's backstop: provider-apis pages them 100 at a time, so 2,000 Projects. */\nconst maxWorkspaceProjectPages = 20;\n/** Long enough to span one tracker read, short enough that a profile change shows on the next. */\nconst recentAccountTTL = 60 * 1000;\n/** A team key and issue number, as Linear writes an issue's identifier (`ENG-123`). */\nconst linearIdentifier = /^([A-Za-z0-9]+)-(\\d+)$/;\n\nexport interface LinearTeamDescriptor extends IssueResourceDescriptor {\n\tavatarUrl: string | undefined;\n}\n\nexport interface LinearOrganizationDescriptor extends IssueResourceDescriptor {\n\turl: string;\n}\n\nexport interface LinearProjectDescriptor extends IssueResourceDescriptor {}\n\n/** The part of a team read's filter that narrows it to the viewer. */\ntype LinearViewerScope = { assignees: string[]; githubSyncedCreators?: string[] };\n\n/**\n * How a user-scoped team read narrows to the viewer: the issues assigned to them, plus, unless the caller asked for\n * assigned issues by name, the GitHub-synced issues they created. Linear's GitHub Issues sync makes the GitHub author\n * of an issue (one who linked their GitHub account) the creator of its Linear copy but assigns no one GitHub doesn't,\n * so an assignee-only read never returns the copy of a GitHub issue the user filed (gitkraken/kepler#4480). Only\n * synced issues widen, and only those the viewer created on either side: the rest of what the user created in Linear\n * stays out of \"my issues\", as does a synced issue they merely follow.\n */\nfunction viewerScope(viewerId: string, filters: IssueFilter[] | undefined): LinearViewerScope {\n\treturn filters?.includes(IssueFilter.Assignee)\n\t\t? { assignees: [viewerId] }\n\t\t: { assignees: [viewerId], githubSyncedCreators: [viewerId] };\n}\n\nexport class LinearIntegration extends IssuesIntegration<IssuesCloudHostIntegrationId.Linear> {\n\t/**\n\t * Built from the teams, so it follows them: rebuilt when the team list changes or the caches are dropped, and once\n\t * {@link isAutolinkSetExpired}: older than the TTL, or than a shorter retry delay when the organization or the teams\n\t * couldn't be read whole. An expired set is still served while it is rebuilt in the background, because autolinks\n\t * are read on every render of a commit message and must not wait on the network (#5907, #6183).\n\t */\n\tprivate readonly _autolinks = new Map<\n\t\tstring,\n\t\t{ autolinks: (AutolinkReference | DynamicAutolinkReference)[]; builtAt: number; complete: boolean }\n\t>();\n\tprivate readonly _autolinksBuilds = new Map<string, Promise<(AutolinkReference | DynamicAutolinkReference)[]>>();\n\n\toverride async autolinks(): Promise<(AutolinkReference | DynamicAutolinkReference)[]> {\n\t\tconst connected = this.maybeConnected ?? (await this.isConnected());\n\t\tif (!connected || this._session == null) {\n\t\t\treturn [];\n\t\t}\n\n\t\tconst session = this._session;\n\t\tconst cached = this._autolinks.get(session.accessToken);\n\t\t// A session kept through a failed refresh is expired: building with it would send that token to the provider\n\t\t// on every render, so serve whatever was built before (none after a forced re-sync) until a read refreshes it.\n\t\tif (this.connectionExpired === true) return cached?.autolinks ?? [];\n\t\tif (cached == null || (cached.builtAt === 0 && !cached.complete && cached.autolinks.length === 0)) {\n\t\t\treturn this.buildAutolinks(session);\n\t\t}\n\n\t\tif (cached.builtAt === 0 || isAutolinkSetExpired(cached)) {\n\t\t\tvoid this.buildAutolinks(session);\n\t\t}\n\t\treturn cached.autolinks;\n\t}\n\n\t/**\n\t * One build per token at a time: concurrent renders share it rather than each re-reading the teams. A drop or a\n\t * change to the team list retires it, so a render after one doesn't join a build reading the teams as they were\n\t * before (#6170, #6184).\n\t */\n\tprivate buildAutolinks(\n\t\tsession: ProviderAuthenticationSession,\n\t): Promise<(AutolinkReference | DynamicAutolinkReference)[]> {\n\t\tconst { accessToken } = session;\n\t\tlet build = this._autolinksBuilds.get(accessToken);\n\t\tif (build == null) {\n\t\t\tbuild = this.buildAutolinksCore(session, () => build).finally(() => {\n\t\t\t\t// A drop or a list change meanwhile retired this build, and the entry may be a later one's now.\n\t\t\t\tif (this._autolinksBuilds.get(accessToken) === build) {\n\t\t\t\t\tthis._autolinksBuilds.delete(accessToken);\n\t\t\t\t}\n\t\t\t});\n\t\t\tthis._autolinksBuilds.set(accessToken, build);\n\t\t}\n\t\treturn build;\n\t}\n\n\tprivate async buildAutolinksCore(\n\t\tsession: ProviderAuthenticationSession,\n\t\treader?: () => Promise<unknown> | undefined,\n\t): Promise<(AutolinkReference | DynamicAutolinkReference)[]> {\n\t\tconst { accessToken } = session;\n\t\tconst generation = this._teams.generation;\n\t\ttry {\n\t\t\tconst organization = await this.getOrganization(session, false, reader);\n\t\t\tif (organization != null && this._teams.generation === generation) {\n\t\t\t\tconst teams = await this.getTeamsWithMetadata(session, false, reader);\n\t\t\t\tif (teams != null && this._teams.generation !== generation) {\n\t\t\t\t\t// Existing waiters own this successful response, but the active generation must not retain it.\n\t\t\t\t\treturn getTeamAutolinks(organization, teams.values);\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (ex) {\n\t\t\tLogger.error(ex, 'LinearIntegration.autolinks');\n\t\t}\n\t\treturn this.deriveAutolinks(accessToken, { store: this._teams.generation === generation });\n\t}\n\n\tprivate deriveAutolinks(\n\t\taccessToken: string,\n\t\toptions?: {\n\t\t\tstore?: boolean;\n\t\t\tsettled?: boolean;\n\t\t},\n\t): (AutolinkReference | DynamicAutolinkReference)[] {\n\t\tconst organization = this._organizations.peek(accessToken);\n\t\tconst complete = this._organizations.get(accessToken) != null && this._teams.get(accessToken) != null;\n\t\tconst autolinks =\n\t\t\torganization != null ? getTeamAutolinks(organization, this._teams.peek(accessToken) ?? []) : [];\n\t\tif (options?.store !== false) {\n\t\t\tthis._autolinks.set(accessToken, {\n\t\t\t\tautolinks: autolinks,\n\t\t\t\tcomplete: complete,\n\t\t\t\t// Stores preserve the retry deadline; only a settled build restarts it.\n\t\t\t\tbuiltAt:\n\t\t\t\t\toptions?.settled !== false\n\t\t\t\t\t\t? Date.now()\n\t\t\t\t\t\t: this._autolinks.get(accessToken)?.builtAt || (complete ? Date.now() : 0),\n\t\t\t});\n\t\t}\n\t\treturn autolinks;\n\t}\n\n\tprivate onDiscoveryStored(accessToken: string, reader?: () => Promise<unknown> | undefined): void {\n\t\t// A build's own store must not break sharing before its continuation runs.\n\t\tif (this._autolinksBuilds.get(accessToken) !== reader?.()) {\n\t\t\tthis._autolinksBuilds.delete(accessToken);\n\t\t}\n\t\tthis.deriveAutolinks(accessToken, { settled: false });\n\t}\n\n\t/** The workspace is the token's organization; kept only as a complete, trimmed pair. */\n\toverride async getProviderResourceForSession(\n\t\tsession: ProviderAuthenticationSession,\n\t): Promise<ConnectionResource | undefined> {\n\t\tconst organization = await this.getOrganization(session, true);\n\t\tconst id = organization?.id.trim();\n\t\tconst name = organization?.name.trim();\n\t\treturn id && name ? { id: id, name: name } : undefined;\n\t}\n\n\tprivate readonly _organizations = new DiscoveryCache<LinearOrganizationDescriptor>();\n\t/**\n\t * In flight by token and discovery generation. The request can't be aborted (provider-apis takes no signal), so a\n\t * lookup that outlives its caller's timeout is joined by the next one rather than piling another request on top of\n\t * it; but not across a drop, since a lookup started before a forced refresh answers as from before it (#6162).\n\t */\n\tprivate readonly _organizationRequests = new Map<string, Promise<LinearOrganizationDescriptor | undefined>>();\n\tprivate async getOrganization(\n\t\tsession: ProviderAuthenticationSession,\n\t\tforce: boolean = false,\n\t\treader?: () => Promise<unknown> | undefined,\n\t): Promise<LinearOrganizationDescriptor | undefined> {\n\t\tconst { accessToken } = session;\n\t\tconst cached = this._organizations.get(accessToken);\n\t\tif (cached != null && !force) return cached;\n\n\t\tconst generation = this._organizations.generation;\n\t\tconst started = this._organizations.startRead();\n\t\tconst requestKey = `${this.discoveryGeneration}:${accessToken}`;\n\t\tlet request = this._organizationRequests.get(requestKey);\n\t\tif (request == null) {\n\t\t\trequest = this.fetchOrganization(session).finally(() => this._organizationRequests.delete(requestKey));\n\t\t\tthis._organizationRequests.set(requestKey, request);\n\t\t}\n\t\tconst organization = await request;\n\t\tif (organization == null) return undefined;\n\n\t\tconst stored = this._organizations.set(accessToken, organization, { generation: generation, read: started });\n\t\tif (stored === 'changed') {\n\t\t\tthis.onDiscoveryStored(accessToken, reader);\n\t\t}\n\t\treturn stored === false && this._organizations.generation === generation\n\t\t\t? this._organizations.peek(accessToken)\n\t\t\t: organization;\n\t}\n\n\tprivate async fetchOrganization(\n\t\tsession: ProviderAuthenticationSession,\n\t): Promise<LinearOrganizationDescriptor | undefined> {\n\t\tconst api = await this.getProvidersApi();\n\t\tconst organization = await api.getLinearOrganization(toTokenWithInfo(this.id, session));\n\t\treturn (\n\t\t\torganization && {\n\t\t\t\tid: organization.id,\n\t\t\t\tkey: organization.key,\n\t\t\t\tname: organization.name,\n\t\t\t\turl: organization.url,\n\t\t\t}\n\t\t);\n\t}\n\n\t/** Expires, and is dropped on a re-sync, so a team created or left mid-session is picked up (#5907). */\n\tprivate readonly _teams = new DiscoveryCache<LinearTeamDescriptor[]>();\n\tprivate async getTeams(\n\t\tsession: ProviderAuthenticationSession,\n\t\tforce: boolean = false,\n\t): Promise<LinearTeamDescriptor[] | undefined> {\n\t\treturn (await this.getTeamsWithMetadata(session, force))?.values;\n\t}\n\n\tprivate async getTeamsWithMetadata(\n\t\tsession: ProviderAuthenticationSession,\n\t\tforce: boolean = false,\n\t\treader?: () => Promise<unknown> | undefined,\n\t): Promise<ProviderApiCollectionResult<LinearTeamDescriptor> | undefined> {\n\t\tconst { accessToken } = session;\n\n\t\tconst cachedResources = this._teams.get(accessToken);\n\t\tif (cachedResources != null && !force) return { values: cachedResources };\n\n\t\tconst generation = this._teams.generation;\n\t\tconst started = this._teams.startRead();\n\t\tconst read = await this.readTeams(session);\n\t\tif (read == null) return read;\n\n\t\t// Not stored when the cache was dropped, or a read started after this one stored the teams, while this read\n\t\t// was in flight.\n\t\tconst stored = this._teams.set(accessToken, read.values, {\n\t\t\tgeneration: generation,\n\t\t\tread: started,\n\t\t\tcomplete: read.metadata == null || read.metadata.completeness === 'complete',\n\t\t});\n\t\tif (stored === 'changed') {\n\t\t\tthis.onDiscoveryStored(accessToken, reader);\n\t\t} else if (stored === false && this._teams.generation === generation) {\n\t\t\t// Refused for a read started after it: answers with that read's newer list, which this older one must not\n\t\t\t// stand in for, not even once expired (#6184).\n\t\t\treturn {\n\t\t\t\tvalues: this._teams.peek(accessToken) ?? read.values,\n\t\t\t\tmetadata: this._teams.get(accessToken) == null ? { completeness: 'unknown' } : undefined,\n\t\t\t};\n\t\t}\n\t\treturn read;\n\t}\n\n\tprivate async readTeams(\n\t\tsession: ProviderAuthenticationSession,\n\t): Promise<ProviderApiCollectionResult<LinearTeamDescriptor> | undefined> {\n\t\tconst api = await this.getProvidersApi();\n\t\tconst teams = await api.getLinearTeamsForCurrentUser(toTokenWithInfo(this.id, session));\n\t\tconst descriptors: LinearTeamDescriptor[] | undefined = teams?.map(t => ({\n\t\t\tid: t.id,\n\t\t\tkey: t.key,\n\t\t\tname: t.name,\n\t\t\tavatarUrl: t.iconUrl,\n\t\t}));\n\t\tif (descriptors == null) return undefined;\n\n\t\t// provider-apis currently requests Linear's teams connection without pageInfo or a cursor. Linear's\n\t\t// implicit page size is 50, so exactly a full page cannot prove there is no team 51. Preserve the useful\n\t\t// prefix, but mark it unknown so the next discovery read retries instead of treating it as\n\t\t// authoritative. Once provider-apis exposes a paged primitive, replace this fail-closed guard with a drain.\n\t\tif (descriptors.length >= linearImplicitTeamsPageSize) {\n\t\t\treturn { values: descriptors, metadata: { completeness: 'unknown' } };\n\t\t}\n\n\t\treturn { values: descriptors };\n\t}\n\n\t/**\n\t * The workspace's Linear Projects (Linear's `Project` entity), drained across their pages. Separate from the\n\t * teams this integration lists as its projects: a Linear Project can span several teams, and selecting one\n\t * narrows an issue read (`IssuesForProjectOptions.linearProjects`) rather than naming what is read.\n\t *\n\t * Cached like the teams, and only when complete: a drain cut short by its backstop or a failed page is returned\n\t * with its `truncated`/`metadata` so the facade can say so, and read again next time. A first-page failure\n\t * rejects, which the result wrapper turns into `{ error }`. `fresh` reads past the cache and any read in flight,\n\t * for a caller that must not take a list from before what it needs to see (a Project created since).\n\t */\n\t@trace()\n\tasync getWorkspaceProjectsResult(\n\t\tconnectionId?: string,\n\t\toptions?: { fresh?: boolean },\n\t): Promise<IntegrationResult<ProviderHierarchyResult<ProviderLinearProject>>> {\n\t\tconst scope = getScopedLogger();\n\t\t// `connectionId` targets a specific account (multi-account); omitted reads the primary.\n\t\tconst session = await this.resolveReadSession(connectionId, scope);\n\t\tif (session == null || isReadSessionFailure(session)) return session && { error: session.error };\n\n\t\ttry {\n\t\t\tconst projects = await this.getWorkspaceProjects(session, options?.fresh === true);\n\t\t\tawait this.confirmScopedAuthFailures(session, projects.metadata);\n\t\t\tthis.resetRequestExceptionCount('getProjectsForResources', connectionId);\n\t\t\treturn { value: projects };\n\t\t} catch (ex) {\n\t\t\tthis.handleProviderException('getProjectsForResources', ex, { connectionId: connectionId });\n\t\t\treturn { error: toError(ex) };\n\t\t}\n\t}\n\n\t/** Expires, and is dropped on a re-sync, so a Project created or archived mid-session is picked up. */\n\tprivate readonly _workspaceProjects = new DiscoveryCache<ProviderLinearProject[]>();\n\t/**\n\t * In flight by token, with the cache generation it started under: concurrent cold reads share one drain, but a\n\t * read after the cache was dropped (a `forceSync`) never joins one started before, which could miss what it asks\n\t * to see.\n\t */\n\tprivate readonly _workspaceProjectsReads = new Map<\n\t\tstring,\n\t\t{ generation: number; read: Promise<ProviderHierarchyResult<ProviderLinearProject>> }\n\t>();\n\tprivate getWorkspaceProjects(\n\t\tsession: ProviderAuthenticationSession,\n\t\tfresh: boolean,\n\t): Promise<ProviderHierarchyResult<ProviderLinearProject>> {\n\t\tconst { accessToken } = session;\n\t\tconst generation = this._workspaceProjects.generation;\n\t\tif (!fresh) {\n\t\t\tconst cached = this._workspaceProjects.get(accessToken);\n\t\t\tif (cached != null) return Promise.resolve({ values: cached });\n\n\t\t\tconst inFlight = this._workspaceProjectsReads.get(accessToken);\n\t\t\tif (inFlight?.generation === generation) return inFlight.read;\n\t\t}\n\n\t\tconst entry = { generation: generation, read: this.readWorkspaceProjects(session) };\n\t\tentry.read = entry.read.then(result => {\n\t\t\tif (\n\t\t\t\tthis._workspaceProjectsReads.get(accessToken) === entry &&\n\t\t\t\tresult.truncated !== true &&\n\t\t\t\t(result.metadata == null || result.metadata.completeness === 'complete')\n\t\t\t) {\n\t\t\t\tthis._workspaceProjects.set(accessToken, result.values, { generation: generation });\n\t\t\t}\n\t\t\treturn result;\n\t\t});\n\t\tthis._workspaceProjectsReads.set(accessToken, entry);\n\t\tvoid entry.read\n\t\t\t.finally(() => {\n\t\t\t\tif (this._workspaceProjectsReads.get(accessToken) === entry) {\n\t\t\t\t\tthis._workspaceProjectsReads.delete(accessToken);\n\t\t\t\t}\n\t\t\t})\n\t\t\t.catch(() => {});\n\t\treturn entry.read;\n\t}\n\n\t/**\n\t * Drains the Projects cursor up to {@link maxWorkspaceProjectPages}. A first-page failure rejects, so the read\n\t * fails as the team read does rather than reading as a workspace with no Projects; a later one keeps the prefix\n\t * and records the failure, as do a stalled cursor and the backstop with pages left.\n\t */\n\tprivate async readWorkspaceProjects(\n\t\tsession: ProviderAuthenticationSession,\n\t): Promise<ProviderHierarchyResult<ProviderLinearProject>> {\n\t\tconst api = await this.getProvidersApi();\n\t\tconst tokenWithInfo = toTokenWithInfo(this.id, session);\n\t\tlet pagesRead = 0;\n\t\tlet firstPageError: Error | undefined;\n\t\tconst read = await collectProviderPagedResult(\n\t\t\tasync cursor => {\n\t\t\t\ttry {\n\t\t\t\t\tconst page = await api.getLinearProjects(tokenWithInfo, { cursor: cursor });\n\t\t\t\t\tpagesRead++;\n\t\t\t\t\treturn page;\n\t\t\t\t} catch (ex) {\n\t\t\t\t\tif (pagesRead === 0) {\n\t\t\t\t\t\tfirstPageError = toError(ex);\n\t\t\t\t\t}\n\t\t\t\t\tthrow ex;\n\t\t\t\t}\n\t\t\t},\n\t\t\tmaxWorkspaceProjectPages,\n\t\t\t{ providerId: this.id },\n\t\t);\n\t\t// The drain records any failure against its scope and keeps the prefix; with no prefix, there is no list.\n\t\tif (firstPageError != null) throw firstPageError;\n\n\t\treturn read;\n\t}\n\n\tprotected override async getProviderResourcesForUser(\n\t\tsession: ProviderAuthenticationSession,\n\t): Promise<ResourceDescriptor[] | undefined> {\n\t\tconst organization = await this.getOrganization(session);\n\t\treturn organization != null ? [organization] : undefined;\n\t}\n\tprotected override async getProviderUncachedResourcesForUser(\n\t\tsession: ProviderAuthenticationSession,\n\t): Promise<ResourceDescriptor[] | undefined> {\n\t\t// Joins none in flight, unlike `getOrganization`: one may have started before what the caller needs to see.\n\t\tconst organization = await this.fetchOrganization(session);\n\t\treturn organization != null ? [organization] : undefined;\n\t}\n\tprotected override getProviderProjectsForResources(\n\t\tsession: ProviderAuthenticationSession,\n\t\t_resources: ResourceDescriptor[],\n\t): Promise<ResourceDescriptor[] | undefined> {\n\t\treturn this.getTeams(session);\n\t}\n\tprotected override async getProviderProjectsForResourcesWithMetadata(\n\t\tsession: ProviderAuthenticationSession,\n\t\t_resources: ResourceDescriptor[],\n\t): Promise<ProviderApiCollectionResult<ResourceDescriptor>> {\n\t\treturn (await this.getTeamsWithMetadata(session)) ?? { values: [], metadata: { completeness: 'unknown' } };\n\t}\n\tprotected override async getProviderUncachedProjectsForResourcesWithMetadata(\n\t\tsession: ProviderAuthenticationSession,\n\t\t_resources: ResourceDescriptor[],\n\t): Promise<ProviderApiCollectionResult<ResourceDescriptor>> {\n\t\treturn (await this.readTeams(session)) ?? { values: [], metadata: { completeness: 'unknown' } };\n\t}\n\n\tprotected override clearDiscoveryCaches(): void {\n\t\tthis._organizations.clear();\n\t\tthis._teams.clear();\n\t\tthis._workspaceProjects.clear();\n\t\tthis._workspaceProjectsReads.clear();\n\t\tthis._autolinks.clear();\n\t\tthis._autolinksBuilds.clear();\n\t\tthis._recentAccounts.clear();\n\t}\n\treadonly authProvider: IntegrationAuthenticationProviderDescriptor = authProvider;\n\n\t/**\n\t * Always asks Linear: the host's current-account cache decides when this runs. The viewer query is account-wide,\n\t * so the answer is lent briefly to the per-resource 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);\n\t}\n\n\tprotected override async getProviderAccountForResource(\n\t\tsession: ProviderAuthenticationSession,\n\t\t_resource: ResourceDescriptor,\n\t): Promise<Account | undefined> {\n\t\treturn this._recentAccounts.getOrCreate(session.accessToken, () => this.fetchAccount(session), {\n\t\t\tevictWhen: account => account == null,\n\t\t});\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(session: ProviderAuthenticationSession): Promise<Account | undefined> {\n\t\tconst api = await this.getProvidersApi();\n\t\t// Linear's viewer isn't a ProviderAccount (no username/avatar), so build the Account manually\n\t\t// (Trello-style) from the fields the viewer query returns.\n\t\tconst user = await api.getLinearCurrentUser(toTokenWithInfo(this.id, session));\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 ?? user.displayName ?? undefined,\n\t\t\tusername: user.displayName ?? undefined,\n\t\t\temail: user.email ?? undefined,\n\t\t\tavatarUrl: undefined,\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\tif (!isIssueResourceDescriptor(project)) return undefined;\n\n\t\t// Scope to \"my issues\" by the viewer's stable id, not the passed display name: Linear's `name` (full name)\n\t\t// and `displayName` (nickname) are distinct fields, and assignees are normalized with `.name` = the full\n\t\t// name while the caller's `user` is the displayName — so a name string can miss. The assignee `.id` is the\n\t\t// Linear user id, which is unambiguous.\n\t\tlet viewerId: string | undefined;\n\t\tif (options?.user != null) {\n\t\t\tviewerId = await this.getViewerId(session, options);\n\t\t\t// If the viewer can't be resolved we can't scope to \"my issues\" — returning the unfiltered team\n\t\t\t// issues would leak everyone else's, and returning [] is indistinguishable from \"no issues assigned\n\t\t\t// to me\". Throw so the facade (getIssuesForProjectResult → runCaptured) surfaces a warning +\n\t\t\t// fetchFailed the caller can act on, instead of a silent empty.\n\t\t\tif (viewerId == null) {\n\t\t\t\tthrow new IntegrationReadUnavailableError(\n\t\t\t\t\tmetadata.name,\n\t\t\t\t\t'could not resolve the current user to scope issues to',\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\t// `getProviderProjectsForResources` returns Linear teams, so `project.id` is a team id here.\n\t\t//\n\t\t// The state and the viewer are narrowed server-side, not after the drain: a team's done work and other\n\t\t// people's issues would otherwise count against the backstop, so a busy team runs out of pages before the\n\t\t// viewer's open issues and hands back a page that looks complete.\n\t\tconst drain = await this.drainIssues(\n\t\t\tsession,\n\t\t\t{\n\t\t\t\tteams: [project.id],\n\t\t\t\t...(options?.linearProjects?.length ? { projects: [...options.linearProjects] } : {}),\n\t\t\t\t...(viewerId != null ? viewerScope(viewerId, options?.filters) : {}),\n\t\t\t\tstates: toProviderIssueStates(options?.state),\n\t\t\t},\n\t\t\toptions?.sort,\n\t\t\t{ providerId: this.id, projectId: project.id },\n\t\t);\n\n\t\treturn drain.truncated\n\t\t\t? { values: drain.issues, truncated: true, recovery: 'none', metadata: drain.metadata }\n\t\t\t: { values: drain.issues, truncated: false, metadata: drain.metadata };\n\t}\n\n\t/**\n\t * Searches every team of a user-scoped read together: one `getIssues` names all of them and the viewer's scope\n\t * (see {@link viewerScope}), so a team with none of the user's issues costs no request of its own. Linear's filter\n\t * is a GraphQL body, not a query string, so there is no key bound to chunk at.\n\t *\n\t * A read narrowed to Linear Projects is searched together even across every assignee: the Projects already bound\n\t * it to a few teams' worth of issues, so a team holding none of them costs no request either. An unnarrowed read\n\t * of every assignee is still read team by team, since a search over all of them would just spend one team's page\n\t * budget before falling back.\n\t */\n\tprotected override getProjectIssuesSearches(\n\t\trequests: readonly ProjectIssuesRequest<ResourceDescriptor>[],\n\t): number[][] | undefined {\n\t\treturn groupProjectIssuesSearches(requests, ({ project, options }) =>\n\t\t\t(options.user != null || options.linearProjects?.length) && isIssueResourceDescriptor(project)\n\t\t\t\t? [\n\t\t\t\t\t\toptions.user ?? '',\n\t\t\t\t\t\toptions.userId ?? '',\n\t\t\t\t\t\toptions.sort ?? '',\n\t\t\t\t\t\toptions.state ?? '',\n\t\t\t\t\t\toptions.filters?.join(',') ?? '',\n\t\t\t\t\t\t...(options.linearProjects ?? []),\n\t\t\t\t\t].join('\\0')\n\t\t\t\t: undefined,\n\t\t);\n\t}\n\n\tprotected override async searchProviderProjectIssues(\n\t\tsession: ProviderAuthenticationSession,\n\t\trequests: readonly ProjectIssuesRequest<ResourceDescriptor>[],\n\t): Promise<IssueShape[][] | undefined> {\n\t\t// Every request of a search shares every option read here (see the key in `getProjectIssuesSearches`).\n\t\tconst { options } = requests[0];\n\t\tlet viewerId: string | undefined;\n\t\tif (options.user != null) {\n\t\t\t// Unresolvable here means each team's own read throws the same warning, so let them.\n\t\t\tviewerId = await this.getViewerId(session, options);\n\t\t\tif (viewerId == null) return undefined;\n\t\t} else if (!options.linearProjects?.length) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst teams = requests.map(request => request.project).filter(isIssueResourceDescriptor);\n\t\tif (teams.length !== requests.length) return undefined;\n\n\t\tconst drain = await this.drainIssues(\n\t\t\tsession,\n\t\t\t{\n\t\t\t\tteams: teams.map(team => team.id),\n\t\t\t\t...(options.linearProjects?.length ? { projects: [...options.linearProjects] } : {}),\n\t\t\t\t...(viewerId != null ? viewerScope(viewerId, options.filters) : {}),\n\t\t\t\tstates: toProviderIssueStates(options.state),\n\t\t\t},\n\t\t\toptions.sort,\n\t\t\t// Never published: an incomplete search is read again per team, which records its own failures.\n\t\t\t{ providerId: this.id },\n\t\t);\n\t\t// Deliberately discarded rather than served: an incomplete search says nothing about which of its teams it\n\t\t// covered, so only the per-team reads can report each one's completeness. The waste is bounded by one team's\n\t\t// page budget, and paid only by a search that needed more than that or failed partway.\n\t\tif (drain.truncated || (drain.metadata != null && drain.metadata.completeness !== 'complete')) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\t// A normalized Linear issue carries its team only inside `project`, which is absent for an issue in no\n\t\t// Linear project, so split by the identifier instead: Linear numbers every issue `<team key>-<n>`, and\n\t\t// renumbers it under its new team's key when it moves.\n\t\treturn splitProjectIssuesSearch(\n\t\t\tteams.map(team => team.key),\n\t\t\tdrain.issues,\n\t\t\tissue => {\n\t\t\t\tconst separator = issue.id.lastIndexOf('-');\n\t\t\t\treturn separator > 0 ? issue.id.slice(0, separator) : undefined;\n\t\t\t},\n\t\t);\n\t}\n\n\tprivate readonly _viewerIds = new PromiseCache<string, string | undefined>({ capacity: 10 });\n\t/**\n\t * The viewer's Linear user id: the caller's resolved `userId` when it has one, else the viewer query, shared per\n\t * token. A tracker read hands each team the id of the team's own resource, which Linear's team descriptors don't\n\t * name, so without sharing every team read (and a search's fallback) would ask for the viewer again.\n\t */\n\tprivate getViewerId(\n\t\tsession: ProviderAuthenticationSession,\n\t\toptions: IssuesForProjectOptions,\n\t): Promise<string | undefined> {\n\t\tif (options.userId) return Promise.resolve(options.userId);\n\n\t\treturn this._viewerIds.getOrCreate(\n\t\t\tsession.accessToken,\n\t\t\tasync () => {\n\t\t\t\tconst api = await this.getProvidersApi();\n\t\t\t\treturn (await api.getLinearCurrentUser(toTokenWithInfo(this.id, session)))?.id;\n\t\t\t},\n\t\t\t// Only a resolved id is worth keeping; an unresolved viewer is asked for again next time, as is a failure.\n\t\t\t{ evictWhen: id => id == null },\n\t\t);\n\t}\n\n\t/**\n\t * Follows `getIssues`' cursor up to {@link maxPagesPerRequest}. `truncated` is set when that backstop stopped\n\t * the drain with more pages still available, when the provider stalled its cursor or flagged its paging as\n\t * truncated, or when a page after the first failed, which is recorded at `failureScope` while the prefix is\n\t * kept. A failure before any issue was kept throws, so the caller sees a hard error rather than an empty success.\n\t */\n\tprivate async drainIssues(\n\t\tsession: ProviderAuthenticationSession,\n\t\tfilter: { teams: string[]; projects?: string[]; states?: GitIssueState[] } & Partial<LinearViewerScope>,\n\t\tsort: IssuesForProjectOptions['sort'],\n\t\tfailureScope: CollectionScopeFailure['scope'],\n\t): Promise<{ issues: IssueShape[]; truncated: boolean; metadata?: CollectionMetadata }> {\n\t\tconst api = await this.getProvidersApi();\n\t\tconst assignees = filter.assignees?.length ? filter.assignees : undefined;\n\t\tconst syncedCreators = filter.githubSyncedCreators?.length ? filter.githubSyncedCreators : undefined;\n\t\tlet cursor: string | undefined;\n\t\tlet hasMore: boolean;\n\t\tlet requestCount = 0;\n\t\tlet truncated = false;\n\t\tlet collectionMetadata: CollectionMetadata | undefined;\n\t\tconst issues: IssueShape[] = [];\n\t\tdo {\n\t\t\tlet result: Awaited<ReturnType<typeof api.getLinearIssues>>;\n\t\t\ttry {\n\t\t\t\tresult = await api.getLinearIssues(toTokenWithInfo(this.id, session), filter, {\n\t\t\t\t\tcursor: cursor,\n\t\t\t\t\tsort: sort,\n\t\t\t\t});\n\t\t\t} catch (ex) {\n\t\t\t\t// Keyed on what was kept, not on the page: provider-apis can empty a page it filters after the query\n\t\t\t\t// (synced-creator reads) and still report more, and a drain that kept nothing has nothing to serve, so\n\t\t\t\t// its caller retries it rather than recording an empty prefix as read.\n\t\t\t\tif (issues.length === 0) throw ex;\n\n\t\t\t\ttruncated = true;\n\t\t\t\tcollectionMetadata = mergeCollectionMetadata(collectionMetadata, {\n\t\t\t\t\tcompleteness: 'partial',\n\t\t\t\t\tfailures: [toCollectionScopeFailure(failureScope, ex)],\n\t\t\t\t});\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\trequestCount += 1;\n\t\t\thasMore = result.paging?.more ?? false;\n\t\t\tconst nextCursor = result.paging?.cursor;\n\t\t\ttruncated ||= result.paging?.truncated === true;\n\t\t\tcollectionMetadata = mergeCollectionMetadata(collectionMetadata, result.metadata);\n\t\t\tfor (const issue of result.values) {\n\t\t\t\tconst shape = toIssueShape(issue, this, { projection: 'project' });\n\t\t\t\t// The read already scopes to the assignees and to the synced issues the creators filed, leaving out the\n\t\t\t\t// issues with no GitHub sync link (`[]`) and keeping one whose link list Linear failed to resolve\n\t\t\t\t// (absent). Checking again keeps another user's issue, or an unsynced one only its GitHub attachment\n\t\t\t\t// matched, out of \"my issues\" should the provider ever return one.\n\t\t\t\tif (\n\t\t\t\t\tshape != null &&\n\t\t\t\t\t(assignees == null ||\n\t\t\t\t\t\tshape.assignees?.some(a => assignees.includes(a.id)) ||\n\t\t\t\t\t\t(syncedCreators != null &&\n\t\t\t\t\t\t\tshape.author != null &&\n\t\t\t\t\t\t\tsyncedCreators.includes(shape.author.id) &&\n\t\t\t\t\t\t\tshape.syncedWith?.length !== 0))\n\t\t\t\t) {\n\t\t\t\t\tissues.push(shape);\n\t\t\t\t}\n\t\t\t}\n\t\t\t// The provider claims more but returns no advancing cursor: we can't continue without re-reading the\n\t\t\t// same page, so the drain is incomplete — flag it rather than silently stopping.\n\t\t\tif (hasMore && (nextCursor == null || nextCursor === cursor)) {\n\t\t\t\ttruncated = true;\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcursor = nextCursor;\n\t\t\tif (hasMore && requestCount >= maxPagesPerRequest) {\n\t\t\t\ttruncated = true;\n\t\t\t}\n\t\t} while (requestCount < maxPagesPerRequest && hasMore);\n\n\t\treturn { issues: issues, truncated: truncated, metadata: collectionMetadata };\n\t}\n\n\toverride get id(): IssuesCloudHostIntegrationId.Linear {\n\t\treturn IssuesCloudHostIntegrationId.Linear;\n\t}\n\tprotected override get key(): 'linear' {\n\t\treturn 'linear';\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\tprotected override async searchProviderMyIssues(\n\t\tsession: ProviderAuthenticationSession,\n\t\tresources?: ResourceDescriptor[],\n\t\tcancellation?: AbortSignal,\n\t): Promise<IssueShape[] | undefined> {\n\t\treturn (await this.searchProviderMyIssuesWithTruncation(session, resources, cancellation))?.values;\n\t}\n\n\t/**\n\t * Account-wide \"my issues\" for Linear, drained to exhaustion and reporting whether it got there.\n\t *\n\t * The SDK read is one server-ordered query over an `or` filter across the four relationships (assigned,\n\t * created, named in an issue's content, named in a comment), so each page is 100 issues the caller has not\n\t * seen and the pages are ordered as one sequence. Draining it is therefore just following the cursor.\n\t *\n\t * Overridden rather than left to the base default because that default hardcodes `truncated: false`, and a\n\t * bounded drain that stops early is exactly the case a caller must be able to see. Three things end the\n\t * drain, and only one of them is completion:\n\t *\n\t * - the provider says there is no next page — complete;\n\t * - the backstop is reached — `truncated`, because issues beyond it exist and were not read;\n\t * - the provider claims a next page but hands back a cursor that does not advance — also `truncated`, since\n\t * the read cannot continue and the remainder is unreachable rather than absent.\n\t *\n\t * Cancellation is deliberately NOT truncation: the caller asked for the read to stop, so the partial list is\n\t * what it asked for, and flagging it would surface an incompleteness warning for a user action.\n\t */\n\tprotected override async searchProviderMyIssuesWithTruncation(\n\t\tsession: ProviderAuthenticationSession,\n\t\tresources?: ResourceDescriptor[],\n\t\tcancellation?: AbortSignal,\n\t\toptions?: SearchMyIssuesOptions,\n\t): Promise<AccountWideIssuesResult | undefined> {\n\t\tif (resources != null) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst api = await this.getProvidersApi();\n\t\tconst states = toProviderIssueStates(options?.state);\n\t\tlet cursor = undefined;\n\t\t// Starts false so an immediate cancellation, which leaves the loop before the first response, reads as\n\t\t// \"no more pages known\" rather than as an unfinished drain.\n\t\tlet hasMore = false;\n\t\tlet requestCount = 0;\n\t\tlet truncated = false;\n\t\tconst issues = [];\n\t\ttry {\n\t\t\tdo {\n\t\t\t\tif (cancellation?.aborted) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tconst result = await api.getIssuesForCurrentUser(toTokenWithInfo(this.id, session), {\n\t\t\t\t\tcursor: cursor,\n\t\t\t\t\tstates: states,\n\t\t\t\t\tsort: options?.sort,\n\t\t\t\t});\n\t\t\t\trequestCount += 1;\n\t\t\t\thasMore = result.paging?.more ?? false;\n\t\t\t\tconst nextCursor = result.paging?.cursor;\n\n\t\t\t\t// Keep this page before deciding whether to continue: the request is already paid for, so\n\t\t\t\t// dropping its rows would lose real results to save nothing.\n\t\t\t\tconst formattedIssues = result.values\n\t\t\t\t\t.map(issue => toIssueShape(issue, this, { projection: 'account' }))\n\t\t\t\t\t.filter((result): result is IssueShape => result != null);\n\t\t\t\tif (formattedIssues.length > 0) {\n\t\t\t\t\tissues.push(...formattedIssues);\n\t\t\t\t}\n\n\t\t\t\t// The provider claims more but hands back no advancing cursor: continuing would re-read the page\n\t\t\t\t// just returned. `ProvidersApi.getPagedResult` already normalizes this into `more: false`, so\n\t\t\t\t// this is a backstop for if that ever stops holding rather than a case seen today -- but the rest\n\t\t\t\t// of the account is unreachable either way, which is what `truncated` says.\n\t\t\t\tif (hasMore && (nextCursor == null || nextCursor === cursor)) {\n\t\t\t\t\ttruncated = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tcursor = nextCursor;\n\t\t\t} while (requestCount < maxAccountWidePagesPerRequest && hasMore);\n\n\t\t\t// Ran out of budget with pages still to come.\n\t\t\tif (hasMore && requestCount >= maxAccountWidePagesPerRequest) {\n\t\t\t\ttruncated = true;\n\t\t\t}\n\t\t} catch (ex) {\n\t\t\tif (issues.length === 0) {\n\t\t\t\tthrow ex;\n\t\t\t}\n\n\t\t\t// Kept what was already fetched, so the list is real but short of the account.\n\t\t\ttruncated = true;\n\t\t\tLogger.error(ex, 'searchProviderMyIssues');\n\t\t}\n\t\treturn { values: issues, truncated: truncated };\n\t}\n\tprotected override async getProviderLinkedIssueOrPullRequest(\n\t\tsession: ProviderAuthenticationSession,\n\t\tresource: ResourceDescriptor,\n\t\t{ key }: { id: string; key: string },\n\t\t_type: undefined | IssueOrPullRequestType,\n\t): Promise<IssueOrPullRequest | undefined> {\n\t\tconst issue = await this.getRawProviderIssue(session, resource, key);\n\t\tconst autolinkableIssue: ProviderIssue | undefined = issue && {\n\t\t\t...issue,\n\t\t\turl: this.getIssueAutolinkLikeUrl(issue),\n\t\t};\n\t\treturn autolinkableIssue && toIssueShape(autolinkableIssue, this, { projection: 'point' });\n\t}\n\tprotected override async getProviderIssue(\n\t\tsession: ProviderAuthenticationSession,\n\t\tresource: ResourceDescriptor,\n\t\tid: string,\n\t): Promise<Issue | undefined> {\n\t\tconst result = await this.getRawProviderIssue(session, resource, id);\n\t\treturn result && fromProviderIssue(result, this, { projection: 'point' });\n\t}\n\n\tprotected override async getProviderIssueByResourceId(\n\t\tsession: ProviderAuthenticationSession,\n\t\tresourceId: string,\n\t\tid: string,\n\t\t_resourceUrl: string | undefined,\n\t): Promise<Issue | undefined> {\n\t\tconst api = await this.getProvidersApi();\n\t\tconst result = await api.getIssue(toTokenWithInfo(this.id, session), {\n\t\t\tresourceId: resourceId,\n\t\t\tnumber: id,\n\t\t});\n\t\treturn result && fromProviderIssue(result, this, { projection: 'batch' });\n\t}\n\n\t/**\n\t * The cheap check behind the batch issue read's etags: one `issues` query per team and\n\t * {@link linearIssuesEtagMaxNumbers} distinct numbers, where {@link getProviderIssueByResourceId} sends one request\n\t * per issue. A request that throws rejects only its own targets' slots, with its error classified as the full\n\t * read's would be.\n\t *\n\t * Never proves an absence. The query filters by the team's CURRENT key and asks for archived issues too, but the\n\t * full read's `issue(id:)` may also resolve an identifier the issue no longer carries (its team was renamed, or it\n\t * moved to another team), so an issue the query leaves out may still exist. Its target's slot is rejected, as is a\n\t * target whose identifier isn't a team key and a number, so the full read decides. When no target was answered and\n\t * nothing failed, the check declines instead, so a batch of only such targets costs a full read, not a failure.\n\t */\n\tprotected override async getProviderIssuesEtagFieldsByResourceId(\n\t\tsession: ProviderAuthenticationSession,\n\t\ttargets: readonly { resourceId: string; identifier: string; resourceUrl?: string }[],\n\t): Promise<PromiseSettledResult<IssueEtagFields | undefined>[] | undefined> {\n\t\tconst slots = new Array<PromiseSettledResult<IssueEtagFields | undefined>>(targets.length);\n\t\tlet answered = false;\n\t\tlet failed = false;\n\n\t\t// Each workspace and team's distinct numbers, with the targets asking for each.\n\t\tconst byTeam = new Map<string, { teamKey: string; numbers: Map<number, number[]> }>();\n\t\tfor (const [index, target] of targets.entries()) {\n\t\t\tconst match = linearIdentifier.exec(target.identifier);\n\t\t\tconst number = match != null ? Number(match[2]) : Number.NaN;\n\t\t\t// Only a number written as Linear writes it, so `ENG-012` never answers for `ENG-12`.\n\t\t\tif (match == null || !Number.isSafeInteger(number) || String(number) !== match[2]) {\n\t\t\t\tslots[index] = {\n\t\t\t\t\tstatus: 'rejected',\n\t\t\t\t\treason: new Error(`Not a Linear issue identifier: ${target.identifier}`),\n\t\t\t\t};\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst teamKey = match[1].toUpperCase();\n\t\t\tconst groupKey = `${target.resourceId}\\n${teamKey}`;\n\t\t\tlet group = byTeam.get(groupKey);\n\t\t\tif (group == null) {\n\t\t\t\tgroup = { teamKey: teamKey, numbers: new Map() };\n\t\t\t\tbyTeam.set(groupKey, group);\n\t\t\t}\n\n\t\t\tlet indices = group.numbers.get(number);\n\t\t\tif (indices == null) {\n\t\t\t\tindices = [];\n\t\t\t\tgroup.numbers.set(number, indices);\n\t\t\t}\n\t\t\tindices.push(index);\n\t\t}\n\n\t\tconst requests = [...byTeam.values()].flatMap(({ teamKey, numbers }) =>\n\t\t\tchunk([...numbers], linearIssuesEtagMaxNumbers).map(entries => ({ teamKey: teamKey, entries: entries })),\n\t\t);\n\t\tif (requests.length) {\n\t\t\tconst api = await this.getProvidersApi();\n\t\t\tconst tokenWithInfo = toTokenWithInfo(this.id, session);\n\t\t\tconst answers = await mapSettledBounded(requests, providerFanOutConcurrency, r =>\n\t\t\t\tapi.getLinearIssuesEtagFields(\n\t\t\t\t\ttokenWithInfo,\n\t\t\t\t\tr.teamKey,\n\t\t\t\t\tr.entries.map(([number]) => number),\n\t\t\t\t),\n\t\t\t);\n\n\t\t\tfor (const [i, answer] of answers.entries()) {\n\t\t\t\tconst { teamKey, entries } = requests[i];\n\t\t\t\tif (answer.status === 'rejected') {\n\t\t\t\t\tfailed = true;\n\t\t\t\t\tfor (const [, indices] of entries) {\n\t\t\t\t\t\tfor (const index of indices) {\n\t\t\t\t\t\t\tslots[index] = answer;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\t// By number, never by position: Linear returns the issues in its own order, and only the ones it found.\n\t\t\t\tconst byNumber = new Map<number, LinearIssueEtagNode>();\n\t\t\t\tfor (const issue of answer.value) {\n\t\t\t\t\tbyNumber.set(issue.number, issue);\n\t\t\t\t}\n\n\t\t\t\tfor (const [number, indices] of entries) {\n\t\t\t\t\tconst issue = byNumber.get(number);\n\t\t\t\t\tlet slot: PromiseSettledResult<IssueEtagFields | undefined>;\n\t\t\t\t\tif (issue == null) {\n\t\t\t\t\t\tslot = { status: 'rejected', reason: new Error(`Linear did not return ${teamKey}-${number}`) };\n\t\t\t\t\t} else {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tslot = { status: 'fulfilled', value: toLinearIssueEtagFields(issue) };\n\t\t\t\t\t\t\tanswered = true;\n\t\t\t\t\t\t} catch (ex) {\n\t\t\t\t\t\t\tslot = { status: 'rejected', reason: ex };\n\t\t\t\t\t\t\tfailed = true;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tfor (const index of indices) {\n\t\t\t\t\t\tslots[index] = slot;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn answered || failed ? slots : undefined;\n\t}\n\n\tprivate async getRawProviderIssue(\n\t\tsession: ProviderAuthenticationSession,\n\t\tresource: ResourceDescriptor,\n\t\tid: string,\n\t): Promise<ProviderIssue | undefined> {\n\t\tconst api = await this.getProvidersApi();\n\t\tif (!isIssueResourceDescriptor(resource)) {\n\t\t\tLogger.error(undefined, 'getProviderIssue: resource is not an IssueResourceDescriptor');\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn api.getIssue(toTokenWithInfo(this.id, session), {\n\t\t\tresourceId: resource.id,\n\t\t\tnumber: id,\n\t\t});\n\t}\n\tprivate getIssueAutolinkLikeUrl(issue: ProviderIssue): string | null {\n\t\tconst url = issue.url;\n\t\tif (url == null) return null;\n\n\t\tconst lastSegment = url.split('/').pop();\n\t\tif (!lastSegment || issue.number === lastSegment) {\n\t\t\treturn url;\n\t\t}\n\t\treturn url.substring(0, url.length - lastSegment.length - 1);\n\t}\n}\n\nfunction getTeamAutolinks(\n\torganization: LinearOrganizationDescriptor,\n\tteams: readonly LinearTeamDescriptor[],\n): AutolinkReference[] {\n\treturn teams.flatMap(team =>\n\t\tcreateIssueAutolinkReferences(team.key, `${organization.url}/issue/${team.key}-<num>`, organization),\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA+CA,MAAM,WAAW,kBAAA;AACjB,MAAM,eAAe,OAAO,OAAO;CAAE,IAAI,SAAS;CAAI,QAAQ,SAAS;AAAO,CAAC;AAC/E,MAAM,qBAAqB;;;;;;;;;;;;;;;AAe3B,MAAM,gCAAgC;AACtC,MAAM,8BAA8B;;AAEpC,MAAM,2BAA2B;;AAEjC,MAAM,mBAAmB;;AAEzB,MAAM,mBAAmB;;;;;;;;;AAuBzB,SAAS,YAAY,UAAkB,SAAuD;CAC7F,OAAO,SAAS,SAAA,UAA6B,IAC1C,EAAE,WAAW,CAAC,QAAQ,EAAE,IACxB;EAAE,WAAW,CAAC,QAAQ;EAAG,sBAAsB,CAAC,QAAQ;CAAE;AAC9D;AAEA,IAAa,oBAAb,cAAuC,kBAAuD;;;;;;;CAO7F,6BAA8B,IAAI,IAGhC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CAAC,eAAe,MAAM,WAAW,aACpC,OAAO;EAER,OAAO,IAAI,UAAU,GAAG,IAAI,SAAS,YAAY,SAAS,CAAC;CAC5D;AACD;AAvsBE,WAAA,CAAA,MAAM,CAAA,GAAA,kBAAA,WAAA,8BAAA,IAAA;AAysBR,SAAS,iBACR,cACA,OACsB;CACtB,OAAO,MAAM,SAAQ,SACpB,8BAA8B,KAAK,KAAK,GAAG,aAAa,IAAI,SAAS,KAAK,IAAI,SAAS,YAAY,CACpG;AACD"}
@@ -16,14 +16,6 @@ export declare function isAutolinkSetExpired(set: {
16
16
  builtAt: number;
17
17
  complete: boolean;
18
18
  }): boolean;
19
- /**
20
- * Whether a kept autolink set is empty and incomplete: the fallback of a failing build that held none, built from no
21
- * list, so it stands for no set to any set built from the lists (#6184).
22
- */
23
- export declare function isEmptyAutolinkFallback(set: {
24
- autolinks: readonly unknown[];
25
- complete: boolean;
26
- }): boolean;
27
19
  /**
28
20
  * A per-key cache of discovery results that expires entries after {@link discoveryCacheTtl} and can be dropped
29
21
  * wholesale when the connection is re-synced.
@@ -59,12 +51,14 @@ export declare class DiscoveryCache<V> {
59
51
  * Stores `value` unless the cache was cleared since `generation` was taken, or, for a `read` from
60
52
  * {@link startRead}, a read started after it stored `key`. `storedAt` backdates an entry seeded from persisted
61
53
  * storage, so it expires on the schedule of the read that produced it rather than of the seeding. Returns `false`
62
- * when refused, `'unchanged'` when `value` equals the one it replaces, expired or not, and `'changed'` otherwise.
54
+ * when refused, `'unchanged'` when value and completeness match, expired or not, and `'changed'` otherwise.
55
+ * Incomplete entries are retained by `peek`, but never satisfy `get`.
63
56
  */
64
57
  set(key: string, value: V, options?: {
65
58
  generation?: number;
66
59
  read?: number;
67
60
  storedAt?: number;
61
+ complete?: boolean;
68
62
  }): 'changed' | 'unchanged' | false;
69
63
  delete(key: string): void;
70
64
  clear(): void;