@agentbadge/database 0.6.6 → 0.6.7

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.
@@ -25,6 +25,7 @@ export declare class EntitlementRepository implements EntitlementStore {
25
25
  limit?: number;
26
26
  }): Promise<EntitlementRow[]>;
27
27
  listExpiring(nowMs: number, limit?: number): Promise<EntitlementRow[]>;
28
+ listActiveWithSource(limit?: number): Promise<EntitlementRow[]>;
28
29
  applyStatus(id: string, expectedFrom: string, to: string): Promise<EntitlementRow | null>;
29
30
  }
30
31
  export declare class ReputationFactRepository implements ReputationFactStore {
@@ -163,6 +163,17 @@ export class EntitlementRepository {
163
163
  .filter((r) => r.validUntilMs != null && r.validUntilMs <= nowMs);
164
164
  return rows.slice(0, need);
165
165
  }
166
+ async listActiveWithSource(limit) {
167
+ const rows = await this.orm
168
+ .where({ status: "ACTIVE" })
169
+ .orderBy((t) => t.createdAt.asc())
170
+ .limit((limit ?? 200) * 4)
171
+ .all();
172
+ return rows
173
+ .map(toEntitlementRow)
174
+ .filter((r) => r.sourcePaymentId != null)
175
+ .slice(0, limit ?? 200);
176
+ }
166
177
  async applyStatus(id, expectedFrom, to) {
167
178
  const existing = await this.getById(id);
168
179
  if (!existing || existing.status !== expectedFrom)
@@ -48,6 +48,7 @@ export interface EntitlementStore {
48
48
  limit?: number;
49
49
  }): Promise<EntitlementRow[]>;
50
50
  listExpiring(nowMs: number, limit?: number): Promise<EntitlementRow[]>;
51
+ listActiveWithSource(limit?: number): Promise<EntitlementRow[]>;
51
52
  applyStatus(id: string, expectedFrom: string, to: string): Promise<EntitlementRow | null>;
52
53
  }
53
54
  export interface ReputationFactInsert {
@@ -99,6 +100,7 @@ export declare class InMemoryEntitlementStore implements EntitlementStore {
99
100
  limit?: number;
100
101
  }): Promise<EntitlementRow[]>;
101
102
  listExpiring(nowMs: number, limit?: number): Promise<EntitlementRow[]>;
103
+ listActiveWithSource(limit?: number): Promise<EntitlementRow[]>;
102
104
  applyStatus(id: string, expectedFrom: string, to: string): Promise<EntitlementRow | null>;
103
105
  }
104
106
  export declare class InMemoryReputationFactStore implements ReputationFactStore {
@@ -14,7 +14,7 @@ export class InMemoryActorStore {
14
14
  did: merge("did"),
15
15
  orgId: merge("orgId"),
16
16
  tier: merge("tier"),
17
- payload: a.payload,
17
+ payload: structuredClone(a.payload),
18
18
  createdAt: existing?.createdAt ?? ts,
19
19
  updatedAt: ts,
20
20
  };
@@ -52,7 +52,7 @@ export class InMemoryEntitlementStore {
52
52
  createdAt: ts,
53
53
  updatedAt: ts,
54
54
  };
55
- this.rows.set(row.id, row);
55
+ this.rows.set(row.id, structuredClone(row));
56
56
  return row;
57
57
  }
58
58
  async getById(id) {
@@ -85,6 +85,13 @@ export class InMemoryEntitlementStore {
85
85
  out = out.slice(0, limit);
86
86
  return out;
87
87
  }
88
+ async listActiveWithSource(limit) {
89
+ let out = [...this.rows.values()].filter((r) => r.status === "ACTIVE" && r.sourcePaymentId != null);
90
+ out = out.sort((a, b) => a.createdAt.localeCompare(b.createdAt));
91
+ if (limit !== undefined)
92
+ out = out.slice(0, limit);
93
+ return out;
94
+ }
88
95
  async applyStatus(id, expectedFrom, to) {
89
96
  const row = this.rows.get(id);
90
97
  if (!row || row.status !== expectedFrom)
@@ -115,7 +122,7 @@ export class InMemoryReputationFactStore {
115
122
  subjectId: f.subjectId ?? null,
116
123
  createdAt: nowIso(),
117
124
  };
118
- this.rows.set(row.id, row);
125
+ this.rows.set(row.id, structuredClone(row));
119
126
  return row;
120
127
  }
121
128
  async getById(id) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentbadge/database",
3
- "version": "0.6.6",
3
+ "version": "0.6.7",
4
4
  "description": "Shared database layer for AgentBadge — Prisma ORM 8 client, repositories, store abstraction",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",