@omnixal/openclaw-nats-plugin 0.2.16 → 0.2.17

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.
@@ -36,11 +36,14 @@ export class RouterRepository extends BaseService {
36
36
  .insert(eventRoutes)
37
37
  .values(route)
38
38
  .onConflictDoUpdate({
39
- target: eventRoutes.pattern,
39
+ target: eventRoutes.name,
40
40
  set: {
41
+ pattern: sql`excluded.pattern`,
41
42
  target: sql`excluded.target`,
42
43
  priority: sql`excluded.priority`,
43
44
  enabled: sql`excluded.enabled`,
45
+ filter: sql`excluded.filter`,
46
+ customPayload: sql`excluded.custom_payload`,
44
47
  },
45
48
  })
46
49
  .returning();
@@ -49,7 +52,7 @@ export class RouterRepository extends BaseService {
49
52
  return { route: result, created };
50
53
  }
51
54
 
52
- async updateById(id: string, fields: Partial<Pick<DbEventRoute, 'target' | 'priority' | 'enabled'>>): Promise<DbEventRoute | null> {
55
+ async updateById(id: string, fields: Partial<Pick<DbEventRoute, 'target' | 'priority' | 'enabled' | 'customPayload' | 'filter'>>): Promise<DbEventRoute | null> {
53
56
  const [result] = await this.db.update(eventRoutes)
54
57
  .set(fields)
55
58
  .where(eq(eventRoutes.id, id))
@@ -68,13 +71,21 @@ export class RouterRepository extends BaseService {
68
71
  .where(eq(eventRoutes.id, routeId));
69
72
  }
70
73
 
74
+ async incrementFilterDropCount(routeId: string): Promise<void> {
75
+ await this.db.update(eventRoutes)
76
+ .set({
77
+ filterDropCount: sql`${eventRoutes.filterDropCount} + 1`,
78
+ })
79
+ .where(eq(eventRoutes.id, routeId));
80
+ }
81
+
71
82
  async deleteById(id: string): Promise<boolean> {
72
83
  const result = await this.db.delete(eventRoutes).where(eq(eventRoutes.id, id)).returning();
73
84
  return result.length > 0;
74
85
  }
75
86
 
76
- async deleteByPattern(pattern: string): Promise<boolean> {
77
- const result = await this.db.delete(eventRoutes).where(eq(eventRoutes.pattern, pattern)).returning();
87
+ async deleteByName(name: string): Promise<boolean> {
88
+ const result = await this.db.delete(eventRoutes).where(eq(eventRoutes.name, name)).returning();
78
89
  return result.length > 0;
79
90
  }
80
91
 
@@ -1,6 +1,7 @@
1
1
  import { Service, BaseService } from '@onebun/core';
2
2
  import { RouterRepository } from './router.repository';
3
3
  import type { DbEventRoute } from '../db/schema';
4
+ import type { FilterExpression } from '../route-filter/filter-expression';
4
5
  import { ulid } from 'ulid';
5
6
 
6
7
  @Service()
@@ -40,21 +41,27 @@ export class RouterService extends BaseService {
40
41
  }
41
42
 
42
43
  async subscribe(
44
+ name: string,
43
45
  pattern: string,
44
46
  target: string = 'main',
45
47
  priority: number = 5,
48
+ filter?: FilterExpression | null,
49
+ customPayload?: unknown,
46
50
  ): Promise<{ route: DbEventRoute; created: boolean }> {
47
51
  return this.repo.upsert({
48
52
  id: ulid(),
53
+ name,
49
54
  pattern,
50
55
  target,
51
56
  enabled: true,
52
57
  priority,
58
+ filter: filter ?? null,
59
+ customPayload: customPayload ?? null,
53
60
  createdAt: new Date(),
54
61
  });
55
62
  }
56
63
 
57
- async updateById(id: string, fields: { target?: string; priority?: number; enabled?: boolean }): Promise<DbEventRoute | null> {
64
+ async updateById(id: string, fields: { target?: string; priority?: number; enabled?: boolean; customPayload?: unknown; filter?: FilterExpression | null }): Promise<DbEventRoute | null> {
58
65
  return this.repo.updateById(id, fields);
59
66
  }
60
67
 
@@ -62,8 +69,12 @@ export class RouterService extends BaseService {
62
69
  await this.repo.recordDelivery(routeId, subject, lagMs);
63
70
  }
64
71
 
65
- async unsubscribe(pattern: string): Promise<boolean> {
66
- return this.repo.deleteByPattern(pattern);
72
+ async incrementFilterDropCount(routeId: string): Promise<void> {
73
+ await this.repo.incrementFilterDropCount(routeId);
74
+ }
75
+
76
+ async unsubscribeByName(name: string): Promise<boolean> {
77
+ return this.repo.deleteByName(name);
67
78
  }
68
79
 
69
80
  async deleteById(id: string): Promise<boolean> {
@@ -18,10 +18,24 @@ export const markDeliveredBodySchema = type({
18
18
 
19
19
  export type MarkDeliveredBody = typeof markDeliveredBodySchema.infer;
20
20
 
21
+ export const filterConditionSchema = type({
22
+ field: 'string',
23
+ op: "'eq' | 'neq' | 'gt' | 'gte' | 'lt' | 'lte' | 'in' | 'nin' | 'contains' | 'exists'",
24
+ value: 'unknown',
25
+ });
26
+
27
+ export const filterExpressionSchema = type({
28
+ logic: "'and' | 'or'",
29
+ conditions: filterConditionSchema.array(),
30
+ });
31
+
21
32
  export const createRouteBodySchema = type({
22
33
  pattern: 'string',
34
+ 'name?': 'string',
23
35
  'target?': 'string',
24
36
  'priority?': 'number',
37
+ 'payload?': 'unknown',
38
+ 'filter?': filterExpressionSchema,
25
39
  });
26
40
 
27
41
  export type CreateRouteBody = typeof createRouteBodySchema.infer;
@@ -40,6 +54,8 @@ export const updateRouteBodySchema = type({
40
54
  'target?': 'string',
41
55
  'priority?': 'number',
42
56
  'enabled?': 'boolean',
57
+ 'payload?': 'unknown',
58
+ 'filter?': 'unknown',
43
59
  });
44
60
 
45
61
  export type UpdateRouteBody = typeof updateRouteBodySchema.infer;