@knpkv/codecommit-core 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (174) hide show
  1. package/README.md +66 -0
  2. package/dist/AwsClient/createPullRequest.d.ts +1 -6
  3. package/dist/AwsClient/createPullRequest.d.ts.map +1 -1
  4. package/dist/AwsClient/createPullRequest.js +3 -11
  5. package/dist/AwsClient/createPullRequest.js.map +1 -1
  6. package/dist/AwsClient/getCallerIdentity.d.ts +5 -6
  7. package/dist/AwsClient/getCallerIdentity.d.ts.map +1 -1
  8. package/dist/AwsClient/getCallerIdentity.js +7 -12
  9. package/dist/AwsClient/getCallerIdentity.js.map +1 -1
  10. package/dist/AwsClient/getCommentsForPullRequest.d.ts +1 -6
  11. package/dist/AwsClient/getCommentsForPullRequest.d.ts.map +1 -1
  12. package/dist/AwsClient/getCommentsForPullRequest.js +9 -16
  13. package/dist/AwsClient/getCommentsForPullRequest.js.map +1 -1
  14. package/dist/AwsClient/getPullRequest.d.ts +2 -7
  15. package/dist/AwsClient/getPullRequest.d.ts.map +1 -1
  16. package/dist/AwsClient/getPullRequest.js +13 -26
  17. package/dist/AwsClient/getPullRequest.js.map +1 -1
  18. package/dist/AwsClient/getPullRequests.d.ts.map +1 -1
  19. package/dist/AwsClient/getPullRequests.js +16 -13
  20. package/dist/AwsClient/getPullRequests.js.map +1 -1
  21. package/dist/AwsClient/index.d.ts +3 -2
  22. package/dist/AwsClient/index.d.ts.map +1 -1
  23. package/dist/AwsClient/index.js.map +1 -1
  24. package/dist/AwsClient/internal.d.ts +47 -11
  25. package/dist/AwsClient/internal.d.ts.map +1 -1
  26. package/dist/AwsClient/internal.js +38 -9
  27. package/dist/AwsClient/internal.js.map +1 -1
  28. package/dist/AwsClient/listBranches.d.ts +1 -6
  29. package/dist/AwsClient/listBranches.d.ts.map +1 -1
  30. package/dist/AwsClient/listBranches.js +3 -11
  31. package/dist/AwsClient/listBranches.js.map +1 -1
  32. package/dist/AwsClient/updatePullRequestDescription.d.ts +1 -6
  33. package/dist/AwsClient/updatePullRequestDescription.d.ts.map +1 -1
  34. package/dist/AwsClient/updatePullRequestDescription.js +3 -11
  35. package/dist/AwsClient/updatePullRequestDescription.js.map +1 -1
  36. package/dist/AwsClient/updatePullRequestTitle.d.ts +1 -6
  37. package/dist/AwsClient/updatePullRequestTitle.d.ts.map +1 -1
  38. package/dist/AwsClient/updatePullRequestTitle.js +3 -11
  39. package/dist/AwsClient/updatePullRequestTitle.js.map +1 -1
  40. package/dist/CacheService/CacheError.d.ts +21 -0
  41. package/dist/CacheService/CacheError.d.ts.map +1 -0
  42. package/dist/CacheService/CacheError.js +17 -0
  43. package/dist/CacheService/CacheError.js.map +1 -0
  44. package/dist/CacheService/Database.d.ts +13 -0
  45. package/dist/CacheService/Database.d.ts.map +1 -0
  46. package/dist/CacheService/Database.js +34 -0
  47. package/dist/CacheService/Database.js.map +1 -0
  48. package/dist/CacheService/EventsHub.d.ts +163 -0
  49. package/dist/CacheService/EventsHub.d.ts.map +1 -0
  50. package/dist/CacheService/EventsHub.js +22 -0
  51. package/dist/CacheService/EventsHub.js.map +1 -0
  52. package/dist/CacheService/diff.d.ts +28 -0
  53. package/dist/CacheService/diff.d.ts.map +1 -0
  54. package/dist/CacheService/diff.js +102 -0
  55. package/dist/CacheService/diff.js.map +1 -0
  56. package/dist/CacheService/index.d.ts +17 -0
  57. package/dist/CacheService/index.d.ts.map +1 -0
  58. package/dist/CacheService/index.js +15 -0
  59. package/dist/CacheService/index.js.map +1 -0
  60. package/dist/CacheService/migrations/0001_initial.d.ts +5 -0
  61. package/dist/CacheService/migrations/0001_initial.d.ts.map +1 -0
  62. package/dist/CacheService/migrations/0001_initial.js +72 -0
  63. package/dist/CacheService/migrations/0001_initial.js.map +1 -0
  64. package/dist/CacheService/migrations/0002_indexes.d.ts +5 -0
  65. package/dist/CacheService/migrations/0002_indexes.d.ts.map +1 -0
  66. package/dist/CacheService/migrations/0002_indexes.js +7 -0
  67. package/dist/CacheService/migrations/0002_indexes.js.map +1 -0
  68. package/dist/CacheService/migrations/0003_add_health_score.d.ts +5 -0
  69. package/dist/CacheService/migrations/0003_add_health_score.d.ts.map +1 -0
  70. package/dist/CacheService/migrations/0003_add_health_score.js +4 -0
  71. package/dist/CacheService/migrations/0003_add_health_score.js.map +1 -0
  72. package/dist/CacheService/migrations/0004_unify_notifications.d.ts +5 -0
  73. package/dist/CacheService/migrations/0004_unify_notifications.d.ts.map +1 -0
  74. package/dist/CacheService/migrations/0004_unify_notifications.js +7 -0
  75. package/dist/CacheService/migrations/0004_unify_notifications.js.map +1 -0
  76. package/dist/CacheService/repos/CommentRepo.d.ts +16 -0
  77. package/dist/CacheService/repos/CommentRepo.d.ts.map +1 -0
  78. package/dist/CacheService/repos/CommentRepo.js +42 -0
  79. package/dist/CacheService/repos/CommentRepo.js.map +1 -0
  80. package/dist/CacheService/repos/NotificationRepo.d.ts +48 -0
  81. package/dist/CacheService/repos/NotificationRepo.d.ts.map +1 -0
  82. package/dist/CacheService/repos/NotificationRepo.js +128 -0
  83. package/dist/CacheService/repos/NotificationRepo.js.map +1 -0
  84. package/dist/CacheService/repos/PullRequestRepo.d.ts +112 -0
  85. package/dist/CacheService/repos/PullRequestRepo.d.ts.map +1 -0
  86. package/dist/CacheService/repos/PullRequestRepo.js +146 -0
  87. package/dist/CacheService/repos/PullRequestRepo.js.map +1 -0
  88. package/dist/CacheService/repos/SubscriptionRepo.d.ts +20 -0
  89. package/dist/CacheService/repos/SubscriptionRepo.d.ts.map +1 -0
  90. package/dist/CacheService/repos/SubscriptionRepo.js +49 -0
  91. package/dist/CacheService/repos/SubscriptionRepo.js.map +1 -0
  92. package/dist/CacheService/repos/SyncMetadataRepo.d.ts +14 -0
  93. package/dist/CacheService/repos/SyncMetadataRepo.d.ts.map +1 -0
  94. package/dist/CacheService/repos/SyncMetadataRepo.js +36 -0
  95. package/dist/CacheService/repos/SyncMetadataRepo.js.map +1 -0
  96. package/dist/ConfigService/backup.d.ts +1 -1
  97. package/dist/ConfigService/detectProfiles.d.ts +1 -1
  98. package/dist/ConfigService/index.d.ts +2 -1
  99. package/dist/ConfigService/index.d.ts.map +1 -1
  100. package/dist/ConfigService/index.js +3 -1
  101. package/dist/ConfigService/index.js.map +1 -1
  102. package/dist/ConfigService/internal.d.ts +6 -0
  103. package/dist/ConfigService/internal.d.ts.map +1 -1
  104. package/dist/ConfigService/internal.js +3 -1
  105. package/dist/ConfigService/internal.js.map +1 -1
  106. package/dist/ConfigService/load.d.ts +3 -1
  107. package/dist/ConfigService/load.d.ts.map +1 -1
  108. package/dist/ConfigService/load.js +4 -2
  109. package/dist/ConfigService/load.js.map +1 -1
  110. package/dist/ConfigService/reset.d.ts.map +1 -1
  111. package/dist/ConfigService/reset.js +3 -1
  112. package/dist/ConfigService/reset.js.map +1 -1
  113. package/dist/ConfigService/save.d.ts +1 -1
  114. package/dist/ConfigService/validate.d.ts +1 -1
  115. package/dist/DateUtils.d.ts +1 -1
  116. package/dist/DateUtils.d.ts.map +1 -1
  117. package/dist/DateUtils.js +2 -2
  118. package/dist/DateUtils.js.map +1 -1
  119. package/dist/Domain.d.ts +179 -10
  120. package/dist/Domain.d.ts.map +1 -1
  121. package/dist/Domain.js +23 -5
  122. package/dist/Domain.js.map +1 -1
  123. package/dist/HealthScore.d.ts.map +1 -1
  124. package/dist/HealthScore.js +1 -3
  125. package/dist/HealthScore.js.map +1 -1
  126. package/dist/PRService/index.d.ts +46 -18
  127. package/dist/PRService/index.d.ts.map +1 -1
  128. package/dist/PRService/index.js +58 -27
  129. package/dist/PRService/index.js.map +1 -1
  130. package/dist/PRService/internal.d.ts +86 -1
  131. package/dist/PRService/internal.d.ts.map +1 -1
  132. package/dist/PRService/internal.js +106 -1
  133. package/dist/PRService/internal.js.map +1 -1
  134. package/dist/PRService/refresh.d.ts +10 -4
  135. package/dist/PRService/refresh.d.ts.map +1 -1
  136. package/dist/PRService/refresh.js +30 -89
  137. package/dist/PRService/refresh.js.map +1 -1
  138. package/dist/PRService/refreshEnrich.d.ts +15 -0
  139. package/dist/PRService/refreshEnrich.d.ts.map +1 -0
  140. package/dist/PRService/refreshEnrich.js +72 -0
  141. package/dist/PRService/refreshEnrich.js.map +1 -0
  142. package/dist/PRService/refreshFetch.d.ts +20 -0
  143. package/dist/PRService/refreshFetch.d.ts.map +1 -0
  144. package/dist/PRService/refreshFetch.js +78 -0
  145. package/dist/PRService/refreshFetch.js.map +1 -0
  146. package/dist/PRService/refreshResolve.d.ts +29 -0
  147. package/dist/PRService/refreshResolve.d.ts.map +1 -0
  148. package/dist/PRService/refreshResolve.js +84 -0
  149. package/dist/PRService/refreshResolve.js.map +1 -0
  150. package/dist/PRService/refreshScore.d.ts +9 -0
  151. package/dist/PRService/refreshScore.d.ts.map +1 -0
  152. package/dist/PRService/refreshScore.js +24 -0
  153. package/dist/PRService/refreshScore.js.map +1 -0
  154. package/dist/PRService/refreshSinglePR.d.ts +13 -0
  155. package/dist/PRService/refreshSinglePR.d.ts.map +1 -0
  156. package/dist/PRService/refreshSinglePR.js +102 -0
  157. package/dist/PRService/refreshSinglePR.js.map +1 -0
  158. package/dist/PRService/setAllAccounts.d.ts +1 -3
  159. package/dist/PRService/setAllAccounts.d.ts.map +1 -1
  160. package/dist/PRService/setAllAccounts.js +2 -2
  161. package/dist/PRService/setAllAccounts.js.map +1 -1
  162. package/dist/PRService/toggleAccount.d.ts +1 -3
  163. package/dist/PRService/toggleAccount.d.ts.map +1 -1
  164. package/dist/PRService/toggleAccount.js +2 -2
  165. package/dist/PRService/toggleAccount.js.map +1 -1
  166. package/dist/index.d.ts +1 -1
  167. package/dist/index.d.ts.map +1 -1
  168. package/dist/index.js +1 -1
  169. package/dist/index.js.map +1 -1
  170. package/package.json +4 -1
  171. package/dist/NotificationsService.d.ts +0 -46
  172. package/dist/NotificationsService.d.ts.map +0 -1
  173. package/dist/NotificationsService.js +0 -57
  174. package/dist/NotificationsService.js.map +0 -1
