@knpkv/codecommit-core 0.3.0 → 0.5.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.
- package/README.md +66 -0
- package/dist/AwsClient/createPullRequest.d.ts +1 -6
- package/dist/AwsClient/createPullRequest.d.ts.map +1 -1
- package/dist/AwsClient/createPullRequest.js +3 -11
- package/dist/AwsClient/createPullRequest.js.map +1 -1
- package/dist/AwsClient/getCallerIdentity.d.ts +5 -6
- package/dist/AwsClient/getCallerIdentity.d.ts.map +1 -1
- package/dist/AwsClient/getCallerIdentity.js +7 -12
- package/dist/AwsClient/getCallerIdentity.js.map +1 -1
- package/dist/AwsClient/getCommentsForPullRequest.d.ts +1 -6
- package/dist/AwsClient/getCommentsForPullRequest.d.ts.map +1 -1
- package/dist/AwsClient/getCommentsForPullRequest.js +9 -16
- package/dist/AwsClient/getCommentsForPullRequest.js.map +1 -1
- package/dist/AwsClient/getPullRequest.d.ts +2 -7
- package/dist/AwsClient/getPullRequest.d.ts.map +1 -1
- package/dist/AwsClient/getPullRequest.js +15 -28
- package/dist/AwsClient/getPullRequest.js.map +1 -1
- package/dist/AwsClient/getPullRequests.d.ts.map +1 -1
- package/dist/AwsClient/getPullRequests.js +18 -15
- package/dist/AwsClient/getPullRequests.js.map +1 -1
- package/dist/AwsClient/index.d.ts +3 -2
- package/dist/AwsClient/index.d.ts.map +1 -1
- package/dist/AwsClient/index.js.map +1 -1
- package/dist/AwsClient/internal.d.ts +47 -11
- package/dist/AwsClient/internal.d.ts.map +1 -1
- package/dist/AwsClient/internal.js +38 -9
- package/dist/AwsClient/internal.js.map +1 -1
- package/dist/AwsClient/listBranches.d.ts +1 -6
- package/dist/AwsClient/listBranches.d.ts.map +1 -1
- package/dist/AwsClient/listBranches.js +3 -11
- package/dist/AwsClient/listBranches.js.map +1 -1
- package/dist/AwsClient/updatePullRequestDescription.d.ts +1 -6
- package/dist/AwsClient/updatePullRequestDescription.d.ts.map +1 -1
- package/dist/AwsClient/updatePullRequestDescription.js +3 -11
- package/dist/AwsClient/updatePullRequestDescription.js.map +1 -1
- package/dist/AwsClient/updatePullRequestTitle.d.ts +1 -6
- package/dist/AwsClient/updatePullRequestTitle.d.ts.map +1 -1
- package/dist/AwsClient/updatePullRequestTitle.js +3 -11
- package/dist/AwsClient/updatePullRequestTitle.js.map +1 -1
- package/dist/CacheService/CacheError.d.ts +21 -0
- package/dist/CacheService/CacheError.d.ts.map +1 -0
- package/dist/CacheService/CacheError.js +17 -0
- package/dist/CacheService/CacheError.js.map +1 -0
- package/dist/CacheService/Database.d.ts +13 -0
- package/dist/CacheService/Database.d.ts.map +1 -0
- package/dist/CacheService/Database.js +38 -0
- package/dist/CacheService/Database.js.map +1 -0
- package/dist/CacheService/EventsHub.d.ts +183 -0
- package/dist/CacheService/EventsHub.d.ts.map +1 -0
- package/dist/CacheService/EventsHub.js +22 -0
- package/dist/CacheService/EventsHub.js.map +1 -0
- package/dist/CacheService/diff.d.ts +28 -0
- package/dist/CacheService/diff.d.ts.map +1 -0
- package/dist/CacheService/diff.js +102 -0
- package/dist/CacheService/diff.js.map +1 -0
- package/dist/CacheService/index.d.ts +19 -0
- package/dist/CacheService/index.d.ts.map +1 -0
- package/dist/CacheService/index.js +16 -0
- package/dist/CacheService/index.js.map +1 -0
- package/dist/CacheService/migrations/0001_initial.d.ts +5 -0
- package/dist/CacheService/migrations/0001_initial.d.ts.map +1 -0
- package/dist/CacheService/migrations/0001_initial.js +72 -0
- package/dist/CacheService/migrations/0001_initial.js.map +1 -0
- package/dist/CacheService/migrations/0002_indexes.d.ts +5 -0
- package/dist/CacheService/migrations/0002_indexes.d.ts.map +1 -0
- package/dist/CacheService/migrations/0002_indexes.js +7 -0
- package/dist/CacheService/migrations/0002_indexes.js.map +1 -0
- package/dist/CacheService/migrations/0003_add_health_score.d.ts +5 -0
- package/dist/CacheService/migrations/0003_add_health_score.d.ts.map +1 -0
- package/dist/CacheService/migrations/0003_add_health_score.js +4 -0
- package/dist/CacheService/migrations/0003_add_health_score.js.map +1 -0
- package/dist/CacheService/migrations/0004_unify_notifications.d.ts +5 -0
- package/dist/CacheService/migrations/0004_unify_notifications.d.ts.map +1 -0
- package/dist/CacheService/migrations/0004_unify_notifications.js +7 -0
- package/dist/CacheService/migrations/0004_unify_notifications.js.map +1 -0
- package/dist/CacheService/migrations/0005_add_sandboxes.d.ts +5 -0
- package/dist/CacheService/migrations/0005_add_sandboxes.d.ts.map +1 -0
- package/dist/CacheService/migrations/0005_add_sandboxes.js +23 -0
- package/dist/CacheService/migrations/0005_add_sandboxes.js.map +1 -0
- package/dist/CacheService/migrations/0006_sandbox_logs.d.ts +5 -0
- package/dist/CacheService/migrations/0006_sandbox_logs.d.ts.map +1 -0
- package/dist/CacheService/migrations/0006_sandbox_logs.js +7 -0
- package/dist/CacheService/migrations/0006_sandbox_logs.js.map +1 -0
- package/dist/CacheService/repos/CommentRepo.d.ts +16 -0
- package/dist/CacheService/repos/CommentRepo.d.ts.map +1 -0
- package/dist/CacheService/repos/CommentRepo.js +42 -0
- package/dist/CacheService/repos/CommentRepo.js.map +1 -0
- package/dist/CacheService/repos/NotificationRepo.d.ts +48 -0
- package/dist/CacheService/repos/NotificationRepo.d.ts.map +1 -0
- package/dist/CacheService/repos/NotificationRepo.js +128 -0
- package/dist/CacheService/repos/NotificationRepo.js.map +1 -0
- package/dist/CacheService/repos/PullRequestRepo.d.ts +112 -0
- package/dist/CacheService/repos/PullRequestRepo.d.ts.map +1 -0
- package/dist/CacheService/repos/PullRequestRepo.js +146 -0
- package/dist/CacheService/repos/PullRequestRepo.js.map +1 -0
- package/dist/CacheService/repos/SandboxRepo.d.ts +116 -0
- package/dist/CacheService/repos/SandboxRepo.d.ts.map +1 -0
- package/dist/CacheService/repos/SandboxRepo.js +88 -0
- package/dist/CacheService/repos/SandboxRepo.js.map +1 -0
- package/dist/CacheService/repos/SubscriptionRepo.d.ts +20 -0
- package/dist/CacheService/repos/SubscriptionRepo.d.ts.map +1 -0
- package/dist/CacheService/repos/SubscriptionRepo.js +49 -0
- package/dist/CacheService/repos/SubscriptionRepo.js.map +1 -0
- package/dist/CacheService/repos/SyncMetadataRepo.d.ts +14 -0
- package/dist/CacheService/repos/SyncMetadataRepo.d.ts.map +1 -0
- package/dist/CacheService/repos/SyncMetadataRepo.js +36 -0
- package/dist/CacheService/repos/SyncMetadataRepo.js.map +1 -0
- package/dist/ConfigService/backup.d.ts +1 -1
- package/dist/ConfigService/detectProfiles.d.ts +1 -1
- package/dist/ConfigService/index.d.ts +3 -2
- package/dist/ConfigService/index.d.ts.map +1 -1
- package/dist/ConfigService/index.js +4 -2
- package/dist/ConfigService/index.js.map +1 -1
- package/dist/ConfigService/internal.d.ts +104 -0
- package/dist/ConfigService/internal.d.ts.map +1 -1
- package/dist/ConfigService/internal.js +18 -1
- package/dist/ConfigService/internal.js.map +1 -1
- package/dist/ConfigService/load.d.ts +18 -1
- package/dist/ConfigService/load.d.ts.map +1 -1
- package/dist/ConfigService/load.js +12 -3
- package/dist/ConfigService/load.js.map +1 -1
- package/dist/ConfigService/reset.d.ts.map +1 -1
- package/dist/ConfigService/reset.js +5 -2
- package/dist/ConfigService/reset.js.map +1 -1
- package/dist/ConfigService/save.d.ts +1 -1
- package/dist/ConfigService/validate.d.ts +1 -1
- package/dist/DateUtils.d.ts +1 -1
- package/dist/DateUtils.d.ts.map +1 -1
- package/dist/DateUtils.js +2 -2
- package/dist/DateUtils.js.map +1 -1
- package/dist/Domain.d.ts +251 -10
- package/dist/Domain.d.ts.map +1 -1
- package/dist/Domain.js +55 -5
- package/dist/Domain.js.map +1 -1
- package/dist/Errors.d.ts +28 -1
- package/dist/Errors.d.ts.map +1 -1
- package/dist/Errors.js +22 -1
- package/dist/Errors.js.map +1 -1
- package/dist/HealthScore.d.ts.map +1 -1
- package/dist/HealthScore.js +1 -3
- package/dist/HealthScore.js.map +1 -1
- package/dist/PRService/index.d.ts +46 -18
- package/dist/PRService/index.d.ts.map +1 -1
- package/dist/PRService/index.js +58 -27
- package/dist/PRService/index.js.map +1 -1
- package/dist/PRService/internal.d.ts +86 -1
- package/dist/PRService/internal.d.ts.map +1 -1
- package/dist/PRService/internal.js +106 -1
- package/dist/PRService/internal.js.map +1 -1
- package/dist/PRService/refresh.d.ts +10 -4
- package/dist/PRService/refresh.d.ts.map +1 -1
- package/dist/PRService/refresh.js +30 -89
- package/dist/PRService/refresh.js.map +1 -1
- package/dist/PRService/refreshEnrich.d.ts +15 -0
- package/dist/PRService/refreshEnrich.d.ts.map +1 -0
- package/dist/PRService/refreshEnrich.js +72 -0
- package/dist/PRService/refreshEnrich.js.map +1 -0
- package/dist/PRService/refreshFetch.d.ts +20 -0
- package/dist/PRService/refreshFetch.d.ts.map +1 -0
- package/dist/PRService/refreshFetch.js +78 -0
- package/dist/PRService/refreshFetch.js.map +1 -0
- package/dist/PRService/refreshResolve.d.ts +29 -0
- package/dist/PRService/refreshResolve.d.ts.map +1 -0
- package/dist/PRService/refreshResolve.js +84 -0
- package/dist/PRService/refreshResolve.js.map +1 -0
- package/dist/PRService/refreshScore.d.ts +9 -0
- package/dist/PRService/refreshScore.d.ts.map +1 -0
- package/dist/PRService/refreshScore.js +24 -0
- package/dist/PRService/refreshScore.js.map +1 -0
- package/dist/PRService/refreshSinglePR.d.ts +13 -0
- package/dist/PRService/refreshSinglePR.d.ts.map +1 -0
- package/dist/PRService/refreshSinglePR.js +102 -0
- package/dist/PRService/refreshSinglePR.js.map +1 -0
- package/dist/PRService/setAllAccounts.d.ts +1 -3
- package/dist/PRService/setAllAccounts.d.ts.map +1 -1
- package/dist/PRService/setAllAccounts.js +2 -2
- package/dist/PRService/setAllAccounts.js.map +1 -1
- package/dist/PRService/toggleAccount.d.ts +1 -3
- package/dist/PRService/toggleAccount.d.ts.map +1 -1
- package/dist/PRService/toggleAccount.js +2 -2
- package/dist/PRService/toggleAccount.js.map +1 -1
- package/dist/SandboxService/DockerService.d.ts +57 -0
- package/dist/SandboxService/DockerService.d.ts.map +1 -0
- package/dist/SandboxService/DockerService.js +83 -0
- package/dist/SandboxService/DockerService.js.map +1 -0
- package/dist/SandboxService/PluginService.d.ts +38 -0
- package/dist/SandboxService/PluginService.d.ts.map +1 -0
- package/dist/SandboxService/PluginService.js +26 -0
- package/dist/SandboxService/PluginService.js.map +1 -0
- package/dist/SandboxService/SandboxService.d.ts +102 -0
- package/dist/SandboxService/SandboxService.d.ts.map +1 -0
- package/dist/SandboxService/SandboxService.js +272 -0
- package/dist/SandboxService/SandboxService.js.map +1 -0
- package/dist/SandboxService/index.d.ts +13 -0
- package/dist/SandboxService/index.d.ts.map +1 -0
- package/dist/SandboxService/index.js +10 -0
- package/dist/SandboxService/index.js.map +1 -0
- package/dist/SandboxService/plugins/ClaudeCodePlugin.d.ts +18 -0
- package/dist/SandboxService/plugins/ClaudeCodePlugin.d.ts.map +1 -0
- package/dist/SandboxService/plugins/ClaudeCodePlugin.js +24 -0
- package/dist/SandboxService/plugins/ClaudeCodePlugin.js.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/package.json +4 -1
- package/dist/NotificationsService.d.ts +0 -46
- package/dist/NotificationsService.d.ts.map +0 -1
- package/dist/NotificationsService.js +0 -57
- package/dist/NotificationsService.js.map +0 -1
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as SqlClient from "@effect/sql/SqlClient";
|
|
2
|
+
import { Effect, Option } from "effect";
|
|
3
|
+
import type { PRCommentLocation } from "../../Domain.js";
|
|
4
|
+
import { CacheError } from "../CacheError.js";
|
|
5
|
+
import { EventsHub } from "../EventsHub.js";
|
|
6
|
+
declare const CommentRepo_base: Effect.Service.Class<CommentRepo, "CommentRepo", {
|
|
7
|
+
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>];
|
|
8
|
+
readonly effect: Effect.Effect<{
|
|
9
|
+
readonly find: (awsAccountId: string, prId: string) => Effect.Effect<Option.Option<readonly PRCommentLocation[]>, CacheError, never>;
|
|
10
|
+
readonly upsert: (awsAccountId: string, prId: string, locationsJson: string) => Effect.Effect<void, CacheError, never>;
|
|
11
|
+
}, never, SqlClient.SqlClient | EventsHub>;
|
|
12
|
+
}>;
|
|
13
|
+
export declare class CommentRepo extends CommentRepo_base {
|
|
14
|
+
}
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=CommentRepo.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CommentRepo.d.ts","sourceRoot":"","sources":["../../../src/CacheService/repos/CommentRepo.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,uBAAuB,CAAA;AAElD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAU,MAAM,QAAQ,CAAA;AAC/C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AAExD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAE7C,OAAO,EAAE,SAAS,EAAc,MAAM,iBAAiB,CAAA;;;;sCAsC5B,MAAM,QAAQ,MAAM;wCAelB,MAAM,QAAQ,MAAM,iBAAiB,MAAM;;;AAvCxE,qBAAa,WAAY,SAAQ,gBA2C/B;CAAG"}
|
|
@@ -0,0 +1,42 @@
|
|
|
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 { PRCommentLocationJson } from "../../Domain.js";
|
|
5
|
+
import { CacheError } from "../CacheError.js";
|
|
6
|
+
import { DatabaseLive } from "../Database.js";
|
|
7
|
+
import { EventsHub, RepoChange } from "../EventsHub.js";
|
|
8
|
+
const CommentRow = Schema.Struct({
|
|
9
|
+
locationsJson: Schema.String
|
|
10
|
+
});
|
|
11
|
+
const LocationsFromJson = Schema.parseJson(Schema.Array(PRCommentLocationJson));
|
|
12
|
+
const cacheError = (op) => (effect) => effect.pipe(Effect.mapError((cause) => new CacheError({ operation: `CommentRepo.${op}`, cause })), Effect.withSpan(`CommentRepo.${op}`, { captureStackTrace: false }));
|
|
13
|
+
export class CommentRepo extends Effect.Service()("CommentRepo", {
|
|
14
|
+
dependencies: [DatabaseLive, EventsHub.Default],
|
|
15
|
+
effect: Effect.gen(function* () {
|
|
16
|
+
const sql = yield* SqlClient.SqlClient;
|
|
17
|
+
const hub = yield* EventsHub;
|
|
18
|
+
const find_ = SqlSchema.findOne({
|
|
19
|
+
Result: CommentRow,
|
|
20
|
+
Request: Schema.Struct({ awsAccountId: Schema.String, pullRequestId: Schema.String }),
|
|
21
|
+
execute: (req) => sql `SELECT locations_json FROM pr_comments
|
|
22
|
+
WHERE aws_account_id = ${req.awsAccountId}
|
|
23
|
+
AND pull_request_id = ${req.pullRequestId}`
|
|
24
|
+
});
|
|
25
|
+
const upsert_ = (awsAccountId, prId, locationsJson) => sql `INSERT OR REPLACE INTO pr_comments
|
|
26
|
+
(aws_account_id, pull_request_id, locations_json, fetched_at)
|
|
27
|
+
VALUES (${awsAccountId}, ${prId}, ${locationsJson}, datetime('now'))
|
|
28
|
+
`.pipe(Effect.asVoid);
|
|
29
|
+
const publish = hub.publish(RepoChange.Comments());
|
|
30
|
+
return {
|
|
31
|
+
find: (awsAccountId, prId) => find_({ awsAccountId, pullRequestId: prId }).pipe(Effect.flatMap(Option.match({
|
|
32
|
+
onNone: () => Effect.succeed(Option.none()),
|
|
33
|
+
onSome: (r) => Schema.decodeUnknown(LocationsFromJson)(r.locationsJson).pipe(
|
|
34
|
+
// PRCommentLocationJson is structurally compatible with PRCommentLocation for diff/count
|
|
35
|
+
Effect.map((decoded) => Option.some(decoded)), Effect.catchAll(() => Effect.succeed(Option.some([]))))
|
|
36
|
+
})), cacheError("find")),
|
|
37
|
+
upsert: (awsAccountId, prId, locationsJson) => upsert_(awsAccountId, prId, locationsJson).pipe(Effect.tap(() => publish), cacheError("upsert"))
|
|
38
|
+
};
|
|
39
|
+
})
|
|
40
|
+
}) {
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=CommentRepo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CommentRepo.js","sourceRoot":"","sources":["../../../src/CacheService/repos/CommentRepo.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;AAE/C,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAA;AACvD,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,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC;IAC/B,aAAa,EAAE,MAAM,CAAC,MAAM;CAC7B,CAAC,CAAA;AAEF,MAAM,iBAAiB,GAAG,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAC,CAAA;AAE/E,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,eAAe,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC,EACrF,MAAM,CAAC,QAAQ,CA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AC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,EAAoC,CAAC;gBAC7E,MAAM,EAAE,CAAC,CAAC,EAAE,EAAE,CACZ,MAAM,CAAC,aAAa,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,IAAI;gBAC3D,yFAAyF;gBACzF,MAAM,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,OAAsD,CAAC,CAAC,EAC5F,MAAM,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAmC,EAAE,CAAC,CAAC,CAAC,CACzF;aACJ,CAAC,CACH,EACD,UAAU,CAAC,MAAM,CAAC,CACnB;YACH,MAAM,EAAE,CAAC,YAAoB,EAAE,IAAY,EAAE,aAAqB,EAAE,EAAE,CACpE,OAAO,CAAC,YAAY,EAAE,IAAI,EAAE,aAAa,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAC;SAC1F,CAAA;IACZ,CAAC,CAAC;CACH,CAAC;CAAG"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import * as SqlClient from "@effect/sql/SqlClient";
|
|
2
|
+
import { Effect, Schema } from "effect";
|
|
3
|
+
import { CacheError } from "../CacheError.js";
|
|
4
|
+
import type { NewNotification } from "../diff.js";
|
|
5
|
+
import { EventsHub } from "../EventsHub.js";
|
|
6
|
+
declare const NotificationRow: Schema.Struct<{
|
|
7
|
+
id: typeof Schema.Number;
|
|
8
|
+
pullRequestId: typeof Schema.String;
|
|
9
|
+
awsAccountId: typeof Schema.String;
|
|
10
|
+
type: typeof Schema.String;
|
|
11
|
+
message: typeof Schema.String;
|
|
12
|
+
title: typeof Schema.String;
|
|
13
|
+
profile: typeof Schema.String;
|
|
14
|
+
createdAt: typeof Schema.String;
|
|
15
|
+
read: typeof Schema.Number;
|
|
16
|
+
}>;
|
|
17
|
+
export type NotificationRow = typeof NotificationRow.Type;
|
|
18
|
+
export type { NewNotification };
|
|
19
|
+
export interface PaginatedNotifications {
|
|
20
|
+
readonly items: ReadonlyArray<NotificationRow>;
|
|
21
|
+
readonly nextCursor?: number;
|
|
22
|
+
}
|
|
23
|
+
declare const NotificationRepo_base: Effect.Service.Class<NotificationRepo, "NotificationRepo", {
|
|
24
|
+
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>];
|
|
25
|
+
readonly effect: Effect.Effect<{
|
|
26
|
+
readonly findAll: (opts?: {
|
|
27
|
+
readonly unreadOnly?: boolean;
|
|
28
|
+
readonly limit?: number;
|
|
29
|
+
readonly cursor?: number;
|
|
30
|
+
readonly filter?: "system" | "prs";
|
|
31
|
+
}) => Effect.Effect<PaginatedNotifications, CacheError>;
|
|
32
|
+
readonly add: (n: NewNotification) => Effect.Effect<void, CacheError, never>;
|
|
33
|
+
readonly addSystem: (n: {
|
|
34
|
+
readonly type: string;
|
|
35
|
+
readonly title: string;
|
|
36
|
+
readonly message: string;
|
|
37
|
+
readonly profile?: string;
|
|
38
|
+
readonly deduplicate?: boolean;
|
|
39
|
+
}) => Effect.Effect<void, CacheError, never>;
|
|
40
|
+
readonly markRead: (id: number) => Effect.Effect<void, CacheError, never>;
|
|
41
|
+
readonly markUnread: (id: number) => Effect.Effect<void, CacheError, never>;
|
|
42
|
+
readonly markAllRead: () => Effect.Effect<void, CacheError, never>;
|
|
43
|
+
readonly unreadCount: () => Effect.Effect<number, CacheError, never>;
|
|
44
|
+
}, never, SqlClient.SqlClient | EventsHub>;
|
|
45
|
+
}>;
|
|
46
|
+
export declare class NotificationRepo extends NotificationRepo_base {
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=NotificationRepo.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NotificationRepo.d.ts","sourceRoot":"","sources":["../../../src/CacheService/repos/NotificationRepo.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,uBAAuB,CAAA;AAElD,OAAO,EAAgB,MAAM,EAAU,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAE7C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AACjD,OAAO,EAAE,SAAS,EAAc,MAAM,iBAAiB,CAAA;AAEvD,QAAA,MAAM,eAAe;;;;;;;;;;EAUnB,CAAA;AAEF,MAAM,MAAM,eAAe,GAAG,OAAO,eAAe,CAAC,IAAI,CAAA;AACzD,YAAY,EAAE,eAAe,EAAE,CAAA;AAM/B,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC,eAAe,CAAC,CAAA;IAC9C,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAC7B;;;;kCAsFsB;YACf,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAA;YAC7B,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAA;YACvB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;YACxB,QAAQ,CAAC,MAAM,CAAC,EAAE,QAAQ,GAAG,KAAK,CAAA;SACnC,KAAG,MAAM,CAAC,MAAM,CAAC,sBAAsB,EAAE,UAAU,CAAC;0BAoB5C,eAAe;gCAET;YACb,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;YACrB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;YACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;YACxB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAA;YACzB,QAAQ,CAAC,WAAW,CAAC,EAAE,OAAO,CAAA;SAC/B;gCAwBc,MAAM;kCAEJ,MAAM;;;;;AAhI7B,qBAAa,gBAAiB,SAAQ,qBA2IpC;CAAG"}
|
|
@@ -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/F,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;IAClD,OAAO,GAAG,CA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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,mBAAmB,CAAA;AAC1C,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,cAAc,EAAE,SAAS,EAAE,aAAa,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAC7G,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,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,CAAC;IAC7C,EAAE,EAAE,aAAa;IACjB,YAAY,EAAE,MAAM,CAAC,MAAM;IAC3B,cAAc,EAAE,cAAc;IAC9B,aAAa,EAAE,SAAS;IACxB,KAAK,EAAE,MAAM,CAAC,MAAM;IACpB,WAAW,EAAE,MAAM,C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