aboutsummaryrefslogtreecommitdiffstats
path: root/packages/trpc/models/lists.ts
diff options
context:
space:
mode:
authorMohamed Bassem <me@mbassem.com>2025-04-27 00:02:20 +0100
committerGitHub <noreply@github.com>2025-04-27 00:02:20 +0100
commit136f126296af65f50da598d084d1485c0e40437a (patch)
tree2725c7932ebbcb9b48b5af98eb9b72329a400260 /packages/trpc/models/lists.ts
parentca47be7fe7be128f459c37614a04902a873fe289 (diff)
downloadkarakeep-136f126296af65f50da598d084d1485c0e40437a.tar.zst
feat: Implement generic rule engine (#1318)
* Add schema for the new rule engine * Add rule engine backend logic * Implement the worker logic and event firing * Implement the UI changesfor the rule engine * Ensure that when a referenced list or tag are deleted, the corresponding event/action is * Dont show smart lists in rule engine events * Add privacy validations for attached tag and list ids * Move the rules logic into a models
Diffstat (limited to 'packages/trpc/models/lists.ts')
-rw-r--r--packages/trpc/models/lists.ts19
1 files changed, 17 insertions, 2 deletions
diff --git a/packages/trpc/models/lists.ts b/packages/trpc/models/lists.ts
index 8072060f..4da127d2 100644
--- a/packages/trpc/models/lists.ts
+++ b/packages/trpc/models/lists.ts
@@ -5,6 +5,7 @@ import { z } from "zod";
import { SqliteError } from "@karakeep/db";
import { bookmarkLists, bookmarksInLists } from "@karakeep/db/schema";
+import { triggerRuleEngineOnEvent } from "@karakeep/shared/queues";
import { parseSearchQuery } from "@karakeep/shared/searchQueryParser";
import {
ZBookmarkList,
@@ -117,7 +118,9 @@ export abstract class List implements PrivacyAware {
}
}
- async update(input: z.infer<typeof zEditBookmarkListSchemaWithValidation>) {
+ async update(
+ input: z.infer<typeof zEditBookmarkListSchemaWithValidation>,
+ ): Promise<void> {
const result = await this.ctx.db
.update(bookmarkLists)
.set({
@@ -137,7 +140,7 @@ export abstract class List implements PrivacyAware {
if (result.length == 0) {
throw new TRPCError({ code: "NOT_FOUND" });
}
- return result[0];
+ this.list = result[0];
}
abstract get type(): "manual" | "smart";
@@ -248,6 +251,12 @@ export class ManualList extends List {
listId: this.list.id,
bookmarkId,
});
+ await triggerRuleEngineOnEvent(bookmarkId, [
+ {
+ type: "addedToList",
+ listId: this.list.id,
+ },
+ ]);
} catch (e) {
if (e instanceof SqliteError) {
if (e.code == "SQLITE_CONSTRAINT_PRIMARYKEY") {
@@ -279,6 +288,12 @@ export class ManualList extends List {
message: `Bookmark ${bookmarkId} is already not in list ${this.list.id}`,
});
}
+ await triggerRuleEngineOnEvent(bookmarkId, [
+ {
+ type: "removedFromList",
+ listId: this.list.id,
+ },
+ ]);
}
async update(input: z.infer<typeof zEditBookmarkListSchemaWithValidation>) {