@cvr/linear 0.4.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/lib/errors.ts CHANGED
@@ -1,15 +1,15 @@
1
1
  import { Schema } from "effect";
2
2
 
3
- export class ConfigError extends Schema.TaggedErrorClass<ConfigError>()("ConfigError", {
3
+ export class ConfigError extends Schema.TaggedError<ConfigError>()("ConfigError", {
4
4
  message: Schema.String,
5
5
  }) {}
6
6
 
7
- export class LinearApiError extends Schema.TaggedErrorClass<LinearApiError>()("LinearApiError", {
7
+ export class LinearApiError extends Schema.TaggedError<LinearApiError>()("LinearApiError", {
8
8
  message: Schema.String,
9
9
  code: Schema.optional(Schema.String),
10
10
  }) {}
11
11
 
12
- export class TokenNotFoundError extends Schema.TaggedErrorClass<TokenNotFoundError>()(
12
+ export class TokenNotFoundError extends Schema.TaggedError<TokenNotFoundError>()(
13
13
  "TokenNotFoundError",
14
14
  {
15
15
  message: Schema.String,
@@ -20,22 +20,26 @@ export class TokenNotFoundError extends Schema.TaggedErrorClass<TokenNotFoundErr
20
20
  });
21
21
  }
22
22
 
23
- export class InvalidTokenError extends Schema.TaggedErrorClass<InvalidTokenError>()(
23
+ export class InvalidTokenError extends Schema.TaggedError<InvalidTokenError>()(
24
24
  "InvalidTokenError",
25
25
  {
26
26
  message: Schema.String,
27
27
  },
28
28
  ) {}
29
29
 
30
- export class NoIssuesError extends Schema.TaggedErrorClass<NoIssuesError>()("NoIssuesError", {
30
+ export class NoIssuesError extends Schema.TaggedError<NoIssuesError>()("NoIssuesError", {
31
31
  message: Schema.String,
32
32
  }) {
33
33
  static readonly default = NoIssuesError.make({ message: "No issues found to select from." });
34
34
  }
35
35
 
36
- export class InvalidInputError extends Schema.TaggedErrorClass<InvalidInputError>()(
36
+ export class InvalidInputError extends Schema.TaggedError<InvalidInputError>()(
37
37
  "InvalidInputError",
38
38
  {
39
39
  message: Schema.String,
40
40
  },
41
41
  ) {}
42
+
43
+ export class FileWriteError extends Schema.TaggedError<FileWriteError>()("FileWriteError", {
44
+ message: Schema.String,
45
+ }) {}
package/src/lib/flags.ts CHANGED
@@ -1,5 +1,17 @@
1
- import { Flag } from "effect/unstable/cli";
1
+ import { Flag } from "effect/cli";
2
2
 
3
- export const jsonFlag = Flag.boolean("json").pipe(
3
+ export const jsonFlag = Flag.Boolean("json").pipe(
4
+ Flag.withDefault(false),
4
5
  Flag.withDescription("Emit stable JSON for scripts and agents"),
5
6
  );
7
+
8
+ export const outputDirFlag = Flag.String("output-dir").pipe(
9
+ Flag.withAlias("o"),
10
+ Flag.withDefault("."),
11
+ Flag.withDescription("Directory to save files in; created when missing"),
12
+ );
13
+
14
+ export const overwriteFlag = Flag.Boolean("overwrite").pipe(
15
+ Flag.withDefault(false),
16
+ Flag.withDescription("Replace files that already exist in the output directory"),
17
+ );
package/src/main.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Command } from "effect/unstable/cli";
1
+ import { Command } from "effect/cli";
2
2
  import { BunRuntime, BunServices } from "@effect/platform-bun";
3
3
  import { Console, Effect, Layer } from "effect";
4
4
  import packageJson from "../package.json" with { type: "json" };
@@ -29,6 +29,7 @@ cli.pipe(
29
29
  ),
30
30
  Effect.tapErrorTag("NoIssuesError", (e) => Console.error(e.message)),
31
31
  Effect.tapErrorTag("InvalidInputError", (e) => Console.error(`Invalid input: ${e.message}`)),
32
+ Effect.tapErrorTag("FileWriteError", (e) => Console.error(`File Error: ${e.message}`)),
32
33
  Effect.provide(MainLayer),
33
34
  BunRuntime.runMain({ disableErrorReporting: true }),
34
35
  );
@@ -23,8 +23,8 @@ export class ConfigService extends Context.Service<
23
23
  Effect.gen(function* () {
24
24
  const fs = yield* FileSystem.FileSystem;
25
25
  const path = yield* Path.Path;
26
- const homeDir = yield* Config.string("HOME").pipe(Config.withDefault(""));
27
- const envToken = yield* Config.redacted("LINEAR_API_KEY").pipe(Config.option);
26
+ const homeDir = yield* Config.String("HOME").pipe(Config.withDefault(""));
27
+ const envToken = yield* Config.Redacted("LINEAR_API_KEY").pipe(Config.option);
28
28
  const configDir = path.join(homeDir, ".config", "linear");
29
29
  const tokenPath = path.join(configDir, "token");
30
30
  const configPath = path.join(configDir, "config.toml");
@@ -82,10 +82,7 @@ export class ConfigService extends Context.Service<
82
82
 
83
83
  static readonly layerTest = (options?: { token?: string; config?: LinearConfig }) =>
84
84
  Layer.succeed(ConfigService, {
85
- getToken:
86
- options?.token === undefined
87
- ? Effect.fail(TokenNotFoundError.default)
88
- : Effect.succeed(Redacted.make(options.token)),
85
+ getToken: makeTestGetToken(options?.token),
89
86
  saveToken: () => Effect.void,
90
87
  getConfig: Effect.succeed(options?.config ?? new LinearConfig({})),
91
88
  });
@@ -99,21 +96,36 @@ const readTokenFile = (
99
96
  Effect.mapError((error) =>
100
97
  ConfigError.make({ message: `Failed to inspect token file: ${error}` }),
101
98
  ),
102
- Effect.flatMap((exists) =>
103
- exists
104
- ? fs.readFileString(tokenPath).pipe(
105
- Effect.mapError((error) =>
106
- ConfigError.make({ message: `Failed to read token file: ${error}` }),
107
- ),
108
- Effect.map((token) => token.trim()),
109
- Effect.map((token) =>
110
- token.length === 0 ? Option.none() : Option.some(Redacted.make(token)),
111
- ),
112
- )
113
- : Effect.succeed(Option.none()),
114
- ),
99
+ Effect.flatMap((exists) => {
100
+ if (!exists) {
101
+ return Effect.succeedNone;
102
+ }
103
+ return fs.readFileString(tokenPath).pipe(
104
+ Effect.mapError((error) =>
105
+ ConfigError.make({ message: `Failed to read token file: ${error}` }),
106
+ ),
107
+ Effect.map((token) => token.trim()),
108
+ Effect.map(toOptionalToken),
109
+ );
110
+ }),
115
111
  );
116
112
 
113
+ const toOptionalToken = (token: string): Option.Option<Redacted.Redacted<string>> => {
114
+ if (token.length === 0) {
115
+ return Option.none();
116
+ }
117
+ return Option.some(Redacted.make(token));
118
+ };
119
+
120
+ const makeTestGetToken = (
121
+ token: string | undefined,
122
+ ): Effect.Effect<Redacted.Redacted<string>, TokenNotFoundError> => {
123
+ if (token === undefined) {
124
+ return Effect.fail(TokenNotFoundError.default);
125
+ }
126
+ return Effect.succeed(Redacted.make(token));
127
+ };
128
+
117
129
  const readConfigFile = Effect.fn("ConfigService.readConfigFile")(function* (
118
130
  fs: Context.Service.Shape<typeof FileSystem.FileSystem>,
119
131
  filePath: string,
@@ -1,21 +1,27 @@
1
1
  import { LinearClient } from "@linear/sdk";
2
- import type { Issue, IssueRelation as SdkIssueRelation, User } from "@linear/sdk";
2
+ import type { Comment, Issue, IssueRelation as SdkIssueRelation, User } from "@linear/sdk";
3
3
  import { Context, Effect, Layer, Redacted } from "effect";
4
4
  import type {
5
5
  CreateIssueInput,
6
6
  CreatedIssue,
7
+ DownloadedFile,
8
+ IssueComment,
7
9
  IssueDetails,
8
10
  IssueDetailsOptions,
9
11
  IssueReference,
12
+ IssueRelation,
10
13
  IssueSelector,
11
14
  IssueSummary,
12
15
  Project,
13
16
  StartedIssue,
14
17
  Team,
18
+ UploadUrl,
15
19
  Viewer,
16
20
  } from "../domain/Linear.js";
21
+ import { fileNameFromContentDisposition } from "../domain/Files.js";
17
22
  import type { ConfigError, TokenNotFoundError } from "../lib/errors.js";
18
23
  import { InvalidInputError, InvalidTokenError, LinearApiError } from "../lib/errors.js";
24
+ import { succeedUndefined } from "../lib/effect.js";
19
25
  import { ConfigService } from "./Config.js";
20
26
 
21
27
  type LinearError = ConfigError | InvalidTokenError | LinearApiError | TokenNotFoundError;
@@ -46,6 +52,7 @@ interface LinearOperations {
46
52
  query: string,
47
53
  variables: Readonly<Record<string, unknown>>,
48
54
  ) => Effect.Effect<unknown, LinearError>;
55
+ readonly downloadFile: (url: UploadUrl) => Effect.Effect<DownloadedFile, LinearError>;
49
56
  }
50
57
 
51
58
  export class LinearService extends Context.Service<LinearService, LinearOperations>()(
@@ -67,7 +74,7 @@ export class LinearService extends Context.Service<LinearService, LinearOperatio
67
74
  getClient.pipe(
68
75
  Effect.flatMap((client) =>
69
76
  Effect.tryPromise({
70
- try: () => Promise.resolve(operation(client)),
77
+ try: () => operation(client),
71
78
  catch: toLinearError,
72
79
  }),
73
80
  ),
@@ -110,8 +117,7 @@ export class LinearService extends Context.Service<LinearService, LinearOperatio
110
117
  const connection = yield* resolveLinearFetch(
111
118
  viewer.assignedIssues({
112
119
  first: filter?.limit ?? 50,
113
- filter:
114
- filter?.state === undefined ? undefined : { state: { type: { eq: filter.state } } },
120
+ filter: toStateFilter(filter?.state),
115
121
  }),
116
122
  );
117
123
  return yield* Effect.forEach(connection.nodes, toIssueSummary, { concurrency: 4 });
@@ -133,67 +139,15 @@ export class LinearService extends Context.Service<LinearService, LinearOperatio
133
139
  loadConnection(() => issue.labels()),
134
140
  ]);
135
141
 
136
- const children = options.children
137
- ? yield* loadConnection(() => issue.children())
138
- : undefined;
139
- const comments = options.comments
140
- ? yield* loadConnection(() => issue.comments())
141
- : undefined;
142
- const outbound = options.relations
143
- ? yield* loadConnection(() => issue.relations())
144
- : undefined;
145
- const inbound = options.relations
146
- ? yield* loadConnection(() => issue.inverseRelations())
147
- : undefined;
148
-
149
- const detailedComments =
150
- comments === undefined
151
- ? undefined
152
- : yield* Effect.forEach(
153
- comments,
154
- (comment) =>
155
- resolveOptionalFetch(comment.user).pipe(
156
- Effect.map((author) => ({
157
- id: comment.id,
158
- body: comment.body,
159
- createdAt: comment.createdAt.toISOString(),
160
- url: comment.url,
161
- author:
162
- author === undefined ? undefined : { id: author.id, name: author.name },
163
- })),
164
- ),
165
- { concurrency: 4 },
166
- );
167
-
168
- const relations =
169
- outbound === undefined || inbound === undefined
170
- ? undefined
171
- : yield* Effect.forEach(
172
- outbound
173
- .map<{
174
- readonly relation: SdkIssueRelation;
175
- readonly direction: "outbound" | "inbound";
176
- }>((relation) => ({ relation, direction: "outbound" }))
177
- .concat(inbound.map((relation) => ({ relation, direction: "inbound" }))),
178
- Effect.fn("LinearService.resolveRelation")(function* ({ direction, relation }) {
179
- const related = yield* resolveOptionalFetch(
180
- direction === "outbound" ? relation.relatedIssue : relation.issue,
181
- );
182
- return related === undefined
183
- ? undefined
184
- : {
185
- id: relation.id,
186
- type: relation.type,
187
- direction,
188
- issue: toIssueReference(related),
189
- };
190
- }),
191
- { concurrency: 4 },
192
- ).pipe(
193
- Effect.map((items) =>
194
- items.filter((item): item is NonNullable<typeof item> => item !== undefined),
195
- ),
196
- );
142
+ const children = yield* loadConnectionWhen(options.children, () => issue.children());
143
+ const comments = yield* loadConnectionWhen(options.comments, () => issue.comments());
144
+ const outbound = yield* loadConnectionWhen(options.relations, () => issue.relations());
145
+ const inbound = yield* loadConnectionWhen(options.relations, () =>
146
+ issue.inverseRelations(),
147
+ );
148
+
149
+ const detailedComments = yield* toDetailedComments(comments);
150
+ const relations = yield* toRelations(outbound, inbound);
197
151
 
198
152
  return {
199
153
  id: summary.id,
@@ -204,16 +158,18 @@ export class LinearService extends Context.Service<LinearService, LinearOperatio
204
158
  priority: summary.priority,
205
159
  state: summary.state,
206
160
  description: issue.description ?? undefined,
207
- team: team === undefined ? undefined : { id: team.id, key: team.key, name: team.name },
208
- assignee:
209
- assignee === undefined
210
- ? undefined
211
- : { id: assignee.id, name: assignee.name, email: assignee.email },
212
- project:
213
- project === undefined
214
- ? undefined
215
- : { id: project.id, name: project.name, url: project.url },
216
- parent: parent === undefined ? undefined : toIssueReference(parent),
161
+ team: mapDefined(team, (value) => ({ id: value.id, key: value.key, name: value.name })),
162
+ assignee: mapDefined(assignee, (value) => ({
163
+ id: value.id,
164
+ name: value.name,
165
+ email: value.email,
166
+ })),
167
+ project: mapDefined(project, (value) => ({
168
+ id: value.id,
169
+ name: value.name,
170
+ url: value.url,
171
+ })),
172
+ parent: mapDefined(parent, toIssueReference),
217
173
  labels: labels.map((label) => ({ id: label.id, name: label.name })),
218
174
  children: children?.map(toIssueReference),
219
175
  comments: detailedComments,
@@ -251,11 +207,20 @@ export class LinearService extends Context.Service<LinearService, LinearOperatio
251
207
  };
252
208
  });
253
209
 
210
+ const resolveParentId = Effect.fn("LinearService.resolveParentId")(function* (
211
+ parent: IssueSelector | undefined,
212
+ ) {
213
+ if (parent === undefined) {
214
+ return undefined;
215
+ }
216
+ const parentIssue = yield* getIssue(parent);
217
+ return parentIssue.id;
218
+ });
219
+
254
220
  const createIssue = Effect.fn("LinearService.createIssue")(function* (
255
221
  input: CreateIssueInput,
256
222
  ) {
257
- const parentId =
258
- input.parent === undefined ? undefined : (yield* getIssue(input.parent)).id;
223
+ const parentId = yield* resolveParentId(input.parent);
259
224
  const payload = yield* withClient((client) =>
260
225
  client.createIssue({
261
226
  title: input.title,
@@ -278,9 +243,12 @@ export class LinearService extends Context.Service<LinearService, LinearOperatio
278
243
  ) {
279
244
  const payload = yield* withClient((client) => client.createComment({ issueId, body }));
280
245
  const comment = yield* resolveOptionalFetch(payload.comment);
281
- return comment === undefined
282
- ? yield* LinearApiError.make({ message: "Linear did not return the created comment" })
283
- : { id: comment.id, url: comment.url };
246
+ if (comment === undefined) {
247
+ return yield* LinearApiError.make({
248
+ message: "Linear did not return the created comment",
249
+ });
250
+ }
251
+ return { id: comment.id, url: comment.url };
284
252
  });
285
253
 
286
254
  const rawQuery = Effect.fn("LinearService.rawQuery")(function* (
@@ -293,6 +261,11 @@ export class LinearService extends Context.Service<LinearService, LinearOperatio
293
261
  return response.data;
294
262
  });
295
263
 
264
+ const downloadFile = Effect.fn("LinearService.downloadFile")(function* (url: UploadUrl) {
265
+ const token = yield* config.getToken;
266
+ return yield* fetchUpload(url, token);
267
+ });
268
+
296
269
  return LinearService.of({
297
270
  authenticate,
298
271
  getViewer,
@@ -304,6 +277,7 @@ export class LinearService extends Context.Service<LinearService, LinearOperatio
304
277
  createIssue,
305
278
  createComment,
306
279
  rawQuery,
280
+ downloadFile,
307
281
  });
308
282
  }),
309
283
  );
@@ -360,6 +334,7 @@ export class LinearService extends Context.Service<LinearService, LinearOperatio
360
334
  createComment: () =>
361
335
  Effect.succeed({ id: "comment", url: "https://linear.app/comment/comment" }),
362
336
  rawQuery: () => Effect.succeed({}),
337
+ downloadFile: () => Effect.succeed({ bytes: new Uint8Array() }),
363
338
  } satisfies LinearOperations,
364
339
  overrides,
365
340
  ),
@@ -368,9 +343,78 @@ export class LinearService extends Context.Service<LinearService, LinearOperatio
368
343
 
369
344
  const toLinearError = (error: unknown): InvalidTokenError | LinearApiError => {
370
345
  const message = String(error);
371
- return message.includes("Authentication") || message.includes("401")
372
- ? InvalidTokenError.make({ message: "Invalid API token" })
373
- : LinearApiError.make({ message });
346
+ if (message.includes("Authentication") || message.includes("401")) {
347
+ return InvalidTokenError.make({ message: "Invalid API token" });
348
+ }
349
+ return LinearApiError.make({ message });
350
+ };
351
+
352
+ type FetchImplementation = (input: string | URL, init?: RequestInit) => Promise<Response>;
353
+
354
+ const isRedirect = (status: number): boolean => status >= 300 && status < 400;
355
+
356
+ const requestUpload = (
357
+ fetchImplementation: FetchImplementation,
358
+ input: string | URL,
359
+ init: RequestInit,
360
+ ): Effect.Effect<Response, LinearApiError> =>
361
+ Effect.tryPromise({
362
+ try: () => fetchImplementation(input, init),
363
+ catch: (error) => LinearApiError.make({ message: `Download failed: ${String(error)}` }),
364
+ });
365
+
366
+ // Linear serves uploads behind the API key and may redirect to signed storage. The key goes
367
+ // only to the upload host; a redirect is followed without it so it never reaches a third party.
368
+ export const fetchUpload = Effect.fn("LinearService.fetchUpload")(function* (
369
+ url: UploadUrl,
370
+ token: Redacted.Redacted<string>,
371
+ fetchImplementation: FetchImplementation = fetch,
372
+ ) {
373
+ let response = yield* requestUpload(fetchImplementation, url, {
374
+ headers: { Authorization: Redacted.value(token) },
375
+ redirect: "manual",
376
+ });
377
+ const location = response.headers.get("location");
378
+ if (isRedirect(response.status) && location !== null) {
379
+ response = yield* requestUpload(fetchImplementation, new URL(location, url), {
380
+ redirect: "follow",
381
+ });
382
+ }
383
+ if (response.status === 401) {
384
+ return yield* InvalidTokenError.make({ message: "Invalid API token" });
385
+ }
386
+ if (!response.ok) {
387
+ return yield* LinearApiError.make({
388
+ message: `Download failed with HTTP ${response.status} for ${url}`,
389
+ code: String(response.status),
390
+ });
391
+ }
392
+ const body = yield* Effect.tryPromise({
393
+ try: () => response.arrayBuffer(),
394
+ catch: (error) => LinearApiError.make({ message: `Download failed: ${String(error)}` }),
395
+ });
396
+ return {
397
+ bytes: new Uint8Array(body),
398
+ contentType: response.headers.get("content-type") ?? undefined,
399
+ fileName: fileNameFromContentDisposition(response.headers.get("content-disposition")),
400
+ } satisfies DownloadedFile;
401
+ });
402
+
403
+ const mapDefined = <T, U>(value: T | undefined, transform: (value: T) => U): U | undefined => {
404
+ if (value === undefined) {
405
+ return undefined;
406
+ }
407
+ return transform(value);
408
+ };
409
+
410
+ const toViewerStatus = (viewer: User): Viewer["status"] => {
411
+ if (viewer.statusEmoji === undefined && viewer.statusLabel === undefined) {
412
+ return undefined;
413
+ }
414
+ return {
415
+ emoji: viewer.statusEmoji ?? undefined,
416
+ label: viewer.statusLabel ?? undefined,
417
+ };
374
418
  };
375
419
 
376
420
  const toViewer = (viewer: User): Viewer => ({
@@ -378,13 +422,7 @@ const toViewer = (viewer: User): Viewer => ({
378
422
  name: viewer.name,
379
423
  email: viewer.email,
380
424
  admin: viewer.admin,
381
- status:
382
- viewer.statusEmoji === undefined && viewer.statusLabel === undefined
383
- ? undefined
384
- : {
385
- emoji: viewer.statusEmoji ?? undefined,
386
- label: viewer.statusLabel ?? undefined,
387
- },
425
+ status: toViewerStatus(viewer),
388
426
  });
389
427
 
390
428
  const toTeam = (team: Awaited<ReturnType<LinearClient["team"]>>): Team => ({
@@ -420,20 +458,116 @@ const toIssueSummary = Effect.fn("LinearService.toIssueSummary")(function* (
420
458
  url: issue.url,
421
459
  branchName: issue.branchName,
422
460
  priority: { value: issue.priority, label: issue.priorityLabel },
423
- state: state === undefined ? undefined : { id: state.id, name: state.name, type: state.type },
461
+ state: mapDefined(state, (value) => ({ id: value.id, name: value.name, type: value.type })),
424
462
  };
425
463
  });
426
464
 
427
465
  const resolveLinearFetch = <T>(fetch: PromiseLike<T>): Effect.Effect<T, LinearApiError> =>
428
466
  Effect.tryPromise({
429
- try: () => Promise.resolve(fetch),
467
+ try: () => fetch,
430
468
  catch: (error) => LinearApiError.make({ message: String(error) }),
431
469
  });
432
470
 
433
471
  const resolveOptionalFetch = <T>(
434
472
  fetch: PromiseLike<T> | undefined,
435
- ): Effect.Effect<T | undefined, LinearApiError> =>
436
- fetch === undefined ? Effect.succeed(undefined) : resolveLinearFetch(fetch);
473
+ ): Effect.Effect<T | undefined, LinearApiError> => {
474
+ if (fetch === undefined) {
475
+ return succeedUndefined;
476
+ }
477
+ return resolveLinearFetch(fetch);
478
+ };
479
+
480
+ const toStateFilter = (
481
+ state: string | undefined,
482
+ ): { readonly state: { readonly type: { readonly eq: string } } } | undefined => {
483
+ if (state === undefined) {
484
+ return undefined;
485
+ }
486
+ return { state: { type: { eq: state } } };
487
+ };
488
+
489
+ const toCommentAuthor = (author: User | undefined): IssueComment["author"] => {
490
+ if (author === undefined) {
491
+ return undefined;
492
+ }
493
+ return { id: author.id, name: author.name };
494
+ };
495
+
496
+ const toDetailedComments = (
497
+ comments: ReadonlyArray<Comment> | undefined,
498
+ ): Effect.Effect<ReadonlyArray<IssueComment> | undefined, LinearApiError> => {
499
+ if (comments === undefined) {
500
+ return succeedUndefined;
501
+ }
502
+ return Effect.forEach(
503
+ comments,
504
+ (comment) =>
505
+ resolveOptionalFetch(comment.user).pipe(
506
+ Effect.map((author) => ({
507
+ id: comment.id,
508
+ body: comment.body,
509
+ createdAt: comment.createdAt.toISOString(),
510
+ url: comment.url,
511
+ author: toCommentAuthor(author),
512
+ })),
513
+ ),
514
+ { concurrency: 4 },
515
+ );
516
+ };
517
+
518
+ interface RelationWithDirection {
519
+ readonly relation: SdkIssueRelation;
520
+ readonly direction: "outbound" | "inbound";
521
+ }
522
+
523
+ const relatedIssueFetch = (entry: RelationWithDirection): PromiseLike<Issue> | undefined => {
524
+ if (entry.direction === "outbound") {
525
+ return entry.relation.relatedIssue;
526
+ }
527
+ return entry.relation.issue;
528
+ };
529
+
530
+ const toRelations = (
531
+ outbound: ReadonlyArray<SdkIssueRelation> | undefined,
532
+ inbound: ReadonlyArray<SdkIssueRelation> | undefined,
533
+ ): Effect.Effect<ReadonlyArray<IssueRelation> | undefined, LinearApiError> => {
534
+ if (outbound === undefined || inbound === undefined) {
535
+ return succeedUndefined;
536
+ }
537
+ const entries = outbound
538
+ .map<RelationWithDirection>((relation) => ({ relation, direction: "outbound" }))
539
+ .concat(inbound.map((relation) => ({ relation, direction: "inbound" })));
540
+ return Effect.forEach(
541
+ entries,
542
+ Effect.fn("LinearService.resolveRelation")(function* ({ direction, relation }) {
543
+ const related = yield* resolveOptionalFetch(relatedIssueFetch({ direction, relation }));
544
+ if (related === undefined) {
545
+ return undefined;
546
+ }
547
+ return {
548
+ id: relation.id,
549
+ type: relation.type,
550
+ direction,
551
+ issue: toIssueReference(related),
552
+ };
553
+ }),
554
+ { concurrency: 4 },
555
+ ).pipe(
556
+ Effect.map((items) =>
557
+ items.filter((item): item is NonNullable<typeof item> => item !== undefined),
558
+ ),
559
+ );
560
+ };
561
+
562
+ const loadConnectionWhen = <T>(
563
+ enabled: boolean,
564
+ load: () => PromiseLike<PaginatedConnection<T>>,
565
+ ): Effect.Effect<ReadonlyArray<T> | undefined, LinearApiError> => {
566
+ if (!enabled) {
567
+ return succeedUndefined;
568
+ }
569
+ return loadConnection(load);
570
+ };
437
571
 
438
572
  interface PaginatedConnection<T> {
439
573
  readonly nodes: ReadonlyArray<T>;
package/tsconfig.json CHANGED
@@ -31,27 +31,48 @@
31
31
  "ignoreEffectErrorsInTscExitCode": false,
32
32
  "diagnosticSeverity": {
33
33
  "anyUnknownInErrorContext": "error",
34
+ "asyncFunction": "off",
35
+ "cryptoRandomUUID": "off",
36
+ "cryptoRandomUUIDInEffect": "off",
37
+ "globalConsole": "off",
38
+ "globalConsoleInEffect": "off",
39
+ "globalDate": "off",
40
+ "globalDateInEffect": "off",
41
+ "globalFetch": "off",
42
+ "globalFetchInEffect": "off",
43
+ "globalRandom": "off",
44
+ "globalRandomInEffect": "off",
45
+ "globalTimers": "off",
46
+ "globalTimersInEffect": "off",
47
+ "newPromise": "off",
48
+ "nodeBuiltinImport": "off",
49
+ "processEnv": "off",
50
+ "processEnvInEffect": "off",
34
51
  "deterministicKeys": "error",
35
- "importFromBarrel": "warning",
36
52
  "instanceOfSchema": "warning",
53
+ // Effect 4.0.0 marks the whole effect/cli module @stability unstable. This CLI is
54
+ // built on it, so the rule would flag every command, flag, and prompt definition.
55
+ "unstableApiUsage": "off",
37
56
  "missedPipeableOpportunity": "suggestion",
38
57
  "missingEffectServiceDependency": "warning",
39
58
  "schemaUnionOfLiterals": "warning",
40
59
  "strictBooleanExpressions": "warning",
41
- "strictEffectProvide": "warning",
60
+ // Upstream default. The rule has no entry-point detection, so it fires on the single
61
+ // legitimate Effect.provide in src/main.ts. multipleEffectProvide still guards chains.
62
+ "strictEffectProvide": "off",
42
63
  "catchAllToMapError": "warning",
43
64
  "catchUnfailableEffect": "warning",
44
65
  "effectFnOpportunity": "warning",
45
66
  "effectMapVoid": "warning",
46
67
  "effectSucceedWithVoid": "warning",
47
68
  "leakingRequirements": "warning",
48
- "preferSchemaOverJson": "warning",
69
+ "preferSchemaOverJson": "off",
49
70
  "redundantSchemaTagIdentifier": "warning",
50
71
  "returnEffectInGen": "warning",
51
72
  "runEffectInsideEffect": "error",
52
73
  "schemaStructWithTag": "warning",
53
74
  "schemaSyncInEffect": "warning",
54
- "tryCatchInEffectGen": "warning",
75
+ "tryCatchInEffectGen": "off",
55
76
  "unnecessaryEffectGen": "warning",
56
77
  "unnecessaryFailYieldableError": "warning",
57
78
  "unnecessaryPipe": "warning",