@agentbadge/database 0.1.1 → 0.3.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 +19 -1
- package/dist/database.d.ts +5 -1
- package/dist/database.js +10 -1
- package/dist/index.d.ts +8 -2
- package/dist/index.js +5 -1
- package/dist/prisma/contract.json +1071 -44
- package/dist/repositories/agent-wallet-repository.d.ts +29 -0
- package/dist/repositories/agent-wallet-repository.js +59 -0
- package/dist/repositories/chat-subscription-repository.d.ts +17 -0
- package/dist/repositories/chat-subscription-repository.js +39 -0
- package/dist/repositories/event-repository.d.ts +1 -0
- package/dist/repositories/event-repository.js +3 -0
- package/dist/repositories/scan-result-repository.d.ts +20 -0
- package/dist/repositories/scan-result-repository.js +41 -0
- package/dist/repositories/venue-repository.d.ts +36 -0
- package/dist/repositories/venue-repository.js +68 -0
- package/dist/store.d.ts +75 -0
- package/dist/store.js +122 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -37,6 +37,8 @@ const database = createDatabase({
|
|
|
37
37
|
|
|
38
38
|
// database.db — Prisma client facade, null when disabled
|
|
39
39
|
// database.events — Store (EventRepository on PG, InMemoryStore otherwise)
|
|
40
|
+
// database.scanResults — ScanResultStore (ScanResultRepository │ InMemoryScanResultStore)
|
|
41
|
+
// database.chatSubscriptions — ChatSubscriptionStore (ChatSubscriptionRepository │ InMemoryChatSubscriptionStore)
|
|
40
42
|
// database.health()— SELECT 1 probe → boolean
|
|
41
43
|
// database.close() — call ONCE at shutdown, never per-request
|
|
42
44
|
```
|
|
@@ -53,6 +55,20 @@ for CLI/migrations/tests inside the package dir only and is never published
|
|
|
53
55
|
(`files: ["dist"]`). `DIRECT_URL` (unpooled, migrations) stays local in
|
|
54
56
|
`.env.deployer` — see `RUNBOOK.md`.
|
|
55
57
|
|
|
58
|
+
## `Event` as a generic persisted-event table
|
|
59
|
+
|
|
60
|
+
`Event` is intentionally generic — new persisted event streams do NOT need
|
|
61
|
+
their own model. Convention (EPIC-145):
|
|
62
|
+
|
|
63
|
+
- `type` — the stream kind, e.g. `"audit"` (keeperhub audit events)
|
|
64
|
+
- `source` — the producing subsystem, e.g. `"keeperhub"`
|
|
65
|
+
- `payload` — the event JSON
|
|
66
|
+
- `Store.list({ type })` filters by stream kind (added in SLICE-145-4)
|
|
67
|
+
|
|
68
|
+
Dedicated models exist only where the shape is truly relational:
|
|
69
|
+
`ScanResult` (latest-scan-per-domain lookups) and `ChatSubscription`
|
|
70
|
+
(telegram chat ↔ username bindings, unique constraints + upsert).
|
|
71
|
+
|
|
56
72
|
## Adding a new entity
|
|
57
73
|
|
|
58
74
|
1. Add the model to `src/prisma/contract.prisma`
|
|
@@ -163,6 +179,8 @@ major = `CacheProvider`/`Store`/`Database` interface breaks.
|
|
|
163
179
|
hackathon/server (Hono) Fly.io machine
|
|
164
180
|
└─ createDatabase({enabled, url}) ──► Prisma Postgres
|
|
165
181
|
├─ events: Store (EventRepository │ InMemoryStore)
|
|
182
|
+
├─ scanResults: ScanResultStore (ScanResultRepository │ InMemoryScanResultStore)
|
|
183
|
+
├─ chatSubscriptions: ChatSubscriptionStore (ChatSubscriptionRepository │ InMemoryChatSubscriptionStore)
|
|
166
184
|
├─ health() → SELECT 1 (pooled DATABASE_URL)
|
|
167
185
|
└─ close() on SIGTERM/SIGINT
|
|
168
186
|
|
|
@@ -177,7 +195,7 @@ packages/database (this repo) local dev
|
|
|
177
195
|
- `src/` — package source (published via `dist/`)
|
|
178
196
|
- `src/prisma/` — contract artifacts (`contract.json`, `contract.d.ts`,
|
|
179
197
|
`db.ts` dev client) — committed (D16)
|
|
180
|
-
- `src/repositories/` — `EventRepository` (canonical template)
|
|
198
|
+
- `src/repositories/` — `EventRepository` (canonical template), `ScanResultRepository`, `ChatSubscriptionRepository`
|
|
181
199
|
- `migrations/` — committed migration packages + snapshot store + `db` ref
|
|
182
200
|
- `tests/` — vitest suites (PG legs skip without `DATABASE_URL`)
|
|
183
201
|
- `scripts/seed.ts` — idempotent seed
|
package/dist/database.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type PrismaDb } from "./repositories/event-repository.js";
|
|
2
|
-
import {
|
|
2
|
+
import { AgentWalletRepository } from "./repositories/agent-wallet-repository.js";
|
|
3
|
+
import { type ChatSubscriptionStore, type ScanResultStore, type Store } from "./store.js";
|
|
3
4
|
export interface DatabaseConfig {
|
|
4
5
|
url?: string;
|
|
5
6
|
enabled?: boolean;
|
|
@@ -7,6 +8,9 @@ export interface DatabaseConfig {
|
|
|
7
8
|
export interface Database {
|
|
8
9
|
db: PrismaDb | null;
|
|
9
10
|
events: Store;
|
|
11
|
+
scanResults: ScanResultStore;
|
|
12
|
+
chatSubscriptions: ChatSubscriptionStore;
|
|
13
|
+
agentWallets: AgentWalletRepository | null;
|
|
10
14
|
health(): Promise<boolean>;
|
|
11
15
|
close(): Promise<void>;
|
|
12
16
|
}
|
package/dist/database.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import postgres from "@prisma/orm-postgres/runtime";
|
|
2
2
|
import contractJson from "./prisma/contract.json" with { type: "json" };
|
|
3
3
|
import { EventRepository } from "./repositories/event-repository.js";
|
|
4
|
-
import {
|
|
4
|
+
import { ScanResultRepository } from "./repositories/scan-result-repository.js";
|
|
5
|
+
import { ChatSubscriptionRepository } from "./repositories/chat-subscription-repository.js";
|
|
6
|
+
import { AgentWalletRepository } from "./repositories/agent-wallet-repository.js";
|
|
7
|
+
import { InMemoryChatSubscriptionStore, InMemoryScanResultStore, InMemoryStore, } from "./store.js";
|
|
5
8
|
export function createDatabase(config) {
|
|
6
9
|
const enabled = config.enabled !== false && Boolean(config.url);
|
|
7
10
|
if (!enabled) {
|
|
@@ -9,6 +12,9 @@ export function createDatabase(config) {
|
|
|
9
12
|
return {
|
|
10
13
|
db: null,
|
|
11
14
|
events,
|
|
15
|
+
scanResults: new InMemoryScanResultStore(),
|
|
16
|
+
chatSubscriptions: new InMemoryChatSubscriptionStore(),
|
|
17
|
+
agentWallets: null,
|
|
12
18
|
health: () => Promise.resolve(false),
|
|
13
19
|
close: () => Promise.resolve(),
|
|
14
20
|
};
|
|
@@ -17,6 +23,9 @@ export function createDatabase(config) {
|
|
|
17
23
|
return {
|
|
18
24
|
db,
|
|
19
25
|
events: new EventRepository(db),
|
|
26
|
+
scanResults: new ScanResultRepository(db),
|
|
27
|
+
chatSubscriptions: new ChatSubscriptionRepository(db),
|
|
28
|
+
agentWallets: new AgentWalletRepository(db),
|
|
20
29
|
health: async () => {
|
|
21
30
|
try {
|
|
22
31
|
const plan = db.raw.sql `SELECT 1 AS health`.returnsRow({ health: "pg/int4@1" }).build();
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,13 @@ export type { Contract } from "./prisma/contract.d.js";
|
|
|
4
4
|
export { createDatabase } from "./database.js";
|
|
5
5
|
export type { Database, DatabaseConfig } from "./database.js";
|
|
6
6
|
export { Repository } from "./repository.js";
|
|
7
|
-
export { InMemoryStore } from "./store.js";
|
|
8
|
-
export type { Event, EventCreate, EventUpdate, Store } from "./store.js";
|
|
7
|
+
export { InMemoryChatSubscriptionStore, InMemoryScanResultStore, InMemoryStore, } from "./store.js";
|
|
8
|
+
export type { ChatSubscription, ChatSubscriptionCreate, ChatSubscriptionStore, ChatSubscriptionUpdate, Event, EventCreate, EventUpdate, ScanResult, ScanResultCreate, ScanResultStore, ScanResultUpdate, Store, } from "./store.js";
|
|
9
9
|
export { EventRepository } from "./repositories/event-repository.js";
|
|
10
|
+
export { ScanResultRepository } from "./repositories/scan-result-repository.js";
|
|
11
|
+
export { ChatSubscriptionRepository } from "./repositories/chat-subscription-repository.js";
|
|
12
|
+
export { VenueRepository } from "./repositories/venue-repository.js";
|
|
13
|
+
export type { VenueJobUpsert, VenueOfferUpsert, } from "./repositories/venue-repository.js";
|
|
14
|
+
export { AgentWalletRepository } from "./repositories/agent-wallet-repository.js";
|
|
15
|
+
export type { AgentWalletUpsert } from "./repositories/agent-wallet-repository.js";
|
|
10
16
|
export type { PrismaDb } from "./repositories/event-repository.js";
|
package/dist/index.js
CHANGED
|
@@ -2,5 +2,9 @@ export const PACKAGE_NAME = "@agentbadge/database";
|
|
|
2
2
|
export const PACKAGE_VERSION = "0.1.0";
|
|
3
3
|
export { createDatabase } from "./database.js";
|
|
4
4
|
export { Repository } from "./repository.js";
|
|
5
|
-
export { InMemoryStore } from "./store.js";
|
|
5
|
+
export { InMemoryChatSubscriptionStore, InMemoryScanResultStore, InMemoryStore, } from "./store.js";
|
|
6
6
|
export { EventRepository } from "./repositories/event-repository.js";
|
|
7
|
+
export { ScanResultRepository } from "./repositories/scan-result-repository.js";
|
|
8
|
+
export { ChatSubscriptionRepository } from "./repositories/chat-subscription-repository.js";
|
|
9
|
+
export { VenueRepository } from "./repositories/venue-repository.js";
|
|
10
|
+
export { AgentWalletRepository } from "./repositories/agent-wallet-repository.js";
|