@@ -0,0 +1,128 @@
1
+ import * as SqlClient from "@effect/sql/SqlClient";
2
+ import * as SqlSchema from "@effect/sql/SqlSchema";
3
+ import { Array as Arr, Effect, Option, Schema } from "effect";
4
+ import { CacheError } from "../CacheError.js";
5
+ import { DatabaseLive } from "../Database.js";
6
+ import { EventsHub, RepoChange } from "../EventsHub.js";
7
+ const NotificationRow = Schema.Struct({
8
+ id: Schema.Number,
9
+ pullRequestId: Schema.String,
10
+ awsAccountId: Schema.String,
11
+ type: Schema.String,
12
+ message: Schema.String,
13
+ title: Schema.String,
14
+ profile: Schema.String,
15
+ createdAt: Schema.String,
16
+ read: Schema.Number
17
+ });
18
+ const DEFAULT_LIMIT = 20;
19
+ // We fetch limit+1 rows; if we got more than limit, the extra row proves there's a next page.
20
+ // Trim to limit and use the last returned row's id as the cursor for the next request.
21
+ const paginate = (rows, limit) => {
22
+ const [items, overflow] = Arr.splitAt(rows, limit);
23
+ return Arr.isNonEmptyReadonlyArray(overflow)
24
+ ? { items, nextCursor: Option.getOrThrow(Arr.last(items)).id }
25
+ : { items };
26
+ };
27
+ const cacheError = (op) => (effect) => effect.pipe(Effect.mapError((cause) => new CacheError({ operation: `NotificationRepo.${op}`, cause })), Effect.withSpan(`NotificationRepo.${op}`, { captureStackTrace: false }));
28
+ export class NotificationRepo extends Effect.Service()("NotificationRepo", {
29
+ dependencies: [DatabaseLive, EventsHub.Default],
30
+ effect: Effect.gen(function* () {
31
+ const sql = yield* SqlClient.SqlClient;
32
+ const hub = yield* EventsHub;
33
+ const findAllUnpaginated = SqlSchema.findAll({
34
+ Result: NotificationRow,
35
+ Request: Schema.Struct({ unreadOnly: Schema.Boolean, filter: Schema.Literal("system", "prs", "all") }),
36
+ execute: (req) => {
37
+ const f = req.filter;
38
+ if (req.unreadOnly) {
39
+ if (f === "system") {
40
+ return sql `SELECT * FROM notifications WHERE read = 0 AND pull_request_id = '' ORDER BY id DESC`;
41
+ }
42
+ if (f === "prs") {
43
+ return sql `SELECT * FROM notifications WHERE read = 0 AND pull_request_id != '' ORDER BY id DESC`;
44
+ }
45
+ return sql `SELECT * FROM notifications WHERE read = 0 ORDER BY id DESC`;
46
+ }
47
+ if (f === "system")
48
+ return sql `SELECT * FROM notifications WHERE pull_request_id = '' ORDER BY id DESC`;
49
+ if (f === "prs")
50
+ return sql `SELECT * FROM notifications WHERE pull_request_id != '' ORDER BY id DESC`;
51
+ return sql `SELECT * FROM notifications ORDER BY id DESC`;
52
+ }
53
+ });
54
+ const findPaginated_ = SqlSchema.findAll({
55
+ Result: NotificationRow,
56
+ Request: Schema.Struct({
57
+ unreadOnly: Schema.Boolean,
58
+ cursor: Schema.Number,
59
+ limit: Schema.Number,
60
+ filter: Schema.Literal("system", "prs", "all")
61
+ }),
62
+ execute: (req) => {
63
+ const f = req.filter;
64
+ if (req.unreadOnly) {
65
+ if (f === "system") {
66
+ return sql `SELECT * FROM notifications WHERE read = 0 AND pull_request_id = '' AND id < ${req.cursor} ORDER BY id DESC LIMIT ${req.limit}`;
67
+ }
68
+ if (f === "prs") {
69
+ return sql `SELECT * FROM notifications WHERE read = 0 AND pull_request_id != '' AND id < ${req.cursor} ORDER BY id DESC LIMIT ${req.limit}`;
70
+ }
71
+ return sql `SELECT * FROM notifications WHERE read = 0 AND id < ${req.cursor} ORDER BY id DESC LIMIT ${req.limit}`;
72
+ }
73
+ if (f === "system") {
74
+ return sql `SELECT * FROM notifications WHERE pull_request_id = '' AND id < ${req.cursor} ORDER BY id DESC LIMIT ${req.limit}`;
75
+ }
76
+ if (f === "prs") {
77
+ return sql `SELECT * FROM notifications WHERE pull_request_id != '' AND id < ${req.cursor} ORDER BY id DESC LIMIT ${req.limit}`;
78
+ }
79
+ return sql `SELECT * FROM notifications WHERE id < ${req.cursor} ORDER BY id DESC LIMIT ${req.limit}`;
80
+ }
81
+ });
82
+ const add_ = (n) => sql `INSERT INTO notifications (pull_request_id, aws_account_id, type, message, title, profile)
83
+ VALUES (${n.pullRequestId}, ${n.awsAccountId}, ${n.type}, ${n.message}, ${n.title ?? ""}, ${n.profile ?? ""})`
84
+ .pipe(Effect.asVoid);
85
+ const markRead_ = (id) => sql `UPDATE notifications SET read = 1 WHERE id = ${id}`.pipe(Effect.asVoid);
86
+ const markUnread_ = (id) => sql `UPDATE notifications SET read = 0 WHERE id = ${id}`.pipe(Effect.asVoid);
87
+ const markAllRead_ = () => sql `UPDATE notifications SET read = 1 WHERE read = 0`.pipe(Effect.asVoid);
88
+ const publish = hub.publish(RepoChange.Notifications());
89
+ return {
90
+ findAll: (opts) => {
91
+ const limit = opts?.limit ?? DEFAULT_LIMIT;
92
+ const unreadOnly = opts?.unreadOnly ?? false;
93
+ const cursor = opts?.cursor;
94
+ const filter = opts?.filter ?? "all";
95
+ if (cursor === undefined) {
96
+ return findAllUnpaginated({ unreadOnly, filter }).pipe(Effect.map((rows) => paginate(rows, limit)), cacheError("findAll"));
97
+ }
98
+ const fetchLimit = limit + 1;
99
+ return findPaginated_({ unreadOnly, cursor, limit: fetchLimit, filter }).pipe(Effect.map((rows) => paginate(rows, limit)), cacheError("findAll"));
100
+ },
101
+ add: (n) => add_(n).pipe(Effect.tap(() => publish), cacheError("add")),
102
+ addSystem: (n) => {
103
+ const insert = add_({
104
+ pullRequestId: "",
105
+ awsAccountId: "",
106
+ type: n.type,
107
+ message: n.message,
108
+ title: n.title,
109
+ profile: n.profile ?? ""
110
+ }).pipe(Effect.tap(() => publish));
111
+ if (!n.deduplicate) {
112
+ return insert.pipe(cacheError("addSystem"));
113
+ }
114
+ // Skip if an unread system notification with same profile+type already exists
115
+ return sql `
116
+ SELECT count(*) as count FROM notifications
117
+ WHERE profile = ${n.profile ?? ""} AND type = ${n.type} AND pull_request_id = '' AND read = 0
118
+ `.pipe(Effect.flatMap((rows) => (rows[0]?.count ?? 0) > 0 ? Effect.void : insert), cacheError("addSystem"));
119
+ },
120
+ markRead: (id) => markRead_(id).pipe(Effect.tap(() => publish), cacheError("markRead")),
121
+ markUnread: (id) => markUnread_(id).pipe(Effect.tap(() => publish), cacheError("markUnread")),
122
+ markAllRead: () => markAllRead_().pipe(Effect.tap(() => publish), cacheError("markAllRead")),
123
+ unreadCount: () => sql `SELECT count(*) as count FROM notifications WHERE read = 0`.pipe(Effect.map((rows) => rows[0]?.count ?? 0), cacheError("unreadCount"))
124
+ };
125
+ })
126
+ }) {
127
+ }
128
+ //# sourceMappingURL=NotificationRepo.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NotificationRepo.js","sourceRoot":"","sources":["../../../src/CacheService/repos/NotificationRepo.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,uBAAuB,CAAA;AAClD,OAAO,KAAK,SAAS,MAAM,uBAAuB,CAAA;AAClD,OAAO,EAAE,KAAK,IAAI,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAE7C,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAEvD,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC;IACpC,EAAE,EAAE,MAAM,CAAC,MAAM;IACjB,aAAa,EAAE,MAAM,CAAC,MAAM;IAC5B,YAAY,EAAE,MAAM,CAAC,MAAM;IAC3B,IAAI,EAAE,MAAM,CAAC,MAAM;IACnB,OAAO,EAAE,MAAM,CAAC,MAAM;IACtB,KAAK,EAAE,MAAM,CAAC,MAAM;IACpB,OAAO,EAAE,MAAM,CAAC,MAAM;IACtB,SAAS,EAAE,MAAM,CAAC,MAAM;IACxB,IAAI,EAAE,MAAM,CAAC,MAAM;CACpB,CAAC,CAAA;AAKF,MAAM,aAAa,GAAG,EAAE,CAAA;AASxB,8FAA8F;AAC9F,uFAAuF;AACvF,MAAM,QAAQ,GAAG,CAAC,IAAoC,EAAE,KAAa,EAA0B,EAAE;IAC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,CAAC,OAAO,CAAC,EAAE,UAAU,CAAC,YAAY,CAAC,CAAC;YAErG,WAAW,EAAE,GAAG,EAAE,CAAC,YAAY,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,EAAE,UAAU,CAAC,aAAa,CAAC,CAAC;YAE5F,WAAW,EAAE,GAAG,EAAE,CAChB,GAAG,CAAmB,4DAA4D,CAAC,IAAI,CACrF,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,KAAK,IAAI,CAAC,CAAC,EACzC,UAAU,CAAC,aAAa,CAAC,CAC1B;SACK,CAAA;IACZ,CAAC,CAAC;CACH,CAAC;CAAG"}
@@ -0,0 +1,112 @@
1
+ import * as Model from "@effect/sql/Model";
2
+ import * as SqlClient from "@effect/sql/SqlClient";
3
+ import { Effect, Option, Schema } from "effect";
4
+ import { CacheError } from "../CacheError.js";
5
+ import { EventsHub } from "../EventsHub.js";
6
+ export declare const CachedPullRequest: Schema.Struct<{
7
+ id: Schema.brand<typeof Schema.String, "PullRequestId">;
8
+ awsAccountId: typeof Schema.String;
9
+ accountProfile: Schema.brand<typeof Schema.String, "AwsProfileName">;
10
+ accountRegion: Schema.brand<typeof Schema.String, "AwsRegion">;
11
+ title: typeof Schema.String;
12
+ description: Schema.NullOr<typeof Schema.String>;
13
+ author: typeof Schema.String;
14
+ repositoryName: Schema.brand<typeof Schema.String, "RepositoryName">;
15
+ creationDate: typeof Schema.DateFromString;
16
+ lastModifiedDate: typeof Schema.DateFromString;
17
+ status: Schema.Literal<["OPEN", "CLOSED", "MERGED"]>;
18
+ sourceBranch: typeof Schema.String;
19
+ destinationBranch: typeof Schema.String;
20
+ isMergeable: typeof Model.BooleanFromNumber;
21
+ isApproved: typeof Model.BooleanFromNumber;
22
+ commentCount: Schema.NullOr<typeof Schema.Number>;
23
+ healthScore: Schema.NullOr<typeof Schema.Number>;
24
+ link: typeof Schema.String;
25
+ fetchedAt: typeof Schema.String;
26
+ }>;
27
+ export type CachedPullRequest = typeof CachedPullRequest.Type;
28
+ export interface SearchResult {
29
+ readonly items: ReadonlyArray<CachedPullRequest>;
30
+ readonly total: number;
31
+ readonly hasMore: boolean;
32
+ }
33
+ export declare const UpsertInput: Schema.Struct<{
34
+ id: typeof Schema.String;
35
+ awsAccountId: typeof Schema.String;
36
+ accountProfile: typeof Schema.String;
37
+ accountRegion: typeof Schema.String;
38
+ title: typeof Schema.String;
39
+ description: Schema.NullOr<typeof Schema.String>;
40
+ author: typeof Schema.String;
41
+ repositoryName: typeof Schema.String;
42
+ creationDate: typeof Schema.String;
43
+ lastModifiedDate: typeof Schema.String;
44
+ status: typeof Schema.String;
45
+ sourceBranch: typeof Schema.String;
46
+ destinationBranch: typeof Schema.String;
47
+ isMergeable: typeof Schema.Number;
48
+ isApproved: typeof Schema.Number;
49
+ commentCount: Schema.NullOr<typeof Schema.Number>;
50
+ link: typeof Schema.String;
51
+ }>;
52
+ export type UpsertInput = typeof UpsertInput.Type;
53
+ declare const PullRequestRepo_base: Effect.Service.Class<PullRequestRepo, "PullRequestRepo", {
54
+ readonly dependencies: readonly [import("effect/Layer").Layer<SqlClient.SqlClient | import("@effect/sql-libsql/LibsqlClient").LibsqlClient, import("@effect/sql/SqlError").SqlError | import("effect/ConfigError").ConfigError | import("@effect/sql/Migrator").MigrationError, import("@effect/platform/FileSystem").FileSystem>, import("effect/Layer").Layer<EventsHub, never, never>];
55
+ readonly effect: Effect.Effect<{
56
+ readonly findAll: () => Effect.Effect<readonly {
57
+ readonly link: string;
58
+ readonly awsAccountId: string;
59
+ readonly id: string & import("effect/Brand").Brand<"PullRequestId">;
60
+ readonly title: string;
61
+ readonly author: string;
62
+ readonly repositoryName: string & import("effect/Brand").Brand<"RepositoryName">;
63
+ readonly creationDate: Date;
64
+ readonly lastModifiedDate: Date;
65
+ readonly status: "OPEN" | "CLOSED" | "MERGED";
66
+ readonly sourceBranch: string;
67
+ readonly destinationBranch: string;
68
+ readonly isMergeable: boolean;
69
+ readonly isApproved: boolean;
70
+ readonly description: string | null;
71
+ readonly commentCount: number | null;
72
+ readonly healthScore: number | null;
73
+ readonly fetchedAt: string;
74
+ readonly accountProfile: string & import("effect/Brand").Brand<"AwsProfileName">;
75
+ readonly accountRegion: string & import("effect/Brand").Brand<"AwsRegion">;
76
+ }[], CacheError, never>;
77
+ readonly findByAccountAndId: (awsAccountId: string, id: string) => Effect.Effect<Option.Option<{
78
+ readonly link: string;
79
+ readonly awsAccountId: string;
80
+ readonly id: string & import("effect/Brand").Brand<"PullRequestId">;
81
+ readonly title: string;
82
+ readonly author: string;
83
+ readonly repositoryName: string & import("effect/Brand").Brand<"RepositoryName">;
84
+ readonly creationDate: Date;
85
+ readonly lastModifiedDate: Date;
86
+ readonly status: "OPEN" | "CLOSED" | "MERGED";
87
+ readonly sourceBranch: string;
88
+ readonly destinationBranch: string;
89
+ readonly isMergeable: boolean;
90
+ readonly isApproved: boolean;
91
+ readonly description: string | null;
92
+ readonly commentCount: number | null;
93
+ readonly healthScore: number | null;
94
+ readonly fetchedAt: string;
95
+ readonly accountProfile: string & import("effect/Brand").Brand<"AwsProfileName">;
96
+ readonly accountRegion: string & import("effect/Brand").Brand<"AwsRegion">;
97
+ }>, CacheError, never>;
98
+ readonly upsert: (input: UpsertInput) => Effect.Effect<void, CacheError, never>;
99
+ readonly upsertMany: (prs: ReadonlyArray<UpsertInput>) => Effect.Effect<void, CacheError, never>;
100
+ readonly search: (query: string, opts?: {
101
+ readonly limit?: number;
102
+ readonly offset?: number;
103
+ }) => Effect.Effect<SearchResult, CacheError>;
104
+ readonly deleteStale: (olderThan: string) => Effect.Effect<void, CacheError, never>;
105
+ readonly updateCommentCount: (awsAccountId: string, id: string, count: number | null) => Effect.Effect<void, CacheError, never>;
106
+ readonly updateHealthScore: (awsAccountId: string, id: string, score: number) => Effect.Effect<void, CacheError, never>;
107
+ }, never, SqlClient.SqlClient | EventsHub>;
108
+ }>;
109
+ export declare class PullRequestRepo extends PullRequestRepo_base {
110
+ }
111
+ export {};
112
+ //# sourceMappingURL=PullRequestRepo.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PullRequestRepo.d.ts","sourceRoot":"","sources":["../../../src/CacheService/repos/PullRequestRepo.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAA;AAC1C,OAAO,KAAK,SAAS,MAAM,uBAAuB,CAAA;AAElD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAE/C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAE7C,OAAO,EAAE,SAAS,EAAc,MAAM,iBAAiB,CAAA;AAEvD,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;EAoB5B,CAAA;AAEF,MAAM,MAAM,iBAAiB,GAAG,OAAO,iBAAiB,CAAC,IAAI,CAAA;AAE7D,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC,iBAAiB,CAAC,CAAA;IAChD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;CAC1B;AAED,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;EAkBtB,CAAA;AAEF,MAAM,MAAM,WAAW,GAAG,OAAO,WAAW,CAAC,IAAI,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;oDAqGR,MAAM,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;iCAErC,WAAW;mCACT,aAAa,CAAC,WAAW,CAAC;iCAGnC,MAAM,SACN;YAAE,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;YAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;SAAE,KAC3D,MAAM,CAAC,MAAM,CAAC,YAAY,EAAE,UAAU,CAAC;0CAoBjB,MAAM;oDAEI,MAAM,MAAM,MAAM,SAAS,MAAM,GAAG,IAAI;mDAEzC,MAAM,MAAM,MAAM,SAAS,MAAM;;;AA7HzE,qBAAa,eAAgB,SAAQ,oBAiInC;CAAG"}
@@ -0,0 +1,146 @@
1
+ import * as Model from "@effect/sql/Model";
2
+ import * as SqlClient from "@effect/sql/SqlClient";
3
+ import * as SqlSchema from "@effect/sql/SqlSchema";
4
+ import { Effect, Option, Schema } from "effect";
5
+ import { AwsProfileName, AwsRegion, PullRequestId, PullRequestStatus, RepositoryName } from "../../Domain.js";
6
+ import { CacheError } from "../CacheError.js";
7
+ import { DatabaseLive } from "../Database.js";
8
+ import { EventsHub, RepoChange } from "../EventsHub.js";
9
+ export const CachedPullRequest = Schema.Struct({
10
+ id: PullRequestId,
11
+ awsAccountId: Schema.String,
12
+ accountProfile: AwsProfileName,
13
+ accountRegion: AwsRegion,
14
+ title: Schema.String,
15
+ description: Schema.NullOr(Schema.String),
16
+ author: Schema.String,
17
+ repositoryName: RepositoryName,
18
+ creationDate: Schema.DateFromString,
19
+ lastModifiedDate: Schema.DateFromString,
20
+ status: PullRequestStatus,
21
+ sourceBranch: Schema.String,
22
+ destinationBranch: Schema.String,
23
+ isMergeable: Model.BooleanFromNumber,
24
+ isApproved: Model.BooleanFromNumber,
25
+ commentCount: Schema.NullOr(Schema.Number),
26
+ healthScore: Schema.NullOr(Schema.Number),
27
+ link: Schema.String,
28
+ fetchedAt: Schema.String
29
+ });
30
+ export const UpsertInput = Schema.Struct({
31
+ id: Schema.String,
32
+ awsAccountId: Schema.String,
33
+ accountProfile: Schema.String,
34
+ accountRegion: Schema.String,
35
+ title: Schema.String,
36
+ description: Schema.NullOr(Schema.String),
37
+ author: Schema.String,
38
+ repositoryName: Schema.String,
39
+ creationDate: Schema.String,
40
+ lastModifiedDate: Schema.String,
41
+ status: Schema.String,
42
+ sourceBranch: Schema.String,
43
+ destinationBranch: Schema.String,
44
+ isMergeable: Schema.Number,
45
+ isApproved: Schema.Number,
46
+ commentCount: Schema.NullOr(Schema.Number),
47
+ link: Schema.String
48
+ });
49
+ const cacheError = (op) => (effect) => effect.pipe(Effect.mapError((cause) => new CacheError({ operation: `PullRequestRepo.${op}`, cause })), Effect.withSpan(`PullRequestRepo.${op}`, { captureStackTrace: false }));
50
+ export class PullRequestRepo extends Effect.Service()("PullRequestRepo", {
51
+ dependencies: [DatabaseLive, EventsHub.Default],
52
+ effect: Effect.gen(function* () {
53
+ const sql = yield* SqlClient.SqlClient;
54
+ const hub = yield* EventsHub;
55
+ const findAll_ = SqlSchema.findAll({
56
+ Result: CachedPullRequest,
57
+ Request: Schema.Void,
58
+ execute: () => sql `SELECT * FROM pull_requests ORDER BY creation_date DESC`
59
+ });
60
+ const findByAccountAndId_ = SqlSchema.findOne({
61
+ Result: CachedPullRequest,
62
+ Request: Schema.Struct({ awsAccountId: Schema.String, id: Schema.String }),
63
+ execute: (req) => sql `SELECT * FROM pull_requests
64
+ WHERE aws_account_id = ${req.awsAccountId} AND id = ${req.id}`
65
+ });
66
+ const upsert_ = SqlSchema.void({
67
+ Request: UpsertInput,
68
+ execute: (req) => sql `INSERT INTO pull_requests
69
+ (id, aws_account_id, account_profile, account_region, title, description,
70
+ author, repository_name, creation_date, last_modified_date, status,
71
+ source_branch, destination_branch, is_mergeable, is_approved,
72
+ comment_count, link, fetched_at)
73
+ VALUES (${req.id}, ${req.awsAccountId}, ${req.accountProfile}, ${req.accountRegion},
74
+ ${req.title}, ${req.description}, ${req.author}, ${req.repositoryName},
75
+ ${req.creationDate}, ${req.lastModifiedDate}, ${req.status},
76
+ ${req.sourceBranch}, ${req.destinationBranch}, ${req.isMergeable}, ${req.isApproved},
77
+ ${req.commentCount}, ${req.link}, strftime('%Y-%m-%dT%H:%M:%SZ', 'now'))
78
+ ON CONFLICT (aws_account_id, id) DO UPDATE SET
79
+ account_profile = excluded.account_profile,
80
+ account_region = excluded.account_region,
81
+ title = excluded.title,
82
+ description = excluded.description,
83
+ author = excluded.author,
84
+ repository_name = excluded.repository_name,
85
+ creation_date = excluded.creation_date,
86
+ last_modified_date = excluded.last_modified_date,
87
+ status = excluded.status,
88
+ source_branch = excluded.source_branch,
89
+ destination_branch = excluded.destination_branch,
90
+ is_mergeable = excluded.is_mergeable,
91
+ is_approved = excluded.is_approved,
92
+ comment_count = COALESCE(excluded.comment_count, pull_requests.comment_count),
93
+ health_score = COALESCE(excluded.health_score, pull_requests.health_score),
94
+ link = excluded.link,
95
+ fetched_at = excluded.fetched_at`
96
+ });
97
+ const search_ = SqlSchema.findAll({
98
+ Result: CachedPullRequest,
99
+ Request: Schema.Struct({ query: Schema.String, limit: Schema.Number, offset: Schema.Number }),
100
+ execute: (req) => sql `SELECT pull_requests.* FROM pull_requests
101
+ JOIN pull_requests_fts fts ON pull_requests.rowid = fts.rowid
102
+ WHERE pull_requests_fts MATCH ${req.query}
103
+ ORDER BY rank
104
+ LIMIT ${req.limit} OFFSET ${req.offset}`
105
+ });
106
+ const searchCount_ = SqlSchema.findOne({
107
+ Result: Schema.Struct({ count: Schema.Number }),
108
+ Request: Schema.Struct({ query: Schema.String }),
109
+ execute: (req) => sql `SELECT count(*) as count FROM pull_requests
110
+ JOIN pull_requests_fts fts ON pull_requests.rowid = fts.rowid
111
+ WHERE pull_requests_fts MATCH ${req.query}`
112
+ });
113
+ const deleteStale_ = SqlSchema.void({
114
+ Request: Schema.Struct({ olderThan: Schema.String }),
115
+ execute: (req) => sql `DELETE FROM pull_requests WHERE fetched_at < ${req.olderThan}`
116
+ });
117
+ const updateCommentCount_ = (awsAccountId, id, count) => sql `UPDATE pull_requests SET comment_count = ${count}
118
+ WHERE id = ${id} AND aws_account_id = ${awsAccountId}`.pipe(Effect.asVoid);
119
+ const updateHealthScore_ = (awsAccountId, id, score) => sql `UPDATE pull_requests SET health_score = ${score}
120
+ WHERE id = ${id} AND aws_account_id = ${awsAccountId}`.pipe(Effect.asVoid);
121
+ const upsertMany_ = (prs) => sql.withTransaction(Effect.forEach(prs, (pr) => upsert_(pr), { discard: true }));
122
+ const publish = hub.publish(RepoChange.PullRequests());
123
+ return {
124
+ findAll: () => findAll_(undefined).pipe(cacheError("findAll")),
125
+ findByAccountAndId: (awsAccountId, id) => findByAccountAndId_({ awsAccountId, id }).pipe(cacheError("findByAccountAndId")),
126
+ upsert: (input) => upsert_(input).pipe(Effect.tap(() => publish), cacheError("upsert")),
127
+ upsertMany: (prs) => upsertMany_(prs).pipe(Effect.tap(() => publish), cacheError("upsertMany")),
128
+ search: (query, opts) => {
129
+ const limit = opts?.limit ?? 20;
130
+ const offset = opts?.offset ?? 0;
131
+ const stripped = query.replace(/[*^"]/g, "").replace(/\b(NEAR|OR|NOT|AND)\b/gi, "");
132
+ const escaped = stripped.replace(/"/g, `""`);
133
+ const ftsQuery = `"${escaped}"`;
134
+ return Effect.all({
135
+ items: search_({ query: ftsQuery, limit, offset }),
136
+ total: searchCount_({ query: ftsQuery }).pipe(Effect.map((r) => r.pipe(Option.getOrElse(() => ({ count: 0 }))).count))
137
+ }).pipe(Effect.map(({ items, total }) => ({ items, total, hasMore: offset + items.length < total })), Effect.catchTag("SqlError", () => Effect.logWarning("FTS search failed").pipe(Effect.as({ items: [], total: 0, hasMore: false }))), cacheError("search"));
138
+ },
139
+ deleteStale: (olderThan) => deleteStale_({ olderThan }).pipe(Effect.tap(() => publish), cacheError("deleteStale")),
140
+ updateCommentCount: (awsAccountId, id, count) => updateCommentCount_(awsAccountId, id, count).pipe(Effect.tap(() => publish), cacheError("updateCommentCount")),
141
+ updateHealthScore: (awsAccountId, id, score) => updateHealthScore_(awsAccountId, id, score).pipe(Effect.tap(() => publish), cacheError("updateHealthScore"))
142
+ };
143
+ })
144
+ }) {
145
+ }
146
+ //# sourceMappingURL=PullRequestRepo.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PullRequestRepo.js","sourceRoot":"","sources":["../../../src/CacheService/repos/PullRequestRepo.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,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AE,KAAK,EAAE,EAAsC,EAAE,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CACvF,CAAC,EACJ,UAAU,CAAC,QAAQ,CAAC,CACrB,CAAA;YACH,CAAC;YACD,WAAW,EAAE,CAAC,SAAiB,EAAE,EAAE,CACjC,YAAY,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,EAAE,UAAU,CAAC,aAAa,CAAC,CAAC;YACxF,kBAAkB,EAAE,CAAC,YAAoB,EAAE,EAAU,EAAE,KAAoB,EAAE,EAAE,CAC7E,mBAAmB,CAAC,YAAY,EAAE,EAAE,EAAE,KAAK,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,EAAE,UAAU,CAAC,oBAAoB,CAAC,CAAC;YAChH,iBAAiB,EAAE,CAAC,YAAoB,EAAE,EAAU,EAAE,KAAa,EAAE,EAAE,CACrE,kBAAkB,CAAC,YAAY,EAAE,EAAE,EAAE,KAAK,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,EAAE,UAAU,CAAC,mBAAmB,CAAC,CAAC;SACtG,CAAA;IACZ,CAAC,CAAC;CACH,CAAC;CAAG"}
@@ -0,0 +1,20 @@
1
+ import * as SqlClient from "@effect/sql/SqlClient";
2
+ import { Effect } from "effect";
3
+ import { CacheError } from "../CacheError.js";
4
+ import { EventsHub } from "../EventsHub.js";
5
+ declare const SubscriptionRepo_base: Effect.Service.Class<SubscriptionRepo, "SubscriptionRepo", {
6
+ readonly dependencies: readonly [import("effect/Layer").Layer<SqlClient.SqlClient | import("@effect/sql-libsql/LibsqlClient").LibsqlClient, import("@effect/sql/SqlError").SqlError | import("effect/ConfigError").ConfigError | import("@effect/sql/Migrator").MigrationError, import("@effect/platform/FileSystem").FileSystem>, import("effect/Layer").Layer<EventsHub, never, never>];
7
+ readonly effect: Effect.Effect<{
8
+ readonly subscribe: (awsAccountId: string, prId: string) => Effect.Effect<void, CacheError, never>;
9
+ readonly unsubscribe: (awsAccountId: string, prId: string) => Effect.Effect<void, CacheError, never>;
10
+ readonly findAll: () => Effect.Effect<readonly {
11
+ readonly awsAccountId: string;
12
+ readonly pullRequestId: string;
13
+ }[], CacheError, never>;
14
+ readonly isSubscribed: (awsAccountId: string, prId: string) => Effect.Effect<boolean, CacheError, never>;
15
+ }, never, SqlClient.SqlClient | EventsHub>;
16
+ }>;
17
+ export declare class SubscriptionRepo extends SubscriptionRepo_base {
18
+ }
19
+ export {};
20
+ //# sourceMappingURL=SubscriptionRepo.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SubscriptionRepo.d.ts","sourceRoot":"","sources":["../../../src/CacheService/repos/SubscriptionRepo.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,uBAAuB,CAAA;AAElD,OAAO,EAAE,MAAM,EAAU,MAAM,QAAQ,CAAA;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAE7C,OAAO,EAAE,SAAS,EAAc,MAAM,iBAAiB,CAAA;;;;2CAoDvB,MAAM,QAAQ,MAAM;6CAGlB,MAAM,QAAQ,MAAM;;;;;8CAKnB,MAAM,QAAQ,MAAM;;;AA/CvD,qBAAa,gBAAiB,SAAQ,qBAsDpC;CAAG"}
@@ -0,0 +1,49 @@
1
+ import * as SqlClient from "@effect/sql/SqlClient";
2
+ import * as SqlSchema from "@effect/sql/SqlSchema";
3
+ import { Effect, Schema } from "effect";
4
+ import { CacheError } from "../CacheError.js";
5
+ import { DatabaseLive } from "../Database.js";
6
+ import { EventsHub, RepoChange } from "../EventsHub.js";
7
+ const SubscriptionRow = Schema.Struct({
8
+ awsAccountId: Schema.String,
9
+ pullRequestId: Schema.String
10
+ });
11
+ const cacheError = (op) => (effect) => effect.pipe(Effect.mapError((cause) => new CacheError({ operation: `SubscriptionRepo.${op}`, cause })), Effect.withSpan(`SubscriptionRepo.${op}`, { captureStackTrace: false }));
12
+ export class SubscriptionRepo extends Effect.Service()("SubscriptionRepo", {
13
+ dependencies: [DatabaseLive, EventsHub.Default],
14
+ effect: Effect.gen(function* () {
15
+ const sql = yield* SqlClient.SqlClient;
16
+ const hub = yield* EventsHub;
17
+ const RequestPair = Schema.Struct({ awsAccountId: Schema.String, prId: Schema.String });
18
+ const subscribe_ = SqlSchema.void({
19
+ Request: RequestPair,
20
+ execute: (req) => sql `INSERT OR IGNORE INTO pr_subscriptions (aws_account_id, pull_request_id)
21
+ VALUES (${req.awsAccountId}, ${req.prId})`
22
+ });
23
+ const unsubscribe_ = SqlSchema.void({
24
+ Request: RequestPair,
25
+ execute: (req) => sql `DELETE FROM pr_subscriptions
26
+ WHERE aws_account_id = ${req.awsAccountId} AND pull_request_id = ${req.prId}`
27
+ });
28
+ const findAll_ = SqlSchema.findAll({
29
+ Result: SubscriptionRow,
30
+ Request: Schema.Void,
31
+ execute: () => sql `SELECT * FROM pr_subscriptions`
32
+ });
33
+ const isSubscribed_ = SqlSchema.findOne({
34
+ Result: Schema.Struct({ exists: Schema.Number }),
35
+ Request: RequestPair,
36
+ execute: (req) => sql `SELECT 1 AS "exists" FROM pr_subscriptions
37
+ WHERE aws_account_id = ${req.awsAccountId} AND pull_request_id = ${req.prId}`
38
+ });
39
+ const publish = hub.publish(RepoChange.Subscriptions());
40
+ return {
41
+ subscribe: (awsAccountId, prId) => subscribe_({ awsAccountId, prId }).pipe(Effect.tap(() => publish), cacheError("subscribe")),
42
+ unsubscribe: (awsAccountId, prId) => unsubscribe_({ awsAccountId, prId }).pipe(Effect.tap(() => publish), cacheError("unsubscribe")),
43
+ findAll: () => findAll_(undefined).pipe(cacheError("findAll")),
44
+ isSubscribed: (awsAccountId, prId) => isSubscribed_({ awsAccountId, prId }).pipe(Effect.map((o) => o._tag === "Some"), cacheError("isSubscribed"))
45
+ };
46
+ })
47
+ }) {
48
+ }
49
+ //# sourceMappingURL=SubscriptionRepo.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SubscriptionRepo.js","sourceRoot":"","sources":["../../../src/CacheService/repos/SubscriptionRepo.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,uBAAuB,CAAA;AAClD,OAAO,KAAK,SAAS,MAAM,uBAAuB,CAAA;AAClD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAEvD,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC;IACpC,YAAY,EAAE,MAAM,CAAC,MAAM;IAC3B,aAAa,EAAE,MAAM,CAAC,MAAM;CAC7B,CAAC,CAAA;AAEF,MAAM,UAAU,GAAG,CAAC,EAAU,EAAE,EAAE,CAAC,CAAU,MAA8B,EAAE,EAAE,CAC7E,MAAM,CAAC,IAAI,CACT,MAAM,CAAC,QAAQ,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,UAAU,CAAC,EAAE,SAAS,EAAE,oBAAoB,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC,EAC1F,MAAM,CAAC,QAAQ,CAAC,oBAAoB,EAAE,EAAE,EAAE,EAAE,iBAAiB,EAAE,KAAK,EAAE,CAAC,CACxE,CAAA;AAEH,MAAM,OAAO,gBAAiB,SAAQ,MAAM,CAAC,OAAO,EAAoB,CAAC,kBAAkB,EAAE;IAC3F,YAAY,EAAE,CAAC,YAAY,EAAE,SAAS,CAAC,OAAO,CAAC;IAC/C,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;QAC1B,MAAM,GAAG,GAAG,KAAK,CAAC,CA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AAC,YAAoB,EAAE,IAAY,EAAE,EAAE,CAChD,UAAU,CAAC,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC;YAE7F,WAAW,EAAE,CAAC,YAAoB,EAAE,IAAY,EAAE,EAAE,CAClD,YAAY,CAAC,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,EAAE,UAAU,CAAC,aAAa,CAAC,CAAC;YAEjG,OAAO,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,SAAiB,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;YAEtE,YAAY,EAAE,CAAC,YAAoB,EAAE,IAAY,EAAE,EAAE,CACnD,aAAa,CAAC,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CACxC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,MAAM,CAAC,EACpC,UAAU,CAAC,cAAc,CAAC,CAC3B;SACK,CAAA;IACZ,CAAC,CAAC;CACH,CAAC;CAAG"}
@@ -0,0 +1,14 @@
1
+ import * as SqlClient from "@effect/sql/SqlClient";
2
+ import { Effect, Option } from "effect";
3
+ import { CacheError } from "../CacheError.js";
4
+ declare const SyncMetadataRepo_base: Effect.Service.Class<SyncMetadataRepo, "SyncMetadataRepo", {
5
+ readonly dependencies: readonly [import("effect/Layer").Layer<SqlClient.SqlClient | import("@effect/sql-libsql/LibsqlClient").LibsqlClient, import("@effect/sql/SqlError").SqlError | import("effect/ConfigError").ConfigError | import("@effect/sql/Migrator").MigrationError, import("@effect/platform/FileSystem").FileSystem>];
6
+ readonly effect: Effect.Effect<{
7
+ readonly getLastSyncedAt: (accountId: string, region: string) => Effect.Effect<Option.Option<string>, CacheError, never>;
8
+ readonly update: (accountId: string, region: string) => Effect.Effect<void, CacheError, never>;
9
+ }, never, SqlClient.SqlClient>;
10
+ }>;
11
+ export declare class SyncMetadataRepo extends SyncMetadataRepo_base {
12
+ }
13
+ export {};
14
+ //# sourceMappingURL=SyncMetadataRepo.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SyncMetadataRepo.d.ts","sourceRoot":"","sources":["../../../src/CacheService/repos/SyncMetadataRepo.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,uBAAuB,CAAA;AAElD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAU,MAAM,QAAQ,CAAA;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;;;;8CAuCV,MAAM,UAAU,MAAM;qCAM/B,MAAM,UAAU,MAAM;;;AA3BhD,qBAAa,gBAAiB,SAAQ,qBA8BpC;CAAG"}
@@ -0,0 +1,36 @@
1
+ import * as SqlClient from "@effect/sql/SqlClient";
2
+ import * as SqlSchema from "@effect/sql/SqlSchema";
3
+ import { Effect, Option, Schema } from "effect";
4
+ import { CacheError } from "../CacheError.js";
5
+ import { DatabaseLive } from "../Database.js";
6
+ const SyncRow = Schema.Struct({
7
+ lastSyncedAt: Schema.String
8
+ });
9
+ const AccountRegion = Schema.Struct({
10
+ accountId: Schema.String,
11
+ region: Schema.String
12
+ });
13
+ const cacheError = (op) => (effect) => effect.pipe(Effect.mapError((cause) => new CacheError({ operation: `SyncMetadataRepo.${op}`, cause })), Effect.withSpan(`SyncMetadataRepo.${op}`, { captureStackTrace: false }));
14
+ export class SyncMetadataRepo extends Effect.Service()("SyncMetadataRepo", {
15
+ dependencies: [DatabaseLive],
16
+ effect: Effect.gen(function* () {
17
+ const sql = yield* SqlClient.SqlClient;
18
+ const getLastSyncedAt_ = SqlSchema.findOne({
19
+ Result: SyncRow,
20
+ Request: AccountRegion,
21
+ execute: (req) => sql `SELECT last_synced_at FROM sync_metadata
22
+ WHERE account_id = ${req.accountId} AND account_region = ${req.region}`
23
+ });
24
+ const update_ = SqlSchema.void({
25
+ Request: AccountRegion,
26
+ execute: (req) => sql `INSERT OR REPLACE INTO sync_metadata (account_id, account_region, last_synced_at)
27
+ VALUES (${req.accountId}, ${req.region}, datetime('now'))`
28
+ });
29
+ return {
30
+ getLastSyncedAt: (accountId, region) => getLastSyncedAt_({ accountId, region }).pipe(Effect.map(Option.map((r) => r.lastSyncedAt)), cacheError("getLastSyncedAt")),
31
+ update: (accountId, region) => update_({ accountId, region }).pipe(cacheError("update"))
32
+ };
33
+ })
34
+ }) {
35
+ }
36
+ //# sourceMappingURL=SyncMetadataRepo.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SyncMetadataRepo.js","sourceRoot":"","sources":["../../../src/CacheService/repos/SyncMetadataRepo.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,uBAAuB,CAAA;AAClD,OAAO,KAAK,SAAS,MAAM,uBAAuB,CAAA;AAClD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAE7C,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC;IAC5B,YAAY,EAAE,MAAM,CAAC,MAAM;CAC5B,CAAC,CAAA;AAEF,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC;IAClC,SAAS,EAAE,MAAM,CAAC,MAAM;IACxB,MAAM,EAAE,MAAM,CAAC,MAAM;CACtB,CAAC,CAAA;AAEF,MAAM,UAAU,GAAG,CAAC,EAAU,EAAE,EAAE,CAAC,CAAU,MAA8B,EAAE,EAAE,CAC7E,MAAM,CAAC,IAAI,CACT,MAAM,CAAC,QAAQ,CAAC,CAAC,KAAK,EAAE,EAAE,CAA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,OAAO,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;SAChG,CAAA;IACZ,CAAC,CAAC;CACH,CAAC;CAAG"}
@@ -5,5 +5,5 @@ import { FileSystem } from "@effect/platform";
5
5
  import { Effect } from "effect";
6
6
  import { ConfigError } from "../Errors.js";
7
7
  import { ConfigPaths } from "./internal.js";
8
- export declare const backup: Effect.Effect<string, ConfigError, ConfigPaths | FileSystem.FileSystem>;
8
+ export declare const backup: Effect.Effect<string, ConfigError, FileSystem.FileSystem | ConfigPaths>;
9
9
  //# sourceMappingURL=backup.d.ts.map
@@ -4,5 +4,5 @@
4
4
  import { FileSystem, Path } from "@effect/platform";
5
5
  import { Effect } from "effect";
6
6
  import { ConfigPaths } from "./internal.js";
7
- export declare const detectProfiles: Effect.Effect<import("./internal.js").DetectedProfile[], import("../Errors.ts").ProfileDetectionError, ConfigPaths | FileSystem.FileSystem | Path.Path>;
7
+ export declare const detectProfiles: Effect.Effect<import("./internal.js").DetectedProfile[], import("../Errors.ts").ProfileDetectionError, FileSystem.FileSystem | ConfigPaths | Path.Path>;
8
8
  //# sourceMappingURL=detectProfiles.d.ts.map
@@ -6,6 +6,7 @@
6
6
  */
7
7
  import type { FileSystem, Path } from "@effect/platform";
8
8
  import { Context, Effect, Layer } from "effect";
9
+ import { EventsHub } from "../CacheService/EventsHub.js";
9
10
  import { ConfigError, ProfileDetectionError } from "../Errors.js";
10
11
  import type { ConfigParseError } from "../Errors.js";
11
12
  import type { DetectedProfile, TuiConfig } from "./internal.js";
@@ -23,5 +24,5 @@ declare const ConfigService_base: Context.TagClass<ConfigService, "@knpkv/codeco
23
24
  }>;
24
25
  export declare class ConfigService extends ConfigService_base {
25
26
  }
26
- export declare const ConfigServiceLive: Layer.Layer<ConfigService, never, FileSystem.FileSystem | Path.Path>;
27
+ export declare const ConfigServiceLive: Layer.Layer<ConfigService, never, FileSystem.FileSystem | EventsHub | Path.Path>;
27
28
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ConfigService/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AACxD,OAAO,EAAU,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAA;AACvD,OAAO,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAA;AACjE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAGpD,OAAO,KAAK,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAK/D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAA;AAG3D,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AACzE,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAA;;mBASnC,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,WAAW,GAAG,gBAAgB,CAAC;mBACxD,CAAC,MAAM,EAAE,SAAS,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,WAAW,CAAC;6BAC7C,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,eAAe,CAAC,EAAE,qBAAqB,CAAC;4BACrE,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC;qBACzC,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC;oBACnC,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,WAAW,GAAG,qBAAqB,CAAC;uBAC1D,MAAM,CAAC,MAAM,CAAC,sBAAsB,EAAE,WAAW,CAAC;;AATzE,qBAAa,aAAc,SAAQ,kBAWhC;CAAG;AAoCN,eAAO,MAAM,iBAAiB,sEAqBQ,CAAA"}
1
+ {"version":3,"file":"index.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